@mastra/memory 0.2.6-alpha.3 → 0.2.6-alpha.4

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.6-alpha.3 build /home/runner/work/mastra/mastra/packages/memory
2
+ > @mastra/memory@0.2.6-alpha.4 build /home/runner/work/mastra/mastra/packages/memory
3
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.6-alpha.3 check /home/runner/work/mastra/mastra/packages/memory
6
+ > @mastra/memory@0.2.6-alpha.4 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
11
  CLI tsup v8.4.0
12
12
  TSC Build start
13
- TSC ⚡️ Build success in 8385ms
13
+ TSC ⚡️ Build success in 13659ms
14
14
  DTS Build start
15
15
  CLI Target: es2022
16
- CLI Cleaning output folder
17
- ESM Build start
18
- CJS Build start
19
16
  Analysis will use the bundled TypeScript version 5.8.2
20
17
  Writing package typings: /home/runner/work/mastra/mastra/packages/memory/dist/_tsup-dts-rollup.d.ts
21
18
  Analysis will use the bundled TypeScript version 5.8.2
22
19
  Writing package typings: /home/runner/work/mastra/mastra/packages/memory/dist/_tsup-dts-rollup.d.cts
23
- DTS ⚡️ Build success in 3439ms
24
- CJS dist/index.cjs 13.37 KB
25
- CJS ⚡️ Build success in 3563ms
26
- ESM dist/index.js 13.34 KB
27
- ESM ⚡️ Build success in 3564ms
20
+ DTS ⚡️ Build success in 5635ms
21
+ CLI Cleaning output folder
22
+ ESM Build start
23
+ CJS Build start
24
+ ESM dist/index.js 13.53 KB
25
+ ESM ⚡️ Build success in 315ms
26
+ CJS dist/index.cjs 13.56 KB
27
+ CJS ⚡️ Build success in 316ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @mastra/memory
2
2
 
3
+ ## 0.2.6-alpha.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 394dfad: Removed working memory tool calls from thread history after the working memory has been updated. This is to prevent updates from polluting the context history and confusing agents. They should only see the most recent copy of working memory.
8
+ Also made memory.getWorkingMemory() public since it's useful for testing, debugging, and building UIs.
9
+
3
10
  ## 0.2.6-alpha.3
4
11
 
5
12
  ### Patch Changes
@@ -52,7 +52,7 @@ export declare class Memory extends MastraMemory {
52
52
  }): Promise<MessageType[]>;
53
53
  protected mutateMessagesToHideWorkingMemory(messages: MessageType[]): void;
54
54
  protected parseWorkingMemory(text: string): string | null;
55
- protected getWorkingMemory({ threadId }: {
55
+ getWorkingMemory({ threadId }: {
56
56
  threadId: string;
57
57
  }): Promise<string | null>;
58
58
  private saveWorkingMemory;
@@ -52,7 +52,7 @@ export declare class Memory extends MastraMemory {
52
52
  }): Promise<MessageType[]>;
53
53
  protected mutateMessagesToHideWorkingMemory(messages: MessageType[]): void;
54
54
  protected parseWorkingMemory(text: string): string | null;
55
- protected getWorkingMemory({ threadId }: {
55
+ getWorkingMemory({ threadId }: {
56
56
  threadId: string;
57
57
  }): Promise<string | null>;
58
58
  private saveWorkingMemory;
package/dist/index.cjs CHANGED
@@ -223,7 +223,7 @@ var Memory = class extends memory.MastraMemory {
223
223
  }
224
224
  mutateMessagesToHideWorkingMemory(messages) {
225
225
  const workingMemoryRegex = /<working_memory>([^]*?)<\/working_memory>/g;
226
- for (const message of messages) {
226
+ for (const [index, message] of messages.entries()) {
227
227
  if (typeof message?.content === `string`) {
228
228
  message.content = message.content.replace(workingMemoryRegex, ``).trim();
229
229
  } else if (Array.isArray(message?.content)) {
@@ -231,6 +231,9 @@ var Memory = class extends memory.MastraMemory {
231
231
  if (content.type === `text`) {
232
232
  content.text = content.text.replace(workingMemoryRegex, ``).trim();
233
233
  }
234
+ if ((content.type === `tool-call` || content.type === `tool-result`) && content.toolName === `updateWorkingMemory`) {
235
+ delete messages[index];
236
+ }
234
237
  }
235
238
  }
236
239
  }
package/dist/index.js CHANGED
@@ -221,7 +221,7 @@ var Memory = class extends MastraMemory {
221
221
  }
222
222
  mutateMessagesToHideWorkingMemory(messages) {
223
223
  const workingMemoryRegex = /<working_memory>([^]*?)<\/working_memory>/g;
224
- for (const message of messages) {
224
+ for (const [index, message] of messages.entries()) {
225
225
  if (typeof message?.content === `string`) {
226
226
  message.content = message.content.replace(workingMemoryRegex, ``).trim();
227
227
  } else if (Array.isArray(message?.content)) {
@@ -229,6 +229,9 @@ var Memory = class extends MastraMemory {
229
229
  if (content.type === `text`) {
230
230
  content.text = content.text.replace(workingMemoryRegex, ``).trim();
231
231
  }
232
+ if ((content.type === `tool-call` || content.type === `tool-result`) && content.toolName === `updateWorkingMemory`) {
233
+ delete messages[index];
234
+ }
232
235
  }
233
236
  }
234
237
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/memory",
3
- "version": "0.2.6-alpha.3",
3
+ "version": "0.2.6-alpha.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/index.ts CHANGED
@@ -281,7 +281,8 @@ export class Memory extends MastraMemory {
281
281
 
282
282
  protected mutateMessagesToHideWorkingMemory(messages: MessageType[]) {
283
283
  const workingMemoryRegex = /<working_memory>([^]*?)<\/working_memory>/g;
284
- for (const message of messages) {
284
+
285
+ for (const [index, message] of messages.entries()) {
285
286
  if (typeof message?.content === `string`) {
286
287
  message.content = message.content.replace(workingMemoryRegex, ``).trim();
287
288
  } else if (Array.isArray(message?.content)) {
@@ -289,6 +290,13 @@ export class Memory extends MastraMemory {
289
290
  if (content.type === `text`) {
290
291
  content.text = content.text.replace(workingMemoryRegex, ``).trim();
291
292
  }
293
+
294
+ if (
295
+ (content.type === `tool-call` || content.type === `tool-result`) &&
296
+ content.toolName === `updateWorkingMemory`
297
+ ) {
298
+ delete messages[index];
299
+ }
292
300
  }
293
301
  }
294
302
  }
@@ -308,7 +316,7 @@ export class Memory extends MastraMemory {
308
316
  return null;
309
317
  }
310
318
 
311
- protected async getWorkingMemory({ threadId }: { threadId: string }): Promise<string | null> {
319
+ public async getWorkingMemory({ threadId }: { threadId: string }): Promise<string | null> {
312
320
  if (!this.threadConfig.workingMemory?.enabled) return null;
313
321
 
314
322
  // Get thread from storage