Skip to content

Commit 756bf33

Browse files
authored
Expose promise that resolves when chat response is complete, and alert on this (microsoft#182983)
1 parent 356b07b commit 756bf33

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/vs/workbench/contrib/chat/browser/chatWidget.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { alert } from 'vs/base/browser/ui/aria/aria';
67
import * as dom from 'vs/base/browser/dom';
78
import { ITreeContextMenuEvent, ITreeElement } from 'vs/base/browser/ui/tree/tree';
89
import { CancellationToken } from 'vs/base/common/cancellation';
@@ -381,6 +382,13 @@ export class ChatWidget extends Disposable implements IChatWidget {
381382
if (result) {
382383
revealLastElement(this.tree);
383384
this.inputPart.acceptInput(query);
385+
result.responseCompletePromise.then(() => {
386+
const responses = this.viewModel?.getItems().filter(isResponseVM);
387+
const lastResponse: IInteractiveResponseViewModel | undefined = responses?.[responses.length - 1];
388+
if (lastResponse) {
389+
alert(lastResponse.response.value);
390+
}
391+
});
384392
}
385393
}
386394
}

src/vs/workbench/contrib/chat/common/chatService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export interface IChatService {
184184
/**
185185
* Returns whether the request was accepted.
186186
*/
187-
sendRequest(sessionId: string, message: string | IChatReplyFollowup): Promise<boolean>;
187+
sendRequest(sessionId: string, message: string | IChatReplyFollowup): Promise<{ responseCompletePromise: Promise<void> } | undefined>;
188188
cancelCurrentRequestForSession(sessionId: string): void;
189189
getSlashCommands(sessionId: string, token: CancellationToken): Promise<ISlashCommand[] | undefined>;
190190
clearSession(sessionId: string): void;

src/vs/workbench/contrib/chat/common/chatServiceImpl.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,12 @@ export class ChatService extends Disposable implements IChatService {
309309
return this._startSession(data.providerId, data, CancellationToken.None);
310310
}
311311

312-
async sendRequest(sessionId: string, request: string | IChatReplyFollowup): Promise<boolean> {
312+
async sendRequest(sessionId: string, request: string | IChatReplyFollowup): Promise<{ responseCompletePromise: Promise<void> } | undefined> {
313313
const messageText = typeof request === 'string' ? request : request.message;
314314
this.trace('sendRequest', `sessionId: ${sessionId}, message: ${messageText.substring(0, 20)}${messageText.length > 20 ? '[...]' : ''}}`);
315315
if (!messageText.trim()) {
316316
this.trace('sendRequest', 'Rejected empty message');
317-
return false;
317+
return;
318318
}
319319

320320
const model = this._sessionModels.get(sessionId);
@@ -330,12 +330,11 @@ export class ChatService extends Disposable implements IChatService {
330330

331331
if (this._pendingRequests.has(sessionId)) {
332332
this.trace('sendRequest', `Session ${sessionId} already has a pending request`);
333-
return false;
333+
return;
334334
}
335335

336336
// This method is only returning whether the request was accepted - don't block on the actual request
337-
this._sendRequestAsync(model, provider, request);
338-
return true;
337+
return { responseCompletePromise: this._sendRequestAsync(model, provider, request) };
339338
}
340339

341340
private async _sendRequestAsync(model: ChatModel, provider: IChatProvider, message: string | IChatReplyFollowup): Promise<void> {
@@ -412,6 +411,7 @@ export class ChatService extends Disposable implements IChatService {
412411
rawResponsePromise.finally(() => {
413412
this._pendingRequests.delete(model.sessionId);
414413
});
414+
return rawResponsePromise;
415415
}
416416

417417
private async handleSlashCommand(sessionId: string, command: string): Promise<string> {

0 commit comments

Comments
 (0)