Skip to content

Commit

Permalink
Add a flag to clear chat response content entirely (microsoft#198715)
Browse files Browse the repository at this point in the history
This may become useful for codeblock vulnerability annotation work, before the API is fully finalized and available
  • Loading branch information
roblourens authored and Splizard committed Nov 21, 2023
1 parent 0a11924 commit bfb58a0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
15 changes: 12 additions & 3 deletions src/vs/workbench/contrib/chat/common/chatModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ export class Response implements IResponse {
return this._responseRepr;
}

clear(): void {
this._responseParts = [];
this._updateRepr(true);
}

updateContent(progress: IChatProgressResponseContent | IChatContent, quiet?: boolean): void {
if (progress.kind === 'content' || progress.kind === 'markdownContent') {
const responsePartLength = this._responseParts.length - 1;
Expand Down Expand Up @@ -310,7 +315,11 @@ export class ChatResponseModel extends Disposable implements IChatResponseModel
this._onDidChange.fire();
}

complete(): void {
complete(errorDetails?: IChatResponseErrorDetails): void {
if (errorDetails?.responseIsRedacted) {
this._response.clear();
}

this._isComplete = true;
this._onDidChange.fire();
}
Expand Down Expand Up @@ -689,12 +698,12 @@ export class ChatModel extends Disposable implements IChatModel {
request.response.setErrorDetails(rawResponse.errorDetails);
}

completeResponse(request: ChatRequestModel): void {
completeResponse(request: ChatRequestModel, errorDetails: IChatResponseErrorDetails | undefined): void {
if (!request.response) {
throw new Error('Call setResponse before completeResponse');
}

request.response.complete();
request.response.complete(errorDetails);
}

setFollowups(request: ChatRequestModel, followups: IChatFollowup[] | undefined): void {
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/chat/common/chatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface IChatResponseErrorDetails {
message: string;
responseIsIncomplete?: boolean;
responseIsFiltered?: boolean;
responseIsRedacted?: boolean;
}

export interface IChatResponse {
Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/contrib/chat/common/chatServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,10 @@ export class ChatService extends Disposable implements IChatService {
if (agentOrCommandFollowups) {
agentOrCommandFollowups.then(followups => {
model.setFollowups(request, followups);
model.completeResponse(request);
model.completeResponse(request, rawResponse?.errorDetails);
});
} else {
model.completeResponse(request);
model.completeResponse(request, rawResponse?.errorDetails);
}
}
} finally {
Expand Down Expand Up @@ -656,7 +656,7 @@ export class ChatService extends Disposable implements IChatService {
if (response.followups !== undefined) {
model.setFollowups(request, response.followups);
}
model.completeResponse(request);
model.completeResponse(request, response.errorDetails);
}

cancelCurrentRequestForSession(sessionId: string): void {
Expand Down
7 changes: 7 additions & 0 deletions src/vscode-dts/vscode.proposed.chatAgents2Additions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ declare module 'vscode' {
supportIssueReporting?: boolean;
}

export interface ChatAgentErrorDetails {
/**
* If set to true, the message content is completely hidden. Only ChatAgentErrorDetails#message will be shown.
*/
responseIsRedacted?: boolean;
}

/**
* This is temporary until inline references are fully supported and adopted
*/
Expand Down

0 comments on commit bfb58a0

Please sign in to comment.