@mastra/memory 1.10.1-alpha.0 → 1.10.1-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.
Files changed (73) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/dist/{chunk-K2NLYL2O.js → chunk-2QSOQQPM.js} +6817 -6615
  3. package/dist/chunk-2QSOQQPM.js.map +1 -0
  4. package/dist/chunk-D4J4XPGM.cjs +111 -0
  5. package/dist/chunk-D4J4XPGM.cjs.map +1 -0
  6. package/dist/chunk-LSJJAJAF.js +105 -0
  7. package/dist/chunk-LSJJAJAF.js.map +1 -0
  8. package/dist/{chunk-HSOEY7M2.cjs → chunk-NS47X3OB.cjs} +6807 -6608
  9. package/dist/chunk-NS47X3OB.cjs.map +1 -0
  10. package/dist/constants-BDOITAO3.js +3 -0
  11. package/dist/constants-BDOITAO3.js.map +1 -0
  12. package/dist/constants-HXOCZPB7.cjs +28 -0
  13. package/dist/constants-HXOCZPB7.cjs.map +1 -0
  14. package/dist/docs/SKILL.md +1 -1
  15. package/dist/docs/assets/SOURCE_MAP.json +67 -61
  16. package/dist/docs/references/docs-memory-observational-memory.md +7 -5
  17. package/dist/docs/references/reference-memory-observational-memory.md +2 -2
  18. package/dist/index.cjs +207 -78
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.ts +52 -5
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +200 -71
  23. package/dist/index.js.map +1 -1
  24. package/dist/{observational-memory-DJMF2UNC.cjs → observational-memory-I5UTOG63.cjs} +46 -41
  25. package/dist/{observational-memory-DJMF2UNC.cjs.map → observational-memory-I5UTOG63.cjs.map} +1 -1
  26. package/dist/observational-memory-WMCWT577.js +4 -0
  27. package/dist/{observational-memory-NMQ7URIP.js.map → observational-memory-WMCWT577.js.map} +1 -1
  28. package/dist/processors/index.cjs +44 -39
  29. package/dist/processors/index.js +2 -1
  30. package/dist/processors/observational-memory/buffering-coordinator.d.ts +61 -0
  31. package/dist/processors/observational-memory/buffering-coordinator.d.ts.map +1 -0
  32. package/dist/processors/observational-memory/constants.d.ts +62 -0
  33. package/dist/processors/observational-memory/constants.d.ts.map +1 -0
  34. package/dist/processors/observational-memory/debug.d.ts +3 -0
  35. package/dist/processors/observational-memory/debug.d.ts.map +1 -0
  36. package/dist/processors/observational-memory/index.d.ts +5 -2
  37. package/dist/processors/observational-memory/index.d.ts.map +1 -1
  38. package/dist/processors/observational-memory/message-utils.d.ts +69 -0
  39. package/dist/processors/observational-memory/message-utils.d.ts.map +1 -0
  40. package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts +33 -0
  41. package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -0
  42. package/dist/processors/observational-memory/observation-strategies/base.d.ts +102 -0
  43. package/dist/processors/observational-memory/observation-strategies/base.d.ts.map +1 -0
  44. package/dist/processors/observational-memory/observation-strategies/index.d.ts +7 -0
  45. package/dist/processors/observational-memory/observation-strategies/index.d.ts.map +1 -0
  46. package/dist/processors/observational-memory/observation-strategies/resource-scoped.d.ts +39 -0
  47. package/dist/processors/observational-memory/observation-strategies/resource-scoped.d.ts.map +1 -0
  48. package/dist/processors/observational-memory/observation-strategies/sync.d.ts +35 -0
  49. package/dist/processors/observational-memory/observation-strategies/sync.d.ts.map +1 -0
  50. package/dist/processors/observational-memory/observation-strategies/types.d.ts +55 -0
  51. package/dist/processors/observational-memory/observation-strategies/types.d.ts.map +1 -0
  52. package/dist/processors/observational-memory/observation-turn/index.d.ts +4 -0
  53. package/dist/processors/observational-memory/observation-turn/index.d.ts.map +1 -0
  54. package/dist/processors/observational-memory/observation-turn/step.d.ts +34 -0
  55. package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -0
  56. package/dist/processors/observational-memory/observation-turn/turn.d.ts +84 -0
  57. package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -0
  58. package/dist/processors/observational-memory/observation-turn/types.d.ts +38 -0
  59. package/dist/processors/observational-memory/observation-turn/types.d.ts.map +1 -0
  60. package/dist/processors/observational-memory/observational-memory.d.ts +388 -553
  61. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  62. package/dist/processors/observational-memory/observer-runner.d.ts +65 -0
  63. package/dist/processors/observational-memory/observer-runner.d.ts.map +1 -0
  64. package/dist/processors/observational-memory/processor.d.ts +70 -0
  65. package/dist/processors/observational-memory/processor.d.ts.map +1 -0
  66. package/dist/processors/observational-memory/reflector-runner.d.ts +95 -0
  67. package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -0
  68. package/dist/processors/observational-memory/types.d.ts +157 -0
  69. package/dist/processors/observational-memory/types.d.ts.map +1 -1
  70. package/package.json +4 -4
  71. package/dist/chunk-HSOEY7M2.cjs.map +0 -1
  72. package/dist/chunk-K2NLYL2O.js.map +0 -1
  73. package/dist/observational-memory-NMQ7URIP.js +0 -3
@@ -0,0 +1,3 @@
1
+ export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTINUATION_HINT, OBSERVATION_RETRIEVAL_INSTRUCTIONS } from './chunk-LSJJAJAF.js';
2
+ //# sourceMappingURL=constants-BDOITAO3.js.map
3
+ //# sourceMappingURL=constants-BDOITAO3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"constants-BDOITAO3.js"}
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ var chunkD4J4XPGM_cjs = require('./chunk-D4J4XPGM.cjs');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, "OBSERVATIONAL_MEMORY_DEFAULTS", {
8
+ enumerable: true,
9
+ get: function () { return chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS; }
10
+ });
11
+ Object.defineProperty(exports, "OBSERVATION_CONTEXT_INSTRUCTIONS", {
12
+ enumerable: true,
13
+ get: function () { return chunkD4J4XPGM_cjs.OBSERVATION_CONTEXT_INSTRUCTIONS; }
14
+ });
15
+ Object.defineProperty(exports, "OBSERVATION_CONTEXT_PROMPT", {
16
+ enumerable: true,
17
+ get: function () { return chunkD4J4XPGM_cjs.OBSERVATION_CONTEXT_PROMPT; }
18
+ });
19
+ Object.defineProperty(exports, "OBSERVATION_CONTINUATION_HINT", {
20
+ enumerable: true,
21
+ get: function () { return chunkD4J4XPGM_cjs.OBSERVATION_CONTINUATION_HINT; }
22
+ });
23
+ Object.defineProperty(exports, "OBSERVATION_RETRIEVAL_INSTRUCTIONS", {
24
+ enumerable: true,
25
+ get: function () { return chunkD4J4XPGM_cjs.OBSERVATION_RETRIEVAL_INSTRUCTIONS; }
26
+ });
27
+ //# sourceMappingURL=constants-HXOCZPB7.cjs.map
28
+ //# sourceMappingURL=constants-HXOCZPB7.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"constants-HXOCZPB7.cjs"}
@@ -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.10.1-alpha.0"
6
+ version: "1.10.1-alpha.2"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,131 +1,136 @@
1
1
  {
2
- "version": "1.10.1-alpha.0",
2
+ "version": "1.10.1-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-K2NLYL2O.js",
8
- "line": 343
9
- },
10
- "OBSERVATIONAL_MEMORY_DEFAULTS": {
11
- "types": "dist/processors/index.d.ts",
12
- "implementation": "dist/chunk-K2NLYL2O.js"
13
- },
14
- "OBSERVATION_CONTEXT_INSTRUCTIONS": {
15
- "types": "dist/processors/index.d.ts",
16
- "implementation": "dist/chunk-K2NLYL2O.js"
17
- },
18
- "OBSERVATION_CONTEXT_PROMPT": {
19
- "types": "dist/processors/index.d.ts",
20
- "implementation": "dist/chunk-K2NLYL2O.js"
21
- },
22
- "OBSERVATION_CONTINUATION_HINT": {
23
- "types": "dist/processors/index.d.ts",
24
- "implementation": "dist/chunk-K2NLYL2O.js"
7
+ "implementation": "dist/chunk-2QSOQQPM.js",
8
+ "line": 664
25
9
  },
26
10
  "OBSERVER_SYSTEM_PROMPT": {
27
11
  "types": "dist/processors/index.d.ts",
28
- "implementation": "dist/chunk-K2NLYL2O.js"
12
+ "implementation": "dist/chunk-2QSOQQPM.js"
29
13
  },
30
14
  "ObservationalMemory": {
31
15
  "types": "dist/processors/index.d.ts",
32
- "implementation": "dist/chunk-K2NLYL2O.js",
33
- "line": 3509
16
+ "implementation": "dist/chunk-2QSOQQPM.js",
17
+ "line": 5516
18
+ },
19
+ "ObservationalMemoryProcessor": {
20
+ "types": "dist/processors/index.d.ts",
21
+ "implementation": "dist/chunk-2QSOQQPM.js",
22
+ "line": 7858
34
23
  },
35
24
  "TokenCounter": {
36
25
  "types": "dist/processors/index.d.ts",
37
- "implementation": "dist/chunk-K2NLYL2O.js",
38
- "line": 2936
26
+ "implementation": "dist/chunk-2QSOQQPM.js",
27
+ "line": 5068
39
28
  },
40
29
  "buildObserverPrompt": {
41
30
  "types": "dist/processors/index.d.ts",
42
- "implementation": "dist/chunk-K2NLYL2O.js",
43
- "line": 1519
31
+ "implementation": "dist/chunk-2QSOQQPM.js",
32
+ "line": 3227
44
33
  },
45
34
  "buildObserverSystemPrompt": {
46
35
  "types": "dist/processors/index.d.ts",
47
- "implementation": "dist/chunk-K2NLYL2O.js",
48
- "line": 986
36
+ "implementation": "dist/chunk-2QSOQQPM.js",
37
+ "line": 2701
49
38
  },
50
39
  "combineObservationGroupRanges": {
51
40
  "types": "dist/processors/index.d.ts",
52
- "implementation": "dist/chunk-K2NLYL2O.js",
53
- "line": 432
41
+ "implementation": "dist/chunk-2QSOQQPM.js",
42
+ "line": 753
54
43
  },
55
44
  "deriveObservationGroupProvenance": {
56
45
  "types": "dist/processors/index.d.ts",
57
- "implementation": "dist/chunk-K2NLYL2O.js",
58
- "line": 459
46
+ "implementation": "dist/chunk-2QSOQQPM.js",
47
+ "line": 780
59
48
  },
60
49
  "extractCurrentTask": {
61
50
  "types": "dist/processors/index.d.ts",
62
- "implementation": "dist/chunk-K2NLYL2O.js",
63
- "line": 1633
51
+ "implementation": "dist/chunk-2QSOQQPM.js",
52
+ "line": 3341
64
53
  },
65
54
  "formatMessagesForObserver": {
66
55
  "types": "dist/processors/index.d.ts",
67
- "implementation": "dist/chunk-K2NLYL2O.js",
68
- "line": 1252
56
+ "implementation": "dist/chunk-2QSOQQPM.js",
57
+ "line": 2967
69
58
  },
70
59
  "getObservationsAsOf": {
71
60
  "types": "dist/processors/index.d.ts",
72
- "implementation": "dist/chunk-K2NLYL2O.js",
73
- "line": 7811
61
+ "implementation": "dist/chunk-2QSOQQPM.js",
62
+ "line": 8013
74
63
  },
75
64
  "hasCurrentTaskSection": {
76
65
  "types": "dist/processors/index.d.ts",
77
- "implementation": "dist/chunk-K2NLYL2O.js",
78
- "line": 1621
66
+ "implementation": "dist/chunk-2QSOQQPM.js",
67
+ "line": 3329
79
68
  },
80
69
  "injectAnchorIds": {
81
70
  "types": "dist/processors/index.d.ts",
82
- "implementation": "dist/chunk-K2NLYL2O.js",
83
- "line": 543
71
+ "implementation": "dist/chunk-2QSOQQPM.js",
72
+ "line": 2258
84
73
  },
85
74
  "optimizeObservationsForContext": {
86
75
  "types": "dist/processors/index.d.ts",
87
- "implementation": "dist/chunk-K2NLYL2O.js",
88
- "line": 1644
76
+ "implementation": "dist/chunk-2QSOQQPM.js",
77
+ "line": 3352
89
78
  },
90
79
  "parseAnchorId": {
91
80
  "types": "dist/processors/index.d.ts",
92
- "implementation": "dist/chunk-K2NLYL2O.js",
93
- "line": 516
81
+ "implementation": "dist/chunk-2QSOQQPM.js",
82
+ "line": 2231
94
83
  },
95
84
  "parseObservationGroups": {
96
85
  "types": "dist/processors/index.d.ts",
97
- "implementation": "dist/chunk-K2NLYL2O.js",
98
- "line": 404
86
+ "implementation": "dist/chunk-2QSOQQPM.js",
87
+ "line": 725
99
88
  },
100
89
  "parseObserverOutput": {
101
90
  "types": "dist/processors/index.d.ts",
102
- "implementation": "dist/chunk-K2NLYL2O.js",
103
- "line": 1529
91
+ "implementation": "dist/chunk-2QSOQQPM.js",
92
+ "line": 3237
104
93
  },
105
94
  "reconcileObservationGroupsFromReflection": {
106
95
  "types": "dist/processors/index.d.ts",
107
- "implementation": "dist/chunk-K2NLYL2O.js",
108
- "line": 486
96
+ "implementation": "dist/chunk-2QSOQQPM.js",
97
+ "line": 807
109
98
  },
110
99
  "renderObservationGroupsForReflection": {
111
100
  "types": "dist/processors/index.d.ts",
112
- "implementation": "dist/chunk-K2NLYL2O.js",
113
- "line": 439
101
+ "implementation": "dist/chunk-2QSOQQPM.js",
102
+ "line": 760
114
103
  },
115
104
  "stripEphemeralAnchorIds": {
116
105
  "types": "dist/processors/index.d.ts",
117
- "implementation": "dist/chunk-K2NLYL2O.js",
118
- "line": 573
106
+ "implementation": "dist/chunk-2QSOQQPM.js",
107
+ "line": 2288
119
108
  },
120
109
  "stripObservationGroups": {
121
110
  "types": "dist/processors/index.d.ts",
122
- "implementation": "dist/chunk-K2NLYL2O.js",
123
- "line": 426
111
+ "implementation": "dist/chunk-2QSOQQPM.js",
112
+ "line": 747
124
113
  },
125
114
  "wrapInObservationGroup": {
126
115
  "types": "dist/processors/index.d.ts",
127
- "implementation": "dist/chunk-K2NLYL2O.js",
128
- "line": 397
116
+ "implementation": "dist/chunk-2QSOQQPM.js",
117
+ "line": 718
118
+ },
119
+ "OBSERVATIONAL_MEMORY_DEFAULTS": {
120
+ "types": "dist/processors/index.d.ts",
121
+ "implementation": "dist/chunk-LSJJAJAF.js"
122
+ },
123
+ "OBSERVATION_CONTEXT_INSTRUCTIONS": {
124
+ "types": "dist/processors/index.d.ts",
125
+ "implementation": "dist/chunk-LSJJAJAF.js"
126
+ },
127
+ "OBSERVATION_CONTEXT_PROMPT": {
128
+ "types": "dist/processors/index.d.ts",
129
+ "implementation": "dist/chunk-LSJJAJAF.js"
130
+ },
131
+ "OBSERVATION_CONTINUATION_HINT": {
132
+ "types": "dist/processors/index.d.ts",
133
+ "implementation": "dist/chunk-LSJJAJAF.js"
129
134
  },
130
135
  "extractWorkingMemoryContent": {
131
136
  "types": "dist/index.d.ts",
@@ -156,7 +161,8 @@
156
161
  "processors": {
157
162
  "index": "dist/processors/index.js",
158
163
  "chunks": [
159
- "chunk-K2NLYL2O.js"
164
+ "chunk-2QSOQQPM.js",
165
+ "chunk-LSJJAJAF.js"
160
166
  ]
161
167
  }
162
168
  }
@@ -150,17 +150,19 @@ const memory = new Memory({
150
150
  observation: {
151
151
  model: new ModelByInputTokens({
152
152
  upTo: {
153
- 10_000: 'google/gemini-2.5-flash', // Fast and cheap for small inputs
154
- 40_000: 'openai/gpt-4o', // Stronger for medium inputs
155
- 1_000_000: 'openai/gpt-4.5', // Most capable for very large inputs
153
+ // Faster, cheaper models for smaller inputs; stronger models for larger contexts
154
+ 5_000: 'openrouter/mistralai/ministral-8b-2512',
155
+ 20_000: 'openrouter/mistralai/mistral-small-2603',
156
+ 40_000: 'openai/gpt-5.4-mini',
157
+ 1_000_000: 'google/gemini-3.1-flash-lite-preview',
156
158
  },
157
159
  }),
158
160
  },
159
161
  reflection: {
160
162
  model: new ModelByInputTokens({
161
163
  upTo: {
162
- 20_000: 'google/gemini-2.5-flash',
163
- 80_000: 'openai/gpt-4o',
164
+ 20_000: 'openai/gpt-5.4-mini',
165
+ 100_000: 'google/gemini-2.5-flash',
164
166
  },
165
167
  }),
166
168
  },
@@ -632,8 +632,8 @@ import { ModelByInputTokens } from '@mastra/memory'
632
632
  const selector = new ModelByInputTokens({
633
633
  upTo: {
634
634
  10_000: 'google/gemini-2.5-flash', // Fast for small inputs
635
- 40_000: 'openai/gpt-4o', // Stronger for medium inputs
636
- 1_000_000: 'openai/gpt-4.5', // Most capable for large inputs
635
+ 40_000: 'openai/gpt-5.4-mini', // Stronger for medium inputs
636
+ 1_000_000: 'openai/gpt-5.4', // Most capable for large inputs
637
637
  },
638
638
  })
639
639
  ```
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 chunkHSOEY7M2_cjs = require('./chunk-HSOEY7M2.cjs');
5
+ var chunkNS47X3OB_cjs = require('./chunk-NS47X3OB.cjs');
6
6
  var v3 = require('zod/v3');
7
7
  var zod = require('zod');
8
8
  var z4 = require('zod/v4');
@@ -15503,7 +15503,7 @@ function formatTimestamp(date) {
15503
15503
  }
15504
15504
  function truncateByTokens(text4, maxTokens, hint) {
15505
15505
  if (tokenx.estimateTokenCount(text4) <= maxTokens) return { text: text4, wasTruncated: false };
15506
- const truncated = chunkHSOEY7M2_cjs.truncateStringByTokens(text4, maxTokens);
15506
+ const truncated = chunkNS47X3OB_cjs.truncateStringByTokens(text4, maxTokens);
15507
15507
  const suffix = hint ? ` [${hint} for more]` : "";
15508
15508
  return { text: truncated + suffix, wasTruncated: true };
15509
15509
  }
@@ -15536,11 +15536,11 @@ function formatMessageParts(msg, detail) {
15536
15536
  } else if (partType === "tool-invocation") {
15537
15537
  const inv = part.toolInvocation;
15538
15538
  if (inv.state === "result") {
15539
- const { value: resultValue } = chunkHSOEY7M2_cjs.resolveToolResultValue(
15539
+ const { value: resultValue } = chunkNS47X3OB_cjs.resolveToolResultValue(
15540
15540
  part,
15541
15541
  inv.result
15542
15542
  );
15543
- const resultStr = chunkHSOEY7M2_cjs.formatToolResultForObserver(resultValue, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
15543
+ const resultStr = chunkNS47X3OB_cjs.formatToolResultForObserver(resultValue, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
15544
15544
  const fullText = `[Tool Result: ${inv.toolName}]
15545
15545
  ${resultStr}`;
15546
15546
  parts.push(makePart(msg, i, "tool-result", fullText, detail));
@@ -15603,7 +15603,7 @@ function renderFormattedParts(parts, timestamps, options) {
15603
15603
  const text4 = buildRenderedText(parts, timestamps);
15604
15604
  let totalTokens = tokenx.estimateTokenCount(text4);
15605
15605
  if (totalTokens > options.maxTokens) {
15606
- const truncated = chunkHSOEY7M2_cjs.truncateStringByTokens(text4, options.maxTokens);
15606
+ const truncated = chunkNS47X3OB_cjs.truncateStringByTokens(text4, options.maxTokens);
15607
15607
  return { text: truncated, truncated: true, tokenOffset: totalTokens - options.maxTokens };
15608
15608
  }
15609
15609
  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));
@@ -15636,7 +15636,7 @@ function renderFormattedParts(parts, timestamps, options) {
15636
15636
  if (expandedTokens <= options.maxTokens) {
15637
15637
  return { text: expanded, truncated: false, tokenOffset: 0 };
15638
15638
  }
15639
- const hardTruncated = chunkHSOEY7M2_cjs.truncateStringByTokens(expanded, options.maxTokens);
15639
+ const hardTruncated = chunkNS47X3OB_cjs.truncateStringByTokens(expanded, options.maxTokens);
15640
15640
  return { text: hardTruncated, truncated: true, tokenOffset: expandedTokens - options.maxTokens };
15641
15641
  }
15642
15642
  async function recallPart({
@@ -15671,7 +15671,7 @@ async function recallPart({
15671
15671
  `Part index ${partIndex} not found in message ${cursor}. Available indices: ${allParts.map((p) => p.partIndex).join(", ")}`
15672
15672
  );
15673
15673
  }
15674
- const truncatedText = chunkHSOEY7M2_cjs.truncateStringByTokens(target.text, maxTokens);
15674
+ const truncatedText = chunkNS47X3OB_cjs.truncateStringByTokens(target.text, maxTokens);
15675
15675
  const wasTruncated = truncatedText !== target.text;
15676
15676
  return {
15677
15677
  text: truncatedText,
@@ -16092,6 +16092,14 @@ var DEFAULT_MESSAGE_RANGE = { before: 1, after: 1 };
16092
16092
  var DEFAULT_TOP_K = 4;
16093
16093
  var VECTOR_DELETE_BATCH_SIZE = 100;
16094
16094
  var Memory = class extends memory.MastraMemory {
16095
+ _omEngine;
16096
+ /** The shared ObservationalMemory engine. Lazily created on first access. */
16097
+ get omEngine() {
16098
+ if (!this._omEngine) {
16099
+ this._omEngine = this._initOMEngine();
16100
+ }
16101
+ return this._omEngine;
16102
+ }
16095
16103
  constructor(config = {}) {
16096
16104
  super({ name: "Memory", ...config });
16097
16105
  const mergedConfig = this.getMergedThreadConfig({
@@ -16732,6 +16740,179 @@ ${workingMemory}`;
16732
16740
  data: workingMemoryData
16733
16741
  });
16734
16742
  }
16743
+ /**
16744
+ * Get everything needed for an LLM call in one shot.
16745
+ *
16746
+ * Assembles the system message (observations + working memory), loads
16747
+ * unobserved messages from storage, and returns them ready to use.
16748
+ *
16749
+ * @example
16750
+ * ```ts
16751
+ * const ctx = await memory.getContext({ threadId });
16752
+ * const result = await generateText({
16753
+ * model: openai('gpt-4o'),
16754
+ * system: ctx.systemMessage,
16755
+ * messages: ctx.messages.map(toAiSdkMessage),
16756
+ * });
16757
+ * ```
16758
+ */
16759
+ async getContext(opts) {
16760
+ const { threadId, resourceId, memoryConfig } = opts;
16761
+ const config = this.getMergedThreadConfig(memoryConfig);
16762
+ const memoryStore = await this.getMemoryStore();
16763
+ const systemParts = [];
16764
+ let hasObservations = false;
16765
+ let omRecord = null;
16766
+ let continuationMessage;
16767
+ let otherThreadsContext;
16768
+ const omEngine = await this.omEngine;
16769
+ if (omEngine) {
16770
+ omRecord = await omEngine.getRecord(threadId, resourceId);
16771
+ if (omRecord?.activeObservations) {
16772
+ hasObservations = true;
16773
+ if (omEngine.scope === "resource" && resourceId) {
16774
+ otherThreadsContext = await omEngine.getOtherThreadsContext(resourceId, threadId);
16775
+ }
16776
+ const obsSystemMessage = await omEngine.buildContextSystemMessage({
16777
+ threadId,
16778
+ resourceId,
16779
+ record: omRecord,
16780
+ unobservedContextBlocks: otherThreadsContext
16781
+ });
16782
+ if (obsSystemMessage) {
16783
+ systemParts.push(obsSystemMessage);
16784
+ }
16785
+ const { OBSERVATION_CONTINUATION_HINT } = await import('./constants-HXOCZPB7.cjs');
16786
+ continuationMessage = {
16787
+ id: "om-continuation",
16788
+ role: "user",
16789
+ createdAt: /* @__PURE__ */ new Date(0),
16790
+ content: {
16791
+ format: 2,
16792
+ parts: [
16793
+ {
16794
+ type: "text",
16795
+ text: `<system-reminder>${OBSERVATION_CONTINUATION_HINT}</system-reminder>`
16796
+ }
16797
+ ]
16798
+ },
16799
+ threadId,
16800
+ resourceId
16801
+ };
16802
+ }
16803
+ }
16804
+ const workingMemoryMessage = await this.getSystemMessage({ threadId, resourceId, memoryConfig: config });
16805
+ if (workingMemoryMessage) {
16806
+ systemParts.push(workingMemoryMessage);
16807
+ }
16808
+ let messages;
16809
+ if (omEngine && omRecord) {
16810
+ const dateFilter = omRecord.lastObservedAt ? { dateRange: { start: new Date(new Date(omRecord.lastObservedAt).getTime() + 1) } } : void 0;
16811
+ if (omEngine.scope === "resource" && resourceId) {
16812
+ const result = await memoryStore.listMessagesByResourceId({
16813
+ resourceId,
16814
+ orderBy: { field: "createdAt", direction: "ASC" },
16815
+ perPage: false,
16816
+ filter: dateFilter
16817
+ });
16818
+ messages = result.messages;
16819
+ } else {
16820
+ const result = await memoryStore.listMessages({
16821
+ threadId,
16822
+ orderBy: { field: "createdAt", direction: "ASC" },
16823
+ perPage: false,
16824
+ filter: dateFilter
16825
+ });
16826
+ messages = result.messages;
16827
+ }
16828
+ } else {
16829
+ const lastMessages = config.lastMessages;
16830
+ if (lastMessages === false) {
16831
+ messages = [];
16832
+ } else {
16833
+ const result = await memoryStore.listMessages({
16834
+ threadId,
16835
+ resourceId,
16836
+ orderBy: { field: "createdAt", direction: "DESC" },
16837
+ perPage: typeof lastMessages === "number" ? lastMessages : void 0
16838
+ });
16839
+ messages = result.messages.reverse();
16840
+ }
16841
+ }
16842
+ return {
16843
+ systemMessage: systemParts.length > 0 ? systemParts.join("\n\n") : void 0,
16844
+ messages,
16845
+ hasObservations,
16846
+ omRecord,
16847
+ continuationMessage,
16848
+ otherThreadsContext
16849
+ };
16850
+ }
16851
+ /**
16852
+ * Raw message upsert — persist messages to storage without embedding or working memory processing.
16853
+ * Used by the processor to save sealed messages before firing a background buffer operation.
16854
+ */
16855
+ async persistMessages(messages) {
16856
+ if (messages.length === 0) return;
16857
+ const memoryStore = await this.getMemoryStore();
16858
+ await memoryStore.saveMessages({ messages });
16859
+ }
16860
+ /**
16861
+ * One-time initialization of the shared ObservationalMemory engine.
16862
+ * Called lazily by the `omEngine` getter on first access.
16863
+ */
16864
+ async _initOMEngine() {
16865
+ const omConfig = normalizeObservationalMemoryConfig(this.threadConfig.observationalMemory);
16866
+ if (!omConfig) return null;
16867
+ const memoryStore = await this.storage.getStore("memory");
16868
+ if (!memoryStore || !memoryStore.supportsObservationalMemory) return null;
16869
+ const coreSupportsOM = features.coreFeatures.has("observationalMemory");
16870
+ if (!coreSupportsOM) {
16871
+ throw new Error(
16872
+ "Observational memory is enabled but the installed version of @mastra/core does not support it. Please upgrade @mastra/core to a version that includes observational memory support."
16873
+ );
16874
+ }
16875
+ if (omConfig.observation?.bufferTokens !== false && !features.coreFeatures.has("asyncBuffering")) {
16876
+ throw new Error(
16877
+ "Observational memory async buffering is enabled by default but the installed version of @mastra/core does not support it. Either upgrade @mastra/core, @mastra/memory, and your storage adapter (@mastra/libsql, @mastra/pg, or @mastra/mongodb) to the latest version, or explicitly disable async buffering by setting `observation: { bufferTokens: false }` in your observationalMemory config."
16878
+ );
16879
+ }
16880
+ if (!features.coreFeatures.has("request-response-id-rotation")) {
16881
+ throw new Error(
16882
+ "Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version."
16883
+ );
16884
+ }
16885
+ const { ObservationalMemory: OMClass } = await import('./observational-memory-I5UTOG63.cjs');
16886
+ return new OMClass({
16887
+ storage: memoryStore,
16888
+ scope: omConfig.scope,
16889
+ retrieval: omConfig.retrieval,
16890
+ shareTokenBudget: omConfig.shareTokenBudget,
16891
+ model: omConfig.model,
16892
+ observation: omConfig.observation ? {
16893
+ model: omConfig.observation.model,
16894
+ messageTokens: omConfig.observation.messageTokens,
16895
+ modelSettings: omConfig.observation.modelSettings,
16896
+ maxTokensPerBatch: omConfig.observation.maxTokensPerBatch,
16897
+ providerOptions: omConfig.observation.providerOptions,
16898
+ bufferTokens: omConfig.observation.bufferTokens,
16899
+ bufferActivation: omConfig.observation.bufferActivation,
16900
+ blockAfter: omConfig.observation.blockAfter,
16901
+ previousObserverTokens: omConfig.observation.previousObserverTokens,
16902
+ instruction: omConfig.observation.instruction,
16903
+ threadTitle: omConfig.observation.threadTitle
16904
+ } : void 0,
16905
+ reflection: omConfig.reflection ? {
16906
+ model: omConfig.reflection.model,
16907
+ observationTokens: omConfig.reflection.observationTokens,
16908
+ modelSettings: omConfig.reflection.modelSettings,
16909
+ providerOptions: omConfig.reflection.providerOptions,
16910
+ bufferActivation: omConfig.reflection.bufferActivation,
16911
+ blockAfter: omConfig.reflection.blockAfter,
16912
+ instruction: omConfig.reflection.instruction
16913
+ } : void 0
16914
+ });
16915
+ }
16735
16916
  defaultWorkingMemoryTemplate = `
16736
16917
  # User Information
16737
16918
  - **First Name**:
@@ -17393,91 +17574,39 @@ Notes:
17393
17574
  return processors;
17394
17575
  }
17395
17576
  /**
17396
- * Creates an ObservationalMemory processor instance if configured and not already present.
17397
- * A new instance is created per call processorStates (e.g., sealedIds) are shared
17398
- * via the ProcessorRunner's state map keyed by processor ID, not by instance identity.
17577
+ * Creates an ObservationalMemory processor wrapping the shared engine.
17578
+ * Returns null if OM is not configured, not supported, or already present
17579
+ * in the user's configured processors.
17399
17580
  */
17400
17581
  async createOMProcessor(configuredProcessors = [], context2) {
17401
17582
  const hasObservationalMemory = configuredProcessors.some(
17402
17583
  (p) => !("workflow" in p) && p.id === "observational-memory"
17403
17584
  );
17404
- const memoryContext = context2?.get("MastraMemory");
17405
- const runtimeMemoryConfig = memoryContext?.memoryConfig;
17406
- const effectiveConfig = runtimeMemoryConfig ? this.getMergedThreadConfig({
17407
- ...runtimeMemoryConfig,
17408
- observationalMemory: runtimeMemoryConfig.observationalMemory
17585
+ if (hasObservationalMemory) return null;
17586
+ const runtimeMemory = context2?.get("MastraMemory");
17587
+ const runtimeObservationalMemory = normalizeObservationalMemoryConfig(
17588
+ runtimeMemory?.memoryConfig?.observationalMemory
17589
+ );
17590
+ const threadConfig = runtimeObservationalMemory ? this.getMergedThreadConfig({
17591
+ ...runtimeMemory?.memoryConfig,
17592
+ observationalMemory: runtimeObservationalMemory
17409
17593
  }) : this.threadConfig;
17410
- const omConfig = normalizeObservationalMemoryConfig(effectiveConfig.observationalMemory);
17411
- if (!omConfig || hasObservationalMemory) {
17412
- return null;
17413
- }
17414
- const coreSupportsOM = features.coreFeatures.has("observationalMemory");
17415
- if (!coreSupportsOM) {
17416
- throw new Error(
17417
- "Observational memory is enabled but the installed version of @mastra/core does not support it. Please upgrade @mastra/core to a version that includes observational memory support."
17418
- );
17419
- }
17420
- const memoryStore = await this.storage.getStore("memory");
17421
- if (!memoryStore) {
17422
- throw new Error(
17423
- "Using Mastra Memory observational memory requires a storage adapter but no attached adapter was detected."
17424
- );
17425
- }
17426
- if (!memoryStore.supportsObservationalMemory) {
17427
- throw new Error(
17428
- `Observational memory is enabled but the storage adapter (${memoryStore.constructor.name}) does not support it. If you're using @mastra/libsql, @mastra/pg, or @mastra/mongodb, upgrade to the latest version. Otherwise, use one of those adapters or disable observational memory.`
17429
- );
17430
- }
17431
- if (omConfig.observation?.bufferTokens !== false && !features.coreFeatures.has("asyncBuffering")) {
17432
- throw new Error(
17433
- "Observational memory async buffering is enabled by default but the installed version of @mastra/core does not support it. Either upgrade @mastra/core, @mastra/memory, and your storage adapter (@mastra/libsql, @mastra/pg, or @mastra/mongodb) to the latest version, or explicitly disable async buffering by setting `observation: { bufferTokens: false }` in your observationalMemory config."
17434
- );
17435
- }
17436
- if (!features.coreFeatures.has("request-response-id-rotation")) {
17437
- throw new Error(
17438
- "Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version."
17439
- );
17440
- }
17441
- const { ObservationalMemory } = await import('./observational-memory-DJMF2UNC.cjs');
17442
- return new ObservationalMemory({
17443
- storage: memoryStore,
17444
- scope: omConfig.scope,
17445
- retrieval: omConfig.retrieval,
17446
- shareTokenBudget: omConfig.shareTokenBudget,
17447
- model: omConfig.model,
17448
- observation: omConfig.observation ? {
17449
- model: omConfig.observation.model,
17450
- messageTokens: omConfig.observation.messageTokens,
17451
- modelSettings: omConfig.observation.modelSettings,
17452
- maxTokensPerBatch: omConfig.observation.maxTokensPerBatch,
17453
- providerOptions: omConfig.observation.providerOptions,
17454
- bufferTokens: omConfig.observation.bufferTokens,
17455
- bufferActivation: omConfig.observation.bufferActivation,
17456
- blockAfter: omConfig.observation.blockAfter,
17457
- previousObserverTokens: omConfig.observation.previousObserverTokens,
17458
- instruction: omConfig.observation.instruction,
17459
- threadTitle: omConfig.observation.threadTitle
17460
- } : void 0,
17461
- reflection: omConfig.reflection ? {
17462
- model: omConfig.reflection.model,
17463
- observationTokens: omConfig.reflection.observationTokens,
17464
- modelSettings: omConfig.reflection.modelSettings,
17465
- providerOptions: omConfig.reflection.providerOptions,
17466
- bufferActivation: omConfig.reflection.bufferActivation,
17467
- blockAfter: omConfig.reflection.blockAfter,
17468
- instruction: omConfig.reflection.instruction
17469
- } : void 0
17470
- });
17594
+ const effectiveConfig = normalizeObservationalMemoryConfig(threadConfig.observationalMemory);
17595
+ if (!effectiveConfig) return null;
17596
+ const engine = await this.omEngine;
17597
+ if (!engine) return null;
17598
+ const { ObservationalMemoryProcessor } = await import('./observational-memory-I5UTOG63.cjs');
17599
+ return new ObservationalMemoryProcessor(engine, this);
17471
17600
  }
17472
17601
  };
17473
17602
 
17474
17603
  Object.defineProperty(exports, "ModelByInputTokens", {
17475
17604
  enumerable: true,
17476
- get: function () { return chunkHSOEY7M2_cjs.ModelByInputTokens; }
17605
+ get: function () { return chunkNS47X3OB_cjs.ModelByInputTokens; }
17477
17606
  });
17478
17607
  Object.defineProperty(exports, "getObservationsAsOf", {
17479
17608
  enumerable: true,
17480
- get: function () { return chunkHSOEY7M2_cjs.getObservationsAsOf; }
17609
+ get: function () { return chunkNS47X3OB_cjs.getObservationsAsOf; }
17481
17610
  });
17482
17611
  Object.defineProperty(exports, "extractWorkingMemoryContent", {
17483
17612
  enumerable: true,