@mastra/mongodb 0.0.0-zod-v4-compat-part-2-20250820135355 → 0.0.0-zod-v4-stuff-20250825154219

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.
package/CHANGELOG.md CHANGED
@@ -1,14 +1,159 @@
1
1
  # @mastra/mongodb
2
2
 
3
- ## 0.0.0-zod-v4-compat-part-2-20250820135355
3
+ ## 0.0.0-zod-v4-stuff-20250825154219
4
4
 
5
5
  ### Patch Changes
6
6
 
7
+ - Updated dependencies [[`0778757`](https://github.com/mastra-ai/mastra/commit/07787570e4addbd501522037bd2542c3d9e26822), [`bf504a8`](https://github.com/mastra-ai/mastra/commit/bf504a833051f6f321d832cc7d631f3cb86d657b), [`e6f5046`](https://github.com/mastra-ai/mastra/commit/e6f50467aff317e67e8bd74c485c3fbe2a5a6db1), [`d51eac2`](https://github.com/mastra-ai/mastra/commit/d51eac24ba0fbb33d3e22dcc310f9c0e7167598d), [`9613558`](https://github.com/mastra-ai/mastra/commit/9613558e6475f4710e05d1be7553a32ee7bddc20)]:
8
+ - @mastra/core@0.0.0-zod-v4-stuff-20250825154219
9
+
10
+ ## 0.13.3
11
+
12
+ ### Patch Changes
13
+
14
+ - [#6700](https://github.com/mastra-ai/mastra/pull/6700) [`a5a23d9`](https://github.com/mastra-ai/mastra/commit/a5a23d981920d458dc6078919992a5338931ef02) Thanks [@gpanakkal](https://github.com/gpanakkal)! - Add `getMessagesById` method to `MastraStorage` adapters
15
+
16
+ - Updated dependencies [[`6e7e120`](https://github.com/mastra-ai/mastra/commit/6e7e1207d6e8d8b838f9024f90bd10df1181ba27), [`0f00e17`](https://github.com/mastra-ai/mastra/commit/0f00e172953ccdccadb35ed3d70f5e4d89115869), [`217cd7a`](https://github.com/mastra-ai/mastra/commit/217cd7a4ce171e9a575c41bb8c83300f4db03236), [`a5a23d9`](https://github.com/mastra-ai/mastra/commit/a5a23d981920d458dc6078919992a5338931ef02)]:
17
+ - @mastra/core@0.14.1
18
+
19
+ ## 0.13.3-alpha.0
20
+
21
+ ### Patch Changes
22
+
23
+ - [#6700](https://github.com/mastra-ai/mastra/pull/6700) [`a5a23d9`](https://github.com/mastra-ai/mastra/commit/a5a23d981920d458dc6078919992a5338931ef02) Thanks [@gpanakkal](https://github.com/gpanakkal)! - Add `getMessagesById` method to `MastraStorage` adapters
24
+
25
+ - Updated dependencies [[`6e7e120`](https://github.com/mastra-ai/mastra/commit/6e7e1207d6e8d8b838f9024f90bd10df1181ba27), [`a5a23d9`](https://github.com/mastra-ai/mastra/commit/a5a23d981920d458dc6078919992a5338931ef02)]:
26
+ - @mastra/core@0.14.1-alpha.0
27
+
28
+ ## 0.13.2
29
+
30
+ ### Patch Changes
31
+
32
+ - 03997ae: Update peerdeps
33
+ - Updated dependencies [227c7e6]
34
+ - Updated dependencies [12cae67]
35
+ - Updated dependencies [fd3a3eb]
36
+ - Updated dependencies [6faaee5]
37
+ - Updated dependencies [4232b14]
38
+ - Updated dependencies [a89de7e]
39
+ - Updated dependencies [5a37d0c]
40
+ - Updated dependencies [4bde0cb]
41
+ - Updated dependencies [cf4f357]
42
+ - Updated dependencies [ad888a2]
43
+ - Updated dependencies [481751d]
44
+ - Updated dependencies [2454423]
45
+ - Updated dependencies [194e395]
46
+ - Updated dependencies [a722c0b]
47
+ - Updated dependencies [c30bca8]
48
+ - Updated dependencies [3b5fec7]
49
+ - Updated dependencies [a8f129d]
50
+ - @mastra/core@0.14.0
51
+
52
+ ## 0.13.2-alpha.0
53
+
54
+ ### Patch Changes
55
+
56
+ - 03997ae: Update peerdeps
57
+ - @mastra/core@0.14.0-alpha.7
58
+
59
+ ## 0.13.1
60
+
61
+ ### Patch Changes
62
+
63
+ - b32c50d: Filter scores by source
64
+ - Updated dependencies [d5330bf]
65
+ - Updated dependencies [2e74797]
66
+ - Updated dependencies [8388649]
67
+ - Updated dependencies [a239d41]
68
+ - Updated dependencies [dd94a26]
69
+ - Updated dependencies [3ba6772]
70
+ - Updated dependencies [b5cf2a3]
71
+ - Updated dependencies [2fff911]
72
+ - Updated dependencies [b32c50d]
73
+ - Updated dependencies [63449d0]
74
+ - Updated dependencies [121a3f8]
75
+ - Updated dependencies [ec510e7]
76
+ - @mastra/core@0.13.2
77
+
78
+ ## 0.13.1-alpha.0
79
+
80
+ ### Patch Changes
81
+
82
+ - b32c50d: Filter scores by source
83
+ - Updated dependencies [d5330bf]
84
+ - Updated dependencies [a239d41]
85
+ - Updated dependencies [b32c50d]
86
+ - Updated dependencies [121a3f8]
87
+ - Updated dependencies [ec510e7]
88
+ - @mastra/core@0.13.2-alpha.2
89
+
90
+ ## 0.13.0
91
+
92
+ ### Minor Changes
93
+
94
+ - ea0c5f2: Add store support to new score api
95
+
96
+ ### Patch Changes
97
+
98
+ - 494ceac: fix: trace mongo safeparse
99
+ - 2871020: update safelyParseJSON to check for value of param when handling parse
100
+ - 4a406ec: fixes TypeScript declaration file imports to ensure proper ESM compatibility
101
+ - 94baf89: fixed an issue where mongodb vector adapter would not properly use metadata filters
102
+ - Updated dependencies [cb36de0]
103
+ - Updated dependencies [d0496e6]
104
+ - Updated dependencies [a82b851]
105
+ - Updated dependencies [ea0c5f2]
106
+ - Updated dependencies [41a0a0e]
107
+ - Updated dependencies [2871020]
7
108
  - Updated dependencies [94f4812]
8
109
  - Updated dependencies [e202b82]
9
110
  - Updated dependencies [e00f6a0]
111
+ - Updated dependencies [4a406ec]
112
+ - Updated dependencies [b0e43c1]
113
+ - Updated dependencies [5d377e5]
114
+ - Updated dependencies [1fb812e]
115
+ - Updated dependencies [35c5798]
116
+ - @mastra/core@0.13.0
117
+
118
+ ## 0.13.0-alpha.3
119
+
120
+ ### Patch Changes
121
+
122
+ - 94baf89: fixed an issue where mongodb vector adapter would not properly use metadata filters
123
+
124
+ ## 0.13.0-alpha.2
125
+
126
+ ### Patch Changes
127
+
128
+ - 2871020: update safelyParseJSON to check for value of param when handling parse
129
+ - 4a406ec: fixes TypeScript declaration file imports to ensure proper ESM compatibility
130
+ - Updated dependencies [cb36de0]
131
+ - Updated dependencies [a82b851]
132
+ - Updated dependencies [41a0a0e]
133
+ - Updated dependencies [2871020]
134
+ - Updated dependencies [4a406ec]
135
+ - Updated dependencies [5d377e5]
136
+ - @mastra/core@0.13.0-alpha.2
137
+
138
+ ## 0.13.0-alpha.1
139
+
140
+ ### Patch Changes
141
+
142
+ - 494ceac: fix: trace mongo safeparse
143
+
144
+ ## 0.13.0-alpha.0
145
+
146
+ ### Minor Changes
147
+
148
+ - ea0c5f2: Add store support to new score api
149
+
150
+ ### Patch Changes
151
+
152
+ - Updated dependencies [ea0c5f2]
153
+ - Updated dependencies [b0e43c1]
154
+ - Updated dependencies [1fb812e]
10
155
  - Updated dependencies [35c5798]
11
- - @mastra/core@0.0.0-zod-v4-compat-part-2-20250820135355
156
+ - @mastra/core@0.13.0-alpha.1
12
157
 
13
158
  ## 0.12.4
14
159
 
package/dist/index.cjs CHANGED
@@ -326,11 +326,12 @@ var MongoDBVector = class extends vector.MastraVector {
326
326
  const indexNameInternal = `${indexName}_vector_index`;
327
327
  const mongoFilter = this.transformFilter(filter);
328
328
  const documentMongoFilter = documentFilter ? { [this.documentFieldName]: documentFilter } : {};
329
+ const transformedMongoFilter = this.transformMetadataFilter(mongoFilter);
329
330
  let combinedFilter = {};
330
- if (Object.keys(mongoFilter).length > 0 && Object.keys(documentMongoFilter).length > 0) {
331
- combinedFilter = { $and: [mongoFilter, documentMongoFilter] };
332
- } else if (Object.keys(mongoFilter).length > 0) {
333
- combinedFilter = mongoFilter;
331
+ if (Object.keys(transformedMongoFilter).length > 0 && Object.keys(documentMongoFilter).length > 0) {
332
+ combinedFilter = { $and: [transformedMongoFilter, documentMongoFilter] };
333
+ } else if (Object.keys(transformedMongoFilter).length > 0) {
334
+ combinedFilter = transformedMongoFilter;
334
335
  } else if (Object.keys(documentMongoFilter).length > 0) {
335
336
  combinedFilter = documentMongoFilter;
336
337
  }
@@ -345,6 +346,8 @@ var MongoDBVector = class extends vector.MastraVector {
345
346
  const candidateIds = await collection.aggregate([{ $match: combinedFilter }, { $project: { _id: 1 } }]).map((doc) => doc._id).toArray();
346
347
  if (candidateIds.length > 0) {
347
348
  vectorSearch.filter = { _id: { $in: candidateIds } };
349
+ } else {
350
+ return [];
348
351
  }
349
352
  }
350
353
  const pipeline = [
@@ -567,6 +570,45 @@ var MongoDBVector = class extends vector.MastraVector {
567
570
  if (!filter) return {};
568
571
  return translator.translate(filter);
569
572
  }
573
+ /**
574
+ * Transform metadata field filters to use MongoDB dot notation.
575
+ * Fields that are stored in the metadata subdocument need to be prefixed with 'metadata.'
576
+ * This handles filters from the Memory system which expects direct field access.
577
+ *
578
+ * @param filter - The filter object to transform
579
+ * @returns Transformed filter with metadata fields properly prefixed
580
+ */
581
+ transformMetadataFilter(filter) {
582
+ if (!filter || typeof filter !== "object") return filter;
583
+ const transformed = {};
584
+ for (const [key, value] of Object.entries(filter)) {
585
+ if (key.startsWith("$")) {
586
+ if (Array.isArray(value)) {
587
+ transformed[key] = value.map((item) => this.transformMetadataFilter(item));
588
+ } else {
589
+ transformed[key] = this.transformMetadataFilter(value);
590
+ }
591
+ } else if (key.startsWith("metadata.")) {
592
+ transformed[key] = value;
593
+ } else if (this.isMetadataField(key)) {
594
+ transformed[`metadata.${key}`] = value;
595
+ } else {
596
+ transformed[key] = value;
597
+ }
598
+ }
599
+ return transformed;
600
+ }
601
+ /**
602
+ * Determine if a field should be treated as a metadata field.
603
+ * Common metadata fields include thread_id, resource_id, message_id, and any field
604
+ * that doesn't start with underscore (MongoDB system fields).
605
+ */
606
+ isMetadataField(key) {
607
+ if (key.startsWith("_")) return false;
608
+ const documentFields = ["_id", this.embeddingFieldName, this.documentFieldName];
609
+ if (documentFields.includes(key)) return false;
610
+ return true;
611
+ }
570
612
  };
571
613
  var MongoDBConnector = class _MongoDBConnector {
572
614
  #client;
@@ -883,6 +925,29 @@ var MemoryStorageMongoDB = class extends storage.MemoryStorage {
883
925
  );
884
926
  }
885
927
  }
928
+ async getMessagesById({
929
+ messageIds,
930
+ format
931
+ }) {
932
+ if (messageIds.length === 0) return [];
933
+ try {
934
+ const collection = await this.operations.getCollection(storage.TABLE_MESSAGES);
935
+ const rawMessages = await collection.find({ id: { $in: messageIds } }).sort({ createdAt: -1 }).toArray();
936
+ const list = new agent.MessageList().add(rawMessages.map(this.parseRow), "memory");
937
+ if (format === `v1`) return list.get.all.v1();
938
+ return list.get.all.v2();
939
+ } catch (error$1) {
940
+ throw new error.MastraError(
941
+ {
942
+ id: "MONGODB_STORE_GET_MESSAGES_BY_ID_FAILED",
943
+ domain: error.ErrorDomain.STORAGE,
944
+ category: error.ErrorCategory.THIRD_PARTY,
945
+ details: { messageIds: JSON.stringify(messageIds) }
946
+ },
947
+ error$1
948
+ );
949
+ }
950
+ }
886
951
  async getMessagesPaginated(args) {
887
952
  const { threadId, format, selectBy } = args;
888
953
  const { page = 0, perPage: perPageInput, dateRange } = selectBy?.pagination || {};
@@ -1492,12 +1557,12 @@ function transformScoreRow(row) {
1492
1557
  console.warn("Failed to parse scorer:", e);
1493
1558
  }
1494
1559
  }
1495
- let extractStepResultValue = null;
1496
- if (row.extractStepResult) {
1560
+ let preprocessStepResultValue = null;
1561
+ if (row.preprocessStepResult) {
1497
1562
  try {
1498
- extractStepResultValue = typeof row.extractStepResult === "string" ? storage.safelyParseJSON(row.extractStepResult) : row.extractStepResult;
1563
+ preprocessStepResultValue = typeof row.preprocessStepResult === "string" ? storage.safelyParseJSON(row.preprocessStepResult) : row.preprocessStepResult;
1499
1564
  } catch (e) {
1500
- console.warn("Failed to parse extractStepResult:", e);
1565
+ console.warn("Failed to parse preprocessStepResult:", e);
1501
1566
  }
1502
1567
  }
1503
1568
  let analyzeStepResultValue = null;
@@ -1548,7 +1613,7 @@ function transformScoreRow(row) {
1548
1613
  traceId: row.traceId,
1549
1614
  runId: row.runId,
1550
1615
  scorer: scorerValue,
1551
- extractStepResult: extractStepResultValue,
1616
+ preprocessStepResult: preprocessStepResultValue,
1552
1617
  analyzeStepResult: analyzeStepResultValue,
1553
1618
  score: row.score,
1554
1619
  reason: row.reason,
@@ -1605,11 +1670,13 @@ var ScoresStorageMongoDB = class extends storage.ScoresStorage {
1605
1670
  traceId: score.traceId || "",
1606
1671
  runId: score.runId,
1607
1672
  scorer: typeof score.scorer === "string" ? storage.safelyParseJSON(score.scorer) : score.scorer,
1608
- extractStepResult: typeof score.extractStepResult === "string" ? storage.safelyParseJSON(score.extractStepResult) : score.extractStepResult,
1673
+ preprocessStepResult: typeof score.preprocessStepResult === "string" ? storage.safelyParseJSON(score.preprocessStepResult) : score.preprocessStepResult,
1609
1674
  analyzeStepResult: typeof score.analyzeStepResult === "string" ? storage.safelyParseJSON(score.analyzeStepResult) : score.analyzeStepResult,
1610
1675
  score: score.score,
1611
1676
  reason: score.reason,
1612
- extractPrompt: score.extractPrompt,
1677
+ preprocessPrompt: score.preprocessPrompt,
1678
+ generateScorePrompt: score.generateScorePrompt,
1679
+ generateReasonPrompt: score.generateReasonPrompt,
1613
1680
  analyzePrompt: score.analyzePrompt,
1614
1681
  reasonPrompt: score.reasonPrompt,
1615
1682
  input: typeof score.input === "string" ? storage.safelyParseJSON(score.input) : score.input,
@@ -1648,7 +1715,8 @@ var ScoresStorageMongoDB = class extends storage.ScoresStorage {
1648
1715
  scorerId,
1649
1716
  pagination,
1650
1717
  entityId,
1651
- entityType
1718
+ entityType,
1719
+ source
1652
1720
  }) {
1653
1721
  try {
1654
1722
  const query = { scorerId };
@@ -1658,6 +1726,9 @@ var ScoresStorageMongoDB = class extends storage.ScoresStorage {
1658
1726
  if (entityType) {
1659
1727
  query.entityType = entityType;
1660
1728
  }
1729
+ if (source) {
1730
+ query.source = source;
1731
+ }
1661
1732
  const collection = await this.operations.getCollection(storage.TABLE_SCORERS);
1662
1733
  const total = await collection.countDocuments(query);
1663
1734
  const currentOffset = pagination.page * pagination.perPage;
@@ -2187,6 +2258,12 @@ var MongoDBStore = class extends storage.MastraStorage {
2187
2258
  }) {
2188
2259
  return this.stores.memory.getMessages({ threadId, selectBy, format });
2189
2260
  }
2261
+ async getMessagesById({
2262
+ messageIds,
2263
+ format
2264
+ }) {
2265
+ return this.stores.memory.getMessagesById({ messageIds, format });
2266
+ }
2190
2267
  async saveMessages(args) {
2191
2268
  return this.stores.memory.saveMessages(args);
2192
2269
  }
@@ -2273,9 +2350,10 @@ var MongoDBStore = class extends storage.MastraStorage {
2273
2350
  scorerId,
2274
2351
  pagination,
2275
2352
  entityId,
2276
- entityType
2353
+ entityType,
2354
+ source
2277
2355
  }) {
2278
- return this.stores.scores.getScoresByScorerId({ scorerId, pagination, entityId, entityType });
2356
+ return this.stores.scores.getScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
2279
2357
  }
2280
2358
  /**
2281
2359
  * RESOURCES