@yielded/agent-platform-cloudflare 0.1.0-beta.167 → 0.1.0-beta.169
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/dist/{Alarm-B0ODr1NE.mjs → Alarm-BMEAZo3p.mjs} +261 -159
- package/dist/Alarm-BMEAZo3p.mjs.map +1 -0
- package/dist/Alarm.d.mts +29 -36
- package/dist/Alarm.mjs +2 -2
- package/dist/BrowserCredentials-C5IWfi7f.d.mts +91 -0
- package/dist/BrowserCredentials.d.mts +2 -91
- package/dist/BrowserRestCapture.mjs +3 -3
- package/dist/BrowserRestCapture.mjs.map +1 -1
- package/dist/BrowserRestCrawl.mjs +6 -6
- package/dist/BrowserRestCrawl.mjs.map +1 -1
- package/dist/{BrowserSession-RfIzxGCH.mjs → BrowserSession-BfNmyayH.mjs} +5 -5
- package/dist/BrowserSession-BfNmyayH.mjs.map +1 -0
- package/dist/{BrowserSession-B969Xg-2.d.mts → BrowserSession-Bx0V1-6_.d.mts} +6 -3
- package/dist/BrowserSession.d.mts +1 -1
- package/dist/BrowserSession.mjs +2 -2
- package/dist/BrowserUse-Bc2JdLW2.mjs +1528 -0
- package/dist/BrowserUse-Bc2JdLW2.mjs.map +1 -0
- package/dist/BrowserUse.d.mts +83 -0
- package/dist/BrowserUse.mjs +2 -0
- package/dist/CloudflareBindings.d.mts +8 -1
- package/dist/CloudflareBindings.mjs +2 -2
- package/dist/CloudflareBindings.mjs.map +1 -1
- package/dist/{CloudflareBrowser-5an6m-Qb.mjs → CloudflareBrowser-Vt8qTdYW.mjs} +11 -13
- package/dist/CloudflareBrowser-Vt8qTdYW.mjs.map +1 -0
- package/dist/CloudflareBrowser.mjs +1 -1
- package/dist/CloudflareCodeMode.mjs +1 -1
- package/dist/CloudflareCodeMode.mjs.map +1 -1
- package/dist/{CloudflareConfig-qDrRLofL.d.mts → CloudflareConfig-C9MvPbX8.d.mts} +9 -11
- package/dist/CloudflareConfig.d.mts +1 -1
- package/dist/CloudflareConfig.mjs +9 -12
- package/dist/CloudflareConfig.mjs.map +1 -1
- package/dist/CloudflareMemory.d.mts +3 -25
- package/dist/CloudflareMemory.mjs +33 -31
- package/dist/CloudflareMemory.mjs.map +1 -1
- package/dist/CloudflareScheduling.mjs +8 -15
- package/dist/CloudflareScheduling.mjs.map +1 -1
- package/dist/CloudflareSubscriptions.mjs +9 -16
- package/dist/CloudflareSubscriptions.mjs.map +1 -1
- package/dist/CloudflareThreadClient-CLZpN9zU.mjs +588 -0
- package/dist/CloudflareThreadClient-CLZpN9zU.mjs.map +1 -0
- package/dist/CloudflareThreadClient-QsVzLGGZ.d.mts +2033 -0
- package/dist/CloudflareThreadClient.d.mts +2 -1796
- package/dist/CloudflareThreadClient.mjs +2 -382
- package/dist/{InteractiveBrowser-BbG3kGA9.mjs → InteractiveBrowser-LdKzQeLR.mjs} +18 -19
- package/dist/InteractiveBrowser-LdKzQeLR.mjs.map +1 -0
- package/dist/InteractiveBrowser.mjs +1 -1
- package/dist/{ThreadObject-BcfXbzSO.d.mts → ThreadObject-7s5XnlH-.d.mts} +103 -79
- package/dist/{ThreadObject-DHjrnlX4.mjs → ThreadObject-CgXZMlr4.mjs} +265 -66
- package/dist/ThreadObject-CgXZMlr4.mjs.map +1 -0
- package/dist/ThreadObject.d.mts +2 -2
- package/dist/ThreadObject.mjs +2 -3
- package/dist/WakeScheduler.d.mts +6 -5
- package/dist/WakeScheduler.mjs +15 -11
- package/dist/WakeScheduler.mjs.map +1 -1
- package/dist/index.d.mts +7 -6
- package/dist/index.mjs +7 -6
- package/dist/page-function-CmUCcyNP.mjs +11 -0
- package/dist/page-function-CmUCcyNP.mjs.map +1 -0
- package/dist/{prepared-admission-DMX5p9dC.mjs → prepared-admission-B61A7y6O.mjs} +3 -3
- package/dist/{prepared-admission-DMX5p9dC.mjs.map → prepared-admission-B61A7y6O.mjs.map} +1 -1
- package/package.json +1 -1
- package/src/Alarm.ts +512 -279
- package/src/BrowserRestCapture.ts +2 -2
- package/src/BrowserRestCrawl.ts +10 -14
- package/src/BrowserSession.ts +10 -2
- package/src/BrowserUse.ts +1591 -0
- package/src/CloudflareBindings.ts +13 -4
- package/src/CloudflareCodeMode.ts +1 -1
- package/src/CloudflareConfig.ts +9 -12
- package/src/CloudflareMemory.ts +21 -28
- package/src/CloudflareScheduling.ts +7 -15
- package/src/CloudflareSubscriptions.ts +11 -20
- package/src/CloudflareThreadClient.ts +289 -9
- package/src/InteractiveBrowser.ts +325 -323
- package/src/ThreadObject.ts +172 -52
- package/src/WakeScheduler.ts +29 -18
- package/src/index.ts +1 -0
- package/src/internal/browser-dom.ts +886 -0
- package/src/internal/browser-file-selection.ts +8 -1
- package/src/internal/browser-jev-dom.ts +362 -0
- package/src/internal/browser-quick-action.ts +7 -8
- package/src/internal/browser-session-lifecycle.ts +2 -5
- package/src/internal/crypto.ts +41 -0
- package/src/internal/due-queue.ts +5 -69
- package/src/internal/layers.ts +100 -17
- package/src/internal/live-text-protocol.ts +51 -0
- package/src/internal/live-text.ts +256 -0
- package/src/internal/page-function.ts +12 -0
- package/src/internal/prepared-admission.ts +1 -1
- package/src/internal/progress-wait.ts +19 -24
- package/src/internal/transport.ts +1 -1
- package/dist/Alarm-B0ODr1NE.mjs.map +0 -1
- package/dist/BrowserSession-RfIzxGCH.mjs.map +0 -1
- package/dist/CloudflareBrowser-5an6m-Qb.mjs.map +0 -1
- package/dist/CloudflareThreadClient.mjs.map +0 -1
- package/dist/InteractiveBrowser-BbG3kGA9.mjs.map +0 -1
- 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(
|
|
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,362 @@
|
|
|
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
|
+
let ancestor: Element | null = node;
|
|
50
|
+
|
|
51
|
+
while (ancestor !== null) {
|
|
52
|
+
if (ancestor.matches('[aria-hidden="true"],[inert]')) return false;
|
|
53
|
+
const root = ancestor.getRootNode();
|
|
54
|
+
|
|
55
|
+
ancestor = ancestor.parentElement ?? (root instanceof ShadowRoot ? root.host : null);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return node.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true });
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const inView = (node: Element) => {
|
|
62
|
+
const rect = node.getBoundingClientRect();
|
|
63
|
+
const x = rect.x + rect.width / 2;
|
|
64
|
+
const y = rect.y + rect.height / 2;
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
rect.width > 0 && rect.height > 0 && x >= 0 && y >= 0 && x < innerWidth && y < innerHeight
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const name = (node: Element | null, seen = new Set<Element>()): string => {
|
|
72
|
+
if (node === null || seen.has(node) || seen.size >= 10_000) return "";
|
|
73
|
+
seen.add(node);
|
|
74
|
+
|
|
75
|
+
const referenced = (node.getAttribute("aria-labelledby") ?? "")
|
|
76
|
+
.split(/\s+/)
|
|
77
|
+
.map((id) => name(document.getElementById(id), seen))
|
|
78
|
+
.filter(Boolean)
|
|
79
|
+
.join(" ");
|
|
80
|
+
|
|
81
|
+
const labels =
|
|
82
|
+
node instanceof HTMLInputElement ||
|
|
83
|
+
node instanceof HTMLTextAreaElement ||
|
|
84
|
+
node instanceof HTMLSelectElement
|
|
85
|
+
? node.labels
|
|
86
|
+
: null;
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
referenced ||
|
|
90
|
+
node.getAttribute("aria-label") ||
|
|
91
|
+
Array.from(labels ?? [])
|
|
92
|
+
.map((label) => name(label, seen))
|
|
93
|
+
.filter(Boolean)
|
|
94
|
+
.join(" ") ||
|
|
95
|
+
(node instanceof HTMLInputElement && ["button", "submit", "reset"].includes(node.type)
|
|
96
|
+
? node.value
|
|
97
|
+
: "") ||
|
|
98
|
+
node.getAttribute("alt") ||
|
|
99
|
+
(node.tagName === "INPUT"
|
|
100
|
+
? ""
|
|
101
|
+
: Array.from(node.childNodes)
|
|
102
|
+
.map((child) =>
|
|
103
|
+
child instanceof Text
|
|
104
|
+
? child.textContent
|
|
105
|
+
: child instanceof Element && child.getAttribute("aria-hidden") !== "true"
|
|
106
|
+
? name(child, seen)
|
|
107
|
+
: "",
|
|
108
|
+
)
|
|
109
|
+
.join(" ")
|
|
110
|
+
.trim()) ||
|
|
111
|
+
node.getAttribute("title") ||
|
|
112
|
+
node.getAttribute("placeholder") ||
|
|
113
|
+
""
|
|
114
|
+
).slice(0, 4_096);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const roles = [
|
|
118
|
+
"button",
|
|
119
|
+
"link",
|
|
120
|
+
"checkbox",
|
|
121
|
+
"radio",
|
|
122
|
+
"switch",
|
|
123
|
+
"tab",
|
|
124
|
+
"menuitem",
|
|
125
|
+
"menuitemradio",
|
|
126
|
+
"option",
|
|
127
|
+
"gridcell",
|
|
128
|
+
"combobox",
|
|
129
|
+
"textbox",
|
|
130
|
+
"searchbox",
|
|
131
|
+
"spinbutton",
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
const role = (node: HTMLElement) => {
|
|
135
|
+
const explicit = node.getAttribute("role");
|
|
136
|
+
|
|
137
|
+
if (explicit !== null && roles.includes(explicit)) return explicit;
|
|
138
|
+
if (node.tagName === "BUTTON" || node.tagName === "SUMMARY") return "button";
|
|
139
|
+
if (node.tagName === "A") return "link";
|
|
140
|
+
if (node instanceof HTMLSelectElement) return "combobox";
|
|
141
|
+
if (node instanceof HTMLTextAreaElement || node.isContentEditable) return "textbox";
|
|
142
|
+
if (node instanceof HTMLInputElement) {
|
|
143
|
+
if (["checkbox", "radio"].includes(node.type)) return node.type;
|
|
144
|
+
if (["button", "submit", "reset", "image"].includes(node.type)) return "button";
|
|
145
|
+
if (node.type === "search") return "searchbox";
|
|
146
|
+
if (node.type === "number") return "spinbutton";
|
|
147
|
+
if (["text", "email", "url", "tel"].includes(node.type)) return "textbox";
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return null;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const value = (node: HTMLElement) =>
|
|
154
|
+
("value" in node
|
|
155
|
+
? String(node.value)
|
|
156
|
+
: node.isContentEditable || role(node) === "combobox"
|
|
157
|
+
? node.innerText.trim()
|
|
158
|
+
: ""
|
|
159
|
+
).slice(0, 4_096);
|
|
160
|
+
|
|
161
|
+
const readOnly = (node: HTMLElement) =>
|
|
162
|
+
((node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement) &&
|
|
163
|
+
node.readOnly) ||
|
|
164
|
+
node.getAttribute("aria-readonly") === "true";
|
|
165
|
+
|
|
166
|
+
const closedRoots: ReadonlyMap<Element, ShadowRoot> | undefined = Reflect.get(
|
|
167
|
+
globalThis,
|
|
168
|
+
"@effect-agent/native-browser-closed-roots",
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
const candidates = [document, ...(closedRoots?.values() ?? [])].flatMap((root) =>
|
|
172
|
+
Array.from(
|
|
173
|
+
root.querySelectorAll(
|
|
174
|
+
'a[href],button,input,textarea,select,summary,[contenteditable="true"],' +
|
|
175
|
+
roles.map((role) => `[role="${role}"]`).join(","),
|
|
176
|
+
),
|
|
177
|
+
),
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const controls: Array<typeof Control.Type> = [];
|
|
181
|
+
let truncated = candidates.length > 10_000;
|
|
182
|
+
// A modal dialog blocks background input; offer only its controls, as default observations do.
|
|
183
|
+
const modal = document.querySelector("dialog:modal");
|
|
184
|
+
|
|
185
|
+
for (const node of Array.from(candidates).slice(0, 10_000)) {
|
|
186
|
+
if (!(node instanceof HTMLElement)) continue;
|
|
187
|
+
if (selector !== undefined && !node.matches(selector) && node.closest(selector) === null)
|
|
188
|
+
continue;
|
|
189
|
+
if (node instanceof HTMLInputElement && ["password", "file", "hidden"].includes(node.type))
|
|
190
|
+
continue;
|
|
191
|
+
if (
|
|
192
|
+
!visible(node) ||
|
|
193
|
+
!inView(node) ||
|
|
194
|
+
(modal !== null && !modal.contains(node)) ||
|
|
195
|
+
node.matches(":disabled") ||
|
|
196
|
+
node.closest('[aria-disabled="true"]')
|
|
197
|
+
)
|
|
198
|
+
continue;
|
|
199
|
+
const kind = role(node);
|
|
200
|
+
|
|
201
|
+
if (kind === null || (kind === "gridcell" && node.querySelector('button,[role="button"]')))
|
|
202
|
+
continue;
|
|
203
|
+
if (controls.length >= maximum) {
|
|
204
|
+
truncated = true;
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
const ref = `${prefix}-${controls.length}`;
|
|
208
|
+
const label = name(node) || kind;
|
|
209
|
+
const currentValue = value(node);
|
|
210
|
+
const readonly = readOnly(node);
|
|
211
|
+
const allOptions = node instanceof HTMLSelectElement ? Array.from(node.options) : [];
|
|
212
|
+
|
|
213
|
+
const matching = allOptions.flatMap((option, index) =>
|
|
214
|
+
option.selected ||
|
|
215
|
+
optionFilter === undefined ||
|
|
216
|
+
`${option.label}\n${option.value}`.toLowerCase().includes(optionFilter.toLowerCase())
|
|
217
|
+
? [{ option, index }]
|
|
218
|
+
: [],
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
const selected = matching.filter(({ option }) => option.selected);
|
|
222
|
+
|
|
223
|
+
const options = [
|
|
224
|
+
...selected.slice(0, 256),
|
|
225
|
+
...matching
|
|
226
|
+
.filter(({ option }) => !option.selected)
|
|
227
|
+
.slice(0, Math.max(0, 256 - selected.length)),
|
|
228
|
+
];
|
|
229
|
+
|
|
230
|
+
truncated ||= matching.length > options.length;
|
|
231
|
+
registry.set(ref, node);
|
|
232
|
+
checks.set(ref, {
|
|
233
|
+
name: label,
|
|
234
|
+
originalName: node.innerText.replace(/\s+/g, " ").trim().slice(0, 300),
|
|
235
|
+
kind,
|
|
236
|
+
viewport: true,
|
|
237
|
+
verify: () =>
|
|
238
|
+
role(node) === kind &&
|
|
239
|
+
(name(node) || kind) === label &&
|
|
240
|
+
value(node) === currentValue &&
|
|
241
|
+
readOnly(node) === readonly &&
|
|
242
|
+
node.closest('[aria-disabled="true"]') === null &&
|
|
243
|
+
inView(node),
|
|
244
|
+
});
|
|
245
|
+
controls.push({
|
|
246
|
+
ref,
|
|
247
|
+
kind,
|
|
248
|
+
name: label,
|
|
249
|
+
value: currentValue,
|
|
250
|
+
disabled: false,
|
|
251
|
+
editable:
|
|
252
|
+
!readonly &&
|
|
253
|
+
(["textbox", "searchbox", "spinbutton"].includes(kind) ||
|
|
254
|
+
(kind === "combobox" &&
|
|
255
|
+
(node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement))),
|
|
256
|
+
pointerEvents: getComputedStyle(node).pointerEvents.slice(0, 64),
|
|
257
|
+
options: options.map(({ option }) => option.value.slice(0, 4_096)),
|
|
258
|
+
...(node instanceof HTMLSelectElement
|
|
259
|
+
? {
|
|
260
|
+
optionCount: allOptions.length,
|
|
261
|
+
optionDetails: options.map(({ option, index }) => ({
|
|
262
|
+
index,
|
|
263
|
+
value: option.value.slice(0, 4_096),
|
|
264
|
+
label: option.label.slice(0, 300),
|
|
265
|
+
selected: option.selected,
|
|
266
|
+
disabled:
|
|
267
|
+
option.disabled ||
|
|
268
|
+
(option.parentElement instanceof HTMLOptGroupElement &&
|
|
269
|
+
option.parentElement.disabled),
|
|
270
|
+
})),
|
|
271
|
+
}
|
|
272
|
+
: {}),
|
|
273
|
+
...(node instanceof HTMLInputElement && ["checkbox", "radio"].includes(node.type)
|
|
274
|
+
? { checked: node.checked }
|
|
275
|
+
: {}),
|
|
276
|
+
attributes: Object.fromEntries(
|
|
277
|
+
[
|
|
278
|
+
"id",
|
|
279
|
+
"name",
|
|
280
|
+
"type",
|
|
281
|
+
"role",
|
|
282
|
+
"tabindex",
|
|
283
|
+
"placeholder",
|
|
284
|
+
"aria-label",
|
|
285
|
+
"aria-labelledby",
|
|
286
|
+
"aria-expanded",
|
|
287
|
+
"aria-selected",
|
|
288
|
+
"aria-checked",
|
|
289
|
+
"aria-readonly",
|
|
290
|
+
"aria-disabled",
|
|
291
|
+
"aria-controls",
|
|
292
|
+
"href",
|
|
293
|
+
].flatMap((key) => {
|
|
294
|
+
const attribute = node.getAttribute(key);
|
|
295
|
+
|
|
296
|
+
return attribute === null ? [] : [[key, attribute.slice(0, 1_024)]];
|
|
297
|
+
}),
|
|
298
|
+
),
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const scopes =
|
|
303
|
+
selector === undefined ? [document.body] : Array.from(document.querySelectorAll(selector));
|
|
304
|
+
|
|
305
|
+
const visited = new Set<Node>();
|
|
306
|
+
const words: Array<string> = [];
|
|
307
|
+
const range = document.createRange();
|
|
308
|
+
let length = 0;
|
|
309
|
+
let scanned = 0;
|
|
310
|
+
|
|
311
|
+
truncated ||= scopes.length > 256;
|
|
312
|
+
for (const scope of scopes.slice(0, 256)) {
|
|
313
|
+
if (scope === null) continue;
|
|
314
|
+
const walker = document.createTreeWalker(scope, NodeFilter.SHOW_TEXT);
|
|
315
|
+
let node = walker.nextNode();
|
|
316
|
+
|
|
317
|
+
while (node !== null && length < 6_000 && scanned++ < 10_000) {
|
|
318
|
+
const text = node.textContent?.trim() ?? "";
|
|
319
|
+
const parent = node.parentElement;
|
|
320
|
+
|
|
321
|
+
if (
|
|
322
|
+
!visited.has(node) &&
|
|
323
|
+
text &&
|
|
324
|
+
parent &&
|
|
325
|
+
!parent.closest("script,style,noscript,template") &&
|
|
326
|
+
visible(parent)
|
|
327
|
+
) {
|
|
328
|
+
range.selectNodeContents(node);
|
|
329
|
+
const rect = range.getBoundingClientRect();
|
|
330
|
+
|
|
331
|
+
if (
|
|
332
|
+
rect.width > 0 &&
|
|
333
|
+
rect.height > 0 &&
|
|
334
|
+
rect.bottom > 0 &&
|
|
335
|
+
rect.top < innerHeight &&
|
|
336
|
+
rect.right > 0 &&
|
|
337
|
+
rect.left < innerWidth
|
|
338
|
+
) {
|
|
339
|
+
words.push(text);
|
|
340
|
+
length += text.length;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
visited.add(node);
|
|
344
|
+
node = walker.nextNode();
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
const text = words.join("\n");
|
|
348
|
+
|
|
349
|
+
return {
|
|
350
|
+
text: text.slice(0, 6_000),
|
|
351
|
+
controls,
|
|
352
|
+
readyState: document.readyState,
|
|
353
|
+
truncated: truncated || text.length > 6_000 || scanned >= 10_000,
|
|
354
|
+
page: {
|
|
355
|
+
title: document.title,
|
|
356
|
+
scrollY,
|
|
357
|
+
viewportHeight: innerHeight,
|
|
358
|
+
documentHeight: document.documentElement.scrollHeight,
|
|
359
|
+
},
|
|
360
|
+
};
|
|
361
|
+
},
|
|
362
|
+
);
|
|
@@ -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 =
|
|
103
|
+
const invoke = (
|
|
104
104
|
action: "screenshot" | "content" | "markdown" | "links" | "scrape" | "json",
|
|
105
105
|
evaluate: () => Promise<Response>,
|
|
106
|
-
): Effect.
|
|
107
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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,
|
|
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
|
-
|
|
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,
|