@animalabs/agent-framework 0.23.1 → 0.24.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 +212 -42
- package/dist/src/agent.d.ts +60 -9
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +92 -12
- package/dist/src/agent.js.map +1 -1
- package/dist/src/api/server.d.ts.map +1 -1
- package/dist/src/api/server.js +14 -12
- package/dist/src/api/server.js.map +1 -1
- package/dist/src/code-execution/engine.d.ts +177 -0
- package/dist/src/code-execution/engine.d.ts.map +1 -0
- package/dist/src/code-execution/engine.js +494 -0
- package/dist/src/code-execution/engine.js.map +1 -0
- package/dist/src/code-execution/index.d.ts +5 -10
- package/dist/src/code-execution/index.d.ts.map +1 -1
- package/dist/src/code-execution/index.js +5 -9
- package/dist/src/code-execution/index.js.map +1 -1
- package/dist/src/code-execution/isolate/calls.d.ts +114 -0
- package/dist/src/code-execution/isolate/calls.d.ts.map +1 -0
- package/dist/src/code-execution/isolate/calls.js +145 -0
- package/dist/src/code-execution/isolate/calls.js.map +1 -0
- package/dist/src/code-execution/isolate/child-entry.d.ts +2 -0
- package/dist/src/code-execution/isolate/child-entry.d.ts.map +1 -0
- package/dist/src/code-execution/isolate/child-entry.js +5 -0
- package/dist/src/code-execution/isolate/child-entry.js.map +1 -0
- package/dist/src/code-execution/isolate/child-main.d.ts +26 -0
- package/dist/src/code-execution/isolate/child-main.d.ts.map +1 -0
- package/dist/src/code-execution/isolate/child-main.js +132 -0
- package/dist/src/code-execution/isolate/child-main.js.map +1 -0
- package/dist/src/code-execution/isolate/child.d.ts +44 -0
- package/dist/src/code-execution/isolate/child.d.ts.map +1 -0
- package/dist/src/code-execution/isolate/child.js +315 -0
- package/dist/src/code-execution/isolate/child.js.map +1 -0
- package/dist/src/code-execution/isolate/frames.d.ts +80 -0
- package/dist/src/code-execution/isolate/frames.d.ts.map +1 -0
- package/dist/src/code-execution/isolate/frames.js +210 -0
- package/dist/src/code-execution/isolate/frames.js.map +1 -0
- package/dist/src/code-execution/isolate/output.d.ts +68 -0
- package/dist/src/code-execution/isolate/output.d.ts.map +1 -0
- package/dist/src/code-execution/isolate/output.js +143 -0
- package/dist/src/code-execution/isolate/output.js.map +1 -0
- package/dist/src/code-execution/isolate/prelude.d.ts +109 -0
- package/dist/src/code-execution/isolate/prelude.d.ts.map +1 -0
- package/dist/src/code-execution/isolate/prelude.js +401 -0
- package/dist/src/code-execution/isolate/prelude.js.map +1 -0
- package/dist/src/code-execution/isolate/protocol.d.ts +151 -0
- package/dist/src/code-execution/isolate/protocol.d.ts.map +1 -0
- package/dist/src/code-execution/isolate/protocol.js +150 -0
- package/dist/src/code-execution/isolate/protocol.js.map +1 -0
- package/dist/src/code-execution/isolate/render.d.ts +57 -0
- package/dist/src/code-execution/isolate/render.d.ts.map +1 -0
- package/dist/src/code-execution/isolate/render.js +214 -0
- package/dist/src/code-execution/isolate/render.js.map +1 -0
- package/dist/src/code-execution/isolate/runner.d.ts +250 -0
- package/dist/src/code-execution/isolate/runner.d.ts.map +1 -0
- package/dist/src/code-execution/isolate/runner.js +854 -0
- package/dist/src/code-execution/isolate/runner.js.map +1 -0
- package/dist/src/code-execution/isolate/scripts.d.ts +175 -0
- package/dist/src/code-execution/isolate/scripts.d.ts.map +1 -0
- package/dist/src/code-execution/isolate/scripts.js +357 -0
- package/dist/src/code-execution/isolate/scripts.js.map +1 -0
- package/dist/src/code-execution/quickjs.wasm +0 -0
- package/dist/src/code-execution/tool-definition.d.ts +93 -43
- package/dist/src/code-execution/tool-definition.d.ts.map +1 -1
- package/dist/src/code-execution/tool-definition.js +176 -142
- package/dist/src/code-execution/tool-definition.js.map +1 -1
- package/dist/src/deadline-timer.d.ts +3 -0
- package/dist/src/deadline-timer.d.ts.map +1 -1
- package/dist/src/deadline-timer.js +1 -1
- package/dist/src/deadline-timer.js.map +1 -1
- package/dist/src/framework.d.ts +1036 -440
- package/dist/src/framework.d.ts.map +1 -1
- package/dist/src/framework.js +4131 -2228
- package/dist/src/framework.js.map +1 -1
- package/dist/src/gate/event-gate.d.ts +28 -1
- package/dist/src/gate/event-gate.d.ts.map +1 -1
- package/dist/src/gate/event-gate.js +88 -10
- package/dist/src/gate/event-gate.js.map +1 -1
- package/dist/src/held-writes.d.ts +16 -3
- package/dist/src/held-writes.d.ts.map +1 -1
- package/dist/src/held-writes.js +16 -3
- package/dist/src/held-writes.js.map +1 -1
- package/dist/src/index.d.ts +6 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +9 -8
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcpl/channel-registry.d.ts +471 -75
- package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
- package/dist/src/mcpl/channel-registry.js +1673 -337
- package/dist/src/mcpl/channel-registry.js.map +1 -1
- package/dist/src/mcpl/conversation-router.d.ts +12 -7
- package/dist/src/mcpl/conversation-router.d.ts.map +1 -1
- package/dist/src/mcpl/conversation-router.js +12 -7
- package/dist/src/mcpl/conversation-router.js.map +1 -1
- package/dist/src/mcpl/convert-block.d.ts.map +1 -1
- package/dist/src/mcpl/convert-block.js +9 -5
- package/dist/src/mcpl/convert-block.js.map +1 -1
- package/dist/src/mcpl/inbound-source.d.ts +50 -0
- package/dist/src/mcpl/inbound-source.d.ts.map +1 -1
- package/dist/src/mcpl/inbound-source.js +130 -0
- package/dist/src/mcpl/inbound-source.js.map +1 -1
- package/dist/src/mcpl/index.d.ts +2 -1
- package/dist/src/mcpl/index.d.ts.map +1 -1
- package/dist/src/mcpl/index.js +3 -2
- package/dist/src/mcpl/index.js.map +1 -1
- package/dist/src/mcpl/log-value.d.ts +6 -0
- package/dist/src/mcpl/log-value.d.ts.map +1 -1
- package/dist/src/mcpl/log-value.js +8 -0
- package/dist/src/mcpl/log-value.js.map +1 -1
- package/dist/src/mcpl/modern-connection.d.ts +15 -6
- package/dist/src/mcpl/modern-connection.d.ts.map +1 -1
- package/dist/src/mcpl/modern-connection.js +168 -53
- package/dist/src/mcpl/modern-connection.js.map +1 -1
- package/dist/src/mcpl/prose-grammar.d.ts +4 -5
- package/dist/src/mcpl/prose-grammar.d.ts.map +1 -1
- package/dist/src/mcpl/prose-grammar.js +4 -5
- package/dist/src/mcpl/prose-grammar.js.map +1 -1
- package/dist/src/mcpl/protocol-family.d.ts +97 -10
- package/dist/src/mcpl/protocol-family.d.ts.map +1 -1
- package/dist/src/mcpl/protocol-family.js +173 -16
- package/dist/src/mcpl/protocol-family.js.map +1 -1
- package/dist/src/mcpl/push-coalescer.d.ts +132 -14
- package/dist/src/mcpl/push-coalescer.d.ts.map +1 -1
- package/dist/src/mcpl/push-coalescer.js +227 -50
- package/dist/src/mcpl/push-coalescer.js.map +1 -1
- package/dist/src/mcpl/push-handler.d.ts +6 -1
- package/dist/src/mcpl/push-handler.d.ts.map +1 -1
- package/dist/src/mcpl/push-handler.js +4 -1
- package/dist/src/mcpl/push-handler.js.map +1 -1
- package/dist/src/mcpl/reference-fetcher.d.ts +2 -2
- package/dist/src/mcpl/reference-fetcher.d.ts.map +1 -1
- package/dist/src/mcpl/reference-fetcher.js +4 -4
- package/dist/src/mcpl/reference-fetcher.js.map +1 -1
- package/dist/src/mcpl/server-connection.d.ts +50 -21
- package/dist/src/mcpl/server-connection.d.ts.map +1 -1
- package/dist/src/mcpl/server-connection.js +158 -74
- package/dist/src/mcpl/server-connection.js.map +1 -1
- package/dist/src/mcpl/tags.d.ts +24 -0
- package/dist/src/mcpl/tags.d.ts.map +1 -1
- package/dist/src/mcpl/tags.js +33 -0
- package/dist/src/mcpl/tags.js.map +1 -1
- package/dist/src/mcpl/tool-result-normalize.d.ts +2 -1
- package/dist/src/mcpl/tool-result-normalize.d.ts.map +1 -1
- package/dist/src/mcpl/tool-result-normalize.js.map +1 -1
- package/dist/src/mcpl/transport.d.ts +55 -7
- package/dist/src/mcpl/transport.d.ts.map +1 -1
- package/dist/src/mcpl/transport.js +163 -34
- package/dist/src/mcpl/transport.js.map +1 -1
- package/dist/src/mcpl/types.d.ts +22 -6
- package/dist/src/mcpl/types.d.ts.map +1 -1
- package/dist/src/mcpl/types.js.map +1 -1
- package/dist/src/module-registry.d.ts +4 -2
- package/dist/src/module-registry.d.ts.map +1 -1
- package/dist/src/module-registry.js +100 -13
- package/dist/src/module-registry.js.map +1 -1
- package/dist/src/modules/discord/index.d.ts.map +1 -1
- package/dist/src/modules/discord/index.js +8 -13
- package/dist/src/modules/discord/index.js.map +1 -1
- package/dist/src/modules/history/index.d.ts.map +1 -1
- package/dist/src/modules/history/index.js +27 -4
- package/dist/src/modules/history/index.js.map +1 -1
- package/dist/src/modules/history/semantic.d.ts +15 -3
- package/dist/src/modules/history/semantic.d.ts.map +1 -1
- package/dist/src/modules/history/semantic.js +27 -5
- package/dist/src/modules/history/semantic.js.map +1 -1
- package/dist/src/modules/index.d.ts +1 -1
- package/dist/src/modules/index.d.ts.map +1 -1
- package/dist/src/modules/index.js.map +1 -1
- package/dist/src/modules/unknown-tool.d.ts +4 -1
- package/dist/src/modules/unknown-tool.d.ts.map +1 -1
- package/dist/src/modules/unknown-tool.js +4 -1
- package/dist/src/modules/unknown-tool.js.map +1 -1
- package/dist/src/modules/workspace/branch-intent.d.ts +3 -1
- package/dist/src/modules/workspace/branch-intent.d.ts.map +1 -1
- package/dist/src/modules/workspace/branch-intent.js +3 -1
- package/dist/src/modules/workspace/branch-intent.js.map +1 -1
- package/dist/src/modules/workspace/edit-plan.d.ts +265 -0
- package/dist/src/modules/workspace/edit-plan.d.ts.map +1 -0
- package/dist/src/modules/workspace/edit-plan.js +794 -0
- package/dist/src/modules/workspace/edit-plan.js.map +1 -0
- package/dist/src/modules/workspace/edit-text.d.ts +117 -0
- package/dist/src/modules/workspace/edit-text.d.ts.map +1 -0
- package/dist/src/modules/workspace/edit-text.js +584 -0
- package/dist/src/modules/workspace/edit-text.js.map +1 -0
- package/dist/src/modules/workspace/effects.d.ts +5 -4
- package/dist/src/modules/workspace/effects.d.ts.map +1 -1
- package/dist/src/modules/workspace/effects.js +78 -25
- package/dist/src/modules/workspace/effects.js.map +1 -1
- package/dist/src/modules/workspace/index.d.ts +484 -61
- package/dist/src/modules/workspace/index.d.ts.map +1 -1
- package/dist/src/modules/workspace/index.js +2173 -645
- package/dist/src/modules/workspace/index.js.map +1 -1
- package/dist/src/modules/workspace/observe.d.ts +213 -38
- package/dist/src/modules/workspace/observe.d.ts.map +1 -1
- package/dist/src/modules/workspace/observe.js +416 -36
- package/dist/src/modules/workspace/observe.js.map +1 -1
- package/dist/src/modules/workspace/reconcile.d.ts.map +1 -1
- package/dist/src/modules/workspace/reconcile.js +15 -8
- package/dist/src/modules/workspace/reconcile.js.map +1 -1
- package/dist/src/modules/workspace/text.d.ts +32 -0
- package/dist/src/modules/workspace/text.d.ts.map +1 -0
- package/dist/src/modules/workspace/text.js +67 -0
- package/dist/src/modules/workspace/text.js.map +1 -0
- package/dist/src/modules/workspace/types.d.ts +210 -6
- package/dist/src/modules/workspace/types.d.ts.map +1 -1
- package/dist/src/modules/workspace/types.js.map +1 -1
- package/dist/src/modules/workspace/watcher.d.ts +3 -2
- package/dist/src/modules/workspace/watcher.d.ts.map +1 -1
- package/dist/src/modules/workspace/watcher.js.map +1 -1
- package/dist/src/operator-log.d.ts +52 -24
- package/dist/src/operator-log.d.ts.map +1 -1
- package/dist/src/operator-log.js.map +1 -1
- package/dist/src/recovery/discord-awareness-outbox.d.ts +496 -72
- package/dist/src/recovery/discord-awareness-outbox.d.ts.map +1 -1
- package/dist/src/recovery/discord-awareness-outbox.js +1196 -289
- package/dist/src/recovery/discord-awareness-outbox.js.map +1 -1
- package/dist/src/recovery/offline-branch.d.ts +26 -1
- package/dist/src/recovery/offline-branch.d.ts.map +1 -1
- package/dist/src/recovery/offline-branch.js +164 -39
- package/dist/src/recovery/offline-branch.js.map +1 -1
- package/dist/src/recovery/recover-cli.js +23 -4
- package/dist/src/recovery/recover-cli.js.map +1 -1
- package/dist/src/send-tools.d.ts +11 -0
- package/dist/src/send-tools.d.ts.map +1 -0
- package/dist/src/send-tools.js +11 -0
- package/dist/src/send-tools.js.map +1 -0
- package/dist/src/tool-result-guard.d.ts +4 -3
- package/dist/src/tool-result-guard.d.ts.map +1 -1
- package/dist/src/tool-result-guard.js +5 -4
- package/dist/src/tool-result-guard.js.map +1 -1
- package/dist/src/tool-result-history.d.ts +1 -1
- package/dist/src/tool-result-history.js +1 -1
- package/dist/src/tune-out/coordinator.d.ts +21 -0
- package/dist/src/tune-out/coordinator.d.ts.map +1 -1
- package/dist/src/tune-out/coordinator.js +139 -37
- package/dist/src/tune-out/coordinator.js.map +1 -1
- package/dist/src/types/agent.d.ts +4 -0
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/events.d.ts +62 -9
- package/dist/src/types/events.d.ts.map +1 -1
- package/dist/src/types/framework.d.ts +62 -58
- package/dist/src/types/framework.d.ts.map +1 -1
- package/dist/src/types/module.d.ts +40 -8
- package/dist/src/types/module.d.ts.map +1 -1
- package/dist/src/types/trace.d.ts +111 -10
- package/dist/src/types/trace.d.ts.map +1 -1
- package/dist/src/usage/types.d.ts +16 -0
- package/dist/src/usage/types.d.ts.map +1 -1
- package/dist/src/usage/usage-tracker.d.ts +14 -1
- package/dist/src/usage/usage-tracker.d.ts.map +1 -1
- package/dist/src/usage/usage-tracker.js +81 -41
- package/dist/src/usage/usage-tracker.js.map +1 -1
- package/package.json +6 -5
- package/src/agent.ts +93 -12
- package/src/api/server.ts +14 -12
- package/src/code-execution/engine.ts +595 -0
- package/src/code-execution/index.ts +5 -17
- package/src/code-execution/isolate/calls.ts +199 -0
- package/src/code-execution/isolate/child-entry.ts +5 -0
- package/src/code-execution/isolate/child-main.ts +132 -0
- package/src/code-execution/isolate/child.ts +327 -0
- package/src/code-execution/isolate/frames.ts +209 -0
- package/src/code-execution/isolate/output.ts +161 -0
- package/src/code-execution/isolate/prelude.ts +409 -0
- package/src/code-execution/isolate/protocol.ts +240 -0
- package/src/code-execution/isolate/render.ts +230 -0
- package/src/code-execution/isolate/runner.ts +911 -0
- package/src/code-execution/isolate/scripts.ts +479 -0
- package/src/code-execution/quickjs.wasm +0 -0
- package/src/code-execution/quickjs.wasm.LICENSES +149 -0
- package/src/code-execution/tool-definition.ts +236 -167
- package/src/deadline-timer.ts +1 -1
- package/src/framework.ts +4507 -2406
- package/src/gate/event-gate.ts +78 -11
- package/src/held-writes.ts +17 -3
- package/src/index.ts +30 -22
- package/src/mcpl/channel-registry.ts +1825 -368
- package/src/mcpl/conversation-router.ts +12 -7
- package/src/mcpl/convert-block.ts +9 -5
- package/src/mcpl/inbound-source.ts +131 -0
- package/src/mcpl/index.ts +4 -2
- package/src/mcpl/log-value.ts +9 -0
- package/src/mcpl/modern-connection.ts +162 -53
- package/src/mcpl/prose-grammar.ts +4 -5
- package/src/mcpl/protocol-family.ts +199 -21
- package/src/mcpl/push-coalescer.ts +306 -62
- package/src/mcpl/push-handler.ts +10 -2
- package/src/mcpl/reference-fetcher.ts +4 -4
- package/src/mcpl/server-connection.ts +180 -79
- package/src/mcpl/tags.ts +36 -0
- package/src/mcpl/tool-result-normalize.ts +2 -1
- package/src/mcpl/transport.ts +162 -33
- package/src/mcpl/types.ts +23 -6
- package/src/module-registry.ts +92 -13
- package/src/modules/discord/index.ts +8 -13
- package/src/modules/history/index.ts +25 -3
- package/src/modules/history/semantic.ts +29 -6
- package/src/modules/index.ts +1 -0
- package/src/modules/unknown-tool.ts +4 -1
- package/src/modules/workspace/branch-intent.ts +3 -1
- package/src/modules/workspace/edit-plan.ts +954 -0
- package/src/modules/workspace/edit-text.ts +618 -0
- package/src/modules/workspace/effects.ts +70 -19
- package/src/modules/workspace/index.ts +2247 -642
- package/src/modules/workspace/observe.ts +465 -56
- package/src/modules/workspace/reconcile.ts +14 -7
- package/src/modules/workspace/text.ts +68 -0
- package/src/modules/workspace/types.ts +211 -6
- package/src/modules/workspace/watcher.ts +3 -2
- package/src/operator-log.ts +47 -19
- package/src/recovery/discord-awareness-outbox.ts +1500 -356
- package/src/recovery/offline-branch.ts +189 -55
- package/src/recovery/recover-cli.ts +25 -4
- package/src/send-tools.ts +11 -0
- package/src/tool-result-guard.ts +6 -5
- package/src/tool-result-history.ts +1 -1
- package/src/tune-out/coordinator.ts +163 -42
- package/src/types/agent.ts +4 -0
- package/src/types/events.ts +62 -9
- package/src/types/framework.ts +62 -58
- package/src/types/module.ts +40 -8
- package/src/types/trace.ts +121 -15
- package/src/usage/types.ts +16 -0
- package/src/usage/usage-tracker.ts +86 -43
- package/dist/src/code-execution/py-runner.d.ts +0 -191
- package/dist/src/code-execution/py-runner.d.ts.map +0 -1
- package/dist/src/code-execution/py-runner.js +0 -655
- package/dist/src/code-execution/py-runner.js.map +0 -1
- package/dist/src/code-execution/runtime-py.d.ts +0 -50
- package/dist/src/code-execution/runtime-py.d.ts.map +0 -1
- package/dist/src/code-execution/runtime-py.js +0 -677
- package/dist/src/code-execution/runtime-py.js.map +0 -1
- package/dist/src/mcpl/prose-stream-router.d.ts +0 -88
- package/dist/src/mcpl/prose-stream-router.d.ts.map +0 -1
- package/dist/src/mcpl/prose-stream-router.js +0 -291
- package/dist/src/mcpl/prose-stream-router.js.map +0 -1
- package/src/code-execution/py-runner.ts +0 -791
- package/src/code-execution/runtime-py.ts +0 -677
- package/src/mcpl/prose-stream-router.ts +0 -268
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* code_execution's engine binding: QuickJS-ng compiled to WebAssembly (`quickjs.wasm`, built by
|
|
3
|
+
* `engine/build.sh` from the quickjs-ng release it pins and `engine/interface.c`), loaded into the child
|
|
4
|
+
* process that runs one script.
|
|
5
|
+
*
|
|
6
|
+
* The guest reaches nothing outside JavaScript except three of the slots the child fills: a host
|
|
7
|
+
* call, the interrupt check and output. The fourth, supervision, the guest can't reach: the engine
|
|
8
|
+
* calls it at each interrupt check. Only text crosses them: a tool's name and its arguments as
|
|
9
|
+
* JSON, output, and each result's JSON on the way back in. The module's memory is made here, with
|
|
10
|
+
* the maximum the child is given, so that maximum bounds everything the guest holds.
|
|
11
|
+
*/
|
|
12
|
+
import { readFile } from 'node:fs/promises';
|
|
13
|
+
import { randomFillSync } from 'node:crypto';
|
|
14
|
+
/** The engine failed, rather than the script: a slot threw, the engine crashed, or it was misused. */
|
|
15
|
+
export class EngineError extends Error {
|
|
16
|
+
constructor(message, options) {
|
|
17
|
+
super(message, options);
|
|
18
|
+
this.name = 'EngineError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const PAGE = 65536;
|
|
22
|
+
/** The link-time stack, at the start of linear memory (engine/build.sh). */
|
|
23
|
+
const LINK_STACK_BYTES = 1024 * 1024;
|
|
24
|
+
export const MIN_MEMORY_BYTES = 4 * 1024 * 1024;
|
|
25
|
+
/**
|
|
26
|
+
* 2 GiB, so that every address in linear memory fits the signed 32-bit numbers the module's
|
|
27
|
+
* pointers arrive as, and no conversion is needed where the host reads them.
|
|
28
|
+
*/
|
|
29
|
+
export const MAX_MEMORY_BYTES = 2048 * 1024 * 1024;
|
|
30
|
+
/**
|
|
31
|
+
* The most QuickJS's stack limit may be, and its default. QuickJS measures its stack in the
|
|
32
|
+
* module's linear memory, but each level of a script's recursion through calls also takes the
|
|
33
|
+
* host's own stack, two to three times as much in the 31 ways to recurse that were measured, and
|
|
34
|
+
* under Node that stack is about 984 KiB. Recursing through a getter, a proxy trap or a built-in
|
|
35
|
+
* that calls back (map, toString, for...of), the host's stack ran out first, crashing the engine,
|
|
36
|
+
* once QuickJS's limit passed about 320 KiB. At this limit, QuickJS's catchable RangeError comes
|
|
37
|
+
* first in each of the 31, with about two fifths of the host's stack to spare. Bun's stack is
|
|
38
|
+
* larger, and the same limit holds there, so recursion through calls ends the same way on either.
|
|
39
|
+
*
|
|
40
|
+
* Recursion in C that the check barely sees isn't held to it, and under Node crashes the run, the
|
|
41
|
+
* host's stack running out: a script's text nesting function expressions 300 deep or brackets 700
|
|
42
|
+
* deep (the parser), a chain of 3,000 iterator helpers, and the script's own data nested about
|
|
43
|
+
* 5,000 deep in JSON.stringify (4,000 with V8's optimizing tier alone), as a call's arguments
|
|
44
|
+
* are, or about 8,000 deep in JSON.parse (5,000; see MAX_RESULT_DEPTH). Under Bun, whose stack
|
|
45
|
+
* is larger, QuickJS's check ends JSON's recursion first, with a RangeError the script can catch,
|
|
46
|
+
* from about 15,000 deep, though a parse nested 22,000 deep still runs Bun's stack out. Each
|
|
47
|
+
* iterator helper's next calls the one before directly, past QuickJS's checks, so under Bun a
|
|
48
|
+
* chain of 30,000 runs the module's own 1 MiB stack out instead, and the module traps: the stack
|
|
49
|
+
* sits first in its memory, so an overflow wraps below address 0 to past the memory's end.
|
|
50
|
+
*/
|
|
51
|
+
export const MAX_STACK_BYTES = 192 * 1024;
|
|
52
|
+
export const DEFAULT_STACK_BYTES = MAX_STACK_BYTES;
|
|
53
|
+
/**
|
|
54
|
+
* The deepest nesting of arrays and objects a result may have. QuickJS's stack check measures the
|
|
55
|
+
* module's own stack, which the C recursion of JSON's parse and stringify barely uses, so under
|
|
56
|
+
* Node a parse nested about 8,000 deep (5,000 with V8's optimizing tier alone) overflows the
|
|
57
|
+
* host's stack first, and the engine crashes (under Bun, QuickJS's check comes first). A deeper
|
|
58
|
+
* result is unfit, since the call took effect. A script's own data isn't held to this, and nested
|
|
59
|
+
* thousands deep, it can crash its own run (see MAX_STACK_BYTES).
|
|
60
|
+
*/
|
|
61
|
+
export const MAX_RESULT_DEPTH = 2000;
|
|
62
|
+
/** The most of the engine's own stdio a crash's message keeps. */
|
|
63
|
+
const DIAGNOSTICS_CHARS = 4096;
|
|
64
|
+
/**
|
|
65
|
+
* The longest ending text the binding decodes, in UTF-8 bytes: V8's longest string, 2^29 - 24
|
|
66
|
+
* characters (Node's `buffer.constants.MAX_STRING_LENGTH`), which a text of this many bytes can't
|
|
67
|
+
* exceed. Node can't decode a longer one. Bun's longest string is 2^31 - 1, and the same bound
|
|
68
|
+
* holds there, so a script ends the same way on either. A longer text is answered with a
|
|
69
|
+
* RangeError that gives its length: `rejected` for the script's own ending, its value's or what it
|
|
70
|
+
* threw, and `failed` for an exception that ended the run.
|
|
71
|
+
*/
|
|
72
|
+
const MAX_ENDING_BYTES = 2 ** 29 - 24;
|
|
73
|
+
// interface.c's states and failures.
|
|
74
|
+
const PENDING = 0, FULFILLED = 1, REJECTED = 2, INTERRUPTED = 3, HOST_FAILED = 4, FAILED = 5;
|
|
75
|
+
const UNFIT = 16, DROPPED = 32;
|
|
76
|
+
const MISUSE = -1, NO_MEMORY = -2, UNKNOWN_CALL = -3;
|
|
77
|
+
const Wasm = globalThis.WebAssembly;
|
|
78
|
+
let compiled;
|
|
79
|
+
/** The committed module, compiled once per process. */
|
|
80
|
+
function engineModule() {
|
|
81
|
+
compiled ??= readFile(new URL('./quickjs.wasm', import.meta.url)).then((bytes) => Wasm.compile(bytes));
|
|
82
|
+
return compiled;
|
|
83
|
+
}
|
|
84
|
+
/** Whether JSON text nests arrays and objects deeper than `limit`. */
|
|
85
|
+
function nestsDeeper(json, limit) {
|
|
86
|
+
// The characters that count are ASCII, so UTF-8 bytes and UTF-16 code units read alike.
|
|
87
|
+
const at = typeof json === 'string' ? (i) => json.charCodeAt(i) : (i) => json[i];
|
|
88
|
+
let depth = 0, inString = false;
|
|
89
|
+
for (let i = 0; i < json.length; i++) {
|
|
90
|
+
const c = at(i);
|
|
91
|
+
if (inString) {
|
|
92
|
+
if (c === 0x5c)
|
|
93
|
+
i++; // a backslash escapes the next character
|
|
94
|
+
else if (c === 0x22)
|
|
95
|
+
inString = false;
|
|
96
|
+
}
|
|
97
|
+
else if (c === 0x22) {
|
|
98
|
+
inString = true;
|
|
99
|
+
}
|
|
100
|
+
else if (c === 0x5b || c === 0x7b) {
|
|
101
|
+
if (++depth > limit)
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
else if (c === 0x5d || c === 0x7d) {
|
|
105
|
+
depth--;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
/** QuickJS's allocation limit for a given linear maximum: the stack and data, then a margin. */
|
|
111
|
+
function quickjsMemoryLimit(memoryMaxBytes) {
|
|
112
|
+
return memoryMaxBytes - LINK_STACK_BYTES - 1024 * 1024 - Math.floor(memoryMaxBytes / 32);
|
|
113
|
+
}
|
|
114
|
+
/** Instantiates the committed module with these limits and slots. One instance per child. */
|
|
115
|
+
export async function loadEngine(limits, slots) {
|
|
116
|
+
const { memoryMaxBytes } = limits;
|
|
117
|
+
const stackBytes = limits.maxStackBytes ?? DEFAULT_STACK_BYTES;
|
|
118
|
+
if (!Number.isSafeInteger(memoryMaxBytes) || memoryMaxBytes % PAGE !== 0 ||
|
|
119
|
+
memoryMaxBytes < MIN_MEMORY_BYTES || memoryMaxBytes > MAX_MEMORY_BYTES) {
|
|
120
|
+
throw new RangeError(`memoryMaxBytes must be a whole number of 64 KiB pages from ${MIN_MEMORY_BYTES} to ${MAX_MEMORY_BYTES}, not ${memoryMaxBytes}`);
|
|
121
|
+
}
|
|
122
|
+
if (!Number.isSafeInteger(stackBytes) || stackBytes < 16 * 1024 || stackBytes > MAX_STACK_BYTES) {
|
|
123
|
+
throw new RangeError(`maxStackBytes must be from 16384 to ${MAX_STACK_BYTES}, not ${stackBytes}`);
|
|
124
|
+
}
|
|
125
|
+
const memory = new Wasm.Memory({ initial: Math.ceil((LINK_STACK_BYTES + 2 * PAGE) / PAGE), maximum: memoryMaxBytes / PAGE });
|
|
126
|
+
// ignoreBOM, so text that starts with U+FEFF keeps it.
|
|
127
|
+
const decoder = new TextDecoder('utf-8', { ignoreBOM: true });
|
|
128
|
+
const encoder = new TextEncoder();
|
|
129
|
+
/** Whether a slot threw, and what: a slot may throw anything, undefined included. */
|
|
130
|
+
let slotFailed = false;
|
|
131
|
+
let slotError;
|
|
132
|
+
let broken;
|
|
133
|
+
/** What the engine wrote before it crashed. */
|
|
134
|
+
let diagnostics = '';
|
|
135
|
+
/** A call into the module is in progress, so a slot is the only thing that can call again. */
|
|
136
|
+
let busy = false;
|
|
137
|
+
/** interrupt() has returned true: the guest is stopped for good. */
|
|
138
|
+
let stopped = false;
|
|
139
|
+
/** The module trapped, so its state may be anything, and it isn't called again. */
|
|
140
|
+
let crashed = false;
|
|
141
|
+
/**
|
|
142
|
+
* A view of the module's memory. A corrupted guest could pass any pointer, and the view's own
|
|
143
|
+
* bounds check throws a RangeError for one outside the memory, which ends the run as a slot's
|
|
144
|
+
* failure. Made at each read, since a growing memory replaces its buffer.
|
|
145
|
+
*/
|
|
146
|
+
const bytes = (ptr, len) => new Uint8Array(memory.buffer, ptr, len);
|
|
147
|
+
const text = (ptr, len) => decoder.decode(bytes(ptr, len));
|
|
148
|
+
/** Runs a slot. A throw is kept, and the engine told the slot failed. */
|
|
149
|
+
const guard = (fn) => {
|
|
150
|
+
if (slotFailed)
|
|
151
|
+
return 1;
|
|
152
|
+
try {
|
|
153
|
+
fn();
|
|
154
|
+
return 0;
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
slotFailed = true;
|
|
158
|
+
slotError = err;
|
|
159
|
+
return 1;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const EBADF = 8, EINVAL = 28, ESPIPE = 70;
|
|
163
|
+
const env = {
|
|
164
|
+
memory,
|
|
165
|
+
host_call: (id, name, nameLen, args, argsLen) => guard(() => slots.hostCall(id >>> 0, text(name, nameLen), text(args, argsLen))),
|
|
166
|
+
// Once a slot has failed, this stops the guest at its next check.
|
|
167
|
+
host_interrupt: () => {
|
|
168
|
+
if (slotFailed)
|
|
169
|
+
return 1;
|
|
170
|
+
try {
|
|
171
|
+
if (!slots.interrupt())
|
|
172
|
+
return 0;
|
|
173
|
+
stopped = true;
|
|
174
|
+
return 1;
|
|
175
|
+
}
|
|
176
|
+
catch (err) {
|
|
177
|
+
slotFailed = true;
|
|
178
|
+
slotError = err;
|
|
179
|
+
return 1;
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
host_output: (stream, ptr, len) => guard(() => slots.output(stream === 2 ? 2 : 1, text(ptr, len))),
|
|
183
|
+
// Not an ordinary slot: a slot's failure doesn't end it, so a guest that keeps its stop from
|
|
184
|
+
// landing is still watched.
|
|
185
|
+
host_supervise: () => {
|
|
186
|
+
try {
|
|
187
|
+
slots.supervise();
|
|
188
|
+
}
|
|
189
|
+
catch (err) {
|
|
190
|
+
if (!slotFailed) {
|
|
191
|
+
slotFailed = true;
|
|
192
|
+
slotError = err;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
// The few WASI calls libc makes: the clocks (the real-time one for Date.now and the seed QuickJS
|
|
198
|
+
// gives Math.random, the monotonic one for performance.now), four random bytes libc asks for
|
|
199
|
+
// once as the module loads, and stdio, which only the engine's own diagnostics reach (an
|
|
200
|
+
// assertion's message before it traps).
|
|
201
|
+
const wasi = {
|
|
202
|
+
clock_time_get: (id, _precision, out) => {
|
|
203
|
+
let ns;
|
|
204
|
+
if (id === 0)
|
|
205
|
+
ns = BigInt(Date.now()) * 1000000n;
|
|
206
|
+
else if (id >= 1 && id <= 3)
|
|
207
|
+
ns = process.hrtime.bigint();
|
|
208
|
+
else
|
|
209
|
+
return EINVAL;
|
|
210
|
+
new DataView(memory.buffer).setBigUint64(bytes(out, 8).byteOffset, ns, true);
|
|
211
|
+
return 0;
|
|
212
|
+
},
|
|
213
|
+
random_get: (ptr, len) => {
|
|
214
|
+
randomFillSync(bytes(ptr, len));
|
|
215
|
+
return 0;
|
|
216
|
+
},
|
|
217
|
+
fd_write: (fd, iovs, iovsLen, written) => {
|
|
218
|
+
if (fd !== 1 && fd !== 2)
|
|
219
|
+
return EBADF;
|
|
220
|
+
const view = new DataView(memory.buffer);
|
|
221
|
+
let total = 0;
|
|
222
|
+
for (let i = 0; i < iovsLen; i++) {
|
|
223
|
+
const base = view.getUint32(bytes(iovs + i * 8, 8).byteOffset, true);
|
|
224
|
+
const len = view.getUint32(iovs + i * 8 + 4, true);
|
|
225
|
+
// Kept to DIAGNOSTICS_CHARS in all, clipped before decoding: each byte is at most a char.
|
|
226
|
+
const room = DIAGNOSTICS_CHARS - diagnostics.length;
|
|
227
|
+
if (room > 0)
|
|
228
|
+
diagnostics += text(base, Math.min(len, room));
|
|
229
|
+
total += len;
|
|
230
|
+
}
|
|
231
|
+
view.setUint32(bytes(written, 4).byteOffset, total, true);
|
|
232
|
+
return 0;
|
|
233
|
+
},
|
|
234
|
+
fd_fdstat_get: (fd, out) => {
|
|
235
|
+
if (fd !== 1 && fd !== 2)
|
|
236
|
+
return EBADF;
|
|
237
|
+
const b = bytes(out, 24);
|
|
238
|
+
b.fill(0);
|
|
239
|
+
b[0] = 2; // a character device, so stdio writes unbuffered lines
|
|
240
|
+
return 0;
|
|
241
|
+
},
|
|
242
|
+
fd_seek: (fd) => (fd === 1 || fd === 2 ? ESPIPE : EBADF),
|
|
243
|
+
fd_close: () => EBADF,
|
|
244
|
+
};
|
|
245
|
+
const instance = await Wasm.instantiate(await engineModule(), { env, wasi_snapshot_preview1: wasi });
|
|
246
|
+
const ex = instance.exports;
|
|
247
|
+
/**
|
|
248
|
+
* Calls into the module. A trap leaves the engine broken, and every later call throws its error.
|
|
249
|
+
* One made from inside a slot, while another is in progress, is refused: the two would share the
|
|
250
|
+
* module's state.
|
|
251
|
+
*/
|
|
252
|
+
const call = (what, fn) => {
|
|
253
|
+
if (broken)
|
|
254
|
+
throw broken;
|
|
255
|
+
if (busy)
|
|
256
|
+
throw new EngineError(`${what} was called from inside one of the engine's slots, which may not call back into it`);
|
|
257
|
+
busy = true;
|
|
258
|
+
let out;
|
|
259
|
+
try {
|
|
260
|
+
out = fn();
|
|
261
|
+
}
|
|
262
|
+
catch (err) {
|
|
263
|
+
if (err instanceof EngineError)
|
|
264
|
+
throw err;
|
|
265
|
+
// A trap, or an exception in reading what the module returned, which it only throws when the
|
|
266
|
+
// module returned something it couldn't have made whole: either way the module can't be
|
|
267
|
+
// taken as whole, so dispose() leaves it as it is.
|
|
268
|
+
crashed = true;
|
|
269
|
+
// A slot that failed first is why: the guest ran on, refused, until the module trapped.
|
|
270
|
+
if (slotFailed)
|
|
271
|
+
return slotFailure(what);
|
|
272
|
+
const why = diagnostics.trim();
|
|
273
|
+
broken = new EngineError(`the engine crashed in ${what}: ${describe(err)}${why ? ` (${why})` : ''}`, { cause: err });
|
|
274
|
+
throw broken;
|
|
275
|
+
}
|
|
276
|
+
finally {
|
|
277
|
+
busy = false;
|
|
278
|
+
}
|
|
279
|
+
return out;
|
|
280
|
+
};
|
|
281
|
+
/** A thrown value as text, for a message: it may have no string form, or one that throws. */
|
|
282
|
+
const describe = (err) => {
|
|
283
|
+
try {
|
|
284
|
+
return String(err instanceof Error ? err.message : err);
|
|
285
|
+
}
|
|
286
|
+
catch {
|
|
287
|
+
return 'a value with no string form';
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
/** Copies text, or UTF-8 bytes, into the module with the NUL its C expects. The caller frees it, or hands it to engine_settle, which does. */
|
|
291
|
+
const put = (value) => {
|
|
292
|
+
const len = typeof value === 'string' ? Buffer.byteLength(value, 'utf8') : value.length;
|
|
293
|
+
const ptr = ex.engine_alloc(len + 1);
|
|
294
|
+
if (ptr === 0)
|
|
295
|
+
return { ptr: 0, len };
|
|
296
|
+
const dst = new Uint8Array(memory.buffer, ptr, len + 1);
|
|
297
|
+
if (typeof value === 'string')
|
|
298
|
+
encoder.encodeInto(value, dst);
|
|
299
|
+
else
|
|
300
|
+
dst.set(value);
|
|
301
|
+
dst[len] = 0;
|
|
302
|
+
return { ptr, len };
|
|
303
|
+
};
|
|
304
|
+
/** The ending's text, or its length alone when it's too long to decode, or nothing when the module couldn't make it. */
|
|
305
|
+
const result = () => {
|
|
306
|
+
const ptr = ex.engine_result();
|
|
307
|
+
if (ptr === 0)
|
|
308
|
+
return undefined;
|
|
309
|
+
const view = new DataView(memory.buffer);
|
|
310
|
+
const kind = view.getUint32(ptr, true);
|
|
311
|
+
const len = view.getUint32(ptr + 4, true);
|
|
312
|
+
if (len > MAX_ENDING_BYTES) {
|
|
313
|
+
ex.engine_free(ptr);
|
|
314
|
+
return { kind, tooLong: len };
|
|
315
|
+
}
|
|
316
|
+
const out = decoder.decode(new Uint8Array(memory.buffer, ptr + 8, len));
|
|
317
|
+
ex.engine_free(ptr);
|
|
318
|
+
return { kind, text: out };
|
|
319
|
+
};
|
|
320
|
+
const errorState = (json, kind) => {
|
|
321
|
+
const e = JSON.parse(json);
|
|
322
|
+
const state = { kind, name: e.name ?? '', message: e.message ?? '' };
|
|
323
|
+
if (typeof e.stack === 'string')
|
|
324
|
+
state.stack = e.stack;
|
|
325
|
+
return state;
|
|
326
|
+
};
|
|
327
|
+
/** What an ending that can't be read out is answered with, by what it is. */
|
|
328
|
+
const unread = {
|
|
329
|
+
[FULFILLED]: {
|
|
330
|
+
memory: 'out of memory while serializing the script\'s return value; return less, or let go of data the script no longer needs',
|
|
331
|
+
long: (n) => `the script's return value comes to ${n} bytes as text, more than the ${MAX_ENDING_BYTES} the engine reads back; return less`,
|
|
332
|
+
},
|
|
333
|
+
[REJECTED]: {
|
|
334
|
+
memory: 'out of memory while reading what the script threw; throw something smaller, such as an Error with a shorter message, or let go of data the script no longer needs',
|
|
335
|
+
long: (n) => `what the script threw comes to ${n} bytes as text, more than the ${MAX_ENDING_BYTES} the engine reads back; throw something smaller`,
|
|
336
|
+
},
|
|
337
|
+
[FAILED]: {
|
|
338
|
+
memory: 'out of memory while reading the exception that ended the run; let go of data the script no longer needs, and if a callback given to queueMicrotask or a FinalizationRegistry threw it, throw something smaller or catch it there',
|
|
339
|
+
long: (n) => `the exception that ended the run comes to ${n} bytes as text, more than the ${MAX_ENDING_BYTES} the engine reads back; if a callback given to queueMicrotask or a FinalizationRegistry threw it, throw something smaller or catch it there`,
|
|
340
|
+
},
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* Each ending as it was first read. Reading one serializes the script's value or error in the
|
|
344
|
+
* guest, which can run the script's own code (a toJSON, a getter), and every settle after the
|
|
345
|
+
* script has ended answers that ending again: read once, that code runs once.
|
|
346
|
+
*/
|
|
347
|
+
const endings = new Map();
|
|
348
|
+
/** The run ended because a slot threw. */
|
|
349
|
+
const slotFailure = (what) => {
|
|
350
|
+
broken = new EngineError(`a slot threw during ${what}: ${describe(slotError)}`, { cause: slotError });
|
|
351
|
+
throw broken;
|
|
352
|
+
};
|
|
353
|
+
/** Reads a state code into a RunState, or throws for the engine's own failures. */
|
|
354
|
+
const toState = (code, what) => {
|
|
355
|
+
switch (code) {
|
|
356
|
+
case PENDING:
|
|
357
|
+
return { kind: 'pending' };
|
|
358
|
+
case INTERRUPTED:
|
|
359
|
+
// A slot's failure stops the guest through the interrupt, so this can be that failure.
|
|
360
|
+
if (slotFailed)
|
|
361
|
+
return slotFailure(what);
|
|
362
|
+
return { kind: 'interrupted' };
|
|
363
|
+
case FULFILLED:
|
|
364
|
+
case REJECTED:
|
|
365
|
+
case FAILED: {
|
|
366
|
+
// Each kept under its own code, so a failure after the script's own ending is read anew.
|
|
367
|
+
const known = endings.get(code);
|
|
368
|
+
if (known)
|
|
369
|
+
return { ...known };
|
|
370
|
+
const r = result();
|
|
371
|
+
// Reading runs the interrupt slot, which can throw, or stop the guest. A stop that lands
|
|
372
|
+
// while the script's own ending is read leaves none to give (the module returns nothing),
|
|
373
|
+
// so this call answers as any call does in which that happens. One that lands in the jobs
|
|
374
|
+
// the read queued comes after a whole ending, which this call answers. An exception
|
|
375
|
+
// escaping those jobs ends the run after its ending, and is what this call answers. An
|
|
376
|
+
// exception that ended the run is read with the parts a stop cut off left out.
|
|
377
|
+
if (slotFailed)
|
|
378
|
+
return slotFailure(what);
|
|
379
|
+
if (code !== FAILED) {
|
|
380
|
+
if (ex.engine_state() === FAILED)
|
|
381
|
+
return toState(FAILED, what);
|
|
382
|
+
if (!r && stopped)
|
|
383
|
+
return { kind: 'interrupted' };
|
|
384
|
+
}
|
|
385
|
+
const kind = code === FAILED ? 'failed' : 'rejected';
|
|
386
|
+
const state = !r ? { kind, name: 'InternalError', message: unread[code].memory }
|
|
387
|
+
: 'tooLong' in r ? { kind, name: 'RangeError', message: unread[code].long(r.tooLong) }
|
|
388
|
+
: r.kind === 0 ? { kind: 'fulfilled', json: undefined }
|
|
389
|
+
: r.kind === 1 ? { kind: 'fulfilled', json: r.text }
|
|
390
|
+
: errorState(r.text, kind);
|
|
391
|
+
endings.set(code, state);
|
|
392
|
+
return { ...state };
|
|
393
|
+
}
|
|
394
|
+
case HOST_FAILED:
|
|
395
|
+
return slotFailure(what);
|
|
396
|
+
case UNKNOWN_CALL:
|
|
397
|
+
throw new EngineError(`${what}: no pending call with that id`);
|
|
398
|
+
case NO_MEMORY:
|
|
399
|
+
broken = new EngineError(`${what}: the engine ran out of memory for its own state`);
|
|
400
|
+
throw broken;
|
|
401
|
+
case MISUSE:
|
|
402
|
+
default:
|
|
403
|
+
throw new EngineError(`${what}: the engine refused the call (${code})`);
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
call('initialization', () => ex._initialize());
|
|
407
|
+
const init = call('initialization', () => ex.engine_init(quickjsMemoryLimit(memoryMaxBytes), stackBytes));
|
|
408
|
+
if (init !== 0)
|
|
409
|
+
throw new EngineError(`the engine couldn't initialize (${init})`);
|
|
410
|
+
let started = false;
|
|
411
|
+
let disposed = false;
|
|
412
|
+
const live = (what) => {
|
|
413
|
+
if (disposed)
|
|
414
|
+
throw new EngineError(`${what} after dispose()`);
|
|
415
|
+
};
|
|
416
|
+
return {
|
|
417
|
+
start(prelude, script, filename) {
|
|
418
|
+
live('start()');
|
|
419
|
+
if (broken)
|
|
420
|
+
throw broken;
|
|
421
|
+
if (started)
|
|
422
|
+
throw new EngineError('start() was already called');
|
|
423
|
+
started = true;
|
|
424
|
+
return call('start()', () => {
|
|
425
|
+
const p = put(prelude), s = put(script), f = put(filename);
|
|
426
|
+
try {
|
|
427
|
+
if (!p.ptr || !s.ptr || !f.ptr)
|
|
428
|
+
return { kind: 'rejected', name: 'InternalError', message: 'out of memory while loading the script' };
|
|
429
|
+
return toState(ex.engine_start(p.ptr, p.len, s.ptr, s.len, f.ptr), 'start()');
|
|
430
|
+
}
|
|
431
|
+
finally {
|
|
432
|
+
for (const b of [p, s, f])
|
|
433
|
+
if (b.ptr)
|
|
434
|
+
ex.engine_free(b.ptr);
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
},
|
|
438
|
+
settle(callId, ok, json, unfitJson) {
|
|
439
|
+
live('settle()');
|
|
440
|
+
if (broken)
|
|
441
|
+
throw broken;
|
|
442
|
+
if (!started)
|
|
443
|
+
throw new EngineError('settle() before start()');
|
|
444
|
+
if (callId >>> 0 !== callId)
|
|
445
|
+
throw new EngineError(`settle(): ${callId} isn't a call id`);
|
|
446
|
+
return call('settle()', () => {
|
|
447
|
+
// The small error first, so a result that takes the last of the memory leaves it room,
|
|
448
|
+
// and once more if refused: the refusal opens the allocator's headroom, which it fits in.
|
|
449
|
+
// A copy the module can't make room for goes as a null pointer, and so does a result
|
|
450
|
+
// nested too deeply to parse. The module frees both copies, each as soon as it's parsed.
|
|
451
|
+
let u = put(unfitJson);
|
|
452
|
+
if (!u.ptr)
|
|
453
|
+
u = put(unfitJson);
|
|
454
|
+
const j = nestsDeeper(json, MAX_RESULT_DEPTH) ? { ptr: 0, len: 0 } : put(json);
|
|
455
|
+
const code = ex.engine_settle(callId, ok ? 1 : 0, j.ptr, j.len, u.ptr, u.len);
|
|
456
|
+
if (code < 0)
|
|
457
|
+
return toState(code, 'settle()');
|
|
458
|
+
const state = toState(code & ~(UNFIT | DROPPED), 'settle()');
|
|
459
|
+
if (code & UNFIT)
|
|
460
|
+
state.unfit = true;
|
|
461
|
+
if (code & DROPPED)
|
|
462
|
+
state.dropped = true;
|
|
463
|
+
return state;
|
|
464
|
+
});
|
|
465
|
+
},
|
|
466
|
+
dispose() {
|
|
467
|
+
if (disposed)
|
|
468
|
+
return;
|
|
469
|
+
// Refused from inside a slot, it isn't marked done, so it can be made again.
|
|
470
|
+
if (busy)
|
|
471
|
+
throw new EngineError('dispose() was called from inside one of the engine\'s slots, which may not call back into it');
|
|
472
|
+
// A module whose call ended in an exception, a trap or otherwise, may have stopped anywhere,
|
|
473
|
+
// so it's left as it is. One that ended for a slot's failure, or for want of memory for its
|
|
474
|
+
// own state, is whole, and frees its runtime.
|
|
475
|
+
if (!crashed) {
|
|
476
|
+
busy = true;
|
|
477
|
+
try {
|
|
478
|
+
ex.engine_dispose();
|
|
479
|
+
}
|
|
480
|
+
catch (err) {
|
|
481
|
+
crashed = true;
|
|
482
|
+
disposed = true;
|
|
483
|
+
broken = new EngineError(`the engine crashed in dispose(): ${describe(err)}`, { cause: err });
|
|
484
|
+
throw broken;
|
|
485
|
+
}
|
|
486
|
+
finally {
|
|
487
|
+
busy = false;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
disposed = true;
|
|
491
|
+
},
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../../src/code-execution/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAqH7C,sGAAsG;AACtG,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED,MAAM,IAAI,GAAG,KAAK,CAAC;AACnB,4EAA4E;AAC5E,MAAM,gBAAgB,GAAG,IAAI,GAAG,IAAI,CAAC;AACrC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAChD;;;GAG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,IAAI,IAAI,GAAG,KAAK;oBAAE,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC;gBACrC,IAAI,IAAI,GAAG,OAAO;oBAAE,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;gBACzC,OAAO,KAAK,CAAC;YACf,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO;YACL,IAAI,QAAQ;gBAAE,OAAO;YACrB,6EAA6E;YAC7E,IAAI,IAAI;gBAAE,MAAM,IAAI,WAAW,CAAC,8FAA8F,CAAC,CAAC;YAChI,6FAA6F;YAC7F,4FAA4F;YAC5F,8CAA8C;YAC9C,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,IAAI,GAAG,IAAI,CAAC;gBACZ,IAAI,CAAC;oBACH,EAAE,CAAC,cAAc,EAAE,CAAC;gBACtB,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,OAAO,GAAG,IAAI,CAAC;oBACf,QAAQ,GAAG,IAAI,CAAC;oBAChB,MAAM,GAAG,IAAI,WAAW,CAAC,oCAAoC,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;oBAC9F,MAAM,MAAM,CAAC;gBACf,CAAC;wBAAS,CAAC;oBACT,IAAI,GAAG,KAAK,CAAC;gBACf,CAAC;YACH,CAAC;YACD,QAAQ,GAAG,IAAI,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Client-side programmatic tool calling (
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* through the framework's own tool routing — intermediate results never
|
|
8
|
-
* enter the model's context; the full trace stays on-box.
|
|
2
|
+
* Client-side programmatic tool calling (`code_execution`): an agent's
|
|
3
|
+
* scripts call its other tools in-process through the framework's own tool
|
|
4
|
+
* routing, so intermediate results never enter the model's context. Each
|
|
5
|
+
* script runs in a process of its own, in QuickJS compiled to WebAssembly
|
|
6
|
+
* (engine.ts), and reaches nothing but the agent's tools.
|
|
9
7
|
*/
|
|
10
|
-
export { PyRunner, buildInjectedTools } from './py-runner.js';
|
|
11
|
-
export type { InjectedTool, ExecResult, PyRunnerOptions, ScriptToolCallHandler, ScriptToolResult, BackgroundExecOptions, } from './py-runner.js';
|
|
12
|
-
export { PYTHON_RUNTIME_SOURCE } from './runtime-py.js';
|
|
13
8
|
export { buildCodeExecutionToolDefinition, CODE_EXECUTION_TOOL_NAME } from './tool-definition.js';
|
|
14
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/code-execution/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/code-execution/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,gCAAgC,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Client-side programmatic tool calling (
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* through the framework's own tool routing — intermediate results never
|
|
8
|
-
* enter the model's context; the full trace stays on-box.
|
|
2
|
+
* Client-side programmatic tool calling (`code_execution`): an agent's
|
|
3
|
+
* scripts call its other tools in-process through the framework's own tool
|
|
4
|
+
* routing, so intermediate results never enter the model's context. Each
|
|
5
|
+
* script runs in a process of its own, in QuickJS compiled to WebAssembly
|
|
6
|
+
* (engine.ts), and reaches nothing but the agent's tools.
|
|
9
7
|
*/
|
|
10
|
-
export { PyRunner, buildInjectedTools } from './py-runner.js';
|
|
11
|
-
export { PYTHON_RUNTIME_SOURCE } from './runtime-py.js';
|
|
12
8
|
export { buildCodeExecutionToolDefinition, CODE_EXECUTION_TOOL_NAME } from './tool-definition.js';
|
|
13
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/code-execution/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/code-execution/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,gCAAgC,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC"}
|