diff --git a/src/codewhispererChat/clients/chat/v0/chat.ts b/src/codewhispererChat/clients/chat/v0/chat.ts index eb68f441315..0d753fbf949 100644 --- a/src/codewhispererChat/clients/chat/v0/chat.ts +++ b/src/codewhispererChat/clients/chat/v0/chat.ts @@ -29,6 +29,10 @@ export class ChatSession { this.tokenSource = new vscode.CancellationTokenSource() } + public setSessionID(id?: string){ + this.sessionId = id + } + async chat(chatRequest: GenerateAssistantResponseRequest): Promise { this.client = await new CodeWhispererStreamingClient().createSdkClient() @@ -43,15 +47,6 @@ export class ChatSession { ) } - // read the first event to get conversation id. - // this assumes that the metadataEvent is the first event in the response stream. - for await (const event of response.generateAssistantResponseResponse) { - if (event.messageMetadataEvent !== undefined) { - this.sessionId = event.messageMetadataEvent!.conversationId - } - break - } - return response } } diff --git a/src/codewhispererChat/controllers/chat/messenger/messenger.ts b/src/codewhispererChat/controllers/chat/messenger/messenger.ts index 079326923ed..70cc3e1331c 100644 --- a/src/codewhispererChat/controllers/chat/messenger/messenger.ts +++ b/src/codewhispererChat/controllers/chat/messenger/messenger.ts @@ -115,6 +115,10 @@ export class Messenger { } } + if (chatEvent.messageMetadataEvent !== undefined) { + session.setSessionID(chatEvent.messageMetadataEvent!.conversationId) + } + if (session.tokenSource.token.isCancellationRequested) { return true }