@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/tool-result-guard.ts
CHANGED
|
@@ -4,10 +4,19 @@ import type { ContextManager, MessageId, MessageMetadata } from '@animalabs/cont
|
|
|
4
4
|
import type { ContentBlock, NormalizedMessage, ToolResult } from '@animalabs/membrane';
|
|
5
5
|
import type { CompletedToolCall } from './types/index.js';
|
|
6
6
|
import { ensureStateRegistered } from './module-registry.js';
|
|
7
|
-
import {
|
|
7
|
+
import { classifyBlock } from './mcpl/references.js';
|
|
8
|
+
import { resultClaimsOf, rfc005TextOf, toolResultDataToHistoryString } from './tool-result-history.js';
|
|
8
9
|
import { safeSlice } from './safe-slice.js';
|
|
9
10
|
|
|
10
11
|
export const TOOL_RESULT_GUARD_NOTICE = 'Tool result withheld by the guard. The tool has already executed.';
|
|
12
|
+
export type WithheldNoticeKind = 'ran' | 'refused' | 'error';
|
|
13
|
+
const GUARD_NOTICES: Record<WithheldNoticeKind, string> = {
|
|
14
|
+
ran: TOOL_RESULT_GUARD_NOTICE,
|
|
15
|
+
refused: "Tool result withheld by the guard. The tool didn't run.",
|
|
16
|
+
error: "Tool result withheld by the guard. The call returned an error, and this notice can't say whether the tool ran.",
|
|
17
|
+
};
|
|
18
|
+
const noticeKind = (result: CompletedToolCall['result'] | undefined): WithheldNoticeKind =>
|
|
19
|
+
result?.refused === true ? 'refused' : result?.isError === true ? 'error' : 'ran';
|
|
11
20
|
export const TOOL_RESULT_GUARD_AUDIT_STATE = 'framework/tool-result-guard';
|
|
12
21
|
|
|
13
22
|
/** Where a withheld result's original went: a workspace path; the path a
|
|
@@ -53,9 +62,12 @@ export interface WithheldHost {
|
|
|
53
62
|
}
|
|
54
63
|
|
|
55
64
|
/**
|
|
56
|
-
* The stub a withheld result settles to: #159's neutral notice
|
|
57
|
-
*
|
|
58
|
-
*
|
|
65
|
+
* The stub a withheld result settles to: #159's neutral notice for its
|
|
66
|
+
* `kind` (a result that isn't an error, a refused call's, or another error's),
|
|
67
|
+
* then where the original is, then, for an error whose original is in a file
|
|
68
|
+
* known written, a line telling the agent to read it, then, when its tool
|
|
69
|
+
* marked any, the fields kept from its result (`kept`, from
|
|
70
|
+
* keptWhenWithheld). It names no refusal and no
|
|
59
71
|
* category (#159 keeps those in operational logs), so reading the rest back
|
|
60
72
|
* is the agent's deliberate choice (agent-framework #277). The place holds
|
|
61
73
|
* the result as stored, which for one over the inline cap is its capped
|
|
@@ -66,7 +78,7 @@ export interface WithheldHost {
|
|
|
66
78
|
* save failed is still queued in memory, and a restart before its retry
|
|
67
79
|
* loses it.
|
|
68
80
|
*/
|
|
69
|
-
export function withheldResultNotice(spill: WithheldSpill, auditDurable: boolean, kept?: string): string {
|
|
81
|
+
export function withheldResultNotice(spill: WithheldSpill, auditDurable: boolean, kept?: string, kind: WithheldNoticeKind = 'ran'): string {
|
|
70
82
|
const audit = `the guard's audit record (${TOOL_RESULT_GUARD_AUDIT_STATE}), for an operator`;
|
|
71
83
|
const keptIn = (only: string) => auditDurable
|
|
72
84
|
? `is kept ${only}in ${audit}`
|
|
@@ -79,8 +91,10 @@ export function withheldResultNotice(spill: WithheldSpill, auditDurable: boolean
|
|
|
79
91
|
: spill.error === undefined
|
|
80
92
|
? `Its result is in workspace file ${spill.path}.`
|
|
81
93
|
: `Writing its result to workspace file ${spill.path} failed, so it ${keptIn('only ')}.`;
|
|
94
|
+
const readable = kind === 'error' && !!spill && 'path' in spill && spill.error === undefined && !spill.unfinished;
|
|
95
|
+
const readFirst = readable ? ' Read it before calling again.' : '';
|
|
82
96
|
const fields = kept === undefined ? '' : ` Kept from its result: ${kept}`;
|
|
83
|
-
return `${
|
|
97
|
+
return `${GUARD_NOTICES[kind]} ${place}${readFirst}${fields}`;
|
|
84
98
|
}
|
|
85
99
|
|
|
86
100
|
/**
|
|
@@ -90,7 +104,9 @@ export function withheldResultNotice(spill: WithheldSpill, auditDurable: boolean
|
|
|
90
104
|
* inline cap or less (storeResults' keptCap), they're cut, with a note that
|
|
91
105
|
* says so and where the whole result is, since a later field can then be cut
|
|
92
106
|
* away entirely. Undefined when it keeps nothing, as for a failed result
|
|
93
|
-
* (agent-framework #277)
|
|
107
|
+
* (agent-framework #277), one whose claims can't be read whole
|
|
108
|
+
* (resultClaimsOf), or one whose data is MCP's embedded resource, whose
|
|
109
|
+
* fields can't be kept apart from its contents or its uri. A write's file
|
|
94
110
|
* list is evidence of what it did, rarely what drew a refusal, and keeping it
|
|
95
111
|
* is what shows a clobbered file when the receipt is withheld.
|
|
96
112
|
*/
|
|
@@ -99,13 +115,23 @@ export function keptWhenWithheld(result: CompletedToolCall['result'], maxChars:
|
|
|
99
115
|
if (!result.success || result.isError || !keys?.length || !data || typeof data !== 'object' || Array.isArray(data)) {
|
|
100
116
|
return undefined;
|
|
101
117
|
}
|
|
118
|
+
// MCP's embedded resource is its contents: shown as text, it's the very
|
|
119
|
+
// body the guard withheld, and a field picked out of it, such as
|
|
120
|
+
// `resource`, is data that shows its uri. So it keeps nothing.
|
|
121
|
+
if (classifyBlock(data).kind === 'embedded') return undefined;
|
|
102
122
|
const fields = data as Record<string, unknown>;
|
|
103
123
|
const kept = Object.fromEntries(keys.filter((key) => Object.hasOwn(fields, key)).map((key) => [key, fields[key]]));
|
|
104
124
|
if (Object.keys(kept).length === 0) return undefined;
|
|
105
125
|
// Data that RFC-005 shows as text, such as a reference's stub, keeps that
|
|
106
126
|
// text: picked out of it, a kept uri would lose the type that makes it a
|
|
107
127
|
// reference, and be written out of the stub that hides it.
|
|
108
|
-
|
|
128
|
+
// The kept fields are shown as the whole result claims (resultClaimsOf), so
|
|
129
|
+
// a never elsewhere in it still withholds a kept link's uri. Where a value
|
|
130
|
+
// stops that walk, such as a getter that throws, which the audit's JSON
|
|
131
|
+
// doesn't read, what the rest claims is unknown, and nothing is kept.
|
|
132
|
+
const claims = resultClaimsOf(fields);
|
|
133
|
+
if (claims === null) return undefined;
|
|
134
|
+
const whole = rfc005TextOf(fields) ?? toolResultDataToHistoryString(kept, undefined, { claims });
|
|
109
135
|
if (!maxChars || whole.length <= maxChars) return whole;
|
|
110
136
|
// Never half a surrogate pair: the stub goes to the provider as text, so
|
|
111
137
|
// the cut can be one character short of the cap.
|
|
@@ -127,6 +153,7 @@ interface PendingBatch {
|
|
|
127
153
|
/** What each result's stub keeps if the batch is withheld, by its index in
|
|
128
154
|
* content: the fields its tool marked (keptWhenWithheld). */
|
|
129
155
|
kept: Map<number, string>;
|
|
156
|
+
notices: Map<string, WithheldNoticeKind>;
|
|
130
157
|
}
|
|
131
158
|
|
|
132
159
|
interface AuditOperation {
|
|
@@ -235,7 +262,7 @@ export class ToolResultGuard {
|
|
|
235
262
|
if (block.type === 'image') images += 1;
|
|
236
263
|
else chars += JSON.stringify(block).length;
|
|
237
264
|
}
|
|
238
|
-
chars -=
|
|
265
|
+
chars -= GUARD_NOTICES[pending.notices.get(result.toolUseId) ?? 'ran'].length;
|
|
239
266
|
}
|
|
240
267
|
return Math.max(0, Math.ceil(chars / 4) + images * 1600);
|
|
241
268
|
}
|
|
@@ -348,12 +375,13 @@ export class ToolResultGuard {
|
|
|
348
375
|
// with a placeholder if the audit cannot become durable below.
|
|
349
376
|
console.error(`[tool-result-guard] agent=${this.agentName} staged audit write queued:`, error);
|
|
350
377
|
}
|
|
378
|
+
const results = new Map(originals.map((call) => [call.id, call.result]));
|
|
379
|
+
const notices = new Map([...results].map(([id, result]) => [id, noticeKind(result)]));
|
|
351
380
|
const withheld: ContentBlock[] = content.map((block) => block.type === 'tool_result'
|
|
352
|
-
? { type: 'tool_result', toolUseId: block.toolUseId, content:
|
|
381
|
+
? { type: 'tool_result', toolUseId: block.toolUseId, content: GUARD_NOTICES[notices.get(block.toolUseId) ?? 'ran'], isError: block.isError }
|
|
353
382
|
: block);
|
|
354
383
|
// What each stub keeps if the batch is withheld, matched to its tool's
|
|
355
384
|
// result by tool use id, keyed by index as the stubs and files are.
|
|
356
|
-
const results = new Map(originals.map((call) => [call.id, call.result]));
|
|
357
385
|
const kept = new Map<number, string>();
|
|
358
386
|
for (const [index, block] of content.entries()) {
|
|
359
387
|
const result = block.type === 'tool_result' ? results.get(block.toolUseId) : undefined;
|
|
@@ -366,7 +394,7 @@ export class ToolResultGuard {
|
|
|
366
394
|
// which is correct since a reopened guard has no pending batch.
|
|
367
395
|
const messageId = this.cm.addMessage('user', withheld, metadata, undefined, { holdCompression: true });
|
|
368
396
|
this.pending = { id, messageId, content, withheld, wireResults,
|
|
369
|
-
branch: this.cm.currentBranch().name, submitted: false, durable: false, kept };
|
|
397
|
+
branch: this.cm.currentBranch().name, submitted: false, durable: false, kept, notices };
|
|
370
398
|
// Durability barrier: the audit must reach Chronicle's chain heads before
|
|
371
399
|
// the originals can go to a provider. On a failed sync the batch fails
|
|
372
400
|
// CLOSED: the placeholders go on the wire instead (the turn continues,
|
|
@@ -393,7 +421,7 @@ export class ToolResultGuard {
|
|
|
393
421
|
if (pending.durable) { pending.submitted = true; return results; }
|
|
394
422
|
const ids = new Set(pending.wireResults.map((result) => result.toolUseId));
|
|
395
423
|
return results.map((result) => ids.has(result.toolUseId)
|
|
396
|
-
? { ...result, content:
|
|
424
|
+
? { ...result, content: GUARD_NOTICES[pending.notices.get(result.toolUseId) ?? 'ran'] } : result);
|
|
397
425
|
}
|
|
398
426
|
|
|
399
427
|
/** The stream carrying this batch ended without a clean round (abort or
|
|
@@ -500,7 +528,7 @@ export class ToolResultGuard {
|
|
|
500
528
|
/**
|
|
501
529
|
* Turn a withheld batch's notices into stubs that say where each original
|
|
502
530
|
* is (agent-framework #277): written to the workspace when it has a
|
|
503
|
-
* writable mount without an include to take it, else kept in the audit
|
|
531
|
+
* writable mount without an include, not configured direct, to take it, else kept in the audit
|
|
504
532
|
* record. A stub also keeps the file
|
|
505
533
|
* lists its tool marked. Its own unedited placeholder is
|
|
506
534
|
* the only thing it edits: an operator's later edit, removal or rollback
|
|
@@ -590,7 +618,7 @@ export class ToolResultGuard {
|
|
|
590
618
|
spills.set(index, spill);
|
|
591
619
|
}
|
|
592
620
|
const annotated: ContentBlock[] = pending.withheld.map((block, index) => block.type === 'tool_result'
|
|
593
|
-
? { ...block, content: withheldResultNotice(spills.get(index) ?? null, pending.durable, pending.kept.get(index)) }
|
|
621
|
+
? { ...block, content: withheldResultNotice(spills.get(index) ?? null, pending.durable, pending.kept.get(index), pending.notices.get(block.toolUseId)) }
|
|
594
622
|
: block);
|
|
595
623
|
try {
|
|
596
624
|
this.append({
|
|
@@ -599,8 +627,8 @@ export class ToolResultGuard {
|
|
|
599
627
|
if (block.type !== 'tool_result') return [];
|
|
600
628
|
if (thrown.has(index)) return [{ toolUseId: block.toolUseId, error: thrown.get(index)! }];
|
|
601
629
|
const spill = spills.get(index) ?? null;
|
|
602
|
-
// No file was written: no writable mount without an include
|
|
603
|
-
// or the framework was stopping.
|
|
630
|
+
// No file was written: no writable mount without an include
|
|
631
|
+
// that isn't configured direct, or the framework was stopping.
|
|
604
632
|
if (spill === null) return [{ toolUseId: block.toolUseId, skipped: 'no_workspace_file' }];
|
|
605
633
|
if ('skipped' in spill) return [{ toolUseId: block.toolUseId, skipped: spill.skipped }];
|
|
606
634
|
return [{ toolUseId: block.toolUseId, path: spill.path,
|