Skip to content

Commit b29b0cc

Browse files
committed
customization override should only happen once for a specific override
1 parent b5e72bf commit b29b0cc

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

packages/core/src/codewhisperer/util/customizationUtil.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ export const baseCustomization = {
9191
}
9292

9393
/**
94-
* Gets the customization that should be used for user requests. If a user has manually selected
95-
* a customization, always respect that choice. If not, check if the user is part of an AB
96-
* group assigned a specific customization. If so, use that customization. If not, use the
97-
* base customization.
94+
* @returns customization selected by users, `baseCustomization` if none is selected
9895
*/
9996
export const getSelectedCustomization = (): Customization => {
10097
if (
@@ -119,10 +116,23 @@ export const getSelectedCustomization = (): Customization => {
119116
}
120117
}
121118

122-
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) => {
123127
if (!AuthUtil.instance.isValidEnterpriseSsoInUse() || !AuthUtil.instance.conn) {
124128
return
125129
}
130+
if (isOverride) {
131+
const previousOverride = globals.globalState.tryGet<string>('aws.amazonq.customization.override', String)
132+
if (customization.arn === previousOverride) {
133+
return
134+
}
135+
}
126136
const selectedCustomizationObj = globals.globalState.tryGet<{ [label: string]: Customization }>(
127137
'CODEWHISPERER_SELECTED_CUSTOMIZATION',
128138
Object,
@@ -132,6 +142,9 @@ export const setSelectedCustomization = async (customization: Customization) =>
132142
getLogger().debug(`Selected customization ${customization.name} for ${AuthUtil.instance.conn.label}`)
133143

134144
await globals.globalState.update('CODEWHISPERER_SELECTED_CUSTOMIZATION', selectedCustomizationObj)
145+
if (isOverride) {
146+
await globals.globalState.update('aws.amazonq.customization.override', customization.arn)
147+
}
135148
vsCodeState.isFreeTierLimitReached = false
136149
await Commands.tryExecute('aws.amazonq.refreshStatusBar')
137150
}

packages/core/src/shared/globalState.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export type globalKey =
4545
| 'aws.toolkit.amazonq.dismissed'
4646
| 'aws.toolkit.amazonqInstall.dismissed'
4747
| 'aws.amazonq.workspaceIndexToggleOn'
48+
| 'aws.amazonq.customization.override'
4849
// Deprecated/legacy names. New keys should start with "aws.".
4950
| '#sessionCreationDates' // Legacy name from `ssoAccessTokenProvider.ts`.
5051
| 'CODECATALYST_RECONNECT'

0 commit comments

Comments
 (0)