agents 0.20.1 → 0.22.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.
- package/README.md +51 -12
- package/dist/{agent-tool-types-BC-WFlsz.d.ts → agent-routing-CnkaHb-v.d.ts} +3305 -3138
- package/dist/agent-routing.d.ts +14 -0
- package/dist/agent-routing.js +187 -0
- package/dist/agent-routing.js.map +1 -0
- package/dist/agent-tool-types.d.ts +26 -26
- package/dist/{agent-tools-DeHe9Xov.d.ts → agent-tools-C0XJqWzB.d.ts} +7 -7
- package/dist/agent-tools.d.ts +44 -28
- package/dist/agent-tools.js +16 -7
- package/dist/agent-tools.js.map +1 -1
- package/dist/browser/ai.d.ts +5 -3
- package/dist/browser/ai.js +88 -8
- package/dist/browser/ai.js.map +1 -1
- package/dist/browser/index.d.ts +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/browser/tanstack-ai.js +13 -1
- package/dist/browser/tanstack-ai.js.map +1 -1
- package/dist/capability-BjSKYpzg.js +42 -0
- package/dist/capability-BjSKYpzg.js.map +1 -0
- package/dist/capability-runner-CvHGZqUu.d.ts +150 -0
- package/dist/chat/index.d.ts +51 -15
- package/dist/chat/index.js +59 -4
- package/dist/chat/index.js.map +1 -1
- package/dist/chat/react.d.ts +19 -180
- package/dist/chat/react.js +93 -600
- package/dist/chat/react.js.map +1 -1
- package/dist/chat/transport.d.ts +10 -0
- package/dist/chat/transport.js +2 -0
- package/dist/chat-sdk/index.d.ts +4 -4
- package/dist/chat-sdk/index.js +1 -1
- package/dist/{client-zqKcsyFa.js → client-jagG8a9_.js} +129 -37
- package/dist/client-jagG8a9_.js.map +1 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.js +1 -1
- package/dist/{cloudflare-BduZwmYK.js → cloudflare-Dzvc7V2N.js} +10 -3
- package/dist/{cloudflare-BduZwmYK.js.map → cloudflare-Dzvc7V2N.js.map} +1 -1
- package/dist/{connector-v2M1zlZp.d.ts → connector-CkQD4MK3.d.ts} +20 -3
- package/dist/{connector-KEJnl6e5.js → connector-CptFKzRh.js} +158 -40
- package/dist/connector-CptFKzRh.js.map +1 -0
- package/dist/current-agent-CuMErtly.d.ts +283 -0
- package/dist/current-agent-DhoDkSnH.js +51 -0
- package/dist/current-agent-DhoDkSnH.js.map +1 -0
- package/dist/diagnostics-CaBjfz4J.js +41 -0
- package/dist/diagnostics-CaBjfz4J.js.map +1 -0
- package/dist/{do-oauth-client-provider-VTZj2VtM.d.ts → do-oauth-client-provider-Tmf1vgKz.d.ts} +2 -2
- package/dist/durable-object-lifecycle-D6nNQJJd.js +862 -0
- package/dist/durable-object-lifecycle-D6nNQJJd.js.map +1 -0
- package/dist/{email-CL27preh.d.ts → email-7TatiTnl.d.ts} +38 -9
- package/dist/email-send.d.ts +15 -0
- package/dist/email-send.js +32 -0
- package/dist/email-send.js.map +1 -0
- package/dist/email.d.ts +14 -10
- package/dist/email.js.map +1 -1
- package/dist/experimental/memory/session/index.d.ts +3 -2
- package/dist/experimental/memory/session/index.js +15 -10
- package/dist/experimental/memory/session/index.js.map +1 -1
- package/dist/{handler-stateless-C_bo-Ytq.d.ts → handler-stateless-DxYpJ_XF.d.ts} +3 -3
- package/dist/{handler-stateless-CIkKPETH.js → handler-stateless-VvrWSAVA.js} +5 -5
- package/dist/handler-stateless-VvrWSAVA.js.map +1 -0
- package/dist/{index-BRnybD6X.d.ts → index-DcSAZKsB.d.ts} +19 -31
- package/dist/index.d.ts +102 -91
- package/dist/index.js +12 -7235
- package/dist/internal_context-BlxFEWfn.d.ts +19 -0
- package/dist/internal_context.d.ts +10 -4
- package/dist/internal_context.js +1 -10
- package/dist/{client-invoker-BNSZxAkv.d.ts → invoker-CG0_p_Wq.d.ts} +2 -2
- package/dist/{client-invoker-VNZ7X0nn.js → invoker-CHMnoxIA.js} +2 -2
- package/dist/invoker-CHMnoxIA.js.map +1 -0
- package/dist/lifecycle/index.d.ts +48 -0
- package/dist/lifecycle/index.js +4 -0
- package/dist/mcp/{do-oauth-client-provider.d.ts → client/do-oauth-client-provider.d.ts} +1 -1
- package/dist/mcp/{do-oauth-client-provider.js → client/do-oauth-client-provider.js} +1 -1
- package/dist/mcp/client/do-oauth-client-provider.js.map +1 -0
- package/dist/mcp/client/index.d.ts +42 -0
- package/dist/mcp/{client.js → client/index.js} +1 -1
- package/dist/mcp/{x402.d.ts → client/x402.d.ts} +2 -2
- package/dist/mcp/{x402.js → client/x402.js} +2 -2
- package/dist/mcp/client/x402.js.map +1 -0
- package/dist/mcp/index.d.ts +36 -36
- package/dist/mcp/index.js +14 -16
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/{server.d.ts → server/index.d.ts} +1 -1
- package/dist/mcp/{server.js → server/index.js} +1 -1
- package/dist/observability/ai/index.d.ts +1 -130
- package/dist/observability/ai/index.js +88 -433
- package/dist/observability/ai/index.js.map +1 -1
- package/dist/observability/index.d.ts +4 -4
- package/dist/observability/index.js +3 -50
- package/dist/observability/index.js.map +1 -1
- package/dist/{wire-types-CU9rLoeS.js → protocol-B0nh6KNf.js} +20 -66
- package/dist/protocol-B0nh6KNf.js.map +1 -0
- package/dist/react.d.ts +4 -4
- package/dist/react.js +6 -9
- package/dist/react.js.map +1 -1
- package/dist/schedule.d.ts +25 -94
- package/dist/schedule.js +1 -98
- package/dist/schedule.js.map +1 -1
- package/dist/scheduler-CR9RHGos.js +857 -0
- package/dist/scheduler-CR9RHGos.js.map +1 -0
- package/dist/scheduler-DQoTGoAW.d.ts +224 -0
- package/dist/schedules/index.d.ts +22 -0
- package/dist/schedules/index.js +2 -0
- package/dist/schedules/parser.d.ts +79 -0
- package/dist/schedules/parser.js +103 -0
- package/dist/schedules/parser.js.map +1 -0
- package/dist/serializable.d.ts +1 -1
- package/dist/sql-error-CPY-GXyI.d.ts +12 -0
- package/dist/sql-error.d.ts +2 -0
- package/dist/sql-error.js +16 -0
- package/dist/sql-error.js.map +1 -0
- package/dist/src-5W6JNKVb.js +6613 -0
- package/dist/src-5W6JNKVb.js.map +1 -0
- package/dist/sub-routing.d.ts +18 -6
- package/dist/sub-routing.js +92 -2
- package/dist/sub-routing.js.map +1 -1
- package/dist/wire-types-CnMt6_HR.js +47 -0
- package/dist/wire-types-CnMt6_HR.js.map +1 -0
- package/dist/workflow-types.d.ts +25 -25
- package/dist/workflow-types.js.map +1 -1
- package/dist/workflows.d.ts +22 -22
- package/dist/workflows.js +2 -1
- package/dist/workflows.js.map +1 -1
- package/dist/ws-chat-transport-UNRIS2xl.d.ts +184 -0
- package/dist/ws-chat-transport-rWwta645.js +698 -0
- package/dist/ws-chat-transport-rWwta645.js.map +1 -0
- package/docs/adding-to-existing-project.md +4 -2
- package/docs/agent-class.md +29 -87
- package/docs/agent-tools.md +29 -0
- package/docs/browse-the-web.md +16 -1
- package/docs/chat-agents.md +16 -13
- package/docs/client-sdk.md +12 -8
- package/docs/configuration.md +7 -1
- package/docs/cross-domain-authentication.md +7 -35
- package/docs/durable-execution.md +1 -1
- package/docs/email.md +2 -13
- package/docs/http-websockets.md +1 -11
- package/docs/human-in-the-loop.md +16 -13
- package/docs/index.md +1 -0
- package/docs/lifecycle.md +323 -0
- package/docs/long-running-agents.md +13 -15
- package/docs/mcp-client.md +55 -0
- package/docs/mcp-servers.md +6 -0
- package/docs/mcp-transports.md +18 -12
- package/docs/migration-to-ai-sdk-v5.md +2 -2
- package/docs/migration-to-ai-sdk-v6.md +5 -1
- package/docs/observability.md +33 -77
- package/docs/resumable-streaming.md +1 -1
- package/docs/routing.md +27 -0
- package/docs/scheduling.md +175 -15
- package/docs/server-driven-messages.md +1 -1
- package/docs/sub-agents.md +47 -2
- package/docs/webhooks.md +109 -136
- package/docs/workflows.md +9 -1
- package/package.json +41 -23
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +0 -26
- package/dist/cli/index.js.map +0 -1
- package/dist/client-invoker-VNZ7X0nn.js.map +0 -1
- package/dist/client-zqKcsyFa.js.map +0 -1
- package/dist/connector-KEJnl6e5.js.map +0 -1
- package/dist/handler-stateless-CIkKPETH.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/internal_context-Dg4Cgjcu.d.ts +0 -37
- package/dist/internal_context.js.map +0 -1
- package/dist/mcp/client.d.ts +0 -42
- package/dist/mcp/do-oauth-client-provider.js.map +0 -1
- package/dist/mcp/x402.js.map +0 -1
- package/dist/wire-types-CU9rLoeS.js.map +0 -1
- package/dist/workflow-types-Baz_PO5v.d.ts +0 -280
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connector-CptFKzRh.js","names":[],"sources":["../src/browser/cdp-session.ts","../src/browser/browser-run.ts","../src/browser/quick-actions.ts","../src/browser/spec.ts","../src/browser/session-manager.ts","../src/browser/connector.ts"],"sourcesContent":["interface PendingCommand {\n resolve: (result: unknown) => void;\n reject: (error: Error) => void;\n timeoutId: ReturnType<typeof setTimeout>;\n method: string;\n sessionId?: string;\n startedAt: number;\n}\n\ninterface DebugEntry {\n at: string;\n type: string;\n [key: string]: unknown;\n}\n\nexport interface CdpSendOptions {\n timeoutMs?: number;\n sessionId?: string;\n}\n\nexport interface CdpAttachOptions {\n timeoutMs?: number;\n}\n\nconst DEFAULT_TIMEOUT_MS = 10_000;\nconst MAX_DEBUG_ENTRIES = 400;\n\n/**\n * A CDP session over an open WebSocket. Manages command correlation,\n * timeouts, target sessions, and a debug event ring buffer.\n *\n * Used host-side (not in the sandbox) — the sandbox calls into this\n * via DynamicWorkerExecutor's ToolDispatcher RPC.\n */\nexport class CdpSession {\n #socket: WebSocket;\n #nextId = 1;\n #pending = new Map<number, PendingCommand>();\n #debugLog: DebugEntry[] = [];\n #defaultTimeoutMs: number;\n #dispose?: () => void;\n readonly sessionId?: string;\n\n constructor(\n socket: WebSocket,\n defaultTimeoutMs = DEFAULT_TIMEOUT_MS,\n dispose?: () => void,\n sessionId?: string\n ) {\n this.#socket = socket;\n this.#defaultTimeoutMs = defaultTimeoutMs;\n this.#dispose = dispose;\n this.sessionId = sessionId;\n\n socket.addEventListener(\"message\", (event) => this.#handleMessage(event));\n socket.addEventListener(\"error\", () => {\n this.#rejectAll(new Error(\"CDP socket error\"));\n });\n socket.addEventListener(\"close\", () => {\n this.#rejectAll(new Error(\"CDP connection closed\"));\n });\n }\n\n send(\n method: string,\n params?: unknown,\n options: CdpSendOptions = {}\n ): Promise<unknown> {\n const id = this.#nextId++;\n const timeoutMs = options.timeoutMs ?? this.#defaultTimeoutMs;\n const sessionId =\n typeof options.sessionId === \"string\" && options.sessionId.length > 0\n ? options.sessionId\n : undefined;\n\n const domain = typeof method === \"string\" ? method.split(\".\")[0] : \"\";\n if (!sessionId && domain && ![\"Browser\", \"Target\"].includes(domain)) {\n this.#recordDebug(\"warning\", {\n id,\n method,\n reason: \"target-scoped method sent without sessionId\"\n });\n }\n\n const result = new Promise<unknown>((resolve, reject) => {\n const startedAt = performance.now();\n const timeoutId = setTimeout(() => {\n this.#pending.delete(id);\n reject(\n new Error(`CDP command timed out after ${timeoutMs}ms: ${method}`)\n );\n }, timeoutMs);\n this.#pending.set(id, {\n resolve,\n reject,\n timeoutId,\n method,\n sessionId,\n startedAt\n });\n });\n\n this.#recordDebug(\"send\", { id, method, sessionId, timeoutMs });\n this.#socket.send(JSON.stringify({ id, method, params, sessionId }));\n return result;\n }\n\n async attachToTarget(\n targetId: string,\n options: CdpAttachOptions = {}\n ): Promise<string> {\n if (typeof targetId !== \"string\" || !targetId) {\n throw new Error(\n \"attachToTarget requires a targetId — list open tabs with \" +\n \"send('Target.getTargets') or create one with \" +\n \"send('Target.createTarget', { url })\"\n );\n }\n\n const result = (await this.send(\n \"Target.attachToTarget\",\n {\n targetId,\n flatten: true\n },\n { timeoutMs: options.timeoutMs }\n )) as { sessionId?: string };\n\n const sessionId = result?.sessionId ?? \"\";\n if (!sessionId) {\n throw new Error(\n `Target.attachToTarget did not return a sessionId for target ${targetId}`\n );\n }\n\n this.#recordDebug(\"attach\", { targetId, sessionId });\n return sessionId;\n }\n\n getDebugLog(limit = 50): DebugEntry[] {\n const normalized = Number.isFinite(limit)\n ? Math.max(1, Math.floor(limit))\n : 50;\n return this.#debugLog.slice(-normalized);\n }\n\n clearDebugLog(): void {\n this.#debugLog = [];\n }\n\n disconnect(): void {\n this.#rejectAll(new Error(\"CDP session disconnected\"));\n try {\n this.#socket.close(1000, \"Done\");\n } catch {\n // socket may already be closed\n }\n }\n\n close(): void {\n this.disconnect();\n this.#dispose?.();\n }\n\n #rejectAll(error: Error): void {\n for (const [id, pending] of this.#pending.entries()) {\n clearTimeout(pending.timeoutId);\n this.#pending.delete(id);\n pending.reject(error);\n }\n }\n\n #handleMessage(event: MessageEvent): void {\n if (typeof event.data !== \"string\") {\n return;\n }\n\n let payload: Record<string, unknown>;\n try {\n payload = JSON.parse(event.data) as Record<string, unknown>;\n } catch {\n return;\n }\n\n this.#recordDebug(\"receive\", {\n id: payload.id,\n method: payload.method,\n sessionId: payload.sessionId,\n hasError: !!payload.error\n });\n\n if (typeof payload.id !== \"number\") {\n return;\n }\n\n const pending = this.#pending.get(payload.id);\n if (!pending) {\n return;\n }\n\n clearTimeout(pending.timeoutId);\n this.#pending.delete(payload.id);\n\n if (payload.error) {\n const err = payload.error as { code?: unknown; message?: string };\n const code = err.code ?? \"unknown\";\n const message = err.message ?? \"CDP error\";\n pending.reject(\n new Error(`CDP error ${code}: ${message} for ${pending.method}`)\n );\n return;\n }\n\n pending.resolve(payload.result);\n }\n\n #recordDebug(type: string, data: Record<string, unknown>): void {\n this.#debugLog.push({\n at: new Date().toISOString(),\n type,\n ...data\n });\n if (this.#debugLog.length > MAX_DEBUG_ENTRIES) {\n this.#debugLog.splice(0, this.#debugLog.length - MAX_DEBUG_ENTRIES);\n }\n }\n}\n\nconst LOCALHOST_HOSTS = new Set([\n \"localhost\",\n \"127.0.0.1\",\n \"0.0.0.0\",\n \"::1\",\n \"[::1]\"\n]);\n\n/**\n * Connect to a browser via a CDP base URL (e.g. http://localhost:9222).\n * Discovers the WebSocket debugger URL via /json/version,\n * rewrites localhost URLs to the base URL host, and opens the WebSocket.\n *\n * Useful for local development with `chrome --remote-debugging-port=9222`\n * or when connecting through a tunnel.\n */\nexport async function connectUrl(\n baseUrl: string,\n options?: { timeoutMs?: number; headers?: Record<string, string> }\n): Promise<CdpSession> {\n const endpoint = new URL(\"/json/version\", baseUrl).toString();\n const response = await fetch(endpoint, {\n headers: options?.headers\n });\n if (!response.ok) {\n throw new Error(\n `Failed to discover CDP endpoint at ${endpoint}: ${response.status}`\n );\n }\n\n const payload = (await response.json()) as {\n webSocketDebuggerUrl?: string;\n };\n if (!payload.webSocketDebuggerUrl) {\n throw new Error(\"CDP /json/version did not include webSocketDebuggerUrl\");\n }\n\n let wsUrl = payload.webSocketDebuggerUrl;\n const parsed = new URL(wsUrl);\n if (LOCALHOST_HOSTS.has(parsed.hostname)) {\n const base = new URL(baseUrl);\n parsed.hostname = base.hostname;\n parsed.port = base.port;\n parsed.protocol = base.protocol;\n } else {\n // Workers runtime requires fetch + Upgrade header for outbound WebSockets\n parsed.protocol = parsed.protocol === \"wss:\" ? \"https:\" : \"http:\";\n }\n const fetchUrl = parsed.toString();\n\n const wsResponse = await fetch(fetchUrl, {\n headers: { ...options?.headers, Upgrade: \"websocket\" }\n });\n const ws = wsResponse.webSocket;\n if (!ws) {\n throw new Error(\n `Failed to establish CDP WebSocket at ${fetchUrl} (status ${wsResponse.status})`\n );\n }\n ws.accept();\n\n return new CdpSession(ws, options?.timeoutMs);\n}\n","import { CdpSession } from \"./cdp-session\";\n\n/**\n * A Browser Rendering binding. Structural so it accepts both the classic\n * `Fetcher`-typed binding and the newer `BrowserRun` type generated by\n * `wrangler types` — we only ever use its `fetch` surface.\n */\nexport interface BrowserBinding {\n fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;\n}\n\nexport interface BrowserTargetInfo {\n id: string;\n type?: string;\n url?: string;\n title?: string;\n description?: string;\n devtoolsFrontendUrl?: string;\n webSocketDebuggerUrl?: string;\n}\n\nexport interface BrowserSessionInfo {\n sessionId: string;\n targets?: BrowserTargetInfo[];\n webSocketDebuggerUrl?: string;\n}\n\nexport interface ConnectBrowserOptions {\n timeoutMs?: number;\n keepAliveMs?: number;\n includeTargets?: boolean;\n /**\n * Opt into Browser Run [session recording](https://developers.cloudflare.com/browser-run/features/session-recording/):\n * an rrweb capture of DOM changes, input, and navigation, finalized when the\n * session closes. Set at session-launch time. Retrieve later with\n * {@link getBrowserRecording}.\n */\n recording?: boolean;\n /**\n * Select the browser engine. Defaults to Chromium. Use `\"kitesurf\"` for\n * Cloudflare's connection-scoped, agent-first browser engine.\n */\n browser?: \"kitesurf\";\n}\n\n/** An rrweb session recording for a closed Browser Run session. */\nexport interface BrowserRecording {\n sessionId: string;\n /** Recording length in milliseconds. */\n duration: number;\n /**\n * rrweb event arrays keyed by CDP target id (one per tab). Each value can be\n * passed directly to `rrweb-player` to replay that tab.\n */\n events: Record<string, unknown[]>;\n}\n\nexport class BrowserRenderingError extends Error {\n constructor(\n message: string,\n readonly status: number\n ) {\n super(message);\n this.name = \"BrowserRenderingError\";\n }\n}\n\nfunction browserSessionEndpoint(\n sessionId?: string,\n options?: {\n keepAliveMs?: number;\n includeTargets?: boolean;\n recording?: boolean;\n browser?: \"kitesurf\";\n }\n): string {\n const path = sessionId\n ? `/v1/devtools/browser/${sessionId}`\n : \"/v1/devtools/browser\";\n const url = new URL(`https://localhost${path}`);\n\n if (options?.keepAliveMs !== undefined) {\n url.searchParams.set(\"keep_alive\", String(options.keepAliveMs));\n }\n if (options?.includeTargets) {\n url.searchParams.set(\"targets\", \"true\");\n }\n if (options?.recording) {\n url.searchParams.set(\"recording\", \"true\");\n }\n if (options?.browser) {\n url.searchParams.set(\"browser\", options.browser);\n }\n\n return url.toString();\n}\n\nasync function parseBrowserSessionInfo(\n response: Response\n): Promise<BrowserSessionInfo> {\n const payload = (await response.json()) as {\n sessionId?: unknown;\n targets?: unknown;\n webSocketDebuggerUrl?: unknown;\n };\n const sessionId =\n typeof payload.sessionId === \"string\" ? payload.sessionId : \"\";\n\n if (!sessionId) {\n throw new Error(\"Browser Rendering response did not include a sessionId\");\n }\n\n return {\n sessionId,\n targets: Array.isArray(payload.targets)\n ? (payload.targets as BrowserTargetInfo[])\n : undefined,\n webSocketDebuggerUrl:\n typeof payload.webSocketDebuggerUrl === \"string\"\n ? payload.webSocketDebuggerUrl\n : undefined\n };\n}\n\nexport async function createBrowserSession(\n browser: BrowserBinding,\n options?: {\n keepAliveMs?: number;\n includeTargets?: boolean;\n recording?: boolean;\n }\n): Promise<BrowserSessionInfo> {\n const response = await browser.fetch(\n browserSessionEndpoint(undefined, options),\n { method: \"POST\" }\n );\n\n if (!response.ok) {\n throw new BrowserRenderingError(\n `Failed to create Browser Rendering session: ${response.status}`,\n response.status\n );\n }\n\n return parseBrowserSessionInfo(response);\n}\n\nexport async function listBrowserTargets(\n browser: BrowserBinding,\n sessionId: string\n): Promise<BrowserTargetInfo[]> {\n const response = await browser.fetch(\n `https://localhost/v1/devtools/browser/${sessionId}/json/list`\n );\n\n if (!response.ok) {\n throw new BrowserRenderingError(\n `Failed to list Browser Rendering targets for ${sessionId}: ${response.status}`,\n response.status\n );\n }\n\n const payload = (await response.json()) as unknown;\n return Array.isArray(payload) ? (payload as BrowserTargetInfo[]) : [];\n}\n\nexport async function deleteBrowserSession(\n browser: BrowserBinding,\n sessionId: string\n): Promise<void> {\n const response = await browser.fetch(\n `https://localhost/v1/devtools/browser/${sessionId}`,\n { method: \"DELETE\" }\n );\n\n if (!response.ok && response.status !== 404) {\n throw new BrowserRenderingError(\n `Failed to delete Browser Rendering session ${sessionId}: ${response.status}`,\n response.status\n );\n }\n}\n\n/**\n * Connect to a Browser Rendering session and delete it when closed.\n */\nexport async function connectBrowser(\n browser: BrowserBinding,\n options?: number | ConnectBrowserOptions\n): Promise<CdpSession> {\n const normalizedOptions =\n typeof options === \"number\" ? { timeoutMs: options } : (options ?? {});\n const isKitesurf = normalizedOptions.browser === \"kitesurf\";\n if (\n isKitesurf &&\n (normalizedOptions.keepAliveMs ||\n normalizedOptions.includeTargets ||\n normalizedOptions.recording)\n ) {\n throw new Error(\n \"Kitesurf does not support keepAliveMs, includeTargets, or recording\"\n );\n }\n\n const response = await browser.fetch(\n browserSessionEndpoint(undefined, {\n // Explicitly disabled Chromium-only options are accepted but never sent:\n // `keep_alive=0` is not a valid Kitesurf query parameter.\n keepAliveMs: isKitesurf ? undefined : normalizedOptions.keepAliveMs,\n includeTargets: normalizedOptions.includeTargets,\n recording: normalizedOptions.recording,\n browser: normalizedOptions.browser\n }),\n { headers: { Upgrade: \"websocket\" } }\n );\n\n const ws = response.webSocket;\n if (!ws) {\n throw new Error(\n \"Browser Rendering binding did not return a WebSocket. \" +\n \"Ensure the 'browser' binding is configured in wrangler.jsonc.\"\n );\n }\n\n if (normalizedOptions.browser === \"kitesurf\") {\n // A Kitesurf browser is scoped to this WebSocket. Browser Run may return\n // an ID for analytics correlation, but it cannot be used with the\n // session-scoped reconnect or delete endpoints.\n ws.accept();\n return new CdpSession(ws, normalizedOptions.timeoutMs);\n }\n\n const sessionId = response.headers.get(\"cf-browser-session-id\");\n if (!sessionId) {\n throw new Error(\n \"Browser Rendering binding did not include a session ID when opening the CDP WebSocket\"\n );\n }\n\n ws.accept();\n return new CdpSession(\n ws,\n normalizedOptions.timeoutMs,\n () => {\n deleteBrowserSession(browser, sessionId).catch((error: unknown) => {\n console.warn(\n `[agents/browser] Failed to delete one-shot Browser Run session ${sessionId}`,\n error\n );\n });\n },\n sessionId\n );\n}\n\n/**\n * Fetch a Browser Run [session recording](https://developers.cloudflare.com/browser-run/features/session-recording/)\n * by session id, via the Browser Rendering REST API.\n *\n * A recording is only available **after** the session closes (explicit\n * `closeSession()`, idle `keep_alive` expiry, or sweep) and is retained for 30\n * days. Capture the session id while the session is alive — e.g. from\n * `connector.liveView()`/`sessionInfo()` — then call this once it has ended.\n *\n * Unlike the binding-based helpers, this hits `api.cloudflare.com` directly, so\n * it needs an account id and an API token with `Browser Rendering` read access\n * (the Workers Browser Run binding cannot read recordings).\n */\nexport async function getBrowserRecording(options: {\n accountId: string;\n apiToken: string;\n sessionId: string;\n /** Override for testing; defaults to the global `fetch`. */\n fetchImpl?: typeof fetch;\n}): Promise<BrowserRecording> {\n const { accountId, apiToken, sessionId } = options;\n const fetchImpl = options.fetchImpl ?? fetch;\n const endpoint = `https://api.cloudflare.com/client/v4/accounts/${accountId}/browser-rendering/recording/${sessionId}`;\n\n const response = await fetchImpl(endpoint, {\n headers: { Authorization: `Bearer ${apiToken}` }\n });\n\n if (!response.ok) {\n throw new BrowserRenderingError(\n `Failed to fetch Browser Run recording for ${sessionId}: ${response.status}`,\n response.status\n );\n }\n\n // The recording endpoint returns the recording object directly; tolerate a\n // standard v4 `{ result }` envelope in case that changes.\n const payload = (await response.json()) as\n | BrowserRecording\n | { result?: BrowserRecording };\n const recording =\n \"result\" in payload && payload.result ? payload.result : payload;\n\n return recording as BrowserRecording;\n}\n\n/**\n * Connect to an existing Browser Rendering session without deleting it on close.\n */\nexport async function connectBrowserSession(\n browser: BrowserBinding,\n sessionId: string,\n timeoutMs?: number\n): Promise<CdpSession> {\n const response = await browser.fetch(browserSessionEndpoint(sessionId), {\n headers: { Upgrade: \"websocket\" }\n });\n\n const ws = response.webSocket;\n if (!ws) {\n throw new Error(\n `Browser Rendering binding did not return a WebSocket for session ${sessionId}`\n );\n }\n\n ws.accept();\n return new CdpSession(ws, timeoutMs, undefined, sessionId);\n}\n","import { BrowserRenderingError } from \"./browser-run\";\n\n/**\n * A Browser Run binding that supports [Quick Actions](https://developers.cloudflare.com/browser-run/quick-actions/).\n *\n * This is the `quickAction()` surface of the `BrowserRun` binding generated by\n * `wrangler types`. Quick Actions are stateless one-shot tasks (screenshot,\n * PDF, markdown, structured extraction, …) — no session, no token, just the\n * binding.\n *\n * Requires a Worker `compatibility_date` of `2026-03-24` or later, and\n * `remote: true` on the browser binding for local `wrangler dev`.\n */\nexport interface QuickActionBinding {\n // `options: unknown` (declared as a method, so parameters are checked\n // bivariantly) lets the real `BrowserRun` binding — whose `quickAction` is a\n // set of per-action typed overloads — satisfy this structural type.\n quickAction(action: string, options: unknown): Promise<Response>;\n}\n\n/** The Quick Action endpoints exposed by Browser Run. */\nexport type QuickAction =\n | \"content\"\n | \"screenshot\"\n | \"pdf\"\n | \"markdown\"\n | \"snapshot\"\n | \"scrape\"\n | \"json\"\n | \"links\"\n | \"crawl\";\n\ntype GotoOptions = {\n waitUntil?: \"load\" | \"domcontentloaded\" | \"networkidle0\" | \"networkidle2\";\n timeout?: number;\n};\n\n/** Options accepted by every Quick Action endpoint. */\nexport interface QuickActionCommonOptions {\n gotoOptions?: GotoOptions;\n viewport?: { width: number; height: number; deviceScaleFactor?: number };\n cookies?: unknown[];\n authenticate?: { username: string; password: string };\n setExtraHTTPHeaders?: Record<string, string>;\n userAgent?: string;\n /** Regex strings for requests to drop before render (e.g. `[\"/\\\\.css$/\"]`). */\n rejectRequestPattern?: string[];\n}\n\n/**\n * The page a Quick Action operates on: a `url` to load, or raw `html` to\n * render. Exactly one is required.\n */\nexport type QuickActionPage =\n | ({ url: string; html?: never } & QuickActionCommonOptions)\n | ({ html: string; url?: never } & QuickActionCommonOptions);\n\n/** Input for the AI-powered `/json` extraction endpoint. */\nexport type QuickActionExtractInput = QuickActionPage & {\n /** Natural-language instruction for what to extract. */\n prompt?: string;\n /** A JSON Schema describing the desired output shape. */\n response_format?: { type: \"json_schema\"; json_schema: unknown };\n /** Bring-your-own model(s), tried in order, for extraction. */\n custom_ai?: { model: string; authorization: string }[];\n};\n\n/** Input for the `/scrape` endpoint. */\nexport type QuickActionScrapeInput = QuickActionPage & {\n elements: { selector: string }[];\n};\n\n/** Input for the `/screenshot` endpoint. */\nexport type QuickActionScreenshotInput = QuickActionPage & {\n screenshotOptions?: Record<string, unknown>;\n selector?: string;\n};\n\n/** Binary output (screenshot or PDF) with its reported content type. */\nexport interface QuickActionBinary {\n data: Uint8Array;\n contentType: string;\n}\n\n/** Any Quick Action input accepted by the typed helpers. */\nexport type QuickActionInput =\n | QuickActionPage\n | QuickActionExtractInput\n | QuickActionScrapeInput\n | QuickActionScreenshotInput;\n\n/** Elements matched by one selector via `/scrape`. */\nexport interface QuickActionScrapeResult {\n selector: string;\n results: {\n html: string;\n text: string;\n width: number;\n height: number;\n top: number;\n left: number;\n attributes: { name: string; value: string }[];\n }[];\n}\n\n/** Result of a `/snapshot` request: rendered HTML plus a base64 screenshot. */\nexport interface QuickActionSnapshot {\n /** HTML content of the page. */\n content: string;\n /** Base64-encoded screenshot image. */\n screenshot: string;\n}\n\n/**\n * Run a Quick Action and return the raw {@link Response} from the binding.\n *\n * Most callers want a typed helper ({@link browserMarkdown},\n * {@link browserExtract}, …) instead; reach for this only when you need an\n * endpoint or option not yet wrapped. The per-action overloads type `params`\n * against the action when it is a string literal (e.g. `\"json\"` requires a\n * {@link QuickActionExtractInput}); any {@link QuickActionInput} is accepted\n * otherwise.\n */\nexport function runQuickAction(\n browser: QuickActionBinding,\n action: \"json\",\n params: QuickActionExtractInput\n): Promise<Response>;\nexport function runQuickAction(\n browser: QuickActionBinding,\n action: \"scrape\",\n params: QuickActionScrapeInput\n): Promise<Response>;\nexport function runQuickAction(\n browser: QuickActionBinding,\n action: \"screenshot\",\n params: QuickActionScreenshotInput\n): Promise<Response>;\nexport function runQuickAction(\n browser: QuickActionBinding,\n action: QuickAction,\n params: QuickActionInput\n): Promise<Response>;\nexport function runQuickAction(\n browser: QuickActionBinding,\n action: QuickAction,\n params: QuickActionInput\n): Promise<Response> {\n return browser.quickAction(action, params);\n}\n\n/** Build an error that includes the service's explanation, if the body has one. */\nasync function quickActionError(\n action: QuickAction,\n response: Response\n): Promise<BrowserRenderingError> {\n let detail = \"\";\n try {\n const text = await response.text();\n try {\n const body = JSON.parse(text) as {\n errors?: { message?: string }[];\n rawAiResponse?: string;\n };\n const messages = (body.errors ?? [])\n .map((e) => e.message)\n .filter((m): m is string => Boolean(m));\n if (messages.length > 0) detail = `: ${messages.join(\"; \")}`;\n else if (body.rawAiResponse) detail = `: ${body.rawAiResponse}`;\n else if (text) detail = `: ${text.slice(0, 200)}`;\n } catch {\n if (text) detail = `: ${text.slice(0, 200)}`;\n }\n } catch {\n // Body unreadable — fall back to the status code alone.\n }\n return new BrowserRenderingError(\n `Browser Run ${action} failed (${response.status})${detail}`,\n response.status\n );\n}\n\nasync function quickActionJson<T>(\n browser: QuickActionBinding,\n action: QuickAction,\n params: QuickActionInput\n): Promise<T> {\n const response = await runQuickAction(browser, action, params);\n if (!response.ok) throw await quickActionError(action, response);\n const payload = (await response.json()) as {\n success?: boolean;\n result?: T;\n errors?: { message?: string }[];\n };\n if (payload.success === false || payload.result === undefined) {\n const messages = (payload.errors ?? [])\n .map((e) => e.message)\n .filter((m): m is string => Boolean(m));\n throw new BrowserRenderingError(\n `Browser Run ${action} returned no result${messages.length > 0 ? `: ${messages.join(\"; \")}` : \"\"}`,\n response.status\n );\n }\n return payload.result;\n}\n\nasync function quickActionBinary(\n browser: QuickActionBinding,\n action: QuickAction,\n params: QuickActionInput\n): Promise<QuickActionBinary> {\n const response = await runQuickAction(browser, action, params);\n if (!response.ok) throw await quickActionError(action, response);\n const buffer = await response.arrayBuffer();\n return {\n data: new Uint8Array(buffer),\n contentType:\n response.headers.get(\"content-type\") ?? \"application/octet-stream\"\n };\n}\n\n/** Fetch a page's fully rendered HTML via `/content`. */\nexport function browserContent(\n browser: QuickActionBinding,\n input: QuickActionPage\n): Promise<string> {\n return quickActionJson<string>(browser, \"content\", input);\n}\n\n/** Convert a page (or raw HTML) to Markdown via `/markdown`. */\nexport function browserMarkdown(\n browser: QuickActionBinding,\n input: QuickActionPage\n): Promise<string> {\n return quickActionJson<string>(browser, \"markdown\", input);\n}\n\n/**\n * Extract structured data from a page with AI via `/json`. Provide a `prompt`,\n * a `response_format` JSON Schema, or both.\n */\nexport function browserExtract<T = unknown>(\n browser: QuickActionBinding,\n input: QuickActionExtractInput\n): Promise<T> {\n return quickActionJson<T>(browser, \"json\", input);\n}\n\n/** Retrieve every link on a page via `/links`. */\nexport function browserLinks(\n browser: QuickActionBinding,\n input: QuickActionPage\n): Promise<string[]> {\n return quickActionJson<string[]>(browser, \"links\", input);\n}\n\n/** Scrape specific elements (by CSS selector) via `/scrape`. */\nexport function browserScrape(\n browser: QuickActionBinding,\n input: QuickActionScrapeInput\n): Promise<QuickActionScrapeResult[]> {\n return quickActionJson<QuickActionScrapeResult[]>(browser, \"scrape\", input);\n}\n\n/** Capture rendered HTML plus a base64 screenshot in one request via `/snapshot`. */\nexport function browserSnapshot(\n browser: QuickActionBinding,\n input: QuickActionPage\n): Promise<QuickActionSnapshot> {\n return quickActionJson<QuickActionSnapshot>(browser, \"snapshot\", input);\n}\n\n/**\n * Render a screenshot via `/screenshot`. Returns the raw bytes and their\n * content type — by default a PNG (`image/png`). Note that passing\n * `screenshotOptions.encoding: \"base64\"` makes the service return a `text/plain`\n * data-URI string instead of binary, which this helper hands back verbatim.\n */\nexport function browserScreenshot(\n browser: QuickActionBinding,\n input: QuickActionScreenshotInput\n): Promise<QuickActionBinary> {\n return quickActionBinary(browser, \"screenshot\", input);\n}\n\n/** Render a PDF via `/pdf`. Returns the PDF bytes. */\nexport function browserPdf(\n browser: QuickActionBinding,\n input: QuickActionPage\n): Promise<QuickActionBinary> {\n return quickActionBinary(browser, \"pdf\", input);\n}\n","/**\n * Chrome DevTools Protocol spec fetching + caching.\n *\n * The raw `/json/protocol` payload is normalized into a searchable shape and\n * cached per source: `cdpUrl` specs by endpoint + headers, Browser Rendering\n * specs by the binding itself (a WeakMap) so two different bindings in the\n * same isolate don't share an entry. The CDP protocol is identical across\n * bindings, but per-binding keys avoid surprising cross-binding cache reads.\n */\n\nimport type { BrowserBinding } from \"./browser-run\";\n\ninterface RawCdpCommand {\n name: string;\n description?: string;\n}\n\ninterface RawCdpEvent {\n name: string;\n description?: string;\n}\n\ninterface RawCdpType {\n id: string;\n description?: string;\n}\n\n/** Raw CDP protocol domain from `/json/protocol` */\ninterface RawCdpDomain {\n domain: string;\n description?: string;\n commands?: RawCdpCommand[];\n events?: RawCdpEvent[];\n types?: RawCdpType[];\n}\n\nexport interface SearchableCdpSpec {\n domains: Array<{\n name: string;\n description?: string;\n commands: Array<{ name: string; method: string; description?: string }>;\n events: Array<{ name: string; event: string; description?: string }>;\n types: Array<{ id: string; name: string; description?: string }>;\n }>;\n}\n\nexport interface CdpSpecSource {\n /** Browser Rendering binding (Fetcher) — used in production */\n browser?: BrowserBinding;\n /** CDP base URL override (e.g. http://localhost:9222) */\n cdpUrl?: string;\n /** Headers to send with CDP URL discovery requests */\n cdpHeaders?: Record<string, string>;\n}\n\nconst MISSING_BROWSER_CONFIG =\n \"Either 'browser' (Fetcher binding) or 'cdpUrl' must be provided\";\n\ninterface SpecCacheEntry {\n spec: SearchableCdpSpec;\n cachedAt: number;\n}\n\nconst urlSpecCache = new Map<string, SpecCacheEntry>();\nconst bindingSpecCache = new WeakMap<BrowserBinding, SpecCacheEntry>();\n\nconst CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes\n\nfunction normalizeCdpSpec(spec: {\n domains?: RawCdpDomain[];\n}): SearchableCdpSpec {\n return {\n domains: (spec.domains ?? []).map((domain) => ({\n name: domain.domain,\n description: domain.description,\n commands: (domain.commands ?? []).map((command) => ({\n name: command.name,\n method: `${domain.domain}.${command.name}`,\n description: command.description\n })),\n events: (domain.events ?? []).map((event) => ({\n name: event.name,\n event: `${domain.domain}.${event.name}`,\n description: event.description\n })),\n types: (domain.types ?? []).map((type) => ({\n id: type.id,\n name: `${domain.domain}.${type.id}`,\n description: type.description\n }))\n }))\n };\n}\n\nfunction getSpecCacheKey(\n source: string,\n headers?: Record<string, string>\n): string {\n const headerEntries = Object.entries(headers ?? {}).sort(([a], [b]) =>\n a.localeCompare(b)\n );\n return `${source}:${JSON.stringify(headerEntries)}`;\n}\n\nasync function getCachedSpec<K>(\n cache: {\n get(key: K): SpecCacheEntry | undefined;\n set(key: K, entry: SpecCacheEntry): void;\n },\n key: K,\n load: () => Promise<{ domains?: RawCdpDomain[] }>\n): Promise<SearchableCdpSpec> {\n const cached = cache.get(key);\n if (cached && Date.now() - cached.cachedAt < CACHE_TTL_MS) {\n return cached.spec;\n }\n\n const spec = normalizeCdpSpec(await load());\n cache.set(key, { spec, cachedAt: Date.now() });\n return spec;\n}\n\nasync function fetchCdpSpecFromUrl(\n cdpBaseUrl: string,\n headers?: Record<string, string>\n): Promise<SearchableCdpSpec> {\n const endpoint = new URL(\"/json/protocol\", cdpBaseUrl).toString();\n\n return getCachedSpec(\n urlSpecCache,\n getSpecCacheKey(endpoint, headers),\n async () => {\n const response = await fetch(endpoint, { headers });\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch CDP spec from ${endpoint}: ${response.status}`\n );\n }\n\n return (await response.json()) as { domains?: RawCdpDomain[] };\n }\n );\n}\n\nasync function fetchCdpSpecFromBrowser(\n browser: BrowserBinding\n): Promise<SearchableCdpSpec> {\n return getCachedSpec(bindingSpecCache, browser, async () => {\n const createResponse = await browser.fetch(\n \"https://localhost/v1/devtools/browser\",\n {\n method: \"POST\"\n }\n );\n\n if (!createResponse.ok) {\n throw new Error(\n \"Failed to create Browser Rendering session for protocol fetch: \" +\n `${createResponse.status}`\n );\n }\n\n const payload = (await createResponse.json()) as { sessionId?: string };\n const sessionId = payload.sessionId;\n if (!sessionId) {\n throw new Error(\n \"Browser Rendering session response did not include a sessionId\"\n );\n }\n\n try {\n const response = await browser.fetch(\n `https://localhost/v1/devtools/browser/${sessionId}/json/protocol`\n );\n\n if (!response.ok) {\n throw new Error(\n \"Failed to fetch CDP spec from Browser Rendering: \" +\n `${response.status}`\n );\n }\n\n return (await response.json()) as { domains?: RawCdpDomain[] };\n } finally {\n try {\n await browser.fetch(\n `https://localhost/v1/devtools/browser/${sessionId}`,\n {\n method: \"DELETE\"\n }\n );\n } catch {\n // Cleanup failure should not mask the original result or error\n }\n }\n });\n}\n\n/** Load the (cached) searchable CDP spec for a browser source. */\nexport async function loadCdpSpec(\n source: CdpSpecSource\n): Promise<SearchableCdpSpec> {\n if (source.cdpUrl) {\n return fetchCdpSpecFromUrl(source.cdpUrl, source.cdpHeaders);\n }\n if (source.browser) {\n return fetchCdpSpecFromBrowser(source.browser);\n }\n throw new Error(MISSING_BROWSER_CONFIG);\n}\n","type MaybePromise<T> = T | Promise<T>;\n\nexport interface StoredBrowserSession {\n sessionId: string;\n createdAt: number;\n updatedAt: number;\n /**\n * Set when a sweep closed this entry's Browser Run session but kept the\n * entry as a tombstone, so a later resume of the owning execution fails\n * loudly instead of silently continuing in a fresh browser.\n */\n closedAt?: number;\n}\n\nexport interface BrowserSessionLock {\n release(): MaybePromise<void>;\n}\n\nexport interface BrowserSessionStore {\n /**\n * Acquire an exclusive lock for this session key. The lock must serialize\n * all holders using the same key. Held only around storage reads/writes —\n * never across Browser Rendering network calls.\n */\n acquireLock(key: string): MaybePromise<BrowserSessionLock>;\n get(key: string): MaybePromise<StoredBrowserSession | undefined>;\n set(key: string, session: StoredBrowserSession): MaybePromise<void>;\n delete(key: string): MaybePromise<void>;\n /**\n * List stored sessions by key prefix. Optional — used by sweeps to find\n * orphaned per-execution sessions; without it only the shared session key\n * is swept.\n */\n list?(prefix: string): MaybePromise<Map<string, StoredBrowserSession>>;\n}\n\nexport class DurableBrowserSessionStore implements BrowserSessionStore {\n static #queues = new WeakMap<\n DurableObjectStorage,\n Map<string, Promise<void>>\n >();\n\n constructor(private readonly storage: DurableObjectStorage) {}\n\n async acquireLock(key: string): Promise<BrowserSessionLock> {\n let queues = DurableBrowserSessionStore.#queues.get(this.storage);\n if (!queues) {\n queues = new Map();\n DurableBrowserSessionStore.#queues.set(this.storage, queues);\n }\n\n const previous = queues.get(key) ?? Promise.resolve();\n let releaseQueue: () => void = () => undefined;\n const current = previous.then(\n () =>\n new Promise<void>((resolve) => {\n releaseQueue = resolve;\n })\n );\n queues.set(key, current);\n await previous;\n\n let released = false;\n return {\n release: () => {\n if (released) return;\n released = true;\n if (queues.get(key) === current) {\n queues.delete(key);\n }\n releaseQueue();\n }\n };\n }\n\n async get(key: string): Promise<StoredBrowserSession | undefined> {\n return this.storage.get<StoredBrowserSession>(this.#storageKey(key));\n }\n\n async set(key: string, session: StoredBrowserSession): Promise<void> {\n await this.storage.put(this.#storageKey(key), session);\n }\n\n async delete(key: string): Promise<void> {\n await this.storage.delete(this.#storageKey(key));\n }\n\n async list(prefix: string): Promise<Map<string, StoredBrowserSession>> {\n const storagePrefix = this.#storageKey(prefix);\n const entries = await this.storage.list<StoredBrowserSession>({\n prefix: storagePrefix\n });\n const result = new Map<string, StoredBrowserSession>();\n for (const [storageKey, value] of entries) {\n result.set(storageKey.slice(\"browser-session:\".length), value);\n }\n return result;\n }\n\n #storageKey(key: string): string {\n return `browser-session:${key}`;\n }\n}\n\n/**\n * Default idle window used by {@link BrowserConnector.sweep} for the shared\n * (reuse/promoted) session entry.\n */\nexport const DEFAULT_SWEEP_IDLE_MS = 10 * 60 * 1000;\n","import { Validator, type OutputUnit, type Schema } from \"@cfworker/json-schema\";\nimport {\n CodemodeConnector,\n type ConnectorTool,\n type ConnectorTools,\n type ExecutionEndStatus,\n type PassEndStatus,\n type ToolExecuteContext\n} from \"@cloudflare/codemode\";\nimport { CdpSession, connectUrl } from \"./cdp-session\";\nimport {\n connectBrowser,\n connectBrowserSession,\n createBrowserSession,\n deleteBrowserSession,\n listBrowserTargets,\n BrowserRenderingError,\n type BrowserBinding,\n type BrowserSessionInfo,\n type BrowserTargetInfo\n} from \"./browser-run\";\nimport { loadCdpSpec, type SearchableCdpSpec } from \"./spec\";\nimport type {\n BrowserSessionStore,\n StoredBrowserSession\n} from \"./session-manager\";\nimport { DEFAULT_SWEEP_IDLE_MS } from \"./session-manager\";\n\n/** Browser session lifecycle for the connector (binding-backed only). */\nexport interface BrowserConnectorSessionOptions {\n /**\n * - `\"one-shot\"` (default) — one Browser Run session per codemode\n * execution, deleted when the execution ends.\n * - `\"reuse\"` — all executions share one stored session under `key`.\n * - `\"dynamic\"` — per-execution sessions by default; the model can call\n * `cdp.startSession()` to promote the current session into the shared\n * slot so later executions reuse it.\n */\n mode?: \"one-shot\" | \"reuse\" | \"dynamic\";\n /** Logical owner key for the shared (reuse/promoted) session. Default `\"default\"`. */\n key?: string;\n /** Browser Run inactivity timeout. Browser Run currently caps this server-side. */\n keepAliveMs?: number;\n /**\n * Opt into Browser Run [session recording](https://developers.cloudflare.com/browser-run/features/session-recording/)\n * for sessions this connector creates: an rrweb capture of everything the\n * agent did, finalized when the session closes. Retrieve it afterward with\n * {@link getBrowserRecording} using the session id from\n * {@link BrowserConnector.liveView}/`sessionInfo()`.\n */\n recording?: boolean;\n /**\n * Select the browser engine. Defaults to Chromium. Kitesurf is scoped to\n * one CDP WebSocket, so it supports only one-shot execution without\n * pause/resume, Live View, recording, or keep-alive.\n */\n browser?: \"kitesurf\";\n}\n\nexport type BrowserConnectorOptions = (\n | {\n /** Browser Rendering binding (Fetcher) — used in production. */\n browser: BrowserBinding;\n /**\n * Durable store for Browser Run session ids. Required with the binding:\n * a session must survive a pause (approval) and resume on a fresh\n * instance, so its id cannot live in connector memory.\n */\n store: BrowserSessionStore;\n session?: BrowserConnectorSessionOptions;\n cdpUrl?: never;\n cdpHeaders?: never;\n }\n | {\n /**\n * CDP base URL override (e.g. http://localhost:9222). The browser is\n * externally managed: no Browser Run sessions are created or deleted,\n * and session modes don't apply.\n */\n cdpUrl: string;\n /** Headers to send with CDP URL discovery requests (e.g. Access headers). */\n cdpHeaders?: Record<string, string>;\n browser?: never;\n store?: never;\n session?: never;\n }\n) & {\n /** CDP command timeout in milliseconds (default: 10000). */\n timeout?: number;\n};\n\nexport interface BrowserConnectorSweepOptions {\n /**\n * Close the shared (reuse/promoted) session when idle for at least this\n * many milliseconds. Defaults to the connector's `keepAliveMs`, or\n * {@link DEFAULT_SWEEP_IDLE_MS}.\n */\n maxIdleMs?: number;\n /**\n * Close *per-execution* sessions when idle for at least this many\n * milliseconds. Defaults to {@link DEFAULT_EXEC_SWEEP_IDLE_MS} (24h) —\n * deliberately at least as long as the codemode runtime's default paused\n * TTL, so a run awaiting approval is normally expired (and disposed) by\n * `expirePaused` before the sweep backstop ever touches its browser.\n */\n maxExecIdleMs?: number;\n}\n\nexport interface BrowserConnectorSweepResult {\n /** Store keys (and their Browser Run session ids) closed by this sweep. */\n swept: Array<{ key: string; sessionId: string }>;\n}\n\n/**\n * Live View rendering mode (the `mode` query param the hosted UI at\n * `live.browser.run` understands):\n *\n * - `\"tab\"` — a standalone, interactive page view (best for handing control\n * to a human).\n * - `\"devtools\"` — the full DevTools inspector panel (Elements, Console,\n * Network, …).\n *\n * Omit it to use whatever mode the binding's `devtoolsFrontendUrl` defaults\n * to.\n */\nexport type LiveViewMode = \"tab\" | \"devtools\";\n\n/** A single tab's Live View URL. */\nexport interface BrowserLiveViewUrl {\n /** Open this in a browser to watch/control the tab in real time. */\n url: string;\n /** CDP target (tab) id the URL points at. */\n targetId: string;\n /** Milliseconds the URL stays valid from when it was generated (~5 min). */\n expiresInMs: number;\n}\n\nexport interface BrowserLiveViewTarget {\n targetId: string;\n /** Embeddable Live View URL (the `devtoolsFrontendUrl`) for this tab. */\n url: string;\n /** The page the tab is currently showing (e.g. `https://example.com`). */\n pageUrl?: string;\n title?: string;\n type?: string;\n}\n\n/** Live View URLs for every tab in a (shared) session. */\nexport interface BrowserLiveView {\n sessionId: string;\n targets: BrowserLiveViewTarget[];\n /** Milliseconds the URLs stay valid from when they were generated (~5 min). */\n expiresInMs: number;\n}\n\nconst EXEC_KEY_PREFIX = \"cdp:exec:\";\n/**\n * Prefix of the synthetic session id stored for a Kitesurf execution: the\n * connection is scoped to its execution, so the entry is a marker rather than\n * a Browser Run session that can be reconnected to or deleted.\n */\nconst KITESURF_SESSION_PREFIX = \"kitesurf:\";\nconst REUSE_KEY_PREFIX = \"cdp:reuse:\";\n\n/**\n * Default idle window before {@link BrowserConnector.sweep} reclaims a\n * per-execution session. Matches the codemode runtime's default paused TTL\n * (24h): an execution paused for approval keeps its browser until the run\n * itself is expired.\n */\nexport const DEFAULT_EXEC_SWEEP_IDLE_MS = 24 * 60 * 60 * 1000;\n\n/**\n * Minimum interval between `updatedAt` bumps on a per-execution store entry.\n * Touching on every CDP call would write-amplify; once a minute is enough to\n * keep an active or recently-resumed execution out of sweep range.\n */\nconst EXEC_TOUCH_INTERVAL_MS = 60 * 1000;\n\n/**\n * Browser Run mints `devtoolsFrontendUrl`s (the Live View links) that are\n * valid for ~5 minutes. We surface the window so callers can decide how long\n * a shared link is good for before re-listing targets.\n */\nconst LIVE_VIEW_URL_TTL_MS = 5 * 60 * 1000;\n\nfunction isMissingBrowserSession(error: unknown): boolean {\n // Browser Run uses 404 for unknown ids and 410 after keep_alive expiry.\n return (\n error instanceof BrowserRenderingError &&\n (error.status === 404 || error.status === 410)\n );\n}\n\nfunction formatToolValidationError(\n connector: string,\n tool: string,\n errors: OutputUnit[]\n): string {\n // A failing property emits both a generic parent `properties` error and a\n // specific child error. Prefer the latter so the model sees what to fix.\n const specific = errors.filter((error) => error.keyword !== \"properties\");\n const relevant = specific.length > 0 ? specific : errors;\n const details = relevant.map((error) => {\n const location = error.instanceLocation\n .replace(/^#\\/?/, \"\")\n .replaceAll(\"~1\", \"/\")\n .replaceAll(\"~0\", \"~\")\n .replaceAll(\"/\", \".\");\n return `${location ? ` at ${location}` : \"\"}: ${error.error}`;\n });\n return `Invalid arguments for ${connector}.${tool}${details.join(\";\")}`;\n}\n\n/**\n * Rewrite the hosted Live View UI's `mode` query param (`tab` | `devtools`).\n * The raw `devtoolsFrontendUrl` is returned unchanged when no mode is asked\n * for or the URL can't be parsed.\n */\nfunction applyLiveViewMode(rawUrl: string, mode?: LiveViewMode): string {\n if (!mode) return rawUrl;\n try {\n const url = new URL(rawUrl);\n url.searchParams.set(\"mode\", mode === \"devtools\" ? \"devtools\" : \"tab\");\n return url.toString();\n } catch {\n return rawUrl;\n }\n}\n\ninterface CachedSocket {\n session: CdpSession;\n /** Browser Run session id the socket is attached to (undefined for cdpUrl). */\n browserSessionId?: string;\n /**\n * Live CDP session id per attach handle, valid for this socket only.\n * Rebuilt lazily after a reconnect (sockets are per-pass).\n */\n attached: Map<string, string>;\n}\n\n/**\n * `cdp.attachToTarget` returns `{ sessionId: \"target:<targetId>\" }` — a stable\n * handle instead of the raw CDP session id. (The object shape mirrors the real\n * `Target.attachToTarget` response, which is what models reach for.) Raw ids\n * are connection-scoped: a run that pauses\n * for approval resumes on a fresh WebSocket where the old id is invalid, and\n * the durable replay log would otherwise pin the stale value. The handle is a\n * pure function of the target, so replayed code computes identical arguments,\n * and `send` resolves it to a live session id on the current socket —\n * re-attaching lazily after a reconnect.\n */\nconst ATTACH_HANDLE_PREFIX = \"target:\";\n\n/**\n * Codemode connector exposing a live browser over the Chrome DevTools\n * Protocol as the `cdp` global.\n *\n * Per-execution resources are keyed by the codemode `executionId`:\n *\n * - The Browser Run session id is stored durably under `cdp:exec:<id>`, so a\n * run that pauses for approval reconnects to the *same* browser when it\n * resumes — even on a fresh instance.\n * - The CDP WebSocket is per-pass: `onPassEnd` disconnects it (a paused run\n * holds no socket), and the next pass reconnects from the stored id.\n * - `disposeExecution` deletes the session unless it was promoted to the\n * shared slot via `cdp.startSession()` (dynamic mode).\n *\n * Locks on the session store are held only around store reads/writes, never\n * across network calls to Browser Run or while a socket is open.\n */\nexport class BrowserConnector extends CodemodeConnector {\n #options: BrowserConnectorOptions;\n #sockets = new Map<string, CachedSocket>();\n #connecting = new Map<string, Promise<CdpSession>>();\n\n constructor(\n ctx: DurableObjectState | ExecutionContext,\n options: BrowserConnectorOptions\n ) {\n super(ctx, {});\n if (!options.cdpUrl && !options.browser) {\n throw new Error(\n \"BrowserConnector requires either 'browser' (Fetcher binding) or 'cdpUrl'\"\n );\n }\n if (options.browser && !options.store) {\n throw new Error(\n \"BrowserConnector requires 'store' when using the Browser Rendering binding\"\n );\n }\n if (options.session?.browser === \"kitesurf\") {\n if (\n options.session.mode !== undefined &&\n options.session.mode !== \"one-shot\"\n ) {\n throw new Error('Kitesurf only supports session mode \"one-shot\"');\n }\n if (options.session.keepAliveMs) {\n throw new Error(\"Kitesurf does not support keepAliveMs\");\n }\n if (options.session.recording) {\n throw new Error(\"Kitesurf does not support session recording\");\n }\n }\n this.#options = options;\n }\n\n name(): string {\n return \"cdp\";\n }\n\n protected instructions(): string {\n const mode = this.#mode();\n const lines = [\n \"Issue CDP calls sequentially — never in parallel (no Promise.all): call order is recorded for durable replay.\",\n \"cdp.send returns the CDP method result directly, not the outer JSON-RPC envelope: Target.createTarget returns { targetId }, Runtime.evaluate returns { result: { value } }, and Page.captureScreenshot returns { data }.\",\n \"Browser-/Target-scoped commands (Target.createTarget, Target.getTargets) need no sessionId. Page-scoped commands (Page.navigate, Runtime.evaluate) require one: `const { sessionId } = await cdp.attachToTarget({ targetId });` then pass it to every page-scoped send. Use this helper instead of sending Target.attachToTarget manually.\",\n \"Write large textual outputs such as page dumps to a file or workspace and pass around small references. For screenshots, follow the host tool's documented screenshot result format.\",\n \"If a command fails or times out, check cdp.getDebugLog() for recent protocol traffic.\"\n ];\n if (this.#isKitesurf()) {\n lines.push(\n \"Kitesurf implements a subset of CDP and does not expose protocol discovery.\",\n \"Kitesurf is scoped to this connection. Complete the whole browser task in one execution and do not pause for approval: the browser cannot reconnect when execution resumes.\",\n \"Kitesurf Page.navigate may resolve before layout and paint. Before a screenshot: call Page.enable; navigate; poll Runtime.evaluate with returnByValue: true until result.value reports document.readyState === 'complete' and non-empty body text; then wait 1000ms before Page.captureScreenshot. Do not capture if readiness fails.\"\n );\n } else {\n lines.push(\n \"Use cdp.spec() to discover commands, events, and types when unsure.\",\n \"When a step needs a human (login, MFA, CAPTCHA, sensitive input), call cdp.getLiveViewUrl() to get a link they can open to control the browser live — surface it, then make an approval-gated call so the run pauses until they're done.\"\n );\n }\n if (mode === \"one-shot\") {\n lines.push(\n \"The browser session lasts for this execution only and is closed when it ends.\"\n );\n } else if (mode === \"reuse\") {\n lines.push(\n \"The browser session is shared and persists across executions — tabs and state you leave behind will still be there next time.\"\n );\n } else {\n lines.push(\n \"The browser session is one-shot by default. If browser state must persist after this execution (e.g. a logged-in page), call cdp.startSession() to keep it alive for later executions.\"\n );\n }\n return lines.join(\"\\n\");\n }\n\n protected override tool(name: string, tool: ConnectorTool): ConnectorTool {\n if (!tool.inputSchema) return tool;\n\n // Both types describe draft-7 schemas, but @cfworker's `Schema` type is\n // narrower than JSONSchema7 around boolean subschemas.\n const schema = tool.inputSchema as unknown as Schema;\n const validator = new Validator(schema, \"7\", false);\n return {\n ...tool,\n execute: async (args, ctx) => {\n // Browser's argumentless tools are documented as `cdp.spec()` etc.;\n // treat an omitted argument as the empty object their schemas expect.\n const input = args === undefined ? {} : args;\n const result = validator.validate(input);\n if (!result.valid) {\n throw new Error(\n formatToolValidationError(this.name(), name, result.errors)\n );\n }\n return await tool.execute(input, ctx);\n }\n };\n }\n\n protected tools(): ConnectorTools {\n const tools: ConnectorTools = {\n send: {\n description:\n \"Send a CDP command and return its method result directly (the outer JSON-RPC envelope is removed). Page-scoped commands require a sessionId — pass the handle returned by attachToTarget.\",\n inputSchema: {\n type: \"object\",\n properties: {\n method: {\n type: \"string\",\n description: 'CDP method, e.g. \"Target.createTarget\"'\n },\n params: {\n type: \"object\",\n description: \"CDP command parameters\"\n },\n sessionId: {\n type: \"string\",\n description:\n \"Session handle from attachToTarget, for page-scoped commands\"\n },\n timeoutMs: {\n type: \"number\",\n description: \"Per-command timeout override in milliseconds\"\n }\n },\n required: [\"method\"]\n },\n execute: async (args, ctx) => {\n const { method, params, sessionId, timeoutMs } = args as {\n method: string;\n params?: unknown;\n sessionId?: string;\n timeoutMs?: number;\n };\n const executionId = this.#executionId(ctx);\n const socket = await this.#socket(executionId);\n const resolved = await this.#resolveSessionHandle(\n executionId,\n sessionId\n );\n try {\n return await socket.send(method, params, {\n sessionId: resolved,\n timeoutMs\n });\n } catch (err) {\n // \"Method wasn't found\" is almost always one of two model\n // mistakes. Teach the fix instead of leaving a bare protocol\n // error: either the method is actually an event (events can't be\n // sent), or a page-scoped command went to the browser-level\n // session because no sessionId was passed.\n if (\n err instanceof Error &&\n /-32601|wasn't found/.test(err.message)\n ) {\n if (await this.#isSpecEvent(method)) {\n throw new Error(\n `${err.message}. '${method}' is a CDP *event*, not a ` +\n `command — it cannot be called via cdp.send. To wait for ` +\n `page state, poll instead (e.g. Runtime.evaluate of ` +\n `document.readyState until \"complete\").`\n );\n }\n if (!sessionId) {\n throw new Error(\n `${err.message}. Page-scoped commands need a sessionId: ` +\n `const { sessionId } = await cdp.attachToTarget({ targetId }); ` +\n `then pass sessionId to cdp.send.`\n );\n }\n }\n throw err;\n }\n }\n },\n\n attachToTarget: {\n description: this.#isKitesurf()\n ? \"Attach to a target (tab) and return { sessionId } to pass to page-scoped send calls for this connection.\"\n : \"Attach to a target (tab) and return { sessionId } — a stable session handle to pass as sessionId in page-scoped send calls. The handle stays valid across pauses/resumes.\",\n inputSchema: {\n type: \"object\",\n properties: {\n targetId: {\n type: \"string\",\n description: \"Target id from Target.createTarget/getTargets\"\n },\n timeoutMs: { type: \"number\" }\n },\n required: [\"targetId\"]\n },\n outputSchema: {\n type: \"object\",\n properties: {\n sessionId: {\n type: \"string\",\n description: this.#isKitesurf()\n ? \"Session handle for page-scoped send calls on this connection\"\n : \"Stable session handle for page-scoped send calls (valid across pauses/resumes)\"\n }\n },\n required: [\"sessionId\"]\n },\n execute: async (args, ctx) => {\n const { targetId, timeoutMs } = args as {\n targetId: string;\n timeoutMs?: number;\n };\n const executionId = this.#executionId(ctx);\n await this.#attach(executionId, targetId, timeoutMs);\n return { sessionId: `${ATTACH_HANDLE_PREFIX}${targetId}` };\n }\n },\n\n spec: {\n description:\n \"Return the searchable Chrome DevTools Protocol spec: domains with their commands, events, and types. Use it to discover method names and capabilities.\",\n replay: \"reexecute\",\n inputSchema: { type: \"object\", properties: {} },\n execute: async (): Promise<SearchableCdpSpec> => {\n if (this.#isKitesurf()) {\n throw new Error(\n \"Kitesurf does not expose a CDP protocol specification\"\n );\n }\n return loadCdpSpec(this.#options);\n }\n },\n\n getDebugLog: {\n description:\n \"Return recent CDP protocol traffic (sends, receives, warnings) for this execution's connection — useful to diagnose failures and timeouts.\",\n replay: \"reexecute\",\n inputSchema: {\n type: \"object\",\n properties: {\n limit: {\n type: \"number\",\n description: \"Max entries to return (default 50)\"\n }\n }\n },\n execute: async (args, ctx) => {\n const { limit } = (args ?? {}) as { limit?: number };\n const socket = await this.#socket(this.#executionId(ctx));\n return socket.getDebugLog(limit);\n }\n },\n\n clearDebugLog: {\n description: \"Clear the CDP debug log for this execution's connection.\",\n inputSchema: { type: \"object\", properties: {} },\n execute: async (_args, ctx) => {\n const socket = await this.#socket(this.#executionId(ctx));\n socket.clearDebugLog();\n return null;\n }\n }\n };\n\n if (this.#isKitesurf()) {\n delete tools.spec;\n } else {\n tools.getLiveViewUrl = {\n description:\n \"Return a Live View URL for a tab — a link a human can open in a \" +\n \"browser to watch and control this session in real time. Use it \" +\n \"for human-in-the-loop steps (login, MFA, CAPTCHA, sensitive \" +\n \"input): get the URL, surface it to the user, then make a call \" +\n \"that pauses for approval so they can act before the run \" +\n \"continues. The URL is valid for ~5 minutes.\",\n replay: \"reexecute\",\n inputSchema: {\n type: \"object\",\n properties: {\n targetId: {\n type: \"string\",\n description:\n \"Target (tab) id to view; defaults to the first open page\"\n },\n mode: {\n type: \"string\",\n enum: [\"tab\", \"devtools\"],\n description:\n \"tab = standalone interactive page view (best for handoff); \" +\n \"devtools = full DevTools inspector panel\"\n }\n }\n },\n execute: async (args, ctx) => {\n const { targetId, mode } = (args ?? {}) as {\n targetId?: string;\n mode?: LiveViewMode;\n };\n return this.#liveViewUrl(this.#executionId(ctx), { targetId, mode });\n }\n };\n }\n\n const mode = this.#mode();\n if (mode === \"reuse\" || mode === \"dynamic\") {\n tools.startSession = {\n description:\n mode === \"dynamic\"\n ? \"Promote the current browser session into the shared slot so it persists after this execution. Later executions reuse it. Returns the session info.\"\n : \"Ensure the shared browser session exists and return its info.\",\n inputSchema: { type: \"object\", properties: {} },\n execute: async (_args, ctx) =>\n this.#startSession(this.#executionId(ctx))\n };\n tools.sessionInfo = {\n description:\n \"Return info about the shared browser session (id and open targets), or null when none exists.\",\n replay: \"reexecute\",\n inputSchema: { type: \"object\", properties: {} },\n execute: async () => (await this.sessionInfo()) ?? null\n };\n tools.closeSession = {\n description:\n \"Close the shared browser session, discarding its tabs and state.\",\n inputSchema: { type: \"object\", properties: {} },\n execute: async (_args, ctx) => {\n await this.#closeReusableFor(this.#executionId(ctx));\n return null;\n }\n };\n tools.resetSession = {\n description:\n \"Close the shared browser session and start a fresh one. Returns the new session info.\",\n inputSchema: { type: \"object\", properties: {} },\n execute: async (_args, ctx) =>\n this.#resetSession(this.#executionId(ctx))\n };\n }\n\n return tools;\n }\n\n // ---------------------------------------------------------------------\n // Lifecycle hooks\n // ---------------------------------------------------------------------\n\n /**\n * A pass is over (completed, errored, or paused awaiting approval) — drop\n * the CDP socket. The Browser Run session itself stays alive; a resume\n * reconnects from the durably stored session id.\n */\n override async onPassEnd(\n executionId: string,\n status: PassEndStatus\n ): Promise<void> {\n this.#dropSocket(executionId);\n if (!this.#isKitesurf() || status !== \"paused\") return;\n\n const key = this.#execKey(executionId);\n const lock = await this.#store.acquireLock(key);\n try {\n const stored = await this.#store.get(key);\n // Only a Kitesurf marker is gone with its connection; a session left by\n // an earlier Chromium run is still live and must stay reclaimable.\n if (stored?.sessionId.startsWith(KITESURF_SESSION_PREFIX)) {\n await this.#store.set(key, { ...stored, closedAt: Date.now() });\n }\n } finally {\n await lock.release();\n }\n }\n\n /**\n * The execution is terminal — delete its Browser Run session unless it was\n * promoted to the shared slot via `cdp.startSession()`.\n */\n override async disposeExecution(\n executionId: string,\n _status: ExecutionEndStatus\n ): Promise<void> {\n this.#dropSocket(executionId);\n if (!this.#options.browser) return;\n\n if (this.#isKitesurf()) {\n const key = this.#execKey(executionId);\n const lock = await this.#store.acquireLock(key);\n // An entry written before the connector was switched to Kitesurf still\n // holds a real Browser Run session that has to be closed.\n let stale: StoredBrowserSession | undefined;\n try {\n const stored = await this.#store.get(key);\n if (\n stored &&\n stored.closedAt === undefined &&\n !stored.sessionId.startsWith(KITESURF_SESSION_PREFIX)\n ) {\n stale = stored;\n }\n await this.#store.delete(key);\n } finally {\n await lock.release();\n }\n if (stale) {\n try {\n await deleteBrowserSession(this.#options.browser, stale.sessionId);\n } catch (error) {\n console.warn(\n `[agents/browser] Failed to delete Browser Run session ${stale.sessionId} for execution ${executionId}`,\n error\n );\n }\n }\n return;\n }\n\n const store = this.#options.store;\n const execKey = this.#execKey(executionId);\n const lock = await store.acquireLock(execKey);\n // Decide and update storage under the lock; the Browser Rendering delete\n // happens after release (locks wrap storage only).\n let toClose: StoredBrowserSession | undefined;\n try {\n const stored = await store.get(execKey);\n if (!stored) return;\n\n let promoted = false;\n if (this.#mode() === \"dynamic\") {\n const shared = await store.get(this.#reuseKey());\n promoted = shared?.sessionId === stored.sessionId;\n }\n\n if (!promoted && stored.closedAt === undefined) {\n toClose = stored;\n }\n await store.delete(execKey);\n } finally {\n await lock.release();\n }\n\n if (toClose) {\n try {\n await deleteBrowserSession(this.#options.browser, toClose.sessionId);\n } catch (error) {\n console.warn(\n `[agents/browser] Failed to delete Browser Run session ${toClose.sessionId} for execution ${executionId}`,\n error\n );\n }\n }\n }\n\n // ---------------------------------------------------------------------\n // Host-side helpers — for callables and scheduled tasks on the agent.\n // ---------------------------------------------------------------------\n\n /** Info about the shared (reuse/promoted) session, if one exists. */\n async sessionInfo(): Promise<BrowserSessionInfo | undefined> {\n if (!this.#options.browser || this.#isKitesurf()) return undefined;\n const store = this.#options.store;\n const key = this.#reuseKey();\n const lock = await store.acquireLock(key);\n let stored: StoredBrowserSession | undefined;\n try {\n stored = await store.get(key);\n } finally {\n await lock.release();\n }\n if (!stored) return undefined;\n try {\n return {\n sessionId: stored.sessionId,\n targets: await listBrowserTargets(\n this.#options.browser,\n stored.sessionId\n )\n };\n } catch (error) {\n if (isMissingBrowserSession(error)) {\n await this.#deleteStoredEntry(key, stored.sessionId);\n return undefined;\n }\n throw error;\n }\n }\n\n /**\n * Live View URLs for the shared (reuse/promoted) session's tabs, or\n * `undefined` when no shared session exists. Each URL opens an interactive,\n * real-time view of the browser — surface them in your UI (or send them via\n * Slack/email) to let a human watch or take over a running session\n * (human-in-the-loop). URLs are valid for ~5 minutes; call again for fresh\n * ones. Only meaningful with the Browser Rendering binding in\n * `reuse`/`dynamic` mode.\n */\n async liveView(options?: {\n mode?: LiveViewMode;\n }): Promise<BrowserLiveView | undefined> {\n const info = await this.sessionInfo();\n if (!info) return undefined;\n const targets = (info.targets ?? [])\n .filter((target) => target.devtoolsFrontendUrl)\n .map((target) => ({\n targetId: target.id,\n url: applyLiveViewMode(target.devtoolsFrontendUrl!, options?.mode),\n pageUrl: target.url,\n title: target.title,\n type: target.type\n }));\n return {\n sessionId: info.sessionId,\n targets,\n expiresInMs: LIVE_VIEW_URL_TTL_MS\n };\n }\n\n /** Close the shared (reuse/promoted) session, if one exists. */\n async closeSession(): Promise<void> {\n if (!this.#options.browser || this.#isKitesurf()) return;\n await this.#closeStoredSession(this.#reuseKey());\n }\n\n /**\n * Close stored sessions (shared and per-execution) idle past the threshold.\n * Per-execution entries normally die with `disposeExecution` (or the\n * codemode runtime's `expirePaused`); the sweep is the backstop for crashed\n * hosts. Call it from a recurring alarm/scheduled task.\n *\n * Active executions bump their entry's `updatedAt` on use, so only runs\n * idle past `maxExecIdleMs` (default 24h) are reclaimed. A swept\n * per-execution entry is kept as a tombstone (`closedAt`) rather than\n * deleted, so a later resume fails with a clear \"session expired\" error\n * instead of silently continuing in a fresh browser; tombstones are\n * deleted once they age past the threshold again.\n *\n * Kitesurf entries are reclaimed the same way, minus the Browser Run\n * delete: their stored id is a synthetic per-execution marker, not a\n * session, and the connection died with the execution.\n */\n async sweep(\n options?: BrowserConnectorSweepOptions\n ): Promise<BrowserConnectorSweepResult> {\n if (!this.#options.browser) return { swept: [] };\n const browser = this.#options.browser;\n const store = this.#options.store;\n const maxIdleMs =\n options?.maxIdleMs ??\n this.#options.session?.keepAliveMs ??\n DEFAULT_SWEEP_IDLE_MS;\n const maxExecIdleMs = options?.maxExecIdleMs ?? DEFAULT_EXEC_SWEEP_IDLE_MS;\n\n const keys = new Set<string>([this.#reuseKey()]);\n if (store.list) {\n for (const key of (await store.list(\"cdp:\")).keys()) {\n keys.add(key);\n }\n }\n\n const swept: Array<{ key: string; sessionId: string }> = [];\n for (const key of keys) {\n const isExec = key.startsWith(EXEC_KEY_PREFIX);\n const idleMs = isExec ? maxExecIdleMs : maxIdleMs;\n const lock = await store.acquireLock(key);\n let toClose: StoredBrowserSession | undefined;\n try {\n const stored = await store.get(key);\n if (!stored) continue;\n const now = Date.now();\n if (stored.closedAt !== undefined) {\n // Tombstone from a previous sweep — its session is already gone.\n // Drop it once it has aged past the threshold again.\n if (now - stored.closedAt >= idleMs) await store.delete(key);\n continue;\n }\n if (now - stored.updatedAt < idleMs) continue;\n if (isExec) {\n await store.set(key, { ...stored, closedAt: now });\n } else {\n await store.delete(key);\n }\n toClose = stored;\n } finally {\n await lock.release();\n }\n // Kitesurf entries hold a synthetic marker rather than a Browser Run\n // session id: the connection died with its execution, so there is\n // nothing remote to close. Entries written before the connector was\n // reconfigured still need their session deleted, so this is decided per\n // entry rather than from the current options.\n if (!toClose.sessionId.startsWith(KITESURF_SESSION_PREFIX)) {\n try {\n await deleteBrowserSession(browser, toClose.sessionId);\n } catch (error) {\n console.warn(\n `[agents/browser] Sweep failed to delete Browser Run session ${toClose.sessionId}`,\n error\n );\n }\n }\n swept.push({ key, sessionId: toClose.sessionId });\n }\n return { swept };\n }\n\n // ---------------------------------------------------------------------\n // Session + socket resolution\n // ---------------------------------------------------------------------\n\n #isKitesurf(): boolean {\n return this.#options.session?.browser === \"kitesurf\";\n }\n\n #mode(): \"one-shot\" | \"reuse\" | \"dynamic\" {\n return this.#options.session?.mode ?? \"one-shot\";\n }\n\n #execKey(executionId: string): string {\n return `${EXEC_KEY_PREFIX}${executionId}`;\n }\n\n #reuseKey(): string {\n return `${REUSE_KEY_PREFIX}${this.#options.session?.key ?? \"default\"}`;\n }\n\n #executionId(ctx?: ToolExecuteContext): string {\n if (!ctx?.executionId) {\n throw new Error(\n \"BrowserConnector requires an execution context — use it through createCodemodeRuntime\"\n );\n }\n return ctx.executionId;\n }\n\n #dropSocket(executionId: string): void {\n const cached = this.#sockets.get(executionId);\n if (!cached) return;\n this.#sockets.delete(executionId);\n cached.session.disconnect();\n }\n\n /** Attach the current socket to a target, caching the live CDP session id. */\n async #attach(\n executionId: string,\n targetId: string,\n timeoutMs?: number\n ): Promise<string> {\n const socket = await this.#socket(executionId);\n const cached = this.#sockets.get(executionId);\n const handle = `${ATTACH_HANDLE_PREFIX}${targetId}`;\n const existing = cached?.attached.get(handle);\n if (existing) return existing;\n const live = await socket.attachToTarget(targetId, { timeoutMs });\n cached?.attached.set(handle, live);\n return live;\n }\n\n /**\n * List the current tabs (targets) for this execution's browser, including\n * their `devtoolsFrontendUrl` (the Live View link). For the binding this is\n * the current Browser Run session; for an externally-managed `cdpUrl` it is\n * the standard CDP `/json/list`.\n */\n async #liveTargets(executionId: string): Promise<BrowserTargetInfo[]> {\n if (this.#options.cdpUrl) {\n const endpoint = new URL(\"/json/list\", this.#options.cdpUrl).toString();\n const response = await fetch(endpoint, {\n headers: this.#options.cdpHeaders\n });\n if (!response.ok) {\n throw new Error(\n `Failed to list targets at ${endpoint}: ${response.status}`\n );\n }\n const payload = (await response.json()) as unknown;\n return Array.isArray(payload) ? (payload as BrowserTargetInfo[]) : [];\n }\n\n const browser = this.#options.browser;\n if (!browser) throw new Error(\"BrowserConnector has no browser binding\");\n if (this.#isKitesurf()) {\n throw new Error(\"Kitesurf does not support Browser Run Live View\");\n }\n // Ensure a session + socket exist, then read the resolved Browser Run id.\n await this.#socket(executionId);\n const sessionId = this.#sockets.get(executionId)?.browserSessionId;\n if (!sessionId) return [];\n return listBrowserTargets(browser, sessionId);\n }\n\n /** Build a Live View URL for one tab in this execution's browser. */\n async #liveViewUrl(\n executionId: string,\n options: { targetId?: string; mode?: LiveViewMode }\n ): Promise<BrowserLiveViewUrl> {\n const targets = await this.#liveTargets(executionId);\n const target = options.targetId\n ? targets.find((candidate) => candidate.id === options.targetId)\n : (targets.find(\n (candidate) =>\n candidate.type === \"page\" && candidate.devtoolsFrontendUrl\n ) ?? targets.find((candidate) => candidate.devtoolsFrontendUrl));\n\n if (!target) {\n throw new Error(\n options.targetId\n ? `No target ${options.targetId} found. List tabs with Target.getTargets or open one with Target.createTarget.`\n : \"No browser tab is open yet. Create one (Target.createTarget) before requesting a Live View URL.\"\n );\n }\n if (!target.devtoolsFrontendUrl) {\n throw new Error(\n `Target ${target.id} has no Live View URL (devtoolsFrontendUrl). Live View needs the Browser Rendering binding.`\n );\n }\n\n return {\n url: applyLiveViewMode(target.devtoolsFrontendUrl, options.mode),\n targetId: target.id,\n expiresInMs: LIVE_VIEW_URL_TTL_MS\n };\n }\n\n /**\n * Resolve a model-facing session handle to the live CDP session id on the\n * current socket, re-attaching lazily after a reconnect. Raw CDP session\n * ids (from manual Target.attachToTarget sends) pass through untouched.\n */\n /**\n * True when `method` is a CDP *event* (e.g. `Page.loadEventFired`) rather\n * than a command. Used only on the `send` failure path to produce a better\n * error; any spec-loading failure just means no extra hint.\n */\n async #isSpecEvent(method: string): Promise<boolean> {\n try {\n if (this.#isKitesurf()) return false;\n const spec = await loadCdpSpec(this.#options);\n const domain = method.split(\".\")[0];\n return spec.domains.some(\n (d) => d.name === domain && d.events.some((e) => e.event === method)\n );\n } catch {\n return false;\n }\n }\n\n async #resolveSessionHandle(\n executionId: string,\n sessionId?: string\n ): Promise<string | undefined> {\n if (!sessionId?.startsWith(ATTACH_HANDLE_PREFIX)) return sessionId;\n const targetId = sessionId.slice(ATTACH_HANDLE_PREFIX.length);\n return this.#attach(executionId, targetId);\n }\n\n /**\n * Get or open the CDP socket for an execution. Concurrent calls for the\n * same execution (model code that ignores the \"sequential calls\" rule and\n * uses Promise.all) share one in-flight connect instead of racing and\n * leaking the loser's WebSocket.\n */\n #socket(executionId: string): Promise<CdpSession> {\n const inFlight = this.#connecting.get(executionId);\n if (inFlight) return inFlight;\n const promise = this.#socketInner(executionId).finally(() => {\n if (this.#connecting.get(executionId) === promise) {\n this.#connecting.delete(executionId);\n }\n });\n this.#connecting.set(executionId, promise);\n return promise;\n }\n\n async #socketInner(executionId: string): Promise<CdpSession> {\n if (this.#options.cdpUrl) {\n const cached = this.#sockets.get(executionId);\n if (cached) return cached.session;\n const session = await connectUrl(this.#options.cdpUrl, {\n timeoutMs: this.#options.timeout,\n headers: this.#options.cdpHeaders\n });\n this.#sockets.set(executionId, { session, attached: new Map() });\n return session;\n }\n\n const browser = this.#options.browser;\n if (!browser) throw new Error(\"BrowserConnector has no browser binding\");\n\n if (this.#isKitesurf()) {\n const cached = this.#sockets.get(executionId);\n if (cached) return cached.session;\n\n const key = this.#execKey(executionId);\n const lock = await this.#store.acquireLock(key);\n try {\n if (await this.#store.get(key)) {\n throw new Error(\n \"Kitesurf's connection was closed and cannot be resumed; start a new execution\"\n );\n }\n const now = Date.now();\n await this.#store.set(key, {\n sessionId: `${KITESURF_SESSION_PREFIX}${crypto.randomUUID()}`,\n createdAt: now,\n updatedAt: now\n });\n } finally {\n await lock.release();\n }\n\n try {\n const session = await connectBrowser(browser, {\n browser: \"kitesurf\",\n timeoutMs: this.#options.timeout\n });\n this.#sockets.set(executionId, { session, attached: new Map() });\n return session;\n } catch (error) {\n const failed = await this.#readStored(key);\n if (failed) await this.#deleteStoredEntry(key, failed.sessionId);\n throw error;\n }\n }\n\n const stored = await this.#resolveSession(executionId);\n const cached = this.#sockets.get(executionId);\n if (cached?.browserSessionId === stored.sessionId) {\n return cached.session;\n }\n if (cached) this.#dropSocket(executionId);\n\n const session = await connectBrowserSession(\n browser,\n stored.sessionId,\n this.#options.timeout\n );\n this.#sockets.set(executionId, {\n session,\n browserSessionId: stored.sessionId,\n attached: new Map()\n });\n return session;\n }\n\n /**\n * Resolve the Browser Run session for an execution:\n *\n * - An existing `cdp:exec:<id>` entry wins. If its session is gone (e.g.\n * expired while the run was paused), the run fails with a clear error\n * rather than silently continuing in a fresh browser.\n * - In `reuse` mode the shared session is used (created if missing).\n * - In `dynamic` mode an alive shared session is used; otherwise a fresh\n * per-execution session is created.\n * - In `one-shot` mode a fresh per-execution session is created.\n */\n async #resolveSession(executionId: string): Promise<StoredBrowserSession> {\n const browser = this.#options.browser;\n if (!browser) throw new Error(\"BrowserConnector has no browser binding\");\n const mode = this.#mode();\n const execKey = this.#execKey(executionId);\n\n if (mode === \"reuse\") {\n return this.#ensureStoredSession(this.#reuseKey());\n }\n\n // one-shot / dynamic: a session this execution already opened wins.\n const existing = await this.#readStored(execKey);\n if (existing) {\n if (existing.closedAt === undefined && (await this.#isAlive(existing))) {\n // Keep the entry fresh so the sweep backstop never reclaims an\n // active (or recently resumed) execution's session.\n if (Date.now() - existing.updatedAt >= EXEC_TOUCH_INTERVAL_MS) {\n await this.#touchStored(execKey, existing);\n }\n return existing;\n }\n await this.#deleteStoredEntry(execKey, existing.sessionId);\n throw new Error(\n `Browser session ${existing.sessionId} expired or was swept while this execution was paused — the run cannot continue. Start a new execution.`\n );\n }\n\n if (mode === \"dynamic\") {\n const shared = await this.#readStored(this.#reuseKey());\n if (shared) {\n if (await this.#isAlive(shared)) {\n await this.#touchStored(this.#reuseKey(), shared);\n return shared;\n }\n await this.#deleteStoredEntry(this.#reuseKey(), shared.sessionId);\n }\n }\n\n // Create a fresh per-execution session. The Browser Rendering call\n // happens outside the store lock; the lock only guards the commit, so\n // two concurrent tool calls for the same execution don't double-create\n // (the loser's session is deleted).\n return this.#createAndCommit(execKey);\n }\n\n /**\n * Get the stored session under `key`, validating and creating as needed.\n *\n * Network calls (the liveness probe, session creation) happen OUTSIDE the\n * store lock — locks wrap storage only, so a hung Browser Rendering call\n * can't serialize every other operation on this key. The lock is\n * re-acquired to commit, with a sessionId re-check to detect a concurrent\n * swap; on a swap the new entry is re-validated from the top.\n */\n async #ensureStoredSession(key: string): Promise<StoredBrowserSession> {\n const browser = this.#options.browser;\n if (!browser) throw new Error(\"BrowserConnector has no browser binding\");\n const store = this.#store;\n\n for (let attempt = 0; attempt < 3; attempt++) {\n const existing = await store.get(key);\n if (!existing) return this.#createAndCommit(key);\n\n const alive = await this.#isAlive(existing);\n const lock = await store.acquireLock(key);\n try {\n const current = await store.get(key);\n if (current?.sessionId !== existing.sessionId) {\n // Entry was swapped while we probed — validate the new one.\n continue;\n }\n if (alive) {\n const refreshed = { ...current, updatedAt: Date.now() };\n await store.set(key, refreshed);\n return refreshed;\n }\n await store.delete(key);\n } finally {\n await lock.release();\n }\n // Dead entry deleted — the next iteration creates a fresh session.\n }\n throw new Error(\n `Browser session entry ${key} kept changing concurrently — retry`\n );\n }\n\n /**\n * Create a Browser Run session (outside any lock) and commit it under\n * `key`. If a concurrent caller committed first, their entry wins and the\n * redundant session is deleted best-effort.\n */\n async #createAndCommit(key: string): Promise<StoredBrowserSession> {\n const browser = this.#options.browser;\n if (!browser) throw new Error(\"BrowserConnector has no browser binding\");\n const store = this.#store;\n\n const info = await createBrowserSession(browser, {\n keepAliveMs: this.#options.session?.keepAliveMs,\n recording: this.#options.session?.recording\n });\n const now = Date.now();\n const stored: StoredBrowserSession = {\n sessionId: info.sessionId,\n createdAt: now,\n updatedAt: now\n };\n\n const lock = await store.acquireLock(key);\n let winner: StoredBrowserSession | undefined;\n try {\n const raced = await store.get(key);\n if (raced) {\n winner = raced;\n } else {\n await store.set(key, stored);\n }\n } finally {\n await lock.release();\n }\n\n if (winner) {\n try {\n await deleteBrowserSession(browser, stored.sessionId);\n } catch (error) {\n console.warn(\n `[agents/browser] Failed to delete redundant Browser Run session ${stored.sessionId}`,\n error\n );\n }\n return winner;\n }\n return stored;\n }\n\n async #isAlive(stored: StoredBrowserSession): Promise<boolean> {\n const browser = this.#options.browser;\n if (!browser) return false;\n try {\n await listBrowserTargets(browser, stored.sessionId);\n return true;\n } catch (error) {\n if (isMissingBrowserSession(error)) return false;\n throw error;\n }\n }\n\n // ---------------------------------------------------------------------\n // Session tools (reuse/dynamic)\n // ---------------------------------------------------------------------\n\n async #startSession(executionId: string): Promise<BrowserSessionInfo> {\n const browser = this.#options.browser;\n if (!browser) {\n throw new Error(\"startSession requires the Browser Rendering binding\");\n }\n const store = this.#options.store;\n const reuseKey = this.#reuseKey();\n\n if (this.#mode() === \"dynamic\") {\n // Promote this execution's session into the shared slot, if it has one.\n const exec = await this.#readStored(this.#execKey(executionId));\n if (exec && exec.closedAt === undefined) {\n const lock = await store.acquireLock(reuseKey);\n let replaced: StoredBrowserSession | undefined;\n try {\n const shared = await store.get(reuseKey);\n if (shared?.sessionId !== exec.sessionId) {\n replaced = shared;\n await store.set(reuseKey, { ...exec, updatedAt: Date.now() });\n }\n } finally {\n await lock.release();\n }\n if (replaced) {\n try {\n await deleteBrowserSession(browser, replaced.sessionId);\n } catch (error) {\n console.warn(\n `[agents/browser] Failed to delete replaced Browser Run session ${replaced.sessionId}`,\n error\n );\n }\n }\n return {\n sessionId: exec.sessionId,\n targets: await listBrowserTargets(browser, exec.sessionId)\n };\n }\n }\n\n const stored = await this.#ensureStoredSession(reuseKey);\n return {\n sessionId: stored.sessionId,\n targets: await listBrowserTargets(browser, stored.sessionId)\n };\n }\n\n async #resetSession(executionId: string): Promise<BrowserSessionInfo> {\n const browser = this.#options.browser;\n if (!browser) {\n throw new Error(\"resetSession requires the Browser Rendering binding\");\n }\n await this.#closeReusableFor(executionId);\n const stored = await this.#ensureStoredSession(this.#reuseKey());\n return {\n sessionId: stored.sessionId,\n targets: await listBrowserTargets(browser, stored.sessionId)\n };\n }\n\n /**\n * Close the shared session from inside an execution. If this execution's\n * socket is attached to that session, drop it first.\n */\n async #closeReusableFor(executionId: string): Promise<void> {\n const reuseKey = this.#reuseKey();\n const stored = await this.#readStored(reuseKey);\n if (!stored) return;\n const cached = this.#sockets.get(executionId);\n if (cached?.browserSessionId === stored.sessionId) {\n this.#dropSocket(executionId);\n }\n await this.#closeStoredSession(reuseKey);\n // In reuse mode the execution continues against a fresh shared session on\n // the next send. In dynamic mode the exec entry (if any) still points at\n // the closed session; clear it so the next send fails loudly instead of\n // silently targeting a deleted browser.\n const exec = await this.#readStored(this.#execKey(executionId));\n if (exec?.sessionId === stored.sessionId) {\n await this.#deleteStoredEntry(this.#execKey(executionId), exec.sessionId);\n }\n }\n\n // ---------------------------------------------------------------------\n // Store access — locks held only around the store operation itself.\n // ---------------------------------------------------------------------\n\n get #store(): BrowserSessionStore {\n const store = this.#options.store;\n if (!store) {\n throw new Error(\n \"BrowserConnector session storage requires the Browser Rendering binding\"\n );\n }\n return store;\n }\n\n async #readStored(key: string): Promise<StoredBrowserSession | undefined> {\n const store = this.#store;\n const lock = await store.acquireLock(key);\n try {\n return await store.get(key);\n } finally {\n await lock.release();\n }\n }\n\n async #writeStored(key: string, value: StoredBrowserSession): Promise<void> {\n const store = this.#store;\n const lock = await store.acquireLock(key);\n try {\n await store.set(key, value);\n } finally {\n await lock.release();\n }\n }\n\n async #touchStored(key: string, value: StoredBrowserSession): Promise<void> {\n await this.#writeStored(key, { ...value, updatedAt: Date.now() });\n }\n\n /** Delete the store entry only if it still points at `sessionId`. */\n async #deleteStoredEntry(key: string, sessionId: string): Promise<void> {\n const store = this.#store;\n const lock = await store.acquireLock(key);\n try {\n const current = await store.get(key);\n if (current?.sessionId === sessionId) {\n await store.delete(key);\n }\n } finally {\n await lock.release();\n }\n }\n\n /** Delete the stored entry under `key` and its Browser Run session. */\n async #closeStoredSession(key: string): Promise<void> {\n const browser = this.#options.browser;\n if (!browser) return;\n const store = this.#options.store;\n const lock = await store.acquireLock(key);\n let stored: StoredBrowserSession | undefined;\n try {\n stored = await store.get(key);\n if (stored) await store.delete(key);\n } finally {\n await lock.release();\n }\n if (stored) {\n await deleteBrowserSession(browser, stored.sessionId);\n }\n }\n}\n"],"mappings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+
i as DurableObjectCapability,
|
|
3
|
+
l as LifecycleRouteAddress,
|
|
4
|
+
t as AlarmContribution
|
|
5
|
+
} from "./capability-runner-CvHGZqUu.js";
|
|
6
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
|
+
import { DurableObject } from "cloudflare:workers";
|
|
8
|
+
|
|
9
|
+
//#region src/lifecycle/types.d.ts
|
|
10
|
+
type ImmutablePrimitive = undefined | null | boolean | string | number;
|
|
11
|
+
type Immutable<T> = T extends ImmutablePrimitive
|
|
12
|
+
? T
|
|
13
|
+
: T extends Array<infer U>
|
|
14
|
+
? ImmutableArray<U>
|
|
15
|
+
: T extends Map<infer K, infer V>
|
|
16
|
+
? ImmutableMap<K, V>
|
|
17
|
+
: T extends Set<infer M>
|
|
18
|
+
? ImmutableSet<M>
|
|
19
|
+
: ImmutableObject<T>;
|
|
20
|
+
type ImmutableArray<T> = ReadonlyArray<Immutable<T>>;
|
|
21
|
+
type ImmutableMap<K, V> = ReadonlyMap<Immutable<K>, Immutable<V>>;
|
|
22
|
+
type ImmutableSet<T> = ReadonlySet<Immutable<T>>;
|
|
23
|
+
type ImmutableObject<T> = { readonly [K in keyof T]: Immutable<T[K]> };
|
|
24
|
+
/** Immutable state persisted in a hibernating WebSocket attachment. */
|
|
25
|
+
type ConnectionState<T> = ImmutableObject<T> | null;
|
|
26
|
+
/** Functional update applied to a connection's current state. */
|
|
27
|
+
type ConnectionSetStateFn<T> = (prevState: ConnectionState<T>) => T;
|
|
28
|
+
/** Context supplied when a lifecycle accepts a WebSocket connection. */
|
|
29
|
+
type ConnectionContext = {
|
|
30
|
+
/** Original WebSocket upgrade request. */ request: Request;
|
|
31
|
+
};
|
|
32
|
+
/** A WebSocket managed by a Durable Object lifecycle. */
|
|
33
|
+
type Connection<TState = unknown> = WebSocket & {
|
|
34
|
+
/** Connection identifier */ id: string;
|
|
35
|
+
/**
|
|
36
|
+
* The URL of the original WebSocket upgrade request.
|
|
37
|
+
* Persisted in the WebSocket attachment so it survives hibernation.
|
|
38
|
+
*/
|
|
39
|
+
uri: string | null;
|
|
40
|
+
/**
|
|
41
|
+
* Arbitrary state associated with this connection.
|
|
42
|
+
* Read-only — use {@link Connection.setState} to update.
|
|
43
|
+
*
|
|
44
|
+
* This property is configurable, meaning it can be redefined via
|
|
45
|
+
* `Object.defineProperty` by downstream consumers (e.g. the Cloudflare
|
|
46
|
+
* Agents SDK) to namespace or wrap internal state storage.
|
|
47
|
+
*/
|
|
48
|
+
state: ConnectionState<TState>;
|
|
49
|
+
/**
|
|
50
|
+
* Update the state associated with this connection.
|
|
51
|
+
*
|
|
52
|
+
* Accepts either a new state value or an updater function that receives
|
|
53
|
+
* the previous state and returns the next state.
|
|
54
|
+
*
|
|
55
|
+
* This property is configurable, meaning it can be redefined via
|
|
56
|
+
* `Object.defineProperty` by downstream consumers that provide their own
|
|
57
|
+
* state projection.
|
|
58
|
+
*/
|
|
59
|
+
setState(
|
|
60
|
+
state: TState | ConnectionSetStateFn<TState> | null
|
|
61
|
+
): ConnectionState<TState>;
|
|
62
|
+
/**
|
|
63
|
+
* Tags returned by the owning Durable Object's `getConnectionTags` callback.
|
|
64
|
+
* Always includes the connection id as the first tag.
|
|
65
|
+
*/
|
|
66
|
+
tags: readonly string[];
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/lifecycle/durable-object-lifecycle.d.ts
|
|
70
|
+
/** Payload delivered to a lifecycle-managed WebSocket callback. */
|
|
71
|
+
type WSMessage = ArrayBuffer | ArrayBufferView | string;
|
|
72
|
+
/** Internal envelope transported between routed Lifecycle instances. */
|
|
73
|
+
type LifecycleRouteEnvelope = {
|
|
74
|
+
readonly capability: string;
|
|
75
|
+
readonly source: LifecycleRouteAddress | undefined;
|
|
76
|
+
readonly payload: unknown;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Installs and coordinates the runtime lifecycle for a Durable Object.
|
|
80
|
+
*
|
|
81
|
+
* Construct this as an instance field on a class that directly extends
|
|
82
|
+
* `DurableObject`, then call {@link Lifecycle.installHandlers}
|
|
83
|
+
* from that class's constructor.
|
|
84
|
+
*
|
|
85
|
+
* @experimental The API surface may change before stabilizing.
|
|
86
|
+
*/
|
|
87
|
+
declare class Lifecycle<
|
|
88
|
+
Env extends object = Cloudflare.Env,
|
|
89
|
+
Props extends Record<string, unknown> = Record<string, unknown>
|
|
90
|
+
> {
|
|
91
|
+
#private;
|
|
92
|
+
/**
|
|
93
|
+
* Construct and install a lifecycle in one explicit operation.
|
|
94
|
+
*
|
|
95
|
+
* @param host - The Durable Object whose runtime handlers the lifecycle owns.
|
|
96
|
+
* @returns The installed lifecycle.
|
|
97
|
+
*/
|
|
98
|
+
static install<
|
|
99
|
+
Env extends object,
|
|
100
|
+
Props extends Record<string, unknown> = Record<string, unknown>
|
|
101
|
+
>(host: DurableObject<Env>): Lifecycle<Env, Props>;
|
|
102
|
+
/**
|
|
103
|
+
* Bind a lifecycle to a Durable Object instance without mutating its handlers.
|
|
104
|
+
*
|
|
105
|
+
* @param host - The Durable Object whose runtime lifecycle this object owns.
|
|
106
|
+
*/
|
|
107
|
+
constructor(host: DurableObject<Env>);
|
|
108
|
+
/**
|
|
109
|
+
* Install platform fetch, alarm, and hibernating WebSocket handlers.
|
|
110
|
+
*
|
|
111
|
+
* Existing handlers are preserved for framework-owned dispatch such as the
|
|
112
|
+
* Agent's sub-agent router and alarm circuit breaker. Calling this method
|
|
113
|
+
* more than once is an error.
|
|
114
|
+
*/
|
|
115
|
+
installHandlers(): void;
|
|
116
|
+
/**
|
|
117
|
+
* Add a reusable capability before this lifecycle starts.
|
|
118
|
+
*
|
|
119
|
+
* @param capability - The capability to add in dispatch order.
|
|
120
|
+
* @returns This lifecycle.
|
|
121
|
+
*/
|
|
122
|
+
use(capability: DurableObjectCapability<Props>): this;
|
|
123
|
+
/** @internal Deliver a generic capability envelope to this Lifecycle. */
|
|
124
|
+
route(envelope: LifecycleRouteEnvelope): Promise<unknown>;
|
|
125
|
+
/**
|
|
126
|
+
* Execute SQL queries against the Durable Object's database
|
|
127
|
+
* @template T Type of the returned rows
|
|
128
|
+
* @param strings SQL query template strings
|
|
129
|
+
* @param values Values to be inserted into the query
|
|
130
|
+
* @returns Array of query results
|
|
131
|
+
*/
|
|
132
|
+
sql<T = Record<string, string | number | boolean | null>>(
|
|
133
|
+
strings: TemplateStringsArray,
|
|
134
|
+
...values: (string | number | boolean | null)[]
|
|
135
|
+
): T[];
|
|
136
|
+
/**
|
|
137
|
+
* Handle an incoming request for the owning Durable Object.
|
|
138
|
+
*/
|
|
139
|
+
fetch(request: Request): Promise<Response>;
|
|
140
|
+
/** @internal Dispatch a hibernating WebSocket message. */
|
|
141
|
+
webSocketMessage(ws: WebSocket, message: WSMessage): Promise<void>;
|
|
142
|
+
/** @internal Dispatch and reciprocate a hibernating WebSocket close. */
|
|
143
|
+
webSocketClose(
|
|
144
|
+
ws: WebSocket,
|
|
145
|
+
code: number,
|
|
146
|
+
reason: string,
|
|
147
|
+
wasClean: boolean
|
|
148
|
+
): Promise<void>;
|
|
149
|
+
/** @internal Dispatch a hibernating WebSocket error. */
|
|
150
|
+
webSocketError(ws: WebSocket, error: unknown): Promise<void>;
|
|
151
|
+
/**
|
|
152
|
+
* Start lifecycle capabilities and the owning Durable Object.
|
|
153
|
+
*
|
|
154
|
+
* Runtime fetch, alarm, and WebSocket entry points call this automatically.
|
|
155
|
+
* RPC methods may call it explicitly because native RPC bypasses fetch.
|
|
156
|
+
*
|
|
157
|
+
* @param props - Optional properties supplied to capability and host startup.
|
|
158
|
+
*/
|
|
159
|
+
start(props?: Props): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* The name used to address this Durable Object.
|
|
162
|
+
*
|
|
163
|
+
* Native `ctx.id.name` is authoritative. A read-only legacy storage fallback
|
|
164
|
+
* lets objects created by older PartyServer releases migrate without new
|
|
165
|
+
* name writes.
|
|
166
|
+
*/
|
|
167
|
+
get name(): string;
|
|
168
|
+
/** Send a message to all connected clients, except connection ids listed in `without` */
|
|
169
|
+
broadcast(
|
|
170
|
+
msg: string | ArrayBuffer | ArrayBufferView,
|
|
171
|
+
without?: string[] | undefined
|
|
172
|
+
): void;
|
|
173
|
+
/** Get a connection by connection id */
|
|
174
|
+
getConnection<TState = unknown>(id: string): Connection<TState> | undefined;
|
|
175
|
+
/** Get all managed connections, optionally filtered by tag. */
|
|
176
|
+
getConnections<TState = unknown>(tag?: string): Iterable<Connection<TState>>;
|
|
177
|
+
/**
|
|
178
|
+
* Recompute the physical Durable Object alarm from every capability.
|
|
179
|
+
*
|
|
180
|
+
* Concurrent requests are serialized so a later durable-state change cannot
|
|
181
|
+
* be overwritten by an earlier alarm calculation.
|
|
182
|
+
*/
|
|
183
|
+
rearmAlarm(): Promise<void>;
|
|
184
|
+
/** Dispose installed capabilities in reverse registration order. */
|
|
185
|
+
dispose(): Promise<void>;
|
|
186
|
+
/** Permanently disable and clear alarms during explicit object teardown. */
|
|
187
|
+
disableAlarms(): Promise<void>;
|
|
188
|
+
/** Dispatch lifecycle and host alarm callbacks after startup. */
|
|
189
|
+
alarm(): Promise<void>;
|
|
190
|
+
}
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/lifecycle/current-agent.d.ts
|
|
193
|
+
/**
|
|
194
|
+
* A Durable Object that has installed the Agents SDK Lifecycle.
|
|
195
|
+
*
|
|
196
|
+
* Pass a more specific Lifecycle Object type to {@link getCurrentAgent} when
|
|
197
|
+
* shared host code needs APIs implemented by a particular object.
|
|
198
|
+
*
|
|
199
|
+
* @experimental The API surface may change before stabilizing.
|
|
200
|
+
*/
|
|
201
|
+
interface LifecycleObject<
|
|
202
|
+
Env extends object = Cloudflare.Env,
|
|
203
|
+
Props extends Record<string, unknown> = Record<string, unknown>
|
|
204
|
+
> extends DurableObject<Env> {
|
|
205
|
+
readonly lifecycle: Lifecycle<Env, Props>;
|
|
206
|
+
onStart?(props?: Props): void | Promise<void>;
|
|
207
|
+
onRequest?(request: Request): Response | Promise<Response>;
|
|
208
|
+
onAlarm?(): void | Promise<void>;
|
|
209
|
+
getNextAlarm?(): AlarmContribution | Promise<AlarmContribution>;
|
|
210
|
+
onConnect?(
|
|
211
|
+
connection: Connection,
|
|
212
|
+
context: ConnectionContext
|
|
213
|
+
): void | Promise<void>;
|
|
214
|
+
onMessage?(connection: Connection, message: WSMessage): void | Promise<void>;
|
|
215
|
+
onClose?(
|
|
216
|
+
connection: Connection,
|
|
217
|
+
code: number,
|
|
218
|
+
reason: string,
|
|
219
|
+
wasClean: boolean
|
|
220
|
+
): void | Promise<void>;
|
|
221
|
+
onError?(connection: Connection, error: unknown): void | Promise<void>;
|
|
222
|
+
getConnectionTags?(
|
|
223
|
+
connection: Connection,
|
|
224
|
+
context: ConnectionContext
|
|
225
|
+
): string[] | Promise<string[]>;
|
|
226
|
+
}
|
|
227
|
+
/** Values associated with the currently executing Lifecycle host. */
|
|
228
|
+
type AgentContextStore = {
|
|
229
|
+
/** Lifecycle host selected for this invocation. */ agent: unknown /** WebSocket connection selected for this invocation, when applicable. */;
|
|
230
|
+
connection:
|
|
231
|
+
| Connection
|
|
232
|
+
| undefined /** HTTP request selected for this invocation, when applicable. */;
|
|
233
|
+
request:
|
|
234
|
+
| Request
|
|
235
|
+
| undefined /** Extension-owned value selected for this invocation, when applicable. */;
|
|
236
|
+
email: unknown;
|
|
237
|
+
};
|
|
238
|
+
/** Values returned by {@link getCurrentAgent}. */
|
|
239
|
+
type CurrentAgentContext<
|
|
240
|
+
Host extends DurableObject = LifecycleObject,
|
|
241
|
+
Email = unknown
|
|
242
|
+
> = {
|
|
243
|
+
agent: Host | undefined;
|
|
244
|
+
connection: Connection | undefined;
|
|
245
|
+
request: Request | undefined;
|
|
246
|
+
email: Email | undefined;
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Shared invocation context for Lifecycle, Agent, AIChatAgent, and Think.
|
|
250
|
+
*
|
|
251
|
+
* @internal Importing or relying on this symbol will break your code in a
|
|
252
|
+
* future release. Use {@link getCurrentAgent} to read the public context.
|
|
253
|
+
*/
|
|
254
|
+
declare const __DO_NOT_USE_WILL_BREAK__agentContext: AsyncLocalStorage<AgentContextStore>;
|
|
255
|
+
/**
|
|
256
|
+
* Return the current Agent or Lifecycle Object and invocation-specific values.
|
|
257
|
+
*
|
|
258
|
+
* Lifecycle host startup and alarm hooks receive the current object with no
|
|
259
|
+
* request. Request hooks additionally receive the request being handled.
|
|
260
|
+
* Lifecycle-managed WebSocket hooks receive their connection and, during
|
|
261
|
+
* connect, its upgrade request. Agent extensions may also establish context
|
|
262
|
+
* for email, chat turns, callable methods, and detached work. Capability hooks
|
|
263
|
+
* do not run in this ambient context.
|
|
264
|
+
*/
|
|
265
|
+
declare function getCurrentAgent<
|
|
266
|
+
Host extends DurableObject = LifecycleObject
|
|
267
|
+
>(): CurrentAgentContext<Host>;
|
|
268
|
+
//#endregion
|
|
269
|
+
export {
|
|
270
|
+
getCurrentAgent as a,
|
|
271
|
+
WSMessage as c,
|
|
272
|
+
ConnectionSetStateFn as d,
|
|
273
|
+
ConnectionState as f,
|
|
274
|
+
__DO_NOT_USE_WILL_BREAK__agentContext as i,
|
|
275
|
+
Connection as l,
|
|
276
|
+
CurrentAgentContext as n,
|
|
277
|
+
Lifecycle as o,
|
|
278
|
+
LifecycleObject as r,
|
|
279
|
+
LifecycleRouteEnvelope as s,
|
|
280
|
+
AgentContextStore as t,
|
|
281
|
+
ConnectionContext as u
|
|
282
|
+
};
|
|
283
|
+
//# sourceMappingURL=current-agent-CuMErtly.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
//#region src/lifecycle/current-agent.ts
|
|
3
|
+
/**
|
|
4
|
+
* Shared invocation context for Lifecycle, Agent, AIChatAgent, and Think.
|
|
5
|
+
*
|
|
6
|
+
* @internal Importing or relying on this symbol will break your code in a
|
|
7
|
+
* future release. Use {@link getCurrentAgent} to read the public context.
|
|
8
|
+
*/
|
|
9
|
+
const __DO_NOT_USE_WILL_BREAK__agentContext = new AsyncLocalStorage();
|
|
10
|
+
/**
|
|
11
|
+
* Return the current Agent or Lifecycle Object and invocation-specific values.
|
|
12
|
+
*
|
|
13
|
+
* Lifecycle host startup and alarm hooks receive the current object with no
|
|
14
|
+
* request. Request hooks additionally receive the request being handled.
|
|
15
|
+
* Lifecycle-managed WebSocket hooks receive their connection and, during
|
|
16
|
+
* connect, its upgrade request. Agent extensions may also establish context
|
|
17
|
+
* for email, chat turns, callable methods, and detached work. Capability hooks
|
|
18
|
+
* do not run in this ambient context.
|
|
19
|
+
*/
|
|
20
|
+
function getCurrentAgent() {
|
|
21
|
+
const store = __DO_NOT_USE_WILL_BREAK__agentContext.getStore();
|
|
22
|
+
if (!store) return {
|
|
23
|
+
agent: void 0,
|
|
24
|
+
connection: void 0,
|
|
25
|
+
request: void 0,
|
|
26
|
+
email: void 0
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
agent: store.agent,
|
|
30
|
+
connection: store.connection,
|
|
31
|
+
request: store.request,
|
|
32
|
+
email: store.email
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** Run one host hook in the context of its Lifecycle Object. */
|
|
36
|
+
function runInLifecycleHostContext(context, operation) {
|
|
37
|
+
return __DO_NOT_USE_WILL_BREAK__agentContext.run({
|
|
38
|
+
agent: context.host,
|
|
39
|
+
connection: context.connection,
|
|
40
|
+
request: context.request,
|
|
41
|
+
email: void 0
|
|
42
|
+
}, operation);
|
|
43
|
+
}
|
|
44
|
+
/** Run a capability hook without inheriting a current Agent or host context. */
|
|
45
|
+
function runWithoutCurrentAgent(operation) {
|
|
46
|
+
return __DO_NOT_USE_WILL_BREAK__agentContext.exit(operation);
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { runWithoutCurrentAgent as i, getCurrentAgent as n, runInLifecycleHostContext as r, __DO_NOT_USE_WILL_BREAK__agentContext as t };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=current-agent-DhoDkSnH.js.map
|