/** * Generic JSON Schema type */ export type JSONSchema = Record; /** * GraphQL request generated by the LLM */ export type GraphQLRequest = { /** The GraphQL query or mutation string */ query: string; /** Variables for the operation */ variables?: Record; /** Optional operation name if multiple operations in query */ operationName?: string; }; /** * REST request generated by the LLM */ export type RESTRequest = { /** HTTP method */ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE"; /** Path (e.g., "/users/123") */ path: string; /** Query parameters */ query?: Record; /** Request body */ body?: unknown; }; /** * Payload for a tool call request from the iframe */ export type ToolCallPayload = { id: string; name: string; args: unknown; }; /** * Successful tool call result */ export type ToolCallSuccess = { ok: true; result: unknown; }; /** * Failed tool call result */ export type ToolCallError = { ok: false; error: string; }; /** * Union type for tool call responses */ export type ToolCallResult = ToolCallSuccess | ToolCallError; /** * Definition of a single tool available to the LLM */ export type ToolDefinition = { /** Fully qualified procedure name, e.g. "orders.list" */ name: string; /** Human friendly label */ displayName?: string; /** Description shown to the LLM as a tool description */ description?: string; /** Optional JSON Schema for input args */ inputSchema?: JSONSchema; /** Optional JSON Schema for output shape */ outputSchema?: JSONSchema; }; /** * Manifest of all tools available to the chatbot */ export type ToolManifest = { tools: ToolDefinition[]; generated_at?: string; sources?: Array<{ id: string; count: number; }>; }; /** * Tool executor function type (server-side, receives Request object) */ export type ToolExecutor = (name: string, args: unknown, req: Request) => Promise; /** * Tool call handler for client-side integration. * The consuming app decides how to execute the tool call. * * @param name - The tool name being called * @param args - The arguments for the tool * @returns The result of the tool execution * @throws Error if the tool call fails */ export type ToolCallHandler = (name: string, args: unknown) => Promise; /** * Event emitted after a tool call completes (success or failure). * Useful for page-level cache invalidation. */ export type ToolCallEvent = { /** The tool name that was called */ name: string; /** The arguments passed to the tool */ args: unknown; /** Whether the call succeeded */ ok: boolean; /** The result (if ok is true) */ result?: unknown; /** The error message (if ok is false) */ error?: string; }; /** * Listener for tool call completion events. * Called after every tool call completes, regardless of success/failure. */ export type ToolCallEventListener = (event: ToolCallEvent) => void; /** * Client-side tool adapter — the browser-side analogue of the server `ToolSource`. * * An adapter contributes tool definitions to the single merged manifest injected * into the iframe AND knows how to execute the tools it owns. Adapters are composed * with {@link createYakToolset} into one manifest + one `onToolCall` funnel, so * GraphQL, REST, tRPC (server-relayed via {@link createYakServerAdapter}), and custom * tools all flow through the same path — and therefore all surface through * `onToolCallComplete` / `useYakToolEvent`. */ export type ToolAdapter = { /** Stable id for diagnostics / manifest source attribution. */ id?: string; /** Tool definitions this adapter contributes to the merged manifest. */ getTools: () => ToolDefinition[] | Promise; /** Execute a tool this adapter owns. Same signature as {@link ToolCallHandler}. */ execute: ToolCallHandler; /** * Whether this adapter owns `name`. When omitted, ownership defaults to * membership in the names returned by {@link ToolAdapter.getTools}. */ ownsTool?: (name: string) => boolean; }; /** * The result of composing {@link ToolAdapter}s with {@link createYakToolset}: * a merged tool manifest for `getConfig()` and a single routed `onToolCall`. */ export type YakToolset = { /** Resolved, merged + deduped tool manifest — spread into `getConfig().tools`. */ getConfig: () => Promise<{ tools: ToolManifest; }>; /** Single routed funnel for `YakProvider.onToolCall` / `YakClientConfig.onToolCall`. */ onToolCall: ToolCallHandler; }; //# sourceMappingURL=tools.d.ts.map