Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 25 additions & 4 deletions packages/amazonq/src/lsp/chat/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
UiMessageResultParams,
CHAT_PROMPT_OPTION_ACKNOWLEDGED,
ChatPromptOptionAcknowledgedMessage,
STOP_CHAT_RESPONSE,
StopChatResponseMessage,
} from '@aws/chat-client-ui-types'
import {
ChatResult,
Expand Down Expand Up @@ -42,6 +44,7 @@ import {
LINK_CLICK_NOTIFICATION_METHOD,
LinkClickParams,
INFO_LINK_CLICK_NOTIFICATION_METHOD,
CancellationTokenSource,
} from '@aws/language-server-runtimes/protocol'
import { v4 as uuidv4 } from 'uuid'
import * as vscode from 'vscode'
Expand Down Expand Up @@ -97,6 +100,7 @@ export function registerMessageListeners(
provider: AmazonQChatViewProvider,
encryptionKey: Buffer
) {
const chatStreamTokens = new Map<string, CancellationTokenSource>() // tab id -> token
provider.webview?.onDidReceiveMessage(async (message) => {
languageClient.info(`[VSCode Client] Received ${JSON.stringify(message)} from chat`)

Expand Down Expand Up @@ -181,10 +185,21 @@ export function registerMessageListeners(
void openUrl(vscode.Uri.parse(linkParams.link))
break
}
case STOP_CHAT_RESPONSE: {
const tabId = (message as StopChatResponseMessage).params.tabId
const token = chatStreamTokens.get(tabId)
token?.cancel()
token?.dispose()
chatStreamTokens.delete(tabId)
break
}
case chatRequestType.method: {
const chatParams: ChatParams = { ...message.params }
const partialResultToken = uuidv4()
let lastPartialResult: ChatResult | undefined
const cancellationToken = new CancellationTokenSource()
chatStreamTokens.set(chatParams.tabId, cancellationToken)

const chatDisposable = languageClient.onProgress(
chatRequestType,
partialResultToken,
Expand Down Expand Up @@ -212,10 +227,14 @@ export function registerMessageListeners(

const chatRequest = await encryptRequest<ChatParams>(chatParams, encryptionKey)
try {
const chatResult = await languageClient.sendRequest<string | ChatResult>(chatRequestType.method, {
...chatRequest,
partialResultToken,
})
const chatResult = await languageClient.sendRequest<string | ChatResult>(
chatRequestType.method,
{
...chatRequest,
partialResultToken,
},
cancellationToken.token
)
await handleCompleteResult<ChatResult>(
chatResult,
encryptionKey,
Expand All @@ -240,6 +259,8 @@ export function registerMessageListeners(
chatParams.tabId,
chatDisposable
)
} finally {
chatStreamTokens.delete(chatParams.tabId)
}
break
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@
"devDependencies": {
"@aws-sdk/types": "^3.13.1",
"@aws/chat-client": "^0.1.4",
"@aws/chat-client-ui-types": "^0.1.22",
"@aws/chat-client-ui-types": "^0.1.24",
"@aws/language-server-runtimes": "^0.2.58",
"@aws/language-server-runtimes-types": "^0.1.13",
"@cspotcode/source-map-support": "^0.8.1",
Expand Down
Loading