fix(codex): accumulate output items from stream events
The Codex/OpenAI Responses streaming API sends output items via response.output_item.done events during the stream, but the final response.completed event arrives with an empty Output array. This caused all Codex provider responses to return empty content despite the model successfully generating a reply. Fix by accumulating output items as they arrive and merging them into the response when response.completed has none. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
06023c79fa
commit
be005307b2
1 changed files with 9 additions and 0 deletions
|
|
@ -104,12 +104,21 @@ func (p *CodexProvider) Chat(
|
||||||
defer stream.Close()
|
defer stream.Close()
|
||||||
|
|
||||||
var resp *responses.Response
|
var resp *responses.Response
|
||||||
|
var accumulatedOutput []responses.ResponseOutputItemUnion
|
||||||
for stream.Next() {
|
for stream.Next() {
|
||||||
evt := stream.Current()
|
evt := stream.Current()
|
||||||
|
// Accumulate output items as they arrive — the response.completed
|
||||||
|
// event may not include them in its Response.Output field.
|
||||||
|
if evt.Type == "response.output_item.done" {
|
||||||
|
accumulatedOutput = append(accumulatedOutput, evt.Item)
|
||||||
|
}
|
||||||
if evt.Type == "response.completed" || evt.Type == "response.failed" || evt.Type == "response.incomplete" {
|
if evt.Type == "response.completed" || evt.Type == "response.failed" || evt.Type == "response.incomplete" {
|
||||||
evtResp := evt.Response
|
evtResp := evt.Response
|
||||||
if evtResp.ID != "" {
|
if evtResp.ID != "" {
|
||||||
evtRespCopy := evtResp
|
evtRespCopy := evtResp
|
||||||
|
if len(evtRespCopy.Output) == 0 && len(accumulatedOutput) > 0 {
|
||||||
|
evtRespCopy.Output = accumulatedOutput
|
||||||
|
}
|
||||||
resp = &evtRespCopy
|
resp = &evtRespCopy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue