@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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export * from './vector';
2
- export * from './storage';
3
- export * from './storage/connectors/base';
4
- export { MONGODB_PROMPT } from './vector/prompt';
1
+ export * from './vector/index.js';
2
+ export * from './storage/index.js';
3
+ export * from './storage/connectors/base.js';
4
+ export { MONGODB_PROMPT } from './vector/prompt.js';
5
5
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -324,11 +324,12 @@ var MongoDBVector = class extends MastraVector {
324
324
  const indexNameInternal = `${indexName}_vector_index`;
325
325
  const mongoFilter = this.transformFilter(filter);
326
326
  const documentMongoFilter = documentFilter ? { [this.documentFieldName]: documentFilter } : {};
327
+ const transformedMongoFilter = this.transformMetadataFilter(mongoFilter);
327
328
  let combinedFilter = {};
328
- if (Object.keys(mongoFilter).length > 0 && Object.keys(documentMongoFilter).length > 0) {
329
- combinedFilter = { $and: [mongoFilter, documentMongoFilter] };
330
- } else if (Object.keys(mongoFilter).length > 0) {
331
- combinedFilter = mongoFilter;
329
+ if (Object.keys(transformedMongoFilter).length > 0 && Object.keys(documentMongoFilter).length > 0) {
330
+ combinedFilter = { $and: [transformedMongoFilter, documentMongoFilter] };
331
+ } else if (Object.keys(transformedMongoFilter).length > 0) {
332
+ combinedFilter = transformedMongoFilter;
332
333
  } else if (Object.keys(documentMongoFilter).length > 0) {
333
334
  combinedFilter = documentMongoFilter;
334
335
  }
@@ -343,6 +344,8 @@ var MongoDBVector = class extends MastraVector {
343
344
  const candidateIds = await collection.aggregate([{ $match: combinedFilter }, { $project: { _id: 1 } }]).map((doc) => doc._id).toArray();
344
345
  if (candidateIds.length > 0) {
345
346
  vectorSearch.filter = { _id: { $in: candidateIds } };
347
+ } else {
348
+ return [];
346
349
  }
347
350
  }
348
351
  const pipeline = [
@@ -565,6 +568,45 @@ var MongoDBVector = class extends MastraVector {
565
568
  if (!filter) return {};
566
569
  return translator.translate(filter);
567
570
  }
571
+ /**
572
+ * Transform metadata field filters to use MongoDB dot notation.
573
+ * Fields that are stored in the metadata subdocument need to be prefixed with 'metadata.'
574
+ * This handles filters from the Memory system which expects direct field access.
575
+ *
576
+ * @param filter - The filter object to transform
577
+ * @returns Transformed filter with metadata fields properly prefixed
578
+ */
579
+ transformMetadataFilter(filter) {
580
+ if (!filter || typeof filter !== "object") return filter;
581
+ const transformed = {};
582
+ for (const [key, value] of Object.entries(filter)) {
583
+ if (key.startsWith("$")) {
584
+ if (Array.isArray(value)) {
585
+ transformed[key] = value.map((item) => this.transformMetadataFilter(item));
586
+ } else {
587
+ transformed[key] = this.transformMetadataFilter(value);
588
+ }
589
+ } else if (key.startsWith("metadata.")) {
590
+ transformed[key] = value;
591
+ } else if (this.isMetadataField(key)) {
592
+ transformed[`metadata.${key}`] = value;
593
+ } else {
594
+ transformed[key] = value;
595
+ }
596
+ }
597
+ return transformed;
598
+ }
599
+ /**
600
+ * Determine if a field should be treated as a metadata field.
601
+ * Common metadata fields include thread_id, resource_id, message_id, and any field
602
+ * that doesn't start with underscore (MongoDB system fields).
603
+ */
604
+ isMetadataField(key) {
605
+ if (key.startsWith("_")) return false;
606
+ const documentFields = ["_id", this.embeddingFieldName, this.documentFieldName];
607
+ if (documentFields.includes(key)) return false;
608
+ return true;
609
+ }
568
610
  };
569
611
  var MongoDBConnector = class _MongoDBConnector {
570
612
  #client;
@@ -881,6 +923,29 @@ var MemoryStorageMongoDB = class extends MemoryStorage {
881
923
  );
882
924
  }
883
925
  }
926
+ async getMessagesById({
927
+ messageIds,
928
+ format
929
+ }) {
930
+ if (messageIds.length === 0) return [];
931
+ try {
932
+ const collection = await this.operations.getCollection(TABLE_MESSAGES);
933
+ const rawMessages = await collection.find({ id: { $in: messageIds } }).sort({ createdAt: -1 }).toArray();
934
+ const list = new MessageList().add(rawMessages.map(this.parseRow), "memory");
935
+ if (format === `v1`) return list.get.all.v1();
936
+ return list.get.all.v2();
937
+ } catch (error) {
938
+ throw new MastraError(
939
+ {
940
+ id: "MONGODB_STORE_GET_MESSAGES_BY_ID_FAILED",
941
+ domain: ErrorDomain.STORAGE,
942
+ category: ErrorCategory.THIRD_PARTY,
943
+ details: { messageIds: JSON.stringify(messageIds) }
944
+ },
945
+ error
946
+ );
947
+ }
948
+ }
884
949
  async getMessagesPaginated(args) {
885
950
  const { threadId, format, selectBy } = args;
886
951
  const { page = 0, perPage: perPageInput, dateRange } = selectBy?.pagination || {};
@@ -1490,12 +1555,12 @@ function transformScoreRow(row) {
1490
1555
  console.warn("Failed to parse scorer:", e);
1491
1556
  }
1492
1557
  }
1493
- let extractStepResultValue = null;
1494
- if (row.extractStepResult) {
1558
+ let preprocessStepResultValue = null;
1559
+ if (row.preprocessStepResult) {
1495
1560
  try {
1496
- extractStepResultValue = typeof row.extractStepResult === "string" ? safelyParseJSON(row.extractStepResult) : row.extractStepResult;
1561
+ preprocessStepResultValue = typeof row.preprocessStepResult === "string" ? safelyParseJSON(row.preprocessStepResult) : row.preprocessStepResult;
1497
1562
  } catch (e) {
1498
- console.warn("Failed to parse extractStepResult:", e);
1563
+ console.warn("Failed to parse preprocessStepResult:", e);
1499
1564
  }
1500
1565
  }
1501
1566
  let analyzeStepResultValue = null;
@@ -1546,7 +1611,7 @@ function transformScoreRow(row) {
1546
1611
  traceId: row.traceId,
1547
1612
  runId: row.runId,
1548
1613
  scorer: scorerValue,
1549
- extractStepResult: extractStepResultValue,
1614
+ preprocessStepResult: preprocessStepResultValue,
1550
1615
  analyzeStepResult: analyzeStepResultValue,
1551
1616
  score: row.score,
1552
1617
  reason: row.reason,
@@ -1603,11 +1668,13 @@ var ScoresStorageMongoDB = class extends ScoresStorage {
1603
1668
  traceId: score.traceId || "",
1604
1669
  runId: score.runId,
1605
1670
  scorer: typeof score.scorer === "string" ? safelyParseJSON(score.scorer) : score.scorer,
1606
- extractStepResult: typeof score.extractStepResult === "string" ? safelyParseJSON(score.extractStepResult) : score.extractStepResult,
1671
+ preprocessStepResult: typeof score.preprocessStepResult === "string" ? safelyParseJSON(score.preprocessStepResult) : score.preprocessStepResult,
1607
1672
  analyzeStepResult: typeof score.analyzeStepResult === "string" ? safelyParseJSON(score.analyzeStepResult) : score.analyzeStepResult,
1608
1673
  score: score.score,
1609
1674
  reason: score.reason,
1610
- extractPrompt: score.extractPrompt,
1675
+ preprocessPrompt: score.preprocessPrompt,
1676
+ generateScorePrompt: score.generateScorePrompt,
1677
+ generateReasonPrompt: score.generateReasonPrompt,
1611
1678
  analyzePrompt: score.analyzePrompt,
1612
1679
  reasonPrompt: score.reasonPrompt,
1613
1680
  input: typeof score.input === "string" ? safelyParseJSON(score.input) : score.input,
@@ -1646,7 +1713,8 @@ var ScoresStorageMongoDB = class extends ScoresStorage {
1646
1713
  scorerId,
1647
1714
  pagination,
1648
1715
  entityId,
1649
- entityType
1716
+ entityType,
1717
+ source
1650
1718
  }) {
1651
1719
  try {
1652
1720
  const query = { scorerId };
@@ -1656,6 +1724,9 @@ var ScoresStorageMongoDB = class extends ScoresStorage {
1656
1724
  if (entityType) {
1657
1725
  query.entityType = entityType;
1658
1726
  }
1727
+ if (source) {
1728
+ query.source = source;
1729
+ }
1659
1730
  const collection = await this.operations.getCollection(TABLE_SCORERS);
1660
1731
  const total = await collection.countDocuments(query);
1661
1732
  const currentOffset = pagination.page * pagination.perPage;
@@ -2185,6 +2256,12 @@ var MongoDBStore = class extends MastraStorage {
2185
2256
  }) {
2186
2257
  return this.stores.memory.getMessages({ threadId, selectBy, format });
2187
2258
  }
2259
+ async getMessagesById({
2260
+ messageIds,
2261
+ format
2262
+ }) {
2263
+ return this.stores.memory.getMessagesById({ messageIds, format });
2264
+ }
2188
2265
  async saveMessages(args) {
2189
2266
  return this.stores.memory.saveMessages(args);
2190
2267
  }
@@ -2271,9 +2348,10 @@ var MongoDBStore = class extends MastraStorage {
2271
2348
  scorerId,
2272
2349
  pagination,
2273
2350
  entityId,
2274
- entityType
2351
+ entityType,
2352
+ source
2275
2353
  }) {
2276
- return this.stores.scores.getScoresByScorerId({ scorerId, pagination, entityId, entityType });
2354
+ return this.stores.scores.getScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
2277
2355
  }
2278
2356
  /**
2279
2357
  * RESOURCES