UNPKG

agents

Version:

A home for your AI agents

78 lines (76 loc) • 2.4 kB
import { C as WebSearchResponse, E as WebSearchToolOutput, T as WebSearchToolInput, c as WebSearchError, d as WebSearchProvider, l as WebSearchErrorCode, p as WebSearchSource, r as WebSearchToolOptions, w as WebSearchResult } from "../../../tool-CTp72Jb_.js"; import { FlexibleSchema } from "ai"; //#region src/web/search/tools/ai-sdk.d.ts /** * The part of the AI SDK's tool execution options the tool reads. Spelled * out rather than imported so it fits every supported `ai` major. */ interface WebSearchToolExecuteOptions { abortSignal?: AbortSignal; } /** * The AI SDK tool {@link webSearchTool} returns. Assignable to the AI SDK's * `Tool`; `execute` and `toModelOutput` are always present. */ interface WebSearchTool { description: string; inputSchema: FlexibleSchema<WebSearchToolInput>; execute( input: WebSearchToolInput, options: WebSearchToolExecuteOptions ): Promise<WebSearchToolOutput>; toModelOutput(options: { output: WebSearchToolOutput }): { type: "text"; value: string; }; } /** * Create an AI SDK tool that searches the web through Cloudflare's Web * Search API. The host gets the full response as the tool's output (whole * descriptions, provider metadata); the model gets a trimmed text rendering * via `toModelOutput`. A failed search throws a `WebSearchError`, which the * AI SDK reports to the model as a tool error: its `message` is written for * the model, and its `cause` is the source's error with the API's detail. * * `toModelOutput` only applies to earlier turns when the tools are passed to * `convertToModelMessages(messages, { tools })`; otherwise the AI SDK sends * the full response back to the model as JSON. `AiSdkHarness` passes them. * * @example * ```ts * import { webSearchTool } from "agents/websearch/ai-sdk"; * * const result = streamText({ * model, * tools: { web_search: webSearchTool({ binding: env.AI }) }, * messages * }); * ``` */ declare function webSearchTool(options: WebSearchToolOptions): WebSearchTool; //#endregion export { WebSearchError, type WebSearchErrorCode, type WebSearchProvider, type WebSearchResponse, type WebSearchResult, type WebSearchSource, WebSearchTool, WebSearchToolExecuteOptions, type WebSearchToolInput, type WebSearchToolOptions, type WebSearchToolOutput, webSearchTool }; //# sourceMappingURL=ai-sdk.d.ts.map