Skip to content

Commit 278ecaa

Browse files
committed
fix(bedrock): reset custom ARN base model with the ARN and show 1M tier pricing
- Clear awsCustomArnBaseModelId when a new ARN is pasted or a regular model is selected, so a stale base model can't apply to a different ARN - Use the 1M pricing tier in the custom-arn model info, matching the provider - Cover the resolver's fallback to the ARN's model for an unknown base model Refs Zoo-Code-Org#1968
1 parent b2ee4ad commit 278ecaa

5 files changed

Lines changed: 58 additions & 4 deletions

File tree

‎packages/types/src/__tests__/bedrock-custom-arn.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ describe("resolveBedrockCustomArnBaseModelId", () => {
3131
).toBe("anthropic.claude-3-5-sonnet-20241022-v2:0")
3232
})
3333

34+
it("falls back to the model named in the ARN when the saved base model is unknown", () => {
35+
expect(
36+
resolveBedrockCustomArnBaseModelId(
37+
"arn:aws:bedrock:us-east-1:123456789012:inference-profile/us.anthropic.claude-opus-4-8",
38+
"anthropic.claude-retired-model",
39+
),
40+
).toBe("anthropic.claude-opus-4-8")
41+
})
42+
3443
it("returns undefined when neither the setting nor the ARN identifies a model", () => {
3544
expect(resolveBedrockCustomArnBaseModelId(appProfileArn, undefined)).toBeUndefined()
3645
expect(resolveBedrockCustomArnBaseModelId(appProfileArn, "")).toBeUndefined()

‎webview-ui/src/components/settings/utils/__tests__/providerModelConfig.spec.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ describe("providerModelConfig", () => {
295295
handleModelChangeSideEffects(providerIdentifiers.bedrock, "anthropic.claude", setApiConfigurationField)
296296

297297
expect(setApiConfigurationField).toHaveBeenCalledWith("awsCustomArn", "")
298+
expect(setApiConfigurationField).toHaveBeenCalledWith("awsCustomArnBaseModelId", "")
298299
expect(setApiConfigurationField).toHaveBeenCalledWith("reasoningEffort", undefined)
299300
expect(setApiConfigurationField).toHaveBeenCalledWith("modelMaxTokens", undefined)
300301
expect(setApiConfigurationField).toHaveBeenCalledWith("modelMaxThinkingTokens", undefined)
@@ -306,6 +307,7 @@ describe("providerModelConfig", () => {
306307
handleModelChangeSideEffects(providerIdentifiers.bedrock, "custom-arn", setApiConfigurationField)
307308

308309
expect(setApiConfigurationField).not.toHaveBeenCalledWith("awsCustomArn", expect.anything())
310+
expect(setApiConfigurationField).not.toHaveBeenCalledWith("awsCustomArnBaseModelId", expect.anything())
309311
expect(setApiConfigurationField).toHaveBeenCalledWith("reasoningEffort", undefined)
310312
expect(setApiConfigurationField).toHaveBeenCalledWith("modelMaxTokens", undefined)
311313
expect(setApiConfigurationField).toHaveBeenCalledWith("modelMaxThinkingTokens", undefined)
@@ -328,6 +330,7 @@ describe("providerModelConfig", () => {
328330
handleModelChangeSideEffects(providerIdentifiers.bedrock, ` ${appProfileArn}\n`, setApiConfigurationField)
329331

330332
expect(setApiConfigurationField).toHaveBeenCalledWith("awsCustomArn", appProfileArn)
333+
expect(setApiConfigurationField).toHaveBeenCalledWith("awsCustomArnBaseModelId", "")
331334
expect(setApiConfigurationField).not.toHaveBeenCalledWith("awsCustomArn", "")
332335
expect(setApiConfigurationField).toHaveBeenCalledWith("modelMaxTokens", undefined)
333336
})

‎webview-ui/src/components/settings/utils/providerModelConfig.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,13 @@ export const handleModelChangeSideEffects = <K extends keyof ProviderSettings>(
254254
setApiConfigurationField: (field: K, value: ProviderSettings[K]) => void,
255255
): void => {
256256
if (provider === providerIdentifiers.bedrock) {
257+
// The base model belongs to a specific ARN, so reset it whenever the ARN is replaced or cleared.
257258
if (isArn(modelId)) {
258259
setApiConfigurationField("awsCustomArn" as K, modelId.trim() as ProviderSettings[K])
260+
setApiConfigurationField("awsCustomArnBaseModelId" as K, "" as ProviderSettings[K])
259261
} else if (modelId !== "custom-arn") {
260262
setApiConfigurationField("awsCustomArn" as K, "" as ProviderSettings[K])
263+
setApiConfigurationField("awsCustomArnBaseModelId" as K, "" as ProviderSettings[K])
261264
}
262265
}
263266

‎webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,34 @@ describe("useSelectedModel", () => {
855855
).toBe(1_000_000)
856856
})
857857

858+
it("uses the 1M pricing tier for a custom ARN base model when 1M context is enabled", () => {
859+
const opus48: ModelInfo = bedrockModels["anthropic.claude-opus-4-8"]
860+
const tier = opus48.tiers?.[0]
861+
expect(tier?.inputPrice).toBeGreaterThan(opus48.inputPrice ?? 0)
862+
863+
expect(
864+
renderCustomArn({ awsCustomArnBaseModelId: "anthropic.claude-opus-4-8", awsBedrock1MContext: true })
865+
.info,
866+
).toMatchObject({
867+
inputPrice: tier?.inputPrice,
868+
outputPrice: tier?.outputPrice,
869+
cacheWritesPrice: tier?.cacheWritesPrice,
870+
cacheReadsPrice: tier?.cacheReadsPrice,
871+
})
872+
expect(renderCustomArn({ awsCustomArnBaseModelId: "anthropic.claude-opus-4-8" }).info?.inputPrice).toBe(
873+
opus48.inputPrice,
874+
)
875+
})
876+
877+
it("applies a configured context window to a listed custom ARN base model", () => {
878+
expect(
879+
renderCustomArn({
880+
awsCustomArnBaseModelId: "anthropic.claude-opus-5-5",
881+
awsModelContextWindow: 400_000,
882+
}).info?.contextWindow,
883+
).toBe(400_000)
884+
})
885+
858886
it("detects the base model from an inference profile ARN that names it", () => {
859887
const { info } = renderCustomArn({
860888
awsCustomArn: "arn:aws:bedrock:us-east-1:123456789012:inference-profile/us.anthropic.claude-opus-4-8",

‎webview-ui/src/components/ui/hooks/useSelectedModel.ts‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,22 @@ function getSelectedModel({
259259
}
260260
}
261261

262+
const baseInfo: ModelInfo = bedrockModels[customArnBaseModelId]
263+
// Mirror the provider: the 1M context beta switches to the first pricing tier.
264+
const use1MContext =
265+
(BEDROCK_1M_CONTEXT_MODEL_IDS as readonly string[]).includes(customArnBaseModelId) &&
266+
!!apiConfiguration.awsBedrock1MContext
267+
const tier = use1MContext ? baseInfo.tiers?.[0] : undefined
262268
const customArnInfo: ModelInfo = {
263-
...bedrockModels[customArnBaseModelId],
264-
...((BEDROCK_1M_CONTEXT_MODEL_IDS as readonly string[]).includes(customArnBaseModelId) &&
265-
apiConfiguration.awsBedrock1MContext
266-
? { contextWindow: 1_000_000 }
269+
...baseInfo,
270+
...(use1MContext
271+
? {
272+
contextWindow: tier?.contextWindow ?? 1_000_000,
273+
inputPrice: tier?.inputPrice ?? baseInfo.inputPrice,
274+
outputPrice: tier?.outputPrice ?? baseInfo.outputPrice,
275+
cacheWritesPrice: tier?.cacheWritesPrice ?? baseInfo.cacheWritesPrice,
276+
cacheReadsPrice: tier?.cacheReadsPrice ?? baseInfo.cacheReadsPrice,
277+
}
267278
: {}),
268279
...(apiConfiguration.awsModelContextWindow
269280
? { contextWindow: apiConfiguration.awsModelContextWindow }

0 commit comments

Comments
 (0)