@pi-oxide/extension-js 0.2.4 → 0.4.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/content-script.d.ts +6 -43
- package/content-script.js +2 -2
- package/extension_js.d.ts +312 -226
- package/extension_js.js +62486 -60963
- package/generated.d.ts +45 -2
- package/index.d.ts +5 -91
- package/index.js +4425 -3529
- package/package.json +1 -1
- package/runner.d.ts +2 -1
- package/schemas.d.ts +209 -20
- package/tool-registry.d.ts +60 -3
- package/worker.js +572 -195
package/worker.js
CHANGED
|
@@ -1,23 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import Q, { setLogLevel as I, ExtensionSession as X, registerJsCallBatch as Z } from "../../pkg/extension_js.js";
|
|
2
|
+
import "zod";
|
|
3
|
+
const R = {
|
|
4
|
+
trace: 0,
|
|
5
|
+
debug: 1,
|
|
6
|
+
info: 2,
|
|
7
|
+
warn: 3,
|
|
8
|
+
error: 4,
|
|
9
|
+
none: 5
|
|
10
|
+
}, x = [
|
|
11
|
+
"trace",
|
|
12
|
+
"debug",
|
|
13
|
+
"info",
|
|
14
|
+
"warn",
|
|
15
|
+
"error",
|
|
16
|
+
"none"
|
|
17
|
+
];
|
|
18
|
+
function ee(r) {
|
|
19
|
+
const e = Math.max(0, Math.min(5, Math.round(r)));
|
|
20
|
+
return x[e] ?? "error";
|
|
21
|
+
}
|
|
22
|
+
let $ = "trace", L = null;
|
|
23
|
+
function re(r) {
|
|
24
|
+
$ = r, L && L(R[r]);
|
|
12
25
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
26
|
+
function te(r) {
|
|
27
|
+
L = r, r(R[$]);
|
|
15
28
|
}
|
|
16
|
-
function
|
|
17
|
-
return
|
|
29
|
+
function ne(r) {
|
|
30
|
+
return R[r] >= R[$];
|
|
18
31
|
}
|
|
19
|
-
function
|
|
20
|
-
var
|
|
32
|
+
function H(r, e = "info") {
|
|
33
|
+
var n;
|
|
21
34
|
if (r === null) return "null";
|
|
22
35
|
if (r === void 0) return "undefined";
|
|
23
36
|
if (typeof r == "string") return r;
|
|
@@ -25,151 +38,507 @@ function k(r, e = "info") {
|
|
|
25
38
|
return String(r);
|
|
26
39
|
if (typeof r == "bigint") return `${r}n`;
|
|
27
40
|
if (r instanceof Error) {
|
|
28
|
-
const
|
|
41
|
+
const t = e === "debug" || e === "trace" ? r.stack : (n = r.stack) == null ? void 0 : n.split(`
|
|
29
42
|
`)[0];
|
|
30
|
-
return JSON.stringify({ message: r.message, name: r.name, stack:
|
|
43
|
+
return JSON.stringify({ message: r.message, name: r.name, stack: t });
|
|
31
44
|
}
|
|
32
45
|
if (typeof r == "function") return "[Function]";
|
|
33
46
|
if (typeof r == "symbol") return String(r);
|
|
34
47
|
if (typeof r == "object")
|
|
35
48
|
try {
|
|
36
49
|
return JSON.stringify(r);
|
|
37
|
-
} catch (
|
|
38
|
-
return
|
|
50
|
+
} catch (t) {
|
|
51
|
+
return t instanceof TypeError && t.message.includes("circular") ? "[Circular]" : `[Unserializable: ${t instanceof Error ? t.message : String(t)}]`;
|
|
39
52
|
}
|
|
40
53
|
return String(r);
|
|
41
54
|
}
|
|
42
|
-
function
|
|
55
|
+
function se(r) {
|
|
43
56
|
return `[extension-js][${r}]`;
|
|
44
57
|
}
|
|
45
|
-
function
|
|
58
|
+
function oe(r, e) {
|
|
46
59
|
if (!r) return "";
|
|
47
|
-
const
|
|
60
|
+
const n = [];
|
|
48
61
|
try {
|
|
49
|
-
for (const [
|
|
50
|
-
|
|
62
|
+
for (const [t, s] of Object.entries(r))
|
|
63
|
+
n.push(`${t}=${H(s, e)}`);
|
|
51
64
|
} catch {
|
|
52
65
|
return " metadata=[unreadable]";
|
|
53
66
|
}
|
|
54
|
-
return
|
|
67
|
+
return n.length > 0 ? ` ${n.join(" ")}` : "";
|
|
55
68
|
}
|
|
56
|
-
function
|
|
69
|
+
function b(r, e) {
|
|
57
70
|
return e.length === 0 ? { event: r } : e.length === 1 && typeof e[0] == "object" && e[0] !== null && !Array.isArray(e[0]) ? { event: r, metadata: e[0] } : {
|
|
58
71
|
event: r,
|
|
59
|
-
metadata: { _args: e.map((
|
|
72
|
+
metadata: { _args: e.map((n) => H(n)).join(" ") }
|
|
60
73
|
};
|
|
61
74
|
}
|
|
62
|
-
class
|
|
75
|
+
class P {
|
|
63
76
|
constructor(e = "root") {
|
|
64
77
|
this.namespace = e;
|
|
65
78
|
}
|
|
66
|
-
log(e,
|
|
79
|
+
log(e, n, t) {
|
|
67
80
|
try {
|
|
68
|
-
if (
|
|
69
|
-
const
|
|
81
|
+
if (!ne(e)) return;
|
|
82
|
+
const s = se(this.namespace), o = oe(t, e), i = `${s} ${n}${o}`;
|
|
70
83
|
switch (e) {
|
|
84
|
+
case "trace":
|
|
71
85
|
case "debug":
|
|
72
|
-
console.log(c);
|
|
73
|
-
break;
|
|
74
86
|
case "info":
|
|
75
|
-
console.log(
|
|
87
|
+
console.log(i);
|
|
76
88
|
break;
|
|
77
89
|
case "warn":
|
|
78
|
-
console.warn(
|
|
90
|
+
console.warn(i);
|
|
79
91
|
break;
|
|
80
92
|
case "error":
|
|
81
|
-
console.error(
|
|
93
|
+
console.error(i);
|
|
82
94
|
break;
|
|
83
95
|
case "none":
|
|
84
96
|
break;
|
|
85
97
|
default: {
|
|
86
|
-
const
|
|
98
|
+
const a = e;
|
|
87
99
|
break;
|
|
88
100
|
}
|
|
89
101
|
}
|
|
90
102
|
} catch {
|
|
91
103
|
}
|
|
92
104
|
}
|
|
93
|
-
|
|
94
|
-
const { event:
|
|
95
|
-
this.log("
|
|
105
|
+
trace(e, ...n) {
|
|
106
|
+
const { event: t, metadata: s } = b(e, n);
|
|
107
|
+
this.log("trace", t, s);
|
|
96
108
|
}
|
|
97
|
-
|
|
98
|
-
const { event:
|
|
99
|
-
this.log("
|
|
109
|
+
debug(e, ...n) {
|
|
110
|
+
const { event: t, metadata: s } = b(e, n);
|
|
111
|
+
this.log("debug", t, s);
|
|
100
112
|
}
|
|
101
|
-
|
|
102
|
-
const { event:
|
|
103
|
-
this.log("
|
|
113
|
+
info(e, ...n) {
|
|
114
|
+
const { event: t, metadata: s } = b(e, n);
|
|
115
|
+
this.log("info", t, s);
|
|
104
116
|
}
|
|
105
|
-
|
|
106
|
-
const { event:
|
|
107
|
-
this.log("
|
|
117
|
+
warn(e, ...n) {
|
|
118
|
+
const { event: t, metadata: s } = b(e, n);
|
|
119
|
+
this.log("warn", t, s);
|
|
120
|
+
}
|
|
121
|
+
error(e, ...n) {
|
|
122
|
+
const { event: t, metadata: s } = b(e, n);
|
|
123
|
+
this.log("error", t, s);
|
|
108
124
|
}
|
|
109
125
|
child(e) {
|
|
110
|
-
return new
|
|
126
|
+
return new P(`${this.namespace}.${e}`);
|
|
111
127
|
}
|
|
112
|
-
timer(e,
|
|
113
|
-
const
|
|
114
|
-
return (
|
|
128
|
+
timer(e, n, t = "info") {
|
|
129
|
+
const s = typeof performance < "u" && performance.now, o = s ? performance.now() : Date.now();
|
|
130
|
+
return (i) => {
|
|
115
131
|
try {
|
|
116
|
-
const
|
|
117
|
-
...
|
|
118
|
-
...
|
|
119
|
-
duration_ms:
|
|
132
|
+
const a = s ? performance.now() : Date.now(), g = Math.round(a - o), p = {
|
|
133
|
+
...n,
|
|
134
|
+
...i,
|
|
135
|
+
duration_ms: g
|
|
120
136
|
};
|
|
121
|
-
this.log(
|
|
137
|
+
this.log(t, e, p);
|
|
122
138
|
} catch {
|
|
123
139
|
}
|
|
124
140
|
};
|
|
125
141
|
}
|
|
126
142
|
}
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
143
|
+
const l = new P("root"), ae = /* @__PURE__ */ new Set([
|
|
144
|
+
"page_url",
|
|
145
|
+
"page_title",
|
|
146
|
+
"page_click",
|
|
147
|
+
"page_fill",
|
|
148
|
+
"page_type",
|
|
149
|
+
"page_append",
|
|
150
|
+
"page_press",
|
|
151
|
+
"page_select",
|
|
152
|
+
"page_check",
|
|
153
|
+
"page_hover",
|
|
154
|
+
"page_unhover",
|
|
155
|
+
"page_scroll",
|
|
156
|
+
"page_scroll_to",
|
|
157
|
+
"page_dblclick",
|
|
158
|
+
"page_back",
|
|
159
|
+
"tab_click",
|
|
160
|
+
"tab_fill",
|
|
161
|
+
"tab_type",
|
|
162
|
+
"tab_press",
|
|
163
|
+
"tab_select",
|
|
164
|
+
"tab_check",
|
|
165
|
+
"tab_hover",
|
|
166
|
+
"tab_unhover",
|
|
167
|
+
"tab_scroll",
|
|
168
|
+
"tab_scroll_to",
|
|
169
|
+
"tab_dblclick",
|
|
170
|
+
"tab_back"
|
|
171
|
+
]);
|
|
172
|
+
function ie(r) {
|
|
173
|
+
return ae.has(r);
|
|
174
|
+
}
|
|
175
|
+
const le = /* @__PURE__ */ new Map();
|
|
176
|
+
function ce(r, e) {
|
|
177
|
+
le.set(r, e);
|
|
178
|
+
}
|
|
179
|
+
function ue(r) {
|
|
180
|
+
return r.startsWith("tab_") ? "required" : "active";
|
|
181
|
+
}
|
|
182
|
+
function de(r) {
|
|
183
|
+
return r === "content-script" ? "content-script" : r === "main-thread" ? "main-thread" : r === "worker" ? "worker:default" : r.startsWith("worker:") ? r : "main-thread";
|
|
184
|
+
}
|
|
185
|
+
function fe(r, e) {
|
|
186
|
+
return e !== "main-thread" ? e : ie(r) ? "content-script" : e;
|
|
187
|
+
}
|
|
188
|
+
function ge(r, e) {
|
|
189
|
+
return {
|
|
190
|
+
endpoint: de(fe(r, e)),
|
|
191
|
+
tabPolicy: ue(r)
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function pe(r) {
|
|
195
|
+
for (const e of r)
|
|
196
|
+
ce(e.action, ge(e.action, e.owner));
|
|
197
|
+
}
|
|
198
|
+
function T(r) {
|
|
199
|
+
return r == null ? {} : r instanceof Map ? Object.fromEntries(
|
|
200
|
+
[...r.entries()].map(([e, n]) => [e, T(n)])
|
|
201
|
+
) : Array.isArray(r) ? r.map(T) : r;
|
|
202
|
+
}
|
|
203
|
+
function me(r) {
|
|
204
|
+
return {
|
|
205
|
+
action: r.action,
|
|
206
|
+
namespace: r.namespace,
|
|
207
|
+
name: r.name,
|
|
208
|
+
publicName: r.publicName,
|
|
209
|
+
description: r.description,
|
|
210
|
+
fields: r.fields,
|
|
211
|
+
aliases: (r.aliases ?? []).map((e) => ({
|
|
212
|
+
namespace: e.namespace,
|
|
213
|
+
name: e.name,
|
|
214
|
+
fields: e.fields
|
|
215
|
+
})),
|
|
216
|
+
paramsDoc: r.paramsDoc.map((e) => ({
|
|
217
|
+
name: e.name,
|
|
218
|
+
type: e.type,
|
|
219
|
+
required: e.required,
|
|
220
|
+
description: e.description
|
|
221
|
+
})),
|
|
222
|
+
returnsDoc: {
|
|
223
|
+
type: r.returnsDoc.type,
|
|
224
|
+
description: r.returnsDoc.description
|
|
225
|
+
},
|
|
226
|
+
errorCode: r.errorCode,
|
|
227
|
+
errorCategory: r.errorCategory ?? null,
|
|
228
|
+
permission: r.permission ?? null,
|
|
229
|
+
example: r.example ?? null
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
l.child("tool-registry");
|
|
233
|
+
let y = null, v = !1;
|
|
234
|
+
const _ = /* @__PURE__ */ new Map();
|
|
235
|
+
function A(r, e) {
|
|
236
|
+
try {
|
|
237
|
+
return r.postMessage(e), !0;
|
|
238
|
+
} catch (n) {
|
|
239
|
+
const t = n instanceof Error ? n.message : String(n);
|
|
240
|
+
return l.error("port_post_failed", { error: t }), !1;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const z = 1e3;
|
|
244
|
+
function J(r, e, n) {
|
|
245
|
+
e === "main-thread" || e === "content-script" ? A(n, { type: "relayCancel", id: r, owner: e }) : A(n, { type: "registryCallCancel", id: r });
|
|
246
|
+
}
|
|
247
|
+
function G(r, e) {
|
|
248
|
+
for (const [n, t] of _)
|
|
249
|
+
clearTimeout(t.timeoutId), J(n, t.owner, t.port), t.settle({
|
|
250
|
+
ok: !1,
|
|
251
|
+
error: { message: e, code: r }
|
|
252
|
+
}), _.delete(n);
|
|
253
|
+
}
|
|
254
|
+
const S = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
|
|
255
|
+
let q = Promise.resolve(), d = null;
|
|
256
|
+
function ye(r) {
|
|
257
|
+
l.trace("sessionQueue_enqueue");
|
|
258
|
+
const e = q.then(r);
|
|
259
|
+
return q = e.then(
|
|
260
|
+
() => {
|
|
261
|
+
},
|
|
262
|
+
() => {
|
|
263
|
+
}
|
|
264
|
+
), e;
|
|
265
|
+
}
|
|
266
|
+
function Y(r) {
|
|
267
|
+
d && (l.error("runCell_worker_failure", {
|
|
268
|
+
runId: d.runId,
|
|
269
|
+
callId: d.id,
|
|
270
|
+
error: r
|
|
271
|
+
}), self.postMessage({
|
|
272
|
+
type: "error",
|
|
273
|
+
id: d.id,
|
|
274
|
+
error: r,
|
|
275
|
+
runId: d.runId
|
|
276
|
+
}), d = null);
|
|
277
|
+
}
|
|
278
|
+
self.addEventListener("error", (r) => {
|
|
279
|
+
const e = r.message || (r.error instanceof Error ? r.error.message : "Worker uncaught error");
|
|
280
|
+
l.error("worker_uncaught_error", { error: e }), Y(e);
|
|
165
281
|
});
|
|
282
|
+
self.addEventListener("unhandledrejection", (r) => {
|
|
283
|
+
const e = r.reason, n = e instanceof Error ? e.message : String(e ?? "Unhandled rejection");
|
|
284
|
+
l.error("worker_unhandled_rejection", { error: n }), Y(n);
|
|
285
|
+
});
|
|
286
|
+
function c(r, e) {
|
|
287
|
+
S.set(r, e);
|
|
288
|
+
}
|
|
289
|
+
function _e() {
|
|
290
|
+
const r = new Uint8Array(16);
|
|
291
|
+
return crypto.getRandomValues(r), Array.from(r, (e) => e.toString(16).padStart(2, "0")).join("");
|
|
292
|
+
}
|
|
293
|
+
function be(r) {
|
|
294
|
+
return ee(r);
|
|
295
|
+
}
|
|
296
|
+
const O = /* @__PURE__ */ new Map(), M = /* @__PURE__ */ new Map();
|
|
297
|
+
function he(r, e) {
|
|
298
|
+
var n;
|
|
299
|
+
if (O.has(r))
|
|
300
|
+
throw new Error(`Worker port already registered for owner: ${r}`);
|
|
301
|
+
if (typeof e.addEventListener != "function")
|
|
302
|
+
throw new Error(`Worker port for owner "${r}" cannot receive responses`);
|
|
303
|
+
O.set(r, e), e.addEventListener("message", async (t) => {
|
|
304
|
+
var o;
|
|
305
|
+
const s = t.data;
|
|
306
|
+
if (s !== null && (s.type === "asyncRelayResult" || s.type === "registryCallResult") && typeof s.id == "string") {
|
|
307
|
+
N(s.id, s.result);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if (s !== null && s.type === "registryCallCancel" && typeof s.id == "string") {
|
|
311
|
+
(o = M.get(s.id)) == null || o.abort(), M.delete(s.id);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (s !== null && s.type === "registryCall" && typeof s.id == "string" && typeof s.action == "string") {
|
|
315
|
+
const i = s.id, a = new AbortController();
|
|
316
|
+
M.set(i, a);
|
|
317
|
+
const g = S.get(s.action);
|
|
318
|
+
let p;
|
|
319
|
+
if (!g)
|
|
320
|
+
p = {
|
|
321
|
+
ok: !1,
|
|
322
|
+
error: { message: `Unknown worker action: ${s.action}`, code: "E_UNKNOWN" }
|
|
323
|
+
};
|
|
324
|
+
else
|
|
325
|
+
try {
|
|
326
|
+
const u = await g(s.params, {
|
|
327
|
+
action: s.action,
|
|
328
|
+
callId: s.callId,
|
|
329
|
+
runId: s.runId,
|
|
330
|
+
signal: a.signal
|
|
331
|
+
});
|
|
332
|
+
p = a.signal.aborted ? { ok: !1, error: { message: "Relay aborted", code: "E_ABORT" } } : { ok: !0, value: u };
|
|
333
|
+
} catch (u) {
|
|
334
|
+
p = {
|
|
335
|
+
ok: !1,
|
|
336
|
+
error: {
|
|
337
|
+
message: u instanceof Error ? u.message : String(u),
|
|
338
|
+
code: a.signal.aborted ? "E_ABORT" : "E_WORKER_HANDLER"
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
M.delete(i), A(e, { type: "registryCallResult", id: i, result: p }) || N(i, {
|
|
343
|
+
ok: !1,
|
|
344
|
+
error: { message: "Failed to deliver worker handler response", code: "E_PORT" }
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
}), (n = e.start) == null || n.call(e);
|
|
348
|
+
}
|
|
349
|
+
function N(r, e) {
|
|
350
|
+
l.trace("resolveAsyncRelayResult", { id: r });
|
|
351
|
+
const n = _.get(r);
|
|
352
|
+
return n ? (n.settle(e), !0) : (l.warn("asyncRelayResult_no_pending_relay", { id: r }), !1);
|
|
353
|
+
}
|
|
354
|
+
function Ee(r) {
|
|
355
|
+
if (r === "main-thread" || r === "content-script")
|
|
356
|
+
return self;
|
|
357
|
+
const e = O.get(r);
|
|
358
|
+
return e || null;
|
|
359
|
+
}
|
|
360
|
+
function we(r) {
|
|
361
|
+
const { owner: e, action: n, tabPolicy: t, resolveTimeoutMs: s } = r, o = r.timeoutMs ?? h;
|
|
362
|
+
return (i, a) => {
|
|
363
|
+
l.trace("safePostAsCall_invoke", { owner: e, action: n, callId: a == null ? void 0 : a.callId, runId: a == null ? void 0 : a.runId });
|
|
364
|
+
const g = (s == null ? void 0 : s(i)) ?? o;
|
|
365
|
+
return new Promise((p, u) => {
|
|
366
|
+
var j;
|
|
367
|
+
if ((j = a == null ? void 0 : a.signal) != null && j.aborted) {
|
|
368
|
+
const f = new Error(`Relay aborted for action: ${n}`);
|
|
369
|
+
f.code = "E_ABORT", u(f);
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
const E = Ee(e);
|
|
373
|
+
if (!E) {
|
|
374
|
+
u(new Error(`No port available for action: ${n}`));
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
if (_.size >= z) {
|
|
378
|
+
u(new Error(
|
|
379
|
+
`Too many pending calls (${z} limit exceeded). Action: ${n}`
|
|
380
|
+
));
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
const w = _e();
|
|
384
|
+
let W = !1;
|
|
385
|
+
const k = (f) => {
|
|
386
|
+
W || (W = !0, clearTimeout(U), a != null && a.signal && a.signal.removeEventListener("abort", C), _.delete(w), f());
|
|
387
|
+
}, D = () => {
|
|
388
|
+
J(w, e, E);
|
|
389
|
+
}, C = () => {
|
|
390
|
+
D();
|
|
391
|
+
const f = new Error(`Relay aborted for action: ${n}`);
|
|
392
|
+
f.code = "E_ABORT", k(() => u(f));
|
|
393
|
+
};
|
|
394
|
+
a != null && a.signal && a.signal.addEventListener("abort", C);
|
|
395
|
+
const U = setTimeout(() => {
|
|
396
|
+
D(), k(() => u(new Error(`Relay timeout for action: ${n}`)));
|
|
397
|
+
}, g);
|
|
398
|
+
_.set(w, {
|
|
399
|
+
settle: (f) => k(() => p(f)),
|
|
400
|
+
timeoutId: U,
|
|
401
|
+
abort: C,
|
|
402
|
+
owner: e,
|
|
403
|
+
port: E
|
|
404
|
+
});
|
|
405
|
+
const F = a == null ? void 0 : a.runId, B = a == null ? void 0 : a.callId;
|
|
406
|
+
A(E, {
|
|
407
|
+
type: e === "main-thread" || e === "content-script" ? "asyncRelay" : "registryCall",
|
|
408
|
+
id: w,
|
|
409
|
+
owner: e,
|
|
410
|
+
action: n,
|
|
411
|
+
params: i,
|
|
412
|
+
callId: B,
|
|
413
|
+
tabPolicy: t,
|
|
414
|
+
command: { action: n, params: i, runId: F, callId: B },
|
|
415
|
+
runId: F
|
|
416
|
+
}) || k(() => u(new Error(`Failed to post relay for action: ${n}`)));
|
|
417
|
+
});
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
const ke = "worker", h = 3e4, V = 5e3, Me = 500, Re = {
|
|
421
|
+
page_goto: "timeout",
|
|
422
|
+
page_wait_for: "timeout",
|
|
423
|
+
tab_wait_for_load: "timeout",
|
|
424
|
+
fetch: "timeout",
|
|
425
|
+
sleep: "duration",
|
|
426
|
+
page_wait: "duration",
|
|
427
|
+
sidepanel_wait: "duration"
|
|
428
|
+
}, K = /* @__PURE__ */ new Set(["page_goto"]);
|
|
429
|
+
function Te(r, e) {
|
|
430
|
+
if (r === null || typeof r != "object" || Array.isArray(r))
|
|
431
|
+
return null;
|
|
432
|
+
const n = r[e];
|
|
433
|
+
return typeof n == "bigint" ? Number(n) : typeof n == "number" && Number.isFinite(n) ? n : null;
|
|
434
|
+
}
|
|
435
|
+
function Ae(r, e) {
|
|
436
|
+
return K.has(r) ? e * 2 + Me + V : e + V;
|
|
437
|
+
}
|
|
438
|
+
function Se(r, e) {
|
|
439
|
+
const n = Re[r];
|
|
440
|
+
if (!n) return h;
|
|
441
|
+
let t = Te(e, n);
|
|
442
|
+
return t === null && K.has(r) && (t = h), t === null ? h : Math.max(
|
|
443
|
+
h,
|
|
444
|
+
Ae(r, t)
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
function Ce(r) {
|
|
448
|
+
if (r.owner === ke) {
|
|
449
|
+
const e = S.get(r.action);
|
|
450
|
+
if (!e)
|
|
451
|
+
throw new Error(
|
|
452
|
+
`No worker-local handler registered for action: ${r.action}`
|
|
453
|
+
);
|
|
454
|
+
return async (n, t) => {
|
|
455
|
+
var o;
|
|
456
|
+
n = T(n);
|
|
457
|
+
const s = (t == null ? void 0 : t.signal) ?? (t != null && t.runId ? (o = m.get(t.runId)) == null ? void 0 : o.signal : void 0);
|
|
458
|
+
try {
|
|
459
|
+
return { ok: !0, value: await e(n, { ...t, action: r.action, signal: s }) };
|
|
460
|
+
} catch (i) {
|
|
461
|
+
const a = i instanceof Error ? i.message : String(i), g = typeof i == "object" && i !== null && "code" in i && typeof i.code == "string" ? i.code : r.errorCode;
|
|
462
|
+
return { ok: !1, error: { message: a, code: g } };
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
} else {
|
|
466
|
+
const e = we({
|
|
467
|
+
owner: r.owner,
|
|
468
|
+
action: r.action,
|
|
469
|
+
resolveTimeoutMs: (n) => Se(r.action, n)
|
|
470
|
+
});
|
|
471
|
+
return (n, t) => {
|
|
472
|
+
var s;
|
|
473
|
+
return e(T(n), {
|
|
474
|
+
...t,
|
|
475
|
+
signal: (t == null ? void 0 : t.signal) ?? (t != null && t.runId ? (s = m.get(t.runId)) == null ? void 0 : s.signal : void 0)
|
|
476
|
+
});
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
function Ie(r) {
|
|
481
|
+
c("exists", (e) => r.fsExists(e)), c("stat", (e) => r.fsStat(e)), c("read", (e) => r.fsRead(e)), c("readText", (e) => r.fsReadText(e)), c("readBase64", (e) => r.fsReadBase64(e)), c("list", (e) => r.fsList(e)), c("mkdir", (e) => r.fsMkdir(e)), c("delete", (e) => r.fsDelete(e)), c("copy", (e) => r.fsCopy(e)), c("move", (e) => r.fsMove(e)), c("write", (e) => r.fsWrite(e)), c("writeText", (e) => r.fsWriteText(e)), c("writeBase64", (e) => r.fsWriteBase64(e)), c("append", (e) => r.fsAppend(e)), c("appendText", (e) => r.fsAppendText(e)), c("appendBase64", (e) => r.fsAppendBase64(e)), c("readRange", (e) => r.fsReadRange(e)), c("update", (e) => r.fsUpdate(e)), c("hash", (e) => r.fsHash(e));
|
|
482
|
+
}
|
|
483
|
+
async function Le(r, e) {
|
|
484
|
+
if (v) return;
|
|
485
|
+
await Q(), y = new X(), I(0), te(I), l.trace("initWasm_start"), Ie(y), pe(r);
|
|
486
|
+
const t = r.map((o) => ({
|
|
487
|
+
entry: me(o),
|
|
488
|
+
callback: Ce(o)
|
|
489
|
+
}));
|
|
490
|
+
try {
|
|
491
|
+
Z(t);
|
|
492
|
+
} catch (o) {
|
|
493
|
+
const i = o instanceof Error ? o.message : String(o);
|
|
494
|
+
throw new Error(`Registry registration failed: ${i}`);
|
|
495
|
+
}
|
|
496
|
+
const { freezeManifest: s } = await import("../../pkg/extension_js.js");
|
|
497
|
+
try {
|
|
498
|
+
s();
|
|
499
|
+
} catch (o) {
|
|
500
|
+
const i = o instanceof Error ? o.message : String(o);
|
|
501
|
+
throw new Error(`Manifest freeze failed: ${i}`);
|
|
502
|
+
}
|
|
503
|
+
if (y.injectRegistryBindings(), e) {
|
|
504
|
+
const o = JSON.stringify(e);
|
|
505
|
+
await y.runCellAsync(
|
|
506
|
+
`(function(){var r=globalThis.chrome&&globalThis.chrome.runtime;if(!r){r={};if(!globalThis.chrome)globalThis.chrome={};globalThis.chrome.runtime=r;}r.id=${o};})();`,
|
|
507
|
+
"",
|
|
508
|
+
"inject-runtime-id"
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
v = !0, l.trace("initWasm_done");
|
|
512
|
+
}
|
|
166
513
|
self.onmessage = async (r) => {
|
|
167
514
|
const e = r.data;
|
|
515
|
+
if (l.trace("onmessage", { type: e.type, id: "id" in e ? e.id : void 0 }), e.type === "asyncRelayResult") {
|
|
516
|
+
l.trace("asyncRelayResult", { id: e.id }), N(e.id, e.result);
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
if (e.type === "registerWorkerPort") {
|
|
520
|
+
const t = r.ports[0];
|
|
521
|
+
if (!t) {
|
|
522
|
+
l.error("register_worker_port_missing", { owner: e.owner });
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
he(e.owner, t);
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
if (e.type === "init") {
|
|
529
|
+
try {
|
|
530
|
+
await Le(e.manifest, e.extensionId), self.postMessage({ type: "ready" });
|
|
531
|
+
} catch (t) {
|
|
532
|
+
const s = t instanceof Error ? t.message : String(t);
|
|
533
|
+
l.error("worker_init_failed", { error: s }), self.postMessage({ type: "error", error: `WASM init failed: ${s}` });
|
|
534
|
+
}
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
168
537
|
if (e.type === "setLogLevel") {
|
|
169
|
-
|
|
538
|
+
I(e.level), re(be(e.level)), l.trace("set_log_level", { level: e.level });
|
|
170
539
|
return;
|
|
171
540
|
}
|
|
172
|
-
if (!
|
|
541
|
+
if (!v || !y) {
|
|
173
542
|
self.postMessage({
|
|
174
543
|
type: "error",
|
|
175
544
|
id: e.id,
|
|
@@ -177,111 +546,119 @@ self.onmessage = async (r) => {
|
|
|
177
546
|
});
|
|
178
547
|
return;
|
|
179
548
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const t =
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
549
|
+
const n = y;
|
|
550
|
+
await ye(async () => {
|
|
551
|
+
switch (e.type) {
|
|
552
|
+
case "runCell": {
|
|
553
|
+
const t = e.runId, s = new AbortController();
|
|
554
|
+
t && m.set(t, s), d = { id: e.id, runId: t }, l.trace("runCell_start", { runId: t, callId: e.id, codeLen: e.code.length });
|
|
555
|
+
try {
|
|
556
|
+
const o = await n.runCellAsync(
|
|
557
|
+
e.code,
|
|
558
|
+
e.stdin || "",
|
|
559
|
+
t || ""
|
|
560
|
+
);
|
|
561
|
+
l.trace("runCell_done", { runId: t, callId: e.id, status: o.status }), self.postMessage({
|
|
562
|
+
type: "result",
|
|
563
|
+
id: e.id,
|
|
564
|
+
data: o,
|
|
565
|
+
runId: t
|
|
566
|
+
});
|
|
567
|
+
} catch (o) {
|
|
568
|
+
const i = o instanceof Error ? o.message : String(o);
|
|
569
|
+
l.error("runCell_error", { runId: t, error: i }), self.postMessage({
|
|
570
|
+
type: "error",
|
|
571
|
+
id: e.id,
|
|
572
|
+
error: i,
|
|
573
|
+
runId: t
|
|
574
|
+
});
|
|
575
|
+
} finally {
|
|
576
|
+
(d == null ? void 0 : d.id) === e.id && (d = null), t && m.delete(t);
|
|
577
|
+
}
|
|
578
|
+
break;
|
|
206
579
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
580
|
+
case "reset": {
|
|
581
|
+
n.setAborted(!0);
|
|
582
|
+
for (const t of m.values()) t.abort();
|
|
583
|
+
m.clear(), G("E_RESET", "Worker reset");
|
|
584
|
+
try {
|
|
585
|
+
n.reset(), self.postMessage({ type: "result", id: e.id, data: { ok: !0 } });
|
|
586
|
+
} catch (t) {
|
|
587
|
+
const s = t instanceof Error ? t.message : String(t);
|
|
588
|
+
self.postMessage({ type: "error", id: e.id, error: s });
|
|
589
|
+
}
|
|
590
|
+
break;
|
|
215
591
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
592
|
+
case "stop": {
|
|
593
|
+
n.setAborted(!0);
|
|
594
|
+
for (const t of m.values()) t.abort();
|
|
595
|
+
m.clear(), G("E_STOPPED", "Worker stopped"), self.postMessage({ type: "result", id: e.id, data: { ok: !0 } });
|
|
596
|
+
break;
|
|
597
|
+
}
|
|
598
|
+
case "setFuelLimit": {
|
|
599
|
+
try {
|
|
600
|
+
n.set_fuel_limit(e.limit), e.id && self.postMessage({ type: "result", id: e.id, data: { ok: !0 } });
|
|
601
|
+
} catch (t) {
|
|
602
|
+
if (e.id) {
|
|
603
|
+
const s = t instanceof Error ? t.message : String(t);
|
|
604
|
+
self.postMessage({ type: "error", id: e.id, error: s });
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
break;
|
|
608
|
+
}
|
|
609
|
+
case "inspectGlobals": {
|
|
610
|
+
try {
|
|
611
|
+
const t = n.inspect_globals();
|
|
612
|
+
self.postMessage({ type: "result", id: e.id, data: t });
|
|
613
|
+
} catch (t) {
|
|
232
614
|
const s = t instanceof Error ? t.message : String(t);
|
|
233
615
|
self.postMessage({ type: "error", id: e.id, error: s });
|
|
234
616
|
}
|
|
617
|
+
break;
|
|
235
618
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
619
|
+
case "apiDocs": {
|
|
620
|
+
try {
|
|
621
|
+
const t = n.apiDocs(e.format);
|
|
622
|
+
self.postMessage({ type: "result", id: e.id, data: t });
|
|
623
|
+
} catch (t) {
|
|
624
|
+
const s = t instanceof Error ? t.message : String(t);
|
|
625
|
+
self.postMessage({ type: "error", id: e.id, error: s });
|
|
626
|
+
}
|
|
627
|
+
break;
|
|
245
628
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
629
|
+
case "loadLibrary": {
|
|
630
|
+
try {
|
|
631
|
+
const t = n.load_library(e.source);
|
|
632
|
+
self.postMessage({ type: "result", id: e.id, data: t });
|
|
633
|
+
} catch (t) {
|
|
634
|
+
const s = t instanceof Error ? t.message : String(t);
|
|
635
|
+
self.postMessage({ type: "error", id: e.id, error: s });
|
|
636
|
+
}
|
|
637
|
+
break;
|
|
255
638
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
639
|
+
case "fsCall": {
|
|
640
|
+
const t = S.get(e.action);
|
|
641
|
+
if (!t) {
|
|
642
|
+
self.postMessage({
|
|
643
|
+
type: "error",
|
|
644
|
+
id: e.id,
|
|
645
|
+
error: `Unknown fs action: ${e.action}`
|
|
646
|
+
});
|
|
647
|
+
break;
|
|
648
|
+
}
|
|
649
|
+
try {
|
|
650
|
+
const s = await t(e.params);
|
|
651
|
+
self.postMessage({ type: "result", id: e.id, data: s });
|
|
652
|
+
} catch (s) {
|
|
653
|
+
const o = s instanceof Error ? s.message : String(s);
|
|
654
|
+
self.postMessage({ type: "error", id: e.id, error: o });
|
|
655
|
+
}
|
|
266
656
|
break;
|
|
267
657
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
} catch (s) {
|
|
272
|
-
const o = s instanceof Error ? s.message : String(s);
|
|
273
|
-
self.postMessage({ type: "error", id: e.id, error: o });
|
|
658
|
+
default: {
|
|
659
|
+
l.error("unhandled_worker_message", { type: e.type });
|
|
660
|
+
break;
|
|
274
661
|
}
|
|
275
|
-
break;
|
|
276
662
|
}
|
|
277
|
-
|
|
278
|
-
f.debug("asyncRelayResult", {
|
|
279
|
-
id: e.id,
|
|
280
|
-
resultType: typeof e.result
|
|
281
|
-
});
|
|
282
|
-
const t = d.get(e.id);
|
|
283
|
-
t ? (d.delete(e.id), t(e.result)) : f.warn("asyncRelayResult_no_pending_relay", { id: e.id });
|
|
284
|
-
break;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
663
|
+
});
|
|
287
664
|
};
|