@@ -26,7 +26,7 @@ import { CellUri, ICellEditOperation } from '../../notebook/common/notebookCommo
26
26
import { IChatAgentCommand , IChatAgentData , IChatAgentResult , IChatAgentService , reviveSerializedAgent } from './chatAgents.js' ;
27
27
import { IChatEditingService , IChatEditingSession } from './chatEditingService.js' ;
28
28
import { ChatRequestTextPart , IParsedChatRequest , reviveParsedChatRequest } from './chatParserTypes.js' ;
29
- import { ChatAgentVoteDirection , ChatAgentVoteDownReason , IChatAgentMarkdownContentWithVulnerability , IChatCodeCitation , IChatCommandButton , IChatConfirmation , IChatContentInlineReference , IChatContentReference , IChatEditingSessionAction , IChatElicitationRequest , IChatExtensionsContent , IChatFollowup , IChatLocationData , IChatMarkdownContent , IChatMultiDiffData , IChatNotebookEdit , IChatPrepareToolInvocationPart , IChatProgress , IChatProgressMessage , IChatPullRequestContent , IChatResponseCodeblockUriPart , IChatResponseProgressFileTreeData , IChatTask , IChatTaskSerialized , IChatTextEdit , IChatToolInvocation , IChatToolInvocationSerialized , IChatTreeData , IChatUndoStop , IChatUsedContext , IChatWarningMessage , isIUsedContext } from './chatService.js' ;
29
+ import { ChatAgentVoteDirection , ChatAgentVoteDownReason , IChatAgentMarkdownContentWithVulnerability , IChatCodeCitation , IChatClearToPreviousToolInvocation , IChatCommandButton , IChatConfirmation , IChatContentInlineReference , IChatContentReference , IChatEditingSessionAction , IChatElicitationRequest , IChatExtensionsContent , IChatFollowup , IChatLocationData , IChatMarkdownContent , IChatMultiDiffData , IChatNotebookEdit , IChatPrepareToolInvocationPart , IChatProgress , IChatProgressMessage , IChatPullRequestContent , IChatResponseCodeblockUriPart , IChatResponseProgressFileTreeData , IChatTask , IChatTaskSerialized , IChatTextEdit , IChatToolInvocation , IChatToolInvocationSerialized , IChatTreeData , IChatUndoStop , IChatUsedContext , IChatWarningMessage , isIUsedContext , ChatResponseClearToPreviousToolInvocationReason } from './chatService.js' ;
30
30
import { IChatRequestVariableEntry } from './chatVariableEntries.js' ;
31
31
import { ChatAgentLocation , ChatModeKind } from './constants.js' ;
32
32
@@ -129,7 +129,8 @@ export type IChatProgressResponseContent =
129
129
| IChatToolInvocationSerialized
130
130
| IChatUndoStop
131
131
| IChatPrepareToolInvocationPart
132
- | IChatElicitationRequest ;
132
+ | IChatElicitationRequest
133
+ | IChatClearToPreviousToolInvocation ;
133
134
134
135
const nonHistoryKinds = new Set ( [ 'toolInvocation' , 'toolInvocationSerialized' , 'undoStop' , 'prepareToolInvocation' ] ) ;
135
136
function isChatProgressHistoryResponseContent ( content : IChatProgressResponseContent ) : content is IChatProgressHistoryResponseContent {
@@ -350,6 +351,10 @@ class AbstractResponse implements IResponse {
350
351
for ( const part of parts ) {
351
352
let segment : { text : string ; isBlock ?: boolean } | undefined ;
352
353
switch ( part . kind ) {
354
+ case 'clearToPreviousToolInvocation' :
355
+ currentBlockSegments = [ ] ;
356
+ blocks . length = 0 ;
357
+ continue ;
353
358
case 'treeData' :
354
359
case 'progressMessage' :
355
360
case 'codeblockUri' :
@@ -465,8 +470,38 @@ export class Response extends AbstractResponse implements IDisposable {
465
470
this . _updateRepr ( true ) ;
466
471
}
467
472
473
+ clearToPreviousToolInvocation ( message ?: string ) : void {
474
+ // look through the response parts and find the last tool invocation, then slice the response parts to that point
475
+ let lastToolInvocationIndex = - 1 ;
476
+ for ( let i = this . _responseParts . length - 1 ; i >= 0 ; i -- ) {
477
+ const part = this . _responseParts [ i ] ;
478
+ if ( part . kind === 'toolInvocation' || part . kind === 'toolInvocationSerialized' ) {
479
+ lastToolInvocationIndex = i ;
480
+ break ;
481
+ }
482
+ }
483
+ if ( lastToolInvocationIndex !== - 1 ) {
484
+ this . _responseParts = this . _responseParts . slice ( 0 , lastToolInvocationIndex + 1 ) ;
485
+ } else {
486
+ this . _responseParts = [ ] ;
487
+ }
488
+ if ( message ) {
489
+ this . _responseParts . push ( { kind : 'warning' , content : new MarkdownString ( message ) } ) ;
490
+ }
491
+ this . _updateRepr ( true ) ;
492
+ }
493
+
468
494
updateContent ( progress : IChatProgressResponseContent | IChatTextEdit | IChatNotebookEdit | IChatTask , quiet ?: boolean ) : void {
469
- if ( progress . kind === 'markdownContent' ) {
495
+ if ( progress . kind === 'clearToPreviousToolInvocation' ) {
496
+ if ( progress . reason === ChatResponseClearToPreviousToolInvocationReason . CopyrightContentRetry ) {
497
+ this . clearToPreviousToolInvocation ( localize ( 'copyrightContentRetry' , "Response cleared due to possible match to public code, retrying with modified prompt." ) ) ;
498
+ } else if ( progress . reason === ChatResponseClearToPreviousToolInvocationReason . FilteredContentRetry ) {
499
+ this . clearToPreviousToolInvocation ( localize ( 'filteredContentRetry' , "Response cleared due to content safety filters, retrying with modified prompt." ) ) ;
500
+ } else {
501
+ this . clearToPreviousToolInvocation ( ) ;
502
+ }
503
+ return ;
504
+ } else if ( progress . kind === 'markdownContent' ) {
470
505
471
506
// last response which is NOT a text edit group because we do want to support heterogenous streaming but not have
472
507
// the MD be chopped up by text edit groups (and likely other non-renderable parts)
0 commit comments