[codex] 修复 Chat Completions 兼容流式 tool_calls 桥接#238
Merged
Conversation
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.
改动内容
/v1/chat/completions被适配到/v1/responses后,Responses API 的function_callSSE 事件没有正确转回 Chat Completionstool_callsdelta 的问题。role: assistant,保持 Chat Completions 流式响应兼容性。finish_reason: "tool_calls",让客户端继续执行工具调用。response.output_item.added、response.function_call_arguments.delta、response.function_call_arguments.done、response.output_item.done中累计并补齐 tool call arguments。问题背景
部分 OpenAI-compatible 客户端,例如 opencode 和 Trae 自定义模型,会通过
/v1/chat/completions访问 Codex/Responses 后端。修复前,上游实际返回了 Responses API 的 function call 流式事件,但桥接层没有把它们转换成 Chat Completions 兼容的
delta.tool_calls。客户端因此只能看到 step 结束和 token 统计,却拿不到可展示文本或可执行的 tool call,表现为模型有返回但界面不显示内容。修复方式
在
ChatCompletionsFromResponsesSseReader中补齐 Responses function call SSE 到 Chat Completions tool_calls SSE 的转换逻辑,使 OpenAI-compatible 客户端能正确识别并继续执行工具调用。测试说明
cargo test -p codexmanager-service chat_completions_reader_ -- --nocapturepnpm run build:desktop