@execbox/quickjs 0.6.0 → 0.7.1

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.
Files changed (48) hide show
  1. package/README.md +9 -12
  2. package/dist/index.cjs +2 -2
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +51 -3
  5. package/dist/index.d.cts.map +1 -1
  6. package/dist/index.d.ts +51 -3
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +2 -2
  9. package/dist/index.js.map +1 -1
  10. package/dist/{runner-DRLfwiqY.cjs → runner-BeRzBTrn.cjs} +92 -74
  11. package/dist/runner-BeRzBTrn.cjs.map +1 -0
  12. package/dist/{runner-oZXbguX3.js → runner-DJd4Bh8V.js} +92 -74
  13. package/dist/runner-DJd4Bh8V.js.map +1 -0
  14. package/dist/workerEntry.cjs +105 -3
  15. package/dist/workerEntry.cjs.map +1 -1
  16. package/dist/workerEntry.js +104 -2
  17. package/dist/workerEntry.js.map +1 -1
  18. package/package.json +2 -29
  19. package/dist/protocolEndpoint-BGyrwlr_.cjs +0 -112
  20. package/dist/protocolEndpoint-BGyrwlr_.cjs.map +0 -1
  21. package/dist/protocolEndpoint-Ceadcq_L.js +0 -107
  22. package/dist/protocolEndpoint-Ceadcq_L.js.map +0 -1
  23. package/dist/remoteEndpoint.cjs +0 -45
  24. package/dist/remoteEndpoint.cjs.map +0 -1
  25. package/dist/remoteEndpoint.d.cts +0 -29
  26. package/dist/remoteEndpoint.d.cts.map +0 -1
  27. package/dist/remoteEndpoint.d.ts +0 -29
  28. package/dist/remoteEndpoint.d.ts.map +0 -1
  29. package/dist/remoteEndpoint.js +0 -45
  30. package/dist/remoteEndpoint.js.map +0 -1
  31. package/dist/runner/index.cjs +0 -3
  32. package/dist/runner/index.d.cts +0 -45
  33. package/dist/runner/index.d.cts.map +0 -1
  34. package/dist/runner/index.d.ts +0 -45
  35. package/dist/runner/index.d.ts.map +0 -1
  36. package/dist/runner/index.js +0 -3
  37. package/dist/runner/protocolEndpoint.cjs +0 -4
  38. package/dist/runner/protocolEndpoint.d.cts +0 -22
  39. package/dist/runner/protocolEndpoint.d.cts.map +0 -1
  40. package/dist/runner/protocolEndpoint.d.ts +0 -22
  41. package/dist/runner/protocolEndpoint.d.ts.map +0 -1
  42. package/dist/runner/protocolEndpoint.js +0 -4
  43. package/dist/runner-DRLfwiqY.cjs.map +0 -1
  44. package/dist/runner-oZXbguX3.js.map +0 -1
  45. package/dist/types-C-XfFJ7u.d.cts +0 -58
  46. package/dist/types-C-XfFJ7u.d.cts.map +0 -1
  47. package/dist/types-CE7SvejR.d.ts +0 -58
  48. package/dist/types-CE7SvejR.d.ts.map +0 -1
@@ -1,45 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- * Public TypeScript declarations for this package entrypoint.
4
- */
5
- import { a as QuickJsWorkerExecutorOptions, i as QuickJsInlineExecutorOptions, n as QuickJsExecutorOptions, o as WorkerResourceLimits, r as QuickJsHostedMode, t as QuickJsExecutorHost } from "../types-CE7SvejR.js";
6
- import { QuickJSWASMModule } from "quickjs-emscripten";
7
- import { ExecuteResult, ExecutorRuntimeOptions, ProviderManifest, ToolCall, ToolCallResult } from "@execbox/core";
8
-
9
- //#region src/runner/index.d.ts
10
-
11
- /**
12
- * Transport-neutral host tool call emitted from a QuickJS session.
13
- */
14
- type QuickJsSessionToolCall = ToolCall;
15
- /**
16
- * Input required to run one transport-backed QuickJS execution session.
17
- */
18
- interface QuickJsSessionRequest {
19
- /** Optional abort controller that should be triggered when execution stops. */
20
- abortController?: AbortController;
21
- /** Guest JavaScript source to evaluate inside QuickJS. */
22
- code: string;
23
- /** Host callback used to fulfill guest tool calls. */
24
- onToolCall: (call: ToolCall) => Promise<ToolCallResult> | ToolCallResult;
25
- /** Optional hook invoked once the guest runtime has started. */
26
- onStarted?: () => void;
27
- /** Transport-safe provider manifests exposed to the guest runtime. */
28
- providers: ProviderManifest[];
29
- /** Optional caller-owned abort signal for the session. */
30
- signal?: AbortSignal;
31
- }
32
- /**
33
- * Options controlling one transport-backed QuickJS session.
34
- */
35
- type QuickJsSessionOptions = ExecutorRuntimeOptions & Pick<QuickJsInlineExecutorOptions, "loadModule"> & {
36
- /** Optional preloaded QuickJS WASM module instance. */
37
- module?: QuickJSWASMModule;
38
- };
39
- /**
40
- * Runs one QuickJS-backed execution session using a transport-neutral tool callback.
41
- */
42
- declare function runQuickJsSession(request: QuickJsSessionRequest, options?: QuickJsSessionOptions): Promise<ExecuteResult>;
43
- //#endregion
44
- export { type QuickJsExecutorHost, type QuickJsExecutorOptions, type QuickJsHostedMode, type QuickJsInlineExecutorOptions, QuickJsSessionOptions, QuickJsSessionRequest, QuickJsSessionToolCall, type QuickJsWorkerExecutorOptions, type WorkerResourceLimits, runQuickJsSession };
45
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/runner/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AA6DA,CAAA,CAAA,CAAA,SAAA,CAAA,OAAA,CAAA,IAAA,CAAA,IAAA,CAAA,IAAA,CAAA,OAAA,CAAA,IAAA,CAAA,CAAA,CAAA,OAAA,CAAA,OAAA;AAKA,CAAA,CAAA;AAEoB,IAAA,CAPR,sBAAA,CAAA,CAAA,CAAyB,QAOjB;;;;AAMwC,SAAA,CAR3C,qBAAA,CAQ2C;EAM/C,CAAA,CAAA,CAAA,CAAA,QAAA,CAAA,KAAA,CAAA,UAAA,CAAA,IAAA,CAAA,MAAA,CAAA,EAAA,CAAA,SAAA,CAAA,IAAA,CAAA,SAAA,CAAA,KAAA,CAAA,CAAA,CAAA;EAGF,eAAA,CAAA,CAAA,CAfS,eAeT;EAAW,CAAA,CAAA,CAAA,CAAA,KAAA,CAAA,UAAA,CAAA,MAAA,CAAA,EAAA,CAAA,QAAA,CAAA,MAAA,CAAA,OAAA,CAAA,CAAA,CAAA;EAMV,IAAA,CAAA,CAAA,MAAA;EAAwB,CAAA,CAAA,CAAA,CAAA,IAAA,CAAA,QAAA,CAAA,IAAA,CAAA,EAAA,CAAA,OAAA,CAAA,KAAA,CAAA,IAAA,CAAA,KAAA,CAAA,CAAA,CAAA;EAC7B,UAAA,CAAA,CAAA,CAAA,IAAA,CAAA,CAhBc,QAgBd,CAAA,CAAA,CAAA,CAAA,CAhB2B,OAgB3B,CAhBmC,cAgBnC,CAAA,CAAA,CAAA,CAhBqD,cAgBrD;EAAL,CAAA,CAAA,CAAA,CAAA,QAAA,CAAA,IAAA,CAAA,OAAA,CAAA,IAAA,CAAA,GAAA,CAAA,KAAA,CAAA,OAAA,CAAA,GAAA,CAAA,OAAA,CAAA,CAAA,CAAA;EAEW,SAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,IAAA;EAAiB,CAAA,CAAA,CAAA,CAAA,SAAA,CAAA,IAAA,CAAA,QAAA,CAAA,SAAA,CAAA,OAAA,CAAA,EAAA,CAAA,GAAA,CAAA,KAAA,CAAA,OAAA,CAAA,CAAA,CAAA;EA4TR,SAAA,CAAA,CAxUT,gBAwU0B,CAAA,CAAA;EAC5B,CAAA,CAAA,CAAA,CAAA,QAAA,CAAA,MAAA,CAAA,KAAA,CAAA,KAAA,CAAA,MAAA,CAAA,GAAA,CAAA,GAAA,CAAA,OAAA,CAAA,CAAA,CAAA;EACA,MAAA,CAAA,CAAA,CAvUA,WAuUA;;;;;KAjUC,qBAAA,CAAA,CAAA,CAAwB,yBAClC,KAAK;;WAEM;;;;;iBA4TS,iBAAA,UACX,iCACA,wBACR,QAAQ"}
@@ -1,3 +0,0 @@
1
- import { t as runQuickJsSession } from "../runner-oZXbguX3.js";
2
-
3
- export { runQuickJsSession };
@@ -1,4 +0,0 @@
1
- require('../runner-DRLfwiqY.cjs');
2
- const require_protocolEndpoint = require('../protocolEndpoint-BGyrwlr_.cjs');
3
-
4
- exports.attachQuickJsProtocolEndpoint = require_protocolEndpoint.attachQuickJsProtocolEndpoint;
@@ -1,22 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- * Public TypeScript declarations for this package entrypoint.
4
- */
5
- import { DispatcherMessage, RunnerMessage } from "@execbox/core/protocol";
6
-
7
- //#region src/runner/protocolEndpoint.d.ts
8
-
9
- /**
10
- * Minimal worker-side port used by the shared QuickJS protocol endpoint.
11
- */
12
- interface QuickJsProtocolPort {
13
- onMessage(handler: (message: DispatcherMessage) => void): void | (() => void);
14
- send(message: RunnerMessage): void;
15
- }
16
- /**
17
- * Attaches the shared QuickJS protocol loop to a worker messaging port.
18
- */
19
- declare function attachQuickJsProtocolEndpoint(port: QuickJsProtocolPort): () => void;
20
- //#endregion
21
- export { QuickJsProtocolPort, attachQuickJsProtocolEndpoint };
22
- //# sourceMappingURL=protocolEndpoint.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"protocolEndpoint.d.cts","names":[],"sources":["../../src/runner/protocolEndpoint.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAmBA,CAAA,CAAA;AAQgB,SAAA,CARC,mBAAA,CAQ4B;+BAPd;gBACf;;;;;iBAMA,6BAAA,OACR"}
@@ -1,22 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- * Public TypeScript declarations for this package entrypoint.
4
- */
5
- import { DispatcherMessage, RunnerMessage } from "@execbox/core/protocol";
6
-
7
- //#region src/runner/protocolEndpoint.d.ts
8
-
9
- /**
10
- * Minimal worker-side port used by the shared QuickJS protocol endpoint.
11
- */
12
- interface QuickJsProtocolPort {
13
- onMessage(handler: (message: DispatcherMessage) => void): void | (() => void);
14
- send(message: RunnerMessage): void;
15
- }
16
- /**
17
- * Attaches the shared QuickJS protocol loop to a worker messaging port.
18
- */
19
- declare function attachQuickJsProtocolEndpoint(port: QuickJsProtocolPort): () => void;
20
- //#endregion
21
- export { QuickJsProtocolPort, attachQuickJsProtocolEndpoint };
22
- //# sourceMappingURL=protocolEndpoint.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"protocolEndpoint.d.ts","names":[],"sources":["../../src/runner/protocolEndpoint.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAmBA,CAAA,CAAA;AAQgB,SAAA,CARC,mBAAA,CAQ4B;+BAPd;gBACf;;;;;iBAMA,6BAAA,OACR"}
@@ -1,4 +0,0 @@
1
- import "../runner-oZXbguX3.js";
2
- import { t as attachQuickJsProtocolEndpoint } from "../protocolEndpoint-Ceadcq_L.js";
3
-
4
- export { attachQuickJsProtocolEndpoint };
@@ -1 +0,0 @@
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,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iB,OAAO;AAChC,kBAAgB,OAAO;AACvB,UAAQ,SAAS;AACjB,UAAQ,SAAS"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"runner-oZXbguX3.js","names":["rejection: unknown","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,SAA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
- */
5
- import { ExecutorPoolOptions, ExecutorRuntimeOptions } from "@execbox/core";
6
-
7
- //#region src/types.d.ts
8
-
9
- /**
10
- * Host boundary options available to the QuickJS executor.
11
- */
12
- type QuickJsExecutorHost = "inline" | "worker";
13
- /**
14
- * Lifecycle modes for worker-hosted QuickJS shells.
15
- */
16
- type QuickJsHostedMode = "pooled" | "ephemeral";
17
- /**
18
- * Optional V8 heap limits used only as a backstop for worker thread safety.
19
- */
20
- interface WorkerResourceLimits {
21
- /** Maximum size of the old generation heap in megabytes. */
22
- maxOldGenerationSizeMb?: number;
23
- /** Maximum size of the young generation heap in megabytes. */
24
- maxYoungGenerationSizeMb?: number;
25
- /** Maximum V8 stack size in megabytes. */
26
- stackSizeMb?: number;
27
- }
28
- /**
29
- * Options for constructing an inline QuickJS executor.
30
- */
31
- interface QuickJsInlineExecutorOptions extends ExecutorRuntimeOptions {
32
- /** Uses inline QuickJS execution inside the current process. */
33
- host?: "inline";
34
- /** Optional QuickJS module loader override for tests or custom builds. */
35
- loadModule?: () => Promise<unknown> | unknown;
36
- }
37
- /**
38
- * Options for constructing a worker-backed QuickJS executor.
39
- */
40
- interface QuickJsWorkerExecutorOptions extends ExecutorRuntimeOptions {
41
- /** Uses a worker thread to host each QuickJS runtime. */
42
- host: "worker";
43
- /** Time to wait before forcefully tearing down a hung worker shell. */
44
- cancelGraceMs?: number;
45
- /** Whether to reuse worker shells or spawn a fresh one per execution. */
46
- mode?: QuickJsHostedMode;
47
- /** Pool sizing and idle-eviction settings for pooled worker shells. */
48
- pool?: ExecutorPoolOptions;
49
- /** Optional worker thread V8 limits used as a coarse safety backstop. */
50
- workerResourceLimits?: WorkerResourceLimits;
51
- }
52
- /**
53
- * Options for constructing a QuickJS executor.
54
- */
55
- type QuickJsExecutorOptions = QuickJsInlineExecutorOptions | QuickJsWorkerExecutorOptions;
56
- //#endregion
57
- export { QuickJsWorkerExecutorOptions as a, QuickJsInlineExecutorOptions as i, QuickJsExecutorOptions as n, WorkerResourceLimits as o, QuickJsHostedMode as r, QuickJsExecutorHost as t };
58
- //# sourceMappingURL=types-C-XfFJ7u.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-C-XfFJ7u.d.cts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAQA,CAAA,CAAA;AAKY,IAAA,CALA,mBAAA,CAAA,CAAA,CAKiB,CAAA,MAAA,CAAA,CAAA,CAAA,CAAA,CAAA,MAAA,CAAA;AAK7B,CAAA,CAAA;AAYA,CAAA,CAAA,CAAA,SAAA,CAAA,KAAA,CAAA,GAAA,CAAA,MAAA,CAAA,MAAA,CAAA,OAAA,CAAA,MAAA;AAWA,CAAA,CAAA;AAQS,IAAA,CApCG,iBAAA,CAAA,CAAA,CAoCH,CAAA,MAAA,CAAA,CAAA,CAAA,CAAA,CAAA,SAAA,CAAA;;;;AARmE,SAAA,CAvB3D,oBAAA,CAuB2D;EAoBhE,CAAA,CAAA,CAAA,CAAA,OAAA,CAAA,IAAA,CAAA,EAAA,CAAA,GAAA,CAAA,GAAA,CAAA,UAAA,CAAA,IAAA,CAAA,EAAA,CAAA,SAAA,CAAA,CAAA,CAAA;;;;;;;;;;UA/BK,4BAAA,CAAA,OAAA,CAAqC;;;;qBAKjC;;;;;UAMJ,4BAAA,CAAA,OAAA,CAAqC;;;;;;SAQ7C;;SAGA;;yBAGgB;;;;;KAMb,sBAAA,CAAA,CAAA,CACR,+BACA"}
@@ -1,58 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- * Public TypeScript declarations for this package entrypoint.
4
- */
5
- import { ExecutorPoolOptions, ExecutorRuntimeOptions } from "@execbox/core";
6
-
7
- //#region src/types.d.ts
8
-
9
- /**
10
- * Host boundary options available to the QuickJS executor.
11
- */
12
- type QuickJsExecutorHost = "inline" | "worker";
13
- /**
14
- * Lifecycle modes for worker-hosted QuickJS shells.
15
- */
16
- type QuickJsHostedMode = "pooled" | "ephemeral";
17
- /**
18
- * Optional V8 heap limits used only as a backstop for worker thread safety.
19
- */
20
- interface WorkerResourceLimits {
21
- /** Maximum size of the old generation heap in megabytes. */
22
- maxOldGenerationSizeMb?: number;
23
- /** Maximum size of the young generation heap in megabytes. */
24
- maxYoungGenerationSizeMb?: number;
25
- /** Maximum V8 stack size in megabytes. */
26
- stackSizeMb?: number;
27
- }
28
- /**
29
- * Options for constructing an inline QuickJS executor.
30
- */
31
- interface QuickJsInlineExecutorOptions extends ExecutorRuntimeOptions {
32
- /** Uses inline QuickJS execution inside the current process. */
33
- host?: "inline";
34
- /** Optional QuickJS module loader override for tests or custom builds. */
35
- loadModule?: () => Promise<unknown> | unknown;
36
- }
37
- /**
38
- * Options for constructing a worker-backed QuickJS executor.
39
- */
40
- interface QuickJsWorkerExecutorOptions extends ExecutorRuntimeOptions {
41
- /** Uses a worker thread to host each QuickJS runtime. */
42
- host: "worker";
43
- /** Time to wait before forcefully tearing down a hung worker shell. */
44
- cancelGraceMs?: number;
45
- /** Whether to reuse worker shells or spawn a fresh one per execution. */
46
- mode?: QuickJsHostedMode;
47
- /** Pool sizing and idle-eviction settings for pooled worker shells. */
48
- pool?: ExecutorPoolOptions;
49
- /** Optional worker thread V8 limits used as a coarse safety backstop. */
50
- workerResourceLimits?: WorkerResourceLimits;
51
- }
52
- /**
53
- * Options for constructing a QuickJS executor.
54
- */
55
- type QuickJsExecutorOptions = QuickJsInlineExecutorOptions | QuickJsWorkerExecutorOptions;
56
- //#endregion
57
- export { QuickJsWorkerExecutorOptions as a, QuickJsInlineExecutorOptions as i, QuickJsExecutorOptions as n, WorkerResourceLimits as o, QuickJsHostedMode as r, QuickJsExecutorHost as t };
58
- //# sourceMappingURL=types-CE7SvejR.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-CE7SvejR.d.ts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAQA,CAAA,CAAA;AAKY,IAAA,CALA,mBAAA,CAAA,CAAA,CAKiB,CAAA,MAAA,CAAA,CAAA,CAAA,CAAA,CAAA,MAAA,CAAA;AAK7B,CAAA,CAAA;AAYA,CAAA,CAAA,CAAA,SAAA,CAAA,KAAA,CAAA,GAAA,CAAA,MAAA,CAAA,MAAA,CAAA,OAAA,CAAA,MAAA;AAWA,CAAA,CAAA;AAQS,IAAA,CApCG,iBAAA,CAAA,CAAA,CAoCH,CAAA,MAAA,CAAA,CAAA,CAAA,CAAA,CAAA,SAAA,CAAA;;;;AARmE,SAAA,CAvB3D,oBAAA,CAuB2D;EAoBhE,CAAA,CAAA,CAAA,CAAA,OAAA,CAAA,IAAA,CAAA,EAAA,CAAA,GAAA,CAAA,GAAA,CAAA,UAAA,CAAA,IAAA,CAAA,EAAA,CAAA,SAAA,CAAA,CAAA,CAAA;;;;;;;;;;UA/BK,4BAAA,CAAA,OAAA,CAAqC;;;;qBAKjC;;;;;UAMJ,4BAAA,CAAA,OAAA,CAAqC;;;;;;SAQ7C;;SAGA;;yBAGgB;;;;;KAMb,sBAAA,CAAA,CAAA,CACR,+BACA"}