@execbox/quickjs 0.2.1 → 0.4.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 +18 -4
- package/dist/index.cjs +543 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +15 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +543 -3
- package/dist/index.js.map +1 -1
- package/dist/processEntry.cjs +17 -0
- package/dist/processEntry.cjs.map +1 -0
- package/dist/processEntry.d.cts +5 -0
- package/dist/processEntry.d.ts +5 -0
- package/dist/processEntry.js +18 -0
- package/dist/processEntry.js.map +1 -0
- package/dist/protocolEndpoint-DGOUVf6J.cjs +147 -0
- package/dist/protocolEndpoint-DGOUVf6J.cjs.map +1 -0
- package/dist/protocolEndpoint-T_JEz8YY.js +142 -0
- package/dist/protocolEndpoint-T_JEz8YY.js.map +1 -0
- package/dist/runner/index.cjs +1 -1
- package/dist/runner/index.d.cts +10 -3
- package/dist/runner/index.d.cts.map +1 -1
- package/dist/runner/index.d.ts +10 -3
- package/dist/runner/index.d.ts.map +1 -1
- package/dist/runner/index.js +1 -1
- package/dist/runner/protocolEndpoint.cjs +3 -141
- package/dist/runner/protocolEndpoint.d.cts +1 -1
- package/dist/runner/protocolEndpoint.d.ts +1 -1
- package/dist/runner/protocolEndpoint.js +3 -141
- package/dist/{runner-CVaY4RVQ.js → runner-CteKTaPD.js} +28 -10
- package/dist/runner-CteKTaPD.js.map +1 -0
- package/dist/{runner-BqkDnP0t.cjs → runner-DRt0kpEk.cjs} +33 -9
- package/dist/{runner-CVaY4RVQ.js.map → runner-DRt0kpEk.cjs.map} +1 -1
- package/dist/types-BeVqrcj8.d.ts +71 -0
- package/dist/types-BeVqrcj8.d.ts.map +1 -0
- package/dist/types-CnNmLawC.d.cts +71 -0
- package/dist/types-CnNmLawC.d.cts.map +1 -0
- package/dist/workerEntry.cjs +19 -0
- package/dist/workerEntry.cjs.map +1 -0
- package/dist/workerEntry.d.cts +5 -0
- package/dist/workerEntry.d.ts +5 -0
- package/dist/workerEntry.js +20 -0
- package/dist/workerEntry.js.map +1 -0
- package/package.json +3 -4
- package/dist/runner/protocolEndpoint.cjs.map +0 -1
- package/dist/runner/protocolEndpoint.js.map +0 -1
- package/dist/runner-BqkDnP0t.cjs.map +0 -1
- package/dist/types-BXi8Lqtk.d.ts +0 -18
- package/dist/types-BXi8Lqtk.d.ts.map +0 -1
- package/dist/types-CVE2n2LY.d.cts +0 -18
- package/dist/types-CVE2n2LY.d.cts.map +0 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require('./runner-DRt0kpEk.cjs');
|
|
2
|
+
const require_protocolEndpoint = require('./protocolEndpoint-DGOUVf6J.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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import "./runner-CteKTaPD.js";
|
|
2
|
+
import { t as attachQuickJsProtocolEndpoint } from "./protocolEndpoint-T_JEz8YY.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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
const require_runner = require('./runner-DRt0kpEk.cjs');
|
|
2
|
+
let node_crypto = require("node:crypto");
|
|
3
|
+
|
|
4
|
+
//#region ../core/src/protocol/messages.ts
|
|
5
|
+
function isRecord(value) {
|
|
6
|
+
return typeof value === "object" && value !== null;
|
|
7
|
+
}
|
|
8
|
+
function isFiniteNumber(value) {
|
|
9
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
10
|
+
}
|
|
11
|
+
function isRuntimeOptions(value) {
|
|
12
|
+
if (!isRecord(value)) return false;
|
|
13
|
+
return isFiniteNumber(value.maxLogChars) && isFiniteNumber(value.maxLogLines) && isFiniteNumber(value.memoryLimitBytes) && isFiniteNumber(value.timeoutMs);
|
|
14
|
+
}
|
|
15
|
+
function isProviderManifest(value) {
|
|
16
|
+
if (!isRecord(value) || typeof value.name !== "string") return false;
|
|
17
|
+
if (!isRecord(value.tools) || typeof value.types !== "string") return false;
|
|
18
|
+
return Object.values(value.tools).every((tool) => isRecord(tool) && typeof tool.originalName === "string" && typeof tool.safeName === "string" && (tool.description === void 0 || typeof tool.description === "string"));
|
|
19
|
+
}
|
|
20
|
+
function isExecuteError(value) {
|
|
21
|
+
return isRecord(value) && typeof value.code === "string" && typeof value.message === "string";
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Returns whether an unknown value is a dispatcher-to-runner message.
|
|
25
|
+
*/
|
|
26
|
+
function isDispatcherMessage(value) {
|
|
27
|
+
if (!isRecord(value) || typeof value.type !== "string") return false;
|
|
28
|
+
switch (value.type) {
|
|
29
|
+
case "cancel": return typeof value.id === "string";
|
|
30
|
+
case "execute": return typeof value.code === "string" && typeof value.id === "string" && isRuntimeOptions(value.options) && Array.isArray(value.providers) && value.providers.every(isProviderManifest);
|
|
31
|
+
case "tool_result":
|
|
32
|
+
if (typeof value.callId !== "string" || typeof value.ok !== "boolean") return false;
|
|
33
|
+
if (value.ok) return "result" in value;
|
|
34
|
+
return isExecuteError(value.error);
|
|
35
|
+
default: return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/runner/protocolEndpoint.ts
|
|
41
|
+
/**
|
|
42
|
+
* @packageDocumentation
|
|
43
|
+
* Public API for the `@execbox/quickjs/runner/protocol-endpoint` entrypoint.
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* Attaches the shared QuickJS protocol loop to a worker/process messaging port.
|
|
47
|
+
*/
|
|
48
|
+
function attachQuickJsProtocolEndpoint(port) {
|
|
49
|
+
const pendingToolCalls = /* @__PURE__ */ new Map();
|
|
50
|
+
let activeAbortController;
|
|
51
|
+
let activeExecutionId;
|
|
52
|
+
async function startExecution(message) {
|
|
53
|
+
if (activeExecutionId) {
|
|
54
|
+
port.send({
|
|
55
|
+
durationMs: 0,
|
|
56
|
+
error: {
|
|
57
|
+
code: "internal_error",
|
|
58
|
+
message: "QuickJS endpoint already has an active execution"
|
|
59
|
+
},
|
|
60
|
+
id: message.id,
|
|
61
|
+
logs: [],
|
|
62
|
+
ok: false,
|
|
63
|
+
type: "done"
|
|
64
|
+
});
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const abortController = new AbortController();
|
|
68
|
+
activeAbortController = abortController;
|
|
69
|
+
activeExecutionId = message.id;
|
|
70
|
+
try {
|
|
71
|
+
const result = await require_runner.runQuickJsSession({
|
|
72
|
+
abortController,
|
|
73
|
+
code: message.code,
|
|
74
|
+
onStarted: () => {
|
|
75
|
+
port.send({
|
|
76
|
+
id: message.id,
|
|
77
|
+
type: "started"
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
onToolCall: (call) => new Promise((resolve) => {
|
|
81
|
+
const callId = (0, node_crypto.randomUUID)();
|
|
82
|
+
pendingToolCalls.set(callId, resolve);
|
|
83
|
+
port.send({
|
|
84
|
+
...call,
|
|
85
|
+
callId,
|
|
86
|
+
type: "tool_call"
|
|
87
|
+
});
|
|
88
|
+
}),
|
|
89
|
+
providers: message.providers
|
|
90
|
+
}, message.options);
|
|
91
|
+
port.send({
|
|
92
|
+
...result,
|
|
93
|
+
id: message.id,
|
|
94
|
+
type: "done"
|
|
95
|
+
});
|
|
96
|
+
} catch (error) {
|
|
97
|
+
port.send({
|
|
98
|
+
durationMs: 0,
|
|
99
|
+
error: {
|
|
100
|
+
code: "internal_error",
|
|
101
|
+
message: error instanceof Error ? error.message : String(error)
|
|
102
|
+
},
|
|
103
|
+
id: message.id,
|
|
104
|
+
logs: [],
|
|
105
|
+
ok: false,
|
|
106
|
+
type: "done"
|
|
107
|
+
});
|
|
108
|
+
} finally {
|
|
109
|
+
pendingToolCalls.clear();
|
|
110
|
+
activeAbortController = void 0;
|
|
111
|
+
activeExecutionId = void 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const maybeDetach = port.onMessage((message) => {
|
|
115
|
+
if (!isDispatcherMessage(message)) return;
|
|
116
|
+
switch (message.type) {
|
|
117
|
+
case "cancel":
|
|
118
|
+
if (message.id === activeExecutionId) activeAbortController?.abort();
|
|
119
|
+
break;
|
|
120
|
+
case "execute":
|
|
121
|
+
startExecution(message);
|
|
122
|
+
break;
|
|
123
|
+
case "tool_result": {
|
|
124
|
+
const resolve = pendingToolCalls.get(message.callId);
|
|
125
|
+
pendingToolCalls.delete(message.callId);
|
|
126
|
+
resolve?.(message);
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
return () => {
|
|
132
|
+
if (typeof maybeDetach === "function") maybeDetach();
|
|
133
|
+
pendingToolCalls.clear();
|
|
134
|
+
activeAbortController?.abort();
|
|
135
|
+
activeAbortController = void 0;
|
|
136
|
+
activeExecutionId = void 0;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
//#endregion
|
|
141
|
+
Object.defineProperty(exports, 'attachQuickJsProtocolEndpoint', {
|
|
142
|
+
enumerable: true,
|
|
143
|
+
get: function () {
|
|
144
|
+
return attachQuickJsProtocolEndpoint;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
//# sourceMappingURL=protocolEndpoint-DGOUVf6J.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocolEndpoint-DGOUVf6J.cjs","names":["activeAbortController: AbortController | undefined","activeExecutionId: string | undefined","runQuickJsSession"],"sources":["../../core/src/protocol/messages.ts","../src/runner/protocolEndpoint.ts"],"sourcesContent":["import type {\n ExecutorRuntimeOptions,\n ProviderManifest,\n ToolCall,\n ToolCallResult,\n} from \"../runner.ts\";\nimport type { ExecuteResult } from \"../types.ts\";\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} from \"@execbox/core/protocol\";\nimport type { ToolCallResult } from \"@execbox/core\";\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 \"../../../core/src/protocol/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,WAAW,YA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hB;GACE,KAAK;AACH,QAAI,QAAQ,OAAO,kBACjB,wBAAuB,OAAO;AAEhC;GACF,KAAK;AACH,IAAK,eAAe,QAAQ;AAC5B;GACF,KAAK,eAAe;IAClB,MAAM,UAAU,iBAAiB,IAAI,QAAQ,OAAO;AACpD,qBAAiB,OAAO,QAAQ,OAAO;AACvC,cAAU,QAAQ;AAClB;;;GAGJ;AAEF,cAAa;AACX,MAAI,OAAO,gBAAgB,WACzB,cAAa;AAEf,mBAAiB,OAAO;AACxB,yBAAuB,OAAO;AAC9B,0BAAwB;AACxB,sBAAoB"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { t as runQuickJsSession } from "./runner-CteKTaPD.js";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
|
|
4
|
+
//#region ../core/src/protocol/messages.ts
|
|
5
|
+
function isRecord(value) {
|
|
6
|
+
return typeof value === "object" && value !== null;
|
|
7
|
+
}
|
|
8
|
+
function isFiniteNumber(value) {
|
|
9
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
10
|
+
}
|
|
11
|
+
function isRuntimeOptions(value) {
|
|
12
|
+
if (!isRecord(value)) return false;
|
|
13
|
+
return isFiniteNumber(value.maxLogChars) && isFiniteNumber(value.maxLogLines) && isFiniteNumber(value.memoryLimitBytes) && isFiniteNumber(value.timeoutMs);
|
|
14
|
+
}
|
|
15
|
+
function isProviderManifest(value) {
|
|
16
|
+
if (!isRecord(value) || typeof value.name !== "string") return false;
|
|
17
|
+
if (!isRecord(value.tools) || typeof value.types !== "string") return false;
|
|
18
|
+
return Object.values(value.tools).every((tool) => isRecord(tool) && typeof tool.originalName === "string" && typeof tool.safeName === "string" && (tool.description === void 0 || typeof tool.description === "string"));
|
|
19
|
+
}
|
|
20
|
+
function isExecuteError(value) {
|
|
21
|
+
return isRecord(value) && typeof value.code === "string" && typeof value.message === "string";
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Returns whether an unknown value is a dispatcher-to-runner message.
|
|
25
|
+
*/
|
|
26
|
+
function isDispatcherMessage(value) {
|
|
27
|
+
if (!isRecord(value) || typeof value.type !== "string") return false;
|
|
28
|
+
switch (value.type) {
|
|
29
|
+
case "cancel": return typeof value.id === "string";
|
|
30
|
+
case "execute": return typeof value.code === "string" && typeof value.id === "string" && isRuntimeOptions(value.options) && Array.isArray(value.providers) && value.providers.every(isProviderManifest);
|
|
31
|
+
case "tool_result":
|
|
32
|
+
if (typeof value.callId !== "string" || typeof value.ok !== "boolean") return false;
|
|
33
|
+
if (value.ok) return "result" in value;
|
|
34
|
+
return isExecuteError(value.error);
|
|
35
|
+
default: return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/runner/protocolEndpoint.ts
|
|
41
|
+
/**
|
|
42
|
+
* @packageDocumentation
|
|
43
|
+
* Public API for the `@execbox/quickjs/runner/protocol-endpoint` entrypoint.
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* Attaches the shared QuickJS protocol loop to a worker/process messaging port.
|
|
47
|
+
*/
|
|
48
|
+
function attachQuickJsProtocolEndpoint(port) {
|
|
49
|
+
const pendingToolCalls = /* @__PURE__ */ new Map();
|
|
50
|
+
let activeAbortController;
|
|
51
|
+
let activeExecutionId;
|
|
52
|
+
async function startExecution(message) {
|
|
53
|
+
if (activeExecutionId) {
|
|
54
|
+
port.send({
|
|
55
|
+
durationMs: 0,
|
|
56
|
+
error: {
|
|
57
|
+
code: "internal_error",
|
|
58
|
+
message: "QuickJS endpoint already has an active execution"
|
|
59
|
+
},
|
|
60
|
+
id: message.id,
|
|
61
|
+
logs: [],
|
|
62
|
+
ok: false,
|
|
63
|
+
type: "done"
|
|
64
|
+
});
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const abortController = new AbortController();
|
|
68
|
+
activeAbortController = abortController;
|
|
69
|
+
activeExecutionId = message.id;
|
|
70
|
+
try {
|
|
71
|
+
const result = await runQuickJsSession({
|
|
72
|
+
abortController,
|
|
73
|
+
code: message.code,
|
|
74
|
+
onStarted: () => {
|
|
75
|
+
port.send({
|
|
76
|
+
id: message.id,
|
|
77
|
+
type: "started"
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
onToolCall: (call) => new Promise((resolve) => {
|
|
81
|
+
const callId = randomUUID();
|
|
82
|
+
pendingToolCalls.set(callId, resolve);
|
|
83
|
+
port.send({
|
|
84
|
+
...call,
|
|
85
|
+
callId,
|
|
86
|
+
type: "tool_call"
|
|
87
|
+
});
|
|
88
|
+
}),
|
|
89
|
+
providers: message.providers
|
|
90
|
+
}, message.options);
|
|
91
|
+
port.send({
|
|
92
|
+
...result,
|
|
93
|
+
id: message.id,
|
|
94
|
+
type: "done"
|
|
95
|
+
});
|
|
96
|
+
} catch (error) {
|
|
97
|
+
port.send({
|
|
98
|
+
durationMs: 0,
|
|
99
|
+
error: {
|
|
100
|
+
code: "internal_error",
|
|
101
|
+
message: error instanceof Error ? error.message : String(error)
|
|
102
|
+
},
|
|
103
|
+
id: message.id,
|
|
104
|
+
logs: [],
|
|
105
|
+
ok: false,
|
|
106
|
+
type: "done"
|
|
107
|
+
});
|
|
108
|
+
} finally {
|
|
109
|
+
pendingToolCalls.clear();
|
|
110
|
+
activeAbortController = void 0;
|
|
111
|
+
activeExecutionId = void 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const maybeDetach = port.onMessage((message) => {
|
|
115
|
+
if (!isDispatcherMessage(message)) return;
|
|
116
|
+
switch (message.type) {
|
|
117
|
+
case "cancel":
|
|
118
|
+
if (message.id === activeExecutionId) activeAbortController?.abort();
|
|
119
|
+
break;
|
|
120
|
+
case "execute":
|
|
121
|
+
startExecution(message);
|
|
122
|
+
break;
|
|
123
|
+
case "tool_result": {
|
|
124
|
+
const resolve = pendingToolCalls.get(message.callId);
|
|
125
|
+
pendingToolCalls.delete(message.callId);
|
|
126
|
+
resolve?.(message);
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
return () => {
|
|
132
|
+
if (typeof maybeDetach === "function") maybeDetach();
|
|
133
|
+
pendingToolCalls.clear();
|
|
134
|
+
activeAbortController?.abort();
|
|
135
|
+
activeAbortController = void 0;
|
|
136
|
+
activeExecutionId = void 0;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
//#endregion
|
|
141
|
+
export { attachQuickJsProtocolEndpoint as t };
|
|
142
|
+
//# sourceMappingURL=protocolEndpoint-T_JEz8YY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocolEndpoint-T_JEz8YY.js","names":["activeAbortController: AbortController | undefined","activeExecutionId: string | undefined"],"sources":["../../core/src/protocol/messages.ts","../src/runner/protocolEndpoint.ts"],"sourcesContent":["import type {\n ExecutorRuntimeOptions,\n ProviderManifest,\n ToolCall,\n ToolCallResult,\n} from \"../runner.ts\";\nimport type { ExecuteResult } from \"../types.ts\";\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} from \"@execbox/core/protocol\";\nimport type { ToolCallResult } from \"@execbox/core\";\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 \"../../../core/src/protocol/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,WAAW,YAAY,OAAO,MAAM,OAAO,UAC1D,QAAO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,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/runner/index.cjs
CHANGED
package/dist/runner/index.d.cts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* Public TypeScript declarations for this package entrypoint.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { a as QuickJsProcessExecutorOptions, i as QuickJsInlineExecutorOptions, n as QuickJsExecutorOptions, o as QuickJsWorkerExecutorOptions, r as QuickJsHostedMode, s as WorkerResourceLimits, t as QuickJsExecutorHost } from "../types-CnNmLawC.cjs";
|
|
6
6
|
import { ExecuteResult, ExecutorRuntimeOptions, ProviderManifest, ToolCall, ToolCallResult } from "@execbox/core";
|
|
7
7
|
import { QuickJSWASMModule } from "quickjs-emscripten";
|
|
8
8
|
|
|
@@ -16,17 +16,24 @@ type QuickJsSessionToolCall = ToolCall;
|
|
|
16
16
|
* Input required to run one transport-backed QuickJS execution session.
|
|
17
17
|
*/
|
|
18
18
|
interface QuickJsSessionRequest {
|
|
19
|
+
/** Optional abort controller that should be triggered when execution stops. */
|
|
19
20
|
abortController?: AbortController;
|
|
21
|
+
/** Guest JavaScript source to evaluate inside QuickJS. */
|
|
20
22
|
code: string;
|
|
23
|
+
/** Host callback used to fulfill guest tool calls. */
|
|
21
24
|
onToolCall: (call: ToolCall) => Promise<ToolCallResult> | ToolCallResult;
|
|
25
|
+
/** Optional hook invoked once the guest runtime has started. */
|
|
22
26
|
onStarted?: () => void;
|
|
27
|
+
/** Transport-safe provider manifests exposed to the guest runtime. */
|
|
23
28
|
providers: ProviderManifest[];
|
|
29
|
+
/** Optional caller-owned abort signal for the session. */
|
|
24
30
|
signal?: AbortSignal;
|
|
25
31
|
}
|
|
26
32
|
/**
|
|
27
33
|
* Options controlling one transport-backed QuickJS session.
|
|
28
34
|
*/
|
|
29
|
-
type QuickJsSessionOptions =
|
|
35
|
+
type QuickJsSessionOptions = ExecutorRuntimeOptions & Pick<QuickJsInlineExecutorOptions, "loadModule"> & {
|
|
36
|
+
/** Optional preloaded QuickJS WASM module instance. */
|
|
30
37
|
module?: QuickJSWASMModule;
|
|
31
38
|
};
|
|
32
39
|
/**
|
|
@@ -34,5 +41,5 @@ type QuickJsSessionOptions = QuickJsExecutorOptions & ExecutorRuntimeOptions & {
|
|
|
34
41
|
*/
|
|
35
42
|
declare function runQuickJsSession(request: QuickJsSessionRequest, options?: QuickJsSessionOptions): Promise<ExecuteResult>;
|
|
36
43
|
//#endregion
|
|
37
|
-
export { type QuickJsExecutorOptions, QuickJsSessionOptions, QuickJsSessionRequest, QuickJsSessionToolCall, runQuickJsSession };
|
|
44
|
+
export { type QuickJsExecutorHost, type QuickJsExecutorOptions, type QuickJsHostedMode, type QuickJsInlineExecutorOptions, type QuickJsProcessExecutorOptions, QuickJsSessionOptions, QuickJsSessionRequest, QuickJsSessionToolCall, type QuickJsWorkerExecutorOptions, type WorkerResourceLimits, runQuickJsSession };
|
|
38
45
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/runner/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/runner/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AA8DA,CAAA,CAAA,CAAA,SAAA,CAAA,OAAA,CAAA,IAAA,CAAA,IAAA,CAAA,IAAA,CAAA,OAAA,CAAA,IAAA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AA,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"}
|
package/dist/runner/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* Public TypeScript declarations for this package entrypoint.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { a as QuickJsProcessExecutorOptions, i as QuickJsInlineExecutorOptions, n as QuickJsExecutorOptions, o as QuickJsWorkerExecutorOptions, r as QuickJsHostedMode, s as WorkerResourceLimits, t as QuickJsExecutorHost } from "../types-BeVqrcj8.js";
|
|
6
6
|
import { QuickJSWASMModule } from "quickjs-emscripten";
|
|
7
7
|
import { ExecuteResult, ExecutorRuntimeOptions, ProviderManifest, ToolCall, ToolCallResult } from "@execbox/core";
|
|
8
8
|
|
|
@@ -16,17 +16,24 @@ type QuickJsSessionToolCall = ToolCall;
|
|
|
16
16
|
* Input required to run one transport-backed QuickJS execution session.
|
|
17
17
|
*/
|
|
18
18
|
interface QuickJsSessionRequest {
|
|
19
|
+
/** Optional abort controller that should be triggered when execution stops. */
|
|
19
20
|
abortController?: AbortController;
|
|
21
|
+
/** Guest JavaScript source to evaluate inside QuickJS. */
|
|
20
22
|
code: string;
|
|
23
|
+
/** Host callback used to fulfill guest tool calls. */
|
|
21
24
|
onToolCall: (call: ToolCall) => Promise<ToolCallResult> | ToolCallResult;
|
|
25
|
+
/** Optional hook invoked once the guest runtime has started. */
|
|
22
26
|
onStarted?: () => void;
|
|
27
|
+
/** Transport-safe provider manifests exposed to the guest runtime. */
|
|
23
28
|
providers: ProviderManifest[];
|
|
29
|
+
/** Optional caller-owned abort signal for the session. */
|
|
24
30
|
signal?: AbortSignal;
|
|
25
31
|
}
|
|
26
32
|
/**
|
|
27
33
|
* Options controlling one transport-backed QuickJS session.
|
|
28
34
|
*/
|
|
29
|
-
type QuickJsSessionOptions =
|
|
35
|
+
type QuickJsSessionOptions = ExecutorRuntimeOptions & Pick<QuickJsInlineExecutorOptions, "loadModule"> & {
|
|
36
|
+
/** Optional preloaded QuickJS WASM module instance. */
|
|
30
37
|
module?: QuickJSWASMModule;
|
|
31
38
|
};
|
|
32
39
|
/**
|
|
@@ -34,5 +41,5 @@ type QuickJsSessionOptions = QuickJsExecutorOptions & ExecutorRuntimeOptions & {
|
|
|
34
41
|
*/
|
|
35
42
|
declare function runQuickJsSession(request: QuickJsSessionRequest, options?: QuickJsSessionOptions): Promise<ExecuteResult>;
|
|
36
43
|
//#endregion
|
|
37
|
-
export { type QuickJsExecutorOptions, QuickJsSessionOptions, QuickJsSessionRequest, QuickJsSessionToolCall, runQuickJsSession };
|
|
44
|
+
export { type QuickJsExecutorHost, type QuickJsExecutorOptions, type QuickJsHostedMode, type QuickJsInlineExecutorOptions, type QuickJsProcessExecutorOptions, QuickJsSessionOptions, QuickJsSessionRequest, QuickJsSessionToolCall, type QuickJsWorkerExecutorOptions, type WorkerResourceLimits, runQuickJsSession };
|
|
38
45
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/runner/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/runner/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AA8DA,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,CA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