@mastra/mongodb 1.20.0 → 1.20.1-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.
@@ -3,7 +3,7 @@ name: mastra-mongodb
3
3
  description: Documentation for @mastra/mongodb. Use when working with @mastra/mongodb APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/mongodb"
6
- version: "1.20.0"
6
+ version: "1.20.1-alpha.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.20.0",
2
+ "version": "1.20.1-alpha.1",
3
3
  "package": "@mastra/mongodb",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -5,12 +5,11 @@ let _mastra_core_storage = require("@mastra/core/storage");
5
5
  let _mastra_core_vector = require("@mastra/core/vector");
6
6
  let mongodb = require("mongodb");
7
7
  let _mastra_core_vector_filter = require("@mastra/core/vector/filter");
8
- let crypto$1 = require("crypto");
9
8
  let _mastra_core_agent = require("@mastra/core/agent");
10
9
  let _mastra_core_evals = require("@mastra/core/evals");
11
10
  let _mastra_core_storage_domains_skills = require("@mastra/core/storage/domains/skills");
12
11
  //#region package.json
13
- var version = "1.20.0";
12
+ var version = "1.20.1-alpha.1";
14
13
  //#endregion
15
14
  //#region src/vector/filter.ts
16
15
  /**
@@ -1020,7 +1019,7 @@ var MongoDBVector = class MongoDBVector extends _mastra_core_vector.MastraVector
1020
1019
  declaredPaths = /* @__PURE__ */ new Set();
1021
1020
  }
1022
1021
  const pushMetadata = !hasMetadataFilter || this.canPushDownFilter(metadataFilter, declaredPaths);
1023
- const pushDocument = !documentFilterExpr || !autoEmbed && (!verifyDocumentPath || declaredPaths.has(documentTextField));
1022
+ const pushDocument = !documentFilterExpr || !autoEmbed && (!verifyDocumentPath || declaredPaths.has(documentTextField)) && this.canPushDownFilter(documentFilter, /* @__PURE__ */ new Set());
1024
1023
  const pushed = [...hasMetadataFilter && pushMetadata ? [metadataFilter] : [], ...documentFilterExpr && pushDocument ? [documentFilterExpr] : []];
1025
1024
  if (!pushMetadata || !pushDocument) {
1026
1025
  const preFilter = [...hasMetadataFilter && !pushMetadata ? [metadataFilter] : [], ...documentFilterExpr && !pushDocument ? [documentFilterExpr] : []];
@@ -1433,6 +1432,7 @@ var MongoDBVector = class MongoDBVector extends _mastra_core_vector.MastraVector
1433
1432
  */
1434
1433
  canPushDownFilter(filter, declaredPaths) {
1435
1434
  if (filter === null || typeof filter !== "object") return true;
1435
+ if (filter instanceof RegExp) return false;
1436
1436
  if (Array.isArray(filter)) return filter.every((item) => this.canPushDownFilter(item, declaredPaths));
1437
1437
  for (const [key, value] of Object.entries(filter)) {
1438
1438
  if (key.startsWith("$")) {
@@ -1844,7 +1844,7 @@ var MongoDBAgentsStorage = class MongoDBAgentsStorage extends _mastra_core_stora
1844
1844
  };
1845
1845
  const { id: _id, authorId: _authorId, visibility: _visibility, metadata: _metadata, ...snapshotConfig } = agent;
1846
1846
  const versionDoc = {
1847
- id: (0, crypto$1.randomUUID)(),
1847
+ id: globalThis.crypto.randomUUID(),
1848
1848
  agentId: agent.id,
1849
1849
  versionNumber: 1,
1850
1850
  changedFields: Object.keys(snapshotConfig),
@@ -3011,7 +3011,7 @@ var MongoDBDatasetsStorage = class extends _mastra_core_storage.DatasetsStorage
3011
3011
  }
3012
3012
  async createDataset(input) {
3013
3013
  try {
3014
- const id = input.id ?? (0, crypto$1.randomUUID)();
3014
+ const id = input.id ?? globalThis.crypto.randomUUID();
3015
3015
  if (input.id !== void 0) this.validateCallerDefinedDatasetId(input.id);
3016
3016
  const now = /* @__PURE__ */ new Date();
3017
3017
  const collection = await this.getCollection(_mastra_core_storage.TABLE_DATASETS);
@@ -3202,8 +3202,8 @@ var MongoDBDatasetsStorage = class extends _mastra_core_storage.DatasetsStorage
3202
3202
  }
3203
3203
  async _doAddItem(args) {
3204
3204
  try {
3205
- const id = (0, crypto$1.randomUUID)();
3206
- const versionId = (0, crypto$1.randomUUID)();
3205
+ const id = globalThis.crypto.randomUUID();
3206
+ const versionId = globalThis.crypto.randomUUID();
3207
3207
  const now = /* @__PURE__ */ new Date();
3208
3208
  const datasetsCollection = await this.getCollection(_mastra_core_storage.TABLE_DATASETS);
3209
3209
  const itemsCollection = await this.getCollection(_mastra_core_storage.TABLE_DATASET_ITEMS);
@@ -3305,7 +3305,7 @@ var MongoDBDatasetsStorage = class extends _mastra_core_storage.DatasetsStorage
3305
3305
  return existing;
3306
3306
  }
3307
3307
  const now = /* @__PURE__ */ new Date();
3308
- const versionId = (0, crypto$1.randomUUID)();
3308
+ const versionId = globalThis.crypto.randomUUID();
3309
3309
  const datasetsCollection = await this.getCollection(_mastra_core_storage.TABLE_DATASETS);
3310
3310
  const itemsCollection = await this.getCollection(_mastra_core_storage.TABLE_DATASET_ITEMS);
3311
3311
  const versionsCollection = await this.getCollection(_mastra_core_storage.TABLE_DATASET_VERSIONS);
@@ -3430,7 +3430,7 @@ var MongoDBDatasetsStorage = class extends _mastra_core_storage.DatasetsStorage
3430
3430
  async _doDeleteItem({ id, datasetId }) {
3431
3431
  try {
3432
3432
  const now = /* @__PURE__ */ new Date();
3433
- const versionId = (0, crypto$1.randomUUID)();
3433
+ const versionId = globalThis.crypto.randomUUID();
3434
3434
  const datasetsCollection = await this.getCollection(_mastra_core_storage.TABLE_DATASETS);
3435
3435
  const itemsCollection = await this.getCollection(_mastra_core_storage.TABLE_DATASET_ITEMS);
3436
3436
  const versionsCollection = await this.getCollection(_mastra_core_storage.TABLE_DATASET_VERSIONS);
@@ -3612,7 +3612,7 @@ var MongoDBDatasetsStorage = class extends _mastra_core_storage.DatasetsStorage
3612
3612
  datasetId: input.datasetId,
3613
3613
  externalId: { $in: externalIds }
3614
3614
  }, { session }).sort({ datasetVersion: 1 }).toArray();
3615
- const plan = this.planDatasetItemBatch(input.items, historyRows.map((row) => this.transformItemRowFull(row)), crypto$1.randomUUID);
3615
+ const plan = this.planDatasetItemBatch(input.items, historyRows.map((row) => this.transformItemRowFull(row)), () => globalThis.crypto.randomUUID());
3616
3616
  const resolved = new Map([...plan.existingCurrentItems].map(([id, row]) => [id, this.datasetItemFromRow(row)]));
3617
3617
  if (plan.inserts.length > 0) {
3618
3618
  const now = /* @__PURE__ */ new Date();
@@ -3652,7 +3652,7 @@ var MongoDBDatasetsStorage = class extends _mastra_core_storage.DatasetsStorage
3652
3652
  resolved.set(item.id, item);
3653
3653
  }
3654
3654
  await versionsCollection.insertOne({
3655
- id: (0, crypto$1.randomUUID)(),
3655
+ id: globalThis.crypto.randomUUID(),
3656
3656
  datasetId: input.datasetId,
3657
3657
  version: newVersion,
3658
3658
  createdAt: now
@@ -3680,7 +3680,7 @@ var MongoDBDatasetsStorage = class extends _mastra_core_storage.DatasetsStorage
3680
3680
  });
3681
3681
  const itemsCollection = await this.getCollection(_mastra_core_storage.TABLE_DATASET_ITEMS);
3682
3682
  const now = /* @__PURE__ */ new Date();
3683
- const versionId = (0, crypto$1.randomUUID)();
3683
+ const versionId = globalThis.crypto.randomUUID();
3684
3684
  const datasetsCollection = await this.getCollection(_mastra_core_storage.TABLE_DATASETS);
3685
3685
  const versionsCollection = await this.getCollection(_mastra_core_storage.TABLE_DATASET_VERSIONS);
3686
3686
  await this.#connector.withTransaction(async (session) => {
@@ -3886,7 +3886,7 @@ var MongoDBDatasetsStorage = class extends _mastra_core_storage.DatasetsStorage
3886
3886
  }
3887
3887
  async createDatasetVersion(datasetId, version) {
3888
3888
  try {
3889
- const id = (0, crypto$1.randomUUID)();
3889
+ const id = globalThis.crypto.randomUUID();
3890
3890
  const now = /* @__PURE__ */ new Date();
3891
3891
  await (await this.getCollection(_mastra_core_storage.TABLE_DATASET_VERSIONS)).insertOne({
3892
3892
  id,
@@ -4246,7 +4246,7 @@ var MongoDBExperimentsStorage = class MongoDBExperimentsStorage extends _mastra_
4246
4246
  await this.createCustomIndexes();
4247
4247
  }
4248
4248
  async createExperiment(input) {
4249
- const id = input.id ?? (0, crypto$1.randomUUID)();
4249
+ const id = input.id ?? globalThis.crypto.randomUUID();
4250
4250
  const now = /* @__PURE__ */ new Date();
4251
4251
  const doc = {
4252
4252
  id,
@@ -4424,7 +4424,7 @@ var MongoDBExperimentsStorage = class MongoDBExperimentsStorage extends _mastra_
4424
4424
  }
4425
4425
  }
4426
4426
  async addExperimentResult(input) {
4427
- const id = input.id ?? (0, crypto$1.randomUUID)();
4427
+ const id = input.id ?? globalThis.crypto.randomUUID();
4428
4428
  const now = /* @__PURE__ */ new Date();
4429
4429
  try {
4430
4430
  return await this.#withPurgeBarrier(input.experimentId, input.itemId, async (session, marker) => {
@@ -4492,7 +4492,7 @@ var MongoDBExperimentsStorage = class MongoDBExperimentsStorage extends _mastra_
4492
4492
  ...marker ? { comment: null } : {}
4493
4493
  },
4494
4494
  $setOnInsert: {
4495
- id: (0, crypto$1.randomUUID)(),
4495
+ id: globalThis.crypto.randomUUID(),
4496
4496
  createdAt: /* @__PURE__ */ new Date()
4497
4497
  }
4498
4498
  }, {
@@ -5679,7 +5679,7 @@ var MongoDBMCPClientsStorage = class MongoDBMCPClientsStorage extends _mastra_co
5679
5679
  const snapshotConfig = {};
5680
5680
  for (const field of SNAPSHOT_FIELDS$5) if (mcpClient[field] !== void 0) snapshotConfig[field] = mcpClient[field];
5681
5681
  const versionDoc = {
5682
- id: (0, crypto$1.randomUUID)(),
5682
+ id: globalThis.crypto.randomUUID(),
5683
5683
  mcpClientId: mcpClient.id,
5684
5684
  versionNumber: 1,
5685
5685
  changedFields: Object.keys(snapshotConfig),
@@ -6134,7 +6134,7 @@ var MongoDBMCPServersStorage = class MongoDBMCPServersStorage extends _mastra_co
6134
6134
  const snapshotConfig = {};
6135
6135
  for (const field of SNAPSHOT_FIELDS$4) if (mcpServer[field] !== void 0) snapshotConfig[field] = mcpServer[field];
6136
6136
  const versionDoc = {
6137
- id: (0, crypto$1.randomUUID)(),
6137
+ id: globalThis.crypto.randomUUID(),
6138
6138
  mcpServerId: mcpServer.id,
6139
6139
  versionNumber: 1,
6140
6140
  changedFields: Object.keys(snapshotConfig),
@@ -7330,7 +7330,7 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends _mastra_core_stora
7330
7330
  text: `Source thread with id ${sourceThreadId} not found`,
7331
7331
  details: { sourceThreadId }
7332
7332
  });
7333
- const newThreadId = providedThreadId || (0, crypto$1.randomUUID)();
7333
+ const newThreadId = providedThreadId || globalThis.crypto.randomUUID();
7334
7334
  if (await this.getThreadById({ threadId: newThreadId })) throw new _mastra_core_error.MastraError({
7335
7335
  id: (0, _mastra_core_storage.createStorageErrorId)("MONGODB", "CLONE_THREAD", "THREAD_EXISTS"),
7336
7336
  domain: _mastra_core_error.ErrorDomain.STORAGE,
@@ -7380,7 +7380,7 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends _mastra_core_stora
7380
7380
  if (sourceMessages.length > 0) {
7381
7381
  const messageDocs = [];
7382
7382
  for (const sourceMsg of sourceMessages) {
7383
- const newMessageId = (0, crypto$1.randomUUID)();
7383
+ const newMessageId = globalThis.crypto.randomUUID();
7384
7384
  messageIdMap[sourceMsg.id] = newMessageId;
7385
7385
  let parsedContent = sourceMsg.content;
7386
7386
  if (typeof parsedContent === "string") try {
@@ -7529,7 +7529,7 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends _mastra_core_stora
7529
7529
  }
7530
7530
  async initializeObservationalMemory(input) {
7531
7531
  try {
7532
- const id = (0, crypto$1.randomUUID)();
7532
+ const id = globalThis.crypto.randomUUID();
7533
7533
  const now = /* @__PURE__ */ new Date();
7534
7534
  const lookupKey = this.getOMKey(input.threadId, input.resourceId);
7535
7535
  const record = {
@@ -7678,7 +7678,7 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends _mastra_core_stora
7678
7678
  }
7679
7679
  async createReflectionGeneration(input) {
7680
7680
  try {
7681
- const id = (0, crypto$1.randomUUID)();
7681
+ const id = globalThis.crypto.randomUUID();
7682
7682
  const now = /* @__PURE__ */ new Date();
7683
7683
  const lookupKey = this.getOMKey(input.currentRecord.threadId, input.currentRecord.resourceId);
7684
7684
  const record = {
@@ -7944,7 +7944,7 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends _mastra_core_stora
7944
7944
  try {
7945
7945
  const collection = await this.getCollection(OM_TABLE);
7946
7946
  const newChunk = {
7947
- id: `ombuf-${(0, crypto$1.randomUUID)()}`,
7947
+ id: `ombuf-${globalThis.crypto.randomUUID()}`,
7948
7948
  cycleId: input.chunk.cycleId,
7949
7949
  observations: input.chunk.observations,
7950
7950
  tokenCount: input.chunk.tokenCount,
@@ -8413,7 +8413,7 @@ var NotificationsMongoDB = class NotificationsMongoDB extends _mastra_core_stora
8413
8413
  }
8414
8414
  const now = input.createdAt ?? /* @__PURE__ */ new Date();
8415
8415
  const record = {
8416
- id: input.id ?? (0, crypto$1.randomUUID)(),
8416
+ id: input.id ?? globalThis.crypto.randomUUID(),
8417
8417
  threadId: input.threadId,
8418
8418
  source: input.source,
8419
8419
  kind: input.kind,
@@ -9368,7 +9368,7 @@ var MongoDBPromptBlocksStorage = class MongoDBPromptBlocksStorage extends _mastr
9368
9368
  const snapshotConfig = {};
9369
9369
  for (const field of SNAPSHOT_FIELDS$3) if (promptBlock[field] !== void 0) snapshotConfig[field] = promptBlock[field];
9370
9370
  const versionDoc = {
9371
- id: (0, crypto$1.randomUUID)(),
9371
+ id: globalThis.crypto.randomUUID(),
9372
9372
  blockId: promptBlock.id,
9373
9373
  versionNumber: 1,
9374
9374
  changedFields: Object.keys(snapshotConfig),
@@ -10073,7 +10073,7 @@ var MongoDBScorerDefinitionsStorage = class MongoDBScorerDefinitionsStorage exte
10073
10073
  const snapshotConfig = {};
10074
10074
  for (const field of SNAPSHOT_FIELDS$2) if (scorerDefinition[field] !== void 0) snapshotConfig[field] = scorerDefinition[field];
10075
10075
  const versionDoc = {
10076
- id: (0, crypto$1.randomUUID)(),
10076
+ id: globalThis.crypto.randomUUID(),
10077
10077
  scorerDefinitionId: scorerDefinition.id,
10078
10078
  versionNumber: 1,
10079
10079
  changedFields: Object.keys(snapshotConfig),
@@ -10546,7 +10546,7 @@ var ScoresStorageMongoDB = class ScoresStorageMongoDB extends _mastra_core_stora
10546
10546
  try {
10547
10547
  const now = /* @__PURE__ */ new Date();
10548
10548
  const suppliedId = validatedScore.id;
10549
- const scoreId = suppliedId ?? (0, crypto$1.randomUUID)();
10549
+ const scoreId = suppliedId ?? globalThis.crypto.randomUUID();
10550
10550
  const scorer = typeof validatedScore.scorer === "string" ? (0, _mastra_core_storage.safelyParseJSON)(validatedScore.scorer) : validatedScore.scorer;
10551
10551
  const preprocessStepResult = typeof validatedScore.preprocessStepResult === "string" ? (0, _mastra_core_storage.safelyParseJSON)(validatedScore.preprocessStepResult) : validatedScore.preprocessStepResult;
10552
10552
  const analyzeStepResult = typeof validatedScore.analyzeStepResult === "string" ? (0, _mastra_core_storage.safelyParseJSON)(validatedScore.analyzeStepResult) : validatedScore.analyzeStepResult;
@@ -10904,7 +10904,7 @@ var MongoDBSkillsStorage = class MongoDBSkillsStorage extends _mastra_core_stora
10904
10904
  const snapshotConfig = {};
10905
10905
  for (const field of SNAPSHOT_FIELDS$1) if (skill[field] !== void 0) snapshotConfig[field] = skill[field];
10906
10906
  const versionDoc = {
10907
- id: (0, crypto$1.randomUUID)(),
10907
+ id: globalThis.crypto.randomUUID(),
10908
10908
  skillId: id,
10909
10909
  versionNumber: 1,
10910
10910
  changedFields: Object.keys(snapshotConfig),
@@ -10972,7 +10972,7 @@ var MongoDBSkillsStorage = class MongoDBSkillsStorage extends _mastra_core_stora
10972
10972
  ...configFields
10973
10973
  };
10974
10974
  newVersionDoc = {
10975
- id: (0, crypto$1.randomUUID)(),
10975
+ id: globalThis.crypto.randomUUID(),
10976
10976
  skillId: id,
10977
10977
  versionNumber: latestVersion.versionNumber + 1,
10978
10978
  changedFields,
@@ -11886,7 +11886,7 @@ var MongoDBWorkspacesStorage = class MongoDBWorkspacesStorage extends _mastra_co
11886
11886
  const snapshotConfig = {};
11887
11887
  for (const field of SNAPSHOT_FIELDS) if (workspace[field] !== void 0) snapshotConfig[field] = workspace[field];
11888
11888
  const versionDoc = {
11889
- id: (0, crypto$1.randomUUID)(),
11889
+ id: globalThis.crypto.randomUUID(),
11890
11890
  workspaceId: id,
11891
11891
  versionNumber: 1,
11892
11892
  changedFields: Object.keys(snapshotConfig),
@@ -11945,7 +11945,7 @@ var MongoDBWorkspacesStorage = class MongoDBWorkspacesStorage extends _mastra_co
11945
11945
  ...configFields
11946
11946
  };
11947
11947
  newVersionDoc = {
11948
- id: (0, crypto$1.randomUUID)(),
11948
+ id: globalThis.crypto.randomUUID(),
11949
11949
  workspaceId: id,
11950
11950
  versionNumber: latestVersion.versionNumber + 1,
11951
11951
  changedFields: Object.keys(configFields),