feat: Grok 适配完善 — 防御性 usage 合并 + thinking 自动检测#1234
Conversation
1. 提取 updateOpenAIUsage 到共享模块 openaiShared.ts,供 OpenAI 和 Grok 两条路径复用,消除 Grok 中重复的 spread 漏洞。 2. 在 requestBody.ts 的 isOpenAIThinkingEnabled() 中增加 Grok 模型 自动检测(模型名含 "grok"),与 DeepSeek/MiMo 并列。 3. messaging 层的 reasoning_content 回传(openaiConvertMessages.ts) 和流解析(openaiStreamAdapter.ts)无需修改,Grok 与 DeepSeek/MiMo 共用相同的 reasoning_content 字段协议。 Co-Authored-By: deepseek-v4-pro[1m] <deepseek-ai@claude-code-best.win>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughExtracts streaming token-usage merging into a shared ChangesStreaming Token Usage Unification
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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 |
Grok 推理模型(如 grok-4.20-reasoning)自动进行推理,不需要 thinking/enable_thinking 请求参数。发送这些参数虽大概率被忽略 (OpenAI SDK 透传 unknown keys),但属于不正确行为。 Co-Authored-By: deepseek-v4-pro[1m] <deepseek-ai@claude-code-best.win>
Summary
完善 Grok (xAI) API 适配,消除与 OpenAI 路径之间不必要的代码重复和漏洞。
1. 提取共享的
updateOpenAIUsage到openaiShared.tssrc/services/api/openai/openaiShared.ts模块message_start和message_delta处理器的裸 spread 漏洞2. Grok thinking mode 自动检测
isOpenAIThinkingEnabled()现在自动检测模型名包含 "grok" 的模型reasoning_content字段与 DeepSeek/MiMo 共享相同的协议openaiStreamAdapter和openaiConvertMessages无需修改3. 无需修改的部分
openaiStreamAdapter.ts— 已正确处理reasoning_content→ thinking block 映射openaiConvertMessages.ts— 已正确保留reasoning_content用于多轮回传cost_in_usd_ticks— Grok 独有的精确计费字段,预留后续处理Context7 API 文档验证
根据 xAI 官方 API 文档确认:
prompt_tokens,completion_tokens,prompt_tokens_details.cached_tokens)reasoning_content字段与 DeepSeek 使用相同的协议Test plan
🤖 Generated with Claude Code Best
Summary by CodeRabbit
Bug Fixes
Refactor
New Features