@execbox/quickjs 0.4.0 → 0.6.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/README.md +38 -38
- package/dist/index.cjs +23 -309
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -304
- package/dist/index.js.map +1 -1
- package/dist/{protocolEndpoint-DGOUVf6J.cjs → protocolEndpoint-BGyrwlr_.cjs} +5 -40
- package/dist/protocolEndpoint-BGyrwlr_.cjs.map +1 -0
- package/dist/{protocolEndpoint-T_JEz8YY.js → protocolEndpoint-Ceadcq_L.js} +4 -39
- package/dist/protocolEndpoint-Ceadcq_L.js.map +1 -0
- package/dist/remoteEndpoint.cjs +45 -0
- package/dist/remoteEndpoint.cjs.map +1 -0
- package/dist/remoteEndpoint.d.cts +29 -0
- package/dist/remoteEndpoint.d.cts.map +1 -0
- package/dist/remoteEndpoint.d.ts +29 -0
- package/dist/remoteEndpoint.d.ts.map +1 -0
- package/dist/remoteEndpoint.js +45 -0
- package/dist/remoteEndpoint.js.map +1 -0
- package/dist/runner/index.cjs +1 -1
- package/dist/runner/index.d.cts +2 -2
- package/dist/runner/index.d.cts.map +1 -1
- package/dist/runner/index.d.ts +2 -2
- package/dist/runner/index.d.ts.map +1 -1
- package/dist/runner/index.js +1 -1
- package/dist/runner/protocolEndpoint.cjs +2 -2
- package/dist/runner/protocolEndpoint.d.cts +2 -2
- package/dist/runner/protocolEndpoint.d.cts.map +1 -1
- package/dist/runner/protocolEndpoint.d.ts +2 -2
- package/dist/runner/protocolEndpoint.d.ts.map +1 -1
- package/dist/runner/protocolEndpoint.js +2 -2
- package/dist/runner-DRLfwiqY.cjs +348 -0
- package/dist/runner-DRLfwiqY.cjs.map +1 -0
- package/dist/runner-oZXbguX3.js +343 -0
- package/dist/runner-oZXbguX3.js.map +1 -0
- package/dist/{types-BeVqrcj8.d.ts → types-C-XfFJ7u.d.cts} +8 -21
- package/dist/types-C-XfFJ7u.d.cts.map +1 -0
- package/dist/{types-CnNmLawC.d.cts → types-CE7SvejR.d.ts} +8 -21
- package/dist/types-CE7SvejR.d.ts.map +1 -0
- package/dist/workerEntry.cjs +2 -2
- package/dist/workerEntry.js +2 -2
- package/package.json +12 -3
- package/dist/processEntry.cjs +0 -17
- package/dist/processEntry.cjs.map +0 -1
- package/dist/processEntry.d.cts +0 -5
- package/dist/processEntry.d.ts +0 -5
- package/dist/processEntry.js +0 -18
- package/dist/processEntry.js.map +0 -1
- package/dist/protocolEndpoint-DGOUVf6J.cjs.map +0 -1
- package/dist/protocolEndpoint-T_JEz8YY.js.map +0 -1
- package/dist/runner-CteKTaPD.js +0 -5654
- package/dist/runner-CteKTaPD.js.map +0 -1
- package/dist/runner-DRt0kpEk.cjs +0 -5707
- package/dist/runner-DRt0kpEk.cjs.map +0 -1
- package/dist/types-BeVqrcj8.d.ts.map +0 -1
- package/dist/types-CnNmLawC.d.cts.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../runner-
|
|
2
|
-
import { t as attachQuickJsProtocolEndpoint } from "../protocolEndpoint-
|
|
1
|
+
import "../runner-oZXbguX3.js";
|
|
2
|
+
import { t as attachQuickJsProtocolEndpoint } from "../protocolEndpoint-Ceadcq_L.js";
|
|
3
3
|
|
|
4
4
|
export { attachQuickJsProtocolEndpoint };
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
let __execbox_core_runtime = require("@execbox/core/runtime");
|
|
2
|
+
let node_crypto = require("node:crypto");
|
|
3
|
+
let quickjs_emscripten = require("quickjs-emscripten");
|
|
4
|
+
|
|
5
|
+
//#region src/quickjsBridge.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates a guest-visible error object that carries a trusted host error code marker.
|
|
8
|
+
*/
|
|
9
|
+
function createGuestErrorHandle(context, code, message, trustedHostErrorKey) {
|
|
10
|
+
const errorHandle = context.newError({
|
|
11
|
+
message,
|
|
12
|
+
name: "Error"
|
|
13
|
+
});
|
|
14
|
+
const codeHandle = context.newString(code);
|
|
15
|
+
const trustedHostMarkerHandle = context.true;
|
|
16
|
+
try {
|
|
17
|
+
context.setProp(errorHandle, "code", codeHandle);
|
|
18
|
+
context.setProp(errorHandle, trustedHostErrorKey, trustedHostMarkerHandle);
|
|
19
|
+
return errorHandle;
|
|
20
|
+
} finally {
|
|
21
|
+
codeHandle.dispose();
|
|
22
|
+
trustedHostMarkerHandle.dispose();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Converts a guest QuickJS handle into a JSON-compatible host value.
|
|
27
|
+
*/
|
|
28
|
+
function fromGuestHandle(context, handle) {
|
|
29
|
+
const guestType = context.typeof(handle);
|
|
30
|
+
if (guestType === "undefined") return;
|
|
31
|
+
if (guestType === "function" || guestType === "symbol" || guestType === "bigint") throw new __execbox_core_runtime.ExecuteFailure("serialization_error", "Guest code returned a non-serializable value");
|
|
32
|
+
const jsonHandle = context.getProp(context.global, "JSON");
|
|
33
|
+
const stringifyHandle = context.getProp(jsonHandle, "stringify");
|
|
34
|
+
try {
|
|
35
|
+
const stringified = context.unwrapResult(context.callFunction(stringifyHandle, jsonHandle, handle));
|
|
36
|
+
if (context.typeof(stringified) === "undefined") throw new __execbox_core_runtime.ExecuteFailure("serialization_error", "Guest code returned a non-serializable value");
|
|
37
|
+
const jsonValue = context.getString(stringified);
|
|
38
|
+
return JSON.parse(jsonValue);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (error instanceof __execbox_core_runtime.ExecuteFailure) throw error;
|
|
41
|
+
throw new __execbox_core_runtime.ExecuteFailure("serialization_error", "Guest code returned a non-serializable value");
|
|
42
|
+
} finally {
|
|
43
|
+
stringifyHandle.dispose();
|
|
44
|
+
jsonHandle.dispose();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Converts a host JSON-compatible value into a guest QuickJS handle.
|
|
49
|
+
*/
|
|
50
|
+
function toGuestHandle(context, value) {
|
|
51
|
+
if (value === void 0) return context.undefined;
|
|
52
|
+
const jsonValue = JSON.stringify(value);
|
|
53
|
+
if (jsonValue === void 0) throw new __execbox_core_runtime.ExecuteFailure("serialization_error", "Host value is not JSON-serializable");
|
|
54
|
+
return context.unwrapResult(context.evalCode(`(${jsonValue})`, "host-value.json"));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/runner/index.ts
|
|
59
|
+
/**
|
|
60
|
+
* @packageDocumentation
|
|
61
|
+
* Public API for the `@execbox/quickjs/runner` entrypoint.
|
|
62
|
+
*/
|
|
63
|
+
const loadDefaultModule = (0, quickjs_emscripten.memoizePromiseFactory)(() => (0, quickjs_emscripten.newQuickJSWASMModule)(quickjs_emscripten.RELEASE_SYNC));
|
|
64
|
+
/**
|
|
65
|
+
* Converts unexpected executor failures into stable public result errors.
|
|
66
|
+
*/
|
|
67
|
+
function toExecuteError(error, deadline) {
|
|
68
|
+
if ((0, __execbox_core_runtime.isExecuteFailure)(error)) return {
|
|
69
|
+
code: error.code,
|
|
70
|
+
message: error.message
|
|
71
|
+
};
|
|
72
|
+
const message = (0, __execbox_core_runtime.normalizeThrownMessage)(error);
|
|
73
|
+
if (Date.now() > deadline || message.includes("interrupted")) return {
|
|
74
|
+
code: "timeout",
|
|
75
|
+
message: (0, __execbox_core_runtime.getExecutionTimeoutMessage)()
|
|
76
|
+
};
|
|
77
|
+
if (message.toLowerCase().includes("out of memory")) return {
|
|
78
|
+
code: "memory_limit",
|
|
79
|
+
message
|
|
80
|
+
};
|
|
81
|
+
return {
|
|
82
|
+
code: "runtime_error",
|
|
83
|
+
message
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function errorFromGuestHandle(context, handle, trustedHostErrorKey) {
|
|
87
|
+
const codeHandle = context.getProp(handle, "code");
|
|
88
|
+
const messageHandle = context.getProp(handle, "message");
|
|
89
|
+
const trustedMarkerHandle = context.getProp(handle, trustedHostErrorKey);
|
|
90
|
+
try {
|
|
91
|
+
const code = context.typeof(codeHandle) === "string" ? context.getString(codeHandle) : void 0;
|
|
92
|
+
const trustedHostError = context.typeof(trustedMarkerHandle) === "boolean";
|
|
93
|
+
const message = context.typeof(messageHandle) === "string" ? context.getString(messageHandle) : (0, __execbox_core_runtime.normalizeThrownMessage)(context.dump(handle));
|
|
94
|
+
if (trustedHostError && (0, __execbox_core_runtime.isKnownExecuteErrorCode)(code)) return {
|
|
95
|
+
code,
|
|
96
|
+
message
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
code: "runtime_error",
|
|
100
|
+
message
|
|
101
|
+
};
|
|
102
|
+
} finally {
|
|
103
|
+
codeHandle.dispose();
|
|
104
|
+
messageHandle.dispose();
|
|
105
|
+
trustedMarkerHandle.dispose();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async function waitForPromiseSettlement(runtime, promise, deadline, trustedHostErrorKey) {
|
|
109
|
+
let settled = false;
|
|
110
|
+
let rejection;
|
|
111
|
+
promise.then(() => {
|
|
112
|
+
settled = true;
|
|
113
|
+
}, (error) => {
|
|
114
|
+
settled = true;
|
|
115
|
+
rejection = error;
|
|
116
|
+
});
|
|
117
|
+
while (!settled) {
|
|
118
|
+
if (Date.now() > deadline) throw new __execbox_core_runtime.ExecuteFailure("timeout", (0, __execbox_core_runtime.getExecutionTimeoutMessage)());
|
|
119
|
+
const pendingJobsResult = runtime.executePendingJobs(-1);
|
|
120
|
+
if ((0, quickjs_emscripten.isFail)(pendingJobsResult)) {
|
|
121
|
+
const pendingError = pendingJobsResult.error;
|
|
122
|
+
try {
|
|
123
|
+
const executeError = errorFromGuestHandle(pendingError.context, pendingError, trustedHostErrorKey);
|
|
124
|
+
throw new __execbox_core_runtime.ExecuteFailure(executeError.code, executeError.message);
|
|
125
|
+
} finally {
|
|
126
|
+
pendingError.dispose();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
130
|
+
}
|
|
131
|
+
if (rejection !== void 0) throw rejection;
|
|
132
|
+
}
|
|
133
|
+
function injectConsole(context, logs) {
|
|
134
|
+
const consoleHandle = context.newObject();
|
|
135
|
+
try {
|
|
136
|
+
for (const methodName of [
|
|
137
|
+
"log",
|
|
138
|
+
"info",
|
|
139
|
+
"warn",
|
|
140
|
+
"error"
|
|
141
|
+
]) {
|
|
142
|
+
const methodHandle = context.newFunction(methodName, (...args) => {
|
|
143
|
+
logs.push((0, __execbox_core_runtime.formatConsoleLine)(args.map((arg) => context.dump(arg))));
|
|
144
|
+
return context.undefined;
|
|
145
|
+
});
|
|
146
|
+
context.setProp(consoleHandle, methodName, methodHandle);
|
|
147
|
+
methodHandle.dispose();
|
|
148
|
+
}
|
|
149
|
+
context.setProp(context.global, "console", consoleHandle);
|
|
150
|
+
} finally {
|
|
151
|
+
consoleHandle.dispose();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function injectProviders(context, providers, signal, trustedHostErrorKey, onToolCall) {
|
|
155
|
+
for (const provider of providers) {
|
|
156
|
+
const providerHandle = context.newObject();
|
|
157
|
+
try {
|
|
158
|
+
for (const [safeToolName] of Object.entries(provider.tools)) {
|
|
159
|
+
const toolHandle = createToolHandle(context, provider.name, safeToolName, signal, trustedHostErrorKey, onToolCall);
|
|
160
|
+
context.setProp(providerHandle, safeToolName, toolHandle);
|
|
161
|
+
toolHandle.dispose();
|
|
162
|
+
}
|
|
163
|
+
context.setProp(context.global, provider.name, providerHandle);
|
|
164
|
+
} finally {
|
|
165
|
+
providerHandle.dispose();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function createToolHandle(context, providerName, safeToolName, signal, trustedHostErrorKey, onToolCall) {
|
|
170
|
+
return context.newFunction(safeToolName, (...args) => {
|
|
171
|
+
const deferred = context.newPromise();
|
|
172
|
+
const disposeDeferred = () => {
|
|
173
|
+
if (context.alive && deferred.alive) deferred.dispose();
|
|
174
|
+
};
|
|
175
|
+
let input;
|
|
176
|
+
try {
|
|
177
|
+
input = args[0] === void 0 ? void 0 : fromGuestHandle(context, args[0]);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
const executeError = (0, __execbox_core_runtime.isExecuteFailure)(error) ? error : new __execbox_core_runtime.ExecuteFailure("serialization_error", "Guest code passed a non-serializable tool input");
|
|
180
|
+
const errorHandle = createGuestErrorHandle(context, executeError.code, executeError.message, trustedHostErrorKey);
|
|
181
|
+
try {
|
|
182
|
+
deferred.reject(errorHandle);
|
|
183
|
+
return deferred.handle;
|
|
184
|
+
} finally {
|
|
185
|
+
errorHandle.dispose();
|
|
186
|
+
queueMicrotask(disposeDeferred);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const onAbort = () => {
|
|
190
|
+
signal.removeEventListener("abort", onAbort);
|
|
191
|
+
if (!context.alive || !deferred.alive) {
|
|
192
|
+
disposeDeferred();
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const errorHandle = createGuestErrorHandle(context, "timeout", (0, __execbox_core_runtime.getExecutionTimeoutMessage)(), trustedHostErrorKey);
|
|
196
|
+
try {
|
|
197
|
+
deferred.reject(errorHandle);
|
|
198
|
+
} finally {
|
|
199
|
+
errorHandle.dispose();
|
|
200
|
+
disposeDeferred();
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
204
|
+
let responsePromise;
|
|
205
|
+
try {
|
|
206
|
+
if (signal.aborted) throw new __execbox_core_runtime.ExecuteFailure("timeout", (0, __execbox_core_runtime.getExecutionTimeoutMessage)());
|
|
207
|
+
responsePromise = Promise.resolve(onToolCall({
|
|
208
|
+
input,
|
|
209
|
+
providerName,
|
|
210
|
+
safeToolName
|
|
211
|
+
}));
|
|
212
|
+
} catch (error) {
|
|
213
|
+
responsePromise = Promise.reject(error);
|
|
214
|
+
}
|
|
215
|
+
responsePromise.then((response) => {
|
|
216
|
+
signal.removeEventListener("abort", onAbort);
|
|
217
|
+
if (!context.alive || !deferred.alive) {
|
|
218
|
+
disposeDeferred();
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
let resultHandle;
|
|
222
|
+
try {
|
|
223
|
+
if (!response.ok) {
|
|
224
|
+
const errorHandle = createGuestErrorHandle(context, response.error.code, response.error.message, trustedHostErrorKey);
|
|
225
|
+
deferred.reject(errorHandle);
|
|
226
|
+
errorHandle.dispose();
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
resultHandle = toGuestHandle(context, response.result);
|
|
230
|
+
deferred.resolve(resultHandle);
|
|
231
|
+
} finally {
|
|
232
|
+
resultHandle?.dispose();
|
|
233
|
+
disposeDeferred();
|
|
234
|
+
}
|
|
235
|
+
}).catch((error) => {
|
|
236
|
+
signal.removeEventListener("abort", onAbort);
|
|
237
|
+
if (!context.alive || !deferred.alive) {
|
|
238
|
+
disposeDeferred();
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const errorHandle = createGuestErrorHandle(context, (0, __execbox_core_runtime.isExecuteFailure)(error) ? error.code : "internal_error", (0, __execbox_core_runtime.normalizeThrownMessage)(error), trustedHostErrorKey);
|
|
242
|
+
try {
|
|
243
|
+
deferred.reject(errorHandle);
|
|
244
|
+
} finally {
|
|
245
|
+
errorHandle.dispose();
|
|
246
|
+
disposeDeferred();
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
return deferred.handle;
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Runs one QuickJS-backed execution session using a transport-neutral tool callback.
|
|
254
|
+
*/
|
|
255
|
+
async function runQuickJsSession(request, options = {}) {
|
|
256
|
+
const runtimeOptions = (0, __execbox_core_runtime.resolveExecutorRuntimeOptions)(options);
|
|
257
|
+
const loadModule = async () => {
|
|
258
|
+
if (options.module) return options.module;
|
|
259
|
+
return options.loadModule ? await options.loadModule() : await loadDefaultModule();
|
|
260
|
+
};
|
|
261
|
+
const { maxLogChars, maxLogLines, memoryLimitBytes, timeoutMs } = runtimeOptions;
|
|
262
|
+
const startedAt = Date.now();
|
|
263
|
+
const logs = [];
|
|
264
|
+
const abortController = new AbortController();
|
|
265
|
+
const trustedHostErrorKey = `__execboxHostError_${(0, node_crypto.randomUUID)()}`;
|
|
266
|
+
const signal = request.abortController?.signal ?? request.signal ?? abortController.signal;
|
|
267
|
+
const runtime = (await loadModule()).newRuntime();
|
|
268
|
+
let deadline = Number.POSITIVE_INFINITY;
|
|
269
|
+
runtime.setMemoryLimit(memoryLimitBytes);
|
|
270
|
+
const context = runtime.newContext();
|
|
271
|
+
try {
|
|
272
|
+
injectConsole(context, logs);
|
|
273
|
+
injectProviders(context, request.providers, signal, trustedHostErrorKey, request.onToolCall);
|
|
274
|
+
deadline = Date.now() + timeoutMs;
|
|
275
|
+
const shouldInterrupt = (0, quickjs_emscripten.shouldInterruptAfterDeadline)(deadline);
|
|
276
|
+
runtime.setInterruptHandler((currentRuntime) => {
|
|
277
|
+
return signal.aborted || shouldInterrupt(currentRuntime);
|
|
278
|
+
});
|
|
279
|
+
request.onStarted?.();
|
|
280
|
+
const executableSource = (0, __execbox_core_runtime.normalizeCode)(request.code);
|
|
281
|
+
const functionHandle = context.unwrapResult(context.evalCode(`(${executableSource})`, "sandbox-user-code.js"));
|
|
282
|
+
try {
|
|
283
|
+
const promiseHandle = context.unwrapResult(context.callFunction(functionHandle, context.undefined));
|
|
284
|
+
try {
|
|
285
|
+
const promiseResult = context.resolvePromise(promiseHandle);
|
|
286
|
+
await waitForPromiseSettlement(runtime, promiseResult, deadline, trustedHostErrorKey);
|
|
287
|
+
const settledResult = await promiseResult;
|
|
288
|
+
if ((0, quickjs_emscripten.isFail)(settledResult)) {
|
|
289
|
+
const errorHandle = settledResult.error;
|
|
290
|
+
try {
|
|
291
|
+
return {
|
|
292
|
+
durationMs: Date.now() - startedAt,
|
|
293
|
+
error: errorFromGuestHandle(context, errorHandle, trustedHostErrorKey),
|
|
294
|
+
logs: (0, __execbox_core_runtime.truncateLogs)(logs, maxLogLines, maxLogChars),
|
|
295
|
+
ok: false
|
|
296
|
+
};
|
|
297
|
+
} finally {
|
|
298
|
+
errorHandle.dispose();
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
try {
|
|
302
|
+
const value = fromGuestHandle(context, settledResult.value);
|
|
303
|
+
return {
|
|
304
|
+
durationMs: Date.now() - startedAt,
|
|
305
|
+
logs: (0, __execbox_core_runtime.truncateLogs)(logs, maxLogLines, maxLogChars),
|
|
306
|
+
ok: true,
|
|
307
|
+
result: value
|
|
308
|
+
};
|
|
309
|
+
} catch (error) {
|
|
310
|
+
return {
|
|
311
|
+
durationMs: Date.now() - startedAt,
|
|
312
|
+
error: toExecuteError(error, deadline),
|
|
313
|
+
logs: (0, __execbox_core_runtime.truncateLogs)(logs, maxLogLines, maxLogChars),
|
|
314
|
+
ok: false
|
|
315
|
+
};
|
|
316
|
+
} finally {
|
|
317
|
+
settledResult.value.dispose();
|
|
318
|
+
}
|
|
319
|
+
} finally {
|
|
320
|
+
promiseHandle.dispose();
|
|
321
|
+
}
|
|
322
|
+
} finally {
|
|
323
|
+
functionHandle.dispose();
|
|
324
|
+
}
|
|
325
|
+
} catch (error) {
|
|
326
|
+
abortController.abort();
|
|
327
|
+
return {
|
|
328
|
+
durationMs: Date.now() - startedAt,
|
|
329
|
+
error: toExecuteError(error, deadline),
|
|
330
|
+
logs: (0, __execbox_core_runtime.truncateLogs)(logs, maxLogLines, maxLogChars),
|
|
331
|
+
ok: false
|
|
332
|
+
};
|
|
333
|
+
} finally {
|
|
334
|
+
request.abortController?.abort();
|
|
335
|
+
abortController.abort();
|
|
336
|
+
context.dispose();
|
|
337
|
+
runtime.dispose();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
//#endregion
|
|
342
|
+
Object.defineProperty(exports, 'runQuickJsSession', {
|
|
343
|
+
enumerable: true,
|
|
344
|
+
get: function () {
|
|
345
|
+
return runQuickJsSession;
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
//# sourceMappingURL=runner-DRLfwiqY.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner-DRLfwiqY.cjs","names":["ExecuteFailure","RELEASE_SYNC","rejection: unknown","ExecuteFailure","input: unknown","responsePromise: Promise<ToolCallResult>","resultHandle: QuickJSHandle | undefined","logs: string[]"],"sources":["../src/quickjsBridge.ts","../src/runner/index.ts"],"sourcesContent":["import type { QuickJSContext, QuickJSHandle } from \"quickjs-emscripten\";\n\nimport { ExecuteFailure } from \"@execbox/core/runtime\";\nimport type { ExecuteErrorCode } from \"@execbox/core\";\n\n/**\n * Creates a guest-visible error object that carries a trusted host error code marker.\n */\nexport function createGuestErrorHandle(\n context: QuickJSContext,\n code: ExecuteErrorCode,\n message: string,\n trustedHostErrorKey: string,\n): QuickJSHandle {\n const errorHandle = context.newError({ message, name: \"Error\" });\n const codeHandle = context.newString(code);\n const trustedHostMarkerHandle = context.true;\n\n try {\n context.setProp(errorHandle, \"code\", codeHandle);\n context.setProp(errorHandle, trustedHostErrorKey, trustedHostMarkerHandle);\n return errorHandle;\n } finally {\n codeHandle.dispose();\n trustedHostMarkerHandle.dispose();\n }\n}\n\n/**\n * Converts a guest QuickJS handle into a JSON-compatible host value.\n */\nexport function fromGuestHandle(\n context: QuickJSContext,\n handle: QuickJSHandle,\n): unknown {\n const guestType = context.typeof(handle);\n\n if (guestType === \"undefined\") {\n return undefined;\n }\n\n if (\n guestType === \"function\" ||\n guestType === \"symbol\" ||\n guestType === \"bigint\"\n ) {\n throw new ExecuteFailure(\n \"serialization_error\",\n \"Guest code returned a non-serializable value\",\n );\n }\n\n const jsonHandle = context.getProp(context.global, \"JSON\");\n const stringifyHandle = context.getProp(jsonHandle, \"stringify\");\n\n try {\n const stringified = context.unwrapResult(\n context.callFunction(stringifyHandle, jsonHandle, handle),\n );\n const stringifiedType = context.typeof(stringified);\n\n if (stringifiedType === \"undefined\") {\n throw new ExecuteFailure(\n \"serialization_error\",\n \"Guest code returned a non-serializable value\",\n );\n }\n\n const jsonValue = context.getString(stringified);\n return JSON.parse(jsonValue);\n } catch (error) {\n if (error instanceof ExecuteFailure) {\n throw error;\n }\n\n throw new ExecuteFailure(\n \"serialization_error\",\n \"Guest code returned a non-serializable value\",\n );\n } finally {\n stringifyHandle.dispose();\n jsonHandle.dispose();\n }\n}\n\n/**\n * Converts a host JSON-compatible value into a guest QuickJS handle.\n */\nexport function toGuestHandle(\n context: QuickJSContext,\n value: unknown,\n): QuickJSHandle {\n if (value === undefined) {\n return context.undefined;\n }\n\n const jsonValue = JSON.stringify(value);\n\n if (jsonValue === undefined) {\n throw new ExecuteFailure(\n \"serialization_error\",\n \"Host value is not JSON-serializable\",\n );\n }\n\n return context.unwrapResult(\n context.evalCode(`(${jsonValue})`, \"host-value.json\"),\n );\n}\n","/**\n * @packageDocumentation\n * Public API for the `@execbox/quickjs/runner` entrypoint.\n */\nimport { randomUUID } from \"node:crypto\";\n\nimport {\n RELEASE_SYNC,\n isFail,\n memoizePromiseFactory,\n newQuickJSWASMModule,\n shouldInterruptAfterDeadline,\n type QuickJSContext,\n type QuickJSHandle,\n type QuickJSRuntime,\n type QuickJSWASMModule,\n} from \"quickjs-emscripten\";\n\nimport {\n ExecuteFailure,\n formatConsoleLine,\n getExecutionTimeoutMessage,\n isExecuteFailure,\n isKnownExecuteErrorCode,\n normalizeCode,\n normalizeThrownMessage,\n resolveExecutorRuntimeOptions,\n truncateLogs,\n} from \"@execbox/core/runtime\";\nimport type {\n ExecuteError,\n ExecuteResult,\n ExecutorRuntimeOptions,\n ProviderManifest,\n ToolCall,\n ToolCallResult,\n} from \"@execbox/core\";\n\nimport {\n createGuestErrorHandle,\n fromGuestHandle,\n toGuestHandle,\n} from \"../quickjsBridge.ts\";\nimport type { QuickJsInlineExecutorOptions } from \"../types.ts\";\n\nexport type {\n QuickJsExecutorHost,\n QuickJsExecutorOptions,\n QuickJsHostedMode,\n QuickJsInlineExecutorOptions,\n QuickJsWorkerExecutorOptions,\n WorkerResourceLimits,\n} from \"../types.ts\";\n\nconst loadDefaultModule = memoizePromiseFactory(() =>\n newQuickJSWASMModule(RELEASE_SYNC),\n);\n\n/**\n * Transport-neutral host tool call emitted from a QuickJS session.\n */\nexport type QuickJsSessionToolCall = ToolCall;\n\n/**\n * Input required to run one transport-backed QuickJS execution session.\n */\nexport interface QuickJsSessionRequest {\n /** Optional abort controller that should be triggered when execution stops. */\n abortController?: AbortController;\n\n /** Guest JavaScript source to evaluate inside QuickJS. */\n code: string;\n\n /** Host callback used to fulfill guest tool calls. */\n onToolCall: (call: ToolCall) => Promise<ToolCallResult> | ToolCallResult;\n\n /** Optional hook invoked once the guest runtime has started. */\n onStarted?: () => void;\n\n /** Transport-safe provider manifests exposed to the guest runtime. */\n providers: ProviderManifest[];\n\n /** Optional caller-owned abort signal for the session. */\n signal?: AbortSignal;\n}\n\n/**\n * Options controlling one transport-backed QuickJS session.\n */\nexport type QuickJsSessionOptions = ExecutorRuntimeOptions &\n Pick<QuickJsInlineExecutorOptions, \"loadModule\"> & {\n /** Optional preloaded QuickJS WASM module instance. */\n module?: QuickJSWASMModule;\n };\n\n/**\n * Converts unexpected executor failures into stable public result errors.\n */\nfunction toExecuteError(error: unknown, deadline: number): ExecuteError {\n if (isExecuteFailure(error)) {\n return {\n code: error.code,\n message: error.message,\n };\n }\n\n const message = normalizeThrownMessage(error);\n\n if (Date.now() > deadline || message.includes(\"interrupted\")) {\n return {\n code: \"timeout\",\n message: getExecutionTimeoutMessage(),\n };\n }\n\n if (message.toLowerCase().includes(\"out of memory\")) {\n return {\n code: \"memory_limit\",\n message,\n };\n }\n\n return {\n code: \"runtime_error\",\n message,\n };\n}\n\nfunction errorFromGuestHandle(\n context: QuickJSContext,\n handle: QuickJSHandle,\n trustedHostErrorKey: string,\n): ExecuteError {\n const codeHandle = context.getProp(handle, \"code\");\n const messageHandle = context.getProp(handle, \"message\");\n const trustedMarkerHandle = context.getProp(handle, trustedHostErrorKey);\n\n try {\n const code =\n context.typeof(codeHandle) === \"string\"\n ? context.getString(codeHandle)\n : undefined;\n const trustedHostError = context.typeof(trustedMarkerHandle) === \"boolean\";\n const message =\n context.typeof(messageHandle) === \"string\"\n ? context.getString(messageHandle)\n : normalizeThrownMessage(context.dump(handle));\n\n if (trustedHostError && isKnownExecuteErrorCode(code)) {\n return {\n code,\n message,\n };\n }\n\n return {\n code: \"runtime_error\",\n message,\n };\n } finally {\n codeHandle.dispose();\n messageHandle.dispose();\n trustedMarkerHandle.dispose();\n }\n}\n\nasync function waitForPromiseSettlement(\n runtime: QuickJSRuntime,\n promise: Promise<unknown>,\n deadline: number,\n trustedHostErrorKey: string,\n): Promise<void> {\n let settled = false;\n let rejection: unknown;\n\n promise.then(\n () => {\n settled = true;\n },\n (error) => {\n settled = true;\n rejection = error;\n },\n );\n\n while (!settled) {\n if (Date.now() > deadline) {\n throw new ExecuteFailure(\"timeout\", getExecutionTimeoutMessage());\n }\n\n const pendingJobsResult = runtime.executePendingJobs(-1);\n if (isFail(pendingJobsResult)) {\n const pendingError = pendingJobsResult.error;\n\n try {\n const executeError = errorFromGuestHandle(\n pendingError.context,\n pendingError,\n trustedHostErrorKey,\n );\n throw new ExecuteFailure(executeError.code, executeError.message);\n } finally {\n pendingError.dispose();\n }\n }\n\n await new Promise((resolve) => setTimeout(resolve, 0));\n }\n\n if (rejection !== undefined) {\n throw rejection;\n }\n}\n\nfunction injectConsole(context: QuickJSContext, logs: string[]): void {\n const consoleHandle = context.newObject();\n\n try {\n for (const methodName of [\"log\", \"info\", \"warn\", \"error\"]) {\n const methodHandle = context.newFunction(methodName, (...args) => {\n logs.push(formatConsoleLine(args.map((arg) => context.dump(arg))));\n return context.undefined;\n });\n\n context.setProp(consoleHandle, methodName, methodHandle);\n methodHandle.dispose();\n }\n\n context.setProp(context.global, \"console\", consoleHandle);\n } finally {\n consoleHandle.dispose();\n }\n}\n\nfunction injectProviders(\n context: QuickJSContext,\n providers: ProviderManifest[],\n signal: AbortSignal,\n trustedHostErrorKey: string,\n onToolCall: QuickJsSessionRequest[\"onToolCall\"],\n): void {\n for (const provider of providers) {\n const providerHandle = context.newObject();\n\n try {\n for (const [safeToolName] of Object.entries(provider.tools)) {\n const toolHandle = createToolHandle(\n context,\n provider.name,\n safeToolName,\n signal,\n trustedHostErrorKey,\n onToolCall,\n );\n context.setProp(providerHandle, safeToolName, toolHandle);\n toolHandle.dispose();\n }\n\n context.setProp(context.global, provider.name, providerHandle);\n } finally {\n providerHandle.dispose();\n }\n }\n}\n\nfunction createToolHandle(\n context: QuickJSContext,\n providerName: string,\n safeToolName: string,\n signal: AbortSignal,\n trustedHostErrorKey: string,\n onToolCall: QuickJsSessionRequest[\"onToolCall\"],\n): QuickJSHandle {\n return context.newFunction(safeToolName, (...args) => {\n const deferred = context.newPromise();\n const disposeDeferred = () => {\n if (context.alive && deferred.alive) {\n deferred.dispose();\n }\n };\n let input: unknown;\n\n try {\n input =\n args[0] === undefined ? undefined : fromGuestHandle(context, args[0]);\n } catch (error) {\n const executeError = isExecuteFailure(error)\n ? error\n : new ExecuteFailure(\n \"serialization_error\",\n \"Guest code passed a non-serializable tool input\",\n );\n const errorHandle = createGuestErrorHandle(\n context,\n executeError.code,\n executeError.message,\n trustedHostErrorKey,\n );\n\n try {\n deferred.reject(errorHandle);\n return deferred.handle;\n } finally {\n errorHandle.dispose();\n queueMicrotask(disposeDeferred);\n }\n }\n const onAbort = () => {\n signal.removeEventListener(\"abort\", onAbort);\n if (!context.alive || !deferred.alive) {\n disposeDeferred();\n return;\n }\n\n const errorHandle = createGuestErrorHandle(\n context,\n \"timeout\",\n getExecutionTimeoutMessage(),\n trustedHostErrorKey,\n );\n\n try {\n deferred.reject(errorHandle);\n } finally {\n errorHandle.dispose();\n disposeDeferred();\n }\n };\n\n signal.addEventListener(\"abort\", onAbort, { once: true });\n\n let responsePromise: Promise<ToolCallResult>;\n\n try {\n if (signal.aborted) {\n throw new ExecuteFailure(\"timeout\", getExecutionTimeoutMessage());\n }\n\n responsePromise = Promise.resolve(\n onToolCall({\n input,\n providerName,\n safeToolName,\n }),\n );\n } catch (error) {\n responsePromise = Promise.reject(error);\n }\n\n void responsePromise\n .then((response) => {\n signal.removeEventListener(\"abort\", onAbort);\n if (!context.alive || !deferred.alive) {\n disposeDeferred();\n return;\n }\n\n let resultHandle: QuickJSHandle | undefined;\n\n try {\n if (!response.ok) {\n const errorHandle = createGuestErrorHandle(\n context,\n response.error.code,\n response.error.message,\n trustedHostErrorKey,\n );\n deferred.reject(errorHandle);\n errorHandle.dispose();\n return;\n }\n\n resultHandle = toGuestHandle(context, response.result);\n deferred.resolve(resultHandle);\n } finally {\n resultHandle?.dispose();\n disposeDeferred();\n }\n })\n .catch((error) => {\n signal.removeEventListener(\"abort\", onAbort);\n if (!context.alive || !deferred.alive) {\n disposeDeferred();\n return;\n }\n\n const errorHandle = createGuestErrorHandle(\n context,\n isExecuteFailure(error) ? error.code : \"internal_error\",\n normalizeThrownMessage(error),\n trustedHostErrorKey,\n );\n\n try {\n deferred.reject(errorHandle);\n } finally {\n errorHandle.dispose();\n disposeDeferred();\n }\n });\n\n return deferred.handle;\n });\n}\n\n/**\n * Runs one QuickJS-backed execution session using a transport-neutral tool callback.\n */\nexport async function runQuickJsSession(\n request: QuickJsSessionRequest,\n options: QuickJsSessionOptions = {},\n): Promise<ExecuteResult> {\n const runtimeOptions = resolveExecutorRuntimeOptions(options);\n const loadModule = async () => {\n if (options.module) {\n return options.module;\n }\n\n const loaded = options.loadModule\n ? await options.loadModule()\n : await loadDefaultModule();\n return loaded as QuickJSWASMModule;\n };\n const { maxLogChars, maxLogLines, memoryLimitBytes, timeoutMs } =\n runtimeOptions;\n const startedAt = Date.now();\n const logs: string[] = [];\n const abortController = new AbortController();\n const trustedHostErrorKey = `__execboxHostError_${randomUUID()}`;\n const signal =\n request.abortController?.signal ?? request.signal ?? abortController.signal;\n const module = await loadModule();\n const runtime = module.newRuntime();\n let deadline = Number.POSITIVE_INFINITY;\n runtime.setMemoryLimit(memoryLimitBytes);\n const context = runtime.newContext();\n\n try {\n injectConsole(context, logs);\n injectProviders(\n context,\n request.providers,\n signal,\n trustedHostErrorKey,\n request.onToolCall,\n );\n const executionStartedAt = Date.now();\n deadline = executionStartedAt + timeoutMs;\n const shouldInterrupt = shouldInterruptAfterDeadline(deadline);\n runtime.setInterruptHandler((currentRuntime) => {\n return signal.aborted || shouldInterrupt(currentRuntime);\n });\n request.onStarted?.();\n\n const executableSource = normalizeCode(request.code);\n const functionHandle = context.unwrapResult(\n context.evalCode(`(${executableSource})`, \"sandbox-user-code.js\"),\n );\n\n try {\n const promiseHandle = context.unwrapResult(\n context.callFunction(functionHandle, context.undefined),\n );\n\n try {\n const promiseResult = context.resolvePromise(promiseHandle);\n await waitForPromiseSettlement(\n runtime,\n promiseResult,\n deadline,\n trustedHostErrorKey,\n );\n const settledResult = await promiseResult;\n\n if (isFail(settledResult)) {\n const errorHandle = settledResult.error;\n\n try {\n return {\n durationMs: Date.now() - startedAt,\n error: errorFromGuestHandle(\n context,\n errorHandle,\n trustedHostErrorKey,\n ),\n logs: truncateLogs(logs, maxLogLines, maxLogChars),\n ok: false,\n };\n } finally {\n errorHandle.dispose();\n }\n }\n\n try {\n const value = fromGuestHandle(context, settledResult.value);\n\n return {\n durationMs: Date.now() - startedAt,\n logs: truncateLogs(logs, maxLogLines, maxLogChars),\n ok: true,\n result: value,\n };\n } catch (error) {\n return {\n durationMs: Date.now() - startedAt,\n error: toExecuteError(error, deadline),\n logs: truncateLogs(logs, maxLogLines, maxLogChars),\n ok: false,\n };\n } finally {\n settledResult.value.dispose();\n }\n } finally {\n promiseHandle.dispose();\n }\n } finally {\n functionHandle.dispose();\n }\n } catch (error) {\n abortController.abort();\n\n return {\n durationMs: Date.now() - startedAt,\n error: toExecuteError(error, deadline),\n logs: truncateLogs(logs, maxLogLines, maxLogChars),\n ok: false,\n };\n } finally {\n request.abortController?.abort();\n abortController.abort();\n context.dispose();\n runtime.dispose();\n }\n}\n"],"mappings":";;;;;;;;AAQA,SAAgB,uBACd,SACA,MACA,SACA,qBACe;CACf,MAAM,cAAc,QAAQ,SAAS;EAAE;EAAS,MAAM;EAAS,CAAC;CAChE,MAAM,aAAa,QAAQ,UAAU,KAAK;CAC1C,MAAM,0BAA0B,QAAQ;AAExC,KAAI;AACF,UAAQ,QAAQ,aAAa,QAAQ,WAAW;AAChD,UAAQ,QAAQ,aAAa,qBAAqB,wBAAwB;AAC1E,SAAO;WACC;AACR,aAAW,SAAS;AACpB,0BAAwB,SAAS;;;;;;AAOrC,SAAgB,gBACd,SACA,QACS;CACT,MAAM,YAAY,QAAQ,OAAO,OAAO;AAExC,KAAI,cAAc,YAChB;AAGF,KACE,cAAc,cACd,cAAc,YACd,cAAc,SAEd,OAAM,IAAIA,sCACR,uBACA,+CACD;CAGH,MAAM,aAAa,QAAQ,QAAQ,QAAQ,QAAQ,OAAO;CAC1D,MAAM,kBAAkB,QAAQ,QAAQ,YAAY,YAAY;AAEhE,KAAI;EACF,MAAM,cAAc,QAAQ,aAC1B,QAAQ,aAAa,iBAAiB,YAAY,OAAO,CAC1D;AAGD,MAFwB,QAAQ,OAAO,YAAY,KAE3B,YACtB,OAAM,IAAIA,sCACR,uBACA,+CACD;EAGH,MAAM,YAAY,QAAQ,UAAU,YAAY;AAChD,SAAO,KAAK,MAAM,UAAU;UACrB,OAAO;AACd,MAAI,iBAAiBA,sCACnB,OAAM;AAGR,QAAM,IAAIA,sCACR,uBACA,+CACD;WACO;AACR,kBAAgB,SAAS;AACzB,aAAW,SAAS;;;;;;AAOxB,SAAgB,cACd,SACA,OACe;AACf,KAAI,UAAU,OACZ,QAAO,QAAQ;CAGjB,MAAM,YAAY,KAAK,UAAU,MAAM;AAEvC,KAAI,cAAc,OAChB,OAAM,IAAIA,sCACR,uBACA,sCACD;AAGH,QAAO,QAAQ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