diff --git a/src/vs/workbench/contrib/chat/browser/actions/chatContinueInAction.ts b/src/vs/workbench/contrib/chat/browser/actions/chatContinueInAction.ts index 3ac8ecac4de..65879e3a0f5 100644 --- a/src/vs/workbench/contrib/chat/browser/actions/chatContinueInAction.ts +++ b/src/vs/workbench/contrib/chat/browser/actions/chatContinueInAction.ts @@ -284,7 +284,7 @@ class CreateRemoteAgentJobAction { }); if (requestData) { - await widget.handleDelegationExitIfNeeded(requestData.agent); + await widget.handleDelegationExitIfNeeded(defaultAgent, requestData.agent); } } catch (e) { console.error('Error creating remote coding agent job', e); diff --git a/src/vs/workbench/contrib/chat/browser/chat.ts b/src/vs/workbench/contrib/chat/browser/chat.ts index c30d0fbea4a..fd31b244e8e 100644 --- a/src/vs/workbench/contrib/chat/browser/chat.ts +++ b/src/vs/workbench/contrib/chat/browser/chat.ts @@ -262,7 +262,7 @@ export interface IChatWidget { clear(): Promise; getViewState(): IChatModelInputState | undefined; lockToCodingAgent(name: string, displayName: string, agentId?: string): void; - handleDelegationExitIfNeeded(agent: IChatAgentData | undefined): Promise; + handleDelegationExitIfNeeded(sourceAgent: Pick | undefined, targetAgent: IChatAgentData | undefined): Promise; delegateScrollFromMouseWheelEvent(event: IMouseWheelEvent): void; } diff --git a/src/vs/workbench/contrib/chat/browser/chatWidget.ts b/src/vs/workbench/contrib/chat/browser/chatWidget.ts index a21145af308..13769995905 100644 --- a/src/vs/workbench/contrib/chat/browser/chatWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/chatWidget.ts @@ -1309,8 +1309,8 @@ export class ChatWidget extends Disposable implements IChatWidget { } } - async handleDelegationExitIfNeeded(agent: IChatAgentData | undefined): Promise { - if (!this._shouldExitAfterDelegation(agent)) { + async handleDelegationExitIfNeeded(sourceAgent: Pick | undefined, targetAgent: IChatAgentData | undefined): Promise { + if (!this._shouldExitAfterDelegation(sourceAgent, targetAgent)) { return; } @@ -1321,20 +1321,29 @@ export class ChatWidget extends Disposable implements IChatWidget { } } - private _shouldExitAfterDelegation(agent: IChatAgentData | undefined): boolean { + private _shouldExitAfterDelegation(sourceAgent: Pick | undefined, targetAgent: IChatAgentData | undefined): boolean { + if (!targetAgent) { + // Undefined behavior + return false; + } + if (!this.configurationService.getValue(ChatConfiguration.ExitAfterDelegation)) { return false; } - if (!agent) { + // Never exit if the source and target are the same (that means that you're providing a follow up, etc.) + // NOTE: sourceAgent would be the chatWidget's 'lockedAgent' + if (sourceAgent && sourceAgent.id === targetAgent.id) { return false; } + + if (!isIChatViewViewContext(this.viewContext)) { return false; } - const contribution = this.chatSessionsService.getChatSessionContribution(agent.id); + const contribution = this.chatSessionsService.getChatSessionContribution(targetAgent.id); if (!contribution) { return false; } @@ -2311,7 +2320,7 @@ export class ChatWidget extends Disposable implements IChatWidget { this.input.acceptInput(isUserQuery); this._onDidSubmitAgent.fire({ agent: result.agent, slashCommand: result.slashCommand }); - this.handleDelegationExitIfNeeded(result.agent); + this.handleDelegationExitIfNeeded(this._lockedAgent, result.agent); this.currentRequest = result.responseCompletePromise.then(() => { const responses = this.viewModel?.getItems().filter(isResponseVM); const lastResponse = responses?.[responses.length - 1];