Repository navigation
refactor: share provider credentials and user agent - #388
cunninghamcard-bit wants to merge 9 commits into
Conversation
Credential, AuthScheme and ProviderHeaders describe a provider's request headers as data and resolve them per request, the way each AI SDK package's getHeaders combines loadApiKey, its fixed headers, the user's headers and withUserAgentSuffix. UserAgentFetch and transport_user_agent make the user-agent edits of the AI SDK AWS transports. They move here from aimux-providers' shared module (RFC-0046 R1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
Every provider imports Credential, AuthScheme, ProviderHeaders, UserAgentFetch and transport_user_agent from provider-utils; the shared copies are gone. Headers are 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
…ider-credentials-and-user-agent # Conflicts: # aimux-provider-utils/src/tests/mod.rs
eric8810
left a comment
There was a problem hiding this comment.
credential/header/UA 的优先级和 redaction 都核对通过,61 处只是路径改动,4 个新测试覆盖完整。只差 rebase:冲突只在 provider-utils/src/tests/mod.rs,保留 master 的三个模块 + mod provider_headers;,CI 重跑。
…ider-credentials-and-user-agent # Conflicts: # aimux-providers/src/azure/openai_provider.rs # aimux-providers/src/openai/config.rs # aimux-providers/src/vertex/anthropic/anthropic_provider.rs
…ider-credentials-and-user-agent # Conflicts: # CHANGELOG.md # aimux-provider-utils/src/tests/mod.rs
Generated by Claude Code |
eric8810
left a comment
There was a problem hiding this comment.
仅 rebase + union;credential/header/UA 优先级和脱敏未变,16/16 CI 通过。Approve。
…ider-credentials-and-user-agent # Conflicts: # CHANGELOG.md # aimux-providers/src/anthropic_aws/provider.rs # aimux-providers/src/decision_support.rs # aimux-providers/src/vertex/anthropic/anthropic_provider.rs
…ider-credentials-and-user-agent # Conflicts: # aimux-provider-utils/src/tests/mod.rs
|
合上 master 到
本地 Generated by Claude Code |
eric8810
left a comment
There was a problem hiding this comment.
Rebase verified content-preserving; CI 16/16; re-approve current head.
…ider-credentials-and-user-agent
eric8810
left a comment
There was a problem hiding this comment.
Rebase 内容没丢,但和 #395 语义冲突:aimux-providers/src/openai_compatible/tests/request_rewrite.rs:11 仍 import crate::shared::{AuthScheme, Credential, ProviderHeaders},这些已搬进 aimux-provider-utils,Rust core clippy 直接 E0432。把该 import 改成 aimux_provider_utils::{...}(或对应 re-export),重跑 CI 即可。
RFC-0046 R1 的第 10 个小 PR,也是 R1 清单的最后一项(见 #328):把凭据与请求头组装(
Credential、AuthScheme、ProviderHeaders)和 UA 改写(UserAgentFetch、transport_user_agent)从aimux-providers/src/shared/mod.rs挪进aimux-provider-utils。Before:这五个是 providers 里
shared模块的pub(crate)项,约 60 个厂商文件从crate::shared引入。它们只依赖 provider-utils 里已有的load_api_key、Resolvable、combine_headers、normalize_headers、with_user_agent_suffix、Fetch。After:五个都在
aimux_provider_utils公开导出,厂商改从这里引入。shared/mod.rs只剩package_fetch(它读 providers 自己的aisdk_pins,留在原处)和TransformRequestBody。请求头逐字节不变。一、体系现状(概览)
上游没有共享的请求头类型,每个包在工厂里写一个
getHeaders:aimux(master 9f9f5ab):
RFC-0046 §3.2 把“凭据、UA 组装”定为 provider-utils 的通用函数。
二、本 PR 改动(细节)
搬过去的代码只多了 clippy pedantic 对公开函数要求的
#[must_use]和# Errors说明,逻辑一字未改。上游没有同名类型,名字沿用。测试:
src/tests/provider_headers.rs.test.ts;4 条非上游:三种凭据方案与Credential::None、用户头覆盖或删除(不分大小写)且 UA 后缀最后追加、Env与OptionalEnv读不到环境变量时的区别、transport_user_agent改写ai-sdk-provider-utils/<v>并追加后缀各厂商已有的请求头、UA 用例全部原样通过。工作区测试数不变(4380),provider-utils 另加 4 个。
改动规模:
providers 那 61 个文件里绝大多数只改一行
use。公开 API 与行为
aimux_provider_utils::{Credential, AuthScheme, ProviderHeaders, UserAgentFetch, transport_user_agent}。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