agents
Version:
A home for your AI agents
45 lines (44 loc) • 1.5 kB
JavaScript
import { a as WebFetchError, r as toolFailure, t as createWebFetchToolCore } from "../../../tool-CxKsvxjm.js";
import { t as webFetchInputSchema } from "../../../input-schema-0uUu392-.js";
import { toolDefinition } from "@tanstack/ai";
//#region src/web/fetch/tools/tanstack-ai.ts
/**
* `agents/webfetch/tanstack-ai` — the `web_fetch` tool for TanStack AI.
*
* @beta
*/
/**
* Create a TanStack AI tool that reads a URL as Markdown, JSON, or text.
* TanStack AI has one return channel, so the model and the host both get
* the rendered window. A failed fetch throws a `WebFetchError`, 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 detail. The tool is
* named `web_fetch` unless you pass `name`.
*
* @example
* ```ts
* import { webFetchTool } from "agents/webfetch/tanstack-ai";
* import { chat } from "@tanstack/ai";
*
* const stream = chat({
* adapter,
* tools: [webFetchTool({ binding: env.AI })],
* messages
* });
* ```
*/
function webFetchTool(options) {
const core = createWebFetchToolCore(options);
return toolDefinition({
name: options.name ?? core.name,
description: core.description,
inputSchema: webFetchInputSchema()
}).server(async (input, context) => {
const run = await core.run(input, { signal: context?.abortSignal });
if (!run.ok) throw toolFailure(run);
return run.text;
});
}
//#endregion
export { WebFetchError, webFetchTool };
//# sourceMappingURL=tanstack-ai.js.map