Repository navigation
fix(relayconvert): Claude tool_result 图片提升到 user 消息;Chat→Responses 流补齐 reasoning part 事件并按段切分 item - #7512
Merged
Calcium-Ion merged 1 commit intoSep 21, 2026
Conversation
…ses reasoning items Claude Messages -> Chat: a tool_result whose content is a block array was stringified into the Chat tool message, so image base64 travelled upstream as text instead of vision input. Text blocks now stay on the tool message (joined with newlines) and image blocks become image_url parts on the user message the same Claude message produces, which lands after the tool batch and keeps parallel tool messages contiguous. Image-only results carry an "[image]" placeholder; arrays with other block types keep the stringified form. Chat stream -> Responses stream: reasoning items now emit response.reasoning_summary_part.added and .done around the summary text, and deltas that arrive after a mid-stream finish_reason open a new reasoning or message item instead of appending to the closed one. Closed items are snapshotted so the completed response lists every segment. Closes #7407 Closes #7495
Contributor
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Calcium-Ion
added a commit
that referenced
this pull request
Sep 21, 2026
…7512 Co-Authored-By: ByebyDoggy <ByebyDoggy@users.noreply.github.com>
Closed
9 of 12 tasks
MOON-DREAM-STARS
added a commit
to MOON-DREAM-STARS/new-api
that referenced
this pull request
Sep 22, 2026
Javabcd
pushed a commit
to Javabcd/new-api
that referenced
this pull request
Sep 22, 2026
…ses reasoning items (QuantumNous#7512) Claude Messages -> Chat: a tool_result whose content is a block array was stringified into the Chat tool message, so image base64 travelled upstream as text instead of vision input. Text blocks now stay on the tool message (joined with newlines) and image blocks become image_url parts on the user message the same Claude message produces, which lands after the tool batch and keeps parallel tool messages contiguous. Image-only results carry an "[image]" placeholder; arrays with other block types keep the stringified form. Chat stream -> Responses stream: reasoning items now emit response.reasoning_summary_part.added and .done around the summary text, and deltas that arrive after a mid-stream finish_reason open a new reasoning or message item instead of appending to the closed one. Closed items are snapshotted so the completed response lists every segment. Closes QuantumNous#7407 Closes QuantumNous#7495 Co-Authored-By: MOON-DREAM-STARS <110315488+MOON-DREAM-STARS@users.noreply.github.com>
Javabcd
pushed a commit
to Javabcd/new-api
that referenced
this pull request
Sep 22, 2026
…landed in QuantumNous#7512 Co-Authored-By: ByebyDoggy <ByebyDoggy@users.noreply.github.com>
8 tasks done
GuDong2003
pushed a commit
to GuDong2003/new-api
that referenced
this pull request
Sep 25, 2026
…ses reasoning items (QuantumNous#7512) Claude Messages -> Chat: a tool_result whose content is a block array was stringified into the Chat tool message, so image base64 travelled upstream as text instead of vision input. Text blocks now stay on the tool message (joined with newlines) and image blocks become image_url parts on the user message the same Claude message produces, which lands after the tool batch and keeps parallel tool messages contiguous. Image-only results carry an "[image]" placeholder; arrays with other block types keep the stringified form. Chat stream -> Responses stream: reasoning items now emit response.reasoning_summary_part.added and .done around the summary text, and deltas that arrive after a mid-stream finish_reason open a new reasoning or message item instead of appending to the closed one. Closed items are snapshotted so the completed response lists every segment. Closes QuantumNous#7407 Closes QuantumNous#7495 Co-Authored-By: MOON-DREAM-STARS <110315488+MOON-DREAM-STARS@users.noreply.github.com> (cherry picked from commit 4eb3b91)
Steve3184
pushed a commit
to Steve3184/new-api
that referenced
this pull request
Sep 25, 2026
…ses reasoning items (QuantumNous#7512) Claude Messages -> Chat: a tool_result whose content is a block array was stringified into the Chat tool message, so image base64 travelled upstream as text instead of vision input. Text blocks now stay on the tool message (joined with newlines) and image blocks become image_url parts on the user message the same Claude message produces, which lands after the tool batch and keeps parallel tool messages contiguous. Image-only results carry an "[image]" placeholder; arrays with other block types keep the stringified form. Chat stream -> Responses stream: reasoning items now emit response.reasoning_summary_part.added and .done around the summary text, and deltas that arrive after a mid-stream finish_reason open a new reasoning or message item instead of appending to the closed one. Closed items are snapshotted so the completed response lists every segment. Closes QuantumNous#7407 Closes QuantumNous#7495 Co-Authored-By: MOON-DREAM-STARS <110315488+MOON-DREAM-STARS@users.noreply.github.com>
TomJKS
pushed a commit
to TomJKS/new-api
that referenced
this pull request
Sep 28, 2026
…ses reasoning items (QuantumNous#7512) Claude Messages -> Chat: a tool_result whose content is a block array was stringified into the Chat tool message, so image base64 travelled upstream as text instead of vision input. Text blocks now stay on the tool message (joined with newlines) and image blocks become image_url parts on the user message the same Claude message produces, which lands after the tool batch and keeps parallel tool messages contiguous. Image-only results carry an "[image]" placeholder; arrays with other block types keep the stringified form. Chat stream -> Responses stream: reasoning items now emit response.reasoning_summary_part.added and .done around the summary text, and deltas that arrive after a mid-stream finish_reason open a new reasoning or message item instead of appending to the closed one. Closed items are snapshotted so the completed response lists every segment. Closes QuantumNous#7407 Closes QuantumNous#7495 Co-Authored-By: MOON-DREAM-STARS <110315488+MOON-DREAM-STARS@users.noreply.github.com>
TomJKS
pushed a commit
to TomJKS/new-api
that referenced
this pull request
Sep 28, 2026
…landed in QuantumNous#7512 Co-Authored-By: ByebyDoggy <ByebyDoggy@users.noreply.github.com>
Javabcd
pushed a commit
to Javabcd/new-api
that referenced
this pull request
Oct 9, 2026
…landed in QuantumNous#7512 Co-Authored-By: ByebyDoggy <ByebyDoggy@users.noreply.github.com>
Javabcd
pushed a commit
to Javabcd/new-api
that referenced
this pull request
Oct 9, 2026
…landed in QuantumNous#7512 Co-Authored-By: ByebyDoggy <ByebyDoggy@users.noreply.github.com>
This was referenced Oct 15, 2026
1 of 5 tasks
Calcium-Ion
deleted the
fix/relayconvert-tool-result-media-and-reasoning-parts
branch
October 22, 2026 04:57
12 tasks
timwenx
pushed a commit
to timwenx/new-api
that referenced
this pull request
Nov 18, 2026
…ses reasoning items (QuantumNous#7512) Claude Messages -> Chat: a tool_result whose content is a block array was stringified into the Chat tool message, so image base64 travelled upstream as text instead of vision input. Text blocks now stay on the tool message (joined with newlines) and image blocks become image_url parts on the user message the same Claude message produces, which lands after the tool batch and keeps parallel tool messages contiguous. Image-only results carry an "[image]" placeholder; arrays with other block types keep the stringified form. Chat stream -> Responses stream: reasoning items now emit response.reasoning_summary_part.added and .done around the summary text, and deltas that arrive after a mid-stream finish_reason open a new reasoning or message item instead of appending to the closed one. Closed items are snapshotted so the completed response lists every segment. Closes QuantumNous#7407 Closes QuantumNous#7495 Co-Authored-By: MOON-DREAM-STARS <110315488+MOON-DREAM-STARS@users.noreply.github.com>
timwenx
pushed a commit
to timwenx/new-api
that referenced
this pull request
Nov 18, 2026
…landed in QuantumNous#7512 Co-Authored-By: ByebyDoggy <ByebyDoggy@users.noreply.github.com>
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.
🔗 关联任务 / Related Issue
🚀 变更类型 / Type of change
📝 变更描述 / Description
两处 relaykit 转换器修复,都只改
relaykit/relayconvert/internal/下的代码。1. Claude Messages → Chat:
tool_result图片不再被字符串化(claude_messages/to_oai_chat_req.go)tool_result.content为内容块数组时,此前整体 JSON 序列化进 tool 消息,图片 base64 以文本形式发往上游,既不是视觉输入又按文本计 token。现在:text块换行拼接留在 tool 消息;image块(base64 或 url source)转成image_url,追加到这条 Claude user 消息本身转换出的 user 消息里。该 user 消息天然位于整批 tool 消息之后,并行tool_use的 tool 回复保持连续。[image]占位,避免上游拒绝空内容。text/image之外的块类型(如document)时整体回退到原有字符串化,不丢数据。text块改成 user 消息,[text, tool_use]形态的 assistant 消息行为不变。2. Chat 流 → Responses 流:reasoning summary part 生命周期(
oai_chat/to_oai_responses_stream_resp.go)response.reasoning_summary_part.added(紧随output_item.added)和response.reasoning_summary_part.done(紧随summary_text.done),补齐官方事件序列。finish_reason之后继续下发reasoning_content或content时,不再向已关闭的 item 追加 delta,而是开新 item(_reasoning_1、_msg_1),已关闭 item 快照保留到最终response.completed的output里。fix(relayconvert): keep reasoning summary items active after mid-stream finish_reason / 修复 reasoning summary 在流中途 finish_reason 后失去 active item #7497 只处理了 reasoning,text 也有同样问题,这里一起处理;tool item 本来就按 index 独立,不受影响。_reasoning_0/_msg_0,对现有客户端无变化。不改计费逻辑,不改 Gemini 路径。
📸 运行证明 / Proof of Work
单元测试(relaykit 模块,
GOWORK=off)claude_messages/to_oai_chat_req_test.go:6 种tool_result形态 + 并行 tool_use 的消息顺序。oai_chat/to_oai_responses_resp_test.go新增两个用例:单段流的完整事件序列;reasoning → text → tool_call → finish_reason → reasoning → text → stop两段流的 item 生命周期与最终 output(5 个 item,ID 各不相同)。go test ./...、go vet ./...、go build ./...、gofmt -l通过;golden 测试通过无需更新快照。根模块go vet ./...、go build ./...通过;make test仅controller包的TestSecurityAccountDeletionConcurrentRequestsHaveOneWinner因 SQLite 锁竞争失败一次,单独重跑-count=3通过,与本 PR 无关。本地 live 验证(一次性 new-api 实例 + 捕获代理,Claude 用例走真实 OpenAI 协议上游,reasoning 用例走本地 mock Chat 上游)
Claude 用例:
/v1/messages请求,assistant 为[text, tool_use×2],两个tool_result中一个含 22.5 KB 红色噪点 PNG,渠道为 OpenAI 类型。image_urlscreenshot captured/note.txt: …;末尾 user 消息含image_urlReasoning 用例:本地 mock 上游按固定顺序回放 Chat 分片(网关内没有模型会在 Chat 流里输出
reasoning_content),Advanced Custom 渠道把/v1/responses路由到 mock 的/v1/chat/completions。finish_reason=tool_calls→ reasoning → text → stopround 1round 2), message(callingfinal …), function_callround 1), message(calling), function_call, reasoning(round 2), message(final …)所有用例消费日志 prompt/completion 与上游 usage 一致,用户额度变动等于日志 quota。
未验证 / 附带观察: Claude 流式用例的
message_start预估input_tokens(约 21,950)与最终 213 左右不一致,修复前后相同,来源是message_start使用的本地预估GetEstimatePromptTokens()把tool_result里的图片 base64 当文本计数,属于 #7148 范围,本 PR 未处理。未对真实上游验证「finish_reason 后继续下发 reasoning」形态,该形态来自 #7495 的报告,本 PR 用 mock 回放复现。✅ 提交前检查项 / Checklist
New feature,我已关联对应 Issue;若尚无 Issue,我已先自行创建。go build通过或测试通过,不视为有效证明。Summary by CodeRabbit
New Features
Bug Fixes