@pi-oxide/extension-js 0.2.0 → 0.2.2
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 +44 -0
- package/extension_js.js +62949 -1175
- package/generated.d.ts +208 -0
- package/index.d.ts +92 -0
- package/index.js +5646 -0
- package/logger.d.ts +16 -0
- package/package.json +12 -5
- package/runner.d.ts +16 -0
- package/schemas.d.ts +505 -0
- package/tool-registry.d.ts +58 -0
- package/worker.js +287 -0
- package/extension_js_bg.wasm +0 -0
package/worker.js
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import R, { setLogLevel as y, ExtensionSession as _ } from "./extension_js.js";
|
|
2
|
+
const g = {
|
|
3
|
+
debug: 0,
|
|
4
|
+
info: 1,
|
|
5
|
+
warn: 2,
|
|
6
|
+
error: 3,
|
|
7
|
+
none: 4
|
|
8
|
+
};
|
|
9
|
+
let u = "error", m = null;
|
|
10
|
+
function E(r) {
|
|
11
|
+
u = r, m && m(g[r]);
|
|
12
|
+
}
|
|
13
|
+
function x(r) {
|
|
14
|
+
m = r, u !== "error" && r(g[u]);
|
|
15
|
+
}
|
|
16
|
+
function $(r) {
|
|
17
|
+
return g[r] >= g[u];
|
|
18
|
+
}
|
|
19
|
+
function k(r, e = "info") {
|
|
20
|
+
var t;
|
|
21
|
+
if (r === null) return "null";
|
|
22
|
+
if (r === void 0) return "undefined";
|
|
23
|
+
if (typeof r == "string") return r;
|
|
24
|
+
if (typeof r == "number" || typeof r == "boolean")
|
|
25
|
+
return String(r);
|
|
26
|
+
if (typeof r == "bigint") return `${r}n`;
|
|
27
|
+
if (r instanceof Error) {
|
|
28
|
+
const s = e === "debug" ? r.stack : (t = r.stack) == null ? void 0 : t.split(`
|
|
29
|
+
`)[0];
|
|
30
|
+
return JSON.stringify({ message: r.message, name: r.name, stack: s });
|
|
31
|
+
}
|
|
32
|
+
if (typeof r == "function") return "[Function]";
|
|
33
|
+
if (typeof r == "symbol") return String(r);
|
|
34
|
+
if (typeof r == "object")
|
|
35
|
+
try {
|
|
36
|
+
return JSON.stringify(r);
|
|
37
|
+
} catch (s) {
|
|
38
|
+
return s instanceof TypeError && s.message.includes("circular") ? "[Circular]" : `[Unserializable: ${s instanceof Error ? s.message : String(s)}]`;
|
|
39
|
+
}
|
|
40
|
+
return String(r);
|
|
41
|
+
}
|
|
42
|
+
function I(r) {
|
|
43
|
+
return `[extension-js][${r}]`;
|
|
44
|
+
}
|
|
45
|
+
function A(r, e) {
|
|
46
|
+
if (!r) return "";
|
|
47
|
+
const t = [];
|
|
48
|
+
try {
|
|
49
|
+
for (const [s, o] of Object.entries(r))
|
|
50
|
+
t.push(`${s}=${k(o, e)}`);
|
|
51
|
+
} catch {
|
|
52
|
+
return " metadata=[unreadable]";
|
|
53
|
+
}
|
|
54
|
+
return t.length > 0 ? ` ${t.join(" ")}` : "";
|
|
55
|
+
}
|
|
56
|
+
function l(r, e) {
|
|
57
|
+
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
|
+
event: r,
|
|
59
|
+
metadata: { _args: e.map((t) => k(t)).join(" ") }
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
class h {
|
|
63
|
+
constructor(e = "root") {
|
|
64
|
+
this.namespace = e;
|
|
65
|
+
}
|
|
66
|
+
log(e, t, s) {
|
|
67
|
+
try {
|
|
68
|
+
if (!$(e)) return;
|
|
69
|
+
const o = I(this.namespace), p = A(s, e), c = `${o} ${t}${p}`;
|
|
70
|
+
switch (e) {
|
|
71
|
+
case "debug":
|
|
72
|
+
console.log(c);
|
|
73
|
+
break;
|
|
74
|
+
case "info":
|
|
75
|
+
console.log(c);
|
|
76
|
+
break;
|
|
77
|
+
case "warn":
|
|
78
|
+
console.warn(c);
|
|
79
|
+
break;
|
|
80
|
+
case "error":
|
|
81
|
+
console.error(c);
|
|
82
|
+
break;
|
|
83
|
+
case "none":
|
|
84
|
+
break;
|
|
85
|
+
default: {
|
|
86
|
+
const w = e;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
} catch {
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
debug(e, ...t) {
|
|
94
|
+
const { event: s, metadata: o } = l(e, t);
|
|
95
|
+
this.log("debug", s, o);
|
|
96
|
+
}
|
|
97
|
+
info(e, ...t) {
|
|
98
|
+
const { event: s, metadata: o } = l(e, t);
|
|
99
|
+
this.log("info", s, o);
|
|
100
|
+
}
|
|
101
|
+
warn(e, ...t) {
|
|
102
|
+
const { event: s, metadata: o } = l(e, t);
|
|
103
|
+
this.log("warn", s, o);
|
|
104
|
+
}
|
|
105
|
+
error(e, ...t) {
|
|
106
|
+
const { event: s, metadata: o } = l(e, t);
|
|
107
|
+
this.log("error", s, o);
|
|
108
|
+
}
|
|
109
|
+
child(e) {
|
|
110
|
+
return new h(`${this.namespace}.${e}`);
|
|
111
|
+
}
|
|
112
|
+
timer(e, t, s = "info") {
|
|
113
|
+
const o = typeof performance < "u" && performance.now, p = o ? performance.now() : Date.now();
|
|
114
|
+
return (c) => {
|
|
115
|
+
try {
|
|
116
|
+
const w = o ? performance.now() : Date.now(), S = Math.round(w - p), L = {
|
|
117
|
+
...t,
|
|
118
|
+
...c,
|
|
119
|
+
duration_ms: S
|
|
120
|
+
};
|
|
121
|
+
this.log(s, e, L);
|
|
122
|
+
} catch {
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const f = new h("root");
|
|
128
|
+
let a = null, b = !1;
|
|
129
|
+
const d = /* @__PURE__ */ new Map();
|
|
130
|
+
let i;
|
|
131
|
+
function T() {
|
|
132
|
+
return Math.random().toString(36).slice(2) + Date.now().toString(36);
|
|
133
|
+
}
|
|
134
|
+
function j(r) {
|
|
135
|
+
return r <= 0 ? "debug" : r === 1 ? "info" : r === 2 ? "warn" : r === 3 ? "error" : "none";
|
|
136
|
+
}
|
|
137
|
+
const W = self;
|
|
138
|
+
W.__extension_js_relay = (r) => (f.debug("relay", {
|
|
139
|
+
action: r == null ? void 0 : r.action,
|
|
140
|
+
runId: i
|
|
141
|
+
}), new Promise((e) => {
|
|
142
|
+
const t = T();
|
|
143
|
+
d.set(t, e), self.postMessage({
|
|
144
|
+
type: "asyncRelay",
|
|
145
|
+
id: t,
|
|
146
|
+
command: r,
|
|
147
|
+
runId: i
|
|
148
|
+
});
|
|
149
|
+
}));
|
|
150
|
+
const M = /* @__PURE__ */ new Map();
|
|
151
|
+
function n(r, e) {
|
|
152
|
+
M.set(r, e);
|
|
153
|
+
}
|
|
154
|
+
function B(r) {
|
|
155
|
+
n("exists", (e) => r.fsExists(e)), n("stat", (e) => r.fsStat(e)), n("read", (e) => r.fsRead(e)), n("readText", (e) => r.fsReadText(e)), n("readBase64", (e) => r.fsReadBase64(e)), n("list", (e) => r.fsList(e)), n("mkdir", (e) => r.fsMkdir(e)), n("delete", (e) => r.fsDelete(e)), n("copy", (e) => r.fsCopy(e)), n("move", (e) => r.fsMove(e)), n("write", (e) => r.fsWrite(e)), n("writeText", (e) => r.fsWriteText(e)), n("writeBase64", (e) => r.fsWriteBase64(e)), n("append", (e) => r.fsAppend(e)), n("appendText", (e) => r.fsAppendText(e)), n("appendBase64", (e) => r.fsAppendBase64(e)), n("readRange", (e) => r.fsReadRange(e)), n("update", (e) => r.fsUpdate(e)), n("hash", (e) => r.fsHash(e));
|
|
156
|
+
}
|
|
157
|
+
async function C() {
|
|
158
|
+
b || (await R(), a = new _(), y(3), x(y), B(a), b = !0);
|
|
159
|
+
}
|
|
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
|
+
self.onmessage = async (r) => {
|
|
167
|
+
const e = r.data;
|
|
168
|
+
if (e.type === "setLogLevel") {
|
|
169
|
+
y(e.level), E(j(e.level)), f.debug("set_log_level", { level: e.level });
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (!b || !a) {
|
|
173
|
+
self.postMessage({
|
|
174
|
+
type: "error",
|
|
175
|
+
id: e.id,
|
|
176
|
+
error: "WASM not initialized"
|
|
177
|
+
});
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
switch (e.type) {
|
|
181
|
+
case "runCell": {
|
|
182
|
+
i = e.runId;
|
|
183
|
+
try {
|
|
184
|
+
const t = await a.runCellAsync(
|
|
185
|
+
e.code,
|
|
186
|
+
e.stdin || "",
|
|
187
|
+
e.runId || ""
|
|
188
|
+
// propagate correlation ID to WASM so trace spans can be linked end-to-end
|
|
189
|
+
);
|
|
190
|
+
self.postMessage({
|
|
191
|
+
type: "result",
|
|
192
|
+
id: e.id,
|
|
193
|
+
data: t,
|
|
194
|
+
runId: i
|
|
195
|
+
});
|
|
196
|
+
} catch (t) {
|
|
197
|
+
const s = t instanceof Error ? t.message : String(t);
|
|
198
|
+
f.error("runCell_error", { runId: i, error: s }), self.postMessage({
|
|
199
|
+
type: "error",
|
|
200
|
+
id: e.id,
|
|
201
|
+
error: s,
|
|
202
|
+
runId: i
|
|
203
|
+
});
|
|
204
|
+
} finally {
|
|
205
|
+
i = void 0;
|
|
206
|
+
}
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
case "reset": {
|
|
210
|
+
try {
|
|
211
|
+
a.reset(), self.postMessage({ type: "result", id: e.id, data: { ok: !0 } });
|
|
212
|
+
} catch (t) {
|
|
213
|
+
const s = t instanceof Error ? t.message : String(t);
|
|
214
|
+
self.postMessage({ type: "error", id: e.id, error: s });
|
|
215
|
+
}
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
case "stop": {
|
|
219
|
+
for (const [t, s] of d)
|
|
220
|
+
s({
|
|
221
|
+
ok: !1,
|
|
222
|
+
error: { message: "Worker stopped", code: "E_STOPPED" }
|
|
223
|
+
}), d.delete(t);
|
|
224
|
+
self.postMessage({ type: "result", id: e.id, data: { ok: !0 } });
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
case "setFuelLimit": {
|
|
228
|
+
try {
|
|
229
|
+
a.set_fuel_limit(e.limit), e.id && self.postMessage({ type: "result", id: e.id, data: { ok: !0 } });
|
|
230
|
+
} catch (t) {
|
|
231
|
+
if (e.id) {
|
|
232
|
+
const s = t instanceof Error ? t.message : String(t);
|
|
233
|
+
self.postMessage({ type: "error", id: e.id, error: s });
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
case "inspectGlobals": {
|
|
239
|
+
try {
|
|
240
|
+
const t = a.inspect_globals();
|
|
241
|
+
self.postMessage({ type: "result", id: e.id, data: t });
|
|
242
|
+
} catch (t) {
|
|
243
|
+
const s = t instanceof Error ? t.message : String(t);
|
|
244
|
+
self.postMessage({ type: "error", id: e.id, error: s });
|
|
245
|
+
}
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
case "loadLibrary": {
|
|
249
|
+
try {
|
|
250
|
+
const t = a.load_library(e.source);
|
|
251
|
+
self.postMessage({ type: "result", id: e.id, data: t });
|
|
252
|
+
} catch (t) {
|
|
253
|
+
const s = t instanceof Error ? t.message : String(t);
|
|
254
|
+
self.postMessage({ type: "error", id: e.id, error: s });
|
|
255
|
+
}
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
case "fsCall": {
|
|
259
|
+
const t = M.get(e.action);
|
|
260
|
+
if (!t) {
|
|
261
|
+
self.postMessage({
|
|
262
|
+
type: "error",
|
|
263
|
+
id: e.id,
|
|
264
|
+
error: `Unknown fs action: ${e.action}`
|
|
265
|
+
});
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
try {
|
|
269
|
+
const s = await t(e.params);
|
|
270
|
+
self.postMessage({ type: "result", id: e.id, data: s });
|
|
271
|
+
} catch (s) {
|
|
272
|
+
const o = s instanceof Error ? s.message : String(s);
|
|
273
|
+
self.postMessage({ type: "error", id: e.id, error: o });
|
|
274
|
+
}
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
case "asyncRelayResult": {
|
|
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
|
+
}
|
|
287
|
+
};
|
package/extension_js_bg.wasm
DELETED
|
Binary file
|