UNPKG

agents

Version:

A home for your AI agents

46 lines (45 loc) • 1.56 kB
import { i as WebSearchError, n as createWebSearchToolCore, r as toolFailure } from "../../../tool-DkT_DJBm.js"; import { t as webSearchInputSchema } from "../../../input-schema-waggtYrH.js"; import { toolDefinition } from "@tanstack/ai"; //#region src/web/search/tools/tanstack-ai.ts /** * `agents/websearch/tanstack-ai` — the `web_search` tool for TanStack AI. * * @beta */ /** * Create a TanStack AI tool that searches the web through Cloudflare's Web * Search API. TanStack AI has one return channel, so the model and the host * both get the trimmed text rendering. A failed search throws a * `WebSearchError`, which TanStack AI reports as an error result: its * `message` is written for the model, and its `cause` is the source's error * with the API's detail. The tool is named `web_search` unless you pass * `name`. * * @example * ```ts * import { webSearchTool } from "agents/websearch/tanstack-ai"; * import { chat } from "@tanstack/ai"; * * const stream = chat({ * adapter, * tools: [webSearchTool({ binding: env.AI })], * messages * }); * ``` */ function webSearchTool(options) { const core = createWebSearchToolCore(options); return toolDefinition({ name: options.name ?? core.name, description: core.description, inputSchema: webSearchInputSchema(core.limit) }).server(async (input, context) => { const run = await core.run(input, { signal: context?.abortSignal }); if (!run.ok) throw toolFailure(run); return run.text; }); } //#endregion export { WebSearchError, webSearchTool }; //# sourceMappingURL=tanstack-ai.js.map