From 3ef3fe51808e0d1f5d21d4ebe41a4bf6469bdf82 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 27 Mar 2025 20:31:52 +0100 Subject: [PATCH] chat - allow mode to be set from protocol link and command (#244911) --- .../contrib/chat/browser/actions/chatActions.ts | 12 +++++++++--- src/vs/workbench/contrib/chat/browser/chatSetup.ts | 12 ++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/actions/chatActions.ts b/src/vs/workbench/contrib/chat/browser/actions/chatActions.ts index 61166f2ede2..a58125f0bd1 100644 --- a/src/vs/workbench/contrib/chat/browser/actions/chatActions.ts +++ b/src/vs/workbench/contrib/chat/browser/actions/chatActions.ts @@ -50,7 +50,7 @@ import { extractAgentAndCommand } from '../../common/chatParserTypes.js'; import { IChatDetail, IChatService } from '../../common/chatService.js'; import { IChatRequestViewModel, IChatResponseViewModel, isRequestVM } from '../../common/chatViewModel.js'; import { IChatWidgetHistoryService } from '../../common/chatWidgetHistoryService.js'; -import { ChatMode } from '../../common/constants.js'; +import { ChatMode, validateChatMode } from '../../common/constants.js'; import { CopilotUsageExtensionFeatureId } from '../../common/languageModelStats.js'; import { ILanguageModelToolsService } from '../../common/languageModelToolsService.js'; import { ChatViewId, EditsViewId, IChatWidget, IChatWidgetService, showChatView, showCopilotView } from '../chat.js'; @@ -68,7 +68,7 @@ const TOGGLE_CHAT_ACTION_ID = 'workbench.action.chat.toggle'; export interface IChatViewOpenOptions { /** - * The query for quick chat. + * The query for chat. */ query: string; /** @@ -83,11 +83,14 @@ export interface IChatViewOpenOptions { * Any previous chat requests and responses that should be shown in the chat view. */ previousRequests?: IChatViewOpenRequestEntry[]; - /** * Whether a screenshot of the focused window should be taken and attached */ attachScreenshot?: boolean; + /** + * The mode to open the chat in. + */ + mode?: ChatMode; } export interface IChatViewOpenRequestEntry { @@ -135,6 +138,9 @@ export function registerChatActions() { if (!chatWidget) { return; } + if (opts?.mode && validateChatMode(opts.mode)) { + chatWidget.input.setChatMode(opts.mode); + } if (opts?.previousRequests?.length && chatWidget.viewModel) { for (const { request, response } of opts.previousRequests) { chatService.addCompleteRequest(chatWidget.viewModel.sessionId, request, undefined, 0, { message: response }); diff --git a/src/vs/workbench/contrib/chat/browser/chatSetup.ts b/src/vs/workbench/contrib/chat/browser/chatSetup.ts index acf89042f84..0ebdddb034e 100644 --- a/src/vs/workbench/contrib/chat/browser/chatSetup.ts +++ b/src/vs/workbench/contrib/chat/browser/chatSetup.ts @@ -63,7 +63,7 @@ import { CHAT_CATEGORY, CHAT_OPEN_ACTION_ID, CHAT_SETUP_ACTION_ID } from './acti import { ChatViewId, EditsViewId, ensureSideBarChatViewSize, IChatWidgetService, preferCopilotEditsView, showCopilotView } from './chat.js'; import { CHAT_EDITING_SIDEBAR_PANEL_ID, CHAT_SIDEBAR_PANEL_ID } from './chatViewPane.js'; import { ChatViewsWelcomeExtensions, IChatViewsWelcomeContributionRegistry } from './viewsWelcome/chatViewsWelcome.js'; -import { ChatAgentLocation, ChatConfiguration } from '../common/constants.js'; +import { ChatAgentLocation, ChatConfiguration, ChatMode, validateChatMode } from '../common/constants.js'; import { ILanguageModelsService } from '../common/languageModels.js'; import { Dialog } from '../../../../base/browser/ui/dialog/dialog.js'; import { ILayoutService } from '../../../../platform/layout/browser/layoutService.js'; @@ -618,7 +618,7 @@ export class ChatSetupContribution extends Disposable implements IWorkbenchContr }); } - override async run(accessor: ServicesAccessor): Promise { + override async run(accessor: ServicesAccessor, mode: ChatMode): Promise { const viewsService = accessor.get(IViewsService); const viewDescriptorService = accessor.get(IViewDescriptorService); const configurationService = accessor.get(IConfigurationService); @@ -631,7 +631,11 @@ export class ChatSetupContribution extends Disposable implements IWorkbenchContr await context.update({ hidden: false }); - showCopilotView(viewsService, layoutService); + const chatWidgetPromise = showCopilotView(viewsService, layoutService); + if (mode) { + const chatWidget = await chatWidgetPromise; + chatWidget?.input.setChatMode(mode); + } const setupFromDialog = configurationService.getValue('chat.setupFromDialog'); if (!setupFromDialog) { @@ -778,7 +782,7 @@ export class ChatSetupContribution extends Disposable implements IWorkbenchContr const params = new URLSearchParams(url.query); this.telemetryService.publicLog2('workbenchActionExecuted', { id: CHAT_SETUP_ACTION_ID, from: 'url', detail: params.get('referrer') ?? undefined }); - await this.commandService.executeCommand(CHAT_SETUP_ACTION_ID); + await this.commandService.executeCommand(CHAT_SETUP_ACTION_ID, validateChatMode(params.get('mode'))); return true; }