import { Separator } from "../../../../base/common/actions.js";
import { VSBuffer } from "../../../../base/common/buffer.js";
import { CancellationToken } from "../../../../base/common/cancellation.js";
import { IMarkdownString } from "../../../../base/common/htmlContent.js";
import { IJSONSchema } from "../../../../base/common/jsonSchema.js";
import { IDisposable } from "../../../../base/common/lifecycle.js";
import { IObservable, IReader, ITransaction, ObservableSet } from "../../../../base/common/observable.js";
import { ThemeIcon } from "../../../../base/common/themables.js";
import { URI } from "../../../../base/common/uri.js";
import { Location } from "../../../../editor/common/languages.js";
import { ContextKeyExpression } from "../../../../platform/contextkey/common/contextkey.js";
import { ExtensionIdentifier } from "../../../../platform/extensions/common/extensions.js";
import { IProgress } from "../../../../platform/progress/common/progress.js";
import { UserSelectedTools } from "@codingame/monaco-vscode-aac7027b-326c-513a-95a9-e4eedd151b38-common/vscode/vs/workbench/contrib/chat/common/chatAgents";
import { IChatExtensionsContent, IChatTodoListContent, IChatToolInputInvocationData, type IChatTerminalToolInvocationData } from "./chatService.js";
import { LanguageModelPartAudience } from "./languageModels.js";
export interface IToolData {
    id: string;
    source: ToolDataSource;
    toolReferenceName?: string;
    icon?: {
        dark: URI;
        light?: URI;
    } | ThemeIcon;
    when?: ContextKeyExpression;
    tags?: string[];
    displayName: string;
    userDescription?: string;
    modelDescription: string;
    inputSchema?: IJSONSchema;
    canBeReferencedInPrompt?: boolean;
    /**
     * True if the tool runs in the (possibly remote) workspace, false if it runs
     * on the host, undefined if known.
     */
    runsInWorkspace?: boolean;
    alwaysDisplayInputOutput?: boolean;
    /** True if this tool might ask for pre-approval */
    canRequestPreApproval?: boolean;
    /** True if this tool might ask for post-approval */
    canRequestPostApproval?: boolean;
}
export interface IToolProgressStep {
    readonly message: string | IMarkdownString | undefined;
    /** 0-1 progress of the tool call */
    readonly progress?: number;
}
export type ToolProgress = IProgress<IToolProgressStep>;
export type ToolDataSource = {
    type: "extension";
    label: string;
    extensionId: ExtensionIdentifier;
} | {
    type: "mcp";
    label: string;
    serverLabel: string | undefined;
    instructions: string | undefined;
    collectionId: string;
    definitionId: string;
} | {
    type: "user";
    label: string;
    file: URI;
} | {
    type: "internal";
    label: string;
} | {
    type: "external";
    label: string;
};
export declare namespace ToolDataSource {
    const Internal: ToolDataSource;
    /** External tools may not be contributed or invoked, but may be invoked externally and described in an IChatToolInvocationSerialized */
    const External: ToolDataSource;
    function toKey(source: ToolDataSource): string;
    function equals(a: ToolDataSource, b: ToolDataSource): boolean;
    function classify(source: ToolDataSource): {
        readonly ordinal: number;
        readonly label: string;
    };
}
export interface IToolInvocation {
    callId: string;
    toolId: string;
    parameters: Object;
    tokenBudget?: number;
    context: IToolInvocationContext | undefined;
    chatRequestId?: string;
    chatInteractionId?: string;
    /**
     * Lets us add some nicer UI to toolcalls that came from a sub-agent, but in the long run, this should probably just be rendered in a similar way to thinking text + tool call groups
     */
    fromSubAgent?: boolean;
    toolSpecificData?: IChatTerminalToolInvocationData | IChatToolInputInvocationData | IChatExtensionsContent | IChatTodoListContent;
    modelId?: string;
    userSelectedTools?: UserSelectedTools;
}
export interface IToolInvocationContext {
    sessionId: string;
}
export declare function isToolInvocationContext(obj: any): obj is IToolInvocationContext;
export interface IToolInvocationPreparationContext {
    parameters: any;
    chatRequestId?: string;
    chatSessionId?: string;
    chatInteractionId?: string;
}
export type ToolInputOutputBase = {
    /** Mimetype of the value, optional */
    mimeType?: string;
    /** URI of the resource on the MCP server. */
    uri?: URI;
    /** If true, this part came in as a resource reference rather than direct data. */
    asResource?: boolean;
    /** Audience of the data part */
    audience?: LanguageModelPartAudience[];
};
export type ToolInputOutputEmbedded = ToolInputOutputBase & {
    type: "embed";
    value: string;
    /** If true, value is text. If false or not given, value is base64 */
    isText?: boolean;
};
export type ToolInputOutputReference = ToolInputOutputBase & {
    type: "ref";
    uri: URI;
};
export interface IToolResultInputOutputDetails {
    readonly input: string;
    readonly output: (ToolInputOutputEmbedded | ToolInputOutputReference)[];
    readonly isError?: boolean;
}
export interface IToolResultOutputDetails {
    readonly output: {
        type: "data";
        mimeType: string;
        value: VSBuffer;
    };
}
export declare function isToolResultInputOutputDetails(obj: any): obj is IToolResultInputOutputDetails;
export declare function isToolResultOutputDetails(obj: any): obj is IToolResultOutputDetails;
export interface IToolResult {
    content: (IToolResultPromptTsxPart | IToolResultTextPart | IToolResultDataPart)[];
    toolResultMessage?: string | IMarkdownString;
    toolResultDetails?: Array<URI | Location> | IToolResultInputOutputDetails | IToolResultOutputDetails;
    toolResultError?: string;
    toolMetadata?: unknown;
    /** Whether to ask the user to confirm these tool results. Overrides {@link IToolConfirmationMessages.confirmResults}. */
    confirmResults?: boolean;
}
export declare function toolContentToA11yString(part: IToolResult["content"]): string;
export declare function toolResultHasBuffers(result: IToolResult): boolean;
export interface IToolResultPromptTsxPart {
    kind: "promptTsx";
    value: unknown;
}
export declare function stringifyPromptTsxPart(part: IToolResultPromptTsxPart): string;
export interface IToolResultTextPart {
    kind: "text";
    value: string;
    audience?: LanguageModelPartAudience[];
}
export interface IToolResultDataPart {
    kind: "data";
    value: {
        mimeType: string;
        data: VSBuffer;
    };
    audience?: LanguageModelPartAudience[];
}
export interface IToolConfirmationMessages {
    /** Title for the confirmation. If set, the user will be asked to confirm execution of the tool */
    title?: string | IMarkdownString;
    /** MUST be set if `title` is also set */
    message?: string | IMarkdownString;
    disclaimer?: string | IMarkdownString;
    allowAutoConfirm?: boolean;
    terminalCustomActions?: ToolConfirmationAction[];
    /** If true, confirmation will be requested after the tool executes and before results are sent to the model */
    confirmResults?: boolean;
}
export interface IToolConfirmationAction {
    label: string;
    disabled?: boolean;
    tooltip?: string;
    data: any;
}
export type ToolConfirmationAction = IToolConfirmationAction | Separator;
export declare enum ToolInvocationPresentation {
    Hidden = "hidden",
    HiddenAfterComplete = "hiddenAfterComplete"
}
export interface IPreparedToolInvocation {
    invocationMessage?: string | IMarkdownString;
    pastTenseMessage?: string | IMarkdownString;
    originMessage?: string | IMarkdownString;
    confirmationMessages?: IToolConfirmationMessages;
    presentation?: ToolInvocationPresentation;
    toolSpecificData?: IChatTerminalToolInvocationData | IChatToolInputInvocationData | IChatExtensionsContent | IChatTodoListContent;
}
export interface IToolImpl {
    invoke(invocation: IToolInvocation, countTokens: CountTokensCallback, progress: ToolProgress, token: CancellationToken): Promise<IToolResult>;
    prepareToolInvocation?(context: IToolInvocationPreparationContext, token: CancellationToken): Promise<IPreparedToolInvocation | undefined>;
}
export type IToolAndToolSetEnablementMap = ReadonlyMap<IToolData | ToolSet, boolean>;
export declare class ToolSet {
    readonly id: string;
    readonly referenceName: string;
    readonly icon: ThemeIcon;
    readonly source: ToolDataSource;
    readonly description?: string | undefined;
    protected readonly _tools: ObservableSet<IToolData>;
    protected readonly _toolSets: ObservableSet<ToolSet>;
    /**
     * A homogenous tool set only contains tools from the same source as the tool set itself
     */
    readonly isHomogenous: IObservable<boolean>;
    constructor(id: string, referenceName: string, icon: ThemeIcon, source: ToolDataSource, description?: string | undefined);
    addTool(data: IToolData, tx?: ITransaction): IDisposable;
    addToolSet(toolSet: ToolSet, tx?: ITransaction): IDisposable;
    getTools(r?: IReader): Iterable<IToolData>;
}
export type CountTokensCallback = (input: string, token: CancellationToken) => Promise<number>;
export declare function createToolInputUri(toolCallId: string): URI;
export declare function createToolSchemaUri(toolOrId: IToolData | string): URI;
export declare namespace GithubCopilotToolReference {
    const shell = "shell";
    const edit = "edit";
    const search = "search";
    const customAgent = "custom-agent";
}
export declare namespace VSCodeToolReference {
    const runCommands = "runCommands";
    const runSubagent = "runSubagent";
}
