@@ -41,7 +41,7 @@ import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storag
41
41
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry' ;
42
42
import { InteractiveEditorDiffWidget } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorDiffWidget' ;
43
43
import { InteractiveEditorZoneWidget } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorWidget' ;
44
- import { CTX_INTERACTIVE_EDITOR_HAS_ACTIVE_REQUEST , CTX_INTERACTIVE_EDITOR_INLNE_DIFF , CTX_INTERACTIVE_EDITOR_LAST_EDIT_TYPE as CTX_INTERACTIVE_EDITOR_LAST_EDIT_KIND , CTX_INTERACTIVE_EDITOR_LAST_FEEDBACK as CTX_INTERACTIVE_EDITOR_LAST_FEEDBACK_KIND , IInteractiveEditorBulkEditResponse , IInteractiveEditorEditResponse , IInteractiveEditorRequest , IInteractiveEditorResponse , IInteractiveEditorService , IInteractiveEditorSession , IInteractiveEditorSessionProvider , IInteractiveEditorSlashCommand , INTERACTIVE_EDITOR_ID , EditMode , InteractiveEditorResponseFeedbackKind , CTX_INTERACTIVE_EDITOR_LAST_RESPONSE_TYPE , InteractiveEditorResponseType } from 'vs/workbench/contrib/interactiveEditor/common/interactiveEditor' ;
44
+ import { CTX_INTERACTIVE_EDITOR_HAS_ACTIVE_REQUEST , CTX_INTERACTIVE_EDITOR_INLNE_DIFF , CTX_INTERACTIVE_EDITOR_LAST_EDIT_TYPE as CTX_INTERACTIVE_EDITOR_LAST_EDIT_KIND , CTX_INTERACTIVE_EDITOR_LAST_FEEDBACK as CTX_INTERACTIVE_EDITOR_LAST_FEEDBACK_KIND , IInteractiveEditorBulkEditResponse , IInteractiveEditorEditResponse , IInteractiveEditorRequest , IInteractiveEditorResponse , IInteractiveEditorService , IInteractiveEditorSession , IInteractiveEditorSessionProvider , IInteractiveEditorSlashCommand , INTERACTIVE_EDITOR_ID , EditMode , InteractiveEditorResponseFeedbackKind , CTX_INTERACTIVE_EDITOR_LAST_RESPONSE_TYPE , InteractiveEditorResponseType , IInteractiveEditorMessageResponse } from 'vs/workbench/contrib/interactiveEditor/common/interactiveEditor' ;
45
45
import { IInteractiveSessionWidgetService } from 'vs/workbench/contrib/interactiveSession/browser/interactiveSessionWidget' ;
46
46
import { IInteractiveSessionService } from 'vs/workbench/contrib/interactiveSession/common/interactiveSessionService' ;
47
47
import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/services/notebookEditorService' ;
@@ -217,7 +217,7 @@ export class EditResponse {
217
217
218
218
class Session {
219
219
220
- private readonly _responses : EditResponse [ ] = [ ] ;
220
+ private readonly _responses : ( EditResponse | IInteractiveEditorMessageResponse ) [ ] = [ ] ;
221
221
222
222
readonly teldata : TelemetryData ;
223
223
@@ -240,12 +240,12 @@ class Session {
240
240
} ;
241
241
}
242
242
243
- addResponse ( response : EditResponse ) : void {
243
+ addResponse ( response : EditResponse | IInteractiveEditorMessageResponse ) : void {
244
244
const newLen = this . _responses . push ( response ) ;
245
245
this . teldata . rounds += `${ newLen } |` ;
246
246
}
247
247
248
- get lastResponse ( ) : EditResponse | undefined {
248
+ get lastResponse ( ) : EditResponse | IInteractiveEditorMessageResponse | undefined {
249
249
return this . _responses [ this . _responses . length - 1 ] ;
250
250
}
251
251
}
@@ -297,6 +297,9 @@ export class InteractiveEditorController implements IEditorContribution {
297
297
private _ctsSession : CancellationTokenSource = new CancellationTokenSource ( ) ;
298
298
private _ctsRequest ?: CancellationTokenSource ;
299
299
300
+ private _requestPrompt : string | undefined ;
301
+ private _messageReply : string | undefined ;
302
+
300
303
constructor (
301
304
private readonly _editor : ICodeEditor ,
302
305
@IInstantiationService private readonly _instaService : IInstantiationService ,
@@ -333,6 +336,12 @@ export class InteractiveEditorController implements IEditorContribution {
333
336
return this . _configurationService . getValue ( 'interactiveEditor.editMode' ) ;
334
337
}
335
338
339
+ viewInChat ( ) {
340
+ if ( this . _messageReply && this . _requestPrompt ) {
341
+ this . _instaService . invokeFunction ( showMessageResponse , this . _requestPrompt , this . _messageReply ) ;
342
+ }
343
+ }
344
+
336
345
async run ( options : InteractiveEditorRunOptions | undefined ) : Promise < void > {
337
346
338
347
// hide/cancel inline completions when invoking IE
@@ -403,7 +412,7 @@ export class InteractiveEditorController implements IEditorContribution {
403
412
store . add ( this . _instaService . invokeFunction ( installSlashCommandSupport , this . _zone . widget . inputEditor as IActiveCodeEditor , session . slashCommands ) ) ;
404
413
}
405
414
406
- this . _zone . widget . updateMessage ( session . message ?? localize ( 'welcome.1' , "AI-generated code may be incorrect." ) ) ;
415
+ this . _zone . widget . updateStatus ( session . message ?? localize ( 'welcome.1' , "AI-generated code may be incorrect." ) ) ;
407
416
408
417
// CANCEL when input changes
409
418
this . _editor . onDidChangeModel ( this . cancelSession , this , store ) ;
@@ -535,7 +544,7 @@ export class InteractiveEditorController implements IEditorContribution {
535
544
if ( ! isCancellationError ( e ) ) {
536
545
this . _logService . error ( '[IE] ERROR during request' , provider . debugName ) ;
537
546
this . _logService . error ( e ) ;
538
- this . _zone . widget . updateMessage ( toErrorMessage ( e ) , { classes : [ 'error' ] } ) ;
547
+ this . _zone . widget . updateStatus ( toErrorMessage ( e ) , { classes : [ 'error' ] } ) ;
539
548
// statusWidget
540
549
continue ;
541
550
}
@@ -553,7 +562,7 @@ export class InteractiveEditorController implements IEditorContribution {
553
562
554
563
if ( ! reply ) {
555
564
this . _logService . trace ( '[IE] NO reply or edits' , provider . debugName ) ;
556
- this . _zone . widget . updateMessage ( localize ( 'empty' , "No results, please refine your input and try again." ) , { classes : [ 'warn' ] } ) ;
565
+ this . _zone . widget . updateStatus ( localize ( 'empty' , "No results, please refine your input and try again." ) , { classes : [ 'warn' ] } ) ;
557
566
continue ;
558
567
}
559
568
@@ -563,9 +572,11 @@ export class InteractiveEditorController implements IEditorContribution {
563
572
564
573
if ( reply . type === 'message' ) {
565
574
this . _logService . info ( '[IE] received a MESSAGE, continuing outside editor' , provider . debugName ) ;
566
- const messageReply = reply . message ;
567
- const renderedMarkdown = renderMarkdown ( messageReply , { inline : true } ) ;
568
- this . _zone . widget . updateMessage ( renderedMarkdown . element , { linkListener : ( ) => this . _instaService . invokeFunction ( showMessageResponse , request . prompt , messageReply . value ) , isMessageReply : true } ) ;
575
+ this . _messageReply = reply . message . value ;
576
+ this . _requestPrompt = request . prompt ;
577
+ const renderedMarkdown = renderMarkdown ( reply . message , { inline : true } ) ;
578
+ this . _zone . widget . updateMarkdownMessage ( renderedMarkdown . element ) ;
579
+ this . _currentSession . addResponse ( reply ) ;
569
580
continue ;
570
581
}
571
582
@@ -655,7 +666,7 @@ export class InteractiveEditorController implements IEditorContribution {
655
666
} else {
656
667
message = localize ( 'lines.N' , "Generated reply and changed {0} lines." , linesChanged ) ;
657
668
}
658
- this . _zone . widget . updateMessage ( message ) ;
669
+ this . _zone . widget . updateStatus ( message ) ;
659
670
}
660
671
661
672
@@ -777,7 +788,7 @@ export class InteractiveEditorController implements IEditorContribution {
777
788
}
778
789
779
790
undoLast ( ) : string | void {
780
- if ( this . _currentSession ?. lastResponse ) {
791
+ if ( this . _currentSession ?. lastResponse instanceof EditResponse ) {
781
792
this . _currentSession . modelN . undo ( ) ;
782
793
return this . _currentSession . lastResponse . localEdits [ 0 ] . text ;
783
794
}
@@ -786,14 +797,14 @@ export class InteractiveEditorController implements IEditorContribution {
786
797
feedbackLast ( helpful : boolean ) {
787
798
if ( this . _currentSession ?. lastResponse ) {
788
799
const kind = helpful ? InteractiveEditorResponseFeedbackKind . Helpful : InteractiveEditorResponseFeedbackKind . Unhelpful ;
789
- this . _currentSession . provider . handleInteractiveEditorResponseFeedback ?.( this . _currentSession . session , this . _currentSession . lastResponse . raw , kind ) ;
800
+ this . _currentSession . provider . handleInteractiveEditorResponseFeedback ?.( this . _currentSession . session , this . _currentSession . lastResponse instanceof EditResponse ? this . _currentSession . lastResponse . raw : this . _currentSession . lastResponse , kind ) ;
790
801
this . _ctxLastFeedbackKind . set ( helpful ? 'helpful' : 'unhelpful' ) ;
791
- this . _zone . widget . updateMessage ( 'Thank you for your feedback!' , { resetAfter : 1250 } ) ;
802
+ this . _zone . widget . updateStatus ( 'Thank you for your feedback!' , { resetAfter : 1250 } ) ;
792
803
}
793
804
}
794
805
795
806
async applyChanges ( ) : Promise < EditResponse | void > {
796
- if ( this . _currentSession ?. lastResponse ) {
807
+ if ( this . _currentSession ?. lastResponse instanceof EditResponse ) {
797
808
const { lastResponse } = this . _currentSession ;
798
809
await this . _strategy ?. apply ( ) ;
799
810
this . _ctsSession . cancel ( ) ;
@@ -845,7 +856,7 @@ class PreviewStrategy extends EditModeStrategy {
845
856
async apply ( ) {
846
857
847
858
const response = this . _session . lastResponse ;
848
- if ( ! response ) {
859
+ if ( ! ( response instanceof EditResponse ) ) {
849
860
return ;
850
861
}
851
862
@@ -1007,7 +1018,8 @@ async function showMessageResponse(accessor: ServicesAccessor, query: string, re
1007
1018
const interactiveSessionWidgetService = accessor . get ( IInteractiveSessionWidgetService ) ;
1008
1019
const widget = await interactiveSessionWidgetService . revealViewForProvider ( providerId ) ;
1009
1020
if ( widget && widget . viewModel ) {
1010
- interactiveSessionService . addCompleteRequest ( widget . viewModel . sessionId , query , { message : response } ) ;
1021
+ await interactiveSessionService . addCompleteRequest ( widget . viewModel . sessionId , query , { message : response } ) ;
1022
+ widget . focusLastMessage ( ) ;
1011
1023
}
1012
1024
}
1013
1025
0 commit comments