Path: blob/main/src/vs/workbench/contrib/chat/common/tools/languageModelToolsConfirmationService.ts
5244 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 { URI } from '../../../../../base/common/uri.js';7import { createDecorator } from '../../../../../platform/instantiation/common/instantiation.js';8import { IQuickInputButton, IQuickTreeItem } from '../../../../../platform/quickinput/common/quickInput.js';9import { ConfirmedReason } from '../chatService/chatService.js';10import { IToolData, ToolDataSource } from './languageModelToolsService.js';1112export interface ILanguageModelToolConfirmationActions {13/** Label for the action */14label: string;15/** Action detail (e.g. tooltip) */16detail?: string;17/** Show a separator before this action */18divider?: boolean;19/** Selects this action. Resolves true if the action should be confirmed after selection */20select(): Promise<boolean>;21}2223export interface ILanguageModelToolConfirmationRef {24toolId: string;25source: ToolDataSource;26parameters: unknown;27chatSessionResource?: URI;28}2930export interface ILanguageModelToolConfirmationActionProducer {31getPreConfirmAction(ref: ILanguageModelToolConfirmationRef): ConfirmedReason | undefined;32getPostConfirmAction(ref: ILanguageModelToolConfirmationRef): ConfirmedReason | undefined;3334/** Gets the selectable actions to take to memorize confirmation changes */35getPreConfirmActions(ref: ILanguageModelToolConfirmationRef): ILanguageModelToolConfirmationActions[];36getPostConfirmActions(ref: ILanguageModelToolConfirmationRef): ILanguageModelToolConfirmationActions[];37}3839export interface ILanguageModelToolConfirmationContributionQuickTreeItem extends IQuickTreeItem {40onDidTriggerItemButton?(button: IQuickInputButton): void;41onDidChangeChecked?(checked: boolean): void;42onDidOpen?(): void;43}4445/**46* Type that can be registered to provide more specific confirmation47* actions for a specific tool.48*/49export type ILanguageModelToolConfirmationContribution = Partial<ILanguageModelToolConfirmationActionProducer> & {50/**51* Gets items to be shown in the `manageConfirmationPreferences` quick tree.52* These are added under the tool's category.53*/54getManageActions?(): ILanguageModelToolConfirmationContributionQuickTreeItem[];5556/**57* Defaults to true. If false, the "Always Allow" options will not be shown58* and _only_ your custom manage actions will be shown.59*/60canUseDefaultApprovals?: boolean;6162/**63* Reset all confirmation settings for this tool.64*/65reset?(): void;66};6768/**69* Handles language model tool confirmation.70*71* - By default, all tools can have their confirmation preferences saved within72* a session, workspace, or globally.73* - Tools with ToolDataSource from an extension or MCP can have that entire74* source's preference saved within a session, workspace, or globally.75* - Contributable confirmations may also be registered for specific behaviors.76*77* Note: this interface MUST NOT depend in the ILanguageModelToolsService.78* The ILanguageModelToolsService depends on this service instead in order to79* call getPreConfirmAction/getPostConfirmAction.80*/81export interface ILanguageModelToolsConfirmationService extends ILanguageModelToolConfirmationActionProducer {82readonly _serviceBrand: undefined;8384/** Opens an IQuickTree to let the user manage their preferences. */85manageConfirmationPreferences(tools: readonly IToolData[], options?: { defaultScope?: 'workspace' | 'profile' | 'session' }): void;8687/**88* Registers a contribution that provides more specific confirmation logic89* for a tool, in addition to the default confirmation handling.90*/91registerConfirmationContribution(toolName: string, contribution: ILanguageModelToolConfirmationContribution): IDisposable;9293/** Resets all tool and server confirmation preferences */94resetToolAutoConfirmation(): void;95}9697export const ILanguageModelToolsConfirmationService = createDecorator<ILanguageModelToolsConfirmationService>('ILanguageModelToolsConfirmationService');9899100