@execbox/quickjs 0.6.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +9 -12
  2. package/dist/index.cjs +2 -2
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +51 -3
  5. package/dist/index.d.cts.map +1 -1
  6. package/dist/index.d.ts +51 -3
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +2 -2
  9. package/dist/index.js.map +1 -1
  10. package/dist/{runner-DRLfwiqY.cjs → runner-BeRzBTrn.cjs} +92 -74
  11. package/dist/runner-BeRzBTrn.cjs.map +1 -0
  12. package/dist/{runner-oZXbguX3.js → runner-DJd4Bh8V.js} +92 -74
  13. package/dist/runner-DJd4Bh8V.js.map +1 -0
  14. package/dist/workerEntry.cjs +105 -3
  15. package/dist/workerEntry.cjs.map +1 -1
  16. package/dist/workerEntry.js +104 -2
  17. package/dist/workerEntry.js.map +1 -1
  18. package/package.json +2 -29
  19. package/dist/protocolEndpoint-BGyrwlr_.cjs +0 -112
  20. package/dist/protocolEndpoint-BGyrwlr_.cjs.map +0 -1
  21. package/dist/protocolEndpoint-Ceadcq_L.js +0 -107
  22. package/dist/protocolEndpoint-Ceadcq_L.js.map +0 -1
  23. package/dist/remoteEndpoint.cjs +0 -45
  24. package/dist/remoteEndpoint.cjs.map +0 -1
  25. package/dist/remoteEndpoint.d.cts +0 -29
  26. package/dist/remoteEndpoint.d.cts.map +0 -1
  27. package/dist/remoteEndpoint.d.ts +0 -29
  28. package/dist/remoteEndpoint.d.ts.map +0 -1
  29. package/dist/remoteEndpoint.js +0 -45
  30. package/dist/remoteEndpoint.js.map +0 -1
  31. package/dist/runner/index.cjs +0 -3
  32. package/dist/runner/index.d.cts +0 -45
  33. package/dist/runner/index.d.cts.map +0 -1
  34. package/dist/runner/index.d.ts +0 -45
  35. package/dist/runner/index.d.ts.map +0 -1
  36. package/dist/runner/index.js +0 -3
  37. package/dist/runner/protocolEndpoint.cjs +0 -4
  38. package/dist/runner/protocolEndpoint.d.cts +0 -22
  39. package/dist/runner/protocolEndpoint.d.cts.map +0 -1
  40. package/dist/runner/protocolEndpoint.d.ts +0 -22
  41. package/dist/runner/protocolEndpoint.d.ts.map +0 -1
  42. package/dist/runner/protocolEndpoint.js +0 -4
  43. package/dist/runner-DRLfwiqY.cjs.map +0 -1
  44. package/dist/runner-oZXbguX3.js.map +0 -1
  45. package/dist/types-C-XfFJ7u.d.cts +0 -58
  46. package/dist/types-C-XfFJ7u.d.cts.map +0 -1
  47. package/dist/types-CE7SvejR.d.ts +0 -58
  48. package/dist/types-CE7SvejR.d.ts.map +0 -1
@@ -1,7 +1,109 @@
1
- import "./runner-oZXbguX3.js";
2
- import { t as attachQuickJsProtocolEndpoint } from "./protocolEndpoint-Ceadcq_L.js";
1
+ import { t as runQuickJsSession } from "./runner-DJd4Bh8V.js";
3
2
  import { parentPort } from "node:worker_threads";
3
+ import { isDispatcherMessage } from "@execbox/core/protocol";
4
+ import { randomUUID } from "node:crypto";
4
5
 
6
+ //#region src/runner/protocolEndpoint.ts
7
+ /**
8
+ * @packageDocumentation
9
+ * Internal QuickJS protocol endpoint used by hosted and remote adapters.
10
+ */
11
+ /**
12
+ * Attaches the shared QuickJS protocol loop to a worker messaging port.
13
+ */
14
+ function attachQuickJsProtocolEndpoint(port) {
15
+ const pendingToolCalls = /* @__PURE__ */ new Map();
16
+ let activeAbortController;
17
+ let activeExecutionId;
18
+ async function startExecution(message) {
19
+ if (activeExecutionId) {
20
+ port.send({
21
+ durationMs: 0,
22
+ error: {
23
+ code: "internal_error",
24
+ message: "QuickJS endpoint already has an active execution"
25
+ },
26
+ id: message.id,
27
+ logs: [],
28
+ ok: false,
29
+ type: "done"
30
+ });
31
+ return;
32
+ }
33
+ const abortController = new AbortController();
34
+ activeAbortController = abortController;
35
+ activeExecutionId = message.id;
36
+ try {
37
+ const result = await runQuickJsSession({
38
+ abortController,
39
+ code: message.code,
40
+ onStarted: () => {
41
+ port.send({
42
+ id: message.id,
43
+ type: "started"
44
+ });
45
+ },
46
+ onToolCall: (call) => new Promise((resolve) => {
47
+ const callId = randomUUID();
48
+ pendingToolCalls.set(callId, resolve);
49
+ port.send({
50
+ ...call,
51
+ callId,
52
+ type: "tool_call"
53
+ });
54
+ }),
55
+ providers: message.providers
56
+ }, message.options);
57
+ port.send({
58
+ ...result,
59
+ id: message.id,
60
+ type: "done"
61
+ });
62
+ } catch (error) {
63
+ port.send({
64
+ durationMs: 0,
65
+ error: {
66
+ code: "internal_error",
67
+ message: error instanceof Error ? error.message : String(error)
68
+ },
69
+ id: message.id,
70
+ logs: [],
71
+ ok: false,
72
+ type: "done"
73
+ });
74
+ } finally {
75
+ pendingToolCalls.clear();
76
+ activeAbortController = void 0;
77
+ activeExecutionId = void 0;
78
+ }
79
+ }
80
+ const maybeDetach = port.onMessage((message) => {
81
+ if (!isDispatcherMessage(message)) return;
82
+ switch (message.type) {
83
+ case "cancel":
84
+ if (message.id === activeExecutionId) activeAbortController?.abort();
85
+ break;
86
+ case "execute":
87
+ startExecution(message);
88
+ break;
89
+ case "tool_result": {
90
+ const resolve = pendingToolCalls.get(message.callId);
91
+ pendingToolCalls.delete(message.callId);
92
+ resolve?.(message);
93
+ break;
94
+ }
95
+ }
96
+ });
97
+ return () => {
98
+ if (typeof maybeDetach === "function") maybeDetach();
99
+ pendingToolCalls.clear();
100
+ activeAbortController?.abort();
101
+ activeAbortController = void 0;
102
+ activeExecutionId = void 0;
103
+ };
104
+ }
105
+
106
+ //#endregion
5
107
  //#region src/workerEntry.ts
6
108
  if (!parentPort) throw new Error("QuickJsExecutor worker host requires a worker parent port");
7
109
  const workerPort = parentPort;
@@ -1 +1 @@
1
- {"version":3,"file":"workerEntry.js","names":[],"sources":["../src/workerEntry.ts"],"sourcesContent":["import { parentPort } from \"node:worker_threads\";\n\nimport type { DispatcherMessage, RunnerMessage } from \"@execbox/core/protocol\";\n\nimport { attachQuickJsProtocolEndpoint } from \"./runner/protocolEndpoint.ts\";\n\nif (!parentPort) {\n throw new Error(\"QuickJsExecutor worker host requires a worker parent port\");\n}\n\nconst workerPort = parentPort;\n\nattachQuickJsProtocolEndpoint({\n onMessage(handler: (message: DispatcherMessage) => void): () => void {\n workerPort.on(\"message\", handler);\n return () => workerPort.off(\"message\", handler);\n },\n send(message: RunnerMessage): void {\n workerPort.postMessage(message);\n },\n});\n"],"mappings":";;;;;AAMA,IAAI,CAAC,WACH,OAAM,IAAI,MAAM,4DAA4D;AAG9E,MAAM,aAAa;AAEnB,8BAA8B;CAC5B,UAAU,SAA2D;AACnE,aAAW,GAAG,WAAW,QAAQ;AACjC,eAAa,WAAW,IAAI,WAAW,QAAQ;;CAEjD,KAAK,SAA8B;AACjC,aAAW,YAAY,QAAQ;;CAElC,CAAC"}
1
+ {"version":3,"file":"workerEntry.js","names":["activeAbortController: AbortController | undefined","activeExecutionId: string | undefined"],"sources":["../src/runner/protocolEndpoint.ts","../src/workerEntry.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Internal QuickJS protocol endpoint used by hosted and remote adapters.\n */\nimport { randomUUID } from \"node:crypto\";\n\nimport { isDispatcherMessage } from \"@execbox/core/protocol\";\nimport type {\n DispatcherMessage,\n ExecuteMessage,\n RunnerMessage,\n ToolCallResult,\n} from \"@execbox/core/protocol\";\n\nimport { runQuickJsSession } from \"./index.ts\";\n\n/**\n * Minimal worker-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 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","import { parentPort } from \"node:worker_threads\";\n\nimport type { DispatcherMessage, RunnerMessage } from \"@execbox/core/protocol\";\n\nimport { attachQuickJsProtocolEndpoint } from \"./runner/protocolEndpoint.ts\";\n\nif (!parentPort) {\n throw new Error(\"QuickJsExecutor worker host requires a worker parent port\");\n}\n\nconst workerPort = parentPort;\n\nattachQuickJsProtocolEndpoint({\n onMessage(handler: (message: DispatcherMessage) => void): () => void {\n workerPort.on(\"message\", handler);\n return () => workerPort.off(\"message\", handler);\n },\n send(message: RunnerMessage): void {\n workerPort.postMessage(message);\n },\n});\n"],"mappings":";;;;;;;;;;;;;AA2BA,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,MAAM,kBACnB;IACE;IACA,MAAM,QAAQ;IACd,iBAAiB;AACf,UAAK,KAAK;MACR,IAAI,QAAQ;MACZ,MAAM;MACP,CAAC;;IAEJ,aAAa,SACX,IAAI,SAAyB,YAAY;KACvC,MAAM,SAAS,YAAY;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,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;;;;;;AChIxB,IAAI,CAAC,WACH,OAAM,IAAI,MAAM,4DAA4D;AAG9E,MAAM,aAAa;AAEnB,8BAA8B;CAC5B,UAAU,SAA2D;AACnE,aAAW,GAAG,WAAW,QAAQ;AACjC,eAAa,WAAW,IAAI,WAAW,QAAQ;;CAEjD,KAAK,SAA8B;AACjC,aAAW,YAAY,QAAQ;;CAElC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@execbox/quickjs",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "QuickJS executor for the execbox core package across inline and worker hosts.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -19,33 +19,6 @@
19
19
  },
20
20
  "import": "./dist/index.js",
21
21
  "require": "./dist/index.cjs"
22
- },
23
- "./runner": {
24
- "source": "./src/runner/index.ts",
25
- "types": {
26
- "import": "./dist/runner/index.d.ts",
27
- "require": "./dist/runner/index.d.cts"
28
- },
29
- "import": "./dist/runner/index.js",
30
- "require": "./dist/runner/index.cjs"
31
- },
32
- "./runner/protocol-endpoint": {
33
- "source": "./src/runner/protocolEndpoint.ts",
34
- "types": {
35
- "import": "./dist/runner/protocolEndpoint.d.ts",
36
- "require": "./dist/runner/protocolEndpoint.d.cts"
37
- },
38
- "import": "./dist/runner/protocolEndpoint.js",
39
- "require": "./dist/runner/protocolEndpoint.cjs"
40
- },
41
- "./remote-endpoint": {
42
- "source": "./src/remoteEndpoint.ts",
43
- "types": {
44
- "import": "./dist/remoteEndpoint.d.ts",
45
- "require": "./dist/remoteEndpoint.d.cts"
46
- },
47
- "import": "./dist/remoteEndpoint.js",
48
- "require": "./dist/remoteEndpoint.cjs"
49
22
  }
50
23
  },
51
24
  "sideEffects": false,
@@ -72,7 +45,7 @@
72
45
  "homepage": "https://github.com/aallam/execbox/tree/main/packages/quickjs#readme",
73
46
  "bugs": "https://github.com/aallam/execbox/issues",
74
47
  "dependencies": {
75
- "@execbox/core": "^0.5.0",
48
+ "@execbox/core": "^0.7.0",
76
49
  "quickjs-emscripten": "^0.31.0"
77
50
  }
78
51
  }
@@ -1,112 +0,0 @@
1
- const require_runner = require('./runner-DRLfwiqY.cjs');
2
- let __execbox_core_protocol = require("@execbox/core/protocol");
3
- let node_crypto = require("node:crypto");
4
-
5
- //#region src/runner/protocolEndpoint.ts
6
- /**
7
- * @packageDocumentation
8
- * Public API for the `@execbox/quickjs/runner/protocol-endpoint` entrypoint.
9
- */
10
- /**
11
- * Attaches the shared QuickJS protocol loop to a worker messaging port.
12
- */
13
- function attachQuickJsProtocolEndpoint(port) {
14
- const pendingToolCalls = /* @__PURE__ */ new Map();
15
- let activeAbortController;
16
- let activeExecutionId;
17
- async function startExecution(message) {
18
- if (activeExecutionId) {
19
- port.send({
20
- durationMs: 0,
21
- error: {
22
- code: "internal_error",
23
- message: "QuickJS endpoint already has an active execution"
24
- },
25
- id: message.id,
26
- logs: [],
27
- ok: false,
28
- type: "done"
29
- });
30
- return;
31
- }
32
- const abortController = new AbortController();
33
- activeAbortController = abortController;
34
- activeExecutionId = message.id;
35
- try {
36
- const result = await require_runner.runQuickJsSession({
37
- abortController,
38
- code: message.code,
39
- onStarted: () => {
40
- port.send({
41
- id: message.id,
42
- type: "started"
43
- });
44
- },
45
- onToolCall: (call) => new Promise((resolve) => {
46
- const callId = (0, node_crypto.randomUUID)();
47
- pendingToolCalls.set(callId, resolve);
48
- port.send({
49
- ...call,
50
- callId,
51
- type: "tool_call"
52
- });
53
- }),
54
- providers: message.providers
55
- }, message.options);
56
- port.send({
57
- ...result,
58
- id: message.id,
59
- type: "done"
60
- });
61
- } catch (error) {
62
- port.send({
63
- durationMs: 0,
64
- error: {
65
- code: "internal_error",
66
- message: error instanceof Error ? error.message : String(error)
67
- },
68
- id: message.id,
69
- logs: [],
70
- ok: false,
71
- type: "done"
72
- });
73
- } finally {
74
- pendingToolCalls.clear();
75
- activeAbortController = void 0;
76
- activeExecutionId = void 0;
77
- }
78
- }
79
- const maybeDetach = port.onMessage((message) => {
80
- if (!(0, __execbox_core_protocol.isDispatcherMessage)(message)) return;
81
- switch (message.type) {
82
- case "cancel":
83
- if (message.id === activeExecutionId) activeAbortController?.abort();
84
- break;
85
- case "execute":
86
- startExecution(message);
87
- break;
88
- case "tool_result": {
89
- const resolve = pendingToolCalls.get(message.callId);
90
- pendingToolCalls.delete(message.callId);
91
- resolve?.(message);
92
- break;
93
- }
94
- }
95
- });
96
- return () => {
97
- if (typeof maybeDetach === "function") maybeDetach();
98
- pendingToolCalls.clear();
99
- activeAbortController?.abort();
100
- activeAbortController = void 0;
101
- activeExecutionId = void 0;
102
- };
103
- }
104
-
105
- //#endregion
106
- Object.defineProperty(exports, 'attachQuickJsProtocolEndpoint', {
107
- enumerable: true,
108
- get: function () {
109
- return attachQuickJsProtocolEndpoint;
110
- }
111
- });
112
- //# sourceMappingURL=protocolEndpoint-BGyrwlr_.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"protocolEndpoint-BGyrwlr_.cjs","names":["activeAbortController: AbortController | undefined","activeExecutionId: string | undefined","runQuickJsSession"],"sources":["../src/runner/protocolEndpoint.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Public API for the `@execbox/quickjs/runner/protocol-endpoint` entrypoint.\n */\nimport { randomUUID } from \"node:crypto\";\n\nimport { isDispatcherMessage } from \"@execbox/core/protocol\";\nimport type {\n DispatcherMessage,\n ExecuteMessage,\n RunnerMessage,\n} from \"@execbox/core/protocol\";\nimport type { ToolCallResult } from \"@execbox/core\";\n\nimport { runQuickJsSession } from \"./index.ts\";\n\n/**\n * Minimal worker-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 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":";;;;;;;;;;;;AA2BA,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,MAAI,kDAAqB,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,107 +0,0 @@
1
- import { t as runQuickJsSession } from "./runner-oZXbguX3.js";
2
- import { isDispatcherMessage } from "@execbox/core/protocol";
3
- import { randomUUID } from "node:crypto";
4
-
5
- //#region src/runner/protocolEndpoint.ts
6
- /**
7
- * @packageDocumentation
8
- * Public API for the `@execbox/quickjs/runner/protocol-endpoint` entrypoint.
9
- */
10
- /**
11
- * Attaches the shared QuickJS protocol loop to a worker messaging port.
12
- */
13
- function attachQuickJsProtocolEndpoint(port) {
14
- const pendingToolCalls = /* @__PURE__ */ new Map();
15
- let activeAbortController;
16
- let activeExecutionId;
17
- async function startExecution(message) {
18
- if (activeExecutionId) {
19
- port.send({
20
- durationMs: 0,
21
- error: {
22
- code: "internal_error",
23
- message: "QuickJS endpoint already has an active execution"
24
- },
25
- id: message.id,
26
- logs: [],
27
- ok: false,
28
- type: "done"
29
- });
30
- return;
31
- }
32
- const abortController = new AbortController();
33
- activeAbortController = abortController;
34
- activeExecutionId = message.id;
35
- try {
36
- const result = await runQuickJsSession({
37
- abortController,
38
- code: message.code,
39
- onStarted: () => {
40
- port.send({
41
- id: message.id,
42
- type: "started"
43
- });
44
- },
45
- onToolCall: (call) => new Promise((resolve) => {
46
- const callId = randomUUID();
47
- pendingToolCalls.set(callId, resolve);
48
- port.send({
49
- ...call,
50
- callId,
51
- type: "tool_call"
52
- });
53
- }),
54
- providers: message.providers
55
- }, message.options);
56
- port.send({
57
- ...result,
58
- id: message.id,
59
- type: "done"
60
- });
61
- } catch (error) {
62
- port.send({
63
- durationMs: 0,
64
- error: {
65
- code: "internal_error",
66
- message: error instanceof Error ? error.message : String(error)
67
- },
68
- id: message.id,
69
- logs: [],
70
- ok: false,
71
- type: "done"
72
- });
73
- } finally {
74
- pendingToolCalls.clear();
75
- activeAbortController = void 0;
76
- activeExecutionId = void 0;
77
- }
78
- }
79
- const maybeDetach = port.onMessage((message) => {
80
- if (!isDispatcherMessage(message)) return;
81
- switch (message.type) {
82
- case "cancel":
83
- if (message.id === activeExecutionId) activeAbortController?.abort();
84
- break;
85
- case "execute":
86
- startExecution(message);
87
- break;
88
- case "tool_result": {
89
- const resolve = pendingToolCalls.get(message.callId);
90
- pendingToolCalls.delete(message.callId);
91
- resolve?.(message);
92
- break;
93
- }
94
- }
95
- });
96
- return () => {
97
- if (typeof maybeDetach === "function") maybeDetach();
98
- pendingToolCalls.clear();
99
- activeAbortController?.abort();
100
- activeAbortController = void 0;
101
- activeExecutionId = void 0;
102
- };
103
- }
104
-
105
- //#endregion
106
- export { attachQuickJsProtocolEndpoint as t };
107
- //# sourceMappingURL=protocolEndpoint-Ceadcq_L.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"protocolEndpoint-Ceadcq_L.js","names":["activeAbortController: AbortController | undefined","activeExecutionId: string | undefined"],"sources":["../src/runner/protocolEndpoint.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Public API for the `@execbox/quickjs/runner/protocol-endpoint` entrypoint.\n */\nimport { randomUUID } from \"node:crypto\";\n\nimport { isDispatcherMessage } from \"@execbox/core/protocol\";\nimport type {\n DispatcherMessage,\n ExecuteMessage,\n RunnerMessage,\n} from \"@execbox/core/protocol\";\nimport type { ToolCallResult } from \"@execbox/core\";\n\nimport { runQuickJsSession } from \"./index.ts\";\n\n/**\n * Minimal worker-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 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":";;;;;;;;;;;;AA2BA,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,MAAM,kBACnB;IACE;IACA,MAAM,QAAQ;IACd,iBAAiB;AACf,UAAK,KAAK;MACR,IAAI,QAAQ;MACZ,MAAM;MACP,CAAC;;IAEJ,aAAa,SACX,IAAI,SAAyB,YAAY;KACvC,MAAM,SAAS,YAAY;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,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,45 +0,0 @@
1
- require('./runner-DRLfwiqY.cjs');
2
- const require_protocolEndpoint = require('./protocolEndpoint-BGyrwlr_.cjs');
3
- let __execbox_core_protocol = require("@execbox/core/protocol");
4
-
5
- //#region src/remoteEndpoint.ts
6
- /**
7
- * @packageDocumentation
8
- * QuickJS remote runner endpoint for `@execbox/remote` transports.
9
- */
10
- /**
11
- * Attaches the shared QuickJS protocol endpoint to a remote runner transport
12
- * and tears it down automatically when the transport closes or errors.
13
- */
14
- function attachQuickJsRemoteEndpoint(port) {
15
- const detachProtocol = require_protocolEndpoint.attachQuickJsProtocolEndpoint({
16
- onMessage(handler) {
17
- const maybeDetach = port.onMessage((message) => {
18
- if (!(0, __execbox_core_protocol.isDispatcherMessage)(message)) return;
19
- handler(message);
20
- });
21
- return () => {
22
- if (typeof maybeDetach === "function") maybeDetach();
23
- };
24
- },
25
- send(message) {
26
- Promise.resolve(port.send(message)).catch(() => {});
27
- }
28
- });
29
- const offClose = port.onClose?.(() => {
30
- cleanup();
31
- });
32
- const offError = port.onError?.(() => {
33
- cleanup();
34
- });
35
- function cleanup() {
36
- if (typeof offClose === "function") offClose();
37
- if (typeof offError === "function") offError();
38
- detachProtocol();
39
- }
40
- return cleanup;
41
- }
42
-
43
- //#endregion
44
- exports.attachQuickJsRemoteEndpoint = attachQuickJsRemoteEndpoint;
45
- //# sourceMappingURL=remoteEndpoint.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"remoteEndpoint.cjs","names":["attachQuickJsProtocolEndpoint"],"sources":["../src/remoteEndpoint.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * QuickJS remote runner endpoint for `@execbox/remote` transports.\n */\nimport {\n isDispatcherMessage,\n type DispatcherMessage,\n type RunnerMessage,\n type TransportCloseReason,\n} from \"@execbox/core/protocol\";\n\nimport { attachQuickJsProtocolEndpoint } from \"./runner/protocolEndpoint.ts\";\n\n/**\n * Minimal runner-side port for transport-backed QuickJS execution.\n */\nexport interface QuickJsRemoteEndpointPort {\n /** Registers a close callback for transport shutdown notifications. */\n onClose?(\n handler: (reason?: TransportCloseReason) => void,\n ): void | (() => void);\n\n /** Registers an error callback for transport-level failures. */\n onError?(handler: (error: Error) => void): void | (() => void);\n\n /** Registers a handler for inbound runner messages. */\n onMessage(handler: (message: unknown) => void): void | (() => void);\n\n /** Sends a transport message to the attached host session. */\n send(message: unknown): void | Promise<void>;\n}\n\n/**\n * Attaches the shared QuickJS protocol endpoint to a remote runner transport\n * and tears it down automatically when the transport closes or errors.\n */\nexport function attachQuickJsRemoteEndpoint(\n port: QuickJsRemoteEndpointPort,\n): () => void {\n const detachProtocol = attachQuickJsProtocolEndpoint({\n onMessage(handler: (message: DispatcherMessage) => void): () => void {\n const maybeDetach = port.onMessage((message: unknown) => {\n if (!isDispatcherMessage(message)) {\n return;\n }\n\n handler(message);\n });\n\n return () => {\n if (typeof maybeDetach === \"function\") {\n maybeDetach();\n }\n };\n },\n send(message: RunnerMessage): void {\n void Promise.resolve(port.send(message)).catch(() => {});\n },\n });\n\n const offClose = port.onClose?.(() => {\n cleanup();\n });\n const offError = port.onError?.(() => {\n cleanup();\n });\n\n function cleanup(): void {\n if (typeof offClose === \"function\") {\n offClose();\n }\n if (typeof offError === \"function\") {\n offError();\n }\n detachProtocol();\n }\n\n return cleanup;\n}\n"],"mappings":";;;;;;;;;;;;;AAoCA,SAAgB,4BACd,MACY;CACZ,MAAM,iBAAiBA,uDAA8B;EACnD,UAAU,SAA2D;GACnE,MAAM,cAAc,KAAK,WAAW,YAAqB;AACvD,QAAI,kDAAqB,QAAQ,CAC/B;AAGF,YAAQ,QAAQ;KAChB;AAEF,gBAAa;AACX,QAAI,OAAO,gBAAgB,WACzB,cAAa;;;EAInB,KAAK,SAA8B;AACjC,GAAK,QAAQ,QAAQ,KAAK,KAAK,QAAQ,CAAC,CAAC,YAAY,GAAG;;EAE3D,CAAC;CAEF,MAAM,WAAW,KAAK,gBAAgB;AACpC,WAAS;GACT;CACF,MAAM,WAAW,KAAK,gBAAgB;AACpC,WAAS;GACT;CAEF,SAAS,UAAgB;AACvB,MAAI,OAAO,aAAa,WACtB,WAAU;AAEZ,MAAI,OAAO,aAAa,WACtB,WAAU;AAEZ,kBAAgB;;AAGlB,QAAO"}
@@ -1,29 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- * Public TypeScript declarations for this package entrypoint.
4
- */
5
- import { TransportCloseReason } from "@execbox/core/protocol";
6
-
7
- //#region src/remoteEndpoint.d.ts
8
-
9
- /**
10
- * Minimal runner-side port for transport-backed QuickJS execution.
11
- */
12
- interface QuickJsRemoteEndpointPort {
13
- /** Registers a close callback for transport shutdown notifications. */
14
- onClose?(handler: (reason?: TransportCloseReason) => void): void | (() => void);
15
- /** Registers an error callback for transport-level failures. */
16
- onError?(handler: (error: Error) => void): void | (() => void);
17
- /** Registers a handler for inbound runner messages. */
18
- onMessage(handler: (message: unknown) => void): void | (() => void);
19
- /** Sends a transport message to the attached host session. */
20
- send(message: unknown): void | Promise<void>;
21
- }
22
- /**
23
- * Attaches the shared QuickJS protocol endpoint to a remote runner transport
24
- * and tears it down automatically when the transport closes or errors.
25
- */
26
- declare function attachQuickJsRemoteEndpoint(port: QuickJsRemoteEndpointPort): () => void;
27
- //#endregion
28
- export { QuickJsRemoteEndpointPort, attachQuickJsRemoteEndpoint };
29
- //# sourceMappingURL=remoteEndpoint.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"remoteEndpoint.d.cts","names":[],"sources":["../src/remoteEndpoint.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AAoCgB,SAAA,CApBC,yBAAA,CAoB0B;;8BAjBpB;;4BAIK;;;;iCAMK;;;;;;iBAOjB,2BAAA,OACR"}
@@ -1,29 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- * Public TypeScript declarations for this package entrypoint.
4
- */
5
- import { TransportCloseReason } from "@execbox/core/protocol";
6
-
7
- //#region src/remoteEndpoint.d.ts
8
-
9
- /**
10
- * Minimal runner-side port for transport-backed QuickJS execution.
11
- */
12
- interface QuickJsRemoteEndpointPort {
13
- /** Registers a close callback for transport shutdown notifications. */
14
- onClose?(handler: (reason?: TransportCloseReason) => void): void | (() => void);
15
- /** Registers an error callback for transport-level failures. */
16
- onError?(handler: (error: Error) => void): void | (() => void);
17
- /** Registers a handler for inbound runner messages. */
18
- onMessage(handler: (message: unknown) => void): void | (() => void);
19
- /** Sends a transport message to the attached host session. */
20
- send(message: unknown): void | Promise<void>;
21
- }
22
- /**
23
- * Attaches the shared QuickJS protocol endpoint to a remote runner transport
24
- * and tears it down automatically when the transport closes or errors.
25
- */
26
- declare function attachQuickJsRemoteEndpoint(port: QuickJsRemoteEndpointPort): () => void;
27
- //#endregion
28
- export { QuickJsRemoteEndpointPort, attachQuickJsRemoteEndpoint };
29
- //# sourceMappingURL=remoteEndpoint.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"remoteEndpoint.d.ts","names":[],"sources":["../src/remoteEndpoint.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AAoCgB,SAAA,CApBC,yBAAA,CAoB0B;;8BAjBpB;;4BAIK;;;;iCAMK;;;;;;iBAOjB,2BAAA,OACR"}
@@ -1,45 +0,0 @@
1
- import "./runner-oZXbguX3.js";
2
- import { t as attachQuickJsProtocolEndpoint } from "./protocolEndpoint-Ceadcq_L.js";
3
- import { isDispatcherMessage } from "@execbox/core/protocol";
4
-
5
- //#region src/remoteEndpoint.ts
6
- /**
7
- * @packageDocumentation
8
- * QuickJS remote runner endpoint for `@execbox/remote` transports.
9
- */
10
- /**
11
- * Attaches the shared QuickJS protocol endpoint to a remote runner transport
12
- * and tears it down automatically when the transport closes or errors.
13
- */
14
- function attachQuickJsRemoteEndpoint(port) {
15
- const detachProtocol = attachQuickJsProtocolEndpoint({
16
- onMessage(handler) {
17
- const maybeDetach = port.onMessage((message) => {
18
- if (!isDispatcherMessage(message)) return;
19
- handler(message);
20
- });
21
- return () => {
22
- if (typeof maybeDetach === "function") maybeDetach();
23
- };
24
- },
25
- send(message) {
26
- Promise.resolve(port.send(message)).catch(() => {});
27
- }
28
- });
29
- const offClose = port.onClose?.(() => {
30
- cleanup();
31
- });
32
- const offError = port.onError?.(() => {
33
- cleanup();
34
- });
35
- function cleanup() {
36
- if (typeof offClose === "function") offClose();
37
- if (typeof offError === "function") offError();
38
- detachProtocol();
39
- }
40
- return cleanup;
41
- }
42
-
43
- //#endregion
44
- export { attachQuickJsRemoteEndpoint };
45
- //# sourceMappingURL=remoteEndpoint.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"remoteEndpoint.js","names":[],"sources":["../src/remoteEndpoint.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * QuickJS remote runner endpoint for `@execbox/remote` transports.\n */\nimport {\n isDispatcherMessage,\n type DispatcherMessage,\n type RunnerMessage,\n type TransportCloseReason,\n} from \"@execbox/core/protocol\";\n\nimport { attachQuickJsProtocolEndpoint } from \"./runner/protocolEndpoint.ts\";\n\n/**\n * Minimal runner-side port for transport-backed QuickJS execution.\n */\nexport interface QuickJsRemoteEndpointPort {\n /** Registers a close callback for transport shutdown notifications. */\n onClose?(\n handler: (reason?: TransportCloseReason) => void,\n ): void | (() => void);\n\n /** Registers an error callback for transport-level failures. */\n onError?(handler: (error: Error) => void): void | (() => void);\n\n /** Registers a handler for inbound runner messages. */\n onMessage(handler: (message: unknown) => void): void | (() => void);\n\n /** Sends a transport message to the attached host session. */\n send(message: unknown): void | Promise<void>;\n}\n\n/**\n * Attaches the shared QuickJS protocol endpoint to a remote runner transport\n * and tears it down automatically when the transport closes or errors.\n */\nexport function attachQuickJsRemoteEndpoint(\n port: QuickJsRemoteEndpointPort,\n): () => void {\n const detachProtocol = attachQuickJsProtocolEndpoint({\n onMessage(handler: (message: DispatcherMessage) => void): () => void {\n const maybeDetach = port.onMessage((message: unknown) => {\n if (!isDispatcherMessage(message)) {\n return;\n }\n\n handler(message);\n });\n\n return () => {\n if (typeof maybeDetach === \"function\") {\n maybeDetach();\n }\n };\n },\n send(message: RunnerMessage): void {\n void Promise.resolve(port.send(message)).catch(() => {});\n },\n });\n\n const offClose = port.onClose?.(() => {\n cleanup();\n });\n const offError = port.onError?.(() => {\n cleanup();\n });\n\n function cleanup(): void {\n if (typeof offClose === \"function\") {\n offClose();\n }\n if (typeof offError === \"function\") {\n offError();\n }\n detachProtocol();\n }\n\n return cleanup;\n}\n"],"mappings":";;;;;;;;;;;;;AAoCA,SAAgB,4BACd,MACY;CACZ,MAAM,iBAAiB,8BAA8B;EACnD,UAAU,SAA2D;GACnE,MAAM,cAAc,KAAK,WAAW,YAAqB;AACvD,QAAI,CAAC,oBAAoB,QAAQ,CAC/B;AAGF,YAAQ,QAAQ;KAChB;AAEF,gBAAa;AACX,QAAI,OAAO,gBAAgB,WACzB,cAAa;;;EAInB,KAAK,SAA8B;AACjC,GAAK,QAAQ,QAAQ,KAAK,KAAK,QAAQ,CAAC,CAAC,YAAY,GAAG;;EAE3D,CAAC;CAEF,MAAM,WAAW,KAAK,gBAAgB;AACpC,WAAS;GACT;CACF,MAAM,WAAW,KAAK,gBAAgB;AACpC,WAAS;GACT;CAEF,SAAS,UAAgB;AACvB,MAAI,OAAO,aAAa,WACtB,WAAU;AAEZ,MAAI,OAAO,aAAa,WACtB,WAAU;AAEZ,kBAAgB;;AAGlB,QAAO"}
@@ -1,3 +0,0 @@
1
- const require_runner = require('../runner-DRLfwiqY.cjs');
2
-
3
- exports.runQuickJsSession = require_runner.runQuickJsSession;
@@ -1,45 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- * Public TypeScript declarations for this package entrypoint.
4
- */
5
- import { a as QuickJsWorkerExecutorOptions, i as QuickJsInlineExecutorOptions, n as QuickJsExecutorOptions, o as WorkerResourceLimits, r as QuickJsHostedMode, t as QuickJsExecutorHost } from "../types-C-XfFJ7u.cjs";
6
- import { ExecuteResult, ExecutorRuntimeOptions, ProviderManifest, ToolCall, ToolCallResult } from "@execbox/core";
7
- import { QuickJSWASMModule } from "quickjs-emscripten";
8
-
9
- //#region src/runner/index.d.ts
10
-
11
- /**
12
- * Transport-neutral host tool call emitted from a QuickJS session.
13
- */
14
- type QuickJsSessionToolCall = ToolCall;
15
- /**
16
- * Input required to run one transport-backed QuickJS execution session.
17
- */
18
- interface QuickJsSessionRequest {
19
- /** Optional abort controller that should be triggered when execution stops. */
20
- abortController?: AbortController;
21
- /** Guest JavaScript source to evaluate inside QuickJS. */
22
- code: string;
23
- /** Host callback used to fulfill guest tool calls. */
24
- onToolCall: (call: ToolCall) => Promise<ToolCallResult> | ToolCallResult;
25
- /** Optional hook invoked once the guest runtime has started. */
26
- onStarted?: () => void;
27
- /** Transport-safe provider manifests exposed to the guest runtime. */
28
- providers: ProviderManifest[];
29
- /** Optional caller-owned abort signal for the session. */
30
- signal?: AbortSignal;
31
- }
32
- /**
33
- * Options controlling one transport-backed QuickJS session.
34
- */
35
- type QuickJsSessionOptions = ExecutorRuntimeOptions & Pick<QuickJsInlineExecutorOptions, "loadModule"> & {
36
- /** Optional preloaded QuickJS WASM module instance. */
37
- module?: QuickJSWASMModule;
38
- };
39
- /**
40
- * Runs one QuickJS-backed execution session using a transport-neutral tool callback.
41
- */
42
- declare function runQuickJsSession(request: QuickJsSessionRequest, options?: QuickJsSessionOptions): Promise<ExecuteResult>;
43
- //#endregion
44
- export { type QuickJsExecutorHost, type QuickJsExecutorOptions, type QuickJsHostedMode, type QuickJsInlineExecutorOptions, QuickJsSessionOptions, QuickJsSessionRequest, QuickJsSessionToolCall, type QuickJsWorkerExecutorOptions, type WorkerResourceLimits, runQuickJsSession };
45
- //# sourceMappingURL=index.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/runner/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AA6DA,CAAA,CAAA,CAAA,SAAA,CAAA,OAAA,CAAA,IAAA,CAAA,IAAA,CAAA,IAAA,CAAA,OAAA,CAAA,IAAA,CAAA,CAAA,CAAA,OAAA,CAAA,OAAA;AAKA,CAAA,CAAA;AAEoB,IAAA,CAPR,sBAAA,CAAA,CAAA,CAAyB,QAOjB;;;;AAMwC,SAAA,CAR3C,qBAAA,CAQ2C;EAM/C,CAAA,CAAA,CAAA,CAAA,QAAA,CAAA,KAAA,CAAA,UAAA,CAAA,IAAA,CAAA,MAAA,CAAA,EAAA,CAAA,SAAA,CAAA,IAAA,CAAA,SAAA,CAAA,KAAA,CAAA,CAAA,CAAA;EAGF,eAAA,CAAA,CAAA,CAfS,eAeT;EAAW,CAAA,CAAA,CAAA,CAAA,KAAA,CAAA,UAAA,CAAA,MAAA,CAAA,EAAA,CAAA,QAAA,CAAA,MAAA,CAAA,OAAA,CAAA,CAAA,CAAA;EAMV,IAAA,CAAA,CAAA,MAAA;EAAwB,CAAA,CAAA,CAAA,CAAA,IAAA,CAAA,QAAA,CAAA,IAAA,CAAA,EAAA,CAAA,OAAA,CAAA,KAAA,CAAA,IAAA,CAAA,KAAA,CAAA,CAAA,CAAA;EAC7B,UAAA,CAAA,CAAA,CAAA,IAAA,CAAA,CAhBc,QAgBd,CAAA,CAAA,CAAA,CAAA,CAhB2B,OAgB3B,CAhBmC,cAgBnC,CAAA,CAAA,CAAA,CAhBqD,cAgBrD;EAAL,CAAA,CAAA,CAAA,CAAA,QAAA,CAAA,IAAA,CAAA,OAAA,CAAA,IAAA,CAAA,GAAA,CAAA,KAAA,CAAA,OAAA,CAAA,GAAA,CAAA,OAAA,CAAA,CAAA,CAAA;EAEW,SAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,IAAA;EAAiB,CAAA,CAAA,CAAA,CAAA,SAAA,CAAA,IAAA,CAAA,QAAA,CAAA,SAAA,CAAA,OAAA,CAAA,EAAA,CAAA,GAAA,CAAA,KAAA,CAAA,OAAA,CAAA,CAAA,CAAA;EA4TR,SAAA,CAAA,CAxUT,gBAwU0B,CAAA,CAAA;EAC5B,CAAA,CAAA,CAAA,CAAA,QAAA,CAAA,MAAA,CAAA,KAAA,CAAA,KAAA,CAAA,MAAA,CAAA,GAAA,CAAA,GAAA,CAAA,OAAA,CAAA,CAAA,CAAA;EACA,MAAA,CAAA,CAAA,CAvUA,WAuUA;;;;;KAjUC,qBAAA,CAAA,CAAA,CAAwB,yBAClC,KAAK;;WAEM;;;;;iBA4TS,iBAAA,UACX,iCACA,wBACR,QAAQ"}