@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
package/src/agent.ts
CHANGED
|
@@ -924,28 +924,89 @@ export class Agent {
|
|
|
924
924
|
}
|
|
925
925
|
|
|
926
926
|
/**
|
|
927
|
-
* RFC-006 consumed watermark: the newest stored message
|
|
928
|
-
* of
|
|
929
|
-
*
|
|
930
|
-
*
|
|
927
|
+
* RFC-006 consumed watermark, per branch: the newest stored message as of
|
|
928
|
+
* the latest of the agent's creation, a committing compile that returns,
|
|
929
|
+
* and a tool boundary that injected messages into a live stream declaring
|
|
930
|
+
* it carries them (`supportsInjectedMessages` true: membrane's native
|
|
931
|
+
* path, from membrane 0.6.0). A compile counts from when it takes its
|
|
932
|
+
* value, before it awaits, so one that began before a boundary's mark
|
|
933
|
+
* doesn't roll the mark back (applyCompileWatermark), and a dry run, such
|
|
934
|
+
* as previewActivation's, doesn't move it. Each move takes the store's
|
|
935
|
+
* head, a scalar, so it also covers stored messages the agent wasn't
|
|
936
|
+
* given, such as another slot's.
|
|
937
|
+
*
|
|
938
|
+
* A message above it may still be replaced or withdrawn in place by its
|
|
939
|
+
* sender, though it may already have been in one of the agent's requests.
|
|
940
|
+
* A live stream carries each round's own content and results, which it
|
|
941
|
+
* stores at its tool boundaries, into its next request. It can also carry
|
|
942
|
+
* the messages injected at a boundary whose stream didn't say whether it
|
|
943
|
+
* carries injections, as no membrane 0.5.x stream does: its native path
|
|
944
|
+
* carries them and its XML path drops them, and either way they stay
|
|
945
|
+
* above it.
|
|
931
946
|
*/
|
|
932
947
|
private consumedWatermark: { branch: string; sequence: number } | null = null;
|
|
933
|
-
/** Counts marks
|
|
934
|
-
*
|
|
948
|
+
/** Counts marks (markContextConsumed's and applyCompileWatermark's), so a
|
|
949
|
+
* compile that finishes can tell whether one was made while it ran. */
|
|
935
950
|
private watermarkMarks = 0;
|
|
951
|
+
/**
|
|
952
|
+
* The newest stored message a compile or a tool boundary may have put in
|
|
953
|
+
* front of the agent, per branch. It moves where the consumed watermark
|
|
954
|
+
* does, and sooner: when a committing compile takes its value, before it
|
|
955
|
+
* awaits, and at every tool boundary that injects, whether or not the
|
|
956
|
+
* stream says it carries injected messages. A message above it may still
|
|
957
|
+
* have been shown, though: for one, a live stream carries each round's own
|
|
958
|
+
* content and results, stored at a boundary that injected nothing, into its
|
|
959
|
+
* next request. A compile that throws assembled nothing, and gives its move
|
|
960
|
+
* back where it can (unshowFailedCompile). A scalar counts a prefix, so a
|
|
961
|
+
* message stored below it without having been shown counts as shown, which
|
|
962
|
+
* errs toward a marker.
|
|
963
|
+
*/
|
|
964
|
+
private shownWatermark: { branch: string; sequence: number } | null = null;
|
|
936
965
|
|
|
937
966
|
getConsumedWatermark(): { branch: string; sequence: number } | null {
|
|
938
967
|
return this.consumedWatermark;
|
|
939
968
|
}
|
|
940
969
|
|
|
970
|
+
getShownWatermark(): { branch: string; sequence: number } | null {
|
|
971
|
+
return this.shownWatermark;
|
|
972
|
+
}
|
|
973
|
+
|
|
941
974
|
/** Mark everything currently stored as consumed (the agent's creation, at
|
|
942
|
-
* boot or later, and a tool boundary that injected messages into
|
|
943
|
-
* stream). */
|
|
975
|
+
* boot or later, and a tool boundary that injected messages into a live
|
|
976
|
+
* stream declaring it carries them; see consumedWatermark). */
|
|
944
977
|
markContextConsumed(): void {
|
|
945
978
|
// Tolerates partial context-manager doubles (tests build Agents over
|
|
946
|
-
// stubs)
|
|
979
|
+
// stubs). Without a watermark, a reader that looks for one takes its own
|
|
980
|
+
// side: the coalescer counts the message as read, and the framework's
|
|
981
|
+
// deferredWriteReadOrGone and unreadNoticesForPrimary count it as unread.
|
|
947
982
|
this.consumedWatermark = this.pendingWatermark();
|
|
948
983
|
this.watermarkMarks++;
|
|
984
|
+
this.shownWatermark = this.consumedWatermark;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
/** Mark everything currently stored as possibly shown (a tool boundary
|
|
988
|
+
* that injected messages, whatever its stream says it carries). Without
|
|
989
|
+
* a watermark the coalescer counts a message as shown, as it counts one
|
|
990
|
+
* read without a consumed watermark. */
|
|
991
|
+
markContextShown(): void {
|
|
992
|
+
this.shownWatermark = this.pendingWatermark();
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
/** A committing compile that threw assembled nothing, so its own move of
|
|
996
|
+
* the shown watermark goes back, unless a boundary or another compile has
|
|
997
|
+
* moved the watermark since. It goes back to the watermark as the compile
|
|
998
|
+
* found it, which can be another compile's claim that has failed as well.
|
|
999
|
+
* Of two overlapping committing compiles, if the first to start throws
|
|
1000
|
+
* first, it gives nothing back (the second's claim is current), and if
|
|
1001
|
+
* the second then throws, it restores the first's failed claim. Messages
|
|
1002
|
+
* up to that claim then count as shown, although no request held those
|
|
1003
|
+
* above the watermark the first compile found, which errs toward a marker
|
|
1004
|
+
* until the next compile or boundary moves the watermark. */
|
|
1005
|
+
private unshowFailedCompile(
|
|
1006
|
+
watermark: { branch: string; sequence: number } | null,
|
|
1007
|
+
before: { branch: string; sequence: number } | null,
|
|
1008
|
+
): void {
|
|
1009
|
+
if (watermark && this.shownWatermark === watermark) this.shownWatermark = before;
|
|
949
1010
|
}
|
|
950
1011
|
|
|
951
1012
|
/**
|
|
@@ -953,7 +1014,9 @@ export class Agent {
|
|
|
953
1014
|
* the watermark only advances: if a mark was made while the compile ran,
|
|
954
1015
|
* the compile's (older) one is applied only where it is later on that
|
|
955
1016
|
* mark's branch, so a boundary's mark is never rolled back by a compile
|
|
956
|
-
* that started before it (a
|
|
1017
|
+
* that started before it (a committing compile, such as compileContext's,
|
|
1018
|
+
* run during a live turn; a dry run, such as previewActivation's, never
|
|
1019
|
+
* reaches here).
|
|
957
1020
|
*/
|
|
958
1021
|
private applyCompileWatermark(watermark: { branch: string; sequence: number }, marksBefore: number): void {
|
|
959
1022
|
const current = this.consumedWatermark;
|
|
@@ -993,8 +1056,16 @@ export class Agent {
|
|
|
993
1056
|
// fails assembled nothing, so the watermark moves only on success.
|
|
994
1057
|
const watermark = this.pendingWatermark();
|
|
995
1058
|
const marksBefore = this.watermarkMarks;
|
|
1059
|
+
const shownBefore = this.shownWatermark;
|
|
1060
|
+
if (watermark) this.shownWatermark = watermark;
|
|
996
1061
|
const compile = () => this.contextManager.compile(this.compileBudget(budget));
|
|
997
|
-
|
|
1062
|
+
let result: CompileResult;
|
|
1063
|
+
try {
|
|
1064
|
+
result = budget ? await compile() : await this.compileAtLiveBudget(compile);
|
|
1065
|
+
} catch (error) {
|
|
1066
|
+
this.unshowFailedCompile(watermark, shownBefore);
|
|
1067
|
+
throw error;
|
|
1068
|
+
}
|
|
998
1069
|
if (watermark) this.applyCompileWatermark(watermark, marksBefore);
|
|
999
1070
|
return result;
|
|
1000
1071
|
}
|
|
@@ -1035,8 +1106,18 @@ export class Agent {
|
|
|
1035
1106
|
// any compile before it selects.
|
|
1036
1107
|
const watermark = opts?.dryRun ? null : this.pendingWatermark();
|
|
1037
1108
|
const marksBefore = this.watermarkMarks;
|
|
1109
|
+
// Shown from the compile's start: what it assembles is in front of the
|
|
1110
|
+
// agent before the consumed watermark moves, once it returns.
|
|
1111
|
+
const shownBefore = this.shownWatermark;
|
|
1112
|
+
if (watermark) this.shownWatermark = watermark;
|
|
1038
1113
|
const compile = () => this.contextManager.compile(this.compileBudget(budget), injections, opts as never);
|
|
1039
|
-
|
|
1114
|
+
let result: CompileResult;
|
|
1115
|
+
try {
|
|
1116
|
+
result = budget || opts?.dryRun ? await compile() : await this.compileAtLiveBudget(compile);
|
|
1117
|
+
} catch (error) {
|
|
1118
|
+
this.unshowFailedCompile(watermark, shownBefore);
|
|
1119
|
+
throw error;
|
|
1120
|
+
}
|
|
1040
1121
|
if (watermark) this.applyCompileWatermark(watermark, marksBefore);
|
|
1041
1122
|
return result;
|
|
1042
1123
|
}
|
package/src/api/server.ts
CHANGED
|
@@ -489,6 +489,12 @@ export class ApiServer {
|
|
|
489
489
|
if (!params.participant || !params.content) {
|
|
490
490
|
throw new Error('participant and content are required');
|
|
491
491
|
}
|
|
492
|
+
// ApiModule stores the message as one text block, which context-manager
|
|
493
|
+
// refuses unless its text is a string, so content that isn't text is
|
|
494
|
+
// refused here, where the caller hears it, rather than at dispatch.
|
|
495
|
+
if (typeof params.content !== 'string') {
|
|
496
|
+
throw new Error('content must be text');
|
|
497
|
+
}
|
|
492
498
|
|
|
493
499
|
// Push api:message event for the ApiModule to handle
|
|
494
500
|
this.framework.pushEvent({
|
|
@@ -587,14 +593,14 @@ export class ApiServer {
|
|
|
587
593
|
|
|
588
594
|
const from = this.currentBranch;
|
|
589
595
|
|
|
590
|
-
// The framework switches the store
|
|
591
|
-
//
|
|
592
|
-
//
|
|
593
|
-
//
|
|
594
|
-
//
|
|
595
|
-
//
|
|
596
|
-
//
|
|
597
|
-
//
|
|
596
|
+
// The framework switches the store and re-materializes the config mount;
|
|
597
|
+
// a branch switch adds or removes no Discord awareness marks. It refuses
|
|
598
|
+
// during a live turn or once stop() has begun, and stop() waits for one
|
|
599
|
+
// already running. It moves the store once any maintenance already
|
|
600
|
+
// running has finished, so the move can come after this call returns.
|
|
601
|
+
// The event names this switch's own move, from the branch read here to
|
|
602
|
+
// the one it was asked for: another switch can move the store again
|
|
603
|
+
// before this one continues.
|
|
598
604
|
let switched = false;
|
|
599
605
|
try {
|
|
600
606
|
await this.framework.switchBranch(params.name);
|
|
@@ -647,8 +653,6 @@ export class ApiServer {
|
|
|
647
653
|
const result = this.framework.undoLastTurn(params.agentName);
|
|
648
654
|
|
|
649
655
|
if (result.undone) {
|
|
650
|
-
// Marks follow behind the data-plane gate; the undo doesn't wait for Discord.
|
|
651
|
-
this.framework.startDiscordAwarenessDelivery('undo', params.agentName);
|
|
652
656
|
this.broadcast('branch:switched', {
|
|
653
657
|
from: result.fromBranch,
|
|
654
658
|
to: result.toBranch,
|
|
@@ -667,8 +671,6 @@ export class ApiServer {
|
|
|
667
671
|
const result = this.framework.redo(params.agentName);
|
|
668
672
|
|
|
669
673
|
if (result.redone) {
|
|
670
|
-
// Marks follow behind the data-plane gate; the redo doesn't wait for Discord.
|
|
671
|
-
this.framework.startDiscordAwarenessDelivery('redo', params.agentName);
|
|
672
674
|
this.broadcast('branch:switched', {
|
|
673
675
|
from: result.fromBranch,
|
|
674
676
|
to: result.toBranch,
|