agents 0.32.0 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/ai-sdk-CpuRsjP5.d.ts +72 -0
  2. package/dist/browser/ai.js +2 -3
  3. package/dist/browser/ai.js.map +1 -1
  4. package/dist/browser/index.d.ts +29 -21
  5. package/dist/browser/index.js +937 -4
  6. package/dist/browser/index.js.map +1 -0
  7. package/dist/browser/tools/ai-sdk.d.ts +5 -70
  8. package/dist/browser/tools/ai-sdk.js +9 -3
  9. package/dist/browser/tools/ai-sdk.js.map +1 -1
  10. package/dist/browser/tools/pi.d.ts +11 -8
  11. package/dist/browser/tools/pi.js +58 -11
  12. package/dist/browser/tools/pi.js.map +1 -1
  13. package/dist/browser/tools/tanstack-ai.d.ts +4 -4
  14. package/dist/browser/tools/tanstack-ai.js +3 -3
  15. package/dist/browser/tools/tanstack-ai.js.map +1 -1
  16. package/dist/{browser-D9RNpJuT.d.ts → browser-CI97khiJ.d.ts} +222 -94
  17. package/dist/{browser-tool-BhjCcNVE.d.ts → browser-tool-Cxtiwfua.d.ts} +2 -2
  18. package/dist/browser-tool-DOqT1oSD.js +360 -0
  19. package/dist/browser-tool-DOqT1oSD.js.map +1 -0
  20. package/dist/chat/react.js +1 -0
  21. package/dist/chat/react.js.map +1 -1
  22. package/dist/cli.js +63 -62
  23. package/dist/{connector-CM-uuxKM.js → connector-Dl098To-.js} +402 -3
  24. package/dist/connector-Dl098To-.js.map +1 -0
  25. package/dist/experimental/webmcp.js +1 -1
  26. package/dist/harness/pi/index.d.ts +73 -26
  27. package/dist/harness/pi/index.js +77 -83
  28. package/dist/harness/pi/index.js.map +1 -1
  29. package/dist/{input-schema-BQykTEp_.js → input-schema-0uUu392-.js} +2 -2
  30. package/dist/input-schema-0uUu392-.js.map +1 -0
  31. package/dist/{input-schema-B0Etuo-o.js → input-schema-waggtYrH.js} +2 -2
  32. package/dist/input-schema-waggtYrH.js.map +1 -0
  33. package/dist/mcp/client/x402.d.ts +8 -8
  34. package/dist/mcp/index.d.ts +1 -1
  35. package/dist/mcp/index.js +3 -3
  36. package/dist/mcp/index.js.map +1 -1
  37. package/dist/models/pi-ai/index.js +11 -141
  38. package/dist/models/pi-ai/index.js.map +1 -1
  39. package/dist/{session-7CDgVE0z.js → session-CRY0bGiI.js} +423 -411
  40. package/dist/session-CRY0bGiI.js.map +1 -0
  41. package/dist/{tool-helpers-BI7ifO2S.js → tool-helpers-F3_Wy2YX.js} +2 -2
  42. package/dist/{tool-helpers-BI7ifO2S.js.map → tool-helpers-F3_Wy2YX.js.map} +1 -1
  43. package/dist/web/fetch/tools/ai-sdk.js +1 -1
  44. package/dist/web/fetch/tools/pi.d.ts +4 -7
  45. package/dist/web/fetch/tools/pi.js +7 -6
  46. package/dist/web/fetch/tools/pi.js.map +1 -1
  47. package/dist/web/fetch/tools/tanstack-ai.js +1 -1
  48. package/dist/web/search/tools/ai-sdk.js +1 -1
  49. package/dist/web/search/tools/pi.d.ts +5 -4
  50. package/dist/web/search/tools/pi.js +5 -10
  51. package/dist/web/search/tools/pi.js.map +1 -1
  52. package/dist/web/search/tools/tanstack-ai.js +1 -1
  53. package/docs/browse-the-web.md +36 -3
  54. package/docs/harnesses/pi.md +50 -30
  55. package/docs/models-pi-ai.md +1 -1
  56. package/package.json +14 -8
  57. package/dist/browser-1eUbPvC2.js +0 -931
  58. package/dist/browser-1eUbPvC2.js.map +0 -1
  59. package/dist/browser-tool-DRan7Lk6.js +0 -497
  60. package/dist/browser-tool-DRan7Lk6.js.map +0 -1
  61. package/dist/connector-CM-uuxKM.js.map +0 -1
  62. package/dist/input-schema-B0Etuo-o.js.map +0 -1
  63. package/dist/input-schema-BQykTEp_.js.map +0 -1
  64. package/dist/session-7CDgVE0z.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"tanstack-ai.js","names":[],"sources":["../../../src/browser/tanstack-ai.ts","../../../src/browser/tools/tanstack-ai.ts"],"sourcesContent":["/**\n * The legacy TanStack AI `createBrowserTools`. `agents/browser/tanstack-ai`\n * (`tools/tanstack-ai.ts`) re-exports it until it's retired.\n */\nimport { toolDefinition } from \"@tanstack/ai\";\nimport type { SchemaInput, ServerTool } from \"@tanstack/ai\";\nimport type { ProxyToolOutput } from \"@cloudflare/codemode\";\nimport { z } from \"zod\";\nimport { createBrowserRuntime, type CreateBrowserToolsOptions } from \"./ai\";\n\nexport type { CreateBrowserToolsOptions } from \"./ai\";\n\n/**\n * Create TanStack AI tools for browser automation via CDP code mode.\n *\n * Returns an array with a single durable `browser_execute` `ServerTool`\n * backed by the same codemode runtime as `agents/browser/ai` — the model\n * writes TypeScript against the `cdp` connector and browser sessions\n * survive pauses.\n *\n * The stateless Quick Action tools are not surfaced through this TanStack\n * wrapper (it exposes only `browser_execute`); use `createQuickActionTools`\n * from `agents/browser/ai` if you want them.\n *\n * @example\n * ```ts\n * import { createBrowserTools } from \"agents/browser/tanstack-ai\";\n * import { chat } from \"@tanstack/ai\";\n *\n * // inside a Durable Object / Agent:\n * const browserTools = createBrowserTools({\n * ctx: this.ctx,\n * browser: this.env.BROWSER,\n * loader: this.env.LOADER,\n * });\n *\n * const stream = chat({\n * adapter: openaiText(\"gpt-4o\"),\n * tools: [...browserTools, ...otherTools],\n * messages,\n * });\n * ```\n *\n * @deprecated Use `browserTool` from `agents/browser/ai-sdk`,\n * `agents/browser/tanstack-ai` or `agents/browser/pi`. See\n * https://github.com/cloudflare/agents/blob/main/docs/agents/browse-the-web.md#persistent-browser\n */\nexport function createBrowserTools(\n options: CreateBrowserToolsOptions\n): ServerTool<SchemaInput, SchemaInput>[] {\n // This wrapper only surfaces `browser_execute`, so don't build the default-on\n // Quick Action tools just to discard them.\n const { tools } = createBrowserRuntime({ ...options, quickActions: false });\n const executeTool = tools.browser_execute;\n\n const execute = toolDefinition({\n name: \"browser_execute\" as const,\n description:\n typeof executeTool.description === \"function\"\n ? \"\"\n : (executeTool.description ?? \"\"),\n inputSchema: z.object({\n code: z.string().meta({\n description:\n \"TypeScript async arrow function that uses the cdp connector\"\n })\n })\n }).server(async ({ code }) => {\n if (!executeTool.execute) {\n throw new Error(\"browser_execute tool is not executable\");\n }\n const result = (await executeTool.execute({ code }, {\n toolCallId: crypto.randomUUID(),\n messages: [],\n context: {}\n } as never)) as ProxyToolOutput;\n // TanStack has a single return channel, so what the host sees is what the\n // model sees: apply the AI SDK path's `toModelOutput` projection so a\n // screenshot's base64 cannot reach the model and the durable `calls` log\n // stays out of its context. The execution envelope (status, executionId)\n // is preserved either way.\n const modelOutput = await executeTool.toModelOutput?.({\n toolCallId: crypto.randomUUID(),\n input: { code },\n output: result\n });\n if (modelOutput?.type === \"error-text\") {\n throw new Error(modelOutput.value);\n }\n if (modelOutput?.type === \"text\") {\n return { ...result, result: modelOutput.value };\n }\n if (modelOutput?.type === \"json\") {\n return modelOutput.value;\n }\n return result;\n });\n\n return [execute];\n}\n","/**\n * `agents/browser/tanstack-ai` — the TanStack AI tool for a persistent\n * `Browser`.\n *\n * The older `createBrowserTools` lives in `../tanstack-ai.ts` and is\n * re-exported here until it's retired.\n */\nimport { toolDefinition } from \"@tanstack/ai\";\nimport {\n createBrowserToolCore,\n type BrowserToolOptions,\n type BrowserToolOutput\n} from \"../browser-tool\";\nimport {\n browserExecuteModelOutput,\n browserScreenshotOutput\n} from \"../tool-helpers\";\n\nexport type {\n BrowserToolInput,\n BrowserToolOptions,\n BrowserToolOutput\n} from \"../browser-tool\";\nexport type { BrowserNewTab, BrowserSource } from \"../session\";\n\nexport interface TanStackBrowserToolOptions<\n TName extends string = \"browser\"\n> extends BrowserToolOptions {\n /** The tool's name. TanStack AI tools carry it in the definition. */\n name?: TName;\n}\n\n/**\n * What the model sees from one run. TanStack AI has one return channel, so\n * the host gets this too: no `calls` log, bounded `logs`, and a screenshot\n * replaced by a sentence saying it was left out.\n */\nfunction browserToolModelResult(output: BrowserToolOutput): unknown {\n const screenshot = browserScreenshotOutput(output);\n if (!screenshot) return browserExecuteModelOutput(output).value;\n const bytes = Math.floor((screenshot.data.length * 3) / 4);\n // Keep the rest of the result (status, notice).\n return browserExecuteModelOutput({\n ...output,\n result: `Screenshot captured (${screenshot.mediaType}, approximately ${bytes.toLocaleString()} bytes), but this tool can't return images, so neither you nor the user can see it. Read the page with Runtime.evaluate instead.`\n }).value;\n}\n\n/**\n * Create a TanStack AI tool that lets the model drive a persistent browser\n * with JavaScript and the Chrome DevTools Protocol.\n *\n * Works like `browserTool` in `agents/browser/ai-sdk`: tabs, cookies, and\n * logins carry over between runs, `sessionId: \"active\"` addresses the tab the\n * model last worked in, and a replaced browser is reported in the\n * result's `notice`. The tool is named `browser` unless you pass `name`.\n *\n * Unlike the AI SDK tool, the host gets the same output as the model, and\n * screenshots aren't supported: a returned screenshot is replaced by a\n * sentence saying it was left out.\n *\n * @example\n * ```ts\n * import { Browser, browserRun } from \"agents/browser\";\n * import { browserTool } from \"agents/browser/tanstack-ai\";\n * import { chat } from \"@tanstack/ai\";\n *\n * export class MyAgent extends Agent<Env> {\n * browser = new Browser({ provider: browserRun(this.env.BROWSER) });\n *\n * constructor(ctx: AgentContext, env: Env) {\n * super(ctx, env);\n * this.lifecycle.use(this.browser);\n * }\n *\n * async onChatMessage() {\n * const stream = chat({\n * adapter,\n * tools: [browserTool({ browser: this.browser, loader: this.env.LOADER })],\n * messages\n * });\n * }\n * }\n * ```\n */\nexport function browserTool<TName extends string = \"browser\">(\n options: TanStackBrowserToolOptions<TName>\n) {\n const core = createBrowserToolCore(options, {\n screenshotHint:\n \"This tool can't return images, so don't take screenshots; read the page with Runtime.evaluate (for example document.body.innerText) instead.\"\n });\n return toolDefinition({\n name: options.name ?? (\"browser\" as TName),\n description: core.description,\n inputSchema: core.inputSchema\n }).server(async (input) => browserToolModelResult(await core.execute(input)));\n}\n\nexport {\n createBrowserTools,\n type CreateBrowserToolsOptions\n} from \"../tanstack-ai\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,SAAgB,mBACd,SACwC;CAGxC,MAAM,EAAE,UAAU,qBAAqB;EAAE,GAAG;EAAS,cAAc;CAAM,CAAC;CAC1E,MAAM,cAAc,MAAM;CA6C1B,OAAO,CA3CS,eAAe;EAC7B,MAAM;EACN,aACE,OAAO,YAAY,gBAAgB,aAC/B,KACC,YAAY,eAAe;EAClC,aAAa,EAAE,OAAO,EACpB,MAAM,EAAE,OAAO,CAAC,CAAC,KAAK,EACpB,aACE,8DACJ,CAAC,EACH,CAAC;CACH,CAAC,CAAC,CAAC,OAAO,OAAO,EAAE,WAAW;EAC5B,IAAI,CAAC,YAAY,SACf,MAAM,IAAI,MAAM,wCAAwC;EAE1D,MAAM,SAAU,MAAM,YAAY,QAAQ,EAAE,KAAK,GAAG;GAClD,YAAY,OAAO,WAAW;GAC9B,UAAU,CAAC;GACX,SAAS,CAAC;EACZ,CAAU;EAMV,MAAM,cAAc,MAAM,YAAY,gBAAgB;GACpD,YAAY,OAAO,WAAW;GAC9B,OAAO,EAAE,KAAK;GACd,QAAQ;EACV,CAAC;EACD,IAAI,aAAa,SAAS,cACxB,MAAM,IAAI,MAAM,YAAY,KAAK;EAEnC,IAAI,aAAa,SAAS,QACxB,OAAO;GAAE,GAAG;GAAQ,QAAQ,YAAY;EAAM;EAEhD,IAAI,aAAa,SAAS,QACxB,OAAO,YAAY;EAErB,OAAO;CACT,CAEc,CAAC;AACjB;;;;;;;;;;;;;;;AC9DA,SAAS,uBAAuB,QAAoC;CAClE,MAAM,aAAa,wBAAwB,MAAM;CACjD,IAAI,CAAC,YAAY,OAAO,0BAA0B,MAAM,CAAC,CAAC;CAC1D,MAAM,QAAQ,KAAK,MAAO,WAAW,KAAK,SAAS,IAAK,CAAC;CAEzD,OAAO,0BAA0B;EAC/B,GAAG;EACH,QAAQ,wBAAwB,WAAW,UAAU,kBAAkB,MAAM,eAAe,EAAE;CAChG,CAAC,CAAC,CAAC;AACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,YACd,SACA;CACA,MAAM,OAAO,sBAAsB,SAAS,EAC1C,gBACE,+IACJ,CAAC;CACD,OAAO,eAAe;EACpB,MAAM,QAAQ,QAAS;EACvB,aAAa,KAAK;EAClB,aAAa,KAAK;CACpB,CAAC,CAAC,CAAC,OAAO,OAAO,UAAU,uBAAuB,MAAM,KAAK,QAAQ,KAAK,CAAC,CAAC;AAC9E"}
1
+ {"version":3,"file":"tanstack-ai.js","names":[],"sources":["../../../src/browser/tanstack-ai.ts","../../../src/browser/tools/tanstack-ai.ts"],"sourcesContent":["/**\n * The legacy TanStack AI `createBrowserTools`. `agents/browser/tanstack-ai`\n * (`tools/tanstack-ai.ts`) re-exports it until it's retired.\n */\nimport { toolDefinition } from \"@tanstack/ai\";\nimport type { SchemaInput, ServerTool } from \"@tanstack/ai\";\nimport type { ProxyToolOutput } from \"@cloudflare/codemode\";\nimport { z } from \"zod\";\nimport { createBrowserRuntime, type CreateBrowserToolsOptions } from \"./ai\";\n\nexport type { CreateBrowserToolsOptions } from \"./ai\";\n\n/**\n * Create TanStack AI tools for browser automation via CDP code mode.\n *\n * Returns an array with a single durable `browser_execute` `ServerTool`\n * backed by the same codemode runtime as `agents/browser/ai` — the model\n * writes TypeScript against the `cdp` connector and browser sessions\n * survive pauses.\n *\n * The stateless Quick Action tools are not surfaced through this TanStack\n * wrapper (it exposes only `browser_execute`); use `createQuickActionTools`\n * from `agents/browser/ai` if you want them.\n *\n * @example\n * ```ts\n * import { createBrowserTools } from \"agents/browser/tanstack-ai\";\n * import { chat } from \"@tanstack/ai\";\n *\n * // inside a Durable Object / Agent:\n * const browserTools = createBrowserTools({\n * ctx: this.ctx,\n * browser: this.env.BROWSER,\n * loader: this.env.LOADER,\n * });\n *\n * const stream = chat({\n * adapter: openaiText(\"gpt-4o\"),\n * tools: [...browserTools, ...otherTools],\n * messages,\n * });\n * ```\n *\n * @deprecated Use `browserTool` from `agents/browser/ai-sdk`,\n * `agents/browser/tanstack-ai` or `agents/browser/pi`. See\n * https://github.com/cloudflare/agents/blob/main/docs/agents/browse-the-web.md#persistent-browser\n */\nexport function createBrowserTools(\n options: CreateBrowserToolsOptions\n): ServerTool<SchemaInput, SchemaInput>[] {\n // This wrapper only surfaces `browser_execute`, so don't build the default-on\n // Quick Action tools just to discard them.\n const { tools } = createBrowserRuntime({ ...options, quickActions: false });\n const executeTool = tools.browser_execute;\n\n const execute = toolDefinition({\n name: \"browser_execute\" as const,\n description:\n typeof executeTool.description === \"function\"\n ? \"\"\n : (executeTool.description ?? \"\"),\n inputSchema: z.object({\n code: z.string().meta({\n description:\n \"TypeScript async arrow function that uses the cdp connector\"\n })\n })\n }).server(async ({ code }) => {\n if (!executeTool.execute) {\n throw new Error(\"browser_execute tool is not executable\");\n }\n const result = (await executeTool.execute({ code }, {\n toolCallId: crypto.randomUUID(),\n messages: [],\n context: {}\n } as never)) as ProxyToolOutput;\n // TanStack has a single return channel, so what the host sees is what the\n // model sees: apply the AI SDK path's `toModelOutput` projection so a\n // screenshot's base64 cannot reach the model and the durable `calls` log\n // stays out of its context. The execution envelope (status, executionId)\n // is preserved either way.\n const modelOutput = await executeTool.toModelOutput?.({\n toolCallId: crypto.randomUUID(),\n input: { code },\n output: result\n });\n if (modelOutput?.type === \"error-text\") {\n throw new Error(modelOutput.value);\n }\n if (modelOutput?.type === \"text\") {\n return { ...result, result: modelOutput.value };\n }\n if (modelOutput?.type === \"json\") {\n return modelOutput.value;\n }\n return result;\n });\n\n return [execute];\n}\n","/**\n * `agents/browser/tanstack-ai` — the TanStack AI tool for a persistent\n * `Browser`.\n *\n * The older `createBrowserTools` lives in `../tanstack-ai.ts` and is\n * re-exported here until it's retired.\n */\nimport { toolDefinition } from \"@tanstack/ai\";\nimport {\n createBrowserToolCore,\n type BrowserToolOptions,\n type BrowserToolOutput\n} from \"../browser-tool\";\nimport {\n browserExecuteModelOutput,\n browserScreenshotOutput\n} from \"../tool-helpers\";\n\nexport type {\n BrowserToolInput,\n BrowserToolOptions,\n BrowserToolOutput\n} from \"../browser-tool\";\nexport type { BrowserNewTab, BrowserSource } from \"../session\";\n\nexport interface TanStackBrowserToolOptions<\n TName extends string = \"browser\"\n> extends BrowserToolOptions {\n /** The tool's name. TanStack AI tools carry it in the definition. */\n name?: TName;\n}\n\n/**\n * What the model sees from one run. TanStack AI has one return channel, so\n * the host gets this too: no `calls` log, bounded `logs`, and a screenshot\n * replaced by a sentence saying it was left out.\n */\nfunction browserToolModelResult(output: BrowserToolOutput): unknown {\n const screenshot = browserScreenshotOutput(output);\n if (!screenshot) return browserExecuteModelOutput(output).value;\n const bytes = Math.floor((screenshot.data.length * 3) / 4);\n // Keep the rest of the result (status, notice).\n return browserExecuteModelOutput({\n ...output,\n result: `Screenshot captured (${screenshot.mediaType}, approximately ${bytes.toLocaleString()} bytes), but this tool can't return images, so neither you nor the user can see it. Read the page with Runtime.evaluate instead.`\n }).value;\n}\n\n/**\n * Create a TanStack AI tool that lets the model drive a persistent browser\n * with JavaScript and the Chrome DevTools Protocol.\n *\n * Works like `browserTool` in `agents/browser/ai-sdk`: tabs, cookies, and\n * logins carry over between runs, `sessionId: \"active\"` addresses the tab the\n * model last worked in, and a replaced browser is reported in the\n * result's `notice`. The tool is named `browser` unless you pass `name`.\n *\n * Unlike the AI SDK tool, the host gets the same output as the model, and\n * screenshots aren't supported: a returned screenshot is replaced by a\n * sentence saying it was left out.\n *\n * @example\n * ```ts\n * import { Browser, browserRun } from \"agents/browser\";\n * import { browserTool } from \"agents/browser/tanstack-ai\";\n * import { chat } from \"@tanstack/ai\";\n *\n * export class MyAgent extends Agent<Env> {\n * browser = new Browser({ provider: browserRun(this.env.BROWSER) });\n *\n * constructor(ctx: AgentContext, env: Env) {\n * super(ctx, env);\n * this.lifecycle.use(this.browser);\n * }\n *\n * async onChatMessage() {\n * const stream = chat({\n * adapter,\n * tools: [browserTool({ browser: this.browser, loader: this.env.LOADER })],\n * messages\n * });\n * }\n * }\n * ```\n */\nexport function browserTool<TName extends string = \"browser\">(\n options: TanStackBrowserToolOptions<TName>\n) {\n const core = createBrowserToolCore(options, {\n screenshotHint:\n \"This tool can't return images, so don't take screenshots; read the page with Runtime.evaluate (for example document.body.innerText) instead.\"\n });\n return toolDefinition({\n name: options.name ?? (\"browser\" as TName),\n description: core.description,\n inputSchema: core.inputSchema\n }).server(async (input, context) =>\n browserToolModelResult(\n await core.execute(input, { signal: context?.abortSignal })\n )\n );\n}\n\nexport {\n createBrowserTools,\n type CreateBrowserToolsOptions\n} from \"../tanstack-ai\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,SAAgB,mBACd,SACwC;CAGxC,MAAM,EAAE,UAAU,qBAAqB;EAAE,GAAG;EAAS,cAAc;CAAM,CAAC;CAC1E,MAAM,cAAc,MAAM;CA6C1B,OAAO,CA3CS,eAAe;EAC7B,MAAM;EACN,aACE,OAAO,YAAY,gBAAgB,aAC/B,KACC,YAAY,eAAe;EAClC,aAAa,EAAE,OAAO,EACpB,MAAM,EAAE,OAAO,CAAC,CAAC,KAAK,EACpB,aACE,8DACJ,CAAC,EACH,CAAC;CACH,CAAC,CAAC,CAAC,OAAO,OAAO,EAAE,WAAW;EAC5B,IAAI,CAAC,YAAY,SACf,MAAM,IAAI,MAAM,wCAAwC;EAE1D,MAAM,SAAU,MAAM,YAAY,QAAQ,EAAE,KAAK,GAAG;GAClD,YAAY,OAAO,WAAW;GAC9B,UAAU,CAAC;GACX,SAAS,CAAC;EACZ,CAAU;EAMV,MAAM,cAAc,MAAM,YAAY,gBAAgB;GACpD,YAAY,OAAO,WAAW;GAC9B,OAAO,EAAE,KAAK;GACd,QAAQ;EACV,CAAC;EACD,IAAI,aAAa,SAAS,cACxB,MAAM,IAAI,MAAM,YAAY,KAAK;EAEnC,IAAI,aAAa,SAAS,QACxB,OAAO;GAAE,GAAG;GAAQ,QAAQ,YAAY;EAAM;EAEhD,IAAI,aAAa,SAAS,QACxB,OAAO,YAAY;EAErB,OAAO;CACT,CAEc,CAAC;AACjB;;;;;;;;;;;;;;;AC9DA,SAAS,uBAAuB,QAAoC;CAClE,MAAM,aAAa,wBAAwB,MAAM;CACjD,IAAI,CAAC,YAAY,OAAO,0BAA0B,MAAM,CAAC,CAAC;CAC1D,MAAM,QAAQ,KAAK,MAAO,WAAW,KAAK,SAAS,IAAK,CAAC;CAEzD,OAAO,0BAA0B;EAC/B,GAAG;EACH,QAAQ,wBAAwB,WAAW,UAAU,kBAAkB,MAAM,eAAe,EAAE;CAChG,CAAC,CAAC,CAAC;AACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,YACd,SACA;CACA,MAAM,OAAO,sBAAsB,SAAS,EAC1C,gBACE,+IACJ,CAAC;CACD,OAAO,eAAe;EACpB,MAAM,QAAQ,QAAS;EACvB,aAAa,KAAK;EAClB,aAAa,KAAK;CACpB,CAAC,CAAC,CAAC,OAAO,OAAO,OAAO,YACtB,uBACE,MAAM,KAAK,QAAQ,OAAO,EAAE,QAAQ,SAAS,YAAY,CAAC,CAC5D,CACF;AACF"}
@@ -94,74 +94,6 @@ interface CdpSpecSource {
94
94
  /** Load the (cached) searchable CDP spec for a browser source. */
95
95
  declare function loadCdpSpec(source: CdpSpecSource): Promise<SearchableCdpSpec>;
96
96
  //#endregion
97
- //#region src/browser/providers/browser-run.d.ts
98
- /**
99
- * Browser Run settings applied every time a browser is created — including
100
- * when a lost browser is replaced — so options like guardrails survive a
101
- * restart.
102
- */
103
- interface BrowserRunOptions<S = Record<string, unknown>> {
104
- /**
105
- * Platform `keep_alive` in milliseconds: how long an idle browser lives.
106
- * Defaults to {@link BROWSER_SESSION_KEEP_ALIVE_DEFAULT_MS} (10 minutes).
107
- * Browser Run accepts up to {@link BROWSER_SESSION_KEEP_ALIVE_MAX_MS}
108
- * (20 minutes).
109
- */
110
- keepAliveMs?: number;
111
- /** Opt into Browser Run session recording (rrweb capture). */
112
- recording?: boolean;
113
- /**
114
- * Hostname guardrails, fixed at launch for every connection. They don't
115
- * apply to `internalHosts`: `allowedDomains: []` leaves the browser able
116
- * to open internal hostnames only.
117
- */
118
- guardrails?: BrowserSessionGuardrails;
119
- /**
120
- * Hostnames only this browser can open, served by your agent or a Worker
121
- * instead of the internet. Plain http on port 80; no HTTPS or WebSockets.
122
- * Deployed Workers only: in local dev the browser starts without them.
123
- *
124
- * Any http page open in the browser can send requests to these hosts, so
125
- * a host whose requests have side effects should check `Origin` (see
126
- * `InternalHost.fetch`).
127
- *
128
- * @example
129
- * ```ts
130
- * browserRun(this.env.BROWSER, {
131
- * internalHosts: {
132
- * router: this.ctx.exports.InternalHostRouter,
133
- * hosts: {
134
- * "preview.internal": {
135
- * description: "A dev server in your sandbox",
136
- * target: z.object({ port: z.number().int() }),
137
- * fetch: (request, { port }) => this.sandboxPort(port, request)
138
- * }
139
- * }
140
- * }
141
- * });
142
- * ```
143
- */
144
- internalHosts?: InternalHostsOptions<S>;
145
- }
146
- /** A {@link Browser} provider backed by Cloudflare Browser Run. */
147
- interface BrowserRunProvider {
148
- readonly kind: "browser-run";
149
- readonly binding: BrowserBinding;
150
- readonly options: BrowserRunOptions;
151
- }
152
- /**
153
- * Run the browser on Cloudflare Browser Run.
154
- *
155
- * @example
156
- * ```ts
157
- * new Browser({ provider: browserRun(env.BROWSER, { recording: true }) });
158
- * ```
159
- */
160
- declare function browserRun<const S extends Record<string, unknown> = {}>(
161
- binding: BrowserBinding,
162
- options?: BrowserRunOptions<S>
163
- ): BrowserRunProvider;
164
- //#endregion
165
97
  //#region src/browser/session.d.ts
166
98
  /**
167
99
  * What a {@link BrowserSession} connects to. Usually a `Browser` installed on
@@ -177,8 +109,8 @@ interface BrowserSource {
177
109
  */
178
110
  connect(options?: BrowserConnectOptions): Promise<BrowserConnection>;
179
111
  /**
180
- * The browser's internal hostnames, when it has any. `browserTool` lists
181
- * them and adds the hosts functions to `browser`.
112
+ * The browser's internal hostnames, when it has any. The docs list them,
113
+ * and {@link BrowserSession.functions} adds the hosts functions.
182
114
  */
183
115
  readonly internalHosts?: BrowserInternalHosts;
184
116
  }
@@ -194,6 +126,35 @@ interface BrowserSessionOptions {
194
126
  * JSON. Defaults to 1,000,000 bytes.
195
127
  */
196
128
  maxResultBytes?: number;
129
+ /**
130
+ * Lock the scope on this browser: the session takes the scope's lock at
131
+ * its first call (or at {@link BrowserSession.lock}) and holds it until it
132
+ * closes. Other locking sessions in the scope wait for the lock, in order,
133
+ * rather than fail, so their calls never interleave. Sessions without it
134
+ * don't wait and aren't waited for. Locks are per isolate, which is per
135
+ * Durable Object.
136
+ *
137
+ * Use it when several runs in one scope can start together (parallel
138
+ * tool calls, say) and must not see each other's navigation.
139
+ *
140
+ * Only `close()` releases the lock: not aborting a signal, losing the
141
+ * browser, or dropping the session. Close a locking session in `finally`,
142
+ * even when connecting failed, or its scope stays locked until the
143
+ * isolate restarts.
144
+ */
145
+ lock?: boolean;
146
+ }
147
+ /** {@link BrowserSession.lock}'s options. */
148
+ interface BrowserLockOptions {
149
+ /**
150
+ * Bounds this call's wait: when it aborts, this call rejects with its
151
+ * reason. The session keeps waiting while other calls still are; once
152
+ * none is, it leaves the queue at once, so it doesn't hold up the
153
+ * sessions behind it. A call without a signal, including the wait a
154
+ * session's first function call makes, never gives up. The signal does
155
+ * nothing once the lock is held: only `close()` releases it.
156
+ */
157
+ signal?: AbortSignal;
197
158
  }
198
159
  /** `send`'s input. */
199
160
  interface BrowserSendInput {
@@ -242,6 +203,11 @@ interface BrowserSessionReport {
242
203
  tabClosed: boolean;
243
204
  /** Another scope is working in this scope's active tab too. */
244
205
  tabShared: boolean;
206
+ /**
207
+ * The report as sentences for the model, one per thing that happened,
208
+ * empty when nothing did. Show them after the run's result.
209
+ */
210
+ notices: string[];
245
211
  }
246
212
  /** `sessionId` value that addresses the tab the agent is working in. */
247
213
  declare const ACTIVE_PAGE_SESSION = "active";
@@ -254,13 +220,42 @@ declare const ACTIVE_PAGE_SESSION = "active";
254
220
  * usually comes from model-written code.
255
221
  *
256
222
  * Create one per run with `browser.session({ scope })`, and close it when
257
- * the run ends. The browser itself stays open.
223
+ * the run ends. The browser itself stays open. Pass `lock: true` when
224
+ * runs in one scope may overlap; see {@link BrowserSessionOptions.lock}.
258
225
  *
259
226
  * @experimental The API surface may change before stabilizing.
260
227
  */
261
228
  declare class BrowserSession {
262
229
  #private;
263
230
  constructor(browser: BrowserSource, options?: BrowserSessionOptions);
231
+ /**
232
+ * The `browser.*` functions bound to this session, by name: the ones
233
+ * `Browser.functionDocs()` describes. Each takes one input object and
234
+ * validates it, so model-written code can call them directly. Like the
235
+ * session's methods, every one rejects once the session is closed, and
236
+ * waits for the scope's lock when the session locks.
237
+ */
238
+ get functions(): Readonly<Record<string, BrowserFunction>>;
239
+ /**
240
+ * Take this scope's lock now rather than at the first call, and hold it
241
+ * until {@link close}. For sessions opened with `lock: true`; a
242
+ * caller with its own time limit calls it first, so the wait doesn't count
243
+ * against the limit, or passes `signal` to bound the wait.
244
+ *
245
+ * Resolves once the session holds the lock, after the locking sessions
246
+ * ahead of it close; later and concurrent calls resolve with the same
247
+ * lock. Rejects when the session closes while waiting. Each call's
248
+ * `signal` bounds only that call's wait: it rejects with the signal's
249
+ * reason, and the session leaves the queue once no call is still
250
+ * waiting (see {@link BrowserLockOptions.signal}); a later call or first
251
+ * call waits again.
252
+ */
253
+ lock(options?: BrowserLockOptions): Promise<void>;
254
+ /**
255
+ * How long this session waited for its lock, in milliseconds: `0` until
256
+ * it has waited, and for sessions that don't lock.
257
+ */
258
+ get waitedForLockMs(): number;
264
259
  /**
265
260
  * Send a CDP command and resolve with its result, without the JSON-RPC
266
261
  * envelope. `sessionId: "active"` runs it in the scope's tab.
@@ -287,16 +282,137 @@ declare class BrowserSession {
287
282
  * connected. Never rejects: failures to read the browser's state are
288
283
  * logged and leave the report incomplete. Later calls resolve with
289
284
  * `undefined`, and other methods reject.
285
+ *
286
+ * A locking session releases the lock once the active tab is saved, or
287
+ * stops waiting for it if it was still waiting.
290
288
  */
291
289
  close(): Promise<BrowserSessionReport | undefined>;
292
290
  }
293
291
  //#endregion
294
- //#region src/browser/browser.d.ts
292
+ //#region src/browser/browser-functions.d.ts
293
+ /**
294
+ * One function on the `browser` object, as the host runs it: it takes one
295
+ * input object (usually from model-written code, so it's validated) and
296
+ * resolves with a JSON-safe result.
297
+ *
298
+ * @experimental The API surface may change before stabilizing.
299
+ */
300
+ type BrowserFunction = (input: unknown) => Promise<unknown>;
301
+ /**
302
+ * What the model needs to know to use the `browser` object, for a tool or
303
+ * module description. `Browser.functionDocs()` returns it.
304
+ *
305
+ * @experimental The API surface may change before stabilizing.
306
+ */
307
+ interface BrowserFunctionDocs {
308
+ /**
309
+ * The `browser.*` functions in Markdown, one bullet per function, then the
310
+ * browser's internal sites when it has any.
311
+ */
312
+ functions: string;
313
+ /**
314
+ * How to use the browser, one rule per entry, without bullets. Rules about
315
+ * how the code runs (timeouts, how screenshots reach the model) belong to
316
+ * whatever runs it, so add those yourself.
317
+ */
318
+ rules: string[];
319
+ }
320
+ //#endregion
321
+ //#region src/browser/providers/browser-run.d.ts
322
+ /**
323
+ * Browser Run settings applied every time a browser is created — including
324
+ * when a lost browser is replaced — so options like guardrails survive a
325
+ * restart.
326
+ */
327
+ interface BrowserRunOptions<S = Record<string, unknown>> {
328
+ /**
329
+ * Platform `keep_alive` in milliseconds: how long an idle browser lives.
330
+ * Defaults to {@link BROWSER_SESSION_KEEP_ALIVE_DEFAULT_MS} (10 minutes).
331
+ * Browser Run accepts up to {@link BROWSER_SESSION_KEEP_ALIVE_MAX_MS}
332
+ * (20 minutes).
333
+ */
334
+ keepAliveMs?: number;
335
+ /** Opt into Browser Run session recording (rrweb capture). */
336
+ recording?: boolean;
337
+ /**
338
+ * Hostname guardrails, fixed at launch for every connection. They don't
339
+ * apply to `internalHosts`: `allowedDomains: []` leaves the browser able
340
+ * to open internal hostnames only.
341
+ */
342
+ guardrails?: BrowserSessionGuardrails;
343
+ /**
344
+ * Hostnames only this browser can open, served by your agent or a Worker
345
+ * instead of the internet. Plain http on port 80; no HTTPS or WebSockets.
346
+ * Deployed Workers only: in local dev the browser starts without them.
347
+ *
348
+ * Any http page open in the browser can send requests to these hosts, so
349
+ * a host whose requests have side effects should check `Origin` (see
350
+ * `InternalHost.fetch`).
351
+ *
352
+ * @example
353
+ * ```ts
354
+ * browserRun(this.env.BROWSER, {
355
+ * internalHosts: {
356
+ * router: this.ctx.exports.InternalHostRouter,
357
+ * hosts: {
358
+ * "preview.internal": {
359
+ * description: "A dev server in your sandbox",
360
+ * target: z.object({ port: z.number().int() }),
361
+ * fetch: (request, { port }) => this.sandboxPort(port, request)
362
+ * }
363
+ * }
364
+ * }
365
+ * });
366
+ * ```
367
+ */
368
+ internalHosts?: InternalHostsOptions<S>;
369
+ }
370
+ /** A {@link Browser} provider backed by Cloudflare Browser Run. */
371
+ interface BrowserRunProvider {
372
+ readonly kind: "browser-run";
373
+ readonly binding: BrowserBinding;
374
+ readonly options: BrowserRunOptions;
375
+ }
376
+ /**
377
+ * Run the browser on Cloudflare Browser Run.
378
+ *
379
+ * @example
380
+ * ```ts
381
+ * new Browser({ provider: browserRun(env.BROWSER, { recording: true }) });
382
+ * ```
383
+ */
384
+ declare function browserRun<const S extends Record<string, unknown> = {}>(
385
+ binding: BrowserBinding,
386
+ options?: BrowserRunOptions<S>
387
+ ): BrowserRunProvider;
388
+ //#endregion
389
+ //#region src/browser/scope.d.ts
390
+ /**
391
+ * Browser scopes: who is driving a shared `Browser`. Sessions with the same
392
+ * scope share an active tab (and, when they lock, a lock); each scope
393
+ * keeps its own. Cookies and logins are shared by every scope.
394
+ */
295
395
  /**
296
396
  * The scope used when a caller doesn't pick one: every caller that leaves
297
- * `scope` out shares this one active tab. See {@link BrowserConnectOptions}.
397
+ * `scope` out shares this one active tab. See `BrowserConnectOptions`.
298
398
  */
299
399
  declare const DEFAULT_BROWSER_SCOPE = "shared";
400
+ /**
401
+ * The scope for one conversation: `conversation:<id>`. pi's `browserTool`
402
+ * gives each conversation this scope by default, so app code that opens
403
+ * sessions with the same scope (a Workspace's `codemode:browser`, say) lands
404
+ * in the same tab as the tool. pi's conversation ids are numbers: pass
405
+ * `String(conversationId)`.
406
+ *
407
+ * Throws on a missing or empty id rather than returning
408
+ * `"conversation:undefined"`, which would quietly put every conversation
409
+ * without an id in one tab.
410
+ *
411
+ * @experimental The API surface may change before stabilizing.
412
+ */
413
+ declare function conversationScope(id: string): string;
414
+ //#endregion
415
+ //#region src/browser/browser.d.ts
300
416
  /**
301
417
  * Scope records kept per browser. Writing a new one past the cap deletes the
302
418
  * least recently used; a scope that comes back afterwards starts fresh.
@@ -459,6 +575,14 @@ declare class Browser extends LifecycleCapability {
459
575
  * one per run.
460
576
  */
461
577
  session(options?: BrowserSessionOptions): BrowserSession;
578
+ /**
579
+ * What the model needs to know to use this browser's `browser.*`
580
+ * functions ({@link BrowserSession.functions}): the functions in Markdown,
581
+ * including the internal sites and hosts functions this browser has, and
582
+ * the rules for using them. For a tool or module description; add rules
583
+ * about how your code runs (timeouts, screenshots) yourself.
584
+ */
585
+ functionDocs(): BrowserFunctionDocs;
462
586
  /**
463
587
  * Close the browser: retire the record (so the next resolve reports
464
588
  * `restarted: true`) and close its provider session. Returns `false` when
@@ -509,31 +633,35 @@ declare class Browser extends LifecycleCapability {
509
633
  }
510
634
  //#endregion
511
635
  export {
512
- CdpItems as C,
513
- loadCdpSpec as E,
514
- CdpField as S,
515
- SearchableCdpSpec as T,
516
- BrowserSessionReport as _,
636
+ loadCdpSpec as A,
637
+ BrowserSessionOptions as C,
638
+ CdpItems as D,
639
+ CdpField as E,
640
+ CdpSpecSource as O,
641
+ BrowserSession as S,
642
+ BrowserSource as T,
643
+ BrowserAttachInput as _,
517
644
  BrowserOptions as a,
518
- BrowserRunProvider as b,
519
- MAX_BROWSER_SCOPES as c,
520
- BrowserAttachInput as d,
521
- BrowserDebugLogInput as f,
522
- BrowserSessionOptions as g,
523
- BrowserSession as h,
645
+ BrowserNewTab as b,
646
+ ResolvedBrowser as c,
647
+ BrowserRunOptions as d,
648
+ BrowserRunProvider as f,
649
+ ACTIVE_PAGE_SESSION as g,
650
+ BrowserFunctionDocs as h,
524
651
  BrowserInternalHosts as i,
525
- ResolvedBrowser as l,
526
- BrowserSendInput as m,
652
+ SearchableCdpSpec as k,
653
+ DEFAULT_BROWSER_SCOPE as l,
654
+ BrowserFunction as m,
527
655
  BrowserConnectOptions as n,
528
656
  BrowserProvider as o,
529
- BrowserNewTab as p,
657
+ browserRun as p,
530
658
  BrowserConnection as r,
531
- DEFAULT_BROWSER_SCOPE as s,
659
+ MAX_BROWSER_SCOPES as s,
532
660
  Browser as t,
533
- ACTIVE_PAGE_SESSION as u,
534
- BrowserSource as v,
535
- CdpSpecSource as w,
536
- browserRun as x,
537
- BrowserRunOptions as y
661
+ conversationScope as u,
662
+ BrowserDebugLogInput as v,
663
+ BrowserSessionReport as w,
664
+ BrowserSendInput as x,
665
+ BrowserLockOptions as y
538
666
  };
539
- //# sourceMappingURL=browser-D9RNpJuT.d.ts.map
667
+ //# sourceMappingURL=browser-CI97khiJ.d.ts.map
@@ -1,4 +1,4 @@
1
- import { v as BrowserSource } from "./browser-D9RNpJuT.js";
1
+ import { T as BrowserSource } from "./browser-CI97khiJ.js";
2
2
 
3
3
  //#region src/browser/browser-tool.d.ts
4
4
  interface BrowserToolOptions {
@@ -68,4 +68,4 @@ export {
68
68
  BrowserToolOutput as r,
69
69
  BrowserToolInput as t
70
70
  };
71
- //# sourceMappingURL=browser-tool-BhjCcNVE.d.ts.map
71
+ //# sourceMappingURL=browser-tool-Cxtiwfua.d.ts.map