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