Skip to content

fix(adapters): forward extra_body params and return reasoning_content properly#75

Merged
pescn merged 2 commits intomainfrom
fix/adapter-passthrough-and-reasoning-content
Feb 9, 2026
Merged

fix(adapters): forward extra_body params and return reasoning_content properly#75
pescn merged 2 commits intomainfrom
fix/adapter-passthrough-and-reasoning-content

Conversation

@pescn
Copy link
Contributor

@pescn pescn commented Feb 9, 2026

Summary

  • Fix request param passthrough: Request adapters had a KNOWN_FIELDS set that excluded recognized fields (e.g. response_format, presence_penalty, seed, frequency_penalty, logit_bias, user, n, modalities, metadata, etc.) from extraParams passthrough, but those fields were never mapped in parse() either — silently dropping them. Renamed to MAPPED_FIELDS containing only fields actually consumed by parse(), so all other fields flow through to upstream providers.
  • Fix reasoning_content serialization: The OpenAI Chat response adapter wrapped reasoning_content in <think> tags inside the content field. This was originally only used for DB logging (commit f837650 by Koi to Coco), but was incorrectly carried over into client response serialization during the adapter refactor (09a0ce9). Now returns reasoning_content as a separate field for client responses, keeping <think> wrapping only for database storage.

Test plan

  • bun run check — type check passes
  • bun run lint — no errors
  • Verified response_format, presence_penalty, seed, and custom fields are forwarded to upstream via unit test script
  • Verified reasoning_content is returned as separate field in non-streaming response (tested with doubao-seed model)
  • Verified streaming reasoning_content delta still works (unchanged)
  • Verified stream_options default behavior preserved (upstream adapter sets include_usage: true when user doesn't provide it)

🤖 Generated with Claude Code

Summary by CodeRabbit

发布说明

  • 新增功能

    • 支持推理内容(reasoning content),响应中可同时包含文本与推理信息,流式输出时也会携带推理内容。
  • 改进

    • 优化适配器的字段映射与额外参数转发逻辑,精简并统一参数处理,提高请求转发与兼容性。

… properly

Request adapters had a KNOWN_FIELDS set that excluded recognized fields
(e.g. response_format, presence_penalty, seed) from extraParams passthrough,
but those fields were never mapped in parse() either — causing them to be
silently dropped when forwarding to upstream providers. Rename to MAPPED_FIELDS
containing only fields actually consumed by parse(), so all other fields
flow through extraParams to the upstream provider.

The response adapter for OpenAI Chat wrapped reasoning_content in <think>
tags inside the content field. This was originally only used for DB logging,
but was incorrectly carried over into client response serialization during
the adapter refactor (09a0ce9). Restore the original behavior: return
reasoning_content as a separate field for client responses, keep <think>
wrapping only for database storage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Feb 9, 2026

📝 Walkthrough

Walkthrough

重命名并收窄了请求适配器中的已映射字段集合(KNOWN_FIELDS -> MAPPED_FIELDS),改变了哪些字段被视为显式映射并将其余字段作为 extraParams 透传;同时在 OpenAI 聊天响应适配器中新增并携带了 reasoning_content 字段以分离推理内容。

Changes

Cohort / File(s) Summary
请求适配器字段映射重构
backend/src/adapters/request/anthropic.ts, backend/src/adapters/request/openai-chat.ts, backend/src/adapters/request/openai-response.ts
KNOWN_FIELDS 重命名为 MAPPED_FIELDS,并缩小/调整其内容。提取额外参数时改为基于 MAPPED_FIELDS 判定,导致更多原先在已知集合内的键现在被视为 extraParams(Anthropic 中移除了 metadata)。
OpenAI 聊天响应:推理内容分离
backend/src/adapters/response/openai-chat.ts
OpenAIChatMessage 添加可选字段 `reasoning_content?: string

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

诗歌

🐰 我是小兔写代码,字段换名跳新潮,

MAPPED 把旧 KNOWN 取代,透传与映射各分晓,
推理内容单独装,流里也能细诉道,
欢欣一跃拍爪跑,代码花园又一苗。

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确地总结了主要变更:修复适配器以正确转发额外参数和返回reasoning_content,与所有四个修改文件的核心目标相符。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/adapter-passthrough-and-reasoning-content

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
backend/src/adapters/response/openai-chat.ts (1)

75-80: 建议将 reasoning_content 添加到 OpenAIChatDelta 接口定义中。

非流式响应的 OpenAIChatMessage(第 38 行)已声明 reasoning_content 字段,但流式响应的 OpenAIChatDelta 接口未声明。第 275 行通过类型交叉 OpenAIChatDelta & { reasoning_content?: string } 临时补丁绕过了类型检查,这会导致接口定义与实际输出不一致,后续维护者可能遗漏该字段的存在。

♻️ 建议在接口中直接声明
 interface OpenAIChatDelta {
   role?: "assistant";
   content?: string | null;
+  reasoning_content?: string | null;
   tool_calls?: OpenAIToolCallDelta[];
   refusal?: string | null;
 }

这样第 275 行可以简化为:

-            const delta: OpenAIChatDelta & { reasoning_content?: string } = {
+            const delta: OpenAIChatDelta = {
               content: null,
               reasoning_content: chunk.delta.thinking,
             };

Also applies to: 273-278


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link

Summary of Changes

Hello @pescn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses two key issues related to data handling within the backend adapters. It refines how request parameters are processed, ensuring that all unmapped fields are correctly passed through to upstream services, thereby preventing silent data loss. Additionally, it rectifies the serialization of 'reasoning_content' in OpenAI chat responses, separating it from the main content field for improved clarity and adherence to expected API structures.

Highlights

  • Request Parameter Passthrough Fix: Request adapters were incorrectly dropping recognized fields (like response_format, presence_penalty, seed, etc.) from extraParams passthrough. The KNOWN_FIELDS set has been renamed to MAPPED_FIELDS and now only includes fields explicitly consumed by the parse() method, ensuring all other fields are correctly forwarded to upstream providers.
  • Reasoning Content Serialization Correction: The OpenAI Chat response adapter previously wrapped reasoning_content in <think> tags within the main content field for client responses. This has been corrected; reasoning_content is now returned as a separate field for client responses, while the <think> tag wrapping is preserved only for database storage.
Changelog
  • backend/src/adapters/request/anthropic.ts
    • Renamed KNOWN_FIELDS to MAPPED_FIELDS to better reflect its purpose: fields explicitly extracted by parse() are excluded from extraParams.
    • Updated comments to clarify that all other fields (e.g., metadata) are passed through via extraParams.
    • Removed "metadata" from the MAPPED_FIELDS set.
    • Replaced all instances of KNOWN_FIELDS with MAPPED_FIELDS in the parse() method.
  • backend/src/adapters/request/openai-chat.ts
    • Renamed KNOWN_FIELDS to MAPPED_FIELDS and updated comments to specify that fields like response_format, presence_penalty, and seed will now pass through.
    • Removed numerous fields (e.g., n, stream_options, presence_penalty, frequency_penalty, logit_bias, logprobs, top_logprobs, user, seed, response_format) from the MAPPED_FIELDS set.
    • Replaced all instances of KNOWN_FIELDS with MAPPED_FIELDS in the parse() method.
  • backend/src/adapters/request/openai-response.ts
    • Renamed KNOWN_FIELDS to MAPPED_FIELDS and updated comments to indicate that fields like modalities, parallel_tool_calls, store, and metadata will now pass through.
    • Removed several fields (e.g., modalities, parallel_tool_calls, previous_response_id, store, metadata) from the MAPPED_FIELDS set.
    • Replaced all instances of KNOWN_FIELDS with MAPPED_FIELDS in the parse() method.
  • backend/src/adapters/response/openai-chat.ts
    • Added reasoning_content?: string | null; to the OpenAIChatMessage interface.
    • Modified extractTextContent to exclusively extract text content, removing previous logic for thinking parts.
    • Introduced a new helper function extractReasoningContent to specifically extract and return thinking content.
    • In the serialize method, extractReasoningContent is now called to obtain reasoningContent.
    • Conditionally added reasoning_content as a distinct field within the message object of the serialized response.
Activity
  • bun run check — type check passes
  • bun run lint — no errors
  • Verified response_format, presence_penalty, seed, and custom fields are forwarded to upstream via unit test script
  • Verified reasoning_content is returned as separate field in non-streaming response (tested with doubao-seed model)
  • Verified streaming reasoning_content delta still works (unchanged)
  • Verified stream_options default behavior preserved (upstream adapter sets include_usage: true when user doesn't provide it)
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces two main fixes: ensuring extra request parameters are correctly forwarded to upstream providers, and properly serializing reasoning_content as a separate field in responses. The changes to the request adapters are clean and effectively address the parameter passthrough issue by renaming KNOWN_FIELDS to the more accurate MAPPED_FIELDS and refining their contents. The response adapter change correctly separates reasoning content from the main content. I've included one suggestion to refactor two related functions into a single one to improve efficiency by avoiding iterating over the same data twice, which also aligns with our guidelines for returning ready-to-use objects from helper functions. Overall, the changes are well-implemented and improve the adapters' behavior.

… single pass

Merge two separate functions that iterated over the same content blocks
array into a single extractContent() function that returns both text and
reasoning in one pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pescn pescn merged commit 3d4016f into main Feb 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant