@execbox/quickjs 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mouaad Aallam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # @execbox/quickjs
2
+
3
+ QuickJS executor backend for `@execbox/core`.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/%40execbox%2Fquickjs?style=flat-square)](https://www.npmjs.com/package/@execbox/quickjs)
6
+ [![License](https://img.shields.io/github/license/aallam/execbox?style=flat-square)](https://github.com/aallam/execbox/blob/main/LICENSE)
7
+
8
+ ## Choose QuickJS When
9
+
10
+ - you want the easiest execbox backend to install
11
+ - you do not want a native addon in CI or local development
12
+ - you want fresh runtimes, captured `console.*` output, and JSON-only tool boundaries
13
+
14
+ ## Security Notes
15
+
16
+ - Each execution gets a fresh QuickJS runtime with no ambient Node globals injected by execbox.
17
+ - Tool calls cross a JSON-only bridge, and executor timeouts propagate abort signals to in-flight provider work.
18
+ - In the default deployment model, provider definitions are controlled by the host application, while hostile users control guest code and tool inputs.
19
+ - This package is not presented as a hard security boundary for hostile code. It is best-effort in-process isolation.
20
+ - If you need a stronger boundary, run execbox behind a separate process or container.
21
+
22
+ ## Architecture Docs
23
+
24
+ - [Execbox architecture overview](https://github.com/aallam/execbox/blob/main/docs/execbox/architecture/README.md)
25
+ - [Execbox executors](https://github.com/aallam/execbox/blob/main/docs/execbox/architecture/execbox-executors.md)
26
+ - [Execbox MCP adapters and protocol](https://github.com/aallam/execbox/blob/main/docs/execbox/architecture/execbox-mcp-and-protocol.md)
27
+
28
+ ## Examples
29
+
30
+ - [Basic provider execution](https://github.com/aallam/execbox/blob/main/examples/execbox-basic.ts)
31
+ - [Worker-backed QuickJS execution](https://github.com/aallam/execbox/blob/main/examples/execbox-worker.ts)
32
+ - [MCP provider wrapping](https://github.com/aallam/execbox/blob/main/examples/execbox-mcp-provider.ts)
33
+ - [MCP server wrapper](https://github.com/aallam/execbox/blob/main/examples/execbox-mcp-server.ts)
34
+ - [Full examples index](https://github.com/aallam/execbox/tree/main/examples)
35
+
36
+ ## Install
37
+
38
+ ```bash
39
+ npm install @execbox/core @execbox/quickjs
40
+ ```
41
+
42
+ Advanced consumers can also import the reusable QuickJS runner from `@execbox/quickjs/runner`.
43
+ Transport-backed executors such as `@execbox/worker` and `@execbox/process` also reuse the shared QuickJS protocol endpoint from `@execbox/quickjs/runner/protocol-endpoint`.
44
+
45
+ ## Usage
46
+
47
+ ```ts
48
+ import { resolveProvider } from "@execbox/core";
49
+ import { QuickJsExecutor } from "@execbox/quickjs";
50
+
51
+ const provider = resolveProvider({
52
+ tools: {
53
+ echo: {
54
+ execute: async (input) => input,
55
+ },
56
+ },
57
+ });
58
+
59
+ const executor = new QuickJsExecutor();
60
+ const result = await executor.execute("await codemode.echo({ ok: true })", [
61
+ provider,
62
+ ]);
63
+ ```
64
+
65
+ Each execution runs in a fresh QuickJS runtime with timeout handling, captured logs, and JSON-only result and tool boundaries.
package/dist/index.cjs ADDED
@@ -0,0 +1,46 @@
1
+ const require_runner = require('./runner-CYXIVOmJ.cjs');
2
+ let __execbox_core = require("@execbox/core");
3
+
4
+ //#region src/quickjsExecutor.ts
5
+ /**
6
+ * QuickJS-backed executor for one-shot sandboxed JavaScript runs.
7
+ */
8
+ var QuickJsExecutor = class {
9
+ options;
10
+ /**
11
+ * Creates a QuickJS executor with one-shot runtime limits and host bridging configuration.
12
+ */
13
+ constructor(options = {}) {
14
+ this.options = options;
15
+ }
16
+ /**
17
+ * Executes JavaScript against the provided tool namespaces in a fresh QuickJS runtime.
18
+ */
19
+ async execute(code, providers, options = {}) {
20
+ if (options.signal?.aborted) return (0, __execbox_core.createTimeoutExecuteResult)();
21
+ const abortController = new AbortController();
22
+ const onToolCall = (0, __execbox_core.createToolCallDispatcher)(providers, abortController.signal);
23
+ const onAbort = () => {
24
+ abortController.abort();
25
+ };
26
+ options.signal?.addEventListener("abort", onAbort, { once: true });
27
+ try {
28
+ return await require_runner.runQuickJsSession({
29
+ abortController,
30
+ code,
31
+ onToolCall,
32
+ providers: (0, __execbox_core.extractProviderManifests)(providers)
33
+ }, {
34
+ ...this.options,
35
+ ...options
36
+ });
37
+ } finally {
38
+ options.signal?.removeEventListener("abort", onAbort);
39
+ abortController.abort();
40
+ }
41
+ }
42
+ };
43
+
44
+ //#endregion
45
+ exports.QuickJsExecutor = QuickJsExecutor;
46
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["runQuickJsSession"],"sources":["../src/quickjsExecutor.ts"],"sourcesContent":["import {\n createTimeoutExecuteResult,\n createToolCallDispatcher,\n extractProviderManifests,\n type ExecutionOptions,\n type ExecuteResult,\n type Executor,\n type ResolvedToolProvider,\n} from \"@execbox/core\";\n\nimport { runQuickJsSession } from \"./runner/index\";\nimport type { QuickJsExecutorOptions } from \"./types\";\n\n/**\n * QuickJS-backed executor for one-shot sandboxed JavaScript runs.\n */\nexport class QuickJsExecutor implements Executor {\n private readonly options: QuickJsExecutorOptions;\n\n /**\n * Creates a QuickJS executor with one-shot runtime limits and host bridging configuration.\n */\n constructor(options: QuickJsExecutorOptions = {}) {\n this.options = options;\n }\n\n /**\n * Executes JavaScript against the provided tool namespaces in a fresh QuickJS runtime.\n */\n async execute(\n code: string,\n providers: ResolvedToolProvider[],\n options: ExecutionOptions = {},\n ): Promise<ExecuteResult> {\n if (options.signal?.aborted) {\n return createTimeoutExecuteResult();\n }\n\n const abortController = new AbortController();\n const onToolCall = createToolCallDispatcher(\n providers,\n abortController.signal,\n );\n const onAbort = () => {\n abortController.abort();\n };\n\n options.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\n try {\n return await runQuickJsSession(\n {\n abortController,\n code,\n onToolCall,\n providers: extractProviderManifests(providers),\n },\n {\n ...this.options,\n ...options,\n },\n );\n } finally {\n options.signal?.removeEventListener(\"abort\", onAbort);\n abortController.abort();\n }\n }\n}\n"],"mappings":";;;;;;;AAgBA,IAAa,kBAAb,MAAiD;CAC/C,AAAiB;;;;CAKjB,YAAY,UAAkC,EAAE,EAAE;AAChD,OAAK,UAAU;;;;;CAMjB,MAAM,QACJ,MACA,WACA,UAA4B,EAAE,EACN;AACxB,MAAI,QAAQ,QAAQ,QAClB,wDAAmC;EAGrC,MAAM,kBAAkB,IAAI,iBAAiB;EAC7C,MAAM,0DACJ,WACA,gBAAgB,OACjB;EACD,MAAM,gBAAgB;AACpB,mBAAgB,OAAO;;AAGzB,UAAQ,QAAQ,iBAAiB,SAAS,SAAS,EAAE,MAAM,MAAM,CAAC;AAElE,MAAI;AACF,UAAO,MAAMA,iCACX;IACE;IACA;IACA;IACA,wDAAoC,UAAU;IAC/C,EACD;IACE,GAAG,KAAK;IACR,GAAG;IACJ,CACF;YACO;AACR,WAAQ,QAAQ,oBAAoB,SAAS,QAAQ;AACrD,mBAAgB,OAAO"}
@@ -0,0 +1,22 @@
1
+ import { t as QuickJsExecutorOptions } from "./types-BB8mb_-T.cjs";
2
+ import { ExecuteResult, ExecutionOptions, Executor, ResolvedToolProvider } from "@execbox/core";
3
+
4
+ //#region src/quickjsExecutor.d.ts
5
+
6
+ /**
7
+ * QuickJS-backed executor for one-shot sandboxed JavaScript runs.
8
+ */
9
+ declare class QuickJsExecutor implements Executor {
10
+ private readonly options;
11
+ /**
12
+ * Creates a QuickJS executor with one-shot runtime limits and host bridging configuration.
13
+ */
14
+ constructor(options?: QuickJsExecutorOptions);
15
+ /**
16
+ * Executes JavaScript against the provided tool namespaces in a fresh QuickJS runtime.
17
+ */
18
+ execute(code: string, providers: ResolvedToolProvider[], options?: ExecutionOptions): Promise<ExecuteResult>;
19
+ }
20
+ //#endregion
21
+ export { QuickJsExecutor, type QuickJsExecutorOptions };
22
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/quickjsExecutor.ts"],"sourcesContent":[],"mappings":";;;;;;;AAgBA;AAMuB,cANV,eAAA,YAA2B,QAMjB,CAAA;EASR,iBAAA,OAAA;EACF;;;EAhB2B,WAAA,CAAA,OAAA,CAAA,EAMjB,sBANiB;EAAQ;;;mCAejC,kCACF,mBACR,QAAQ"}
@@ -0,0 +1,22 @@
1
+ import { t as QuickJsExecutorOptions } from "./types-D7uau0GM.js";
2
+ import { ExecuteResult, ExecutionOptions, Executor, ResolvedToolProvider } from "@execbox/core";
3
+
4
+ //#region src/quickjsExecutor.d.ts
5
+
6
+ /**
7
+ * QuickJS-backed executor for one-shot sandboxed JavaScript runs.
8
+ */
9
+ declare class QuickJsExecutor implements Executor {
10
+ private readonly options;
11
+ /**
12
+ * Creates a QuickJS executor with one-shot runtime limits and host bridging configuration.
13
+ */
14
+ constructor(options?: QuickJsExecutorOptions);
15
+ /**
16
+ * Executes JavaScript against the provided tool namespaces in a fresh QuickJS runtime.
17
+ */
18
+ execute(code: string, providers: ResolvedToolProvider[], options?: ExecutionOptions): Promise<ExecuteResult>;
19
+ }
20
+ //#endregion
21
+ export { QuickJsExecutor, type QuickJsExecutorOptions };
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/quickjsExecutor.ts"],"sourcesContent":[],"mappings":";;;;;;;AAgBA;AAMuB,cANV,eAAA,YAA2B,QAMjB,CAAA;EASR,iBAAA,OAAA;EACF;;;EAhB2B,WAAA,CAAA,OAAA,CAAA,EAMjB,sBANiB;EAAQ;;;mCAejC,kCACF,mBACR,QAAQ"}
package/dist/index.js ADDED
@@ -0,0 +1,46 @@
1
+ import { t as runQuickJsSession } from "./runner-DVOLiGt4.js";
2
+ import { createTimeoutExecuteResult, createToolCallDispatcher, extractProviderManifests } from "@execbox/core";
3
+
4
+ //#region src/quickjsExecutor.ts
5
+ /**
6
+ * QuickJS-backed executor for one-shot sandboxed JavaScript runs.
7
+ */
8
+ var QuickJsExecutor = class {
9
+ options;
10
+ /**
11
+ * Creates a QuickJS executor with one-shot runtime limits and host bridging configuration.
12
+ */
13
+ constructor(options = {}) {
14
+ this.options = options;
15
+ }
16
+ /**
17
+ * Executes JavaScript against the provided tool namespaces in a fresh QuickJS runtime.
18
+ */
19
+ async execute(code, providers, options = {}) {
20
+ if (options.signal?.aborted) return createTimeoutExecuteResult();
21
+ const abortController = new AbortController();
22
+ const onToolCall = createToolCallDispatcher(providers, abortController.signal);
23
+ const onAbort = () => {
24
+ abortController.abort();
25
+ };
26
+ options.signal?.addEventListener("abort", onAbort, { once: true });
27
+ try {
28
+ return await runQuickJsSession({
29
+ abortController,
30
+ code,
31
+ onToolCall,
32
+ providers: extractProviderManifests(providers)
33
+ }, {
34
+ ...this.options,
35
+ ...options
36
+ });
37
+ } finally {
38
+ options.signal?.removeEventListener("abort", onAbort);
39
+ abortController.abort();
40
+ }
41
+ }
42
+ };
43
+
44
+ //#endregion
45
+ export { QuickJsExecutor };
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/quickjsExecutor.ts"],"sourcesContent":["import {\n createTimeoutExecuteResult,\n createToolCallDispatcher,\n extractProviderManifests,\n type ExecutionOptions,\n type ExecuteResult,\n type Executor,\n type ResolvedToolProvider,\n} from \"@execbox/core\";\n\nimport { runQuickJsSession } from \"./runner/index\";\nimport type { QuickJsExecutorOptions } from \"./types\";\n\n/**\n * QuickJS-backed executor for one-shot sandboxed JavaScript runs.\n */\nexport class QuickJsExecutor implements Executor {\n private readonly options: QuickJsExecutorOptions;\n\n /**\n * Creates a QuickJS executor with one-shot runtime limits and host bridging configuration.\n */\n constructor(options: QuickJsExecutorOptions = {}) {\n this.options = options;\n }\n\n /**\n * Executes JavaScript against the provided tool namespaces in a fresh QuickJS runtime.\n */\n async execute(\n code: string,\n providers: ResolvedToolProvider[],\n options: ExecutionOptions = {},\n ): Promise<ExecuteResult> {\n if (options.signal?.aborted) {\n return createTimeoutExecuteResult();\n }\n\n const abortController = new AbortController();\n const onToolCall = createToolCallDispatcher(\n providers,\n abortController.signal,\n );\n const onAbort = () => {\n abortController.abort();\n };\n\n options.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\n try {\n return await runQuickJsSession(\n {\n abortController,\n code,\n onToolCall,\n providers: extractProviderManifests(providers),\n },\n {\n ...this.options,\n ...options,\n },\n );\n } finally {\n options.signal?.removeEventListener(\"abort\", onAbort);\n abortController.abort();\n }\n }\n}\n"],"mappings":";;;;;;;AAgBA,IAAa,kBAAb,MAAiD;CAC/C,AAAiB;;;;CAKjB,YAAY,UAAkC,EAAE,EAAE;AAChD,OAAK,UAAU;;;;;CAMjB,MAAM,QACJ,MACA,WACA,UAA4B,EAAE,EACN;AACxB,MAAI,QAAQ,QAAQ,QAClB,QAAO,4BAA4B;EAGrC,MAAM,kBAAkB,IAAI,iBAAiB;EAC7C,MAAM,aAAa,yBACjB,WACA,gBAAgB,OACjB;EACD,MAAM,gBAAgB;AACpB,mBAAgB,OAAO;;AAGzB,UAAQ,QAAQ,iBAAiB,SAAS,SAAS,EAAE,MAAM,MAAM,CAAC;AAElE,MAAI;AACF,UAAO,MAAM,kBACX;IACE;IACA;IACA;IACA,WAAW,yBAAyB,UAAU;IAC/C,EACD;IACE,GAAG,KAAK;IACR,GAAG;IACJ,CACF;YACO;AACR,WAAQ,QAAQ,oBAAoB,SAAS,QAAQ;AACrD,mBAAgB,OAAO"}
@@ -0,0 +1,3 @@
1
+ const require_runner = require('../runner-CYXIVOmJ.cjs');
2
+
3
+ exports.runQuickJsSession = require_runner.runQuickJsSession;
@@ -0,0 +1,104 @@
1
+ import { t as QuickJsExecutorOptions } from "../types-BB8mb_-T.cjs";
2
+
3
+ //#region ../core/src/types.d.ts
4
+
5
+ /**
6
+ * Stable error codes returned by executors and wrapped tool calls.
7
+ */
8
+ type ExecuteErrorCode = "timeout" | "memory_limit" | "validation_error" | "tool_error" | "runtime_error" | "serialization_error" | "internal_error";
9
+ /**
10
+ * Structured execution failure returned in {@link ExecuteResult}.
11
+ */
12
+ interface ExecuteError {
13
+ /** Machine-readable error category. */
14
+ code: ExecuteErrorCode;
15
+ /** Human-readable failure message. */
16
+ message: string;
17
+ }
18
+ /**
19
+ * Structured result returned by every executor invocation.
20
+ */
21
+ type ExecuteResult<T = unknown> = {
22
+ durationMs: number;
23
+ logs: string[];
24
+ ok: true;
25
+ result: T;
26
+ } | {
27
+ durationMs: number;
28
+ error: ExecuteError;
29
+ logs: string[];
30
+ ok: false;
31
+ };
32
+ //#endregion
33
+ //#region ../core/src/runner.d.ts
34
+ /**
35
+ * Transport-safe metadata for one exposed tool.
36
+ */
37
+ interface ProviderToolManifest {
38
+ description?: string;
39
+ originalName: string;
40
+ safeName: string;
41
+ }
42
+ /**
43
+ * Namespace manifest shared with runner implementations.
44
+ */
45
+ interface ProviderManifest {
46
+ name: string;
47
+ tools: Record<string, ProviderToolManifest>;
48
+ types: string;
49
+ }
50
+ /**
51
+ * Execution limits forwarded to runner implementations.
52
+ */
53
+ interface ExecutorRuntimeOptions {
54
+ maxLogChars?: number;
55
+ maxLogLines?: number;
56
+ memoryLimitBytes?: number;
57
+ timeoutMs?: number;
58
+ }
59
+ /**
60
+ * Tool invocation request emitted from a runner.
61
+ */
62
+ interface ToolCall {
63
+ input: unknown;
64
+ providerName: string;
65
+ safeToolName: string;
66
+ }
67
+ /**
68
+ * Trusted host response to a tool invocation request.
69
+ */
70
+ type ToolCallResult = {
71
+ ok: true;
72
+ result: unknown;
73
+ } | {
74
+ error: ExecuteError;
75
+ ok: false;
76
+ };
77
+ //#endregion
78
+ //#region src/runner/index.d.ts
79
+ /**
80
+ * Transport-neutral host tool call emitted from a QuickJS session.
81
+ */
82
+ type QuickJsSessionToolCall = ToolCall;
83
+ /**
84
+ * Input required to run one transport-backed QuickJS execution session.
85
+ */
86
+ interface QuickJsSessionRequest {
87
+ abortController?: AbortController;
88
+ code: string;
89
+ onToolCall: (call: ToolCall) => Promise<ToolCallResult> | ToolCallResult;
90
+ onStarted?: () => void;
91
+ providers: ProviderManifest[];
92
+ signal?: AbortSignal;
93
+ }
94
+ /**
95
+ * Options controlling one transport-backed QuickJS session.
96
+ */
97
+ type QuickJsSessionOptions = QuickJsExecutorOptions & ExecutorRuntimeOptions;
98
+ /**
99
+ * Runs one QuickJS-backed execution session using a transport-neutral tool callback.
100
+ */
101
+ declare function runQuickJsSession(request: QuickJsSessionRequest, options?: QuickJsSessionOptions): Promise<ExecuteResult>;
102
+ //#endregion
103
+ export { QuickJsSessionOptions, QuickJsSessionRequest, QuickJsSessionToolCall, runQuickJsSession };
104
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +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;AASA;AAiBiB,KDnCL,gBAAA,GCmCa,SAAA,GAAA,cAAA,GAAA,kBAAA,GAAA,YAAA,GAAA,eAAA,GAAA,qBAAA,GAAA,gBAAA;AASzB;;;UDhCiB,YAAA;EEuBL;EAKK,IAAA,EF1BT,gBE0BS;EACG;EAEC,OAAA,EAAA,MAAA;;;;;AAGV,KFxBC,aEwBD,CAAA,IAAA,OAAA,CAAA,GAAA;EAAW,UAAA,EAAA,MAAA;EAMV,IAAA,EAAA,MAAA,EAAA;EAkSU,EAAA,EAAA,IAAA;EACX,MAAA,EF5TG,CE4TH;CACA,GAAA;EACA,UAAA,EAAA,MAAA;EAAR,KAAA,EF1TU,YE0TV;EAAO,IAAA,EAAA,MAAA,EAAA;;;;;;;AFzVV;AAYiB,UCZA,oBAAA,CDcT;EAQI,WAAA,CAAA,EAAA,MAAa;;;;ACtBzB;AASA;AASA;AAiBiB,UA1BA,gBAAA,CA0BQ;EASb,IAAA,EAAA,MAAA;SAjCH,eAAe;;;ACwBxB;AAKA;;AAGqB,UDzBJ,sBAAA,CCyBI;EAAqB,WAAA,CAAA,EAAA,MAAA;EAAR,WAAA,CAAA,EAAA,MAAA;EAA0B,gBAAA,CAAA,EAAA,MAAA;EAE/C,SAAA,CAAA,EAAA,MAAA;;;;;UDVI,QAAA;;;;;;;;KASL,cAAA;;;;SAMC;;;;;;ADlDb;AAYA;AAUY,KEaA,sBAAA,GAAyB,QFJxB;;;;AC/BI,UCwCA,qBAAA,CDxCoB;EASpB,eAAA,CAAA,ECgCG,eD9BI;EAOP,IAAA,EAAA,MAAA;EAiBA,UAAA,EAAQ,CAAA,IAAA,ECQJ,QDRI,EAAA,GCQS,ODRT,CCQiB,cDRjB,CAAA,GCQmC,cDRnC;EASb,SAAA,CAAA,EAAA,GAAA,GAAc,IAAA;aCCb;WACF;;AAXX;AAKA;;AAGqB,KAST,qBAAA,GAAwB,sBATf,GAUnB,sBAVmB;;;;AAER,iBAySS,iBAAA,CAzST,OAAA,EA0SF,qBA1SE,EAAA,OAAA,CAAA,EA2SF,qBA3SE,CAAA,EA4SV,OA5SU,CA4SF,aA5SE,CAAA"}
@@ -0,0 +1,104 @@
1
+ import { t as QuickJsExecutorOptions } from "../types-D7uau0GM.js";
2
+
3
+ //#region ../core/src/types.d.ts
4
+
5
+ /**
6
+ * Stable error codes returned by executors and wrapped tool calls.
7
+ */
8
+ type ExecuteErrorCode = "timeout" | "memory_limit" | "validation_error" | "tool_error" | "runtime_error" | "serialization_error" | "internal_error";
9
+ /**
10
+ * Structured execution failure returned in {@link ExecuteResult}.
11
+ */
12
+ interface ExecuteError {
13
+ /** Machine-readable error category. */
14
+ code: ExecuteErrorCode;
15
+ /** Human-readable failure message. */
16
+ message: string;
17
+ }
18
+ /**
19
+ * Structured result returned by every executor invocation.
20
+ */
21
+ type ExecuteResult<T = unknown> = {
22
+ durationMs: number;
23
+ logs: string[];
24
+ ok: true;
25
+ result: T;
26
+ } | {
27
+ durationMs: number;
28
+ error: ExecuteError;
29
+ logs: string[];
30
+ ok: false;
31
+ };
32
+ //#endregion
33
+ //#region ../core/src/runner.d.ts
34
+ /**
35
+ * Transport-safe metadata for one exposed tool.
36
+ */
37
+ interface ProviderToolManifest {
38
+ description?: string;
39
+ originalName: string;
40
+ safeName: string;
41
+ }
42
+ /**
43
+ * Namespace manifest shared with runner implementations.
44
+ */
45
+ interface ProviderManifest {
46
+ name: string;
47
+ tools: Record<string, ProviderToolManifest>;
48
+ types: string;
49
+ }
50
+ /**
51
+ * Execution limits forwarded to runner implementations.
52
+ */
53
+ interface ExecutorRuntimeOptions {
54
+ maxLogChars?: number;
55
+ maxLogLines?: number;
56
+ memoryLimitBytes?: number;
57
+ timeoutMs?: number;
58
+ }
59
+ /**
60
+ * Tool invocation request emitted from a runner.
61
+ */
62
+ interface ToolCall {
63
+ input: unknown;
64
+ providerName: string;
65
+ safeToolName: string;
66
+ }
67
+ /**
68
+ * Trusted host response to a tool invocation request.
69
+ */
70
+ type ToolCallResult = {
71
+ ok: true;
72
+ result: unknown;
73
+ } | {
74
+ error: ExecuteError;
75
+ ok: false;
76
+ };
77
+ //#endregion
78
+ //#region src/runner/index.d.ts
79
+ /**
80
+ * Transport-neutral host tool call emitted from a QuickJS session.
81
+ */
82
+ type QuickJsSessionToolCall = ToolCall;
83
+ /**
84
+ * Input required to run one transport-backed QuickJS execution session.
85
+ */
86
+ interface QuickJsSessionRequest {
87
+ abortController?: AbortController;
88
+ code: string;
89
+ onToolCall: (call: ToolCall) => Promise<ToolCallResult> | ToolCallResult;
90
+ onStarted?: () => void;
91
+ providers: ProviderManifest[];
92
+ signal?: AbortSignal;
93
+ }
94
+ /**
95
+ * Options controlling one transport-backed QuickJS session.
96
+ */
97
+ type QuickJsSessionOptions = QuickJsExecutorOptions & ExecutorRuntimeOptions;
98
+ /**
99
+ * Runs one QuickJS-backed execution session using a transport-neutral tool callback.
100
+ */
101
+ declare function runQuickJsSession(request: QuickJsSessionRequest, options?: QuickJsSessionOptions): Promise<ExecuteResult>;
102
+ //#endregion
103
+ export { QuickJsSessionOptions, QuickJsSessionRequest, QuickJsSessionToolCall, runQuickJsSession };
104
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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;AASA;AAiBiB,KDnCL,gBAAA,GCmCa,SAAA,GAAA,cAAA,GAAA,kBAAA,GAAA,YAAA,GAAA,eAAA,GAAA,qBAAA,GAAA,gBAAA;AASzB;;;UDhCiB,YAAA;EEuBL;EAKK,IAAA,EF1BT,gBE0BS;EACG;EAEC,OAAA,EAAA,MAAA;;;;;AAGV,KFxBC,aEwBD,CAAA,IAAA,OAAA,CAAA,GAAA;EAAW,UAAA,EAAA,MAAA;EAMV,IAAA,EAAA,MAAA,EAAA;EAkSU,EAAA,EAAA,IAAA;EACX,MAAA,EF5TG,CE4TH;CACA,GAAA;EACA,UAAA,EAAA,MAAA;EAAR,KAAA,EF1TU,YE0TV;EAAO,IAAA,EAAA,MAAA,EAAA;;;;;;;AFzVV;AAYiB,UCZA,oBAAA,CDcT;EAQI,WAAA,CAAA,EAAA,MAAa;;;;ACtBzB;AASA;AASA;AAiBiB,UA1BA,gBAAA,CA0BQ;EASb,IAAA,EAAA,MAAA;SAjCH,eAAe;;;ACwBxB;AAKA;;AAGqB,UDzBJ,sBAAA,CCyBI;EAAqB,WAAA,CAAA,EAAA,MAAA;EAAR,WAAA,CAAA,EAAA,MAAA;EAA0B,gBAAA,CAAA,EAAA,MAAA;EAE/C,SAAA,CAAA,EAAA,MAAA;;;;;UDVI,QAAA;;;;;;;;KASL,cAAA;;;;SAMC;;;;;;ADlDb;AAYA;AAUY,KEaA,sBAAA,GAAyB,QFJxB;;;;AC/BI,UCwCA,qBAAA,CDxCoB;EASpB,eAAA,CAAA,ECgCG,eD9BI;EAOP,IAAA,EAAA,MAAA;EAiBA,UAAA,EAAQ,CAAA,IAAA,ECQJ,QDRI,EAAA,GCQS,ODRT,CCQiB,cDRjB,CAAA,GCQmC,cDRnC;EASb,SAAA,CAAA,EAAA,GAAA,GAAc,IAAA;aCCb;WACF;;AAXX;AAKA;;AAGqB,KAST,qBAAA,GAAwB,sBATf,GAUnB,sBAVmB;;;;AAER,iBAySS,iBAAA,CAzST,OAAA,EA0SF,qBA1SE,EAAA,OAAA,CAAA,EA2SF,qBA3SE,CAAA,EA4SV,OA5SU,CA4SF,aA5SE,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { t as runQuickJsSession } from "../runner-DVOLiGt4.js";
2
+
3
+ export { runQuickJsSession };
@@ -0,0 +1,101 @@
1
+ const require_runner = require('../runner-CYXIVOmJ.cjs');
2
+ let node_crypto = require("node:crypto");
3
+
4
+ //#region src/runner/protocolEndpoint.ts
5
+ /**
6
+ * Attaches the shared QuickJS protocol loop to a worker/process messaging port.
7
+ */
8
+ function attachQuickJsProtocolEndpoint(port) {
9
+ const pendingToolCalls = /* @__PURE__ */ new Map();
10
+ let activeAbortController;
11
+ let activeExecutionId;
12
+ async function startExecution(message) {
13
+ if (activeExecutionId) {
14
+ port.send({
15
+ durationMs: 0,
16
+ error: {
17
+ code: "internal_error",
18
+ message: "QuickJS endpoint already has an active execution"
19
+ },
20
+ id: message.id,
21
+ logs: [],
22
+ ok: false,
23
+ type: "done"
24
+ });
25
+ return;
26
+ }
27
+ const abortController = new AbortController();
28
+ activeAbortController = abortController;
29
+ activeExecutionId = message.id;
30
+ try {
31
+ const result = await require_runner.runQuickJsSession({
32
+ abortController,
33
+ code: message.code,
34
+ onStarted: () => {
35
+ port.send({
36
+ id: message.id,
37
+ type: "started"
38
+ });
39
+ },
40
+ onToolCall: (call) => new Promise((resolve) => {
41
+ const callId = (0, node_crypto.randomUUID)();
42
+ pendingToolCalls.set(callId, resolve);
43
+ port.send({
44
+ ...call,
45
+ callId,
46
+ type: "tool_call"
47
+ });
48
+ }),
49
+ providers: message.providers
50
+ }, message.options);
51
+ port.send({
52
+ ...result,
53
+ id: message.id,
54
+ type: "done"
55
+ });
56
+ } catch (error) {
57
+ port.send({
58
+ durationMs: 0,
59
+ error: {
60
+ code: "internal_error",
61
+ message: error instanceof Error ? error.message : String(error)
62
+ },
63
+ id: message.id,
64
+ logs: [],
65
+ ok: false,
66
+ type: "done"
67
+ });
68
+ } finally {
69
+ pendingToolCalls.clear();
70
+ activeAbortController = void 0;
71
+ activeExecutionId = void 0;
72
+ }
73
+ }
74
+ const maybeDetach = port.onMessage((message) => {
75
+ switch (message.type) {
76
+ case "cancel":
77
+ if (message.id === activeExecutionId) activeAbortController?.abort();
78
+ break;
79
+ case "execute":
80
+ startExecution(message);
81
+ break;
82
+ case "tool_result": {
83
+ const resolve = pendingToolCalls.get(message.callId);
84
+ pendingToolCalls.delete(message.callId);
85
+ resolve?.(message);
86
+ break;
87
+ }
88
+ }
89
+ });
90
+ return () => {
91
+ if (typeof maybeDetach === "function") maybeDetach();
92
+ pendingToolCalls.clear();
93
+ activeAbortController?.abort();
94
+ activeAbortController = void 0;
95
+ activeExecutionId = void 0;
96
+ };
97
+ }
98
+
99
+ //#endregion
100
+ exports.attachQuickJsProtocolEndpoint = attachQuickJsProtocolEndpoint;
101
+ //# sourceMappingURL=protocolEndpoint.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocolEndpoint.cjs","names":["activeAbortController: AbortController | undefined","activeExecutionId: string | undefined","runQuickJsSession"],"sources":["../../src/runner/protocolEndpoint.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\n\nimport type {\n DispatcherMessage,\n ExecuteMessage,\n RunnerMessage,\n ToolCallResult,\n} from \"@execbox/protocol\";\n\nimport { runQuickJsSession } from \"./index.ts\";\n\n/**\n * Minimal worker/process-side port used by the shared QuickJS protocol endpoint.\n */\nexport interface QuickJsProtocolPort {\n onMessage(handler: (message: DispatcherMessage) => void): void | (() => void);\n send(message: RunnerMessage): void;\n}\n\n/**\n * Attaches the shared QuickJS protocol loop to a worker/process messaging port.\n */\nexport function attachQuickJsProtocolEndpoint(\n port: QuickJsProtocolPort,\n): () => void {\n const pendingToolCalls = new Map<string, (result: ToolCallResult) => void>();\n let activeAbortController: AbortController | undefined;\n let activeExecutionId: string | undefined;\n\n async function startExecution(message: ExecuteMessage): Promise<void> {\n if (activeExecutionId) {\n port.send({\n durationMs: 0,\n error: {\n code: \"internal_error\",\n message: \"QuickJS endpoint already has an active execution\",\n },\n id: message.id,\n logs: [],\n ok: false,\n type: \"done\",\n });\n return;\n }\n\n const abortController = new AbortController();\n activeAbortController = abortController;\n activeExecutionId = message.id;\n\n try {\n const result = await runQuickJsSession(\n {\n abortController,\n code: message.code,\n onStarted: () => {\n port.send({\n id: message.id,\n type: \"started\",\n });\n },\n onToolCall: (call) =>\n new Promise<ToolCallResult>((resolve) => {\n const callId = randomUUID();\n pendingToolCalls.set(callId, resolve);\n port.send({\n ...call,\n callId,\n type: \"tool_call\",\n });\n }),\n providers: message.providers,\n },\n message.options,\n );\n\n port.send({\n ...result,\n id: message.id,\n type: \"done\",\n });\n } catch (error) {\n port.send({\n durationMs: 0,\n error: {\n code: \"internal_error\",\n message: error instanceof Error ? error.message : String(error),\n },\n id: message.id,\n logs: [],\n ok: false,\n type: \"done\",\n });\n } finally {\n pendingToolCalls.clear();\n activeAbortController = undefined;\n activeExecutionId = undefined;\n }\n }\n\n const maybeDetach = port.onMessage((message: DispatcherMessage) => {\n switch (message.type) {\n case \"cancel\":\n if (message.id === activeExecutionId) {\n activeAbortController?.abort();\n }\n break;\n case \"execute\":\n void startExecution(message);\n break;\n case \"tool_result\": {\n const resolve = pendingToolCalls.get(message.callId);\n pendingToolCalls.delete(message.callId);\n resolve?.(message);\n break;\n }\n }\n });\n\n return () => {\n if (typeof maybeDetach === \"function\") {\n maybeDetach();\n }\n pendingToolCalls.clear();\n activeAbortController?.abort();\n activeAbortController = undefined;\n activeExecutionId = undefined;\n };\n}\n"],"mappings":";;;;;;;AAsBA,SAAgB,8BACd,MACY;CACZ,MAAM,mCAAmB,IAAI,KAA+C;CAC5E,IAAIA;CACJ,IAAIC;CAEJ,eAAe,eAAe,SAAwC;AACpE,MAAI,mBAAmB;AACrB,QAAK,KAAK;IACR,YAAY;IACZ,OAAO;KACL,MAAM;KACN,SAAS;KACV;IACD,IAAI,QAAQ;IACZ,MAAM,EAAE;IACR,IAAI;IACJ,MAAM;IACP,CAAC;AACF;;EAGF,MAAM,kBAAkB,IAAI,iBAAiB;AAC7C,0BAAwB;AACxB,sBAAoB,QAAQ;AAE5B,MAAI;GACF,MAAM,SAAS,MAAMC,iCACnB;IACE;IACA,MAAM,QAAQ;IACd,iBAAiB;AACf,UAAK,KAAK;MACR,IAAI,QAAQ;MACZ,MAAM;MACP,CAAC;;IAEJ,aAAa,SACX,IAAI,SAAyB,YAAY;KACvC,MAAM,sCAAqB;AAC3B,sBAAiB,IAAI,QAAQ,QAAQ;AACrC,UAAK,KAAK;MACR,GAAG;MACH;MACA,MAAM;MACP,CAAC;MACF;IACJ,WAAW,QAAQ;IACpB,EACD,QAAQ,QACT;AAED,QAAK,KAAK;IACR,GAAG;IACH,IAAI,QAAQ;IACZ,MAAM;IACP,CAAC;WACK,OAAO;AACd,QAAK,KAAK;IACR,YAAY;IACZ,OAAO;KACL,MAAM;KACN,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;KAChE;IACD,IAAI,QAAQ;IACZ,MAAM,EAAE;IACR,IAAI;IACJ,MAAM;IACP,CAAC;YACM;AACR,oBAAiB,OAAO;AACxB,2BAAwB;AACxB,uBAAoB;;;CAIxB,MAAM,cAAc,KAAK,WAAW,YAA+B;AACjE,UAAQ,QAAQ,MAAhB;GACE,KAAK;AACH,QAAI,QAAQ,OAAO,kBACjB,wBAAuB,OAAO;AAEhC;GACF,KAAK;AACH,IAAK,eAAe,QAAQ;AAC5B;GACF,KAAK,eAAe;IAClB,MAAM,UAAU,iBAAiB,IAAI,QAAQ,OAAO;AACpD,qBAAiB,OAAO,QAAQ,OAAO;AACvC,cAAU,QAAQ;AAClB;;;GAGJ;AAEF,cAAa;AACX,MAAI,OAAO,gBAAgB,WACzB,cAAa;AAEf,mBAAiB,OAAO;AACxB,yBAAuB,OAAO;AAC9B,0BAAwB;AACxB,sBAAoB"}
@@ -0,0 +1,18 @@
1
+ import { DispatcherMessage, RunnerMessage } from "@execbox/protocol";
2
+
3
+ //#region src/runner/protocolEndpoint.d.ts
4
+
5
+ /**
6
+ * Minimal worker/process-side port used by the shared QuickJS protocol endpoint.
7
+ */
8
+ interface QuickJsProtocolPort {
9
+ onMessage(handler: (message: DispatcherMessage) => void): void | (() => void);
10
+ send(message: RunnerMessage): void;
11
+ }
12
+ /**
13
+ * Attaches the shared QuickJS protocol loop to a worker/process messaging port.
14
+ */
15
+ declare function attachQuickJsProtocolEndpoint(port: QuickJsProtocolPort): () => void;
16
+ //#endregion
17
+ export { QuickJsProtocolPort, attachQuickJsProtocolEndpoint };
18
+ //# sourceMappingURL=protocolEndpoint.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocolEndpoint.d.cts","names":[],"sources":["../../src/runner/protocolEndpoint.ts"],"sourcesContent":[],"mappings":";;;;;;AAcA;AAQgB,UARC,mBAAA,CAQ4B;+BAPd;gBACf;;;;;iBAMA,6BAAA,OACR"}
@@ -0,0 +1,18 @@
1
+ import { DispatcherMessage, RunnerMessage } from "@execbox/protocol";
2
+
3
+ //#region src/runner/protocolEndpoint.d.ts
4
+
5
+ /**
6
+ * Minimal worker/process-side port used by the shared QuickJS protocol endpoint.
7
+ */
8
+ interface QuickJsProtocolPort {
9
+ onMessage(handler: (message: DispatcherMessage) => void): void | (() => void);
10
+ send(message: RunnerMessage): void;
11
+ }
12
+ /**
13
+ * Attaches the shared QuickJS protocol loop to a worker/process messaging port.
14
+ */
15
+ declare function attachQuickJsProtocolEndpoint(port: QuickJsProtocolPort): () => void;
16
+ //#endregion
17
+ export { QuickJsProtocolPort, attachQuickJsProtocolEndpoint };
18
+ //# sourceMappingURL=protocolEndpoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocolEndpoint.d.ts","names":[],"sources":["../../src/runner/protocolEndpoint.ts"],"sourcesContent":[],"mappings":";;;;;;AAcA;AAQgB,UARC,mBAAA,CAQ4B;+BAPd;gBACf;;;;;iBAMA,6BAAA,OACR"}