@mastra/memory 1.16.0-alpha.0 → 1.16.0-alpha.2
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 +42 -0
- package/dist/{chunk-3NECGYWZ.cjs → chunk-EOHXGI4J.cjs} +149 -14
- package/dist/chunk-EOHXGI4J.cjs.map +1 -0
- package/dist/{chunk-HB6AYAFD.js → chunk-MGHUIRKN.js} +149 -14
- package/dist/chunk-MGHUIRKN.js.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +47 -47
- package/dist/docs/references/docs-memory-observational-memory.md +4 -0
- package/dist/index.cjs +15 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/{observational-memory-X4N2R4CA.cjs → observational-memory-FCDIQ3SX.cjs} +26 -26
- package/dist/{observational-memory-X4N2R4CA.cjs.map → observational-memory-FCDIQ3SX.cjs.map} +1 -1
- package/dist/{observational-memory-WWAB2MMI.js → observational-memory-WJ4BDRUP.js} +3 -3
- package/dist/{observational-memory-WWAB2MMI.js.map → observational-memory-WJ4BDRUP.js.map} +1 -1
- package/dist/processors/index.cjs +24 -24
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/markers.d.ts +3 -1
- package/dist/processors/observational-memory/markers.d.ts.map +1 -1
- package/dist/processors/observational-memory/model-context.d.ts +10 -0
- package/dist/processors/observational-memory/model-context.d.ts.map +1 -0
- package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-turn/turn.d.ts +3 -0
- package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -1
- package/dist/processors/observational-memory/observational-memory.d.ts +9 -1
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/dist/processors/observational-memory/processor.d.ts.map +1 -1
- package/dist/processors/observational-memory/reflector-runner.d.ts +5 -2
- package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
- package/dist/processors/observational-memory/types.d.ts +19 -2
- package/dist/processors/observational-memory/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/dist/chunk-3NECGYWZ.cjs.map +0 -1
- package/dist/chunk-HB6AYAFD.js.map +0 -1
package/dist/docs/SKILL.md
CHANGED
|
@@ -1,120 +1,120 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.16.0-alpha.
|
|
2
|
+
"version": "1.16.0-alpha.2",
|
|
3
3
|
"package": "@mastra/memory",
|
|
4
4
|
"exports": {
|
|
5
5
|
"ModelByInputTokens": {
|
|
6
6
|
"types": "dist/processors/index.d.ts",
|
|
7
|
-
"implementation": "dist/chunk-
|
|
8
|
-
"line":
|
|
7
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
8
|
+
"line": 684
|
|
9
9
|
},
|
|
10
10
|
"OBSERVER_SYSTEM_PROMPT": {
|
|
11
11
|
"types": "dist/processors/index.d.ts",
|
|
12
|
-
"implementation": "dist/chunk-
|
|
12
|
+
"implementation": "dist/chunk-MGHUIRKN.js"
|
|
13
13
|
},
|
|
14
14
|
"ObservationalMemory": {
|
|
15
15
|
"types": "dist/processors/index.d.ts",
|
|
16
|
-
"implementation": "dist/chunk-
|
|
17
|
-
"line":
|
|
16
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
17
|
+
"line": 6432
|
|
18
18
|
},
|
|
19
19
|
"ObservationalMemoryProcessor": {
|
|
20
20
|
"types": "dist/processors/index.d.ts",
|
|
21
|
-
"implementation": "dist/chunk-
|
|
22
|
-
"line":
|
|
21
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
22
|
+
"line": 8868
|
|
23
23
|
},
|
|
24
24
|
"TokenCounter": {
|
|
25
25
|
"types": "dist/processors/index.d.ts",
|
|
26
|
-
"implementation": "dist/chunk-
|
|
27
|
-
"line":
|
|
26
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
27
|
+
"line": 5902
|
|
28
28
|
},
|
|
29
29
|
"buildObserverPrompt": {
|
|
30
30
|
"types": "dist/processors/index.d.ts",
|
|
31
|
-
"implementation": "dist/chunk-
|
|
32
|
-
"line":
|
|
31
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
32
|
+
"line": 3443
|
|
33
33
|
},
|
|
34
34
|
"buildObserverSystemPrompt": {
|
|
35
35
|
"types": "dist/processors/index.d.ts",
|
|
36
|
-
"implementation": "dist/chunk-
|
|
37
|
-
"line":
|
|
36
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
37
|
+
"line": 2842
|
|
38
38
|
},
|
|
39
39
|
"combineObservationGroupRanges": {
|
|
40
40
|
"types": "dist/processors/index.d.ts",
|
|
41
|
-
"implementation": "dist/chunk-
|
|
42
|
-
"line":
|
|
41
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
42
|
+
"line": 776
|
|
43
43
|
},
|
|
44
44
|
"deriveObservationGroupProvenance": {
|
|
45
45
|
"types": "dist/processors/index.d.ts",
|
|
46
|
-
"implementation": "dist/chunk-
|
|
47
|
-
"line":
|
|
46
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
47
|
+
"line": 810
|
|
48
48
|
},
|
|
49
49
|
"extractCurrentTask": {
|
|
50
50
|
"types": "dist/processors/index.d.ts",
|
|
51
|
-
"implementation": "dist/chunk-
|
|
52
|
-
"line":
|
|
51
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
52
|
+
"line": 3557
|
|
53
53
|
},
|
|
54
54
|
"formatMessagesForObserver": {
|
|
55
55
|
"types": "dist/processors/index.d.ts",
|
|
56
|
-
"implementation": "dist/chunk-
|
|
57
|
-
"line":
|
|
56
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
57
|
+
"line": 3169
|
|
58
58
|
},
|
|
59
59
|
"getObservationsAsOf": {
|
|
60
60
|
"types": "dist/processors/index.d.ts",
|
|
61
|
-
"implementation": "dist/chunk-
|
|
62
|
-
"line":
|
|
61
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
62
|
+
"line": 9054
|
|
63
63
|
},
|
|
64
64
|
"hasCurrentTaskSection": {
|
|
65
65
|
"types": "dist/processors/index.d.ts",
|
|
66
|
-
"implementation": "dist/chunk-
|
|
67
|
-
"line":
|
|
66
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
67
|
+
"line": 3545
|
|
68
68
|
},
|
|
69
69
|
"injectAnchorIds": {
|
|
70
70
|
"types": "dist/processors/index.d.ts",
|
|
71
|
-
"implementation": "dist/chunk-
|
|
72
|
-
"line":
|
|
71
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
72
|
+
"line": 2399
|
|
73
73
|
},
|
|
74
74
|
"optimizeObservationsForContext": {
|
|
75
75
|
"types": "dist/processors/index.d.ts",
|
|
76
|
-
"implementation": "dist/chunk-
|
|
77
|
-
"line":
|
|
76
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
77
|
+
"line": 3568
|
|
78
78
|
},
|
|
79
79
|
"parseAnchorId": {
|
|
80
80
|
"types": "dist/processors/index.d.ts",
|
|
81
|
-
"implementation": "dist/chunk-
|
|
82
|
-
"line":
|
|
81
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
82
|
+
"line": 2372
|
|
83
83
|
},
|
|
84
84
|
"parseObservationGroups": {
|
|
85
85
|
"types": "dist/processors/index.d.ts",
|
|
86
|
-
"implementation": "dist/chunk-
|
|
87
|
-
"line":
|
|
86
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
87
|
+
"line": 745
|
|
88
88
|
},
|
|
89
89
|
"parseObserverOutput": {
|
|
90
90
|
"types": "dist/processors/index.d.ts",
|
|
91
|
-
"implementation": "dist/chunk-
|
|
92
|
-
"line":
|
|
91
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
92
|
+
"line": 3453
|
|
93
93
|
},
|
|
94
94
|
"reconcileObservationGroupsFromReflection": {
|
|
95
95
|
"types": "dist/processors/index.d.ts",
|
|
96
|
-
"implementation": "dist/chunk-
|
|
97
|
-
"line":
|
|
96
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
97
|
+
"line": 834
|
|
98
98
|
},
|
|
99
99
|
"renderObservationGroupsForReflection": {
|
|
100
100
|
"types": "dist/processors/index.d.ts",
|
|
101
|
-
"implementation": "dist/chunk-
|
|
102
|
-
"line":
|
|
101
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
102
|
+
"line": 790
|
|
103
103
|
},
|
|
104
104
|
"stripEphemeralAnchorIds": {
|
|
105
105
|
"types": "dist/processors/index.d.ts",
|
|
106
|
-
"implementation": "dist/chunk-
|
|
107
|
-
"line":
|
|
106
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
107
|
+
"line": 2429
|
|
108
108
|
},
|
|
109
109
|
"stripObservationGroups": {
|
|
110
110
|
"types": "dist/processors/index.d.ts",
|
|
111
|
-
"implementation": "dist/chunk-
|
|
112
|
-
"line":
|
|
111
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
112
|
+
"line": 767
|
|
113
113
|
},
|
|
114
114
|
"wrapInObservationGroup": {
|
|
115
115
|
"types": "dist/processors/index.d.ts",
|
|
116
|
-
"implementation": "dist/chunk-
|
|
117
|
-
"line":
|
|
116
|
+
"implementation": "dist/chunk-MGHUIRKN.js",
|
|
117
|
+
"line": 738
|
|
118
118
|
},
|
|
119
119
|
"OBSERVATIONAL_MEMORY_DEFAULTS": {
|
|
120
120
|
"types": "dist/processors/index.d.ts",
|
|
@@ -161,7 +161,7 @@
|
|
|
161
161
|
"processors": {
|
|
162
162
|
"index": "dist/processors/index.js",
|
|
163
163
|
"chunks": [
|
|
164
|
-
"chunk-
|
|
164
|
+
"chunk-MGHUIRKN.js",
|
|
165
165
|
"chunk-LSJJAJAF.js"
|
|
166
166
|
]
|
|
167
167
|
}
|
|
@@ -339,6 +339,7 @@ Reflection works similarly — the Reflector runs in the background when observa
|
|
|
339
339
|
| `observation.bufferActivation` | `0.8` | How aggressively to clear the message window on activation. `0.8` means remove enough messages to keep only 20% of `messageTokens` remaining. Lower values keep more message history. |
|
|
340
340
|
| `observation.blockAfter` | `1.2` | Safety threshold as a multiplier of `messageTokens`. At `1.2`, synchronous observation is forced at 36k tokens (1.2 × 30k). Only matters if buffering can't keep up. |
|
|
341
341
|
| `activateAfterIdle` | none | Forces buffered observations and buffered reflections to activate after a period of inactivity, even if their token thresholds have not been reached yet. Accepts milliseconds or duration strings like `300_000`, `"5m"`, or `"1hr"`. Set this to your prompt cache TTL if you want activation to happen before the next cold prompt. |
|
|
342
|
+
| `activateOnProviderChange` | `false` | Forces buffered observations and reflections to activate when the next step uses a different `provider/model` than the one that produced the latest assistant step. Use this when switching providers or models would invalidate prompt cache reuse. |
|
|
342
343
|
| `reflection.bufferActivation` | `0.5` | When to start background reflection. `0.5` means reflection begins when observations reach 50% of the `observationTokens` threshold. |
|
|
343
344
|
| `reflection.blockAfter` | `1.2` | Safety threshold for reflection, same logic as observation. |
|
|
344
345
|
|
|
@@ -350,6 +351,7 @@ const memory = new Memory({
|
|
|
350
351
|
observationalMemory: {
|
|
351
352
|
model: 'google/gemini-2.5-flash',
|
|
352
353
|
activateAfterIdle: '5m',
|
|
354
|
+
activateOnProviderChange: true,
|
|
353
355
|
},
|
|
354
356
|
},
|
|
355
357
|
})
|
|
@@ -357,6 +359,8 @@ const memory = new Memory({
|
|
|
357
359
|
|
|
358
360
|
With a 5-minute prompt cache TTL, this activates buffered context after 5 minutes of inactivity so the next uncached prompt uses observations and reflections instead of a larger raw message window. If you prefer, `300_000` works the same way.
|
|
359
361
|
|
|
362
|
+
Changing model or providers mid-thread will invalidate the prompt cache. If your agent can switch between providers or models mid-thread, `activateOnProviderChange: true` forces buffered context to activate before the new provider runs. That avoids sending a large raw window to a provider that cannot reuse the previous prompt cache.
|
|
363
|
+
|
|
360
364
|
### Disabling
|
|
361
365
|
|
|
362
366
|
To disable async buffering and use synchronous observation/reflection instead:
|
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var chunkCK4U3AYR_cjs = require('./chunk-CK4U3AYR.cjs');
|
|
4
4
|
var chunkIDRQZVB4_cjs = require('./chunk-IDRQZVB4.cjs');
|
|
5
|
-
var
|
|
5
|
+
var chunkEOHXGI4J_cjs = require('./chunk-EOHXGI4J.cjs');
|
|
6
6
|
var v3 = require('zod/v3');
|
|
7
7
|
var zod = require('zod');
|
|
8
8
|
var z4 = require('zod/v4');
|
|
@@ -42,7 +42,7 @@ function _interopNamespace(e) {
|
|
|
42
42
|
var z4__namespace = /*#__PURE__*/_interopNamespace(z4);
|
|
43
43
|
var xxhash__default = /*#__PURE__*/_interopDefault(xxhash);
|
|
44
44
|
|
|
45
|
-
// ../_vendored/ai_v4/dist/chunk-
|
|
45
|
+
// ../_vendored/ai_v4/dist/chunk-OPIPXJLE.js
|
|
46
46
|
var __create = Object.create;
|
|
47
47
|
var __defProp = Object.defineProperty;
|
|
48
48
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -15709,7 +15709,7 @@ function formatTimestamp(date) {
|
|
|
15709
15709
|
}
|
|
15710
15710
|
function truncateByTokens(text4, maxTokens, hint) {
|
|
15711
15711
|
if (tokenx.estimateTokenCount(text4) <= maxTokens) return { text: text4, wasTruncated: false };
|
|
15712
|
-
const truncated =
|
|
15712
|
+
const truncated = chunkEOHXGI4J_cjs.truncateStringByTokens(text4, maxTokens);
|
|
15713
15713
|
const suffix = hint ? ` [${hint} for more]` : "";
|
|
15714
15714
|
return { text: truncated + suffix, wasTruncated: true };
|
|
15715
15715
|
}
|
|
@@ -15761,11 +15761,11 @@ ${JSON.stringify(inv.args, null, 2)}`;
|
|
|
15761
15761
|
});
|
|
15762
15762
|
}
|
|
15763
15763
|
if (inv.state === "result") {
|
|
15764
|
-
const { value: resultValue } =
|
|
15764
|
+
const { value: resultValue } = chunkEOHXGI4J_cjs.resolveToolResultValue(
|
|
15765
15765
|
part,
|
|
15766
15766
|
inv.result
|
|
15767
15767
|
);
|
|
15768
|
-
const resultStr =
|
|
15768
|
+
const resultStr = chunkEOHXGI4J_cjs.formatToolResultForObserver(resultValue, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
|
|
15769
15769
|
const fullText = `[Tool Result: ${inv.toolName}]
|
|
15770
15770
|
${resultStr}`;
|
|
15771
15771
|
parts.push(makePart(msg, i, "tool-result", fullText, detail, inv.toolName));
|
|
@@ -15792,7 +15792,7 @@ ${typeof rawArgs === "string" ? rawArgs : JSON.stringify(rawArgs, null, 2)}`;
|
|
|
15792
15792
|
const toolName = part.toolName;
|
|
15793
15793
|
if (toolName) {
|
|
15794
15794
|
const rawResult = part.output ?? part.result;
|
|
15795
|
-
const resultStr =
|
|
15795
|
+
const resultStr = chunkEOHXGI4J_cjs.formatToolResultForObserver(rawResult, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
|
|
15796
15796
|
const fullText = `[Tool Result: ${toolName}]
|
|
15797
15797
|
${resultStr}`;
|
|
15798
15798
|
parts.push(makePart(msg, i, "tool-result", fullText, detail, toolName));
|
|
@@ -15871,7 +15871,7 @@ function renderFormattedParts(parts, timestamps, options) {
|
|
|
15871
15871
|
const text4 = buildRenderedText(parts, timestamps);
|
|
15872
15872
|
let totalTokens = tokenx.estimateTokenCount(text4);
|
|
15873
15873
|
if (totalTokens > options.maxTokens) {
|
|
15874
|
-
const truncated =
|
|
15874
|
+
const truncated = chunkEOHXGI4J_cjs.truncateStringByTokens(text4, options.maxTokens);
|
|
15875
15875
|
return { text: truncated, truncated: true, tokenOffset: totalTokens - options.maxTokens };
|
|
15876
15876
|
}
|
|
15877
15877
|
const truncatedIndices = parts.map((p, i) => ({ part: p, index: i })).filter(({ part }) => part.text !== part.fullText).sort((a, b) => expandPriority(a.part) - expandPriority(b.part));
|
|
@@ -15904,7 +15904,7 @@ function renderFormattedParts(parts, timestamps, options) {
|
|
|
15904
15904
|
if (expandedTokens <= options.maxTokens) {
|
|
15905
15905
|
return { text: expanded, truncated: false, tokenOffset: 0 };
|
|
15906
15906
|
}
|
|
15907
|
-
const hardTruncated =
|
|
15907
|
+
const hardTruncated = chunkEOHXGI4J_cjs.truncateStringByTokens(expanded, options.maxTokens);
|
|
15908
15908
|
return { text: hardTruncated, truncated: true, tokenOffset: expandedTokens - options.maxTokens };
|
|
15909
15909
|
}
|
|
15910
15910
|
async function recallPart({
|
|
@@ -15955,7 +15955,7 @@ async function recallPart({
|
|
|
15955
15955
|
|
|
15956
15956
|
`;
|
|
15957
15957
|
const fallbackText = `${fallbackNote}${firstNextPart.text}`;
|
|
15958
|
-
const truncatedText2 =
|
|
15958
|
+
const truncatedText2 = chunkEOHXGI4J_cjs.truncateStringByTokens(fallbackText, maxTokens);
|
|
15959
15959
|
const wasTruncated2 = truncatedText2 !== fallbackText;
|
|
15960
15960
|
return {
|
|
15961
15961
|
text: truncatedText2,
|
|
@@ -15970,7 +15970,7 @@ async function recallPart({
|
|
|
15970
15970
|
}
|
|
15971
15971
|
throw new Error(`Part index ${partIndex} not found in message ${cursor}. Available indices: ${availableIndices}`);
|
|
15972
15972
|
}
|
|
15973
|
-
const truncatedText =
|
|
15973
|
+
const truncatedText = chunkEOHXGI4J_cjs.truncateStringByTokens(target.text, maxTokens);
|
|
15974
15974
|
const wasTruncated = truncatedText !== target.text;
|
|
15975
15975
|
return {
|
|
15976
15976
|
text: truncatedText,
|
|
@@ -17601,7 +17601,7 @@ ${workingMemory}`;
|
|
|
17601
17601
|
"Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version."
|
|
17602
17602
|
);
|
|
17603
17603
|
}
|
|
17604
|
-
const { ObservationalMemory: OMClass } = await import('./observational-memory-
|
|
17604
|
+
const { ObservationalMemory: OMClass } = await import('./observational-memory-FCDIQ3SX.cjs');
|
|
17605
17605
|
const onIndexObservations = this.hasRetrievalSearch(omConfig.retrieval) ? async (observation) => {
|
|
17606
17606
|
await this.indexObservation(observation);
|
|
17607
17607
|
} : void 0;
|
|
@@ -17610,6 +17610,7 @@ ${workingMemory}`;
|
|
|
17610
17610
|
scope: omConfig.scope,
|
|
17611
17611
|
retrieval: omConfig.retrieval,
|
|
17612
17612
|
activateAfterIdle: omConfig.activateAfterIdle,
|
|
17613
|
+
activateOnProviderChange: omConfig.activateOnProviderChange,
|
|
17613
17614
|
shareTokenBudget: omConfig.shareTokenBudget,
|
|
17614
17615
|
model: omConfig.model,
|
|
17615
17616
|
onIndexObservations,
|
|
@@ -18525,18 +18526,18 @@ Notes:
|
|
|
18525
18526
|
if (!effectiveConfig) return null;
|
|
18526
18527
|
const engine = await this.omEngine;
|
|
18527
18528
|
if (!engine) return null;
|
|
18528
|
-
const { ObservationalMemoryProcessor } = await import('./observational-memory-
|
|
18529
|
+
const { ObservationalMemoryProcessor } = await import('./observational-memory-FCDIQ3SX.cjs');
|
|
18529
18530
|
return new ObservationalMemoryProcessor(engine, this);
|
|
18530
18531
|
}
|
|
18531
18532
|
};
|
|
18532
18533
|
|
|
18533
18534
|
Object.defineProperty(exports, "ModelByInputTokens", {
|
|
18534
18535
|
enumerable: true,
|
|
18535
|
-
get: function () { return
|
|
18536
|
+
get: function () { return chunkEOHXGI4J_cjs.ModelByInputTokens; }
|
|
18536
18537
|
});
|
|
18537
18538
|
Object.defineProperty(exports, "getObservationsAsOf", {
|
|
18538
18539
|
enumerable: true,
|
|
18539
|
-
get: function () { return
|
|
18540
|
+
get: function () { return chunkEOHXGI4J_cjs.getObservationsAsOf; }
|
|
18540
18541
|
});
|
|
18541
18542
|
Object.defineProperty(exports, "extractWorkingMemoryContent", {
|
|
18542
18543
|
enumerable: true,
|