@@ -14,6 +14,8 @@ import {
1414 UiMessageResultParams ,
1515 CHAT_PROMPT_OPTION_ACKNOWLEDGED ,
1616 ChatPromptOptionAcknowledgedMessage ,
17+ STOP_CHAT_RESPONSE ,
18+ StopChatResponseMessage ,
1719} from '@aws/chat-client-ui-types'
1820import {
1921 ChatResult ,
@@ -98,6 +100,7 @@ export function registerMessageListeners(
98100 provider : AmazonQChatViewProvider ,
99101 encryptionKey : Buffer
100102) {
103+ const chatStreamTokens = new Map < string , CancellationTokenSource > ( ) // tab id -> token
101104 provider . webview ?. onDidReceiveMessage ( async ( message ) => {
102105 languageClient . info ( `[VSCode Client] Received ${ JSON . stringify ( message ) } from chat` )
103106
@@ -110,8 +113,6 @@ export function registerMessageListeners(
110113 return
111114 }
112115
113- const chatStreamTokens = new Map < string , CancellationTokenSource > ( ) // tab id -> token
114-
115116 const webview = provider . webview
116117 switch ( message . command ) {
117118 case COPY_TO_CLIPBOARD :
@@ -184,8 +185,8 @@ export function registerMessageListeners(
184185 void openUrl ( vscode . Uri . parse ( linkParams . link ) )
185186 break
186187 }
187- case STOP_RESPONSE : {
188- const tabId = ( message as StopResponseMessage ) . tabId
188+ case STOP_CHAT_RESPONSE : {
189+ const tabId = ( message as StopChatResponseMessage ) . params . tabId
189190 const token = chatStreamTokens . get ( tabId )
190191 token ?. cancel ( )
191192 token ?. dispose ( )
@@ -226,10 +227,14 @@ export function registerMessageListeners(
226227
227228 const chatRequest = await encryptRequest < ChatParams > ( chatParams , encryptionKey )
228229 try {
229- const chatResult = await languageClient . sendRequest < string | ChatResult > ( chatRequestType . method , {
230- ...chatRequest ,
231- partialResultToken,
232- } )
230+ const chatResult = await languageClient . sendRequest < string | ChatResult > (
231+ chatRequestType . method ,
232+ {
233+ ...chatRequest ,
234+ partialResultToken,
235+ } ,
236+ cancellationToken . token
237+ )
233238 await handleCompleteResult < ChatResult > (
234239 chatResult ,
235240 encryptionKey ,
0 commit comments