Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: render confirmation actions nicely in chat history #224238

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class ChatConfirmationContentPart extends Disposable implements IChatCont
{ acceptedConfirmationData: [e.data] };
data.agentId = element.agent?.id;
data.slashCommand = element.slashCommand?.name;
data.confirmation = e.label;
if (await this.chatService.sendRequest(element.sessionId, prompt, data)) {
confirmation.isUsed = true;
confirmationWidget.setShowButtons(false);
Expand Down
15 changes: 13 additions & 2 deletions src/vs/workbench/contrib/chat/browser/chatListRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import { CONTEXT_CHAT_RESPONSE_SUPPORT_ISSUE_REPORTING, CONTEXT_REQUEST, CONTEXT
import { IChatRequestVariableEntry, IChatTextEditGroup } from 'vs/workbench/contrib/chat/common/chatModel';
import { chatSubcommandLeader } from 'vs/workbench/contrib/chat/common/chatParserTypes';
import { ChatAgentVoteDirection, IChatConfirmation, IChatContentReference, IChatFollowup, IChatTask, IChatTreeData } from 'vs/workbench/contrib/chat/common/chatService';
import { IChatCodeCitations, IChatReferences, IChatRendererContent, IChatResponseViewModel, IChatWelcomeMessageViewModel, isRequestVM, isResponseVM, isWelcomeVM } from 'vs/workbench/contrib/chat/common/chatViewModel';
import { IChatCodeCitations, IChatReferences, IChatRendererContent, IChatRequestViewModel, IChatResponseViewModel, IChatWelcomeMessageViewModel, isRequestVM, isResponseVM, isWelcomeVM } from 'vs/workbench/contrib/chat/common/chatViewModel';
import { getNWords } from 'vs/workbench/contrib/chat/common/chatWordCounter';
import { annotateSpecialMarkdownContent } from '../common/annotations';
import { CodeBlockModelCollection } from '../common/codeBlockModelCollection';
Expand Down Expand Up @@ -366,6 +366,10 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
this.renderDetail(element, templateData);
}

if (isRequestVM(element) && element.confirmation) {
this.renderConfirmationAction(element, templateData);
}

// Do a progressive render if
// - This the last response in the list
// - And it has some content
Expand Down Expand Up @@ -425,6 +429,13 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
}
}

private renderConfirmationAction(element: IChatRequestViewModel, templateData: IChatListItemTemplate) {
dom.clearNode(templateData.detail);
if (element.confirmation) {
templateData.detail.textContent = localize('chatConfirmationAction', 'selected "{0}"', element.confirmation);
}
}

private renderAvatar(element: ChatTreeItem, templateData: IChatListItemTemplate): void {
const icon = isResponseVM(element) ?
this.getAgentIcon(element.agent?.metadata) :
Expand Down Expand Up @@ -453,7 +464,7 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch

private basicRenderElement(element: ChatTreeItem, index: number, templateData: IChatListItemTemplate) {
let value: IChatRendererContent[] = [];
if (isRequestVM(element)) {
if (isRequestVM(element) && !element.confirmation) {
const markdown = 'message' in element.message ?
element.message.message :
this.markdownDecorationsRenderer.convertParsedRequestToMarkdown(element.message);
Expand Down
12 changes: 9 additions & 3 deletions src/vs/workbench/contrib/chat/common/chatModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface IChatRequestModel {
readonly message: IParsedChatRequest;
readonly attempt: number;
readonly variableData: IChatRequestVariableData;
readonly confirmation?: string;
readonly response?: IChatResponseModel;
}

Expand Down Expand Up @@ -144,11 +145,16 @@ export class ChatRequestModel implements IChatRequestModel {
this._variableData = v;
}

public get confirmation(): string | undefined {
return this._confirmation;
}

constructor(
private _session: ChatModel,
public readonly message: IParsedChatRequest,
private _variableData: IChatRequestVariableData,
private _attempt: number = 0
private _attempt: number = 0,
private _confirmation?: string
) {
this.id = 'request_' + ChatRequestModel.nextId++;
}
Expand Down Expand Up @@ -861,8 +867,8 @@ export class ChatModel extends Disposable implements IChatModel {
return this._requests;
}

addRequest(message: IParsedChatRequest, variableData: IChatRequestVariableData, attempt: number, chatAgent?: IChatAgentData, slashCommand?: IChatAgentCommand): ChatRequestModel {
const request = new ChatRequestModel(this, message, variableData, attempt);
addRequest(message: IParsedChatRequest, variableData: IChatRequestVariableData, attempt: number, chatAgent?: IChatAgentData, slashCommand?: IChatAgentCommand, confirmation?: string): ChatRequestModel {
const request = new ChatRequestModel(this, message, variableData, attempt, confirmation);
request.response = new ChatResponseModel([], this, chatAgent, slashCommand, request.id);

this._requests.push(request);
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/contrib/chat/common/chatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,11 @@ export interface IChatSendRequestOptions {
/** The target agent ID can be specified with this property instead of using @ in 'message' */
agentId?: string;
slashCommand?: string;

/**
* The label of the confirmation action that was selected.
*/
confirmation?: string;
}

export const IChatService = createDecorator<IChatService>('IChatService');
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/chat/common/chatServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ export class ChatService extends Disposable implements IChatService {
const history = getHistoryEntriesFromModel(model, agentPart?.agent.id);

const initVariableData: IChatRequestVariableData = { variables: [] };
request = model.addRequest(parsedRequest, initVariableData, attempt, agent, agentSlashCommandPart?.command);
request = model.addRequest(parsedRequest, initVariableData, attempt, agent, agentSlashCommandPart?.command, options?.confirmation);
completeResponseCreated();
const variableData = await this.chatVariablesService.resolveVariables(parsedRequest, options?.attachedContext, model, progressCallback, token);
model.updateRequest(request, variableData);
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/contrib/chat/common/chatViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export interface IChatRequestViewModel {
readonly variables: IChatRequestVariableEntry[];
currentRenderedHeight: number | undefined;
readonly contentReferences?: ReadonlyArray<IChatContentReference>;
readonly confirmation?: string;
}

export interface IChatResponseMarkdownRenderData {
Expand Down Expand Up @@ -381,6 +382,10 @@ export class ChatRequestViewModel implements IChatRequestViewModel {
return this._model.response?.contentReferences;
}

get confirmation() {
return this._model.confirmation;
}

currentRenderedHeight: number | undefined;

constructor(
Expand Down
Loading