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