Explorar el Código

feat(bedrock): allow global inference selection when cross-region is enabled (#9616)

Co-authored-by: Roo Code <[email protected]>
roomote[bot] hace 1 mes
padre
commit
7e17982c40

+ 41 - 0
src/api/providers/__tests__/bedrock-inference-profiles.spec.ts

@@ -254,5 +254,46 @@ describe("Amazon Bedrock Inference Profiles", () => {
 			const usModel = usHandler.getModel()
 			expect(usModel.id).toBe("us.anthropic.claude-3-sonnet-20240229-v1:0")
 		})
+
+		it("should prioritize global inference over cross-region inference when both are enabled", () => {
+			// When both global inference and cross-region inference are enabled,
+			// global inference should take precedence
+			const handler = createHandler({
+				awsUseCrossRegionInference: true,
+				awsUseGlobalInference: true,
+				awsRegion: "us-east-1",
+				apiModelId: "anthropic.claude-sonnet-4-20250514-v1:0", // Model that supports global inference
+			})
+
+			const model = handler.getModel()
+			// Should use global. prefix, not us. prefix
+			expect(model.id).toBe("global.anthropic.claude-sonnet-4-20250514-v1:0")
+		})
+
+		it("should fall back to cross-region inference when global inference is disabled", () => {
+			const handler = createHandler({
+				awsUseCrossRegionInference: true,
+				awsUseGlobalInference: false,
+				awsRegion: "us-east-1",
+				apiModelId: "anthropic.claude-sonnet-4-20250514-v1:0",
+			})
+
+			const model = handler.getModel()
+			// Should use cross-region prefix since global is disabled
+			expect(model.id).toBe("us.anthropic.claude-sonnet-4-20250514-v1:0")
+		})
+
+		it("should not apply global inference prefix to unsupported models even when enabled", () => {
+			const handler = createHandler({
+				awsUseCrossRegionInference: true,
+				awsUseGlobalInference: true,
+				awsRegion: "us-east-1",
+				apiModelId: "anthropic.claude-3-sonnet-20240229-v1:0", // Model that does NOT support global inference
+			})
+
+			const model = handler.getModel()
+			// Should fall back to cross-region prefix since model doesn't support global inference
+			expect(model.id).toBe("us.anthropic.claude-3-sonnet-20240229-v1:0")
+		})
 	})
 })

+ 1 - 5
webview-ui/src/components/settings/providers/Bedrock.tsx

@@ -152,21 +152,17 @@ export const Bedrock = ({ apiConfiguration, setApiConfigurationField, selectedMo
 			{supportsGlobalInference && (
 				<Checkbox
 					checked={apiConfiguration?.awsUseGlobalInference || false}
-					disabled={apiConfiguration?.awsUseCrossRegionInference || false}
 					onChange={(checked: boolean) => {
-						// Enabling Global Inference should disable cross-region inference
+						// Global Inference takes priority over cross-region when both are enabled
 						setApiConfigurationField("awsUseGlobalInference", checked)
-						if (checked) setApiConfigurationField("awsUseCrossRegionInference", false)
 					}}>
 					{t("settings:providers.awsGlobalInference")}
 				</Checkbox>
 			)}
 			<Checkbox
 				checked={apiConfiguration?.awsUseCrossRegionInference || false}
-				disabled={apiConfiguration?.awsUseGlobalInference || false}
 				onChange={(checked: boolean) => {
 					setApiConfigurationField("awsUseCrossRegionInference", checked)
-					if (checked) setApiConfigurationField("awsUseGlobalInference", false)
 				}}>
 				{t("settings:providers.awsCrossRegion")}
 			</Checkbox>