Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/electron-browser/builtInTools/tools.ts
5263 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 { Disposable } from '../../../../../base/common/lifecycle.js';
7
import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js';
8
import { IWorkbenchContribution } from '../../../../common/contributions.js';
9
import { ChatExternalPathConfirmationContribution } from '../../common/tools/builtinTools/chatExternalPathConfirmation.js';
10
import { ChatUrlFetchingConfirmationContribution } from '../../common/tools/builtinTools/chatUrlFetchingConfirmation.js';
11
import { ILanguageModelToolsConfirmationService } from '../../common/tools/languageModelToolsConfirmationService.js';
12
import { ILanguageModelToolsService } from '../../common/tools/languageModelToolsService.js';
13
import { InternalFetchWebPageToolId } from '../../common/tools/builtinTools/tools.js';
14
import { FetchWebPageTool, FetchWebPageToolData, IFetchWebPageToolParams } from './fetchPageTool.js';
15
16
export class NativeBuiltinToolsContribution extends Disposable implements IWorkbenchContribution {
17
18
static readonly ID = 'chat.nativeBuiltinTools';
19
20
constructor(
21
@ILanguageModelToolsService toolsService: ILanguageModelToolsService,
22
@IInstantiationService instantiationService: IInstantiationService,
23
@ILanguageModelToolsConfirmationService confirmationService: ILanguageModelToolsConfirmationService,
24
) {
25
super();
26
27
const editTool = instantiationService.createInstance(FetchWebPageTool);
28
this._register(toolsService.registerTool(FetchWebPageToolData, editTool));
29
30
this._register(confirmationService.registerConfirmationContribution(
31
InternalFetchWebPageToolId,
32
instantiationService.createInstance(
33
ChatUrlFetchingConfirmationContribution,
34
params => (params as IFetchWebPageToolParams).urls
35
)
36
));
37
38
// Register external path confirmation contribution for read_file and list_dir
39
// They share the same allowlist so approving a folder for reading files also allows listing that directory
40
const externalPathConfirmation = new ChatExternalPathConfirmationContribution(
41
(ref) => {
42
const params = ref.parameters as { filePath?: string; path?: string };
43
// read_file uses filePath (it's a file), list_dir uses path (it's a directory)
44
if (params?.filePath) {
45
return { path: params.filePath, isDirectory: false };
46
}
47
if (params?.path) {
48
return { path: params.path, isDirectory: true };
49
}
50
return undefined;
51
}
52
);
53
54
this._register(confirmationService.registerConfirmationContribution(
55
'copilot_readFile',
56
externalPathConfirmation
57
));
58
59
this._register(confirmationService.registerConfirmationContribution(
60
'copilot_listDirectory',
61
externalPathConfirmation
62
));
63
}
64
}
65
66