@mastra/mongodb 0.10.3 → 0.11.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,23 +1,23 @@
1
1
 
2
- > @mastra/mongodb@0.10.3-alpha.2 build /home/runner/work/mastra/mastra/stores/mongodb
2
+ > @mastra/mongodb@0.11.0-alpha.1 build /home/runner/work/mastra/mastra/stores/mongodb
3
3
  > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.5.0
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 8293ms
9
+ TSC ⚡️ Build success in 9446ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.8.3
13
13
  Writing package typings: /home/runner/work/mastra/mastra/stores/mongodb/dist/_tsup-dts-rollup.d.ts
14
14
  Analysis will use the bundled TypeScript version 5.8.3
15
15
  Writing package typings: /home/runner/work/mastra/mastra/stores/mongodb/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 11502ms
16
+ DTS ⚡️ Build success in 11998ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- ESM dist/index.js 33.73 KB
21
- ESM ⚡️ Build success in 1207ms
22
- CJS dist/index.cjs 33.85 KB
23
- CJS ⚡️ Build success in 1217ms
20
+ CJS dist/index.cjs 34.07 KB
21
+ CJS ⚡️ Build success in 1119ms
22
+ ESM dist/index.js 33.93 KB
23
+ ESM ⚡️ Build success in 1121ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @mastra/mongodb
2
2
 
3
+ ## 0.11.0-alpha.1
4
+
5
+ ### Minor Changes
6
+
7
+ - 704d1ca: Thread Timestamp Auto-Update Enhancement
8
+ Added automatic thread updatedAt timestamp updates when messages are saved across all storage providers
9
+ Enhanced user experience: Threads now accurately reflect their latest activity with automatic timestamp updates when new messages are added
10
+ Universal implementation: Consistent behavior across all 7 storage backends (ClickHouse, Cloudflare D1, DynamoDB, MongoDB, PostgreSQL, Upstash, LibSQL)
11
+ Performance optimized: Updates execute in parallel with message saving operations for minimal performance impact
12
+ Backwards compatible: No breaking changes - existing code continues to work unchanged
13
+ Improved conversation ordering: Chat interfaces can now properly sort threads by actual last activity
14
+ This enhancement resolves the issue where active conversations appeared stale due to outdated thread timestamps, providing better conversation management and user experience in chat applications.
15
+
16
+ ## 0.10.4-alpha.0
17
+
18
+ ### Patch Changes
19
+
20
+ - 63f6b7d: dependencies updates:
21
+ - Updated dependency [`cloudflare@^4.3.0` ↗︎](https://www.npmjs.com/package/cloudflare/v/4.3.0) (from `^4.1.0`, in `dependencies`)
22
+ - Updated dependency [`mongodb@^6.17.0` ↗︎](https://www.npmjs.com/package/mongodb/v/6.17.0) (from `^6.15.0`, in `dependencies`)
23
+ - Updated dependencies [63f6b7d]
24
+ - Updated dependencies [36f1c36]
25
+ - Updated dependencies [10d352e]
26
+ - Updated dependencies [53d3c37]
27
+ - @mastra/core@0.10.6-alpha.0
28
+
3
29
  ## 0.10.3
4
30
 
5
31
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -669,7 +669,11 @@ var MongoDBStore = class extends storage.MastraStorage {
669
669
  };
670
670
  });
671
671
  const collection = await this.getCollection(storage.TABLE_MESSAGES);
672
- await collection.insertMany(messagesToInsert);
672
+ const threadsCollection = await this.getCollection(storage.TABLE_THREADS);
673
+ await Promise.all([
674
+ collection.insertMany(messagesToInsert),
675
+ threadsCollection.updateOne({ id: threadId }, { $set: { updatedAt: /* @__PURE__ */ new Date() } })
676
+ ]);
673
677
  const list = new agent.MessageList().add(messages, "memory");
674
678
  if (format === `v2`) return list.get.all.v2();
675
679
  return list.get.all.v1();
package/dist/index.js CHANGED
@@ -667,7 +667,11 @@ var MongoDBStore = class extends MastraStorage {
667
667
  };
668
668
  });
669
669
  const collection = await this.getCollection(TABLE_MESSAGES);
670
- await collection.insertMany(messagesToInsert);
670
+ const threadsCollection = await this.getCollection(TABLE_THREADS);
671
+ await Promise.all([
672
+ collection.insertMany(messagesToInsert),
673
+ threadsCollection.updateOne({ id: threadId }, { $set: { updatedAt: /* @__PURE__ */ new Date() } })
674
+ ]);
671
675
  const list = new MessageList().add(messages, "memory");
672
676
  if (format === `v2`) return list.get.all.v2();
673
677
  return list.get.all.v1();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mongodb",
3
- "version": "0.10.3",
3
+ "version": "0.11.0-alpha.1",
4
4
  "description": "MongoDB provider for Mastra - includes vector store capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -20,20 +20,20 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@types/mongodb": "^4.0.7",
23
- "cloudflare": "^4.1.0",
24
- "mongodb": "^6.15.0",
23
+ "cloudflare": "^4.3.0",
24
+ "mongodb": "^6.17.0",
25
25
  "uuid": "^11.1.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@microsoft/api-extractor": "^7.52.8",
29
- "@types/node": "^20.17.57",
29
+ "@types/node": "^20.19.0",
30
30
  "eslint": "^9.28.0",
31
31
  "tsup": "^8.5.0",
32
- "typescript": "^5.8.2",
33
- "vitest": "^3.2.2",
34
- "@internal/lint": "0.0.11",
35
- "@internal/storage-test-utils": "0.0.7",
36
- "@mastra/core": "0.10.4"
32
+ "typescript": "^5.8.3",
33
+ "vitest": "^3.2.3",
34
+ "@internal/lint": "0.0.12",
35
+ "@internal/storage-test-utils": "0.0.8",
36
+ "@mastra/core": "0.10.6-alpha.0"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@mastra/core": ">=0.10.4-0 <0.11.0"
@@ -125,6 +125,7 @@ class Test {
125
125
  suspendedPaths: {},
126
126
  runId,
127
127
  timestamp: timestamp.getTime(),
128
+ status: options.status,
128
129
  } as WorkflowRunState;
129
130
  return { snapshot, runId, stepId };
130
131
  }
@@ -271,6 +272,27 @@ describe('MongoDBStore', () => {
271
272
  expect(retrievedThread?.title).toBe('Updated Title');
272
273
  expect(retrievedThread?.metadata).toEqual({ key: 'newValue' });
273
274
  });
275
+
276
+ it('should update thread updatedAt when a message is saved to it', async () => {
277
+ const test = new Test(store).build();
278
+ await test.clearTables();
279
+
280
+ const thread = test.generateSampleThread();
281
+ await store.saveThread({ thread });
282
+
283
+ const initialThread = await store.getThreadById({ threadId: thread.id });
284
+ expect(initialThread).toBeDefined();
285
+ const originalUpdatedAt = initialThread!.updatedAt;
286
+
287
+ await new Promise(resolve => setTimeout(resolve, 10));
288
+
289
+ const message = test.generateSampleMessageV1({ threadId: thread.id });
290
+ await store.saveMessages({ messages: [message] });
291
+
292
+ const updatedThread = await store.getThreadById({ threadId: thread.id });
293
+ expect(updatedThread).toBeDefined();
294
+ expect(updatedThread!.updatedAt.getTime()).toBeGreaterThan(originalUpdatedAt.getTime());
295
+ });
274
296
  });
275
297
 
276
298
  describe('Message Operations', () => {
@@ -620,6 +642,7 @@ describe('MongoDBStore', () => {
620
642
  ],
621
643
  serializedStepGraph: [],
622
644
  runId: runId,
645
+ status: 'running',
623
646
  timestamp: Date.now(),
624
647
  };
625
648
 
@@ -344,6 +344,7 @@ export class MongoDBStore extends MastraStorage {
344
344
  this.logger.error('Thread ID is required to save messages');
345
345
  throw new Error('Thread ID is required');
346
346
  }
347
+
347
348
  try {
348
349
  // Prepare batch statements for all messages
349
350
  const messagesToInsert = messages.map(message => {
@@ -359,9 +360,15 @@ export class MongoDBStore extends MastraStorage {
359
360
  };
360
361
  });
361
362
 
362
- // Execute all inserts in a single batch
363
+ // Execute message inserts and thread update in parallel for better performance
363
364
  const collection = await this.getCollection(TABLE_MESSAGES);
364
- await collection.insertMany(messagesToInsert);
365
+ const threadsCollection = await this.getCollection(TABLE_THREADS);
366
+
367
+ await Promise.all([
368
+ collection.insertMany(messagesToInsert),
369
+ threadsCollection.updateOne({ id: threadId }, { $set: { updatedAt: new Date() } }),
370
+ ]);
371
+
365
372
  const list = new MessageList().add(messages, 'memory');
366
373
  if (format === `v2`) return list.get.all.v2();
367
374
  return list.get.all.v1();