import type { Tool } from "ai"; export interface ToolMiddleware { /** Called before tool execution. Can modify params or throw to block. */ beforeExecute?: (context: ToolCallContext) => Promise | void; /** Called after successful execution. */ afterExecute?: (context: ToolCallContext & { result: unknown; durationMs: number; }) => Promise | void; /** Called on execution error. Return a value to use as fallback result, or rethrow. */ onError?: (context: ToolCallContext & { error: unknown; }) => Promise | unknown; } export interface ToolCallContext { toolName: string; params: unknown; timestamp: number; } /** * Wrap a set of tools with middleware hooks (logging, rate limiting, error handling, etc.). * Returns a new tools object with the same keys but wrapped execute functions. * * ```ts * const tools = withMiddleware(createTikTokTools(opts), { * beforeExecute: ({ toolName }) => console.log(`Calling ${toolName}`), * afterExecute: ({ toolName, durationMs }) => console.log(`${toolName} took ${durationMs}ms`), * onError: ({ toolName, error }) => ({ error: `${toolName} failed: ${error}` }), * }); * ``` */ export declare function withMiddleware>(tools: T, middleware: ToolMiddleware): T; //# sourceMappingURL=middleware.d.ts.map