//#region extensions/crypto/src/services/user-tool-service.d.ts /** * User-Defined Tool Service — CRUD for user-created tools with persistence. * * Users define tools in plain English or structured JSON. The service: * 1. Stores tool definitions to disk (~/.openclawnch/user-tools/) * 2. Compiles definitions into executable AnyAgentTool-compatible objects * 3. Manages lifecycle: create, update, disable, delete, list * 4. Provides a registry that the plugin can query for dynamic tool loading * * Tool types: * - api_connector: wraps an HTTP API endpoint as a tool * - composed: chains existing tools into a higher-level operation * - custom: user-defined logic via natural language description (LLM-interpreted) * * All user tools run through the SandboxRuntime for safety. */ type UserToolType = 'api_connector' | 'composed' | 'custom'; interface UserToolParam { name: string; type: 'string' | 'number' | 'boolean'; description: string; required: boolean; default?: string | number | boolean; } /** API connector definition: wraps an HTTP endpoint as a tool. */ interface ApiConnectorDef { type: 'api_connector'; /** Base URL (e.g. "https://api.example.com/v1"). */ baseUrl: string; /** HTTP method. */ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'; /** URL path template (e.g. "/users/{{userId}}/balance"). */ path: string; /** Request headers (values can reference secrets: "$SECRET:my_api_key"). */ headers?: Record; /** Body template (for POST/PUT/PATCH). JSON string with {{param}} placeholders. */ bodyTemplate?: string; /** How to extract the result from the response. JSONPath-like (e.g. "data.balance"). */ resultPath?: string; /** Timeout in ms. Default: 15000. */ timeoutMs?: number; } /** Composed tool: chains existing tools in sequence. */ interface ComposedToolDef { type: 'composed'; /** Steps to execute in order. Each step calls an existing tool. */ steps: ComposedStep[]; } interface ComposedStep { /** Step label for display. */ label: string; /** Tool name to call. */ tool: string; /** Arguments to pass. Values can reference prior step outputs: "$step.0.balance". */ args: Record; /** If true, stop the chain on failure. Default: true. */ stopOnFailure?: boolean; } /** Custom tool: LLM-interpreted behavior from natural language. */ interface CustomToolDef { type: 'custom'; /** Natural language description of what the tool does. */ behavior: string; /** Which existing tools this custom tool is allowed to invoke. */ allowedTools: string[]; /** Max number of internal tool calls per execution. Default: 5. */ maxCalls?: number; } type UserToolDefinition = ApiConnectorDef | ComposedToolDef | CustomToolDef; interface UserTool { /** Unique ID. */ id: string; /** Tool name (snake_case, must not conflict with built-in tools). */ name: string; /** Human-readable label. */ label: string; /** LLM-facing description. */ description: string; /** Who created this tool. */ createdBy: string; /** Tool parameters the user can pass. */ params: UserToolParam[]; /** The tool definition (api_connector, composed, or custom). */ definition: UserToolDefinition; /** Whether this tool can write (affects readonly gate). */ isWrite: boolean; /** Whether this tool is currently enabled. */ enabled: boolean; /** Usage count (how many times executed). */ usageCount: number; /** Max budget per execution in USD (for sandboxing). Default: 1. */ maxBudgetUsd: number; /** Tags for organization. */ tags: string[]; createdAt: number; updatedAt: number; } declare class UserToolService { private tools; private stateDir; constructor(opts?: { stateDir?: string; }); /** Create a new user-defined tool. */ create(params: { name: string; label: string; description: string; createdBy: string; params: UserToolParam[]; definition: UserToolDefinition; isWrite?: boolean; maxBudgetUsd?: number; tags?: string[]; }): UserTool; /** Update an existing user tool. */ update(id: string, updates: Partial>): UserTool | null; /** Delete a user tool. */ delete(id: string): boolean; /** Get a user tool by ID. */ get(id: string): UserTool | null; /** Get a user tool by name. */ getByName(name: string): UserTool | null; /** List all user tools, optionally filtered. */ list(opts?: { createdBy?: string; enabled?: boolean; type?: UserToolType; }): UserTool[]; /** Get all enabled user tools (for runtime registration). */ getEnabledTools(): UserTool[]; /** Increment usage count after a tool execution. */ recordUsage(id: string): void; /** Check if a name is available for a new tool. */ isNameAvailable(name: string): { available: boolean; reason?: string; }; /** Clear all state (for testing). */ clear(): void; private validateDefinition; private loadState; private saveState; } declare class UserToolError extends Error { constructor(message: string); } declare function getUserToolService(opts?: { stateDir?: string; }): UserToolService; declare function resetUserToolService(): void; //#endregion export { UserTool as a, UserToolParam as c, getUserToolService as d, resetUserToolService as f, CustomToolDef as i, UserToolService as l, ComposedStep as n, UserToolDefinition as o, ComposedToolDef as r, UserToolError as s, ApiConnectorDef as t, UserToolType as u }; //# sourceMappingURL=user-tool-service-QjL2mMWW.d.mts.map