@mastra/memory 1.15.0 → 1.15.1-alpha.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.
@@ -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.15.0"
6
+ version: "1.15.1-alpha.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,119 +1,119 @@
1
1
  {
2
- "version": "1.15.0",
2
+ "version": "1.15.1-alpha.1",
3
3
  "package": "@mastra/memory",
4
4
  "exports": {
5
5
  "ModelByInputTokens": {
6
6
  "types": "dist/processors/index.d.ts",
7
- "implementation": "dist/chunk-42AZEBIK.js",
7
+ "implementation": "dist/chunk-HAEQMUD4.js",
8
8
  "line": 666
9
9
  },
10
10
  "OBSERVER_SYSTEM_PROMPT": {
11
11
  "types": "dist/processors/index.d.ts",
12
- "implementation": "dist/chunk-42AZEBIK.js"
12
+ "implementation": "dist/chunk-HAEQMUD4.js"
13
13
  },
14
14
  "ObservationalMemory": {
15
15
  "types": "dist/processors/index.d.ts",
16
- "implementation": "dist/chunk-42AZEBIK.js",
16
+ "implementation": "dist/chunk-HAEQMUD4.js",
17
17
  "line": 6230
18
18
  },
19
19
  "ObservationalMemoryProcessor": {
20
20
  "types": "dist/processors/index.d.ts",
21
- "implementation": "dist/chunk-42AZEBIK.js",
21
+ "implementation": "dist/chunk-HAEQMUD4.js",
22
22
  "line": 8629
23
23
  },
24
24
  "TokenCounter": {
25
25
  "types": "dist/processors/index.d.ts",
26
- "implementation": "dist/chunk-42AZEBIK.js",
26
+ "implementation": "dist/chunk-HAEQMUD4.js",
27
27
  "line": 5782
28
28
  },
29
29
  "buildObserverPrompt": {
30
30
  "types": "dist/processors/index.d.ts",
31
- "implementation": "dist/chunk-42AZEBIK.js",
31
+ "implementation": "dist/chunk-HAEQMUD4.js",
32
32
  "line": 3412
33
33
  },
34
34
  "buildObserverSystemPrompt": {
35
35
  "types": "dist/processors/index.d.ts",
36
- "implementation": "dist/chunk-42AZEBIK.js",
36
+ "implementation": "dist/chunk-HAEQMUD4.js",
37
37
  "line": 2811
38
38
  },
39
39
  "combineObservationGroupRanges": {
40
40
  "types": "dist/processors/index.d.ts",
41
- "implementation": "dist/chunk-42AZEBIK.js",
41
+ "implementation": "dist/chunk-HAEQMUD4.js",
42
42
  "line": 758
43
43
  },
44
44
  "deriveObservationGroupProvenance": {
45
45
  "types": "dist/processors/index.d.ts",
46
- "implementation": "dist/chunk-42AZEBIK.js",
46
+ "implementation": "dist/chunk-HAEQMUD4.js",
47
47
  "line": 792
48
48
  },
49
49
  "extractCurrentTask": {
50
50
  "types": "dist/processors/index.d.ts",
51
- "implementation": "dist/chunk-42AZEBIK.js",
51
+ "implementation": "dist/chunk-HAEQMUD4.js",
52
52
  "line": 3526
53
53
  },
54
54
  "formatMessagesForObserver": {
55
55
  "types": "dist/processors/index.d.ts",
56
- "implementation": "dist/chunk-42AZEBIK.js",
56
+ "implementation": "dist/chunk-HAEQMUD4.js",
57
57
  "line": 3138
58
58
  },
59
59
  "getObservationsAsOf": {
60
60
  "types": "dist/processors/index.d.ts",
61
- "implementation": "dist/chunk-42AZEBIK.js",
61
+ "implementation": "dist/chunk-HAEQMUD4.js",
62
62
  "line": 8814
63
63
  },
64
64
  "hasCurrentTaskSection": {
65
65
  "types": "dist/processors/index.d.ts",
66
- "implementation": "dist/chunk-42AZEBIK.js",
66
+ "implementation": "dist/chunk-HAEQMUD4.js",
67
67
  "line": 3514
68
68
  },
69
69
  "injectAnchorIds": {
70
70
  "types": "dist/processors/index.d.ts",
71
- "implementation": "dist/chunk-42AZEBIK.js",
71
+ "implementation": "dist/chunk-HAEQMUD4.js",
72
72
  "line": 2368
73
73
  },
74
74
  "optimizeObservationsForContext": {
75
75
  "types": "dist/processors/index.d.ts",
76
- "implementation": "dist/chunk-42AZEBIK.js",
76
+ "implementation": "dist/chunk-HAEQMUD4.js",
77
77
  "line": 3537
78
78
  },
79
79
  "parseAnchorId": {
80
80
  "types": "dist/processors/index.d.ts",
81
- "implementation": "dist/chunk-42AZEBIK.js",
81
+ "implementation": "dist/chunk-HAEQMUD4.js",
82
82
  "line": 2341
83
83
  },
84
84
  "parseObservationGroups": {
85
85
  "types": "dist/processors/index.d.ts",
86
- "implementation": "dist/chunk-42AZEBIK.js",
86
+ "implementation": "dist/chunk-HAEQMUD4.js",
87
87
  "line": 727
88
88
  },
89
89
  "parseObserverOutput": {
90
90
  "types": "dist/processors/index.d.ts",
91
- "implementation": "dist/chunk-42AZEBIK.js",
91
+ "implementation": "dist/chunk-HAEQMUD4.js",
92
92
  "line": 3422
93
93
  },
94
94
  "reconcileObservationGroupsFromReflection": {
95
95
  "types": "dist/processors/index.d.ts",
96
- "implementation": "dist/chunk-42AZEBIK.js",
96
+ "implementation": "dist/chunk-HAEQMUD4.js",
97
97
  "line": 816
98
98
  },
99
99
  "renderObservationGroupsForReflection": {
100
100
  "types": "dist/processors/index.d.ts",
101
- "implementation": "dist/chunk-42AZEBIK.js",
101
+ "implementation": "dist/chunk-HAEQMUD4.js",
102
102
  "line": 772
103
103
  },
104
104
  "stripEphemeralAnchorIds": {
105
105
  "types": "dist/processors/index.d.ts",
106
- "implementation": "dist/chunk-42AZEBIK.js",
106
+ "implementation": "dist/chunk-HAEQMUD4.js",
107
107
  "line": 2398
108
108
  },
109
109
  "stripObservationGroups": {
110
110
  "types": "dist/processors/index.d.ts",
111
- "implementation": "dist/chunk-42AZEBIK.js",
111
+ "implementation": "dist/chunk-HAEQMUD4.js",
112
112
  "line": 749
113
113
  },
114
114
  "wrapInObservationGroup": {
115
115
  "types": "dist/processors/index.d.ts",
116
- "implementation": "dist/chunk-42AZEBIK.js",
116
+ "implementation": "dist/chunk-HAEQMUD4.js",
117
117
  "line": 720
118
118
  },
119
119
  "OBSERVATIONAL_MEMORY_DEFAULTS": {
@@ -161,7 +161,7 @@
161
161
  "processors": {
162
162
  "index": "dist/processors/index.js",
163
163
  "chunks": [
164
- "chunk-42AZEBIK.js",
164
+ "chunk-HAEQMUD4.js",
165
165
  "chunk-LSJJAJAF.js"
166
166
  ]
167
167
  }
@@ -307,8 +307,8 @@ Both scenarios are safe - guardrails prevent inappropriate content from being pe
307
307
 
308
308
  ## Related documentation
309
309
 
310
- - [Processors](https://mastra.ai/docs/agents/processors) - General processor concepts and custom processor creation
311
- - [Guardrails](https://mastra.ai/docs/agents/guardrails) - Security and validation processors
312
- - [Memory Overview](https://mastra.ai/docs/memory/overview) - Memory types and configuration
310
+ - [Processors](https://mastra.ai/docs/agents/processors): General processor concepts and custom processor creation
311
+ - [Guardrails](https://mastra.ai/docs/agents/guardrails): Security and validation processors
312
+ - [Memory Overview](https://mastra.ai/docs/memory/overview): Memory types and configuration
313
313
 
314
314
  When creating custom processors avoid mutating the input `messages` array or its objects directly.
@@ -100,8 +100,8 @@ await agent.stream('Hello', {
100
100
 
101
101
  You can use this history in two ways:
102
102
 
103
- - **Automatic inclusion** - Mastra automatically fetches and includes recent messages in the context window. By default, it includes the last 10 messages, keeping agents grounded in the conversation. You can adjust this number with `lastMessages`, but in most cases you don't need to think about it.
104
- - [**Manual querying**](#querying) - For more control, use the `recall()` function to query threads and messages directly. This lets you choose exactly which memories are included in the context window, or fetch messages to render conversation history in your UI.
103
+ - **Automatic inclusion**: Mastra automatically fetches and includes recent messages in the context window. By default, it includes the last 10 messages, keeping agents grounded in the conversation. You can adjust this number with `lastMessages`, but in most cases you don't need to think about it.
104
+ - [**Manual querying**](#querying): For more control, use the `recall()` function to query threads and messages directly. This lets you choose exactly which memories are included in the context window, or fetch messages to render conversation history in your UI.
105
105
 
106
106
  > **Tip:** When memory is enabled, [Studio](https://mastra.ai/docs/studio/overview) uses message history to display past conversations in the chat sidebar.
107
107
 
@@ -157,7 +157,7 @@ With retrieval mode enabled, OM:
157
157
  - Registers a `recall` tool the agent can call to:
158
158
 
159
159
  - Page through the raw messages behind any observation group range
160
- - Search by semantic similarity (`mode: "search"` with a `query` string) requires `vector: true`
160
+ - Search by semantic similarity (`mode: "search"` with a `query` string); requires `vector: true`
161
161
  - List all threads (`mode: "threads"`), browse other threads (`threadId`), and search across all threads (default `scope: 'resource'`)
162
162
  - When `scope: 'thread'`: restrict browsing and search to the current thread only
163
163
 
@@ -118,8 +118,6 @@ export const agent = new Agent({
118
118
  })
119
119
  ```
120
120
 
121
- > **Warning:** Agent-level storage isn't supported when using [Mastra Cloud Store](https://mastra.ai/docs/mastra-cloud/deployment). If you use Mastra Cloud Store, configure storage on the Mastra instance instead. This limitation doesn't apply if you bring your own database.
122
-
123
121
  ## Threads and resources
124
122
 
125
123
  Mastra organizes conversations using two identifiers:
@@ -397,4 +397,4 @@ const response = await agent.generate('What do you know about me?', {
397
397
 
398
398
  - [Working memory with template](https://github.com/mastra-ai/mastra/tree/main/examples/memory-with-template)
399
399
  - [Working memory with schema](https://github.com/mastra-ai/mastra/tree/main/examples/memory-with-schema)
400
- - [Per-resource working memory](https://github.com/mastra-ai/mastra/tree/main/examples/memory-per-resource-example) - Complete example showing resource-scoped memory persistence
400
+ - [Per-resource working memory](https://github.com/mastra-ai/mastra/tree/main/examples/memory-per-resource-example): Complete example showing resource-scoped memory persistence
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 chunkWNLRMAHY_cjs = require('./chunk-WNLRMAHY.cjs');
5
+ var chunkOUMWCVQI_cjs = require('./chunk-OUMWCVQI.cjs');
6
6
  var v3 = require('zod/v3');
7
7
  var zod = require('zod');
8
8
  var z4 = require('zod/v4');
@@ -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 = chunkWNLRMAHY_cjs.truncateStringByTokens(text4, maxTokens);
15712
+ const truncated = chunkOUMWCVQI_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 } = chunkWNLRMAHY_cjs.resolveToolResultValue(
15764
+ const { value: resultValue } = chunkOUMWCVQI_cjs.resolveToolResultValue(
15765
15765
  part,
15766
15766
  inv.result
15767
15767
  );
15768
- const resultStr = chunkWNLRMAHY_cjs.formatToolResultForObserver(resultValue, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
15768
+ const resultStr = chunkOUMWCVQI_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 = chunkWNLRMAHY_cjs.formatToolResultForObserver(rawResult, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
15795
+ const resultStr = chunkOUMWCVQI_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 = chunkWNLRMAHY_cjs.truncateStringByTokens(text4, options.maxTokens);
15874
+ const truncated = chunkOUMWCVQI_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 = chunkWNLRMAHY_cjs.truncateStringByTokens(expanded, options.maxTokens);
15907
+ const hardTruncated = chunkOUMWCVQI_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 = chunkWNLRMAHY_cjs.truncateStringByTokens(fallbackText, maxTokens);
15958
+ const truncatedText2 = chunkOUMWCVQI_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 = chunkWNLRMAHY_cjs.truncateStringByTokens(target.text, maxTokens);
15973
+ const truncatedText = chunkOUMWCVQI_cjs.truncateStringByTokens(target.text, maxTokens);
15974
15974
  const wasTruncated = truncatedText !== target.text;
15975
15975
  return {
15976
15976
  text: truncatedText,
@@ -16453,6 +16453,25 @@ function deepMergeWorkingMemory(existing, update) {
16453
16453
  }
16454
16454
  return result;
16455
16455
  }
16456
+ function stripNullsFromOptional(value, schema) {
16457
+ if (Array.isArray(value)) {
16458
+ const itemSchema = schema.items ?? {};
16459
+ return value.map((item) => stripNullsFromOptional(item, itemSchema));
16460
+ }
16461
+ if (typeof value === "object" && value !== null) {
16462
+ const properties = schema.properties ?? {};
16463
+ const required = schema.required ?? [];
16464
+ const result = {};
16465
+ for (const [key, propertyValue] of Object.entries(value)) {
16466
+ if (propertyValue === null && !required.includes(key)) {
16467
+ continue;
16468
+ }
16469
+ result[key] = stripNullsFromOptional(propertyValue, properties[key] ?? {});
16470
+ }
16471
+ return result;
16472
+ }
16473
+ return value;
16474
+ }
16456
16475
  var updateWorkingMemoryTool = (memoryConfig) => {
16457
16476
  const schema$2 = memoryConfig?.workingMemory?.schema;
16458
16477
  let inputSchema = zod.z.object({
@@ -16462,7 +16481,7 @@ var updateWorkingMemoryTool = (memoryConfig) => {
16462
16481
  const standardSchema2 = schema$1.isStandardSchemaWithJSON(schema$2) ? schema$2 : schema$1.toStandardSchema(schema$2);
16463
16482
  const jsonSchema4 = schema.standardSchemaToJSONSchema(standardSchema2, { io: "input" });
16464
16483
  delete jsonSchema4.$schema;
16465
- inputSchema = schema$1.toStandardSchema({
16484
+ const wrappedSchema = schema$1.toStandardSchema({
16466
16485
  $schema: "http://json-schema.org/draft-07/schema#",
16467
16486
  type: "object",
16468
16487
  description: "The JSON formatted working memory content to store.",
@@ -16471,6 +16490,41 @@ var updateWorkingMemoryTool = (memoryConfig) => {
16471
16490
  },
16472
16491
  required: ["memory"]
16473
16492
  });
16493
+ inputSchema = {
16494
+ "~standard": {
16495
+ version: 1,
16496
+ vendor: "mastra",
16497
+ validate: (value) => {
16498
+ const wrappedResult = wrappedSchema["~standard"].validate(value);
16499
+ if (wrappedResult instanceof Promise) {
16500
+ return wrappedResult.then((result) => {
16501
+ if (!("issues" in result) || !result.issues) {
16502
+ return result;
16503
+ }
16504
+ if (!value || typeof value !== "object" || Array.isArray(value) || "memory" in value) {
16505
+ return result;
16506
+ }
16507
+ return wrappedSchema["~standard"].validate({
16508
+ memory: stripNullsFromOptional(value, jsonSchema4)
16509
+ });
16510
+ });
16511
+ }
16512
+ if (!("issues" in wrappedResult) || !wrappedResult.issues) {
16513
+ return wrappedResult;
16514
+ }
16515
+ if (!value || typeof value !== "object" || Array.isArray(value) || "memory" in value) {
16516
+ return wrappedResult;
16517
+ }
16518
+ return wrappedSchema["~standard"].validate({
16519
+ memory: stripNullsFromOptional(value, jsonSchema4)
16520
+ });
16521
+ },
16522
+ jsonSchema: {
16523
+ input: (props) => wrappedSchema["~standard"].jsonSchema.input(props),
16524
+ output: (props) => wrappedSchema["~standard"].jsonSchema.output(props)
16525
+ }
16526
+ }
16527
+ };
16474
16528
  }
16475
16529
  const usesMergeSemantics = Boolean(schema$2);
16476
16530
  const description = schema$2 ? `Update the working memory with new information. Data is merged with existing memory - only include fields you want to add or update. To preserve existing data, omit the field entirely. Arrays are replaced entirely when provided, so pass the complete array or omit it to keep the existing values.` : `Update the working memory with new information. Any data not included will be overwritten. Always pass data as string to the memory field. Never pass an object.`;
@@ -17547,7 +17601,7 @@ ${workingMemory}`;
17547
17601
  "Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version."
17548
17602
  );
17549
17603
  }
17550
- const { ObservationalMemory: OMClass } = await import('./observational-memory-3RE2HCRV.cjs');
17604
+ const { ObservationalMemory: OMClass } = await import('./observational-memory-TKXRH2LD.cjs');
17551
17605
  const onIndexObservations = this.hasRetrievalSearch(omConfig.retrieval) ? async (observation) => {
17552
17606
  await this.indexObservation(observation);
17553
17607
  } : void 0;
@@ -18470,18 +18524,18 @@ Notes:
18470
18524
  if (!effectiveConfig) return null;
18471
18525
  const engine = await this.omEngine;
18472
18526
  if (!engine) return null;
18473
- const { ObservationalMemoryProcessor } = await import('./observational-memory-3RE2HCRV.cjs');
18527
+ const { ObservationalMemoryProcessor } = await import('./observational-memory-TKXRH2LD.cjs');
18474
18528
  return new ObservationalMemoryProcessor(engine, this);
18475
18529
  }
18476
18530
  };
18477
18531
 
18478
18532
  Object.defineProperty(exports, "ModelByInputTokens", {
18479
18533
  enumerable: true,
18480
- get: function () { return chunkWNLRMAHY_cjs.ModelByInputTokens; }
18534
+ get: function () { return chunkOUMWCVQI_cjs.ModelByInputTokens; }
18481
18535
  });
18482
18536
  Object.defineProperty(exports, "getObservationsAsOf", {
18483
18537
  enumerable: true,
18484
- get: function () { return chunkWNLRMAHY_cjs.getObservationsAsOf; }
18538
+ get: function () { return chunkOUMWCVQI_cjs.getObservationsAsOf; }
18485
18539
  });
18486
18540
  Object.defineProperty(exports, "extractWorkingMemoryContent", {
18487
18541
  enumerable: true,