UNPKG

agents

Version:

A home for your AI agents

93 lines (91 loc) • 2.67 kB
import { i as QuickActionToolName, r as CreateQuickActionToolsOptions, s as createQuickActionTools } from "../../ai-CDn3Abax.js"; import { T as BrowserSource, b as BrowserNewTab } from "../../browser-C9T74n4c.js"; import { n as BrowserToolOptions, r as BrowserToolOutput, t as BrowserToolInput } from "../../browser-tool-DxAYQY9T.js"; import { FlexibleSchema, JSONValue } from "ai"; //#region src/browser/tool-helpers.d.ts /** What the model sees in place of a browser tool's output. */ type BrowserModelOutput = | { type: "text"; value: string; } | { type: "json"; value: JSONValue; }; //#endregion //#region src/browser/tools/ai-sdk.d.ts /** * The AI SDK tool {@link browserTool} returns. Assignable to the AI SDK's * `Tool`, and `execute` / `toModelOutput` are always present. */ interface BrowserTool { description: string; inputSchema: FlexibleSchema<BrowserToolInput>; execute( input: BrowserToolInput, options: unknown ): Promise<BrowserToolOutput>; toModelOutput(options: { output: BrowserToolOutput }): BrowserModelOutput; } /** * Create an AI SDK tool that lets the model drive a persistent browser with * JavaScript and the Chrome DevTools Protocol. * * The browser outlives each run: tabs, cookies, and logins carry over. The * model never starts, closes, or resets it, and `sessionId: "active"` * addresses the tab it last worked in. If the browser had to be replaced * (it expired or was closed), the code still runs in the new browser and the * result's `notice` says so. * * Browser Run only (Chromium). Guardrails, `keepAliveMs`, and recording are * set on the `Browser`'s provider. * * @example * ```ts * import { Browser, browserRun } from "agents/browser"; * import { browserTool } from "agents/browser/ai-sdk"; * * export class MyAgent extends Agent<Env> { * browser = new Browser({ provider: browserRun(this.env.BROWSER) }); * * constructor(ctx: AgentContext, env: Env) { * super(ctx, env); * this.lifecycle.use(this.browser); * } * * async onChatMessage() { * const tools = { * browser: browserTool({ browser: this.browser, loader: this.env.LOADER }) * }; * // …pass `tools` to streamText / generateText * } * } * ``` */ declare function browserTool(options: BrowserToolOptions): BrowserTool; //#endregion export { type BrowserNewTab, type BrowserSource, BrowserTool, type BrowserToolInput, type BrowserToolOptions, type BrowserToolOutput, type CreateQuickActionToolsOptions, type QuickActionToolName, browserTool, createQuickActionTools }; //# sourceMappingURL=ai-sdk.d.ts.map