import type { ToolDescriptionMode, ToolDescriptionModeConfig } from '../types/config.js'; import type { Tool } from '../types/tool.js'; /** * A function that wraps (decorates) an existing tool. Receives the * original tool and returns a modified version — typically the same * tool with a wrapped `execute` / `executeStream`, or with modified * metadata (description, permission). * * Use `ToolRegistry.wrap()` to apply; the wrapper is called immediately * and the result replaces the registered tool. Multiple wraps stack — * each wrapper receives the output of the previous. * * @example * ```ts * registry.wrap('read', (original) => ({ * ...original, * async execute(input, ctx, opts) { * console.log('read called'); * return original.execute(input, ctx, opts); * } * })); * ``` */ export type ToolWrapper = (tool: Tool) => Tool; export declare class ToolRegistry { private readonly tools; private readonly descriptionModes; /** * Set of tool names that are disabled (hidden from list(), get() and all * other public accessors). The underlying tool data stays in `_tools` so * re-enable is a constant-time operation. */ private readonly _disabled; /** Monotonic version bumped on every registry mutation. */ private _version; /** Cached `list()` result, frozen after build. Invalidated on _version change. */ private _listSnapshot; private _listSnapshotVersion; /** Pre-compute tool definition token estimate once at registration time. */ private _stampDefTokens; /** Apply the description mode transform and stamp token estimates. */ private _prepareForStorage; register(tool: Tool, owner?: string): void; /** * Attempt to register a tool. Returns true if successful, false if a tool * with the same name is already registered. Useful in multi-agent or plugin * scenarios where duplicate registration may be intentional. */ tryRegister(tool: Tool, owner?: string): boolean; /** * Bulk-register multiple tools at once. Each tool that conflicts with an * existing registration is silently skipped — use `registerAllOrThrow` * if you want it to throw on conflicts. */ registerAll(tools: Tool[], owner?: string): void; /** * Bulk-register and throw on the first conflict. Use when you need * strict registration (e.g. at boot time). */ registerAllOrThrow(tools: Tool[], owner?: string): void; /** * Register a tool as a default. If the tool name is already registered, * this is a no-op — the existing registration (from core or another * plugin) takes precedence. Use `override` to intentionally replace. */ registerDefault(tool: Tool, owner?: string): void; unregister(name: string): boolean; /** * Override an existing tool. Throws if the tool is not already registered. * Plugins use this to replace built-in tools with custom implementations. */ override(name: string, tool: Tool, owner?: string): void; /** * Wrap (decorate) an existing tool. The wrapper receives the current * tool and must return a new tool — typically the same tool with a * wrapped `execute` or `executeStream`. Throws if the tool is not * registered. * * Multiple wraps stack: each wrapper gets the output of the previous. * * @example * registry.wrap('bash', (t) => ({ ...t, permission: 'confirm' })); */ wrap(name: string, wrapper: ToolWrapper, owner?: string): void; setDescriptionMode(name: string, mode: ToolDescriptionMode): boolean; getDescriptionMode(name: string): ToolDescriptionMode; applyDescriptionModes(modes?: ToolDescriptionModeConfig): { applied: number; missing: string[]; }; get(name: string): Tool | undefined; ownerOf(name: string): string | undefined; /** * Disable a tool by name. The tool is removed from all public accessors * (list(), get(), listByCategory(), listWithOwner()) so it does NOT * appear in the system prompt or provider request. The underlying * registration is preserved in memory — use `enable()` to restore it. * * @returns `true` if the tool was found and disabled; `false` if the * tool is not registered or is already disabled. */ disable(name: string): boolean; /** * Re-enable a previously disabled tool. The tool reappears in all * public accessors and will be included in the next system prompt / * provider request. * * @returns `true` if the tool was disabled and is now re-enabled; * `false` if the tool was not disabled. */ enable(name: string): boolean; /** * Re-enable ALL currently disabled tools at once. Returns the number * of tools that were re-enabled. */ enableAll(): number; /** * Check whether a tool is currently disabled. */ isDisabled(name: string): boolean; /** * Apply a list of tool names to disable. Tools not in the registry * are silently ignored so config can reference future tools without * error. Returns the number of tools actually disabled. */ applyDisabled(names: readonly string[]): number; /** * Return the list of all disabled tool entries (tool + owner). Useful * for the /tools slash command to show disabled tools alongside * enabled ones. */ listDisabled(): { tool: Tool; owner: string; }[]; list(): Tool[]; /** * Group tools by their `category` field. Tools without a category * are placed under the key `""` (empty string). Returns a Map of * category → tools, sorted by registration order within each category. */ listByCategory(): Map; listWithOwner(): { tool: Tool; owner: string; }[]; clear(): void; /** * Return a new ToolRegistry with the same registered tools and owners. * Useful for creating filtered copies in multi-agent scenarios. */ clone(): ToolRegistry; } //# sourceMappingURL=tool-registry.d.ts.map