Skip to content

Commit 179ac35

Browse files
committed
fix(bedrock): default an unset model ID and treat whitespace ARNs as pending
1 parent 2e10292 commit 179ac35

4 files changed

Lines changed: 35 additions & 16 deletions

File tree

‎src/api/providers/__tests__/bedrock.spec.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import {
5858
BEDROCK_1M_CONTEXT_MODEL_IDS,
5959
BEDROCK_SERVICE_TIER_MODEL_IDS,
6060
bedrockModels,
61+
bedrockDefaultModelId,
6162
SERVICE_TIER_KEY,
6263
ApiProviderError,
6364
BEDROCK_CUSTOM_ARN_OTHER_BASE_MODEL,
@@ -959,6 +960,15 @@ describe("AwsBedrockHandler", () => {
959960
expect(typeof model.info.supportsPromptCache).toBe("boolean")
960961
})
961962

963+
it("selects the default model when no model ID is configured", () => {
964+
const handler = new AwsBedrockHandler({ awsRegion: "us-east-1" })
965+
966+
const model = handler.getModel()
967+
968+
expect(model.id).toBe(bedrockDefaultModelId)
969+
expect(model.info.contextWindow).toBe(bedrockModels[bedrockDefaultModelId].contextWindow)
970+
})
971+
962972
it("should return Claude Fable 5 model info", () => {
963973
const handler = new AwsBedrockHandler({
964974
apiModelId: "anthropic.claude-fable-5",

‎src/api/providers/bedrock.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,11 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
12041204

12051205
//Prompt Router responses come back in a different sequence and the model used is in the response and must be fetched by name
12061206
getModelById(modelId: string, modelType?: string): { id: BedrockModelId | string; info: ModelInfo } {
1207+
// An unset apiModelId selects the default model through the normal lookup path.
1208+
if (!modelId) {
1209+
return this.getModelById(bedrockDefaultModelId, modelType)
1210+
}
1211+
12071212
// Try to find the model in bedrockModels
12081213
const baseModelId = this.parseBaseModelId(modelId) as BedrockModelId
12091214

@@ -1222,7 +1227,7 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
12221227
// Use heuristics for model info, then allow overrides from ProviderSettings
12231228
const guessed = this.guessModelInfoFromId(modelId)
12241229
model = {
1225-
id: modelId || bedrockDefaultModelId,
1230+
id: modelId,
12261231
info: {
12271232
...guessed,
12281233
},

‎webview-ui/src/components/settings/providers/Bedrock.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const Bedrock = ({
4545
organizationAllowList.providers[providerIdentifiers.bedrock]?.allowAll
4646
const customArn = apiConfiguration.awsCustomArn
4747
// The "custom-arn" sentinel is not a request model ID; show a placeholder until an ARN is entered.
48-
const awaitingArn = !customArn && apiConfiguration.apiModelId === "custom-arn"
48+
const awaitingArn = !customArn?.trim() && apiConfiguration.apiModelId === "custom-arn"
4949
const requestModelId = awaitingArn
5050
? "—"
5151
: customArn

‎webview-ui/src/components/settings/providers/__tests__/Bedrock.spec.tsx‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,24 @@ describe("Bedrock Component", () => {
111111
expect(mockSetApiConfigurationField).not.toHaveBeenCalled()
112112
})
113113

114-
it("shows a placeholder and ARN guidance while the custom ARN is still empty", () => {
115-
render(
116-
<Bedrock
117-
apiConfiguration={{
118-
apiModelId: "custom-arn",
119-
awsRegion: "eu-west-3",
120-
awsUseCrossRegionInference: true,
121-
}}
122-
setApiConfigurationField={mockSetApiConfigurationField}
123-
/>,
124-
)
125-
expect(screen.getByTestId("bedrock-request-model").querySelector("code")?.textContent).toBe("—")
126-
expect(screen.getByText("settings:providers.awsArnRouting")).toBeInTheDocument()
127-
})
114+
it.each([undefined, "", " "])(
115+
"shows a placeholder and ARN guidance while the custom ARN is still empty: %j",
116+
(awsCustomArn) => {
117+
render(
118+
<Bedrock
119+
apiConfiguration={{
120+
apiModelId: "custom-arn",
121+
awsCustomArn,
122+
awsRegion: "eu-west-3",
123+
awsUseCrossRegionInference: true,
124+
}}
125+
setApiConfigurationField={mockSetApiConfigurationField}
126+
/>,
127+
)
128+
expect(screen.getByTestId("bedrock-request-model").querySelector("code")?.textContent).toBe("—")
129+
expect(screen.getByText("settings:providers.awsArnRouting")).toBeInTheDocument()
130+
},
131+
)
128132

129133
it.each<[OrganizationAllowList, boolean]>([
130134
[{ allowAll: true, providers: {} }, true],

0 commit comments

Comments
 (0)