fix: Claude stream block index/type transitions - #2854
Conversation
WalkthroughTwo files are modified to improve tool-call indexing in Claude-to-OpenAI streaming conversion. New fields are added to the ClaudeConvertInfo struct to track tool-call indices, while service/convert.go implements helper functions and logic to properly manage content block state transitions and index propagation during tool-call streaming. Changes
Sequence DiagramsequenceDiagram
participant Stream as Streaming Handler
participant State as ClaudeConvertInfo State
participant Blocks as Content Block Manager
participant Events as Event Emitter
Stream->>State: Detect tool_call in stream
Stream->>State: Initialize ToolCallBaseIndex & ToolCallMaxIndexOffset
alt Open Block Exists
Stream->>Blocks: stopOpenBlocks()
Blocks->>Events: Emit content_block_stop (previous block)
end
Stream->>Blocks: Compute correct block index
Blocks->>Events: Emit content_block_start (tool_use)
loop For Each Tool Call Delta
Stream->>Blocks: Emit content_block_delta with correct Index
Blocks->>Events: Stream delta event
end
Stream->>Blocks: Finalize block state
Blocks->>Events: Emit content_block_stop (tool_use)
Events->>Events: Report usage + finish_reason
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
fix: Claude stream block index/type transitions
fix #2695
claude的vscode插件会依赖返回信息的index,在交错思考情况下不符合插件预期。
attach文件再请求即可复现,终端使用不受影响。
另外VsCode插件上传文件没有被读取到,原因为OpenAI转Claude没有兼容文件类型,在另外的PR(#2689
)中有处理。
tips:不建议在有条件用claude原生格式的情况下使用转换,并非所有模型都有同样的交错思考的概念,未必能完美兼容,对性能也或许有一定的损耗。