feat: 提升 Codex custom tool 事件兼容#286
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughExtends Codex-to-OpenAI and Codex-to-Anthropic translators to recognize Changescustom_tool_call Translation Support
Reasoning Include Handling Refactor
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
背景
本次变更参考 Wei-Shaw/sub2api#3065 中 Codex 模拟保真度的低风险部分,聚焦两个已确认范围:
include的合并逻辑。custom_tool_call/response.custom_tool_call_input.delta事件在 Chat Completions 与 Anthropic 兼容路径中的处理。现有实现已经具备较完整的 Codex UA / Originator / Session / WebSocket 头部策略,因此本 PR 不调整请求头相关逻辑,避免破坏已有可工作指纹组合。
修改前
include 行为
PrepareResponsesBody在请求没有include时会默认注入:["reasoning.encrypted_content"]但如果客户端已经传入了其他
include,即使请求包含reasoning,也不会补充reasoning.encrypted_content。例如:{ "reasoning": {"effort": "high"}, "include": ["file_search_call.results"] }旧行为会原样保留 include,导致 reasoning 加密内容项缺失。
custom tool call 事件
旧逻辑主要识别:
function_callresponse.function_call_arguments.delta对于新版上游可能返回的:
custom_tool_callresponse.custom_tool_call_input.delta部分路径无法按工具调用处理,可能出现工具参数增量无法映射、非流式工具调用提取缺失,或旧无状态转换 fallback 将 custom tool input delta 当普通文本输出的问题。
修改后
include 合并
新增 Codex include 合并辅助逻辑:
include时保持原默认行为,注入reasoning.encrypted_content。reasoning且已有include时,如缺少reasoning.encrypted_content则追加。custom tool call 兼容
补齐以下兼容逻辑:
custom_tool_call。response.custom_tool_call_input.delta/done。item.id与call_id到同一 OpenAI tool call index,兼容上游 delta 使用不同 ID 字段回传。custom_tool_call,并从input字段读取参数。custom_tool_call与response.custom_tool_call_input.delta。custom_tool_call。TranslateStreamChunk显式忽略response.custom_tool_call_input.delta/done,避免被 fallback 当作普通文本输出;同时保留旧function_call_arguments.delta行为,减少回归风险。前后对比分析
兼容性
User-Agent、Originator、OpenAI-Beta、Session_id、Conversation_id、Authorization等既有请求头策略。include逻辑为加法合并,保留既有项且不重复。custom_tool_call被映射到 OpenAI/Anthropic 现有工具调用结构,对旧function_call行为保持兼容。风险控制
include不强行覆盖,避免破坏未知客户端输入。item_id与call_id,降低上游事件字段差异导致的索引丢失风险。行为变化
reasoning且已有 include 数组但缺少reasoning.encrypted_content时,会自动追加该项。custom_tool_call/response.custom_tool_call_input.delta时,将按工具调用参数增量处理,而不是丢失或误当普通文本。测试情况
已执行以下测试:
结果:
结果:
结果:
另外执行:
git diff --check结果:无空白错误。Windows 环境下仅出现 Git 换行提示
LF will be replaced by CRLF the next time Git touches it。未通过 / 未执行说明
执行
go test ./...时,根包因当前 worktree 缺少前端构建产物失败:该失败与本 PR 的 Go 代码修改无关;已用除根包外的全部 Go 子包测试进行覆盖验证。
修改总结
本 PR 在不改既有可工作请求头的前提下,补齐了 Codex Responses 请求体 include 合并和 custom tool call SSE 事件兼容能力,提升 Codex 模拟保真度与新版上游事件格式兼容性,并通过定向测试与相关 Go 子包测试验证。
Summary by CodeRabbit
New Features
Tests