import type { StringOrMarkdown, ToolDefinition, URI } from "./state/sessionState.js"; /** * A server tool definition plus agent-host-local metadata that is not part of * the wire protocol. */ export interface IAgentServerToolDefinition extends ToolDefinition { /** * Whether this tool is offered to ephemeral sessions. Defaults to `false` so * throwaway surfaces do not pay for session-management tooling. */ readonly enabledForEphemeralSessions?: boolean; /** Available to owning chats, but not their native or protocol subagents. */ readonly topLevelChatOnly?: boolean; /** * Defers the tool behind discovery when supported; `false` keeps it eager, * which sends its definition on every model request. When omitted, Copilot * sessions defer the tool and other providers keep their SDK defaults. */ readonly deferLoading?: boolean; } /** * Server-side host for the agent host's **server tools** — tools that the * agent host owns and executes in-process (against a session's own state * channels) rather than round-tripping to the workbench. Providers (Copilot, * Claude) implement nothing here; they consume this host to discover the * server tools, advertise them on a session, and execute them by name. * * The set of server tools is open-ended: each group of tools (feedback * "comments" is the first) is contributed to the host at startup, so providers * never hard-code any specific tool — they read {@link definitions} / * {@link toolNames} and route through {@link executeTool}. * * Tool invocation methods take the exact Agent Host chat channel URI. The host * resolves its owning session for session-scoped state and tools. */ /** The confirmation a server tool's call shows, built with the host's state. */ export interface IServerToolConfirmationDisplay { readonly confirmationTitle?: string; readonly confirmationMessage?: StringOrMarkdown; readonly hideConfirmationInput?: boolean; } export interface IAgentServerToolHost { /** Every server tool definition across the contributed groups. */ readonly definitions: readonly IAgentServerToolDefinition[]; /** Server tools eligible for the given session, honoring ephemeral eligibility. */ getDefinitionsForSession(sessionUri: URI): readonly IAgentServerToolDefinition[]; /** Routable server-tool names, including materialized tools retained by sessions after root settings change. */ readonly toolNames: readonly string[]; /** Advertises all server tools on the owning session, accepting a session or chat URI. */ advertise(sessionOrChatUri: URI): void; /** * Whether {@link toolName} can ever prompt for confirmation, independent of * any session's current state. Providers use this to decide up front which * tools must route through their confirmation path; a tool that answers * `false` is auto-approved and never asks {@link requiresConfirmation}. * Returns `false` for unknown tools. * * This must stay session-independent: providers bake the answer into * long-lived SDK allow-lists, so a state-dependent value would go stale. */ canRequireConfirmation(toolName: string): boolean; /** * Whether {@link toolName} needs to prompt for *this* invocation, given the * current state of {@link chatUri}. Lets a tool that normally confirms * run silently when it has nothing to confirm. Defaults to * {@link canRequireConfirmation} when the owning group has no * session-specific condition. * * Providers must consult this before prompting or executing the tool. */ requiresConfirmation(chatUri: URI, toolName: string): boolean; /** * The confirmation a call of {@link toolName} with {@link args} shows, built by its group with the host's state * (for example, linking only sessions the host knows). `undefined` for a tool with no confirmation display, where * providers fall back to their generic one. */ getConfirmationDisplay(toolName: string, args: unknown): IServerToolConfirmationDisplay | undefined; /** * Executes a server tool for the exact chat that invoked it, dispatching any * resulting actions, and returns the textual tool result for the agent. * * @throws if {@link toolName} is not a known server tool or the arguments * are invalid. */ executeTool(chatUri: URI, toolName: string, rawArgs: unknown): string | Promise; }