@yielded/agent-platform-cloudflare 0.1.0-beta.167 → 0.1.0-beta.168

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 (97) hide show
  1. package/dist/{Alarm-B0ODr1NE.mjs → Alarm-DxODgAZZ.mjs} +259 -159
  2. package/dist/Alarm-DxODgAZZ.mjs.map +1 -0
  3. package/dist/Alarm.d.mts +27 -36
  4. package/dist/Alarm.mjs +2 -2
  5. package/dist/BrowserCredentials-C5IWfi7f.d.mts +91 -0
  6. package/dist/BrowserCredentials.d.mts +2 -91
  7. package/dist/BrowserRestCapture.mjs +3 -3
  8. package/dist/BrowserRestCapture.mjs.map +1 -1
  9. package/dist/BrowserRestCrawl.mjs +6 -6
  10. package/dist/BrowserRestCrawl.mjs.map +1 -1
  11. package/dist/{BrowserSession-RfIzxGCH.mjs → BrowserSession-BfNmyayH.mjs} +5 -5
  12. package/dist/BrowserSession-BfNmyayH.mjs.map +1 -0
  13. package/dist/{BrowserSession-B969Xg-2.d.mts → BrowserSession-Bx0V1-6_.d.mts} +6 -3
  14. package/dist/BrowserSession.d.mts +1 -1
  15. package/dist/BrowserSession.mjs +2 -2
  16. package/dist/BrowserUse-AstK0jKX.mjs +1467 -0
  17. package/dist/BrowserUse-AstK0jKX.mjs.map +1 -0
  18. package/dist/BrowserUse.d.mts +83 -0
  19. package/dist/BrowserUse.mjs +2 -0
  20. package/dist/CloudflareBindings.d.mts +8 -1
  21. package/dist/CloudflareBindings.mjs +2 -2
  22. package/dist/CloudflareBindings.mjs.map +1 -1
  23. package/dist/{CloudflareBrowser-5an6m-Qb.mjs → CloudflareBrowser-Vt8qTdYW.mjs} +11 -13
  24. package/dist/CloudflareBrowser-Vt8qTdYW.mjs.map +1 -0
  25. package/dist/CloudflareBrowser.mjs +1 -1
  26. package/dist/CloudflareCodeMode.mjs +1 -1
  27. package/dist/CloudflareCodeMode.mjs.map +1 -1
  28. package/dist/{CloudflareConfig-qDrRLofL.d.mts → CloudflareConfig-C9MvPbX8.d.mts} +9 -11
  29. package/dist/CloudflareConfig.d.mts +1 -1
  30. package/dist/CloudflareConfig.mjs +9 -12
  31. package/dist/CloudflareConfig.mjs.map +1 -1
  32. package/dist/CloudflareMemory.d.mts +3 -25
  33. package/dist/CloudflareMemory.mjs +33 -31
  34. package/dist/CloudflareMemory.mjs.map +1 -1
  35. package/dist/CloudflareScheduling.mjs +8 -15
  36. package/dist/CloudflareScheduling.mjs.map +1 -1
  37. package/dist/CloudflareSubscriptions.mjs +9 -16
  38. package/dist/CloudflareSubscriptions.mjs.map +1 -1
  39. package/dist/CloudflareThreadClient-CZm0TvUe.mjs +588 -0
  40. package/dist/CloudflareThreadClient-CZm0TvUe.mjs.map +1 -0
  41. package/dist/CloudflareThreadClient-QsVzLGGZ.d.mts +2033 -0
  42. package/dist/CloudflareThreadClient.d.mts +2 -1796
  43. package/dist/CloudflareThreadClient.mjs +2 -382
  44. package/dist/{InteractiveBrowser-BbG3kGA9.mjs → InteractiveBrowser-LdKzQeLR.mjs} +18 -19
  45. package/dist/InteractiveBrowser-LdKzQeLR.mjs.map +1 -0
  46. package/dist/InteractiveBrowser.mjs +1 -1
  47. package/dist/{ThreadObject-BcfXbzSO.d.mts → ThreadObject-7s5XnlH-.d.mts} +103 -79
  48. package/dist/{ThreadObject-DHjrnlX4.mjs → ThreadObject-C0vrcDrw.mjs} +265 -66
  49. package/dist/ThreadObject-C0vrcDrw.mjs.map +1 -0
  50. package/dist/ThreadObject.d.mts +2 -2
  51. package/dist/ThreadObject.mjs +2 -3
  52. package/dist/WakeScheduler.d.mts +6 -5
  53. package/dist/WakeScheduler.mjs +15 -11
  54. package/dist/WakeScheduler.mjs.map +1 -1
  55. package/dist/index.d.mts +7 -6
  56. package/dist/index.mjs +7 -6
  57. package/dist/page-function-CmUCcyNP.mjs +11 -0
  58. package/dist/page-function-CmUCcyNP.mjs.map +1 -0
  59. package/dist/{prepared-admission-DMX5p9dC.mjs → prepared-admission-3UUq0zth.mjs} +3 -3
  60. package/dist/{prepared-admission-DMX5p9dC.mjs.map → prepared-admission-3UUq0zth.mjs.map} +1 -1
  61. package/package.json +1 -1
  62. package/src/Alarm.ts +510 -279
  63. package/src/BrowserRestCapture.ts +2 -2
  64. package/src/BrowserRestCrawl.ts +10 -14
  65. package/src/BrowserSession.ts +10 -2
  66. package/src/BrowserUse.ts +1541 -0
  67. package/src/CloudflareBindings.ts +13 -4
  68. package/src/CloudflareCodeMode.ts +1 -1
  69. package/src/CloudflareConfig.ts +9 -12
  70. package/src/CloudflareMemory.ts +21 -28
  71. package/src/CloudflareScheduling.ts +7 -15
  72. package/src/CloudflareSubscriptions.ts +11 -20
  73. package/src/CloudflareThreadClient.ts +289 -9
  74. package/src/InteractiveBrowser.ts +325 -323
  75. package/src/ThreadObject.ts +172 -52
  76. package/src/WakeScheduler.ts +29 -18
  77. package/src/index.ts +1 -0
  78. package/src/internal/browser-dom.ts +845 -0
  79. package/src/internal/browser-file-selection.ts +8 -1
  80. package/src/internal/browser-jev-dom.ts +344 -0
  81. package/src/internal/browser-quick-action.ts +7 -8
  82. package/src/internal/browser-session-lifecycle.ts +2 -5
  83. package/src/internal/crypto.ts +41 -0
  84. package/src/internal/due-queue.ts +5 -69
  85. package/src/internal/layers.ts +100 -17
  86. package/src/internal/live-text-protocol.ts +51 -0
  87. package/src/internal/live-text.ts +256 -0
  88. package/src/internal/page-function.ts +12 -0
  89. package/src/internal/prepared-admission.ts +1 -1
  90. package/src/internal/progress-wait.ts +19 -24
  91. package/src/internal/transport.ts +1 -1
  92. package/dist/Alarm-B0ODr1NE.mjs.map +0 -1
  93. package/dist/BrowserSession-RfIzxGCH.mjs.map +0 -1
  94. package/dist/CloudflareBrowser-5an6m-Qb.mjs.map +0 -1
  95. package/dist/CloudflareThreadClient.mjs.map +0 -1
  96. package/dist/InteractiveBrowser-BbG3kGA9.mjs.map +0 -1
  97. package/dist/ThreadObject-DHjrnlX4.mjs.map +0 -1
@@ -2,6 +2,8 @@ import type { BrowserSelectFileRequest } from "@yielded/agent/interactive-browse
2
2
  import { Base64 } from "effect/encoding";
3
3
  import type { Page } from "puppeteer-core/lib/esm/puppeteer/puppeteer-core-browser.js";
4
4
 
5
+ import { pageFunction } from "./page-function.ts";
6
+
5
7
  type Element = NonNullable<Awaited<ReturnType<Page["$"]>>>;
6
8
 
7
9
  // Both calls run this fixed function in Chromium. No caller-provided code or
@@ -53,7 +55,12 @@ export const makeFileSelection =
53
55
 
54
56
  const select = async (element: Element): Promise<void> => {
55
57
  if (session === undefined)
56
- return element.evaluate(setFileSelection, encoded, request.fileName, request.mediaType);
58
+ return element.evaluate(
59
+ pageFunction(setFileSelection),
60
+ encoded,
61
+ request.fileName,
62
+ request.mediaType,
63
+ );
57
64
  let onOpened: (event: { backendNodeId?: number }) => void = () => {};
58
65
  let onAbort: () => void = () => {};
59
66
  let timer: ReturnType<typeof setTimeout> | undefined;
@@ -0,0 +1,344 @@
1
+ /// <reference lib="dom" />
2
+
3
+ /* @license
4
+ * Selection and accessible naming adapted from jev-ultrafast snapshot.js at 1231850.
5
+ * Copyright (c) 2026 Browser Use
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import type { Control } from "@yielded/agent/browser-use";
27
+
28
+ import { pageFunction } from "./page-function.ts";
29
+
30
+ /** Isolated-realm Jev observation. The same private refs and native guards own input. */
31
+ export const inspectJevDom = pageFunction(
32
+ (
33
+ selector: string | undefined,
34
+ prefix: string,
35
+ maximum: number,
36
+ optionFilter: string | undefined,
37
+ ) => {
38
+ const registry = new Map<string, Element>();
39
+
40
+ const checks = new Map<
41
+ string,
42
+ { name: string; originalName: string; kind: string; viewport: boolean; verify: () => boolean }
43
+ >();
44
+
45
+ Reflect.set(globalThis, "@effect-agent/native-browser", registry);
46
+ Reflect.set(globalThis, "@effect-agent/native-browser-name-checks", checks);
47
+
48
+ const visible = (node: Element) =>
49
+ node.closest('[aria-hidden="true"],[inert]') === null &&
50
+ node.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true });
51
+
52
+ const inView = (node: Element) => {
53
+ const rect = node.getBoundingClientRect();
54
+ const x = rect.x + rect.width / 2;
55
+ const y = rect.y + rect.height / 2;
56
+
57
+ return (
58
+ rect.width > 0 && rect.height > 0 && x >= 0 && y >= 0 && x < innerWidth && y < innerHeight
59
+ );
60
+ };
61
+
62
+ const name = (node: Element | null, seen = new Set<Element>()): string => {
63
+ if (node === null || seen.has(node) || seen.size >= 10_000) return "";
64
+ seen.add(node);
65
+
66
+ const referenced = (node.getAttribute("aria-labelledby") ?? "")
67
+ .split(/\s+/)
68
+ .map((id) => name(document.getElementById(id), seen))
69
+ .filter(Boolean)
70
+ .join(" ");
71
+
72
+ const labels =
73
+ node instanceof HTMLInputElement ||
74
+ node instanceof HTMLTextAreaElement ||
75
+ node instanceof HTMLSelectElement
76
+ ? node.labels
77
+ : null;
78
+
79
+ return (
80
+ referenced ||
81
+ node.getAttribute("aria-label") ||
82
+ Array.from(labels ?? [])
83
+ .map((label) => name(label, seen))
84
+ .filter(Boolean)
85
+ .join(" ") ||
86
+ (node instanceof HTMLInputElement && ["button", "submit", "reset"].includes(node.type)
87
+ ? node.value
88
+ : "") ||
89
+ node.getAttribute("alt") ||
90
+ (node.tagName === "INPUT"
91
+ ? ""
92
+ : Array.from(node.childNodes)
93
+ .map((child) =>
94
+ child instanceof Text
95
+ ? child.textContent
96
+ : child instanceof Element && child.getAttribute("aria-hidden") !== "true"
97
+ ? name(child, seen)
98
+ : "",
99
+ )
100
+ .join(" ")
101
+ .trim()) ||
102
+ node.getAttribute("title") ||
103
+ node.getAttribute("placeholder") ||
104
+ ""
105
+ ).slice(0, 4_096);
106
+ };
107
+
108
+ const roles = [
109
+ "button",
110
+ "link",
111
+ "checkbox",
112
+ "radio",
113
+ "switch",
114
+ "tab",
115
+ "menuitem",
116
+ "menuitemradio",
117
+ "option",
118
+ "gridcell",
119
+ "combobox",
120
+ "textbox",
121
+ "searchbox",
122
+ "spinbutton",
123
+ ];
124
+
125
+ const role = (node: HTMLElement) => {
126
+ const explicit = node.getAttribute("role");
127
+
128
+ if (explicit !== null && roles.includes(explicit)) return explicit;
129
+ if (node.tagName === "BUTTON" || node.tagName === "SUMMARY") return "button";
130
+ if (node.tagName === "A") return "link";
131
+ if (node instanceof HTMLSelectElement) return "combobox";
132
+ if (node instanceof HTMLTextAreaElement || node.isContentEditable) return "textbox";
133
+ if (node instanceof HTMLInputElement) {
134
+ if (["checkbox", "radio"].includes(node.type)) return node.type;
135
+ if (["button", "submit", "reset", "image"].includes(node.type)) return "button";
136
+ if (node.type === "search") return "searchbox";
137
+ if (node.type === "number") return "spinbutton";
138
+ if (["text", "email", "url", "tel"].includes(node.type)) return "textbox";
139
+ }
140
+
141
+ return null;
142
+ };
143
+
144
+ const value = (node: HTMLElement) =>
145
+ ("value" in node
146
+ ? String(node.value)
147
+ : node.isContentEditable || role(node) === "combobox"
148
+ ? node.innerText.trim()
149
+ : ""
150
+ ).slice(0, 4_096);
151
+
152
+ const readOnly = (node: HTMLElement) =>
153
+ ((node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement) &&
154
+ node.readOnly) ||
155
+ node.getAttribute("aria-readonly") === "true";
156
+
157
+ const candidates = document.querySelectorAll(
158
+ 'a[href],button,input,textarea,select,summary,[contenteditable="true"],' +
159
+ roles.map((role) => `[role="${role}"]`).join(","),
160
+ );
161
+
162
+ const controls: Array<typeof Control.Type> = [];
163
+ let truncated = candidates.length > 10_000;
164
+ // A modal dialog blocks background input; offer only its controls, as default observations do.
165
+ const modal = document.querySelector("dialog:modal");
166
+
167
+ for (const node of Array.from(candidates).slice(0, 10_000)) {
168
+ if (!(node instanceof HTMLElement)) continue;
169
+ if (selector !== undefined && !node.matches(selector) && node.closest(selector) === null)
170
+ continue;
171
+ if (node instanceof HTMLInputElement && ["password", "file", "hidden"].includes(node.type))
172
+ continue;
173
+ if (
174
+ !visible(node) ||
175
+ !inView(node) ||
176
+ (modal !== null && !modal.contains(node)) ||
177
+ node.matches(":disabled") ||
178
+ node.closest('[aria-disabled="true"]')
179
+ )
180
+ continue;
181
+ const kind = role(node);
182
+
183
+ if (kind === null || (kind === "gridcell" && node.querySelector('button,[role="button"]')))
184
+ continue;
185
+ if (controls.length >= maximum) {
186
+ truncated = true;
187
+ break;
188
+ }
189
+ const ref = `${prefix}-${controls.length}`;
190
+ const label = name(node) || kind;
191
+ const currentValue = value(node);
192
+ const readonly = readOnly(node);
193
+ const allOptions = node instanceof HTMLSelectElement ? Array.from(node.options) : [];
194
+
195
+ const matching = allOptions.flatMap((option, index) =>
196
+ option.selected ||
197
+ optionFilter === undefined ||
198
+ `${option.label}\n${option.value}`.toLowerCase().includes(optionFilter.toLowerCase())
199
+ ? [{ option, index }]
200
+ : [],
201
+ );
202
+
203
+ const selected = matching.filter(({ option }) => option.selected);
204
+
205
+ const options = [
206
+ ...selected.slice(0, 256),
207
+ ...matching
208
+ .filter(({ option }) => !option.selected)
209
+ .slice(0, Math.max(0, 256 - selected.length)),
210
+ ];
211
+
212
+ truncated ||= matching.length > options.length;
213
+ registry.set(ref, node);
214
+ checks.set(ref, {
215
+ name: label,
216
+ originalName: node.innerText.replace(/\s+/g, " ").trim().slice(0, 300),
217
+ kind,
218
+ viewport: true,
219
+ verify: () =>
220
+ role(node) === kind &&
221
+ (name(node) || kind) === label &&
222
+ value(node) === currentValue &&
223
+ readOnly(node) === readonly &&
224
+ node.closest('[aria-disabled="true"]') === null &&
225
+ inView(node),
226
+ });
227
+ controls.push({
228
+ ref,
229
+ kind,
230
+ name: label,
231
+ value: currentValue,
232
+ disabled: false,
233
+ editable:
234
+ !readonly &&
235
+ (["textbox", "searchbox", "spinbutton"].includes(kind) ||
236
+ (kind === "combobox" &&
237
+ (node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement))),
238
+ pointerEvents: getComputedStyle(node).pointerEvents.slice(0, 64),
239
+ options: options.map(({ option }) => option.value.slice(0, 4_096)),
240
+ ...(node instanceof HTMLSelectElement
241
+ ? {
242
+ optionCount: allOptions.length,
243
+ optionDetails: options.map(({ option, index }) => ({
244
+ index,
245
+ value: option.value.slice(0, 4_096),
246
+ label: option.label.slice(0, 300),
247
+ selected: option.selected,
248
+ disabled:
249
+ option.disabled ||
250
+ (option.parentElement instanceof HTMLOptGroupElement &&
251
+ option.parentElement.disabled),
252
+ })),
253
+ }
254
+ : {}),
255
+ ...(node instanceof HTMLInputElement && ["checkbox", "radio"].includes(node.type)
256
+ ? { checked: node.checked }
257
+ : {}),
258
+ attributes: Object.fromEntries(
259
+ [
260
+ "id",
261
+ "name",
262
+ "type",
263
+ "role",
264
+ "tabindex",
265
+ "placeholder",
266
+ "aria-label",
267
+ "aria-labelledby",
268
+ "aria-expanded",
269
+ "aria-selected",
270
+ "aria-checked",
271
+ "aria-readonly",
272
+ "aria-disabled",
273
+ "aria-controls",
274
+ "href",
275
+ ].flatMap((key) => {
276
+ const attribute = node.getAttribute(key);
277
+
278
+ return attribute === null ? [] : [[key, attribute.slice(0, 1_024)]];
279
+ }),
280
+ ),
281
+ });
282
+ }
283
+
284
+ const scopes =
285
+ selector === undefined ? [document.body] : Array.from(document.querySelectorAll(selector));
286
+
287
+ const visited = new Set<Node>();
288
+ const words: Array<string> = [];
289
+ const range = document.createRange();
290
+ let length = 0;
291
+ let scanned = 0;
292
+
293
+ truncated ||= scopes.length > 256;
294
+ for (const scope of scopes.slice(0, 256)) {
295
+ if (scope === null) continue;
296
+ const walker = document.createTreeWalker(scope, NodeFilter.SHOW_TEXT);
297
+ let node = walker.nextNode();
298
+
299
+ while (node !== null && length < 6_000 && scanned++ < 10_000) {
300
+ const text = node.textContent?.trim() ?? "";
301
+ const parent = node.parentElement;
302
+
303
+ if (
304
+ !visited.has(node) &&
305
+ text &&
306
+ parent &&
307
+ !parent.closest("script,style,noscript,template") &&
308
+ visible(parent)
309
+ ) {
310
+ range.selectNodeContents(node);
311
+ const rect = range.getBoundingClientRect();
312
+
313
+ if (
314
+ rect.width > 0 &&
315
+ rect.height > 0 &&
316
+ rect.bottom > 0 &&
317
+ rect.top < innerHeight &&
318
+ rect.right > 0 &&
319
+ rect.left < innerWidth
320
+ ) {
321
+ words.push(text);
322
+ length += text.length;
323
+ }
324
+ }
325
+ visited.add(node);
326
+ node = walker.nextNode();
327
+ }
328
+ }
329
+ const text = words.join("\n");
330
+
331
+ return {
332
+ text: text.slice(0, 6_000),
333
+ controls,
334
+ readyState: document.readyState,
335
+ truncated: truncated || text.length > 6_000 || scanned >= 10_000,
336
+ page: {
337
+ title: document.title,
338
+ scrollY,
339
+ viewportHeight: innerHeight,
340
+ documentHeight: document.documentElement.scrollHeight,
341
+ },
342
+ };
343
+ },
344
+ );
@@ -100,15 +100,14 @@ export class BrowserQuickActionBrowserBinding extends Context.Service<
100
100
  ): Layer.Layer<BrowserQuickActionBrowserBinding> {
101
101
  const browser = options.browser;
102
102
 
103
- const invoke = Effect.fn("BrowserQuickActionBrowserBinding.invoke")(function* (
103
+ const invoke = (
104
104
  action: "screenshot" | "content" | "markdown" | "links" | "scrape" | "json",
105
105
  evaluate: () => Promise<Response>,
106
- ): Effect.fn.Return<Response, BrowserQuickActionRpcError> {
107
- return yield* Effect.tryPromise({
106
+ ): Effect.Effect<Response, BrowserQuickActionRpcError> =>
107
+ Effect.tryPromise({
108
108
  try: evaluate,
109
109
  catch: (cause) => BrowserQuickActionRpcError.make({ action, cause }),
110
110
  });
111
- });
112
111
 
113
112
  return Layer.succeed(BrowserQuickActionBrowserBinding)({
114
113
  screenshot: (request) =>
@@ -333,7 +332,7 @@ const releaseResponseReader = (
333
332
  ),
334
333
  );
335
334
 
336
- const readBoundedResponse = Effect.fn("BrowserQuickActionCapture.readResponse")(function* (
335
+ const readBoundedResponse = Effect.fnUntraced(function* (
337
336
  response: Response,
338
337
  request: PageCaptureRequest,
339
338
  ) {
@@ -494,7 +493,7 @@ const makeCapture = (
494
493
  browser: BrowserQuickActionClient,
495
494
  workersAi?: BrowserQuickActionWorkersAiPolicy,
496
495
  ): PageCaptureCapture =>
497
- Effect.fn("BrowserQuickActionCapture.capture")(function* (
496
+ Effect.fnUntraced(function* (
498
497
  request: PageCaptureRequest,
499
498
  ): Effect.fn.Return<PageCaptureResult, PageCaptureError> {
500
499
  if (request.engine !== "chromium") {
@@ -727,7 +726,7 @@ const declaredLength = (response: Response): number | undefined => {
727
726
  return Number.isSafeInteger(length) ? length : undefined;
728
727
  };
729
728
 
730
- const readScreenshot = Effect.fn("BrowserQuickActionScreenshot.read")(function* (
729
+ const readScreenshot = Effect.fnUntraced(function* (
731
730
  response: Response,
732
731
  request: PageScreenshotRequest,
733
732
  ) {
@@ -793,7 +792,7 @@ const readScreenshot = Effect.fn("BrowserQuickActionScreenshot.read")(function*
793
792
  }, Effect.scoped);
794
793
 
795
794
  const makeScreenshot = (browser: BrowserQuickActionClient): PageScreenshotCapture =>
796
- Effect.fn("BrowserQuickActionScreenshot.capture")(function* (
795
+ Effect.fnUntraced(function* (
797
796
  request: PageScreenshotRequest,
798
797
  ): Effect.fn.Return<PageScreenshotResult, PageScreenshotError> {
799
798
  if (request.engine !== "chromium") {
@@ -53,10 +53,7 @@ export class BrowserRunSessionLifecycle extends Context.Service<
53
53
  }
54
54
  const client = yield* HttpClient.HttpClient;
55
55
 
56
- const request = Effect.fn("BrowserRunSessionLifecycle.request")(function* (
57
- method: "GET" | "DELETE",
58
- sessionId: string,
59
- ) {
56
+ const request = Effect.fnUntraced(function* (method: "GET" | "DELETE", sessionId: string) {
60
57
  const path = method === "DELETE" ? "browser" : "session";
61
58
 
62
59
  const response = yield* client
@@ -166,7 +163,7 @@ export class BrowserRunSessionLifecycle extends Context.Service<
166
163
  return result.endTime !== undefined && result.endTime > 0;
167
164
  });
168
165
 
169
- const close = Effect.fn("BrowserRunSessionLifecycle.close")(
166
+ const close = Effect.fnUntraced(
170
167
  function* (sessionId: Redacted.Redacted<string>) {
171
168
  const id = yield* Schema.decodeEffect(Identity)(Redacted.value(sessionId)).pipe(
172
169
  Effect.mapError(() => new BrowserRunCleanupError({ reason: "configuration" })),
@@ -0,0 +1,41 @@
1
+ // Implement the Effect Crypto service with the Workers native hashing primitive.
2
+ // @effect-diagnostics-next-line nodeBuiltinImport:off
3
+ import { createHash } from "node:crypto";
4
+
5
+ import { BrowserCrypto } from "@effect/platform-browser";
6
+ import { Crypto, Effect, Layer, PlatformError } from "effect";
7
+
8
+ /** Workers use native SHA-256 while retaining BrowserCrypto's services and overrides. */
9
+ export const cloudflareCryptoLayer: Layer.Layer<Crypto.Crypto> = Layer.effect(
10
+ Crypto.Crypto,
11
+ Effect.gen(function* () {
12
+ const base = yield* Crypto.Crypto;
13
+ const webCrypto = yield* BrowserCrypto.WebCrypto;
14
+ const hostGlobals: object = globalThis;
15
+
16
+ return Crypto.Crypto.of({
17
+ ...base,
18
+ digest: (algorithm, data) => {
19
+ if (
20
+ algorithm !== "SHA-256" ||
21
+ !("crypto" in hostGlobals) ||
22
+ webCrypto !== hostGlobals.crypto ||
23
+ typeof webCrypto.subtle?.digest !== "function"
24
+ )
25
+ return base.digest(algorithm, data);
26
+
27
+ return Effect.try({
28
+ try: () => Uint8Array.from(createHash("sha256").update(new Uint8Array(data)).digest()),
29
+ catch: (cause) =>
30
+ PlatformError.systemError({
31
+ module: "Crypto",
32
+ method: "digest",
33
+ _tag: "Unknown",
34
+ description: "Could not compute digest",
35
+ cause,
36
+ }),
37
+ });
38
+ },
39
+ });
40
+ }),
41
+ ).pipe(Layer.provide(BrowserCrypto.layer));
@@ -1,6 +1,4 @@
1
- import { Effect, Exit, Scheduler, Schema } from "effect";
2
- import { SqlClient } from "effect/sql/SqlClient";
3
- import { SqlError, UnknownError } from "effect/sql/SqlError";
1
+ import { Effect, Schema } from "effect";
4
2
 
5
3
  export const LaneId = Schema.NonEmptyString.check(Schema.isMaxLength(256));
6
4
 
@@ -186,71 +184,6 @@ export const make = (storage: DurableObjectStorage) => {
186
184
  write(changes.slice(offset, offset + 11));
187
185
  };
188
186
 
189
- /** Own the flush inside the source transaction without changing the SQL service.
190
- * Acquire its shared connection permit through Effect requirements. Cleanup follows
191
- * native settlement, including commit rejection or interruption. */
192
- const withTransaction = <A, E, R>(body: Effect.Effect<A, E, R>) =>
193
- Effect.flatMap(SqlClient, (client) =>
194
- Effect.flatMap(Effect.serviceOption(client.transactionService), (ambient) => {
195
- if (ambient._tag === "Some" && !ownsTransaction(storage, ambient.value[1]))
196
- return Effect.fail(
197
- SqlError.make({
198
- reason: UnknownError.make({
199
- operation: "begin maintenance source transaction",
200
- message:
201
- "Use ThreadMutationGate.withTransaction at the outermost source transaction",
202
- cause: new Error(
203
- "Unwrapped SQL transaction cannot own buffered maintenance intent",
204
- ),
205
- }),
206
- }),
207
- );
208
-
209
- return Effect.uninterruptibleMask((restore) =>
210
- Effect.suspend(() => {
211
- let frame: Frame | undefined;
212
-
213
- return client
214
- .withTransaction(
215
- Effect.flatMap(Effect.serviceOption(client.transactionService), (transaction) =>
216
- Effect.sync(() => {
217
- if (transaction._tag === "None") throw new Error("SQL transaction unavailable");
218
- frame = begin(transaction.value[1]);
219
- }),
220
- ).pipe(
221
- Effect.andThen(restore(body)),
222
- Effect.tap(() =>
223
- Effect.try({
224
- try: () => {
225
- if (frame !== undefined) flush(frame);
226
- },
227
- catch: (cause) =>
228
- SqlError.make({
229
- reason: UnknownError.make({
230
- cause,
231
- operation: "flush maintenance due queue",
232
- message: "Maintenance intent could not commit",
233
- }),
234
- }),
235
- }),
236
- ),
237
- ),
238
- )
239
- .pipe(
240
- Effect.onExit((exit) =>
241
- Effect.sync(() => {
242
- if (frame !== undefined) finish(frame, Exit.isSuccess(exit));
243
- }),
244
- ),
245
- // A released permit can resume another transaction. Do not auto-yield
246
- // between the driver's settlement and removing this transaction's frame.
247
- Effect.provideService(Scheduler.PreventSchedulerYield, true),
248
- );
249
- }),
250
- );
251
- }),
252
- );
253
-
254
187
  const transaction = async <A>(
255
188
  body: (transaction: DurableObjectTransaction) => Promise<A>,
256
189
  ): Promise<A> => {
@@ -476,7 +409,10 @@ export const make = (storage: DurableObjectStorage) => {
476
409
  return {
477
410
  initialize,
478
411
  withView,
479
- withTransaction,
412
+ // The host begins inside its transaction, flushes before commit, and finishes after settlement.
413
+ begin,
414
+ flush,
415
+ finish,
480
416
  transaction,
481
417
  read,
482
418
  dirty,