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

store locationData on request and use when resending #225509

Merged
merged 1 commit into from
Aug 14, 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
14 changes: 10 additions & 4 deletions src/vs/workbench/contrib/chat/common/chatModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { ILogService } from 'vs/platform/log/common/log';
import { ChatAgentLocation, IChatAgentCommand, IChatAgentData, IChatAgentHistoryEntry, IChatAgentRequest, IChatAgentResult, IChatAgentService, reviveSerializedAgent } from 'vs/workbench/contrib/chat/common/chatAgents';
import { ChatRequestTextPart, IParsedChatRequest, getPromptText, reviveParsedChatRequest } from 'vs/workbench/contrib/chat/common/chatParserTypes';
import { ChatAgentVoteDirection, IChatAgentMarkdownContentWithVulnerability, IChatCodeCitation, IChatCommandButton, IChatConfirmation, IChatContentInlineReference, IChatContentReference, IChatFollowup, IChatMarkdownContent, IChatProgress, IChatProgressMessage, IChatResponseProgressFileTreeData, IChatTask, IChatTextEdit, IChatTreeData, IChatUsedContext, IChatWarningMessage, isIUsedContext } from 'vs/workbench/contrib/chat/common/chatService';
import { ChatAgentVoteDirection, IChatAgentMarkdownContentWithVulnerability, IChatCodeCitation, IChatCommandButton, IChatConfirmation, IChatContentInlineReference, IChatContentReference, IChatFollowup, IChatLocationData, IChatMarkdownContent, IChatProgress, IChatProgressMessage, IChatResponseProgressFileTreeData, IChatTask, IChatTextEdit, IChatTreeData, IChatUsedContext, IChatWarningMessage, isIUsedContext } from 'vs/workbench/contrib/chat/common/chatService';
import { IChatRequestVariableValue } from 'vs/workbench/contrib/chat/common/chatVariables';

export interface IChatRequestVariableEntry {
Expand Down Expand Up @@ -52,6 +52,7 @@ export interface IChatRequestModel {
readonly message: IParsedChatRequest;
readonly attempt: number;
readonly variableData: IChatRequestVariableData;
readonly locationData?: IChatLocationData;
readonly response?: IChatResponseModel;
}

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

public get locationData(): IChatLocationData | undefined {
return this._locationData;
}

constructor(
private _session: ChatModel,
public readonly message: IParsedChatRequest,
private _variableData: IChatRequestVariableData,
private _attempt: number = 0
private _attempt: number = 0,
private _locationData?: IChatLocationData
) {
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, locationData?: IChatLocationData): ChatRequestModel {
const request = new ChatRequestModel(this, message, variableData, attempt, locationData);
request.response = new ChatResponseModel([], this, chatAgent, slashCommand, request.id);

this._requests.push(request);
Expand Down
10 changes: 7 additions & 3 deletions src/vs/workbench/contrib/chat/common/chatServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,11 @@ export class ChatService extends Disposable implements IChatService {

model.removeRequest(request.id, ChatRequestRemovalReason.Resend);

await this._sendRequestAsync(model, model.sessionId, request.message, attempt, enableCommandDetection, defaultAgent, location, options).responseCompletePromise;
const resendOptions: IChatSendRequestOptions = {
...options,
locationData: request.locationData
};
await this._sendRequestAsync(model, model.sessionId, request.message, attempt, enableCommandDetection, defaultAgent, location, resendOptions).responseCompletePromise;
}

async sendRequest(sessionId: string, request: string, options?: IChatSendRequestOptions): Promise<IChatSendRequestData | undefined> {
Expand Down Expand Up @@ -482,7 +486,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?.locationData);
completeResponseCreated();
const variableData = await this.chatVariablesService.resolveVariables(parsedRequest, options?.attachedContext, model, progressCallback, token);
model.updateRequest(request, variableData);
Expand All @@ -500,7 +504,7 @@ export class ChatService extends Disposable implements IChatService {
enableCommandDetection,
attempt,
location,
locationData: options?.locationData,
locationData: request.locationData,
acceptedConfirmationData: options?.acceptedConfirmationData,
rejectedConfirmationData: options?.rejectedConfirmationData,
};
Expand Down
Loading