@mastra/memory 0.2.0-alpha.8 → 0.2.0

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,27 +1,27 @@
1
1
 
2
- > @mastra/memory@0.2.0-alpha.8 build /home/runner/work/mastra/mastra/packages/memory
3
- > pnpm run check && tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake
2
+ > @mastra/memory@0.2.0-alpha.12 build /home/runner/work/mastra/mastra/packages/memory
3
+ > pnpm run check && tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
4
4
 
5
5
 
6
- > @mastra/memory@0.2.0-alpha.8 check /home/runner/work/mastra/mastra/packages/memory
6
+ > @mastra/memory@0.2.0-alpha.12 check /home/runner/work/mastra/mastra/packages/memory
7
7
  > tsc --noEmit
8
8
 
9
9
  CLI Building entry: src/index.ts
10
10
  CLI Using tsconfig: tsconfig.json
11
- CLI tsup v8.3.6
11
+ CLI tsup v8.4.0
12
12
  TSC Build start
13
- TSC ⚡️ Build success in 8165ms
13
+ TSC ⚡️ Build success in 8090ms
14
14
  DTS Build start
15
15
  CLI Target: es2022
16
16
  Analysis will use the bundled TypeScript version 5.7.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.7.3
19
19
  Writing package typings: /home/runner/work/mastra/mastra/packages/memory/dist/_tsup-dts-rollup.d.cts
20
- DTS ⚡️ Build success in 11167ms
20
+ DTS ⚡️ Build success in 10326ms
21
21
  CLI Cleaning output folder
22
22
  ESM Build start
23
23
  CJS Build start
24
- CJS dist/index.cjs 12.21 KB
25
- CJS ⚡️ Build success in 777ms
26
- ESM dist/index.js 12.18 KB
27
- ESM ⚡️ Build success in 777ms
24
+ CJS dist/index.cjs 12.83 KB
25
+ CJS ⚡️ Build success in 500ms
26
+ ESM dist/index.js 12.79 KB
27
+ ESM ⚡️ Build success in 507ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,93 @@
1
1
  # @mastra/memory
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 59df7b6: Added a new option to use tool-calls for saving working memory: new Memory({ workingMemory: { enabled: true, use: "tool-call" } }). This is to support response methods like toDataStream where masking working memory chunks would be more resource intensive and complex.
8
+ To support this `memory` is now passed into tool execute args.
9
+
10
+ ### Patch Changes
11
+
12
+ - c151ae6: Fixed an issue where models that don't support structured output would error when generating a thread title. Added an option to disable thread title llm generation `new Memory({ threads: { generateTitle: false }})`
13
+ - f2301de: Added the ability to ensure the accessed thread in memory.query() is for the right resource id. ex memory.query({ threadId, resourceId }). If the resourceId doesn't own the thread it will throw an error.
14
+ - fd4a1d7: Update cjs bundling to make sure files are split
15
+ - Updated dependencies [a910463]
16
+ - Updated dependencies [59df7b6]
17
+ - Updated dependencies [22643eb]
18
+ - Updated dependencies [6feb23f]
19
+ - Updated dependencies [f2d6727]
20
+ - Updated dependencies [7a7a547]
21
+ - Updated dependencies [29f3a82]
22
+ - Updated dependencies [3d0e290]
23
+ - Updated dependencies [e9fbac5]
24
+ - Updated dependencies [301e4ee]
25
+ - Updated dependencies [ee667a2]
26
+ - Updated dependencies [dfbe4e9]
27
+ - Updated dependencies [dab255b]
28
+ - Updated dependencies [1e8bcbc]
29
+ - Updated dependencies [f6678e4]
30
+ - Updated dependencies [9e81f35]
31
+ - Updated dependencies [c93798b]
32
+ - Updated dependencies [a85ab24]
33
+ - Updated dependencies [dbd9f2d]
34
+ - Updated dependencies [59df7b6]
35
+ - Updated dependencies [caefaa2]
36
+ - Updated dependencies [c151ae6]
37
+ - Updated dependencies [52e0418]
38
+ - Updated dependencies [d79aedf]
39
+ - Updated dependencies [03236ec]
40
+ - Updated dependencies [3764e71]
41
+ - Updated dependencies [df982db]
42
+ - Updated dependencies [a171b37]
43
+ - Updated dependencies [506f1d5]
44
+ - Updated dependencies [02ffb7b]
45
+ - Updated dependencies [0461849]
46
+ - Updated dependencies [2259379]
47
+ - Updated dependencies [aeb5e36]
48
+ - Updated dependencies [f2301de]
49
+ - Updated dependencies [358f069]
50
+ - Updated dependencies [fd4a1d7]
51
+ - Updated dependencies [c139344]
52
+ - @mastra/core@0.5.0
53
+
54
+ ## 0.2.0-alpha.12
55
+
56
+ ### Patch Changes
57
+
58
+ - Updated dependencies [a85ab24]
59
+ - @mastra/core@0.5.0-alpha.12
60
+
61
+ ## 0.2.0-alpha.11
62
+
63
+ ### Patch Changes
64
+
65
+ - fd4a1d7: Update cjs bundling to make sure files are split
66
+ - Updated dependencies [7a7a547]
67
+ - Updated dependencies [c93798b]
68
+ - Updated dependencies [dbd9f2d]
69
+ - Updated dependencies [a171b37]
70
+ - Updated dependencies [fd4a1d7]
71
+ - @mastra/core@0.5.0-alpha.11
72
+
73
+ ## 0.2.0-alpha.10
74
+
75
+ ### Patch Changes
76
+
77
+ - Updated dependencies [a910463]
78
+ - @mastra/core@0.5.0-alpha.10
79
+
80
+ ## 0.2.0-alpha.9
81
+
82
+ ### Patch Changes
83
+
84
+ - f2301de: Added the ability to ensure the accessed thread in memory.query() is for the right resource id. ex memory.query({ threadId, resourceId }). If the resourceId doesn't own the thread it will throw an error.
85
+ - Updated dependencies [e9fbac5]
86
+ - Updated dependencies [1e8bcbc]
87
+ - Updated dependencies [aeb5e36]
88
+ - Updated dependencies [f2301de]
89
+ - @mastra/core@0.5.0-alpha.9
90
+
3
91
  ## 0.2.0-alpha.8
4
92
 
5
93
  ### Patch Changes
@@ -14,12 +14,14 @@ import type { StorageThreadType } from '@mastra/core/memory';
14
14
  */
15
15
  export declare class Memory extends MastraMemory {
16
16
  constructor(config?: SharedMemoryConfig);
17
- query({ threadId, selectBy, threadConfig, }: StorageGetMessagesArg): Promise<{
17
+ private validateThreadIsOwnedByResource;
18
+ query({ threadId, resourceId, selectBy, threadConfig, }: StorageGetMessagesArg): Promise<{
18
19
  messages: CoreMessage[];
19
20
  uiMessages: AiMessageType[];
20
21
  }>;
21
- rememberMessages({ threadId, vectorMessageSearch, config, }: {
22
+ rememberMessages({ threadId, resourceId, vectorMessageSearch, config, }: {
22
23
  threadId: string;
24
+ resourceId?: string;
23
25
  vectorMessageSearch?: string;
24
26
  config?: MemoryConfig;
25
27
  }): Promise<{
@@ -14,12 +14,14 @@ import type { StorageThreadType } from '@mastra/core/memory';
14
14
  */
15
15
  export declare class Memory extends MastraMemory {
16
16
  constructor(config?: SharedMemoryConfig);
17
- query({ threadId, selectBy, threadConfig, }: StorageGetMessagesArg): Promise<{
17
+ private validateThreadIsOwnedByResource;
18
+ query({ threadId, resourceId, selectBy, threadConfig, }: StorageGetMessagesArg): Promise<{
18
19
  messages: CoreMessage[];
19
20
  uiMessages: AiMessageType[];
20
21
  }>;
21
- rememberMessages({ threadId, vectorMessageSearch, config, }: {
22
+ rememberMessages({ threadId, resourceId, vectorMessageSearch, config, }: {
22
23
  threadId: string;
24
+ resourceId?: string;
23
25
  vectorMessageSearch?: string;
24
26
  config?: MemoryConfig;
25
27
  }): Promise<{
package/dist/index.cjs CHANGED
@@ -45,11 +45,24 @@ var Memory = class extends memory.MastraMemory {
45
45
  });
46
46
  this.threadConfig = mergedConfig;
47
47
  }
48
+ async validateThreadIsOwnedByResource(threadId, resourceId) {
49
+ const thread = await this.storage.getThreadById({ threadId });
50
+ if (!thread) {
51
+ throw new Error(`No thread found with id ${threadId}`);
52
+ }
53
+ if (thread.resourceId !== resourceId) {
54
+ throw new Error(
55
+ `Thread with id ${threadId} is for resource with id ${thread.resourceId} but resource ${resourceId} was queried.`
56
+ );
57
+ }
58
+ }
48
59
  async query({
49
60
  threadId,
61
+ resourceId,
50
62
  selectBy,
51
63
  threadConfig
52
64
  }) {
65
+ if (resourceId) await this.validateThreadIsOwnedByResource(threadId, resourceId);
53
66
  let vectorResults = null;
54
67
  this.logger.debug(`Memory query() with:`, {
55
68
  threadId,
@@ -99,9 +112,11 @@ var Memory = class extends memory.MastraMemory {
99
112
  }
100
113
  async rememberMessages({
101
114
  threadId,
115
+ resourceId,
102
116
  vectorMessageSearch,
103
117
  config
104
118
  }) {
119
+ if (resourceId) await this.validateThreadIsOwnedByResource(threadId, resourceId);
105
120
  const threadConfig = this.getMergedThreadConfig(config || {});
106
121
  if (!threadConfig.lastMessages && !threadConfig.semanticRecall) {
107
122
  return {
package/dist/index.js CHANGED
@@ -43,11 +43,24 @@ var Memory = class extends MastraMemory {
43
43
  });
44
44
  this.threadConfig = mergedConfig;
45
45
  }
46
+ async validateThreadIsOwnedByResource(threadId, resourceId) {
47
+ const thread = await this.storage.getThreadById({ threadId });
48
+ if (!thread) {
49
+ throw new Error(`No thread found with id ${threadId}`);
50
+ }
51
+ if (thread.resourceId !== resourceId) {
52
+ throw new Error(
53
+ `Thread with id ${threadId} is for resource with id ${thread.resourceId} but resource ${resourceId} was queried.`
54
+ );
55
+ }
56
+ }
46
57
  async query({
47
58
  threadId,
59
+ resourceId,
48
60
  selectBy,
49
61
  threadConfig
50
62
  }) {
63
+ if (resourceId) await this.validateThreadIsOwnedByResource(threadId, resourceId);
51
64
  let vectorResults = null;
52
65
  this.logger.debug(`Memory query() with:`, {
53
66
  threadId,
@@ -97,9 +110,11 @@ var Memory = class extends MastraMemory {
97
110
  }
98
111
  async rememberMessages({
99
112
  threadId,
113
+ resourceId,
100
114
  vectorMessageSearch,
101
115
  config
102
116
  }) {
117
+ if (resourceId) await this.validateThreadIsOwnedByResource(threadId, resourceId);
103
118
  const threadConfig = this.getMergedThreadConfig(config || {});
104
119
  if (!threadConfig.lastMessages && !threadConfig.semanticRecall) {
105
120
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/memory",
3
- "version": "0.2.0-alpha.8",
3
+ "version": "0.2.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -42,29 +42,29 @@
42
42
  "author": "",
43
43
  "license": "ISC",
44
44
  "dependencies": {
45
- "@upstash/redis": "^1.34.3",
46
- "ai": "^4.0.12",
47
- "pg": "^8.13.1",
48
- "pg-pool": "^3.7.0",
45
+ "@upstash/redis": "^1.34.5",
46
+ "ai": "^4.1.54",
47
+ "pg": "^8.13.3",
48
+ "pg-pool": "^3.7.1",
49
49
  "postgres": "^3.4.5",
50
50
  "redis": "^4.7.0",
51
- "zod": "^3.24.1",
52
- "@mastra/core": "^0.5.0-alpha.8"
51
+ "zod": "^3.24.2",
52
+ "@mastra/core": "^0.5.0"
53
53
  },
54
54
  "devDependencies": {
55
- "@microsoft/api-extractor": "^7.49.2",
56
- "@types/node": "^22.13.1",
57
- "@types/pg": "^8.11.10",
58
- "eslint": "^9.20.1",
59
- "tsup": "^8.0.1",
60
- "typescript": "^5.7.3",
61
- "typescript-eslint": "^8.20.0",
62
- "vitest": "^3.0.4",
63
- "@internal/lint": "0.0.0"
55
+ "@microsoft/api-extractor": "^7.52.1",
56
+ "@types/node": "^22.13.10",
57
+ "@types/pg": "^8.11.11",
58
+ "eslint": "^9.22.0",
59
+ "tsup": "^8.4.0",
60
+ "typescript": "^5.8.2",
61
+ "typescript-eslint": "^8.26.1",
62
+ "vitest": "^3.0.8",
63
+ "@internal/lint": "0.0.1"
64
64
  },
65
65
  "scripts": {
66
66
  "check": "tsc --noEmit",
67
- "build": "pnpm run check && tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake",
67
+ "build": "pnpm run check && tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
68
68
  "build:watch": "pnpm build --watch",
69
69
  "test:integration": "cd integration-tests && pnpm run test",
70
70
  "test": "pnpm test:integration",
package/src/index.ts CHANGED
@@ -4,7 +4,6 @@ import { MastraMemory } from '@mastra/core/memory';
4
4
  import type { MessageType, MemoryConfig, SharedMemoryConfig, StorageThreadType } from '@mastra/core/memory';
5
5
  import type { StorageGetMessagesArg } from '@mastra/core/storage';
6
6
  import { embed } from 'ai';
7
- import type { Message as AiMessage } from 'ai';
8
7
  import { updateWorkingMemoryTool } from './tools/working-memory';
9
8
 
10
9
  /**
@@ -24,11 +23,26 @@ export class Memory extends MastraMemory {
24
23
  this.threadConfig = mergedConfig;
25
24
  }
26
25
 
26
+ private async validateThreadIsOwnedByResource(threadId: string, resourceId: string) {
27
+ const thread = await this.storage.getThreadById({ threadId });
28
+ if (!thread) {
29
+ throw new Error(`No thread found with id ${threadId}`);
30
+ }
31
+ if (thread.resourceId !== resourceId) {
32
+ throw new Error(
33
+ `Thread with id ${threadId} is for resource with id ${thread.resourceId} but resource ${resourceId} was queried.`,
34
+ );
35
+ }
36
+ }
37
+
27
38
  async query({
28
39
  threadId,
40
+ resourceId,
29
41
  selectBy,
30
42
  threadConfig,
31
43
  }: StorageGetMessagesArg): Promise<{ messages: CoreMessage[]; uiMessages: AiMessageType[] }> {
44
+ if (resourceId) await this.validateThreadIsOwnedByResource(threadId, resourceId);
45
+
32
46
  let vectorResults:
33
47
  | null
34
48
  | {
@@ -108,10 +122,12 @@ export class Memory extends MastraMemory {
108
122
 
109
123
  async rememberMessages({
110
124
  threadId,
125
+ resourceId,
111
126
  vectorMessageSearch,
112
127
  config,
113
128
  }: {
114
129
  threadId: string;
130
+ resourceId?: string;
115
131
  vectorMessageSearch?: string;
116
132
  config?: MemoryConfig;
117
133
  }): Promise<{
@@ -119,6 +135,8 @@ export class Memory extends MastraMemory {
119
135
  messages: CoreMessage[];
120
136
  uiMessages: AiMessageType[];
121
137
  }> {
138
+ if (resourceId) await this.validateThreadIsOwnedByResource(threadId, resourceId);
139
+
122
140
  const threadConfig = this.getMergedThreadConfig(config || {});
123
141
 
124
142
  if (!threadConfig.lastMessages && !threadConfig.semanticRecall) {