@mastra/memory 0.13.1 → 0.13.2-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.
Files changed (33) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/CHANGELOG.md +21 -0
  3. package/dist/index.cjs +5 -4
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +2 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/processors/index.cjs +1 -2
  10. package/dist/processors/index.cjs.map +1 -1
  11. package/dist/processors/index.js +1 -2
  12. package/dist/processors/index.js.map +1 -1
  13. package/dist/processors/token-limiter.d.ts +2 -1
  14. package/dist/processors/token-limiter.d.ts.map +1 -1
  15. package/dist/processors/tool-call-filter.d.ts +2 -2
  16. package/dist/processors/tool-call-filter.d.ts.map +1 -1
  17. package/dist/tools/working-memory.d.ts +2 -2
  18. package/dist/tools/working-memory.d.ts.map +1 -1
  19. package/integration-tests-v5/CHANGELOG.md +17 -0
  20. package/integration-tests-v5/node_modules/.bin/vitest +2 -2
  21. package/integration-tests-v5/package.json +1 -1
  22. package/integration-tests-v5/src/agent-memory.test.ts +3 -3
  23. package/integration-tests-v5/src/mastra/agents/weather.ts +1 -1
  24. package/integration-tests-v5/src/processors.test.ts +18 -14
  25. package/integration-tests-v5/src/test-utils.ts +2 -1
  26. package/integration-tests-v5/src/working-memory.test.ts +1 -1
  27. package/package.json +5 -5
  28. package/src/index.ts +9 -3
  29. package/src/processors/index.test.ts +2 -2
  30. package/src/processors/token-limiter.ts +3 -1
  31. package/src/processors/tool-call-filter.ts +2 -2
  32. package/src/tools/working-memory.ts +6 -6
  33. package/integration-tests-v5/node_modules/.bin/mastra +0 -21
@@ -10,9 +10,9 @@ case `uname` in
10
10
  esac
11
11
 
12
12
  if [ -z "$NODE_PATH" ]; then
13
- export NODE_PATH="/home/runner/work/mastra/mastra/node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@20.19.9_@vitest+ui@3.2.3_jiti@2.4.2_jsdom@_01cfaf0d6bf085f2477a8f2d60758c73/node_modules/vitest/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@20.19.9_@vitest+ui@3.2.3_jiti@2.4.2_jsdom@_01cfaf0d6bf085f2477a8f2d60758c73/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/node_modules"
13
+ export NODE_PATH="/home/runner/work/mastra/mastra/node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@20.19.9_@vitest+ui@3.2.3_jiti@2.4.2_jsdom@_1fa9bcbc4e1992fa15d4041825cc914c/node_modules/vitest/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@20.19.9_@vitest+ui@3.2.3_jiti@2.4.2_jsdom@_1fa9bcbc4e1992fa15d4041825cc914c/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/node_modules"
14
14
  else
15
- export NODE_PATH="/home/runner/work/mastra/mastra/node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@20.19.9_@vitest+ui@3.2.3_jiti@2.4.2_jsdom@_01cfaf0d6bf085f2477a8f2d60758c73/node_modules/vitest/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@20.19.9_@vitest+ui@3.2.3_jiti@2.4.2_jsdom@_01cfaf0d6bf085f2477a8f2d60758c73/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/node_modules:$NODE_PATH"
15
+ export NODE_PATH="/home/runner/work/mastra/mastra/node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@20.19.9_@vitest+ui@3.2.3_jiti@2.4.2_jsdom@_1fa9bcbc4e1992fa15d4041825cc914c/node_modules/vitest/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@20.19.9_@vitest+ui@3.2.3_jiti@2.4.2_jsdom@_1fa9bcbc4e1992fa15d4041825cc914c/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/node_modules:$NODE_PATH"
16
16
  fi
17
17
  if [ -x "$basedir/node" ]; then
18
18
  exec "$basedir/node" "$basedir/../vitest/vitest.mjs" "$@"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mastra/memory-integration-tests-v5",
3
3
  "private": true,
4
- "version": "0.1.2",
4
+ "version": "0.1.3-alpha.1",
5
5
  "scripts": {
6
6
  "test": "pnpm test:streaming && pnpm test:working-memory && pnpm test:agent-memory && pnpm test:processors",
7
7
  "test:agent-memory": "vitest run ./src/agent-memory.test.ts",
@@ -2,9 +2,9 @@ import { randomUUID } from 'node:crypto';
2
2
  import { google } from '@ai-sdk/google';
3
3
  import { openai } from '@ai-sdk/openai';
4
4
  import { Mastra } from '@mastra/core';
5
- import type { CoreMessage } from '@mastra/core';
6
5
  import { Agent } from '@mastra/core/agent';
7
6
  import type { UIMessageWithMetadata } from '@mastra/core/agent';
7
+ import type { CoreMessage } from '@mastra/core/llm';
8
8
  import { RuntimeContext } from '@mastra/core/runtime-context';
9
9
  import { MockStore } from '@mastra/core/storage';
10
10
  import { fastembed } from '@mastra/fastembed';
@@ -230,11 +230,11 @@ describe('Agent Memory Tests', () => {
230
230
  }
231
231
 
232
232
  expect(flattenAssistantMessages(assistantMessages)).toEqual(
233
- expect.arrayContaining([expect.stringContaining('2 + 2'), expect.stringContaining('"result"')]),
233
+ expect.arrayContaining([expect.stringMatching(/2\s*\+\s*2/), expect.stringContaining('"result"')]),
234
234
  );
235
235
 
236
236
  expect(flattenAssistantMessages(assistantUiMessages)).toEqual(
237
- expect.arrayContaining([expect.stringContaining('2 + 2'), expect.stringContaining('"result"')]),
237
+ expect.arrayContaining([expect.stringMatching(/2\s*\+\s*2/), expect.stringContaining('"result"')]),
238
238
  );
239
239
  });
240
240
 
@@ -1,6 +1,6 @@
1
1
  import { openai } from '@ai-sdk/openai';
2
- import { createTool } from '@mastra/core';
3
2
  import { Agent } from '@mastra/core/agent';
3
+ import { createTool } from '@mastra/core/tools';
4
4
  import { LibSQLStore, LibSQLVector } from '@mastra/libsql';
5
5
  import { Memory } from '@mastra/memory';
6
6
  import { ToolCallFilter } from '@mastra/memory/processors';
@@ -3,10 +3,11 @@ import { afterEach } from 'node:test';
3
3
  import { tmpdir } from 'os';
4
4
  import { join } from 'path';
5
5
  import { openai } from '@ai-sdk/openai';
6
- import type { CoreMessage, MemoryProcessorOpts } from '@mastra/core';
7
- import { MemoryProcessor } from '@mastra/core';
8
6
  import type { MastraMessageV2 } from '@mastra/core/agent';
9
7
  import { Agent, MessageList } from '@mastra/core/agent';
8
+ import type { CoreMessage } from '@mastra/core/llm';
9
+ import type { MemoryProcessorOpts } from '@mastra/core/memory';
10
+ import { MemoryProcessor } from '@mastra/core/memory';
10
11
  import { createTool } from '@mastra/core/tools';
11
12
  import { fastembed } from '@mastra/fastembed';
12
13
  import { LibSQLVector, LibSQLStore } from '@mastra/libsql';
@@ -81,7 +82,7 @@ describe('Memory with Processors', () => {
81
82
  threadId: thread.id,
82
83
  selectBy: { last: 20 },
83
84
  });
84
- const result = memory.processMessages({
85
+ const result = await memory.processMessages({
85
86
  messages: new MessageList({ threadId: thread.id, resourceId })
86
87
  .add(queryResult.uiMessages, 'memory')
87
88
  .get.all.core(),
@@ -111,7 +112,7 @@ describe('Memory with Processors', () => {
111
112
  });
112
113
  expect(allMessagesQuery.messages.length).toBe(20);
113
114
 
114
- const allMessagesResult = memory.processMessages({
115
+ const allMessagesResult = await memory.processMessages({
115
116
  messages: new MessageList({ threadId: thread.id, resourceId })
116
117
  .add(allMessagesQuery.uiMessages, 'memory')
117
118
  .get.all.core(),
@@ -155,7 +156,7 @@ describe('Memory with Processors', () => {
155
156
  threadId: thread.id,
156
157
  selectBy: { last: 20 },
157
158
  });
158
- const result = memory.processMessages({
159
+ const result = await memory.processMessages({
159
160
  messages: v2ToCoreMessages(queryResult.uiMessages),
160
161
  processors: [new ToolCallFilter({ exclude: ['weather'] })],
161
162
  });
@@ -171,7 +172,10 @@ describe('Memory with Processors', () => {
171
172
  threadId: thread.id,
172
173
  selectBy: { last: 20 },
173
174
  });
174
- const result2 = memory.processMessages({ messages: v2ToCoreMessages(queryResult2.uiMessages), processors: [] });
175
+ const result2 = await memory.processMessages({
176
+ messages: v2ToCoreMessages(queryResult2.uiMessages),
177
+ processors: [],
178
+ });
175
179
  const messages2 = new MessageList({ threadId: thread.id, resourceId }).add(result2, 'response').get.all.v2();
176
180
  expect(new MessageList().add(messages2, 'memory').get.all.v2()).toHaveLength(messagesV2.length);
177
181
  expect(filterToolCallsByName(result2, 'weather')).toHaveLength(1);
@@ -184,7 +188,7 @@ describe('Memory with Processors', () => {
184
188
  threadId: thread.id,
185
189
  selectBy: { last: 20 },
186
190
  });
187
- const result3 = memory.processMessages({
191
+ const result3 = await memory.processMessages({
188
192
  messages: v2ToCoreMessages(queryResult3.uiMessages),
189
193
  processors: [new ToolCallFilter({ exclude: ['weather', 'calculator'] })],
190
194
  });
@@ -199,7 +203,7 @@ describe('Memory with Processors', () => {
199
203
  threadId: thread.id,
200
204
  selectBy: { last: 20 },
201
205
  });
202
- const result4 = memory.processMessages({
206
+ const result4 = await memory.processMessages({
203
207
  messages: v2ToCoreMessages(queryResult4.uiMessages),
204
208
  processors: [new ToolCallFilter()],
205
209
  });
@@ -234,7 +238,7 @@ describe('Memory with Processors', () => {
234
238
  threadId: thread.id,
235
239
  selectBy: { last: 20 },
236
240
  });
237
- const result = memory.processMessages({
241
+ const result = await memory.processMessages({
238
242
  messages: v2ToCoreMessages(queryResult.uiMessages),
239
243
  processors: [new ToolCallFilter({ exclude: ['weather'] }), new TokenLimiter(250)],
240
244
  });
@@ -420,7 +424,7 @@ describe('Memory with Processors', () => {
420
424
 
421
425
  const list = new MessageList({ threadId }).add(queryResult.messagesV2, 'memory');
422
426
 
423
- const baselineResult = memory.processMessages({
427
+ const baselineResult = await memory.processMessages({
424
428
  messages: list.get.remembered.core(),
425
429
  newMessages: list.get.input.core(),
426
430
  processors: [],
@@ -441,7 +445,7 @@ describe('Memory with Processors', () => {
441
445
  selectBy: { last: 20 },
442
446
  });
443
447
  const list2 = new MessageList({ threadId }).add(weatherQueryResult.messagesV2, 'memory');
444
- const weatherFilteredResult = memory.processMessages({
448
+ const weatherFilteredResult = await memory.processMessages({
445
449
  messages: list2.get.all.core(),
446
450
  processors: [new ToolCallFilter({ exclude: ['get_weather'] })],
447
451
  });
@@ -462,7 +466,7 @@ describe('Memory with Processors', () => {
462
466
  selectBy: { last: 20 },
463
467
  });
464
468
  const list3 = new MessageList({ threadId }).add(tokenLimitQuery.messages, 'memory');
465
- const tokenLimitedResult = memory.processMessages({
469
+ const tokenLimitedResult = await memory.processMessages({
466
470
  messages: list3.get.all.core(),
467
471
  processors: [new TokenLimiter(100)], // Small limit to only get a subset
468
472
  });
@@ -476,7 +480,7 @@ describe('Memory with Processors', () => {
476
480
  selectBy: { last: 20 },
477
481
  });
478
482
  const list4 = new MessageList({ threadId }).add(combinedQuery.messages, 'memory');
479
- const combinedResult = memory.processMessages({
483
+ const combinedResult = await memory.processMessages({
480
484
  messages: list4.get.all.core(),
481
485
  processors: [new ToolCallFilter({ exclude: ['get_weather', 'calculator'] }), new TokenLimiter(500)],
482
486
  });
@@ -529,7 +533,7 @@ describe('Memory with Processors', () => {
529
533
  });
530
534
 
531
535
  // Retrieve the message (no TokenLimiter, just get the message back)
532
- const result = memory.processMessages({
536
+ const result = await memory.processMessages({
533
537
  messages: v2ToCoreMessages(queryResult.uiMessages),
534
538
  });
535
539
 
@@ -1,6 +1,7 @@
1
- import type { CoreMessage, MastraMessageV1 } from '@mastra/core';
2
1
  import { MessageList } from '@mastra/core/agent';
3
2
  import type { MastraMessageV2 } from '@mastra/core/agent';
3
+ import type { CoreMessage } from '@mastra/core/llm';
4
+ import type { MastraMessageV1 } from '@mastra/core/memory';
4
5
 
5
6
  const toolArgs = {
6
7
  weather: { location: 'New York' },
@@ -3,8 +3,8 @@ import { mkdtemp } from 'node:fs/promises';
3
3
  import { tmpdir } from 'node:os';
4
4
  import { join } from 'node:path';
5
5
  import { openai } from '@ai-sdk/openai';
6
- import type { MastraMessageV1 } from '@mastra/core';
7
6
  import { Agent } from '@mastra/core/agent';
7
+ import type { MastraMessageV1 } from '@mastra/core/memory';
8
8
  import { fastembed } from '@mastra/fastembed';
9
9
  import { LibSQLVector, LibSQLStore } from '@mastra/libsql';
10
10
  import { Memory } from '@mastra/memory';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/memory",
3
- "version": "0.13.1",
3
+ "version": "0.13.2-alpha.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -43,9 +43,8 @@
43
43
  "redis": "^5.8.2",
44
44
  "async-mutex": "^0.5.0",
45
45
  "xxhash-wasm": "^1.1.0",
46
- "zod": "^3.25.67",
47
46
  "zod-to-json-schema": "^3.24.5",
48
- "@mastra/schema-compat": "0.10.7"
47
+ "@mastra/schema-compat": "0.10.6-alpha.0"
49
48
  },
50
49
  "devDependencies": {
51
50
  "@ai-sdk/openai": "^1.3.24",
@@ -58,12 +57,13 @@
58
57
  "typescript": "^5.8.3",
59
58
  "typescript-eslint": "^8.38.0",
60
59
  "vitest": "^3.2.4",
60
+ "@mastra/core": "0.14.2-alpha.1",
61
61
  "@internal/lint": "0.0.31",
62
- "@mastra/core": "0.14.1",
63
62
  "@internal/types-builder": "0.0.6"
64
63
  },
65
64
  "peerDependencies": {
66
- "@mastra/core": ">=0.14.0-0 <0.15.0-0"
65
+ "@mastra/core": ">=0.12.0-0 <0.15.0-0",
66
+ "zod": "^3.0.0 || ^4.0.0"
67
67
  },
68
68
  "scripts": {
69
69
  "check": "tsc --noEmit",
package/src/index.ts CHANGED
@@ -1,10 +1,16 @@
1
- import { generateEmptyFromSchema } from '@mastra/core';
2
- import type { MastraMessageV1, ToolAction } from '@mastra/core';
3
1
  import { MessageList } from '@mastra/core/agent';
4
2
  import type { MastraMessageV2, UIMessageWithMetadata } from '@mastra/core/agent';
5
3
  import { MastraMemory } from '@mastra/core/memory';
6
- import type { MemoryConfig, SharedMemoryConfig, StorageThreadType, WorkingMemoryTemplate } from '@mastra/core/memory';
4
+ import type {
5
+ MastraMessageV1,
6
+ MemoryConfig,
7
+ SharedMemoryConfig,
8
+ StorageThreadType,
9
+ WorkingMemoryTemplate,
10
+ } from '@mastra/core/memory';
7
11
  import type { StorageGetMessagesArg, ThreadSortOptions, PaginationInfo } from '@mastra/core/storage';
12
+ import type { ToolAction } from '@mastra/core/tools';
13
+ import { generateEmptyFromSchema } from '@mastra/core/utils';
8
14
  import { embedMany } from 'ai';
9
15
  import type { CoreMessage, TextPart } from 'ai';
10
16
  import { embedMany as embedManyV5 } from 'ai-v5';
@@ -1,7 +1,7 @@
1
1
  import { openai } from '@ai-sdk/openai';
2
- import { createTool } from '@mastra/core';
3
- import type { MastraMessageV1 } from '@mastra/core';
4
2
  import { Agent } from '@mastra/core/agent';
3
+ import type { MastraMessageV1 } from '@mastra/core/memory';
4
+ import { createTool } from '@mastra/core/tools';
5
5
  import type { CoreMessage } from 'ai';
6
6
  import cl100k_base from 'js-tiktoken/ranks/cl100k_base';
7
7
  import { describe, it, expect, vi } from 'vitest';
@@ -1,5 +1,7 @@
1
- import type { CoreMessage, MemoryProcessorOpts } from '@mastra/core';
1
+ import type { CoreMessage } from '@mastra/core/llm';
2
2
  import { MemoryProcessor } from '@mastra/core/memory';
3
+ import type { MemoryProcessorOpts } from '@mastra/core/memory';
4
+
3
5
  import { Tiktoken } from 'js-tiktoken/lite';
4
6
  import type { TiktokenBPE } from 'js-tiktoken/lite';
5
7
  import o200k_base from 'js-tiktoken/ranks/o200k_base';
@@ -1,5 +1,5 @@
1
- import type { CoreMessage } from '@mastra/core';
2
- import { MemoryProcessor } from '@mastra/core';
1
+ import type { CoreMessage } from '@mastra/core/llm';
2
+ import { MemoryProcessor } from '@mastra/core/memory';
3
3
 
4
4
  /**
5
5
  * Filters out tool calls and results from messages.
@@ -1,14 +1,14 @@
1
- import type { MemoryConfig } from '@mastra/core';
2
- import { createTool } from '@mastra/core';
1
+ import type { MemoryConfig } from '@mastra/core/memory';
2
+ import { createTool } from '@mastra/core/tools';
3
3
  import { convertSchemaToZod } from '@mastra/schema-compat';
4
4
  import type { Schema } from 'ai';
5
5
  import { z, ZodObject } from 'zod';
6
- import type { ZodTypeAny } from 'zod';
6
+ import type { ZodType } from 'zod';
7
7
 
8
8
  export const updateWorkingMemoryTool = (memoryConfig?: MemoryConfig) => {
9
9
  const schema = memoryConfig?.workingMemory?.schema;
10
10
 
11
- let inputSchema: ZodTypeAny = z.object({
11
+ let inputSchema: ZodType = z.object({
12
12
  memory: z
13
13
  .string()
14
14
  .describe(`The Markdown formatted working memory content to store. This MUST be a string. Never pass an object.`),
@@ -19,9 +19,9 @@ export const updateWorkingMemoryTool = (memoryConfig?: MemoryConfig) => {
19
19
  memory:
20
20
  schema instanceof ZodObject
21
21
  ? schema
22
- : convertSchemaToZod({ jsonSchema: schema } as Schema).describe(
22
+ : (convertSchemaToZod({ jsonSchema: schema } as Schema).describe(
23
23
  `The JSON formatted working memory content to store.`,
24
- ),
24
+ ) as ZodObject<any>),
25
25
  });
26
26
  }
27
27
 
@@ -1,21 +0,0 @@
1
- #!/bin/sh
2
- basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
-
4
- case `uname` in
5
- *CYGWIN*|*MINGW*|*MSYS*)
6
- if command -v cygpath > /dev/null 2>&1; then
7
- basedir=`cygpath -w "$basedir"`
8
- fi
9
- ;;
10
- esac
11
-
12
- if [ -z "$NODE_PATH" ]; then
13
- export NODE_PATH="/home/runner/work/mastra/mastra/packages/cli/dist/node_modules:/home/runner/work/mastra/mastra/packages/cli/node_modules:/home/runner/work/mastra/mastra/packages/node_modules:/home/runner/work/mastra/mastra/node_modules:/home/runner/work/mastra/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/node_modules"
14
- else
15
- export NODE_PATH="/home/runner/work/mastra/mastra/packages/cli/dist/node_modules:/home/runner/work/mastra/mastra/packages/cli/node_modules:/home/runner/work/mastra/mastra/packages/node_modules:/home/runner/work/mastra/mastra/node_modules:/home/runner/work/mastra/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/node_modules:$NODE_PATH"
16
- fi
17
- if [ -x "$basedir/node" ]; then
18
- exec "$basedir/node" "$basedir/../mastra/dist/index.js" "$@"
19
- else
20
- exec node "$basedir/../mastra/dist/index.js" "$@"
21
- fi