@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
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
*/
|
|
36
36
|
import type { ContextStrategy } from '@animalabs/context-manager';
|
|
37
37
|
import type { ChannelDescriptor } from './types.js';
|
|
38
|
+
import { type ChannelRef } from './channel-registry.js';
|
|
38
39
|
/** When an unbound channel acquires a fork. */
|
|
39
40
|
export type BindRule = 'always' | 'mention' | 'never';
|
|
40
41
|
/** When a message on a bound channel triggers inference (it always lands in
|
|
@@ -93,6 +94,9 @@ export interface ConversationRouterConfig {
|
|
|
93
94
|
}
|
|
94
95
|
export interface ConversationBinding {
|
|
95
96
|
channelId: string;
|
|
97
|
+
/** The channel's server: channel ids are unique only within one server's
|
|
98
|
+
* connection (MCPL §14.2), so each server's channel has its own binding. */
|
|
99
|
+
serverId: string;
|
|
96
100
|
agentName: string;
|
|
97
101
|
/** Engagement counter per channel — fresh forks get a new generation. */
|
|
98
102
|
generation: number;
|
|
@@ -139,10 +143,14 @@ export declare const DEFAULT_CLOSURE_PROMPT: string;
|
|
|
139
143
|
*/
|
|
140
144
|
export declare class ConversationRouter {
|
|
141
145
|
private config;
|
|
142
|
-
/** Active bindings, keyed by
|
|
146
|
+
/** Active bindings, keyed by the channel's server and id (destinationKey):
|
|
147
|
+
* two servers' channels with one id are two conversations. */
|
|
143
148
|
private bindings;
|
|
144
|
-
/** Engagement counter per channel — survives unbind, so a re-bound
|
|
145
|
-
* gets a distinct fork agent name.
|
|
149
|
+
/** Engagement counter per channel id — survives unbind, so a re-bound
|
|
150
|
+
* channel gets a distinct fork agent name. Kept by bare id, as it's
|
|
151
|
+
* persisted: two servers sharing an id share a counter, which still never
|
|
152
|
+
* repeats a name, and their forks' names differ anyway, since each hashes
|
|
153
|
+
* its server (forkAgentName). */
|
|
146
154
|
private generations;
|
|
147
155
|
constructor(config: ConversationRouterConfig);
|
|
148
156
|
get templateAgent(): string;
|
|
@@ -160,15 +168,15 @@ export declare class ConversationRouter {
|
|
|
160
168
|
* Record a binding after the framework successfully spawned the fork.
|
|
161
169
|
* Returns the new binding.
|
|
162
170
|
*/
|
|
163
|
-
bind(
|
|
171
|
+
bind(channel: ChannelRef, agentName: string, generation: number, now?: number): ConversationBinding;
|
|
164
172
|
/** Record delivered activity on an existing binding. Does not bind a
|
|
165
173
|
* channel or advance its generation. Call after successful delivery, not
|
|
166
174
|
* when previewing a route. The optional clock supports deterministic use. */
|
|
167
|
-
touch(
|
|
168
|
-
unbind(
|
|
169
|
-
getBinding(
|
|
175
|
+
touch(channel: ChannelRef, now?: number): void;
|
|
176
|
+
unbind(channel: ChannelRef): void;
|
|
177
|
+
getBinding(channel: ChannelRef): ConversationBinding | undefined;
|
|
170
178
|
/** Reverse lookup: the channel an agent is bound to, if any. */
|
|
171
|
-
channelForAgent(agentName: string):
|
|
179
|
+
channelForAgent(agentName: string): ChannelRef | undefined;
|
|
172
180
|
getBindings(): ConversationBinding[];
|
|
173
181
|
/** Bindings whose idle TTL has elapsed. Does not unbind: the framework
|
|
174
182
|
* unbinds each one first, so the channel's next message goes to a newer
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation-router.d.ts","sourceRoot":"","sources":["../../../src/mcpl/conversation-router.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAGH,OAAO,KAAK,E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U,EAAE,MAAM,GAAG,MAAM,CAIzH"}
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
* follow-up.
|
|
35
35
|
*/
|
|
36
36
|
import { createHash } from 'node:crypto';
|
|
37
|
+
import { destinationKey } from './channel-registry.js';
|
|
37
38
|
/** Logged once by the framework when `FrameworkConfig.conversations` is set. */
|
|
38
39
|
export const CONVERSATION_ROUTING_DEPRECATION_NOTICE = 'Per-channel conversation routing (FrameworkConfig.conversations) is deprecated and will ' +
|
|
39
40
|
'be removed in a future release. Its \'mention\' bind/trigger rule reads ' +
|
|
@@ -55,10 +56,14 @@ export const DEFAULT_CLOSURE_PROMPT = '[system] This engagement is closing due t
|
|
|
55
56
|
*/
|
|
56
57
|
export class ConversationRouter {
|
|
57
58
|
config;
|
|
58
|
-
/** Active bindings, keyed by
|
|
59
|
+
/** Active bindings, keyed by the channel's server and id (destinationKey):
|
|
60
|
+
* two servers' channels with one id are two conversations. */
|
|
59
61
|
bindings = new Map();
|
|
60
|
-
/** Engagement counter per channel — survives unbind, so a re-bound
|
|
61
|
-
* gets a distinct fork agent name.
|
|
62
|
+
/** Engagement counter per channel id — survives unbind, so a re-bound
|
|
63
|
+
* channel gets a distinct fork agent name. Kept by bare id, as it's
|
|
64
|
+
* persisted: two servers sharing an id share a counter, which still never
|
|
65
|
+
* repeats a name, and their forks' names differ anyway, since each hashes
|
|
66
|
+
* its server (forkAgentName). */
|
|
62
67
|
generations = new Map();
|
|
63
68
|
constructor(config) {
|
|
64
69
|
this.config = config;
|
|
@@ -82,7 +87,7 @@ export class ConversationRouter {
|
|
|
82
87
|
* unchanged; a failed spawn doesn't leave a dangling route.
|
|
83
88
|
*/
|
|
84
89
|
route(facts) {
|
|
85
|
-
const existing = this.bindings.get(facts.channelId);
|
|
90
|
+
const existing = this.bindings.get(bindingKey({ serverId: facts.serverId ?? '', channelId: facts.channelId }));
|
|
86
91
|
if (existing) {
|
|
87
92
|
return {
|
|
88
93
|
kind: 'existing',
|
|
@@ -108,37 +113,42 @@ export class ConversationRouter {
|
|
|
108
113
|
* Record a binding after the framework successfully spawned the fork.
|
|
109
114
|
* Returns the new binding.
|
|
110
115
|
*/
|
|
111
|
-
bind(
|
|
112
|
-
|
|
116
|
+
bind(channel, agentName, generation, now = Date.now()) {
|
|
117
|
+
// The counter is kept by bare id, and two servers' spawns on one id run
|
|
118
|
+
// beside each other, so a bind can finish after a later spawn's: the
|
|
119
|
+
// counter keeps the higher, or the next spawn would propose a fork name
|
|
120
|
+
// already used.
|
|
121
|
+
this.generations.set(channel.channelId, Math.max(this.generations.get(channel.channelId) ?? 0, generation));
|
|
113
122
|
const binding = {
|
|
114
|
-
channelId,
|
|
123
|
+
channelId: channel.channelId,
|
|
124
|
+
serverId: channel.serverId,
|
|
115
125
|
agentName,
|
|
116
126
|
generation,
|
|
117
127
|
boundAt: now,
|
|
118
128
|
lastActivity: now,
|
|
119
129
|
};
|
|
120
|
-
this.bindings.set(
|
|
130
|
+
this.bindings.set(bindingKey(channel), binding);
|
|
121
131
|
return binding;
|
|
122
132
|
}
|
|
123
133
|
/** Record delivered activity on an existing binding. Does not bind a
|
|
124
134
|
* channel or advance its generation. Call after successful delivery, not
|
|
125
135
|
* when previewing a route. The optional clock supports deterministic use. */
|
|
126
|
-
touch(
|
|
127
|
-
const binding = this.bindings.get(
|
|
136
|
+
touch(channel, now = Date.now()) {
|
|
137
|
+
const binding = this.bindings.get(bindingKey(channel));
|
|
128
138
|
if (binding)
|
|
129
139
|
binding.lastActivity = now;
|
|
130
140
|
}
|
|
131
|
-
unbind(
|
|
132
|
-
this.bindings.delete(
|
|
141
|
+
unbind(channel) {
|
|
142
|
+
this.bindings.delete(bindingKey(channel));
|
|
133
143
|
}
|
|
134
|
-
getBinding(
|
|
135
|
-
return this.bindings.get(
|
|
144
|
+
getBinding(channel) {
|
|
145
|
+
return this.bindings.get(bindingKey(channel));
|
|
136
146
|
}
|
|
137
147
|
/** Reverse lookup: the channel an agent is bound to, if any. */
|
|
138
148
|
channelForAgent(agentName) {
|
|
139
149
|
for (const binding of this.bindings.values()) {
|
|
140
150
|
if (binding.agentName === agentName)
|
|
141
|
-
return binding.channelId;
|
|
151
|
+
return { serverId: binding.serverId, channelId: binding.channelId };
|
|
142
152
|
}
|
|
143
153
|
return undefined;
|
|
144
154
|
}
|
|
@@ -200,6 +210,10 @@ export class ConversationRouter {
|
|
|
200
210
|
}
|
|
201
211
|
/** The readable part of a fork's name stops here: uniqueness rides on the hash. */
|
|
202
212
|
const FORK_NAME_READABLE_MAX = 64;
|
|
213
|
+
/** A binding's key: its channel's server and id (destinationKey). */
|
|
214
|
+
function bindingKey(channel) {
|
|
215
|
+
return destinationKey(channel);
|
|
216
|
+
}
|
|
203
217
|
/**
|
|
204
218
|
* A fork's agent name: `<prefix>-<readable>-g<generation>-<hash>`, such as
|
|
205
219
|
* `conversation-C123-g2-e08e564271867d16` for Slack's channel `C123` on the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation-router.js","sourceRoot":"","sources":["../../../src/mcpl/conversation-router.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"conversation-router.js","sourceRoot":"","sources":["../../../src/mcpl/conversation-router.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,cAAc,EAAmB,MAAM,uBAAuB,CAAC;AAmBxE,gFAAgF;AAChF,MAAM,CAAC,MAAM,uCAAuC,GAClD,0FAA0F;IAC1F,0EAA0E;IAC1E,yFAAyF;IACzF,0FAA0F;IAC1F,wDAAwD,CAAC;AA+E3D,MAAM,mBAAmB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEhD,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AC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAClD,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,SAAS,CAAC;IAC9C,CAAC;CACF;AAED,mFAAmF;AACnF,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAElC,qEAAqE;AACrE,SAAS,UAAU,CAAC,OAAmB;IACrC,OAAO,cAAc,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,QAA4B,EAAE,SAAiB,EAAE,UAAkB;IAC/G,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,sBAAsB,CAAC,CAAC;IAC7F,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC3G,OAAO,GAAG,MAAM,IAAI,QAAQ,KAAK,UAAU,IAAI,IAAI,EAAE,CAAC;AACxD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-block.d.ts","sourceRoot":"","sources":["../../../src/mcpl/convert-block.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"convert-block.d.ts","sourceRoot":"","sources":["../../../src/mcpl/convert-block.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAaxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,YAAY,CAiFxG"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* for pushed events, channel messages and context injections alike, so a rule
|
|
4
4
|
* about a malformed block holds on all three.
|
|
5
5
|
*/
|
|
6
|
-
import { AUDIO_NO_DATA_TEXT, AUDIO_NO_MEDIA_TYPE_TEXT, IMAGE_NO_DATA_TEXT, IMAGE_NO_MEDIA_TYPE_TEXT, INLINE_WITHHELD_TEXT, isInlineContradiction, referenceStubOrNull, unknownBlockText, } from './references.js';
|
|
6
|
+
import { AUDIO_NO_DATA_TEXT, AUDIO_NO_MEDIA_TYPE_TEXT, IMAGE_NO_DATA_TEXT, IMAGE_NO_MEDIA_TYPE_TEXT, INLINE_WITHHELD_TEXT, classifyBlock, isInlineContradiction, referenceStubOrNull, unknownBlockText, } from './references.js';
|
|
7
7
|
import { NON_STRING_TEXT_PLACEHOLDER } from './visible-content.js';
|
|
8
8
|
/**
|
|
9
9
|
* Convert a single MCPL wire-format content block to a membrane ContentBlock.
|
|
@@ -69,11 +69,23 @@ export function convertBlock(block, provenance, serverId) {
|
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
return { type: 'text', text: isFilledString(block.data) ? AUDIO_NO_MEDIA_TYPE_TEXT : AUDIO_NO_DATA_TEXT };
|
|
72
|
-
case 'resource':
|
|
72
|
+
case 'resource': {
|
|
73
|
+
// MCP's embedded resource shows as the block its contents make would
|
|
74
|
+
// show here (RFC-005 §8.1), its uri never.
|
|
75
|
+
const c = classifyBlock(block);
|
|
76
|
+
if (c.kind === 'embedded' && c.contents.kind === 'block') {
|
|
77
|
+
return convertBlock(c.contents.block, provenance, serverId);
|
|
78
|
+
}
|
|
73
79
|
// RFC-005: reference blocks become bounded stubs — never raw URIs
|
|
74
80
|
// (a signed URL is a bearer credential that looks like a location).
|
|
75
81
|
return { type: 'text', text: referenceStubOrNull(block, provenance, serverId) ?? '[reference]' };
|
|
82
|
+
}
|
|
76
83
|
default: {
|
|
84
|
+
// MCP's link to a resource isn't one of MCPL's own blocks, but a server
|
|
85
|
+
// can send one, and RFC-005 §8.1 makes it a reference, shown as one.
|
|
86
|
+
if (block.type === 'resource_link') {
|
|
87
|
+
return { type: 'text', text: referenceStubOrNull(block, provenance, serverId) ?? '[reference]' };
|
|
88
|
+
}
|
|
77
89
|
// Unknown wire block types previously fell off the exhaustive switch
|
|
78
90
|
// and propagated `undefined` into ContentBlock[]. Fail visibly. A type
|
|
79
91
|
// that isn't a string is no type, and is never converted to one: an
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-block.js","sourceRoot":"","sources":["../../../src/mcpl/convert-block.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,kBAAkB,EAClB,wBAAwB,EACxB,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAGnE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,YAAY,CAAC,KAAuB,EAAE,UAAkB,EAAE,QAAgB;IACxF,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,MAAM;YACT,qEAAqE;YACrE,kEAAkE;YAClE,8DAA8D;YAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,2BAA2B,EAAE,CAAC;QAE3G,KAAK,OAAO;YACV,IAAI,qBAAqB,CAAC,KAAK,CAAC,EAAE,CAAC;gBACjC,iEAAiE;gBACjE,8DAA8D;gBAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,EAA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,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAyB,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;YAClF,CAAC;YACD,kEAAkE;YAClE,oEAAoE;YACpE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,IAAI,aAAa,EAAE,CAAC;QACnG,CAAC;QAED,SAAS,CAAC;YACR,wEAAwE;YACxE,qEAAqE;YACrE,IAAK,KAA4B,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;gBAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,IAAI,aAAa,EAAE,CAAC;YACnG,CAAC;YACD,qEAAqE;YACrE,uEAAuE;YACvE,oEAAoE;YACpE,+BAA+B;YAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QACzD,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;4CAG4C;AAC5C,SAAS,cAAc,CAAC,KAAc;IACpC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,CAAC;AACnD,CAAC"}
|
|
@@ -36,8 +36,14 @@ export declare class HookOrchestrator {
|
|
|
36
36
|
*
|
|
37
37
|
* Returns aggregated ContextInjection[] ready for context-manager's compile().
|
|
38
38
|
* Fail-open: servers that time out or error are silently skipped.
|
|
39
|
+
*
|
|
40
|
+
* `channelsFor` gives each server its own channel context (§14.4), in
|
|
41
|
+
* place of `params.channels`: channel ids are unique only within one
|
|
42
|
+
* server's connection (§14.2), so each server is told only of its own
|
|
43
|
+
* channels (ChannelRegistry.buildChannelContext). Undefined from it leaves
|
|
44
|
+
* the field out for that server.
|
|
39
45
|
*/
|
|
40
|
-
beforeInference(params: BeforeInferenceParams): Promise<ContextInjection[]>;
|
|
46
|
+
beforeInference(params: BeforeInferenceParams, channelsFor?: (serverId: string) => BeforeInferenceParams['channels']): Promise<ContextInjection[]>;
|
|
41
47
|
/**
|
|
42
48
|
* Fan out `inference/lifecycle` (§10.5) — the metadata-only replacement
|
|
43
49
|
* for context/afterInference. Notifications, fire-and-forget, gated on the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook-orchestrator.d.ts","sourceRoot":"","sources":["../../../src/mcpl/hook-orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,KAAK,EAGV,qBAAqB,EAErB,wBAAwB,EACzB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"hook-orchestrator.d.ts","sourceRoot":"","sources":["../../../src/mcpl/hook-orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,KAAK,EAGV,qBAAqB,EAErB,wBAAwB,EACzB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AA8DlE,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,SAAS,CAAS;IAC1B,0EAA0E;IAC1E,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAqB;IACrD,oGAAoG;IACpG,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAqB;IAEpD,YAAY,QAAQ,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,iBAAiB,EAG7E;IAED;;;;OAIG;IACH,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED;;;;;;;;;;;OAWG;IACG,eAAe,CACnB,MAAM,EAAE,qBAAqB,EAC7B,WAAW,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,qBAAqB,CAAC,UAAU,CAAC,GACpE,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAqB7B;IAED;;;;;;OAMG;IACH,aAAa,CAAC,MAAM,EAAE,wBAAwB,GAAG,IAAI,CASpD;YAMa,qBAAqB;IAqGnC;;;;;;;;OAQG;IACH,OAAO,CAAC,aAAa;IAgBrB;;;;;;;OAOG;IACH,OAAO,CAAC,kBAAkB;CAY3B"}
|
|
@@ -49,7 +49,9 @@ function convertContent(content, serverId) {
|
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* Convert an MCPL wire-format context injection, from the server `serverId`,
|
|
52
|
-
* to a context-manager ContextInjection.
|
|
52
|
+
* to a context-manager ContextInjection. It builds only these four fields,
|
|
53
|
+
* so a server can't opt an injection out of being stored
|
|
54
|
+
* (ModuleContextInjection.placedEachCompile, which only a module may set).
|
|
53
55
|
*/
|
|
54
56
|
function convertMcplInjection(mcplInj, serverId) {
|
|
55
57
|
return {
|
|
@@ -87,8 +89,14 @@ export class HookOrchestrator {
|
|
|
87
89
|
*
|
|
88
90
|
* Returns aggregated ContextInjection[] ready for context-manager's compile().
|
|
89
91
|
* Fail-open: servers that time out or error are silently skipped.
|
|
92
|
+
*
|
|
93
|
+
* `channelsFor` gives each server its own channel context (§14.4), in
|
|
94
|
+
* place of `params.channels`: channel ids are unique only within one
|
|
95
|
+
* server's connection (§14.2), so each server is told only of its own
|
|
96
|
+
* channels (ChannelRegistry.buildChannelContext). Undefined from it leaves
|
|
97
|
+
* the field out for that server.
|
|
90
98
|
*/
|
|
91
|
-
async beforeInference(params) {
|
|
99
|
+
async beforeInference(params, channelsFor) {
|
|
92
100
|
// §5.4: the GRANT decides fan-out, not the raw advertisement — which
|
|
93
101
|
// also fixes selection for the recursive §5.1 shape, where
|
|
94
102
|
// `beforeInference: {observe: true, …}` is an object, not `true`. A
|
|
@@ -102,7 +110,7 @@ export class HookOrchestrator {
|
|
|
102
110
|
}
|
|
103
111
|
this._isInHook = true;
|
|
104
112
|
try {
|
|
105
|
-
return await this.fanOutBeforeInference(servers, params);
|
|
113
|
+
return await this.fanOutBeforeInference(servers, params, channelsFor);
|
|
106
114
|
}
|
|
107
115
|
finally {
|
|
108
116
|
this._isInHook = false;
|
|
@@ -130,15 +138,32 @@ export class HookOrchestrator {
|
|
|
130
138
|
// ==========================================================================
|
|
131
139
|
// Private: beforeInference fan-out
|
|
132
140
|
// ==========================================================================
|
|
133
|
-
async fanOutBeforeInference(servers, params) {
|
|
134
|
-
const results = await Promise.allSettled(
|
|
141
|
+
async fanOutBeforeInference(servers, params, channelsFor) {
|
|
142
|
+
const results = await Promise.allSettled(
|
|
143
|
+
// Async, so a throw building one server's channel context fails that
|
|
144
|
+
// server alone, as its timeout or transport error would.
|
|
145
|
+
servers.map(async (server) => {
|
|
146
|
+
let base = params;
|
|
147
|
+
if (channelsFor) {
|
|
148
|
+
const { channels: _shared, ...rest } = params;
|
|
149
|
+
let channels;
|
|
150
|
+
try {
|
|
151
|
+
channels = channelsFor(server.id);
|
|
152
|
+
}
|
|
153
|
+
catch (err) {
|
|
154
|
+
// A bug, not a server's failure: said, then this server is skipped.
|
|
155
|
+
console.error(`[beforeInference] the channel context for "${server.id}" couldn't be built, so it isn't called:`, err);
|
|
156
|
+
throw err;
|
|
157
|
+
}
|
|
158
|
+
base = channels ? { ...rest, channels } : rest;
|
|
159
|
+
}
|
|
135
160
|
// §10.1: a server not granted observe MUST receive
|
|
136
161
|
// `userMessage: null` — the field is ABSENT authority, not merely
|
|
137
162
|
// discouraged — while the hook is still invoked so granted
|
|
138
163
|
// injection positions keep working (write-without-read).
|
|
139
164
|
const perServer = CapabilityGrant.of(server).has('contextHooks.beforeInference.observe')
|
|
140
|
-
?
|
|
141
|
-
: { ...
|
|
165
|
+
? base
|
|
166
|
+
: { ...base, userMessage: null };
|
|
142
167
|
return withTimeout(server.sendBeforeInference(perServer), BEFORE_INFERENCE_TIMEOUT_MS, `beforeInference to "${server.id}"`).then((result) => ({ server, result }));
|
|
143
168
|
}));
|
|
144
169
|
const injections = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook-orchestrator.js","sourceRoot":"","sources":["../../../src/mcpl/hook-orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAalD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAErD,0DAA0D;AAC1D,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAE1C;;oCAEoC;AACpC,MAAM,aAAa,GAAsD;IACvE,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,4CAA4C,EAAE;IAC1E,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,gDAAgD,EAAE;IAClF,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,+CAA+C,EAAE;CACjF,CAAC;AAEF;;GAEG;AACH,SAAS,WAAW,CAAI,OAAmB,EAAE,EAAU,EAAE,KAAa;IACpE,OAAO,OAAO,CAAC,IAAI,CAAC;QAClB,OAAO;QACP,IAAI,OAAO,CAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,CACtC,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,GAAG,KAAK,oBAAoB,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC,CAC5E;KACF,CAAC,CAAC;AACL,CAAC;AAED,+EAA+E;AAC/E,+E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ACP,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;QAC5E,CAAC;QACD,IAAI,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC;YAAE,OAAO;QAC/C,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACnC,OAAO,CAAC,KAAK,CACX,UAAU,QAAQ,kGAAkG;YAClH,yGAAyG,QAAQ,CAAC,IAAI,CAAC,IAAI;YAC3H,sDAAsD,CACzD,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACK,kBAAkB,CAAC,QAAgB,EAAE,SAAkB,EAAE,OAAuB;QACtF,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC;YAAE,OAAO;QAC5D,MAAM,GAAG,GAAG,GAAG,QAAQ,SAAS,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;QACpD,IAAI,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,OAAO;QACzC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC7B,OAAO,CAAC,KAAK,CACX,UAAU,QAAQ,qCAAqC,QAAQ,CAAC,SAAS,CAAC,kCAAkC;YAC1G,iHAAiH;YACjH,oEAAoE,CACvE,CAAC;IACJ,CAAC;CAEF"}
|
|
@@ -139,23 +139,39 @@ export declare function canonicalJson(value: unknown): string;
|
|
|
139
139
|
* room-220 #46752–#47210): SHA-256 hex of `canonicalJson([blocks])` over the
|
|
140
140
|
* ContentBlock[] the framework stores for the body — after MCPL conversion,
|
|
141
141
|
* before any host decoration is added and before storage shards it — with
|
|
142
|
-
* each block as the store keeps it
|
|
143
|
-
* hashes alike as delivered, as handed to storage, and as
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
142
|
+
* each block as the store keeps it, which context-manager's `blockAsStored`
|
|
143
|
+
* gives. So a body hashes alike as delivered, as handed to storage, and as
|
|
144
|
+
* read back unsharded from the store with its blobs resolved, except one
|
|
145
|
+
* whose blocks the store changes together: when it mends a `tool_use` whose
|
|
146
|
+
* input isn't an object, it also releases a raw replay form (`rawXml`,
|
|
147
|
+
* `rawItem`) that the message's other blocks share, which no one block's
|
|
148
|
+
* stored form shows. A body an MCPL lane stamps is never one. A block the
|
|
149
|
+
* store refuses on write, a `blob_ref` among them, is digested as given. The
|
|
150
|
+
* one-element array keeps the framing an undecorated, unsharded stored copy
|
|
151
|
+
* has always hashed to, so a stamped copy and an older copy of the same body
|
|
152
|
+
* share a version where the store keeps the body as it did then.
|
|
153
|
+
*
|
|
154
|
+
* A digest is a digest under the context-manager release that computed it: a
|
|
155
|
+
* release that changes what the store keeps, such as its set of image
|
|
156
|
+
* signatures, changes the digest of a body it touches.
|
|
147
157
|
*
|
|
148
158
|
* Ingestion stamps it as `metadata.sourceBodyDigest`, and the same function
|
|
149
159
|
* over exactly the blocks handed to storage (decorations included) as
|
|
150
160
|
* `metadata.storedBodyDigest`, on both MCPL lanes. Both live outside the
|
|
151
161
|
* frozen admission envelope: they describe the body actually delivered (a
|
|
152
162
|
* materialization, a correction), not the admission. Neither proves later
|
|
153
|
-
* presence or completeness
|
|
163
|
+
* presence or completeness. An unsharded stored copy that no longer hashes
|
|
154
164
|
* to its storedBodyDigest was changed after delivery (editMessage keeps
|
|
155
|
-
* metadata)
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
165
|
+
* metadata), or holds blocks the store changes together, or its digest was
|
|
166
|
+
* taken under a release that kept some block of it differently: a
|
|
167
|
+
* context-manager release that changed a stored form, or an agent-framework
|
|
168
|
+
* release from 0.24.0 up to the one that brought in blockAsStored, which
|
|
169
|
+
* took stored forms from a copy of the store's transform. Digests already
|
|
170
|
+
* stamped are never recomputed. A body the store shards carries the whole
|
|
171
|
+
* body's two digests on every shard, and no shard hashes to them. Check a
|
|
172
|
+
* copy read back with its blobs resolved (getAllMessages, getMessage, or
|
|
173
|
+
* getMessageWindow without `resolveBlobs: false`): a blob reference never
|
|
174
|
+
* matches.
|
|
159
175
|
*
|
|
160
176
|
* Exported from the package root, so a consumer checks a copy against either
|
|
161
177
|
* field with this same function rather than a copy of it.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inbound-source.d.ts","sourceRoot":"","sources":["../../../src/mcpl/inbound-source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;
|
|
1
|
+
{"version":3,"file":"inbound-source.d.ts","sourceRoot":"","sources":["../../../src/mcpl/inbound-source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAMH;;;;+CAI+C;AAC/C,MAAM,MAAM,WAAW,GAAG,mBAAmB,GAAG,YAAY,CAAC;AAE7D,oDAAoD;AACpD,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,SAAS,CAAC;IAChB,6DAA6D;IAC7D,IAAI,EAAE,WAAW,CAAC;IAClB,oDAAoD;IACpD,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,kFAAkF;IAClF,QAAQ,EAAE,MAAM,CAAC;IACjB;;qFAEiF;IACjF,OAAO,EAAE,MAAM,CAAC;IAChB;gFAC4E;IAC5E,SAAS,EAAE,MAAM,CAAC;IAClB,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iEAAiE;IACjE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,0DAA0D;IAC1D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,IAAI,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AE,GAAG,MAAM,CAEnE"}
|
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
* key: `eventId` is present only when the producer supplied one.
|
|
22
22
|
*/
|
|
23
23
|
import { createHash } from 'node:crypto';
|
|
24
|
+
import { blockAsStored, MalformedContentError } from '@animalabs/context-manager';
|
|
25
|
+
import { logDetail, logValue } from './log-value.js';
|
|
24
26
|
/** Metadata key the framework stamps. */
|
|
25
27
|
export const INBOUND_SOURCE_KEY = 'inboundSource';
|
|
26
28
|
const isText = (v) => typeof v === 'string' && v.length > 0;
|
|
@@ -117,92 +119,61 @@ export function canonicalJson(value) {
|
|
|
117
119
|
return JSON.stringify(value) ?? 'null';
|
|
118
120
|
}
|
|
119
121
|
/**
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* 'base64', data, mediaType } }` and nothing else, its data re-encoded from
|
|
124
|
-
* the decoded bytes, and an image's media type taken from its bytes'
|
|
125
|
-
* signature where they have one. Any other block comes back as it was given,
|
|
126
|
-
* except a store-internal `blob_ref` from an unresolved read, which resolves
|
|
127
|
-
* to inline media by default. It is digested as given here, so an unresolved
|
|
128
|
-
* read and its resolved form differ. Context-manager refuses caller-supplied
|
|
129
|
-
* blob_ref writes; the MCPL lanes never store one.
|
|
122
|
+
* blockAsStored throws a `MalformedContentError` for a block the store
|
|
123
|
+
* refuses on write, a caller-supplied `blob_ref` among them. Such a block
|
|
124
|
+
* has no stored form, and whatever is thrown, it is digested as given.
|
|
130
125
|
*/
|
|
131
126
|
function storedBlock(block) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
? media.source?.type !== 'url'
|
|
135
|
-
: media?.type === 'document' || media?.type === 'audio' || media?.type === 'video';
|
|
136
|
-
const source = media?.source;
|
|
137
|
-
if (!blob || typeof source?.data !== 'string')
|
|
138
|
-
return block;
|
|
139
|
-
const data = canonicalBase64(source.data);
|
|
140
|
-
const mediaType = media.type === 'image'
|
|
141
|
-
? sniffRasterImageMediaType(Buffer.from(data.slice(0, 32), 'base64')) ?? source.mediaType
|
|
142
|
-
: source.mediaType;
|
|
143
|
-
return { type: media.type, source: { type: 'base64', data, mediaType } };
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Base64 as the store writes it back from the decoded bytes: padded, with no
|
|
147
|
-
* whitespace, the standard alphabet and zero unused bits. Data already in
|
|
148
|
-
* that form, as every stored copy's is, is returned without decoding it all.
|
|
149
|
-
*/
|
|
150
|
-
function canonicalBase64(data) {
|
|
151
|
-
if (data.length % 4 === 0 && /^[A-Za-z0-9+/]*={0,2}$/.test(data)) {
|
|
152
|
-
const last = data.slice(-4);
|
|
153
|
-
if (Buffer.from(last, 'base64').toString('base64') === last)
|
|
154
|
-
return data;
|
|
127
|
+
try {
|
|
128
|
+
return blockAsStored(block);
|
|
155
129
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
function sniffRasterImageMediaType(bytes) {
|
|
164
|
-
if (bytes.length >= 8 &&
|
|
165
|
-
bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4e && bytes[3] === 0x47 &&
|
|
166
|
-
bytes[4] === 0x0d && bytes[5] === 0x0a && bytes[6] === 0x1a && bytes[7] === 0x0a) {
|
|
167
|
-
return 'image/png';
|
|
168
|
-
}
|
|
169
|
-
if (bytes.length >= 3 && bytes[0] === 0xff && bytes[1] === 0xd8 && bytes[2] === 0xff) {
|
|
170
|
-
return 'image/jpeg';
|
|
171
|
-
}
|
|
172
|
-
if (bytes.length >= 6) {
|
|
173
|
-
const signature = Buffer.from(bytes.subarray(0, 6)).toString('ascii');
|
|
174
|
-
if (signature === 'GIF87a' || signature === 'GIF89a')
|
|
175
|
-
return 'image/gif';
|
|
176
|
-
}
|
|
177
|
-
if (bytes.length >= 12 &&
|
|
178
|
-
Buffer.from(bytes.subarray(0, 4)).toString('ascii') === 'RIFF' &&
|
|
179
|
-
Buffer.from(bytes.subarray(8, 12)).toString('ascii') === 'WEBP') {
|
|
180
|
-
return 'image/webp';
|
|
130
|
+
catch (err) {
|
|
131
|
+
if (!(err instanceof MalformedContentError)) {
|
|
132
|
+
const { name, message } = (err ?? {});
|
|
133
|
+
console.error(`[stored-digest-as-given] error=${logValue(typeof name === 'string' ? name : typeof err)}: ` +
|
|
134
|
+
logDetail(typeof message === 'string' ? message : ''));
|
|
135
|
+
}
|
|
136
|
+
return block;
|
|
181
137
|
}
|
|
182
|
-
return null;
|
|
183
138
|
}
|
|
184
139
|
/**
|
|
185
140
|
* The version identity of a delivered body (agreed with the receipts lane,
|
|
186
141
|
* room-220 #46752–#47210): SHA-256 hex of `canonicalJson([blocks])` over the
|
|
187
142
|
* ContentBlock[] the framework stores for the body — after MCPL conversion,
|
|
188
143
|
* before any host decoration is added and before storage shards it — with
|
|
189
|
-
* each block as the store keeps it
|
|
190
|
-
* hashes alike as delivered, as handed to storage, and as
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
144
|
+
* each block as the store keeps it, which context-manager's `blockAsStored`
|
|
145
|
+
* gives. So a body hashes alike as delivered, as handed to storage, and as
|
|
146
|
+
* read back unsharded from the store with its blobs resolved, except one
|
|
147
|
+
* whose blocks the store changes together: when it mends a `tool_use` whose
|
|
148
|
+
* input isn't an object, it also releases a raw replay form (`rawXml`,
|
|
149
|
+
* `rawItem`) that the message's other blocks share, which no one block's
|
|
150
|
+
* stored form shows. A body an MCPL lane stamps is never one. A block the
|
|
151
|
+
* store refuses on write, a `blob_ref` among them, is digested as given. The
|
|
152
|
+
* one-element array keeps the framing an undecorated, unsharded stored copy
|
|
153
|
+
* has always hashed to, so a stamped copy and an older copy of the same body
|
|
154
|
+
* share a version where the store keeps the body as it did then.
|
|
155
|
+
*
|
|
156
|
+
* A digest is a digest under the context-manager release that computed it: a
|
|
157
|
+
* release that changes what the store keeps, such as its set of image
|
|
158
|
+
* signatures, changes the digest of a body it touches.
|
|
194
159
|
*
|
|
195
160
|
* Ingestion stamps it as `metadata.sourceBodyDigest`, and the same function
|
|
196
161
|
* over exactly the blocks handed to storage (decorations included) as
|
|
197
162
|
* `metadata.storedBodyDigest`, on both MCPL lanes. Both live outside the
|
|
198
163
|
* frozen admission envelope: they describe the body actually delivered (a
|
|
199
164
|
* materialization, a correction), not the admission. Neither proves later
|
|
200
|
-
* presence or completeness
|
|
165
|
+
* presence or completeness. An unsharded stored copy that no longer hashes
|
|
201
166
|
* to its storedBodyDigest was changed after delivery (editMessage keeps
|
|
202
|
-
* metadata)
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
167
|
+
* metadata), or holds blocks the store changes together, or its digest was
|
|
168
|
+
* taken under a release that kept some block of it differently: a
|
|
169
|
+
* context-manager release that changed a stored form, or an agent-framework
|
|
170
|
+
* release from 0.24.0 up to the one that brought in blockAsStored, which
|
|
171
|
+
* took stored forms from a copy of the store's transform. Digests already
|
|
172
|
+
* stamped are never recomputed. A body the store shards carries the whole
|
|
173
|
+
* body's two digests on every shard, and no shard hashes to them. Check a
|
|
174
|
+
* copy read back with its blobs resolved (getAllMessages, getMessage, or
|
|
175
|
+
* getMessageWindow without `resolveBlobs: false`): a blob reference never
|
|
176
|
+
* matches.
|
|
206
177
|
*
|
|
207
178
|
* Exported from the package root, so a consumer checks a copy against either
|
|
208
179
|
* field with this same function rather than a copy of it.
|