@execbox/quickjs 0.2.0 → 0.2.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 (34) hide show
  1. package/README.md +4 -2
  2. package/dist/index.cjs +68 -5
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +5 -1
  5. package/dist/index.d.cts.map +1 -1
  6. package/dist/index.d.ts +5 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +65 -2
  9. package/dist/index.js.map +1 -1
  10. package/dist/runner/index.cjs +1 -1
  11. package/dist/runner/index.d.cts +8 -77
  12. package/dist/runner/index.d.cts.map +1 -1
  13. package/dist/runner/index.d.ts +8 -77
  14. package/dist/runner/index.d.ts.map +1 -1
  15. package/dist/runner/index.js +1 -1
  16. package/dist/runner/protocolEndpoint.cjs +5 -1
  17. package/dist/runner/protocolEndpoint.cjs.map +1 -1
  18. package/dist/runner/protocolEndpoint.d.cts +4 -0
  19. package/dist/runner/protocolEndpoint.d.cts.map +1 -1
  20. package/dist/runner/protocolEndpoint.d.ts +4 -0
  21. package/dist/runner/protocolEndpoint.d.ts.map +1 -1
  22. package/dist/runner/protocolEndpoint.js +5 -1
  23. package/dist/runner/protocolEndpoint.js.map +1 -1
  24. package/dist/{runner-DhOZH9xz.cjs → runner-BqkDnP0t.cjs} +108 -1
  25. package/dist/{runner-DhOZH9xz.cjs.map → runner-BqkDnP0t.cjs.map} +1 -1
  26. package/dist/{runner-B4UG88h1.js → runner-CVaY4RVQ.js} +67 -2
  27. package/dist/{runner-B4UG88h1.js.map → runner-CVaY4RVQ.js.map} +1 -1
  28. package/dist/{types-BB8mb_-T.d.cts → types-BXi8Lqtk.d.ts} +6 -2
  29. package/dist/types-BXi8Lqtk.d.ts.map +1 -0
  30. package/dist/{types-D7uau0GM.d.ts → types-CVE2n2LY.d.cts} +6 -2
  31. package/dist/types-CVE2n2LY.d.cts.map +1 -0
  32. package/package.json +15 -6
  33. package/dist/types-BB8mb_-T.d.cts.map +0 -1
  34. package/dist/types-D7uau0GM.d.ts.map +0 -1
package/README.md CHANGED
@@ -5,6 +5,8 @@ QuickJS executor backend for `@execbox/core`.
5
5
  [![npm version](https://img.shields.io/npm/v/%40execbox%2Fquickjs?style=flat-square)](https://www.npmjs.com/package/@execbox/quickjs)
6
6
  [![License](https://img.shields.io/github/license/aallam/execbox?style=flat-square)](https://github.com/aallam/execbox/blob/main/LICENSE)
7
7
 
8
+ Docs: https://execbox.aallam.com
9
+
8
10
  ## Choose QuickJS When
9
11
 
10
12
  - you want the easiest execbox backend to install
@@ -16,8 +18,8 @@ QuickJS executor backend for `@execbox/core`.
16
18
  - Each execution gets a fresh QuickJS runtime with no ambient Node globals injected by execbox.
17
19
  - Tool calls cross a JSON-only bridge, and executor timeouts propagate abort signals to in-flight provider work.
18
20
  - 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
+ - This package is designed for host-controlled deployments and does not by itself create a hard isolation boundary for hostile code.
22
+ - If you need a stronger boundary, move execution into a separate process, container, or remote runtime.
21
23
 
22
24
  ## Architecture Docs
23
25
 
package/dist/index.cjs CHANGED
@@ -1,6 +1,69 @@
1
- const require_runner = require('./runner-DhOZH9xz.cjs');
2
- let __execbox_core = require("@execbox/core");
1
+ const require_runner = require('./runner-BqkDnP0t.cjs');
3
2
 
3
+ //#region ../core/src/runner.ts
4
+ function toTrustedExecuteError(error) {
5
+ if (require_runner.isExecuteFailure(error)) return {
6
+ code: error.code,
7
+ message: error.message
8
+ };
9
+ return {
10
+ code: "tool_error",
11
+ message: require_runner.normalizeThrownMessage(error)
12
+ };
13
+ }
14
+ /**
15
+ * Converts resolved providers into manifest metadata that reveals only namespace details.
16
+ */
17
+ function extractProviderManifests(providers) {
18
+ return providers.map((provider) => ({
19
+ name: provider.name,
20
+ tools: Object.fromEntries(Object.entries(provider.tools).map(([safeToolName, descriptor]) => [safeToolName, {
21
+ description: descriptor.description,
22
+ originalName: descriptor.originalName,
23
+ safeName: descriptor.safeName
24
+ }])),
25
+ types: provider.types
26
+ }));
27
+ }
28
+ /**
29
+ * Creates a host-side dispatcher for runner-emitted tool calls.
30
+ */
31
+ function createToolCallDispatcher(providers, signal) {
32
+ const providerMap = new Map(providers.map((provider) => [provider.name, provider]));
33
+ return async (call) => {
34
+ const provider = providerMap.get(call.providerName);
35
+ const descriptor = provider?.tools[call.safeToolName];
36
+ if (!provider || !descriptor) return {
37
+ error: {
38
+ code: "internal_error",
39
+ message: `Unknown tool ${call.providerName}.${call.safeToolName}`
40
+ },
41
+ ok: false
42
+ };
43
+ try {
44
+ if (signal.aborted) return {
45
+ error: {
46
+ code: "timeout",
47
+ message: require_runner.getExecutionTimeoutMessage()
48
+ },
49
+ ok: false
50
+ };
51
+ const result = await descriptor.execute(call.input, require_runner.createExecutionContext(signal, provider.name, descriptor.safeName, descriptor.originalName));
52
+ if (result !== void 0 && !require_runner.isJsonSerializable(result)) throw new require_runner.ExecuteFailure("serialization_error", "Host value is not JSON-serializable");
53
+ return {
54
+ ok: true,
55
+ result
56
+ };
57
+ } catch (error) {
58
+ return {
59
+ error: toTrustedExecuteError(error),
60
+ ok: false
61
+ };
62
+ }
63
+ };
64
+ }
65
+
66
+ //#endregion
4
67
  //#region src/quickjsExecutor.ts
5
68
  /**
6
69
  * QuickJS-backed executor for ephemeral sandboxed JavaScript runs.
@@ -17,9 +80,9 @@ var QuickJsExecutor = class {
17
80
  * Executes JavaScript against the provided tool namespaces in a fresh QuickJS runtime.
18
81
  */
19
82
  async execute(code, providers, options = {}) {
20
- if (options.signal?.aborted) return (0, __execbox_core.createTimeoutExecuteResult)();
83
+ if (options.signal?.aborted) return require_runner.createTimeoutExecuteResult();
21
84
  const abortController = new AbortController();
22
- const onToolCall = (0, __execbox_core.createToolCallDispatcher)(providers, abortController.signal);
85
+ const onToolCall = createToolCallDispatcher(providers, abortController.signal);
23
86
  const onAbort = () => {
24
87
  abortController.abort();
25
88
  };
@@ -29,7 +92,7 @@ var QuickJsExecutor = class {
29
92
  abortController,
30
93
  code,
31
94
  onToolCall,
32
- providers: (0, __execbox_core.extractProviderManifests)(providers)
95
+ providers: extractProviderManifests(providers)
33
96
  }, {
34
97
  ...this.options,
35
98
  ...options
@@ -1 +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 ephemeral sandboxed JavaScript runs.\n */\nexport class QuickJsExecutor implements Executor {\n private readonly options: QuickJsExecutorOptions;\n\n /**\n * Creates a QuickJS executor with ephemeral 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"}
1
+ {"version":3,"file":"index.cjs","names":["isExecuteFailure","normalizeThrownMessage","getExecutionTimeoutMessage","createExecutionContext","isJsonSerializable","ExecuteFailure","createTimeoutExecuteResult","runQuickJsSession"],"sources":["../../core/src/runner.ts","../src/quickjsExecutor.ts"],"sourcesContent":["import {\n createExecutionContext,\n getExecutionTimeoutMessage,\n normalizeThrownMessage,\n} from \"./executor/shared.ts\";\nimport {\n ExecuteFailure,\n isExecuteFailure,\n isJsonSerializable,\n} from \"./errors.ts\";\nimport type { ExecuteError, ResolvedToolProvider } from \"./types.ts\";\n\n/**\n * Transport-safe metadata for one exposed tool.\n */\nexport interface ProviderToolManifest {\n description?: string;\n originalName: string;\n safeName: string;\n}\n\n/**\n * Namespace manifest shared with runner implementations.\n */\nexport interface ProviderManifest {\n name: string;\n tools: Record<string, ProviderToolManifest>;\n types: string;\n}\n\n/**\n * Execution limits forwarded to runner implementations.\n */\nexport interface ExecutorRuntimeOptions {\n maxLogChars?: number;\n maxLogLines?: number;\n memoryLimitBytes?: number;\n timeoutMs?: number;\n}\n\n/**\n * Public execution options accepted by executors per call.\n */\nexport interface ExecutionOptions extends ExecutorRuntimeOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Tool invocation request emitted from a runner.\n */\nexport interface ToolCall {\n input: unknown;\n providerName: string;\n safeToolName: string;\n}\n\n/**\n * Trusted host response to a tool invocation request.\n */\nexport type ToolCallResult =\n | {\n ok: true;\n result: unknown;\n }\n | {\n error: ExecuteError;\n ok: false;\n };\n\nfunction toTrustedExecuteError(error: unknown): ExecuteError {\n if (isExecuteFailure(error)) {\n return {\n code: error.code,\n message: error.message,\n };\n }\n\n return {\n code: \"tool_error\",\n message: normalizeThrownMessage(error),\n };\n}\n\n/**\n * Converts resolved providers into manifest metadata that reveals only namespace details.\n */\nexport function extractProviderManifests(\n providers: ResolvedToolProvider[],\n): ProviderManifest[] {\n return providers.map((provider) => ({\n name: provider.name,\n tools: Object.fromEntries(\n Object.entries(provider.tools).map(([safeToolName, descriptor]) => [\n safeToolName,\n {\n description: descriptor.description,\n originalName: descriptor.originalName,\n safeName: descriptor.safeName,\n },\n ]),\n ),\n types: provider.types,\n }));\n}\n\n/**\n * Creates a host-side dispatcher for runner-emitted tool calls.\n */\nexport function createToolCallDispatcher(\n providers: ResolvedToolProvider[],\n signal: AbortSignal,\n): (call: ToolCall) => Promise<ToolCallResult> {\n const providerMap = new Map(\n providers.map((provider) => [provider.name, provider] as const),\n );\n\n return async (call) => {\n const provider = providerMap.get(call.providerName);\n const descriptor = provider?.tools[call.safeToolName];\n\n if (!provider || !descriptor) {\n return {\n error: {\n code: \"internal_error\",\n message: `Unknown tool ${call.providerName}.${call.safeToolName}`,\n },\n ok: false,\n };\n }\n\n try {\n if (signal.aborted) {\n return {\n error: {\n code: \"timeout\",\n message: getExecutionTimeoutMessage(),\n },\n ok: false,\n };\n }\n\n const result = await descriptor.execute(\n call.input,\n createExecutionContext(\n signal,\n provider.name,\n descriptor.safeName,\n descriptor.originalName,\n ),\n );\n\n if (result !== undefined && !isJsonSerializable(result)) {\n throw new ExecuteFailure(\n \"serialization_error\",\n \"Host value is not JSON-serializable\",\n );\n }\n\n return {\n ok: true,\n result,\n };\n } catch (error) {\n return {\n error: toTrustedExecuteError(error),\n ok: false,\n };\n }\n };\n}\n","import {\n createTimeoutExecuteResult,\n createToolCallDispatcher,\n extractProviderManifests,\n} from \"../../core/src/runtime.ts\";\nimport type {\n ExecutionOptions,\n ExecuteResult,\n Executor,\n ResolvedToolProvider,\n} from \"@execbox/core\";\n\nimport { runQuickJsSession } from \"./runner/index.ts\";\nimport type { QuickJsExecutorOptions } from \"./types\";\n\n/**\n * QuickJS-backed executor for ephemeral sandboxed JavaScript runs.\n */\nexport class QuickJsExecutor implements Executor {\n private readonly options: QuickJsExecutorOptions;\n\n /**\n * Creates a QuickJS executor with ephemeral 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":";;;AAqEA,SAAS,sBAAsB,OAA8B;AAC3D,KAAIA,gCAAiB,MAAM,CACzB,QAAO;EACL,MAAM,MAAM;EACZ,SAAS,MAAM;EAChB;AAGH,QAAO;EACL,MAAM;EACN,SAASC,sCAAuB,MAAM;EACvC;;;;;AAMH,SAAgB,yBACd,WACoB;AACpB,QAAO,UAAU,KAAK,cAAc;EAClC,MAAM,SAAS;EACf,OAAO,OAAO,YACZ,OAAO,QAAQ,SAAS,MAA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AAiB,SAAS,SAAS,EAAE,MAAM,MAAM,CAAC;AAElE,MAAI;AACF,UAAO,MAAMC,iCACX;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"}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,8 @@
1
- import { t as QuickJsExecutorOptions } from "./types-BB8mb_-T.cjs";
1
+ /**
2
+ * @packageDocumentation
3
+ * Public TypeScript declarations for this package entrypoint.
4
+ */
5
+ import { t as QuickJsExecutorOptions } from "./types-CVE2n2LY.cjs";
2
6
  import { ExecuteResult, ExecutionOptions, Executor, ResolvedToolProvider } from "@execbox/core";
3
7
 
4
8
  //#region src/quickjsExecutor.d.ts
@@ -1 +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"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/quickjsExecutor.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AAkBA,CAAA,CAAA;AAMuB,OAAA,CAAA,KAAA,CANV,eAAA,CAAA,UAAA,CAA2B,QAMjB,CAAA;EASR,OAAA,CAAA,QAAA,CAAA,OAAA;EACF,CAAA,CAAA;;;EAhB2B,WAAA,CAAA,OAAA,CAAA,CAAA,CAMjB,sBANiB,CAAA;EAAQ,CAAA,CAAA;;;mCAejC,kCACF,mBACR,QAAQ"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,8 @@
1
- import { t as QuickJsExecutorOptions } from "./types-D7uau0GM.js";
1
+ /**
2
+ * @packageDocumentation
3
+ * Public TypeScript declarations for this package entrypoint.
4
+ */
5
+ import { t as QuickJsExecutorOptions } from "./types-BXi8Lqtk.js";
2
6
  import { ExecuteResult, ExecutionOptions, Executor, ResolvedToolProvider } from "@execbox/core";
3
7
 
4
8
  //#region src/quickjsExecutor.d.ts
@@ -1 +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"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/quickjsExecutor.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AAkBA,CAAA,CAAA;AAMuB,OAAA,CAAA,KAAA,CANV,eAAA,CAAA,UAAA,CAA2B,QAMjB,CAAA;EASR,OAAA,CAAA,QAAA,CAAA,OAAA;EACF,CAAA,CAAA;;;EAhB2B,WAAA,CAAA,OAAA,CAAA,CAAA,CAMjB,sBANiB,CAAA;EAAQ,CAAA,CAAA;;;mCAejC,kCACF,mBACR,QAAQ"}
package/dist/index.js CHANGED
@@ -1,6 +1,69 @@
1
- import { t as runQuickJsSession } from "./runner-B4UG88h1.js";
2
- import { createTimeoutExecuteResult, createToolCallDispatcher, extractProviderManifests } from "@execbox/core";
1
+ import { a as createExecutionContext, c as normalizeThrownMessage, i as isJsonSerializable, n as ExecuteFailure, o as createTimeoutExecuteResult, r as isExecuteFailure, s as getExecutionTimeoutMessage, t as runQuickJsSession } from "./runner-CVaY4RVQ.js";
3
2
 
3
+ //#region ../core/src/runner.ts
4
+ function toTrustedExecuteError(error) {
5
+ if (isExecuteFailure(error)) return {
6
+ code: error.code,
7
+ message: error.message
8
+ };
9
+ return {
10
+ code: "tool_error",
11
+ message: normalizeThrownMessage(error)
12
+ };
13
+ }
14
+ /**
15
+ * Converts resolved providers into manifest metadata that reveals only namespace details.
16
+ */
17
+ function extractProviderManifests(providers) {
18
+ return providers.map((provider) => ({
19
+ name: provider.name,
20
+ tools: Object.fromEntries(Object.entries(provider.tools).map(([safeToolName, descriptor]) => [safeToolName, {
21
+ description: descriptor.description,
22
+ originalName: descriptor.originalName,
23
+ safeName: descriptor.safeName
24
+ }])),
25
+ types: provider.types
26
+ }));
27
+ }
28
+ /**
29
+ * Creates a host-side dispatcher for runner-emitted tool calls.
30
+ */
31
+ function createToolCallDispatcher(providers, signal) {
32
+ const providerMap = new Map(providers.map((provider) => [provider.name, provider]));
33
+ return async (call) => {
34
+ const provider = providerMap.get(call.providerName);
35
+ const descriptor = provider?.tools[call.safeToolName];
36
+ if (!provider || !descriptor) return {
37
+ error: {
38
+ code: "internal_error",
39
+ message: `Unknown tool ${call.providerName}.${call.safeToolName}`
40
+ },
41
+ ok: false
42
+ };
43
+ try {
44
+ if (signal.aborted) return {
45
+ error: {
46
+ code: "timeout",
47
+ message: getExecutionTimeoutMessage()
48
+ },
49
+ ok: false
50
+ };
51
+ const result = await descriptor.execute(call.input, createExecutionContext(signal, provider.name, descriptor.safeName, descriptor.originalName));
52
+ if (result !== void 0 && !isJsonSerializable(result)) throw new ExecuteFailure("serialization_error", "Host value is not JSON-serializable");
53
+ return {
54
+ ok: true,
55
+ result
56
+ };
57
+ } catch (error) {
58
+ return {
59
+ error: toTrustedExecuteError(error),
60
+ ok: false
61
+ };
62
+ }
63
+ };
64
+ }
65
+
66
+ //#endregion
4
67
  //#region src/quickjsExecutor.ts
5
68
  /**
6
69
  * QuickJS-backed executor for ephemeral sandboxed JavaScript runs.
package/dist/index.js.map CHANGED
@@ -1 +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 ephemeral sandboxed JavaScript runs.\n */\nexport class QuickJsExecutor implements Executor {\n private readonly options: QuickJsExecutorOptions;\n\n /**\n * Creates a QuickJS executor with ephemeral 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"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../core/src/runner.ts","../src/quickjsExecutor.ts"],"sourcesContent":["import {\n createExecutionContext,\n getExecutionTimeoutMessage,\n normalizeThrownMessage,\n} from \"./executor/shared.ts\";\nimport {\n ExecuteFailure,\n isExecuteFailure,\n isJsonSerializable,\n} from \"./errors.ts\";\nimport type { ExecuteError, ResolvedToolProvider } from \"./types.ts\";\n\n/**\n * Transport-safe metadata for one exposed tool.\n */\nexport interface ProviderToolManifest {\n description?: string;\n originalName: string;\n safeName: string;\n}\n\n/**\n * Namespace manifest shared with runner implementations.\n */\nexport interface ProviderManifest {\n name: string;\n tools: Record<string, ProviderToolManifest>;\n types: string;\n}\n\n/**\n * Execution limits forwarded to runner implementations.\n */\nexport interface ExecutorRuntimeOptions {\n maxLogChars?: number;\n maxLogLines?: number;\n memoryLimitBytes?: number;\n timeoutMs?: number;\n}\n\n/**\n * Public execution options accepted by executors per call.\n */\nexport interface ExecutionOptions extends ExecutorRuntimeOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Tool invocation request emitted from a runner.\n */\nexport interface ToolCall {\n input: unknown;\n providerName: string;\n safeToolName: string;\n}\n\n/**\n * Trusted host response to a tool invocation request.\n */\nexport type ToolCallResult =\n | {\n ok: true;\n result: unknown;\n }\n | {\n error: ExecuteError;\n ok: false;\n };\n\nfunction toTrustedExecuteError(error: unknown): ExecuteError {\n if (isExecuteFailure(error)) {\n return {\n code: error.code,\n message: error.message,\n };\n }\n\n return {\n code: \"tool_error\",\n message: normalizeThrownMessage(error),\n };\n}\n\n/**\n * Converts resolved providers into manifest metadata that reveals only namespace details.\n */\nexport function extractProviderManifests(\n providers: ResolvedToolProvider[],\n): ProviderManifest[] {\n return providers.map((provider) => ({\n name: provider.name,\n tools: Object.fromEntries(\n Object.entries(provider.tools).map(([safeToolName, descriptor]) => [\n safeToolName,\n {\n description: descriptor.description,\n originalName: descriptor.originalName,\n safeName: descriptor.safeName,\n },\n ]),\n ),\n types: provider.types,\n }));\n}\n\n/**\n * Creates a host-side dispatcher for runner-emitted tool calls.\n */\nexport function createToolCallDispatcher(\n providers: ResolvedToolProvider[],\n signal: AbortSignal,\n): (call: ToolCall) => Promise<ToolCallResult> {\n const providerMap = new Map(\n providers.map((provider) => [provider.name, provider] as const),\n );\n\n return async (call) => {\n const provider = providerMap.get(call.providerName);\n const descriptor = provider?.tools[call.safeToolName];\n\n if (!provider || !descriptor) {\n return {\n error: {\n code: \"internal_error\",\n message: `Unknown tool ${call.providerName}.${call.safeToolName}`,\n },\n ok: false,\n };\n }\n\n try {\n if (signal.aborted) {\n return {\n error: {\n code: \"timeout\",\n message: getExecutionTimeoutMessage(),\n },\n ok: false,\n };\n }\n\n const result = await descriptor.execute(\n call.input,\n createExecutionContext(\n signal,\n provider.name,\n descriptor.safeName,\n descriptor.originalName,\n ),\n );\n\n if (result !== undefined && !isJsonSerializable(result)) {\n throw new ExecuteFailure(\n \"serialization_error\",\n \"Host value is not JSON-serializable\",\n );\n }\n\n return {\n ok: true,\n result,\n };\n } catch (error) {\n return {\n error: toTrustedExecuteError(error),\n ok: false,\n };\n }\n };\n}\n","import {\n createTimeoutExecuteResult,\n createToolCallDispatcher,\n extractProviderManifests,\n} from \"../../core/src/runtime.ts\";\nimport type {\n ExecutionOptions,\n ExecuteResult,\n Executor,\n ResolvedToolProvider,\n} from \"@execbox/core\";\n\nimport { runQuickJsSession } from \"./runner/index.ts\";\nimport type { QuickJsExecutorOptions } from \"./types\";\n\n/**\n * QuickJS-backed executor for ephemeral sandboxed JavaScript runs.\n */\nexport class QuickJsExecutor implements Executor {\n private readonly options: QuickJsExecutorOptions;\n\n /**\n * Creates a QuickJS executor with ephemeral 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":";;;AAqEA,SAAS,sBAAsB,OAA8B;AAC3D,KAAI,iBAAiB,MAAM,CACzB,QAAO;EACL,MAAM,MAAM;EACZ,SAAS,MAAM;EAChB;AAGH,QAAO;EACL,MAAM;EACN,SAAS,uBAAuB,MAAM;EACvC;;;;;AAMH,SAAgB,yBACd,WACoB;AACpB,QAAO,UAAU,KAAK,cAAc;EAClC,MAAM,SAAS;EACf,OAAO,OAAO,YACZ,OAAO,QAAQ,SAAS,MAAM,CAAC,KAAK,CAAC,cAAc,gBAAgB,CACjE,cACA;GACE,aAAa,WAAW;GACxB,cAAc,WAAW;GACzB,UAAU,WAAW;GACtB,CACF,CAAC,CACH;EACD,OAAO,SAAS;EACjB,EAAE;;;;;AAML,SAAgB,yBACd,WACA,QAC6C;CAC7C,MAAM,cAAc,IAAI,IACtB,UAAU,KAAK,aAAa,CAAC,SAAS,MAAM,SAAS,CAAU,CAChE;AAED,QAAO,OAAO,SAAS;EACrB,MAAM,WAAW,YAAY,IAAI,KAAK,aAAa;EACnD,MAAM,aAAa,UAAU,MAAM,KAAK;AAExC,MAAI,CAAC,YAAY,CAAC,WAChB,QAAO;GACL,OAAO;IACL,MAAM;IACN,SAAS,gBAAgB,KAAK,aAAa,GAAG,KAAK;IACpD;GACD,IAAI;GACL;AAGH,MAAI;AACF,OAAI,OAAO,QACT,QAAO;IACL,OAAO;KACL,MAAM;KACN,SAAS,4BAA4B;KACtC;IACD,IAAI;IACL;GAGH,MAAM,SAAS,MAAM,WAAW,QAC9B,KAAK,OACL,uBACE,QACA,SAAS,MACT,WAAW,UACX,WAAW,aACZ,CACF;AAED,OAAI,WAAW,UAAa,CAAC,mBAAmB,OAAO,CACrD,OAAM,IAAI,eACR,uBACA,sCACD;AAGH,UAAO;IACL,IAAI;IACJ;IACD;WACM,OAAO;AACd,UAAO;IACL,OAAO,sBAAsB,MAAM;IACnC,IAAI;IACL;;;;;;;;;;ACpJP,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"}
@@ -1,3 +1,3 @@
1
- const require_runner = require('../runner-DhOZH9xz.cjs');
1
+ const require_runner = require('../runner-BqkDnP0t.cjs');
2
2
 
3
3
  exports.runQuickJsSession = require_runner.runQuickJsSession;
@@ -1,82 +1,13 @@
1
- import { t as QuickJsExecutorOptions } from "../types-BB8mb_-T.cjs";
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 { t as QuickJsExecutorOptions } from "../types-CVE2n2LY.cjs";
6
+ import { ExecuteResult, ExecutorRuntimeOptions, ProviderManifest, ToolCall, ToolCallResult } from "@execbox/core";
7
+ import { QuickJSWASMModule } from "quickjs-emscripten";
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
  */
@@ -103,5 +34,5 @@ type QuickJsSessionOptions = QuickJsExecutorOptions & ExecutorRuntimeOptions & {
103
34
  */
104
35
  declare function runQuickJsSession(request: QuickJsSessionRequest, options?: QuickJsSessionOptions): Promise<ExecuteResult>;
105
36
  //#endregion
106
- export { QuickJsSessionOptions, QuickJsSessionRequest, QuickJsSessionToolCall, runQuickJsSession };
37
+ export { type QuickJsExecutorOptions, QuickJsSessionOptions, QuickJsSessionRequest, QuickJsSessionToolCall, runQuickJsSession };
107
38
  //# sourceMappingURL=index.d.cts.map
@@ -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,oBAAA,CDAW;EAYX,WAAA,CAAA,EAAA,MAAY;EAUjB,YAAA,EAAA,MAAa;;;;ACtBzB;AASA;AASiB,UATA,gBAAA,CASsB;EAiBtB,IAAA,EAAA,MAAQ;EASb,KAAA,EAjCH,MAiCG,CAAA,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IP;EACF,IAAA,CAAA,CAAA,MAAA;EAAW,UAAA,CAAA,CAAA,CAAA,IAAA,CAAA,CAHD,QAGC,CAAA,CAAA,CAAA,CAAA,CAHY,OAGZ,CAHoB,cAGpB,CAAA,CAAA,CAAA,CAHsC,cAGtC;EAMV,SAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,IAAA;EAAwB,SAAA,CAAA,CAPvB,gBAOuB,CAAA,CAAA;EAClC,MAAA,CAAA,CAAA,CAPS,WAOT;;;AA6TF,CAAA,CAAA,CAAA,OAAA,CAAA,WAAA,CAAA,GAAA,CAAA,SAAA,CAAA,MAAA,CAAA,OAAA,CAAA,OAAA;;AAEW,IAAA,CAhUC,qBAAA,CAAA,CAAA,CAAwB,sBAgUzB,CAAA,CAAA,CA/TT,sBA+TS,CAAA,CAAA,CAAA;EACA,MAAA,CAAA,CAAA,CA/TE,iBA+TF;CAAR;;;;iBAHmB,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 { t as QuickJsExecutorOptions } from "../types-BXi8Lqtk.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
  */
@@ -103,5 +34,5 @@ type QuickJsSessionOptions = QuickJsExecutorOptions & ExecutorRuntimeOptions & {
103
34
  */
104
35
  declare function runQuickJsSession(request: QuickJsSessionRequest, options?: QuickJsSessionOptions): Promise<ExecuteResult>;
105
36
  //#endregion
106
- export { QuickJsSessionOptions, QuickJsSessionRequest, QuickJsSessionToolCall, runQuickJsSession };
37
+ export { type QuickJsExecutorOptions, QuickJsSessionOptions, QuickJsSessionRequest, QuickJsSessionToolCall, runQuickJsSession };
107
38
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts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,CAAA,CAAwB,sBAgUzB,CAAA,CAAA,CA/TT,sBA+TS,CAAA,CAAA,CAAA;EACA,MAAA,CAAA,CAAA,CA/TE,iBA+TF;CAAR;;;;iBAHmB,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-CVaY4RVQ.js";
2
2
 
3
3
  export { runQuickJsSession };
@@ -1,4 +1,4 @@
1
- const require_runner = require('../runner-DhOZH9xz.cjs');
1
+ const require_runner = require('../runner-BqkDnP0t.cjs');
2
2
  let node_crypto = require("node:crypto");
3
3
 
4
4
  //#region ../protocol/src/messages.ts
@@ -39,6 +39,10 @@ function isDispatcherMessage(value) {
39
39
  //#endregion
40
40
  //#region src/runner/protocolEndpoint.ts
41
41
  /**
42
+ * @packageDocumentation
43
+ * Public API for the `@execbox/quickjs/runner/protocol-endpoint` entrypoint.
44
+ */
45
+ /**
42
46
  * Attaches the shared QuickJS protocol loop to a worker/process messaging port.
43
47
  */
44
48
  function attachQuickJsProtocolEndpoint(port) {
@@ -1 +1 @@
1
- {"version":3,"file":"protocolEndpoint.cjs","names":["activeAbortController: AbortController | undefined","activeExecutionId: string | undefined","runQuickJsSession"],"sources":["../../../protocol/src/messages.ts","../../src/runner/protocolEndpoint.ts"],"sourcesContent":["import type {\n ExecuteResult,\n ExecutorRuntimeOptions,\n ProviderManifest,\n ToolCall,\n ToolCallResult,\n} from \"@execbox/core\";\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction isFiniteNumber(value: unknown): value is number {\n return typeof value === \"number\" && Number.isFinite(value);\n}\n\nfunction isRuntimeOptions(value: unknown): value is ExecutorRuntimeOptions {\n if (!isRecord(value)) {\n return false;\n }\n\n return (\n isFiniteNumber(value.maxLogChars) &&\n isFiniteNumber(value.maxLogLines) &&\n isFiniteNumber(value.memoryLimitBytes) &&\n isFiniteNumber(value.timeoutMs)\n );\n}\n\nfunction isProviderManifest(value: unknown): value is ProviderManifest {\n if (!isRecord(value) || typeof value.name !== \"string\") {\n return false;\n }\n\n if (!isRecord(value.tools) || typeof value.types !== \"string\") {\n return false;\n }\n\n return Object.values(value.tools).every(\n (tool) =>\n isRecord(tool) &&\n typeof tool.originalName === \"string\" &&\n typeof tool.safeName === \"string\" &&\n (tool.description === undefined || typeof tool.description === \"string\"),\n );\n}\n\nfunction isExecuteError(\n value: unknown,\n): value is { code: string; message: string } {\n return (\n isRecord(value) &&\n typeof value.code === \"string\" &&\n typeof value.message === \"string\"\n );\n}\n\nfunction isDonePayload(value: unknown): value is DoneMessage {\n if (!isRecord(value) || !isFiniteNumber(value.durationMs)) {\n return false;\n }\n\n if (\n !Array.isArray(value.logs) ||\n !value.logs.every((log) => typeof log === \"string\")\n ) {\n return false;\n }\n\n if (typeof value.ok !== \"boolean\") {\n return false;\n }\n\n return value.ok ? true : isExecuteError(value.error);\n}\n\n/**\n * Message sent from dispatcher to runner to start one execution session.\n */\nexport interface ExecuteMessage {\n code: string;\n id: string;\n options: ExecutorRuntimeOptions;\n providers: ProviderManifest[];\n type: \"execute\";\n}\n\n/**\n * Message sent from dispatcher to request prompt cancellation.\n */\nexport interface CancelMessage {\n id: string;\n type: \"cancel\";\n}\n\n/**\n * Message sent from a runner when guest code invokes a host tool.\n */\nexport interface ToolCallMessage extends ToolCall {\n callId: string;\n type: \"tool_call\";\n}\n\n/**\n * Message carrying a trusted host tool result back to the runner.\n */\nexport type ToolResultMessage = {\n callId: string;\n type: \"tool_result\";\n} & ToolCallResult;\n\n/**\n * Message indicating the runner has finished bootstrapping guest execution timing.\n */\nexport interface StartedMessage {\n id: string;\n type: \"started\";\n}\n\n/**\n * Final successful execution result returned by a runner.\n *\n * Node IPC can omit `undefined` fields during serialization, so `result`\n * remains optional at the protocol boundary and is normalized by the host.\n */\nexport type DoneSuccessMessage<T = unknown> = {\n durationMs: number;\n id: string;\n logs: string[];\n ok: true;\n result?: T;\n type: \"done\";\n};\n\n/**\n * Final failed execution result returned by a runner.\n */\nexport type DoneFailureMessage = {\n id: string;\n type: \"done\";\n} & Extract<ExecuteResult, { ok: false }>;\n\n/**\n * Final execution result returned by a runner.\n */\nexport type DoneMessage = DoneSuccessMessage | DoneFailureMessage;\n\n/**\n * Messages accepted by a runner transport endpoint.\n */\nexport type DispatcherMessage =\n | CancelMessage\n | ExecuteMessage\n | ToolResultMessage;\n\n/**\n * Messages emitted by a runner transport endpoint.\n */\nexport type RunnerMessage = DoneMessage | StartedMessage | ToolCallMessage;\n\n/**\n * Returns whether an unknown value is a dispatcher-to-runner message.\n */\nexport function isDispatcherMessage(\n value: unknown,\n): value is DispatcherMessage {\n if (!isRecord(value) || typeof value.type !== \"string\") {\n return false;\n }\n\n switch (value.type) {\n case \"cancel\":\n return typeof value.id === \"string\";\n case \"execute\":\n return (\n typeof value.code === \"string\" &&\n typeof value.id === \"string\" &&\n isRuntimeOptions(value.options) &&\n Array.isArray(value.providers) &&\n value.providers.every(isProviderManifest)\n );\n case \"tool_result\":\n if (typeof value.callId !== \"string\" || typeof value.ok !== \"boolean\") {\n return false;\n }\n\n if (value.ok) {\n return \"result\" in value;\n }\n\n return isExecuteError(value.error);\n default:\n return false;\n }\n}\n\n/**\n * Returns whether an unknown value is a runner-to-dispatcher message.\n */\nexport function isRunnerMessage(value: unknown): value is RunnerMessage {\n if (!isRecord(value) || typeof value.type !== \"string\") {\n return false;\n }\n\n switch (value.type) {\n case \"started\":\n return typeof value.id === \"string\";\n case \"tool_call\":\n return (\n typeof value.callId === \"string\" &&\n typeof value.providerName === \"string\" &&\n typeof value.safeToolName === \"string\" &&\n \"input\" in value\n );\n case \"done\":\n return typeof value.id === \"string\" && isDonePayload(value);\n default:\n return false;\n }\n}\n","import { randomUUID } from \"node:crypto\";\n\nimport type {\n DispatcherMessage,\n ExecuteMessage,\n RunnerMessage,\n ToolCallResult,\n} from \"@execbox/protocol\";\nimport { isDispatcherMessage } from \"../../../protocol/src/messages.ts\";\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 if (!isDispatcherMessage(message)) {\n return;\n }\n\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":";;;;AAQA,SAAS,SAAS,OAAkD;AAClE,QAAO,OAAO,UAAU,YAAY,UAAU;;AAGhD,SAAS,eAAe,OAAiC;AACvD,QAAO,OAAO,UAAU,YAAY,OAAO,SAAS,MAAM;;AAG5D,SAAS,iBAAiB,OAAiD;AACzE,KAAI,CAAC,SAAS,MAAM,CAClB,QAAO;AAGT,QACE,eAAe,MAAM,YAAY,IACjC,eAAe,MAAM,YAAY,IACjC,eAAe,MAAM,iBAAiB,IACtC,eAAe,MAAM,UAAU;;AAInC,SAAS,mBAAmB,OAA2C;AACrE,KAAI,CAAC,SAAS,MAAM,IAAI,OAAO,MAAM,SAAS,SAC5C,QAAO;AAGT,KAAI,CAAC,SAAS,MAAM,MAAM,IAAI,OAAO,MAAM,UAAU,SACnD,QAAO;AAGT,QAAO,OAAO,OAAO,MAAM,MAAM,CAAC,OAC/B,SACC,SAAS,KAAK,IACd,OAAO,KAAK,iBAAiB,YAC7B,OAAO,KAAK,aAAa,aACxB,KAAK,gBAAgB,UAAa,OAAO,KAAK,gBAAgB,UAClE;;AAGH,SAAS,eACP,OAC4C;AAC5C,QACE,SAAS,MAAM,IACf,OAAO,MAAM,SAAS,YACtB,OAAO,MAAM,YAAY;;;;;AA8G7B,SAAgB,oBACd,OAC4B;AAC5B,KAAI,CAAC,SAAS,MAAM,IAAI,OAAO,MAAM,SAAS,SAC5C,QAAO;AAGT,SAAQ,MAAM,MAAd;EACE,KAAK,SACH,QAAO,OAAO,MAAM,OAAO;EAC7B,KAAK,UACH,QACE,OAAO,MAAM,SAAS,YACtB,OAAO,MAAM,OAAO,YACpB,iBAAiB,MAAM,QA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AoB;;;CAIxB,MAAM,cAAc,KAAK,WAAW,YAA+B;AACjE,MAAI,CAAC,oBAAoB,QAAQ,CAC/B;AAGF,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"}
1
+ {"version":3,"file":"protocolEndpoint.cjs","names":["activeAbortController: AbortController | undefined","activeExecutionId: string | undefined","runQuickJsSession"],"sources":["../../../protocol/src/messages.ts","../../src/runner/protocolEndpoint.ts"],"sourcesContent":["import type {\n ExecuteResult,\n ExecutorRuntimeOptions,\n ProviderManifest,\n ToolCall,\n ToolCallResult,\n} from \"@execbox/core\";\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction isFiniteNumber(value: unknown): value is number {\n return typeof value === \"number\" && Number.isFinite(value);\n}\n\nfunction isRuntimeOptions(value: unknown): value is ExecutorRuntimeOptions {\n if (!isRecord(value)) {\n return false;\n }\n\n return (\n isFiniteNumber(value.maxLogChars) &&\n isFiniteNumber(value.maxLogLines) &&\n isFiniteNumber(value.memoryLimitBytes) &&\n isFiniteNumber(value.timeoutMs)\n );\n}\n\nfunction isProviderManifest(value: unknown): value is ProviderManifest {\n if (!isRecord(value) || typeof value.name !== \"string\") {\n return false;\n }\n\n if (!isRecord(value.tools) || typeof value.types !== \"string\") {\n return false;\n }\n\n return Object.values(value.tools).every(\n (tool) =>\n isRecord(tool) &&\n typeof tool.originalName === \"string\" &&\n typeof tool.safeName === \"string\" &&\n (tool.description === undefined || typeof tool.description === \"string\"),\n );\n}\n\nfunction isExecuteError(\n value: unknown,\n): value is { code: string; message: string } {\n return (\n isRecord(value) &&\n typeof value.code === \"string\" &&\n typeof value.message === \"string\"\n );\n}\n\nfunction isDonePayload(value: unknown): value is DoneMessage {\n if (!isRecord(value) || !isFiniteNumber(value.durationMs)) {\n return false;\n }\n\n if (\n !Array.isArray(value.logs) ||\n !value.logs.every((log) => typeof log === \"string\")\n ) {\n return false;\n }\n\n if (typeof value.ok !== \"boolean\") {\n return false;\n }\n\n return value.ok ? true : isExecuteError(value.error);\n}\n\n/**\n * Message sent from dispatcher to runner to start one execution session.\n */\nexport interface ExecuteMessage {\n code: string;\n id: string;\n options: ExecutorRuntimeOptions;\n providers: ProviderManifest[];\n type: \"execute\";\n}\n\n/**\n * Message sent from dispatcher to request prompt cancellation.\n */\nexport interface CancelMessage {\n id: string;\n type: \"cancel\";\n}\n\n/**\n * Message sent from a runner when guest code invokes a host tool.\n */\nexport interface ToolCallMessage extends ToolCall {\n callId: string;\n type: \"tool_call\";\n}\n\n/**\n * Message carrying a trusted host tool result back to the runner.\n */\nexport type ToolResultMessage = {\n callId: string;\n type: \"tool_result\";\n} & ToolCallResult;\n\n/**\n * Message indicating the runner has finished bootstrapping guest execution timing.\n */\nexport interface StartedMessage {\n id: string;\n type: \"started\";\n}\n\n/**\n * Final successful execution result returned by a runner.\n *\n * Node IPC can omit `undefined` fields during serialization, so `result`\n * remains optional at the protocol boundary and is normalized by the host.\n */\nexport type DoneSuccessMessage<T = unknown> = {\n durationMs: number;\n id: string;\n logs: string[];\n ok: true;\n result?: T;\n type: \"done\";\n};\n\n/**\n * Final failed execution result returned by a runner.\n */\nexport type DoneFailureMessage = {\n id: string;\n type: \"done\";\n} & Extract<ExecuteResult, { ok: false }>;\n\n/**\n * Final execution result returned by a runner.\n */\nexport type DoneMessage = DoneSuccessMessage | DoneFailureMessage;\n\n/**\n * Messages accepted by a runner transport endpoint.\n */\nexport type DispatcherMessage =\n | CancelMessage\n | ExecuteMessage\n | ToolResultMessage;\n\n/**\n * Messages emitted by a runner transport endpoint.\n */\nexport type RunnerMessage = DoneMessage | StartedMessage | ToolCallMessage;\n\n/**\n * Returns whether an unknown value is a dispatcher-to-runner message.\n */\nexport function isDispatcherMessage(\n value: unknown,\n): value is DispatcherMessage {\n if (!isRecord(value) || typeof value.type !== \"string\") {\n return false;\n }\n\n switch (value.type) {\n case \"cancel\":\n return typeof value.id === \"string\";\n case \"execute\":\n return (\n typeof value.code === \"string\" &&\n typeof value.id === \"string\" &&\n isRuntimeOptions(value.options) &&\n Array.isArray(value.providers) &&\n value.providers.every(isProviderManifest)\n );\n case \"tool_result\":\n if (typeof value.callId !== \"string\" || typeof value.ok !== \"boolean\") {\n return false;\n }\n\n if (value.ok) {\n return \"result\" in value;\n }\n\n return isExecuteError(value.error);\n default:\n return false;\n }\n}\n\n/**\n * Returns whether an unknown value is a runner-to-dispatcher message.\n */\nexport function isRunnerMessage(value: unknown): value is RunnerMessage {\n if (!isRecord(value) || typeof value.type !== \"string\") {\n return false;\n }\n\n switch (value.type) {\n case \"started\":\n return typeof value.id === \"string\";\n case \"tool_call\":\n return (\n typeof value.callId === \"string\" &&\n typeof value.providerName === \"string\" &&\n typeof value.safeToolName === \"string\" &&\n \"input\" in value\n );\n case \"done\":\n return typeof value.id === \"string\" && isDonePayload(value);\n default:\n return false;\n }\n}\n","/**\n * @packageDocumentation\n * Public API for the `@execbox/quickjs/runner/protocol-endpoint` entrypoint.\n */\nimport { randomUUID } from \"node:crypto\";\n\nimport type {\n DispatcherMessage,\n ExecuteMessage,\n RunnerMessage,\n ToolCallResult,\n} from \"@execbox/protocol\";\n// This entrypoint is executed directly from source in worker/process tests before\n// workspace packages are built, so its runtime validator must stay source-local.\nimport { isDispatcherMessage } from \"../../../protocol/src/messages.ts\";\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 if (!isDispatcherMessage(message)) {\n return;\n }\n\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":";;;;AAQA,SAAS,SAAS,OAAkD;AAClE,QAAO,OAAO,UAAU,YAAY,UAAU;;AAGhD,SAAS,eAAe,OAAiC;AACvD,QAAO,OAAO,UAAU,YAAY,OAAO,SAAS,MAAM;;AAG5D,SAAS,iBAAiB,OAAiD;AACzE,KAAI,CAAC,SAAS,MAAM,CAClB,QAAO;AAGT,QACE,eAAe,MAAM,YAAY,IACjC,eAAe,MAAM,YAAY,IACjC,eAAe,MAAM,iBAAiB,IACtC,eAAe,MAAM,UAAU;;AAInC,SAAS,mBAAmB,OAA2C;AACrE,KAAI,CAAC,SAAS,MAAM,IAAI,OAAO,MAAM,SAAS,SAC5C,QAAO;AAGT,KAAI,CAAC,SAAS,MAAM,MAAM,IAAI,OAAO,MAAM,UAAU,SACnD,QAAO;AAGT,QAAO,OAAO,OAAO,MAAM,MAAM,CAAC,OAC/B,SACC,SAAS,KAAK,IACd,OAAO,KAAK,iBAAiB,YAC7B,OAAO,KAAK,aAAa,aACxB,KAAK,gBAAgB,UAAa,OAAO,KAAK,gBAAgB,UAClE;;AAGH,SAAS,eACP,OAC4C;AAC5C,QACE,SAAS,MAAM,IACf,OAAO,MAAM,SAAS,YACtB,OAAO,MAAM,YAAY;;;;;AA8G7B,SAAgB,oBACd,OAC4B;AAC5B,KAAI,CAAC,SAAS,MAAM,IAAI,OAAO,MAAM,SAAS,SAC5C,QAAO;AAGT,SAAQ,MAAM,MAAd;EACE,KAAK,SACH,QAAO,OAAO,MAAM,OAAO;EAC7B,KAAK,UACH,QACE,OAAO,MAAM,SAAS,YACtB,OAAO,MAAM,OAAO,YACpB,iBAAiB,MAAM,QAAQ,IAC/B,MAAM,QAAQ,MAAM,UAAU,IAC9B,MAAM,UAAU,MAAM,mBAAmB;EAE7C,KAAK;AACH,OAAI,OAAO,MAAM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AAQ,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"}
@@ -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,4 +1,4 @@
1
- import { t as runQuickJsSession } from "../runner-B4UG88h1.js";
1
+ import { t as runQuickJsSession } from "../runner-CVaY4RVQ.js";
2
2
  import { randomUUID } from "node:crypto";
3
3
 
4
4
  //#region ../protocol/src/messages.ts
@@ -39,6 +39,10 @@ function isDispatcherMessage(value) {
39
39
  //#endregion
40
40
  //#region src/runner/protocolEndpoint.ts
41
41
  /**
42
+ * @packageDocumentation
43
+ * Public API for the `@execbox/quickjs/runner/protocol-endpoint` entrypoint.
44
+ */
45
+ /**
42
46
  * Attaches the shared QuickJS protocol loop to a worker/process messaging port.
43
47
  */
44
48
  function attachQuickJsProtocolEndpoint(port) {