@execbox/quickjs 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +21 -5
  2. package/dist/index.cjs +610 -7
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +19 -4
  5. package/dist/index.d.cts.map +1 -1
  6. package/dist/index.d.ts +19 -4
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +607 -4
  9. package/dist/index.js.map +1 -1
  10. package/dist/processEntry.cjs +17 -0
  11. package/dist/processEntry.cjs.map +1 -0
  12. package/dist/processEntry.d.cts +5 -0
  13. package/dist/processEntry.d.ts +5 -0
  14. package/dist/processEntry.js +18 -0
  15. package/dist/processEntry.js.map +1 -0
  16. package/dist/protocolEndpoint-A1JBvHG_.cjs +147 -0
  17. package/dist/protocolEndpoint-A1JBvHG_.cjs.map +1 -0
  18. package/dist/protocolEndpoint-CDGgtfFu.js +142 -0
  19. package/dist/protocolEndpoint-CDGgtfFu.js.map +1 -0
  20. package/dist/runner/index.cjs +1 -1
  21. package/dist/runner/index.d.cts +16 -78
  22. package/dist/runner/index.d.cts.map +1 -1
  23. package/dist/runner/index.d.ts +16 -78
  24. package/dist/runner/index.d.ts.map +1 -1
  25. package/dist/runner/index.js +1 -1
  26. package/dist/runner/protocolEndpoint.cjs +3 -137
  27. package/dist/runner/protocolEndpoint.d.cts +4 -0
  28. package/dist/runner/protocolEndpoint.d.cts.map +1 -1
  29. package/dist/runner/protocolEndpoint.d.ts +4 -0
  30. package/dist/runner/protocolEndpoint.d.ts.map +1 -1
  31. package/dist/runner/protocolEndpoint.js +3 -137
  32. package/dist/{runner-B4UG88h1.js → runner-CteKTaPD.js} +93 -10
  33. package/dist/runner-CteKTaPD.js.map +1 -0
  34. package/dist/{runner-DhOZH9xz.cjs → runner-DRt0kpEk.cjs} +140 -9
  35. package/dist/{runner-B4UG88h1.js.map → runner-DRt0kpEk.cjs.map} +1 -1
  36. package/dist/types-BeVqrcj8.d.ts +71 -0
  37. package/dist/types-BeVqrcj8.d.ts.map +1 -0
  38. package/dist/types-CnNmLawC.d.cts +71 -0
  39. package/dist/types-CnNmLawC.d.cts.map +1 -0
  40. package/dist/workerEntry.cjs +19 -0
  41. package/dist/workerEntry.cjs.map +1 -0
  42. package/dist/workerEntry.d.cts +5 -0
  43. package/dist/workerEntry.d.ts +5 -0
  44. package/dist/workerEntry.js +20 -0
  45. package/dist/workerEntry.js.map +1 -0
  46. package/package.json +16 -7
  47. package/dist/runner/protocolEndpoint.cjs.map +0 -1
  48. package/dist/runner/protocolEndpoint.js.map +0 -1
  49. package/dist/runner-DhOZH9xz.cjs.map +0 -1
  50. package/dist/types-BB8mb_-T.d.cts +0 -14
  51. package/dist/types-BB8mb_-T.d.cts.map +0 -1
  52. package/dist/types-D7uau0GM.d.ts +0 -14
  53. package/dist/types-D7uau0GM.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../../../core/src/types.ts","../../../core/src/runner.ts","../../src/runner/index.ts"],"sourcesContent":[],"mappings":";;;;;;ACeA;AASA;AASiB,KDlBL,gBAAA,GCkB2B,SAAA,GAAA,cAAA,GAAA,kBAAA,GAAA,YAAA,GAAA,eAAA,GAAA,qBAAA,GAAA,gBAAA;AAiBvC;AASA;;UDhCiB,YAAA;;EEuBL,IAAA,EFrBJ,gBEqBI;EAKK;EACG,OAAA,EAAA,MAAA;;;;;AAIP,KFvBD,aEuBC,CAAA,IAAA,OAAA,CAAA,GAAA;EACF,UAAA,EAAA,MAAA;EAAW,IAAA,EAAA,MAAA,EAAA;EAMV,EAAA,EAAA,IAAA;EAAwB,MAAA,EFzBtB,CEyBsB;CAClC,GAAA;EACW,UAAA,EAAA,MAAA;EAAiB,KAAA,EFvBjB,YEuBiB;EA4TR,IAAA,EAAA,MAAA,EAAA;EACX,EAAA,EAAA,KAAA;CACA;;;;;;AFpXC,UCAK,oBAA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,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,82 +1,13 @@
1
- import { t as QuickJsExecutorOptions } from "../types-D7uau0GM.js";
2
- import { QuickJSWASMModule } from "quickjs-emscripten";
3
-
4
- //#region ../core/src/types.d.ts
5
-
6
- /**
7
- * Stable error codes returned by executors and wrapped tool calls.
8
- */
9
- type ExecuteErrorCode = "timeout" | "memory_limit" | "validation_error" | "tool_error" | "runtime_error" | "serialization_error" | "internal_error";
10
- /**
11
- * Structured execution failure returned in {@link ExecuteResult}.
12
- */
13
- interface ExecuteError {
14
- /** Machine-readable error category. */
15
- code: ExecuteErrorCode;
16
- /** Human-readable failure message. */
17
- message: string;
18
- }
19
- /**
20
- * Structured result returned by every executor invocation.
21
- */
22
- type ExecuteResult<T = unknown> = {
23
- durationMs: number;
24
- logs: string[];
25
- ok: true;
26
- result: T;
27
- } | {
28
- durationMs: number;
29
- error: ExecuteError;
30
- logs: string[];
31
- ok: false;
32
- };
33
- //#endregion
34
- //#region ../core/src/runner.d.ts
35
- /**
36
- * Transport-safe metadata for one exposed tool.
37
- */
38
- interface ProviderToolManifest {
39
- description?: string;
40
- originalName: string;
41
- safeName: string;
42
- }
43
1
  /**
44
- * Namespace manifest shared with runner implementations.
2
+ * @packageDocumentation
3
+ * Public TypeScript declarations for this package entrypoint.
45
4
  */
46
- interface ProviderManifest {
47
- name: string;
48
- tools: Record<string, ProviderToolManifest>;
49
- types: string;
50
- }
51
- /**
52
- * Execution limits forwarded to runner implementations.
53
- */
54
- interface ExecutorRuntimeOptions {
55
- maxLogChars?: number;
56
- maxLogLines?: number;
57
- memoryLimitBytes?: number;
58
- timeoutMs?: number;
59
- }
60
- /**
61
- * Tool invocation request emitted from a runner.
62
- */
63
- interface ToolCall {
64
- input: unknown;
65
- providerName: string;
66
- safeToolName: string;
67
- }
68
- /**
69
- * Trusted host response to a tool invocation request.
70
- */
71
- type ToolCallResult = {
72
- ok: true;
73
- result: unknown;
74
- } | {
75
- error: ExecuteError;
76
- ok: false;
77
- };
78
- //#endregion
5
+ import { a as QuickJsProcessExecutorOptions, i as QuickJsInlineExecutorOptions, n as QuickJsExecutorOptions, o as QuickJsWorkerExecutorOptions, r as QuickJsHostedMode, s as WorkerResourceLimits, t as QuickJsExecutorHost } from "../types-BeVqrcj8.js";
6
+ import { QuickJSWASMModule } from "quickjs-emscripten";
7
+ import { ExecuteResult, ExecutorRuntimeOptions, ProviderManifest, ToolCall, ToolCallResult } from "@execbox/core";
8
+
79
9
  //#region src/runner/index.d.ts
10
+
80
11
  /**
81
12
  * Transport-neutral host tool call emitted from a QuickJS session.
82
13
  */
@@ -85,17 +16,24 @@ type QuickJsSessionToolCall = ToolCall;
85
16
  * Input required to run one transport-backed QuickJS execution session.
86
17
  */
87
18
  interface QuickJsSessionRequest {
19
+ /** Optional abort controller that should be triggered when execution stops. */
88
20
  abortController?: AbortController;
21
+ /** Guest JavaScript source to evaluate inside QuickJS. */
89
22
  code: string;
23
+ /** Host callback used to fulfill guest tool calls. */
90
24
  onToolCall: (call: ToolCall) => Promise<ToolCallResult> | ToolCallResult;
25
+ /** Optional hook invoked once the guest runtime has started. */
91
26
  onStarted?: () => void;
27
+ /** Transport-safe provider manifests exposed to the guest runtime. */
92
28
  providers: ProviderManifest[];
29
+ /** Optional caller-owned abort signal for the session. */
93
30
  signal?: AbortSignal;
94
31
  }
95
32
  /**
96
33
  * Options controlling one transport-backed QuickJS session.
97
34
  */
98
- type QuickJsSessionOptions = QuickJsExecutorOptions & ExecutorRuntimeOptions & {
35
+ type QuickJsSessionOptions = ExecutorRuntimeOptions & Pick<QuickJsInlineExecutorOptions, "loadModule"> & {
36
+ /** Optional preloaded QuickJS WASM module instance. */
99
37
  module?: QuickJSWASMModule;
100
38
  };
101
39
  /**
@@ -103,5 +41,5 @@ type QuickJsSessionOptions = QuickJsExecutorOptions & ExecutorRuntimeOptions & {
103
41
  */
104
42
  declare function runQuickJsSession(request: QuickJsSessionRequest, options?: QuickJsSessionOptions): Promise<ExecuteResult>;
105
43
  //#endregion
106
- export { QuickJsSessionOptions, QuickJsSessionRequest, QuickJsSessionToolCall, runQuickJsSession };
44
+ export { type QuickJsExecutorHost, type QuickJsExecutorOptions, type QuickJsHostedMode, type QuickJsInlineExecutorOptions, type QuickJsProcessExecutorOptions, QuickJsSessionOptions, QuickJsSessionRequest, QuickJsSessionToolCall, type QuickJsWorkerExecutorOptions, type WorkerResourceLimits, runQuickJsSession };
107
45
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../core/src/types.ts","../../../core/src/runner.ts","../../src/runner/index.ts"],"sourcesContent":[],"mappings":";;;;;;ACeA;AASA;AASiB,KDlBL,gBAAA,GCkB2B,SAAA,GAAA,cAAA,GAAA,kBAAA,GAAA,YAAA,GAAA,eAAA,GAAA,qBAAA,GAAA,gBAAA;AAiBvC;AASA;;UDhCiB,YAAA;;EEuBL,IAAA,EFrBJ,gBEqBI;EAKK;EACG,OAAA,EAAA,MAAA;;;;;AAIP,KFvBD,aEuBC,CAAA,IAAA,OAAA,CAAA,GAAA;EACF,UAAA,EAAA,MAAA;EAAW,IAAA,EAAA,MAAA,EAAA;EAMV,EAAA,EAAA,IAAA;EAAwB,MAAA,EFzBtB,CEyBsB;CAClC,GAAA;EACW,UAAA,EAAA,MAAA;EAAiB,KAAA,EFvBjB,YEuBiB;EA4TR,IAAA,EAAA,MAAA,EAAA;EACX,EAAA,EAAA,KAAA;CACA;;;;;;AFpXC,UCAK,oBAAA,CDAW;EAYX,WAAA,CAAA,EAAA,MAAY;EAUjB,YAAA,EAAA,MAAa;;;;ACtB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,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 +1,3 @@
1
- import { t as runQuickJsSession } from "../runner-B4UG88h1.js";
1
+ import { t as runQuickJsSession } from "../runner-CteKTaPD.js";
2
2
 
3
3
  export { runQuickJsSession };
@@ -1,138 +1,4 @@
1
- const require_runner = require('../runner-DhOZH9xz.cjs');
2
- let node_crypto = require("node:crypto");
1
+ require('../runner-DRt0kpEk.cjs');
2
+ const require_protocolEndpoint = require('../protocolEndpoint-A1JBvHG_.cjs');
3
3
 
4
- //#region ../protocol/src/messages.ts
5
- function isRecord(value) {
6
- return typeof value === "object" && value !== null;
7
- }
8
- function isFiniteNumber(value) {
9
- return typeof value === "number" && Number.isFinite(value);
10
- }
11
- function isRuntimeOptions(value) {
12
- if (!isRecord(value)) return false;
13
- return isFiniteNumber(value.maxLogChars) && isFiniteNumber(value.maxLogLines) && isFiniteNumber(value.memoryLimitBytes) && isFiniteNumber(value.timeoutMs);
14
- }
15
- function isProviderManifest(value) {
16
- if (!isRecord(value) || typeof value.name !== "string") return false;
17
- if (!isRecord(value.tools) || typeof value.types !== "string") return false;
18
- return Object.values(value.tools).every((tool) => isRecord(tool) && typeof tool.originalName === "string" && typeof tool.safeName === "string" && (tool.description === void 0 || typeof tool.description === "string"));
19
- }
20
- function isExecuteError(value) {
21
- return isRecord(value) && typeof value.code === "string" && typeof value.message === "string";
22
- }
23
- /**
24
- * Returns whether an unknown value is a dispatcher-to-runner message.
25
- */
26
- function isDispatcherMessage(value) {
27
- if (!isRecord(value) || typeof value.type !== "string") return false;
28
- switch (value.type) {
29
- case "cancel": return typeof value.id === "string";
30
- case "execute": return typeof value.code === "string" && typeof value.id === "string" && isRuntimeOptions(value.options) && Array.isArray(value.providers) && value.providers.every(isProviderManifest);
31
- case "tool_result":
32
- if (typeof value.callId !== "string" || typeof value.ok !== "boolean") return false;
33
- if (value.ok) return "result" in value;
34
- return isExecuteError(value.error);
35
- default: return false;
36
- }
37
- }
38
-
39
- //#endregion
40
- //#region src/runner/protocolEndpoint.ts
41
- /**
42
- * Attaches the shared QuickJS protocol loop to a worker/process messaging port.
43
- */
44
- function attachQuickJsProtocolEndpoint(port) {
45
- const pendingToolCalls = /* @__PURE__ */ new Map();
46
- let activeAbortController;
47
- let activeExecutionId;
48
- async function startExecution(message) {
49
- if (activeExecutionId) {
50
- port.send({
51
- durationMs: 0,
52
- error: {
53
- code: "internal_error",
54
- message: "QuickJS endpoint already has an active execution"
55
- },
56
- id: message.id,
57
- logs: [],
58
- ok: false,
59
- type: "done"
60
- });
61
- return;
62
- }
63
- const abortController = new AbortController();
64
- activeAbortController = abortController;
65
- activeExecutionId = message.id;
66
- try {
67
- const result = await require_runner.runQuickJsSession({
68
- abortController,
69
- code: message.code,
70
- onStarted: () => {
71
- port.send({
72
- id: message.id,
73
- type: "started"
74
- });
75
- },
76
- onToolCall: (call) => new Promise((resolve) => {
77
- const callId = (0, node_crypto.randomUUID)();
78
- pendingToolCalls.set(callId, resolve);
79
- port.send({
80
- ...call,
81
- callId,
82
- type: "tool_call"
83
- });
84
- }),
85
- providers: message.providers
86
- }, message.options);
87
- port.send({
88
- ...result,
89
- id: message.id,
90
- type: "done"
91
- });
92
- } catch (error) {
93
- port.send({
94
- durationMs: 0,
95
- error: {
96
- code: "internal_error",
97
- message: error instanceof Error ? error.message : String(error)
98
- },
99
- id: message.id,
100
- logs: [],
101
- ok: false,
102
- type: "done"
103
- });
104
- } finally {
105
- pendingToolCalls.clear();
106
- activeAbortController = void 0;
107
- activeExecutionId = void 0;
108
- }
109
- }
110
- const maybeDetach = port.onMessage((message) => {
111
- if (!isDispatcherMessage(message)) return;
112
- switch (message.type) {
113
- case "cancel":
114
- if (message.id === activeExecutionId) activeAbortController?.abort();
115
- break;
116
- case "execute":
117
- startExecution(message);
118
- break;
119
- case "tool_result": {
120
- const resolve = pendingToolCalls.get(message.callId);
121
- pendingToolCalls.delete(message.callId);
122
- resolve?.(message);
123
- break;
124
- }
125
- }
126
- });
127
- return () => {
128
- if (typeof maybeDetach === "function") maybeDetach();
129
- pendingToolCalls.clear();
130
- activeAbortController?.abort();
131
- activeAbortController = void 0;
132
- activeExecutionId = void 0;
133
- };
134
- }
135
-
136
- //#endregion
137
- exports.attachQuickJsProtocolEndpoint = attachQuickJsProtocolEndpoint;
138
- //# sourceMappingURL=protocolEndpoint.cjs.map
4
+ exports.attachQuickJsProtocolEndpoint = require_protocolEndpoint.attachQuickJsProtocolEndpoint;
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * Public TypeScript declarations for this package entrypoint.
4
+ */
1
5
  import { DispatcherMessage, RunnerMessage } from "@execbox/protocol";
2
6
 
3
7
  //#region src/runner/protocolEndpoint.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"protocolEndpoint.d.cts","names":[],"sources":["../../src/runner/protocolEndpoint.ts"],"sourcesContent":[],"mappings":";;;;;;AAeA;AAQgB,UARC,mBAAA,CAQ4B;+BAPd;gBACf;;;;;iBAMA,6BAAA,OACR"}
1
+ {"version":3,"file":"protocolEndpoint.d.cts","names":[],"sources":["../../src/runner/protocolEndpoint.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAqBA,CAAA,CAAA;AAQgB,SAAA,CARC,mBAAA,CAQ4B;+BAPd;gBACf;;;;;iBAMA,6BAAA,OACR"}
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * Public TypeScript declarations for this package entrypoint.
4
+ */
1
5
  import { DispatcherMessage, RunnerMessage } from "@execbox/protocol";
2
6
 
3
7
  //#region src/runner/protocolEndpoint.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"protocolEndpoint.d.ts","names":[],"sources":["../../src/runner/protocolEndpoint.ts"],"sourcesContent":[],"mappings":";;;;;;AAeA;AAQgB,UARC,mBAAA,CAQ4B;+BAPd;gBACf;;;;;iBAMA,6BAAA,OACR"}
1
+ {"version":3,"file":"protocolEndpoint.d.ts","names":[],"sources":["../../src/runner/protocolEndpoint.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAqBA,CAAA,CAAA;AAQgB,SAAA,CARC,mBAAA,CAQ4B;+BAPd;gBACf;;;;;iBAMA,6BAAA,OACR"}
@@ -1,138 +1,4 @@
1
- import { t as runQuickJsSession } from "../runner-B4UG88h1.js";
2
- import { randomUUID } from "node:crypto";
1
+ import "../runner-CteKTaPD.js";
2
+ import { t as attachQuickJsProtocolEndpoint } from "../protocolEndpoint-CDGgtfFu.js";
3
3
 
4
- //#region ../protocol/src/messages.ts
5
- function isRecord(value) {
6
- return typeof value === "object" && value !== null;
7
- }
8
- function isFiniteNumber(value) {
9
- return typeof value === "number" && Number.isFinite(value);
10
- }
11
- function isRuntimeOptions(value) {
12
- if (!isRecord(value)) return false;
13
- return isFiniteNumber(value.maxLogChars) && isFiniteNumber(value.maxLogLines) && isFiniteNumber(value.memoryLimitBytes) && isFiniteNumber(value.timeoutMs);
14
- }
15
- function isProviderManifest(value) {
16
- if (!isRecord(value) || typeof value.name !== "string") return false;
17
- if (!isRecord(value.tools) || typeof value.types !== "string") return false;
18
- return Object.values(value.tools).every((tool) => isRecord(tool) && typeof tool.originalName === "string" && typeof tool.safeName === "string" && (tool.description === void 0 || typeof tool.description === "string"));
19
- }
20
- function isExecuteError(value) {
21
- return isRecord(value) && typeof value.code === "string" && typeof value.message === "string";
22
- }
23
- /**
24
- * Returns whether an unknown value is a dispatcher-to-runner message.
25
- */
26
- function isDispatcherMessage(value) {
27
- if (!isRecord(value) || typeof value.type !== "string") return false;
28
- switch (value.type) {
29
- case "cancel": return typeof value.id === "string";
30
- case "execute": return typeof value.code === "string" && typeof value.id === "string" && isRuntimeOptions(value.options) && Array.isArray(value.providers) && value.providers.every(isProviderManifest);
31
- case "tool_result":
32
- if (typeof value.callId !== "string" || typeof value.ok !== "boolean") return false;
33
- if (value.ok) return "result" in value;
34
- return isExecuteError(value.error);
35
- default: return false;
36
- }
37
- }
38
-
39
- //#endregion
40
- //#region src/runner/protocolEndpoint.ts
41
- /**
42
- * Attaches the shared QuickJS protocol loop to a worker/process messaging port.
43
- */
44
- function attachQuickJsProtocolEndpoint(port) {
45
- const pendingToolCalls = /* @__PURE__ */ new Map();
46
- let activeAbortController;
47
- let activeExecutionId;
48
- async function startExecution(message) {
49
- if (activeExecutionId) {
50
- port.send({
51
- durationMs: 0,
52
- error: {
53
- code: "internal_error",
54
- message: "QuickJS endpoint already has an active execution"
55
- },
56
- id: message.id,
57
- logs: [],
58
- ok: false,
59
- type: "done"
60
- });
61
- return;
62
- }
63
- const abortController = new AbortController();
64
- activeAbortController = abortController;
65
- activeExecutionId = message.id;
66
- try {
67
- const result = await runQuickJsSession({
68
- abortController,
69
- code: message.code,
70
- onStarted: () => {
71
- port.send({
72
- id: message.id,
73
- type: "started"
74
- });
75
- },
76
- onToolCall: (call) => new Promise((resolve) => {
77
- const callId = randomUUID();
78
- pendingToolCalls.set(callId, resolve);
79
- port.send({
80
- ...call,
81
- callId,
82
- type: "tool_call"
83
- });
84
- }),
85
- providers: message.providers
86
- }, message.options);
87
- port.send({
88
- ...result,
89
- id: message.id,
90
- type: "done"
91
- });
92
- } catch (error) {
93
- port.send({
94
- durationMs: 0,
95
- error: {
96
- code: "internal_error",
97
- message: error instanceof Error ? error.message : String(error)
98
- },
99
- id: message.id,
100
- logs: [],
101
- ok: false,
102
- type: "done"
103
- });
104
- } finally {
105
- pendingToolCalls.clear();
106
- activeAbortController = void 0;
107
- activeExecutionId = void 0;
108
- }
109
- }
110
- const maybeDetach = port.onMessage((message) => {
111
- if (!isDispatcherMessage(message)) return;
112
- switch (message.type) {
113
- case "cancel":
114
- if (message.id === activeExecutionId) activeAbortController?.abort();
115
- break;
116
- case "execute":
117
- startExecution(message);
118
- break;
119
- case "tool_result": {
120
- const resolve = pendingToolCalls.get(message.callId);
121
- pendingToolCalls.delete(message.callId);
122
- resolve?.(message);
123
- break;
124
- }
125
- }
126
- });
127
- return () => {
128
- if (typeof maybeDetach === "function") maybeDetach();
129
- pendingToolCalls.clear();
130
- activeAbortController?.abort();
131
- activeAbortController = void 0;
132
- activeExecutionId = void 0;
133
- };
134
- }
135
-
136
- //#endregion
137
- export { attachQuickJsProtocolEndpoint };
138
- //# sourceMappingURL=protocolEndpoint.js.map
4
+ export { attachQuickJsProtocolEndpoint };
@@ -28,6 +28,20 @@ function getExecutionTimeoutMessage() {
28
28
  return EXECUTION_TIMEOUT_MESSAGE;
29
29
  }
30
30
  /**
31
+ * Creates the canonical timeout failure result used for preflight cancellation.
32
+ */
33
+ function createTimeoutExecuteResult(durationMs = 0) {
34
+ return {
35
+ durationMs,
36
+ error: {
37
+ code: "timeout",
38
+ message: getExecutionTimeoutMessage()
39
+ },
40
+ logs: [],
41
+ ok: false
42
+ };
43
+ }
44
+ /**
31
45
  * Normalizes an unknown thrown value into a human-readable message.
32
46
  */
33
47
  function normalizeThrownMessage(error) {
@@ -39,6 +53,17 @@ function normalizeThrownMessage(error) {
39
53
  return String(error);
40
54
  }
41
55
  /**
56
+ * Builds the standard tool execution context passed to resolved tool wrappers.
57
+ */
58
+ function createExecutionContext(signal, providerName, safeToolName, originalToolName) {
59
+ return {
60
+ originalToolName,
61
+ providerName,
62
+ safeToolName,
63
+ signal
64
+ };
65
+ }
66
+ /**
42
67
  * Truncates captured logs to the configured line and character limits.
43
68
  */
44
69
  function truncateLogs(logs, maxLogLines, maxLogChars) {
@@ -5226,6 +5251,66 @@ var ExecuteFailure = class extends Error {
5226
5251
  function isExecuteFailure(value) {
5227
5252
  return value instanceof ExecuteFailure;
5228
5253
  }
5254
+ /**
5255
+ * Returns whether a value can be serialized through the JSON-only host/guest boundary.
5256
+ */
5257
+ function isJsonSerializable(value, active = /* @__PURE__ */ new Set(), memo = /* @__PURE__ */ new WeakSet()) {
5258
+ if (value === null) return true;
5259
+ switch (typeof value) {
5260
+ case "string":
5261
+ case "boolean": return true;
5262
+ case "number": return Number.isFinite(value);
5263
+ case "bigint":
5264
+ case "function":
5265
+ case "symbol":
5266
+ case "undefined": return false;
5267
+ case "object": {
5268
+ const objectValue = value;
5269
+ if (memo.has(objectValue)) return true;
5270
+ if (active.has(objectValue)) return false;
5271
+ active.add(objectValue);
5272
+ let isSerializable = false;
5273
+ try {
5274
+ if (Array.isArray(value)) {
5275
+ isSerializable = value.every((item) => isJsonSerializable(item, active, memo));
5276
+ return isSerializable;
5277
+ }
5278
+ const prototype = Object.getPrototypeOf(value);
5279
+ if (prototype !== Object.prototype && prototype !== null) return false;
5280
+ isSerializable = Object.values(value).every((item) => isJsonSerializable(item, active, memo));
5281
+ return isSerializable;
5282
+ } finally {
5283
+ active.delete(objectValue);
5284
+ if (isSerializable) memo.add(objectValue);
5285
+ }
5286
+ }
5287
+ }
5288
+ return false;
5289
+ }
5290
+
5291
+ //#endregion
5292
+ //#region ../core/src/runtimeOptions.ts
5293
+ /**
5294
+ * Default runtime limits shared across the built-in executor implementations.
5295
+ */
5296
+ const DEFAULT_EXECUTOR_RUNTIME_OPTIONS = {
5297
+ maxLogChars: 64e3,
5298
+ maxLogLines: 100,
5299
+ memoryLimitBytes: 64 * 1024 * 1024,
5300
+ timeoutMs: 5e3
5301
+ };
5302
+ /**
5303
+ * Resolves executor runtime limits by applying explicit overrides on top of a
5304
+ * base options object and finally the shared defaults.
5305
+ */
5306
+ function resolveExecutorRuntimeOptions(options = {}, overrides = {}) {
5307
+ return {
5308
+ maxLogChars: overrides.maxLogChars ?? options.maxLogChars ?? DEFAULT_EXECUTOR_RUNTIME_OPTIONS.maxLogChars,
5309
+ maxLogLines: overrides.maxLogLines ?? options.maxLogLines ?? DEFAULT_EXECUTOR_RUNTIME_OPTIONS.maxLogLines,
5310
+ memoryLimitBytes: overrides.memoryLimitBytes ?? options.memoryLimitBytes ?? DEFAULT_EXECUTOR_RUNTIME_OPTIONS.memoryLimitBytes,
5311
+ timeoutMs: overrides.timeoutMs ?? options.timeoutMs ?? DEFAULT_EXECUTOR_RUNTIME_OPTIONS.timeoutMs
5312
+ };
5313
+ }
5229
5314
 
5230
5315
  //#endregion
5231
5316
  //#region src/quickjsBridge.ts
@@ -5282,10 +5367,10 @@ function toGuestHandle(context, value) {
5282
5367
 
5283
5368
  //#endregion
5284
5369
  //#region src/runner/index.ts
5285
- const DEFAULT_MEMORY_LIMIT_BYTES = 64 * 1024 * 1024;
5286
- const DEFAULT_TIMEOUT_MS = 5e3;
5287
- const DEFAULT_MAX_LOG_LINES = 100;
5288
- const DEFAULT_MAX_LOG_CHARS = 64e3;
5370
+ /**
5371
+ * @packageDocumentation
5372
+ * Public API for the `@execbox/quickjs/runner` entrypoint.
5373
+ */
5289
5374
  const loadDefaultModule = memoizePromiseFactory(() => newQuickJSWASMModule(RELEASE_SYNC));
5290
5375
  /**
5291
5376
  * Converts unexpected executor failures into stable public result errors.
@@ -5479,14 +5564,12 @@ function createToolHandle(context, providerName, safeToolName, signal, trustedHo
5479
5564
  * Runs one QuickJS-backed execution session using a transport-neutral tool callback.
5480
5565
  */
5481
5566
  async function runQuickJsSession(request, options = {}) {
5567
+ const runtimeOptions = resolveExecutorRuntimeOptions(options);
5482
5568
  const loadModule = async () => {
5483
5569
  if (options.module) return options.module;
5484
5570
  return options.loadModule ? await options.loadModule() : await loadDefaultModule();
5485
5571
  };
5486
- const maxLogChars = options.maxLogChars ?? DEFAULT_MAX_LOG_CHARS;
5487
- const maxLogLines = options.maxLogLines ?? DEFAULT_MAX_LOG_LINES;
5488
- const memoryLimitBytes = options.memoryLimitBytes ?? DEFAULT_MEMORY_LIMIT_BYTES;
5489
- const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
5572
+ const { maxLogChars, maxLogLines, memoryLimitBytes, timeoutMs } = runtimeOptions;
5490
5573
  const startedAt = Date.now();
5491
5574
  const logs = [];
5492
5575
  const abortController = new AbortController();
@@ -5567,5 +5650,5 @@ async function runQuickJsSession(request, options = {}) {
5567
5650
  }
5568
5651
 
5569
5652
  //#endregion
5570
- export { runQuickJsSession as t };
5571
- //# sourceMappingURL=runner-B4UG88h1.js.map
5653
+ export { isJsonSerializable as a, getExecutionTimeoutMessage as c, isExecuteFailure as i, normalizeThrownMessage as l, resolveExecutorRuntimeOptions as n, createExecutionContext as o, ExecuteFailure as r, createTimeoutExecuteResult as s, runQuickJsSession as t };
5654
+ //# sourceMappingURL=runner-CteKTaPD.js.map