Skip to content

Commit 2fdde9b

Browse files
deps(amazonq): handle authFollowUpClick from webview UI (#5668)
Handle reauthenticate follow up button clicks. This is triggered when a token expires while a chat session is open. Grouping based on VSC implementation: https://github.com/aws/aws-toolkit-visual-studio-staging/blob/5a6757e071858848db926f9cb6eab80ed98523ff/vspackages/AmazonQ/AwsToolkit.AmazonQ.Shared/Chat/ViewModels/ChatViewModel.cs#L289-L327
1 parent 7c2ca19 commit 2fdde9b

File tree

5 files changed

+82
-3
lines changed

5 files changed

+82
-3
lines changed

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/BrowserConnector.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import software.aws.toolkits.jetbrains.services.amazonq.lsp.encryption.JwtEncryp
3535
import software.aws.toolkits.jetbrains.services.amazonq.lsp.flareChat.AwsServerCapabilitiesProvider
3636
import software.aws.toolkits.jetbrains.services.amazonq.lsp.flareChat.ChatCommunicationManager
3737
import software.aws.toolkits.jetbrains.services.amazonq.lsp.flareChat.getTextDocumentIdentifier
38+
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.AUTH_FOLLOW_UP_CLICKED
39+
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.AuthFollowUpClickNotification
3840
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.ButtonClickNotification
3941
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.ButtonClickParams
4042
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.ButtonClickResult
@@ -412,6 +414,13 @@ class BrowserConnector(
412414
}
413415
}
414416
}
417+
AUTH_FOLLOW_UP_CLICKED -> {
418+
val message = serializer.deserializeChatMessages<AuthFollowUpClickNotification>(node)
419+
chatCommunicationManager.handleAuthFollowUpClicked(
420+
project,
421+
message.params
422+
)
423+
}
415424
CHAT_COPY_CODE_TO_CLIPBOARD -> {
416425
handleChatNotification<CopyCodeToClipboardNotification, CopyCodeToClipboardParams>(node) { server, params ->
417426
server.copyCodeToClipboard(params)

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import com.intellij.openapi.project.Project
1919
import com.intellij.openapi.util.Disposer
2020
import com.intellij.openapi.util.Key
2121
import com.intellij.openapi.util.SystemInfo
22-
import com.intellij.util.animation.consumer
2322
import com.intellij.util.io.await
2423
import kotlinx.coroutines.CoroutineScope
2524
import kotlinx.coroutines.Deferred
@@ -40,7 +39,6 @@ import org.eclipse.lsp4j.SynchronizationCapabilities
4039
import org.eclipse.lsp4j.TextDocumentClientCapabilities
4140
import org.eclipse.lsp4j.WorkspaceClientCapabilities
4241
import org.eclipse.lsp4j.jsonrpc.Launcher
43-
import org.eclipse.lsp4j.jsonrpc.Launcher.Builder
4442
import org.eclipse.lsp4j.jsonrpc.MessageConsumer
4543
import org.eclipse.lsp4j.jsonrpc.messages.ResponseMessage
4644
import org.eclipse.lsp4j.launch.LSPLauncher

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/flareChat/ChatCommunicationManager.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,22 @@ import com.intellij.openapi.components.Service
88
import com.intellij.openapi.components.service
99
import com.intellij.openapi.project.Project
1010
import org.eclipse.lsp4j.ProgressParams
11+
import software.aws.toolkits.core.utils.getLogger
12+
import software.aws.toolkits.core.utils.warn
13+
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManager
14+
import software.aws.toolkits.jetbrains.core.credentials.pinning.QConnection
15+
import software.aws.toolkits.jetbrains.core.credentials.reauthConnectionIfNeeded
1116
import software.aws.toolkits.jetbrains.services.amazonq.lsp.AmazonQLspService
1217
import software.aws.toolkits.jetbrains.services.amazonq.lsp.flareChat.ProgressNotificationUtils.getObject
18+
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.AuthFollowUpClickedParams
19+
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.AuthFollowupType
1320
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.CHAT_ERROR_PARAMS
1421
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.ErrorParams
1522
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.GetSerializedChatResult
1623
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.OpenTabResult
1724
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.SEND_CHAT_COMMAND_PROMPT
25+
import software.aws.toolkits.jetbrains.services.amazonq.profile.QRegionProfileManager
26+
import software.aws.toolkits.jetbrains.services.amazonq.profile.QRegionProfileSelectedListener
1827
import java.util.UUID
1928
import java.util.concurrent.CompletableFuture
2029
import java.util.concurrent.ConcurrentHashMap
@@ -91,9 +100,40 @@ class ChatCommunicationManager {
91100
return uiMessage
92101
}
93102

103+
fun handleAuthFollowUpClicked(project: Project, params: AuthFollowUpClickedParams) {
104+
val incomingType = params.authFollowupType
105+
val connectionManager = ToolkitConnectionManager.getInstance(project)
106+
try {
107+
connectionManager.activeConnectionForFeature(QConnection.getInstance())?.let {
108+
reauthConnectionIfNeeded(project, it, isReAuth = true)
109+
}
110+
when (incomingType) {
111+
AuthFollowupType.USE_SUPPORTED_AUTH.value -> {
112+
project.messageBus.syncPublisher(QRegionProfileSelectedListener.TOPIC)
113+
.onProfileSelected(project, QRegionProfileManager.getInstance().activeProfile(project))
114+
return
115+
}
116+
AuthFollowupType.RE_AUTH.value,
117+
AuthFollowupType.MISSING_SCOPES.value,
118+
AuthFollowupType.FULL_AUTH.value,
119+
-> {
120+
return
121+
}
122+
else -> {
123+
LOG.warn { "Unknown auth follow up type: $incomingType" }
124+
}
125+
}
126+
} catch (ex: Exception) {
127+
LOG.warn(ex) { "Failed to handle authentication when auth follow up clicked" }
128+
throw ex
129+
}
130+
}
131+
94132
companion object {
95133
fun getInstance(project: Project) = project.service<ChatCommunicationManager>()
96134

135+
private val LOG = getLogger<ChatCommunicationManager>()
136+
97137
val pendingSerializedChatRequests = ConcurrentHashMap<String, CompletableFuture<GetSerializedChatResult>>()
98138
fun completeSerializedChatResponse(requestId: String, content: String) {
99139
pendingSerializedChatRequests.remove(requestId)?.complete(GetSerializedChatResult((content)))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat
5+
6+
data class AuthFollowUpClickNotification(
7+
override val command: String,
8+
override val params: AuthFollowUpClickedParams,
9+
) : ChatNotification<AuthFollowUpClickedParams>
10+
11+
data class AuthFollowUpClickedParams(
12+
val tabId: String,
13+
val messageId: String,
14+
val authFollowupType: String,
15+
) {
16+
companion object {
17+
fun create(tabId: String, messageId: String, authType: AuthFollowupType): AuthFollowUpClickedParams =
18+
AuthFollowUpClickedParams(tabId, messageId, authType.value)
19+
}
20+
}
21+
22+
enum class AuthFollowupType(val value: String) {
23+
FULL_AUTH("full-auth"),
24+
RE_AUTH("re-auth"),
25+
MISSING_SCOPES("missing_scopes"),
26+
USE_SUPPORTED_AUTH("use-supported-auth"),
27+
;
28+
29+
override fun toString(): String =
30+
name.lowercase()
31+
}

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/aws/chat/FlareChatCommands.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat
55

6+
const val AUTH_FOLLOW_UP_CLICKED = "authFollowUpClicked"
67
const val CHAT_BUTTON_CLICK = "aws/chat/buttonClick"
78
const val CHAT_CONVERSATION_CLICK = "aws/chat/conversationClick"
89
const val CHAT_COPY_CODE_TO_CLIPBOARD = "copyToClipboard"
@@ -33,10 +34,10 @@ const val CHAT_TAB_REMOVE = "aws/chat/tabRemove"
3334
const val GET_SERIALIZED_CHAT_REQUEST_METHOD = "aws/chat/getSerializedChat"
3435

3536
const val OPEN_FILE_DIFF = "aws/openFileDiff"
37+
const val OPEN_SETTINGS = "openSettings"
3638

3739
const val PROMPT_INPUT_OPTIONS_CHANGE = "aws/chat/promptInputOptionChange"
3840

3941
const val SEND_CHAT_COMMAND_PROMPT = "aws/chat/sendChatPrompt"
4042
const val SHOW_SAVE_FILE_DIALOG_REQUEST_METHOD = "aws/showSaveFileDialog"
4143
const val STOP_CHAT_RESPONSE = "stopChatResponse"
42-
const val OPEN_SETTINGS = "openSettings"

0 commit comments

Comments
 (0)