Path: blob/main/src/vs/workbench/contrib/chat/browser/promptSyntax/chatModeActions.ts
5251 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { CHAT_CATEGORY, CHAT_CONFIG_MENU_ID } from '../actions/chatActions.js';6import { Codicon } from '../../../../../base/common/codicons.js';7import { ChatContextKeys } from '../../common/actions/chatContextKeys.js';8import { localize, localize2 } from '../../../../../nls.js';9import { PromptFilePickers } from './pickers/promptFilePickers.js';10import { ServicesAccessor } from '../../../../../editor/browser/editorExtensions.js';11import { Action2, MenuId, registerAction2 } from '../../../../../platform/actions/common/actions.js';12import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js';13import { PromptsType } from '../../common/promptSyntax/promptTypes.js';14import { ChatViewId } from '../chat.js';15import { ContextKeyExpr } from '../../../../../platform/contextkey/common/contextkey.js';16import { IOpenerService } from '../../../../../platform/opener/common/opener.js';1718abstract class ConfigAgentActionImpl extends Action2 {19public override async run(accessor: ServicesAccessor): Promise<void> {20const instaService = accessor.get(IInstantiationService);21const openerService = accessor.get(IOpenerService);22const pickers = instaService.createInstance(PromptFilePickers);23const placeholder = localize('configure.agent.prompts.placeholder', "Select the custom agents to open and configure visibility in the agent picker");2425const result = await pickers.selectPromptFile({ placeholder, type: PromptsType.agent, optionEdit: false, optionVisibility: true });26if (result !== undefined) {27await openerService.open(result.promptFile);28}29}30}3132// Separate action `Configure Custom Agents` link in the agent picker.3334const PICKER_CONFIGURE_AGENTS_ACTION_ID = 'workbench.action.chat.picker.customagents';3536function createPickerConfigureAgentsActionConfig(disabled: boolean) {37const config = {38id: disabled ? PICKER_CONFIGURE_AGENTS_ACTION_ID + '.disabled' : PICKER_CONFIGURE_AGENTS_ACTION_ID,39title: localize2('select-agent', "Configure Custom Agents..."),40tooltip: disabled ? localize('managedByOrganization', "Managed by your organization") : undefined,41icon: disabled ? Codicon.lock : undefined,42category: CHAT_CATEGORY,43f1: false,44precondition: disabled ? ContextKeyExpr.false() : ChatContextKeys.Modes.agentModeDisabledByPolicy.negate(),45menu: {46id: MenuId.ChatModePicker,47when: disabled ? ChatContextKeys.Modes.agentModeDisabledByPolicy : ChatContextKeys.Modes.agentModeDisabledByPolicy.negate(),48},49};50return config;51}5253class PickerConfigAgentAction extends ConfigAgentActionImpl { constructor() { super(createPickerConfigureAgentsActionConfig(false)); } }54class PickerConfigAgentActionDisabled extends ConfigAgentActionImpl { constructor() { super(createPickerConfigureAgentsActionConfig(true)); } }5556/**57* Action ID for the `Configure Custom Agents` action.58*/59const CONFIGURE_AGENTS_ACTION_ID = 'workbench.action.chat.configure.customagents';6061function createManageAgentsActionConfig(disabled: boolean) {62const base = {63id: disabled ? CONFIGURE_AGENTS_ACTION_ID + '.disabled' : CONFIGURE_AGENTS_ACTION_ID,64title: localize2('configure-agents', "Configure Custom Agents..."),65shortTitle: localize('configure-agents.short', "Custom Agents"),66icon: disabled ? Codicon.lock : Codicon.bookmark,67f1: !disabled,68precondition: disabled ? ContextKeyExpr.false() : ContextKeyExpr.and(ChatContextKeys.enabled, ChatContextKeys.Modes.agentModeDisabledByPolicy.negate()),69category: CHAT_CATEGORY,70menu: [71{72id: CHAT_CONFIG_MENU_ID,73when: ContextKeyExpr.and(74ChatContextKeys.enabled,75ContextKeyExpr.equals('view', ChatViewId),76disabled ? ChatContextKeys.Modes.agentModeDisabledByPolicy : ChatContextKeys.Modes.agentModeDisabledByPolicy.negate()77),78order: 10,79group: '0_level'80}81]82};83return disabled ? { ...base, tooltip: localize('managedByOrganization', "Managed by your organization") } : base;84}85class ManageAgentsAction extends ConfigAgentActionImpl { constructor() { super(createManageAgentsActionConfig(false)); } }86class ManageAgentsActionDisabled extends ConfigAgentActionImpl { constructor() { super(createManageAgentsActionConfig(true)); } }878889/**90* Helper to register all the `Run Current Prompt` actions.91*/92export function registerAgentActions(): void {93registerAction2(ManageAgentsAction);94registerAction2(ManageAgentsActionDisabled);95registerAction2(PickerConfigAgentAction);96registerAction2(PickerConfigAgentActionDisabled);97}9899100