Skip to content

Commit 84fe051

Browse files
committed
remove composite key & cr
1 parent 4fb8dc9 commit 84fe051

File tree

4 files changed

+11
-26
lines changed

4 files changed

+11
-26
lines changed

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/customization/CodeWhispererCustomizationDialog.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ class CodeWhispererCustomizationDialog(
109109
RadioButtonOption.Customization -> run {
110110
CodeWhispererModelConfigurator.getInstance().switchCustomization(project, modal.selectedCustomization?.customization)
111111
notifyCustomizationIsSelected(project, modal.selectedCustomization)
112+
// Switch profile if it doesn't match the customization's profile.
113+
// Customizations are profile-scoped and must be used under the correct context.
112114
if (modal.selectedCustomization?.customization?.profile?.arn != QRegionProfileManager.getInstance().activeProfile(project)?.arn) {
113115
QRegionProfileManager.getInstance().switchProfile(
114116
project,

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/customization/CodeWhispererModelConfigurator.kt

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import software.aws.toolkits.jetbrains.services.amazonq.profile.QRegionProfile
2727
import software.aws.toolkits.jetbrains.services.amazonq.profile.QRegionProfileManager
2828
import software.aws.toolkits.jetbrains.services.amazonq.profile.QRegionProfileSelectedListener
2929
import software.aws.toolkits.jetbrains.services.codewhisperer.credentials.CodeWhispererClientAdaptor
30-
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants
3130
import software.aws.toolkits.jetbrains.utils.notifyInfo
3231
import software.aws.toolkits.jetbrains.utils.notifyWarn
3332
import software.aws.toolkits.jetbrains.utils.pluginAwareExecuteOnPooledThread
@@ -65,13 +64,6 @@ private fun notifyNewCustomization(project: Project) {
6564
)
6665
}
6766

68-
/**
69-
* generate a stable composite key for profile & customization combination for diff/deduplicate/search
70-
* rule: `<profileArn>::<customizationArn>`
71-
*/
72-
private fun CodeWhispererCustomization.compositeKey(): String =
73-
"${profile?.arn.orEmpty()}::$arn"
74-
7567
@Service(Service.Level.APP)
7668
@State(name = "codewhispererCustomizationStates", storages = [Storage("aws.xml")])
7769
class DefaultCodeWhispererModelConfigurator : CodeWhispererModelConfigurator, PersistentStateComponent<CodeWhispererCustomizationState>, Disposable {
@@ -80,7 +72,6 @@ class DefaultCodeWhispererModelConfigurator : CodeWhispererModelConfigurator, Pe
8072
private val connectionIdToActiveCustomizationArn = Collections.synchronizedMap<String, CodeWhispererCustomization>(mutableMapOf())
8173

8274
// Map to store connectionId to its listAvailableCustomizations result last time
83-
// Format of the customization key: profileArn::customizationArn
8475
private val connectionToCustomizationsShownLastTime = mutableMapOf<String, MutableList<String>>()
8576

8677
private val connectionIdToIsAllowlisted = Collections.synchronizedMap<String, Boolean>(mutableMapOf())
@@ -126,23 +117,15 @@ class DefaultCodeWhispererModelConfigurator : CodeWhispererModelConfigurator, Pe
126117
CodeWhispererClientAdaptor.getInstance(project).listAvailableCustomizations(profile)
127118
}.onFailure { e ->
128119
val requestId = (e as? CodeWhispererRuntimeException)?.requestId()
129-
val isNotAllowlisted = (e as? Exception)
130-
?.let { CodeWhispererConstants.Customization.noAccessToCustomizationExceptionPredicate(e) }
131-
?: false
132-
val logMessage = if (isNotAllowlisted) {
133-
// TODO: not required for non GP users
134-
"ListAvailableCustomizations: connection ${it.id} is not allowlisted, requestId: ${requestId.orEmpty()}"
135-
} else {
136-
"ListAvailableCustomizations: failed due to unknown error ${e.message}, requestId: ${requestId.orEmpty()}"
137-
}
120+
val logMessage = "ListAvailableCustomizations: failed due to unknown error ${e.message}, " +
121+
"requestId: ${requestId.orEmpty()}, profileName: ${profile.profileName}"
138122
LOG.debug { logMessage }
139123
}.getOrDefault(emptyList())
140124
}
141125

142126
// 2. get diff
143127
val previousCustomizationsShapshot = connectionToCustomizationsShownLastTime.getOrElse(it.id) { emptyList() }
144-
// calculate new profile+customization list using compositeKey
145-
val diff = aggregatedCustomizations.filterNot { customization -> previousCustomizationsShapshot.contains(customization.compositeKey()) }.toSet()
128+
val diff = aggregatedCustomizations.filterNot { customization -> previousCustomizationsShapshot.contains(customization.arn) }.toSet()
146129

147130
// 3 if passive,
148131
// (1) update allowlisting
@@ -156,18 +139,18 @@ class DefaultCodeWhispererModelConfigurator : CodeWhispererModelConfigurator, Pe
156139
notifyNewCustomization(project)
157140
}
158141
} else {
159-
connectionToCustomizationsShownLastTime[it.id] = aggregatedCustomizations.map { customization -> customization.compositeKey() }.toMutableList()
142+
connectionToCustomizationsShownLastTime[it.id] = aggregatedCustomizations.map { customization -> customization.arn }.toMutableList()
160143
}
161144

162145
// 4. invalidate selected customization if
163146
// (1) the API call failed
164147
// (2) the selected customization is not in the resultset of API call
165-
// (3) the q region profile associated with the selected customization does not match the currently active profile
148+
// (3) the existing q region profile associated with the selected customization does not match the currently active profile
166149
activeCustomization(project)?.let { activeCustom ->
167150
if (aggregatedCustomizations.isEmpty()) {
168151
invalidateSelectedAndNotify(project)
169-
} else if (!aggregatedCustomizations.any { latestCustom -> latestCustom.compositeKey() == activeCustom.compositeKey() } ||
170-
activeCustom.profile != QRegionProfileManager.getInstance().activeProfile(project)
152+
} else if (!aggregatedCustomizations.any { latestCustom -> latestCustom.arn == activeCustom.arn } ||
153+
(activeCustom.profile != null && activeCustom.profile != QRegionProfileManager.getInstance().activeProfile(project))
171154
) {
172155
invalidateSelectedAndNotify(project)
173156
}

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/profile/QProfileSwitchIntent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package software.aws.toolkits.jetbrains.services.amazonq.profile
88
* 'auth' -> users change the profile through webview profile selector page
99
* 'update' -> plugin auto select the profile on users' behalf as there is only 1 profile
1010
* 'reload' -> on plugin restart, plugin will try to reload previous selected profile
11-
* - 'customization' -> users selected a customization tied to a different profile, triggering a profile switch
11+
* 'customization' -> users selected a customization tied to a different profile, triggering a profile switch
1212
*/
1313
enum class QProfileSwitchIntent(val value: String) {
1414
User("user"),

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/profile/QRegionProfileManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class QRegionProfileManager : PersistentStateComponent<QProfileState>, Disposabl
182182
}
183183

184184
inline fun <reified T : SdkClient> getQClient(project: Project): T = getQClient(project, null, T::class)
185-
inline fun <reified T : SdkClient> getQClient(project: Project, profile: QRegionProfile?): T = getQClient(project, profile, T::class)
185+
inline fun <reified T : SdkClient> getQClient(project: Project, profile: QRegionProfile): T = getQClient(project, profile, T::class)
186186

187187
fun <T : SdkClient> getQClient(project: Project, profile: QRegionProfile?, sdkClass: KClass<T>): T {
188188
val settings = getQClientSettings(project, profile)

0 commit comments

Comments
 (0)