agents 0.32.0 → 0.34.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 +1 -1
- package/dist/{agent-routing-vVMA7m8Y.d.ts → agent-routing-BSoZzNiP.d.ts} +537 -373
- package/dist/agent-routing.d.ts +1 -1
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/{agent-tools-gGXXkf1z.d.ts → agent-tools-Be-hpRpH.d.ts} +2 -2
- package/dist/agent-tools.d.ts +1 -1
- package/dist/{ai-sdk-Kon40i0q.js → ai-sdk-CRMlEBX7.js} +75 -44
- package/dist/ai-sdk-CRMlEBX7.js.map +1 -0
- package/dist/browser/ai.js +2 -3
- package/dist/browser/ai.js.map +1 -1
- package/dist/browser/index.d.ts +33 -21
- package/dist/browser/index.js +937 -4
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/tools/ai-sdk.d.ts +4 -4
- package/dist/browser/tools/ai-sdk.js +9 -3
- package/dist/browser/tools/ai-sdk.js.map +1 -1
- package/dist/browser/tools/pi.d.ts +11 -8
- package/dist/browser/tools/pi.js +58 -11
- package/dist/browser/tools/pi.js.map +1 -1
- package/dist/browser/tools/tanstack-ai.d.ts +4 -4
- package/dist/browser/tools/tanstack-ai.js +3 -3
- package/dist/browser/tools/tanstack-ai.js.map +1 -1
- package/dist/{browser-D9RNpJuT.d.ts → browser-C9T74n4c.d.ts} +302 -95
- package/dist/browser-tool-DOqT1oSD.js +360 -0
- package/dist/browser-tool-DOqT1oSD.js.map +1 -0
- package/dist/{browser-tool-BhjCcNVE.d.ts → browser-tool-DxAYQY9T.d.ts} +2 -2
- package/dist/capability-DBAKc6UZ.js.map +1 -1
- package/dist/{capability-runner-BiVUtjqC.d.ts → capability-runner-uFOdSANC.d.ts} +3 -2
- package/dist/chat/index.d.ts +37 -6
- package/dist/chat/index.js +39 -3
- package/dist/chat/index.js.map +1 -1
- package/dist/chat/react.js +1 -0
- package/dist/chat/react.js.map +1 -1
- package/dist/chat-sdk/index.d.ts +3 -3
- package/dist/chat-sdk/index.js +1 -1
- package/dist/cli.js +62 -60
- package/dist/client-CkT8voRY.js +3740 -0
- package/dist/client-CkT8voRY.js.map +1 -0
- package/dist/{client-eSfgYvd3.d.ts → client-DqS6oequ.d.ts} +2 -2
- package/dist/client.d.ts +1 -1
- package/dist/{connector-CM-uuxKM.js → connector-Bphz6wIw.js} +414 -3
- package/dist/connector-Bphz6wIw.js.map +1 -0
- package/dist/{conversations-FjHDRZyD.d.ts → conversations-CoAYNW_q.d.ts} +4 -4
- package/dist/{current-agent-CKgT5d1O.d.ts → current-agent-DShbQHDO.d.ts} +24 -3
- package/dist/current-agent-DhoDkSnH.js.map +1 -1
- package/dist/{do-oauth-client-provider-DtNqv7oj.d.ts → do-oauth-client-provider-BsT8-vtd.d.ts} +22 -2
- package/dist/{durable-object-lifecycle-DOI_bzCH.d.ts → durable-object-lifecycle-CRCA6O0W.d.ts} +2 -2
- package/dist/experimental/channels/index.d.ts +2 -2
- package/dist/experimental/channels/web/index.d.ts +2 -2
- package/dist/experimental/channels/web/index.js +1 -1
- package/dist/{gateway-BFO6vRDn.d.ts → gateway-Dz8zyZBJ.d.ts} +2 -2
- package/dist/harness/ai-sdk/index.d.ts +2 -2
- package/dist/harness/container/index.d.ts +2 -2
- package/dist/harness/container/index.js +1 -1
- package/dist/harness/container/index.js.map +1 -1
- package/dist/harness/opencode/index.d.ts +1 -1
- package/dist/harness/pi/index.d.ts +200 -37
- package/dist/harness/pi/index.js +202 -100
- package/dist/harness/pi/index.js.map +1 -1
- package/dist/harness/think/index.d.ts +2 -2
- package/dist/{images-CfuRCjwq.js → images-D4gtE06D.js} +119 -27
- package/dist/images-D4gtE06D.js.map +1 -0
- package/dist/{index-8k4qsX1T.d.ts → index-BXVgv6tp.d.ts} +4 -4
- package/dist/{index-BEL3ZV-s.d.ts → index-Cs7Ed9la.d.ts} +2 -2
- package/dist/{index-CBt8oRJt.d.ts → index-XiZxauMU.d.ts} +3 -3
- package/dist/index.d.ts +21 -21
- package/dist/index.js +2 -2
- package/dist/{input-schema-BQykTEp_.js → input-schema-D6GilRXI.js} +3 -3
- package/dist/input-schema-D6GilRXI.js.map +1 -0
- package/dist/{input-schema-B0Etuo-o.js → input-schema-y8W5bOdM.js} +3 -3
- package/dist/input-schema-y8W5bOdM.js.map +1 -0
- package/dist/internal_context.d.ts +1 -1
- package/dist/lifecycle/index.d.ts +3 -3
- package/dist/lifecycle/index.js +1 -1
- package/dist/{lifecycle-v1rKHV2C.js → lifecycle-CB5Dmtrt.js} +126 -38
- package/dist/lifecycle-CB5Dmtrt.js.map +1 -0
- package/dist/mcp/client/do-oauth-client-provider.d.ts +1 -1
- package/dist/mcp/client/do-oauth-client-provider.js +45 -2
- package/dist/mcp/client/do-oauth-client-provider.js.map +1 -1
- package/dist/mcp/client/index.d.ts +42 -36
- package/dist/mcp/client/index.js +2 -2
- package/dist/mcp/index.d.ts +16 -16
- package/dist/mcp/index.js +2 -2
- package/dist/models/ai-sdk/index.d.ts +9 -5
- package/dist/models/ai-sdk/index.js +1 -1
- package/dist/models/opencode/index.d.ts +3 -3
- package/dist/models/opencode/index.js +2 -2
- package/dist/models/opencode/index.js.map +1 -1
- package/dist/models/pi-ai/index.d.ts +4 -4
- package/dist/models/pi-ai/index.js +64 -170
- package/dist/models/pi-ai/index.js.map +1 -1
- package/dist/{options-CiIsJHXR.d.ts → options-CiXaymmZ.d.ts} +2 -2
- package/dist/queue/index.d.ts +1 -1
- package/dist/queue/index.js +1 -1
- package/dist/{queue-CcIjVYTE.js → queue-B_wl6K0Z.js} +24 -5
- package/dist/queue-B_wl6K0Z.js.map +1 -0
- package/dist/react.d.ts +2 -2
- package/dist/routing/index.d.ts +2 -2
- package/dist/{scheduler-BCLESHSC.d.ts → scheduler-CTpR0Ct0.d.ts} +2 -2
- package/dist/{scheduler-FIHv2-kJ.js → scheduler-DGNEmxQR.js} +2 -1
- package/dist/scheduler-DGNEmxQR.js.map +1 -0
- package/dist/schedules/index.d.ts +1 -1
- package/dist/schedules/index.js +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/{session-7CDgVE0z.js → session-CRY0bGiI.js} +423 -411
- package/dist/session-CRY0bGiI.js.map +1 -0
- package/dist/sessions/index.d.ts +1 -1
- package/dist/{settings-Dk2il2Hf.js → settings-D2F_qONv.js} +11 -2
- package/dist/settings-D2F_qONv.js.map +1 -0
- package/dist/{src-DoGNJ4Ud.js → src-BO1FdLK1.js} +145 -86
- package/dist/src-BO1FdLK1.js.map +1 -0
- package/dist/state/index.d.ts +1 -1
- package/dist/streams/index.d.ts +1 -1
- package/dist/{streams-vrCtbUIn.d.ts → streams-CAZxZBDg.d.ts} +2 -2
- package/dist/sub-routing.d.ts +12 -12
- package/dist/tasks/index.d.ts +1 -1
- package/dist/tasks/index.js +1 -1
- package/dist/{tasks-BN_5AWqI.js → tasks-Cf_UfEO4.js} +2 -1
- package/dist/{tasks-BN_5AWqI.js.map → tasks-Cf_UfEO4.js.map} +1 -1
- package/dist/{tasks-E89KdwkS.d.ts → tasks-Cs8ilctE.d.ts} +2 -2
- package/dist/{tool-DkT_DJBm.js → tool-CmAGY6Fo.js} +24 -3
- package/dist/tool-CmAGY6Fo.js.map +1 -0
- package/dist/{tool-CxKsvxjm.js → tool-Kxcj8_22.js} +24 -4
- package/dist/tool-Kxcj8_22.js.map +1 -0
- package/dist/{tool-helpers-BI7ifO2S.js → tool-helpers-F3_Wy2YX.js} +2 -2
- package/dist/{tool-helpers-BI7ifO2S.js.map → tool-helpers-F3_Wy2YX.js.map} +1 -1
- package/dist/{transport-5moD2pW5.d.ts → transport-hV8AW4Bv.d.ts} +45 -12
- package/dist/voice/index.d.ts +2 -2
- package/dist/web/fetch/index.js +1 -1
- package/dist/web/fetch/tools/ai-sdk.js +2 -2
- package/dist/web/fetch/tools/pi.d.ts +9 -7
- package/dist/web/fetch/tools/pi.js +31 -7
- package/dist/web/fetch/tools/pi.js.map +1 -1
- package/dist/web/fetch/tools/tanstack-ai.js +2 -2
- package/dist/web/search/index.js +1 -1
- package/dist/web/search/tools/ai-sdk.js +2 -2
- package/dist/web/search/tools/pi.d.ts +9 -4
- package/dist/web/search/tools/pi.js +27 -11
- package/dist/web/search/tools/pi.js.map +1 -1
- package/dist/web/search/tools/tanstack-ai.js +2 -2
- package/dist/websockets/index.d.ts +2 -2
- package/dist/websockets/index.js +1 -1
- package/dist/{websockets-C6SJtWCJ.js → websockets-W4uhRg4-.js} +68 -5
- package/dist/websockets-W4uhRg4-.js.map +1 -0
- package/dist/workflow-types.d.ts +1 -1
- package/dist/workflows.d.ts +1 -1
- package/docs/agent-class.md +30 -4
- package/docs/browse-the-web.md +50 -3
- package/docs/chat-agents.md +13 -10
- package/docs/client-tools-continuation.md +1 -1
- package/docs/codemode.md +1 -1
- package/docs/configuration.md +6 -3
- package/docs/cross-domain-authentication.md +1 -1
- package/docs/fetch-the-web.md +20 -0
- package/docs/harnesses/pi.md +242 -33
- package/docs/harnesses/think.md +1 -1
- package/docs/http-websockets.md +40 -32
- package/docs/human-in-the-loop.md +2 -2
- package/docs/lifecycle.md +56 -0
- package/docs/mcp-client.md +104 -7
- package/docs/models-pi-ai.md +24 -10
- package/docs/models.md +42 -17
- package/docs/resumable-streaming.md +1 -1
- package/docs/retries.md +3 -6
- package/docs/search-the-web.md +10 -0
- package/docs/voice.md +1 -1
- package/package.json +16 -9
- package/dist/ai-sdk-Kon40i0q.js.map +0 -1
- package/dist/browser-1eUbPvC2.js +0 -931
- package/dist/browser-1eUbPvC2.js.map +0 -1
- package/dist/browser-tool-DRan7Lk6.js +0 -497
- package/dist/browser-tool-DRan7Lk6.js.map +0 -1
- package/dist/client-DMWujQJ1.js +0 -2325
- package/dist/client-DMWujQJ1.js.map +0 -1
- package/dist/connector-CM-uuxKM.js.map +0 -1
- package/dist/images-CfuRCjwq.js.map +0 -1
- package/dist/input-schema-B0Etuo-o.js.map +0 -1
- package/dist/input-schema-BQykTEp_.js.map +0 -1
- package/dist/lifecycle-v1rKHV2C.js.map +0 -1
- package/dist/queue-CcIjVYTE.js.map +0 -1
- package/dist/scheduler-FIHv2-kJ.js.map +0 -1
- package/dist/session-7CDgVE0z.js.map +0 -1
- package/dist/settings-Dk2il2Hf.js.map +0 -1
- package/dist/src-DoGNJ4Ud.js.map +0 -1
- package/dist/tool-CxKsvxjm.js.map +0 -1
- package/dist/tool-DkT_DJBm.js.map +0 -1
- package/dist/websockets-C6SJtWCJ.js.map +0 -1
package/dist/browser/index.js
CHANGED
|
@@ -1,5 +1,938 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldSet2, r as _assertClassBrand, t as _classPrivateFieldGet2 } from "../classPrivateFieldGet2-DZBYAB34.js";
|
|
2
|
+
import { t as _classPrivateMethodInitSpec } from "../classPrivateMethodInitSpec-qMjJ6sHQ.js";
|
|
3
|
+
import { t as LifecycleCapability } from "../capability-DBAKc6UZ.js";
|
|
4
|
+
import { t as browserCapabilityId } from "../capability-id-B3J8Nok_.js";
|
|
5
|
+
import { a as conversationScope, c as CdpConnection, d as connectUrl, i as DEFAULT_BROWSER_SCOPE, n as BrowserSession, o as browserFunctionDocs, t as ACTIVE_PAGE_SESSION, u as CdpSession } from "../session-CRY0bGiI.js";
|
|
6
|
+
import { C as deleteBrowserSession, E as listBrowserTargets, S as createBrowserSession, T as isMissingBrowserSession, _ as BrowserRenderingError, a as loadCdpSpec, b as connectBrowser, c as browserContent, d as browserMarkdown, f as browserPdf, g as runQuickAction, h as browserSnapshot, i as DurableBrowserSessionStore, l as browserExtract, m as browserScreenshot, n as DEFAULT_EXEC_SWEEP_IDLE_MS, o as normalizeCdpSpec, p as browserScrape, r as DEFAULT_SWEEP_IDLE_MS, s as createLiveView, t as BrowserConnector, u as browserLinks, v as acquireBrowserSession, w as getBrowserRecording, x as connectBrowserSession, y as closeBrowserSession } from "../connector-Bphz6wIw.js";
|
|
7
|
+
import { WorkerEntrypoint } from "cloudflare:workers";
|
|
4
8
|
import { CodemodeRuntime } from "@cloudflare/codemode";
|
|
5
|
-
|
|
9
|
+
import { Validator } from "@cfworker/json-schema";
|
|
10
|
+
//#region src/browser/internal-hosts.ts
|
|
11
|
+
/**
|
|
12
|
+
* Internal hostnames: sites only this agent's browser can open.
|
|
13
|
+
*
|
|
14
|
+
* A host maps a hostname such as `preview.internal` to code in your agent
|
|
15
|
+
* (`fetch`) or to a deployed Worker (`worker`). Browser Run sends the
|
|
16
|
+
* browser's requests for that hostname to it instead of the internet, so a
|
|
17
|
+
* page can be served from a sandbox port or a workspace folder, without exposing anything publicly.
|
|
18
|
+
*
|
|
19
|
+
* How a request travels: Browser Run accepts only entrypoints of your own
|
|
20
|
+
* Worker as routes, and keeps them for the whole browser session (observed
|
|
21
|
+
* across redeploys and Durable Object eviction; Browser Run doesn't document
|
|
22
|
+
* this yet). So every `fetch` host routes to {@link InternalHostRouter}, which
|
|
23
|
+
* you export from your main module. Its props say which agent and browser
|
|
24
|
+
* own the host, and nothing else. It calls the agent's `fetchInternalHost()`
|
|
25
|
+
* over RPC, and the agent's `Browser` runs the host's `fetch`. `Agent` has
|
|
26
|
+
* that method built in; a plain Durable Object adds it (see
|
|
27
|
+
* {@link InternalHostMessage}). A `worker` host goes straight to the Worker
|
|
28
|
+
* you gave it.
|
|
29
|
+
*/
|
|
30
|
+
/** The most hostnames one browser can have. A Browser Run limit. */
|
|
31
|
+
const MAX_INTERNAL_HOSTS = 8;
|
|
32
|
+
const HOSTNAME = /^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/;
|
|
33
|
+
/**
|
|
34
|
+
* Suffixes reserved so they never resolve on the internet. A real domain
|
|
35
|
+
* would be served by the host over http but reach the real site over https
|
|
36
|
+
* (and Chrome tries https first), so internal hostnames must use one.
|
|
37
|
+
* Single labels like `preview` would work, but Browser Run doesn't route
|
|
38
|
+
* labels that are real TLDs (`docs`, `app`) and gives no error for them, so
|
|
39
|
+
* they're rejected rather than checked against a TLD list.
|
|
40
|
+
*/
|
|
41
|
+
const RESERVED_SUFFIXES = [
|
|
42
|
+
".internal",
|
|
43
|
+
".test",
|
|
44
|
+
".example",
|
|
45
|
+
".invalid"
|
|
46
|
+
];
|
|
47
|
+
/** Why `host` can't be an internal hostname, or undefined when it can. */
|
|
48
|
+
function hostnameProblem(host) {
|
|
49
|
+
if (host.includes("://")) return "drop the scheme";
|
|
50
|
+
if (host.includes("/")) return "drop the path";
|
|
51
|
+
if (host.includes(":")) return "drop the port (only port 80 is routed)";
|
|
52
|
+
if (host !== host.toLowerCase()) return "use lowercase";
|
|
53
|
+
if (/^\d+(\.\d+){3}$/.test(host)) return "use a name, not an IP address";
|
|
54
|
+
if (host === "localhost" || host.endsWith(".localhost")) return "Chrome sends localhost to the browser's own machine";
|
|
55
|
+
if (!HOSTNAME.test(host)) return "not a valid hostname";
|
|
56
|
+
if (!RESERVED_SUFFIXES.some((suffix) => host.endsWith(suffix))) return `use a name that can't be a real site: end it in ${RESERVED_SUFFIXES.join(", ")}`;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Check `internalHosts` when the provider is created, so a mistake fails at
|
|
60
|
+
* startup instead of at the first browser launch.
|
|
61
|
+
*/
|
|
62
|
+
function validateInternalHosts(options) {
|
|
63
|
+
const hosts = Object.entries(options.hosts);
|
|
64
|
+
if (hosts.length === 0) throw new Error("internalHosts.hosts needs at least one hostname");
|
|
65
|
+
if (hosts.length > 8) throw new Error(`internalHosts has ${hosts.length} hostnames; Browser Run allows at most 8 per browser`);
|
|
66
|
+
for (const [host, config] of hosts) {
|
|
67
|
+
const problem = hostnameProblem(host);
|
|
68
|
+
if (problem) throw new Error(`Internal hostname "${host}": ${problem}`);
|
|
69
|
+
const hasFetch = typeof config.fetch === "function";
|
|
70
|
+
const hasWorker = config.worker !== void 0;
|
|
71
|
+
if (hasFetch === hasWorker) throw new Error(`Internal hostname "${host}" needs exactly one of fetch or worker`);
|
|
72
|
+
if (hasWorker && config.target !== void 0) throw new Error(`Internal hostname "${host}": target needs fetch; a worker host can't be assigned`);
|
|
73
|
+
if (hasFetch && typeof options.router !== "function") throw new Error(`Internal hostname "${host}" uses fetch, which needs internalHosts.router: this.ctx.exports.InternalHostRouter (and \`export { InternalHostRouter } from "agents/browser"\` in your main module)`);
|
|
74
|
+
if (config.target !== void 0) targetJsonSchema(host, config.target);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Identifies the set of hostnames and how each is routed. A browser started
|
|
79
|
+
* with a different set is replaced: Browser Run fixes routes at launch.
|
|
80
|
+
*/
|
|
81
|
+
function internalHostsSignature(options) {
|
|
82
|
+
if (!options) return void 0;
|
|
83
|
+
return Object.entries(options.hosts).map(([host, config]) => `${host}=${config.worker ? "worker" : "fetch"}`).sort().join(",");
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The route Browser Run gets for a `worker` host. A `ctx.exports`
|
|
87
|
+
* entrypoint is a loopback stub that Browser Run can't take as is, so it's
|
|
88
|
+
* called (with empty props) to get a Fetcher it can.
|
|
89
|
+
*/
|
|
90
|
+
function workerRoute(worker) {
|
|
91
|
+
if (typeof worker !== "function") return worker;
|
|
92
|
+
return worker({ props: {} });
|
|
93
|
+
}
|
|
94
|
+
function isStandardSchema(schema) {
|
|
95
|
+
return typeof schema === "object" && schema !== null && "~standard" in schema;
|
|
96
|
+
}
|
|
97
|
+
/** A host's target schema as JSON Schema, for the model and for plain validation. */
|
|
98
|
+
function targetJsonSchema(host, schema) {
|
|
99
|
+
if (!isStandardSchema(schema)) {
|
|
100
|
+
if (typeof schema !== "object" || schema === null) throw new Error(`Internal hostname "${host}": target must be a schema`);
|
|
101
|
+
return schema;
|
|
102
|
+
}
|
|
103
|
+
const { jsonSchema } = schema["~standard"];
|
|
104
|
+
if (!jsonSchema?.input) throw new Error(`Internal hostname "${host}": target needs a schema that can describe itself as JSON Schema (Standard JSON Schema, such as zod 4.2+), or a plain JSON Schema object`);
|
|
105
|
+
try {
|
|
106
|
+
return jsonSchema.input({ target: "draft-07" });
|
|
107
|
+
} catch {
|
|
108
|
+
return jsonSchema.input({ target: "draft-2020-12" });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const plainValidators = /* @__PURE__ */ new WeakMap();
|
|
112
|
+
function formatIssues(issues) {
|
|
113
|
+
return issues.map((issue) => issue.path ? `${issue.path}: ${issue.message}` : issue.message).join("; ");
|
|
114
|
+
}
|
|
115
|
+
function pathString(path) {
|
|
116
|
+
if (!path?.length) return void 0;
|
|
117
|
+
return path.map((part) => String(typeof part === "object" ? part.key : part)).join(".");
|
|
118
|
+
}
|
|
119
|
+
function plainIssues(errors) {
|
|
120
|
+
const specific = errors.filter((error) => error.keyword !== "properties");
|
|
121
|
+
return (specific.length > 0 ? specific : errors).map((error) => ({
|
|
122
|
+
message: error.error,
|
|
123
|
+
path: error.instanceLocation.replace(/^#\/?/, "").replaceAll("/", ".") || void 0
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Validate a target against a host's schema. Returns the validated value
|
|
128
|
+
* (a Standard Schema's output, which may differ from its input), or a
|
|
129
|
+
* message saying what's wrong.
|
|
130
|
+
*/
|
|
131
|
+
async function validateTarget(schema, value) {
|
|
132
|
+
if (isStandardSchema(schema)) {
|
|
133
|
+
const result = await schema["~standard"].validate(value);
|
|
134
|
+
if (result.issues) return {
|
|
135
|
+
ok: false,
|
|
136
|
+
error: formatIssues(result.issues.map((issue) => ({
|
|
137
|
+
message: issue.message,
|
|
138
|
+
path: pathString(issue.path)
|
|
139
|
+
})))
|
|
140
|
+
};
|
|
141
|
+
return {
|
|
142
|
+
ok: true,
|
|
143
|
+
value: result.value
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
let validator = plainValidators.get(schema);
|
|
147
|
+
if (!validator) {
|
|
148
|
+
validator = new Validator(schema, "7", false);
|
|
149
|
+
plainValidators.set(schema, validator);
|
|
150
|
+
}
|
|
151
|
+
const result = validator.validate(value);
|
|
152
|
+
return result.valid ? {
|
|
153
|
+
ok: true,
|
|
154
|
+
value
|
|
155
|
+
} : {
|
|
156
|
+
ok: false,
|
|
157
|
+
error: formatIssues(plainIssues(result.errors))
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function isInternalHostMessage(value) {
|
|
161
|
+
if (typeof value !== "object" || value === null) return false;
|
|
162
|
+
const message = value;
|
|
163
|
+
return typeof message.browser === "string" && typeof message.host === "string" && message.request instanceof Request;
|
|
164
|
+
}
|
|
165
|
+
/** A plain-text response the browser shows for a failed internal request. */
|
|
166
|
+
function internalHostError(status, message) {
|
|
167
|
+
return new Response(message, {
|
|
168
|
+
status,
|
|
169
|
+
headers: { "content-type": "text/plain; charset=utf-8" }
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Whether an RPC call failed because the agent has no `fetchInternalHost()`.
|
|
174
|
+
* workerd says: `The RPC receiver does not implement the method
|
|
175
|
+
* "fetchInternalHost".` If that wording changes, the router falls back to its
|
|
176
|
+
* generic 502, which names the method too.
|
|
177
|
+
*/
|
|
178
|
+
function isMissingMethod(error) {
|
|
179
|
+
return error instanceof Error && error.message.includes("fetchInternalHost") && /does not implement|is not a function/.test(error.message);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Carries a browser's requests for an internal hostname to the agent that
|
|
183
|
+
* owns it. Export it from your Worker's main module, so
|
|
184
|
+
* `this.ctx.exports.InternalHostRouter` exists:
|
|
185
|
+
*
|
|
186
|
+
* ```ts
|
|
187
|
+
* export { InternalHostRouter } from "agents/browser";
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* It trusts its props: Browser Run sets them from your routes, but another
|
|
191
|
+
* Worker in your account with a service binding to this entrypoint could
|
|
192
|
+
* set its own and reach any agent's hosts. That Worker could already call
|
|
193
|
+
* your agents directly, so this grants nothing new.
|
|
194
|
+
*
|
|
195
|
+
* It holds no logic of its own: it calls the agent's `fetchInternalHost()`
|
|
196
|
+
* with an {@link InternalHostMessage}, and the agent's `Browser` runs the
|
|
197
|
+
* host's `fetch`. `Agent` has `fetchInternalHost()` built in; a plain
|
|
198
|
+
* Durable Object adds it (see {@link InternalHostMessage}).
|
|
199
|
+
*
|
|
200
|
+
* @experimental The API may change before it stabilizes.
|
|
201
|
+
*/
|
|
202
|
+
var InternalHostRouter = class extends WorkerEntrypoint {
|
|
203
|
+
async fetch(request) {
|
|
204
|
+
const props = this.ctx.props;
|
|
205
|
+
if (!isRouterProps(props)) return internalHostError(502, "InternalHostRouter was called without route props. Only Browser Run calls it, with the routes browserRun({ internalHosts }) gives it.");
|
|
206
|
+
const namespace = this.ctx.exports?.[props.className];
|
|
207
|
+
if (!namespace?.getByName) return internalHostError(502, `${props.host}: the agent class "${props.className}" isn't exported from this Worker`);
|
|
208
|
+
try {
|
|
209
|
+
const response = await namespace.getByName(props.name).fetchInternalHost({
|
|
210
|
+
browser: props.browser,
|
|
211
|
+
host: props.host,
|
|
212
|
+
request
|
|
213
|
+
});
|
|
214
|
+
if (response instanceof Response) return response;
|
|
215
|
+
return internalHostError(502, `${props.host}: the agent didn't answer with a Response`);
|
|
216
|
+
} catch (error) {
|
|
217
|
+
if (isMissingMethod(error)) return internalHostError(502, `${props.host}: ${props.className} has no fetchInternalHost() method. Agent has it built in; on a plain Durable Object add: fetchInternalHost(message) { return this.browser.fetchInternalHost(message); }`);
|
|
218
|
+
console.error(`[agents/browser] ${props.className} failed to serve ${props.host}`, error);
|
|
219
|
+
return internalHostError(502, `${props.host}: the agent failed to serve this request`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
function isRouterProps(props) {
|
|
224
|
+
return props?.v === 1 && typeof props.className === "string" && typeof props.name === "string" && typeof props.browser === "string" && typeof props.host === "string";
|
|
225
|
+
}
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region src/browser/providers/provider-adapter.ts
|
|
228
|
+
/**
|
|
229
|
+
* Thrown by {@link BrowserProviderAdapter.connect} when the session no longer
|
|
230
|
+
* exists upstream (closed, expired, or reclaimed). `Browser` treats it as
|
|
231
|
+
* "this browser is lost" and replaces it; any other error is passed on.
|
|
232
|
+
*/
|
|
233
|
+
var BrowserSessionGoneError = class extends Error {
|
|
234
|
+
constructor(sessionId, options) {
|
|
235
|
+
super(`Browser session gone: ${sessionId}`, options);
|
|
236
|
+
this.sessionId = sessionId;
|
|
237
|
+
this.name = "BrowserSessionGoneError";
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* Run the browser on Cloudflare Browser Run.
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```ts
|
|
245
|
+
* new Browser({ provider: browserRun(env.BROWSER, { recording: true }) });
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
function browserRun(binding, options = {}) {
|
|
249
|
+
const erased = options;
|
|
250
|
+
if (erased.internalHosts) validateInternalHosts(erased.internalHosts);
|
|
251
|
+
return {
|
|
252
|
+
kind: "browser-run",
|
|
253
|
+
binding,
|
|
254
|
+
options: erased
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
function isDataCloneError(error) {
|
|
258
|
+
return error instanceof Error && error.name === "DataCloneError";
|
|
259
|
+
}
|
|
260
|
+
/** One `outboundByHost` route per internal hostname. */
|
|
261
|
+
function internalHostRoutes(internalHosts, owner) {
|
|
262
|
+
const routes = {};
|
|
263
|
+
const hosts = Object.entries(internalHosts.hosts);
|
|
264
|
+
for (const [host, config] of hosts) {
|
|
265
|
+
if (config.worker) {
|
|
266
|
+
routes[host] = workerRoute(config.worker);
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
routes[host] = internalHosts.router({ props: {
|
|
270
|
+
v: 1,
|
|
271
|
+
...owner,
|
|
272
|
+
host
|
|
273
|
+
} });
|
|
274
|
+
}
|
|
275
|
+
return routes;
|
|
276
|
+
}
|
|
277
|
+
/** The code behind {@link browserRun}. */
|
|
278
|
+
function browserRunAdapter(provider) {
|
|
279
|
+
const { binding, options } = provider;
|
|
280
|
+
const keepAliveMs = () => options.keepAliveMs ?? 6e5;
|
|
281
|
+
return {
|
|
282
|
+
get keepAliveMs() {
|
|
283
|
+
return keepAliveMs();
|
|
284
|
+
},
|
|
285
|
+
internalHosts: options.internalHosts,
|
|
286
|
+
internalHostsSignature: internalHostsSignature(options.internalHosts),
|
|
287
|
+
async create(context) {
|
|
288
|
+
const { internalHosts } = options;
|
|
289
|
+
if (internalHosts && !context?.owner) throw new Error("Internal hostnames need the Browser installed with Lifecycle.use() on a top-level agent");
|
|
290
|
+
try {
|
|
291
|
+
return await acquireBrowserSession(binding, {
|
|
292
|
+
keepAliveMs: keepAliveMs(),
|
|
293
|
+
recording: options.recording,
|
|
294
|
+
guardrails: options.guardrails,
|
|
295
|
+
...internalHosts && context?.owner ? { outboundByHost: internalHostRoutes(internalHosts, context.owner) } : {}
|
|
296
|
+
});
|
|
297
|
+
} catch (error) {
|
|
298
|
+
if (internalHosts && isDataCloneError(error)) throw new Error("Browser Run couldn't take the internal hostname routes: a worker host must be a service binding or an entrypoint of this Worker (this.ctx.exports.Name), not a Dynamic Worker or another object it can't hold", { cause: error });
|
|
299
|
+
throw error;
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
async isAlive(sessionId) {
|
|
303
|
+
try {
|
|
304
|
+
await listBrowserTargets(binding, sessionId);
|
|
305
|
+
return true;
|
|
306
|
+
} catch (error) {
|
|
307
|
+
if (isMissingBrowserSession(error)) return false;
|
|
308
|
+
throw error;
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
async connect(sessionId, connectOptions) {
|
|
312
|
+
try {
|
|
313
|
+
return await connectBrowserSession(binding, sessionId, connectOptions);
|
|
314
|
+
} catch (error) {
|
|
315
|
+
if (isMissingBrowserSession(error)) throw new BrowserSessionGoneError(sessionId, { cause: error });
|
|
316
|
+
throw error;
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
async close(sessionId) {
|
|
320
|
+
try {
|
|
321
|
+
await closeBrowserSession(binding, sessionId);
|
|
322
|
+
} catch (error) {
|
|
323
|
+
if (!isMissingBrowserSession(error)) throw error;
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
spec(sessionId) {
|
|
327
|
+
return loadCdpSpec({
|
|
328
|
+
browser: binding,
|
|
329
|
+
sessionId
|
|
330
|
+
});
|
|
331
|
+
},
|
|
332
|
+
async liveView(sessionId, mode) {
|
|
333
|
+
try {
|
|
334
|
+
return createLiveView(sessionId, await listBrowserTargets(binding, sessionId), mode);
|
|
335
|
+
} catch (error) {
|
|
336
|
+
if (isMissingBrowserSession(error)) return void 0;
|
|
337
|
+
throw error;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Scope records kept per browser. Writing a new one past the cap deletes the
|
|
344
|
+
* least recently used; a scope that comes back afterwards starts fresh.
|
|
345
|
+
*/
|
|
346
|
+
const MAX_BROWSER_SCOPES = 100;
|
|
347
|
+
const NAMED_SESSION_KEY_PREFIX = "browser:session:";
|
|
348
|
+
/** The store key holding the named browser's current record. */
|
|
349
|
+
function namedBrowserSessionKey(name) {
|
|
350
|
+
return `${NAMED_SESSION_KEY_PREFIX}${name}`;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Where a closed or lost browser's record moves: permanent evidence that the
|
|
354
|
+
* name once owned a browser, so a later resolve reports `restarted: true`.
|
|
355
|
+
* Kept outside {@link NAMED_SESSION_KEY_PREFIX} so listing that prefix
|
|
356
|
+
* yields only names that currently own a browser. Grows with the number of
|
|
357
|
+
* distinct names the host has ever used.
|
|
358
|
+
*/
|
|
359
|
+
const RETIRED_SESSION_KEY_PREFIX = "browser:retired:";
|
|
360
|
+
function retiredBrowserSessionKey(name) {
|
|
361
|
+
return `${RETIRED_SESSION_KEY_PREFIX}${name}`;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Where a browser's scope records live. The name's length is part of the
|
|
365
|
+
* prefix, so one browser's prefix never matches another name's (`a` with
|
|
366
|
+
* scope `b:c` vs. `a:b` with scope `c`).
|
|
367
|
+
*/
|
|
368
|
+
function browserScopeKeyPrefix(name) {
|
|
369
|
+
return `browser:scope:${name.length}:${name}:`;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Where a browser's internal-host targets live: one key per host, under a
|
|
373
|
+
* prefix per browser (length-prefixed like scope records, so one browser's
|
|
374
|
+
* prefix never matches another's). Kept apart from the session record, so
|
|
375
|
+
* targets survive the browser being replaced.
|
|
376
|
+
*/
|
|
377
|
+
function internalHostTargetsPrefix(name) {
|
|
378
|
+
return `browser:hosts:${name.length}:${name}:`;
|
|
379
|
+
}
|
|
380
|
+
/** The adapter behind a provider: one explicit case per provider kind. */
|
|
381
|
+
function providerAdapterFor(provider) {
|
|
382
|
+
switch (provider.kind) {
|
|
383
|
+
case "browser-run": return browserRunAdapter(provider);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
var _options = /* @__PURE__ */ new WeakMap();
|
|
387
|
+
var _key = /* @__PURE__ */ new WeakMap();
|
|
388
|
+
var _adapter = /* @__PURE__ */ new WeakMap();
|
|
389
|
+
var _store = /* @__PURE__ */ new WeakMap();
|
|
390
|
+
var _Browser_brand = /* @__PURE__ */ new WeakSet();
|
|
391
|
+
/**
|
|
392
|
+
* One named, persistent browser.
|
|
393
|
+
*
|
|
394
|
+
* Install it with `Lifecycle.use()` — on an Agent subclass or any Durable
|
|
395
|
+
* Object that composes `Lifecycle` — and it stores its record in the
|
|
396
|
+
* object's own storage. It schedules nothing: the provider reclaims idle
|
|
397
|
+
* browsers itself (Browser Run once `keep_alive` elapses), and the next use
|
|
398
|
+
* replaces the lost browser with `restarted: true`.
|
|
399
|
+
*
|
|
400
|
+
* Everything here is host-side. Models never see browser names, provider
|
|
401
|
+
* session ids, or Live View URLs through this surface.
|
|
402
|
+
*
|
|
403
|
+
* Store discipline: locks wrap storage operations only — liveness probes and
|
|
404
|
+
* provider create/close calls always happen outside any lock, with a commit
|
|
405
|
+
* re-check to detect concurrent swaps.
|
|
406
|
+
*
|
|
407
|
+
* @experimental The API surface may change before stabilizing.
|
|
408
|
+
*/
|
|
409
|
+
var Browser = class extends LifecycleCapability {
|
|
410
|
+
constructor(options) {
|
|
411
|
+
const name = options.name ?? "default";
|
|
412
|
+
super(browserCapabilityId(name));
|
|
413
|
+
_classPrivateMethodInitSpec(this, _Browser_brand);
|
|
414
|
+
_classPrivateFieldInitSpec(this, _options, void 0);
|
|
415
|
+
_classPrivateFieldInitSpec(this, _key, void 0);
|
|
416
|
+
_classPrivateFieldInitSpec(this, _adapter, void 0);
|
|
417
|
+
_classPrivateFieldInitSpec(this, _store, void 0);
|
|
418
|
+
if (name.trim() === "") throw new Error("Browser names must be non-empty");
|
|
419
|
+
this.name = name;
|
|
420
|
+
_classPrivateFieldSet2(_options, this, options);
|
|
421
|
+
_classPrivateFieldSet2(_key, this, namedBrowserSessionKey(name));
|
|
422
|
+
_classPrivateFieldSet2(_adapter, this, providerAdapterFor(options.provider));
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Reattach to the browser when it is still alive, otherwise create a fresh
|
|
426
|
+
* one. See {@link ResolvedBrowser.restarted} for the mortality signal.
|
|
427
|
+
*/
|
|
428
|
+
async resolve() {
|
|
429
|
+
const { name } = this;
|
|
430
|
+
const key = _classPrivateFieldGet2(_key, this);
|
|
431
|
+
for (let attempt = 0; attempt < 4; attempt++) {
|
|
432
|
+
const existing = await _assertClassBrand(_Browser_brand, this, _readStored).call(this);
|
|
433
|
+
if (existing === void 0) {
|
|
434
|
+
const { session, restarted } = await _assertClassBrand(_Browser_brand, this, _createAndCommit).call(this);
|
|
435
|
+
return {
|
|
436
|
+
name,
|
|
437
|
+
restarted,
|
|
438
|
+
...resolvedFields(session)
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
const routesMatch = existing.internalHosts === _classPrivateFieldGet2(_adapter, this).internalHostsSignature;
|
|
442
|
+
const alive = routesMatch && await _classPrivateFieldGet2(_adapter, this).isAlive(existing.sessionId);
|
|
443
|
+
const lock = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).acquireLock(key);
|
|
444
|
+
try {
|
|
445
|
+
const current = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).get(key);
|
|
446
|
+
if (current?.sessionId !== existing.sessionId) continue;
|
|
447
|
+
if (alive) {
|
|
448
|
+
const refreshed = {
|
|
449
|
+
...current,
|
|
450
|
+
updatedAt: Date.now()
|
|
451
|
+
};
|
|
452
|
+
await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).set(key, refreshed);
|
|
453
|
+
return {
|
|
454
|
+
name,
|
|
455
|
+
restarted: false,
|
|
456
|
+
...resolvedFields(refreshed)
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
await _assertClassBrand(_Browser_brand, this, _retire).call(this, current);
|
|
460
|
+
} finally {
|
|
461
|
+
await lock.release();
|
|
462
|
+
}
|
|
463
|
+
if (!routesMatch) await _assertClassBrand(_Browser_brand, this, _closeQuietly).call(this, existing.sessionId);
|
|
464
|
+
}
|
|
465
|
+
throw new Error(`Browser "${name}" kept changing concurrently — retry`);
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Resolve the browser and open a CDP connection to it for one scope (see
|
|
469
|
+
* {@link BrowserConnectOptions.scope}). Commands sent over the connection
|
|
470
|
+
* refresh the record's `updatedAt` (throttled to
|
|
471
|
+
* {@link SESSION_TOUCH_INTERVAL_MS}), so hosts can tell an actively used
|
|
472
|
+
* browser from one the platform has likely reclaimed.
|
|
473
|
+
*
|
|
474
|
+
* If the browser expires between the liveness probe and the WebSocket
|
|
475
|
+
* upgrade, the record is retired and the browser resolved once more, so
|
|
476
|
+
* the caller gets a fresh browser instead of an error.
|
|
477
|
+
*/
|
|
478
|
+
async connect(options = {}) {
|
|
479
|
+
const scope = options.scope ?? "shared";
|
|
480
|
+
if (scope.trim() === "") throw new Error("Browser scopes must be non-empty");
|
|
481
|
+
let resolved = await this.resolve();
|
|
482
|
+
let cdp;
|
|
483
|
+
try {
|
|
484
|
+
cdp = await _assertClassBrand(_Browser_brand, this, _open).call(this, resolved);
|
|
485
|
+
} catch (error) {
|
|
486
|
+
if (!(error instanceof BrowserSessionGoneError)) throw error;
|
|
487
|
+
await _assertClassBrand(_Browser_brand, this, _retireIfCurrent).call(this, resolved.sessionId);
|
|
488
|
+
resolved = await this.resolve();
|
|
489
|
+
cdp = await _assertClassBrand(_Browser_brand, this, _open).call(this, resolved);
|
|
490
|
+
}
|
|
491
|
+
try {
|
|
492
|
+
const entered = await _assertClassBrand(_Browser_brand, this, _enterScope).call(this, scope, resolved.sessionId);
|
|
493
|
+
return _assertClassBrand(_Browser_brand, this, _connection).call(this, resolved, scope, cdp, entered);
|
|
494
|
+
} catch (error) {
|
|
495
|
+
cdp.disconnect();
|
|
496
|
+
throw error;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Start a session on this browser for one run: connects on its first
|
|
501
|
+
* call, resolves `sessionId: "active"` to the scope's tab, and reports
|
|
502
|
+
* what happened to the browser when you close it. `browserTool` opens
|
|
503
|
+
* one per run.
|
|
504
|
+
*/
|
|
505
|
+
session(options) {
|
|
506
|
+
return new BrowserSession(this, options);
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* What the model needs to know to use this browser's `browser.*`
|
|
510
|
+
* functions ({@link BrowserSession.functions}): the functions in Markdown,
|
|
511
|
+
* including the internal sites and hosts functions this browser has, and
|
|
512
|
+
* the rules for using them. For a tool or module description; add rules
|
|
513
|
+
* about how your code runs (timeouts, screenshots) yourself.
|
|
514
|
+
*/
|
|
515
|
+
functionDocs() {
|
|
516
|
+
return browserFunctionDocs(this.internalHosts);
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Close the browser: retire the record (so the next resolve reports
|
|
520
|
+
* `restarted: true`) and close its provider session. Returns `false` when
|
|
521
|
+
* there was nothing to close.
|
|
522
|
+
*
|
|
523
|
+
* The provider close is best-effort: the retired record is the durable
|
|
524
|
+
* outcome, and a browser whose close failed is unreachable through this
|
|
525
|
+
* store, so the provider reclaims it once idle (Browser Run: after
|
|
526
|
+
* `keepAliveMs`, at most 20 minutes).
|
|
527
|
+
*/
|
|
528
|
+
async close() {
|
|
529
|
+
let stored;
|
|
530
|
+
const lock = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).acquireLock(_classPrivateFieldGet2(_key, this));
|
|
531
|
+
try {
|
|
532
|
+
const current = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).get(_classPrivateFieldGet2(_key, this));
|
|
533
|
+
if (!current) return false;
|
|
534
|
+
stored = current;
|
|
535
|
+
await _assertClassBrand(_Browser_brand, this, _retire).call(this, current);
|
|
536
|
+
} finally {
|
|
537
|
+
await lock.release();
|
|
538
|
+
}
|
|
539
|
+
try {
|
|
540
|
+
await _classPrivateFieldGet2(_adapter, this).close(stored.sessionId);
|
|
541
|
+
} catch (error) {
|
|
542
|
+
console.warn(`[agents/browser] Failed to close browser session ${stored.sessionId}`, error);
|
|
543
|
+
}
|
|
544
|
+
return true;
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Mint Live View URLs for the browser's open tabs, fresh from a target
|
|
548
|
+
* listing. `undefined` when the browser was never created, is closed, or
|
|
549
|
+
* is gone. The URLs are bearer credentials with a short connect window
|
|
550
|
+
* (~5 min) — hand them to a trusted human, never to the model, and never
|
|
551
|
+
* store them: re-mint instead.
|
|
552
|
+
*/
|
|
553
|
+
async liveView(options) {
|
|
554
|
+
const entry = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).get(_classPrivateFieldGet2(_key, this));
|
|
555
|
+
if (!entry) return void 0;
|
|
556
|
+
const view = await _classPrivateFieldGet2(_adapter, this).liveView(entry.sessionId, options?.mode);
|
|
557
|
+
if (!view) return void 0;
|
|
558
|
+
try {
|
|
559
|
+
if (!await _assertClassBrand(_Browser_brand, this, _touch).call(this, entry.sessionId)) return void 0;
|
|
560
|
+
} catch (error) {
|
|
561
|
+
console.warn(`[agents/browser] Failed to refresh activity for browser "${this.name}"`, error);
|
|
562
|
+
}
|
|
563
|
+
return view;
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* The browser's internal hostnames, or `undefined` when its provider has
|
|
567
|
+
* none. See {@link BrowserInternalHosts}.
|
|
568
|
+
*/
|
|
569
|
+
get internalHosts() {
|
|
570
|
+
const config = _classPrivateFieldGet2(_adapter, this).internalHosts;
|
|
571
|
+
if (!config) return void 0;
|
|
572
|
+
const hosts = config.hosts;
|
|
573
|
+
const describe = () => Object.entries(hosts).map(([host, entry]) => ({
|
|
574
|
+
host,
|
|
575
|
+
url: `http://${host}/`,
|
|
576
|
+
...entry.description ? { description: entry.description } : {},
|
|
577
|
+
assignable: entry.target !== void 0,
|
|
578
|
+
...entry.target !== void 0 ? { targetSchema: targetJsonSchema(host, entry.target) } : {}
|
|
579
|
+
}));
|
|
580
|
+
const assignable = (host) => {
|
|
581
|
+
const entry = hosts[host];
|
|
582
|
+
if (!entry || !Object.hasOwn(hosts, host)) throw new Error(`"${host}" isn't an internal hostname. The hostnames are: ${Object.keys(hosts).join(", ")}`);
|
|
583
|
+
if (entry.target === void 0) throw new Error(`"${host}" always serves the same thing; it has no target to assign`);
|
|
584
|
+
return entry.target;
|
|
585
|
+
};
|
|
586
|
+
return {
|
|
587
|
+
describe,
|
|
588
|
+
list: async () => {
|
|
589
|
+
const prefix = internalHostTargetsPrefix(this.name);
|
|
590
|
+
const stored = await this.lifecycle.storage.list({ prefix });
|
|
591
|
+
return describe().map((info) => {
|
|
592
|
+
const key = prefix + info.host;
|
|
593
|
+
return stored.has(key) ? {
|
|
594
|
+
...info,
|
|
595
|
+
target: stored.get(key)
|
|
596
|
+
} : info;
|
|
597
|
+
});
|
|
598
|
+
},
|
|
599
|
+
assign: async (host, target) => {
|
|
600
|
+
const schema = assignable(host);
|
|
601
|
+
if (target === void 0) throw new Error(`browser.assignHost needs a target for ${host}; use browser.clearHost to unassign it`);
|
|
602
|
+
const json = JSON.parse(JSON.stringify(target));
|
|
603
|
+
const checked = await validateTarget(schema, json);
|
|
604
|
+
if (!checked.ok) throw new Error(`Invalid target for ${host}: ${checked.error}`);
|
|
605
|
+
await this.lifecycle.storage.put(_assertClassBrand(_Browser_brand, this, _targetKey).call(this, host), json);
|
|
606
|
+
return { url: `http://${host}/` };
|
|
607
|
+
},
|
|
608
|
+
clear: async (host) => {
|
|
609
|
+
assignable(host);
|
|
610
|
+
return this.lifecycle.storage.delete(_assertClassBrand(_Browser_brand, this, _targetKey).call(this, host));
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Serve one browser request to an internal hostname. `InternalHostRouter`
|
|
616
|
+
* calls the agent's `fetchInternalHost()` with the message; `Agent` passes
|
|
617
|
+
* it here on its own. A plain Durable Object passes it on itself:
|
|
618
|
+
*
|
|
619
|
+
* ```ts
|
|
620
|
+
* fetchInternalHost(message: InternalHostMessage) {
|
|
621
|
+
* return this.browser.fetchInternalHost(message);
|
|
622
|
+
* }
|
|
623
|
+
* ```
|
|
624
|
+
*
|
|
625
|
+
* Answers 502 with the reason when this browser doesn't serve the host.
|
|
626
|
+
*/
|
|
627
|
+
async fetchInternalHost(message) {
|
|
628
|
+
if (message.browser !== this.name) return internalHostError(502, `${message.host} belongs to browser "${message.browser}", but was passed to browser "${this.name}"`);
|
|
629
|
+
return _assertClassBrand(_Browser_brand, this, _serveInternalHost).call(this, message.host, message.request);
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* `Agent.fetchInternalHost()` routes here through Lifecycle, so `Agent`
|
|
633
|
+
* needn't import the browser.
|
|
634
|
+
*
|
|
635
|
+
* @internal Called by Lifecycle; not part of the host API.
|
|
636
|
+
*/
|
|
637
|
+
async onRoute(context) {
|
|
638
|
+
const { payload } = context;
|
|
639
|
+
if (!isInternalHostMessage(payload)) throw new Error(`Browser "${this.name}" got an unknown routed message`);
|
|
640
|
+
return this.fetchInternalHost(payload);
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
function _connection(resolved, scope, cdp, entered) {
|
|
644
|
+
const { sessionId } = resolved;
|
|
645
|
+
return {
|
|
646
|
+
name: resolved.name,
|
|
647
|
+
sessionId,
|
|
648
|
+
scope,
|
|
649
|
+
restarted: entered.restarted,
|
|
650
|
+
activeTargetId: entered.activeTargetId,
|
|
651
|
+
cdp,
|
|
652
|
+
setActiveTarget: (targetId) => _assertClassBrand(_Browser_brand, this, _updateScope).call(this, scope, sessionId, targetId),
|
|
653
|
+
targetsInOtherScopes: async () => activeTargets(await _assertClassBrand(_Browser_brand, this, _listScopes).call(this), scope, sessionId),
|
|
654
|
+
spec: () => _classPrivateFieldGet2(_adapter, this).spec(sessionId)
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
async function _open(resolved) {
|
|
658
|
+
let lastTouchAt = Date.now();
|
|
659
|
+
let touchInFlight = false;
|
|
660
|
+
return _classPrivateFieldGet2(_adapter, this).connect(resolved.sessionId, {
|
|
661
|
+
timeoutMs: _classPrivateFieldGet2(_options, this).timeoutMs,
|
|
662
|
+
onActivity: () => {
|
|
663
|
+
const now = Date.now();
|
|
664
|
+
if (touchInFlight || now - lastTouchAt < _get_touchIntervalMs.call(_assertClassBrand(_Browser_brand, this))) return;
|
|
665
|
+
touchInFlight = true;
|
|
666
|
+
lastTouchAt = now;
|
|
667
|
+
_assertClassBrand(_Browser_brand, this, _touch).call(this, resolved.sessionId).catch((error) => {
|
|
668
|
+
console.warn(`[agents/browser] Failed to refresh activity for browser "${this.name}"`, error);
|
|
669
|
+
}).finally(() => {
|
|
670
|
+
touchInFlight = false;
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
async function _serveInternalHost(host, request) {
|
|
676
|
+
const hosts = _classPrivateFieldGet2(_adapter, this).internalHosts?.hosts;
|
|
677
|
+
const entry = hosts && Object.hasOwn(hosts, host) ? hosts[host] : void 0;
|
|
678
|
+
if (!entry?.fetch) return internalHostError(502, `${host} is no longer an internal hostname of browser "${this.name}"`);
|
|
679
|
+
let target;
|
|
680
|
+
if (entry.target !== void 0) {
|
|
681
|
+
const assigned = await this.lifecycle.storage.get(_assertClassBrand(_Browser_brand, this, _targetKey).call(this, host));
|
|
682
|
+
if (assigned === void 0) return internalHostError(502, `${host} isn't pointed anywhere yet. Call browser.assignHost({ host: "${host}", target }) first.`);
|
|
683
|
+
const checked = await validateTarget(entry.target, assigned);
|
|
684
|
+
if (!checked.ok) return internalHostError(502, `${host}'s target no longer matches its schema (${checked.error}). Call browser.assignHost again.`);
|
|
685
|
+
target = checked.value;
|
|
686
|
+
}
|
|
687
|
+
const fetch = entry.fetch;
|
|
688
|
+
try {
|
|
689
|
+
const response = await this.lifecycle.runInHostContext(() => fetch(request, target), { request });
|
|
690
|
+
if (response instanceof Response) return response;
|
|
691
|
+
return internalHostError(502, `${host}: its fetch didn't return a Response`);
|
|
692
|
+
} catch (error) {
|
|
693
|
+
console.error(`[agents/browser] ${host}: its fetch threw`, error);
|
|
694
|
+
return internalHostError(502, `${host}: its fetch failed`);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* Which agent and browser the session's routes lead back to. `undefined`
|
|
699
|
+
* without internal hostnames.
|
|
700
|
+
*/
|
|
701
|
+
function _internalHostOwner() {
|
|
702
|
+
if (!_classPrivateFieldGet2(_adapter, this).internalHosts) return void 0;
|
|
703
|
+
const services = this.lifecycleServices;
|
|
704
|
+
if (!services) throw new Error(`Browser "${this.name}" has internal hostnames, which need it installed with Lifecycle.use()`);
|
|
705
|
+
if (services.routes.source !== void 0) throw new Error(`Browser "${this.name}" has internal hostnames, which sub-agents don't support yet`);
|
|
706
|
+
return {
|
|
707
|
+
className: services.className,
|
|
708
|
+
name: services.name,
|
|
709
|
+
browser: this.name
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
/** The storage key of one host's target. */
|
|
713
|
+
function _targetKey(host) {
|
|
714
|
+
return internalHostTargetsPrefix(this.name) + host;
|
|
715
|
+
}
|
|
716
|
+
async function _closeQuietly(sessionId) {
|
|
717
|
+
try {
|
|
718
|
+
await _classPrivateFieldGet2(_adapter, this).close(sessionId);
|
|
719
|
+
} catch (error) {
|
|
720
|
+
console.warn(`[agents/browser] Failed to close browser session ${sessionId}`, error);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Capped at half the provider's keep-alive window: a browser with
|
|
725
|
+
* continuous CDP traffic must never look older than the window the
|
|
726
|
+
* provider uses to reclaim it.
|
|
727
|
+
*/
|
|
728
|
+
function _get_touchIntervalMs() {
|
|
729
|
+
const interval = _classPrivateFieldGet2(_options, this).touchIntervalMs ?? 6e4;
|
|
730
|
+
const { keepAliveMs } = _classPrivateFieldGet2(_adapter, this);
|
|
731
|
+
return keepAliveMs === void 0 ? interval : Math.min(interval, Math.floor(keepAliveMs / 2));
|
|
732
|
+
}
|
|
733
|
+
/** Lazy: `lifecycle.storage` exists only once `Lifecycle.use()` ran. */
|
|
734
|
+
function _get_sessionStore() {
|
|
735
|
+
_classPrivateFieldGet2(_store, this) ?? _classPrivateFieldSet2(_store, this, _classPrivateFieldGet2(_options, this).store ?? new DurableBrowserSessionStore(this.lifecycle.storage));
|
|
736
|
+
return _classPrivateFieldGet2(_store, this);
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* Refresh `updatedAt` while the record still holds `sessionId`. Returns
|
|
740
|
+
* false when a concurrent close or replacement already retired it.
|
|
741
|
+
*/
|
|
742
|
+
function _touch(sessionId) {
|
|
743
|
+
return _assertClassBrand(_Browser_brand, this, _update).call(this, sessionId, (current) => ({
|
|
744
|
+
...current,
|
|
745
|
+
updatedAt: Date.now()
|
|
746
|
+
}));
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* Rewrite the record only while it still holds `sessionId`: a replaced or
|
|
750
|
+
* retired record is never resurrected.
|
|
751
|
+
*/
|
|
752
|
+
async function _update(sessionId, change) {
|
|
753
|
+
const lock = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).acquireLock(_classPrivateFieldGet2(_key, this));
|
|
754
|
+
try {
|
|
755
|
+
const current = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).get(_classPrivateFieldGet2(_key, this));
|
|
756
|
+
if (current?.sessionId !== sessionId) return false;
|
|
757
|
+
await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).set(_classPrivateFieldGet2(_key, this), change(current));
|
|
758
|
+
return true;
|
|
759
|
+
} finally {
|
|
760
|
+
await lock.release();
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
function _scopeKey(scope) {
|
|
764
|
+
return `${browserScopeKeyPrefix(this.name)}${scope}`;
|
|
765
|
+
}
|
|
766
|
+
/** The lock every scope record of this browser is written under. */
|
|
767
|
+
function _get_scopesLockKey() {
|
|
768
|
+
return browserScopeKeyPrefix(this.name);
|
|
769
|
+
}
|
|
770
|
+
/** Every scope record of this browser, by scope. */
|
|
771
|
+
async function _listScopes() {
|
|
772
|
+
const prefix = browserScopeKeyPrefix(this.name);
|
|
773
|
+
const entries = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).list(prefix);
|
|
774
|
+
const scopes = /* @__PURE__ */ new Map();
|
|
775
|
+
for (const [key, entry] of entries) scopes.set(key.slice(prefix.length), entry);
|
|
776
|
+
return scopes;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Start a connection's scope: a scope whose record names an earlier
|
|
780
|
+
* browser was restarted, and its record moves to this one. A new record
|
|
781
|
+
* past {@link MAX_BROWSER_SCOPES} evicts the least recently used.
|
|
782
|
+
*/
|
|
783
|
+
async function _enterScope(scope, sessionId) {
|
|
784
|
+
const key = _assertClassBrand(_Browser_brand, this, _scopeKey).call(this, scope);
|
|
785
|
+
const lock = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).acquireLock(_get_scopesLockKey.call(_assertClassBrand(_Browser_brand, this)));
|
|
786
|
+
try {
|
|
787
|
+
const entry = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).get(key);
|
|
788
|
+
const now = Date.now();
|
|
789
|
+
if (entry?.sessionId === sessionId) {
|
|
790
|
+
await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).set(key, {
|
|
791
|
+
...entry,
|
|
792
|
+
updatedAt: now
|
|
793
|
+
});
|
|
794
|
+
return {
|
|
795
|
+
restarted: false,
|
|
796
|
+
activeTargetId: entry.activeTargetId
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).set(key, {
|
|
800
|
+
sessionId,
|
|
801
|
+
createdAt: now,
|
|
802
|
+
updatedAt: now
|
|
803
|
+
});
|
|
804
|
+
if (!entry) await _assertClassBrand(_Browser_brand, this, _evictScopes).call(this);
|
|
805
|
+
return { restarted: entry !== void 0 };
|
|
806
|
+
} finally {
|
|
807
|
+
await lock.release();
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
/** Delete the least recently used scope records past the cap. */
|
|
811
|
+
async function _evictScopes() {
|
|
812
|
+
const scopes = await _assertClassBrand(_Browser_brand, this, _listScopes).call(this);
|
|
813
|
+
if (scopes.size <= 100) return;
|
|
814
|
+
const oldest = [...scopes].sort(([, a], [, b]) => a.updatedAt - b.updatedAt).slice(0, scopes.size - 100);
|
|
815
|
+
for (const [scope] of oldest) await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).delete(_assertClassBrand(_Browser_brand, this, _scopeKey).call(this, scope));
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* Set a scope's tab (or clear it with `undefined`). Never resurrects:
|
|
819
|
+
* does nothing (and returns `false`) once the browser this connection
|
|
820
|
+
* resolved was closed or replaced.
|
|
821
|
+
*/
|
|
822
|
+
async function _updateScope(scope, sessionId, targetId) {
|
|
823
|
+
const key = _assertClassBrand(_Browser_brand, this, _scopeKey).call(this, scope);
|
|
824
|
+
const lock = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).acquireLock(_get_scopesLockKey.call(_assertClassBrand(_Browser_brand, this)));
|
|
825
|
+
try {
|
|
826
|
+
const current = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).get(_classPrivateFieldGet2(_key, this));
|
|
827
|
+
const entry = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).get(key);
|
|
828
|
+
if (current?.sessionId !== sessionId || entry?.sessionId !== sessionId) return false;
|
|
829
|
+
await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).set(key, {
|
|
830
|
+
...entry,
|
|
831
|
+
activeTargetId: targetId,
|
|
832
|
+
updatedAt: Date.now()
|
|
833
|
+
});
|
|
834
|
+
return true;
|
|
835
|
+
} finally {
|
|
836
|
+
await lock.release();
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
/** Retire the record if it still holds `sessionId`. */
|
|
840
|
+
async function _retireIfCurrent(sessionId) {
|
|
841
|
+
const lock = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).acquireLock(_classPrivateFieldGet2(_key, this));
|
|
842
|
+
try {
|
|
843
|
+
const current = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).get(_classPrivateFieldGet2(_key, this));
|
|
844
|
+
if (current?.sessionId === sessionId) await _assertClassBrand(_Browser_brand, this, _retire).call(this, current);
|
|
845
|
+
} finally {
|
|
846
|
+
await lock.release();
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* Move the record to its retired marker. Callers hold the key lock, so a
|
|
851
|
+
* resolver always sees either the record or the marker.
|
|
852
|
+
*/
|
|
853
|
+
async function _retire(current) {
|
|
854
|
+
await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).set(retiredBrowserSessionKey(this.name), {
|
|
855
|
+
...current,
|
|
856
|
+
closedAt: Date.now()
|
|
857
|
+
});
|
|
858
|
+
await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).delete(_classPrivateFieldGet2(_key, this));
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Create a provider session (outside any lock) and commit it. The adapter
|
|
862
|
+
* applies the provider's creation options. If a concurrent caller
|
|
863
|
+
* committed an entry first, theirs wins and the redundant session is
|
|
864
|
+
* closed best-effort.
|
|
865
|
+
*
|
|
866
|
+
* `restarted` is read under the commit lock: a retired marker — left by
|
|
867
|
+
* close() or a dead-browser recovery — is evidence a prior browser
|
|
868
|
+
* existed, and only first-ever use of the name is not a restart. Markers
|
|
869
|
+
* are permanent, so reading at commit time also catches a browser that
|
|
870
|
+
* was created and closed while this create was in flight.
|
|
871
|
+
*/
|
|
872
|
+
async function _createAndCommit() {
|
|
873
|
+
const info = await _classPrivateFieldGet2(_adapter, this).create({ owner: _assertClassBrand(_Browser_brand, this, _internalHostOwner).call(this) });
|
|
874
|
+
const now = Date.now();
|
|
875
|
+
const signature = _classPrivateFieldGet2(_adapter, this).internalHostsSignature;
|
|
876
|
+
const stored = {
|
|
877
|
+
sessionId: info.sessionId,
|
|
878
|
+
createdAt: now,
|
|
879
|
+
updatedAt: now,
|
|
880
|
+
...signature !== void 0 ? { internalHosts: signature } : {}
|
|
881
|
+
};
|
|
882
|
+
let winner;
|
|
883
|
+
let restarted;
|
|
884
|
+
const lock = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).acquireLock(_classPrivateFieldGet2(_key, this));
|
|
885
|
+
try {
|
|
886
|
+
restarted = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).get(retiredBrowserSessionKey(this.name)) !== void 0;
|
|
887
|
+
const current = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).get(_classPrivateFieldGet2(_key, this));
|
|
888
|
+
if (current === void 0) await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).set(_classPrivateFieldGet2(_key, this), stored);
|
|
889
|
+
else winner = current;
|
|
890
|
+
} finally {
|
|
891
|
+
await lock.release();
|
|
892
|
+
}
|
|
893
|
+
if (winner) {
|
|
894
|
+
try {
|
|
895
|
+
await _classPrivateFieldGet2(_adapter, this).close(stored.sessionId);
|
|
896
|
+
} catch (error) {
|
|
897
|
+
console.warn(`[agents/browser] Failed to close redundant browser session ${stored.sessionId}`, error);
|
|
898
|
+
}
|
|
899
|
+
return {
|
|
900
|
+
session: winner,
|
|
901
|
+
restarted
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
return {
|
|
905
|
+
session: stored,
|
|
906
|
+
restarted
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
async function _readStored() {
|
|
910
|
+
const lock = await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).acquireLock(_classPrivateFieldGet2(_key, this));
|
|
911
|
+
try {
|
|
912
|
+
return await _get_sessionStore.call(_assertClassBrand(_Browser_brand, this)).get(_classPrivateFieldGet2(_key, this));
|
|
913
|
+
} finally {
|
|
914
|
+
await lock.release();
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
/** A store record without fields that belong to scope records. */
|
|
918
|
+
function resolvedFields(session) {
|
|
919
|
+
const { sessionId, createdAt, updatedAt } = session;
|
|
920
|
+
return {
|
|
921
|
+
sessionId,
|
|
922
|
+
createdAt,
|
|
923
|
+
updatedAt
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
/** The tabs scopes other than `scope` are working in, in `sessionId`. */
|
|
927
|
+
function activeTargets(scopes, scope, sessionId) {
|
|
928
|
+
const targets = /* @__PURE__ */ new Set();
|
|
929
|
+
for (const [other, entry] of scopes) {
|
|
930
|
+
if (other === scope || entry.sessionId !== sessionId) continue;
|
|
931
|
+
if (entry.activeTargetId) targets.add(entry.activeTargetId);
|
|
932
|
+
}
|
|
933
|
+
return targets;
|
|
934
|
+
}
|
|
935
|
+
//#endregion
|
|
936
|
+
export { ACTIVE_PAGE_SESSION, Browser, BrowserConnector, BrowserRenderingError, BrowserSession, CdpConnection, CdpSession, CodemodeRuntime, DEFAULT_BROWSER_SCOPE, DEFAULT_EXEC_SWEEP_IDLE_MS, DEFAULT_SWEEP_IDLE_MS, DurableBrowserSessionStore, InternalHostRouter, MAX_BROWSER_SCOPES, MAX_INTERNAL_HOSTS, browserContent, browserExtract, browserLinks, browserMarkdown, browserPdf, browserRun, browserScrape, browserScreenshot, browserSnapshot, connectBrowser, connectBrowserSession, connectUrl, conversationScope, createBrowserSession, deleteBrowserSession, getBrowserRecording, listBrowserTargets, loadCdpSpec, normalizeCdpSpec, runQuickAction };
|
|
937
|
+
|
|
938
|
+
//# sourceMappingURL=index.js.map
|