@animalabs/agent-framework 0.23.3 → 0.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +212 -42
- package/dist/src/agent.d.ts +65 -9
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +98 -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/clock-rows.d.ts +115 -0
- package/dist/src/clock-rows.d.ts.map +1 -0
- package/dist/src/clock-rows.js +222 -0
- package/dist/src/clock-rows.js.map +1 -0
- 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 +1120 -457
- package/dist/src/framework.d.ts.map +1 -1
- package/dist/src/framework.js +4635 -2505
- package/dist/src/framework.js.map +1 -1
- package/dist/src/gate/event-gate.d.ts +28 -4
- package/dist/src/gate/event-gate.d.ts.map +1 -1
- package/dist/src/gate/event-gate.js +89 -13
- 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 +8 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +10 -8
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcpl/channel-registry.d.ts +483 -115
- package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
- package/dist/src/mcpl/channel-registry.js +1735 -425
- package/dist/src/mcpl/channel-registry.js.map +1 -1
- package/dist/src/mcpl/conversation-router.d.ts +19 -39
- package/dist/src/mcpl/conversation-router.d.ts.map +1 -1
- package/dist/src/mcpl/conversation-router.js +27 -59
- 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 +174 -17
- 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 +9 -20
- package/dist/src/mcpl/push-handler.d.ts.map +1 -1
- package/dist/src/mcpl/push-handler.js +7 -49
- 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 +493 -62
- package/dist/src/modules/workspace/index.d.ts.map +1 -1
- package/dist/src/modules/workspace/index.js +2216 -652
- 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/timezone.d.ts +4 -2
- package/dist/src/timezone.d.ts.map +1 -1
- package/dist/src/timezone.js +4 -2
- package/dist/src/timezone.js.map +1 -1
- package/dist/src/tool-image-ledger.d.ts +46 -7
- package/dist/src/tool-image-ledger.d.ts.map +1 -1
- package/dist/src/tool-image-ledger.js +60 -7
- package/dist/src/tool-image-ledger.js.map +1 -1
- package/dist/src/tool-result-guard.d.ts +14 -11
- package/dist/src/tool-result-guard.d.ts.map +1 -1
- package/dist/src/tool-result-guard.js +17 -14
- package/dist/src/tool-result-guard.js.map +1 -1
- package/dist/src/tool-result-history.d.ts +3 -2
- package/dist/src/tool-result-history.d.ts.map +1 -1
- package/dist/src/tool-result-history.js +3 -2
- package/dist/src/tool-result-history.js.map +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 +142 -40
- package/dist/src/tune-out/coordinator.js.map +1 -1
- package/dist/src/types/agent.d.ts +31 -6
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/events.d.ts +66 -9
- package/dist/src/types/events.d.ts.map +1 -1
- package/dist/src/types/framework.d.ts +69 -62
- 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 -8
- package/src/agent.ts +99 -12
- package/src/api/server.ts +14 -12
- package/src/clock-rows.ts +302 -0
- 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 +4978 -2671
- package/src/gate/event-gate.ts +79 -17
- package/src/held-writes.ts +17 -3
- package/src/index.ts +32 -22
- package/src/mcpl/channel-registry.ts +1892 -471
- package/src/mcpl/conversation-router.ts +26 -72
- 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 +200 -22
- package/src/mcpl/push-coalescer.ts +306 -62
- package/src/mcpl/push-handler.ts +12 -54
- 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 +2293 -650
- 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/timezone.ts +4 -2
- package/src/tool-image-ledger.ts +62 -8
- package/src/tool-result-guard.ts +18 -15
- package/src/tool-result-history.ts +3 -2
- package/src/tune-out/coordinator.ts +166 -45
- package/src/types/agent.ts +32 -6
- package/src/types/events.ts +66 -9
- package/src/types/framework.ts +69 -62
- 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,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A script's output, bounded once, in the parent: every return, whether a
|
|
3
|
+
* yield, a wait or the ending's, gives what the script wrote since the
|
|
4
|
+
* previous one, its first and last characters within the bound and a count of
|
|
5
|
+
* what was dropped between. A long stretch keeps its start, since that's
|
|
6
|
+
* often where its trouble began, such as the first error before a cascade.
|
|
7
|
+
*
|
|
8
|
+
* The child can't know when the parent returns, since its frames reach it only
|
|
9
|
+
* while its guest is idle, so the bound sits in the parent: the child holds
|
|
10
|
+
* one bounded batch of what the guest writes and flushes it, and the parent
|
|
11
|
+
* keeps the head and tail of each return's stretch, starting both afresh at
|
|
12
|
+
* each return. Memory is bounded by construction on both sides; the price is
|
|
13
|
+
* that a printing loop's whole output crosses the pipe, in batches.
|
|
14
|
+
*/
|
|
15
|
+
export interface OutputBounds {
|
|
16
|
+
/** Characters kept from the start of each return's stretch. */
|
|
17
|
+
headChars: number;
|
|
18
|
+
/** Characters kept from its end. */
|
|
19
|
+
tailChars: number;
|
|
20
|
+
}
|
|
21
|
+
export declare const DEFAULT_OUTPUT_BOUNDS: OutputBounds;
|
|
22
|
+
/** The most one output frame carries, so a single large write is sent in pieces. */
|
|
23
|
+
export declare const MAX_BATCH_CHARS: number;
|
|
24
|
+
/** The child's side: what the guest wrote since the last flush, at most a batch of it at a time. */
|
|
25
|
+
export declare class OutputBatch {
|
|
26
|
+
private pending;
|
|
27
|
+
private size;
|
|
28
|
+
/** Characters waiting to be flushed. */
|
|
29
|
+
get unflushed(): number;
|
|
30
|
+
/** True once the batch is full, so the caller flushes now. */
|
|
31
|
+
write(text: string): boolean;
|
|
32
|
+
/** The waiting text in pieces of at most a batch each, emptying it; empty when nothing waits. */
|
|
33
|
+
flush(): string[];
|
|
34
|
+
}
|
|
35
|
+
/** A return's stretch of output: its head and tail, and the count dropped between them. */
|
|
36
|
+
export interface OutputWindow {
|
|
37
|
+
head: string;
|
|
38
|
+
tail: string;
|
|
39
|
+
dropped: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The stretch as the model sees it: the head, a line naming what was dropped
|
|
43
|
+
* if anything was, and the tail. Past `max`, its start and its end are cut
|
|
44
|
+
* alike to fit it, each taking the room the other doesn't need, and the count
|
|
45
|
+
* takes in what they gave up, so a return held to its agent's inline cap
|
|
46
|
+
* still shows both ends. A `max` that leaves no room for that line gets the
|
|
47
|
+
* line alone, which passes it.
|
|
48
|
+
*/
|
|
49
|
+
export declare function renderOutput(w: OutputWindow, max?: number): string;
|
|
50
|
+
/** The parent's side: the head and tail of what arrived since the last return, and the count dropped between. */
|
|
51
|
+
export declare class WindowOutput {
|
|
52
|
+
private readonly bounds;
|
|
53
|
+
private head;
|
|
54
|
+
private tail;
|
|
55
|
+
private dropped;
|
|
56
|
+
constructor(bounds: OutputBounds);
|
|
57
|
+
/** Add text the child flushed. */
|
|
58
|
+
apply(text: string): void;
|
|
59
|
+
/** Characters dropped from the stretch so far. */
|
|
60
|
+
get droppedChars(): number;
|
|
61
|
+
/** The stretch as it stands. */
|
|
62
|
+
window(): OutputWindow;
|
|
63
|
+
/** The stretch as the model sees it, whole (renderOutput). */
|
|
64
|
+
render(): string;
|
|
65
|
+
/** The stretch, and a fresh one from here. */
|
|
66
|
+
take(): OutputWindow;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../../../src/code-execution/isolate/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,YAAY;IAC3B,+DAA+D;IAC/D,SAAS,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,qBAAqB,EAAE,YAAqD,CAAC;AAE1F,oFAAoF;AACpF,eAAO,MAAM,eAAe,QAAY,CAAC;AASzC,oGAAoG;AACpG,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,IAAI,CAAK;IAEjB,wCAAwC;IACxC,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,8DAA8D;IAC9D,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAK3B;IAED,iGAAiG;IACjG,KAAK,IAAI,MAAM,EAAE,CAahB;CACF;AAED,2FAA2F;AAC3F,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAKD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,YAAY,EAAE,GAAG,SAAW,GAAG,MAAM,CAgBpE;AAED,iHAAiH;AACjH,qBAAa,YAAY;IAKX,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJnC,OAAO,CAAC,IAAI,CAAM;IAClB,OAAO,CAAC,IAAI,CAAM;IAClB,OAAO,CAAC,OAAO,CAAK;IAEpB,YAA6B,MAAM,EAAE,YAAY,EAAI;IAErD,kCAAkC;IAClC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAqBxB;IAED,kDAAkD;IAClD,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,gCAAgC;IAChC,MAAM,IAAI,YAAY,CAErB;IAED,8DAA8D;IAC9D,MAAM,IAAI,MAAM,CAEf;IAED,8CAA8C;IAC9C,IAAI,IAAI,YAAY,CAMnB;CACF"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A script's output, bounded once, in the parent: every return, whether a
|
|
3
|
+
* yield, a wait or the ending's, gives what the script wrote since the
|
|
4
|
+
* previous one, its first and last characters within the bound and a count of
|
|
5
|
+
* what was dropped between. A long stretch keeps its start, since that's
|
|
6
|
+
* often where its trouble began, such as the first error before a cascade.
|
|
7
|
+
*
|
|
8
|
+
* The child can't know when the parent returns, since its frames reach it only
|
|
9
|
+
* while its guest is idle, so the bound sits in the parent: the child holds
|
|
10
|
+
* one bounded batch of what the guest writes and flushes it, and the parent
|
|
11
|
+
* keeps the head and tail of each return's stretch, starting both afresh at
|
|
12
|
+
* each return. Memory is bounded by construction on both sides; the price is
|
|
13
|
+
* that a printing loop's whole output crosses the pipe, in batches.
|
|
14
|
+
*/
|
|
15
|
+
export const DEFAULT_OUTPUT_BOUNDS = { headChars: 8_000, tailChars: 8_000 };
|
|
16
|
+
/** The most one output frame carries, so a single large write is sent in pieces. */
|
|
17
|
+
export const MAX_BATCH_CHARS = 64 * 1024;
|
|
18
|
+
/** Where to cut `text` near `at` without parting a surrogate pair: one earlier if `at` falls inside one. */
|
|
19
|
+
function safeCut(text, at) {
|
|
20
|
+
if (at <= 0 || at >= text.length)
|
|
21
|
+
return Math.max(0, Math.min(at, text.length));
|
|
22
|
+
const before = text.charCodeAt(at - 1);
|
|
23
|
+
return before >= 0xd800 && before <= 0xdbff ? at - 1 : at;
|
|
24
|
+
}
|
|
25
|
+
/** The child's side: what the guest wrote since the last flush, at most a batch of it at a time. */
|
|
26
|
+
export class OutputBatch {
|
|
27
|
+
pending = [];
|
|
28
|
+
size = 0;
|
|
29
|
+
/** Characters waiting to be flushed. */
|
|
30
|
+
get unflushed() {
|
|
31
|
+
return this.size;
|
|
32
|
+
}
|
|
33
|
+
/** True once the batch is full, so the caller flushes now. */
|
|
34
|
+
write(text) {
|
|
35
|
+
if (text.length === 0)
|
|
36
|
+
return this.size >= MAX_BATCH_CHARS;
|
|
37
|
+
this.pending.push(text);
|
|
38
|
+
this.size += text.length;
|
|
39
|
+
return this.size >= MAX_BATCH_CHARS;
|
|
40
|
+
}
|
|
41
|
+
/** The waiting text in pieces of at most a batch each, emptying it; empty when nothing waits. */
|
|
42
|
+
flush() {
|
|
43
|
+
if (this.size === 0)
|
|
44
|
+
return [];
|
|
45
|
+
let text = this.pending.join('');
|
|
46
|
+
this.pending = [];
|
|
47
|
+
this.size = 0;
|
|
48
|
+
const pieces = [];
|
|
49
|
+
while (text.length > MAX_BATCH_CHARS) {
|
|
50
|
+
const cut = safeCut(text, MAX_BATCH_CHARS);
|
|
51
|
+
pieces.push(text.slice(0, cut));
|
|
52
|
+
text = text.slice(cut);
|
|
53
|
+
}
|
|
54
|
+
if (text.length > 0)
|
|
55
|
+
pieces.push(text);
|
|
56
|
+
return pieces;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** The line naming what was dropped, at its longest, as renderOutput puts it between the head and the tail. */
|
|
60
|
+
const DROPPED_LINE_CHARS = `\n[… ${Number.MAX_SAFE_INTEGER} characters of output dropped here …]\n`.length;
|
|
61
|
+
/**
|
|
62
|
+
* The stretch as the model sees it: the head, a line naming what was dropped
|
|
63
|
+
* if anything was, and the tail. Past `max`, its start and its end are cut
|
|
64
|
+
* alike to fit it, each taking the room the other doesn't need, and the count
|
|
65
|
+
* takes in what they gave up, so a return held to its agent's inline cap
|
|
66
|
+
* still shows both ends. A `max` that leaves no room for that line gets the
|
|
67
|
+
* line alone, which passes it.
|
|
68
|
+
*/
|
|
69
|
+
export function renderOutput(w, max = Infinity) {
|
|
70
|
+
const whole = w.dropped === 0 ? w.head + w.tail : `${w.head}\n[… ${w.dropped} characters of output dropped here …]\n${w.tail}`;
|
|
71
|
+
if (whole.length <= max)
|
|
72
|
+
return whole;
|
|
73
|
+
const room = Math.max(0, Math.floor(max) - DROPPED_LINE_CHARS);
|
|
74
|
+
// With nothing dropped yet, the head and the tail are one stretch, whose end
|
|
75
|
+
// lies in the head while the tail is short or empty: it's cut as one.
|
|
76
|
+
const [first, last] = w.dropped === 0 ? [whole, whole] : [w.head, w.tail];
|
|
77
|
+
const lastKeep = Math.min(last.length, Math.max(Math.floor(room / 2), room - first.length));
|
|
78
|
+
const head = first.slice(0, safeCut(first, Math.min(first.length, room - lastKeep)));
|
|
79
|
+
// Kept from the end, never starting on a pair's second half.
|
|
80
|
+
let from = last.length - lastKeep;
|
|
81
|
+
const at = last.charCodeAt(from);
|
|
82
|
+
if (from > 0 && at >= 0xdc00 && at <= 0xdfff)
|
|
83
|
+
from += 1;
|
|
84
|
+
const tail = last.slice(from);
|
|
85
|
+
const dropped = w.dropped === 0 ? whole.length - head.length - tail.length : w.dropped + (first.length - head.length) + from;
|
|
86
|
+
return `${head}\n[… ${dropped} characters of output dropped here …]\n${tail}`;
|
|
87
|
+
}
|
|
88
|
+
/** The parent's side: the head and tail of what arrived since the last return, and the count dropped between. */
|
|
89
|
+
export class WindowOutput {
|
|
90
|
+
bounds;
|
|
91
|
+
head = '';
|
|
92
|
+
tail = '';
|
|
93
|
+
dropped = 0;
|
|
94
|
+
constructor(bounds) {
|
|
95
|
+
this.bounds = bounds;
|
|
96
|
+
}
|
|
97
|
+
/** Add text the child flushed. */
|
|
98
|
+
apply(text) {
|
|
99
|
+
let rest = text;
|
|
100
|
+
if (this.tail.length === 0 && this.dropped === 0) {
|
|
101
|
+
const room = this.bounds.headChars - this.head.length;
|
|
102
|
+
if (room > 0) {
|
|
103
|
+
const cut = safeCut(rest, room);
|
|
104
|
+
this.head += rest.slice(0, cut);
|
|
105
|
+
rest = rest.slice(cut);
|
|
106
|
+
if (rest.length === 0)
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
this.tail += rest;
|
|
111
|
+
const over = this.tail.length - this.bounds.tailChars;
|
|
112
|
+
if (over > 0) {
|
|
113
|
+
// Drop from the front, never splitting a pair: the cut moves later by one if it would.
|
|
114
|
+
let cut = over;
|
|
115
|
+
const at = this.tail.charCodeAt(cut - 1);
|
|
116
|
+
if (at >= 0xd800 && at <= 0xdbff)
|
|
117
|
+
cut += 1;
|
|
118
|
+
this.dropped += cut;
|
|
119
|
+
this.tail = this.tail.slice(cut);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/** Characters dropped from the stretch so far. */
|
|
123
|
+
get droppedChars() {
|
|
124
|
+
return this.dropped;
|
|
125
|
+
}
|
|
126
|
+
/** The stretch as it stands. */
|
|
127
|
+
window() {
|
|
128
|
+
return { head: this.head, tail: this.tail, dropped: this.dropped };
|
|
129
|
+
}
|
|
130
|
+
/** The stretch as the model sees it, whole (renderOutput). */
|
|
131
|
+
render() {
|
|
132
|
+
return renderOutput(this.window());
|
|
133
|
+
}
|
|
134
|
+
/** The stretch, and a fresh one from here. */
|
|
135
|
+
take() {
|
|
136
|
+
const window = this.window();
|
|
137
|
+
this.head = '';
|
|
138
|
+
this.tail = '';
|
|
139
|
+
this.dropped = 0;
|
|
140
|
+
return window;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../../../src/code-execution/isolate/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AASH,MAAM,CAAC,MAAM,qBAAqB,GAAiB,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AAE1F,oFAAoF;AACpF,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,GAAG,IAAI,CAAC;AAEzC,4GAA4G;AAC5G,SAAS,OAAO,CAAC,IAAY,EAAE,EAAU;IACvC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAChF,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IACvC,OAAO,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC5D,CAAC;AAED,oGA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jB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The guest's prelude: JavaScript the engine evaluates before a script, which
|
|
3
|
+
* builds what a script meets from the binding's two globals, `__host(name,
|
|
4
|
+
* argsJson)` and `__output(stream, text)`:
|
|
5
|
+
*
|
|
6
|
+
* - `tools[name](args)`, each tool by its exact name, answering one result
|
|
7
|
+
* shape, `{ content, structuredContent, isError }`. A refusal before
|
|
8
|
+
* dispatch rejects with an Error carrying the refusal's fields. Reading a
|
|
9
|
+
* name that isn't a tool throws at once, naming the close matches.
|
|
10
|
+
* At most MAX_CALLS_IN_FLIGHT are out at once, and one past them waits
|
|
11
|
+
* here, in the script's own memory, until one is answered.
|
|
12
|
+
* - `ALL_TOOLS`, each tool's name, description and input schema.
|
|
13
|
+
* - `text(value)` and `console.log/info/warn/error/debug(...)`, which write
|
|
14
|
+
* the script's output: a string as it is, anything else as JSON.
|
|
15
|
+
* - `wake_agent(payload)`, which asks the host to wake the agent.
|
|
16
|
+
* - `__run(src)`, which runs a script as the body of an async function, so it
|
|
17
|
+
* may `await` at its top level and `return` a value.
|
|
18
|
+
*
|
|
19
|
+
* Nothing here guards a boundary: the guest's whole world is this instance,
|
|
20
|
+
* and every call it makes is checked by the host. Built-ins aren't frozen, so a
|
|
21
|
+
* script that patches one breaks only itself: its calls and its ending are
|
|
22
|
+
* recorded outside the guest.
|
|
23
|
+
*
|
|
24
|
+
* Adapted from pi-codemode's guest prelude (`@earendil-works/pi-codemode`
|
|
25
|
+
* 1.3.0, `dist/runtime/prelude-source.js`): the tools proxy and its
|
|
26
|
+
* close-match error, the output helpers and the error formatting. Its licence,
|
|
27
|
+
* the LICENSE at the root of github.com/earendil-works/pi, which the package's
|
|
28
|
+
* `license: "MIT"` refers to:
|
|
29
|
+
*
|
|
30
|
+
* MIT License. Copyright (c) 2025 Mario Zechner. Permission is hereby granted,
|
|
31
|
+
* free of charge, to any person obtaining a copy of this software and
|
|
32
|
+
* associated documentation files (the "Software"), to deal in the Software
|
|
33
|
+
* without restriction, including without limitation the rights to use, copy,
|
|
34
|
+
* modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
|
35
|
+
* Software, and to permit persons to whom the Software is furnished to do so,
|
|
36
|
+
* subject to the following conditions: The above copyright notice and this
|
|
37
|
+
* permission notice shall be included in all copies or substantial portions
|
|
38
|
+
* of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
|
39
|
+
* KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
40
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
|
41
|
+
* EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
42
|
+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
43
|
+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
44
|
+
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
45
|
+
*/
|
|
46
|
+
/** The host call name `wake_agent()` uses. Parentheses can't be in a tool's name, so it never names a tool. */
|
|
47
|
+
export declare const WAKE_CALL_NAME = "(wake_agent)";
|
|
48
|
+
/**
|
|
49
|
+
* How many lines QuickJS's async function constructor puts before a script's
|
|
50
|
+
* first line, and the filename it gives the script's code: a script's frames
|
|
51
|
+
* read `<input>:N:C`, with its own line N less this.
|
|
52
|
+
*/
|
|
53
|
+
export declare const SCRIPT_LINE_OFFSET = 2;
|
|
54
|
+
/**
|
|
55
|
+
* A frame of the script's own code, as QuickJS writes one in a stack: " at
|
|
56
|
+
* NAME (PLACE)", or " at PLACE" for a syntax error, its PLACE at the end
|
|
57
|
+
* and the script's, `<input>:LINE:COLUMN`, its LINE of at most ten digits, as
|
|
58
|
+
* QuickJS writes a line (a 32-bit integer). A NAME may hold any character but
|
|
59
|
+
* a line feed, which the stack's lines are split at, so `[^]` rather than
|
|
60
|
+
* `.`, which stops at a carriage return and U+2028 and U+2029 too. The
|
|
61
|
+
* guest's copy of the rule (errorText) is given these two patterns as they
|
|
62
|
+
* are.
|
|
63
|
+
*/
|
|
64
|
+
export declare const SCRIPT_FRAME: RegExp;
|
|
65
|
+
/** A script frame's place, at its end: its line is renumbered as the agent wrote it. */
|
|
66
|
+
export declare const SCRIPT_PLACE: RegExp;
|
|
67
|
+
/**
|
|
68
|
+
* A failure's frames as the agent reads them, one per line: the script's own,
|
|
69
|
+
* numbered as the agent wrote its lines, leaving out the prelude's frames and
|
|
70
|
+
* the engine's native ones. QuickJS gives an Error's stack as its frames
|
|
71
|
+
* alone, and nothing here adds the failure's name and message to it, so the
|
|
72
|
+
* script's frames are the lines shaped as its frames are (SCRIPT_FRAME): a
|
|
73
|
+
* line of a stack the script or its Error.prepareStackTrace set is one if it
|
|
74
|
+
* is shaped so, and isn't otherwise. A function's name holding a line feed
|
|
75
|
+
* splits its frame in two, and each half is read on its own, so the frame is
|
|
76
|
+
* lost unless a half is itself shaped as a frame. Code the script compiles at
|
|
77
|
+
* run time is named `<input>` as the script is, so the rule takes its frames
|
|
78
|
+
* for the script's: an eval's read at its string's lines less two, and a
|
|
79
|
+
* Function constructor's at its body's own lines, plus one for each line
|
|
80
|
+
* break in its parameters, since the constructor puts its parameters and two
|
|
81
|
+
* lines before the body, as the prelude's AsyncFunction does. The prelude's
|
|
82
|
+
* errorText applies this rule in the guest, to an Error the script logs,
|
|
83
|
+
* leading with the name and message, while a string the script logs, an
|
|
84
|
+
* Error's `stack` among them, shows as QuickJS or the script wrote it; the
|
|
85
|
+
* child applies the rule here to every failure's stack. The two are one rule:
|
|
86
|
+
* the guest is given the pair of patterns as they are, and the walk here
|
|
87
|
+
* reads SCRIPT_FRAME as SCRIPT_FRAME_IN_STACK and renumbers a place itself,
|
|
88
|
+
* as SCRIPT_PLACE says, so a change to one has to be made to all three, and
|
|
89
|
+
* tests hold them together.
|
|
90
|
+
*/
|
|
91
|
+
export declare function scriptFrames(stack: string, max?: number): string;
|
|
92
|
+
/** One tool as the prelude lists it in ALL_TOOLS. */
|
|
93
|
+
export interface PreludeTool {
|
|
94
|
+
name: string;
|
|
95
|
+
description: string;
|
|
96
|
+
/** The tool's input schema, as the agent's own tool list gives it. */
|
|
97
|
+
inputSchema?: unknown;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The prelude, for these tools. The child, not the prelude, refuses a wake
|
|
101
|
+
* past the script's cap (child.ts). The tool list goes in as
|
|
102
|
+
* a JSON string the prelude parses, so a schema's `__proto__` key stays a key,
|
|
103
|
+
* as it would not in an object literal, and the prelude is one string the
|
|
104
|
+
* engine evaluates as global code.
|
|
105
|
+
*/
|
|
106
|
+
export declare function preludeSource(tools: readonly PreludeTool[]): string;
|
|
107
|
+
/** The one line `start` evaluates after the prelude: the script, as a string literal, handed to `__run`. */
|
|
108
|
+
export declare function scriptCall(script: string): string;
|
|
109
|
+
//# sourceMappingURL=prelude.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prelude.d.ts","sourceRoot":"","sources":["../../../../src/code-execution/isolate/prelude.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAKH,+GAA+G;AAC/G,eAAO,MAAM,cAAc,iBAAiB,CAAC;AAE7C;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAEpC;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,QAAyC,CAAC;AACnE,wFAAwF;AACxF,eAAO,MAAM,YAAY,QAAiC,CAAC;AAS3D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,SAAW,GAAG,MAAM,CAoClE;AAuCD,qDAAqD;AACrD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,sEAAsE;IACtE,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,MAAM,CAiNnE;AAED,4GAA4G;AAC5G,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEjD"}
|