Files
cc-switch/tests/config/claudeProviderPresets.test.ts
T
Keith Yu 8ea9638b9d feat: Add AWS Bedrock Provider Support (AKSK & API Key) (#1047)
* Add AWS Bedrock provider integration design document

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add AWS Bedrock provider implementation plan

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Update implementation plan: add OpenCode Bedrock support

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add cloud_provider category to ProviderCategory type

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add AWS Bedrock (AKSK) Claude Code provider preset with tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add AWS Bedrock (API Key) Claude Code provider preset with tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add AWS Bedrock OpenCode provider preset with @ai-sdk/amazon-bedrock

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* docs: add AWS Bedrock provider feature summary for PR

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore: remove internal planning documents

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* docs: add AWS Bedrock support to README (EN/ZH/JA)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add AWS Bedrock UI merge design document

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add AWS Bedrock UI merge implementation plan

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: skip optional template values in validation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: support isSecret template fields and hide base URL for Bedrock

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add Bedrock validation, cleanup, and isBedrock prop in ProviderForm

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: extend TemplateValueConfig and merge Bedrock presets

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: mask Bedrock API Key as secret and support GovCloud regions

- Add isSecret: true to BEDROCK_API_KEY template value
- Update region regex to support multi-segment regions (us-gov-west-1)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* style: replace AWS icon with updated logo

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* style: replace AWS icon with updated logo

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* style: replace AWS icon with new PNG image

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: address code review findings

- Fix AWS icon: use SVG with embedded <image> instead of raw <img> tag
- Hide duplicate ApiKeySection for Bedrock (auth via template fields only)
- Guard settingsConfig cleanup against unresolved template placeholders

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore: remove planning documents

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: address PR review - split Bedrock into two presets, restore SVG icon

Based on maintainer review feedback on PR #1047:

1. Split merged "AWS Bedrock" back into two separate presets:
   - "AWS Bedrock (AKSK)": uses AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY
   - "AWS Bedrock (API Key)": uses top-level apiKey field via standard UI input

2. Restore aws.svg to pure vector SVG (was PNG-in-SVG)

3. Remove all Bedrock-specific logic from shared components:
   - Remove isBedrock prop from ClaudeFormFields
   - Remove Bedrock validation/cleanup blocks from ProviderForm
   - Remove optional/isSecret from TemplateValueConfig
   - Remove optional skip from useTemplateValues

4. Add cloud_provider category handling:
   - Skip API Key/Base URL required validation
   - Hide Speed Test and Base URL for cloud_provider
   - Hide API format selector for cloud_provider (always Anthropic)
   - Show API Key input only when config has apiKey field

5. Fix providerConfigUtils to support top-level apiKey:
   - getApiKeyFromConfig: check config.apiKey before env fields
   - setApiKeyInConfig: write to config.apiKey when present
   - hasApiKeyField: detect top-level apiKey property

6. Add OpenClaw Bedrock preset (bedrock-converse-stream protocol)

7. Update model IDs:
   - Sonnet: global.anthropic.claude-sonnet-4-6
   - Opus: global.anthropic.claude-opus-4-6-v1
   - Haiku: global.anthropic.claude-haiku-4-5-20251001-v1:0

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(test): align Bedrock API Key test assertions with preset implementation

The API Key preset was refactored to use standard UI input (apiKey: "")
instead of template variables, but the tests were not updated accordingly.

---------

Co-authored-by: root <root@ip-10-0-11-189.ap-northeast-1.compute.internal>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Jason <farion1231@gmail.com>
2026-02-24 21:11:18 +08:00

79 lines
2.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { providerPresets } from "@/config/claudeProviderPresets";
describe("AWS Bedrock Provider Presets", () => {
const bedrockAksk = providerPresets.find(
(p) => p.name === "AWS Bedrock (AKSK)",
);
it("should include AWS Bedrock (AKSK) preset", () => {
expect(bedrockAksk).toBeDefined();
});
it("AKSK preset should have required AWS env variables", () => {
const env = (bedrockAksk!.settingsConfig as any).env;
expect(env).toHaveProperty("AWS_ACCESS_KEY_ID");
expect(env).toHaveProperty("AWS_SECRET_ACCESS_KEY");
expect(env).toHaveProperty("AWS_REGION");
expect(env).toHaveProperty("CLAUDE_CODE_USE_BEDROCK", "1");
});
it("AKSK preset should have template values for AWS credentials", () => {
expect(bedrockAksk!.templateValues).toBeDefined();
expect(bedrockAksk!.templateValues!.AWS_ACCESS_KEY_ID).toBeDefined();
expect(bedrockAksk!.templateValues!.AWS_SECRET_ACCESS_KEY).toBeDefined();
expect(bedrockAksk!.templateValues!.AWS_REGION).toBeDefined();
expect(bedrockAksk!.templateValues!.AWS_REGION.editorValue).toBe(
"us-west-2",
);
});
it("AKSK preset should have correct base URL template", () => {
const env = (bedrockAksk!.settingsConfig as any).env;
expect(env.ANTHROPIC_BASE_URL).toContain("bedrock-runtime");
expect(env.ANTHROPIC_BASE_URL).toContain("${AWS_REGION}");
});
it("AKSK preset should have cloud_provider category", () => {
expect(bedrockAksk!.category).toBe("cloud_provider");
});
it("AKSK preset should have Bedrock model as default", () => {
const env = (bedrockAksk!.settingsConfig as any).env;
expect(env.ANTHROPIC_MODEL).toContain("anthropic.claude");
});
const bedrockApiKey = providerPresets.find(
(p) => p.name === "AWS Bedrock (API Key)",
);
it("should include AWS Bedrock (API Key) preset", () => {
expect(bedrockApiKey).toBeDefined();
});
it("API Key preset should have apiKey field and AWS env variables", () => {
const config = bedrockApiKey!.settingsConfig as any;
expect(config).toHaveProperty("apiKey", "");
expect(config.env).toHaveProperty("AWS_REGION");
expect(config.env).toHaveProperty("CLAUDE_CODE_USE_BEDROCK", "1");
});
it("API Key preset should NOT have AKSK env variables", () => {
const env = (bedrockApiKey!.settingsConfig as any).env;
expect(env).not.toHaveProperty("AWS_ACCESS_KEY_ID");
expect(env).not.toHaveProperty("AWS_SECRET_ACCESS_KEY");
});
it("API Key preset should have template values for region only", () => {
expect(bedrockApiKey!.templateValues).toBeDefined();
expect(bedrockApiKey!.templateValues!.AWS_REGION).toBeDefined();
expect(bedrockApiKey!.templateValues!.AWS_REGION.editorValue).toBe(
"us-west-2",
);
});
it("API Key preset should have cloud_provider category", () => {
expect(bedrockApiKey!.category).toBe("cloud_provider");
});
});