@mastra/memory 0.3.5-alpha.0 → 0.4.0-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.
@@ -1,29 +1,29 @@
1
1
 
2
- > @mastra/memory@0.3.5-alpha.0 build /home/runner/work/mastra/mastra/packages/memory
2
+ > @mastra/memory@0.4.0-alpha.1 build /home/runner/work/mastra/mastra/packages/memory
3
3
  > pnpm run check && tsup src/index.ts src/processors/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
4
4
 
5
5
 
6
- > @mastra/memory@0.3.5-alpha.0 check /home/runner/work/mastra/mastra/packages/memory
6
+ > @mastra/memory@0.4.0-alpha.1 check /home/runner/work/mastra/mastra/packages/memory
7
7
  > tsc --noEmit
8
8
 
9
9
  CLI Building entry: src/index.ts, src/processors/index.ts
10
10
  CLI Using tsconfig: tsconfig.json
11
11
  CLI tsup v8.4.0
12
12
  TSC Build start
13
- TSC ⚡️ Build success in 9856ms
13
+ TSC ⚡️ Build success in 9760ms
14
14
  DTS Build start
15
15
  CLI Target: es2022
16
16
  Analysis will use the bundled TypeScript version 5.8.3
17
17
  Writing package typings: /home/runner/work/mastra/mastra/packages/memory/dist/_tsup-dts-rollup.d.ts
18
18
  Analysis will use the bundled TypeScript version 5.8.3
19
19
  Writing package typings: /home/runner/work/mastra/mastra/packages/memory/dist/_tsup-dts-rollup.d.cts
20
- DTS ⚡️ Build success in 11835ms
20
+ DTS ⚡️ Build success in 11637ms
21
21
  CLI Cleaning output folder
22
22
  ESM Build start
23
23
  CJS Build start
24
- CJS dist/index.cjs 18.85 KB
24
+ CJS dist/index.cjs 19.00 KB
25
25
  CJS dist/processors/index.cjs 5.59 KB
26
- CJS ⚡️ Build success in 740ms
27
- ESM dist/index.js 18.68 KB
26
+ CJS ⚡️ Build success in 995ms
27
+ ESM dist/index.js 18.81 KB
28
28
  ESM dist/processors/index.js 5.38 KB
29
- ESM ⚡️ Build success in 740ms
29
+ ESM ⚡️ Build success in 995ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @mastra/memory
2
2
 
3
+ ## 0.4.0-alpha.1
4
+
5
+ ### Minor Changes
6
+
7
+ - 83da932: Move @mastra/core to peerdeps
8
+ - 0dcb9f0: Memory breaking changes: storage, vector, and embedder are now required. Working memory text streaming has been removed, only tool calling is supported for working memory updates now. Default settings have changed (lastMessages: 40->10, semanticRecall: true->false, threads.generateTitle: true->false)
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies [b3a3d63]
13
+ - Updated dependencies [344f453]
14
+ - Updated dependencies [0a3ae6d]
15
+ - Updated dependencies [95911be]
16
+ - Updated dependencies [5eb5a99]
17
+ - Updated dependencies [7e632c5]
18
+ - Updated dependencies [1e9fbfa]
19
+ - Updated dependencies [b2ae5aa]
20
+ - Updated dependencies [a7292b0]
21
+ - Updated dependencies [0dcb9f0]
22
+ - @mastra/core@0.10.0-alpha.1
23
+
3
24
  ## 0.3.5-alpha.0
4
25
 
5
26
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -82,6 +82,8 @@ function reorderToolCallsAndResults(messages) {
82
82
 
83
83
  // src/index.ts
84
84
  var CHARS_PER_TOKEN = 4;
85
+ var DEFAULT_MESSAGE_RANGE = { before: 2, after: 2 };
86
+ var DEFAULT_TOP_K = 2;
85
87
  var Memory = class extends memory.MastraMemory {
86
88
  constructor(config = {}) {
87
89
  super({ name: "Memory", ...config });
@@ -97,6 +99,7 @@ var Memory = class extends memory.MastraMemory {
97
99
  this.threadConfig = mergedConfig;
98
100
  }
99
101
  async validateThreadIsOwnedByResource(threadId, resourceId) {
102
+ await this.storage.init();
100
103
  const thread = await this.storage.getThreadById({ threadId });
101
104
  if (!thread) {
102
105
  throw new Error(`No thread found with id ${threadId}`);
@@ -121,8 +124,8 @@ var Memory = class extends memory.MastraMemory {
121
124
  threadConfig
122
125
  });
123
126
  const config = this.getMergedThreadConfig(threadConfig || {});
124
- const defaultRange = core.memoryDefaultOptions.semanticRecall.messageRange;
125
- const defaultTopK = core.memoryDefaultOptions.semanticRecall.topK;
127
+ const defaultRange = DEFAULT_MESSAGE_RANGE;
128
+ const defaultTopK = DEFAULT_TOP_K;
126
129
  const vectorConfig = typeof config?.semanticRecall === `boolean` ? {
127
130
  topK: defaultTopK,
128
131
  messageRange: defaultRange
@@ -153,6 +156,7 @@ var Memory = class extends memory.MastraMemory {
153
156
  })
154
157
  );
155
158
  }
159
+ await this.storage.init();
156
160
  const rawMessages = await this.storage.getMessages({
157
161
  threadId,
158
162
  selectBy: {
@@ -204,15 +208,18 @@ var Memory = class extends memory.MastraMemory {
204
208
  };
205
209
  }
206
210
  async getThreadById({ threadId }) {
211
+ await this.storage.init();
207
212
  return this.storage.getThreadById({ threadId });
208
213
  }
209
214
  async getThreadsByResourceId({ resourceId }) {
215
+ await this.storage.init();
210
216
  return this.storage.getThreadsByResourceId({ resourceId });
211
217
  }
212
218
  async saveThread({
213
219
  thread,
214
220
  memoryConfig
215
221
  }) {
222
+ await this.storage.init();
216
223
  const config = this.getMergedThreadConfig(memoryConfig || {});
217
224
  if (config.workingMemory?.enabled && !thread?.metadata?.workingMemory) {
218
225
  return this.storage.saveThread({
@@ -230,6 +237,7 @@ var Memory = class extends memory.MastraMemory {
230
237
  title,
231
238
  metadata
232
239
  }) {
240
+ await this.storage.init();
233
241
  return this.storage.updateThread({
234
242
  id,
235
243
  title,
@@ -237,6 +245,7 @@ var Memory = class extends memory.MastraMemory {
237
245
  });
238
246
  }
239
247
  async deleteThread(threadId) {
248
+ await this.storage.init();
240
249
  await this.storage.deleteThread({ threadId });
241
250
  }
242
251
  chunkText(text, tokenSize = 4096) {
@@ -293,6 +302,7 @@ var Memory = class extends memory.MastraMemory {
293
302
  messages,
294
303
  memoryConfig
295
304
  }) {
305
+ await this.storage.init();
296
306
  await this.saveWorkingMemory(messages);
297
307
  const updatedMessages = this.updateMessagesToHideWorkingMemory(messages);
298
308
  const config = this.getMergedThreadConfig(memoryConfig);
@@ -376,6 +386,7 @@ var Memory = class extends memory.MastraMemory {
376
386
  }
377
387
  async getWorkingMemory({ threadId }) {
378
388
  if (!this.threadConfig.workingMemory?.enabled) return null;
389
+ await this.storage.init();
379
390
  const thread = await this.storage.getThreadById({ threadId });
380
391
  if (!thread) return this.threadConfig?.workingMemory?.template || this.defaultWorkingMemoryTemplate;
381
392
  const memory = thread.metadata?.workingMemory || this.threadConfig.workingMemory.template || this.defaultWorkingMemoryTemplate;
@@ -395,6 +406,7 @@ var Memory = class extends memory.MastraMemory {
395
406
  if (!newMemory) {
396
407
  return;
397
408
  }
409
+ await this.storage.init();
398
410
  const thread = await this.storage.getThreadById({ threadId });
399
411
  if (!thread) return;
400
412
  await this.storage.updateThread({
@@ -418,10 +430,7 @@ var Memory = class extends memory.MastraMemory {
418
430
  if (!workingMemory) {
419
431
  return null;
420
432
  }
421
- if (config.workingMemory.use === "tool-call") {
422
- return this.getWorkingMemoryToolInstruction(workingMemory);
423
- }
424
- return this.getWorkingMemoryWithInstruction(workingMemory);
433
+ return this.getWorkingMemoryToolInstruction(workingMemory);
425
434
  }
426
435
  defaultWorkingMemoryTemplate = `
427
436
  # User Information
@@ -482,7 +491,7 @@ Notes:
482
491
  }
483
492
  getTools(config) {
484
493
  const mergedConfig = this.getMergedThreadConfig(config);
485
- if (mergedConfig.workingMemory?.enabled && mergedConfig.workingMemory.use === "tool-call") {
494
+ if (mergedConfig.workingMemory?.enabled) {
486
495
  return {
487
496
  updateWorkingMemory: updateWorkingMemoryTool
488
497
  };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { memoryDefaultOptions, deepMerge } from '@mastra/core';
1
+ import { deepMerge } from '@mastra/core';
2
2
  import { MastraMemory } from '@mastra/core/memory';
3
3
  import { embedMany } from 'ai';
4
4
  import xxhash from 'xxhash-wasm';
@@ -76,6 +76,8 @@ function reorderToolCallsAndResults(messages) {
76
76
 
77
77
  // src/index.ts
78
78
  var CHARS_PER_TOKEN = 4;
79
+ var DEFAULT_MESSAGE_RANGE = { before: 2, after: 2 };
80
+ var DEFAULT_TOP_K = 2;
79
81
  var Memory = class extends MastraMemory {
80
82
  constructor(config = {}) {
81
83
  super({ name: "Memory", ...config });
@@ -91,6 +93,7 @@ var Memory = class extends MastraMemory {
91
93
  this.threadConfig = mergedConfig;
92
94
  }
93
95
  async validateThreadIsOwnedByResource(threadId, resourceId) {
96
+ await this.storage.init();
94
97
  const thread = await this.storage.getThreadById({ threadId });
95
98
  if (!thread) {
96
99
  throw new Error(`No thread found with id ${threadId}`);
@@ -115,8 +118,8 @@ var Memory = class extends MastraMemory {
115
118
  threadConfig
116
119
  });
117
120
  const config = this.getMergedThreadConfig(threadConfig || {});
118
- const defaultRange = memoryDefaultOptions.semanticRecall.messageRange;
119
- const defaultTopK = memoryDefaultOptions.semanticRecall.topK;
121
+ const defaultRange = DEFAULT_MESSAGE_RANGE;
122
+ const defaultTopK = DEFAULT_TOP_K;
120
123
  const vectorConfig = typeof config?.semanticRecall === `boolean` ? {
121
124
  topK: defaultTopK,
122
125
  messageRange: defaultRange
@@ -147,6 +150,7 @@ var Memory = class extends MastraMemory {
147
150
  })
148
151
  );
149
152
  }
153
+ await this.storage.init();
150
154
  const rawMessages = await this.storage.getMessages({
151
155
  threadId,
152
156
  selectBy: {
@@ -198,15 +202,18 @@ var Memory = class extends MastraMemory {
198
202
  };
199
203
  }
200
204
  async getThreadById({ threadId }) {
205
+ await this.storage.init();
201
206
  return this.storage.getThreadById({ threadId });
202
207
  }
203
208
  async getThreadsByResourceId({ resourceId }) {
209
+ await this.storage.init();
204
210
  return this.storage.getThreadsByResourceId({ resourceId });
205
211
  }
206
212
  async saveThread({
207
213
  thread,
208
214
  memoryConfig
209
215
  }) {
216
+ await this.storage.init();
210
217
  const config = this.getMergedThreadConfig(memoryConfig || {});
211
218
  if (config.workingMemory?.enabled && !thread?.metadata?.workingMemory) {
212
219
  return this.storage.saveThread({
@@ -224,6 +231,7 @@ var Memory = class extends MastraMemory {
224
231
  title,
225
232
  metadata
226
233
  }) {
234
+ await this.storage.init();
227
235
  return this.storage.updateThread({
228
236
  id,
229
237
  title,
@@ -231,6 +239,7 @@ var Memory = class extends MastraMemory {
231
239
  });
232
240
  }
233
241
  async deleteThread(threadId) {
242
+ await this.storage.init();
234
243
  await this.storage.deleteThread({ threadId });
235
244
  }
236
245
  chunkText(text, tokenSize = 4096) {
@@ -287,6 +296,7 @@ var Memory = class extends MastraMemory {
287
296
  messages,
288
297
  memoryConfig
289
298
  }) {
299
+ await this.storage.init();
290
300
  await this.saveWorkingMemory(messages);
291
301
  const updatedMessages = this.updateMessagesToHideWorkingMemory(messages);
292
302
  const config = this.getMergedThreadConfig(memoryConfig);
@@ -370,6 +380,7 @@ var Memory = class extends MastraMemory {
370
380
  }
371
381
  async getWorkingMemory({ threadId }) {
372
382
  if (!this.threadConfig.workingMemory?.enabled) return null;
383
+ await this.storage.init();
373
384
  const thread = await this.storage.getThreadById({ threadId });
374
385
  if (!thread) return this.threadConfig?.workingMemory?.template || this.defaultWorkingMemoryTemplate;
375
386
  const memory = thread.metadata?.workingMemory || this.threadConfig.workingMemory.template || this.defaultWorkingMemoryTemplate;
@@ -389,6 +400,7 @@ var Memory = class extends MastraMemory {
389
400
  if (!newMemory) {
390
401
  return;
391
402
  }
403
+ await this.storage.init();
392
404
  const thread = await this.storage.getThreadById({ threadId });
393
405
  if (!thread) return;
394
406
  await this.storage.updateThread({
@@ -412,10 +424,7 @@ var Memory = class extends MastraMemory {
412
424
  if (!workingMemory) {
413
425
  return null;
414
426
  }
415
- if (config.workingMemory.use === "tool-call") {
416
- return this.getWorkingMemoryToolInstruction(workingMemory);
417
- }
418
- return this.getWorkingMemoryWithInstruction(workingMemory);
427
+ return this.getWorkingMemoryToolInstruction(workingMemory);
419
428
  }
420
429
  defaultWorkingMemoryTemplate = `
421
430
  # User Information
@@ -476,7 +485,7 @@ Notes:
476
485
  }
477
486
  getTools(config) {
478
487
  const mergedConfig = this.getMergedThreadConfig(config);
479
- if (mergedConfig.workingMemory?.enabled && mergedConfig.workingMemory.use === "tool-call") {
488
+ if (mergedConfig.workingMemory?.enabled) {
480
489
  return {
481
490
  updateWorkingMemory: updateWorkingMemoryTool
482
491
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/memory",
3
- "version": "0.3.5-alpha.0",
3
+ "version": "0.4.0-alpha.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -40,8 +40,7 @@
40
40
  "postgres": "^3.4.5",
41
41
  "redis": "^4.7.0",
42
42
  "xxhash-wasm": "^1.1.0",
43
- "zod": "^3.24.3",
44
- "@mastra/core": "^0.9.5-alpha.0"
43
+ "zod": "^3.24.3"
45
44
  },
46
45
  "devDependencies": {
47
46
  "@ai-sdk/openai": "^1.3.3",
@@ -53,8 +52,12 @@
53
52
  "typescript": "^5.8.2",
54
53
  "typescript-eslint": "^8.26.1",
55
54
  "vitest": "^3.1.2",
55
+ "@mastra/core": "0.10.0-alpha.1",
56
56
  "@internal/lint": "0.0.5"
57
57
  },
58
+ "peerDependencies": {
59
+ "@mastra/core": "^0.9.4"
60
+ },
58
61
  "scripts": {
59
62
  "check": "tsc --noEmit",
60
63
  "build": "pnpm run check && tsup src/index.ts src/processors/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { deepMerge, memoryDefaultOptions } from '@mastra/core';
1
+ import { deepMerge } from '@mastra/core';
2
2
  import type { AiMessageType, CoreMessage, CoreTool } from '@mastra/core';
3
3
  import { MastraMemory } from '@mastra/core/memory';
4
4
  import type { MessageType, MemoryConfig, SharedMemoryConfig, StorageThreadType } from '@mastra/core/memory';
@@ -13,6 +13,9 @@ import { reorderToolCallsAndResults } from './utils';
13
13
  // Average characters per token based on OpenAI's tokenization
14
14
  const CHARS_PER_TOKEN = 4;
15
15
 
16
+ const DEFAULT_MESSAGE_RANGE = { before: 2, after: 2 } as const;
17
+ const DEFAULT_TOP_K = 2;
18
+
16
19
  /**
17
20
  * Concrete implementation of MastraMemory that adds support for thread configuration
18
21
  * and message injection.
@@ -34,6 +37,7 @@ export class Memory extends MastraMemory {
34
37
  }
35
38
 
36
39
  private async validateThreadIsOwnedByResource(threadId: string, resourceId: string) {
40
+ await this.storage.init();
37
41
  const thread = await this.storage.getThreadById({ threadId });
38
42
  if (!thread) {
39
43
  throw new Error(`No thread found with id ${threadId}`);
@@ -70,8 +74,8 @@ export class Memory extends MastraMemory {
70
74
 
71
75
  const config = this.getMergedThreadConfig(threadConfig || {});
72
76
 
73
- const defaultRange = memoryDefaultOptions.semanticRecall.messageRange;
74
- const defaultTopK = memoryDefaultOptions.semanticRecall.topK;
77
+ const defaultRange = DEFAULT_MESSAGE_RANGE;
78
+ const defaultTopK = DEFAULT_TOP_K;
75
79
 
76
80
  const vectorConfig =
77
81
  typeof config?.semanticRecall === `boolean`
@@ -110,6 +114,7 @@ export class Memory extends MastraMemory {
110
114
  );
111
115
  }
112
116
 
117
+ await this.storage.init();
113
118
  // Get raw messages from storage
114
119
  const rawMessages = await this.storage.getMessages({
115
120
  threadId,
@@ -190,10 +195,12 @@ export class Memory extends MastraMemory {
190
195
  }
191
196
 
192
197
  async getThreadById({ threadId }: { threadId: string }): Promise<StorageThreadType | null> {
198
+ await this.storage.init();
193
199
  return this.storage.getThreadById({ threadId });
194
200
  }
195
201
 
196
202
  async getThreadsByResourceId({ resourceId }: { resourceId: string }): Promise<StorageThreadType[]> {
203
+ await this.storage.init();
197
204
  return this.storage.getThreadsByResourceId({ resourceId });
198
205
  }
199
206
 
@@ -204,6 +211,7 @@ export class Memory extends MastraMemory {
204
211
  thread: StorageThreadType;
205
212
  memoryConfig?: MemoryConfig;
206
213
  }): Promise<StorageThreadType> {
214
+ await this.storage.init();
207
215
  const config = this.getMergedThreadConfig(memoryConfig || {});
208
216
 
209
217
  if (config.workingMemory?.enabled && !thread?.metadata?.workingMemory) {
@@ -229,6 +237,7 @@ export class Memory extends MastraMemory {
229
237
  title: string;
230
238
  metadata: Record<string, unknown>;
231
239
  }): Promise<StorageThreadType> {
240
+ await this.storage.init();
232
241
  return this.storage.updateThread({
233
242
  id,
234
243
  title,
@@ -237,6 +246,7 @@ export class Memory extends MastraMemory {
237
246
  }
238
247
 
239
248
  async deleteThread(threadId: string): Promise<void> {
249
+ await this.storage.init();
240
250
  await this.storage.deleteThread({ threadId });
241
251
  }
242
252
 
@@ -324,6 +334,7 @@ export class Memory extends MastraMemory {
324
334
  messages: MessageType[];
325
335
  memoryConfig?: MemoryConfig;
326
336
  }): Promise<MessageType[]> {
337
+ await this.storage.init();
327
338
  // First save working memory from any messages
328
339
  await this.saveWorkingMemory(messages);
329
340
 
@@ -441,6 +452,7 @@ export class Memory extends MastraMemory {
441
452
  public async getWorkingMemory({ threadId }: { threadId: string }): Promise<string | null> {
442
453
  if (!this.threadConfig.workingMemory?.enabled) return null;
443
454
 
455
+ await this.storage.init();
444
456
  // Get thread from storage
445
457
  const thread = await this.storage.getThreadById({ threadId });
446
458
  if (!thread) return this.threadConfig?.workingMemory?.template || this.defaultWorkingMemoryTemplate;
@@ -480,6 +492,7 @@ export class Memory extends MastraMemory {
480
492
  return;
481
493
  }
482
494
 
495
+ await this.storage.init();
483
496
  const thread = await this.storage.getThreadById({ threadId });
484
497
  if (!thread) return;
485
498
 
@@ -511,11 +524,7 @@ export class Memory extends MastraMemory {
511
524
  return null;
512
525
  }
513
526
 
514
- if (config.workingMemory.use === 'tool-call') {
515
- return this.getWorkingMemoryToolInstruction(workingMemory);
516
- }
517
-
518
- return this.getWorkingMemoryWithInstruction(workingMemory);
527
+ return this.getWorkingMemoryToolInstruction(workingMemory);
519
528
  }
520
529
 
521
530
  public defaultWorkingMemoryTemplate = `
@@ -580,7 +589,7 @@ Notes:
580
589
 
581
590
  public getTools(config?: MemoryConfig): Record<string, CoreTool> {
582
591
  const mergedConfig = this.getMergedThreadConfig(config);
583
- if (mergedConfig.workingMemory?.enabled && mergedConfig.workingMemory.use === 'tool-call') {
592
+ if (mergedConfig.workingMemory?.enabled) {
584
593
  return {
585
594
  updateWorkingMemory: updateWorkingMemoryTool,
586
595
  };