agents 0.32.0 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/ai-sdk-CpuRsjP5.d.ts +72 -0
  2. package/dist/browser/ai.js +2 -3
  3. package/dist/browser/ai.js.map +1 -1
  4. package/dist/browser/index.d.ts +29 -21
  5. package/dist/browser/index.js +937 -4
  6. package/dist/browser/index.js.map +1 -0
  7. package/dist/browser/tools/ai-sdk.d.ts +5 -70
  8. package/dist/browser/tools/ai-sdk.js +9 -3
  9. package/dist/browser/tools/ai-sdk.js.map +1 -1
  10. package/dist/browser/tools/pi.d.ts +11 -8
  11. package/dist/browser/tools/pi.js +58 -11
  12. package/dist/browser/tools/pi.js.map +1 -1
  13. package/dist/browser/tools/tanstack-ai.d.ts +4 -4
  14. package/dist/browser/tools/tanstack-ai.js +3 -3
  15. package/dist/browser/tools/tanstack-ai.js.map +1 -1
  16. package/dist/{browser-D9RNpJuT.d.ts → browser-CI97khiJ.d.ts} +222 -94
  17. package/dist/{browser-tool-BhjCcNVE.d.ts → browser-tool-Cxtiwfua.d.ts} +2 -2
  18. package/dist/browser-tool-DOqT1oSD.js +360 -0
  19. package/dist/browser-tool-DOqT1oSD.js.map +1 -0
  20. package/dist/chat/react.js +1 -0
  21. package/dist/chat/react.js.map +1 -1
  22. package/dist/cli.js +63 -62
  23. package/dist/{connector-CM-uuxKM.js → connector-Dl098To-.js} +402 -3
  24. package/dist/connector-Dl098To-.js.map +1 -0
  25. package/dist/experimental/webmcp.js +1 -1
  26. package/dist/harness/pi/index.d.ts +73 -26
  27. package/dist/harness/pi/index.js +77 -83
  28. package/dist/harness/pi/index.js.map +1 -1
  29. package/dist/{input-schema-BQykTEp_.js → input-schema-0uUu392-.js} +2 -2
  30. package/dist/input-schema-0uUu392-.js.map +1 -0
  31. package/dist/{input-schema-B0Etuo-o.js → input-schema-waggtYrH.js} +2 -2
  32. package/dist/input-schema-waggtYrH.js.map +1 -0
  33. package/dist/mcp/client/x402.d.ts +8 -8
  34. package/dist/mcp/index.d.ts +1 -1
  35. package/dist/mcp/index.js +3 -3
  36. package/dist/mcp/index.js.map +1 -1
  37. package/dist/models/pi-ai/index.js +11 -141
  38. package/dist/models/pi-ai/index.js.map +1 -1
  39. package/dist/{session-7CDgVE0z.js → session-CRY0bGiI.js} +423 -411
  40. package/dist/session-CRY0bGiI.js.map +1 -0
  41. package/dist/{tool-helpers-BI7ifO2S.js → tool-helpers-F3_Wy2YX.js} +2 -2
  42. package/dist/{tool-helpers-BI7ifO2S.js.map → tool-helpers-F3_Wy2YX.js.map} +1 -1
  43. package/dist/web/fetch/tools/ai-sdk.js +1 -1
  44. package/dist/web/fetch/tools/pi.d.ts +4 -7
  45. package/dist/web/fetch/tools/pi.js +7 -6
  46. package/dist/web/fetch/tools/pi.js.map +1 -1
  47. package/dist/web/fetch/tools/tanstack-ai.js +1 -1
  48. package/dist/web/search/tools/ai-sdk.js +1 -1
  49. package/dist/web/search/tools/pi.d.ts +5 -4
  50. package/dist/web/search/tools/pi.js +5 -10
  51. package/dist/web/search/tools/pi.js.map +1 -1
  52. package/dist/web/search/tools/tanstack-ai.js +1 -1
  53. package/docs/browse-the-web.md +36 -3
  54. package/docs/harnesses/pi.md +50 -30
  55. package/docs/models-pi-ai.md +1 -1
  56. package/package.json +14 -8
  57. package/dist/browser-1eUbPvC2.js +0 -931
  58. package/dist/browser-1eUbPvC2.js.map +0 -1
  59. package/dist/browser-tool-DRan7Lk6.js +0 -497
  60. package/dist/browser-tool-DRan7Lk6.js.map +0 -1
  61. package/dist/connector-CM-uuxKM.js.map +0 -1
  62. package/dist/input-schema-B0Etuo-o.js.map +0 -1
  63. package/dist/input-schema-BQykTEp_.js.map +0 -1
  64. package/dist/session-7CDgVE0z.js.map +0 -1
@@ -1,8 +1,191 @@
1
1
  import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldSet2, r as _assertClassBrand, t as _classPrivateFieldGet2 } from "./classPrivateFieldGet2-DZBYAB34.js";
2
2
  import { t as _classPrivateMethodInitSpec } from "./classPrivateMethodInitSpec-qMjJ6sHQ.js";
3
- import { C as CdpProtocolError, T as connectUrl, _ as deleteBrowserSession, b as listBrowserTargets, c as LIVE_VIEW_URL_TTL_MS, d as BrowserRenderingError, g as createBrowserSession, h as connectBrowserSession, l as applyLiveViewMode, m as connectBrowser, s as loadCdpSpec, u as createLiveView } from "./session-7CDgVE0z.js";
3
+ import { c as CdpConnection, d as connectUrl, l as CdpProtocolError } from "./session-CRY0bGiI.js";
4
4
  import { CodemodeConnector } from "@cloudflare/codemode";
5
5
  import { Validator } from "@cfworker/json-schema";
6
+ //#region src/browser/browser-run.ts
7
+ var BrowserRenderingError = class extends Error {
8
+ constructor(message, status) {
9
+ super(message);
10
+ this.status = status;
11
+ this.name = "BrowserRenderingError";
12
+ }
13
+ };
14
+ /**
15
+ * Whether an error means the platform session is gone: Browser Run uses 404
16
+ * for unknown ids and 410 after `keep_alive` expiry.
17
+ */
18
+ function isMissingBrowserSession$1(error) {
19
+ return error instanceof BrowserRenderingError && (error.status === 404 || error.status === 410);
20
+ }
21
+ function browserSessionEndpoint(sessionId, options) {
22
+ const path = sessionId ? `/v1/devtools/browser/${sessionId}` : "/v1/devtools/browser";
23
+ const url = new URL(`https://localhost${path}`);
24
+ if (options?.keepAliveMs !== void 0) url.searchParams.set("keep_alive", String(options.keepAliveMs));
25
+ if (options?.includeTargets) url.searchParams.set("targets", "true");
26
+ if (options?.recording) url.searchParams.set("recording", "true");
27
+ if (options?.browser) url.searchParams.set("browser", options.browser);
28
+ return url.toString();
29
+ }
30
+ async function parseBrowserSessionInfo(response) {
31
+ const payload = await response.json();
32
+ const sessionId = typeof payload.sessionId === "string" ? payload.sessionId : "";
33
+ if (!sessionId) throw new Error("Browser Rendering response did not include a sessionId");
34
+ return {
35
+ sessionId,
36
+ targets: Array.isArray(payload.targets) ? payload.targets : void 0,
37
+ webSocketDebuggerUrl: typeof payload.webSocketDebuggerUrl === "string" ? payload.webSocketDebuggerUrl : void 0
38
+ };
39
+ }
40
+ async function createBrowserSession(browser, options) {
41
+ const response = await browser.fetch(browserSessionEndpoint(void 0, options), {
42
+ method: "POST",
43
+ headers: { "Content-Type": "application/json" },
44
+ body: JSON.stringify(options?.guardrails ? { guardrails: options.guardrails } : {})
45
+ });
46
+ if (!response.ok) throw new BrowserRenderingError(`Failed to create Browser Rendering session: ${response.status}`, response.status);
47
+ return parseBrowserSessionInfo(response);
48
+ }
49
+ async function listBrowserTargets(browser, sessionId) {
50
+ const response = await browser.fetch(`https://localhost/v1/devtools/browser/${sessionId}/json/list`);
51
+ if (!response.ok) throw new BrowserRenderingError(`Failed to list Browser Rendering targets for ${sessionId}: ${response.status}`, response.status);
52
+ const payload = await response.json();
53
+ return Array.isArray(payload) ? payload : [];
54
+ }
55
+ async function deleteBrowserSession(browser, sessionId) {
56
+ const response = await browser.fetch(`https://localhost/v1/devtools/browser/${sessionId}`, { method: "DELETE" });
57
+ if (!response.ok && response.status !== 404) throw new BrowserRenderingError(`Failed to delete Browser Rendering session ${sessionId}: ${response.status}`, response.status);
58
+ }
59
+ /**
60
+ * Whether a typed binding call failed because the binding doesn't have that
61
+ * method. Fully local dev (Miniflare) has only `fetch`: every other method
62
+ * still looks like a function, then throws this when called.
63
+ */
64
+ function isUnimplementedBindingMethod(error, method) {
65
+ return error instanceof TypeError && error.message === `The RPC receiver does not implement the method "${method}".`;
66
+ }
67
+ /**
68
+ * Create a session with the binding's typed `acquire()`. Falls back to the
69
+ * HTTP API ({@link createBrowserSession}) when the binding doesn't have
70
+ * `acquire()`, as in fully local dev.
71
+ */
72
+ async function acquireBrowserSession(browser, options = {}) {
73
+ const { outboundByHost, ...httpOptions } = options;
74
+ if (browser.acquire) try {
75
+ const { sessionId } = await browser.acquire({
76
+ keepAlive: options.keepAliveMs,
77
+ recording: options.recording,
78
+ guardrails: options.guardrails,
79
+ ...outboundByHost ? { outboundByHost } : {}
80
+ });
81
+ return { sessionId };
82
+ } catch (error) {
83
+ if (!isUnimplementedBindingMethod(error, "acquire")) throw error;
84
+ }
85
+ if (outboundByHost) warnInternalHostsUnavailable(Object.keys(outboundByHost));
86
+ const { sessionId } = await createBrowserSession(browser, httpOptions);
87
+ return { sessionId };
88
+ }
89
+ let warnedInternalHostsUnavailable = false;
90
+ /** Say once per isolate that internal hostnames need a deployed Worker. */
91
+ function warnInternalHostsUnavailable(hosts) {
92
+ if (warnedInternalHostsUnavailable) return;
93
+ warnedInternalHostsUnavailable = true;
94
+ console.warn(`[agents/browser] Internal hostnames (${hosts.join(", ")}) only work once deployed: this Browser Run binding has no acquire(), as in local dev, so the browser starts without them.`);
95
+ }
96
+ /**
97
+ * The HTTP status in a typed binding method's error. Browser Run's binding
98
+ * errors carry it only in the message, e.g. `Not Found (status=404)`.
99
+ */
100
+ function bindingErrorStatus(error) {
101
+ if (!(error instanceof Error)) return void 0;
102
+ const match = /\(status=(\d{3})[,)]/.exec(error.message);
103
+ return match ? Number(match[1]) : void 0;
104
+ }
105
+ /**
106
+ * Close a session with the binding's typed `closeSession()`. A session
107
+ * Browser Run no longer knows (404 or 410) counts as closed. Falls back to
108
+ * the HTTP API ({@link deleteBrowserSession}) when the binding doesn't have
109
+ * `closeSession()`, as in fully local dev.
110
+ */
111
+ async function closeBrowserSession(browser, sessionId) {
112
+ if (browser.closeSession) try {
113
+ await browser.closeSession(sessionId);
114
+ return;
115
+ } catch (error) {
116
+ const status = bindingErrorStatus(error);
117
+ if (status === 404 || status === 410) return;
118
+ if (!isUnimplementedBindingMethod(error, "closeSession")) throw error;
119
+ }
120
+ await deleteBrowserSession(browser, sessionId);
121
+ }
122
+ /**
123
+ * Connect to a Browser Rendering session and delete it when closed.
124
+ */
125
+ async function connectBrowser(browser, options) {
126
+ const normalizedOptions = typeof options === "number" ? { timeoutMs: options } : options ?? {};
127
+ if (normalizedOptions.browser === "kitesurf") {
128
+ const smuggled = normalizedOptions;
129
+ if (smuggled.keepAliveMs || smuggled.includeTargets || smuggled.recording) throw new Error("Kitesurf does not support keepAliveMs, includeTargets, or recording");
130
+ }
131
+ const response = await browser.fetch(browserSessionEndpoint(void 0, normalizedOptions.browser === "kitesurf" ? { browser: "kitesurf" } : {
132
+ keepAliveMs: normalizedOptions.keepAliveMs,
133
+ includeTargets: normalizedOptions.includeTargets,
134
+ recording: normalizedOptions.recording
135
+ }), { headers: { Upgrade: "websocket" } });
136
+ const ws = response.webSocket;
137
+ if (!ws) throw new Error("Browser Rendering binding did not return a WebSocket. Ensure the 'browser' binding is configured in wrangler.jsonc.");
138
+ if (normalizedOptions.browser === "kitesurf") {
139
+ ws.accept();
140
+ return new CdpConnection(ws, { timeoutMs: normalizedOptions.timeoutMs });
141
+ }
142
+ const sessionId = response.headers.get("cf-browser-session-id");
143
+ if (!sessionId) throw new Error("Browser Rendering binding did not include a session ID when opening the CDP WebSocket");
144
+ ws.accept();
145
+ return new CdpConnection(ws, {
146
+ timeoutMs: normalizedOptions.timeoutMs,
147
+ onClose: () => {
148
+ deleteBrowserSession(browser, sessionId).catch((error) => {
149
+ console.warn(`[agents/browser] Failed to delete one-shot Browser Run session ${sessionId}`, error);
150
+ });
151
+ },
152
+ sessionId
153
+ });
154
+ }
155
+ /**
156
+ * Fetch a Browser Run [session recording](https://developers.cloudflare.com/browser-run/features/session-recording/)
157
+ * by session id, via the Browser Rendering REST API.
158
+ *
159
+ * A recording is only available **after** the session closes (explicit
160
+ * `closeSession()`, idle `keep_alive` expiry, or sweep) and is retained for 30
161
+ * days. Capture the session id while the session is alive — e.g. from
162
+ * `connector.liveView()`/`sessionInfo()` — then call this once it has ended.
163
+ *
164
+ * Unlike the binding-based helpers, this hits `api.cloudflare.com` directly, so
165
+ * it needs an account id and an API token with `Browser Rendering` read access
166
+ * (the Workers Browser Run binding cannot read recordings).
167
+ */
168
+ async function getBrowserRecording(options) {
169
+ const { accountId, apiToken, sessionId } = options;
170
+ const response = await (options.fetchImpl ?? fetch)(`https://api.cloudflare.com/client/v4/accounts/${accountId}/browser-rendering/recording/${sessionId}`, { headers: { Authorization: `Bearer ${apiToken}` } });
171
+ if (!response.ok) throw new BrowserRenderingError(`Failed to fetch Browser Run recording for ${sessionId}: ${response.status}`, response.status);
172
+ const payload = await response.json();
173
+ return "result" in payload && payload.result ? payload.result : payload;
174
+ }
175
+ async function connectBrowserSession(browser, sessionId, options) {
176
+ const normalized = typeof options === "number" ? { timeoutMs: options } : options ?? {};
177
+ const response = await browser.fetch(browserSessionEndpoint(sessionId), { headers: { Upgrade: "websocket" } });
178
+ const ws = response.webSocket;
179
+ if (!ws) throw new BrowserRenderingError(`Browser Rendering binding did not return a WebSocket for session ${sessionId} (${response.status})`, response.status);
180
+ ws.accept();
181
+ return new CdpConnection(ws, {
182
+ timeoutMs: normalized.timeoutMs,
183
+ onClose: normalized.onClose,
184
+ sessionId,
185
+ onActivity: normalized.onActivity
186
+ });
187
+ }
188
+ //#endregion
6
189
  //#region src/browser/quick-actions.ts
7
190
  function runQuickAction(browser, action, params) {
8
191
  return browser.quickAction(action, params);
@@ -165,6 +348,222 @@ function validateConnectorArgs(connector, name, tool) {
165
348
  };
166
349
  }
167
350
  //#endregion
351
+ //#region src/browser/live-view.ts
352
+ /**
353
+ * Browser Run mints `devtoolsFrontendUrl`s (the Live View links) that are
354
+ * valid for ~5 minutes. We surface the window so callers can decide how long
355
+ * a shared link is good for before re-listing targets.
356
+ */
357
+ const LIVE_VIEW_URL_TTL_MS = 300 * 1e3;
358
+ /**
359
+ * Rewrite the hosted Live View UI's `mode` query param (`tab` | `devtools`).
360
+ * The raw `devtoolsFrontendUrl` is returned unchanged when no mode is asked
361
+ * for or the URL can't be parsed.
362
+ */
363
+ function applyLiveViewMode(rawUrl, mode) {
364
+ if (!mode) return rawUrl;
365
+ try {
366
+ const url = new URL(rawUrl);
367
+ url.searchParams.set("mode", mode === "devtools" ? "devtools" : "tab");
368
+ return url.toString();
369
+ } catch {
370
+ return rawUrl;
371
+ }
372
+ }
373
+ /**
374
+ * Project a fresh target listing into Live View links — one per tab that has
375
+ * a `devtoolsFrontendUrl`. Pure; the caller supplies just-listed targets.
376
+ */
377
+ function createLiveView(sessionId, targets, mode) {
378
+ return {
379
+ sessionId,
380
+ targets: targets.filter((target) => target.devtoolsFrontendUrl).map((target) => ({
381
+ targetId: target.id,
382
+ url: applyLiveViewMode(target.devtoolsFrontendUrl, mode),
383
+ pageUrl: target.url,
384
+ title: target.title,
385
+ type: target.type
386
+ })),
387
+ expiresInMs: LIVE_VIEW_URL_TTL_MS
388
+ };
389
+ }
390
+ //#endregion
391
+ //#region src/browser/spec.ts
392
+ const MISSING_BROWSER_CONFIG = "Either 'browser' (Fetcher binding) or 'cdpUrl' must be provided";
393
+ const urlSpecCache = /* @__PURE__ */ new Map();
394
+ const bindingSpecCache = /* @__PURE__ */ new WeakMap();
395
+ const CACHE_TTL_MS = 300 * 1e3;
396
+ /** Qualify a same-domain `$ref` (`"FrameId"` → `"Page.FrameId"`). */
397
+ function qualifyRef(domain, ref) {
398
+ if (ref === void 0) return void 0;
399
+ return ref.includes(".") ? ref : `${domain}.${ref}`;
400
+ }
401
+ function normalizeItems(domain, items) {
402
+ if (!items) return void 0;
403
+ return {
404
+ type: items.type,
405
+ $ref: qualifyRef(domain, items.$ref),
406
+ enum: items.enum
407
+ };
408
+ }
409
+ function normalizeFields(domain, fields) {
410
+ return (fields ?? []).map((field) => ({
411
+ name: field.name,
412
+ description: field.description,
413
+ optional: field.optional,
414
+ experimental: field.experimental,
415
+ deprecated: field.deprecated,
416
+ type: field.type,
417
+ $ref: qualifyRef(domain, field.$ref),
418
+ enum: field.enum,
419
+ items: normalizeItems(domain, field.items)
420
+ }));
421
+ }
422
+ function normalizeCdpSpec(spec) {
423
+ return { domains: (spec.domains ?? []).map(({ domain, ...raw }) => ({
424
+ name: domain,
425
+ description: raw.description,
426
+ experimental: raw.experimental,
427
+ deprecated: raw.deprecated,
428
+ commands: (raw.commands ?? []).map((command) => ({
429
+ name: command.name,
430
+ method: `${domain}.${command.name}`,
431
+ description: command.description,
432
+ experimental: command.experimental,
433
+ deprecated: command.deprecated,
434
+ parameters: normalizeFields(domain, command.parameters),
435
+ returns: normalizeFields(domain, command.returns)
436
+ })),
437
+ events: (raw.events ?? []).map((event) => ({
438
+ name: event.name,
439
+ event: `${domain}.${event.name}`,
440
+ description: event.description,
441
+ experimental: event.experimental,
442
+ deprecated: event.deprecated,
443
+ parameters: normalizeFields(domain, event.parameters)
444
+ })),
445
+ types: (raw.types ?? []).map((type) => ({
446
+ id: type.id,
447
+ name: `${domain}.${type.id}`,
448
+ description: type.description,
449
+ experimental: type.experimental,
450
+ deprecated: type.deprecated,
451
+ type: type.type,
452
+ enum: type.enum,
453
+ properties: normalizeFields(domain, type.properties),
454
+ items: normalizeItems(domain, type.items)
455
+ }))
456
+ })) };
457
+ }
458
+ function getSpecCacheKey(source, headers) {
459
+ const headerEntries = Object.entries(headers ?? {}).sort(([a], [b]) => a.localeCompare(b));
460
+ return `${source}:${JSON.stringify(headerEntries)}`;
461
+ }
462
+ async function getCachedSpec(cache, key, load) {
463
+ const cached = cache.get(key);
464
+ if (cached && Date.now() - cached.cachedAt < CACHE_TTL_MS) return cached.spec;
465
+ const spec = normalizeCdpSpec(await load());
466
+ cache.set(key, {
467
+ spec,
468
+ cachedAt: Date.now()
469
+ });
470
+ return spec;
471
+ }
472
+ async function fetchCdpSpecFromUrl(cdpBaseUrl, headers) {
473
+ const endpoint = new URL("/json/protocol", cdpBaseUrl).toString();
474
+ return getCachedSpec(urlSpecCache, getSpecCacheKey(endpoint, headers), async () => {
475
+ const response = await fetch(endpoint, { headers });
476
+ if (!response.ok) throw new Error(`Failed to fetch CDP spec from ${endpoint}: ${response.status}`);
477
+ return await response.json();
478
+ });
479
+ }
480
+ async function fetchCdpSpecFromSession(browser, sessionId) {
481
+ return getCachedSpec(bindingSpecCache, browser, async () => {
482
+ const response = await browser.fetch(`https://localhost/v1/devtools/browser/${sessionId}/json/protocol`);
483
+ if (!response.ok) throw new Error(`Failed to fetch CDP spec from Browser Rendering: ${response.status}`);
484
+ return await response.json();
485
+ });
486
+ }
487
+ async function fetchCdpSpecFromBrowser(browser) {
488
+ return getCachedSpec(bindingSpecCache, browser, async () => {
489
+ const createResponse = await browser.fetch("https://localhost/v1/devtools/browser", { method: "POST" });
490
+ if (!createResponse.ok) throw new Error(`Failed to create Browser Rendering session for protocol fetch: ${createResponse.status}`);
491
+ const sessionId = (await createResponse.json()).sessionId;
492
+ if (!sessionId) throw new Error("Browser Rendering session response did not include a sessionId");
493
+ try {
494
+ const response = await browser.fetch(`https://localhost/v1/devtools/browser/${sessionId}/json/protocol`);
495
+ if (!response.ok) throw new Error(`Failed to fetch CDP spec from Browser Rendering: ${response.status}`);
496
+ return await response.json();
497
+ } finally {
498
+ try {
499
+ await browser.fetch(`https://localhost/v1/devtools/browser/${sessionId}`, { method: "DELETE" });
500
+ } catch {}
501
+ }
502
+ });
503
+ }
504
+ /** Load the (cached) searchable CDP spec for a browser source. */
505
+ async function loadCdpSpec(source) {
506
+ if (source.cdpUrl) return fetchCdpSpecFromUrl(source.cdpUrl, source.cdpHeaders);
507
+ if (source.browser && source.sessionId) return fetchCdpSpecFromSession(source.browser, source.sessionId);
508
+ if (source.browser) return fetchCdpSpecFromBrowser(source.browser);
509
+ throw new Error(MISSING_BROWSER_CONFIG);
510
+ }
511
+ //#endregion
512
+ //#region src/browser/session-store.ts
513
+ var _DurableBrowserSessionStore_brand = /* @__PURE__ */ new WeakSet();
514
+ var DurableBrowserSessionStore = class {
515
+ constructor(storage) {
516
+ this.storage = storage;
517
+ _classPrivateMethodInitSpec(this, _DurableBrowserSessionStore_brand);
518
+ }
519
+ async acquireLock(key) {
520
+ let queues = _queues._.get(this.storage);
521
+ if (!queues) {
522
+ queues = /* @__PURE__ */ new Map();
523
+ _queues._.set(this.storage, queues);
524
+ }
525
+ const previous = queues.get(key) ?? Promise.resolve();
526
+ let releaseQueue = () => void 0;
527
+ const current = previous.then(() => new Promise((resolve) => {
528
+ releaseQueue = resolve;
529
+ }));
530
+ queues.set(key, current);
531
+ await previous;
532
+ let released = false;
533
+ return { release: () => {
534
+ if (released) return;
535
+ released = true;
536
+ if (queues.get(key) === current) queues.delete(key);
537
+ releaseQueue();
538
+ } };
539
+ }
540
+ async get(key) {
541
+ return this.storage.get(_assertClassBrand(_DurableBrowserSessionStore_brand, this, _storageKey).call(this, key));
542
+ }
543
+ async set(key, session) {
544
+ await this.storage.put(_assertClassBrand(_DurableBrowserSessionStore_brand, this, _storageKey).call(this, key), session);
545
+ }
546
+ async delete(key) {
547
+ await this.storage.delete(_assertClassBrand(_DurableBrowserSessionStore_brand, this, _storageKey).call(this, key));
548
+ }
549
+ async list(prefix) {
550
+ const storagePrefix = _assertClassBrand(_DurableBrowserSessionStore_brand, this, _storageKey).call(this, prefix);
551
+ const entries = await this.storage.list({ prefix: storagePrefix });
552
+ const result = /* @__PURE__ */ new Map();
553
+ for (const [storageKey, value] of entries) result.set(storageKey.slice(16), value);
554
+ return result;
555
+ }
556
+ };
557
+ function _storageKey(key) {
558
+ return `browser-session:${key}`;
559
+ }
560
+ var _queues = { _: /* @__PURE__ */ new WeakMap() };
561
+ /**
562
+ * Default idle window used by {@link BrowserConnector.sweep} for the shared
563
+ * (reuse/promoted) session entry.
564
+ */
565
+ const DEFAULT_SWEEP_IDLE_MS = 600 * 1e3;
566
+ //#endregion
168
567
  //#region src/browser/connector.ts
169
568
  const EXEC_KEY_PREFIX = "cdp:exec:";
170
569
  /**
@@ -1023,6 +1422,6 @@ async function _closeStoredSession(key) {
1023
1422
  if (stored) await deleteBrowserSession(browser, stored.sessionId);
1024
1423
  }
1025
1424
  //#endregion
1026
- export { browserLinks as a, browserScrape as c, runQuickAction as d, browserExtract as i, browserScreenshot as l, DEFAULT_EXEC_SWEEP_IDLE_MS as n, browserMarkdown as o, browserContent as r, browserPdf as s, BrowserConnector as t, browserSnapshot as u };
1425
+ export { getBrowserRecording as C, deleteBrowserSession as S, listBrowserTargets as T, acquireBrowserSession as _, loadCdpSpec as a, connectBrowserSession as b, browserExtract as c, browserPdf as d, browserScrape as f, BrowserRenderingError as g, runQuickAction as h, DurableBrowserSessionStore as i, browserLinks as l, browserSnapshot as m, DEFAULT_EXEC_SWEEP_IDLE_MS as n, createLiveView as o, browserScreenshot as p, DEFAULT_SWEEP_IDLE_MS as r, browserContent as s, BrowserConnector as t, browserMarkdown as u, closeBrowserSession as v, isMissingBrowserSession$1 as w, createBrowserSession as x, connectBrowser as y };
1027
1426
 
1028
- //# sourceMappingURL=connector-CM-uuxKM.js.map
1427
+ //# sourceMappingURL=connector-Dl098To-.js.map