@@ -18,7 +18,6 @@ import { showMessageWithUrl } from '../../shared/utilities/messages'
1818import { parse } from '@aws-sdk/util-arn-parser'
1919import { Commands } from '../../shared/vscode/commands2'
2020import { vsCodeState } from '../models/model'
21- import { FeatureConfigProvider , Features } from '../../shared/featureConfig'
2221
2322/**
2423 *
@@ -92,10 +91,7 @@ export const baseCustomization = {
9291}
9392
9493/**
95- * Gets the customization that should be used for user requests. If a user has manually selected
96- * a customization, always respect that choice. If not, check if the user is part of an AB
97- * group assigned a specific customization. If so, use that customization. If not, use the
98- * base customization.
94+ * @returns customization selected by users, `baseCustomization` if none is selected
9995 */
10096export const getSelectedCustomization = ( ) : Customization => {
10197 if (
@@ -116,25 +112,27 @@ export const getSelectedCustomization = (): Customization => {
116112 if ( selectedCustomization && selectedCustomization . name !== '' ) {
117113 return selectedCustomization
118114 } else {
119- const customizationFeature = FeatureConfigProvider . getFeature ( Features . customizationArnOverride )
120- const arnOverride = customizationFeature ?. value . stringValue
121- const customizationOverrideName = customizationFeature ?. variation
122- if ( arnOverride === undefined ) {
123- return baseCustomization
124- } else {
125- return {
126- arn : arnOverride ,
127- name : customizationOverrideName ,
128- description : baseCustomization . description ,
129- }
130- }
115+ return baseCustomization
131116 }
132117}
133118
134- export const setSelectedCustomization = async ( customization : Customization ) => {
119+ /**
120+ * @param customization customization to select
121+ * @param isOverride if the API call is made from us (Q) but not users' intent, set isOverride to TRUE
122+ * Override happens when ALL following conditions are met
123+ * 1. service returns non-empty override customization arn, refer to [featureConfig.ts]
124+ * 2. the override customization arn is different from the previous override customization if any. The purpose is to only do override once on users' behalf.
125+ */
126+ export const setSelectedCustomization = async ( customization : Customization , isOverride : boolean = false ) => {
135127 if ( ! AuthUtil . instance . isValidEnterpriseSsoInUse ( ) || ! AuthUtil . instance . conn ) {
136128 return
137129 }
130+ if ( isOverride ) {
131+ const previousOverride = globals . globalState . tryGet < string > ( 'aws.amazonq.customization.override' , String )
132+ if ( customization . arn === previousOverride ) {
133+ return
134+ }
135+ }
138136 const selectedCustomizationObj = globals . globalState . tryGet < { [ label : string ] : Customization } > (
139137 'CODEWHISPERER_SELECTED_CUSTOMIZATION' ,
140138 Object ,
@@ -144,6 +142,9 @@ export const setSelectedCustomization = async (customization: Customization) =>
144142 getLogger ( ) . debug ( `Selected customization ${ customization . name } for ${ AuthUtil . instance . conn . label } ` )
145143
146144 await globals . globalState . update ( 'CODEWHISPERER_SELECTED_CUSTOMIZATION' , selectedCustomizationObj )
145+ if ( isOverride ) {
146+ await globals . globalState . update ( 'aws.amazonq.customization.override' , customization . arn )
147+ }
147148 vsCodeState . isFreeTierLimitReached = false
148149 await Commands . tryExecute ( 'aws.amazonq.refreshStatusBar' )
149150}
0 commit comments