@@ -3,17 +3,18 @@ import { VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
33
44import {
55 type ProviderSettings ,
6+ BEDROCK_CUSTOM_ARN_OTHER_BASE_MODEL ,
67 BEDROCK_DEFAULT_CONTEXT ,
78 BEDROCK_MAX_TOKENS ,
89 bedrockModels ,
10+ isBedrockFoundationModelArn ,
911 resolveBedrockCustomArnBaseModelId ,
1012} from "@roo-code/types"
1113
1214import { validateBedrockArn } from "@src/utils/validate"
1315import { useAppTranslation } from "@src/i18n/TranslationContext"
1416import { Select , SelectContent , SelectItem , SelectTrigger , SelectValue } from "@src/components/ui"
1517
16- const OTHER_BASE_MODEL = "other"
1718const baseModelIds = Object . keys ( bedrockModels ) . sort ( ( a , b ) => a . localeCompare ( b ) )
1819
1920const toPositiveInteger = ( value : string ) : number | undefined => {
@@ -36,24 +37,41 @@ export const BedrockCustomArn = ({ apiConfiguration, setApiConfigurationField }:
3637
3738 const baseModelId =
3839 resolveBedrockCustomArnBaseModelId ( apiConfiguration . awsCustomArn , apiConfiguration . awsCustomArnBaseModelId ) ??
39- OTHER_BASE_MODEL
40+ BEDROCK_CUSTOM_ARN_OTHER_BASE_MODEL
41+ // A foundation-model ARN invokes the model it names, so the underlying model can't be changed.
42+ const isFoundationModelArn = isBedrockFoundationModelArn ( apiConfiguration . awsCustomArn )
4043
41- const onBaseModelChange = ( value : string ) => {
42- setApiConfigurationField ( "awsCustomArnBaseModelId" , value === OTHER_BASE_MODEL ? "" : value )
43- // Different models have different output, thinking and context defaults.
44+ // Different models have different output, thinking and context defaults.
45+ const resetModelSettings = ( ) => {
4446 setApiConfigurationField ( "modelMaxTokens" , undefined )
4547 setApiConfigurationField ( "modelMaxThinkingTokens" , undefined )
4648 setApiConfigurationField ( "reasoningEffort" , undefined )
4749 setApiConfigurationField ( "awsModelContextWindow" , undefined )
4850 }
4951
52+ const onBaseModelChange = ( value : string ) => {
53+ setApiConfigurationField ( "awsCustomArnBaseModelId" , value )
54+ resetModelSettings ( )
55+ }
56+
57+ // The underlying model and limits belong to one ARN, so a different ARN starts from detection again.
58+ const onArnInput = ( value : string ) => {
59+ if ( value === ( apiConfiguration . awsCustomArn ?? "" ) ) {
60+ return
61+ }
62+ setApiConfigurationField ( "awsCustomArn" , value )
63+ setApiConfigurationField ( "awsCustomArnBaseModelId" , "" )
64+ resetModelSettings ( )
65+ }
66+
5067 return (
5168 < >
5269 < VSCodeTextField
5370 value = { apiConfiguration ?. awsCustomArn || "" }
54- onInput = { ( e ) => setApiConfigurationField ( "awsCustomArn" , ( e . target as HTMLInputElement ) . value ) }
71+ onInput = { ( e ) => onArnInput ( ( e . target as HTMLInputElement ) . value ) }
5572 placeholder = { t ( "settings:placeholders.customArn" ) }
56- className = "w-full" >
73+ className = "w-full"
74+ data-testid = "custom-arn-input" >
5775 < label className = "block font-medium mb-1" > { t ( "settings:labels.customArn" ) } </ label >
5876 </ VSCodeTextField >
5977 < div className = "text-sm text-vscode-descriptionForeground -mt-2" >
@@ -78,12 +96,12 @@ export const BedrockCustomArn = ({ apiConfiguration, setApiConfigurationField }:
7896 ) }
7997 < div data-testid = "custom-arn-base-model" >
8098 < label className = "block font-medium mb-1" > { t ( "settings:providers.awsCustomArnBaseModel" ) } </ label >
81- < Select value = { baseModelId } onValueChange = { onBaseModelChange } >
99+ < Select value = { baseModelId } onValueChange = { onBaseModelChange } disabled = { isFoundationModelArn } >
82100 < SelectTrigger className = "w-full" >
83101 < SelectValue placeholder = { t ( "settings:common.select" ) } />
84102 </ SelectTrigger >
85103 < SelectContent >
86- < SelectItem value = { OTHER_BASE_MODEL } >
104+ < SelectItem value = { BEDROCK_CUSTOM_ARN_OTHER_BASE_MODEL } >
87105 { t ( "settings:providers.awsCustomArnBaseModelOther" ) }
88106 </ SelectItem >
89107 { baseModelIds . map ( ( id ) => (
@@ -97,7 +115,7 @@ export const BedrockCustomArn = ({ apiConfiguration, setApiConfigurationField }:
97115 { t ( "settings:providers.awsCustomArnBaseModelDesc" ) }
98116 </ div >
99117 </ div >
100- { baseModelId === OTHER_BASE_MODEL && (
118+ { baseModelId === BEDROCK_CUSTOM_ARN_OTHER_BASE_MODEL && (
101119 < >
102120 < VSCodeTextField
103121 value = { apiConfiguration . awsModelContextWindow ?. toString ( ) ?? "" }
0 commit comments