fix(providers/openai): emit source parts for Responses API streaming annotations#10
Open
fix(providers/openai): emit source parts for Responses API streaming annotations#10
Conversation
…annotations The Responses API streaming path was missing a handler for "response.output_text.annotation.added" events. This meant that url_citation and file_citation annotations—which carry source URLs and titles for web search results—were silently dropped during streaming. The non-streaming Generate path and the Chat Completions API streaming path both handled annotations correctly; only the Responses API Stream path was affected. Add a case for "response.output_text.annotation.added" that parses the annotation map and yields StreamPartTypeSource parts for url_citation and file_citation types, matching the behavior of the existing Generate path and the Anthropic provider. Update TestResponsesStream_WebSearchResponse to include annotation.added events in the mock stream and assert that source parts are emitted with the correct URL, title, and type.
ef923d6 to
5bc340a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The OpenAI Responses API streaming path was missing a handler for
response.output_text.annotation.addedevents. This meant thaturl_citationandfile_citationannotations—which carry source URLs and titles for web search results—were silently dropped during streaming.The non-streaming
Generatepath and the Chat Completions API streaming path both handled annotations correctly; only the Responses APIStreampath was affected. This caused downstream consumers (e.g. chatd in coder/coder) to receivetool-call,tool-result,reasoning, andtextparts but zerosourceparts when using OpenAI web search.Intended upstream target: charmbracelet/fantasy (opened here on fork due to permissions; please merge upstream.)
Fix
Add a
case "response.output_text.annotation.added"to the streaming event switch inresponses_language_model.gothat:anytype in the SDK, deserializes asmap[string]interface{})url_citation: yields aStreamPartTypeSourcewithSourceTypeURL, URL, and titlefile_citation: yields aStreamPartTypeSourcewithSourceTypeDocumentand the filename as titleThis matches the existing behavior in:
Generatepath (lines 770-796)parseAnnotationsFromDelta)Test
Updated
TestResponsesStream_WebSearchResponseto:response.output_text.annotation.addedevents in the mock stream (matching real API behavior observed in recorded test data)StreamPartTypeSourceparts are emitted with correct URL, title, source type, and non-empty IDs