@namzu/sdk 0.1.4 → 0.1.5-rc.1-fix
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/CHANGELOG.md +8 -0
- package/dist/advisory/executor.d.ts +2 -2
- package/dist/advisory/executor.d.ts.map +1 -1
- package/dist/advisory/executor.js.map +1 -1
- package/dist/agents/AbstractAgent.d.ts +20 -2
- package/dist/agents/AbstractAgent.d.ts.map +1 -1
- package/dist/agents/AbstractAgent.js +23 -1
- package/dist/agents/AbstractAgent.js.map +1 -1
- package/dist/agents/PipelineAgent.d.ts.map +1 -1
- package/dist/agents/PipelineAgent.js +1 -1
- package/dist/agents/PipelineAgent.js.map +1 -1
- package/dist/agents/ReactiveAgent.d.ts.map +1 -1
- package/dist/agents/ReactiveAgent.js +1 -0
- package/dist/agents/ReactiveAgent.js.map +1 -1
- package/dist/agents/RouterAgent.d.ts.map +1 -1
- package/dist/agents/RouterAgent.js +4 -2
- package/dist/agents/RouterAgent.js.map +1 -1
- package/dist/agents/SupervisorAgent.d.ts.map +1 -1
- package/dist/agents/SupervisorAgent.js +4 -1
- package/dist/agents/SupervisorAgent.js.map +1 -1
- package/dist/agents/__tests__/lock.test.d.ts +2 -0
- package/dist/agents/__tests__/lock.test.d.ts.map +1 -0
- package/dist/agents/__tests__/lock.test.js +131 -0
- package/dist/agents/__tests__/lock.test.js.map +1 -0
- package/dist/agents/index.d.ts +2 -0
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +1 -0
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/lock.d.ts +42 -0
- package/dist/agents/lock.d.ts.map +1 -0
- package/dist/agents/lock.js +54 -0
- package/dist/agents/lock.js.map +1 -0
- package/dist/bridge/a2a/message.d.ts.map +1 -1
- package/dist/bridge/a2a/message.js.map +1 -1
- package/dist/bridge/tools/connector/router.d.ts +4 -5
- package/dist/bridge/tools/connector/router.d.ts.map +1 -1
- package/dist/bridge/tools/connector/router.js.map +1 -1
- package/dist/compaction/__tests__/SlidingWindowManager.test.d.ts +2 -0
- package/dist/compaction/__tests__/SlidingWindowManager.test.d.ts.map +1 -0
- package/dist/compaction/__tests__/SlidingWindowManager.test.js +113 -0
- package/dist/compaction/__tests__/SlidingWindowManager.test.js.map +1 -0
- package/dist/compaction/__tests__/dangling.test.d.ts +2 -0
- package/dist/compaction/__tests__/dangling.test.d.ts.map +1 -0
- package/dist/compaction/__tests__/dangling.test.js +356 -0
- package/dist/compaction/__tests__/dangling.test.js.map +1 -0
- package/dist/compaction/__tests__/factory.test.d.ts +2 -0
- package/dist/compaction/__tests__/factory.test.d.ts.map +1 -0
- package/dist/compaction/__tests__/factory.test.js +43 -0
- package/dist/compaction/__tests__/factory.test.js.map +1 -0
- package/dist/compaction/dangling.d.ts +96 -0
- package/dist/compaction/dangling.d.ts.map +1 -0
- package/dist/compaction/dangling.js +274 -0
- package/dist/compaction/dangling.js.map +1 -0
- package/dist/compaction/factory.d.ts +20 -0
- package/dist/compaction/factory.d.ts.map +1 -0
- package/dist/compaction/factory.js +35 -0
- package/dist/compaction/factory.js.map +1 -0
- package/dist/compaction/index.d.ts +5 -0
- package/dist/compaction/index.d.ts.map +1 -1
- package/dist/compaction/index.js +3 -0
- package/dist/compaction/index.js.map +1 -1
- package/dist/compaction/interface.d.ts +33 -0
- package/dist/compaction/interface.d.ts.map +1 -0
- package/dist/compaction/interface.js +2 -0
- package/dist/compaction/interface.js.map +1 -0
- package/dist/compaction/managers/index.d.ts +4 -0
- package/dist/compaction/managers/index.d.ts.map +1 -0
- package/dist/compaction/managers/index.js +4 -0
- package/dist/compaction/managers/index.js.map +1 -0
- package/dist/compaction/managers/null.d.ts +12 -0
- package/dist/compaction/managers/null.d.ts.map +1 -0
- package/dist/compaction/managers/null.js +15 -0
- package/dist/compaction/managers/null.js.map +1 -0
- package/dist/compaction/managers/slidingWindow.d.ts +27 -0
- package/dist/compaction/managers/slidingWindow.d.ts.map +1 -0
- package/dist/compaction/managers/slidingWindow.js +41 -0
- package/dist/compaction/managers/slidingWindow.js.map +1 -0
- package/dist/compaction/managers/structured.d.ts +23 -0
- package/dist/compaction/managers/structured.d.ts.map +1 -0
- package/dist/compaction/managers/structured.js +144 -0
- package/dist/compaction/managers/structured.js.map +1 -0
- package/dist/compaction/types.d.ts +1 -1
- package/dist/compaction/types.d.ts.map +1 -1
- package/dist/config/runtime.d.ts +16 -16
- package/dist/config/runtime.js +1 -1
- package/dist/config/runtime.js.map +1 -1
- package/dist/constants/agent/index.d.ts +1 -1
- package/dist/constants/agent/index.d.ts.map +1 -1
- package/dist/gateway/local.d.ts +2 -2
- package/dist/gateway/local.d.ts.map +1 -1
- package/dist/gateway/local.js +10 -1
- package/dist/gateway/local.js.map +1 -1
- package/dist/index.d.ts +18 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/manager/agent/lifecycle.d.ts.map +1 -1
- package/dist/manager/agent/lifecycle.js +3 -2
- package/dist/manager/agent/lifecycle.js.map +1 -1
- package/dist/manager/run/persistence.d.ts +1 -2
- package/dist/manager/run/persistence.d.ts.map +1 -1
- package/dist/manager/run/persistence.js +2 -1
- package/dist/manager/run/persistence.js.map +1 -1
- package/dist/plugin/__tests__/lifecycle.test.d.ts +2 -0
- package/dist/plugin/__tests__/lifecycle.test.d.ts.map +1 -0
- package/dist/plugin/__tests__/lifecycle.test.js +332 -0
- package/dist/plugin/__tests__/lifecycle.test.js.map +1 -0
- package/dist/plugin/lifecycle.d.ts +2 -2
- package/dist/plugin/lifecycle.d.ts.map +1 -1
- package/dist/plugin/lifecycle.js +28 -2
- package/dist/plugin/lifecycle.js.map +1 -1
- package/dist/plugin/resolver.d.ts +2 -2
- package/dist/plugin/resolver.d.ts.map +1 -1
- package/dist/plugin/resolver.js.map +1 -1
- package/dist/registry/agent/definitions.d.ts +3 -2
- package/dist/registry/agent/definitions.d.ts.map +1 -1
- package/dist/registry/agent/definitions.js.map +1 -1
- package/dist/registry/tool/execute.d.ts +2 -5
- package/dist/registry/tool/execute.d.ts.map +1 -1
- package/dist/registry/tool/execute.js.map +1 -1
- package/dist/runtime/decision/parser.d.ts.map +1 -1
- package/dist/runtime/decision/parser.js +15 -40
- package/dist/runtime/decision/parser.js.map +1 -1
- package/dist/runtime/query/context-cache.d.ts +3 -3
- package/dist/runtime/query/context-cache.d.ts.map +1 -1
- package/dist/runtime/query/context-cache.js.map +1 -1
- package/dist/runtime/query/context.d.ts +1 -1
- package/dist/runtime/query/context.d.ts.map +1 -1
- package/dist/runtime/query/context.js.map +1 -1
- package/dist/runtime/query/events.js +11 -11
- package/dist/runtime/query/events.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +4 -2
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +1 -0
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts +5 -3
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +2 -1
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts +2 -2
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/advisory.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/advisory.js.map +1 -1
- package/dist/runtime/query/iteration/phases/checkpoint.d.ts +1 -1
- package/dist/runtime/query/iteration/phases/checkpoint.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/checkpoint.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +2 -2
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/plan.d.ts +1 -1
- package/dist/runtime/query/iteration/phases/plan.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/plan.js.map +1 -1
- package/dist/runtime/query/prompt.d.ts +2 -2
- package/dist/runtime/query/prompt.d.ts.map +1 -1
- package/dist/runtime/query/prompt.js.map +1 -1
- package/dist/runtime/query/result.d.ts +1 -1
- package/dist/runtime/query/result.d.ts.map +1 -1
- package/dist/runtime/query/result.js.map +1 -1
- package/dist/runtime/query/tooling.d.ts +4 -2
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js +1 -0
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/store/conversation/memory.d.ts +1 -1
- package/dist/store/conversation/memory.d.ts.map +1 -1
- package/dist/store/conversation/memory.js +15 -3
- package/dist/store/conversation/memory.js.map +1 -1
- package/dist/store/run/disk.d.ts +1 -2
- package/dist/store/run/disk.d.ts.map +1 -1
- package/dist/store/run/disk.js +21 -13
- package/dist/store/run/disk.js.map +1 -1
- package/dist/tools/builtins/__tests__/structuredOutput.example.d.ts +140 -0
- package/dist/tools/builtins/__tests__/structuredOutput.example.d.ts.map +1 -0
- package/dist/tools/builtins/__tests__/structuredOutput.example.js +183 -0
- package/dist/tools/builtins/__tests__/structuredOutput.example.js.map +1 -0
- package/dist/tools/builtins/__tests__/structuredOutput.test.d.ts +2 -0
- package/dist/tools/builtins/__tests__/structuredOutput.test.d.ts.map +1 -0
- package/dist/tools/builtins/__tests__/structuredOutput.test.js +224 -0
- package/dist/tools/builtins/__tests__/structuredOutput.test.js.map +1 -0
- package/dist/tools/builtins/grep.d.ts.map +1 -1
- package/dist/tools/builtins/grep.js +1 -2
- package/dist/tools/builtins/grep.js.map +1 -1
- package/dist/tools/builtins/index.d.ts +1 -0
- package/dist/tools/builtins/index.d.ts.map +1 -1
- package/dist/tools/builtins/index.js +3 -0
- package/dist/tools/builtins/index.js.map +1 -1
- package/dist/tools/builtins/ls.d.ts +1 -1
- package/dist/tools/builtins/structuredOutput.d.ts +27 -0
- package/dist/tools/builtins/structuredOutput.d.ts.map +1 -0
- package/dist/tools/builtins/structuredOutput.js +46 -0
- package/dist/tools/builtins/structuredOutput.js.map +1 -0
- package/dist/tools/task/list.d.ts +1 -1
- package/dist/tools/task/list.d.ts.map +1 -1
- package/dist/tools/task/list.js.map +1 -1
- package/dist/types/agent/base.d.ts +4 -1
- package/dist/types/agent/base.d.ts.map +1 -1
- package/dist/types/agent/index.d.ts +1 -0
- package/dist/types/agent/index.d.ts.map +1 -1
- package/dist/types/agent/index.js +1 -0
- package/dist/types/agent/index.js.map +1 -1
- package/dist/types/agent/manager.d.ts +27 -0
- package/dist/types/agent/manager.d.ts.map +1 -0
- package/dist/types/agent/manager.js +2 -0
- package/dist/types/agent/manager.js.map +1 -0
- package/dist/types/agent/reactive.d.ts +2 -2
- package/dist/types/agent/reactive.d.ts.map +1 -1
- package/dist/types/agent/supervisor.d.ts +2 -2
- package/dist/types/agent/supervisor.d.ts.map +1 -1
- package/dist/types/agent/task.d.ts +0 -2
- package/dist/types/agent/task.d.ts.map +1 -1
- package/dist/types/agent/task.js +0 -2
- package/dist/types/agent/task.js.map +1 -1
- package/dist/types/common/index.d.ts +0 -1
- package/dist/types/common/index.d.ts.map +1 -1
- package/dist/types/common/index.js +0 -1
- package/dist/types/common/index.js.map +1 -1
- package/dist/types/hitl/index.d.ts +1 -2
- package/dist/types/hitl/index.d.ts.map +1 -1
- package/dist/types/hitl/index.js.map +1 -1
- package/dist/types/invocation/__tests__/state.test.d.ts +2 -0
- package/dist/types/invocation/__tests__/state.test.d.ts.map +1 -0
- package/dist/types/invocation/__tests__/state.test.js +167 -0
- package/dist/types/invocation/__tests__/state.test.js.map +1 -0
- package/dist/types/invocation/index.d.ts +37 -0
- package/dist/types/invocation/index.d.ts.map +1 -0
- package/dist/types/invocation/index.js +23 -0
- package/dist/types/invocation/index.js.map +1 -0
- package/dist/types/plugin/index.d.ts +6 -0
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/plugin/index.js +16 -0
- package/dist/types/plugin/index.js.map +1 -1
- package/dist/types/run/events.d.ts +1 -1
- package/dist/types/run/events.d.ts.map +1 -1
- package/dist/types/run/index.d.ts +1 -0
- package/dist/types/run/index.d.ts.map +1 -1
- package/dist/types/run/index.js +1 -0
- package/dist/types/run/index.js.map +1 -1
- package/dist/types/run/metadata.d.ts +1 -1
- package/dist/types/run/metadata.d.ts.map +1 -1
- package/dist/types/run/state.d.ts +1 -1
- package/dist/types/run/state.d.ts.map +1 -1
- package/dist/types/run/stop-reason.d.ts +2 -0
- package/dist/types/run/stop-reason.d.ts.map +1 -0
- package/dist/types/run/stop-reason.js +2 -0
- package/dist/types/run/stop-reason.js.map +1 -0
- package/dist/types/structured-output/index.d.ts +51 -0
- package/dist/types/structured-output/index.d.ts.map +1 -0
- package/dist/types/structured-output/index.js +2 -0
- package/dist/types/structured-output/index.js.map +1 -0
- package/dist/types/tool/index.d.ts +36 -0
- package/dist/types/tool/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/advisory/executor.ts +2 -4
- package/src/agents/AbstractAgent.ts +26 -3
- package/src/agents/PipelineAgent.ts +1 -1
- package/src/agents/ReactiveAgent.ts +1 -0
- package/src/agents/RouterAgent.ts +8 -2
- package/src/agents/SupervisorAgent.ts +5 -1
- package/src/agents/__tests__/lock.test.ts +158 -0
- package/src/agents/index.ts +2 -0
- package/src/agents/lock.ts +66 -0
- package/src/bridge/a2a/message.ts +1 -2
- package/src/bridge/tools/connector/router.ts +4 -5
- package/src/compaction/__tests__/SlidingWindowManager.test.ts +139 -0
- package/src/compaction/__tests__/dangling.test.ts +447 -0
- package/src/compaction/__tests__/factory.test.ts +53 -0
- package/src/compaction/dangling.ts +321 -0
- package/src/compaction/factory.ts +41 -0
- package/src/compaction/index.ts +14 -0
- package/src/compaction/interface.ts +35 -0
- package/src/compaction/managers/index.ts +3 -0
- package/src/compaction/managers/null.ts +19 -0
- package/src/compaction/managers/slidingWindow.ts +57 -0
- package/src/compaction/managers/structured.ts +169 -0
- package/src/compaction/types.ts +1 -1
- package/src/config/runtime.ts +1 -1
- package/src/constants/agent/index.ts +1 -1
- package/src/gateway/local.ts +13 -4
- package/src/index.ts +38 -1
- package/src/manager/agent/lifecycle.ts +3 -2
- package/src/manager/run/persistence.ts +3 -8
- package/src/plugin/__tests__/lifecycle.test.ts +430 -0
- package/src/plugin/lifecycle.ts +32 -6
- package/src/plugin/resolver.ts +3 -3
- package/src/registry/agent/definitions.ts +3 -2
- package/src/registry/tool/execute.ts +2 -5
- package/src/runtime/decision/parser.ts +15 -40
- package/src/runtime/query/context-cache.ts +3 -4
- package/src/runtime/query/context.ts +1 -2
- package/src/runtime/query/events.ts +11 -11
- package/src/runtime/query/executor.ts +5 -3
- package/src/runtime/query/index.ts +11 -4
- package/src/runtime/query/iteration/index.ts +2 -2
- package/src/runtime/query/iteration/phases/advisory.ts +1 -2
- package/src/runtime/query/iteration/phases/checkpoint.ts +1 -2
- package/src/runtime/query/iteration/phases/context.ts +2 -2
- package/src/runtime/query/iteration/phases/plan.ts +1 -2
- package/src/runtime/query/prompt.ts +3 -3
- package/src/runtime/query/result.ts +1 -2
- package/src/runtime/query/tooling.ts +5 -2
- package/src/store/conversation/memory.ts +21 -5
- package/src/store/run/disk.ts +18 -16
- package/src/tools/builtins/__tests__/structuredOutput.example.ts +221 -0
- package/src/tools/builtins/__tests__/structuredOutput.test.ts +275 -0
- package/src/tools/builtins/grep.ts +1 -2
- package/src/tools/builtins/index.ts +3 -0
- package/src/tools/builtins/structuredOutput.ts +55 -0
- package/src/tools/task/list.ts +1 -2
- package/src/types/agent/base.ts +5 -1
- package/src/types/agent/index.ts +1 -0
- package/src/types/agent/manager.ts +36 -0
- package/src/types/agent/reactive.ts +2 -2
- package/src/types/agent/supervisor.ts +2 -2
- package/src/types/agent/task.ts +0 -4
- package/src/types/common/index.ts +0 -2
- package/src/types/hitl/index.ts +1 -2
- package/src/types/invocation/__tests__/state.test.ts +210 -0
- package/src/types/invocation/index.ts +55 -0
- package/src/types/plugin/index.ts +19 -0
- package/src/types/run/events.ts +1 -10
- package/src/types/run/index.ts +1 -0
- package/src/types/run/metadata.ts +1 -1
- package/src/types/run/state.ts +1 -1
- package/src/types/run/stop-reason.ts +10 -0
- package/src/types/structured-output/index.ts +56 -0
- package/src/types/tool/index.ts +45 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.test.d.ts","sourceRoot":"","sources":["../../../src/compaction/__tests__/factory.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { RUNTIME_DEFAULTS } from '../../config/runtime.js';
|
|
3
|
+
import { createConversationManager } from '../factory.js';
|
|
4
|
+
import { NullManager, SlidingWindowManager, StructuredCompactionManager, } from '../managers/index.js';
|
|
5
|
+
describe('createConversationManager', () => {
|
|
6
|
+
const config = RUNTIME_DEFAULTS.compaction;
|
|
7
|
+
it('should create NullManager for disabled strategy', () => {
|
|
8
|
+
const manager = createConversationManager('disabled', config);
|
|
9
|
+
expect(manager).toBeInstanceOf(NullManager);
|
|
10
|
+
expect(manager.name).toBe('null');
|
|
11
|
+
});
|
|
12
|
+
it('should create SlidingWindowManager for sliding-window strategy', () => {
|
|
13
|
+
const manager = createConversationManager('sliding-window', config);
|
|
14
|
+
expect(manager).toBeInstanceOf(SlidingWindowManager);
|
|
15
|
+
expect(manager.name).toBe('sliding-window');
|
|
16
|
+
});
|
|
17
|
+
it('should create StructuredCompactionManager for structured strategy', () => {
|
|
18
|
+
const manager = createConversationManager('structured', config);
|
|
19
|
+
expect(manager).toBeInstanceOf(StructuredCompactionManager);
|
|
20
|
+
expect(manager.name).toBe('structured');
|
|
21
|
+
});
|
|
22
|
+
it('should throw on unknown strategy', () => {
|
|
23
|
+
// @ts-expect-error - Testing invalid input
|
|
24
|
+
expect(() => createConversationManager('unknown', config)).toThrow();
|
|
25
|
+
});
|
|
26
|
+
it('should pass keepRecentMessages to SlidingWindowManager', () => {
|
|
27
|
+
const customConfig = {
|
|
28
|
+
...config,
|
|
29
|
+
keepRecentMessages: 8,
|
|
30
|
+
};
|
|
31
|
+
const manager = createConversationManager('sliding-window', customConfig);
|
|
32
|
+
expect(manager).toBeInstanceOf(SlidingWindowManager);
|
|
33
|
+
});
|
|
34
|
+
it('should pass config to StructuredCompactionManager', () => {
|
|
35
|
+
const customConfig = {
|
|
36
|
+
...config,
|
|
37
|
+
convoTextBudget: 5000,
|
|
38
|
+
};
|
|
39
|
+
const manager = createConversationManager('structured', customConfig);
|
|
40
|
+
expect(manager).toBeInstanceOf(StructuredCompactionManager);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=factory.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.test.js","sourceRoot":"","sources":["../../../src/compaction/__tests__/factory.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAA;AACzD,OAAO,EACN,WAAW,EACX,oBAAoB,EACpB,2BAA2B,GAC3B,MAAM,sBAAsB,CAAA;AAE7B,QAAQ,CAAC,2BAA2B,EAAE,GAAG,EAAE;IAC1C,MAAM,MAAM,GAAG,gBAAgB,CAAC,UAAU,CAAA;IAE1C,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;QAC1D,MAAM,OAAO,GAAG,yBAAyB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;QAC7D,MAAM,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;QAC3C,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAClC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,gEAAgE,EAAE,GAAG,EAAE;QACzE,MAAM,OAAO,GAAG,yBAAyB,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAA;QACnE,MAAM,CAAC,OAAO,CAAC,CAAC,cAA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|
|
|
1
|
+
import type { Message } from '../types/message/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Represents the result of scanning messages for dangling tool call/result pairs.
|
|
4
|
+
* Used to identify which messages should be removed to ensure message validity.
|
|
5
|
+
*/
|
|
6
|
+
export interface DanglingResult {
|
|
7
|
+
/** Indices of assistant messages with unmatched tool calls */
|
|
8
|
+
assistantsWithUnmatchedCalls: number[];
|
|
9
|
+
/** Indices of tool messages with no matching assistant tool call */
|
|
10
|
+
orphanedToolMessages: number[];
|
|
11
|
+
/** Whether the message sequence is valid (no dangling messages) */
|
|
12
|
+
isValid: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Scans a message sequence and identifies dangling tool call/result pairs.
|
|
16
|
+
*
|
|
17
|
+
* A dangling pair occurs when:
|
|
18
|
+
* 1. An assistant message has tool calls but no matching tool message follows
|
|
19
|
+
* 2. A tool message exists but its toolCallId doesn't match any preceding assistant tool call
|
|
20
|
+
*
|
|
21
|
+
* @param messages - Array of messages to scan
|
|
22
|
+
* @returns DanglingResult with indices of invalid messages
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const messages = [
|
|
27
|
+
* { role: 'user', content: 'test' },
|
|
28
|
+
* { role: 'assistant', content: null, toolCalls: [{ id: '1', type: 'function', function: { name: 'test', arguments: '{}' } }] },
|
|
29
|
+
* // Missing tool message for call id '1'
|
|
30
|
+
* { role: 'user', content: 'next' }
|
|
31
|
+
* ]
|
|
32
|
+
* const result = findDanglingMessages(messages)
|
|
33
|
+
* // result.assistantsWithUnmatchedCalls = [1] (index 1 has unmatched tool call)
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function findDanglingMessages(messages: Message[]): DanglingResult;
|
|
37
|
+
/**
|
|
38
|
+
* Removes dangling messages from a message sequence, preserving order.
|
|
39
|
+
*
|
|
40
|
+
* This function removes the minimum set of messages needed to ensure
|
|
41
|
+
* all remaining tool call/result pairs are valid and complete.
|
|
42
|
+
*
|
|
43
|
+
* Algorithm:
|
|
44
|
+
* 1. Identify dangling assistant messages and orphaned tool messages
|
|
45
|
+
* 2. Remove orphaned tool messages
|
|
46
|
+
* 3. For assistant messages with unmatched calls, remove both the assistant
|
|
47
|
+
* message AND any following tool messages that attempt to satisfy it
|
|
48
|
+
*
|
|
49
|
+
* @param messages - Array of messages to clean
|
|
50
|
+
* @returns New array with dangling messages removed, original order preserved
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const messages = [
|
|
55
|
+
* { role: 'user', content: 'test' },
|
|
56
|
+
* { role: 'assistant', content: null, toolCalls: [{ id: '1', ... }] },
|
|
57
|
+
* // Missing tool response
|
|
58
|
+
* { role: 'user', content: 'next' }
|
|
59
|
+
* ]
|
|
60
|
+
* const clean = removeDanglingMessages(messages)
|
|
61
|
+
* // Result: [{ role: 'user', content: 'test' }, { role: 'user', content: 'next' }]
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function removeDanglingMessages(messages: Message[]): Message[];
|
|
65
|
+
/**
|
|
66
|
+
* Finds a safe index for trimming messages while preserving tool call/result atomicity.
|
|
67
|
+
*
|
|
68
|
+
* Given a desired trim point (maxIndex), adjusts it forward to ensure:
|
|
69
|
+
* 1. The trim doesn't split a tool call/result pair
|
|
70
|
+
* 2. The first message after the trim point is not a ToolMessage (orphaned result)
|
|
71
|
+
* 3. All tool call/result pairs are kept intact (either fully included or fully excluded)
|
|
72
|
+
*
|
|
73
|
+
* Algorithm:
|
|
74
|
+
* 1. Start from desired index
|
|
75
|
+
* 2. Check if there's an incomplete tool call/result pair that started before the trim point
|
|
76
|
+
* 3. If so, advance trim point past the complete pair
|
|
77
|
+
* 4. If the new trim point starts with a tool message, advance past it
|
|
78
|
+
*
|
|
79
|
+
* @param messages - Array of messages to analyze
|
|
80
|
+
* @param targetIndex - Desired trim point (exclusive upper bound)
|
|
81
|
+
* @returns Safe trim index where message sequence is valid (at least 0, at most messages.length)
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const messages = [
|
|
86
|
+
* { role: 'user', content: 'test' },
|
|
87
|
+
* { role: 'assistant', content: null, toolCalls: [{ id: '1', ... }] },
|
|
88
|
+
* { role: 'tool', content: 'result', toolCallId: '1' },
|
|
89
|
+
* { role: 'user', content: 'next' }
|
|
90
|
+
* ]
|
|
91
|
+
* const safeIdx = findSafeTrimIndex(messages, 2)
|
|
92
|
+
* // Result: 3 (skips the incomplete pair at index 1-2)
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function findSafeTrimIndex(messages: Message[], targetIndex: number): number;
|
|
96
|
+
//# sourceMappingURL=dangling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dangling.d.ts","sourceRoot":"","sources":["../../src/compaction/dangling.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAExD;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B,8DAA8D;IAC9D,4BAA4B,EAAE,MAAM,EAAE,CAAA;IACtC,oEAAoE;IACpE,oBAAoB,EAAE,MAAM,EAAE,CAAA;IAC9B,mEAAmE;IACnE,OAAO,EAAE,OAAO,CAAA;CAChB;AAmCD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,cAAc,CAuDxE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAiDrE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAqFlF"}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Named constants for dangling message detection logic.
|
|
3
|
+
*/
|
|
4
|
+
const CONSTANTS = {
|
|
5
|
+
/** Role sentinel for tool message identification */
|
|
6
|
+
TOOL_ROLE: 'tool',
|
|
7
|
+
/** Role sentinel for assistant message identification */
|
|
8
|
+
ASSISTANT_ROLE: 'assistant',
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Checks if a message is an assistant message with tool calls.
|
|
12
|
+
* @param message - Message to inspect
|
|
13
|
+
* @returns true if message has role 'assistant' and contains toolCalls array
|
|
14
|
+
*/
|
|
15
|
+
function hasToolCalls(message) {
|
|
16
|
+
return (message.role === CONSTANTS.ASSISTANT_ROLE &&
|
|
17
|
+
'toolCalls' in message &&
|
|
18
|
+
Array.isArray(message.toolCalls) &&
|
|
19
|
+
message.toolCalls.length > 0);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Checks if a message is a tool result message.
|
|
23
|
+
* @param message - Message to inspect
|
|
24
|
+
* @returns true if message has role 'tool'
|
|
25
|
+
*/
|
|
26
|
+
function isToolMessage(message) {
|
|
27
|
+
return message.role === CONSTANTS.TOOL_ROLE;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Scans a message sequence and identifies dangling tool call/result pairs.
|
|
31
|
+
*
|
|
32
|
+
* A dangling pair occurs when:
|
|
33
|
+
* 1. An assistant message has tool calls but no matching tool message follows
|
|
34
|
+
* 2. A tool message exists but its toolCallId doesn't match any preceding assistant tool call
|
|
35
|
+
*
|
|
36
|
+
* @param messages - Array of messages to scan
|
|
37
|
+
* @returns DanglingResult with indices of invalid messages
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const messages = [
|
|
42
|
+
* { role: 'user', content: 'test' },
|
|
43
|
+
* { role: 'assistant', content: null, toolCalls: [{ id: '1', type: 'function', function: { name: 'test', arguments: '{}' } }] },
|
|
44
|
+
* // Missing tool message for call id '1'
|
|
45
|
+
* { role: 'user', content: 'next' }
|
|
46
|
+
* ]
|
|
47
|
+
* const result = findDanglingMessages(messages)
|
|
48
|
+
* // result.assistantsWithUnmatchedCalls = [1] (index 1 has unmatched tool call)
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export function findDanglingMessages(messages) {
|
|
52
|
+
const assistantsWithUnmatchedCalls = [];
|
|
53
|
+
const orphanedToolMessages = [];
|
|
54
|
+
// Build a set of all tool call IDs that exist in assistant messages
|
|
55
|
+
// along with their coverage map (which tool messages satisfy them)
|
|
56
|
+
const toolCallIds = new Map();
|
|
57
|
+
for (let i = 0; i < messages.length; i++) {
|
|
58
|
+
const message = messages[i];
|
|
59
|
+
if (!message)
|
|
60
|
+
continue;
|
|
61
|
+
if (hasToolCalls(message)) {
|
|
62
|
+
// Record all tool calls from this assistant message
|
|
63
|
+
const assistantMsg = message;
|
|
64
|
+
if (assistantMsg.toolCalls) {
|
|
65
|
+
for (const toolCall of assistantMsg.toolCalls) {
|
|
66
|
+
toolCallIds.set(toolCall.id, { assistantIndex: i, satisfied: false });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// Second pass: mark satisfied tool calls and find orphaned tool messages
|
|
72
|
+
for (let i = 0; i < messages.length; i++) {
|
|
73
|
+
const message = messages[i];
|
|
74
|
+
if (!message)
|
|
75
|
+
continue;
|
|
76
|
+
if (isToolMessage(message)) {
|
|
77
|
+
const toolMsg = message;
|
|
78
|
+
if (toolCallIds.has(toolMsg.toolCallId)) {
|
|
79
|
+
// Tool message satisfies a preceding tool call
|
|
80
|
+
const entry = toolCallIds.get(toolMsg.toolCallId);
|
|
81
|
+
if (entry) {
|
|
82
|
+
entry.satisfied = true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// Tool message has no matching tool call
|
|
87
|
+
orphanedToolMessages.push(i);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Third pass: identify unsatisfied tool calls
|
|
92
|
+
for (const entry of toolCallIds.values()) {
|
|
93
|
+
if (!entry.satisfied) {
|
|
94
|
+
assistantsWithUnmatchedCalls.push(entry.assistantIndex);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
assistantsWithUnmatchedCalls,
|
|
99
|
+
orphanedToolMessages,
|
|
100
|
+
isValid: assistantsWithUnmatchedCalls.length === 0 && orphanedToolMessages.length === 0,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Removes dangling messages from a message sequence, preserving order.
|
|
105
|
+
*
|
|
106
|
+
* This function removes the minimum set of messages needed to ensure
|
|
107
|
+
* all remaining tool call/result pairs are valid and complete.
|
|
108
|
+
*
|
|
109
|
+
* Algorithm:
|
|
110
|
+
* 1. Identify dangling assistant messages and orphaned tool messages
|
|
111
|
+
* 2. Remove orphaned tool messages
|
|
112
|
+
* 3. For assistant messages with unmatched calls, remove both the assistant
|
|
113
|
+
* message AND any following tool messages that attempt to satisfy it
|
|
114
|
+
*
|
|
115
|
+
* @param messages - Array of messages to clean
|
|
116
|
+
* @returns New array with dangling messages removed, original order preserved
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const messages = [
|
|
121
|
+
* { role: 'user', content: 'test' },
|
|
122
|
+
* { role: 'assistant', content: null, toolCalls: [{ id: '1', ... }] },
|
|
123
|
+
* // Missing tool response
|
|
124
|
+
* { role: 'user', content: 'next' }
|
|
125
|
+
* ]
|
|
126
|
+
* const clean = removeDanglingMessages(messages)
|
|
127
|
+
* // Result: [{ role: 'user', content: 'test' }, { role: 'user', content: 'next' }]
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export function removeDanglingMessages(messages) {
|
|
131
|
+
const result = findDanglingMessages(messages);
|
|
132
|
+
if (result.isValid) {
|
|
133
|
+
return messages.slice(); // Return shallow copy if already valid
|
|
134
|
+
}
|
|
135
|
+
// Build a set of indices to remove
|
|
136
|
+
const indicesToRemove = new Set();
|
|
137
|
+
// Mark orphaned tool messages for removal
|
|
138
|
+
for (const idx of result.orphanedToolMessages) {
|
|
139
|
+
indicesToRemove.add(idx);
|
|
140
|
+
}
|
|
141
|
+
// For unsatisfied assistant messages:
|
|
142
|
+
// 1. Remove the assistant message itself
|
|
143
|
+
// 2. Remove any immediately following tool messages (they can't match)
|
|
144
|
+
for (const assistantIdx of result.assistantsWithUnmatchedCalls) {
|
|
145
|
+
indicesToRemove.add(assistantIdx);
|
|
146
|
+
// Collect the tool call IDs from this unsatisfied assistant message
|
|
147
|
+
const assistantMsg = messages[assistantIdx];
|
|
148
|
+
const toolCallIds = new Set();
|
|
149
|
+
if (assistantMsg.toolCalls) {
|
|
150
|
+
for (const toolCall of assistantMsg.toolCalls) {
|
|
151
|
+
toolCallIds.add(toolCall.id);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Remove any following tool messages that match these tool call IDs
|
|
155
|
+
// (they are orphaned now that the assistant message is removed)
|
|
156
|
+
for (let i = assistantIdx + 1; i < messages.length; i++) {
|
|
157
|
+
const msg = messages[i];
|
|
158
|
+
if (!msg)
|
|
159
|
+
continue;
|
|
160
|
+
if (isToolMessage(msg)) {
|
|
161
|
+
const toolMsg = msg;
|
|
162
|
+
if (toolCallIds.has(toolMsg.toolCallId)) {
|
|
163
|
+
indicesToRemove.add(i);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// Return messages not marked for removal, preserving order
|
|
169
|
+
return messages.filter((_, idx) => !indicesToRemove.has(idx));
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Finds a safe index for trimming messages while preserving tool call/result atomicity.
|
|
173
|
+
*
|
|
174
|
+
* Given a desired trim point (maxIndex), adjusts it forward to ensure:
|
|
175
|
+
* 1. The trim doesn't split a tool call/result pair
|
|
176
|
+
* 2. The first message after the trim point is not a ToolMessage (orphaned result)
|
|
177
|
+
* 3. All tool call/result pairs are kept intact (either fully included or fully excluded)
|
|
178
|
+
*
|
|
179
|
+
* Algorithm:
|
|
180
|
+
* 1. Start from desired index
|
|
181
|
+
* 2. Check if there's an incomplete tool call/result pair that started before the trim point
|
|
182
|
+
* 3. If so, advance trim point past the complete pair
|
|
183
|
+
* 4. If the new trim point starts with a tool message, advance past it
|
|
184
|
+
*
|
|
185
|
+
* @param messages - Array of messages to analyze
|
|
186
|
+
* @param targetIndex - Desired trim point (exclusive upper bound)
|
|
187
|
+
* @returns Safe trim index where message sequence is valid (at least 0, at most messages.length)
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* const messages = [
|
|
192
|
+
* { role: 'user', content: 'test' },
|
|
193
|
+
* { role: 'assistant', content: null, toolCalls: [{ id: '1', ... }] },
|
|
194
|
+
* { role: 'tool', content: 'result', toolCallId: '1' },
|
|
195
|
+
* { role: 'user', content: 'next' }
|
|
196
|
+
* ]
|
|
197
|
+
* const safeIdx = findSafeTrimIndex(messages, 2)
|
|
198
|
+
* // Result: 3 (skips the incomplete pair at index 1-2)
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
export function findSafeTrimIndex(messages, targetIndex) {
|
|
202
|
+
// Clamp to valid bounds
|
|
203
|
+
const clampedTarget = Math.max(0, Math.min(targetIndex, messages.length));
|
|
204
|
+
// If no messages after trim point, safe to trim here
|
|
205
|
+
if (clampedTarget >= messages.length) {
|
|
206
|
+
return messages.length;
|
|
207
|
+
}
|
|
208
|
+
// Check for incomplete tool call/result pairs that cross the trim boundary
|
|
209
|
+
// Build a map of tool call IDs and whether they have results in the kept portion
|
|
210
|
+
let currentIndex = clampedTarget;
|
|
211
|
+
let attempts = 0;
|
|
212
|
+
const maxAttempts = messages.length; // Prevent infinite loops
|
|
213
|
+
while (attempts < maxAttempts) {
|
|
214
|
+
attempts++;
|
|
215
|
+
if (currentIndex >= messages.length) {
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
// Check if message at currentIndex is a tool message (orphaned result)
|
|
219
|
+
const currentMsg = messages[currentIndex];
|
|
220
|
+
if (currentMsg && isToolMessage(currentMsg)) {
|
|
221
|
+
// Skip orphaned tool message
|
|
222
|
+
currentIndex++;
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
// Check for incomplete tool call/result pairs in the kept portion [0, currentIndex)
|
|
226
|
+
const keptMessages = messages.slice(0, currentIndex);
|
|
227
|
+
const incompleteResult = findDanglingMessages(keptMessages);
|
|
228
|
+
if (!incompleteResult.isValid) {
|
|
229
|
+
// Find the maximum dangling message index
|
|
230
|
+
const allDanglingIndices = [
|
|
231
|
+
...incompleteResult.assistantsWithUnmatchedCalls,
|
|
232
|
+
...incompleteResult.orphanedToolMessages,
|
|
233
|
+
];
|
|
234
|
+
if (allDanglingIndices.length === 0) {
|
|
235
|
+
// No dangling messages found, but isValid is false — shouldn't happen
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
const maxDanglingIdx = Math.max(...allDanglingIndices);
|
|
239
|
+
// Move trim point past the dangling message
|
|
240
|
+
currentIndex = maxDanglingIdx + 1;
|
|
241
|
+
// For assistant messages, also skip following tool messages from that call
|
|
242
|
+
const assistantAtDanglingIdx = messages[maxDanglingIdx];
|
|
243
|
+
if (assistantAtDanglingIdx && hasToolCalls(assistantAtDanglingIdx)) {
|
|
244
|
+
const toolCallIds = new Set();
|
|
245
|
+
const assistantMsg = assistantAtDanglingIdx;
|
|
246
|
+
if (assistantMsg.toolCalls) {
|
|
247
|
+
for (const toolCall of assistantMsg.toolCalls) {
|
|
248
|
+
toolCallIds.add(toolCall.id);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// Skip following tool messages from this assistant
|
|
252
|
+
while (currentIndex < messages.length) {
|
|
253
|
+
const nextMsg = messages[currentIndex];
|
|
254
|
+
if (!nextMsg)
|
|
255
|
+
break;
|
|
256
|
+
if (isToolMessage(nextMsg)) {
|
|
257
|
+
const toolMsg = nextMsg;
|
|
258
|
+
if (toolCallIds.has(toolMsg.toolCallId)) {
|
|
259
|
+
currentIndex++;
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
// No dangling messages in the kept portion, we're safe
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return Math.min(currentIndex, messages.length);
|
|
273
|
+
}
|
|
274
|
+
//# sourceMappingURL=dangling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dangling.js","sourceRoot":"","sources":["../../src/compaction/dangling.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,MAAM,SAAS,GAAG;IACjB,oDAAoD;IACpD,SAAS,EAAE,MAAM;IACjB,yDAAyD;IACzD,cAAc,EAAE,WAAW;CAClB,CAAA;AAEV;;;;GAIG;AACH,SAAS,YAAY,CAAC,OAAgB;IACrC,OAAO,CACN,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,cAAc;QACzC,WAAW,IAAI,OAAO;QACtB,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;QAChC,OAAO,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAC5B,CAAA;AACF,CAAC;AAED;;;;GAIG;AACH,SAAS,aAAa,CAAC,OAAgB;IACtC,OAAO,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,SAAS,CAAA;AAC5C,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAAmB;IACvD,MAAM,4BAA4B,GAAa,EAAE,CAAA;IACjD,MAAM,oBAAoB,GAAa,EAAE,CAAA;IAEzC,oEAAoE;IACpE,mEAAmE;IACnE,MAAM,WAAW,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AC;oBAC5B,KAAK,MAAM,QAAQ,IAAI,YAAY,CAAC,SAAS,EAAE,CAAC;wBAC/C,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;oBAC7B,CAAC;gBACF,CAAC;gBAED,mDAAmD;gBACnD,OAAO,YAAY,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC;oBACvC,MAAM,OAAO,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAA;oBACtC,IAAI,CAAC,OAAO;wBAAE,MAAK;oBACnB,IAAI,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;wBAC5B,MAAM,OAAO,GAAG,OAAiC,CAAA;wBACjD,IAAI,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;4BACzC,YAAY,EAAE,CAAA;4BACd,SAAQ;wBACT,CAAC;oBACF,CAAC;oBACD,MAAK;gBACN,CAAC;YACF,CAAC;QACF,CAAC;aAAM,CAAC;YACP,uDAAuD;YACvD,MAAK;QACN,CAAC;IACF,CAAC;IAED,OAAO,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;AAC/C,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CompactionConfig } from '../config/runtime.js';
|
|
2
|
+
import type { ConversationManager } from './interface.js';
|
|
3
|
+
import type { CompactionStrategy } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Factory function to create a ConversationManager based on the configured strategy.
|
|
6
|
+
*
|
|
7
|
+
* @param strategy - Selected compaction strategy: 'structured', 'sliding-window', or 'disabled'
|
|
8
|
+
* @param config - CompactionConfig with keepRecentMessages and other settings
|
|
9
|
+
* @returns Instantiated ConversationManager
|
|
10
|
+
*
|
|
11
|
+
* @throws If strategy is not recognized (exhaustiveness check ensures this never happens at runtime)
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const manager = createConversationManager('structured', config)
|
|
16
|
+
* const trimmed = manager.applyManagement(messages)
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function createConversationManager(strategy: CompactionStrategy, config: CompactionConfig): ConversationManager;
|
|
20
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/compaction/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAIzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEpD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CACxC,QAAQ,EAAE,kBAAkB,EAC5B,MAAM,EAAE,gBAAgB,GACtB,mBAAmB,CAerB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { NullManager } from './managers/null.js';
|
|
2
|
+
import { SlidingWindowManager } from './managers/slidingWindow.js';
|
|
3
|
+
import { StructuredCompactionManager } from './managers/structured.js';
|
|
4
|
+
/**
|
|
5
|
+
* Factory function to create a ConversationManager based on the configured strategy.
|
|
6
|
+
*
|
|
7
|
+
* @param strategy - Selected compaction strategy: 'structured', 'sliding-window', or 'disabled'
|
|
8
|
+
* @param config - CompactionConfig with keepRecentMessages and other settings
|
|
9
|
+
* @returns Instantiated ConversationManager
|
|
10
|
+
*
|
|
11
|
+
* @throws If strategy is not recognized (exhaustiveness check ensures this never happens at runtime)
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const manager = createConversationManager('structured', config)
|
|
16
|
+
* const trimmed = manager.applyManagement(messages)
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export function createConversationManager(strategy, config) {
|
|
20
|
+
switch (strategy) {
|
|
21
|
+
case 'structured':
|
|
22
|
+
return new StructuredCompactionManager(config);
|
|
23
|
+
case 'sliding-window':
|
|
24
|
+
return new SlidingWindowManager({
|
|
25
|
+
keepRecentMessages: config.keepRecentMessages,
|
|
26
|
+
});
|
|
27
|
+
case 'disabled':
|
|
28
|
+
return new NullManager();
|
|
29
|
+
default: {
|
|
30
|
+
const _exhaustive = strategy;
|
|
31
|
+
throw new Error(`Unknown compaction strategy: ${_exhaustive}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/compaction/factory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAA;AAGtE;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,yBAAyB,CACxC,QAA4B,EAC5B,MAAwB;IAExB,QAAQ,QAAQ,EAAE,CAAC;QAClB,KAAK,YAAY;YAChB,OAAO,IAAI,2BAA2B,CAAC,MAAM,CAAC,CAAA;QAC/C,KAAK,gBAAgB;YACpB,OAAO,IAAI,oBAAoB,CAAC;gBAC/B,kBAAkB,EAAE,MAAM,CAAC,kBAAkB;aAC7C,CAAC,CAAA;QACH,KAAK,UAAU;YACd,OAAO,IAAI,WAAW,EAAE,CAAA;QACzB,OAAO,CAAC,CAAC,CAAC;YACT,MAAM,WAAW,GAAU,QAAQ,CAAA;YACnC,MAAM,IAAI,KAAK,CAAC,gCAAgC,WAAW,EAAE,CAAC,CAAA;QAC/D,CAAC;IACF,CAAC;AACF,CAAC"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export type { WorkingState, PlanSlot, FileSlot, FileAction, ToolResultSlot, CompactionStrategy, } from './types.js';
|
|
2
|
+
export type { DanglingResult } from './dangling.js';
|
|
3
|
+
export type { ConversationManager } from './interface.js';
|
|
2
4
|
export { WorkingStateManager } from './manager.js';
|
|
3
5
|
export { serializeState } from './serializer.js';
|
|
4
6
|
export { extractFromToolCall, extractFromToolResult, extractFromUserMessage, extractFromAssistantMessage, } from './extractor.js';
|
|
5
7
|
export { buildVerifiedSummary } from './verifier.js';
|
|
8
|
+
export { findDanglingMessages, removeDanglingMessages, findSafeTrimIndex, } from './dangling.js';
|
|
9
|
+
export { NullManager, SlidingWindowManager, StructuredCompactionManager } from './managers/index.js';
|
|
10
|
+
export { createConversationManager } from './factory.js';
|
|
6
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compaction/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,cAAc,EACd,kBAAkB,GAClB,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,OAAO,EACN,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,2BAA2B,GAC3B,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compaction/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,cAAc,EACd,kBAAkB,GAClB,MAAM,YAAY,CAAA;AAEnB,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAEnD,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,OAAO,EACN,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,2BAA2B,GAC3B,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAEpD,OAAO,EACN,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,GACjB,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAA;AAEpG,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA"}
|
package/dist/compaction/index.js
CHANGED
|
@@ -2,4 +2,7 @@ export { WorkingStateManager } from './manager.js';
|
|
|
2
2
|
export { serializeState } from './serializer.js';
|
|
3
3
|
export { extractFromToolCall, extractFromToolResult, extractFromUserMessage, extractFromAssistantMessage, } from './extractor.js';
|
|
4
4
|
export { buildVerifiedSummary } from './verifier.js';
|
|
5
|
+
export { findDanglingMessages, removeDanglingMessages, findSafeTrimIndex, } from './dangling.js';
|
|
6
|
+
export { NullManager, SlidingWindowManager, StructuredCompactionManager } from './managers/index.js';
|
|
7
|
+
export { createConversationManager } from './factory.js';
|
|
5
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/compaction/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/compaction/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,OAAO,EACN,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,2BAA2B,GAC3B,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAEpD,OAAO,EACN,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,GACjB,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAA;AAEpG,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Message } from '../types/message/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Strategy interface for managing conversation context.
|
|
4
|
+
* Implementations decide how to handle context overflow and message trimming.
|
|
5
|
+
*
|
|
6
|
+
* A manager applies two strategies:
|
|
7
|
+
* 1. **Routine management** (applyManagement): Called after each iteration to proactively optimize context.
|
|
8
|
+
* 2. **Overflow reduction** (reduceContext): Called when the LLM reports context window exceeded.
|
|
9
|
+
*/
|
|
10
|
+
export interface ConversationManager {
|
|
11
|
+
/** Unique name for this manager (e.g., 'structured', 'sliding-window', 'disabled') */
|
|
12
|
+
readonly name: string;
|
|
13
|
+
/**
|
|
14
|
+
* Apply routine management after each iteration.
|
|
15
|
+
* Called proactively, not in response to an error.
|
|
16
|
+
* Returns modified messages array (or same reference if no changes).
|
|
17
|
+
*
|
|
18
|
+
* @param messages - Current message history
|
|
19
|
+
* @returns Modified messages array (may be same reference if no changes made)
|
|
20
|
+
*/
|
|
21
|
+
applyManagement(messages: Message[]): Message[];
|
|
22
|
+
/**
|
|
23
|
+
* Reduce context when overflow is detected.
|
|
24
|
+
* Called when the LLM reports context window exceeded.
|
|
25
|
+
* Returns true if context was successfully reduced, false if no reduction possible.
|
|
26
|
+
*
|
|
27
|
+
* @param messages - Current message history
|
|
28
|
+
* @param overflowTokens - Approximate number of tokens over budget
|
|
29
|
+
* @returns true if context was successfully reduced, false if no reduction possible
|
|
30
|
+
*/
|
|
31
|
+
reduceContext(messages: Message[], overflowTokens: number): boolean;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/compaction/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAExD;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAmB;IACnC,sFAAsF;IACtF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB;;;;;;;OAOG;IACH,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAAA;IAE/C;;;;;;;;OAQG;IACH,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAA;CACnE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../../src/compaction/interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/compaction/managers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,EAAE,oBAAoB,EAAE,KAAK,0BAA0B,EAAE,MAAM,oBAAoB,CAAA;AAC1F,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/compaction/managers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,EAAE,oBAAoB,EAAmC,MAAM,oBAAoB,CAAA;AAC1F,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Message } from '../../types/message/index.js';
|
|
2
|
+
import type { ConversationManager } from '../interface.js';
|
|
3
|
+
/**
|
|
4
|
+
* No-op conversation manager implementation.
|
|
5
|
+
* Never modifies messages, useful for testing or when context management is disabled.
|
|
6
|
+
*/
|
|
7
|
+
export declare class NullManager implements ConversationManager {
|
|
8
|
+
readonly name = "null";
|
|
9
|
+
applyManagement(messages: Message[]): Message[];
|
|
10
|
+
reduceContext(_messages: Message[], _overflowTokens: number): boolean;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=null.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"null.d.ts","sourceRoot":"","sources":["../../../src/compaction/managers/null.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAE1D;;;GAGG;AACH,qBAAa,WAAY,YAAW,mBAAmB;IACtD,QAAQ,CAAC,IAAI,UAAS;IAEtB,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE;IAI/C,aAAa,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO;CAIrE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* No-op conversation manager implementation.
|
|
3
|
+
* Never modifies messages, useful for testing or when context management is disabled.
|
|
4
|
+
*/
|
|
5
|
+
export class NullManager {
|
|
6
|
+
name = 'null';
|
|
7
|
+
applyManagement(messages) {
|
|
8
|
+
return messages;
|
|
9
|
+
}
|
|
10
|
+
reduceContext(_messages, _overflowTokens) {
|
|
11
|
+
// Cannot reduce; no operations performed
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=null.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"null.js","sourceRoot":"","sources":["../../../src/compaction/managers/null.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,OAAO,WAAW;IACd,IAAI,GAAG,MAAM,CAAA;IAEtB,eAAe,CAAC,QAAmB;QAClC,OAAO,QAAQ,CAAA;IAChB,CAAC;IAED,aAAa,CAAC,SAAoB,EAAE,eAAuB;QAC1D,yCAAyC;QACzC,OAAO,KAAK,CAAA;IACb,CAAC;CACD"}
|