From 1eaeb1812dca1b77df2bb9dd0cd0ebc1d6c36d1e Mon Sep 17 00:00:00 2001 From: AJ Juaire <46756248+ajjuaire@users.noreply.github.com> Date: Tue, 7 Oct 2025 11:49:09 -0700 Subject: [PATCH] Add Bedrock global and jp inference profile support. (#6666) * Add Bedrock global and jp inference profile support. * Update package-lock.json after merging latest main Regenerated package-lock.json to reflect the latest dependency changes from the merged main branch updates. * Revert "Update package-lock.json after merging latest main" This reverts commit 2fa79acd383bd0e3b589a7137974f3ce2d295316. --- .changeset/plain-carrots-slide.md | 5 + proto/cline/models.proto | 1 + proto/cline/state.proto | 1 + src/core/api/index.ts | 1 + .../api/providers/__tests__/bedrock.test.ts | 210 +++++++++++------- src/core/api/providers/bedrock.ts | 11 + src/core/storage/StateManager.ts | 3 + src/core/storage/state-keys.ts | 1 + src/core/storage/utils/state-helpers.ts | 3 + src/shared/api.ts | 5 + .../models/api-configuration-conversion.ts | 2 + .../settings/providers/BedrockProvider.tsx | 11 + 12 files changed, 169 insertions(+), 85 deletions(-) create mode 100644 .changeset/plain-carrots-slide.md diff --git a/.changeset/plain-carrots-slide.md b/.changeset/plain-carrots-slide.md new file mode 100644 index 00000000..02fdc926 --- /dev/null +++ b/.changeset/plain-carrots-slide.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +Add JP and Global inference profile options to Cline diff --git a/proto/cline/models.proto b/proto/cline/models.proto index 9f8bd797..45b6deb2 100644 --- a/proto/cline/models.proto +++ b/proto/cline/models.proto @@ -326,6 +326,7 @@ message ModelsApiConfiguration { optional string oca_api_key = 74; optional string oca_refresh_token = 75; optional string oca_mode = 76; + optional bool aws_use_global_inference = 77; // Plan mode configurations optional ApiProvider plan_mode_api_provider = 100; diff --git a/proto/cline/state.proto b/proto/cline/state.proto index 0b468eeb..f64df950 100644 --- a/proto/cline/state.proto +++ b/proto/cline/state.proto @@ -225,6 +225,7 @@ message ApiConfiguration { optional string oca_api_key = 67; optional string oca_refresh_token = 68; optional string oca_mode = 69; + optional bool aws_use_global_inference = 70; // Plan mode configurations optional ApiProvider plan_mode_api_provider = 100; diff --git a/src/core/api/index.ts b/src/core/api/index.ts index 259363d5..e4ac3dbb 100644 --- a/src/core/api/index.ts +++ b/src/core/api/index.ts @@ -102,6 +102,7 @@ function createHandlerForProvider( awsAuthentication: options.awsAuthentication, awsBedrockApiKey: options.awsBedrockApiKey, awsUseCrossRegionInference: options.awsUseCrossRegionInference, + awsUseGlobalInference: options.awsUseGlobalInference, awsBedrockUsePromptCache: options.awsBedrockUsePromptCache, awsUseProfile: options.awsUseProfile, awsProfile: options.awsProfile, diff --git a/src/core/api/providers/__tests__/bedrock.test.ts b/src/core/api/providers/__tests__/bedrock.test.ts index 43e1c26d..4255b9de 100644 --- a/src/core/api/providers/__tests__/bedrock.test.ts +++ b/src/core/api/providers/__tests__/bedrock.test.ts @@ -213,6 +213,7 @@ describe("AwsBedrockHandler", () => { awsBedrockApiKey: "", awsBedrockUsePromptCache: false, awsUseCrossRegionInference: false, + awsUseGlobalInference: false, awsBedrockEndpoint: "", awsBedrockCustomSelected: false, awsBedrockCustomModelBaseId: undefined, @@ -612,102 +613,141 @@ describe("AwsBedrockHandler", () => { }) }) - // TODO: Re-enable or remove these tests. - // describe("getModelId", () => { - // it("should return raw model ID for custom models", async () => { - // const customOptions: ApiHandlerOptions = { - // ...mockOptions, - // actModeAwsBedrockCustomSelected: true, - // actModeApiModelId: - // "arn:aws:bedrock:us-west-2:123456789012:custom-model/anthropic.claude-3-5-sonnet-20241022-v2:0/Qk8MMyLmRd", - // } - // const customHandler = new AwsBedrockHandler(customOptions) + describe("getModelId", () => { + it("should return raw model ID for custom models", async () => { + const customOptions: AwsBedrockHandlerOptions = { + ...mockOptions, + awsBedrockCustomSelected: true, + apiModelId: + "arn:aws:bedrock:us-west-2:123456789012:custom-model/anthropic.claude-3-5-sonnet-20241022-v2:0/Qk8MMyLmRd", + } + const customHandler = new AwsBedrockHandler(customOptions) - // const modelId = await customHandler.getModelId() - // modelId.should.equal( - // "arn:aws:bedrock:us-west-2:123456789012:custom-model/anthropic.claude-3-5-sonnet-20241022-v2:0/Qk8MMyLmRd", - // ) - // }) + const modelId = await customHandler.getModelId() + modelId.should.equal( + "arn:aws:bedrock:us-west-2:123456789012:custom-model/anthropic.claude-3-5-sonnet-20241022-v2:0/Qk8MMyLmRd", + ) + }) - // it("should not encode custom model IDs with slashes", async () => { - // const customOptions: ApiHandlerOptions = { - // ...mockOptions, - // actModeAwsBedrockCustomSelected: true, - // actModeApiModelId: "my-namespace/my-custom-model", - // } - // const customHandler = new AwsBedrockHandler(customOptions) + it("should not encode custom model IDs with slashes", async () => { + const customOptions: AwsBedrockHandlerOptions = { + ...mockOptions, + awsBedrockCustomSelected: true, + apiModelId: "my-namespace/my-custom-model", + } + const customHandler = new AwsBedrockHandler(customOptions) - // const modelId = await customHandler.getModelId() - // modelId.should.equal("my-namespace/my-custom-model") - // modelId.should.not.match(/%2F/) - // }) + const modelId = await customHandler.getModelId() + modelId.should.equal("my-namespace/my-custom-model") + modelId.should.not.match(/%2F/) + }) - // it("should apply cross-region prefix for non-custom models when enabled", async () => { - // const crossRegionOptions: ApiHandlerOptions = { - // ...mockOptions, - // awsUseCrossRegionInference: true, - // awsRegion: "us-west-2", - // } - // const crossRegionHandler = new AwsBedrockHandler(crossRegionOptions) + it("should apply cross-region prefix for non-custom models when enabled", async () => { + const crossRegionOptions: AwsBedrockHandlerOptions = { + ...mockOptions, + awsUseCrossRegionInference: true, + awsRegion: "us-west-2", + } + const crossRegionHandler = new AwsBedrockHandler(crossRegionOptions) - // const modelId = await crossRegionHandler.getModelId() - // modelId.should.equal("us.anthropic.claude-3-7-sonnet-20250219-v1:0") - // }) + const modelId = await crossRegionHandler.getModelId() + modelId.should.equal("us.anthropic.claude-3-7-sonnet-20250219-v1:0") + }) - // it("should apply EU cross-region prefix", async () => { - // const euOptions: ApiHandlerOptions = { - // ...mockOptions, - // awsUseCrossRegionInference: true, - // awsRegion: "eu-central-1", - // } - // const euHandler = new AwsBedrockHandler(euOptions) + it("should apply EU cross-region prefix", async () => { + const euOptions: AwsBedrockHandlerOptions = { + ...mockOptions, + awsUseCrossRegionInference: true, + awsRegion: "eu-central-1", + } + const euHandler = new AwsBedrockHandler(euOptions) - // const modelId = await euHandler.getModelId() - // modelId.should.equal("eu.anthropic.claude-3-7-sonnet-20250219-v1:0") - // }) + const modelId = await euHandler.getModelId() + modelId.should.equal("eu.anthropic.claude-3-7-sonnet-20250219-v1:0") + }) - // it("should apply APAC cross-region prefix", async () => { - // const apacOptions: ApiHandlerOptions = { - // ...mockOptions, - // awsUseCrossRegionInference: true, - // awsRegion: "ap-northeast-1", - // } - // const apacHandler = new AwsBedrockHandler(apacOptions) + it("should apply JP cross-region prefix for sonnet 4.5", async () => { + const jpOptions: AwsBedrockHandlerOptions = { + ...mockOptions, + awsUseCrossRegionInference: true, + apiModelId: "anthropic.claude-sonnet-4-5-20250929-v1:0", + awsRegion: "ap-northeast-1", + } + const jpHandler = new AwsBedrockHandler(jpOptions) - // const modelId = await apacHandler.getModelId() - // modelId.should.equal("apac.anthropic.claude-3-7-sonnet-20250219-v1:0") - // }) + const modelId = await jpHandler.getModelId() + modelId.should.equal("jp.anthropic.claude-sonnet-4-5-20250929-v1:0") + }) - // it("should not apply cross-region prefix for custom models even when enabled", async () => { - // const customCrossRegionOptions: ApiHandlerOptions = { - // ...mockOptions, - // actModeAwsBedrockCustomSelected: true, - // actModeApiModelId: "arn:aws:bedrock:us-west-2:123456789012:custom-model/my-model", - // awsUseCrossRegionInference: true, - // } - // const customCrossRegionHandler = new AwsBedrockHandler(customCrossRegionOptions) + it("should apply global cross-region prefix for supported models", async () => { + const globalOptions: AwsBedrockHandlerOptions = { + ...mockOptions, + awsUseCrossRegionInference: true, + awsUseGlobalInference: true, + apiModelId: "anthropic.claude-sonnet-4-5-20250929-v1:0", + awsRegion: "ap-northeast-1", + } + const globalHandler = new AwsBedrockHandler(globalOptions) - // const modelId = await customCrossRegionHandler.getModelId() - // modelId.should.equal("arn:aws:bedrock:us-west-2:123456789012:custom-model/my-model") - // }) + const modelId = await globalHandler.getModelId() + modelId.should.equal("global.anthropic.claude-sonnet-4-5-20250929-v1:0") + }) - // it("should handle UltraThink model ARN correctly", async () => { - // const ultraThinkOptions: ApiHandlerOptions = { - // ...mockOptions, - // actModeAwsBedrockCustomSelected: true, - // actModeApiModelId: - // "arn:aws:bedrock:us-west-2:123456789012:custom-model/anthropic.claude-3-5-sonnet-20241022-v2:0/Qk8MMyLmRd", - // actModeAwsBedrockCustomModelBaseId: "anthropic.claude-3-5-sonnet-20241022-v2:0", - // } - // const ultraThinkHandler = new AwsBedrockHandler(ultraThinkOptions) + it("should NOT apply global cross-region prefix for unsupported models", async () => { + const options: AwsBedrockHandlerOptions = { + ...mockOptions, + awsUseCrossRegionInference: true, + awsUseGlobalInference: true, + apiModelId: "anthropic.claude-3-7-sonnet-20250219-v1:0", // 3.7 does not support a global inference profile + awsRegion: "us-west-2", + } + const usHandler = new AwsBedrockHandler(options) - // const modelId = await ultraThinkHandler.getModelId() - // // Should return the raw ARN without any encoding - // modelId.should.equal( - // "arn:aws:bedrock:us-west-2:123456789012:custom-model/anthropic.claude-3-5-sonnet-20241022-v2:0/Qk8MMyLmRd", - // ) - // modelId.should.not.match(/%2F/) - // modelId.should.not.match(/%3A/) - // }) - // }) + const modelId = await usHandler.getModelId() + modelId.should.equal("us.anthropic.claude-3-7-sonnet-20250219-v1:0") + }) + + it("should apply APAC cross-region prefix", async () => { + const apacOptions: AwsBedrockHandlerOptions = { + ...mockOptions, + awsUseCrossRegionInference: true, + awsRegion: "ap-northeast-1", + } + const apacHandler = new AwsBedrockHandler(apacOptions) + + const modelId = await apacHandler.getModelId() + modelId.should.equal("apac.anthropic.claude-3-7-sonnet-20250219-v1:0") + }) + + it("should not apply cross-region prefix for custom models even when enabled", async () => { + const customCrossRegionOptions: AwsBedrockHandlerOptions = { + ...mockOptions, + awsBedrockCustomSelected: true, + apiModelId: "arn:aws:bedrock:us-west-2:123456789012:custom-model/my-model", + awsUseCrossRegionInference: true, + } + const customCrossRegionHandler = new AwsBedrockHandler(customCrossRegionOptions) + + const modelId = await customCrossRegionHandler.getModelId() + modelId.should.equal("arn:aws:bedrock:us-west-2:123456789012:custom-model/my-model") + }) + + it("should handle UltraThink model ARN correctly", async () => { + const ultraThinkOptions: AwsBedrockHandlerOptions = { + ...mockOptions, + awsBedrockCustomSelected: true, + apiModelId: + "arn:aws:bedrock:us-west-2:123456789012:custom-model/anthropic.claude-3-5-sonnet-20241022-v2:0/Qk8MMyLmRd", + } + const ultraThinkHandler = new AwsBedrockHandler(ultraThinkOptions) + + const modelId = await ultraThinkHandler.getModelId() + // Should return the raw ARN without any encoding + modelId.should.equal( + "arn:aws:bedrock:us-west-2:123456789012:custom-model/anthropic.claude-3-5-sonnet-20241022-v2:0/Qk8MMyLmRd", + ) + modelId.should.not.match(/%2F/) + modelId.should.not.match(/%3A/) + }) + }) }) diff --git a/src/core/api/providers/bedrock.ts b/src/core/api/providers/bedrock.ts index bcde4ae3..c8076c59 100644 --- a/src/core/api/providers/bedrock.ts +++ b/src/core/api/providers/bedrock.ts @@ -25,6 +25,7 @@ export interface AwsBedrockHandlerOptions extends CommonApiHandlerOptions { awsAuthentication?: string awsBedrockApiKey?: string awsUseCrossRegionInference?: boolean + awsUseGlobalInference?: boolean awsBedrockUsePromptCache?: boolean awsUseProfile?: boolean awsProfile?: string @@ -106,6 +107,10 @@ interface ProviderChainOptions { profile?: string } +// a special jp inference profile was created for sonnet 4.5 +// https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-support.html +const JP_SUPPORTED_CRIS_MODELS = ["anthropic.claude-sonnet-4-5-20250929-v1:0", "anthropic.claude-sonnet-4-5-20250929-v1:0:1m"] + // https://docs.anthropic.com/en/api/claude-on-amazon-bedrock export class AwsBedrockHandler implements ApiHandler { private options: AwsBedrockHandlerOptions @@ -271,6 +276,9 @@ export class AwsBedrockHandler implements ApiHandler { */ async getModelId(): Promise { if (!this.options.awsBedrockCustomSelected && this.options.awsUseCrossRegionInference) { + if (this.getModel().info.supportsGlobalEndpoint && this.options.awsUseGlobalInference) { + return `global.${this.getModel().id}` + } const regionPrefix = this.getRegion().slice(0, 3) switch (regionPrefix) { case "us-": @@ -278,6 +286,9 @@ export class AwsBedrockHandler implements ApiHandler { case "eu-": return `eu.${this.getModel().id}` case "ap-": + if (JP_SUPPORTED_CRIS_MODELS.includes(this.getModel().id)) { + return `jp.${this.getModel().id}` + } return `apac.${this.getModel().id}` default: // cross region inference is not supported in this region, falling back to default model diff --git a/src/core/storage/StateManager.ts b/src/core/storage/StateManager.ts index 0f965d1a..70476611 100644 --- a/src/core/storage/StateManager.ts +++ b/src/core/storage/StateManager.ts @@ -388,6 +388,7 @@ export class StateManager { awsSessionToken, awsRegion, awsUseCrossRegionInference, + awsUseGlobalInference, awsBedrockUsePromptCache, awsBedrockEndpoint, awsBedrockApiKey, @@ -598,6 +599,7 @@ export class StateManager { // Global state updates awsRegion, awsUseCrossRegionInference, + awsUseGlobalInference, awsBedrockUsePromptCache, awsBedrockEndpoint, awsProfile, @@ -940,6 +942,7 @@ export class StateManager { awsRegion: this.taskStateCache["awsRegion"] || this.globalStateCache["awsRegion"], awsUseCrossRegionInference: this.taskStateCache["awsUseCrossRegionInference"] || this.globalStateCache["awsUseCrossRegionInference"], + awsUseGlobalInference: this.taskStateCache["awsUseGlobalInference"] || this.globalStateCache["awsUseGlobalInference"], awsBedrockUsePromptCache: this.taskStateCache["awsBedrockUsePromptCache"] || this.globalStateCache["awsBedrockUsePromptCache"], awsBedrockEndpoint: this.taskStateCache["awsBedrockEndpoint"] || this.globalStateCache["awsBedrockEndpoint"], diff --git a/src/core/storage/state-keys.ts b/src/core/storage/state-keys.ts index f360d806..048963d5 100644 --- a/src/core/storage/state-keys.ts +++ b/src/core/storage/state-keys.ts @@ -47,6 +47,7 @@ export interface GlobalState { export interface Settings { awsRegion: string | undefined awsUseCrossRegionInference: boolean | undefined + awsUseGlobalInference: boolean | undefined awsBedrockUsePromptCache: boolean | undefined awsBedrockEndpoint: string | undefined awsProfile: string | undefined diff --git a/src/core/storage/utils/state-helpers.ts b/src/core/storage/utils/state-helpers.ts index 0c35ac9f..4d587fe2 100644 --- a/src/core/storage/utils/state-helpers.ts +++ b/src/core/storage/utils/state-helpers.ts @@ -157,6 +157,8 @@ export async function readGlobalStateFromDisk(context: ExtensionContext): Promis const awsRegion = context.globalState.get("awsRegion") const awsUseCrossRegionInference = context.globalState.get("awsUseCrossRegionInference") + const awsUseGlobalInference = + context.globalState.get("awsUseGlobalInference") const awsBedrockUsePromptCache = context.globalState.get("awsBedrockUsePromptCache") const awsBedrockEndpoint = context.globalState.get("awsBedrockEndpoint") @@ -423,6 +425,7 @@ export async function readGlobalStateFromDisk(context: ExtensionContext): Promis claudeCodePath, awsRegion, awsUseCrossRegionInference, + awsUseGlobalInference, awsBedrockUsePromptCache, awsBedrockEndpoint, awsProfile, diff --git a/src/shared/api.ts b/src/shared/api.ts index 267d8c33..ed18154e 100644 --- a/src/shared/api.ts +++ b/src/shared/api.ts @@ -87,6 +87,7 @@ export interface ApiHandlerOptions { openRouterProviderSorting?: string awsRegion?: string awsUseCrossRegionInference?: boolean + awsUseGlobalInference?: boolean awsBedrockUsePromptCache?: boolean awsAuthentication?: string awsUseProfile?: boolean @@ -438,6 +439,7 @@ export const bedrockModels = { contextWindow: 200_000, supportsImages: true, supportsPromptCache: true, + supportsGlobalEndpoint: true, inputPrice: 3.0, outputPrice: 15.0, cacheWritesPrice: 3.75, @@ -448,6 +450,7 @@ export const bedrockModels = { contextWindow: 1_000_000, supportsImages: true, supportsPromptCache: true, + supportsGlobalEndpoint: true, inputPrice: 3.0, outputPrice: 15.0, cacheWritesPrice: 3.75, @@ -459,6 +462,7 @@ export const bedrockModels = { contextWindow: 200_000, supportsImages: true, supportsPromptCache: true, + supportsGlobalEndpoint: true, inputPrice: 3.0, outputPrice: 15.0, cacheWritesPrice: 3.75, @@ -469,6 +473,7 @@ export const bedrockModels = { contextWindow: 1_000_000, supportsImages: true, supportsPromptCache: true, + supportsGlobalEndpoint: true, inputPrice: 3.0, outputPrice: 15.0, cacheWritesPrice: 3.75, diff --git a/src/shared/proto-conversions/models/api-configuration-conversion.ts b/src/shared/proto-conversions/models/api-configuration-conversion.ts index 39aed98e..6f70735e 100644 --- a/src/shared/proto-conversions/models/api-configuration-conversion.ts +++ b/src/shared/proto-conversions/models/api-configuration-conversion.ts @@ -411,6 +411,7 @@ export function convertApiConfigurationToProto(config: ApiConfiguration): ProtoA awsSessionToken: config.awsSessionToken, awsRegion: config.awsRegion, awsUseCrossRegionInference: config.awsUseCrossRegionInference, + awsUseGlobalInference: config.awsUseGlobalInference, awsBedrockUsePromptCache: config.awsBedrockUsePromptCache, awsUseProfile: config.awsUseProfile, awsAuthentication: config.awsAuthentication, @@ -561,6 +562,7 @@ export function convertProtoToApiConfiguration(protoConfig: ProtoApiConfiguratio awsSessionToken: protoConfig.awsSessionToken, awsRegion: protoConfig.awsRegion, awsUseCrossRegionInference: protoConfig.awsUseCrossRegionInference, + awsUseGlobalInference: protoConfig.awsUseGlobalInference, awsBedrockUsePromptCache: protoConfig.awsBedrockUsePromptCache, awsUseProfile: protoConfig.awsUseProfile, awsAuthentication: protoConfig.awsAuthentication, diff --git a/webview-ui/src/components/settings/providers/BedrockProvider.tsx b/webview-ui/src/components/settings/providers/BedrockProvider.tsx index 4dc78df4..2685e6cd 100644 --- a/webview-ui/src/components/settings/providers/BedrockProvider.tsx +++ b/webview-ui/src/components/settings/providers/BedrockProvider.tsx @@ -168,6 +168,17 @@ export const BedrockProvider = ({ showModelOptions, isPopup, currentMode }: Bedr Use cross-region inference + {apiConfiguration?.awsUseCrossRegionInference && selectedModelInfo.supportsGlobalEndpoint && ( + { + const isChecked = e.target.checked === true + handleFieldChange("awsUseGlobalInference", isChecked) + }}> + Use global inference profile + + )} + {selectedModelInfo.supportsPromptCache && (