/** * Tool Registry — central catalog for discovering and accessing tools. * * The registry supports two kinds of tool sources: * 1. **Direct tools** — fully instantiated Tool objects. * 2. **Tool factories** — functions that create tools on demand given a context. * * This design mirrors OpenClaw's plugin tool registration pattern while being * completely standalone. Tools from the openclaw submodule are loaded by the * discovery layer and registered here. * * @module */ import type { Tool, ToolContext, ToolFactory, ToolMeta, ToolProfile, ToolSection } from "../types.js"; /** * Central registry for tool discovery and resolution. * * @example * ```ts * import { ToolRegistry } from "clawtools/tools"; * * const registry = new ToolRegistry(); * * // Register a tool directly * registry.register({ * name: "my_tool", * description: "Does something useful", * parameters: { type: "object", properties: { input: { type: "string" } } }, * execute: async (id, params) => ({ * content: [{ type: "text", text: `Got: ${params.input}` }], * }), * }); * * // Retrieve all tools for a given context * const tools = registry.resolveAll({ workspaceDir: "/my/project" }); * ``` */ export declare class ToolRegistry { private entries; private sections; /** * Register a section label. Called by the discovery layer so that * `listBySection()` can return human-readable labels for core sections. * * @param section - The section to register. */ registerSection(section: ToolSection): void; /** * Register a fully-instantiated tool. * * @param tool - The tool to register. * @param meta - Optional metadata overrides. If omitted, metadata is derived * from the tool itself with sensible defaults. */ register(tool: Tool, meta?: Partial): void; /** * Register a tool factory that will be called when tools are resolved. * * Factories allow deferred tool creation — the factory receives a * {@link ToolContext} and may return one or more tools, or null to skip. * * @param factory - Function that produces tool(s) from a context. * @param meta - Metadata for catalog listing. `id` is required. */ registerFactory(factory: ToolFactory, meta: ToolMeta): void; /** * Resolve all registered tools for a given context. * * Direct tools are returned as-is. Factories are invoked with the provided * context and their results are included. * * @param ctx - The context to pass to tool factories. * @param onError - Optional callback invoked when a factory throws. Receives * the tool metadata and the thrown error. If omitted, errors are silently * discarded (same behaviour as before). * @returns An array of resolved tools. */ resolveAll(ctx?: ToolContext, onError?: (meta: ToolMeta, err: unknown) => void): Tool[]; /** * Resolve tools filtered by a tool profile. * * @param profile - The profile to filter by ("minimal", "coding", "messaging", "full"). * Passing `"full"` acts as a wildcard — all registered tools are included. * @param ctx - The context to pass to tool factories. * @param onError - Optional callback invoked when a factory throws. * @param options - Additional filter options. * @param options.includeAll - If `true`, include all registered tools regardless of * their `profiles` array. Equivalent to passing `profile: "full"` and kept for * call-site clarity. Backward-compatible with the existing `"full"` string. * @returns An array of resolved tools matching the profile. */ resolveByProfile(profile: ToolProfile, ctx?: ToolContext, onError?: (meta: ToolMeta, err: unknown) => void, options?: { includeAll?: boolean; }): Tool[]; /** * Resolve a single tool by name. * * @param name - The tool's canonical name. * @param ctx - The context to pass to tool factories. * @param onError - Optional callback invoked when the factory throws. * @returns The resolved tool, or undefined if not found. */ resolve(name: string, ctx?: ToolContext, onError?: (meta: ToolMeta, err: unknown) => void): Tool | undefined; /** * List metadata for all registered tools (without resolving factories). * * @returns An array of tool metadata entries. */ list(): ToolMeta[]; /** * List metadata grouped by section. * * @returns An array of sections, each containing their tools' metadata. */ listBySection(): Array; /** * Check whether a tool with the given name is registered. */ has(name: string): boolean; /** * Remove a tool from the registry. */ unregister(name: string): boolean; /** * Remove all registered tools. */ clear(): void; /** * The number of registered tools. */ get size(): number; private resolveEntry; } //# sourceMappingURL=registry.d.ts.map