Skip to content

Commit 8b64384

Browse files
authored
Handle Background Agent requet when a tool call is pending (#2549)
* Handle Background Agent requet when a tool call is pending * Updates
1 parent cf88db5 commit 8b64384

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
471471
private CLI_INCLUDE_CHANGES = vscode.l10n.t('Include Changes');
472472
private CLI_SKIP_CHANGES = vscode.l10n.t('Skip Changes');
473473
private CLI_CANCEL = vscode.l10n.t('Cancel');
474-
474+
private readonly untitledSessionIdMapping = new Map<string, string>();
475475
constructor(
476476
private readonly contentProvider: CopilotCLIChatSessionContentProvider,
477477
private readonly promptResolver: CopilotCLIPromptResolver,
@@ -607,6 +607,7 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
607607
// Delete old information stored for untitled session id.
608608
_sessionModel.delete(id);
609609
_sessionModel.set(session.object.sessionId, modelId);
610+
this.untitledSessionIdMapping.delete(id);
610611
_untitledSessionIdMap.delete(session.object.sessionId);
611612
this.sessionItemProvider.swap(chatSessionContext.chatSessionItem, { resource: SessionIdForCLI.getResource(session.object.sessionId), label: request.prompt });
612613
}
@@ -673,15 +674,16 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
673674

674675
private async getOrCreateSession(request: vscode.ChatRequest, chatSessionContext: vscode.ChatSessionContext, model: string | undefined, agent: SweCustomAgent | undefined, stream: vscode.ChatResponseStream, disposables: DisposableStore, token: vscode.CancellationToken): Promise<IReference<ICopilotCLISession> | undefined> {
675676
const { resource } = chatSessionContext.chatSessionItem;
676-
const id = SessionIdForCLI.parse(resource);
677-
677+
const existingSessionId = this.untitledSessionIdMapping.get(SessionIdForCLI.parse(resource));
678+
const id = existingSessionId ?? SessionIdForCLI.parse(resource);
679+
const isNewSession = chatSessionContext.isUntitled && !existingSessionId;
678680
const isolationEnabled = this.worktreeManager.getIsolationPreference(id);
679-
const workingDirectoryValue = chatSessionContext.isUntitled ?
681+
const workingDirectoryValue = isNewSession || !isolationEnabled ?
680682
(isolationEnabled ? await this.worktreeManager.createWorktree(stream) : await this.copilotCLISDK.getDefaultWorkingDirectory().then(dir => dir?.fsPath)) :
681683
this.worktreeManager.getWorktreePath(id);
682684
const workingDirectory = workingDirectoryValue ? Uri.file(workingDirectoryValue) : undefined;
683685

684-
const session = chatSessionContext.isUntitled ?
686+
const session = isNewSession ?
685687
await this.sessionService.createSession({ model, workingDirectory, isolationEnabled, agent }, token) :
686688
await this.sessionService.getSession(id, { model, workingDirectory, isolationEnabled, readonly: false, agent }, token);
687689
this.sessionItemProvider.notifySessionsChange();
@@ -691,7 +693,10 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
691693
return undefined;
692694
}
693695

694-
if (chatSessionContext.isUntitled && workingDirectory && isolationEnabled) {
696+
if (isNewSession) {
697+
this.untitledSessionIdMapping.set(id, session.object.sessionId);
698+
}
699+
if (isNewSession && workingDirectory && isolationEnabled) {
695700
await this.worktreeManager.storeWorktreePath(session.object.sessionId, workingDirectory.fsPath);
696701
}
697702
disposables.add(session.object.attachStream(stream));

0 commit comments

Comments
 (0)