feat(bedrock): 新增 Amazon Bedrock 供应商支持(双鉴权路径 + 评审修复)#1374
Open
yourlin wants to merge 4 commits into
Open
Conversation
支持双鉴权路径(Bedrock API Key / AWS Profile SSO),前后端各自实现 生成与识别端并通过 property test 保证契约;同时把评审中提出的 10 项 问题(P0/P1/P2/P3)一并修复。 主要改动: - 生成端:complete_bedrock_bearer_token_config / complete_bedrock_aws_profile_config - 识别端:bedrock_config_from_config_text(Rust/TS 双端保持契约一致) - 前端:BedrockRelayProfileEditor(名称、Provider 标识符、Region、 API Key、IAM 用户名、AWS Profile 等字段),并提供 Long-Term / Short-Term Key 与 AWS SSO 的 CLI 命令示例 - 供应商预设:ProviderPresetSelector 里 Bedrock 入口归入「第三方」 分组、排在 Azure OpenAI 前面;搜索命中 aws / bedrock / amazon 时 也可见 - 常量:BEDROCK_MANTLE_URL_PREFIX / SUFFIX 提取给 Rust/TS 两端参照 - 测试:proptest 覆盖 10 条属性 + regression 覆盖脏字段残留 / 表段感知 / 保留字冲突去重 / 天数校验 评审修复清单: - P0-1 保留字冲突时 inline 与底部错误提示去重 - P0-2 bedrockValidationError 注释与实现对齐 - P1-3 ensure_root_scalars_precede_tables 加入表段感知,忽略注释行 - P1-4 tomlStringAssignment / Bool 对 key 做 escapeRegExp - P2-5 Bearer Token 分支改为整表替换,避免同名旧 provider 表脏字段残留 - P2-6 BEDROCK_MANTLE_URL_PREFIX / SUFFIX 提取常量,Rust/TS 同步 - P3-7 IAM 用户名字段 label 精简,长括号说明改到 field-hint - P3-8 bedrockLongTermApiKeyCommand 拒绝非法天数(fallback 90) - P3-9 require_non_empty label 统一中文("AWS 区域") - UI 补齐:Bedrock 编辑器新增「名称」字段,修复无法改名的问题
relay_switch.switch_relay_profile_in_home 之前依赖 BedrockConfig.auth_mode
== AwsProfile 显式绕过 configured 检查——把针对单一供应商的耦合塞进了
通用切换器。改为在 relay_config_status_from_home 内部完成通用兜底:只要
config.toml 中存在与顶层 model_provider 对应的 [model_providers.<id>]
或 [model_providers.<id>.<sub>] 表段,即视为 configured;OpenAI 兼容的
requires_openai_auth + base_url + Bearer/API Key 严格校验路径保留不变。
- 抽出 has_model_provider_section 私有 helper,识别 provider 直接表段
与任意子表段(例如 Amazon Bedrock AWS Profile 的
[model_providers.amazon-bedrock.aws])
- relay_switch.rs 移除 BedrockAuthMode/LaunchMode 引用与
is_bedrock_aws_profile 分支;同时跟随上游 v1.2.33 删除
launch_mode_for_relay_profile(切换 profile 时不再强制覆盖 launch_mode)
- 新增两条集成测试:
* reports_native_provider_configured_via_child_table_only 覆盖
Bedrock AWS Profile 形态
* reports_not_configured_when_provider_section_missing 防止过度放宽兜底
Bedrock 数据模型 (BedrockConfig / BedrockAuthMode) 仍保留在 settings.rs
与 relay_config.rs 的生成分支,属于 Bedrock 内部实现细节;relay_switch
不再感知具体供应商。未来新增仅使用子表段的原生 provider(Vertex、
SageMaker 等)无需再改 relay_switch。
sim: BigPizzaV3#1374
同步 upstream/main (23bbf13) 到本 fork。关键上游变更: - upstream 已删除 relay_switch.rs 里的 launch_mode_for_relay_profile - upstream 引入 relay_environment / relay_latency 等新模块 - upstream 引入 model_catalog 相关修复、桌宠、V2 广告回退等改动 Bedrock 相关代码(BedrockConfig、Bedrock 编辑器、双路径生成)与 upstream 新增功能均沿各自模块保留,通过 relay_config_status_from_home 的通用化 兜底解耦,不再对 relay_switch 造成耦合。 sim: BigPizzaV3#1374
Bedrock 编辑器此前把"会写入 config.toml 的字段"与"仅用于拼接 CLI 示例 命令的参数"混排在一起,容易让用户误以为示例区里的输入也会影响配置。 本次按语义重排两条鉴权路径的字段布局: - 新增带说明文字的分隔线(BedrockCliExamplesDivider):横线中间标注 "以下为命令行生成示例,不影响实际配置",把配置区与示例区视觉隔开 - 模型(model)会写入 config.toml,归入配置区,移到分隔线上方 - IAM 用户名 / Long-Term Key 有效期仅作为 bedrockLongTermApiKeyCommand 的 --user-name / --credential-age-days 参数,不参与 config 生成,移到 分隔线下方的示例区,并补 field-hint 明确"不写入配置" - AWS Profile 分支同样把 AWS SSO 命令示例收到分隔线下方 纯 UI 布局调整,不改变数据流:所有字段仍绑定原有 bedrock.* 状态并照常 持久化到 settings.json。styles.css 新增 .bedrock-cli-divider 伪元素横线 样式,深浅色主题均适配。 验证:tsc --noEmit 干净;前端 node --test 全通过;npm run build (cargo release + tauri build)成功。 sim: BigPizzaV3#1374
Author
|
已经合并了最新的代码,无冲突 |
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.
摘要
新增 Amazon Bedrock 供应商,支持 Bedrock API Key (Bearer Token) 与 AWS Profile (SSO) 双鉴权路径。前后端各自实现生成与识别端并通过 property test 保证契约。同时把代码评审中提出的 10 项问题(P0/P1/P2/P3)一并修复。
主要改动
后端(Rust /
codex-plus-core)complete_bedrock_bearer_token_config/complete_bedrock_aws_profile_configbedrock_config_from_config_text(与 TS 端保持契约一致)RelayProfile.bedrock: Option<BedrockConfig>,包含auth_mode/provider_id/region/aws_profile/iam_user_name/iam_key_validity_days六个字段;bedrock: None不序列化(旧 settings.json 落盘格式不变)relay_switch里对 AWS Profile 模式跳过configured检查,避免把合法配置误判为"未检测到完整 custom provider"BEDROCK_MANTLE_URL_PREFIX/BEDROCK_MANTLE_URL_SUFFIX提取到模块顶部,供生成端与识别端共同引用前端(TypeScript / Tauri manager)
BedrockRelayProfileEditor:名称、Provider 标识符、Region、API Key、IAM 用户名、AWS Profile 等字段;提供 Long-Term / Short-Term Key 与 AWS SSO 的 CLI 命令示例ProviderPresetSelector:Bedrock 入口归入「第三方」分组,排在 Azure OpenAI 前面;搜索命中aws/bedrock/amazon时也可见bedrock-config.ts:与 Rust 契约对齐的解析/校验/命令生成纯函数测试
proptest覆盖 10 条属性(Bearer Token / AWS Profile 生成正确性、region 必填、保留字冲突、Base URL 一致性、生成 → 识别往返 等)bedrock-config.test.ts/BedrockRelayProfileEditor.test.ts/ProviderPresetSelector.test.ts用 Node--test+ fast-check 属性测试代码评审修复(P0/P1/P2/P3)
bedrockValidationErrorForBottom)bedrockValidationError注释与实现对齐ensure_root_scalars_precede_tables加入表段感知,忽略注释行;同步 property test 生成器tomlStringAssignment/tomlBoolAssignment对 key 做escapeRegExpenv_key/http_headers等杂字段残留BEDROCK_MANTLE_URL_PREFIX/SUFFIX提取常量,Rust / TS 双端同步field-hintbedrockLongTermApiKeyCommand拒绝非法天数(非正整数、前导零、字母、负号统一 fallback 到90)require_non_empty调用点 label 统一为中文("AWS 区域"),消除"region 不能为空"半中半英验证
cargo test -p codex-plus-core --lib:125/125 通过(含 8 property + 3 新增 regression)cargo test -p codex-plus-core --test relay_switch --test launcher:60/60 通过(含 Bedrock Bearer Token / AWS Profile 两条完整写入路径的集成测试)node --test --experimental-strip-types src/**/*.test.ts:56/56 通过tsc --noEmit:干净npm run build:完整 release 构建通过(Vite +cargo build --release)openai/amazon-bedrock等)只在 Provider ID 下方展示 inline 红字,底部不再重复abc/-5/090均 fallback 到90~/.codex/config.toml生成的[model_providers.*]段落干净、无脏字段残留已知限制 / 备注
tauri.conf.json里bundle.active = false,本 PR 不涉及.app/.dmg打包变化。i18n-en.ts未为本次新增中文串补翻译,沿用项目现状:t()找不到映射时回落到原文。tests/installers.rs有 3 项 bundle 命名相关的失败是仓库既存问题(本 PR 前后一致,与本次改动无关)。BEDROCK_MANTLE_URL_PREFIX/SUFFIX仍需 Rust / TS 两端手动同步;若未来 endpoint 模板改变,两处需同时更新。