Repository navigation
refactor: share tool result to content - #386
Merged
Merged
Conversation
The tool message content the AI SDK's chat converters build from a tool result: the text of a text or error-text output, the denial reason, or JSON.stringify of a JSON or content output. Upstream repeats this switch in each converter; RFC-0046 puts the shared copy in provider-utils. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
Ten converters reached into the OpenAI chat converter for tool_result_to_content and tool_result_content_value. They now call the provider-utils functions and the OpenAI copies are gone; output is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
cunninghamcard-bit
marked this pull request as ready for review
October 28, 2026 00:23
This was referenced Oct 28, 2026
…-result-to-content # Conflicts: # aimux-provider-utils/src/tests/mod.rs
eric8810
reviewed
Oct 28, 2026
eric8810
left a comment
Contributor
There was a problem hiding this comment.
tool result content 转换语义核对通过(text/error-text/execution-denied/json/content parts、file data、providerOptions),新增测试也够。只差 rebase:冲突只在 provider-utils/src/tests/mod.rs,保留 mod tool_result_to_content; 和 mod uint8_utils;,CI 重跑。
…-result-to-content
…-result-to-content # Conflicts: # CHANGELOG.md # aimux-provider-utils/src/lib.rs # aimux-provider-utils/src/tests/mod.rs
Contributor
Author
Generated by Claude Code |
eric8810
approved these changes
Oct 28, 2026
eric8810
left a comment
Contributor
There was a problem hiding this comment.
Rebase 仅保留 union,同步删除未用 FileBytes import;tool_result_to_content 与测试逐字节未变,16/16 CI 通过。Approve。
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.
RFC-0046 R1 的第 8 个小 PR(清单见 #328):把工具结果转内容的两个函数
tool_result_to_content、tool_result_content_value从 OpenAI 的 chat 转换文件挪进aimux-provider-utils,借用它们的 9 家改从 provider-utils 调用。Before:这两个函数是
openai/chat/convert_to_chat_messages.rs里的pub(crate)函数,经openai::convert转出去。Open Responses、xAI、OpenAI 兼容层、Mistral、Groq、DeepSeek、Cohere、Google 都去 OpenAI 的私有文件拿(RFC-0046 §2.2 第一行)。After:两个函数在
aimux_provider_utils公开导出,所有调用点直接用它们,openai::convert不再转出。输出逐字节不变。一、体系现状(概览)
上游没有共享函数,每个转换文件各写一遍同一个
switch:aimux(master 9f9f5ab):
RFC-0046 §3.2 把这一族定为 provider-utils 的通用函数:上游各家重复的是同一段逻辑,Rust 这边已经只有一份,只是放错了地方。
二、本 PR 改动(细节)
Anthropic、Bedrock 的工具结果转换是各自的块格式,上游也是各写各的,不在本 PR 范围。
测试:
src/tests/tool_result_to_content.rs.test.ts;4 条非上游:text/error-text、execution-denied(有无 reason)、json/error-json、content(camelCase 键、二进制按字节下标、url 带 originalUrl)各厂商已有的工具结果用例全部原样通过。工作区测试数不变(4380),provider-utils 另加 4 个。
改动规模:
公开 API 与行为
aimux_provider_utils::tool_result_to_content、aimux_provider_utils::tool_result_content_value。pub(crate),没有 Breaking;行为不变。CHANGELOG 的 Added 一条。检查
cargo fmt --check、scripts/check_provider_boundaries.sh、cargo +1.99 clippy(providers 与 provider-utils,-D warnings)、cargo check --workspace、cargo doc、全部测试均通过。Generated by Claude Code