Path: blob/main/src/vs/workbench/contrib/chat/common/tools/languageModelToolsConfirmationService.ts
4780 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { IDisposable } from '../../../../../base/common/lifecycle.js';6import { createDecorator } from '../../../../../platform/instantiation/common/instantiation.js';7import { IQuickInputButton, IQuickTreeItem } from '../../../../../platform/quickinput/common/quickInput.js';8import { ConfirmedReason } from '../chatService/chatService.js';9import { IToolData, ToolDataSource } from './languageModelToolsService.js';1011export interface ILanguageModelToolConfirmationActions {12/** Label for the action */13label: string;14/** Action detail (e.g. tooltip) */15detail?: string;16/** Show a separator before this action */17divider?: boolean;18/** Selects this action. Resolves true if the action should be confirmed after selection */19select(): Promise<boolean>;20}2122export interface ILanguageModelToolConfirmationRef {23toolId: string;24source: ToolDataSource;25parameters: unknown;26}2728export interface ILanguageModelToolConfirmationActionProducer {29getPreConfirmAction(ref: ILanguageModelToolConfirmationRef): ConfirmedReason | undefined;30getPostConfirmAction(ref: ILanguageModelToolConfirmationRef): ConfirmedReason | undefined;3132/** Gets the selectable actions to take to memorize confirmation changes */33getPreConfirmActions(ref: ILanguageModelToolConfirmationRef): ILanguageModelToolConfirmationActions[];34getPostConfirmActions(ref: ILanguageModelToolConfirmationRef): ILanguageModelToolConfirmationActions[];35}3637export interface ILanguageModelToolConfirmationContributionQuickTreeItem extends IQuickTreeItem {38onDidTriggerItemButton?(button: IQuickInputButton): void;39onDidChangeChecked?(checked: boolean): void;40onDidOpen?(): void;41}4243/**44* Type that can be registered to provide more specific confirmation45* actions for a specific tool.46*/47export type ILanguageModelToolConfirmationContribution = Partial<ILanguageModelToolConfirmationActionProducer> & {48/**49* Gets items to be shown in the `manageConfirmationPreferences` quick tree.50* These are added under the tool's category.51*/52getManageActions?(): ILanguageModelToolConfirmationContributionQuickTreeItem[];5354/**55* Defaults to true. If false, the "Always Allow" options will not be shown56* and _only_ your custom manage actions will be shown.57*/58canUseDefaultApprovals?: boolean;5960/**61* Reset all confirmation settings for this tool.62*/63reset?(): void;64};6566/**67* Handles language model tool confirmation.68*69* - By default, all tools can have their confirmation preferences saved within70* a session, workspace, or globally.71* - Tools with ToolDataSource from an extension or MCP can have that entire72* source's preference saved within a session, workspace, or globally.73* - Contributable confirmations may also be registered for specific behaviors.74*75* Note: this interface MUST NOT depend in the ILanguageModelToolsService.76* The ILanguageModelToolsService depends on this service instead in order to77* call getPreConfirmAction/getPostConfirmAction.78*/79export interface ILanguageModelToolsConfirmationService extends ILanguageModelToolConfirmationActionProducer {80readonly _serviceBrand: undefined;8182/** Opens an IQuickTree to let the user manage their preferences. */83manageConfirmationPreferences(tools: readonly IToolData[], options?: { defaultScope?: 'workspace' | 'profile' | 'session' }): void;8485/**86* Registers a contribution that provides more specific confirmation logic87* for a tool, in addition to the default confirmation handling.88*/89registerConfirmationContribution(toolName: string, contribution: ILanguageModelToolConfirmationContribution): IDisposable;9091/** Resets all tool and server confirmation preferences */92resetToolAutoConfirmation(): void;93}9495export const ILanguageModelToolsConfirmationService = createDecorator<ILanguageModelToolsConfirmationService>('ILanguageModelToolsConfirmationService');969798