@animalabs/agent-framework 0.32.0 → 0.34.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 +340 -22
- package/dist/src/admission/admit.d.ts +18 -0
- package/dist/src/admission/admit.d.ts.map +1 -1
- package/dist/src/admission/admit.js +16 -3
- package/dist/src/admission/admit.js.map +1 -1
- package/dist/src/agent.d.ts +208 -80
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +345 -113
- package/dist/src/agent.js.map +1 -1
- package/dist/src/api/mcp-server-core.d.ts.map +1 -1
- package/dist/src/api/mcp-server-core.js +50 -12
- package/dist/src/api/mcp-server-core.js.map +1 -1
- package/dist/src/api/server.d.ts.map +1 -1
- package/dist/src/api/server.js +4 -20
- package/dist/src/api/server.js.map +1 -1
- package/dist/src/append-all.d.ts +5 -0
- package/dist/src/append-all.d.ts.map +1 -0
- package/dist/src/append-all.js +8 -0
- package/dist/src/append-all.js.map +1 -0
- package/dist/src/code-execution/isolate/scripts.d.ts +12 -8
- package/dist/src/code-execution/isolate/scripts.d.ts.map +1 -1
- package/dist/src/code-execution/isolate/scripts.js +24 -0
- package/dist/src/code-execution/isolate/scripts.js.map +1 -1
- package/dist/src/config-checks.d.ts +7 -0
- package/dist/src/config-checks.d.ts.map +1 -1
- package/dist/src/config-checks.js +14 -0
- package/dist/src/config-checks.js.map +1 -1
- package/dist/src/context-manager-errors.d.ts +25 -0
- package/dist/src/context-manager-errors.d.ts.map +1 -0
- package/dist/src/context-manager-errors.js +31 -0
- package/dist/src/context-manager-errors.js.map +1 -0
- package/dist/src/context-options.d.ts +70 -0
- package/dist/src/context-options.d.ts.map +1 -0
- package/dist/src/context-options.js +90 -0
- package/dist/src/context-options.js.map +1 -0
- package/dist/src/cut-off-round.js +4 -4
- package/dist/src/deferred-import.d.ts +93 -0
- package/dist/src/deferred-import.d.ts.map +1 -0
- package/dist/src/deferred-import.js +177 -0
- package/dist/src/deferred-import.js.map +1 -0
- package/dist/src/dendrite/audience.d.ts +223 -0
- package/dist/src/dendrite/audience.d.ts.map +1 -0
- package/dist/src/dendrite/audience.js +202 -0
- package/dist/src/dendrite/audience.js.map +1 -0
- package/dist/src/dendrite/index.d.ts +5 -3
- package/dist/src/dendrite/index.d.ts.map +1 -1
- package/dist/src/dendrite/index.js +2 -1
- package/dist/src/dendrite/index.js.map +1 -1
- package/dist/src/dendrite/presets.d.ts +10 -5
- package/dist/src/dendrite/presets.d.ts.map +1 -1
- package/dist/src/dendrite/presets.js +17 -5
- package/dist/src/dendrite/presets.js.map +1 -1
- package/dist/src/dendrite/registry.d.ts +62 -7
- package/dist/src/dendrite/registry.d.ts.map +1 -1
- package/dist/src/dendrite/registry.js +183 -12
- package/dist/src/dendrite/registry.js.map +1 -1
- package/dist/src/dendrite/types.d.ts +91 -8
- package/dist/src/dendrite/types.d.ts.map +1 -1
- package/dist/src/failure-text.d.ts +36 -0
- package/dist/src/failure-text.d.ts.map +1 -0
- package/dist/src/failure-text.js +89 -0
- package/dist/src/failure-text.js.map +1 -0
- package/dist/src/foreign-rounds.d.ts +69 -0
- package/dist/src/foreign-rounds.d.ts.map +1 -0
- package/dist/src/foreign-rounds.js +152 -0
- package/dist/src/foreign-rounds.js.map +1 -0
- package/dist/src/framework.d.ts +2064 -842
- package/dist/src/framework.d.ts.map +1 -1
- package/dist/src/framework.js +8586 -3739
- package/dist/src/framework.js.map +1 -1
- package/dist/src/gate/event-gate.d.ts +125 -21
- package/dist/src/gate/event-gate.d.ts.map +1 -1
- package/dist/src/gate/event-gate.js +487 -72
- package/dist/src/gate/event-gate.js.map +1 -1
- package/dist/src/gate/index.d.ts +1 -1
- package/dist/src/gate/index.d.ts.map +1 -1
- package/dist/src/gate/index.js.map +1 -1
- package/dist/src/gate/reply-judge.d.ts +4 -0
- package/dist/src/gate/reply-judge.d.ts.map +1 -1
- package/dist/src/gate/reply-judge.js +12 -3
- package/dist/src/gate/reply-judge.js.map +1 -1
- package/dist/src/gate/rule-scope.d.ts +30 -0
- package/dist/src/gate/rule-scope.d.ts.map +1 -0
- package/dist/src/gate/rule-scope.js +41 -0
- package/dist/src/gate/rule-scope.js.map +1 -0
- package/dist/src/gate/suppress-script-worker.d.ts +2 -0
- package/dist/src/gate/suppress-script-worker.d.ts.map +1 -0
- package/dist/src/gate/suppress-script-worker.js +103 -0
- package/dist/src/gate/suppress-script-worker.js.map +1 -0
- package/dist/src/gate/suppress-scripts.d.ts +105 -0
- package/dist/src/gate/suppress-scripts.d.ts.map +1 -0
- package/dist/src/gate/suppress-scripts.js +403 -0
- package/dist/src/gate/suppress-scripts.js.map +1 -0
- package/dist/src/gate/suppression-review.d.ts +143 -0
- package/dist/src/gate/suppression-review.d.ts.map +1 -0
- package/dist/src/gate/suppression-review.js +463 -0
- package/dist/src/gate/suppression-review.js.map +1 -0
- package/dist/src/gate/suppression-stats.d.ts +125 -0
- package/dist/src/gate/suppression-stats.d.ts.map +1 -0
- package/dist/src/gate/suppression-stats.js +214 -0
- package/dist/src/gate/suppression-stats.js.map +1 -0
- package/dist/src/gate/types.d.ts +142 -7
- package/dist/src/gate/types.d.ts.map +1 -1
- package/dist/src/gate/wake-onboarding.d.ts +119 -0
- package/dist/src/gate/wake-onboarding.d.ts.map +1 -0
- package/dist/src/gate/wake-onboarding.js +277 -0
- package/dist/src/gate/wake-onboarding.js.map +1 -0
- package/dist/src/heartbeat/heartbeat.js +1 -1
- package/dist/src/heartbeat/heartbeat.js.map +1 -1
- package/dist/src/held-writes.d.ts +31 -23
- package/dist/src/held-writes.d.ts.map +1 -1
- package/dist/src/held-writes.js +44 -59
- package/dist/src/held-writes.js.map +1 -1
- package/dist/src/index.d.ts +6 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/inference-bounds.d.ts +2 -1
- package/dist/src/inference-bounds.d.ts.map +1 -1
- package/dist/src/inference-bounds.js +9 -6
- package/dist/src/inference-bounds.js.map +1 -1
- package/dist/src/jsonrpc-envelope.d.ts +69 -0
- package/dist/src/jsonrpc-envelope.d.ts.map +1 -0
- package/dist/src/jsonrpc-envelope.js +66 -0
- package/dist/src/jsonrpc-envelope.js.map +1 -0
- package/dist/src/mcpl/channel-registry.d.ts +188 -28
- package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
- package/dist/src/mcpl/channel-registry.js +426 -70
- package/dist/src/mcpl/channel-registry.js.map +1 -1
- package/dist/src/mcpl/checkpoint-manager.d.ts +2 -4
- package/dist/src/mcpl/checkpoint-manager.d.ts.map +1 -1
- package/dist/src/mcpl/checkpoint-manager.js.map +1 -1
- package/dist/src/mcpl/feature-set-manager.d.ts +2 -4
- package/dist/src/mcpl/feature-set-manager.d.ts.map +1 -1
- package/dist/src/mcpl/feature-set-manager.js.map +1 -1
- package/dist/src/mcpl/inbound-source.d.ts +2 -1
- package/dist/src/mcpl/inbound-source.d.ts.map +1 -1
- package/dist/src/mcpl/inbound-source.js +2 -1
- package/dist/src/mcpl/inbound-source.js.map +1 -1
- package/dist/src/mcpl/inference-router.d.ts +6 -6
- package/dist/src/mcpl/inference-router.d.ts.map +1 -1
- package/dist/src/mcpl/inference-router.js.map +1 -1
- package/dist/src/mcpl/modern-connection.d.ts +109 -15
- package/dist/src/mcpl/modern-connection.d.ts.map +1 -1
- package/dist/src/mcpl/modern-connection.js +593 -86
- package/dist/src/mcpl/modern-connection.js.map +1 -1
- package/dist/src/mcpl/protocol-family.d.ts +3 -1
- package/dist/src/mcpl/protocol-family.d.ts.map +1 -1
- package/dist/src/mcpl/protocol-family.js +15 -9
- package/dist/src/mcpl/protocol-family.js.map +1 -1
- package/dist/src/mcpl/push-coalescer.d.ts +132 -22
- package/dist/src/mcpl/push-coalescer.d.ts.map +1 -1
- package/dist/src/mcpl/push-coalescer.js +105 -15
- package/dist/src/mcpl/push-coalescer.js.map +1 -1
- package/dist/src/mcpl/push-handler.d.ts +9 -7
- package/dist/src/mcpl/push-handler.d.ts.map +1 -1
- package/dist/src/mcpl/push-handler.js.map +1 -1
- package/dist/src/mcpl/server-connection.d.ts +50 -28
- package/dist/src/mcpl/server-connection.d.ts.map +1 -1
- package/dist/src/mcpl/server-connection.js +165 -72
- package/dist/src/mcpl/server-connection.js.map +1 -1
- package/dist/src/mcpl/tool-classes.d.ts.map +1 -1
- package/dist/src/mcpl/tool-classes.js +3 -0
- package/dist/src/mcpl/tool-classes.js.map +1 -1
- package/dist/src/mcpl/tool-presence.d.ts.map +1 -1
- package/dist/src/mcpl/tool-presence.js +10 -6
- package/dist/src/mcpl/tool-presence.js.map +1 -1
- package/dist/src/mcpl/toolset-host.d.ts.map +1 -1
- package/dist/src/mcpl/toolset-host.js +7 -6
- package/dist/src/mcpl/toolset-host.js.map +1 -1
- package/dist/src/mcpl/toolsets-module.d.ts.map +1 -1
- package/dist/src/mcpl/toolsets-module.js +2 -1
- package/dist/src/mcpl/toolsets-module.js.map +1 -1
- package/dist/src/mcpl/types.d.ts +33 -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 +24 -1
- package/dist/src/module-registry.d.ts.map +1 -1
- package/dist/src/module-registry.js +68 -18
- package/dist/src/module-registry.js.map +1 -1
- package/dist/src/modules/discord/index.d.ts +45 -8
- package/dist/src/modules/discord/index.d.ts.map +1 -1
- package/dist/src/modules/discord/index.js +238 -87
- package/dist/src/modules/discord/index.js.map +1 -1
- package/dist/src/modules/health/index.js +2 -2
- package/dist/src/modules/health/index.js.map +1 -1
- package/dist/src/modules/history/index.d.ts +59 -0
- package/dist/src/modules/history/index.d.ts.map +1 -1
- package/dist/src/modules/history/index.js +432 -67
- package/dist/src/modules/history/index.js.map +1 -1
- package/dist/src/modules/history/semantic.d.ts +6 -5
- package/dist/src/modules/history/semantic.d.ts.map +1 -1
- package/dist/src/modules/history/semantic.js +18 -25
- package/dist/src/modules/history/semantic.js.map +1 -1
- package/dist/src/modules/workspace/disk-agreement.d.ts +1 -1
- package/dist/src/modules/workspace/disk-agreement.js +1 -1
- package/dist/src/modules/workspace/index.d.ts +28 -7
- package/dist/src/modules/workspace/index.d.ts.map +1 -1
- package/dist/src/modules/workspace/index.js +80 -25
- package/dist/src/modules/workspace/index.js.map +1 -1
- package/dist/src/modules/workspace/observe.d.ts.map +1 -1
- package/dist/src/modules/workspace/observe.js +2 -1
- 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 +3 -2
- package/dist/src/modules/workspace/reconcile.js.map +1 -1
- package/dist/src/notice-tags.d.ts +20 -9
- package/dist/src/notice-tags.d.ts.map +1 -1
- package/dist/src/notice-tags.js +20 -9
- package/dist/src/notice-tags.js.map +1 -1
- package/dist/src/operator-log.d.ts +36 -3
- package/dist/src/operator-log.d.ts.map +1 -1
- package/dist/src/operator-log.js +2 -2
- package/dist/src/operator-log.js.map +1 -1
- package/dist/src/presentation.d.ts +747 -0
- package/dist/src/presentation.d.ts.map +1 -0
- package/dist/src/presentation.js +1437 -0
- package/dist/src/presentation.js.map +1 -0
- package/dist/src/prose-drafts.d.ts +15 -11
- package/dist/src/prose-drafts.d.ts.map +1 -1
- package/dist/src/prose-drafts.js +16 -12
- package/dist/src/prose-drafts.js.map +1 -1
- package/dist/src/read-marks.d.ts +192 -0
- package/dist/src/read-marks.d.ts.map +1 -0
- package/dist/src/read-marks.js +242 -0
- package/dist/src/read-marks.js.map +1 -0
- package/dist/src/reasoning-loss.d.ts +5 -0
- package/dist/src/reasoning-loss.d.ts.map +1 -0
- package/dist/src/reasoning-loss.js +8 -0
- package/dist/src/reasoning-loss.js.map +1 -0
- package/dist/src/recovery/offline-branch.d.ts +91 -6
- package/dist/src/recovery/offline-branch.d.ts.map +1 -1
- package/dist/src/recovery/offline-branch.js +277 -32
- package/dist/src/recovery/offline-branch.js.map +1 -1
- package/dist/src/recovery/recover-cli.js +24 -4
- package/dist/src/recovery/recover-cli.js.map +1 -1
- package/dist/src/send-tools.d.ts +5 -9
- package/dist/src/send-tools.d.ts.map +1 -1
- package/dist/src/send-tools.js +40 -7
- package/dist/src/send-tools.js.map +1 -1
- package/dist/src/sent-rows.js +1 -1
- package/dist/src/stored-injections.d.ts +2 -2
- package/dist/src/stored-injections.js +2 -2
- package/dist/src/stored-removal.d.ts +17 -4
- package/dist/src/stored-removal.d.ts.map +1 -1
- package/dist/src/stored-removal.js +29 -5
- package/dist/src/stored-removal.js.map +1 -1
- package/dist/src/supplied-text.d.ts +1 -1
- package/dist/src/supplied-text.js +3 -3
- package/dist/src/supplied-text.js.map +1 -1
- package/dist/src/thinking-drops.d.ts +2 -0
- package/dist/src/thinking-drops.d.ts.map +1 -1
- package/dist/src/thinking-drops.js.map +1 -1
- package/dist/src/tool-presentation.d.ts.map +1 -1
- package/dist/src/tool-presentation.js +38 -9
- package/dist/src/tool-presentation.js.map +1 -1
- package/dist/src/tool-result-guard.d.ts +12 -1
- package/dist/src/tool-result-guard.d.ts.map +1 -1
- package/dist/src/tool-result-guard.js +42 -8
- package/dist/src/tool-result-guard.js.map +1 -1
- package/dist/src/tune-out/coordinator.d.ts +1170 -81
- package/dist/src/tune-out/coordinator.d.ts.map +1 -1
- package/dist/src/tune-out/coordinator.js +3732 -369
- package/dist/src/tune-out/coordinator.js.map +1 -1
- package/dist/src/tune-out/tools.d.ts +114 -17
- package/dist/src/tune-out/tools.d.ts.map +1 -1
- package/dist/src/tune-out/tools.js +89 -28
- package/dist/src/tune-out/tools.js.map +1 -1
- package/dist/src/tune-out/window-anchor.d.ts +143 -0
- package/dist/src/tune-out/window-anchor.d.ts.map +1 -0
- package/dist/src/tune-out/window-anchor.js +202 -0
- package/dist/src/tune-out/window-anchor.js.map +1 -0
- package/dist/src/types/agent.d.ts +121 -25
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/events.d.ts +2 -0
- package/dist/src/types/events.d.ts.map +1 -1
- package/dist/src/types/framework.d.ts +72 -17
- package/dist/src/types/framework.d.ts.map +1 -1
- package/dist/src/types/inference-log.d.ts +1 -0
- package/dist/src/types/inference-log.d.ts.map +1 -1
- package/dist/src/types/module.d.ts +180 -69
- package/dist/src/types/module.d.ts.map +1 -1
- package/dist/src/types/trace.d.ts +573 -39
- package/dist/src/types/trace.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/admission/admit.ts +32 -3
- package/src/agent.ts +392 -132
- package/src/api/mcp-server-core.ts +54 -17
- package/src/api/server.ts +4 -23
- package/src/append-all.ts +6 -0
- package/src/code-execution/isolate/scripts.ts +28 -3
- package/src/config-checks.ts +14 -0
- package/src/context-manager-errors.ts +37 -0
- package/src/context-options.ts +106 -0
- package/src/cut-off-round.ts +4 -4
- package/src/deferred-import.ts +239 -0
- package/src/dendrite/audience.ts +315 -0
- package/src/dendrite/index.ts +14 -2
- package/src/dendrite/presets.ts +18 -6
- package/src/dendrite/registry.ts +213 -14
- package/src/dendrite/types.ts +92 -8
- package/src/failure-text.ts +88 -0
- package/src/foreign-rounds.ts +199 -0
- package/src/framework.ts +8796 -3813
- package/src/gate/event-gate.ts +518 -91
- package/src/gate/index.ts +3 -0
- package/src/gate/reply-judge.ts +12 -3
- package/src/gate/rule-scope.ts +45 -0
- package/src/gate/suppress-script-worker.ts +89 -0
- package/src/gate/suppress-scripts.ts +414 -0
- package/src/gate/suppression-review.ts +517 -0
- package/src/gate/suppression-stats.ts +314 -0
- package/src/gate/types.ts +148 -7
- package/src/gate/wake-onboarding.ts +309 -0
- package/src/heartbeat/heartbeat.ts +1 -1
- package/src/held-writes.ts +49 -60
- package/src/index.ts +10 -2
- package/src/inference-bounds.ts +11 -6
- package/src/jsonrpc-envelope.ts +81 -0
- package/src/mcpl/channel-registry.ts +513 -116
- package/src/mcpl/checkpoint-manager.ts +3 -2
- package/src/mcpl/feature-set-manager.ts +2 -1
- package/src/mcpl/inbound-source.ts +2 -1
- package/src/mcpl/inference-router.ts +7 -4
- package/src/mcpl/modern-connection.ts +629 -91
- package/src/mcpl/protocol-family.ts +15 -9
- package/src/mcpl/push-coalescer.ts +193 -34
- package/src/mcpl/push-handler.ts +10 -5
- package/src/mcpl/server-connection.ts +169 -75
- package/src/mcpl/tool-classes.ts +3 -0
- package/src/mcpl/tool-presence.ts +10 -5
- package/src/mcpl/toolset-host.ts +7 -6
- package/src/mcpl/toolsets-module.ts +2 -1
- package/src/mcpl/types.ts +33 -6
- package/src/module-registry.ts +73 -17
- package/src/modules/discord/index.ts +230 -82
- package/src/modules/health/index.ts +2 -2
- package/src/modules/history/index.ts +439 -70
- package/src/modules/history/semantic.ts +18 -24
- package/src/modules/workspace/disk-agreement.ts +1 -1
- package/src/modules/workspace/index.ts +89 -26
- package/src/modules/workspace/observe.ts +2 -1
- package/src/modules/workspace/reconcile.ts +3 -2
- package/src/notice-tags.ts +21 -9
- package/src/operator-log.ts +36 -3
- package/src/presentation.ts +1678 -0
- package/src/prose-drafts.ts +16 -12
- package/src/read-marks.ts +328 -0
- package/src/reasoning-loss.ts +7 -0
- package/src/recovery/offline-branch.ts +350 -35
- package/src/recovery/recover-cli.ts +23 -4
- package/src/send-tools.ts +40 -7
- package/src/sent-rows.ts +1 -1
- package/src/stored-injections.ts +2 -2
- package/src/stored-removal.ts +31 -7
- package/src/supplied-text.ts +3 -3
- package/src/thinking-drops.ts +2 -0
- package/src/tool-presentation.ts +34 -9
- package/src/tool-result-guard.ts +41 -7
- package/src/tune-out/coordinator.ts +4121 -472
- package/src/tune-out/tools.ts +162 -44
- package/src/tune-out/window-anchor.ts +277 -0
- package/src/types/agent.ts +122 -25
- package/src/types/events.ts +2 -0
- package/src/types/framework.ts +73 -17
- package/src/types/inference-log.ts +1 -0
- package/src/types/module.ts +181 -68
- package/src/types/trace.ts +607 -43
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Another agent's rounds as an agent that watches its slot is sent them
|
|
3
|
+
* (#291, answer 13).
|
|
4
|
+
*
|
|
5
|
+
* An agent reads another agent's rounds through an observe edge (decision
|
|
6
|
+
* 1), as the persistent subconscious watches the residents' slot, and an
|
|
7
|
+
* agent derived or forked from such a watcher inherits them, sent in its
|
|
8
|
+
* mode. A co-resident's rows stored before audience stamps, which a window
|
|
9
|
+
* written down from the record keeps, reach an agent that observes no one
|
|
10
|
+
* too: they go out as stored there, as earlier releases sent them. An agent
|
|
11
|
+
* sent others' rounds as a transcript is sent those as one, read by their
|
|
12
|
+
* participant.
|
|
13
|
+
* Those rounds are stored as the other agent's: its signed thinking, its
|
|
14
|
+
* tool calls and their results. None of that is valid as the watcher's own.
|
|
15
|
+
* A provider takes tool blocks only in their own pairing, in the turns of
|
|
16
|
+
* the agent that made the call, and a thinking block's signature binds it
|
|
17
|
+
* to the prefix the other agent was sent. Sent raw in a user turn, the
|
|
18
|
+
* blocks are refused, or moved into the watcher's assistant turns, where
|
|
19
|
+
* they read as calls the watcher made.
|
|
20
|
+
*
|
|
21
|
+
* So by default the watcher is sent them as a transcript, a line per block:
|
|
22
|
+
* a call as the tool's name and its input in brief, a result as the tool's
|
|
23
|
+
* name and its outcome in brief, and no thinking at all. Text, images and
|
|
24
|
+
* the rest go as stored. The signature forbids sending a thinking block as
|
|
25
|
+
* part of another prefix, not its text: leaving the text out is this
|
|
26
|
+
* transcript's choice. A host can have the rounds sent as stored instead
|
|
27
|
+
* (PersistentReaderConfig.foreignRounds `'raw'`, as 0.30.0 sent them). The rule is one function of the stored row, applied the same
|
|
28
|
+
* way to a compile's messages and to a row a tool boundary injects, so what
|
|
29
|
+
* the watcher's window holds and what its requests carried stay one thing.
|
|
30
|
+
*
|
|
31
|
+
* The watcher's own rows go as stored: its rounds (its own participant's
|
|
32
|
+
* messages), and the results of its own calls, which are stored under
|
|
33
|
+
* another participant (`user`) and are told by the call they answer: the
|
|
34
|
+
* nearest call before the result with its id, since a provider (or a mock)
|
|
35
|
+
* that numbers calls per response gives two agents' calls the same id.
|
|
36
|
+
*/
|
|
37
|
+
import type { ContentBlock, NormalizedMessage } from '@animalabs/membrane';
|
|
38
|
+
import { NOTICE_TAG } from './notice-tags.js';
|
|
39
|
+
import { cutToFit, markedTexts, oneLine } from './supplied-text.js';
|
|
40
|
+
|
|
41
|
+
/** How long one transcript line's call or outcome runs before it is cut. */
|
|
42
|
+
const BRIEF_CHARS = 160;
|
|
43
|
+
|
|
44
|
+
/** A piece of a transcript line's call or outcome, and whether the other
|
|
45
|
+
* agent supplied it (a call's input, a result's text) or the framework
|
|
46
|
+
* wrote it (a placeholder naming a result block's kind). */
|
|
47
|
+
interface Piece {
|
|
48
|
+
text: string;
|
|
49
|
+
supplied: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** `text` on one line: each line break the framework counts as one
|
|
53
|
+
* (oneLine), and each other run of whitespace, as one space. */
|
|
54
|
+
function flat(text: string): string {
|
|
55
|
+
return oneLine(text).replace(/\s+/g, ' ').trim();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** A tool result's content as pieces: its text, and its other blocks named
|
|
59
|
+
* by kind, in placeholders that are the framework's own. */
|
|
60
|
+
function resultPieces(content: string | ContentBlock[]): Piece[] {
|
|
61
|
+
if (typeof content === 'string') return [{ text: content, supplied: true }];
|
|
62
|
+
return content.map((b) => (b.type === 'text'
|
|
63
|
+
? { text: (b as { text: string }).text, supplied: true }
|
|
64
|
+
: { text: `[${b.type}]`, supplied: false }));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** A call's input as a piece: its JSON, or what the model sent when that
|
|
68
|
+
* wasn't an object. */
|
|
69
|
+
function callPiece(block: Extract<ContentBlock, { type: 'tool_use' }>): Piece {
|
|
70
|
+
if (block.unparseableInput !== undefined) return { text: block.unparseableInput, supplied: true };
|
|
71
|
+
try {
|
|
72
|
+
return { text: JSON.stringify(block.input ?? {}) ?? '', supplied: true };
|
|
73
|
+
} catch {
|
|
74
|
+
return { text: '', supplied: true };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A transcript line: the framework's bracket around the tool's name, which
|
|
80
|
+
* the other agent's call supplied, the framework's words for what happened
|
|
81
|
+
* (`words[0]` before a call or outcome, `words[1]` when there is none), and
|
|
82
|
+
* the call or outcome in brief. What the line holds is supplied text
|
|
83
|
+
* (#852): set inside the framework's bracket here, where a tool block's own
|
|
84
|
+
* content isn't, an opening of one of the framework's notices is marked
|
|
85
|
+
* wherever it forms, read across the whole line (markedTexts): inside a
|
|
86
|
+
* piece, across a result's blocks, or where the name meets the bracket or
|
|
87
|
+
* the framework's words. Those words and the placeholders aren't marked.
|
|
88
|
+
* Each piece goes on one line first (flat), and the call or outcome is cut
|
|
89
|
+
* to BRIEF_CHARS with an ellipsis, at a whole character, never parting a
|
|
90
|
+
* mark from its bracket (cutToFit).
|
|
91
|
+
*/
|
|
92
|
+
function transcriptLine(name: string, words: readonly [string, string], body: readonly Piece[]): string {
|
|
93
|
+
const pieces = body.map((p) => ({ ...p, text: flat(p.text) })).filter((p) => p.text.length > 0);
|
|
94
|
+
const word = pieces.length > 0 ? words[0] : words[1];
|
|
95
|
+
const marked = markedTexts(['[', oneLine(name), word, ...pieces.map((p) => p.text)], [true, true, false, ...pieces.map((p) => p.supplied)]);
|
|
96
|
+
const said = marked.slice(3).join(' ');
|
|
97
|
+
return `${marked.slice(0, 3).join('')}${said.length > BRIEF_CHARS ? `${cutToFit(said, BRIEF_CHARS - 1)}…` : said}]`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Where a row with nothing left to send stands, so the transcript keeps a row for each stored one. */
|
|
101
|
+
const NOTHING_SAID = `[${NOTICE_TAG.noText}]`;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* One stored row of another agent's as the watcher is sent it: thinking
|
|
105
|
+
* dropped, each call and each result a line of text, a text block's
|
|
106
|
+
* provider-native item (`rawItem`) dropped with it, everything else as it is.
|
|
107
|
+
* `ownCalls` are the watcher's own calls, whose results it is sent as they
|
|
108
|
+
* are; `callNames` names the calls the row's results answer, where the
|
|
109
|
+
* result doesn't name its tool itself. A row left with nothing says so in
|
|
110
|
+
* a line, rather than going empty.
|
|
111
|
+
*/
|
|
112
|
+
export function foreignRowAsSent(
|
|
113
|
+
content: readonly ContentBlock[],
|
|
114
|
+
context: { ownCalls?: { has(id: string): boolean }; callNames?: { get(id: string): string | undefined } } = {},
|
|
115
|
+
): ContentBlock[] {
|
|
116
|
+
let changed = false;
|
|
117
|
+
const out: ContentBlock[] = [];
|
|
118
|
+
for (const block of content) {
|
|
119
|
+
switch (block.type) {
|
|
120
|
+
case 'thinking':
|
|
121
|
+
case 'redacted_thinking':
|
|
122
|
+
changed = true;
|
|
123
|
+
break;
|
|
124
|
+
case 'tool_use': {
|
|
125
|
+
changed = true;
|
|
126
|
+
out.push({ type: 'text', text: transcriptLine(block.name, [' called: ', ' called: '], [callPiece(block)]) });
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
case 'tool_result': {
|
|
130
|
+
if (context.ownCalls?.has(block.toolUseId)) {
|
|
131
|
+
out.push(block);
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
changed = true;
|
|
135
|
+
const name = block.toolName ?? context.callNames?.get(block.toolUseId) ?? 'a tool';
|
|
136
|
+
const word = block.isError ? ' failed' : ' returned';
|
|
137
|
+
out.push({ type: 'text', text: transcriptLine(name, [`${word}: `, word], resultPieces(block.content)) });
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
case 'text': {
|
|
141
|
+
if ((block as { rawItem?: unknown }).rawItem === undefined) {
|
|
142
|
+
out.push(block);
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
changed = true;
|
|
146
|
+
if (block.text.length > 0) out.push({ type: 'text', text: block.text });
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
default:
|
|
150
|
+
out.push(block);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (!changed) return content as ContentBlock[];
|
|
154
|
+
return out.length > 0 ? out : [{ type: 'text', text: NOTHING_SAID }];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* A request's messages as an agent that watches another's slot is sent them:
|
|
159
|
+
* each message whose participant isn't the agent's own (`isOwn`) through
|
|
160
|
+
* foreignRowAsSent, with the results of the agent's own calls kept, and
|
|
161
|
+
* each result named by the call it answers. A result answers the nearest
|
|
162
|
+
* call before it with its id, read in one pass in order, so another
|
|
163
|
+
* agent's result whose id an own call of the watcher's also has, before or
|
|
164
|
+
* after it, is still transcribed. A call answers one result: a result after
|
|
165
|
+
* the one that answered it, in the same message or a later one, names no
|
|
166
|
+
* call (another agent's, whose call the request doesn't carry), and is
|
|
167
|
+
* transcribed. A message nothing changes is the same object, and so is the
|
|
168
|
+
* array when none changes.
|
|
169
|
+
*/
|
|
170
|
+
export function transcribeForeignRounds(
|
|
171
|
+
messages: readonly NormalizedMessage[],
|
|
172
|
+
isOwn: (participant: string) => boolean,
|
|
173
|
+
): NormalizedMessage[] {
|
|
174
|
+
const latest = new Map<string, { own: boolean; name: string }>();
|
|
175
|
+
// The watcher's own call is answered by the first result read for it,
|
|
176
|
+
// block by block: that result takes its entry, so a second result for it
|
|
177
|
+
// in the same message names no call.
|
|
178
|
+
const ownCalls = {
|
|
179
|
+
has: (id: string) => {
|
|
180
|
+
if (latest.get(id)?.own !== true) return false;
|
|
181
|
+
latest.delete(id);
|
|
182
|
+
return true;
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
const callNames = { get: (id: string) => latest.get(id)?.name };
|
|
186
|
+
let changed = false;
|
|
187
|
+
const out = messages.map((m) => {
|
|
188
|
+
const own = isOwn(m.participant);
|
|
189
|
+
for (const b of m.content) if (b.type === 'tool_use') latest.set(b.id, { own, name: b.name });
|
|
190
|
+
const content = own ? m.content : foreignRowAsSent(m.content, { ownCalls, callNames });
|
|
191
|
+
// A call answers one result: a later result with its id (another
|
|
192
|
+
// agent's, whose call the request doesn't carry) answers no call here.
|
|
193
|
+
for (const b of m.content) if (b.type === 'tool_result') latest.delete(b.toolUseId);
|
|
194
|
+
if (content === m.content) return m;
|
|
195
|
+
changed = true;
|
|
196
|
+
return { ...m, content };
|
|
197
|
+
});
|
|
198
|
+
return changed ? out : messages as NormalizedMessage[];
|
|
199
|
+
}
|