44 */
55
66import {
7- Customization ,
87 FeatureValue ,
98 ListFeatureEvaluationsRequest ,
109 ListFeatureEvaluationsResponse ,
@@ -21,7 +20,7 @@ import { getClientId, getOperatingSystem } from './telemetry/util'
2120import { extensionVersion } from './vscode/env'
2221import { telemetry } from './telemetry/telemetry'
2322import { Commands } from './vscode/commands2'
24- import { setSelectedCustomization } from '../codewhisperer/util/customizationUtil'
23+ import { getAvailableCustomizationsList , setSelectedCustomization } from '../codewhisperer/util/customizationUtil'
2524
2625const localize = nls . loadMessageBundle ( )
2726
@@ -145,29 +144,15 @@ export class FeatureConfigProvider {
145144 }
146145 getLogger ( ) . info ( 'AB Testing Cohort Assignments %O' , response . featureEvaluations )
147146
148- const profile = AuthUtil . instance . regionProfileManager . activeRegionProfile
149147 const customizationArnOverride = this . featureConfigs . get ( Features . customizationArnOverride ) ?. value
150148 ?. stringValue
151149 const previousOverride = globals . globalState . tryGet < string > ( 'aws.amazonq.customization.overrideV2' , String )
152- if ( profile && customizationArnOverride !== undefined && customizationArnOverride !== previousOverride ) {
150+ if ( customizationArnOverride !== undefined && customizationArnOverride !== previousOverride ) {
153151 // Double check if server-side wrongly returns a customizationArn to BID users
154152 if ( isBuilderIdConnection ( AuthUtil . instance . conn ) ) {
155153 this . featureConfigs . delete ( Features . customizationArnOverride )
156154 } else if ( isIdcSsoConnection ( AuthUtil . instance . conn ) ) {
157- let availableCustomizations : Customization [ ] = [ ]
158- try {
159- const items : Customization [ ] = [ ]
160- // TODO: list all customization across different profiles
161- const response = await client . listAvailableCustomizations ( profile )
162- for ( const customizations of response . map (
163- ( listAvailableCustomizationsResponse ) => listAvailableCustomizationsResponse . customizations
164- ) ) {
165- items . push ( ...customizations )
166- }
167- availableCustomizations = items
168- } catch ( e ) {
169- getLogger ( ) . debug ( 'amazonq: Failed to list available customizations' )
170- }
155+ const availableCustomizations = await getAvailableCustomizationsList ( )
171156
172157 // If customizationArn from A/B is not available in listAvailableCustomizations response, don't use this value
173158 const targetCustomization = availableCustomizations ?. find ( ( c ) => c . arn === customizationArnOverride )
@@ -178,6 +163,16 @@ export class FeatureConfigProvider {
178163 this . featureConfigs . delete ( Features . customizationArnOverride )
179164 } else {
180165 await setSelectedCustomization ( targetCustomization , true )
166+ // note that we should also switch profile if either
167+ // 1. user has not selected a profile yet
168+ // 2. user's selected profile is not the same as the one of customizationOverride
169+ const profile = AuthUtil . instance . regionProfileManager . activeRegionProfile
170+ if ( ! profile || ( profile && profile . arn !== targetCustomization . profile . arn ) ) {
171+ await AuthUtil . instance . regionProfileManager . switchRegionProfile (
172+ targetCustomization . profile ,
173+ 'customization'
174+ )
175+ }
181176 }
182177
183178 await vscode . commands . executeCommand ( 'aws.amazonq.refreshStatusBar' )
0 commit comments