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