Skip to content

Commit a54a2c5

Browse files
committed
add chatAccessibilityService
1 parent e94b3ef commit a54a2c5

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

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

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ export interface IChatWidgetStyles {
5353
resultEditorBackground: string;
5454
}
5555

56-
const CHAT_RESPONSE_PENDING_AUDIO_CUE_LOOP_MS = 7000;
57-
5856
export class ChatWidget extends Disposable implements IChatWidget {
5957
public static readonly CONTRIBS: { new(...args: [IChatWidget, ...any]): any }[] = [];
6058

@@ -110,6 +108,8 @@ export class ChatWidget extends Disposable implements IChatWidget {
110108
private lastSlashCommands: ISlashCommand[] | undefined;
111109
private slashCommandsPromise: Promise<ISlashCommand[] | undefined> | undefined;
112110

111+
private _chatAccessibilityService: ChatAccessibilityService;
112+
113113
constructor(
114114
readonly viewContext: IChatWidgetViewContext,
115115
private readonly styles: IChatWidgetStyles,
@@ -118,13 +118,14 @@ export class ChatWidget extends Disposable implements IChatWidget {
118118
@IChatService private readonly chatService: IChatService,
119119
@IChatWidgetService chatWidgetService: IChatWidgetService,
120120
@IContextMenuService private readonly contextMenuService: IContextMenuService,
121-
@IAudioCueService private readonly audioCueService: IAudioCueService
121+
@IAudioCueService audioCueService: IAudioCueService
122122
) {
123123
super();
124124
CONTEXT_IN_CHAT_SESSION.bindTo(contextKeyService).set(true);
125125
this.requestInProgress = CONTEXT_CHAT_REQUEST_IN_PROGRESS.bindTo(contextKeyService);
126126

127127
this._register((chatWidgetService as ChatWidgetService).register(this));
128+
this._chatAccessibilityService = new ChatAccessibilityService(audioCueService);
128129
}
129130

130131
get providerId(): string {
@@ -392,22 +393,17 @@ export class ChatWidget extends Disposable implements IChatWidget {
392393
this.instantiationService.invokeFunction(clearChatSession, this);
393394
return;
394395
}
395-
this.audioCueService.playAudioCue(AudioCue.chatRequestSent, true);
396-
const responsePendingAudioCue = this.audioCueService.playAudioCueLoop(AudioCue.chatResponsePending, CHAT_RESPONSE_PENDING_AUDIO_CUE_LOOP_MS);
396+
this._chatAccessibilityService.acceptRequest();
397397
const input = query ?? editorValue;
398398
const result = await this.chatService.sendRequest(this.viewModel.sessionId, input);
399399

400400
if (result) {
401401
this.inputPart.acceptInput(query);
402402
result.responseCompletePromise.then(async () => {
403-
responsePendingAudioCue?.dispose();
404-
this.audioCueService.playRandomAudioCue(AudioCueGroupId.chatResponseReceived, true);
403+
405404
const responses = this.viewModel?.getItems().filter(isResponseVM);
406405
const lastResponse = responses?.[responses.length - 1];
407-
if (lastResponse) {
408-
const errorDetails = lastResponse.errorDetails ? ` ${lastResponse.errorDetails.message}` : '';
409-
alert(lastResponse.response.value + errorDetails);
410-
}
406+
this._chatAccessibilityService.acceptResponse(lastResponse);
411407
});
412408
}
413409
}
@@ -513,3 +509,25 @@ export class ChatWidgetService implements IChatWidgetService {
513509
);
514510
}
515511
}
512+
513+
const CHAT_RESPONSE_PENDING_AUDIO_CUE_LOOP_MS = 7000;
514+
class ChatAccessibilityService extends Disposable {
515+
private _responsePendingAudioCue: IDisposable | undefined;
516+
constructor(@IAudioCueService private readonly _audioCueService: IAudioCueService) {
517+
super();
518+
}
519+
acceptRequest(): void {
520+
this._audioCueService.playAudioCue(AudioCue.chatRequestSent, true);
521+
this._responsePendingAudioCue = this._audioCueService.playAudioCueLoop(AudioCue.chatResponsePending, CHAT_RESPONSE_PENDING_AUDIO_CUE_LOOP_MS);
522+
}
523+
acceptResponse(response?: IChatResponseViewModel): void {
524+
this._responsePendingAudioCue?.dispose();
525+
if (!response) {
526+
return;
527+
}
528+
this._audioCueService.playRandomAudioCue(AudioCueGroupId.chatResponseReceived, true);
529+
const errorDetails = response.errorDetails ? ` ${response.errorDetails.message}` : '';
530+
alert(response.response.value + errorDetails);
531+
}
532+
}
533+

0 commit comments

Comments
 (0)