@@ -48,6 +48,7 @@ import {
48
48
LINK_CLICK_NOTIFICATION_METHOD ,
49
49
LinkClickParams ,
50
50
INFO_LINK_CLICK_NOTIFICATION_METHOD ,
51
+ READY_NOTIFICATION_METHOD ,
51
52
buttonClickRequestType ,
52
53
ButtonClickResult ,
53
54
CancellationTokenSource ,
@@ -115,19 +116,12 @@ export function registerLanguageServerEventListener(languageClient: LanguageClie
115
116
chatOptions . quickActions . quickActionsCommandGroups [ 0 ] . groupName = 'Quick Actions'
116
117
}
117
118
118
- provider . onDidResolveWebview ( ( ) => {
119
- void provider . webview ?. postMessage ( {
120
- command : CHAT_OPTIONS ,
121
- params : chatOptions ,
122
- } )
123
- } )
124
-
125
119
// This passes through metric data from LSP events to Toolkit telemetry with all fields from the LSP server
126
120
languageClient . onTelemetry ( ( e ) => {
127
121
const telemetryName : string = e . name
128
122
129
123
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 ) } ` )
131
125
telemetry [ telemetryName as keyof TelemetryBase ] . emit ( e . data )
132
126
}
133
127
} )
@@ -139,6 +133,10 @@ export function registerMessageListeners(
139
133
encryptionKey : Buffer
140
134
) {
141
135
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
+
142
140
provider . webview ?. onDidReceiveMessage ( async ( message ) => {
143
141
languageClient . info ( `[VSCode Client] Received ${ JSON . stringify ( message ) } from chat` )
144
142
@@ -152,7 +150,32 @@ export function registerMessageListeners(
152
150
}
153
151
154
152
const webview = provider . webview
153
+
155
154
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
156
179
case COPY_TO_CLIPBOARD :
157
180
languageClient . info ( '[VSCode Client] Copy to clipboard event received' )
158
181
try {
0 commit comments