@mastra/mongodb 0.10.2-alpha.0 → 0.10.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.
@@ -1,23 +1,23 @@
1
1
 
2
- > @mastra/mongodb@0.10.2-alpha.0 build /home/runner/work/mastra/mastra/stores/mongodb
2
+ > @mastra/mongodb@0.10.2-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.4.0
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 9494ms
9
+ TSC ⚡️ Build success in 8403ms
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 12316ms
16
+ DTS ⚡️ Build success in 12384ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- CJS dist/index.cjs 32.94 KB
21
- CJS ⚡️ Build success in 973ms
22
- ESM dist/index.js 32.83 KB
23
- ESM ⚡️ Build success in 973ms
20
+ ESM dist/index.js 33.01 KB
21
+ ESM ⚡️ Build success in 985ms
22
+ CJS dist/index.cjs 33.13 KB
23
+ CJS ⚡️ Build success in 986ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @mastra/mongodb
2
2
 
3
+ ## 0.10.2-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - c5bf1ce: Add backwards compat code for new MessageList in storage
8
+ - Updated dependencies [c5bf1ce]
9
+ - Updated dependencies [12b7002]
10
+ - @mastra/core@0.10.2-alpha.4
11
+
3
12
  ## 0.10.2-alpha.0
4
13
 
5
14
  ### Patch Changes
@@ -5,9 +5,10 @@ import type { DeleteVectorParams } from '@mastra/core/vector';
5
5
  import type { DescribeIndexParams } from '@mastra/core/vector';
6
6
  import type { EvalRow } from '@mastra/core/storage';
7
7
  import type { IndexStats } from '@mastra/core/vector';
8
+ import type { MastraMessageV1 } from '@mastra/core/memory';
9
+ import type { MastraMessageV2 } from '@mastra/core/memory';
8
10
  import { MastraStorage } from '@mastra/core/storage';
9
11
  import { MastraVector } from '@mastra/core/vector';
10
- import type { MessageType } from '@mastra/core/memory';
11
12
  import type { MongoClientOptions } from 'mongodb';
12
13
  import type { OperatorSupport } from '@mastra/core/vector/filter';
13
14
  import type { QueryResult } from '@mastra/core/vector';
@@ -103,9 +104,14 @@ declare class MongoDBStore extends MastraStorage {
103
104
  threadId: string;
104
105
  }): Promise<void>;
105
106
  getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T[]>;
106
- saveMessages({ messages }: {
107
- messages: MessageType[];
108
- }): Promise<MessageType[]>;
107
+ saveMessages(args: {
108
+ messages: MastraMessageV1[];
109
+ format?: undefined | 'v1';
110
+ }): Promise<MastraMessageV1[]>;
111
+ saveMessages(args: {
112
+ messages: MastraMessageV2[];
113
+ format: 'v2';
114
+ }): Promise<MastraMessageV2[]>;
109
115
  getTraces({ name, scope, page, perPage, attributes, filters, }?: {
110
116
  name?: string;
111
117
  scope?: string;
@@ -5,9 +5,10 @@ import type { DeleteVectorParams } from '@mastra/core/vector';
5
5
  import type { DescribeIndexParams } from '@mastra/core/vector';
6
6
  import type { EvalRow } from '@mastra/core/storage';
7
7
  import type { IndexStats } from '@mastra/core/vector';
8
+ import type { MastraMessageV1 } from '@mastra/core/memory';
9
+ import type { MastraMessageV2 } from '@mastra/core/memory';
8
10
  import { MastraStorage } from '@mastra/core/storage';
9
11
  import { MastraVector } from '@mastra/core/vector';
10
- import type { MessageType } from '@mastra/core/memory';
11
12
  import type { MongoClientOptions } from 'mongodb';
12
13
  import type { OperatorSupport } from '@mastra/core/vector/filter';
13
14
  import type { QueryResult } from '@mastra/core/vector';
@@ -103,9 +104,14 @@ declare class MongoDBStore extends MastraStorage {
103
104
  threadId: string;
104
105
  }): Promise<void>;
105
106
  getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T[]>;
106
- saveMessages({ messages }: {
107
- messages: MessageType[];
108
- }): Promise<MessageType[]>;
107
+ saveMessages(args: {
108
+ messages: MastraMessageV1[];
109
+ format?: undefined | 'v1';
110
+ }): Promise<MastraMessageV1[]>;
111
+ saveMessages(args: {
112
+ messages: MastraMessageV2[];
113
+ format: 'v2';
114
+ }): Promise<MastraMessageV2[]>;
109
115
  getTraces({ name, scope, page, perPage, attributes, filters, }?: {
110
116
  name?: string;
111
117
  scope?: string;
package/dist/index.cjs CHANGED
@@ -4,6 +4,7 @@ var vector = require('@mastra/core/vector');
4
4
  var mongodb = require('mongodb');
5
5
  var uuid = require('uuid');
6
6
  var filter = require('@mastra/core/vector/filter');
7
+ var agent = require('@mastra/core/agent');
7
8
  var storage = require('@mastra/core/storage');
8
9
 
9
10
  // src/vector/index.ts
@@ -628,7 +629,10 @@ var MongoDBStore = class extends storage.MastraStorage {
628
629
  throw error;
629
630
  }
630
631
  }
631
- async saveMessages({ messages }) {
632
+ async saveMessages({
633
+ messages,
634
+ format
635
+ }) {
632
636
  if (!messages.length) {
633
637
  return messages;
634
638
  }
@@ -652,7 +656,9 @@ var MongoDBStore = class extends storage.MastraStorage {
652
656
  });
653
657
  const collection = await this.getCollection(storage.TABLE_MESSAGES);
654
658
  await collection.insertMany(messagesToInsert);
655
- return messages;
659
+ const list = new agent.MessageList().add(messages, "memory");
660
+ if (format === `v2`) return list.get.all.v2();
661
+ return list.get.all.v1();
656
662
  } catch (error) {
657
663
  this.logger.error("Failed to save messages in database: " + error?.message);
658
664
  throw error;
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ import { MastraVector } from '@mastra/core/vector';
2
2
  import { MongoClient } from 'mongodb';
3
3
  import { v4 } from 'uuid';
4
4
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
5
+ import { MessageList } from '@mastra/core/agent';
5
6
  import { MastraStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_TRACES, TABLE_WORKFLOW_SNAPSHOT, TABLE_EVALS } from '@mastra/core/storage';
6
7
 
7
8
  // src/vector/index.ts
@@ -626,7 +627,10 @@ var MongoDBStore = class extends MastraStorage {
626
627
  throw error;
627
628
  }
628
629
  }
629
- async saveMessages({ messages }) {
630
+ async saveMessages({
631
+ messages,
632
+ format
633
+ }) {
630
634
  if (!messages.length) {
631
635
  return messages;
632
636
  }
@@ -650,7 +654,9 @@ var MongoDBStore = class extends MastraStorage {
650
654
  });
651
655
  const collection = await this.getCollection(TABLE_MESSAGES);
652
656
  await collection.insertMany(messagesToInsert);
653
- return messages;
657
+ const list = new MessageList().add(messages, "memory");
658
+ if (format === `v2`) return list.get.all.v2();
659
+ return list.get.all.v1();
654
660
  } catch (error) {
655
661
  this.logger.error("Failed to save messages in database: " + error?.message);
656
662
  throw error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mongodb",
3
- "version": "0.10.2-alpha.0",
3
+ "version": "0.10.2-alpha.1",
4
4
  "description": "MongoDB provider for Mastra - includes vector store capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -32,7 +32,7 @@
32
32
  "typescript": "^5.8.2",
33
33
  "vitest": "^3.1.2",
34
34
  "@internal/lint": "0.0.7",
35
- "@mastra/core": "0.10.2-alpha.2"
35
+ "@mastra/core": "0.10.2-alpha.4"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@mastra/core": "^0.10.0-alpha.0"
@@ -1,5 +1,5 @@
1
1
  import { randomUUID } from 'crypto';
2
- import type { MessageType, MetricResult, WorkflowRunState } from '@mastra/core';
2
+ import type { MastraMessageV1, MetricResult, WorkflowRunState } from '@mastra/core';
3
3
  import { TABLE_EVALS, TABLE_MESSAGES, TABLE_THREADS, TABLE_WORKFLOW_SNAPSHOT } from '@mastra/core/storage';
4
4
  import { afterAll, beforeAll, describe, expect, it } from 'vitest';
5
5
  import type { MongoDBConfig } from './index';
@@ -40,7 +40,7 @@ class Test {
40
40
  };
41
41
  }
42
42
 
43
- generateSampleMessage(threadId: string): MessageType {
43
+ generateSampleMessage(threadId: string): MastraMessageV1 {
44
44
  return {
45
45
  id: `msg-${randomUUID()}`,
46
46
  role: 'user',
@@ -88,6 +88,7 @@ class Test {
88
88
  },
89
89
  input: {},
90
90
  },
91
+ serializedStepGraph: [],
91
92
  activePaths: [],
92
93
  suspendedPaths: {},
93
94
  runId,
@@ -244,7 +245,10 @@ describe('MongoDBStore', () => {
244
245
  const thread = test.generateSampleThread();
245
246
  await store.saveThread({ thread });
246
247
 
247
- const messages = [test.generateSampleMessage(thread.id), test.generateSampleMessage(thread.id)];
248
+ const messages = [
249
+ test.generateSampleMessage(thread.id),
250
+ { ...test.generateSampleMessage(thread.id), role: 'assistant' as const },
251
+ ];
248
252
 
249
253
  // Save messages
250
254
  const savedMessages = await store.saveMessages({ messages });
@@ -274,15 +278,15 @@ describe('MongoDBStore', () => {
274
278
  const messages = [
275
279
  {
276
280
  ...test.generateSampleMessage(thread.id),
277
- content: [{ type: 'text', text: 'First' }] as MessageType['content'],
281
+ content: [{ type: 'text', text: 'First' }] as MastraMessageV1['content'],
278
282
  },
279
283
  {
280
284
  ...test.generateSampleMessage(thread.id),
281
- content: [{ type: 'text', text: 'Second' }] as MessageType['content'],
285
+ content: [{ type: 'text', text: 'Second' }] as MastraMessageV1['content'],
282
286
  },
283
287
  {
284
288
  ...test.generateSampleMessage(thread.id),
285
- content: [{ type: 'text', text: 'Third' }] as MessageType['content'],
289
+ content: [{ type: 'text', text: 'Third' }] as MastraMessageV1['content'],
286
290
  },
287
291
  ];
288
292
 
@@ -479,6 +483,7 @@ describe('MongoDBStore', () => {
479
483
  status: 'waiting',
480
484
  },
481
485
  ],
486
+ serializedStepGraph: [],
482
487
  runId: runId,
483
488
  timestamp: Date.now(),
484
489
  };
@@ -1,5 +1,6 @@
1
+ import { MessageList } from '@mastra/core/agent';
1
2
  import type { MetricResult, TestInfo } from '@mastra/core/eval';
2
- import type { MessageType, StorageThreadType } from '@mastra/core/memory';
3
+ import type { MastraMessageV1, MastraMessageV2, StorageThreadType } from '@mastra/core/memory';
3
4
  import type { EvalRow, StorageGetMessagesArg, TABLE_NAMES, WorkflowRun } from '@mastra/core/storage';
4
5
  import {
5
6
  MastraStorage,
@@ -235,8 +236,8 @@ export class MongoDBStore extends MastraStorage {
235
236
  try {
236
237
  const limit = typeof selectBy?.last === 'number' ? selectBy.last : 40;
237
238
  const include = selectBy?.include || [];
238
- let messages: MessageType[] = [];
239
- let allMessages: MessageType[] = [];
239
+ let messages: MastraMessageV2[] = [];
240
+ let allMessages: MastraMessageV2[] = [];
240
241
  const collection = await this.getCollection(TABLE_MESSAGES);
241
242
  // Get all messages from the thread ordered by creation date descending
242
243
  allMessages = (await collection.find({ thread_id: threadId }).sort({ createdAt: -1 }).toArray()).map((row: any) =>
@@ -270,7 +271,7 @@ export class MongoDBStore extends MastraStorage {
270
271
  messages.push(
271
272
  ...Array.from(selectedIndexes)
272
273
  .map(i => allMessages[i])
273
- .filter((m): m is MessageType => !!m),
274
+ .filter((m): m is MastraMessageV2 => !!m),
274
275
  );
275
276
  }
276
277
 
@@ -293,7 +294,14 @@ export class MongoDBStore extends MastraStorage {
293
294
  }
294
295
  }
295
296
 
296
- async saveMessages({ messages }: { messages: MessageType[] }): Promise<MessageType[]> {
297
+ async saveMessages(args: { messages: MastraMessageV1[]; format?: undefined | 'v1' }): Promise<MastraMessageV1[]>;
298
+ async saveMessages(args: { messages: MastraMessageV2[]; format: 'v2' }): Promise<MastraMessageV2[]>;
299
+ async saveMessages({
300
+ messages,
301
+ format,
302
+ }:
303
+ | { messages: MastraMessageV1[]; format?: undefined | 'v1' }
304
+ | { messages: MastraMessageV2[]; format: 'v2' }): Promise<MastraMessageV2[] | MastraMessageV1[]> {
297
305
  if (!messages.length) {
298
306
  return messages;
299
307
  }
@@ -321,7 +329,9 @@ export class MongoDBStore extends MastraStorage {
321
329
  // Execute all inserts in a single batch
322
330
  const collection = await this.getCollection(TABLE_MESSAGES);
323
331
  await collection.insertMany(messagesToInsert);
324
- return messages;
332
+ const list = new MessageList().add(messages, 'memory');
333
+ if (format === `v2`) return list.get.all.v2();
334
+ return list.get.all.v1();
325
335
  } catch (error) {
326
336
  this.logger.error('Failed to save messages in database: ' + (error as { message: string })?.message);
327
337
  throw error;
@@ -628,7 +638,7 @@ export class MongoDBStore extends MastraStorage {
628
638
  };
629
639
  }
630
640
 
631
- private parseRow(row: any): MessageType {
641
+ private parseRow(row: any): MastraMessageV2 {
632
642
  let content = row.content;
633
643
  try {
634
644
  content = JSON.parse(row.content);
@@ -642,7 +652,7 @@ export class MongoDBStore extends MastraStorage {
642
652
  type: row.type,
643
653
  createdAt: new Date(row.createdAt as string),
644
654
  threadId: row.thread_id,
645
- } as MessageType;
655
+ } as MastraMessageV2;
646
656
  }
647
657
 
648
658
  private transformEvalRow(row: Record<string, any>): EvalRow {