-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathtoolNames.ts
More file actions
252 lines (228 loc) · 9.88 KB
/
toolNames.ts
File metadata and controls
252 lines (228 loc) · 9.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { cloneAndChange } from '../../../util/vs/base/common/objects';
/**
* Categories for tool grouping in the virtual tools system
*/
export enum ToolCategory {
JupyterNotebook = 'Jupyter Notebook Tools',
WebInteraction = 'Web Interaction',
VSCodeInteraction = 'VS Code Interaction',
Testing = 'Testing',
RedundantButSpecific = 'Redundant but Specific',
// Core tools that should not be grouped
Core = 'Core'
}
export enum ToolName {
ApplyPatch = 'apply_patch',
Codebase = 'semantic_search',
VSCodeAPI = 'get_vscode_api',
TestFailure = 'test_failure',
FindFiles = 'file_search',
FindTextInFiles = 'grep_search',
ReadFile = 'read_file',
ViewImage = 'view_image',
ListDirectory = 'list_dir',
GetErrors = 'get_errors',
GetScmChanges = 'get_changed_files',
ReadProjectStructure = 'read_project_structure',
CreateNewWorkspace = 'create_new_workspace',
CreateNewJupyterNotebook = 'create_new_jupyter_notebook',
SearchWorkspaceSymbols = 'search_workspace_symbols',
EditFile = 'insert_edit_into_file',
CreateFile = 'create_file',
ReplaceString = 'replace_string_in_file',
MultiReplaceString = 'multi_replace_string_in_file',
EditNotebook = 'edit_notebook_file',
RunNotebookCell = 'run_notebook_cell',
GetNotebookSummary = 'copilot_getNotebookSummary',
ReadCellOutput = 'read_notebook_cell_output',
InstallExtension = 'install_extension',
FetchWebPage = 'fetch_webpage',
Memory = 'memory',
FindTestFiles = 'test_search',
GetProjectSetupInfo = 'get_project_setup_info',
SearchViewResults = 'get_search_view_results',
GithubRepo = 'github_repo',
CreateDirectory = 'create_directory',
RunVscodeCmd = 'run_vscode_command',
CoreManageTodoList = 'manage_todo_list',
CoreRunInTerminal = 'run_in_terminal',
CoreGetTerminalOutput = 'get_terminal_output',
CoreTerminalSelection = 'terminal_selection',
CoreTerminalLastCommand = 'terminal_last_command',
CoreCreateAndRunTask = 'create_and_run_task',
CoreRunTask = 'run_task',
CoreGetTaskOutput = 'get_task_output',
CoreRunTest = 'runTests',
EditFilesPlaceholder = 'edit_files',
CoreRunSubagent = 'runSubagent',
CoreConfirmationTool = 'vscode_get_confirmation',
CoreConfirmationToolWithOptions = 'vscode_get_confirmation_with_options',
CoreTerminalConfirmationTool = 'vscode_get_terminal_confirmation',
SearchSubagent = 'search_subagent',
CoreAskQuestions = 'vscode_askQuestions',
SwitchAgent = 'switch_agent',
ToolSearch = 'tool_search',
ResolveMemoryFileUri = 'resolve_memory_file_uri',
ExecutionSubagent = 'execution_subagent',
}
export enum ContributedToolName {
ApplyPatch = 'copilot_applyPatch',
Codebase = 'copilot_searchCodebase',
SearchWorkspaceSymbols = 'copilot_searchWorkspaceSymbols',
VSCodeAPI = 'copilot_getVSCodeAPI',
TestFailure = 'copilot_testFailure',
/** @deprecated moving to core soon */
RunTests = 'copilot_runTests1',
FindFiles = 'copilot_findFiles',
FindTextInFiles = 'copilot_findTextInFiles',
ReadFile = 'copilot_readFile',
ViewImage = 'copilot_viewImage',
ListDirectory = 'copilot_listDirectory',
GetErrors = 'copilot_getErrors',
GetScmChanges = 'copilot_getChangedFiles',
ReadProjectStructure = 'copilot_readProjectStructure',
CreateNewWorkspace = 'copilot_createNewWorkspace',
CreateNewJupyterNotebook = 'copilot_createNewJupyterNotebook',
EditFile = 'copilot_insertEdit',
CreateFile = 'copilot_createFile',
ReplaceString = 'copilot_replaceString',
MultiReplaceString = 'copilot_multiReplaceString',
EditNotebook = 'copilot_editNotebook',
RunNotebookCell = 'copilot_runNotebookCell',
GetNotebookSummary = 'copilot_getNotebookSummary',
ReadCellOutput = 'copilot_readNotebookCellOutput',
InstallExtension = 'copilot_installExtension',
FetchWebPage = 'copilot_fetchWebPage',
Memory = 'copilot_memory',
FindTestFiles = 'copilot_findTestFiles',
GetProjectSetupInfo = 'copilot_getProjectSetupInfo',
SearchViewResults = 'copilot_getSearchResults',
GithubRepo = 'copilot_githubRepo',
CreateAndRunTask = 'copilot_createAndRunTask',
CreateDirectory = 'copilot_createDirectory',
RunVscodeCmd = 'copilot_runVscodeCommand',
EditFilesPlaceholder = 'copilot_editFiles',
SwitchAgent = 'copilot_switchAgent',
ResolveMemoryFileUri = 'copilot_resolveMemoryFileUri',
}
export const byokEditToolNamesToToolNames = {
'find-replace': ToolName.ReplaceString,
'multi-find-replace': ToolName.MultiReplaceString,
'apply-patch': ToolName.ApplyPatch,
'code-rewrite': ToolName.EditFile,
} as const;
const toolNameToContributedToolNames = new Map<ToolName, ContributedToolName>();
const contributedToolNameToToolNames = new Map<ContributedToolName, ToolName>();
for (const [contributedNameKey, contributedName] of Object.entries(ContributedToolName)) {
const toolName = ToolName[contributedNameKey as keyof typeof ToolName];
if (toolName) {
toolNameToContributedToolNames.set(toolName, contributedName);
contributedToolNameToToolNames.set(contributedName, toolName);
}
}
export function getContributedToolName(name: string | ToolName): string | ContributedToolName {
return toolNameToContributedToolNames.get(name as ToolName) ?? name;
}
export function getToolName(name: string | ContributedToolName): string | ToolName {
return contributedToolNameToToolNames.get(name as ContributedToolName) ?? name;
}
export function mapContributedToolNamesInString(str: string): string {
contributedToolNameToToolNames.forEach((value, key) => {
const re = new RegExp(`\\b${key}\\b`, 'g');
str = str.replace(re, value);
});
return str;
}
export function mapContributedToolNamesInSchema(inputSchema: object): object {
return cloneAndChange(inputSchema, value => typeof value === 'string' ? mapContributedToolNamesInString(value) : undefined);
}
/**
* Type-safe mapping of all ToolName enum values to their categories.
* This ensures that every tool is properly categorized and provides compile-time safety.
* When new tools are added to ToolName, they must be added here or TypeScript will error.
*/
export const toolCategories: Record<ToolName, ToolCategory> = {
// Core tools (not grouped - expanded by default)
[ToolName.Codebase]: ToolCategory.Core,
[ToolName.FindTextInFiles]: ToolCategory.Core,
[ToolName.ReadFile]: ToolCategory.Core,
[ToolName.ViewImage]: ToolCategory.Core,
[ToolName.CreateFile]: ToolCategory.Core,
[ToolName.ApplyPatch]: ToolCategory.Core,
[ToolName.ReplaceString]: ToolCategory.Core,
[ToolName.EditFile]: ToolCategory.Core,
[ToolName.CoreRunInTerminal]: ToolCategory.Core,
[ToolName.ListDirectory]: ToolCategory.Core,
[ToolName.CoreGetTerminalOutput]: ToolCategory.Core,
[ToolName.CoreManageTodoList]: ToolCategory.Core,
[ToolName.MultiReplaceString]: ToolCategory.Core,
[ToolName.FindFiles]: ToolCategory.Core,
[ToolName.CreateDirectory]: ToolCategory.Core,
[ToolName.ReadProjectStructure]: ToolCategory.Core,
[ToolName.CoreRunSubagent]: ToolCategory.Core,
[ToolName.SearchSubagent]: ToolCategory.Core,
[ToolName.ExecutionSubagent]: ToolCategory.Core,
// already enabled only when tasks are enabled
[ToolName.CoreRunTask]: ToolCategory.Core,
[ToolName.CoreGetTaskOutput]: ToolCategory.Core,
// never enabled, so it doesn't matter where it's categorized
[ToolName.EditFilesPlaceholder]: ToolCategory.Core,
// Jupyter Notebook Tools
[ToolName.CreateNewJupyterNotebook]: ToolCategory.JupyterNotebook,
[ToolName.EditNotebook]: ToolCategory.JupyterNotebook,
[ToolName.RunNotebookCell]: ToolCategory.JupyterNotebook,
[ToolName.GetNotebookSummary]: ToolCategory.JupyterNotebook,
[ToolName.ReadCellOutput]: ToolCategory.JupyterNotebook,
// Web Interaction
[ToolName.FetchWebPage]: ToolCategory.WebInteraction,
[ToolName.GithubRepo]: ToolCategory.WebInteraction,
// VS Code Interaction
[ToolName.SearchWorkspaceSymbols]: ToolCategory.VSCodeInteraction,
[ToolName.GetErrors]: ToolCategory.VSCodeInteraction,
[ToolName.VSCodeAPI]: ToolCategory.VSCodeInteraction,
[ToolName.GetScmChanges]: ToolCategory.VSCodeInteraction,
[ToolName.CreateNewWorkspace]: ToolCategory.VSCodeInteraction,
[ToolName.InstallExtension]: ToolCategory.VSCodeInteraction,
[ToolName.GetProjectSetupInfo]: ToolCategory.VSCodeInteraction,
[ToolName.CoreCreateAndRunTask]: ToolCategory.VSCodeInteraction,
[ToolName.RunVscodeCmd]: ToolCategory.VSCodeInteraction,
[ToolName.SearchViewResults]: ToolCategory.VSCodeInteraction,
[ToolName.CoreTerminalSelection]: ToolCategory.VSCodeInteraction,
[ToolName.CoreTerminalLastCommand]: ToolCategory.VSCodeInteraction,
// Testing
[ToolName.TestFailure]: ToolCategory.Testing,
[ToolName.FindTestFiles]: ToolCategory.Testing,
[ToolName.CoreRunTest]: ToolCategory.Testing,
// Other tools - categorize appropriately
[ToolName.CoreConfirmationTool]: ToolCategory.VSCodeInteraction,
[ToolName.CoreConfirmationToolWithOptions]: ToolCategory.VSCodeInteraction,
[ToolName.CoreTerminalConfirmationTool]: ToolCategory.VSCodeInteraction,
[ToolName.CoreAskQuestions]: ToolCategory.VSCodeInteraction,
[ToolName.SwitchAgent]: ToolCategory.VSCodeInteraction,
[ToolName.Memory]: ToolCategory.VSCodeInteraction,
[ToolName.ToolSearch]: ToolCategory.Core,
[ToolName.ResolveMemoryFileUri]: ToolCategory.Core,
} as const;
/**
* Get the category for a tool, checking both ToolName enum and external tools.
*/
export function getToolCategory(toolName: string): ToolCategory | undefined {
return toolCategories.hasOwnProperty(toolName) ? toolCategories[toolName as ToolName] : undefined;
}
/**
* Get all tools for a specific category.
*/
export function getToolsForCategory(category: ToolCategory): string[] {
const result: string[] = [];
// Add tools from ToolName enum
for (const [toolName, toolCategory] of Object.entries(toolCategories)) {
if (toolCategory === category) {
result.push(toolName);
}
}
return result;
}