@animalabs/agent-framework 0.8.0 → 0.10.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/dist/src/agent.d.ts +11 -1
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +33 -3
- package/dist/src/agent.js.map +1 -1
- package/dist/src/framework.d.ts +184 -18
- package/dist/src/framework.d.ts.map +1 -1
- package/dist/src/framework.js +1323 -246
- package/dist/src/framework.js.map +1 -1
- package/dist/src/gate/event-gate.d.ts +73 -7
- package/dist/src/gate/event-gate.d.ts.map +1 -1
- package/dist/src/gate/event-gate.js +399 -22
- package/dist/src/gate/event-gate.js.map +1 -1
- package/dist/src/gate/types.d.ts +56 -0
- package/dist/src/gate/types.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcpl/capability-grant.d.ts +115 -0
- package/dist/src/mcpl/capability-grant.d.ts.map +1 -0
- package/dist/src/mcpl/capability-grant.js +291 -0
- package/dist/src/mcpl/capability-grant.js.map +1 -0
- package/dist/src/mcpl/capability-mask.d.ts +51 -0
- package/dist/src/mcpl/capability-mask.d.ts.map +1 -0
- package/dist/src/mcpl/capability-mask.js +190 -0
- package/dist/src/mcpl/capability-mask.js.map +1 -0
- package/dist/src/mcpl/channel-registry.d.ts +3 -1
- package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
- package/dist/src/mcpl/channel-registry.js +163 -36
- package/dist/src/mcpl/channel-registry.js.map +1 -1
- package/dist/src/mcpl/checkpoint-manager.d.ts +8 -3
- package/dist/src/mcpl/checkpoint-manager.d.ts.map +1 -1
- package/dist/src/mcpl/checkpoint-manager.js +28 -8
- package/dist/src/mcpl/checkpoint-manager.js.map +1 -1
- package/dist/src/mcpl/errors.d.ts +6 -0
- package/dist/src/mcpl/errors.d.ts.map +1 -1
- package/dist/src/mcpl/errors.js +6 -0
- package/dist/src/mcpl/errors.js.map +1 -1
- package/dist/src/mcpl/feature-set-manager.d.ts +10 -1
- package/dist/src/mcpl/feature-set-manager.d.ts.map +1 -1
- package/dist/src/mcpl/feature-set-manager.js +45 -4
- package/dist/src/mcpl/feature-set-manager.js.map +1 -1
- package/dist/src/mcpl/hook-orchestrator.d.ts +10 -14
- package/dist/src/mcpl/hook-orchestrator.d.ts.map +1 -1
- package/dist/src/mcpl/hook-orchestrator.js +58 -67
- package/dist/src/mcpl/hook-orchestrator.js.map +1 -1
- package/dist/src/mcpl/index.d.ts +1 -1
- package/dist/src/mcpl/index.d.ts.map +1 -1
- package/dist/src/mcpl/index.js.map +1 -1
- package/dist/src/mcpl/prose-grammar.d.ts +11 -0
- package/dist/src/mcpl/prose-grammar.d.ts.map +1 -1
- package/dist/src/mcpl/prose-grammar.js +21 -0
- package/dist/src/mcpl/prose-grammar.js.map +1 -1
- package/dist/src/mcpl/prose-stream-router.d.ts +11 -2
- package/dist/src/mcpl/prose-stream-router.d.ts.map +1 -1
- package/dist/src/mcpl/prose-stream-router.js +73 -13
- package/dist/src/mcpl/prose-stream-router.js.map +1 -1
- package/dist/src/mcpl/push-handler.d.ts.map +1 -1
- package/dist/src/mcpl/push-handler.js +20 -2
- package/dist/src/mcpl/push-handler.js.map +1 -1
- package/dist/src/mcpl/server-connection.d.ts +93 -9
- package/dist/src/mcpl/server-connection.d.ts.map +1 -1
- package/dist/src/mcpl/server-connection.js +231 -32
- package/dist/src/mcpl/server-connection.js.map +1 -1
- package/dist/src/mcpl/server-registry.d.ts.map +1 -1
- package/dist/src/mcpl/server-registry.js +4 -3
- package/dist/src/mcpl/server-registry.js.map +1 -1
- package/dist/src/mcpl/tags.d.ts +24 -0
- package/dist/src/mcpl/tags.d.ts.map +1 -0
- package/dist/src/mcpl/tags.js +52 -0
- package/dist/src/mcpl/tags.js.map +1 -0
- package/dist/src/mcpl/transport.d.ts.map +1 -1
- package/dist/src/mcpl/transport.js +10 -0
- package/dist/src/mcpl/transport.js.map +1 -1
- package/dist/src/mcpl/types.d.ts +159 -64
- package/dist/src/mcpl/types.d.ts.map +1 -1
- package/dist/src/mcpl/types.js +16 -2
- package/dist/src/mcpl/types.js.map +1 -1
- package/dist/src/modules/workspace/index.d.ts +23 -0
- package/dist/src/modules/workspace/index.d.ts.map +1 -1
- package/dist/src/modules/workspace/index.js +48 -0
- package/dist/src/modules/workspace/index.js.map +1 -1
- package/dist/src/modules/workspace/sync.d.ts +11 -2
- package/dist/src/modules/workspace/sync.d.ts.map +1 -1
- package/dist/src/modules/workspace/sync.js +18 -8
- package/dist/src/modules/workspace/sync.js.map +1 -1
- package/dist/src/refusal-reactions.d.ts +27 -0
- package/dist/src/refusal-reactions.d.ts.map +1 -0
- package/dist/src/refusal-reactions.js +35 -0
- package/dist/src/refusal-reactions.js.map +1 -0
- package/dist/src/tool-result-history.d.ts +20 -0
- package/dist/src/tool-result-history.d.ts.map +1 -1
- package/dist/src/tool-result-history.js +26 -5
- package/dist/src/tool-result-history.js.map +1 -1
- package/dist/src/types/agent.d.ts +39 -1
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/framework.d.ts +16 -0
- package/dist/src/types/framework.d.ts.map +1 -1
- package/dist/src/types/trace.d.ts +24 -0
- package/dist/src/types/trace.d.ts.map +1 -1
- package/dist/test/channel-registry-routing.test.js +38 -10
- package/dist/test/channel-registry-routing.test.js.map +1 -1
- package/dist/test/channel-registry-typing.test.js +10 -1
- package/dist/test/channel-registry-typing.test.js.map +1 -1
- package/dist/test/checkpoint-attribution.test.js +168 -8
- package/dist/test/checkpoint-attribution.test.js.map +1 -1
- package/dist/test/conversation-fork-injection-scoping.test.js +8 -3
- package/dist/test/conversation-fork-injection-scoping.test.js.map +1 -1
- package/dist/test/event-gate-passthrough.test.d.ts +15 -0
- package/dist/test/event-gate-passthrough.test.d.ts.map +1 -0
- package/dist/test/event-gate-passthrough.test.js +289 -0
- package/dist/test/event-gate-passthrough.test.js.map +1 -0
- package/dist/test/event-gate-selfwake.test.d.ts +15 -0
- package/dist/test/event-gate-selfwake.test.d.ts.map +1 -0
- package/dist/test/event-gate-selfwake.test.js +125 -0
- package/dist/test/event-gate-selfwake.test.js.map +1 -0
- package/dist/test/explicit-prose-routing.test.js +137 -7
- package/dist/test/explicit-prose-routing.test.js.map +1 -1
- package/dist/test/fixtures/awareness-barrier-mcpl-server.mjs +276 -0
- package/dist/test/fixtures/flaky-mcpl-server.mjs +41 -0
- package/dist/test/machine-close-provenance.test.js +6 -0
- package/dist/test/machine-close-provenance.test.js.map +1 -1
- package/dist/test/mcpl-awareness-barrier.test.js +10 -0
- package/dist/test/mcpl-awareness-barrier.test.js.map +1 -1
- package/dist/test/mcpl-capability-grant.test.d.ts +10 -0
- package/dist/test/mcpl-capability-grant.test.d.ts.map +1 -0
- package/dist/test/mcpl-capability-grant.test.js +109 -0
- package/dist/test/mcpl-capability-grant.test.js.map +1 -0
- package/dist/test/mcpl-capability-scoping.test.d.ts +2 -0
- package/dist/test/mcpl-capability-scoping.test.d.ts.map +1 -0
- package/dist/test/mcpl-capability-scoping.test.js +266 -0
- package/dist/test/mcpl-capability-scoping.test.js.map +1 -0
- package/dist/test/mcpl-gate-roundtrip.test.js +13 -0
- package/dist/test/mcpl-gate-roundtrip.test.js.map +1 -1
- package/dist/test/mcpl-list-status.test.d.ts +2 -0
- package/dist/test/mcpl-list-status.test.d.ts.map +1 -0
- package/dist/test/mcpl-list-status.test.js +78 -0
- package/dist/test/mcpl-list-status.test.js.map +1 -0
- package/dist/test/mcpl-manifest-changed.test.d.ts +2 -0
- package/dist/test/mcpl-manifest-changed.test.d.ts.map +1 -0
- package/dist/test/mcpl-manifest-changed.test.js +177 -0
- package/dist/test/mcpl-manifest-changed.test.js.map +1 -0
- package/dist/test/mcpl-reconnect-events.test.js +27 -2
- package/dist/test/mcpl-reconnect-events.test.js.map +1 -1
- package/dist/test/mcpl-reconnect-reregistration.test.js +53 -17
- package/dist/test/mcpl-reconnect-reregistration.test.js.map +1 -1
- package/dist/test/mcpl-request-timeout.test.js +1 -1
- package/dist/test/mcpl-request-timeout.test.js.map +1 -1
- package/dist/test/physical-window-restart.test.d.ts +14 -0
- package/dist/test/physical-window-restart.test.d.ts.map +1 -0
- package/dist/test/physical-window-restart.test.js +222 -0
- package/dist/test/physical-window-restart.test.js.map +1 -0
- package/dist/test/present-while-acting.test.js +199 -1
- package/dist/test/present-while-acting.test.js.map +1 -1
- package/dist/test/prose-stream-router.test.js +43 -0
- package/dist/test/prose-stream-router.test.js.map +1 -1
- package/dist/test/refusal-reaction-baseline.test.d.ts +2 -0
- package/dist/test/refusal-reaction-baseline.test.d.ts.map +1 -0
- package/dist/test/refusal-reaction-baseline.test.js +74 -0
- package/dist/test/refusal-reaction-baseline.test.js.map +1 -0
- package/dist/test/state-scaling-e2e.test.js +7 -1
- package/dist/test/state-scaling-e2e.test.js.map +1 -1
- package/dist/test/state-scaling.test.js +9 -1
- package/dist/test/state-scaling.test.js.map +1 -1
- package/dist/test/tool-result-spill.test.d.ts +13 -0
- package/dist/test/tool-result-spill.test.d.ts.map +1 -0
- package/dist/test/tool-result-spill.test.js +472 -0
- package/dist/test/tool-result-spill.test.js.map +1 -0
- package/dist/test/trunk-channel-routing.test.js +45 -0
- package/dist/test/trunk-channel-routing.test.js.map +1 -1
- package/dist/test/xml-round-persist.test.d.ts +19 -0
- package/dist/test/xml-round-persist.test.d.ts.map +1 -0
- package/dist/test/xml-round-persist.test.js +235 -0
- package/dist/test/xml-round-persist.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -4
- package/src/agent.ts +38 -4
- package/src/framework.ts +1488 -272
- package/src/gate/event-gate.ts +427 -24
- package/src/gate/types.ts +58 -0
- package/src/index.ts +1 -0
- package/src/mcpl/capability-grant.ts +319 -0
- package/src/mcpl/capability-mask.ts +228 -0
- package/src/mcpl/channel-registry.ts +167 -39
- package/src/mcpl/checkpoint-manager.ts +28 -8
- package/src/mcpl/errors.ts +7 -0
- package/src/mcpl/feature-set-manager.ts +50 -5
- package/src/mcpl/hook-orchestrator.ts +64 -86
- package/src/mcpl/index.ts +0 -2
- package/src/mcpl/prose-grammar.ts +21 -0
- package/src/mcpl/prose-stream-router.ts +65 -14
- package/src/mcpl/push-handler.ts +18 -2
- package/src/mcpl/server-connection.ts +262 -34
- package/src/mcpl/server-registry.ts +4 -3
- package/src/mcpl/tags.ts +50 -0
- package/src/mcpl/transport.ts +11 -0
- package/src/mcpl/types.ts +176 -78
- package/src/modules/workspace/index.ts +48 -0
- package/src/modules/workspace/sync.ts +30 -7
- package/src/refusal-reactions.ts +37 -0
- package/src/tool-result-history.ts +27 -5
- package/src/types/agent.ts +40 -1
- package/src/types/framework.ts +17 -0
- package/src/types/trace.ts +22 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@animalabs/agent-framework",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Multi-agent framework with pluggable modules, persistent state, and concurrent tool execution",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"clean": "rm -rf dist",
|
|
32
32
|
"typecheck": "tsc --noEmit",
|
|
33
33
|
"pretest": "mkdir -p dist/test/fixtures && cp test/fixtures/*.mjs dist/test/fixtures/",
|
|
34
|
-
"test": "node --test dist/test/*.test.js",
|
|
34
|
+
"test": "node --test --test-force-exit dist/test/*.test.js",
|
|
35
|
+
"version": "node scripts/release-changelog.mjs && git add CHANGELOG.md",
|
|
35
36
|
"prepublishOnly": "npm run build"
|
|
36
37
|
},
|
|
37
38
|
"keywords": [
|
|
@@ -45,9 +46,9 @@
|
|
|
45
46
|
"author": "Anima Research",
|
|
46
47
|
"license": "MIT",
|
|
47
48
|
"dependencies": {
|
|
48
|
-
"@animalabs/chronicle": "^0.
|
|
49
|
+
"@animalabs/chronicle": "^0.3.0",
|
|
49
50
|
"@animalabs/context-manager": "^0.6.0",
|
|
50
|
-
"@animalabs/membrane": "^0.5.
|
|
51
|
+
"@animalabs/membrane": "^0.5.78",
|
|
51
52
|
"chokidar": "^4.0.3",
|
|
52
53
|
"discord.js": "^14.25.1",
|
|
53
54
|
"ws": "^8.18.0"
|
package/src/agent.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { Membrane, NormalizedMessage, NormalizedRequest, ContentBlock, YieldingStream } from '@animalabs/membrane';
|
|
2
2
|
import { isAbortedResponse } from '@animalabs/membrane';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
toolResultDataToHistoryString,
|
|
5
|
+
truncateForHistory,
|
|
6
|
+
DEFAULT_TOOL_RESULT_INLINE_MAX_CHARS,
|
|
7
|
+
} from './tool-result-history.js';
|
|
4
8
|
|
|
5
9
|
export interface StartStreamResult {
|
|
6
10
|
stream: YieldingStream;
|
|
@@ -63,7 +67,7 @@ export class Agent {
|
|
|
63
67
|
/** Refusal auto-rewind policy (see AgentConfig.refusalHandling). */
|
|
64
68
|
readonly refusalHandling: AgentConfig['refusalHandling'];
|
|
65
69
|
/** Prose delivery mode (see AgentConfig.proseRouting). Default 'locus'. */
|
|
66
|
-
readonly proseRouting: 'locus' | 'explicit';
|
|
70
|
+
readonly proseRouting: 'locus' | 'explicit' | 'hybrid';
|
|
67
71
|
/** Prompt-cache TTL forwarded to the provider (see AgentConfig.cacheTtl). */
|
|
68
72
|
readonly cacheTtl: NonNullable<AgentConfig['cacheTtl']>;
|
|
69
73
|
/** Emit prompt-cache markers on requests (see AgentConfig.promptCaching). */
|
|
@@ -78,7 +82,17 @@ export class Agent {
|
|
|
78
82
|
private _inferenceStartedAt = 0;
|
|
79
83
|
private _streamId = 0;
|
|
80
84
|
lastStreamInputTokens = 0;
|
|
85
|
+
/** Real prefix size of the last usage event: fresh + cache creation +
|
|
86
|
+
* cache read. THE window-shaped number — `lastStreamInputTokens` alone
|
|
87
|
+
* omits cached tokens, which are most of a warm stream's window. */
|
|
88
|
+
lastStreamRealInputTokens = 0;
|
|
89
|
+
/** Output tokens of the last usage event — the prior round's generated
|
|
90
|
+
* thinking/text/tool_use, which becomes part of the NEXT round's input
|
|
91
|
+
* and so belongs in the physical-window projection. */
|
|
92
|
+
lastStreamOutputTokens = 0;
|
|
81
93
|
maxStreamTokens: number;
|
|
94
|
+
/** Provider hard context cap (see AgentConfig.physicalWindowTokens). */
|
|
95
|
+
readonly physicalWindowTokens?: number;
|
|
82
96
|
/** Per-agent context compile budget (input tokens). When unset, the
|
|
83
97
|
* ContextManager's built-in default applies. reserveForResponse uses
|
|
84
98
|
* this agent's maxTokens. */
|
|
@@ -113,6 +127,7 @@ export class Agent {
|
|
|
113
127
|
this.providerParams = config.providerParams;
|
|
114
128
|
this.sameRoundThinkTextPolicy = config.sameRoundThinkTextPolicy;
|
|
115
129
|
this.maxStreamTokens = config.maxStreamTokens ?? 150_000;
|
|
130
|
+
this.physicalWindowTokens = config.physicalWindowTokens;
|
|
116
131
|
this.contextBudgetTokens = config.contextBudgetTokens;
|
|
117
132
|
this.configuredContextBudgetTokens = config.contextBudgetTokens;
|
|
118
133
|
this.contextManager = contextManager;
|
|
@@ -676,6 +691,14 @@ export class Agent {
|
|
|
676
691
|
this._streamId++;
|
|
677
692
|
this._inferenceStartedAt = Date.now();
|
|
678
693
|
this.lastStreamInputTokens = 0;
|
|
694
|
+
// Reset the cache-inclusive counters too: a new stream must not inherit
|
|
695
|
+
// the prior stream's window size — on the physical-window restart path
|
|
696
|
+
// that inherited value IS the oversized number that caused the restart,
|
|
697
|
+
// and projecting on it before this stream's first usage event would
|
|
698
|
+
// restart again (loop). The `> 0` guard downstream means "no usage
|
|
699
|
+
// observed on THIS stream yet" only because of this reset.
|
|
700
|
+
this.lastStreamRealInputTokens = 0;
|
|
701
|
+
this.lastStreamOutputTokens = 0;
|
|
679
702
|
|
|
680
703
|
const request = await this.buildActivationRequest(availableTools, injections, budget);
|
|
681
704
|
|
|
@@ -683,6 +706,12 @@ export class Agent {
|
|
|
683
706
|
emitTokens: true,
|
|
684
707
|
emitBlocks: false,
|
|
685
708
|
emitUsage: true,
|
|
709
|
+
// Retry a content-policy refusal at the provider seam rather than at
|
|
710
|
+
// the framework level: membrane replays the SAME request immediately
|
|
711
|
+
// (cache-warm), where a framework-level requeue would recompile and
|
|
712
|
+
// land a different window. The framework's driveStream handles the
|
|
713
|
+
// resulting `retrying` event by discarding the abandoned attempt.
|
|
714
|
+
...(this.refusalHandling?.retries ? { refusalRetries: this.refusalHandling.retries } : {}),
|
|
686
715
|
});
|
|
687
716
|
|
|
688
717
|
this._state = { status: 'streaming', stream };
|
|
@@ -884,12 +913,17 @@ export class Agent {
|
|
|
884
913
|
// Tool results go as a user message with tool_result blocks. The history
|
|
885
914
|
// serializer turns MCP image blocks into `[image: type, size]` so the
|
|
886
915
|
// persisted transcript stays small and survives truncation.
|
|
916
|
+
//
|
|
917
|
+
// This is the direct-Agent-API path (the framework stores results itself
|
|
918
|
+
// via buildStoredToolResultContent, with workspace spill). No workspace
|
|
919
|
+
// is reachable from here, so the house default cap applies as plain
|
|
920
|
+
// truncation — bounded beats unbounded, for errors too.
|
|
887
921
|
const content = results.map((r) => ({
|
|
888
922
|
type: 'tool_result' as const,
|
|
889
923
|
toolUseId: r.id,
|
|
890
924
|
content: r.result.isError
|
|
891
|
-
? r.result.error ?? 'Unknown error'
|
|
892
|
-
: toolResultDataToHistoryString(r.result.data),
|
|
925
|
+
? truncateForHistory(r.result.error ?? 'Unknown error', DEFAULT_TOOL_RESULT_INLINE_MAX_CHARS)
|
|
926
|
+
: toolResultDataToHistoryString(r.result.data, DEFAULT_TOOL_RESULT_INLINE_MAX_CHARS),
|
|
893
927
|
isError: r.result.isError,
|
|
894
928
|
}));
|
|
895
929
|
|