@mastra/memory 1.41.3-alpha.4 → 1.41.3-alpha.5

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.
@@ -3,7 +3,7 @@ name: mastra-memory
3
3
  description: Documentation for @mastra/memory. Use when working with @mastra/memory APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/memory"
6
- version: "1.41.3-alpha.4"
6
+ version: "1.41.3-alpha.5"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,243 +1,243 @@
1
1
  {
2
- "version": "1.41.3-alpha.4",
2
+ "version": "1.41.3-alpha.5",
3
3
  "package": "@mastra/memory",
4
4
  "exports": {
5
5
  "AUTO_MODEL_BY_PROVIDER": {
6
6
  "types": "dist/processors/observational-memory/auto-model.d.ts",
7
- "implementation": "dist/src-TRQ73bGO.js",
8
- "line": 32819
7
+ "implementation": "dist/src-C6oJP8WI.js",
8
+ "line": 32928
9
9
  },
10
10
  "Extractor": {
11
11
  "types": "dist/processors/observational-memory/extractor.d.ts",
12
- "implementation": "dist/src-TRQ73bGO.js",
12
+ "implementation": "dist/src-C6oJP8WI.js",
13
13
  "line": 24432
14
14
  },
15
15
  "ModelByInputTokens": {
16
16
  "types": "dist/processors/observational-memory/model-by-input-tokens.d.ts",
17
- "implementation": "dist/src-TRQ73bGO.js",
18
- "line": 32602
17
+ "implementation": "dist/src-C6oJP8WI.js",
18
+ "line": 32711
19
19
  },
20
20
  "OBSERVATIONAL_MEMORY_DEFAULTS": {
21
21
  "types": "dist/processors/observational-memory/constants.d.ts",
22
- "implementation": "dist/src-TRQ73bGO.js",
22
+ "implementation": "dist/src-C6oJP8WI.js",
23
23
  "line": 24168
24
24
  },
25
25
  "OBSERVATION_CONTEXT_INSTRUCTIONS": {
26
26
  "types": "dist/processors/observational-memory/constants.d.ts",
27
- "implementation": "dist/src-TRQ73bGO.js",
27
+ "implementation": "dist/src-C6oJP8WI.js",
28
28
  "line": 24229
29
29
  },
30
30
  "OBSERVATION_CONTEXT_PROMPT": {
31
31
  "types": "dist/processors/observational-memory/constants.d.ts",
32
- "implementation": "dist/src-TRQ73bGO.js",
32
+ "implementation": "dist/src-C6oJP8WI.js",
33
33
  "line": 24211
34
34
  },
35
35
  "OBSERVATION_CONTEXT_PROMPT_THREAD": {
36
36
  "types": "dist/processors/observational-memory/constants.d.ts",
37
- "implementation": "dist/src-TRQ73bGO.js",
37
+ "implementation": "dist/src-C6oJP8WI.js",
38
38
  "line": 24216
39
39
  },
40
40
  "OBSERVATION_CONTINUATION_HINT": {
41
41
  "types": "dist/processors/observational-memory/constants.d.ts",
42
- "implementation": "dist/src-TRQ73bGO.js",
42
+ "implementation": "dist/src-C6oJP8WI.js",
43
43
  "line": 24198
44
44
  },
45
45
  "OBSERVER_SYSTEM_PROMPT": {
46
46
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
47
- "implementation": "dist/src-TRQ73bGO.js",
48
- "line": 26804
47
+ "implementation": "dist/src-C6oJP8WI.js",
48
+ "line": 26861
49
49
  },
50
50
  "ObservationalMemory": {
51
51
  "types": "dist/processors/observational-memory/observational-memory.d.ts",
52
- "implementation": "dist/src-TRQ73bGO.js",
53
- "line": 37893
52
+ "implementation": "dist/src-C6oJP8WI.js",
53
+ "line": 38045
54
54
  },
55
55
  "ObservationalMemoryProcessor": {
56
56
  "types": "dist/processors/observational-memory/processor.d.ts",
57
- "implementation": "dist/src-TRQ73bGO.js",
58
- "line": 40641
57
+ "implementation": "dist/src-C6oJP8WI.js",
58
+ "line": 40861
59
59
  },
60
60
  "TokenCounter": {
61
61
  "types": "dist/processors/observational-memory/token-counter.d.ts",
62
- "implementation": "dist/src-TRQ73bGO.js",
63
- "line": 29321
62
+ "implementation": "dist/src-C6oJP8WI.js",
63
+ "line": 29393
64
64
  },
65
65
  "WorkingMemoryExtractor": {
66
66
  "types": "dist/processors/observational-memory/working-memory-extractor.d.ts",
67
- "implementation": "dist/src-TRQ73bGO.js",
68
- "line": 30340
67
+ "implementation": "dist/src-C6oJP8WI.js",
68
+ "line": 30449
69
69
  },
70
70
  "buildObserverPrompt": {
71
71
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
72
- "implementation": "dist/src-TRQ73bGO.js",
73
- "line": 27488
72
+ "implementation": "dist/src-C6oJP8WI.js",
73
+ "line": 27545
74
74
  },
75
75
  "buildObserverSystemPrompt": {
76
76
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
77
- "implementation": "dist/src-TRQ73bGO.js",
78
- "line": 26698
77
+ "implementation": "dist/src-C6oJP8WI.js",
78
+ "line": 26755
79
79
  },
80
80
  "combineObservationGroupRanges": {
81
81
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
82
- "implementation": "dist/src-TRQ73bGO.js",
83
- "line": 30922
82
+ "implementation": "dist/src-C6oJP8WI.js",
83
+ "line": 31031
84
84
  },
85
85
  "deriveObservationGroupProvenance": {
86
86
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
87
- "implementation": "dist/src-TRQ73bGO.js",
88
- "line": 30966
87
+ "implementation": "dist/src-C6oJP8WI.js",
88
+ "line": 31075
89
89
  },
90
90
  "extractCurrentTask": {
91
91
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
92
- "implementation": "dist/src-TRQ73bGO.js",
93
- "line": 27801
92
+ "implementation": "dist/src-C6oJP8WI.js",
93
+ "line": 27858
94
94
  },
95
95
  "formatMessagesForObserver": {
96
96
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
97
- "implementation": "dist/src-TRQ73bGO.js",
98
- "line": 27239
97
+ "implementation": "dist/src-C6oJP8WI.js",
98
+ "line": 27296
99
99
  },
100
100
  "getObservationContextPrompt": {
101
101
  "types": "dist/processors/observational-memory/constants.d.ts",
102
- "implementation": "dist/src-TRQ73bGO.js",
102
+ "implementation": "dist/src-C6oJP8WI.js",
103
103
  "line": 24222
104
104
  },
105
105
  "getObservationsAsOf": {
106
106
  "types": "dist/processors/observational-memory/observation-utils.d.ts",
107
- "implementation": "dist/src-TRQ73bGO.js",
108
- "line": 40981
107
+ "implementation": "dist/src-C6oJP8WI.js",
108
+ "line": 41206
109
109
  },
110
110
  "hasCurrentTaskSection": {
111
111
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
112
- "implementation": "dist/src-TRQ73bGO.js",
113
- "line": 27789
112
+ "implementation": "dist/src-C6oJP8WI.js",
113
+ "line": 27846
114
114
  },
115
115
  "injectAnchorIds": {
116
116
  "types": "dist/processors/observational-memory/anchor-ids.d.ts",
117
- "implementation": "dist/src-TRQ73bGO.js",
118
- "line": 25420
117
+ "implementation": "dist/src-C6oJP8WI.js",
118
+ "line": 25432
119
119
  },
120
120
  "optimizeObservationsForContext": {
121
121
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
122
- "implementation": "dist/src-TRQ73bGO.js",
123
- "line": 27822
122
+ "implementation": "dist/src-C6oJP8WI.js",
123
+ "line": 27879
124
124
  },
125
125
  "parseAnchorId": {
126
126
  "types": "dist/processors/observational-memory/anchor-ids.d.ts",
127
- "implementation": "dist/src-TRQ73bGO.js",
128
- "line": 25404
127
+ "implementation": "dist/src-C6oJP8WI.js",
128
+ "line": 25416
129
129
  },
130
130
  "parseObservationGroups": {
131
131
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
132
- "implementation": "dist/src-TRQ73bGO.js",
133
- "line": 30877
132
+ "implementation": "dist/src-C6oJP8WI.js",
133
+ "line": 30986
134
134
  },
135
135
  "parseObserverOutput": {
136
136
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
137
- "implementation": "dist/src-TRQ73bGO.js",
138
- "line": 27499
137
+ "implementation": "dist/src-C6oJP8WI.js",
138
+ "line": 27556
139
139
  },
140
140
  "reconcileObservationGroupsFromReflection": {
141
141
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
142
- "implementation": "dist/src-TRQ73bGO.js",
143
- "line": 30985
142
+ "implementation": "dist/src-C6oJP8WI.js",
143
+ "line": 31094
144
144
  },
145
145
  "renderObservationGroupsForReflection": {
146
146
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
147
- "implementation": "dist/src-TRQ73bGO.js",
148
- "line": 30951
147
+ "implementation": "dist/src-C6oJP8WI.js",
148
+ "line": 31060
149
149
  },
150
150
  "resolveAutoModelId": {
151
151
  "types": "dist/processors/observational-memory/auto-model.d.ts",
152
- "implementation": "dist/src-TRQ73bGO.js",
153
- "line": 32839
152
+ "implementation": "dist/src-C6oJP8WI.js",
153
+ "line": 32948
154
154
  },
155
155
  "stripEphemeralAnchorIds": {
156
156
  "types": "dist/processors/observational-memory/anchor-ids.d.ts",
157
- "implementation": "dist/src-TRQ73bGO.js",
158
- "line": 25443
157
+ "implementation": "dist/src-C6oJP8WI.js",
158
+ "line": 25455
159
159
  },
160
160
  "stripObservationGroups": {
161
161
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
162
- "implementation": "dist/src-TRQ73bGO.js",
163
- "line": 30894
162
+ "implementation": "dist/src-C6oJP8WI.js",
163
+ "line": 31003
164
164
  },
165
165
  "summarizeConversation": {
166
166
  "types": "dist/processors/observational-memory/summarize.d.ts",
167
- "implementation": "dist/src-TRQ73bGO.js",
168
- "line": 29952
167
+ "implementation": "dist/src-C6oJP8WI.js",
168
+ "line": 30061
169
169
  },
170
170
  "wrapInObservationGroup": {
171
171
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
172
- "implementation": "dist/src-TRQ73bGO.js",
173
- "line": 30848
172
+ "implementation": "dist/src-C6oJP8WI.js",
173
+ "line": 30957
174
174
  },
175
175
  "KnowledgeSemanticIndexCoordinator": {
176
176
  "types": "dist/removed-subconscious.d.ts",
177
- "implementation": "dist/src-TRQ73bGO.js",
178
- "line": 30446
177
+ "implementation": "dist/src-C6oJP8WI.js",
178
+ "line": 30555
179
179
  },
180
180
  "Memory": {
181
181
  "types": "dist/index.d.ts",
182
- "implementation": "dist/src-TRQ73bGO.js",
183
- "line": 41212
182
+ "implementation": "dist/src-C6oJP8WI.js",
183
+ "line": 41437
184
184
  },
185
185
  "SUMMARIZE_THREAD_DEFAULTS": {
186
186
  "types": "dist/processors/observational-memory/summarize.d.ts",
187
- "implementation": "dist/src-TRQ73bGO.js",
188
- "line": 29908
187
+ "implementation": "dist/src-C6oJP8WI.js",
188
+ "line": 30017
189
189
  },
190
190
  "StaleKnowledgeSemanticIndexError": {
191
191
  "types": "dist/removed-subconscious.d.ts",
192
- "implementation": "dist/src-TRQ73bGO.js",
193
- "line": 30452
192
+ "implementation": "dist/src-C6oJP8WI.js",
193
+ "line": 30561
194
194
  },
195
195
  "Subconscious": {
196
196
  "types": "dist/removed-subconscious.d.ts",
197
- "implementation": "dist/src-TRQ73bGO.js",
198
- "line": 30440
197
+ "implementation": "dist/src-C6oJP8WI.js",
198
+ "line": 30549
199
199
  },
200
200
  "WORKING_MEMORY_STATE_ID": {
201
201
  "types": "dist/processors/working-memory-state/processor.d.ts",
202
- "implementation": "dist/src-TRQ73bGO.js",
203
- "line": 32648
202
+ "implementation": "dist/src-C6oJP8WI.js",
203
+ "line": 32757
204
204
  },
205
205
  "WORKING_MEMORY_STATE_PROCESSOR_ID": {
206
206
  "types": "dist/processors/working-memory-state/processor.d.ts",
207
- "implementation": "dist/src-TRQ73bGO.js",
208
- "line": 32649
207
+ "implementation": "dist/src-C6oJP8WI.js",
208
+ "line": 32758
209
209
  },
210
210
  "WorkingMemoryStateProcessor": {
211
211
  "types": "dist/processors/working-memory-state/processor.d.ts",
212
- "implementation": "dist/src-TRQ73bGO.js",
213
- "line": 32650
212
+ "implementation": "dist/src-C6oJP8WI.js",
213
+ "line": 32759
214
214
  },
215
215
  "deepMergeWorkingMemory": {
216
216
  "types": "dist/tools/working-memory.d.ts",
217
- "implementation": "dist/src-TRQ73bGO.js",
218
- "line": 30031
217
+ "implementation": "dist/src-C6oJP8WI.js",
218
+ "line": 30140
219
219
  },
220
220
  "extractWorkingMemoryContent": {
221
221
  "types": "dist/index.d.ts",
222
- "implementation": "dist/src-TRQ73bGO.js",
223
- "line": 41046
222
+ "implementation": "dist/src-C6oJP8WI.js",
223
+ "line": 41271
224
224
  },
225
225
  "extractWorkingMemoryTags": {
226
226
  "types": "dist/index.d.ts",
227
- "implementation": "dist/src-TRQ73bGO.js",
228
- "line": 41014
227
+ "implementation": "dist/src-C6oJP8WI.js",
228
+ "line": 41239
229
229
  },
230
230
  "removeWorkingMemoryTags": {
231
231
  "types": "dist/index.d.ts",
232
- "implementation": "dist/src-TRQ73bGO.js",
233
- "line": 41027
232
+ "implementation": "dist/src-C6oJP8WI.js",
233
+ "line": 41252
234
234
  }
235
235
  },
236
236
  "modules": {
237
237
  "processors": {
238
238
  "index": "dist/processors/index.js",
239
239
  "chunks": [
240
- "src-TRQ73bGO.js"
240
+ "src-C6oJP8WI.js"
241
241
  ]
242
242
  }
243
243
  }
@@ -527,9 +527,12 @@ A manager treats a `running` task as abandoned only after its lease expires.
527
527
 
528
528
  When `recoverStaleTasksOnStart` is `true`, the default, each manager that runs tasks scans for abandoned tasks on startup. If the scan finds a lease that hasn't expired yet, the manager scans again shortly after that lease expires, and repeats until no live lease is left. A task that a manager starts after that and then abandons waits for the next startup scan. For each task the scan recovers:
529
529
 
530
- - If the task has `maxRetries` above `0`, it returns to `pending` and is dispatched again.
530
+ - If the task's worker shut down gracefully, it returns to `pending` and is dispatched again without using a retry.
531
+ - If the worker died and the task's `retryCount` is below `maxRetries`, it uses a retry, returns to `pending`, and is dispatched again.
531
532
  - Otherwise, it fails with `Worker process terminated before task completed`.
532
533
 
534
+ Only a crash counts against `maxRetries`, so a task that keeps taking its worker down stops after its retries are used, while a deploy doesn't use one.
535
+
533
536
  The recovery write is conditional on the owner and lease that the scan read, so only one manager recovers each task.
534
537
 
535
538
  If the pubsub redelivers the unacknowledged dispatch of an abandoned task, the redelivery claims the task once its lease expires and runs it again, even when `maxRetries` is `0`.
@@ -8,7 +8,7 @@
8
8
 
9
9
  Knowledge gives agents a shared, organized place for information that lives outside any one conversation: policies, product docs, conventions, runbooks and what other agents have learned. Agents search, read and write it with tools. Pages you pin reach the agent's context through [signals](https://mastra.ai/docs/signals/overview) and stay current while it runs.
10
10
 
11
- > **Alpha:** Knowledge is in alpha. Its API may change between releases. Each scope's data is kept separate, but an agent with access to more than one scope can leak content between them. Give each agent only the scopes it needs, as [Keep scopes apart](https://mastra.ai/docs/knowledge/scopes-and-access) explains. Knowledge has no built-in importers yet, but you can [write content through its API](https://mastra.ai/docs/knowledge/load-your-content), and Mastra Platform offers importers. Knowledge can't expire old pages yet.
11
+ > **Alpha:** Knowledge is in alpha. Its API may change between releases. Each scope's data is kept separate, but an agent with access to more than one scope can leak content between them. Give each agent only the scopes it needs, as [Keep scopes apart](https://mastra.ai/docs/knowledge/scopes-and-access) explains. Knowledge has no built-in importers yet, but you can [write content through its API](https://mastra.ai/docs/knowledge/load-your-content) or [write your own importer](https://mastra.ai/docs/knowledge/importers), and Mastra Platform offers importers. Knowledge can't expire old pages yet.
12
12
 
13
13
  ## What Knowledge is
14
14
 
@@ -493,10 +493,10 @@ OM decides when to observe from local token estimates, not from the provider's u
493
493
 
494
494
  OM caches estimates in message metadata so threshold checks don't recount the same content:
495
495
 
496
- - Per-part estimates are stored on `part.providerMetadata.mastra` and reused while the cache version and tokenizer source match.
496
+ - Per-part estimates are stored on `part.providerMetadata.mastra.tokenEstimate` and saved with the message. A later request reuses one only when its content hash matches the part, so a count that no longer matches the part's content is ignored and the part is counted again. The hash shows a count is current, not who wrote it: a caller-supplied count whose hash matches the content is used. Counts for history that has none are saved once, for the current thread only.
497
497
  - Messages with string-only content (no parts) use a message-level cache.
498
498
  - Message and conversation overhead is recalculated every pass. Only payload estimates are cached.
499
- - `data-*` and `reasoning` parts are skipped and not cached.
499
+ - `data-*`, `reasoning` and `step-start` parts are skipped and not cached.
500
500
 
501
501
  ### Supplying your own estimate for a file
502
502
 
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("./src-CKIbQdMJ.cjs");
2
+ const require_src = require("./src-DxOLwFhL.cjs");
3
3
  let _mastra_core_processors = require("@mastra/core/processors");
4
4
  let _mastra_core_memory = require("@mastra/core/memory");
5
5
  exports.AUTO_MODEL_BY_PROVIDER = require_src.AUTO_MODEL_BY_PROVIDER;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { m as AUTO_MODEL_BY_PROVIDER, K as Extractor, D as KnowledgeSemanticIndexCoordinator, t as Memory, n as MessageHistory, y as ModelByInputTokens, M as SUMMARIZE_THREAD_DEFAULTS, r as SemanticRecall, O as StaleKnowledgeSemanticIndexError, k as Subconscious, g as WORKING_MEMORY_STATE_ID, _ as WORKING_MEMORY_STATE_PROCESSOR_ID, i as WorkingMemory, A as WorkingMemoryExtractor, v as WorkingMemoryStateProcessor, a as asUserTurn, j as deepMergeWorkingMemory, o as escapeTurnMarkup, s as extractWorkingMemoryContent, c as extractWorkingMemoryTags, d as getObservationsAsOf, l as removeWorkingMemoryTags, h as resolveAutoModelId, u as sealTurnMarkup, N as summarizeConversation } from "./src-TRQ73bGO.js";
1
+ export { m as AUTO_MODEL_BY_PROVIDER, K as Extractor, D as KnowledgeSemanticIndexCoordinator, t as Memory, n as MessageHistory, y as ModelByInputTokens, M as SUMMARIZE_THREAD_DEFAULTS, r as SemanticRecall, O as StaleKnowledgeSemanticIndexError, k as Subconscious, g as WORKING_MEMORY_STATE_ID, _ as WORKING_MEMORY_STATE_PROCESSOR_ID, i as WorkingMemory, A as WorkingMemoryExtractor, v as WorkingMemoryStateProcessor, a as asUserTurn, j as deepMergeWorkingMemory, o as escapeTurnMarkup, s as extractWorkingMemoryContent, c as extractWorkingMemoryTags, d as getObservationsAsOf, l as removeWorkingMemoryTags, h as resolveAutoModelId, u as sealTurnMarkup, N as summarizeConversation } from "./src-C6oJP8WI.js";
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("../src-CKIbQdMJ.cjs");
2
+ const require_src = require("../src-DxOLwFhL.cjs");
3
3
  exports.AUTO_MODEL_BY_PROVIDER = require_src.AUTO_MODEL_BY_PROVIDER;
4
4
  exports.Extractor = require_src.Extractor;
5
5
  exports.ModelByInputTokens = require_src.ModelByInputTokens;
@@ -1 +1 @@
1
- export { m as AUTO_MODEL_BY_PROVIDER, K as Extractor, y as ModelByInputTokens, q as OBSERVATIONAL_MEMORY_DEFAULTS, J as OBSERVATION_CONTEXT_INSTRUCTIONS, Y as OBSERVATION_CONTEXT_PROMPT, X as OBSERVATION_CONTEXT_PROMPT_THREAD, Z as OBSERVATION_CONTINUATION_HINT, F as OBSERVER_SYSTEM_PROMPT, p as ObservationalMemory, f as ObservationalMemoryProcessor, P as TokenCounter, A as WorkingMemoryExtractor, I as buildObserverPrompt, L as buildObserverSystemPrompt, b as combineObservationGroupRanges, x as deriveObservationGroupProvenance, R as extractCurrentTask, z as formatMessagesForObserver, Q as getObservationContextPrompt, d as getObservationsAsOf, B as hasCurrentTaskSection, U as injectAnchorIds, V as optimizeObservationsForContext, W as parseAnchorId, S as parseObservationGroups, H as parseObserverOutput, C as reconcileObservationGroupsFromReflection, w as renderObservationGroupsForReflection, h as resolveAutoModelId, G as stripEphemeralAnchorIds, T as stripObservationGroups, N as summarizeConversation, E as wrapInObservationGroup } from "../src-TRQ73bGO.js";
1
+ export { m as AUTO_MODEL_BY_PROVIDER, K as Extractor, y as ModelByInputTokens, q as OBSERVATIONAL_MEMORY_DEFAULTS, J as OBSERVATION_CONTEXT_INSTRUCTIONS, Y as OBSERVATION_CONTEXT_PROMPT, X as OBSERVATION_CONTEXT_PROMPT_THREAD, Z as OBSERVATION_CONTINUATION_HINT, F as OBSERVER_SYSTEM_PROMPT, p as ObservationalMemory, f as ObservationalMemoryProcessor, P as TokenCounter, A as WorkingMemoryExtractor, I as buildObserverPrompt, L as buildObserverSystemPrompt, b as combineObservationGroupRanges, x as deriveObservationGroupProvenance, R as extractCurrentTask, z as formatMessagesForObserver, Q as getObservationContextPrompt, d as getObservationsAsOf, B as hasCurrentTaskSection, U as injectAnchorIds, V as optimizeObservationsForContext, W as parseAnchorId, S as parseObservationGroups, H as parseObserverOutput, C as reconcileObservationGroupsFromReflection, w as renderObservationGroupsForReflection, h as resolveAutoModelId, G as stripEphemeralAnchorIds, T as stripObservationGroups, N as summarizeConversation, E as wrapInObservationGroup } from "../src-C6oJP8WI.js";
@@ -447,9 +447,19 @@ export declare class ObservationalMemory {
447
447
  * to detect already-persisted messages, avoiding redundant DB operations.
448
448
  *
449
449
  * Messages with observation markers are always saved (upserted) even if sealed,
450
- * because the markers need to be persisted to storage.
450
+ * because the markers need to be persisted to storage. A stored message in `resaveIds` gained token
451
+ * counts after it was stored, whether or not it is sealed: only those counts are copied onto the stored
452
+ * copy, see {@link persistTokenEstimatesOntoStored}; one with no stored row was deleted during the turn and stays deleted. Ids in `resaveIds` must not be this turn's own
453
+ * input or output, which are saved whole.
451
454
  */
452
- persistMessages(messagesToSave: MastraDBMessage[], threadId: string, resourceId: string | undefined): Promise<void>;
455
+ persistMessages(messagesToSave: MastraDBMessage[], threadId: string, resourceId: string | undefined, resaveIds?: ReadonlySet<string>): Promise<void>;
456
+ /**
457
+ * Copy the token counts of `messages` onto their stored copies. A stored copy can hold
458
+ * parts the in-memory one lacks (markers written straight to storage), so it is patched
459
+ * instead of saved whole. Each count goes to the first stored part whose content matches the counted
460
+ * part, so a part that changed in storage keeps no count and is counted again on read.
461
+ */
462
+ private persistTokenEstimatesOntoStored;
453
463
  /**
454
464
  * Load messages from storage that haven't been observed yet.
455
465
  * Uses cursor-based query with lastObservedAt timestamp for efficiency.
@@ -0,0 +1,23 @@
1
+ import type { MastraDBMessage, MessageList } from '@mastra/core/agent';
2
+ /**
3
+ * Mark the stored history of `threadId` in `messageList` that OM gave new token counts, so the counts are saved
4
+ * with the messages. Call the returned function once the counting is done: every message holding a part that
5
+ * gained a count in this process is marked for resave, and the normal save writes it back whole. Counts made
6
+ * before this is called (while the turn loaded history) are caught too.
7
+ *
8
+ * Only messages of `threadId` are marked. A message recalled from another thread of the resource is counted but
9
+ * never written, because saving it would bump that thread's `updatedAt` and reorder the recent-thread list.
10
+ *
11
+ * A Core without `markForResave` is left alone: counting still works, the counts are just not saved.
12
+ */
13
+ export declare function resaveCountedMessagesFor(messageList: MessageList, threadId: string): () => void;
14
+ /** The stored messages marked for resave in `messageList`; none for a Core without `markForResave`. */
15
+ export declare function messagesMarkedForResave(messageList: MessageList): MastraDBMessage[];
16
+ /**
17
+ * Ids of the stored messages marked for resave in `messageList` that are not in `ownMessages` (the turn's
18
+ * own input and output). Those are saved whole; the rest only gained counts and are patched onto storage.
19
+ */
20
+ export declare function idsMarkedForResave(messageList: MessageList, ownMessages?: MastraDBMessage[]): Set<string>;
21
+ /** `messages` with the messages marked for resave added, each message once. */
22
+ export declare function withMessagesMarkedForResave(messageList: MessageList, messages: MastraDBMessage[]): MastraDBMessage[];
23
+ //# sourceMappingURL=resave-counted-messages.d.ts.map
@@ -95,6 +95,15 @@ export declare function hasAbortInChain(error: unknown): boolean;
95
95
  * @internal
96
96
  */
97
97
  export declare function isTransientLLMError(error: unknown): boolean;
98
+ /**
99
+ * Returns true when the error says the provider account has no credits or quota left, as core's
100
+ * provider-error classifier decides it. These can carry a retryable status (OpenAI's are HTTP 429,
101
+ * the status of a rate limit), so `withRetry` stops on them even though `isTransientLLMError`
102
+ * matches: the account stays unusable until someone adds credits. Rate limits are still retried.
103
+ *
104
+ * @internal
105
+ */
106
+ export declare function isExhaustedAccountError(error: unknown): boolean;
98
107
  /**
99
108
  * Compute the backoff delay (ms) for the Nth retry (0-indexed).
100
109
  *
@@ -125,7 +134,8 @@ export type OnAttemptActivity = () => void;
125
134
  /**
126
135
  * Run `fn` with retries on transient transport-class errors.
127
136
  *
128
- * Non-transient errors (auth, validation, schema, etc.) are rethrown
137
+ * Non-transient errors (auth, validation, schema, etc.) and errors from an
138
+ * account with no credits or quota left (see `isExhaustedAccountError`) are rethrown
129
139
  * immediately. User-initiated aborts are rethrown without delay.
130
140
  *
131
141
  * @internal
@@ -6,6 +6,10 @@ export type TokenCounterModelContext = {
6
6
  type TokenCounterOptions = {
7
7
  model?: string | TokenCounterModelContext;
8
8
  };
9
+ /** Whether `part` gained a stored count in this process that has not been handed to a save yet. */
10
+ export declare function hasUnsavedTokenEstimate(part: unknown): boolean;
11
+ /** Note that `part`'s count is on its way to storage, so later steps do not save it again. */
12
+ export declare function markTokenEstimateSaved(part: unknown): void;
9
13
  export declare function isHttpUrlString(value: unknown): boolean;
10
14
  /**
11
15
  * Decodes a stored attachment payload (data URI, raw base64, Buffer, or typed array) into bytes.
@@ -18,7 +22,11 @@ export declare function decodeImageBuffer(value: unknown): Buffer | undefined;
18
22
  * undercounted as generic JSON blobs.
19
23
  */
20
24
  export declare class TokenCounter {
21
- private readonly cacheSource;
25
+ /**
26
+ * Stored counts belong to the stock estimator. A subclass or instance that overrides `countString`
27
+ * reads and writes its own namespace, so it never reuses a count the stock estimator saved.
28
+ */
29
+ private get cacheSource();
22
30
  private readonly defaultModelContext?;
23
31
  private readonly inFlightAttachmentCounts;
24
32
  private readonly multimodalToolResultCounts;
@@ -32,6 +40,15 @@ export declare class TokenCounter {
32
40
  */
33
41
  countString(text: string): number;
34
42
  private readOrPersistPartEstimate;
43
+ /**
44
+ * Count one content-only piece of a part (its text, a tool's args or result) the same way as
45
+ * {@link readOrPersistPartEstimate}: a stored count is reused only when its content hash matches.
46
+ * `refs` are the values the payload is built from. While the same part object still holds the same
47
+ * refs, the count from the last call is returned without serializing or hashing again, so a part
48
+ * counted by `getStatus` and then by the next step is hashed once per process.
49
+ * Only string refs are memoized (object payloads are hashed every time, since they can change in place).
50
+ */
51
+ private readOrPersistMemoizedPartEstimate;
35
52
  private readOrPersistFixedPartEstimate;
36
53
  private readOrPersistMessageEstimate;
37
54
  private resolveToolResultForTokenCounting;
@@ -46,8 +63,8 @@ export declare class TokenCounter {
46
63
  /**
47
64
  * Count the name and the arguments of a tool call. Every state before the tool produces an
48
65
  * output holds the same call signature in the context window, so all of those states share
49
- * these cache kinds. `buildEstimateKey` hashes the text, so a shared kind stays correct and
50
- * keeps the estimate warm while the invocation moves from one state to the next.
66
+ * these cache kinds, and the estimate stays warm while the invocation moves from one state to
67
+ * the next. Name and args don't change across those states once the call stops streaming.
51
68
  */
52
69
  private countToolCallSignature;
53
70
  private countNonAttachmentPart;