@animalabs/agent-framework 0.26.2 → 0.28.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 +99 -8
- package/dist/src/agent.d.ts +291 -23
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +596 -61
- package/dist/src/agent.js.map +1 -1
- package/dist/src/api/server.d.ts.map +1 -1
- package/dist/src/api/server.js +5 -4
- package/dist/src/api/server.js.map +1 -1
- package/dist/src/auto-continue.d.ts +34 -0
- package/dist/src/auto-continue.d.ts.map +1 -0
- package/dist/src/auto-continue.js +36 -0
- package/dist/src/auto-continue.js.map +1 -0
- package/dist/src/code-execution/isolate/scripts.d.ts +11 -0
- package/dist/src/code-execution/isolate/scripts.d.ts.map +1 -1
- package/dist/src/code-execution/isolate/scripts.js +5 -1
- package/dist/src/code-execution/isolate/scripts.js.map +1 -1
- package/dist/src/cut-off-round.d.ts +24 -0
- package/dist/src/cut-off-round.d.ts.map +1 -0
- package/dist/src/cut-off-round.js +87 -0
- package/dist/src/cut-off-round.js.map +1 -0
- package/dist/src/framework.d.ts +1038 -193
- package/dist/src/framework.d.ts.map +1 -1
- package/dist/src/framework.js +5967 -1514
- package/dist/src/framework.js.map +1 -1
- package/dist/src/gate/event-gate.d.ts +405 -46
- package/dist/src/gate/event-gate.d.ts.map +1 -1
- package/dist/src/gate/event-gate.js +2646 -399
- package/dist/src/gate/event-gate.js.map +1 -1
- package/dist/src/gate/index.d.ts +3 -2
- package/dist/src/gate/index.d.ts.map +1 -1
- package/dist/src/gate/index.js +2 -1
- package/dist/src/gate/index.js.map +1 -1
- package/dist/src/gate/recipe-reconcile.d.ts +103 -0
- package/dist/src/gate/recipe-reconcile.d.ts.map +1 -0
- package/dist/src/gate/recipe-reconcile.js +325 -0
- package/dist/src/gate/recipe-reconcile.js.map +1 -0
- package/dist/src/gate/reply-judge.d.ts +116 -0
- package/dist/src/gate/reply-judge.d.ts.map +1 -0
- package/dist/src/gate/reply-judge.js +467 -0
- package/dist/src/gate/reply-judge.js.map +1 -0
- package/dist/src/gate/types.d.ts +229 -8
- package/dist/src/gate/types.d.ts.map +1 -1
- package/dist/src/heartbeat/heartbeat.d.ts +184 -0
- package/dist/src/heartbeat/heartbeat.d.ts.map +1 -0
- package/dist/src/heartbeat/heartbeat.js +752 -0
- package/dist/src/heartbeat/heartbeat.js.map +1 -0
- package/dist/src/heartbeat/reminder-time.d.ts +5 -0
- package/dist/src/heartbeat/reminder-time.d.ts.map +1 -0
- package/dist/src/heartbeat/reminder-time.js +107 -0
- package/dist/src/heartbeat/reminder-time.js.map +1 -0
- package/dist/src/index.d.ts +10 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +7 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcpl/capability-mask.d.ts.map +1 -1
- package/dist/src/mcpl/capability-mask.js +3 -2
- package/dist/src/mcpl/capability-mask.js.map +1 -1
- package/dist/src/mcpl/channel-registry.d.ts +433 -113
- package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
- package/dist/src/mcpl/channel-registry.js +1154 -435
- package/dist/src/mcpl/channel-registry.js.map +1 -1
- package/dist/src/mcpl/conversation-router.d.ts +16 -8
- package/dist/src/mcpl/conversation-router.d.ts.map +1 -1
- package/dist/src/mcpl/conversation-router.js +29 -15
- 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 +14 -2
- package/dist/src/mcpl/convert-block.js.map +1 -1
- package/dist/src/mcpl/hook-orchestrator.d.ts +7 -1
- package/dist/src/mcpl/hook-orchestrator.d.ts.map +1 -1
- package/dist/src/mcpl/hook-orchestrator.js +32 -7
- package/dist/src/mcpl/hook-orchestrator.js.map +1 -1
- package/dist/src/mcpl/inbound-source.d.ts +26 -10
- package/dist/src/mcpl/inbound-source.d.ts.map +1 -1
- package/dist/src/mcpl/inbound-source.js +40 -69
- package/dist/src/mcpl/inbound-source.js.map +1 -1
- package/dist/src/mcpl/index.d.ts +5 -1
- package/dist/src/mcpl/index.d.ts.map +1 -1
- package/dist/src/mcpl/index.js +4 -0
- package/dist/src/mcpl/index.js.map +1 -1
- package/dist/src/mcpl/inference-router.d.ts +14 -2
- package/dist/src/mcpl/inference-router.d.ts.map +1 -1
- package/dist/src/mcpl/inference-router.js +73 -28
- package/dist/src/mcpl/inference-router.js.map +1 -1
- package/dist/src/mcpl/prose-grammar.d.ts +4 -0
- package/dist/src/mcpl/prose-grammar.d.ts.map +1 -1
- package/dist/src/mcpl/prose-grammar.js +6 -0
- package/dist/src/mcpl/prose-grammar.js.map +1 -1
- package/dist/src/mcpl/protocol-family.d.ts.map +1 -1
- package/dist/src/mcpl/protocol-family.js +3 -0
- package/dist/src/mcpl/protocol-family.js.map +1 -1
- package/dist/src/mcpl/push-coalescer.d.ts +20 -2
- package/dist/src/mcpl/push-coalescer.d.ts.map +1 -1
- package/dist/src/mcpl/push-coalescer.js +33 -11
- package/dist/src/mcpl/push-coalescer.js.map +1 -1
- package/dist/src/mcpl/reference-fetcher.d.ts +63 -42
- package/dist/src/mcpl/reference-fetcher.d.ts.map +1 -1
- package/dist/src/mcpl/reference-fetcher.js +177 -145
- package/dist/src/mcpl/reference-fetcher.js.map +1 -1
- package/dist/src/mcpl/references.d.ts +380 -46
- package/dist/src/mcpl/references.d.ts.map +1 -1
- package/dist/src/mcpl/references.js +736 -77
- package/dist/src/mcpl/references.js.map +1 -1
- package/dist/src/mcpl/server-connection.d.ts +93 -4
- package/dist/src/mcpl/server-connection.d.ts.map +1 -1
- package/dist/src/mcpl/server-connection.js +176 -11
- package/dist/src/mcpl/server-connection.js.map +1 -1
- package/dist/src/mcpl/tags.d.ts +9 -2
- package/dist/src/mcpl/tags.d.ts.map +1 -1
- package/dist/src/mcpl/tags.js +12 -2
- package/dist/src/mcpl/tags.js.map +1 -1
- package/dist/src/mcpl/tool-lifecycle.d.ts +11 -0
- package/dist/src/mcpl/tool-lifecycle.d.ts.map +1 -1
- package/dist/src/mcpl/tool-lifecycle.js +21 -0
- package/dist/src/mcpl/tool-lifecycle.js.map +1 -1
- package/dist/src/mcpl/tool-presence.d.ts +311 -0
- package/dist/src/mcpl/tool-presence.d.ts.map +1 -0
- package/dist/src/mcpl/tool-presence.js +697 -0
- package/dist/src/mcpl/tool-presence.js.map +1 -0
- package/dist/src/mcpl/tool-result-normalize.d.ts +9 -3
- package/dist/src/mcpl/tool-result-normalize.d.ts.map +1 -1
- package/dist/src/mcpl/tool-result-normalize.js +14 -6
- package/dist/src/mcpl/tool-result-normalize.js.map +1 -1
- package/dist/src/mcpl/tool-signature.d.ts +46 -0
- package/dist/src/mcpl/tool-signature.d.ts.map +1 -0
- package/dist/src/mcpl/tool-signature.js +321 -0
- package/dist/src/mcpl/tool-signature.js.map +1 -0
- package/dist/src/mcpl/toolset-host.d.ts +251 -0
- package/dist/src/mcpl/toolset-host.d.ts.map +1 -0
- package/dist/src/mcpl/toolset-host.js +720 -0
- package/dist/src/mcpl/toolset-host.js.map +1 -0
- package/dist/src/mcpl/toolsets-module.d.ts +83 -0
- package/dist/src/mcpl/toolsets-module.d.ts.map +1 -0
- package/dist/src/mcpl/toolsets-module.js +523 -0
- package/dist/src/mcpl/toolsets-module.js.map +1 -0
- package/dist/src/mcpl/transport.d.ts +2 -2
- package/dist/src/mcpl/transport.d.ts.map +1 -1
- package/dist/src/mcpl/transport.js +3 -2
- package/dist/src/mcpl/transport.js.map +1 -1
- package/dist/src/mcpl/types.d.ts +24 -2
- package/dist/src/mcpl/types.d.ts.map +1 -1
- package/dist/src/mcpl/types.js.map +1 -1
- package/dist/src/mcpl/visible-content.d.ts +7 -9
- package/dist/src/mcpl/visible-content.d.ts.map +1 -1
- package/dist/src/mcpl/visible-content.js +21 -9
- package/dist/src/mcpl/visible-content.js.map +1 -1
- package/dist/src/module-registry.d.ts +27 -9
- package/dist/src/module-registry.d.ts.map +1 -1
- package/dist/src/module-registry.js +77 -17
- package/dist/src/module-registry.js.map +1 -1
- package/dist/src/modules/discord/index.js +1 -1
- package/dist/src/modules/discord/index.js.map +1 -1
- package/dist/src/modules/history/index.d.ts +2 -1
- package/dist/src/modules/history/index.d.ts.map +1 -1
- package/dist/src/modules/history/index.js +73 -28
- package/dist/src/modules/history/index.js.map +1 -1
- package/dist/src/modules/history/semantic.d.ts +108 -6
- package/dist/src/modules/history/semantic.d.ts.map +1 -1
- package/dist/src/modules/history/semantic.js +273 -57
- package/dist/src/modules/history/semantic.js.map +1 -1
- package/dist/src/modules/workspace/answers.d.ts +22 -0
- package/dist/src/modules/workspace/answers.d.ts.map +1 -0
- package/dist/src/modules/workspace/answers.js +123 -0
- package/dist/src/modules/workspace/answers.js.map +1 -0
- package/dist/src/modules/workspace/branch-intent.d.ts +5 -3
- package/dist/src/modules/workspace/branch-intent.d.ts.map +1 -1
- package/dist/src/modules/workspace/branch-intent.js +6 -2
- package/dist/src/modules/workspace/branch-intent.js.map +1 -1
- package/dist/src/modules/workspace/direct-write.d.ts +184 -0
- package/dist/src/modules/workspace/direct-write.d.ts.map +1 -0
- package/dist/src/modules/workspace/direct-write.js +417 -0
- package/dist/src/modules/workspace/direct-write.js.map +1 -0
- package/dist/src/modules/workspace/disk-agreement.d.ts +33 -11
- package/dist/src/modules/workspace/disk-agreement.d.ts.map +1 -1
- package/dist/src/modules/workspace/disk-agreement.js +48 -17
- package/dist/src/modules/workspace/disk-agreement.js.map +1 -1
- package/dist/src/modules/workspace/edit-text.d.ts +27 -12
- package/dist/src/modules/workspace/edit-text.d.ts.map +1 -1
- package/dist/src/modules/workspace/edit-text.js +61 -29
- package/dist/src/modules/workspace/edit-text.js.map +1 -1
- package/dist/src/modules/workspace/effects.d.ts +10 -0
- package/dist/src/modules/workspace/effects.d.ts.map +1 -1
- package/dist/src/modules/workspace/effects.js +21 -14
- package/dist/src/modules/workspace/effects.js.map +1 -1
- package/dist/src/modules/workspace/index.d.ts +308 -78
- package/dist/src/modules/workspace/index.d.ts.map +1 -1
- package/dist/src/modules/workspace/index.js +2103 -720
- package/dist/src/modules/workspace/index.js.map +1 -1
- package/dist/src/modules/workspace/observe.d.ts +75 -63
- package/dist/src/modules/workspace/observe.d.ts.map +1 -1
- package/dist/src/modules/workspace/observe.js +366 -180
- package/dist/src/modules/workspace/observe.js.map +1 -1
- package/dist/src/modules/workspace/read-page.d.ts +41 -0
- package/dist/src/modules/workspace/read-page.d.ts.map +1 -0
- package/dist/src/modules/workspace/read-page.js +219 -0
- package/dist/src/modules/workspace/read-page.js.map +1 -0
- package/dist/src/modules/workspace/reconcile.d.ts.map +1 -1
- package/dist/src/modules/workspace/reconcile.js +26 -16
- package/dist/src/modules/workspace/reconcile.js.map +1 -1
- package/dist/src/modules/workspace/result-text.d.ts +68 -0
- package/dist/src/modules/workspace/result-text.d.ts.map +1 -0
- package/dist/src/modules/workspace/result-text.js +94 -0
- package/dist/src/modules/workspace/result-text.js.map +1 -0
- package/dist/src/modules/workspace/sync.d.ts +9 -0
- package/dist/src/modules/workspace/sync.d.ts.map +1 -1
- package/dist/src/modules/workspace/sync.js +14 -0
- package/dist/src/modules/workspace/sync.js.map +1 -1
- package/dist/src/modules/workspace/text.d.ts +29 -12
- package/dist/src/modules/workspace/text.d.ts.map +1 -1
- package/dist/src/modules/workspace/text.js +35 -33
- package/dist/src/modules/workspace/text.js.map +1 -1
- package/dist/src/modules/workspace/types.d.ts +137 -60
- 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.map +1 -1
- package/dist/src/modules/workspace/watcher.js +8 -3
- package/dist/src/modules/workspace/watcher.js.map +1 -1
- package/dist/src/prose-drafts.d.ts +4 -3
- package/dist/src/prose-drafts.d.ts.map +1 -1
- package/dist/src/prose-drafts.js +3 -2
- package/dist/src/prose-drafts.js.map +1 -1
- package/dist/src/reasoning-loss-notice.d.ts +23 -0
- package/dist/src/reasoning-loss-notice.d.ts.map +1 -0
- package/dist/src/reasoning-loss-notice.js +50 -0
- package/dist/src/reasoning-loss-notice.js.map +1 -0
- package/dist/src/reasoning-loss.d.ts +24 -0
- package/dist/src/reasoning-loss.d.ts.map +1 -0
- package/dist/src/reasoning-loss.js +102 -0
- package/dist/src/reasoning-loss.js.map +1 -0
- package/dist/src/send-tools.d.ts +3 -2
- package/dist/src/send-tools.d.ts.map +1 -1
- package/dist/src/send-tools.js +3 -2
- package/dist/src/send-tools.js.map +1 -1
- package/dist/src/sent-rows.d.ts +59 -0
- package/dist/src/sent-rows.d.ts.map +1 -0
- package/dist/src/sent-rows.js +145 -0
- package/dist/src/sent-rows.js.map +1 -0
- package/dist/src/silent-heartbeat.d.ts +17 -10
- package/dist/src/silent-heartbeat.d.ts.map +1 -1
- package/dist/src/silent-heartbeat.js.map +1 -1
- package/dist/src/stable-hash.d.ts +3 -0
- package/dist/src/stable-hash.d.ts.map +1 -0
- package/dist/src/stable-hash.js +15 -0
- package/dist/src/stable-hash.js.map +1 -0
- package/dist/src/stored-injections.d.ts +99 -0
- package/dist/src/stored-injections.d.ts.map +1 -0
- package/dist/src/stored-injections.js +106 -0
- package/dist/src/stored-injections.js.map +1 -0
- package/dist/src/text-as-stored.d.ts +4 -3
- package/dist/src/text-as-stored.d.ts.map +1 -1
- package/dist/src/text-as-stored.js +4 -3
- package/dist/src/text-as-stored.js.map +1 -1
- package/dist/src/thinking-drops.d.ts +74 -0
- package/dist/src/thinking-drops.d.ts.map +1 -0
- package/dist/src/thinking-drops.js +96 -0
- package/dist/src/thinking-drops.js.map +1 -0
- package/dist/src/tool-args.d.ts +12 -0
- package/dist/src/tool-args.d.ts.map +1 -1
- package/dist/src/tool-args.js +35 -1
- package/dist/src/tool-args.js.map +1 -1
- package/dist/src/tool-image-ledger.d.ts +9 -8
- package/dist/src/tool-image-ledger.d.ts.map +1 -1
- package/dist/src/tool-image-ledger.js +9 -8
- package/dist/src/tool-image-ledger.js.map +1 -1
- package/dist/src/tool-presentation.d.ts.map +1 -1
- package/dist/src/tool-presentation.js +3 -1
- package/dist/src/tool-presentation.js.map +1 -1
- package/dist/src/tool-result-guard.d.ts +12 -6
- package/dist/src/tool-result-guard.d.ts.map +1 -1
- package/dist/src/tool-result-guard.js +44 -17
- package/dist/src/tool-result-guard.js.map +1 -1
- package/dist/src/tool-result-history.d.ts +176 -24
- package/dist/src/tool-result-history.d.ts.map +1 -1
- package/dist/src/tool-result-history.js +411 -91
- package/dist/src/tool-result-history.js.map +1 -1
- package/dist/src/tune-out/coordinator.d.ts +17 -9
- package/dist/src/tune-out/coordinator.d.ts.map +1 -1
- package/dist/src/tune-out/coordinator.js +84 -37
- package/dist/src/tune-out/coordinator.js.map +1 -1
- package/dist/src/tune-out/tools.d.ts +4 -1
- package/dist/src/tune-out/tools.d.ts.map +1 -1
- package/dist/src/types/agent.d.ts +217 -7
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/events.d.ts +33 -9
- package/dist/src/types/events.d.ts.map +1 -1
- package/dist/src/types/framework.d.ts +39 -3
- package/dist/src/types/framework.d.ts.map +1 -1
- package/dist/src/types/module.d.ts +95 -9
- package/dist/src/types/module.d.ts.map +1 -1
- package/dist/src/types/trace.d.ts +91 -3
- package/dist/src/types/trace.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/agent.ts +661 -67
- package/src/api/server.ts +5 -4
- package/src/auto-continue.ts +43 -0
- package/src/code-execution/isolate/scripts.ts +11 -3
- package/src/cut-off-round.ts +98 -0
- package/src/framework.ts +6168 -1540
- package/src/gate/event-gate.ts +2895 -405
- package/src/gate/index.ts +10 -1
- package/src/gate/recipe-reconcile.ts +355 -0
- package/src/gate/reply-judge.ts +512 -0
- package/src/gate/types.ts +234 -9
- package/src/heartbeat/heartbeat.ts +804 -0
- package/src/heartbeat/reminder-time.ts +107 -0
- package/src/index.ts +11 -4
- package/src/mcpl/capability-mask.ts +3 -2
- package/src/mcpl/channel-registry.ts +1222 -468
- package/src/mcpl/conversation-router.ts +34 -16
- package/src/mcpl/convert-block.ts +14 -1
- package/src/mcpl/hook-orchestrator.ts +33 -6
- package/src/mcpl/inbound-source.ts +42 -69
- package/src/mcpl/index.ts +6 -1
- package/src/mcpl/inference-router.ts +79 -34
- package/src/mcpl/prose-grammar.ts +7 -0
- package/src/mcpl/protocol-family.ts +2 -0
- package/src/mcpl/push-coalescer.ts +51 -13
- package/src/mcpl/reference-fetcher.ts +201 -162
- package/src/mcpl/references.ts +851 -77
- package/src/mcpl/server-connection.ts +189 -11
- package/src/mcpl/tags.ts +13 -2
- package/src/mcpl/tool-lifecycle.ts +21 -0
- package/src/mcpl/tool-presence.ts +716 -0
- package/src/mcpl/tool-result-normalize.ts +18 -6
- package/src/mcpl/tool-signature.ts +316 -0
- package/src/mcpl/toolset-host.ts +727 -0
- package/src/mcpl/toolsets-module.ts +545 -0
- package/src/mcpl/transport.ts +3 -2
- package/src/mcpl/types.ts +25 -2
- package/src/mcpl/visible-content.ts +22 -9
- package/src/module-registry.ts +85 -26
- package/src/modules/discord/index.ts +1 -1
- package/src/modules/history/index.ts +70 -30
- package/src/modules/history/semantic.ts +308 -54
- package/src/modules/workspace/answers.ts +133 -0
- package/src/modules/workspace/branch-intent.ts +10 -5
- package/src/modules/workspace/direct-write.ts +460 -0
- package/src/modules/workspace/disk-agreement.ts +52 -21
- package/src/modules/workspace/edit-text.ts +84 -35
- package/src/modules/workspace/effects.ts +22 -13
- package/src/modules/workspace/index.ts +2142 -723
- package/src/modules/workspace/observe.ts +381 -177
- package/src/modules/workspace/read-page.ts +228 -0
- package/src/modules/workspace/reconcile.ts +27 -15
- package/src/modules/workspace/result-text.ts +121 -0
- package/src/modules/workspace/sync.ts +16 -0
- package/src/modules/workspace/text.ts +58 -32
- package/src/modules/workspace/types.ts +137 -60
- package/src/modules/workspace/watcher.ts +8 -3
- package/src/prose-drafts.ts +4 -3
- package/src/reasoning-loss-notice.ts +62 -0
- package/src/reasoning-loss.ts +120 -0
- package/src/send-tools.ts +3 -2
- package/src/sent-rows.ts +162 -0
- package/src/silent-heartbeat.ts +17 -10
- package/src/stable-hash.ts +14 -0
- package/src/stored-injections.ts +131 -0
- package/src/text-as-stored.ts +4 -3
- package/src/thinking-drops.ts +135 -0
- package/src/tool-args.ts +34 -1
- package/src/tool-image-ledger.ts +9 -8
- package/src/tool-presentation.ts +3 -1
- package/src/tool-result-guard.ts +45 -17
- package/src/tool-result-history.ts +471 -90
- package/src/tune-out/coordinator.ts +80 -37
- package/src/tune-out/tools.ts +4 -1
- package/src/types/agent.ts +220 -7
- package/src/types/events.ts +33 -9
- package/src/types/framework.ts +36 -3
- package/src/types/module.ts +91 -9
- package/src/types/trace.ts +94 -3
package/src/api/server.ts
CHANGED
|
@@ -518,8 +518,7 @@ export class ApiServer {
|
|
|
518
518
|
const contextManager = agent.getContextManager();
|
|
519
519
|
// A dry run: listed, never sent, so it persists no fold resolutions and
|
|
520
520
|
// queues none of the compression its fold plan calls for (see
|
|
521
|
-
// Agent.compileWithInjections for what a dry run still leaves
|
|
522
|
-
// context-manager#160's thinking binding).
|
|
521
|
+
// Agent.compileWithInjections for what a dry run still leaves).
|
|
523
522
|
const { messages } = await contextManager.compile(undefined, undefined, { dryRun: true });
|
|
524
523
|
|
|
525
524
|
const limit = params?.limit ?? 50;
|
|
@@ -650,7 +649,8 @@ export class ApiServer {
|
|
|
650
649
|
throw new Error('agentName is required');
|
|
651
650
|
}
|
|
652
651
|
|
|
653
|
-
const result = this.framework.undoLastTurn(params.agentName);
|
|
652
|
+
const { settled, ...result } = this.framework.undoLastTurn(params.agentName);
|
|
653
|
+
await settled;
|
|
654
654
|
|
|
655
655
|
if (result.undone) {
|
|
656
656
|
this.broadcast('branch:switched', {
|
|
@@ -668,7 +668,8 @@ export class ApiServer {
|
|
|
668
668
|
throw new Error('agentName is required');
|
|
669
669
|
}
|
|
670
670
|
|
|
671
|
-
const result = this.framework.redo(params.agentName);
|
|
671
|
+
const { settled, ...result } = this.framework.redo(params.agentName);
|
|
672
|
+
await settled;
|
|
672
673
|
|
|
673
674
|
if (result.redone) {
|
|
674
675
|
this.broadcast('branch:switched', {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* autoContinue (AgentConfig.autoContinue, docs/auto-continue.md): a turn the
|
|
3
|
+
* model ends itself is followed by another, unless it ended on a skip. This
|
|
4
|
+
* module holds what doesn't need the framework: which ends continue, and the
|
|
5
|
+
* row the next turn reads.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** The reason on a continuation's wake (InferenceRequest.reason). */
|
|
9
|
+
export const AUTO_CONTINUE_REASON = 'auto-continue';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Stop reasons of a turn the model ended itself. The others don't continue:
|
|
13
|
+
* a refusal has its own handling (retries, rewind, the reaction), a
|
|
14
|
+
* `max_tokens` end was cut off rather than chosen, and `no_progress` and
|
|
15
|
+
* `round_limit` are the stall guard's verdict that the turn wasn't moving.
|
|
16
|
+
*/
|
|
17
|
+
export const AUTO_CONTINUE_STOP_REASONS: ReadonlySet<string> = new Set(['end_turn', 'stop_sequence']);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The row a continuation's turn reads. It names the agent (residents read
|
|
21
|
+
* one shared message slot), says another turn starts, says how to stop
|
|
22
|
+
* (`stop`, an imperative such as "call skip_reply") and that anything written
|
|
23
|
+
* without it is sent as usual, and, on the last continuation of a run, that
|
|
24
|
+
* the agent waits for the next event after it. When some or all of the last
|
|
25
|
+
* turn's closing words were held because a send that turn may already have
|
|
26
|
+
* posted where they were going, it says so. Short,
|
|
27
|
+
* neutral and event-shaped on purpose: it rides as a system row in the
|
|
28
|
+
* window, where instruction blocks about output have tripped classifiers,
|
|
29
|
+
* and wording that reads as a lapse or a budget invites a published reply.
|
|
30
|
+
*/
|
|
31
|
+
export function autoContinueNotice(opts: {
|
|
32
|
+
agentName: string;
|
|
33
|
+
stop: string;
|
|
34
|
+
last: boolean;
|
|
35
|
+
heldAfterSend?: boolean;
|
|
36
|
+
}): string {
|
|
37
|
+
return `[continue] ${opts.agentName}, another turn starts now.` +
|
|
38
|
+
(opts.heldAfterSend
|
|
39
|
+
? ' Some or all of your closing words last turn were held, not sent: a send that turn may already have posted where they were going.'
|
|
40
|
+
: '') +
|
|
41
|
+
` If you're done, ${opts.stop}; anything you write without it is sent as usual.` +
|
|
42
|
+
(opts.last ? ' This is the last continuation in a row: after this turn you wait for the next event either way.' : '');
|
|
43
|
+
}
|
|
@@ -46,6 +46,10 @@ export interface ScriptCallContext {
|
|
|
46
46
|
watch?: ScriptWatch;
|
|
47
47
|
/** The call watching the script now, if one is: a result that ends the turn ends it at that call's return. Without it, `watch`. */
|
|
48
48
|
watching?(): ScriptWatch | undefined;
|
|
49
|
+
/** The turn the script's run call was made in, when one was: the turn its words were written in, which a later turn's wait doesn't change. */
|
|
50
|
+
startTurnId?: number;
|
|
51
|
+
/** What its agent had read when the run call started the script (the host's consumed watermark), given at run: what the script's words were written having read, which a later round's wait doesn't change. */
|
|
52
|
+
startReadThrough?: { branch: string; sequence: number } | null;
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
export interface ScriptsHost {
|
|
@@ -113,7 +117,7 @@ interface Script {
|
|
|
113
117
|
/** The code it runs. */
|
|
114
118
|
code: string;
|
|
115
119
|
run: ScriptRun;
|
|
116
|
-
context: { origin?: unknown };
|
|
120
|
+
context: { origin?: unknown; startReadThrough?: { branch: string; sequence: number } | null };
|
|
117
121
|
/** The turn its run call was made in, when one was: its agent's turns end it by that. */
|
|
118
122
|
turnId: number | undefined;
|
|
119
123
|
startedAt: number;
|
|
@@ -176,7 +180,7 @@ export class AgentScripts {
|
|
|
176
180
|
agentName: string,
|
|
177
181
|
code: string,
|
|
178
182
|
askedMs?: number,
|
|
179
|
-
options: { origin?: unknown; watch?: ScriptWatch } = {},
|
|
183
|
+
options: { origin?: unknown; watch?: ScriptWatch; startReadThrough?: { branch: string; sequence: number } | null } = {},
|
|
180
184
|
): Promise<ScriptReturn> {
|
|
181
185
|
// Listed first, so a module whose tool list throws refuses the run with nothing taken.
|
|
182
186
|
let tools: readonly PreludeTool[];
|
|
@@ -202,7 +206,10 @@ export class AgentScripts {
|
|
|
202
206
|
agentName,
|
|
203
207
|
code,
|
|
204
208
|
run: null as unknown as ScriptRun,
|
|
205
|
-
context:
|
|
209
|
+
context: {
|
|
210
|
+
...(options.origin === undefined ? {} : { origin: options.origin }),
|
|
211
|
+
...(options.startReadThrough === undefined ? {} : { startReadThrough: options.startReadThrough }),
|
|
212
|
+
},
|
|
206
213
|
turnId: options.watch?.turnId,
|
|
207
214
|
startedAt: Date.now(),
|
|
208
215
|
endedAt: null,
|
|
@@ -231,6 +238,7 @@ export class AgentScripts {
|
|
|
231
238
|
...script.context,
|
|
232
239
|
...(script.watch ? { watch: script.watch } : {}),
|
|
233
240
|
watching: () => script.watch ?? undefined,
|
|
241
|
+
...(script.turnId !== undefined ? { startTurnId: script.turnId } : {}),
|
|
234
242
|
}),
|
|
235
243
|
onWake: (payload, n) => this.wake(script, payload, n),
|
|
236
244
|
onEnd: (ending) => this.ended(script, ending),
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import type { ContentBlock, NormalizedResponse } from '@animalabs/membrane';
|
|
3
|
+
|
|
4
|
+
export interface CutOffCall {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
input: Record<string, unknown>;
|
|
8
|
+
unparseableInput?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface CutOffRound {
|
|
12
|
+
content: ContentBlock[];
|
|
13
|
+
start: number;
|
|
14
|
+
calls: CutOffCall[];
|
|
15
|
+
unnamed: boolean;
|
|
16
|
+
xml: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The last round of a response that ended at the output limit, when it holds
|
|
21
|
+
* calls that never ran, or, in XML tool mode, a tool-call block cut off before
|
|
22
|
+
* any call in it was named (`unnamed`). Membrane yields a round's calls only
|
|
23
|
+
* at its tool_use stop, or in XML tool mode at its `</function_calls>` stop,
|
|
24
|
+
* and the round begins after the last result that answers one of the
|
|
25
|
+
* response's calls.
|
|
26
|
+
*/
|
|
27
|
+
export function cutOffRound(response: NormalizedResponse): CutOffRound | undefined {
|
|
28
|
+
if (response.stopReason !== 'max_tokens') return undefined;
|
|
29
|
+
const callIds = new Set<string>();
|
|
30
|
+
let start = 0;
|
|
31
|
+
response.content.forEach((block, index) => {
|
|
32
|
+
if (block.type === 'tool_use') callIds.add(block.id);
|
|
33
|
+
else if (block.type === 'tool_result' && callIds.has(block.toolUseId)) start = index + 1;
|
|
34
|
+
});
|
|
35
|
+
const cut = response.details?.stop?.unclosedToolBlock ? cutToolBlock(response.content, start) : undefined;
|
|
36
|
+
const content = cut ?? response.content;
|
|
37
|
+
const uses = content.slice(start).filter((block): block is ContentBlock & { type: 'tool_use' } => block.type === 'tool_use');
|
|
38
|
+
const calls = uses.map(({ id, name, input, unparseableInput }) => ({
|
|
39
|
+
id, name, input,
|
|
40
|
+
...(unparseableInput !== undefined ? { unparseableInput } : {}),
|
|
41
|
+
}));
|
|
42
|
+
const unnamed = !!cut && calls.length === 0;
|
|
43
|
+
const xml = !!cut || uses.some((block) => (block as { rawXml?: string }).rawXml !== undefined);
|
|
44
|
+
return calls.length > 0 || unnamed ? { content, start, calls, unnamed, xml } : undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Membrane 0.8.0's grammar (unchanged from 0.7.2) for the anthropic-xml
|
|
49
|
+
* formatter's XML tool mode. Membrane exports two of its predicates,
|
|
50
|
+
* hasUnclosedToolBlock and endsWithPartialToolBlock, but not the grammar
|
|
51
|
+
* itself (dist/utils/tool-parser.js, INVOKE_REGEX): a block opens
|
|
52
|
+
* with `<function_calls>` and each call with `<invoke name="…">`, either tag
|
|
53
|
+
* optionally `antml:` prefixed, and a closer ends the innermost block still
|
|
54
|
+
* open. Its parser takes spans out of an unclosed block's text, which leaves
|
|
55
|
+
* that text in several text blocks: thinking, which stays with the round, a
|
|
56
|
+
* whole inner block its stop sequence didn't end, whose calls are the round's
|
|
57
|
+
* too, and results, which don't stay. Only a block's opener
|
|
58
|
+
* and each call's name head are read, nothing after a name, and a name that
|
|
59
|
+
* isn't a tool name's characters isn't taken as one: the formatter writes a
|
|
60
|
+
* stored call's name into the next request as it is.
|
|
61
|
+
*/
|
|
62
|
+
const OPENER = /<(antml:)?function_calls(>|[^>]*$)/g;
|
|
63
|
+
const CLOSER = /<\/(antml:)?function_calls>/g;
|
|
64
|
+
const NAME_HEAD = /<(antml:)?invoke\s+name=(["'])((?:(?!\2).)+)\2\s*\/?>/g;
|
|
65
|
+
const TOOL_NAME = /^[A-Za-z0-9_.:-]{1,128}$/;
|
|
66
|
+
|
|
67
|
+
function cutToolBlock(content: ContentBlock[], start: number): ContentBlock[] | undefined {
|
|
68
|
+
const texts = content.map((block, index) => ({ block, index }))
|
|
69
|
+
.filter((entry): entry is { block: ContentBlock & { type: 'text' }; index: number } => entry.index >= start && entry.block.type === 'text');
|
|
70
|
+
const joined = texts.map(({ block }) => block.text).join('');
|
|
71
|
+
const tags = [
|
|
72
|
+
...[...joined.matchAll(OPENER)].map((match) => ({ index: match.index, opens: true })),
|
|
73
|
+
...[...joined.matchAll(CLOSER)].map((match) => ({ index: match.index, opens: false })),
|
|
74
|
+
].sort((a, b) => a.index - b.index);
|
|
75
|
+
const open: number[] = [];
|
|
76
|
+
for (const tag of tags) {
|
|
77
|
+
if (tag.opens) open.push(tag.index);
|
|
78
|
+
else open.pop();
|
|
79
|
+
}
|
|
80
|
+
if (open.length === 0) return undefined;
|
|
81
|
+
const opener = open[0]!;
|
|
82
|
+
let at = opener;
|
|
83
|
+
const holder = texts.find(({ block }) => {
|
|
84
|
+
if (at < block.text.length) return true;
|
|
85
|
+
at -= block.text.length;
|
|
86
|
+
return false;
|
|
87
|
+
})!;
|
|
88
|
+
const blockText = joined.slice(opener);
|
|
89
|
+
const heads = [...blockText.matchAll(NAME_HEAD)].filter((head) => TOOL_NAME.test(head[3]!));
|
|
90
|
+
const calls: ContentBlock[] = heads.map((head, index) => ({
|
|
91
|
+
type: 'tool_use', id: `tool_${randomUUID()}`, name: head[3]!, input: {},
|
|
92
|
+
unparseableInput: blockText.slice(head.index, heads[index + 1]?.index),
|
|
93
|
+
}));
|
|
94
|
+
const prose: ContentBlock[] = at > 0 ? [{ type: 'text', text: holder.block.text.slice(0, at) }] : [];
|
|
95
|
+
const kept = content.slice(holder.index + 1)
|
|
96
|
+
.filter((block) => block.type === 'thinking' || block.type === 'redacted_thinking' || block.type === 'tool_use');
|
|
97
|
+
return [...content.slice(0, holder.index), ...prose, ...kept, ...calls];
|
|
98
|
+
}
|