@anvia/core 1.4.0 → 1.5.1

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.
Files changed (52) hide show
  1. package/README.md +29 -6
  2. package/dist/agent/agent.js +7 -7
  3. package/dist/agent/index.d.ts +5 -5
  4. package/dist/agent/index.js +10 -10
  5. package/dist/agent/resolve-options.js +2 -2
  6. package/dist/agent/resolved-agent.js +8 -8
  7. package/dist/agent/team/agent-team.js +10 -10
  8. package/dist/agent/team/index.js +10 -10
  9. package/dist/{agent-D3iyrJQb.d.ts → agent-BUc18r6A.d.ts} +6 -2
  10. package/dist/{chunk-HSWH3ZLP.js → chunk-3SUEXGRA.js} +3 -3
  11. package/dist/{chunk-6RVQ3C64.js → chunk-AJC6YRVB.js} +3 -3
  12. package/dist/{chunk-ZGDUEOSH.js → chunk-DXW37JLZ.js} +4 -4
  13. package/dist/{chunk-GE46NHN4.js → chunk-NDAGW32C.js} +38 -28
  14. package/dist/chunk-NDAGW32C.js.map +1 -0
  15. package/dist/{chunk-E44DRLUL.js → chunk-PPMK7CG4.js} +9 -5
  16. package/dist/chunk-PPMK7CG4.js.map +1 -0
  17. package/dist/{chunk-PXX3ITNH.js → chunk-PWWKX2HA.js} +4 -4
  18. package/dist/{chunk-U5AJS7KM.js → chunk-PZ7ATNR6.js} +5 -5
  19. package/dist/{chunk-APKCA2LY.js → chunk-TK2VXQVZ.js} +3 -3
  20. package/dist/{chunk-IHAURFIO.js → chunk-UYODZ7OE.js} +2 -2
  21. package/dist/{chunk-K4IBS7VB.js → chunk-WLUWRBQ4.js} +22 -8
  22. package/dist/chunk-WLUWRBQ4.js.map +1 -0
  23. package/dist/evals/index.d.ts +2 -2
  24. package/dist/index.d.ts +3 -3
  25. package/dist/index.js +11 -11
  26. package/dist/internal/agent-runtime/agent-run.js +4 -4
  27. package/dist/internal/agent-runtime/memory.js +2 -2
  28. package/dist/internal/agent.d.ts +3 -3
  29. package/dist/internal/agent.js +8 -8
  30. package/dist/internal/team-runtime/run.js +9 -9
  31. package/dist/memory/compaction.js +1 -1
  32. package/dist/memory/index.d.ts +2 -2
  33. package/dist/memory/index.js +2 -2
  34. package/dist/memory/options.js +1 -1
  35. package/dist/{middleware-DORuwSy-.d.ts → middleware-BxzML2hK.d.ts} +1 -1
  36. package/dist/observability/index.d.ts +2 -2
  37. package/dist/pipeline/index.d.ts +3 -3
  38. package/dist/pipeline/index.js +2 -2
  39. package/dist/pipeline/pipeline.js +2 -2
  40. package/dist/tool/index.d.ts +2 -2
  41. package/dist/{types-DhWxTobb.d.ts → types-B8KBVXuH.d.ts} +20 -5
  42. package/package.json +2 -2
  43. package/dist/chunk-E44DRLUL.js.map +0 -1
  44. package/dist/chunk-GE46NHN4.js.map +0 -1
  45. package/dist/chunk-K4IBS7VB.js.map +0 -1
  46. /package/dist/{chunk-HSWH3ZLP.js.map → chunk-3SUEXGRA.js.map} +0 -0
  47. /package/dist/{chunk-6RVQ3C64.js.map → chunk-AJC6YRVB.js.map} +0 -0
  48. /package/dist/{chunk-ZGDUEOSH.js.map → chunk-DXW37JLZ.js.map} +0 -0
  49. /package/dist/{chunk-PXX3ITNH.js.map → chunk-PWWKX2HA.js.map} +0 -0
  50. /package/dist/{chunk-U5AJS7KM.js.map → chunk-PZ7ATNR6.js.map} +0 -0
  51. /package/dist/{chunk-APKCA2LY.js.map → chunk-TK2VXQVZ.js.map} +0 -0
  52. /package/dist/{chunk-IHAURFIO.js.map → chunk-UYODZ7OE.js.map} +0 -0
package/README.md CHANGED
@@ -660,7 +660,7 @@ const agent = new Agent({
660
660
  savePolicy: "message",
661
661
  compaction: {
662
662
  trigger: { afterTokens: 32_000 },
663
- retention: { recentTokens: 8_000 },
663
+ retention: { recentTurns: 4 },
664
664
  compactor,
665
665
  conflictRetries: false,
666
666
  },
@@ -679,10 +679,25 @@ for await (const event of agent.stream({ prompt: "What did we decide?", session
679
679
  }
680
680
  ```
681
681
 
682
- The trigger includes the stored transcript and the incoming user message. Retention keeps as many
683
- recent complete user-led turns as fit the configured budget; the newest complete turn is always
684
- kept and never split, even when it exceeds that budget. When `retention` is omitted, it defaults to
685
- 25% of `afterTokens`.
682
+ ### Retention API design
683
+
684
+ - **Public option:** `retention: { recentTurns: N }`.
685
+ - **Counting unit:** a user-led turn, not an individual message. Each `user` message starts a turn;
686
+ every following `assistant`, `tool`, or `system` message belongs to it until the next `user`
687
+ message. Tool calls and results therefore cannot be split at the compaction boundary.
688
+ - **Default:** omitting `retention` resolves to `{ recentTurns: 1 }`.
689
+ - **Validation:** `N` must be a nonnegative safe integer. Fractions, negative values, infinity, and
690
+ specifying both retention modes are rejected.
691
+ - **Boundaries:** exactly the last `N` complete stored turns remain unsummarized. `N = 0` summarizes
692
+ the whole stored transcript when it contains a user-led turn. If at most `N` turns exist,
693
+ compaction is a no-op.
694
+ - **Leading messages:** messages before the first `user` do not count as a turn. When older turns
695
+ are summarized, this leading prefix is summarized with them.
696
+ - **Trigger interaction:** the stored transcript plus incoming user message is compared with
697
+ `afterTokens`, but the incoming message is not part of the stored-turn retention count.
698
+ `afterTokens` remains only the automatic trigger threshold and does not cap retained turns.
699
+ - **Compatibility:** deprecated `{ recentTokens: N }` remains supported with its previous
700
+ whole-turn semantics. It is mutually exclusive with `recentTurns`.
686
701
 
687
702
  The built-in token counter is a lightweight provider-neutral estimate. Pass `tokenCounter` when you
688
703
  have a model-specific tokenizer or counting service. A custom counter may be async, can be called
@@ -691,12 +706,20 @@ multiple times, and must return deterministic, monotonic, nonnegative safe integ
691
706
  ```ts
692
707
  compaction: {
693
708
  trigger: { afterTokens: 32_000 },
694
- retention: { recentTokens: 8_000 },
709
+ retention: { recentTurns: 4 },
695
710
  tokenCounter: (messages) => tokenizer.count(messages),
696
711
  compactor,
697
712
  }
698
713
  ```
699
714
 
715
+ For migration, the deprecated `retention: { recentTokens: N }` form remains supported with its
716
+ previous semantics: it keeps as many complete recent user-led turns as fit the token budget and
717
+ always keeps the newest turn. `recentTokens` must be positive and less than `afterTokens`.
718
+ `recentTurns` and `recentTokens` are mutually exclusive; use `recentTurns` for deterministic
719
+ count-based retention. Omitting `retention` previously used
720
+ `Math.floor(afterTokens / 4)` as a token budget and now retains one turn. To preserve the old
721
+ implicit behavior during migration, set that value explicitly as `recentTokens`.
722
+
700
723
  You can force the configured policy without starting an Agent run. The result makes a no-op
701
724
  explicit rather than throwing:
702
725
 
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  Agent
3
- } from "../chunk-PXX3ITNH.js";
4
- import "../chunk-U5AJS7KM.js";
3
+ } from "../chunk-PWWKX2HA.js";
4
+ import "../chunk-PZ7ATNR6.js";
5
5
  import "../chunk-B57NNDEF.js";
6
6
  import "../chunk-LAIATEUB.js";
7
- import "../chunk-GE46NHN4.js";
7
+ import "../chunk-NDAGW32C.js";
8
8
  import "../chunk-GDY2Z2SZ.js";
9
9
  import "../chunk-KITX3HDN.js";
10
10
  import "../chunk-NPJ2T3L5.js";
@@ -19,9 +19,9 @@ import "../chunk-T3ZOZEAB.js";
19
19
  import "../chunk-6E6ABRJ6.js";
20
20
  import "../chunk-YNA3UR42.js";
21
21
  import "../chunk-H3H74RWJ.js";
22
- import "../chunk-E44DRLUL.js";
23
- import "../chunk-LQJ4KHMY.js";
24
22
  import "../chunk-MJCMKZFP.js";
23
+ import "../chunk-PPMK7CG4.js";
24
+ import "../chunk-LQJ4KHMY.js";
25
25
  import "../chunk-EZR5AV3J.js";
26
26
  import "../chunk-OJF67RNM.js";
27
27
  import "../chunk-FAPIZJS2.js";
@@ -34,8 +34,8 @@ import "../chunk-NF6WBPFG.js";
34
34
  import "../chunk-LBYJPMHC.js";
35
35
  import "../chunk-KFAVEL5F.js";
36
36
  import "../chunk-GLMYZ6OA.js";
37
- import "../chunk-IHAURFIO.js";
38
- import "../chunk-K4IBS7VB.js";
37
+ import "../chunk-UYODZ7OE.js";
38
+ import "../chunk-WLUWRBQ4.js";
39
39
  import "../chunk-ZPJFXRQZ.js";
40
40
  import "../chunk-MEN4AFDZ.js";
41
41
  import "../chunk-VZ5ZZBNX.js";
@@ -1,15 +1,15 @@
1
1
  export { M as ModelCallOptions } from '../model-call-options-CZkSw_xN.js';
2
2
  export { R as RetryContext, a as RetryOptions, b as RetrySetting } from '../retry-CjvSlKGW.js';
3
- import { A as Agent, d as AgentOptions } from '../agent-D3iyrJQb.js';
4
- export { a as AgentContextInput, b as AgentMemory, c as AgentMemoryOptions, e as AgentToolInput, f as AgentToolOptions, C as CreateHybridVectorContextOptions, g as CreateVectorContextOptions, V as VectorContext, h as VectorContextBaseOptions, i as createVectorContext, j as isVectorContext } from '../agent-D3iyrJQb.js';
3
+ import { A as Agent, d as AgentOptions } from '../agent-BUc18r6A.js';
4
+ export { a as AgentContextInput, b as AgentMemory, c as AgentMemoryOptions, e as AgentToolInput, f as AgentToolOptions, C as CreateHybridVectorContextOptions, g as CreateVectorContextOptions, V as VectorContext, h as VectorContextBaseOptions, i as createVectorContext, j as isVectorContext } from '../agent-BUc18r6A.js';
5
5
  import { d as CompletionModel, f as CompletionModelControlsOf, M as Message, U as Usage, c as CompletionFinishReason } from '../types-DYqZKDA8.js';
6
6
  import { AgentInteractionRequest, AgentInteractionResponse } from './interactions/index.js';
7
- import { p as AgentRunSettings, m as AgentPrompt, n as AgentResponse, A as AgentBlockedOutcome, v as AgentStreamEvent, r as AgentSteerInput, s as AgentSteerReceipt, g as AgentInteractionOutcome } from '../middleware-DORuwSy-.js';
8
- export { a as AgentChildStreamEvent, b as AgentDeltaEvent, c as AgentErrorEvent, d as AgentErrorStreamEvent, e as AgentFinishEvent, f as AgentInput, h as AgentLifecycle, i as AgentMemoryCompactionEvent, j as AgentMemoryCompactionOptions, l as AgentOutcome, o as AgentRunOptions, q as AgentStartEvent, t as AgentStepFinishEvent, u as AgentStream, w as AgentToolCallDeltaEvent, x as AgentToolFinishEvent, y as AgentToolStartEvent } from '../middleware-DORuwSy-.js';
7
+ import { p as AgentRunSettings, m as AgentPrompt, n as AgentResponse, A as AgentBlockedOutcome, v as AgentStreamEvent, r as AgentSteerInput, s as AgentSteerReceipt, g as AgentInteractionOutcome } from '../middleware-BxzML2hK.js';
8
+ export { a as AgentChildStreamEvent, b as AgentDeltaEvent, c as AgentErrorEvent, d as AgentErrorStreamEvent, e as AgentFinishEvent, f as AgentInput, h as AgentLifecycle, i as AgentMemoryCompactionEvent, j as AgentMemoryCompactionOptions, l as AgentOutcome, o as AgentRunOptions, q as AgentStartEvent, t as AgentStepFinishEvent, u as AgentStream, w as AgentToolCallDeltaEvent, x as AgentToolFinishEvent, y as AgentToolStartEvent } from '../middleware-BxzML2hK.js';
9
9
  import '../types-CqiX-4_C.js';
10
10
  import '../types-0t3BczrD.js';
11
11
  import '../tool-D_jV3cRZ.js';
12
- import '../types-DhWxTobb.js';
12
+ import '../types-B8KBVXuH.js';
13
13
  import '../zod-schema-C7F4clpm.js';
14
14
  import 'zod';
15
15
  import '../types-Cu2tEf3V.js';
@@ -1,9 +1,9 @@
1
1
  import "../chunk-53TPAXYR.js";
2
2
  import {
3
3
  AgentTeam
4
- } from "../chunk-APKCA2LY.js";
4
+ } from "../chunk-TK2VXQVZ.js";
5
5
  import "../chunk-X6WS3XWL.js";
6
- import "../chunk-HSWH3ZLP.js";
6
+ import "../chunk-3SUEXGRA.js";
7
7
  import "../chunk-PIMD4DYG.js";
8
8
  import "../chunk-FSBDE6RF.js";
9
9
  import "../chunk-3TAQXJBC.js";
@@ -12,14 +12,14 @@ import {
12
12
  AgentTeamInteractionError,
13
13
  AgentTeamLimitError
14
14
  } from "../chunk-ENZ2XX27.js";
15
- import "../chunk-6RVQ3C64.js";
15
+ import "../chunk-AJC6YRVB.js";
16
16
  import {
17
17
  Agent
18
- } from "../chunk-PXX3ITNH.js";
19
- import "../chunk-U5AJS7KM.js";
18
+ } from "../chunk-PWWKX2HA.js";
19
+ import "../chunk-PZ7ATNR6.js";
20
20
  import "../chunk-B57NNDEF.js";
21
21
  import "../chunk-LAIATEUB.js";
22
- import "../chunk-GE46NHN4.js";
22
+ import "../chunk-NDAGW32C.js";
23
23
  import "../chunk-GDY2Z2SZ.js";
24
24
  import "../chunk-KITX3HDN.js";
25
25
  import "../chunk-NPJ2T3L5.js";
@@ -34,9 +34,9 @@ import "../chunk-T3ZOZEAB.js";
34
34
  import "../chunk-6E6ABRJ6.js";
35
35
  import "../chunk-YNA3UR42.js";
36
36
  import "../chunk-H3H74RWJ.js";
37
- import "../chunk-E44DRLUL.js";
38
- import "../chunk-LQJ4KHMY.js";
39
37
  import "../chunk-MJCMKZFP.js";
38
+ import "../chunk-PPMK7CG4.js";
39
+ import "../chunk-LQJ4KHMY.js";
40
40
  import "../chunk-EZR5AV3J.js";
41
41
  import "../chunk-OJF67RNM.js";
42
42
  import "../chunk-FAPIZJS2.js";
@@ -49,8 +49,8 @@ import "../chunk-NF6WBPFG.js";
49
49
  import "../chunk-LBYJPMHC.js";
50
50
  import "../chunk-KFAVEL5F.js";
51
51
  import "../chunk-GLMYZ6OA.js";
52
- import "../chunk-IHAURFIO.js";
53
- import "../chunk-K4IBS7VB.js";
52
+ import "../chunk-UYODZ7OE.js";
53
+ import "../chunk-WLUWRBQ4.js";
54
54
  import "../chunk-ZPJFXRQZ.js";
55
55
  import "../chunk-MEN4AFDZ.js";
56
56
  import "../chunk-VZ5ZZBNX.js";
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  markResolvedAgentOptions,
3
3
  resolveAgentOptions
4
- } from "../chunk-IHAURFIO.js";
5
- import "../chunk-K4IBS7VB.js";
4
+ } from "../chunk-UYODZ7OE.js";
5
+ import "../chunk-WLUWRBQ4.js";
6
6
  import "../chunk-ZPJFXRQZ.js";
7
7
  import "../chunk-MEN4AFDZ.js";
8
8
  import "../chunk-VZ5ZZBNX.js";
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  createResolvedAgent,
3
3
  getResolvedAgentOptions
4
- } from "../chunk-6RVQ3C64.js";
5
- import "../chunk-PXX3ITNH.js";
6
- import "../chunk-U5AJS7KM.js";
4
+ } from "../chunk-AJC6YRVB.js";
5
+ import "../chunk-PWWKX2HA.js";
6
+ import "../chunk-PZ7ATNR6.js";
7
7
  import "../chunk-B57NNDEF.js";
8
8
  import "../chunk-LAIATEUB.js";
9
- import "../chunk-GE46NHN4.js";
9
+ import "../chunk-NDAGW32C.js";
10
10
  import "../chunk-GDY2Z2SZ.js";
11
11
  import "../chunk-KITX3HDN.js";
12
12
  import "../chunk-NPJ2T3L5.js";
@@ -21,9 +21,9 @@ import "../chunk-T3ZOZEAB.js";
21
21
  import "../chunk-6E6ABRJ6.js";
22
22
  import "../chunk-YNA3UR42.js";
23
23
  import "../chunk-H3H74RWJ.js";
24
- import "../chunk-E44DRLUL.js";
25
- import "../chunk-LQJ4KHMY.js";
26
24
  import "../chunk-MJCMKZFP.js";
25
+ import "../chunk-PPMK7CG4.js";
26
+ import "../chunk-LQJ4KHMY.js";
27
27
  import "../chunk-EZR5AV3J.js";
28
28
  import "../chunk-OJF67RNM.js";
29
29
  import "../chunk-FAPIZJS2.js";
@@ -36,8 +36,8 @@ import "../chunk-NF6WBPFG.js";
36
36
  import "../chunk-LBYJPMHC.js";
37
37
  import "../chunk-KFAVEL5F.js";
38
38
  import "../chunk-GLMYZ6OA.js";
39
- import "../chunk-IHAURFIO.js";
40
- import "../chunk-K4IBS7VB.js";
39
+ import "../chunk-UYODZ7OE.js";
40
+ import "../chunk-WLUWRBQ4.js";
41
41
  import "../chunk-ZPJFXRQZ.js";
42
42
  import "../chunk-MEN4AFDZ.js";
43
43
  import "../chunk-VZ5ZZBNX.js";
@@ -1,19 +1,19 @@
1
1
  import {
2
2
  AgentTeam
3
- } from "../../chunk-APKCA2LY.js";
3
+ } from "../../chunk-TK2VXQVZ.js";
4
4
  import "../../chunk-X6WS3XWL.js";
5
- import "../../chunk-HSWH3ZLP.js";
5
+ import "../../chunk-3SUEXGRA.js";
6
6
  import "../../chunk-PIMD4DYG.js";
7
7
  import "../../chunk-FSBDE6RF.js";
8
8
  import "../../chunk-3TAQXJBC.js";
9
9
  import "../../chunk-CJKGTEN4.js";
10
10
  import "../../chunk-ENZ2XX27.js";
11
- import "../../chunk-6RVQ3C64.js";
12
- import "../../chunk-PXX3ITNH.js";
13
- import "../../chunk-U5AJS7KM.js";
11
+ import "../../chunk-AJC6YRVB.js";
12
+ import "../../chunk-PWWKX2HA.js";
13
+ import "../../chunk-PZ7ATNR6.js";
14
14
  import "../../chunk-B57NNDEF.js";
15
15
  import "../../chunk-LAIATEUB.js";
16
- import "../../chunk-GE46NHN4.js";
16
+ import "../../chunk-NDAGW32C.js";
17
17
  import "../../chunk-GDY2Z2SZ.js";
18
18
  import "../../chunk-KITX3HDN.js";
19
19
  import "../../chunk-NPJ2T3L5.js";
@@ -28,9 +28,9 @@ import "../../chunk-T3ZOZEAB.js";
28
28
  import "../../chunk-6E6ABRJ6.js";
29
29
  import "../../chunk-YNA3UR42.js";
30
30
  import "../../chunk-H3H74RWJ.js";
31
- import "../../chunk-E44DRLUL.js";
32
- import "../../chunk-LQJ4KHMY.js";
33
31
  import "../../chunk-MJCMKZFP.js";
32
+ import "../../chunk-PPMK7CG4.js";
33
+ import "../../chunk-LQJ4KHMY.js";
34
34
  import "../../chunk-EZR5AV3J.js";
35
35
  import "../../chunk-OJF67RNM.js";
36
36
  import "../../chunk-FAPIZJS2.js";
@@ -43,8 +43,8 @@ import "../../chunk-NF6WBPFG.js";
43
43
  import "../../chunk-LBYJPMHC.js";
44
44
  import "../../chunk-KFAVEL5F.js";
45
45
  import "../../chunk-GLMYZ6OA.js";
46
- import "../../chunk-IHAURFIO.js";
47
- import "../../chunk-K4IBS7VB.js";
46
+ import "../../chunk-UYODZ7OE.js";
47
+ import "../../chunk-WLUWRBQ4.js";
48
48
  import "../../chunk-ZPJFXRQZ.js";
49
49
  import "../../chunk-MEN4AFDZ.js";
50
50
  import "../../chunk-VZ5ZZBNX.js";
@@ -1,9 +1,9 @@
1
1
  import "../../chunk-53TPAXYR.js";
2
2
  import {
3
3
  AgentTeam
4
- } from "../../chunk-APKCA2LY.js";
4
+ } from "../../chunk-TK2VXQVZ.js";
5
5
  import "../../chunk-X6WS3XWL.js";
6
- import "../../chunk-HSWH3ZLP.js";
6
+ import "../../chunk-3SUEXGRA.js";
7
7
  import "../../chunk-PIMD4DYG.js";
8
8
  import "../../chunk-FSBDE6RF.js";
9
9
  import "../../chunk-3TAQXJBC.js";
@@ -12,12 +12,12 @@ import {
12
12
  AgentTeamInteractionError,
13
13
  AgentTeamLimitError
14
14
  } from "../../chunk-ENZ2XX27.js";
15
- import "../../chunk-6RVQ3C64.js";
16
- import "../../chunk-PXX3ITNH.js";
17
- import "../../chunk-U5AJS7KM.js";
15
+ import "../../chunk-AJC6YRVB.js";
16
+ import "../../chunk-PWWKX2HA.js";
17
+ import "../../chunk-PZ7ATNR6.js";
18
18
  import "../../chunk-B57NNDEF.js";
19
19
  import "../../chunk-LAIATEUB.js";
20
- import "../../chunk-GE46NHN4.js";
20
+ import "../../chunk-NDAGW32C.js";
21
21
  import "../../chunk-GDY2Z2SZ.js";
22
22
  import "../../chunk-KITX3HDN.js";
23
23
  import "../../chunk-NPJ2T3L5.js";
@@ -32,9 +32,9 @@ import "../../chunk-T3ZOZEAB.js";
32
32
  import "../../chunk-6E6ABRJ6.js";
33
33
  import "../../chunk-YNA3UR42.js";
34
34
  import "../../chunk-H3H74RWJ.js";
35
- import "../../chunk-E44DRLUL.js";
36
- import "../../chunk-LQJ4KHMY.js";
37
35
  import "../../chunk-MJCMKZFP.js";
36
+ import "../../chunk-PPMK7CG4.js";
37
+ import "../../chunk-LQJ4KHMY.js";
38
38
  import "../../chunk-EZR5AV3J.js";
39
39
  import "../../chunk-OJF67RNM.js";
40
40
  import "../../chunk-FAPIZJS2.js";
@@ -47,8 +47,8 @@ import "../../chunk-NF6WBPFG.js";
47
47
  import "../../chunk-LBYJPMHC.js";
48
48
  import "../../chunk-KFAVEL5F.js";
49
49
  import "../../chunk-GLMYZ6OA.js";
50
- import "../../chunk-IHAURFIO.js";
51
- import "../../chunk-K4IBS7VB.js";
50
+ import "../../chunk-UYODZ7OE.js";
51
+ import "../../chunk-WLUWRBQ4.js";
52
52
  import "../../chunk-ZPJFXRQZ.js";
53
53
  import "../../chunk-MEN4AFDZ.js";
54
54
  import "../../chunk-VZ5ZZBNX.js";
@@ -2,8 +2,8 @@ import { b as RetrySetting } from './retry-CjvSlKGW.js';
2
2
  import { D as Document, d as CompletionModel, P as ProviderTool, J as JsonObject, C as CompletionControlValues, f as CompletionModelControlsOf, z as ToolChoice } from './types-DYqZKDA8.js';
3
3
  import { d as GuardrailPolicyInput, c as GuardrailPolicy } from './types-CqiX-4_C.js';
4
4
  import { a as McpServer } from './types-0t3BczrD.js';
5
- import { E as MemoryStore, z as MemorySavePolicy, F as MemoryTokenCounter, n as MemoryCompactor, d as MemoryCompactionConflictRetryOptions, y as MemoryOptions, k as MemoryCompactionResult } from './types-DhWxTobb.js';
6
- import { h as AgentLifecycle, P as AgentObservabilityOptions, k as AgentMiddleware, o as AgentRunOptions, l as AgentOutcome, p as AgentRunSettings, u as AgentStream, j as AgentMemoryCompactionOptions } from './middleware-DORuwSy-.js';
5
+ import { F as MemoryStore, A as MemorySavePolicy, G as MemoryTokenCounter, o as MemoryCompactor, d as MemoryCompactionConflictRetryOptions, z as MemoryOptions, k as MemoryCompactionResult } from './types-B8KBVXuH.js';
6
+ import { h as AgentLifecycle, P as AgentObservabilityOptions, k as AgentMiddleware, o as AgentRunOptions, l as AgentOutcome, p as AgentRunSettings, u as AgentStream, j as AgentMemoryCompactionOptions } from './middleware-BxzML2hK.js';
7
7
  import { Z as ZodSchema } from './zod-schema-C7F4clpm.js';
8
8
  import { A as AnyTool, T as Tool, c as ToolCallContext, N as NormalizedToolOutput } from './tool-D_jV3cRZ.js';
9
9
  import { AgentContinuation, AgentInteractionResponse } from './agent/interactions/index.js';
@@ -78,7 +78,11 @@ type AgentMemory = {
78
78
  afterTokens: number;
79
79
  };
80
80
  retention: {
81
+ recentTurns: number;
82
+ recentTokens?: undefined;
83
+ } | {
81
84
  recentTokens: number;
85
+ recentTurns?: undefined;
82
86
  };
83
87
  tokenCounter: MemoryTokenCounter;
84
88
  compactor: MemoryCompactor;
@@ -19,10 +19,10 @@ import {
19
19
  import {
20
20
  createResolvedAgent,
21
21
  getResolvedAgentOptions
22
- } from "./chunk-6RVQ3C64.js";
22
+ } from "./chunk-AJC6YRVB.js";
23
23
  import {
24
24
  AgentRun
25
- } from "./chunk-U5AJS7KM.js";
25
+ } from "./chunk-PZ7ATNR6.js";
26
26
  import {
27
27
  withInternalAgentRunOptions
28
28
  } from "./chunk-KITX3HDN.js";
@@ -619,4 +619,4 @@ var TeamRun = class {
619
619
  export {
620
620
  TeamRun
621
621
  };
622
- //# sourceMappingURL=chunk-HSWH3ZLP.js.map
622
+ //# sourceMappingURL=chunk-3SUEXGRA.js.map
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  Agent
3
- } from "./chunk-PXX3ITNH.js";
3
+ } from "./chunk-PWWKX2HA.js";
4
4
  import {
5
5
  getAgentToolState
6
6
  } from "./chunk-A7BXVZXZ.js";
7
7
  import {
8
8
  markResolvedAgentOptions
9
- } from "./chunk-IHAURFIO.js";
9
+ } from "./chunk-UYODZ7OE.js";
10
10
 
11
11
  // src/agent/resolved-agent.ts
12
12
  function createResolvedAgent(options) {
@@ -45,4 +45,4 @@ export {
45
45
  createResolvedAgent,
46
46
  getResolvedAgentOptions
47
47
  };
48
- //# sourceMappingURL=chunk-6RVQ3C64.js.map
48
+ //# sourceMappingURL=chunk-AJC6YRVB.js.map
@@ -2,6 +2,9 @@ import {
2
2
  snapshotPipelineObservability,
3
3
  startPipelineRunObservers
4
4
  } from "./chunk-ETYB5JO6.js";
5
+ import {
6
+ PipelineAgentSuspensionError
7
+ } from "./chunk-R6722CIU.js";
5
8
  import {
6
9
  childContext,
7
10
  combineAbortSignals,
@@ -9,9 +12,6 @@ import {
9
12
  runNode,
10
13
  stageContext
11
14
  } from "./chunk-EKZRAWBP.js";
12
- import {
13
- PipelineAgentSuspensionError
14
- } from "./chunk-R6722CIU.js";
15
15
  import {
16
16
  appendComposedGraph,
17
17
  appendParallelBranch,
@@ -372,4 +372,4 @@ function normalizeParallelBranches(branches) {
372
372
  export {
373
373
  Pipeline
374
374
  };
375
- //# sourceMappingURL=chunk-ZGDUEOSH.js.map
375
+ //# sourceMappingURL=chunk-DXW37JLZ.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createMemoryCompactionSummary,
3
3
  cumulativeCompactedMessageCount
4
- } from "./chunk-E44DRLUL.js";
4
+ } from "./chunk-PPMK7CG4.js";
5
5
  import {
6
6
  MemoryCompactionConflictError,
7
7
  MemoryCompactionError
@@ -162,7 +162,7 @@ var AgentRunMemory = class {
162
162
  snapshot.messages,
163
163
  incomingMessages,
164
164
  options.trigger.afterTokens,
165
- options.retention.recentTokens,
165
+ options.retention,
166
166
  options.tokenCounter,
167
167
  force
168
168
  );
@@ -249,7 +249,7 @@ var AgentRunMemory = class {
249
249
  throw new MemoryCompactionConflictError(maxAttempts, usage);
250
250
  }
251
251
  };
252
- async function selectCompactionPrefix(messages, incomingMessages, afterTokens, recentTokens, tokenCounter, force) {
252
+ async function selectCompactionPrefix(messages, incomingMessages, afterTokens, retention, tokenCounter, force) {
253
253
  const originalTokenCount = await countTokens(tokenCounter, messages);
254
254
  const incomingTokenCount = incomingMessages.length === 0 ? 0 : await countTokens(tokenCounter, incomingMessages);
255
255
  const none = {
@@ -264,31 +264,42 @@ async function selectCompactionPrefix(messages, incomingMessages, afterTokens, r
264
264
  const userMessageIndexes = messages.flatMap(
265
265
  (message, index) => message.role === "user" ? [index] : []
266
266
  );
267
- if (userMessageIndexes.length <= 1) {
268
- return none;
269
- }
270
- const tailTokenCounts = /* @__PURE__ */ new Map();
271
- const countTail = async (messageIndex) => {
272
- const cached = tailTokenCounts.get(messageIndex);
273
- if (cached !== void 0) return cached;
274
- const count = await countTokens(tokenCounter, messages.slice(messageIndex));
275
- tailTokenCounts.set(messageIndex, count);
276
- return count;
277
- };
278
- let lower = 0;
279
- let upper = userMessageIndexes.length - 1;
280
- let retainedBoundary = upper;
281
- while (lower <= upper) {
282
- const middle = Math.floor((lower + upper) / 2);
283
- const candidate = userMessageIndexes[middle] ?? 0;
284
- if (await countTail(candidate) <= recentTokens) {
285
- retainedBoundary = middle;
286
- upper = middle - 1;
287
- } else {
288
- lower = middle + 1;
267
+ let compactedMessageCount;
268
+ let retainedTokenCount;
269
+ if (retention.recentTurns !== void 0) {
270
+ if (userMessageIndexes.length <= retention.recentTurns) {
271
+ return none;
272
+ }
273
+ compactedMessageCount = retention.recentTurns === 0 ? messages.length : userMessageIndexes[userMessageIndexes.length - retention.recentTurns] ?? 0;
274
+ retainedTokenCount = await countTokens(tokenCounter, messages.slice(compactedMessageCount));
275
+ } else {
276
+ if (userMessageIndexes.length <= 1) {
277
+ return none;
278
+ }
279
+ const tailTokenCounts = /* @__PURE__ */ new Map();
280
+ const countTail = async (messageIndex) => {
281
+ const cached = tailTokenCounts.get(messageIndex);
282
+ if (cached !== void 0) return cached;
283
+ const count = await countTokens(tokenCounter, messages.slice(messageIndex));
284
+ tailTokenCounts.set(messageIndex, count);
285
+ return count;
286
+ };
287
+ let lower = 0;
288
+ let upper = userMessageIndexes.length - 1;
289
+ let retainedBoundary = upper;
290
+ while (lower <= upper) {
291
+ const middle = Math.floor((lower + upper) / 2);
292
+ const candidate = userMessageIndexes[middle] ?? 0;
293
+ if (await countTail(candidate) <= retention.recentTokens) {
294
+ retainedBoundary = middle;
295
+ upper = middle - 1;
296
+ } else {
297
+ lower = middle + 1;
298
+ }
289
299
  }
300
+ compactedMessageCount = userMessageIndexes[retainedBoundary] ?? 0;
301
+ retainedTokenCount = tailTokenCounts.get(compactedMessageCount) ?? await countTokens(tokenCounter, messages.slice(compactedMessageCount));
290
302
  }
291
- const compactedMessageCount = userMessageIndexes[retainedBoundary] ?? 0;
292
303
  if (compactedMessageCount === 0) {
293
304
  return none;
294
305
  }
@@ -296,7 +307,6 @@ async function selectCompactionPrefix(messages, incomingMessages, afterTokens, r
296
307
  tokenCounter,
297
308
  messages.slice(0, compactedMessageCount)
298
309
  );
299
- const retainedTokenCount = tailTokenCounts.get(compactedMessageCount) ?? await countTokens(tokenCounter, messages.slice(compactedMessageCount));
300
310
  return {
301
311
  compactedMessageCount,
302
312
  originalTokenCount,
@@ -339,4 +349,4 @@ function isEmptyUsage(usage) {
339
349
  export {
340
350
  AgentRunMemory
341
351
  };
342
- //# sourceMappingURL=chunk-GE46NHN4.js.map
352
+ //# sourceMappingURL=chunk-NDAGW32C.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/internal/agent-runtime/memory.ts"],"sourcesContent":["import type { Agent } from \"../../agent/agent\";\nimport type { AgentMemory } from \"../../agent/types\";\nimport { type Message as MessageType, Usage } from \"../../completion/index\";\nimport {\n createMemoryCompactionSummary,\n cumulativeCompactedMessageCount,\n} from \"../../memory/compaction\";\nimport { MemoryCompactionConflictError, MemoryCompactionError } from \"../../memory/errors\";\nimport type {\n MemoryCompactionInfo,\n MemoryCompactionResult,\n MemorySavePolicy,\n MemoryScope,\n MemoryTokenCounter,\n} from \"../../memory/types\";\nimport { throwIfAborted } from \"../abort\";\n\nexport type MemoryPreparation = {\n history: MessageType[];\n usage: ReturnType<typeof Usage.empty>;\n compaction?: MemoryCompactionInfo | undefined;\n originalTokenCount?: number | undefined;\n};\n\ntype MemoryAgent = Pick<Agent, \"memory\">;\n\nexport class AgentRunMemory {\n constructor(\n private readonly agent: MemoryAgent,\n private readonly memoryScope: MemoryScope | undefined,\n private readonly initialHistory: MessageType[],\n ) {}\n\n memoryPolicy(): MemorySavePolicy | undefined {\n return this.memory()?.savePolicy;\n }\n\n pendingTurnMessages(newMessages: MessageType[]): MessageType[] {\n return this.memoryPolicy() === \"turn\" ? [...newMessages] : [];\n }\n\n async prepareHistory(\n runId: string,\n incomingMessages: readonly MessageType[],\n abortSignal?: AbortSignal | undefined,\n ): Promise<MemoryPreparation> {\n const memory = this.memory();\n if (memory === undefined || this.memoryScope === undefined) {\n return {\n history: this.initialHistory,\n usage: Usage.empty(),\n };\n }\n\n const preparation = await this.prepareStoredHistory(\n memory,\n runId,\n incomingMessages,\n abortSignal,\n );\n const memoryHistory = preparation.history;\n const chatHistory = [...memoryHistory, ...this.initialHistory];\n return {\n ...preparation,\n history: chatHistory,\n };\n }\n\n async compact(\n runId: string,\n abortSignal?: AbortSignal | undefined,\n ): Promise<MemoryCompactionResult> {\n const memory = this.memory();\n const scope = this.memoryScope;\n if (memory === undefined || scope === undefined) {\n throw new TypeError(\"Manual memory compaction requires an Agent with configured memory.\");\n }\n if (memory.compaction === undefined || memory.store.compaction === undefined) {\n throw new TypeError(\"Manual memory compaction requires a configured compaction policy.\");\n }\n const preparation = await this.prepareStoredHistory(memory, runId, [], abortSignal, true);\n if (preparation.compaction !== undefined) {\n return { type: \"compacted\", ...preparation.compaction };\n }\n return {\n type: \"skipped\",\n reason: \"nothing_to_compact\",\n originalMessageCount: preparation.history.length,\n originalTokenCount:\n preparation.originalTokenCount ??\n (await countTokens(memory.compaction.tokenCounter, preparation.history)),\n };\n }\n\n async commitAcceptedInput(runId: string, messages: MessageType[]): Promise<void> {\n const memory = this.memory();\n if (\n memory === undefined ||\n this.memoryScope === undefined ||\n memory.savePolicy !== \"message\" ||\n messages.length === 0\n ) {\n return;\n }\n\n await memory.store.append({\n scope: this.memoryScope,\n runId,\n turn: 1,\n messages,\n });\n }\n\n async commitMessages(\n runId: string,\n turn: number,\n messages: MessageType[],\n pendingTurnMessages: MessageType[],\n ): Promise<void> {\n const memory = this.memory();\n if (memory === undefined || this.memoryScope === undefined || messages.length === 0) {\n return;\n }\n if (memory.savePolicy === \"message\") {\n await memory.store.append({\n scope: this.memoryScope,\n runId,\n turn,\n messages,\n });\n } else if (memory.savePolicy === \"turn\") {\n pendingTurnMessages.push(...messages);\n }\n }\n\n async commitCompletedTurn(\n runId: string,\n turn: number,\n pendingTurnMessages: MessageType[],\n ): Promise<void> {\n const memory = this.memory();\n if (\n memory === undefined ||\n this.memoryScope === undefined ||\n memory.savePolicy !== \"turn\" ||\n pendingTurnMessages.length === 0\n ) {\n return;\n }\n await memory.store.append({\n scope: this.memoryScope,\n runId,\n turn,\n messages: [...pendingTurnMessages],\n });\n pendingTurnMessages.length = 0;\n }\n\n async commitCompletedRun(\n runId: string,\n turn: number,\n newMessages: MessageType[],\n pendingTurnMessages: MessageType[],\n ): Promise<void> {\n await this.commitCompletedTurn(runId, turn, pendingTurnMessages);\n const memory = this.memory();\n if (memory === undefined || this.memoryScope === undefined || memory.savePolicy !== \"run\") {\n return;\n }\n await memory.store.append({\n scope: this.memoryScope,\n runId,\n turn,\n messages: [...newMessages],\n });\n }\n\n async recordError(runId: string, error: unknown, newMessages: MessageType[]): Promise<void> {\n const memory = this.memory();\n if (memory === undefined || this.memoryScope === undefined) {\n return;\n }\n await memory.store.recordError?.({\n scope: this.memoryScope,\n runId,\n error,\n messages: [...newMessages],\n });\n }\n\n private memory(): AgentMemory | undefined {\n return this.memoryScope === undefined ? undefined : this.agent.memory;\n }\n\n private async prepareStoredHistory(\n memory: AgentMemory,\n runId: string,\n incomingMessages: readonly MessageType[],\n abortSignal?: AbortSignal | undefined,\n force = false,\n ): Promise<MemoryPreparation> {\n const scope = this.memoryScope;\n if (scope === undefined) {\n return { history: [], usage: Usage.empty() };\n }\n const options = memory.compaction;\n const capability = memory.store.compaction;\n if (options === undefined || capability === undefined) {\n return {\n history: await memory.store.load({ scope }),\n usage: Usage.empty(),\n };\n }\n\n let usage = Usage.empty();\n const maxAttempts = options.conflictRetries === false ? 1 : options.conflictRetries.maxAttempts;\n for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {\n throwIfAborted(abortSignal);\n const snapshot = await capability.snapshot({ scope });\n throwIfAborted(abortSignal);\n const selection = await selectCompactionPrefix(\n snapshot.messages,\n incomingMessages,\n options.trigger.afterTokens,\n options.retention,\n options.tokenCounter,\n force,\n );\n throwIfAborted(abortSignal);\n const compactedMessageCount = selection.compactedMessageCount;\n if (compactedMessageCount === 0) {\n return {\n history: snapshot.messages,\n usage,\n originalTokenCount: selection.originalTokenCount,\n };\n }\n\n const prefix = snapshot.messages.slice(0, compactedMessageCount);\n let result: Awaited<ReturnType<typeof options.compactor>>;\n try {\n result = await options.compactor({\n scope,\n messages: prefix,\n abortSignal,\n });\n } catch (error) {\n throw remappedCompactorError(error, usage);\n }\n if (result.usage !== undefined) {\n usage = Usage.add(usage, result.usage);\n }\n if (typeof result?.summary !== \"string\") {\n throw new MemoryCompactionError(\"Memory compactor must return a summary string.\", {\n usage,\n });\n }\n const summaryText = result.summary.trim();\n if (summaryText.length === 0) {\n throw new MemoryCompactionError(\"Memory compactor returned an empty summary.\", {\n usage,\n });\n }\n const summary = createMemoryCompactionSummary(\n summaryText,\n cumulativeCompactedMessageCount(prefix),\n );\n const retained = snapshot.messages.slice(compactedMessageCount);\n let resultTokenCount: number;\n try {\n resultTokenCount = await countTokens(options.tokenCounter, [summary, ...retained]);\n } catch (error) {\n throw remappedCompactorError(error, usage);\n }\n throwIfAborted(abortSignal);\n let replacement: Awaited<ReturnType<typeof capability.replacePrefix>>;\n try {\n replacement = await capability.replacePrefix({\n scope,\n revision: snapshot.revision,\n messageCount: compactedMessageCount,\n replacement: summary,\n runId: `memory-compaction:${runId}:${attempt}`,\n });\n } catch (error) {\n throw new MemoryCompactionError(\"Memory compaction prefix replacement failed.\", {\n cause: error,\n usage,\n });\n }\n if (replacement.status === \"committed\") {\n return {\n history: [summary, ...retained],\n usage,\n compaction: {\n originalMessageCount: snapshot.messages.length,\n compactedMessageCount,\n retainedMessageCount: retained.length,\n originalTokenCount: selection.originalTokenCount,\n compactedTokenCount: selection.compactedTokenCount,\n retainedTokenCount: selection.retainedTokenCount,\n resultTokenCount,\n attempts: attempt,\n usage,\n },\n };\n }\n throwIfAborted(abortSignal);\n }\n\n throw new MemoryCompactionConflictError(maxAttempts, usage);\n }\n}\n\ntype CompactionSelection = {\n compactedMessageCount: number;\n originalTokenCount: number;\n compactedTokenCount: number;\n retainedTokenCount: number;\n};\n\nasync function selectCompactionPrefix(\n messages: readonly MessageType[],\n incomingMessages: readonly MessageType[],\n afterTokens: number,\n retention:\n | { recentTurns: number; recentTokens?: undefined }\n | { recentTokens: number; recentTurns?: undefined },\n tokenCounter: MemoryTokenCounter,\n force: boolean,\n): Promise<CompactionSelection> {\n const originalTokenCount = await countTokens(tokenCounter, messages);\n const incomingTokenCount =\n incomingMessages.length === 0 ? 0 : await countTokens(tokenCounter, incomingMessages);\n const none = {\n compactedMessageCount: 0,\n originalTokenCount,\n compactedTokenCount: 0,\n retainedTokenCount: originalTokenCount,\n };\n if (!force && originalTokenCount + incomingTokenCount <= afterTokens) {\n return none;\n }\n const userMessageIndexes = messages.flatMap((message, index) =>\n message.role === \"user\" ? [index] : [],\n );\n let compactedMessageCount: number;\n let retainedTokenCount: number;\n if (retention.recentTurns !== undefined) {\n if (userMessageIndexes.length <= retention.recentTurns) {\n return none;\n }\n compactedMessageCount =\n retention.recentTurns === 0\n ? messages.length\n : (userMessageIndexes[userMessageIndexes.length - retention.recentTurns] ?? 0);\n retainedTokenCount = await countTokens(tokenCounter, messages.slice(compactedMessageCount));\n } else {\n if (userMessageIndexes.length <= 1) {\n return none;\n }\n\n // Legacy token retention still keeps complete user-led turns. The newest turn is always kept\n // even when it alone exceeds the budget. Find the earliest fitting tail logarithmically.\n const tailTokenCounts = new Map<number, number>();\n const countTail = async (messageIndex: number): Promise<number> => {\n const cached = tailTokenCounts.get(messageIndex);\n if (cached !== undefined) return cached;\n const count = await countTokens(tokenCounter, messages.slice(messageIndex));\n tailTokenCounts.set(messageIndex, count);\n return count;\n };\n let lower = 0;\n let upper = userMessageIndexes.length - 1;\n let retainedBoundary = upper;\n while (lower <= upper) {\n const middle = Math.floor((lower + upper) / 2);\n const candidate = userMessageIndexes[middle] ?? 0;\n if ((await countTail(candidate)) <= retention.recentTokens) {\n retainedBoundary = middle;\n upper = middle - 1;\n } else {\n lower = middle + 1;\n }\n }\n compactedMessageCount = userMessageIndexes[retainedBoundary] ?? 0;\n retainedTokenCount =\n tailTokenCounts.get(compactedMessageCount) ??\n (await countTokens(tokenCounter, messages.slice(compactedMessageCount)));\n }\n if (compactedMessageCount === 0) {\n return none;\n }\n const compactedTokenCount = await countTokens(\n tokenCounter,\n messages.slice(0, compactedMessageCount),\n );\n return {\n compactedMessageCount,\n originalTokenCount,\n compactedTokenCount,\n retainedTokenCount,\n };\n}\n\nasync function countTokens(\n tokenCounter: MemoryTokenCounter,\n messages: readonly MessageType[],\n): Promise<number> {\n let count: number;\n try {\n count = await tokenCounter(messages);\n } catch (error) {\n throw new MemoryCompactionError(\"Memory token counter failed.\", { cause: error });\n }\n if (!Number.isSafeInteger(count) || count < 0) {\n throw new MemoryCompactionError(\"Memory token counter must return a nonnegative safe integer.\");\n }\n return count;\n}\n\nfunction remappedCompactorError(error: unknown, usage: ReturnType<typeof Usage.empty>): Error {\n if (error instanceof MemoryCompactionError) {\n const mergedUsage =\n error.usage === undefined\n ? usage\n : isEmptyUsage(usage)\n ? error.usage\n : Usage.add(usage, error.usage);\n if (mergedUsage === error.usage || (error.usage === undefined && isEmptyUsage(usage))) {\n return error;\n }\n return new MemoryCompactionError(error.message, {\n cause: error,\n usage: mergedUsage,\n });\n }\n return new MemoryCompactionError(\"Memory compactor failed.\", {\n cause: error,\n usage,\n });\n}\n\nfunction isEmptyUsage(usage: ReturnType<typeof Usage.empty>): boolean {\n return (\n usage.inputTokens === 0 &&\n usage.outputTokens === 0 &&\n usage.totalTokens === 0 &&\n usage.cachedInputTokens === 0 &&\n usage.cacheCreationInputTokens === 0\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA0BO,IAAM,iBAAN,MAAqB;AAAA,EAC1B,YACmB,OACA,aACA,gBACjB;AAHiB;AACA;AACA;AAAA,EAChB;AAAA,EAHgB;AAAA,EACA;AAAA,EACA;AAAA,EAGnB,eAA6C;AAC3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AM,IAAI,sBAAsB,8DAA8D;AAAA,EAChG;AACA,SAAO;AACT;AAEA,SAAS,uBAAuB,OAAgB,OAA8C;AAC5F,MAAI,iBAAiB,uBAAuB;AAC1C,UAAM,cACJ,MAAM,UAAU,SACZ,QACA,aAAa,KAAK,IAChB,MAAM,QACN,MAAM,IAAI,OAAO,MAAM,KAAK;AACpC,QAAI,gBAAgB,MAAM,SAAU,MAAM,UAAU,UAAa,aAAa,KAAK,GAAI;AACrF,aAAO;AAAA,IACT;AACA,WAAO,IAAI,sBAAsB,MAAM,SAAS;AAAA,MAC9C,OAAO;AAAA,MACP,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACA,SAAO,IAAI,sBAAsB,4BAA4B;AAAA,IAC3D,OAAO;AAAA,IACP;AAAA,EACF,CAAC;AACH;AAEA,SAAS,aAAa,OAAgD;AACpE,SACE,MAAM,gBAAgB,KACtB,MAAM,iBAAiB,KACvB,MAAM,gBAAgB,KACtB,MAAM,sBAAsB,KAC5B,MAAM,6BAA6B;AAEvC;","names":[]}
@@ -16,6 +16,7 @@ Preserve established facts, user preferences, decisions, unresolved work, constr
16
16
  Do not invent details. Do not include hidden reasoning or mention that you are summarizing.
17
17
  Return only the concise memory summary.`;
18
18
  var MAX_FILE_TEXT_CHARS = 2e3;
19
+ var MAX_TOOL_OUTPUT_CHARS = 2e3;
19
20
  function createSummaryMemoryCompactor(options) {
20
21
  const maxTokens = options.maxTokens ?? 1024;
21
22
  const temperature = options.temperature ?? 0;
@@ -152,15 +153,18 @@ ${serializeToolOutput(content.output)}`;
152
153
  }
153
154
  function serializeToolOutput(output) {
154
155
  if (output.type === "text" || output.type === "error-text") {
155
- return output.value;
156
+ return truncateForSummary(output.value, MAX_TOOL_OUTPUT_CHARS);
156
157
  }
157
158
  if (output.type === "json" || output.type === "error-json") {
158
- return safeJson(output.value);
159
+ return truncateForSummary(safeJson(output.value), MAX_TOOL_OUTPUT_CHARS);
159
160
  }
160
161
  if (output.type === "execution-denied") {
161
- return output.reason ?? "Tool execution was denied.";
162
+ return truncateForSummary(output.reason ?? "Tool execution was denied.", MAX_TOOL_OUTPUT_CHARS);
162
163
  }
163
- return output.value.map((part) => part.type === "text" ? part.text : fileDescriptor(part)).join("\n");
164
+ return truncateForSummary(
165
+ output.value.map((part) => part.type === "text" ? part.text : fileDescriptor(part)).join("\n"),
166
+ MAX_TOOL_OUTPUT_CHARS
167
+ );
164
168
  }
165
169
  function imageDescriptor(content) {
166
170
  if (content.image.type === "url") {
@@ -209,4 +213,4 @@ export {
209
213
  createMemoryCompactionSummary,
210
214
  cumulativeCompactedMessageCount
211
215
  };
212
- //# sourceMappingURL=chunk-E44DRLUL.js.map
216
+ //# sourceMappingURL=chunk-PPMK7CG4.js.map