Repository navigation
RFC-0046: provider 协议的小重构与抽象设计 - #294
Merged
Merged
Conversation
…or reuse (Draft) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
Contributor
Author
|
贡献者意见(li),供维护者决定:
Generated by Claude Code |
Merged
3 tasks done
…tion design Three layers (shared functions, protocol implementations, vendors), closed-enum Config hooks, one-way vendor dependencies, one SigV4 fetch. Unit tests in foo/tests.rs; public-API tests in tests/it/<vendor>/. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
This was referenced Oct 20, 2026
Merged
Each upstream test file maps to one Rust file of the same name under src/<vendor>/tests/, for both direct-call and mock-fetch tests; the crate tests/ directory keeps only cross-vendor tests. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
cunninghamcard-bit
marked this pull request as ready for review
October 20, 2026 10:02
35 of 70 tasks
eric8810
reviewed
Oct 20, 2026
eric8810
left a comment
Contributor
There was a problem hiding this comment.
Review
现状盘点(7 个环、126 个测试二进制、282 个 preset 等)基本准确,但方案有几处会阻碍实现:
- 阻塞 RFC 声称“不改变公开 API”,但 §4.2 把
openai::model、mistral::convert等公开模块改名,下游路径会断;需要兼容 shim 或明确 major 版本。 - 阻塞
TransformRequestBody枚举和现有公开Arc<dyn Fn(Value) -> Value>别名同名,兼容层用户回调无法放进这个枚举;建议换名并保留原 alias。 - 阻塞 枚举 dispatch 从 Anthropic 调
vertex::anthropic::...,又建回 Anthropic→Vertex 的反向边;应把变换放在协议/公共层,或存函数对象。 - 重要 R2 声称解开全部 7 个环,但 Anthropic↔Vertex/AWS 的
AnthropicConfig在 R3 才引入;需要拆分 R2/R3 的边界。 - 重要 RFC-0048 计划把 provider replay 测试放在
aimux-providers/tests/common/replay.rs,但ReplaySession最终在aimux-devtools,与 RFC-0044 分层冲突。 - 次要 两处 SigV4 实际都包同一个
SigV4Fetch,重复的是 UA/鉴权判断;搬移测试 PR 里有环境变量、计数器、临时路径的语义变化,不只是“只搬不改”。
Say which public paths change and how they ship (§4.5), rename the internal rewrite enums so the public TransformRequestBody callback alias stays, and keep the rewrite functions in the protocol directories so no reverse edge appears. Move the AnthropicConfig endpoint into R2 so R2 really breaks all seven cycles, correct the SigV4 duplication, put ReplaySession-based tests in ops, and say that merging tests into one binary shares env vars, counters and temp paths. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
Contributor
Author
|
逐条处理如下,都在 fe5f2f0。左列是 @eric8810 的原话。
Generated by Claude Code |
3 tasks done
eric8810
reviewed
Oct 20, 2026
eric8810
left a comment
Contributor
There was a problem hiding this comment.
复审(fe5f2f07)
之前 7 条里 6 条已实质解决:公开路径改为明确 breaking + §4.5、TransformRequestBody 枚举改名、Anthropic 改写移入协议目录、R2/R3 拆分、replay 测试移到 ops、SigV4/搬移措辞修正。
仍有以下阻塞/重要项:
- 阻塞 公开回调 API 没有落点:
AnthropicAwsProviderSettings.transform_request_body、VertexProviderSettings.transform_request_body、Bedrock、Codex、ElevenLabs、HuggingFace、OpenResponses、Voyage、preset等公开 settings 仍暴露TransformRequestBody;RFC 只给AnthropicConfig一个Option<AnthropicBodyRewrite>,这些用户回调没有迁移路径。需要在 Config 里保留 callback 变体,或在 §4.5 明确删除并登记 breaking。 - 重要 R3 与 R5 重复:R3 已说
AnthropicConfig补齐 URL/请求体改写字段,R5 又说“Config 钩子改成枚举”。请明确 R3 只加字段、R5 再换枚举,或合并两步。 - 重要 V5 仍写“逻辑在厂商目录的普通函数里”,与 §3.5 的“协议目录、协议目录不 use 厂商”矛盾。
- 重要 §3.2 删除
with_user_agent_suffix_fn和without_trailing_slash_opt,两者都是 provider-utils 的公开 API;需要登记 breaking/deprecation。 - 次要 §4.5 说 crate root 导出不变,但
replay按 C6 移出、provider-utils 公开函数删除;请把范围限定到 R7 或列出例外。 - 次要 §3.5 的 Rust 代码块结尾 ``` 和“端点解析…”写在同一行,CommonMark 不会正确闭合。
- 提示 基线写
5743a40a,但 55 个pub mod计数引用的是c0622ea4。
Lists the ten public settings that take a transform_request_body callback and where each lands; internal rewrites move to a separate body_rewrite field so the user callbacks keep their field; R3 adds the Anthropic enums directly and R5 is only the compatible-layer rewrites; V5 says the rewrite code lives in protocol directories; the two public provider-utils functions removed in R1 and the replay move are registered in 4.5; closes the 3.5 code fence; recounts the 55 public modules at the baseline. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
Contributor
Author
|
第二轮复审(review 5586872163)逐条处理,改动在 5165bf2。下表左列是 eric 的原话(摘要),每条都在 master@
顺带:全文的 file:line 在基线上又核对了一遍,§3.6 里 Generated by Claude Code |
eric8810
approved these changes
Oct 21, 2026
eric8810
left a comment
Contributor
There was a problem hiding this comment.
复审通过。10 个公开 transform_request_body 的落点、R3/R5 边界、V5、provider-utils 公开 API 的破坏性登记、§4.5 范围、代码围栏和基线都已修正。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.
Summary
新增
rfc/0046-provider-protocol-abstraction.md,只有这一个文件,不改代码。aimux-providers里同一种协议有多份实现,厂商之间互相去对方的私有文件拿函数,形成 7 个环。本文做一次小重构并定下抽象:通用函数进aimux-provider-utils,每种协议一份实现(模型 +XxxConfig),厂商只剩工厂、Config 取值和 Fetch 层鉴权;托管变体只换 Config,经对方的internal入口单向依赖,CI 禁止新的环。目录、文件名和测试位置随之整理。wire 行为不变;厂商模块根的导出和公开设置不变,但厂商目录里现在公开的 55 个子模块路径会变,provider-utils 删两个只有测试在用的公开函数(§4.5)。crate 怎么拆见 RFC-0044(#279),两份互不依赖。实施进度(R1–R7 和各厂商搬移)在 #328 跟踪。
一、体系现状(概览,master
5743a40a)协议实现和谁在用(48 个厂商实现)
openai/、openai_compatible/@ai-sdk/openai、@ai-sdk/openai-compatible,Groq 等是独立包openai/responses/open_responses.rs、xai/responses/、huggingface/responses.rs各一份anthropic/@ai-sdk/anthropic/internalgoogle/@ai-sdk/google-vertex复用@ai-sdk/google的模型bedrock/@ai-sdk/amazon-bedrock基础厂商的一次调用(Mistral,右侧是去向)
上游
@ai-sdk/mistral只依赖@ai-sdk/provider和@ai-sdk/provider-utils,工具结果在convert-to-mistral-chat-messages.ts:167自己转换。托管变体的一次调用(Vertex 上的 Claude)
上游托管变体走基础厂商的
/internal入口,基础厂商不认识变体:amazon-bedrock/src/anthropic/amazon-bedrock-anthropic-provider.ts:17从@ai-sdk/anthropic/internal取模型。用户请求体回调:10 个公开设置有
transform_request_body: Option<TransformRequestBody>(兼容层照上游,另外 9 个是 aimux 扩展)。Anthropic 现在把内部改写和用户回调串在一起:目录与测试:
aimux-providers/src三种目录形态混用,文件用通用名(model.rs、convert.rs),对不上上游文件;测试在tests/下 126 个独立测试程序。二、本 PR 改动(细节)
1. 三层
2. 改完后的三条调用
3. Config 钩子
厂商之间内部用的请求体改写、请求 URL 改成每种协议一个封闭枚举(
AnthropicBodyRewrite、AnthropicRequestUrl、CompatibleBodyRewrite),放在单独的body_rewrite、build_request_url字段;枚举和改写函数都在协议目录(anthropic/request_rewrite.rs等),托管变体只选变体,不形成反向边。10 个公开设置里的用户回调保留,进协议 Config 的transform_request_body,先跑内部改写、再跑用户回调,和现在的顺序一样;公开别名TransformRequestBody(shared/mod.rs:75)不改名。把用户回调也删掉是 §9 的备选。4. SigV4
5. 测试位置
搬移 PR 不改断言、不删测试,前后比较
cargo test -p aimux-providers -- --list的数量;测试并进同一个程序后环境变量、全局计数器、临时路径变成共享,每个搬移 PR 的描述列出本家涉及哪些。6. 公开路径
厂商目录里的 55 个
pub mod(openai 14、anthropic 11、google 9 …)按上游改名或收为私有,算破坏性变更,随下一个 minor 版本发布,每个搬移 PR 在 CHANGELOG 列出本家的旧路径和替代入口;留#[deprecated]过渡模块的做法是 §9 的待讨论项。例外两处:R1 删 provider-utils 的with_user_agent_suffix_fn、without_trailing_slash_opt,同样登记为破坏性变更;replay按 RFC-0044 C6 移到 ops,由那份 RFC 登记。步骤
endpoint的AnthropicConfig),加internal模块和 CI 检查AnthropicConfig补齐其余字段,URL 和内部改写直接用枚举,用户回调单独一个字段;Anthropic AWS、Vertex Claude 改用它;两个 SigV4 外层合并GoogleConfig(行为修正)body_rewritelayout.toml,按厂商家族分批,Mistral 先做样例Type of change
Checklist
rfc/)纯文档,cargo 检查不受影响。
Notes for reviewers
0046-provider-layout-and-reuse.md改名,标题改成“provider 协议的小重构与抽象设计”,目录和测试位置变成其中两节。tests/目录(§5),原来的foo/tests.rs加tests/it/不再用。body_rewrite字段;R3 直接用枚举,R5 只剩兼容层;V5 改正;provider-utils 两个公开函数和replay在 §4.5 登记;代码块闭合;55 个pub mod在基线上重数;全文行号在基线上重新核对。layout.toml和测试位置)、RFC-0048(RFC-0048: 录制 schema 3 与传输回放 #325)、Provider 构造与配置:迁移后遗留缺口 #275、Core 运行时:与 AI SDK 的剩余差距(对齐文档 §9.1 已知差距) #276、测试:补迁上游 AI SDK 测试(按用例名约 18% 对上) #278。🤖 Generated with Claude Code
https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW