@@ -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 ,
@@ -114,37 +115,6 @@ export function registerLanguageServerEventListener(languageClient: LanguageClie
114
115
chatOptions . quickActions . quickActionsCommandGroups [ 0 ] . groupName = 'Quick Actions'
115
116
}
116
117
117
- provider . onDidResolveWebview ( ( ) => {
118
- // Give the webview a moment to fully initialize before sending messages
119
- setTimeout ( ( ) => {
120
- if ( provider . webview ) {
121
- // Ensure webview is ready and properly initialized
122
- const sendPromise = provider . webview
123
- . postMessage ( {
124
- command : CHAT_OPTIONS ,
125
- params : chatOptions ,
126
- } )
127
- . then ( ( ) => {
128
- // Log success only after message is confirmed sent
129
- const quickActionCommands =
130
- chatOptions ?. quickActions ?. quickActionsCommandGroups ?. [ 0 ] ?. commands || [ ]
131
- const quickActionsDisplay = quickActionCommands . map ( ( cmd : any ) => cmd . command ) . join ( ', ' )
132
- languageClient . info (
133
- `[VSCode Client] Chat options flags: mcpServers=${ chatOptions ?. mcpServers } , history=${ chatOptions ?. history } , export=${ chatOptions ?. export } , quickActions=[${ quickActionsDisplay } ]`
134
- )
135
- } )
136
-
137
- // Handle potential errors separately since PromiseLike might not have catch
138
- sendPromise . then ( undefined , ( err : Error ) => {
139
- // Log any errors that occur during message sending
140
- languageClient . error ( `[VSCode Client] Failed to send CHAT_OPTIONS: ${ err . message } ` )
141
- } )
142
- } else {
143
- languageClient . warn ( `[VSCode Client] Cannot send CHAT_OPTIONS: webview is not available` )
144
- }
145
- } , 100 ) // Short delay of 100ms to ensure webview is ready
146
- } )
147
-
148
118
// This passes through metric data from LSP events to Toolkit telemetry with all fields from the LSP server
149
119
languageClient . onTelemetry ( ( e ) => {
150
120
const telemetryName : string = e . name
@@ -177,6 +147,10 @@ export function registerMessageListeners(
177
147
encryptionKey : Buffer
178
148
) {
179
149
const chatStreamTokens = new Map < string , CancellationTokenSource > ( ) // tab id -> token
150
+
151
+ // Keep track of pending chat options to send when webview UI is ready
152
+ const pendingChatOptions = languageClient . initializeResult ?. awsServerCapabilities ?. chatOptions
153
+
180
154
provider . webview ?. onDidReceiveMessage ( async ( message ) => {
181
155
languageClient . info ( `[VSCode Client] Received ${ JSON . stringify ( message ) } from chat` )
182
156
@@ -190,7 +164,32 @@ export function registerMessageListeners(
190
164
}
191
165
192
166
const webview = provider . webview
167
+
193
168
switch ( message . command ) {
169
+ // Handle "aws/chat/ready" event
170
+ case READY_NOTIFICATION_METHOD :
171
+ languageClient . info ( `[VSCode Client] "aws/chat/ready" event is received, sending chat options` )
172
+ if ( webview && pendingChatOptions ) {
173
+ try {
174
+ await webview . postMessage ( {
175
+ command : CHAT_OPTIONS ,
176
+ params : pendingChatOptions ,
177
+ } )
178
+
179
+ // Display a more readable representation of quick actions
180
+ const quickActionCommands =
181
+ pendingChatOptions ?. quickActions ?. quickActionsCommandGroups ?. [ 0 ] ?. commands || [ ]
182
+ const quickActionsDisplay = quickActionCommands . map ( ( cmd : any ) => cmd . command ) . join ( ', ' )
183
+ languageClient . info (
184
+ `[VSCode Client] Chat options flags: mcpServers=${ pendingChatOptions ?. mcpServers } , history=${ pendingChatOptions ?. history } , export=${ pendingChatOptions ?. export } , quickActions=[${ quickActionsDisplay } ]`
185
+ )
186
+ } catch ( err ) {
187
+ languageClient . error (
188
+ `[VSCode Client] Failed to send CHAT_OPTIONS after "aws/chat/ready" event: ${ ( err as Error ) . message } `
189
+ )
190
+ }
191
+ }
192
+ break
194
193
case COPY_TO_CLIPBOARD :
195
194
languageClient . info ( '[VSCode Client] Copy to clipboard event received' )
196
195
try {
0 commit comments