Skip to content

Commit 3bf6b1d

Browse files
Merge master into feature/stepfunctions-execution
2 parents d14492d + 89903fe commit 3bf6b1d

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

packages/amazonq/src/lsp/chat/messages.ts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
LINK_CLICK_NOTIFICATION_METHOD,
4949
LinkClickParams,
5050
INFO_LINK_CLICK_NOTIFICATION_METHOD,
51+
READY_NOTIFICATION_METHOD,
5152
buttonClickRequestType,
5253
ButtonClickResult,
5354
CancellationTokenSource,
@@ -115,19 +116,12 @@ export function registerLanguageServerEventListener(languageClient: LanguageClie
115116
chatOptions.quickActions.quickActionsCommandGroups[0].groupName = 'Quick Actions'
116117
}
117118

118-
provider.onDidResolveWebview(() => {
119-
void provider.webview?.postMessage({
120-
command: CHAT_OPTIONS,
121-
params: chatOptions,
122-
})
123-
})
124-
125119
// This passes through metric data from LSP events to Toolkit telemetry with all fields from the LSP server
126120
languageClient.onTelemetry((e) => {
127121
const telemetryName: string = e.name
128122

129123
if (telemetryName in telemetry) {
130-
languageClient.info(`[Telemetry] Emitting ${telemetryName} telemetry: ${JSON.stringify(e.data)}`)
124+
languageClient.info(`[VSCode Telemetry] Emitting ${telemetryName} telemetry: ${JSON.stringify(e.data)}`)
131125
telemetry[telemetryName as keyof TelemetryBase].emit(e.data)
132126
}
133127
})
@@ -139,6 +133,10 @@ export function registerMessageListeners(
139133
encryptionKey: Buffer
140134
) {
141135
const chatStreamTokens = new Map<string, CancellationTokenSource>() // tab id -> token
136+
137+
// Keep track of pending chat options to send when webview UI is ready
138+
const pendingChatOptions = languageClient.initializeResult?.awsServerCapabilities?.chatOptions
139+
142140
provider.webview?.onDidReceiveMessage(async (message) => {
143141
languageClient.info(`[VSCode Client] Received ${JSON.stringify(message)} from chat`)
144142

@@ -152,7 +150,32 @@ export function registerMessageListeners(
152150
}
153151

154152
const webview = provider.webview
153+
155154
switch (message.command) {
155+
// Handle "aws/chat/ready" event
156+
case READY_NOTIFICATION_METHOD:
157+
languageClient.info(`[VSCode Client] "aws/chat/ready" event is received, sending chat options`)
158+
if (webview && pendingChatOptions) {
159+
try {
160+
await webview.postMessage({
161+
command: CHAT_OPTIONS,
162+
params: pendingChatOptions,
163+
})
164+
165+
// Display a more readable representation of quick actions
166+
const quickActionCommands =
167+
pendingChatOptions?.quickActions?.quickActionsCommandGroups?.[0]?.commands || []
168+
const quickActionsDisplay = quickActionCommands.map((cmd: any) => cmd.command).join(', ')
169+
languageClient.info(
170+
`[VSCode Client] Chat options flags: mcpServers=${pendingChatOptions?.mcpServers}, history=${pendingChatOptions?.history}, export=${pendingChatOptions?.export}, quickActions=[${quickActionsDisplay}]`
171+
)
172+
} catch (err) {
173+
languageClient.error(
174+
`[VSCode Client] Failed to send CHAT_OPTIONS after "aws/chat/ready" event: ${(err as Error).message}`
175+
)
176+
}
177+
}
178+
break
156179
case COPY_TO_CLIPBOARD:
157180
languageClient.info('[VSCode Client] Copy to clipboard event received')
158181
try {

0 commit comments

Comments
 (0)