@animalabs/agent-framework 0.32.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +340 -22
- package/dist/src/admission/admit.d.ts +18 -0
- package/dist/src/admission/admit.d.ts.map +1 -1
- package/dist/src/admission/admit.js +16 -3
- package/dist/src/admission/admit.js.map +1 -1
- package/dist/src/agent.d.ts +208 -80
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +345 -113
- package/dist/src/agent.js.map +1 -1
- package/dist/src/api/mcp-server-core.d.ts.map +1 -1
- package/dist/src/api/mcp-server-core.js +50 -12
- package/dist/src/api/mcp-server-core.js.map +1 -1
- package/dist/src/api/server.d.ts.map +1 -1
- package/dist/src/api/server.js +4 -20
- package/dist/src/api/server.js.map +1 -1
- package/dist/src/append-all.d.ts +5 -0
- package/dist/src/append-all.d.ts.map +1 -0
- package/dist/src/append-all.js +8 -0
- package/dist/src/append-all.js.map +1 -0
- package/dist/src/code-execution/isolate/scripts.d.ts +12 -8
- package/dist/src/code-execution/isolate/scripts.d.ts.map +1 -1
- package/dist/src/code-execution/isolate/scripts.js +24 -0
- package/dist/src/code-execution/isolate/scripts.js.map +1 -1
- package/dist/src/config-checks.d.ts +7 -0
- package/dist/src/config-checks.d.ts.map +1 -1
- package/dist/src/config-checks.js +14 -0
- package/dist/src/config-checks.js.map +1 -1
- package/dist/src/context-manager-errors.d.ts +25 -0
- package/dist/src/context-manager-errors.d.ts.map +1 -0
- package/dist/src/context-manager-errors.js +31 -0
- package/dist/src/context-manager-errors.js.map +1 -0
- package/dist/src/context-options.d.ts +70 -0
- package/dist/src/context-options.d.ts.map +1 -0
- package/dist/src/context-options.js +90 -0
- package/dist/src/context-options.js.map +1 -0
- package/dist/src/cut-off-round.js +4 -4
- package/dist/src/deferred-import.d.ts +93 -0
- package/dist/src/deferred-import.d.ts.map +1 -0
- package/dist/src/deferred-import.js +177 -0
- package/dist/src/deferred-import.js.map +1 -0
- package/dist/src/dendrite/audience.d.ts +223 -0
- package/dist/src/dendrite/audience.d.ts.map +1 -0
- package/dist/src/dendrite/audience.js +202 -0
- package/dist/src/dendrite/audience.js.map +1 -0
- package/dist/src/dendrite/index.d.ts +5 -3
- package/dist/src/dendrite/index.d.ts.map +1 -1
- package/dist/src/dendrite/index.js +2 -1
- package/dist/src/dendrite/index.js.map +1 -1
- package/dist/src/dendrite/presets.d.ts +10 -5
- package/dist/src/dendrite/presets.d.ts.map +1 -1
- package/dist/src/dendrite/presets.js +17 -5
- package/dist/src/dendrite/presets.js.map +1 -1
- package/dist/src/dendrite/registry.d.ts +62 -7
- package/dist/src/dendrite/registry.d.ts.map +1 -1
- package/dist/src/dendrite/registry.js +183 -12
- package/dist/src/dendrite/registry.js.map +1 -1
- package/dist/src/dendrite/types.d.ts +91 -8
- package/dist/src/dendrite/types.d.ts.map +1 -1
- package/dist/src/failure-text.d.ts +36 -0
- package/dist/src/failure-text.d.ts.map +1 -0
- package/dist/src/failure-text.js +89 -0
- package/dist/src/failure-text.js.map +1 -0
- package/dist/src/foreign-rounds.d.ts +69 -0
- package/dist/src/foreign-rounds.d.ts.map +1 -0
- package/dist/src/foreign-rounds.js +152 -0
- package/dist/src/foreign-rounds.js.map +1 -0
- package/dist/src/framework.d.ts +2064 -842
- package/dist/src/framework.d.ts.map +1 -1
- package/dist/src/framework.js +8586 -3739
- package/dist/src/framework.js.map +1 -1
- package/dist/src/gate/event-gate.d.ts +125 -21
- package/dist/src/gate/event-gate.d.ts.map +1 -1
- package/dist/src/gate/event-gate.js +487 -72
- package/dist/src/gate/event-gate.js.map +1 -1
- package/dist/src/gate/index.d.ts +1 -1
- package/dist/src/gate/index.d.ts.map +1 -1
- package/dist/src/gate/index.js.map +1 -1
- package/dist/src/gate/reply-judge.d.ts +4 -0
- package/dist/src/gate/reply-judge.d.ts.map +1 -1
- package/dist/src/gate/reply-judge.js +12 -3
- package/dist/src/gate/reply-judge.js.map +1 -1
- package/dist/src/gate/rule-scope.d.ts +30 -0
- package/dist/src/gate/rule-scope.d.ts.map +1 -0
- package/dist/src/gate/rule-scope.js +41 -0
- package/dist/src/gate/rule-scope.js.map +1 -0
- package/dist/src/gate/suppress-script-worker.d.ts +2 -0
- package/dist/src/gate/suppress-script-worker.d.ts.map +1 -0
- package/dist/src/gate/suppress-script-worker.js +103 -0
- package/dist/src/gate/suppress-script-worker.js.map +1 -0
- package/dist/src/gate/suppress-scripts.d.ts +105 -0
- package/dist/src/gate/suppress-scripts.d.ts.map +1 -0
- package/dist/src/gate/suppress-scripts.js +403 -0
- package/dist/src/gate/suppress-scripts.js.map +1 -0
- package/dist/src/gate/suppression-review.d.ts +143 -0
- package/dist/src/gate/suppression-review.d.ts.map +1 -0
- package/dist/src/gate/suppression-review.js +463 -0
- package/dist/src/gate/suppression-review.js.map +1 -0
- package/dist/src/gate/suppression-stats.d.ts +125 -0
- package/dist/src/gate/suppression-stats.d.ts.map +1 -0
- package/dist/src/gate/suppression-stats.js +214 -0
- package/dist/src/gate/suppression-stats.js.map +1 -0
- package/dist/src/gate/types.d.ts +142 -7
- package/dist/src/gate/types.d.ts.map +1 -1
- package/dist/src/gate/wake-onboarding.d.ts +119 -0
- package/dist/src/gate/wake-onboarding.d.ts.map +1 -0
- package/dist/src/gate/wake-onboarding.js +277 -0
- package/dist/src/gate/wake-onboarding.js.map +1 -0
- package/dist/src/heartbeat/heartbeat.js +1 -1
- package/dist/src/heartbeat/heartbeat.js.map +1 -1
- package/dist/src/held-writes.d.ts +31 -23
- package/dist/src/held-writes.d.ts.map +1 -1
- package/dist/src/held-writes.js +44 -59
- package/dist/src/held-writes.js.map +1 -1
- package/dist/src/index.d.ts +6 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/inference-bounds.d.ts +2 -1
- package/dist/src/inference-bounds.d.ts.map +1 -1
- package/dist/src/inference-bounds.js +9 -6
- package/dist/src/inference-bounds.js.map +1 -1
- package/dist/src/jsonrpc-envelope.d.ts +69 -0
- package/dist/src/jsonrpc-envelope.d.ts.map +1 -0
- package/dist/src/jsonrpc-envelope.js +66 -0
- package/dist/src/jsonrpc-envelope.js.map +1 -0
- package/dist/src/mcpl/channel-registry.d.ts +188 -28
- package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
- package/dist/src/mcpl/channel-registry.js +426 -70
- package/dist/src/mcpl/channel-registry.js.map +1 -1
- package/dist/src/mcpl/checkpoint-manager.d.ts +2 -4
- package/dist/src/mcpl/checkpoint-manager.d.ts.map +1 -1
- package/dist/src/mcpl/checkpoint-manager.js.map +1 -1
- package/dist/src/mcpl/feature-set-manager.d.ts +2 -4
- package/dist/src/mcpl/feature-set-manager.d.ts.map +1 -1
- package/dist/src/mcpl/feature-set-manager.js.map +1 -1
- package/dist/src/mcpl/inbound-source.d.ts +2 -1
- package/dist/src/mcpl/inbound-source.d.ts.map +1 -1
- package/dist/src/mcpl/inbound-source.js +2 -1
- package/dist/src/mcpl/inbound-source.js.map +1 -1
- package/dist/src/mcpl/inference-router.d.ts +6 -6
- package/dist/src/mcpl/inference-router.d.ts.map +1 -1
- package/dist/src/mcpl/inference-router.js.map +1 -1
- package/dist/src/mcpl/modern-connection.d.ts +109 -15
- package/dist/src/mcpl/modern-connection.d.ts.map +1 -1
- package/dist/src/mcpl/modern-connection.js +593 -86
- package/dist/src/mcpl/modern-connection.js.map +1 -1
- package/dist/src/mcpl/protocol-family.d.ts +3 -1
- package/dist/src/mcpl/protocol-family.d.ts.map +1 -1
- package/dist/src/mcpl/protocol-family.js +15 -9
- package/dist/src/mcpl/protocol-family.js.map +1 -1
- package/dist/src/mcpl/push-coalescer.d.ts +132 -22
- package/dist/src/mcpl/push-coalescer.d.ts.map +1 -1
- package/dist/src/mcpl/push-coalescer.js +105 -15
- package/dist/src/mcpl/push-coalescer.js.map +1 -1
- package/dist/src/mcpl/push-handler.d.ts +9 -7
- package/dist/src/mcpl/push-handler.d.ts.map +1 -1
- package/dist/src/mcpl/push-handler.js.map +1 -1
- package/dist/src/mcpl/server-connection.d.ts +50 -28
- package/dist/src/mcpl/server-connection.d.ts.map +1 -1
- package/dist/src/mcpl/server-connection.js +165 -72
- package/dist/src/mcpl/server-connection.js.map +1 -1
- package/dist/src/mcpl/tool-classes.d.ts.map +1 -1
- package/dist/src/mcpl/tool-classes.js +3 -0
- package/dist/src/mcpl/tool-classes.js.map +1 -1
- package/dist/src/mcpl/tool-presence.d.ts.map +1 -1
- package/dist/src/mcpl/tool-presence.js +10 -6
- package/dist/src/mcpl/tool-presence.js.map +1 -1
- package/dist/src/mcpl/toolset-host.d.ts.map +1 -1
- package/dist/src/mcpl/toolset-host.js +7 -6
- package/dist/src/mcpl/toolset-host.js.map +1 -1
- package/dist/src/mcpl/toolsets-module.d.ts.map +1 -1
- package/dist/src/mcpl/toolsets-module.js +2 -1
- package/dist/src/mcpl/toolsets-module.js.map +1 -1
- package/dist/src/mcpl/types.d.ts +33 -6
- package/dist/src/mcpl/types.d.ts.map +1 -1
- package/dist/src/mcpl/types.js.map +1 -1
- package/dist/src/module-registry.d.ts +24 -1
- package/dist/src/module-registry.d.ts.map +1 -1
- package/dist/src/module-registry.js +68 -18
- package/dist/src/module-registry.js.map +1 -1
- package/dist/src/modules/discord/index.d.ts +45 -8
- package/dist/src/modules/discord/index.d.ts.map +1 -1
- package/dist/src/modules/discord/index.js +238 -87
- package/dist/src/modules/discord/index.js.map +1 -1
- package/dist/src/modules/health/index.js +2 -2
- package/dist/src/modules/health/index.js.map +1 -1
- package/dist/src/modules/history/index.d.ts +59 -0
- package/dist/src/modules/history/index.d.ts.map +1 -1
- package/dist/src/modules/history/index.js +432 -67
- package/dist/src/modules/history/index.js.map +1 -1
- package/dist/src/modules/history/semantic.d.ts +6 -5
- package/dist/src/modules/history/semantic.d.ts.map +1 -1
- package/dist/src/modules/history/semantic.js +18 -25
- package/dist/src/modules/history/semantic.js.map +1 -1
- package/dist/src/modules/workspace/disk-agreement.d.ts +1 -1
- package/dist/src/modules/workspace/disk-agreement.js +1 -1
- package/dist/src/modules/workspace/index.d.ts +28 -7
- package/dist/src/modules/workspace/index.d.ts.map +1 -1
- package/dist/src/modules/workspace/index.js +80 -25
- package/dist/src/modules/workspace/index.js.map +1 -1
- package/dist/src/modules/workspace/observe.d.ts.map +1 -1
- package/dist/src/modules/workspace/observe.js +2 -1
- package/dist/src/modules/workspace/observe.js.map +1 -1
- package/dist/src/modules/workspace/reconcile.d.ts.map +1 -1
- package/dist/src/modules/workspace/reconcile.js +3 -2
- package/dist/src/modules/workspace/reconcile.js.map +1 -1
- package/dist/src/notice-tags.d.ts +20 -9
- package/dist/src/notice-tags.d.ts.map +1 -1
- package/dist/src/notice-tags.js +20 -9
- package/dist/src/notice-tags.js.map +1 -1
- package/dist/src/operator-log.d.ts +36 -3
- package/dist/src/operator-log.d.ts.map +1 -1
- package/dist/src/operator-log.js +2 -2
- package/dist/src/operator-log.js.map +1 -1
- package/dist/src/presentation.d.ts +747 -0
- package/dist/src/presentation.d.ts.map +1 -0
- package/dist/src/presentation.js +1437 -0
- package/dist/src/presentation.js.map +1 -0
- package/dist/src/prose-drafts.d.ts +15 -11
- package/dist/src/prose-drafts.d.ts.map +1 -1
- package/dist/src/prose-drafts.js +16 -12
- package/dist/src/prose-drafts.js.map +1 -1
- package/dist/src/read-marks.d.ts +192 -0
- package/dist/src/read-marks.d.ts.map +1 -0
- package/dist/src/read-marks.js +242 -0
- package/dist/src/read-marks.js.map +1 -0
- package/dist/src/reasoning-loss.d.ts +5 -0
- package/dist/src/reasoning-loss.d.ts.map +1 -0
- package/dist/src/reasoning-loss.js +8 -0
- package/dist/src/reasoning-loss.js.map +1 -0
- package/dist/src/recovery/offline-branch.d.ts +91 -6
- package/dist/src/recovery/offline-branch.d.ts.map +1 -1
- package/dist/src/recovery/offline-branch.js +277 -32
- package/dist/src/recovery/offline-branch.js.map +1 -1
- package/dist/src/recovery/recover-cli.js +24 -4
- package/dist/src/recovery/recover-cli.js.map +1 -1
- package/dist/src/send-tools.d.ts +5 -9
- package/dist/src/send-tools.d.ts.map +1 -1
- package/dist/src/send-tools.js +40 -7
- package/dist/src/send-tools.js.map +1 -1
- package/dist/src/sent-rows.js +1 -1
- package/dist/src/stored-injections.d.ts +2 -2
- package/dist/src/stored-injections.js +2 -2
- package/dist/src/stored-removal.d.ts +17 -4
- package/dist/src/stored-removal.d.ts.map +1 -1
- package/dist/src/stored-removal.js +29 -5
- package/dist/src/stored-removal.js.map +1 -1
- package/dist/src/supplied-text.d.ts +1 -1
- package/dist/src/supplied-text.js +3 -3
- package/dist/src/supplied-text.js.map +1 -1
- package/dist/src/thinking-drops.d.ts +2 -0
- package/dist/src/thinking-drops.d.ts.map +1 -1
- package/dist/src/thinking-drops.js.map +1 -1
- package/dist/src/tool-presentation.d.ts.map +1 -1
- package/dist/src/tool-presentation.js +38 -9
- package/dist/src/tool-presentation.js.map +1 -1
- package/dist/src/tool-result-guard.d.ts +12 -1
- package/dist/src/tool-result-guard.d.ts.map +1 -1
- package/dist/src/tool-result-guard.js +42 -8
- package/dist/src/tool-result-guard.js.map +1 -1
- package/dist/src/tune-out/coordinator.d.ts +1170 -81
- package/dist/src/tune-out/coordinator.d.ts.map +1 -1
- package/dist/src/tune-out/coordinator.js +3732 -369
- package/dist/src/tune-out/coordinator.js.map +1 -1
- package/dist/src/tune-out/tools.d.ts +114 -17
- package/dist/src/tune-out/tools.d.ts.map +1 -1
- package/dist/src/tune-out/tools.js +89 -28
- package/dist/src/tune-out/tools.js.map +1 -1
- package/dist/src/tune-out/window-anchor.d.ts +143 -0
- package/dist/src/tune-out/window-anchor.d.ts.map +1 -0
- package/dist/src/tune-out/window-anchor.js +202 -0
- package/dist/src/tune-out/window-anchor.js.map +1 -0
- package/dist/src/types/agent.d.ts +121 -25
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/events.d.ts +2 -0
- package/dist/src/types/events.d.ts.map +1 -1
- package/dist/src/types/framework.d.ts +72 -17
- package/dist/src/types/framework.d.ts.map +1 -1
- package/dist/src/types/inference-log.d.ts +1 -0
- package/dist/src/types/inference-log.d.ts.map +1 -1
- package/dist/src/types/module.d.ts +180 -69
- package/dist/src/types/module.d.ts.map +1 -1
- package/dist/src/types/trace.d.ts +573 -39
- package/dist/src/types/trace.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/admission/admit.ts +32 -3
- package/src/agent.ts +392 -132
- package/src/api/mcp-server-core.ts +54 -17
- package/src/api/server.ts +4 -23
- package/src/append-all.ts +6 -0
- package/src/code-execution/isolate/scripts.ts +28 -3
- package/src/config-checks.ts +14 -0
- package/src/context-manager-errors.ts +37 -0
- package/src/context-options.ts +106 -0
- package/src/cut-off-round.ts +4 -4
- package/src/deferred-import.ts +239 -0
- package/src/dendrite/audience.ts +315 -0
- package/src/dendrite/index.ts +14 -2
- package/src/dendrite/presets.ts +18 -6
- package/src/dendrite/registry.ts +213 -14
- package/src/dendrite/types.ts +92 -8
- package/src/failure-text.ts +88 -0
- package/src/foreign-rounds.ts +199 -0
- package/src/framework.ts +8796 -3813
- package/src/gate/event-gate.ts +518 -91
- package/src/gate/index.ts +3 -0
- package/src/gate/reply-judge.ts +12 -3
- package/src/gate/rule-scope.ts +45 -0
- package/src/gate/suppress-script-worker.ts +89 -0
- package/src/gate/suppress-scripts.ts +414 -0
- package/src/gate/suppression-review.ts +517 -0
- package/src/gate/suppression-stats.ts +314 -0
- package/src/gate/types.ts +148 -7
- package/src/gate/wake-onboarding.ts +309 -0
- package/src/heartbeat/heartbeat.ts +1 -1
- package/src/held-writes.ts +49 -60
- package/src/index.ts +10 -2
- package/src/inference-bounds.ts +11 -6
- package/src/jsonrpc-envelope.ts +81 -0
- package/src/mcpl/channel-registry.ts +513 -116
- package/src/mcpl/checkpoint-manager.ts +3 -2
- package/src/mcpl/feature-set-manager.ts +2 -1
- package/src/mcpl/inbound-source.ts +2 -1
- package/src/mcpl/inference-router.ts +7 -4
- package/src/mcpl/modern-connection.ts +629 -91
- package/src/mcpl/protocol-family.ts +15 -9
- package/src/mcpl/push-coalescer.ts +193 -34
- package/src/mcpl/push-handler.ts +10 -5
- package/src/mcpl/server-connection.ts +169 -75
- package/src/mcpl/tool-classes.ts +3 -0
- package/src/mcpl/tool-presence.ts +10 -5
- package/src/mcpl/toolset-host.ts +7 -6
- package/src/mcpl/toolsets-module.ts +2 -1
- package/src/mcpl/types.ts +33 -6
- package/src/module-registry.ts +73 -17
- package/src/modules/discord/index.ts +230 -82
- package/src/modules/health/index.ts +2 -2
- package/src/modules/history/index.ts +439 -70
- package/src/modules/history/semantic.ts +18 -24
- package/src/modules/workspace/disk-agreement.ts +1 -1
- package/src/modules/workspace/index.ts +89 -26
- package/src/modules/workspace/observe.ts +2 -1
- package/src/modules/workspace/reconcile.ts +3 -2
- package/src/notice-tags.ts +21 -9
- package/src/operator-log.ts +36 -3
- package/src/presentation.ts +1678 -0
- package/src/prose-drafts.ts +16 -12
- package/src/read-marks.ts +328 -0
- package/src/reasoning-loss.ts +7 -0
- package/src/recovery/offline-branch.ts +350 -35
- package/src/recovery/recover-cli.ts +23 -4
- package/src/send-tools.ts +40 -7
- package/src/sent-rows.ts +1 -1
- package/src/stored-injections.ts +2 -2
- package/src/stored-removal.ts +31 -7
- package/src/supplied-text.ts +3 -3
- package/src/thinking-drops.ts +2 -0
- package/src/tool-presentation.ts +34 -9
- package/src/tool-result-guard.ts +41 -7
- package/src/tune-out/coordinator.ts +4121 -472
- package/src/tune-out/tools.ts +162 -44
- package/src/tune-out/window-anchor.ts +277 -0
- package/src/types/agent.ts +122 -25
- package/src/types/events.ts +2 -0
- package/src/types/framework.ts +73 -17
- package/src/types/inference-log.ts +1 -0
- package/src/types/module.ts +181 -68
- package/src/types/trace.ts +607 -43
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failure-text.d.ts","sourceRoot":"","sources":["../../src/failure-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIpD;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,OAAQ,CAAC;AAE5C;0DAC0D;AAC1D,eAAO,MAAM,6BAA6B,MAAM,CAAC;AAcjD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,GAAE,MAA+B,GAAG,MAAM,CAU3F;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEtE;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,KAAK,GAAG,aAAa,GAAG,iBAAiB,GAAG,SAAS,CAQ5F;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,KAAK,GAAG,MAAM,GAAG,SAAS,CAE1D;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,KAAK,EAAE,SAAS,SAAoB,GAAG,MAAM,CAU9E"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { MembraneError } from '@animalabs/membrane';
|
|
2
|
+
import { OverBudgetError, UncoveredDropError } from '@animalabs/context-manager';
|
|
3
|
+
import { isDeadlineCut } from './inference-bounds.js';
|
|
4
|
+
/**
|
|
5
|
+
* Longest failure text the inference-failure pipeline writes to one sink: the
|
|
6
|
+
* reason in the exhaustion stderr line, a field of a logs/failures.log record,
|
|
7
|
+
* an ops alert's message, the inference log's `error`, and a trace event's
|
|
8
|
+
* `error` and `stack`. A failure's text is whatever its source put in
|
|
9
|
+
* `Error.message`, and a provider can echo the entire rejected request there
|
|
10
|
+
* (one OpenAI-compatible 400 echoed ~1.7 MB). The sinks with shorter bounds
|
|
11
|
+
* name their own, and every cut goes through boundFailureText. This bound
|
|
12
|
+
* doesn't depend on membrane bounding its own errors.
|
|
13
|
+
*/
|
|
14
|
+
export const FAILURE_TEXT_MAX_CHARS = 2_000;
|
|
15
|
+
/** Longest provider error code recorded verbatim; real codes are short tokens.
|
|
16
|
+
* A failure's name and type are bounded the same way. */
|
|
17
|
+
export const PROVIDER_ERROR_CODE_MAX_CHARS = 128;
|
|
18
|
+
const isHighSurrogate = (text, index) => {
|
|
19
|
+
const code = text.charCodeAt(index);
|
|
20
|
+
return code >= 0xd800 && code <= 0xdbff;
|
|
21
|
+
};
|
|
22
|
+
const isLowSurrogate = (text, index) => {
|
|
23
|
+
const code = text.charCodeAt(index);
|
|
24
|
+
return code >= 0xdc00 && code <= 0xdfff;
|
|
25
|
+
};
|
|
26
|
+
/** Whether a cut before `index` would separate the halves of a surrogate pair. */
|
|
27
|
+
const splitsPair = (text, index) => index > 0 && index < text.length && isHighSurrogate(text, index - 1) && isLowSurrogate(text, index);
|
|
28
|
+
/**
|
|
29
|
+
* `text` when it fits within `max` characters; otherwise its head and tail
|
|
30
|
+
* around a marker stating how many of how many characters were omitted, the
|
|
31
|
+
* whole within `max`. A cut that would separate a surrogate pair moves toward
|
|
32
|
+
* omission, so the result never holds half of a pair the text held whole, and
|
|
33
|
+
* bounding bounded text returns it as is. Each sink cuts the whole text, so
|
|
34
|
+
* its marker states the whole length.
|
|
35
|
+
*/
|
|
36
|
+
export function boundFailureText(text, max = FAILURE_TEXT_MAX_CHARS) {
|
|
37
|
+
if (text.length <= max)
|
|
38
|
+
return text;
|
|
39
|
+
const markerLength = ` …[${text.length} of ${text.length} characters omitted]… `.length;
|
|
40
|
+
const budget = Math.max(0, max - markerLength);
|
|
41
|
+
const tailLength = Math.floor(budget / 4);
|
|
42
|
+
let headEnd = budget - tailLength;
|
|
43
|
+
if (splitsPair(text, headEnd))
|
|
44
|
+
headEnd--;
|
|
45
|
+
let tailStart = text.length - tailLength;
|
|
46
|
+
if (splitsPair(text, tailStart))
|
|
47
|
+
tailStart++;
|
|
48
|
+
return `${text.slice(0, headEnd)} …[${tailStart - headEnd} of ${text.length} characters omitted]… ${text.slice(tailStart)}`;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A MembraneError, from this framework's copy of membrane or from another: the
|
|
52
|
+
* host supplies the Membrane instance (config.membrane), so with two copies
|
|
53
|
+
* installed its errors are instances of a class this framework's `instanceof`
|
|
54
|
+
* doesn't match. Recognised by name as well, as context-manager's errors are;
|
|
55
|
+
* its fields are the same, so callers still check each one's type.
|
|
56
|
+
*/
|
|
57
|
+
export function isMembraneError(error) {
|
|
58
|
+
return error instanceof MembraneError || (error instanceof Error && error.name === 'MembraneError');
|
|
59
|
+
}
|
|
60
|
+
export function compileRefusalType(err) {
|
|
61
|
+
if (err instanceof OverBudgetError || err.name === 'OverBudgetError')
|
|
62
|
+
return 'over_budget';
|
|
63
|
+
// context-manager's fatal coverage invariant (fix/coverage-invariant-fatal,
|
|
64
|
+
// 2026-07-26): a compile REFUSES rather than shipping a context with
|
|
65
|
+
// silently-dropped messages. Recovery is identical to over_budget — kick
|
|
66
|
+
// the compression drain so summaries cover the un-represented span.
|
|
67
|
+
if (err instanceof UncoveredDropError || err.name === 'UncoveredDropError')
|
|
68
|
+
return 'context_refusal';
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
export function houseReason(err) {
|
|
72
|
+
return isDeadlineCut(err) || compileRefusalType(err) !== undefined ? String(err.message) : undefined;
|
|
73
|
+
}
|
|
74
|
+
export function failureWords(err, otherwise = 'the turn failed') {
|
|
75
|
+
const own = houseReason(err);
|
|
76
|
+
if (own !== undefined)
|
|
77
|
+
return own;
|
|
78
|
+
if (!isMembraneError(err))
|
|
79
|
+
return otherwise;
|
|
80
|
+
if (err.type === 'safety')
|
|
81
|
+
return "the request couldn't be completed";
|
|
82
|
+
const status = typeof err.httpStatus === 'number' ? `HTTP ${err.httpStatus}` : undefined;
|
|
83
|
+
if (err.type === 'timeout')
|
|
84
|
+
return `the model call timed out${status ? ` (${status})` : ''}`;
|
|
85
|
+
const type = typeof err.type === 'string' ? boundFailureText(err.type, PROVIDER_ERROR_CODE_MAX_CHARS) : undefined;
|
|
86
|
+
const parts = [type, status].filter((part) => part !== undefined);
|
|
87
|
+
return `the model call failed${parts.length > 0 ? ` (${parts.join(', ')})` : ''}`;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=failure-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failure-text.js","sourceRoot":"","sources":["../../src/failure-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,CAAC;AAE5C;0DAC0D;AAC1D,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAG,CAAC;AAEjD,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,KAAa,EAAW,EAAE;IAC/D,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACpC,OAAO,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,CAAC;AAC1C,CAAC,CAAC;AACF,MAAM,cAAc,GAAG,CAAC,IAAY,EAAE,KAAa,EAAW,EAAE;IAC9D,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACpC,OAAO,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,CAAC;AAC1C,CAAC,CAAC;AACF,kFAAkF;AAClF,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,KAAa,EAAW,EAAE,CAC1D,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,IAAI,eAAe,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,CAAC,IAAI,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAEtG;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,GAAG,GAAW,sBAAsB;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AAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Another agent's rounds as an agent that watches its slot is sent them
|
|
3
|
+
* (#291, answer 13).
|
|
4
|
+
*
|
|
5
|
+
* An agent reads another agent's rounds through an observe edge (decision
|
|
6
|
+
* 1), as the persistent subconscious watches the residents' slot, and an
|
|
7
|
+
* agent derived or forked from such a watcher inherits them, sent in its
|
|
8
|
+
* mode. A co-resident's rows stored before audience stamps, which a window
|
|
9
|
+
* written down from the record keeps, reach an agent that observes no one
|
|
10
|
+
* too: they go out as stored there, as earlier releases sent them. An agent
|
|
11
|
+
* sent others' rounds as a transcript is sent those as one, read by their
|
|
12
|
+
* participant.
|
|
13
|
+
* Those rounds are stored as the other agent's: its signed thinking, its
|
|
14
|
+
* tool calls and their results. None of that is valid as the watcher's own.
|
|
15
|
+
* A provider takes tool blocks only in their own pairing, in the turns of
|
|
16
|
+
* the agent that made the call, and a thinking block's signature binds it
|
|
17
|
+
* to the prefix the other agent was sent. Sent raw in a user turn, the
|
|
18
|
+
* blocks are refused, or moved into the watcher's assistant turns, where
|
|
19
|
+
* they read as calls the watcher made.
|
|
20
|
+
*
|
|
21
|
+
* So by default the watcher is sent them as a transcript, a line per block:
|
|
22
|
+
* a call as the tool's name and its input in brief, a result as the tool's
|
|
23
|
+
* name and its outcome in brief, and no thinking at all. Text, images and
|
|
24
|
+
* the rest go as stored. The signature forbids sending a thinking block as
|
|
25
|
+
* part of another prefix, not its text: leaving the text out is this
|
|
26
|
+
* transcript's choice. A host can have the rounds sent as stored instead
|
|
27
|
+
* (PersistentReaderConfig.foreignRounds `'raw'`, as 0.30.0 sent them). The rule is one function of the stored row, applied the same
|
|
28
|
+
* way to a compile's messages and to a row a tool boundary injects, so what
|
|
29
|
+
* the watcher's window holds and what its requests carried stay one thing.
|
|
30
|
+
*
|
|
31
|
+
* The watcher's own rows go as stored: its rounds (its own participant's
|
|
32
|
+
* messages), and the results of its own calls, which are stored under
|
|
33
|
+
* another participant (`user`) and are told by the call they answer: the
|
|
34
|
+
* nearest call before the result with its id, since a provider (or a mock)
|
|
35
|
+
* that numbers calls per response gives two agents' calls the same id.
|
|
36
|
+
*/
|
|
37
|
+
import type { ContentBlock, NormalizedMessage } from '@animalabs/membrane';
|
|
38
|
+
/**
|
|
39
|
+
* One stored row of another agent's as the watcher is sent it: thinking
|
|
40
|
+
* dropped, each call and each result a line of text, a text block's
|
|
41
|
+
* provider-native item (`rawItem`) dropped with it, everything else as it is.
|
|
42
|
+
* `ownCalls` are the watcher's own calls, whose results it is sent as they
|
|
43
|
+
* are; `callNames` names the calls the row's results answer, where the
|
|
44
|
+
* result doesn't name its tool itself. A row left with nothing says so in
|
|
45
|
+
* a line, rather than going empty.
|
|
46
|
+
*/
|
|
47
|
+
export declare function foreignRowAsSent(content: readonly ContentBlock[], context?: {
|
|
48
|
+
ownCalls?: {
|
|
49
|
+
has(id: string): boolean;
|
|
50
|
+
};
|
|
51
|
+
callNames?: {
|
|
52
|
+
get(id: string): string | undefined;
|
|
53
|
+
};
|
|
54
|
+
}): ContentBlock[];
|
|
55
|
+
/**
|
|
56
|
+
* A request's messages as an agent that watches another's slot is sent them:
|
|
57
|
+
* each message whose participant isn't the agent's own (`isOwn`) through
|
|
58
|
+
* foreignRowAsSent, with the results of the agent's own calls kept, and
|
|
59
|
+
* each result named by the call it answers. A result answers the nearest
|
|
60
|
+
* call before it with its id, read in one pass in order, so another
|
|
61
|
+
* agent's result whose id an own call of the watcher's also has, before or
|
|
62
|
+
* after it, is still transcribed. A call answers one result: a result after
|
|
63
|
+
* the one that answered it, in the same message or a later one, names no
|
|
64
|
+
* call (another agent's, whose call the request doesn't carry), and is
|
|
65
|
+
* transcribed. A message nothing changes is the same object, and so is the
|
|
66
|
+
* array when none changes.
|
|
67
|
+
*/
|
|
68
|
+
export declare function transcribeForeignRounds(messages: readonly NormalizedMessage[], isOwn: (participant: string) => boolean): NormalizedMessage[];
|
|
69
|
+
//# sourceMappingURL=foreign-rounds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foreign-rounds.d.ts","sourceRoot":"","sources":["../../src/foreign-rounds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAkE3E;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,SAAS,YAAY,EAAE,EAChC,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAAC,SAAS,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;KAAE,CAAA;CAAO,GAC7G,YAAY,EAAE,CAwChB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,SAAS,iBAAiB,EAAE,EACtC,KAAK,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,GACtC,iBAAiB,EAAE,CA0BrB"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { NOTICE_TAG } from './notice-tags.js';
|
|
2
|
+
import { cutToFit, markedTexts, oneLine } from './supplied-text.js';
|
|
3
|
+
/** How long one transcript line's call or outcome runs before it is cut. */
|
|
4
|
+
const BRIEF_CHARS = 160;
|
|
5
|
+
/** `text` on one line: each line break the framework counts as one
|
|
6
|
+
* (oneLine), and each other run of whitespace, as one space. */
|
|
7
|
+
function flat(text) {
|
|
8
|
+
return oneLine(text).replace(/\s+/g, ' ').trim();
|
|
9
|
+
}
|
|
10
|
+
/** A tool result's content as pieces: its text, and its other blocks named
|
|
11
|
+
* by kind, in placeholders that are the framework's own. */
|
|
12
|
+
function resultPieces(content) {
|
|
13
|
+
if (typeof content === 'string')
|
|
14
|
+
return [{ text: content, supplied: true }];
|
|
15
|
+
return content.map((b) => (b.type === 'text'
|
|
16
|
+
? { text: b.text, supplied: true }
|
|
17
|
+
: { text: `[${b.type}]`, supplied: false }));
|
|
18
|
+
}
|
|
19
|
+
/** A call's input as a piece: its JSON, or what the model sent when that
|
|
20
|
+
* wasn't an object. */
|
|
21
|
+
function callPiece(block) {
|
|
22
|
+
if (block.unparseableInput !== undefined)
|
|
23
|
+
return { text: block.unparseableInput, supplied: true };
|
|
24
|
+
try {
|
|
25
|
+
return { text: JSON.stringify(block.input ?? {}) ?? '', supplied: true };
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return { text: '', supplied: true };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A transcript line: the framework's bracket around the tool's name, which
|
|
33
|
+
* the other agent's call supplied, the framework's words for what happened
|
|
34
|
+
* (`words[0]` before a call or outcome, `words[1]` when there is none), and
|
|
35
|
+
* the call or outcome in brief. What the line holds is supplied text
|
|
36
|
+
* (#852): set inside the framework's bracket here, where a tool block's own
|
|
37
|
+
* content isn't, an opening of one of the framework's notices is marked
|
|
38
|
+
* wherever it forms, read across the whole line (markedTexts): inside a
|
|
39
|
+
* piece, across a result's blocks, or where the name meets the bracket or
|
|
40
|
+
* the framework's words. Those words and the placeholders aren't marked.
|
|
41
|
+
* Each piece goes on one line first (flat), and the call or outcome is cut
|
|
42
|
+
* to BRIEF_CHARS with an ellipsis, at a whole character, never parting a
|
|
43
|
+
* mark from its bracket (cutToFit).
|
|
44
|
+
*/
|
|
45
|
+
function transcriptLine(name, words, body) {
|
|
46
|
+
const pieces = body.map((p) => ({ ...p, text: flat(p.text) })).filter((p) => p.text.length > 0);
|
|
47
|
+
const word = pieces.length > 0 ? words[0] : words[1];
|
|
48
|
+
const marked = markedTexts(['[', oneLine(name), word, ...pieces.map((p) => p.text)], [true, true, false, ...pieces.map((p) => p.supplied)]);
|
|
49
|
+
const said = marked.slice(3).join(' ');
|
|
50
|
+
return `${marked.slice(0, 3).join('')}${said.length > BRIEF_CHARS ? `${cutToFit(said, BRIEF_CHARS - 1)}…` : said}]`;
|
|
51
|
+
}
|
|
52
|
+
/** Where a row with nothing left to send stands, so the transcript keeps a row for each stored one. */
|
|
53
|
+
const NOTHING_SAID = `[${NOTICE_TAG.noText}]`;
|
|
54
|
+
/**
|
|
55
|
+
* One stored row of another agent's as the watcher is sent it: thinking
|
|
56
|
+
* dropped, each call and each result a line of text, a text block's
|
|
57
|
+
* provider-native item (`rawItem`) dropped with it, everything else as it is.
|
|
58
|
+
* `ownCalls` are the watcher's own calls, whose results it is sent as they
|
|
59
|
+
* are; `callNames` names the calls the row's results answer, where the
|
|
60
|
+
* result doesn't name its tool itself. A row left with nothing says so in
|
|
61
|
+
* a line, rather than going empty.
|
|
62
|
+
*/
|
|
63
|
+
export function foreignRowAsSent(content, context = {}) {
|
|
64
|
+
let changed = false;
|
|
65
|
+
const out = [];
|
|
66
|
+
for (const block of content) {
|
|
67
|
+
switch (block.type) {
|
|
68
|
+
case 'thinking':
|
|
69
|
+
case 'redacted_thinking':
|
|
70
|
+
changed = true;
|
|
71
|
+
break;
|
|
72
|
+
case 'tool_use': {
|
|
73
|
+
changed = true;
|
|
74
|
+
out.push({ type: 'text', text: transcriptLine(block.name, [' called: ', ' called: '], [callPiece(block)]) });
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
case 'tool_result': {
|
|
78
|
+
if (context.ownCalls?.has(block.toolUseId)) {
|
|
79
|
+
out.push(block);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
changed = true;
|
|
83
|
+
const name = block.toolName ?? context.callNames?.get(block.toolUseId) ?? 'a tool';
|
|
84
|
+
const word = block.isError ? ' failed' : ' returned';
|
|
85
|
+
out.push({ type: 'text', text: transcriptLine(name, [`${word}: `, word], resultPieces(block.content)) });
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case 'text': {
|
|
89
|
+
if (block.rawItem === undefined) {
|
|
90
|
+
out.push(block);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
changed = true;
|
|
94
|
+
if (block.text.length > 0)
|
|
95
|
+
out.push({ type: 'text', text: block.text });
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
default:
|
|
99
|
+
out.push(block);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (!changed)
|
|
103
|
+
return content;
|
|
104
|
+
return out.length > 0 ? out : [{ type: 'text', text: NOTHING_SAID }];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A request's messages as an agent that watches another's slot is sent them:
|
|
108
|
+
* each message whose participant isn't the agent's own (`isOwn`) through
|
|
109
|
+
* foreignRowAsSent, with the results of the agent's own calls kept, and
|
|
110
|
+
* each result named by the call it answers. A result answers the nearest
|
|
111
|
+
* call before it with its id, read in one pass in order, so another
|
|
112
|
+
* agent's result whose id an own call of the watcher's also has, before or
|
|
113
|
+
* after it, is still transcribed. A call answers one result: a result after
|
|
114
|
+
* the one that answered it, in the same message or a later one, names no
|
|
115
|
+
* call (another agent's, whose call the request doesn't carry), and is
|
|
116
|
+
* transcribed. A message nothing changes is the same object, and so is the
|
|
117
|
+
* array when none changes.
|
|
118
|
+
*/
|
|
119
|
+
export function transcribeForeignRounds(messages, isOwn) {
|
|
120
|
+
const latest = new Map();
|
|
121
|
+
// The watcher's own call is answered by the first result read for it,
|
|
122
|
+
// block by block: that result takes its entry, so a second result for it
|
|
123
|
+
// in the same message names no call.
|
|
124
|
+
const ownCalls = {
|
|
125
|
+
has: (id) => {
|
|
126
|
+
if (latest.get(id)?.own !== true)
|
|
127
|
+
return false;
|
|
128
|
+
latest.delete(id);
|
|
129
|
+
return true;
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
const callNames = { get: (id) => latest.get(id)?.name };
|
|
133
|
+
let changed = false;
|
|
134
|
+
const out = messages.map((m) => {
|
|
135
|
+
const own = isOwn(m.participant);
|
|
136
|
+
for (const b of m.content)
|
|
137
|
+
if (b.type === 'tool_use')
|
|
138
|
+
latest.set(b.id, { own, name: b.name });
|
|
139
|
+
const content = own ? m.content : foreignRowAsSent(m.content, { ownCalls, callNames });
|
|
140
|
+
// A call answers one result: a later result with its id (another
|
|
141
|
+
// agent's, whose call the request doesn't carry) answers no call here.
|
|
142
|
+
for (const b of m.content)
|
|
143
|
+
if (b.type === 'tool_result')
|
|
144
|
+
latest.delete(b.toolUseId);
|
|
145
|
+
if (content === m.content)
|
|
146
|
+
return m;
|
|
147
|
+
changed = true;
|
|
148
|
+
return { ...m, content };
|
|
149
|
+
});
|
|
150
|
+
return changed ? out : messages;
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=foreign-rounds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foreign-rounds.js","sourceRoot":"","sources":["../../src/foreign-rounds.ts"],"names":[],"mappings":"AAqCA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAEpE,4EAA4E;AAC5E,MAAM,WAAW,GAAG,GAAG,CAAC;AAUxB;iEACiE;AACjE,SAAS,IAAI,CAAC,IAAY;IACxB,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AACnD,CAAC;AAED;6DAC6D;AAC7D,SAAS,YAAY,CAAC,OAAgC;IACpD,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5E,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CA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