@mastra/memory 0.3.0-alpha.8 → 0.3.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,29 +1,29 @@
1
1
 
2
- > @mastra/memory@0.3.0-alpha.8 build /home/runner/work/mastra/mastra/packages/memory
2
+ > @mastra/memory@0.3.0-alpha.9 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.0-alpha.8 check /home/runner/work/mastra/mastra/packages/memory
6
+ > @mastra/memory@0.3.0-alpha.9 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 8757ms
13
+ TSC ⚡️ Build success in 10184ms
14
14
  DTS Build start
15
15
  CLI Target: es2022
16
16
  Analysis will use the bundled TypeScript version 5.8.2
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.2
19
19
  Writing package typings: /home/runner/work/mastra/mastra/packages/memory/dist/_tsup-dts-rollup.d.cts
20
- DTS ⚡️ Build success in 10025ms
20
+ DTS ⚡️ Build success in 11957ms
21
21
  CLI Cleaning output folder
22
22
  ESM Build start
23
23
  CJS Build start
24
- ESM dist/processors/index.js 5.33 KB
24
+ ESM dist/processors/index.js 5.38 KB
25
25
  ESM dist/index.js 17.83 KB
26
- ESM ⚡️ Build success in 907ms
26
+ ESM ⚡️ Build success in 1115ms
27
+ CJS dist/processors/index.cjs 5.59 KB
27
28
  CJS dist/index.cjs 18.02 KB
28
- CJS dist/processors/index.cjs 5.54 KB
29
- CJS ⚡️ Build success in 916ms
29
+ CJS ⚡️ Build success in 1115ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  # @mastra/memory
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - fe3ae4d: Remove \_\_ functions in storage and move to storage proxy to make sure init is called
8
+
9
+ ### Patch Changes
10
+
11
+ - 000a6d4: Fixed an issue where the TokenLimiter message processor was adding new messages into the remembered messages array
12
+ - 71d9444: updated savemessage to not use mutation when hiding working memory
13
+ - 5c6825c: [MASTRA-2782] removed tiktoken from memory chunktext
14
+ - 6f92295: Fixed an issue where some user messages and llm messages would have the exact same createdAt date, leading to incorrect message ordering. Added a fix for new messages as well as any that were saved before the fix in the wrong order
15
+ - Updated dependencies [000a6d4]
16
+ - Updated dependencies [08bb78e]
17
+ - Updated dependencies [ed2f549]
18
+ - Updated dependencies [7e92011]
19
+ - Updated dependencies [9ee4293]
20
+ - Updated dependencies [03f3cd0]
21
+ - Updated dependencies [c0f22b4]
22
+ - Updated dependencies [71d9444]
23
+ - Updated dependencies [157c741]
24
+ - Updated dependencies [8a8a73b]
25
+ - Updated dependencies [0a033fa]
26
+ - Updated dependencies [fe3ae4d]
27
+ - Updated dependencies [9c26508]
28
+ - Updated dependencies [0f4eae3]
29
+ - Updated dependencies [16a8648]
30
+ - Updated dependencies [6f92295]
31
+ - @mastra/core@0.9.0
32
+
33
+ ## 0.3.0-alpha.9
34
+
35
+ ### Patch Changes
36
+
37
+ - 000a6d4: Fixed an issue where the TokenLimiter message processor was adding new messages into the remembered messages array
38
+ - Updated dependencies [000a6d4]
39
+ - Updated dependencies [ed2f549]
40
+ - Updated dependencies [c0f22b4]
41
+ - Updated dependencies [0a033fa]
42
+ - Updated dependencies [9c26508]
43
+ - Updated dependencies [0f4eae3]
44
+ - Updated dependencies [16a8648]
45
+ - @mastra/core@0.9.0-alpha.8
46
+
3
47
  ## 0.3.0-alpha.8
4
48
 
5
49
  ### Patch Changes
@@ -56,7 +56,9 @@ var TokenLimiter = class extends memory.MemoryProcessor {
56
56
  if (!message) continue;
57
57
  const messageTokens = this.countTokens(message);
58
58
  if (totalTokens + messageTokens <= this.maxTokens) {
59
- result.unshift(message);
59
+ if (i < messages.length) {
60
+ result.unshift(message);
61
+ }
60
62
  totalTokens += messageTokens;
61
63
  } else {
62
64
  this.logger.info(
@@ -50,7 +50,9 @@ var TokenLimiter = class extends MemoryProcessor {
50
50
  if (!message) continue;
51
51
  const messageTokens = this.countTokens(message);
52
52
  if (totalTokens + messageTokens <= this.maxTokens) {
53
- result.unshift(message);
53
+ if (i < messages.length) {
54
+ result.unshift(message);
55
+ }
54
56
  totalTokens += messageTokens;
55
57
  } else {
56
58
  this.logger.info(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/memory",
3
- "version": "0.3.0-alpha.8",
3
+ "version": "0.3.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -41,7 +41,7 @@
41
41
  "redis": "^4.7.0",
42
42
  "xxhash-wasm": "^1.1.0",
43
43
  "zod": "^3.24.2",
44
- "@mastra/core": "^0.9.0-alpha.7"
44
+ "@mastra/core": "^0.9.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@ai-sdk/openai": "^1.3.3",
@@ -90,7 +90,7 @@ describe('TokenLimiter', () => {
90
90
  console.log(`Estimated ${estimate} tokens, used ${used} tokens.\n`, counts);
91
91
 
92
92
  // Check if within 2% margin
93
- expect(percentDifference(estimate, used)).toBeLessThanOrEqual(2);
93
+ expect(percentDifference(estimate, used)).toBeLessThanOrEqual(4);
94
94
  }
95
95
 
96
96
  const calculatorTool = createTool({
@@ -111,7 +111,7 @@ describe('TokenLimiter', () => {
111
111
  tools: { calculatorTool },
112
112
  });
113
113
 
114
- describe.concurrent(`98% accuracy`, () => {
114
+ describe.concurrent(`96% accuracy`, () => {
115
115
  it(`20 messages, no tools`, async () => {
116
116
  await expectTokenEstimate(
117
117
  {
@@ -73,7 +73,7 @@ export class TokenLimiter extends MemoryProcessor {
73
73
 
74
74
  const result: CoreMessage[] = [];
75
75
 
76
- // Process messages in reverse (newest first)
76
+ // Process messages in reverse (newest first) so that we stop estimating tokens on old messages. Once we get to our limit of tokens there's no reason to keep processing older messages
77
77
  for (let i = allMessages.length - 1; i >= 0; i--) {
78
78
  const message = allMessages[i];
79
79
 
@@ -83,8 +83,11 @@ export class TokenLimiter extends MemoryProcessor {
83
83
  const messageTokens = this.countTokens(message);
84
84
 
85
85
  if (totalTokens + messageTokens <= this.maxTokens) {
86
- // Insert at the beginning to maintain chronological order
87
- result.unshift(message);
86
+ // Insert at the beginning to maintain chronological order, but only if it's not a new message
87
+ if (i < messages.length) {
88
+ // less than messages.length because we're iterating in reverse. If the index is greater than messages.length it's a new message
89
+ result.unshift(message);
90
+ }
88
91
  totalTokens += messageTokens;
89
92
  } else {
90
93
  this.logger.info(