diff --git a/src/vs/workbench/contrib/chat/browser/chat.contribution.ts b/src/vs/workbench/contrib/chat/browser/chat.contribution.ts index ff0d0ebc145..172bf27819a 100644 --- a/src/vs/workbench/contrib/chat/browser/chat.contribution.ts +++ b/src/vs/workbench/contrib/chat/browser/chat.contribution.ts @@ -42,7 +42,7 @@ import { ChatVariablesService } from 'vs/workbench/contrib/chat/browser/chatVari import { ChatWidgetService } from 'vs/workbench/contrib/chat/browser/chatWidget'; import 'vs/workbench/contrib/chat/browser/contrib/chatHistoryVariables'; import 'vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib'; -import { ChatAgentService, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents'; +import { ChatAgentLocation, ChatAgentService, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents'; import { CONTEXT_IN_CHAT_SESSION } from 'vs/workbench/contrib/chat/common/chatContextKeys'; import { IChatContributionService } from 'vs/workbench/contrib/chat/common/chatContributionService'; import { ChatWelcomeMessageModel } from 'vs/workbench/contrib/chat/common/chatModel'; @@ -250,7 +250,7 @@ class ChatSlashStaticSlashCommandsContribution extends Disposable { sortText: 'z1_help', executeImmediately: true }, async (prompt, progress) => { - const defaultAgent = chatAgentService.getDefaultAgent(); + const defaultAgent = chatAgentService.getDefaultAgent(ChatAgentLocation.Panel); const agents = chatAgentService.getAgents(); // Report prefix diff --git a/src/vs/workbench/contrib/chat/browser/chatFollowups.ts b/src/vs/workbench/contrib/chat/browser/chatFollowups.ts index 7f0c4279c5d..e38f7eccb8d 100644 --- a/src/vs/workbench/contrib/chat/browser/chatFollowups.ts +++ b/src/vs/workbench/contrib/chat/browser/chatFollowups.ts @@ -9,7 +9,7 @@ import { MarkdownString } from 'vs/base/common/htmlContent'; import { Disposable } from 'vs/base/common/lifecycle'; import { localize } from 'vs/nls'; import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; -import { IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents'; +import { ChatAgentLocation, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents'; import { chatAgentLeader, chatSubcommandLeader } from 'vs/workbench/contrib/chat/common/chatParserTypes'; import { IChatFollowup } from 'vs/workbench/contrib/chat/common/chatService'; import { IInlineChatFollowup } from 'vs/workbench/contrib/inlineChat/common/inlineChat'; @@ -20,6 +20,7 @@ export class ChatFollowups extend constructor( container: HTMLElement, followups: T[], + private readonly location: ChatAgentLocation, private readonly options: IButtonStyles | undefined, private readonly clickHandler: (followup: T) => void, @IContextKeyService private readonly contextService: IContextKeyService, @@ -37,13 +38,13 @@ export class ChatFollowups extend return; } - if (!this.chatAgentService.getDefaultAgent()) { + if (!this.chatAgentService.getDefaultAgent(this.location)) { // No default agent yet, which affects how followups are rendered, so can't render this yet return; } let tooltipPrefix = ''; - if ('agentId' in followup && followup.agentId && followup.agentId !== this.chatAgentService.getDefaultAgent()?.id) { + if ('agentId' in followup && followup.agentId && followup.agentId !== this.chatAgentService.getDefaultAgent(this.location)?.id) { tooltipPrefix += `${chatAgentLeader}${followup.agentId} `; if ('subCommand' in followup && followup.subCommand) { tooltipPrefix += `${chatSubcommandLeader}${followup.subCommand} `; diff --git a/src/vs/workbench/contrib/chat/browser/chatInputPart.ts b/src/vs/workbench/contrib/chat/browser/chatInputPart.ts index aaf61c8562b..5ae86608afc 100644 --- a/src/vs/workbench/contrib/chat/browser/chatInputPart.ts +++ b/src/vs/workbench/contrib/chat/browser/chatInputPart.ts @@ -40,7 +40,7 @@ import { ChatSubmitEditorAction, ChatSubmitSecondaryAgentEditorAction } from 'vs import { IChatExecuteActionContext, SubmitAction } from 'vs/workbench/contrib/chat/browser/actions/chatExecuteActions'; import { IChatWidget } from 'vs/workbench/contrib/chat/browser/chat'; import { ChatFollowups } from 'vs/workbench/contrib/chat/browser/chatFollowups'; -import { IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents'; +import { ChatAgentLocation, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents'; import { CONTEXT_CHAT_INPUT_CURSOR_AT_TOP, CONTEXT_CHAT_INPUT_HAS_FOCUS, CONTEXT_CHAT_INPUT_HAS_TEXT, CONTEXT_IN_CHAT_INPUT } from 'vs/workbench/contrib/chat/common/chatContextKeys'; import { chatAgentLeader } from 'vs/workbench/contrib/chat/common/chatParserTypes'; import { IChatFollowup } from 'vs/workbench/contrib/chat/common/chatService'; @@ -119,6 +119,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge constructor( // private readonly editorOptions: ChatEditorOptions, // TODO this should be used + private readonly location: ChatAgentLocation, private readonly options: { renderFollowups: boolean; renderStyle?: 'default' | 'compact'; @@ -415,7 +416,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge dom.clearNode(this.followupsContainer); if (items && items.length > 0) { - this.followupsDisposables.add(this.instantiationService.createInstance, ChatFollowups>(ChatFollowups, this.followupsContainer, items, undefined, followup => this._onDidAcceptFollowup.fire({ followup, response }))); + this.followupsDisposables.add(this.instantiationService.createInstance, ChatFollowups>(ChatFollowups, this.followupsContainer, items, this.location, undefined, followup => this._onDidAcceptFollowup.fire({ followup, response }))); } } diff --git a/src/vs/workbench/contrib/chat/browser/chatListRenderer.ts b/src/vs/workbench/contrib/chat/browser/chatListRenderer.ts index 28758e10791..0e3816eafed 100644 --- a/src/vs/workbench/contrib/chat/browser/chatListRenderer.ts +++ b/src/vs/workbench/contrib/chat/browser/chatListRenderer.ts @@ -53,7 +53,7 @@ import { ChatFollowups } from 'vs/workbench/contrib/chat/browser/chatFollowups'; import { ChatMarkdownDecorationsRenderer } from 'vs/workbench/contrib/chat/browser/chatMarkdownDecorationsRenderer'; import { ChatEditorOptions } from 'vs/workbench/contrib/chat/browser/chatOptions'; import { ChatCodeBlockContentProvider, CodeBlockPart, ICodeBlockData, localFileLanguageId, parseLocalFileData } from 'vs/workbench/contrib/chat/browser/codeBlockPart'; -import { IChatAgentMetadata } from 'vs/workbench/contrib/chat/common/chatAgents'; +import { ChatAgentLocation, IChatAgentMetadata } from 'vs/workbench/contrib/chat/common/chatAgents'; import { CONTEXT_CHAT_RESPONSE_SUPPORT_ISSUE_REPORTING, CONTEXT_REQUEST, CONTEXT_RESPONSE, CONTEXT_RESPONSE_DETECTED_AGENT_COMMAND, CONTEXT_RESPONSE_FILTERED, CONTEXT_RESPONSE_VOTE } from 'vs/workbench/contrib/chat/common/chatContextKeys'; import { IChatProgressRenderableResponseContent } from 'vs/workbench/contrib/chat/common/chatModel'; import { chatAgentLeader, chatSubcommandLeader } from 'vs/workbench/contrib/chat/common/chatParserTypes'; @@ -131,6 +131,7 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer this._onDidClickFollowup.fire(followup))); } else { diff --git a/src/vs/workbench/contrib/chat/browser/chatWidget.ts b/src/vs/workbench/contrib/chat/browser/chatWidget.ts index df3bf9fde56..0e0b353dbb3 100644 --- a/src/vs/workbench/contrib/chat/browser/chatWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/chatWidget.ts @@ -404,6 +404,7 @@ export class ChatWidget extends Disposable implements IChatWidget { this.renderer = this._register(scopedInstantiationService.createInstance( ChatListItemRenderer, this.editorOptions, + this.location, options, rendererDelegate, this._codeBlockModelCollection, @@ -495,11 +496,14 @@ export class ChatWidget extends Disposable implements IChatWidget { } private createInput(container: HTMLElement, options?: { renderFollowups: boolean; renderStyle?: 'default' | 'compact' }): void { - this.inputPart = this._register(this.instantiationService.createInstance(ChatInputPart, { - renderFollowups: options?.renderFollowups ?? true, - renderStyle: options?.renderStyle, - menus: { executeToolbar: MenuId.ChatExecute, ...this.viewOptions.menus } - })); + this.inputPart = this._register(this.instantiationService.createInstance(ChatInputPart, + this.location, + { + renderFollowups: options?.renderFollowups ?? true, + renderStyle: options?.renderStyle, + menus: { executeToolbar: MenuId.ChatExecute, ...this.viewOptions.menus } + } + )); this.inputPart.render(container, '', this); this._register(this.inputPart.onDidLoadInputState(state => { @@ -516,7 +520,7 @@ export class ChatWidget extends Disposable implements IChatWidget { } let msg = ''; - if (e.followup.agentId !== this.chatAgentService.getDefaultAgent()?.id) { + if (e.followup.agentId !== this.chatAgentService.getDefaultAgent(this.location)?.id) { msg = `${chatAgentLeader}${e.followup.agentId} `; if (e.followup.subCommand) { msg += `${chatSubcommandLeader}${e.followup.subCommand} `; @@ -564,7 +568,7 @@ export class ChatWidget extends Disposable implements IChatWidget { } this.parsedChatRequest = undefined; const agentAndSubcommand = extractAgentAndCommand(this.parsedInput); - const currentAgent = agentAndSubcommand.agentPart?.agent ?? this.chatAgentService.getDefaultAgent(); + const currentAgent = agentAndSubcommand.agentPart?.agent ?? this.chatAgentService.getDefaultAgent(this.location); const implicitVariables = agentAndSubcommand.commandPart ? agentAndSubcommand.commandPart.command.defaultImplicitVariables : currentAgent?.defaultImplicitVariables; @@ -734,7 +738,6 @@ export class ChatWidget extends Disposable implements IChatWidget { this.inputPart.layout(height, width); const inputPartHeight = this.inputPart.inputPartHeight; - // const inputPartHeight = dom.getTotalHeight(this.inputPart.element); const lastElementVisible = this.tree.scrollTop + this.tree.renderHeight >= this.tree.scrollHeight; const listHeight = height - inputPartHeight; diff --git a/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib.ts b/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib.ts index dda85245b9f..c5d4f440990 100644 --- a/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib.ts +++ b/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib.ts @@ -126,7 +126,7 @@ class InputEditorDecorations extends Disposable { } if (!inputValue) { - const defaultAgent = this.chatAgentService.getDefaultAgent(); + const defaultAgent = this.chatAgentService.getDefaultAgent(this.widget.location); const decoration: IDecorationOptions[] = [ { range: { diff --git a/src/vs/workbench/contrib/chat/common/chatAgents.ts b/src/vs/workbench/contrib/chat/common/chatAgents.ts index 203aa9548de..2aa2893de49 100644 --- a/src/vs/workbench/contrib/chat/common/chatAgents.ts +++ b/src/vs/workbench/contrib/chat/common/chatAgents.ts @@ -138,7 +138,7 @@ export interface IChatAgentService { getAgents(): IChatAgentData[]; getActivatedAgents(): Array; getAgentsByName(name: string): IChatAgentData[]; - getDefaultAgent(): IChatAgent | undefined; + getDefaultAgent(location: ChatAgentLocation): IChatAgent | undefined; getSecondaryAgent(): IChatAgentData | undefined; updateAgent(id: string, updateMetadata: IChatAgentMetadata): void; } @@ -219,9 +219,8 @@ export class ChatAgentService implements IChatAgentService { this._onDidChangeAgents.fire(new MergedChatAgent(agent.data, agent.impl)); } - getDefaultAgent(): IChatAgent | undefined { - // TODO@jrieken pass location! - return this.getActivatedAgents().find(a => !!a.isDefault && a.locations.includes(ChatAgentLocation.Panel)); + getDefaultAgent(location: ChatAgentLocation): IChatAgent | undefined { + return this.getActivatedAgents().find(a => !!a.isDefault && a.locations.includes(location)); } getSecondaryAgent(): IChatAgentData | undefined { diff --git a/src/vs/workbench/contrib/chat/common/chatModel.ts b/src/vs/workbench/contrib/chat/common/chatModel.ts index efba768f7ba..f40371fcd5e 100644 --- a/src/vs/workbench/contrib/chat/common/chatModel.ts +++ b/src/vs/workbench/contrib/chat/common/chatModel.ts @@ -347,10 +347,10 @@ export class ChatResponseModel extends Disposable implements IChatResponseModel } } - setAgent(agent: IChatAgentData, slashCommand?: IChatAgentCommand, detected?: boolean) { + setAgent(agent: IChatAgentData, slashCommand?: IChatAgentCommand) { this._agent = agent; this._slashCommand = slashCommand; - this._agentOrSlashCommandDetected = detected; + this._agentOrSlashCommandDetected = true; this._onDidChange.fire(); } @@ -531,7 +531,7 @@ export class ChatModel extends Disposable implements IChatModel { } private get _defaultAgent() { - return this.chatAgentService.getDefaultAgent(); + return this.chatAgentService.getDefaultAgent(ChatAgentLocation.Panel); } get requesterUsername(): string { @@ -741,7 +741,7 @@ export class ChatModel extends Disposable implements IChatModel { } else if (progress.kind === 'agentDetection') { const agent = this.chatAgentService.getAgent(progress.agentId); if (agent) { - request.response.setAgent(agent, progress.command, progress.detected); + request.response.setAgent(agent, progress.command); } } else if (progress.kind === 'textEdit') { request.response.updateTextEdits(progress.uri, progress.edits); @@ -897,11 +897,11 @@ export class ChatWelcomeMessageModel implements IChatWelcomeMessageModel { } public get username(): string { - return this.chatAgentService.getDefaultAgent()?.metadata.fullName ?? ''; + return this.chatAgentService.getDefaultAgent(ChatAgentLocation.Panel)?.metadata.fullName ?? ''; } public get avatarIcon(): ThemeIcon | undefined { - return this.chatAgentService.getDefaultAgent()?.metadata.themeIcon; + return this.chatAgentService.getDefaultAgent(ChatAgentLocation.Panel)?.metadata.themeIcon; } } diff --git a/src/vs/workbench/contrib/chat/common/chatService.ts b/src/vs/workbench/contrib/chat/common/chatService.ts index da68a68451c..42c94d58248 100644 --- a/src/vs/workbench/contrib/chat/common/chatService.ts +++ b/src/vs/workbench/contrib/chat/common/chatService.ts @@ -88,7 +88,6 @@ export interface IChatContentInlineReference { export interface IChatAgentDetection { agentId: string; command?: IChatAgentCommand; - detected?: boolean; kind: 'agentDetection'; } diff --git a/src/vs/workbench/contrib/chat/common/chatServiceImpl.ts b/src/vs/workbench/contrib/chat/common/chatServiceImpl.ts index f739e51a21b..b932b682cbf 100644 --- a/src/vs/workbench/contrib/chat/common/chatServiceImpl.ts +++ b/src/vs/workbench/contrib/chat/common/chatServiceImpl.ts @@ -383,7 +383,7 @@ export class ChatService extends Disposable implements IChatService { this.trace('startSession', `Provider returned session`); - const defaultAgent = this.chatAgentService.getDefaultAgent(); + const defaultAgent = this.chatAgentService.getDefaultAgent(ChatAgentLocation.Panel); if (!defaultAgent) { throw new ErrorNoTelemetry('No default agent'); } @@ -458,10 +458,7 @@ export class ChatService extends Disposable implements IChatService { return; } - let defaultAgent = this.chatAgentService.getDefaultAgent()!; - if (location && !defaultAgent?.locations.includes(location)) { - defaultAgent = this.chatAgentService.getActivatedAgents().find(a => a.locations.includes(location)) ?? defaultAgent; - } + const defaultAgent = this.chatAgentService.getDefaultAgent(location)!; const parsedRequest = this.instantiationService.createInstance(ChatRequestParser).parseChatRequest(sessionId, request, location, parserContext); const agent = parsedRequest.parts.find((r): r is ChatRequestAgentPart => r instanceof ChatRequestAgentPart)?.agent ?? defaultAgent; @@ -534,7 +531,6 @@ export class ChatService extends Disposable implements IChatService { let rawResult: IChatAgentResult | null | undefined; let agentOrCommandFollowups: Promise | undefined = undefined; - // const defaultAgent = this.chatAgentService.getDefaultAgent(); if (agentPart || (defaultAgent && !commandPart)) { const agent = (agentPart?.agent ?? defaultAgent)!; await this.extensionService.activateByEvent(`onChatParticipant:${agent.id}`); diff --git a/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agent_and_subcommand_after_newline.0.snap b/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agent_and_subcommand_after_newline.0.snap index 6b0f7e0b229..913d93883a3 100644 --- a/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agent_and_subcommand_after_newline.0.snap +++ b/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agent_and_subcommand_after_newline.0.snap @@ -32,14 +32,14 @@ value: "nullExtensionDescription", _lower: "nullextensiondescription" }, + locations: [ "panel" ], metadata: { description: "" }, slashCommands: [ { name: "subCommand", description: "" } - ], - locations: [ "panel" ] + ] }, kind: "agent" }, diff --git a/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agent_and_subcommand_with_leading_whitespace.0.snap b/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agent_and_subcommand_with_leading_whitespace.0.snap index 09add844a3e..847804842be 100644 --- a/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agent_and_subcommand_with_leading_whitespace.0.snap +++ b/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agent_and_subcommand_with_leading_whitespace.0.snap @@ -32,14 +32,14 @@ value: "nullExtensionDescription", _lower: "nullextensiondescription" }, + locations: [ "panel" ], metadata: { description: "" }, slashCommands: [ { name: "subCommand", description: "" } - ], - locations: [ "panel" ] + ] }, kind: "agent" }, diff --git a/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agent_with_question_mark.0.snap b/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agent_with_question_mark.0.snap index 6cfedc2209f..42a9e4e71d0 100644 --- a/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agent_with_question_mark.0.snap +++ b/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agent_with_question_mark.0.snap @@ -18,14 +18,14 @@ value: "nullExtensionDescription", _lower: "nullextensiondescription" }, + locations: [ "panel" ], metadata: { description: "" }, slashCommands: [ { name: "subCommand", description: "" } - ], - locations: [ "panel" ] + ] }, kind: "agent" }, diff --git a/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agent_with_subcommand_after_text.0.snap b/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agent_with_subcommand_after_text.0.snap index 5a9468592a5..50301b0cf1c 100644 --- a/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agent_with_subcommand_after_text.0.snap +++ b/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agent_with_subcommand_after_text.0.snap @@ -18,14 +18,14 @@ value: "nullExtensionDescription", _lower: "nullextensiondescription" }, + locations: [ "panel" ], metadata: { description: "" }, slashCommands: [ { name: "subCommand", description: "" } - ], - locations: [ "panel" ] + ] }, kind: "agent" }, diff --git a/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agents__subCommand.0.snap b/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agents__subCommand.0.snap index 89d86aece8e..8de370325aa 100644 --- a/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agents__subCommand.0.snap +++ b/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agents__subCommand.0.snap @@ -18,14 +18,14 @@ value: "nullExtensionDescription", _lower: "nullextensiondescription" }, + locations: [ "panel" ], metadata: { description: "" }, slashCommands: [ { name: "subCommand", description: "" } - ], - locations: [ "panel" ] + ] }, kind: "agent" }, diff --git a/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agents_and_variables_and_multiline.0.snap b/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agents_and_variables_and_multiline.0.snap index 801cb6cb86c..855c14d6033 100644 --- a/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agents_and_variables_and_multiline.0.snap +++ b/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agents_and_variables_and_multiline.0.snap @@ -18,14 +18,14 @@ value: "nullExtensionDescription", _lower: "nullextensiondescription" }, + locations: [ "panel" ], metadata: { description: "" }, slashCommands: [ { name: "subCommand", description: "" } - ], - locations: [ "panel" ] + ] }, kind: "agent" }, diff --git a/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agents_and_variables_and_multiline__part2.0.snap b/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agents_and_variables_and_multiline__part2.0.snap index 605fc7efdd2..c33398a6d33 100644 --- a/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agents_and_variables_and_multiline__part2.0.snap +++ b/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatRequestParser_agents_and_variables_and_multiline__part2.0.snap @@ -18,14 +18,14 @@ value: "nullExtensionDescription", _lower: "nullextensiondescription" }, + locations: [ "panel" ], metadata: { description: "" }, slashCommands: [ { name: "subCommand", description: "" } - ], - locations: [ "panel" ] + ] }, kind: "agent" }, diff --git a/src/vs/workbench/contrib/chat/test/common/chatRequestParser.test.ts b/src/vs/workbench/contrib/chat/test/common/chatRequestParser.test.ts index e661419be79..c28817bb090 100644 --- a/src/vs/workbench/contrib/chat/test/common/chatRequestParser.test.ts +++ b/src/vs/workbench/contrib/chat/test/common/chatRequestParser.test.ts @@ -112,7 +112,7 @@ suite('ChatRequestParser', () => { }); const getAgentWithSlashCommands = (slashCommands: IChatAgentCommand[]) => { - return { id: 'agent', name: 'agent', extensionId: nullExtensionDescription.identifier, metadata: { description: '' }, slashCommands, locations: [ChatAgentLocation.Panel] }; + return { id: 'agent', name: 'agent', extensionId: nullExtensionDescription.identifier, locations: [ChatAgentLocation.Panel], metadata: { description: '' }, slashCommands }; }; test('agent with subcommand after text', async () => { diff --git a/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts b/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts index 00abf5e1f5e..c7fa9a70abd 100644 --- a/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts +++ b/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts @@ -508,6 +508,10 @@ export class InlineChatController implements IEditorContribution { const refer = slashCommandLike && this._session.session.slashCommands?.some(value => value.refer && slashCommandLike.text === `/${value.command}`); if (refer) { this._log('[IE] seeing refer command, continuing outside editor', this._session.provider.extensionId); + + // cancel this request + this._chatService.cancelCurrentRequestForSession(request.session.sessionId); + this._editor.setSelection(this._session.wholeRange.value); let massagedInput = input; const withoutSubCommandLeader = slashCommandLike.text.slice(1); @@ -521,7 +525,7 @@ export class InlineChatController implements IEditorContribution { } } // if agent has a refer command, massage the input to include the agent name - this._instaService.invokeFunction(sendRequest, massagedInput); + await this._instaService.invokeFunction(sendRequest, massagedInput); if (!this._session.lastExchange) { // DONE when there wasn't any exchange yet. We used the inline chat only as trampoline diff --git a/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionServiceImpl.ts b/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionServiceImpl.ts index 77e995c3409..897b1fc63df 100644 --- a/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionServiceImpl.ts +++ b/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionServiceImpl.ts @@ -58,6 +58,10 @@ class BridgeAgent implements IChatAgentImplementation { async invoke(request: IChatAgentRequest, progress: (part: IChatProgress) => void, history: IChatAgentHistoryEntry[], token: CancellationToken): Promise { + if (token.isCancellationRequested) { + return {}; + } + const data = this._findSessionDataByRequest(request); if (!data) { @@ -91,7 +95,7 @@ class BridgeAgent implements IChatAgentImplementation { // } if (data.slashCommand) { const command = this._data.slashCommands.find(c => c.name === data.slashCommand); - progress({ kind: 'agentDetection', detected: true, agentId: this._data.id, command }); + progress({ kind: 'agentDetection', agentId: this._data.id, command }); } if (data.markdownFragment) { progress({ kind: 'markdownContent', content: new MarkdownString(data.markdownFragment) }); diff --git a/src/vs/workbench/contrib/inlineChat/browser/inlineChatWidget.ts b/src/vs/workbench/contrib/inlineChat/browser/inlineChatWidget.ts index c325bf5c515..77bb2fc8aab 100644 --- a/src/vs/workbench/contrib/inlineChat/browser/inlineChatWidget.ts +++ b/src/vs/workbench/contrib/inlineChat/browser/inlineChatWidget.ts @@ -502,7 +502,7 @@ export class InlineChatWidget { reset(this._elements.followUps); if (items && items.length > 0 && onFollowup) { this._followUpDisposables.add( - this._instantiationService.createInstance(ChatFollowups, this._elements.followUps, items, undefined, onFollowup)); + this._instantiationService.createInstance(ChatFollowups, this._elements.followUps, items, ChatAgentLocation.Editor, undefined, onFollowup)); } this._onDidChangeHeight.fire(); } diff --git a/src/vs/workbench/contrib/quickaccess/browser/commandsQuickAccess.ts b/src/vs/workbench/contrib/quickaccess/browser/commandsQuickAccess.ts index 3d492fd2e02..0964b31e3bb 100644 --- a/src/vs/workbench/contrib/quickaccess/browser/commandsQuickAccess.ts +++ b/src/vs/workbench/contrib/quickaccess/browser/commandsQuickAccess.ts @@ -32,7 +32,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IWorkbenchQuickAccessConfiguration } from 'vs/workbench/browser/quickaccess'; import { CHAT_OPEN_ACTION_ID } from 'vs/workbench/contrib/chat/browser/actions/chatActions'; import { ASK_QUICK_QUESTION_ACTION_ID } from 'vs/workbench/contrib/chat/browser/actions/chatQuickInputActions'; -import { IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents'; +import { ChatAgentLocation, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents'; import { CommandInformationResult, IAiRelatedInformationService, RelatedInformationType } from 'vs/workbench/services/aiRelatedInformation/common/aiRelatedInformation'; import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; @@ -172,7 +172,7 @@ export class CommandsQuickAccessProvider extends AbstractEditorCommandsQuickAcce }); } - const defaultAgent = this.chatAgentService.getDefaultAgent(); + const defaultAgent = this.chatAgentService.getDefaultAgent(ChatAgentLocation.Panel); if (defaultAgent) { additionalPicks.push({ label: localize('askXInChat', "Ask {0}: {1}", defaultAgent.metadata.fullName, filter),