fix: correct streaming id/model extraction and multi-format usage tracking#28
Merged
john-zhh merged 1 commit intofeat/v3.0.1from Mar 12, 2026
Merged
Conversation
…cking - stream.go: extract id/model from nested response object in response.created/in_progress events (was reading wrong top-level key) - stream.go: capture call_id/name from response.output_item.added so first tool_calls delta includes proper id and function.name header - stream.go: emit full tool call header (id, type, function.name, first args) on first delta; subsequent deltas carry args only - server.go: sseUsageExtractor.processChunk now handles Responses API response.completed events and OpenAI Chat final chunks (no "type" field, usage at top level with prompt_tokens/completion_tokens) - tests: assert id and model fields in streaming chunks; add response.output_item.added to tool call test; cover Responses API and OpenAI Chat usage extraction in sseUsageExtractor tests Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
response.created/response.in_progressnow correctly readsidandmodelfrom the nestedresponseobject (not top-level) — fixes wrongid/modelin emittedchat.completion.chunkobjectsresponse.output_item.addedhandler to capturecall_idandnameper tool call index; first delta now emits full header (id,type: "function",function.name, first args chunk)sseUsageExtractor.processChunknow handles three SSE formats:message_start/message_delta(existing)response.completedwith nestedresponse.usagetypefield, final chunk with top-levelusage.prompt_tokens/completion_tokensid,model,tool_call.id, andfunction.name; usage extractor tests cover all three formatsTest plan
TestTransformResponsesAPIToOpenAIChat_Text— assertschatcmpl-resp_chat1id andgpt-5model in output chunksTestTransformResponsesAPIToOpenAIChat_ToolCall— assertscall_abctool call id andget_weatherfunction nameTestSSEUsageExtractor/extracts_usage_from_responses_api_sse— coversresponse.completedusage extractionTestSSEUsageExtractor/extracts_usage_from_openai_chat_sse— covers OpenAI Chat final chunk usage extractioninternal/proxycoverage ≥ 80.2%,internal/proxy/transform≥ 87.7%🤖 Generated with Claude Code