Skip to content

Commit 3a24655

Browse files
fix(amazonq): fix chat input not responding correctly after reauth (#5805)
* sync q dev profile with reauth * fix initial quick actions * use slice * only check feature flags when chat is ready * remove comments * update groups only * clean up script * refactor
1 parent b6cf812 commit 3a24655

File tree

3 files changed

+53
-10
lines changed

3 files changed

+53
-10
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ class Browser(parent: Disposable, private val webUri: URI, val project: Project)
139139
},
140140
141141
"${activeProfile?.profileName.orEmpty()}")
142-
const commands = [hybridChatConnector.initialQuickActions[0], hybridChatConnector.initialQuickActions[1]]
143142
amazonQChat.createChat(
144143
{
145144
postMessage: message => {
@@ -148,7 +147,7 @@ class Browser(parent: Disposable, private val webUri: URI, val project: Project)
148147
},
149148
{
150149
agenticMode: true,
151-
quickActionCommands: commands,
150+
quickActionCommands: [],
152151
disclaimerAcknowledged: ${MeetQSettings.getInstance().disclaimerAcknowledged},
153152
pairProgrammingAcknowledged: ${MeetQSettings.getInstance().pairProgrammingAcknowledged}
154153
},

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

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ import software.aws.toolkits.jetbrains.services.amazonq.util.command
9494
import software.aws.toolkits.jetbrains.services.amazonq.util.tabType
9595
import software.aws.toolkits.jetbrains.services.amazonq.webview.theme.AmazonQTheme
9696
import software.aws.toolkits.jetbrains.services.amazonq.webview.theme.ThemeBrowserAdapter
97+
import software.aws.toolkits.jetbrains.services.amazonqCodeScan.auth.isCodeScanAvailable
98+
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.auth.isCodeTestAvailable
99+
import software.aws.toolkits.jetbrains.services.amazonqDoc.auth.isDocAvailable
100+
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.auth.isFeatureDevAvailable
101+
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.isCodeTransformAvailable
97102
import software.aws.toolkits.jetbrains.services.codewhisperer.settings.CodeWhispererConfigurable
98103
import software.aws.toolkits.jetbrains.settings.MeetQSettings
99104
import software.aws.toolkits.telemetry.MetricResult
@@ -173,12 +178,7 @@ class BrowserConnector(
173178
uiReady.await()
174179

175180
// Chat options including history and quick actions need to be sent in once UI is ready
176-
val showChatOptions = """{
177-
"command": "chatOptions",
178-
"params": ${Gson().toJson(AwsServerCapabilitiesProvider.getInstance(project).getChatOptions())}
179-
}
180-
""".trimIndent()
181-
browser.postChat(showChatOptions)
181+
updateQuickActionsInBrowser(browser)
182182

183183
// Send inbound messages to the browser
184184
val inboundMessages = connections.map { it.messagesFromAppToUi.flow }.merge()
@@ -535,6 +535,45 @@ class BrowserConnector(
535535
browser.postChat(cancelMessage)
536536
}
537537

538+
private fun updateQuickActionsInBrowser(browser: Browser) {
539+
val isFeatureDevAvailable = isFeatureDevAvailable(project)
540+
val isCodeTransformAvailable = isCodeTransformAvailable(project)
541+
val isDocAvailable = isDocAvailable(project)
542+
val isCodeScanAvailable = isCodeScanAvailable(project)
543+
val isCodeTestAvailable = isCodeTestAvailable(project)
544+
545+
val script = """
546+
try {
547+
const tempConnector = connectorAdapter.initiateAdapter(
548+
false,
549+
true, // the two values are not used here, needed for constructor
550+
$isFeatureDevAvailable,
551+
$isCodeTransformAvailable,
552+
$isDocAvailable,
553+
$isCodeScanAvailable,
554+
$isCodeTestAvailable,
555+
{ postMessage: () => {} }
556+
);
557+
558+
const commands = tempConnector.initialQuickActions?.slice(0, 2) || [];
559+
const options = ${Gson().toJson(AwsServerCapabilitiesProvider.getInstance(project).getChatOptions())};
560+
options.quickActions.quickActionsCommandGroups = [
561+
...commands,
562+
...options.quickActions.quickActionsCommandGroups
563+
];
564+
565+
window.postMessage({
566+
command: "chatOptions",
567+
params: options
568+
});
569+
} catch (e) {
570+
console.error("Error updating quick actions:", e);
571+
}
572+
""".trimIndent()
573+
574+
browser.jcefBrowser.cefBrowser.executeJavaScript(script, browser.jcefBrowser.cefBrowser.url, 0)
575+
}
576+
538577
private fun cancelInflightRequests(tabId: String) {
539578
chatCommunicationManager.getInflightRequestForTab(tabId)?.let { request ->
540579
request.cancel(true)

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,14 @@ class DefaultAuthCredentialsService(
111111
return CompletableFuture.failedFuture(e)
112112
}
113113

114-
return AmazonQLspService.executeIfRunning(project) { server ->
114+
val future = AmazonQLspService.executeIfRunning(project) { server ->
115115
server.updateTokenCredentials(payload)
116-
} ?: (CompletableFuture.failedFuture(IllegalStateException("LSP Server not running")))
116+
} ?: CompletableFuture.failedFuture(IllegalStateException("LSP Server not running"))
117+
118+
return future.thenApply { response ->
119+
updateConfiguration()
120+
response
121+
}
117122
}
118123

119124
override fun deleteTokenCredentials(): CompletableFuture<Unit> =

0 commit comments

Comments
 (0)