Skip to content

feat: Add custom region support for AWS Bedrock provider #5924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/types/src/providers/bedrock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,4 +405,10 @@ export const BEDROCK_REGIONS = [
{ value: "sa-east-1", label: "sa-east-1" },
{ value: "us-gov-east-1", label: "us-gov-east-1" },
{ value: "us-gov-west-1", label: "us-gov-west-1" },
].sort((a, b) => a.value.localeCompare(b.value))
{ value: "custom", label: "Custom region..." },
].sort((a, b) => {
// Keep 'custom' option at the end
if (a.value === "custom") return 1;
if (b.value === "custom") return -1;
return a.value.localeCompare(b.value);
})
38 changes: 36 additions & 2 deletions webview-ui/src/components/settings/providers/Bedrock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,27 @@ type BedrockProps = {
export const Bedrock = ({ apiConfiguration, setApiConfigurationField, selectedModelInfo }: BedrockProps) => {
const { t } = useAppTranslation()
const [awsEndpointSelected, setAwsEndpointSelected] = useState(!!apiConfiguration?.awsBedrockEndpointEnabled)
const [isCustomRegion, setIsCustomRegion] = useState(
apiConfiguration?.awsRegion && !BEDROCK_REGIONS.some((region) => region.value === apiConfiguration.awsRegion),
)

// Update the endpoint enabled state when the configuration changes
useEffect(() => {
setAwsEndpointSelected(!!apiConfiguration?.awsBedrockEndpointEnabled)
}, [apiConfiguration?.awsBedrockEndpointEnabled])

// Initialize custom region state on component mount
useEffect(() => {
if (apiConfiguration?.awsRegion) {
const isStandardRegion = BEDROCK_REGIONS.some(
(region: { value: string; label: string }) =>
region.value === apiConfiguration.awsRegion && region.value !== "custom",
)
setIsCustomRegion(!isStandardRegion)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []) // Only run on mount - deliberately ignoring apiConfiguration dependency to avoid conflicts

const handleInputChange = useCallback(
<K extends keyof ProviderSettings, E>(
field: K,
Expand Down Expand Up @@ -88,8 +103,16 @@ export const Bedrock = ({ apiConfiguration, setApiConfigurationField, selectedMo
<div>
<label className="block font-medium mb-1">{t("settings:providers.awsRegion")}</label>
<Select
value={apiConfiguration?.awsRegion || ""}
onValueChange={(value) => setApiConfigurationField("awsRegion", value)}>
value={isCustomRegion ? "custom" : apiConfiguration?.awsRegion || ""}
onValueChange={(value) => {
if (value === "custom") {
setIsCustomRegion(true)
setApiConfigurationField("awsRegion", "")
} else {
setIsCustomRegion(false)
setApiConfigurationField("awsRegion", value)
}
}}>
<SelectTrigger className="w-full">
<SelectValue placeholder={t("settings:common.select")} />
</SelectTrigger>
Expand All @@ -101,6 +124,17 @@ export const Bedrock = ({ apiConfiguration, setApiConfigurationField, selectedMo
))}
</SelectContent>
</Select>
{isCustomRegion && (
<div className="mt-2">
<VSCodeTextField
value={apiConfiguration?.awsRegion || ""}
onInput={handleInputChange("awsRegion")}
placeholder="Enter custom region (e.g., us-west-3)"
className="w-full">
<label className="block font-medium mb-1">Custom Region</label>
</VSCodeTextField>
</div>
)}
</div>
<Checkbox
checked={apiConfiguration?.awsUseCrossRegionInference || false}
Expand Down