@@ -160,21 +160,26 @@ class VoiceChatSessionControllerFactory {
160
160
}
161
161
}
162
162
163
- class VoiceChatSession {
163
+ interface ActiveVoiceChatSession {
164
+ readonly controller : IVoiceChatSessionController ;
165
+ readonly disposables : DisposableStore ;
166
+ }
167
+
168
+ class VoiceChatSessions {
164
169
165
- private static instance : VoiceChatSession | undefined = undefined ;
166
- static getInstance ( instantiationService : IInstantiationService ) : VoiceChatSession {
167
- if ( ! VoiceChatSession . instance ) {
168
- VoiceChatSession . instance = instantiationService . createInstance ( VoiceChatSession ) ;
170
+ private static instance : VoiceChatSessions | undefined = undefined ;
171
+ static getInstance ( instantiationService : IInstantiationService ) : VoiceChatSessions {
172
+ if ( ! VoiceChatSessions . instance ) {
173
+ VoiceChatSessions . instance = instantiationService . createInstance ( VoiceChatSessions ) ;
169
174
}
170
175
171
- return VoiceChatSession . instance ;
176
+ return VoiceChatSessions . instance ;
172
177
}
173
178
174
179
private voiceChatInProgressKey = CONTEXT_VOICE_CHAT_IN_PROGRESS . bindTo ( this . contextKeyService ) ;
175
180
private voiceChatGettingReadyKey = CONTEXT_VOICE_CHAT_GETTING_READY . bindTo ( this . contextKeyService ) ;
176
181
177
- private currentVoiceChatSession : DisposableStore | undefined = undefined ;
182
+ private currentVoiceChatSession : ActiveVoiceChatSession | undefined = undefined ;
178
183
private voiceChatSessionIds = 0 ;
179
184
180
185
constructor (
@@ -186,14 +191,18 @@ class VoiceChatSession {
186
191
this . stop ( ) ;
187
192
188
193
const voiceChatSessionId = ++ this . voiceChatSessionIds ;
189
- this . currentVoiceChatSession = new DisposableStore ( ) ;
194
+ this . currentVoiceChatSession = {
195
+ controller,
196
+ disposables : new DisposableStore ( )
197
+ } ;
190
198
191
199
const cts = new CancellationTokenSource ( ) ;
192
- this . currentVoiceChatSession . add ( toDisposable ( ( ) => cts . dispose ( true ) ) ) ;
200
+ this . currentVoiceChatSession . disposables . add ( toDisposable ( ( ) => cts . dispose ( true ) ) ) ;
193
201
194
- this . currentVoiceChatSession . add ( controller . onDidAcceptInput ( ( ) => this . stop ( voiceChatSessionId ) ) ) ;
195
- this . currentVoiceChatSession . add ( controller . onDidCancelInput ( ( ) => this . stop ( voiceChatSessionId ) ) ) ;
202
+ this . currentVoiceChatSession . disposables . add ( controller . onDidAcceptInput ( ( ) => this . stop ( voiceChatSessionId ) ) ) ;
203
+ this . currentVoiceChatSession . disposables . add ( controller . onDidCancelInput ( ( ) => this . stop ( voiceChatSessionId ) ) ) ;
196
204
205
+ controller . updateInput ( '' ) ;
197
206
controller . focusInput ( ) ;
198
207
199
208
this . voiceChatGettingReadyKey . set ( true ) ;
@@ -209,14 +218,14 @@ class VoiceChatSession {
209
218
this . voiceChatGettingReadyKey . set ( false ) ;
210
219
this . voiceChatInProgressKey . set ( true ) ;
211
220
212
- this . registerTranscriptionListener ( controller , onDidTranscribe , this . currentVoiceChatSession ) ;
221
+ this . registerTranscriptionListener ( this . currentVoiceChatSession , onDidTranscribe ) ;
213
222
}
214
223
215
- private registerTranscriptionListener ( controller : IVoiceChatSessionController , onDidTranscribe : Event < string > , disposables : DisposableStore ) {
224
+ private registerTranscriptionListener ( session : ActiveVoiceChatSession , onDidTranscribe : Event < string > ) {
216
225
let lastText : string | undefined = undefined ;
217
226
let lastTextSimilarCount = 0 ;
218
227
219
- disposables . add ( onDidTranscribe ( text => {
228
+ session . disposables . add ( onDidTranscribe ( text => {
220
229
if ( ! text && lastText ) {
221
230
text = lastText ;
222
231
}
@@ -230,9 +239,9 @@ class VoiceChatSession {
230
239
}
231
240
232
241
if ( lastTextSimilarCount >= 2 ) {
233
- controller . acceptInput ( ) ;
242
+ session . controller . acceptInput ( ) ;
234
243
} else {
235
- controller . updateInput ( text ) ;
244
+ session . controller . updateInput ( text ) ;
236
245
}
237
246
238
247
}
@@ -261,12 +270,23 @@ class VoiceChatSession {
261
270
return ;
262
271
}
263
272
264
- this . currentVoiceChatSession . dispose ( ) ;
273
+ this . currentVoiceChatSession . disposables . dispose ( ) ;
265
274
this . currentVoiceChatSession = undefined ;
266
275
267
276
this . voiceChatGettingReadyKey . set ( false ) ;
268
277
this . voiceChatInProgressKey . set ( false ) ;
269
278
}
279
+
280
+ accept ( voiceChatSessionId = this . voiceChatSessionIds ) : void {
281
+ if (
282
+ ! this . currentVoiceChatSession ||
283
+ this . voiceChatSessionIds !== voiceChatSessionId
284
+ ) {
285
+ return ;
286
+ }
287
+
288
+ this . currentVoiceChatSession . controller . acceptInput ( ) ;
289
+ }
270
290
}
271
291
272
292
class VoiceChatInChatViewAction extends Action2 {
@@ -291,7 +311,7 @@ class VoiceChatInChatViewAction extends Action2 {
291
311
292
312
const controller = await VoiceChatSessionControllerFactory . create ( accessor , 'view' ) ;
293
313
if ( controller ) {
294
- VoiceChatSession . getInstance ( instantiationService ) . start ( controller ) ;
314
+ VoiceChatSessions . getInstance ( instantiationService ) . start ( controller ) ;
295
315
}
296
316
}
297
317
}
@@ -318,7 +338,7 @@ class InlineVoiceChatAction extends Action2 {
318
338
319
339
const controller = await VoiceChatSessionControllerFactory . create ( accessor , 'inline' ) ;
320
340
if ( controller ) {
321
- VoiceChatSession . getInstance ( instantiationService ) . start ( controller ) ;
341
+ VoiceChatSessions . getInstance ( instantiationService ) . start ( controller ) ;
322
342
}
323
343
}
324
344
}
@@ -345,7 +365,7 @@ class QuickVoiceChatAction extends Action2 {
345
365
346
366
const controller = await VoiceChatSessionControllerFactory . create ( accessor , 'quick' ) ;
347
367
if ( controller ) {
348
- VoiceChatSession . getInstance ( instantiationService ) . start ( controller ) ;
368
+ VoiceChatSessions . getInstance ( instantiationService ) . start ( controller ) ;
349
369
}
350
370
}
351
371
}
@@ -391,7 +411,7 @@ class StartVoiceChatAction extends Action2 {
391
411
392
412
const controller = await VoiceChatSessionControllerFactory . create ( accessor , 'focussed' ) ;
393
413
if ( controller ) {
394
- VoiceChatSession . getInstance ( instantiationService ) . start ( controller ) ;
414
+ VoiceChatSessions . getInstance ( instantiationService ) . start ( controller ) ;
395
415
} else {
396
416
// fallback to Quick Voice Chat command
397
417
commandService . executeCommand ( QuickVoiceChatAction . ID ) ;
@@ -434,7 +454,29 @@ class StopVoiceChatAction extends Action2 {
434
454
}
435
455
436
456
run ( accessor : ServicesAccessor ) : void {
437
- VoiceChatSession . getInstance ( accessor . get ( IInstantiationService ) ) . stop ( ) ;
457
+ VoiceChatSessions . getInstance ( accessor . get ( IInstantiationService ) ) . stop ( ) ;
458
+ }
459
+ }
460
+
461
+ class StopVoiceChatAndSubmitAction extends Action2 {
462
+
463
+ static readonly ID = 'workbench.action.chat.stopVoiceChatAndSubmit' ;
464
+
465
+ constructor ( ) {
466
+ super ( {
467
+ id : StopVoiceChatAndSubmitAction . ID ,
468
+ title : {
469
+ value : localize ( 'workbench.action.chat.stopAndAcceptVoiceChat.label' , "Stop Voice Chat and Submit" ) ,
470
+ original : 'Stop Voice Chat and Submit'
471
+ } ,
472
+ category : CHAT_CATEGORY ,
473
+ f1 : true ,
474
+ precondition : CONTEXT_VOICE_CHAT_IN_PROGRESS
475
+ } ) ;
476
+ }
477
+
478
+ run ( accessor : ServicesAccessor ) : void {
479
+ VoiceChatSessions . getInstance ( accessor . get ( IInstantiationService ) ) . accept ( ) ;
438
480
}
439
481
}
440
482
@@ -446,5 +488,6 @@ export function registerVoiceChatActions() {
446
488
447
489
registerAction2 ( StartVoiceChatAction ) ;
448
490
registerAction2 ( StopVoiceChatAction ) ;
491
+ registerAction2 ( StopVoiceChatAndSubmitAction ) ;
449
492
}
450
493
}
0 commit comments