@execbox/quickjs 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -15
- package/dist/index.cjs +17 -240
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +56 -8
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +56 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -240
- package/dist/index.js.map +1 -1
- package/dist/{runner-DRLfwiqY.cjs → runner-BeRzBTrn.cjs} +92 -74
- package/dist/runner-BeRzBTrn.cjs.map +1 -0
- package/dist/{runner-DJ5AWw-k.js → runner-DJd4Bh8V.js} +92 -74
- package/dist/runner-DJd4Bh8V.js.map +1 -0
- package/dist/workerEntry.cjs +105 -3
- package/dist/workerEntry.cjs.map +1 -1
- package/dist/workerEntry.js +104 -2
- package/dist/workerEntry.js.map +1 -1
- package/package.json +3 -30
- package/dist/processEntry.cjs +0 -17
- package/dist/processEntry.cjs.map +0 -1
- package/dist/processEntry.d.cts +0 -5
- package/dist/processEntry.d.ts +0 -5
- package/dist/processEntry.js +0 -18
- package/dist/processEntry.js.map +0 -1
- package/dist/protocolEndpoint-ByylXGle.cjs +0 -112
- package/dist/protocolEndpoint-ByylXGle.cjs.map +0 -1
- package/dist/protocolEndpoint-CwyUhKrN.js +0 -107
- package/dist/protocolEndpoint-CwyUhKrN.js.map +0 -1
- package/dist/remoteEndpoint.cjs +0 -45
- package/dist/remoteEndpoint.cjs.map +0 -1
- package/dist/remoteEndpoint.d.cts +0 -29
- package/dist/remoteEndpoint.d.cts.map +0 -1
- package/dist/remoteEndpoint.d.ts +0 -29
- package/dist/remoteEndpoint.d.ts.map +0 -1
- package/dist/remoteEndpoint.js +0 -45
- package/dist/remoteEndpoint.js.map +0 -1
- package/dist/runner/index.cjs +0 -3
- package/dist/runner/index.d.cts +0 -45
- package/dist/runner/index.d.cts.map +0 -1
- package/dist/runner/index.d.ts +0 -45
- package/dist/runner/index.d.ts.map +0 -1
- package/dist/runner/index.js +0 -3
- package/dist/runner/protocolEndpoint.cjs +0 -4
- package/dist/runner/protocolEndpoint.d.cts +0 -22
- package/dist/runner/protocolEndpoint.d.cts.map +0 -1
- package/dist/runner/protocolEndpoint.d.ts +0 -22
- package/dist/runner/protocolEndpoint.d.ts.map +0 -1
- package/dist/runner/protocolEndpoint.js +0 -4
- package/dist/runner-DJ5AWw-k.js.map +0 -1
- package/dist/runner-DRLfwiqY.cjs.map +0 -1
- package/dist/types-7wOdERLE.d.ts +0 -71
- package/dist/types-7wOdERLE.d.ts.map +0 -1
- package/dist/types-BMA2zKnX.d.cts +0 -71
- package/dist/types-BMA2zKnX.d.cts.map +0 -1
package/dist/workerEntry.js
CHANGED
|
@@ -1,7 +1,109 @@
|
|
|
1
|
-
import "./runner-
|
|
2
|
-
import { t as attachQuickJsProtocolEndpoint } from "./protocolEndpoint-CwyUhKrN.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;
|
package/dist/workerEntry.js.map
CHANGED
|
@@ -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":"
|
|
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@execbox/quickjs",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "QuickJS executor for the execbox core package across inline
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "QuickJS executor for the execbox core package across inline and worker hosts.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
@@ -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.
|
|
48
|
+
"@execbox/core": "^0.6.0",
|
|
76
49
|
"quickjs-emscripten": "^0.31.0"
|
|
77
50
|
}
|
|
78
51
|
}
|
package/dist/processEntry.cjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
require('./runner-DRLfwiqY.cjs');
|
|
2
|
-
const require_protocolEndpoint = require('./protocolEndpoint-ByylXGle.cjs');
|
|
3
|
-
|
|
4
|
-
//#region src/processEntry.ts
|
|
5
|
-
if (typeof process.send !== "function") throw new Error("QuickJsExecutor process host requires a child process IPC channel");
|
|
6
|
-
require_protocolEndpoint.attachQuickJsProtocolEndpoint({
|
|
7
|
-
onMessage(handler) {
|
|
8
|
-
process.on("message", handler);
|
|
9
|
-
return () => process.off("message", handler);
|
|
10
|
-
},
|
|
11
|
-
send(message) {
|
|
12
|
-
process.send?.(message);
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
|
-
//# sourceMappingURL=processEntry.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"processEntry.cjs","names":["attachQuickJsProtocolEndpoint"],"sources":["../src/processEntry.ts"],"sourcesContent":["import type { DispatcherMessage, RunnerMessage } from \"@execbox/core/protocol\";\n\nimport { attachQuickJsProtocolEndpoint } from \"./runner/protocolEndpoint.ts\";\n\nif (typeof process.send !== \"function\") {\n throw new Error(\n \"QuickJsExecutor process host requires a child process IPC channel\",\n );\n}\n\nattachQuickJsProtocolEndpoint({\n onMessage(handler: (message: DispatcherMessage) => void): () => void {\n process.on(\"message\", handler);\n return () => process.off(\"message\", handler);\n },\n send(message: RunnerMessage): void {\n process.send?.(message);\n },\n});\n"],"mappings":";;;;AAIA,IAAI,OAAO,QAAQ,SAAS,WAC1B,OAAM,IAAI,MACR,oEACD;AAGHA,uDAA8B;CAC5B,UAAU,SAA2D;AACnE,UAAQ,GAAG,WAAW,QAAQ;AAC9B,eAAa,QAAQ,IAAI,WAAW,QAAQ;;CAE9C,KAAK,SAA8B;AACjC,UAAQ,OAAO,QAAQ;;CAE1B,CAAC"}
|
package/dist/processEntry.d.cts
DELETED
package/dist/processEntry.d.ts
DELETED
package/dist/processEntry.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import "./runner-DJ5AWw-k.js";
|
|
2
|
-
import { t as attachQuickJsProtocolEndpoint } from "./protocolEndpoint-CwyUhKrN.js";
|
|
3
|
-
|
|
4
|
-
//#region src/processEntry.ts
|
|
5
|
-
if (typeof process.send !== "function") throw new Error("QuickJsExecutor process host requires a child process IPC channel");
|
|
6
|
-
attachQuickJsProtocolEndpoint({
|
|
7
|
-
onMessage(handler) {
|
|
8
|
-
process.on("message", handler);
|
|
9
|
-
return () => process.off("message", handler);
|
|
10
|
-
},
|
|
11
|
-
send(message) {
|
|
12
|
-
process.send?.(message);
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
|
-
export { };
|
|
18
|
-
//# sourceMappingURL=processEntry.js.map
|
package/dist/processEntry.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"processEntry.js","names":[],"sources":["../src/processEntry.ts"],"sourcesContent":["import type { DispatcherMessage, RunnerMessage } from \"@execbox/core/protocol\";\n\nimport { attachQuickJsProtocolEndpoint } from \"./runner/protocolEndpoint.ts\";\n\nif (typeof process.send !== \"function\") {\n throw new Error(\n \"QuickJsExecutor process host requires a child process IPC channel\",\n );\n}\n\nattachQuickJsProtocolEndpoint({\n onMessage(handler: (message: DispatcherMessage) => void): () => void {\n process.on(\"message\", handler);\n return () => process.off(\"message\", handler);\n },\n send(message: RunnerMessage): void {\n process.send?.(message);\n },\n});\n"],"mappings":";;;;AAIA,IAAI,OAAO,QAAQ,SAAS,WAC1B,OAAM,IAAI,MACR,oEACD;AAGH,8BAA8B;CAC5B,UAAU,SAA2D;AACnE,UAAQ,GAAG,WAAW,QAAQ;AAC9B,eAAa,QAAQ,IAAI,WAAW,QAAQ;;CAE9C,KAAK,SAA8B;AACjC,UAAQ,OAAO,QAAQ;;CAE1B,CAAC"}
|
|
@@ -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/process 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-ByylXGle.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"protocolEndpoint-ByylXGle.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/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":";;;;;;;;;;;;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-DJ5AWw-k.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/process 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-CwyUhKrN.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"protocolEndpoint-CwyUhKrN.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/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":";;;;;;;;;;;;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"}
|
package/dist/remoteEndpoint.cjs
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
require('./runner-DRLfwiqY.cjs');
|
|
2
|
-
const require_protocolEndpoint = require('./protocolEndpoint-ByylXGle.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"}
|
package/dist/remoteEndpoint.d.ts
DELETED
|
@@ -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"}
|
package/dist/remoteEndpoint.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import "./runner-DJ5AWw-k.js";
|
|
2
|
-
import { t as attachQuickJsProtocolEndpoint } from "./protocolEndpoint-CwyUhKrN.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
|