@@ -53,8 +53,6 @@ export interface IChatWidgetStyles {
53
53
resultEditorBackground : string ;
54
54
}
55
55
56
- const CHAT_RESPONSE_PENDING_AUDIO_CUE_LOOP_MS = 7000 ;
57
-
58
56
export class ChatWidget extends Disposable implements IChatWidget {
59
57
public static readonly CONTRIBS : { new ( ...args : [ IChatWidget , ...any ] ) : any } [ ] = [ ] ;
60
58
@@ -110,6 +108,8 @@ export class ChatWidget extends Disposable implements IChatWidget {
110
108
private lastSlashCommands : ISlashCommand [ ] | undefined ;
111
109
private slashCommandsPromise : Promise < ISlashCommand [ ] | undefined > | undefined ;
112
110
111
+ private _chatAccessibilityService : ChatAccessibilityService ;
112
+
113
113
constructor (
114
114
readonly viewContext : IChatWidgetViewContext ,
115
115
private readonly styles : IChatWidgetStyles ,
@@ -118,13 +118,14 @@ export class ChatWidget extends Disposable implements IChatWidget {
118
118
@IChatService private readonly chatService : IChatService ,
119
119
@IChatWidgetService chatWidgetService : IChatWidgetService ,
120
120
@IContextMenuService private readonly contextMenuService : IContextMenuService ,
121
- @IAudioCueService private readonly audioCueService : IAudioCueService
121
+ @IAudioCueService audioCueService : IAudioCueService
122
122
) {
123
123
super ( ) ;
124
124
CONTEXT_IN_CHAT_SESSION . bindTo ( contextKeyService ) . set ( true ) ;
125
125
this . requestInProgress = CONTEXT_CHAT_REQUEST_IN_PROGRESS . bindTo ( contextKeyService ) ;
126
126
127
127
this . _register ( ( chatWidgetService as ChatWidgetService ) . register ( this ) ) ;
128
+ this . _chatAccessibilityService = new ChatAccessibilityService ( audioCueService ) ;
128
129
}
129
130
130
131
get providerId ( ) : string {
@@ -392,22 +393,17 @@ export class ChatWidget extends Disposable implements IChatWidget {
392
393
this . instantiationService . invokeFunction ( clearChatSession , this ) ;
393
394
return ;
394
395
}
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 ( ) ;
397
397
const input = query ?? editorValue ;
398
398
const result = await this . chatService . sendRequest ( this . viewModel . sessionId , input ) ;
399
399
400
400
if ( result ) {
401
401
this . inputPart . acceptInput ( query ) ;
402
402
result . responseCompletePromise . then ( async ( ) => {
403
- responsePendingAudioCue ?. dispose ( ) ;
404
- this . audioCueService . playRandomAudioCue ( AudioCueGroupId . chatResponseReceived , true ) ;
403
+
405
404
const responses = this . viewModel ?. getItems ( ) . filter ( isResponseVM ) ;
406
405
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 ) ;
411
407
} ) ;
412
408
}
413
409
}
@@ -513,3 +509,25 @@ export class ChatWidgetService implements IChatWidgetService {
513
509
) ;
514
510
}
515
511
}
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