@namzu/sdk 3.0.0 → 3.2.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/CHANGELOG.md +223 -0
- package/dist/advisory/__tests__/consultation-context.test.d.ts +2 -0
- package/dist/advisory/__tests__/consultation-context.test.d.ts.map +1 -0
- package/dist/advisory/__tests__/consultation-context.test.js +124 -0
- package/dist/advisory/__tests__/consultation-context.test.js.map +1 -0
- package/dist/advisory/context.d.ts +25 -0
- package/dist/advisory/context.d.ts.map +1 -1
- package/dist/advisory/context.js +18 -0
- package/dist/advisory/context.js.map +1 -1
- package/dist/advisory/executor.d.ts.map +1 -1
- package/dist/advisory/executor.js +25 -3
- package/dist/advisory/executor.js.map +1 -1
- package/dist/compaction/__tests__/context-reducer.test.d.ts +2 -0
- package/dist/compaction/__tests__/context-reducer.test.d.ts.map +1 -0
- package/dist/compaction/__tests__/context-reducer.test.js +197 -0
- package/dist/compaction/__tests__/context-reducer.test.js.map +1 -0
- package/dist/compaction/factory.d.ts +7 -0
- package/dist/compaction/factory.d.ts.map +1 -1
- package/dist/compaction/factory.js +7 -0
- package/dist/compaction/factory.js.map +1 -1
- package/dist/compaction/index.d.ts +2 -0
- package/dist/compaction/index.d.ts.map +1 -1
- package/dist/compaction/index.js +1 -0
- package/dist/compaction/index.js.map +1 -1
- package/dist/compaction/interface.d.ts +13 -0
- package/dist/compaction/interface.d.ts.map +1 -1
- package/dist/compaction/managers/null.d.ts +3 -0
- package/dist/compaction/managers/null.d.ts.map +1 -1
- package/dist/compaction/managers/null.js +3 -0
- package/dist/compaction/managers/null.js.map +1 -1
- package/dist/compaction/managers/slidingWindow.d.ts +6 -0
- package/dist/compaction/managers/slidingWindow.d.ts.map +1 -1
- package/dist/compaction/managers/slidingWindow.js +6 -0
- package/dist/compaction/managers/slidingWindow.js.map +1 -1
- package/dist/compaction/managers/structured.d.ts +10 -0
- package/dist/compaction/managers/structured.d.ts.map +1 -1
- package/dist/compaction/managers/structured.js +10 -0
- package/dist/compaction/managers/structured.js.map +1 -1
- package/dist/compaction/reducer.d.ts +86 -0
- package/dist/compaction/reducer.d.ts.map +1 -0
- package/dist/compaction/reducer.js +77 -0
- package/dist/compaction/reducer.js.map +1 -0
- package/dist/connector/builtins/__tests__/oauth2-auth.test.d.ts +2 -0
- package/dist/connector/builtins/__tests__/oauth2-auth.test.d.ts.map +1 -0
- package/dist/connector/builtins/__tests__/oauth2-auth.test.js +54 -0
- package/dist/connector/builtins/__tests__/oauth2-auth.test.js.map +1 -0
- package/dist/connector/builtins/http.d.ts.map +1 -1
- package/dist/connector/builtins/http.js +24 -2
- package/dist/connector/builtins/http.js.map +1 -1
- package/dist/connector/builtins/http.test.js +18 -2
- package/dist/connector/builtins/http.test.js.map +1 -1
- package/dist/connector/index.d.ts +2 -2
- package/dist/connector/index.d.ts.map +1 -1
- package/dist/connector/index.js +1 -1
- package/dist/connector/index.js.map +1 -1
- package/dist/connector/mcp/__tests__/prompts-and-lifecycle.test.d.ts +2 -0
- package/dist/connector/mcp/__tests__/prompts-and-lifecycle.test.d.ts.map +1 -0
- package/dist/connector/mcp/__tests__/prompts-and-lifecycle.test.js +214 -0
- package/dist/connector/mcp/__tests__/prompts-and-lifecycle.test.js.map +1 -0
- package/dist/connector/mcp/client.d.ts +52 -1
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +86 -0
- package/dist/connector/mcp/client.js.map +1 -1
- package/dist/connector/mcp/discovery.d.ts +12 -1
- package/dist/connector/mcp/discovery.d.ts.map +1 -1
- package/dist/connector/mcp/discovery.js +19 -4
- package/dist/connector/mcp/discovery.js.map +1 -1
- package/dist/connector/mcp/index.d.ts +2 -2
- package/dist/connector/mcp/index.d.ts.map +1 -1
- package/dist/connector/mcp/index.js +1 -1
- package/dist/connector/mcp/index.js.map +1 -1
- package/dist/connector/mcp/server.d.ts +42 -1
- package/dist/connector/mcp/server.d.ts.map +1 -1
- package/dist/connector/mcp/server.js +77 -4
- package/dist/connector/mcp/server.js.map +1 -1
- package/dist/manager/agent/__tests__/depth-limit-authority.test.d.ts +2 -0
- package/dist/manager/agent/__tests__/depth-limit-authority.test.d.ts.map +1 -0
- package/dist/manager/agent/__tests__/depth-limit-authority.test.js +58 -0
- package/dist/manager/agent/__tests__/depth-limit-authority.test.js.map +1 -0
- package/dist/plugin/__tests__/discovery-scopes.test.d.ts +2 -0
- package/dist/plugin/__tests__/discovery-scopes.test.d.ts.map +1 -0
- package/dist/plugin/__tests__/discovery-scopes.test.js +97 -0
- package/dist/plugin/__tests__/discovery-scopes.test.js.map +1 -0
- package/dist/plugin/__tests__/enable-contributions.test.js +5 -1
- package/dist/plugin/__tests__/enable-contributions.test.js.map +1 -1
- package/dist/plugin/__tests__/mcp-admission.test.d.ts +2 -0
- package/dist/plugin/__tests__/mcp-admission.test.d.ts.map +1 -0
- package/dist/plugin/__tests__/mcp-admission.test.js +192 -0
- package/dist/plugin/__tests__/mcp-admission.test.js.map +1 -0
- package/dist/plugin/lifecycle.d.ts +41 -0
- package/dist/plugin/lifecycle.d.ts.map +1 -1
- package/dist/plugin/lifecycle.js +29 -1
- package/dist/plugin/lifecycle.js.map +1 -1
- package/dist/plugin/loader.d.ts +39 -3
- package/dist/plugin/loader.d.ts.map +1 -1
- package/dist/plugin/loader.js +37 -4
- package/dist/plugin/loader.js.map +1 -1
- package/dist/public-runtime.d.ts +5 -3
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +11 -3
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-types.d.ts +2 -2
- package/dist/public-types.d.ts.map +1 -1
- package/dist/rag/__tests__/namespace-isolation.test.d.ts +2 -0
- package/dist/rag/__tests__/namespace-isolation.test.d.ts.map +1 -0
- package/dist/rag/__tests__/namespace-isolation.test.js +80 -0
- package/dist/rag/__tests__/namespace-isolation.test.js.map +1 -0
- package/dist/rag/ingestion.d.ts.map +1 -1
- package/dist/rag/ingestion.js +1 -0
- package/dist/rag/ingestion.js.map +1 -1
- package/dist/rag/retriever.d.ts.map +1 -1
- package/dist/rag/retriever.js +2 -0
- package/dist/rag/retriever.js.map +1 -1
- package/dist/rag/vector-store.d.ts.map +1 -1
- package/dist/rag/vector-store.js +6 -0
- package/dist/rag/vector-store.js.map +1 -1
- package/dist/registry/tool/execute.d.ts.map +1 -1
- package/dist/registry/tool/execute.js +113 -109
- package/dist/registry/tool/execute.js.map +1 -1
- package/dist/runtime/query/__tests__/capability-negotiation.test.js +59 -0
- package/dist/runtime/query/__tests__/capability-negotiation.test.js.map +1 -1
- package/dist/runtime/query/__tests__/per-step-skills.test.d.ts +10 -0
- package/dist/runtime/query/__tests__/per-step-skills.test.d.ts.map +1 -0
- package/dist/runtime/query/__tests__/per-step-skills.test.js +122 -0
- package/dist/runtime/query/__tests__/per-step-skills.test.js.map +1 -0
- package/dist/runtime/query/__tests__/per-step-tool-choice.test.d.ts +2 -0
- package/dist/runtime/query/__tests__/per-step-tool-choice.test.d.ts.map +1 -0
- package/dist/runtime/query/__tests__/per-step-tool-choice.test.js +153 -0
- package/dist/runtime/query/__tests__/per-step-tool-choice.test.js.map +1 -0
- package/dist/runtime/query/__tests__/resume-run.test.d.ts +2 -0
- package/dist/runtime/query/__tests__/resume-run.test.d.ts.map +1 -0
- package/dist/runtime/query/__tests__/resume-run.test.js +211 -0
- package/dist/runtime/query/__tests__/resume-run.test.js.map +1 -0
- package/dist/runtime/query/executor.d.ts +1 -0
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +10 -1
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts +10 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +26 -0
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +118 -34
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction-model-routing.test.d.ts +2 -0
- package/dist/runtime/query/iteration/phases/compaction-model-routing.test.d.ts.map +1 -0
- package/dist/runtime/query/iteration/phases/compaction-model-routing.test.js +96 -0
- package/dist/runtime/query/iteration/phases/compaction-model-routing.test.js.map +1 -0
- package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.js +95 -5
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context-reducer-dispatch.test.d.ts +2 -0
- package/dist/runtime/query/iteration/phases/context-reducer-dispatch.test.d.ts.map +1 -0
- package/dist/runtime/query/iteration/phases/context-reducer-dispatch.test.js +180 -0
- package/dist/runtime/query/iteration/phases/context-reducer-dispatch.test.js.map +1 -0
- package/dist/runtime/query/iteration/phases/context.d.ts +9 -0
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/runtime/query/resume-run.d.ts +70 -0
- package/dist/runtime/query/resume-run.d.ts.map +1 -0
- package/dist/runtime/query/resume-run.js +46 -0
- package/dist/runtime/query/resume-run.js.map +1 -0
- package/dist/telemetry/__tests__/model-call-span.test.d.ts +2 -0
- package/dist/telemetry/__tests__/model-call-span.test.d.ts.map +1 -0
- package/dist/telemetry/__tests__/model-call-span.test.js +147 -0
- package/dist/telemetry/__tests__/model-call-span.test.js.map +1 -0
- package/dist/telemetry/__tests__/span-closure.test.d.ts +2 -0
- package/dist/telemetry/__tests__/span-closure.test.d.ts.map +1 -0
- package/dist/telemetry/__tests__/span-closure.test.js +124 -0
- package/dist/telemetry/__tests__/span-closure.test.js.map +1 -0
- package/dist/tools/advisory/index.js +1 -1
- package/dist/tools/advisory/index.js.map +1 -1
- package/dist/tools/builtins/__tests__/edit-commits-atomically.test.d.ts +2 -0
- package/dist/tools/builtins/__tests__/edit-commits-atomically.test.d.ts.map +1 -0
- package/dist/tools/builtins/__tests__/edit-commits-atomically.test.js +78 -0
- package/dist/tools/builtins/__tests__/edit-commits-atomically.test.js.map +1 -0
- package/dist/tools/builtins/__tests__/edit.test.js +242 -1
- package/dist/tools/builtins/__tests__/edit.test.js.map +1 -1
- package/dist/tools/builtins/__tests__/stale-file-refusal.test.d.ts +2 -0
- package/dist/tools/builtins/__tests__/stale-file-refusal.test.d.ts.map +1 -0
- package/dist/tools/builtins/__tests__/stale-file-refusal.test.js +187 -0
- package/dist/tools/builtins/__tests__/stale-file-refusal.test.js.map +1 -0
- package/dist/tools/builtins/atomic-write-file.d.ts +1 -1
- package/dist/tools/builtins/atomic-write-file.d.ts.map +1 -1
- package/dist/tools/builtins/atomic-write-file.js +31 -2
- package/dist/tools/builtins/atomic-write-file.js.map +1 -1
- package/dist/tools/builtins/content-fingerprint.d.ts +23 -0
- package/dist/tools/builtins/content-fingerprint.d.ts.map +1 -0
- package/dist/tools/builtins/content-fingerprint.js +30 -0
- package/dist/tools/builtins/content-fingerprint.js.map +1 -0
- package/dist/tools/builtins/edit.d.ts.map +1 -1
- package/dist/tools/builtins/edit.js +172 -31
- package/dist/tools/builtins/edit.js.map +1 -1
- package/dist/tools/builtins/read-file.d.ts.map +1 -1
- package/dist/tools/builtins/read-file.js +5 -2
- package/dist/tools/builtins/read-file.js.map +1 -1
- package/dist/tools/builtins/write-file.d.ts.map +1 -1
- package/dist/tools/builtins/write-file.js +75 -27
- package/dist/tools/builtins/write-file.js.map +1 -1
- package/dist/tools/coordinator/__tests__/ask-user-question.test.js +55 -0
- package/dist/tools/coordinator/__tests__/ask-user-question.test.js.map +1 -1
- package/dist/tools/coordinator/__tests__/plan-dependencies.test.d.ts +2 -0
- package/dist/tools/coordinator/__tests__/plan-dependencies.test.d.ts.map +1 -0
- package/dist/tools/coordinator/__tests__/plan-dependencies.test.js +126 -0
- package/dist/tools/coordinator/__tests__/plan-dependencies.test.js.map +1 -0
- package/dist/tools/coordinator/index.d.ts.map +1 -1
- package/dist/tools/coordinator/index.js +75 -5
- package/dist/tools/coordinator/index.js.map +1 -1
- package/dist/tools/coordinator/plan-dependencies.d.ts +43 -0
- package/dist/tools/coordinator/plan-dependencies.d.ts.map +1 -0
- package/dist/tools/coordinator/plan-dependencies.js +148 -0
- package/dist/tools/coordinator/plan-dependencies.js.map +1 -0
- package/dist/types/agent/supervisor.d.ts +15 -0
- package/dist/types/agent/supervisor.d.ts.map +1 -1
- package/dist/types/connector/core.d.ts +34 -0
- package/dist/types/connector/core.d.ts.map +1 -1
- package/dist/types/connector/definition.d.ts +10 -0
- package/dist/types/connector/definition.d.ts.map +1 -1
- package/dist/types/connector/mcp.d.ts +13 -0
- package/dist/types/connector/mcp.d.ts.map +1 -1
- package/dist/types/rag/retrieval.d.ts +16 -0
- package/dist/types/rag/retrieval.d.ts.map +1 -1
- package/dist/types/rag/storage.d.ts +9 -0
- package/dist/types/rag/storage.d.ts.map +1 -1
- package/dist/types/rag/vector.d.ts +11 -0
- package/dist/types/rag/vector.d.ts.map +1 -1
- package/dist/types/router/task-router.d.ts +19 -0
- package/dist/types/router/task-router.d.ts.map +1 -1
- package/dist/types/run/prepare-step.d.ts +56 -3
- package/dist/types/run/prepare-step.d.ts.map +1 -1
- package/dist/types/tool/index.d.ts +17 -1
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/types/toolset/index.d.ts +22 -0
- package/dist/types/toolset/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/advisory/__tests__/consultation-context.test.ts +191 -0
- package/src/advisory/context.ts +32 -0
- package/src/advisory/executor.ts +30 -3
- package/src/compaction/__tests__/context-reducer.test.ts +239 -0
- package/src/compaction/factory.ts +7 -0
- package/src/compaction/index.ts +8 -0
- package/src/compaction/interface.ts +13 -0
- package/src/compaction/managers/null.ts +3 -0
- package/src/compaction/managers/slidingWindow.ts +6 -0
- package/src/compaction/managers/structured.ts +10 -0
- package/src/compaction/reducer.ts +154 -0
- package/src/connector/builtins/__tests__/oauth2-auth.test.ts +73 -0
- package/src/connector/builtins/http.test.ts +28 -2
- package/src/connector/builtins/http.ts +26 -2
- package/src/connector/index.ts +6 -2
- package/src/connector/mcp/__tests__/prompts-and-lifecycle.test.ts +286 -0
- package/src/connector/mcp/client.ts +95 -0
- package/src/connector/mcp/discovery.ts +19 -4
- package/src/connector/mcp/index.ts +6 -2
- package/src/connector/mcp/server.ts +101 -3
- package/src/manager/agent/__tests__/depth-limit-authority.test.ts +74 -0
- package/src/plugin/__tests__/discovery-scopes.test.ts +133 -0
- package/src/plugin/__tests__/enable-contributions.test.ts +5 -1
- package/src/plugin/__tests__/mcp-admission.test.ts +242 -0
- package/src/plugin/lifecycle.ts +57 -1
- package/src/plugin/loader.ts +57 -3
- package/src/public-runtime.ts +16 -1
- package/src/public-types.ts +5 -0
- package/src/rag/__tests__/namespace-isolation.test.ts +109 -0
- package/src/rag/ingestion.ts +1 -0
- package/src/rag/retriever.ts +2 -0
- package/src/rag/vector-store.ts +5 -0
- package/src/registry/tool/execute.ts +123 -119
- package/src/runtime/query/__tests__/capability-negotiation.test.ts +69 -0
- package/src/runtime/query/__tests__/per-step-skills.test.ts +154 -0
- package/src/runtime/query/__tests__/per-step-tool-choice.test.ts +180 -0
- package/src/runtime/query/__tests__/resume-run.test.ts +262 -0
- package/src/runtime/query/executor.ts +9 -1
- package/src/runtime/query/index.ts +39 -0
- package/src/runtime/query/iteration/index.ts +130 -34
- package/src/runtime/query/iteration/phases/compaction-model-routing.test.ts +125 -0
- package/src/runtime/query/iteration/phases/compaction.ts +106 -5
- package/src/runtime/query/iteration/phases/context-reducer-dispatch.test.ts +238 -0
- package/src/runtime/query/iteration/phases/context.ts +11 -0
- package/src/runtime/query/resume-run.ts +93 -0
- package/src/telemetry/__tests__/model-call-span.test.ts +189 -0
- package/src/telemetry/__tests__/span-closure.test.ts +153 -0
- package/src/tools/advisory/index.ts +1 -1
- package/src/tools/builtins/__tests__/edit-commits-atomically.test.ts +103 -0
- package/src/tools/builtins/__tests__/edit.test.ts +324 -1
- package/src/tools/builtins/__tests__/stale-file-refusal.test.ts +258 -0
- package/src/tools/builtins/atomic-write-file.ts +30 -2
- package/src/tools/builtins/content-fingerprint.ts +33 -0
- package/src/tools/builtins/edit.ts +188 -36
- package/src/tools/builtins/read-file.ts +5 -2
- package/src/tools/builtins/write-file.ts +79 -28
- package/src/tools/coordinator/__tests__/ask-user-question.test.ts +68 -0
- package/src/tools/coordinator/__tests__/plan-dependencies.test.ts +186 -0
- package/src/tools/coordinator/index.ts +116 -42
- package/src/tools/coordinator/plan-dependencies.ts +175 -0
- package/src/types/agent/supervisor.ts +15 -0
- package/src/types/connector/core.ts +34 -0
- package/src/types/connector/definition.ts +10 -0
- package/src/types/connector/mcp.ts +14 -0
- package/src/types/rag/retrieval.ts +16 -0
- package/src/types/rag/storage.ts +9 -0
- package/src/types/rag/vector.ts +11 -0
- package/src/types/router/task-router.ts +19 -0
- package/src/types/run/prepare-step.ts +58 -3
- package/src/types/tool/index.ts +17 -1
- package/src/types/toolset/index.ts +22 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { createSlidingWindowReducer } from '../reducer.js';
|
|
3
|
+
/**
|
|
4
|
+
* `strategy: 'sliding-window'` was accepted by the config schema and then
|
|
5
|
+
* ignored — the runtime asked only whether the strategy was `'disabled'`, so
|
|
6
|
+
* a host who chose the cheap non-LLM path silently got the expensive LLM one,
|
|
7
|
+
* summarization calls and all. These pin the behaviour the name always
|
|
8
|
+
* claimed, and the three invariants that make a shorter history usable rather
|
|
9
|
+
* than merely shorter.
|
|
10
|
+
*/
|
|
11
|
+
const sys = (content) => ({ role: 'system', content, timestamp: 1 });
|
|
12
|
+
const user = (content) => ({ role: 'user', content, timestamp: 1 });
|
|
13
|
+
const asst = (content) => ({ role: 'assistant', content, timestamp: 1 });
|
|
14
|
+
const callsTool = (id) => ({
|
|
15
|
+
role: 'assistant',
|
|
16
|
+
content: null,
|
|
17
|
+
timestamp: 1,
|
|
18
|
+
toolCalls: [{ id, type: 'function', function: { name: 'echo', arguments: '{}' } }],
|
|
19
|
+
});
|
|
20
|
+
const toolResult = (id) => ({
|
|
21
|
+
role: 'tool',
|
|
22
|
+
content: 'ok',
|
|
23
|
+
timestamp: 1,
|
|
24
|
+
toolCallId: id,
|
|
25
|
+
});
|
|
26
|
+
function reduction(messages, over) {
|
|
27
|
+
return {
|
|
28
|
+
messages,
|
|
29
|
+
reason: 'threshold',
|
|
30
|
+
estimatedTokens: 1_000,
|
|
31
|
+
contextWindowTokens: 2_000,
|
|
32
|
+
model: 'mock-model',
|
|
33
|
+
keepRecentMessages: 4,
|
|
34
|
+
...over,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
describe('the sliding window keeps recent turns and drops the rest', () => {
|
|
38
|
+
it('keeps the configured tail', async () => {
|
|
39
|
+
const reduce = createSlidingWindowReducer();
|
|
40
|
+
const messages = [sys('prompt'), ...Array.from({ length: 10 }, (_, i) => user(`m${i}`))];
|
|
41
|
+
const next = await reduce(reduction(messages));
|
|
42
|
+
expect(next).toBeDefined();
|
|
43
|
+
expect(next?.length).toBe(5); // the system floor plus keepRecentMessages
|
|
44
|
+
expect(next?.at(-1)).toBe(messages.at(-1));
|
|
45
|
+
});
|
|
46
|
+
it('cuts harder when the provider already rejected the prompt', async () => {
|
|
47
|
+
const reduce = createSlidingWindowReducer();
|
|
48
|
+
const messages = [sys('prompt'), ...Array.from({ length: 10 }, (_, i) => user(`m${i}`))];
|
|
49
|
+
const threshold = await reduce(reduction(messages));
|
|
50
|
+
const overflow = await reduce(reduction(messages, { reason: 'overflow' }));
|
|
51
|
+
// An overflow means the ordinary window was ALREADY too big. Cutting to
|
|
52
|
+
// the same size would shed nothing and the caller would retry an
|
|
53
|
+
// identical prompt.
|
|
54
|
+
expect(overflow?.length).toBeLessThan(threshold?.length ?? 0);
|
|
55
|
+
});
|
|
56
|
+
it('summarizes nothing — every survivor is the original object', async () => {
|
|
57
|
+
const reduce = createSlidingWindowReducer();
|
|
58
|
+
const messages = [sys('prompt'), ...Array.from({ length: 8 }, (_, i) => user(`m${i}`))];
|
|
59
|
+
const next = await reduce(reduction(messages));
|
|
60
|
+
for (const message of next ?? [])
|
|
61
|
+
expect(messages).toContain(message);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
describe('the three invariants a shorter history has to keep', () => {
|
|
65
|
+
it('never drops the leading system floor', async () => {
|
|
66
|
+
const reduce = createSlidingWindowReducer();
|
|
67
|
+
const messages = [
|
|
68
|
+
sys('prompt'),
|
|
69
|
+
sys('working memory'),
|
|
70
|
+
...Array.from({ length: 8 }, (_, i) => user(`m${i}`)),
|
|
71
|
+
];
|
|
72
|
+
const next = await reduce(reduction(messages));
|
|
73
|
+
expect(next?.[0]).toBe(messages[0]);
|
|
74
|
+
expect(next?.[1]).toBe(messages[1]);
|
|
75
|
+
});
|
|
76
|
+
it('does not split a tool_use from its tool_result', async () => {
|
|
77
|
+
const reduce = createSlidingWindowReducer();
|
|
78
|
+
// The naive cut at length-3 lands between the assistant call and its
|
|
79
|
+
// result, which is a provider 400 on the next turn.
|
|
80
|
+
const messages = [
|
|
81
|
+
sys('prompt'),
|
|
82
|
+
user('go'),
|
|
83
|
+
asst('thinking'),
|
|
84
|
+
callsTool('c1'),
|
|
85
|
+
toolResult('c1'),
|
|
86
|
+
user('again'),
|
|
87
|
+
asst('done'),
|
|
88
|
+
user('more'),
|
|
89
|
+
];
|
|
90
|
+
const next = await reduce(reduction(messages, { keepRecentMessages: 5 }));
|
|
91
|
+
const kept = new Set(next ?? []);
|
|
92
|
+
// Cutting at 3 would keep the call and its result together; cutting at
|
|
93
|
+
// 4 would orphan the result. The pair is never split either way.
|
|
94
|
+
expect(kept.has(messages[4])).toBe(kept.has(messages[3]));
|
|
95
|
+
});
|
|
96
|
+
it('takes a cut above the requested window when nothing below is safe', async () => {
|
|
97
|
+
const reduce = createSlidingWindowReducer();
|
|
98
|
+
// A multi-step turn: the user is silent while the agent works, so every
|
|
99
|
+
// boundary inside the recent window opens on an assistant or tool
|
|
100
|
+
// message. A backwards-only search would decline here — exactly when
|
|
101
|
+
// the history is longest.
|
|
102
|
+
const messages = [
|
|
103
|
+
sys('prompt'),
|
|
104
|
+
user('go'),
|
|
105
|
+
callsTool('c1'),
|
|
106
|
+
toolResult('c1'),
|
|
107
|
+
asst('working'),
|
|
108
|
+
callsTool('c2'),
|
|
109
|
+
toolResult('c2'),
|
|
110
|
+
// The only user turn after the opening one, and it sits ABOVE the
|
|
111
|
+
// requested cut — so every candidate below opens on an assistant or
|
|
112
|
+
// tool message and the backwards search comes back empty.
|
|
113
|
+
user('next'),
|
|
114
|
+
callsTool('c3'),
|
|
115
|
+
toolResult('c3'),
|
|
116
|
+
];
|
|
117
|
+
const next = await reduce(reduction(messages, { keepRecentMessages: 5 }));
|
|
118
|
+
expect(next).toBeDefined();
|
|
119
|
+
expect(next?.length).toBeLessThan(messages.length);
|
|
120
|
+
// It kept LESS than asked rather than declining, and what it kept opens
|
|
121
|
+
// on a user turn.
|
|
122
|
+
expect(next?.[1]?.role).toBe('user');
|
|
123
|
+
});
|
|
124
|
+
it('keeps a pinned turn from the middle of the conversation', async () => {
|
|
125
|
+
const reduce = createSlidingWindowReducer();
|
|
126
|
+
const pinned = { ...user('the account id is X'), retain: true };
|
|
127
|
+
const messages = [
|
|
128
|
+
sys('prompt'),
|
|
129
|
+
user('m0'),
|
|
130
|
+
pinned,
|
|
131
|
+
...Array.from({ length: 8 }, (_, i) => user(`m${i + 1}`)),
|
|
132
|
+
];
|
|
133
|
+
const next = await reduce(reduction(messages));
|
|
134
|
+
// Recency is not the only thing that matters, which is what `retain`
|
|
135
|
+
// exists to say.
|
|
136
|
+
expect(next).toContain(pinned);
|
|
137
|
+
expect(next).not.toContain(messages[1]);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
describe('refusing beats a reduction that would break the next turn', () => {
|
|
141
|
+
it('declines when there is nothing but the system floor to cut', async () => {
|
|
142
|
+
const reduce = createSlidingWindowReducer();
|
|
143
|
+
expect(await reduce(reduction([sys('prompt'), user('go')]))).toBeUndefined();
|
|
144
|
+
});
|
|
145
|
+
it('declines when every candidate cut splits one assistant fan-out', async () => {
|
|
146
|
+
const reduce = createSlidingWindowReducer();
|
|
147
|
+
// Six results answering one call: no cut inside the block is safe, and
|
|
148
|
+
// the condition clears itself on the next assistant message.
|
|
149
|
+
const messages = [
|
|
150
|
+
sys('prompt'),
|
|
151
|
+
user('go'),
|
|
152
|
+
{
|
|
153
|
+
role: 'assistant',
|
|
154
|
+
content: null,
|
|
155
|
+
timestamp: 1,
|
|
156
|
+
toolCalls: Array.from({ length: 6 }, (_, i) => ({
|
|
157
|
+
id: `c${i}`,
|
|
158
|
+
type: 'function',
|
|
159
|
+
function: { name: 'echo', arguments: '{}' },
|
|
160
|
+
})),
|
|
161
|
+
},
|
|
162
|
+
...Array.from({ length: 6 }, (_, i) => toolResult(`c${i}`)),
|
|
163
|
+
];
|
|
164
|
+
expect(await reduce(reduction(messages, { keepRecentMessages: 2 }))).toBeUndefined();
|
|
165
|
+
});
|
|
166
|
+
it('declines rather than reporting a reduction that removed nothing', async () => {
|
|
167
|
+
const reduce = createSlidingWindowReducer();
|
|
168
|
+
// Every non-system message is pinned, so the survivor set is the input.
|
|
169
|
+
const messages = [
|
|
170
|
+
sys('prompt'),
|
|
171
|
+
...Array.from({ length: 8 }, (_, i) => ({ ...user(`m${i}`), retain: true })),
|
|
172
|
+
];
|
|
173
|
+
// Saying "reduced" here would have the overflow path retry an identical
|
|
174
|
+
// prompt and burn a model call to be told the same thing.
|
|
175
|
+
expect(await reduce(reduction(messages))).toBeUndefined();
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
describe('the knob a caller reaches for', () => {
|
|
179
|
+
it('lets an explicit window override the run config', async () => {
|
|
180
|
+
const reduce = createSlidingWindowReducer({ keepRecentMessages: 2 });
|
|
181
|
+
const messages = [sys('prompt'), ...Array.from({ length: 10 }, (_, i) => user(`m${i}`))];
|
|
182
|
+
const next = await reduce(reduction(messages, { keepRecentMessages: 8 }));
|
|
183
|
+
expect(next?.length).toBe(3);
|
|
184
|
+
});
|
|
185
|
+
it('is a plain function, so a host can wrap one', async () => {
|
|
186
|
+
const inner = createSlidingWindowReducer();
|
|
187
|
+
const seen = vi.fn();
|
|
188
|
+
const reduce = async (input) => {
|
|
189
|
+
seen(input.reason);
|
|
190
|
+
return inner(input);
|
|
191
|
+
};
|
|
192
|
+
const messages = [sys('prompt'), ...Array.from({ length: 8 }, (_, i) => user(`m${i}`))];
|
|
193
|
+
await reduce(reduction(messages, { reason: 'overflow' }));
|
|
194
|
+
expect(seen).toHaveBeenCalledWith('overflow');
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
//# sourceMappingURL=context-reducer.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-reducer.test.js","sourceRoot":"","sources":["../../../src/compaction/__tests__/context-reducer.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAGjD,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAA;AAG1D;;;;;;;GAOG;AAEH,MAAM,GAAG,GAAG,CAAC,OAAe,EAAW,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,CAAA;AACrF,MAAM,IAAI,GAAG,CAAC,OAAe,EAAW,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,CAAA;AACpF,MAAM,IAAI,GAAG,CAAC,OAAe,EAAW,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,CAAA;AAEzF,MAAM,SAAS,GAAG,CAA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AAK,CAAC,MAAM,CAAC,CAAA;YAClB,OAAO,KAAK,CAAC,KAAK,CAAC,CAAA;QACpB,CAAC,CAAA;QACD,MAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAEvF,MAAM,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,CAAA;QAEzD,MAAM,CAAC,IAAI,CAAC,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAA;IAC9C,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -16,5 +16,12 @@ import type { CompactionStrategy } from './types.js';
|
|
|
16
16
|
* const trimmed = manager.applyManagement(messages)
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Nothing calls this. Select a strategy with
|
|
21
|
+
* `compactionConfig.strategy`, or pass a `contextReducer` to `query()`.
|
|
22
|
+
*
|
|
23
|
+
* The factory produced managers the runtime had no seam to drive, so its
|
|
24
|
+
* return value was always dropped on the floor. See {@link ConversationManager}.
|
|
25
|
+
*/
|
|
19
26
|
export declare function createConversationManager(strategy: CompactionStrategy, config: CompactionConfig): ConversationManager;
|
|
20
27
|
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +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"}
|
|
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;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACxC,QAAQ,EAAE,kBAAkB,EAC5B,MAAM,EAAE,gBAAgB,GACtB,mBAAmB,CAerB"}
|
|
@@ -16,6 +16,13 @@ import { StructuredCompactionManager } from './managers/structured.js';
|
|
|
16
16
|
* const trimmed = manager.applyManagement(messages)
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Nothing calls this. Select a strategy with
|
|
21
|
+
* `compactionConfig.strategy`, or pass a `contextReducer` to `query()`.
|
|
22
|
+
*
|
|
23
|
+
* The factory produced managers the runtime had no seam to drive, so its
|
|
24
|
+
* return value was always dropped on the floor. See {@link ConversationManager}.
|
|
25
|
+
*/
|
|
19
26
|
export function createConversationManager(strategy, config) {
|
|
20
27
|
switch (strategy) {
|
|
21
28
|
case 'structured':
|
|
@@ -1 +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;;;;;;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A;QAC/D,CAAC;IACF,CAAC;AACF,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export type { WorkingState, PlanSlot, FileSlot, FileAction, ToolResultSlot, CompactionStrategy, } from './types.js';
|
|
2
2
|
export type { DanglingResult } from './dangling.js';
|
|
3
3
|
export type { ConversationManager } from './interface.js';
|
|
4
|
+
export { createSlidingWindowReducer } from './reducer.js';
|
|
5
|
+
export type { ContextReducer, ContextReduction, ContextReductionReason, SlidingWindowOptions, } from './reducer.js';
|
|
4
6
|
export { WorkingStateManager } from './manager.js';
|
|
5
7
|
export { serializeState } from './serializer.js';
|
|
6
8
|
export { extractFromToolCall, extractFromToolResult, extractFromUserMessage, extractFromAssistantMessage, } from './extractor.js';
|
|
@@ -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,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,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEpD,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CA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MAAM,qBAAqB,CAAA;AAEpG,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EACN,8BAA8B,EAC9B,mBAAmB,EACnB,oBAAoB,GACpB,MAAM,qBAAqB,CAAA;AAC5B,YAAY,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAEhE,OAAO,EACN,qBAAqB,EACrB,mBAAmB,EACnB,gCAAgC,EAChC,0BAA0B,GAC1B,MAAM,0BAA0B,CAAA;AACjC,YAAY,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAA"}
|
package/dist/compaction/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { createSlidingWindowReducer } from './reducer.js';
|
|
1
2
|
export { WorkingStateManager } from './manager.js';
|
|
2
3
|
export { serializeState } from './serializer.js';
|
|
3
4
|
export { extractFromToolCall, extractFromToolResult, extractFromUserMessage, extractFromAssistantMessage, } from './extractor.js';
|
|
@@ -1 +1 @@
|
|
|
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,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEpD,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAA;AAEpG,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EACN,8BAA8B,EAC9B,mBAAmB,EACnB,oBAAoB,GACpB,MAAM,qBAAqB,CAAA;AAG5B,OAAO,EACN,qBAAqB,EACrB,mBAAmB,EACnB,gCAAgC,EAChC,0BAA0B,GAC1B,MAAM,0BAA0B,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/compaction/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAA;AAQzD,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,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEpD,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAA;AAEpG,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EACN,8BAA8B,EAC9B,mBAAmB,EACnB,oBAAoB,GACpB,MAAM,qBAAqB,CAAA;AAG5B,OAAO,EACN,qBAAqB,EACrB,mBAAmB,EACnB,gCAAgC,EAChC,0BAA0B,GAC1B,MAAM,0BAA0B,CAAA"}
|
|
@@ -6,6 +6,19 @@ import type { Message } from '../types/message/index.js';
|
|
|
6
6
|
* A manager applies two strategies:
|
|
7
7
|
* 1. **Routine management** (applyManagement): Called after each iteration to proactively optimize context.
|
|
8
8
|
* 2. **Overflow reduction** (reduceContext): Called when the LLM reports context window exceeded.
|
|
9
|
+
*
|
|
10
|
+
* @deprecated Use {@link ContextReducer}, which the runtime actually drives.
|
|
11
|
+
*
|
|
12
|
+
* This interface cannot be implemented correctly. `reduceContext` is
|
|
13
|
+
* documented as reducing the history, but it takes `Message[]` and returns
|
|
14
|
+
* `boolean` — the only way to honour the contract is to mutate the argument
|
|
15
|
+
* in place, and neither shipped implementation does. Both build a shorter
|
|
16
|
+
* array locally, discard it, and return `true`. Nothing in the runtime ever
|
|
17
|
+
* called any of it, which is why an unfulfillable contract survived.
|
|
18
|
+
*
|
|
19
|
+
* `ContextReducer` returns the new history, may be async so a reducer can
|
|
20
|
+
* call a model, and is told whether it was asked speculatively or after the
|
|
21
|
+
* provider rejected the prompt. Kept exported until the next major.
|
|
9
22
|
*/
|
|
10
23
|
export interface ConversationManager {
|
|
11
24
|
/** Unique name for this manager (e.g., 'structured', 'sliding-window', 'disabled') */
|
|
@@ -1 +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
|
|
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;;;;;;;;;;;;;;;;;;;;GAoBG;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"}
|
|
@@ -4,6 +4,9 @@ import type { ConversationManager } from '../interface.js';
|
|
|
4
4
|
* No-op conversation manager implementation.
|
|
5
5
|
* Never modifies messages, useful for testing or when context management is disabled.
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use `strategy: 'disabled'`, which the runtime reads.
|
|
9
|
+
*/
|
|
7
10
|
export declare class NullManager implements ConversationManager {
|
|
8
11
|
readonly name = "null";
|
|
9
12
|
applyManagement(messages: Message[]): Message[];
|
|
@@ -1 +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"}
|
|
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;;GAEG;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"}
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
* No-op conversation manager implementation.
|
|
3
3
|
* Never modifies messages, useful for testing or when context management is disabled.
|
|
4
4
|
*/
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Use `strategy: 'disabled'`, which the runtime reads.
|
|
7
|
+
*/
|
|
5
8
|
export class NullManager {
|
|
6
9
|
name = 'null';
|
|
7
10
|
applyManagement(messages) {
|
|
@@ -1 +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"}
|
|
1
|
+
{"version":3,"file":"null.js","sourceRoot":"","sources":["../../../src/compaction/managers/null.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH;;GAEG;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"}
|
|
@@ -17,6 +17,12 @@ export interface SlidingWindowManagerConfig {
|
|
|
17
17
|
* 2. Use findSafeTrimIndex to ensure tool call/result pairs remain atomic
|
|
18
18
|
* 3. applyManagement runs proactively each iteration; reduceContext on overflow
|
|
19
19
|
*/
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use `createSlidingWindowReducer()`, or `strategy: 'sliding-window'`.
|
|
22
|
+
*
|
|
23
|
+
* Never reachable through the runtime, and `reduceContext` here computes a
|
|
24
|
+
* trim index and returns a boolean without trimming anything.
|
|
25
|
+
*/
|
|
20
26
|
export declare class SlidingWindowManager implements ConversationManager {
|
|
21
27
|
readonly name = "sliding-window";
|
|
22
28
|
private readonly keepRecentMessages;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slidingWindow.d.ts","sourceRoot":"","sources":["../../../src/compaction/managers/slidingWindow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAE3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAE1D,MAAM,WAAW,0BAA0B;IAC1C;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED;;;;;;;;;GASG;AACH,qBAAa,oBAAqB,YAAW,mBAAmB;IAC/D,QAAQ,CAAC,IAAI,oBAAmB;IAChC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAQ;gBAE/B,MAAM,GAAE,0BAA+B;IAInD,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE;IAW/C,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO;CAepE"}
|
|
1
|
+
{"version":3,"file":"slidingWindow.d.ts","sourceRoot":"","sources":["../../../src/compaction/managers/slidingWindow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAE3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAE1D,MAAM,WAAW,0BAA0B;IAC1C;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED;;;;;;;;;GASG;AACH;;;;;GAKG;AACH,qBAAa,oBAAqB,YAAW,mBAAmB;IAC/D,QAAQ,CAAC,IAAI,oBAAmB;IAChC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAQ;gBAE/B,MAAM,GAAE,0BAA+B;IAInD,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE;IAW/C,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO;CAepE"}
|
|
@@ -9,6 +9,12 @@ import { findSafeTrimIndex } from '../dangling.js';
|
|
|
9
9
|
* 2. Use findSafeTrimIndex to ensure tool call/result pairs remain atomic
|
|
10
10
|
* 3. applyManagement runs proactively each iteration; reduceContext on overflow
|
|
11
11
|
*/
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use `createSlidingWindowReducer()`, or `strategy: 'sliding-window'`.
|
|
14
|
+
*
|
|
15
|
+
* Never reachable through the runtime, and `reduceContext` here computes a
|
|
16
|
+
* trim index and returns a boolean without trimming anything.
|
|
17
|
+
*/
|
|
12
18
|
export class SlidingWindowManager {
|
|
13
19
|
name = 'sliding-window';
|
|
14
20
|
keepRecentMessages;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slidingWindow.js","sourceRoot":"","sources":["../../../src/compaction/managers/slidingWindow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAWlD;;;;;;;;;GASG;AACH,MAAM,OAAO,oBAAoB;IACvB,IAAI,GAAG,gBAAgB,CAAA;IACf,kBAAkB,CAAQ;IAE3C,YAAY,SAAqC,EAAE;QAClD,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,IAAI,CAAC,CAAA;IACzD,CAAC;IAED,eAAe,CAAC,QAAmB;QAClC,gCAAgC;QAChC,IAAI,QAAQ,CAAC,MAAM,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAChD,OAAO,QAAQ,CAAA;QAChB,CAAC;QAED,MAAM,gBAAgB,GAAG,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAA;QAClE,MAAM,WAAW,GAAG,iBAAiB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAA;QACjE,OAAO,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;IACnC,CAAC;IAED,aAAa,CAAC,QAAmB,EAAE,eAAuB;QACzD,8CAA8C;QAC9C,sDAAs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QAC9C,sDAAsD;QACtD,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,kBAAkB,GAAG,GAAG,CAAC,CAAC,CAAA;QAC3E,MAAM,gBAAgB,GAAG,QAAQ,CAAC,MAAM,GAAG,YAAY,CAAA;QACvD,MAAM,WAAW,GAAG,iBAAiB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAA;QAEjE,IAAI,WAAW,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YACpC,sBAAsB;YACtB,OAAO,KAAK,CAAA;QACb,CAAC;QAED,0DAA0D;QAC1D,OAAO,WAAW,GAAG,CAAC,CAAA;IACvB,CAAC;CACD"}
|
|
@@ -13,6 +13,16 @@ import type { ConversationManager } from '../interface.js';
|
|
|
13
13
|
*
|
|
14
14
|
* Provides maximum context preservation but more computational overhead.
|
|
15
15
|
*/
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Not the structured strategy. `strategy: 'structured'` runs the
|
|
18
|
+
* live path in `runtime/query/iteration/phases/compaction.ts`, which this
|
|
19
|
+
* class predates and does not share code with.
|
|
20
|
+
*
|
|
21
|
+
* What is here is a weaker parallel copy: no LLM-verified summary, no stale
|
|
22
|
+
* tool-result clearing, no retention pins, no events — and a `reduceContext`
|
|
23
|
+
* that builds a shorter history into a local array and then returns a
|
|
24
|
+
* boolean, discarding it.
|
|
25
|
+
*/
|
|
16
26
|
export declare class StructuredCompactionManager implements ConversationManager {
|
|
17
27
|
readonly name = "structured";
|
|
18
28
|
private readonly config;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structured.d.ts","sourceRoot":"","sources":["../../../src/compaction/managers/structured.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAO3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAI1D;;;;;;;;;;;GAWG;AACH,qBAAa,2BAA4B,YAAW,mBAAmB;IACtE,QAAQ,CAAC,IAAI,gBAAe;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;gBAE7B,MAAM,EAAE,gBAAgB;IAIpC,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE;IA+E/C,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO;CA0DpE"}
|
|
1
|
+
{"version":3,"file":"structured.d.ts","sourceRoot":"","sources":["../../../src/compaction/managers/structured.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAO3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAI1D;;;;;;;;;;;GAWG;AACH;;;;;;;;;GASG;AACH,qBAAa,2BAA4B,YAAW,mBAAmB;IACtE,QAAQ,CAAC,IAAI,gBAAe;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;gBAE7B,MAAM,EAAE,gBAAgB;IAIpC,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE;IA+E/C,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO;CA0DpE"}
|
|
@@ -14,6 +14,16 @@ import { serializeState } from '../serializer.js';
|
|
|
14
14
|
*
|
|
15
15
|
* Provides maximum context preservation but more computational overhead.
|
|
16
16
|
*/
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Not the structured strategy. `strategy: 'structured'` runs the
|
|
19
|
+
* live path in `runtime/query/iteration/phases/compaction.ts`, which this
|
|
20
|
+
* class predates and does not share code with.
|
|
21
|
+
*
|
|
22
|
+
* What is here is a weaker parallel copy: no LLM-verified summary, no stale
|
|
23
|
+
* tool-result clearing, no retention pins, no events — and a `reduceContext`
|
|
24
|
+
* that builds a shorter history into a local array and then returns a
|
|
25
|
+
* boolean, discarding it.
|
|
26
|
+
*/
|
|
17
27
|
export class StructuredCompactionManager {
|
|
18
28
|
name = 'structured';
|
|
19
29
|
config;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structured.js","sourceRoot":"","sources":["../../../src/compaction/managers/structured.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EACN,2BAA2B,EAC3B,mBAAmB,EACnB,sBAAsB,GACtB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,2BAA2B;IAC9B,IAAI,GAAG,YAAY,CAAA;IACX,MAAM,CAAkB;IAEzC,YAAY,MAAwB;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACrB,CAAC;IAED,eAAe,CAAC,QAAmB;QAClC,wCAAwC;QACxC,MAAM,YAAY,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAEzD,IAAI,kBAAkB,GAAG,IAAI,CAAA;QAC7B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAChC,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;gBAC7B,sBAAsB,CAAC,YAAY,EAAE,OAAO,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAA;gBACzE,kBAAkB,GAAG,KAAK,CAAA;YAC3B,CAAC;iBAAM,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;gBAC5D,2BAA2B,CAAC,YA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CAAA;YACpD,MAAM,WAAW,GAAG,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;YAC/D,OAAO,WAAW,GAAG,CAAC,IAAI,WAAW,GAAG,MAAM,CAAC,MAAM,CAAA;QACtD,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAA;IACvC,CAAC;CACD"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Message } from '../types/message/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Why the runtime is asking for a shorter history.
|
|
4
|
+
*
|
|
5
|
+
* The two cases want different behaviour and a reducer that cannot tell
|
|
6
|
+
* them apart has to guess. `'threshold'` is speculative — the estimate says
|
|
7
|
+
* the window is filling, nothing has failed, and declining costs only some
|
|
8
|
+
* headroom. `'overflow'` is the provider having already rejected the
|
|
9
|
+
* prompt: declining there ends the run.
|
|
10
|
+
*/
|
|
11
|
+
export type ContextReductionReason = 'threshold' | 'overflow';
|
|
12
|
+
/** Everything a reducer needs to decide, and nothing it cannot act on. */
|
|
13
|
+
export interface ContextReduction {
|
|
14
|
+
/** The live history, oldest first. Treat as read-only and return a new array. */
|
|
15
|
+
readonly messages: readonly Message[];
|
|
16
|
+
readonly reason: ContextReductionReason;
|
|
17
|
+
/** Estimated size of `messages`. Derived from the provider's last prompt count when there is one, else measured. */
|
|
18
|
+
readonly estimatedTokens: number;
|
|
19
|
+
/** What it has to fit in. Resolved from the model when the host did not say. */
|
|
20
|
+
readonly contextWindowTokens: number;
|
|
21
|
+
/** The model this run is calling, for a reducer that varies by model. */
|
|
22
|
+
readonly model: string;
|
|
23
|
+
/** The run's configured recent-window size, as a starting point. */
|
|
24
|
+
readonly keepRecentMessages: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Replace the run's history with a shorter one.
|
|
28
|
+
*
|
|
29
|
+
* Returning `undefined` means "I could not shorten this" and is a first-class
|
|
30
|
+
* answer, not a failure — on `'threshold'` the run simply continues, and on
|
|
31
|
+
* `'overflow'` it fails with an irreducible-prompt error instead of retrying
|
|
32
|
+
* a prompt nothing changed. That is deliberate: a reducer that returned the
|
|
33
|
+
* input unchanged while reporting success would send the same rejected
|
|
34
|
+
* prompt again and burn a call to learn the same thing.
|
|
35
|
+
*
|
|
36
|
+
* A reducer OWNS reduction for the run it governs. The built-in structured
|
|
37
|
+
* pass — LLM-verified summarization, stale tool-result clearing, working
|
|
38
|
+
* state slots — does not also run, because two mechanisms editing the same
|
|
39
|
+
* history in one pass cannot both be reasoned about.
|
|
40
|
+
*
|
|
41
|
+
* Invariants a reducer is expected to keep, all three enforced by the
|
|
42
|
+
* built-in one and none of them checkable from here:
|
|
43
|
+
*
|
|
44
|
+
* 1. The leading system messages stay. They carry the system prompt and the
|
|
45
|
+
* working-memory slot; dropping them changes who the agent is.
|
|
46
|
+
* 2. `tool_use` and its `tool_result` stay together. A split pair is a 400
|
|
47
|
+
* from the provider, so a reducer that splits one turns a context problem
|
|
48
|
+
* into a dead run. {@link findSafeTrimIndex} is exported for this.
|
|
49
|
+
* 3. Messages marked `retain` survive. That marker is how a caller says a
|
|
50
|
+
* fact in the middle of the conversation outranks recency.
|
|
51
|
+
*/
|
|
52
|
+
export type ContextReducer = (reduction: ContextReduction) => readonly Message[] | undefined | Promise<readonly Message[] | undefined>;
|
|
53
|
+
export interface SlidingWindowOptions {
|
|
54
|
+
/**
|
|
55
|
+
* How many trailing messages to keep. Defaults to the run's configured
|
|
56
|
+
* `keepRecentMessages`, so the same knob governs both strategies.
|
|
57
|
+
*/
|
|
58
|
+
readonly keepRecentMessages?: number;
|
|
59
|
+
/**
|
|
60
|
+
* Fraction of the window to keep when relieving an overflow, applied to
|
|
61
|
+
* the recent count. Defaults to 0.5.
|
|
62
|
+
*
|
|
63
|
+
* An overflow means the ordinary window was already too big, so cutting
|
|
64
|
+
* to the same size again would shed nothing and the caller would retry
|
|
65
|
+
* an identical prompt.
|
|
66
|
+
*/
|
|
67
|
+
readonly overflowFactor?: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Keep the last N turns, drop what precedes them, summarize nothing.
|
|
71
|
+
*
|
|
72
|
+
* The honest counterpart to the structured strategy rather than a lesser
|
|
73
|
+
* version of it. Structured compaction pays a summarization call and
|
|
74
|
+
* paraphrases the agent's own reasoning to buy context; this pays nothing
|
|
75
|
+
* and admits the older history is gone. For a long-running agent whose
|
|
76
|
+
* state lives outside the transcript — a task queue, a file it keeps
|
|
77
|
+
* editing, a working-memory block the host renders each turn — that is the
|
|
78
|
+
* better trade, and the paraphrase was only ever cost.
|
|
79
|
+
*
|
|
80
|
+
* Until now `strategy: 'sliding-window'` was accepted by the config schema
|
|
81
|
+
* and then ignored: the runtime asked only whether the strategy was
|
|
82
|
+
* `'disabled'`, so choosing the cheap non-LLM path silently ran the
|
|
83
|
+
* expensive LLM one. This is the implementation that name always claimed.
|
|
84
|
+
*/
|
|
85
|
+
export declare function createSlidingWindowReducer(options?: SlidingWindowOptions): ContextReducer;
|
|
86
|
+
//# sourceMappingURL=reducer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../src/compaction/reducer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAIxD;;;;;;;;GAQG;AACH,MAAM,MAAM,sBAAsB,GAAG,WAAW,GAAG,UAAU,CAAA;AAE7D,0EAA0E;AAC1E,MAAM,WAAW,gBAAgB;IAChC,iFAAiF;IACjF,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAA;IACrC,QAAQ,CAAC,MAAM,EAAE,sBAAsB,CAAA;IACvC,oHAAoH;IACpH,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,gFAAgF;IAChF,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAA;IACpC,yEAAyE;IACzE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,oEAAoE;IACpE,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAA;CACnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,MAAM,cAAc,GAAG,CAC5B,SAAS,EAAE,gBAAgB,KACvB,SAAS,OAAO,EAAE,GAAG,SAAS,GAAG,OAAO,CAAC,SAAS,OAAO,EAAE,GAAG,SAAS,CAAC,CAAA;AAE7E,MAAM,WAAW,oBAAoB;IACpC;;;OAGG;IACH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAEpC;;;;;;;OAOG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CAChC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,GAAE,oBAAyB,GAAG,cAAc,CA2D7F"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { findSafeTrimIndex } from './dangling.js';
|
|
2
|
+
import { findRetainedIndices } from './retention.js';
|
|
3
|
+
/**
|
|
4
|
+
* Keep the last N turns, drop what precedes them, summarize nothing.
|
|
5
|
+
*
|
|
6
|
+
* The honest counterpart to the structured strategy rather than a lesser
|
|
7
|
+
* version of it. Structured compaction pays a summarization call and
|
|
8
|
+
* paraphrases the agent's own reasoning to buy context; this pays nothing
|
|
9
|
+
* and admits the older history is gone. For a long-running agent whose
|
|
10
|
+
* state lives outside the transcript — a task queue, a file it keeps
|
|
11
|
+
* editing, a working-memory block the host renders each turn — that is the
|
|
12
|
+
* better trade, and the paraphrase was only ever cost.
|
|
13
|
+
*
|
|
14
|
+
* Until now `strategy: 'sliding-window'` was accepted by the config schema
|
|
15
|
+
* and then ignored: the runtime asked only whether the strategy was
|
|
16
|
+
* `'disabled'`, so choosing the cheap non-LLM path silently ran the
|
|
17
|
+
* expensive LLM one. This is the implementation that name always claimed.
|
|
18
|
+
*/
|
|
19
|
+
export function createSlidingWindowReducer(options = {}) {
|
|
20
|
+
const factor = options.overflowFactor ?? 0.5;
|
|
21
|
+
return ({ messages, reason, keepRecentMessages }) => {
|
|
22
|
+
const configured = options.keepRecentMessages ?? keepRecentMessages;
|
|
23
|
+
const keep = reason === 'overflow' ? Math.max(1, Math.floor(configured * factor)) : Math.max(1, configured);
|
|
24
|
+
let leadingSystem = 0;
|
|
25
|
+
while (messages[leadingSystem]?.role === 'system')
|
|
26
|
+
leadingSystem++;
|
|
27
|
+
const naive = messages.length - keep;
|
|
28
|
+
if (naive <= leadingSystem)
|
|
29
|
+
return undefined;
|
|
30
|
+
// `findSafeTrimIndex` moves a cut forward until the kept tail is a
|
|
31
|
+
// history a provider will accept — no `tool_result` without its
|
|
32
|
+
// `tool_use`, and never opening on an assistant turn, because the tail
|
|
33
|
+
// becomes the start of the wire conversation once the older half is
|
|
34
|
+
// gone. So a candidate is safe exactly when it is already its own
|
|
35
|
+
// answer.
|
|
36
|
+
//
|
|
37
|
+
// Walk BACKWARDS first: that lands on the safe cut nearest the
|
|
38
|
+
// requested window, keeping a little more than asked rather than a lot
|
|
39
|
+
// less.
|
|
40
|
+
const trimmable = [...messages];
|
|
41
|
+
let cut = -1;
|
|
42
|
+
for (let candidate = naive; candidate > leadingSystem; candidate--) {
|
|
43
|
+
if (findSafeTrimIndex(trimmable, candidate) === candidate) {
|
|
44
|
+
cut = candidate;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Nothing safe below the request. Take the answer ABOVE it instead of
|
|
49
|
+
// refusing: in a multi-step turn — the agent working through tool calls
|
|
50
|
+
// with the user silent — every boundary in the recent window lands on
|
|
51
|
+
// an assistant or tool message, so a backwards-only search declines
|
|
52
|
+
// exactly when the history is longest and shedding matters most. The
|
|
53
|
+
// forward cut keeps less than asked, which is a smaller history than
|
|
54
|
+
// the caller wanted but still a correct one.
|
|
55
|
+
if (cut < 0) {
|
|
56
|
+
const forward = findSafeTrimIndex(trimmable, naive);
|
|
57
|
+
// `messages.length` means "keep nothing", which is not a history.
|
|
58
|
+
if (forward > leadingSystem && forward < messages.length)
|
|
59
|
+
cut = forward;
|
|
60
|
+
}
|
|
61
|
+
if (cut < 0)
|
|
62
|
+
return undefined;
|
|
63
|
+
const retained = findRetainedIndices(messages);
|
|
64
|
+
const survivors = [];
|
|
65
|
+
for (let i = 0; i < messages.length; i++) {
|
|
66
|
+
const message = messages[i];
|
|
67
|
+
if (!message)
|
|
68
|
+
continue;
|
|
69
|
+
if (i < leadingSystem || i >= cut || retained.has(i))
|
|
70
|
+
survivors.push(message);
|
|
71
|
+
}
|
|
72
|
+
// Nothing went. Reporting that as a reduction would have the overflow
|
|
73
|
+
// path retry an identical prompt.
|
|
74
|
+
return survivors.length === messages.length ? undefined : survivors;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=reducer.js.map
|