Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/common/tools/languageModelToolsConfirmationService.ts
4780 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 { IDisposable } from '../../../../../base/common/lifecycle.js';
7
import { createDecorator } from '../../../../../platform/instantiation/common/instantiation.js';
8
import { IQuickInputButton, IQuickTreeItem } from '../../../../../platform/quickinput/common/quickInput.js';
9
import { ConfirmedReason } from '../chatService/chatService.js';
10
import { IToolData, ToolDataSource } from './languageModelToolsService.js';
11
12
export interface ILanguageModelToolConfirmationActions {
13
/** Label for the action */
14
label: string;
15
/** Action detail (e.g. tooltip) */
16
detail?: string;
17
/** Show a separator before this action */
18
divider?: boolean;
19
/** Selects this action. Resolves true if the action should be confirmed after selection */
20
select(): Promise<boolean>;
21
}
22
23
export interface ILanguageModelToolConfirmationRef {
24
toolId: string;
25
source: ToolDataSource;
26
parameters: unknown;
27
}
28
29
export interface ILanguageModelToolConfirmationActionProducer {
30
getPreConfirmAction(ref: ILanguageModelToolConfirmationRef): ConfirmedReason | undefined;
31
getPostConfirmAction(ref: ILanguageModelToolConfirmationRef): ConfirmedReason | undefined;
32
33
/** Gets the selectable actions to take to memorize confirmation changes */
34
getPreConfirmActions(ref: ILanguageModelToolConfirmationRef): ILanguageModelToolConfirmationActions[];
35
getPostConfirmActions(ref: ILanguageModelToolConfirmationRef): ILanguageModelToolConfirmationActions[];
36
}
37
38
export interface ILanguageModelToolConfirmationContributionQuickTreeItem extends IQuickTreeItem {
39
onDidTriggerItemButton?(button: IQuickInputButton): void;
40
onDidChangeChecked?(checked: boolean): void;
41
onDidOpen?(): void;
42
}
43
44
/**
45
* Type that can be registered to provide more specific confirmation
46
* actions for a specific tool.
47
*/
48
export type ILanguageModelToolConfirmationContribution = Partial<ILanguageModelToolConfirmationActionProducer> & {
49
/**
50
* Gets items to be shown in the `manageConfirmationPreferences` quick tree.
51
* These are added under the tool's category.
52
*/
53
getManageActions?(): ILanguageModelToolConfirmationContributionQuickTreeItem[];
54
55
/**
56
* Defaults to true. If false, the "Always Allow" options will not be shown
57
* and _only_ your custom manage actions will be shown.
58
*/
59
canUseDefaultApprovals?: boolean;
60
61
/**
62
* Reset all confirmation settings for this tool.
63
*/
64
reset?(): void;
65
};
66
67
/**
68
* Handles language model tool confirmation.
69
*
70
* - By default, all tools can have their confirmation preferences saved within
71
* a session, workspace, or globally.
72
* - Tools with ToolDataSource from an extension or MCP can have that entire
73
* source's preference saved within a session, workspace, or globally.
74
* - Contributable confirmations may also be registered for specific behaviors.
75
*
76
* Note: this interface MUST NOT depend in the ILanguageModelToolsService.
77
* The ILanguageModelToolsService depends on this service instead in order to
78
* call getPreConfirmAction/getPostConfirmAction.
79
*/
80
export interface ILanguageModelToolsConfirmationService extends ILanguageModelToolConfirmationActionProducer {
81
readonly _serviceBrand: undefined;
82
83
/** Opens an IQuickTree to let the user manage their preferences. */
84
manageConfirmationPreferences(tools: readonly IToolData[], options?: { defaultScope?: 'workspace' | 'profile' | 'session' }): void;
85
86
/**
87
* Registers a contribution that provides more specific confirmation logic
88
* for a tool, in addition to the default confirmation handling.
89
*/
90
registerConfirmationContribution(toolName: string, contribution: ILanguageModelToolConfirmationContribution): IDisposable;
91
92
/** Resets all tool and server confirmation preferences */
93
resetToolAutoConfirmation(): void;
94
}
95
96
export const ILanguageModelToolsConfirmationService = createDecorator<ILanguageModelToolsConfirmationService>('ILanguageModelToolsConfirmationService');
97
98