@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.
package/dist/index.js CHANGED
@@ -4,12 +4,11 @@ import { AgentsStorage, BackgroundTasksStorage, BlobStore, DatasetsStorage, Expe
4
4
  import { MastraVector, validateUpsertInput, validateVectorValues } from "@mastra/core/vector";
5
5
  import { MongoBulkWriteError, MongoClient, ObjectId } from "mongodb";
6
6
  import { BaseFilterTranslator } from "@mastra/core/vector/filter";
7
- import { randomUUID } from "crypto";
8
7
  import { MessageList } from "@mastra/core/agent";
9
8
  import { saveScorePayloadSchema } from "@mastra/core/evals";
10
9
  import { skillSnapshotFieldValuesEqual } from "@mastra/core/storage/domains/skills";
11
10
  //#region package.json
12
- var version = "1.20.0";
11
+ var version = "1.20.1-alpha.1";
13
12
  //#endregion
14
13
  //#region src/vector/filter.ts
15
14
  /**
@@ -1019,7 +1018,7 @@ var MongoDBVector = class MongoDBVector extends MastraVector {
1019
1018
  declaredPaths = /* @__PURE__ */ new Set();
1020
1019
  }
1021
1020
  const pushMetadata = !hasMetadataFilter || this.canPushDownFilter(metadataFilter, declaredPaths);
1022
- const pushDocument = !documentFilterExpr || !autoEmbed && (!verifyDocumentPath || declaredPaths.has(documentTextField));
1021
+ const pushDocument = !documentFilterExpr || !autoEmbed && (!verifyDocumentPath || declaredPaths.has(documentTextField)) && this.canPushDownFilter(documentFilter, /* @__PURE__ */ new Set());
1023
1022
  const pushed = [...hasMetadataFilter && pushMetadata ? [metadataFilter] : [], ...documentFilterExpr && pushDocument ? [documentFilterExpr] : []];
1024
1023
  if (!pushMetadata || !pushDocument) {
1025
1024
  const preFilter = [...hasMetadataFilter && !pushMetadata ? [metadataFilter] : [], ...documentFilterExpr && !pushDocument ? [documentFilterExpr] : []];
@@ -1432,6 +1431,7 @@ var MongoDBVector = class MongoDBVector extends MastraVector {
1432
1431
  */
1433
1432
  canPushDownFilter(filter, declaredPaths) {
1434
1433
  if (filter === null || typeof filter !== "object") return true;
1434
+ if (filter instanceof RegExp) return false;
1435
1435
  if (Array.isArray(filter)) return filter.every((item) => this.canPushDownFilter(item, declaredPaths));
1436
1436
  for (const [key, value] of Object.entries(filter)) {
1437
1437
  if (key.startsWith("$")) {
@@ -1843,7 +1843,7 @@ var MongoDBAgentsStorage = class MongoDBAgentsStorage extends AgentsStorage {
1843
1843
  };
1844
1844
  const { id: _id, authorId: _authorId, visibility: _visibility, metadata: _metadata, ...snapshotConfig } = agent;
1845
1845
  const versionDoc = {
1846
- id: randomUUID(),
1846
+ id: globalThis.crypto.randomUUID(),
1847
1847
  agentId: agent.id,
1848
1848
  versionNumber: 1,
1849
1849
  changedFields: Object.keys(snapshotConfig),
@@ -3010,7 +3010,7 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
3010
3010
  }
3011
3011
  async createDataset(input) {
3012
3012
  try {
3013
- const id = input.id ?? randomUUID();
3013
+ const id = input.id ?? globalThis.crypto.randomUUID();
3014
3014
  if (input.id !== void 0) this.validateCallerDefinedDatasetId(input.id);
3015
3015
  const now = /* @__PURE__ */ new Date();
3016
3016
  const collection = await this.getCollection(TABLE_DATASETS);
@@ -3201,8 +3201,8 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
3201
3201
  }
3202
3202
  async _doAddItem(args) {
3203
3203
  try {
3204
- const id = randomUUID();
3205
- const versionId = randomUUID();
3204
+ const id = globalThis.crypto.randomUUID();
3205
+ const versionId = globalThis.crypto.randomUUID();
3206
3206
  const now = /* @__PURE__ */ new Date();
3207
3207
  const datasetsCollection = await this.getCollection(TABLE_DATASETS);
3208
3208
  const itemsCollection = await this.getCollection(TABLE_DATASET_ITEMS);
@@ -3304,7 +3304,7 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
3304
3304
  return existing;
3305
3305
  }
3306
3306
  const now = /* @__PURE__ */ new Date();
3307
- const versionId = randomUUID();
3307
+ const versionId = globalThis.crypto.randomUUID();
3308
3308
  const datasetsCollection = await this.getCollection(TABLE_DATASETS);
3309
3309
  const itemsCollection = await this.getCollection(TABLE_DATASET_ITEMS);
3310
3310
  const versionsCollection = await this.getCollection(TABLE_DATASET_VERSIONS);
@@ -3429,7 +3429,7 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
3429
3429
  async _doDeleteItem({ id, datasetId }) {
3430
3430
  try {
3431
3431
  const now = /* @__PURE__ */ new Date();
3432
- const versionId = randomUUID();
3432
+ const versionId = globalThis.crypto.randomUUID();
3433
3433
  const datasetsCollection = await this.getCollection(TABLE_DATASETS);
3434
3434
  const itemsCollection = await this.getCollection(TABLE_DATASET_ITEMS);
3435
3435
  const versionsCollection = await this.getCollection(TABLE_DATASET_VERSIONS);
@@ -3611,7 +3611,7 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
3611
3611
  datasetId: input.datasetId,
3612
3612
  externalId: { $in: externalIds }
3613
3613
  }, { session }).sort({ datasetVersion: 1 }).toArray();
3614
- const plan = this.planDatasetItemBatch(input.items, historyRows.map((row) => this.transformItemRowFull(row)), randomUUID);
3614
+ const plan = this.planDatasetItemBatch(input.items, historyRows.map((row) => this.transformItemRowFull(row)), () => globalThis.crypto.randomUUID());
3615
3615
  const resolved = new Map([...plan.existingCurrentItems].map(([id, row]) => [id, this.datasetItemFromRow(row)]));
3616
3616
  if (plan.inserts.length > 0) {
3617
3617
  const now = /* @__PURE__ */ new Date();
@@ -3651,7 +3651,7 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
3651
3651
  resolved.set(item.id, item);
3652
3652
  }
3653
3653
  await versionsCollection.insertOne({
3654
- id: randomUUID(),
3654
+ id: globalThis.crypto.randomUUID(),
3655
3655
  datasetId: input.datasetId,
3656
3656
  version: newVersion,
3657
3657
  createdAt: now
@@ -3679,7 +3679,7 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
3679
3679
  });
3680
3680
  const itemsCollection = await this.getCollection(TABLE_DATASET_ITEMS);
3681
3681
  const now = /* @__PURE__ */ new Date();
3682
- const versionId = randomUUID();
3682
+ const versionId = globalThis.crypto.randomUUID();
3683
3683
  const datasetsCollection = await this.getCollection(TABLE_DATASETS);
3684
3684
  const versionsCollection = await this.getCollection(TABLE_DATASET_VERSIONS);
3685
3685
  await this.#connector.withTransaction(async (session) => {
@@ -3885,7 +3885,7 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
3885
3885
  }
3886
3886
  async createDatasetVersion(datasetId, version) {
3887
3887
  try {
3888
- const id = randomUUID();
3888
+ const id = globalThis.crypto.randomUUID();
3889
3889
  const now = /* @__PURE__ */ new Date();
3890
3890
  await (await this.getCollection(TABLE_DATASET_VERSIONS)).insertOne({
3891
3891
  id,
@@ -4245,7 +4245,7 @@ var MongoDBExperimentsStorage = class MongoDBExperimentsStorage extends Experime
4245
4245
  await this.createCustomIndexes();
4246
4246
  }
4247
4247
  async createExperiment(input) {
4248
- const id = input.id ?? randomUUID();
4248
+ const id = input.id ?? globalThis.crypto.randomUUID();
4249
4249
  const now = /* @__PURE__ */ new Date();
4250
4250
  const doc = {
4251
4251
  id,
@@ -4423,7 +4423,7 @@ var MongoDBExperimentsStorage = class MongoDBExperimentsStorage extends Experime
4423
4423
  }
4424
4424
  }
4425
4425
  async addExperimentResult(input) {
4426
- const id = input.id ?? randomUUID();
4426
+ const id = input.id ?? globalThis.crypto.randomUUID();
4427
4427
  const now = /* @__PURE__ */ new Date();
4428
4428
  try {
4429
4429
  return await this.#withPurgeBarrier(input.experimentId, input.itemId, async (session, marker) => {
@@ -4491,7 +4491,7 @@ var MongoDBExperimentsStorage = class MongoDBExperimentsStorage extends Experime
4491
4491
  ...marker ? { comment: null } : {}
4492
4492
  },
4493
4493
  $setOnInsert: {
4494
- id: randomUUID(),
4494
+ id: globalThis.crypto.randomUUID(),
4495
4495
  createdAt: /* @__PURE__ */ new Date()
4496
4496
  }
4497
4497
  }, {
@@ -5678,7 +5678,7 @@ var MongoDBMCPClientsStorage = class MongoDBMCPClientsStorage extends MCPClients
5678
5678
  const snapshotConfig = {};
5679
5679
  for (const field of SNAPSHOT_FIELDS$5) if (mcpClient[field] !== void 0) snapshotConfig[field] = mcpClient[field];
5680
5680
  const versionDoc = {
5681
- id: randomUUID(),
5681
+ id: globalThis.crypto.randomUUID(),
5682
5682
  mcpClientId: mcpClient.id,
5683
5683
  versionNumber: 1,
5684
5684
  changedFields: Object.keys(snapshotConfig),
@@ -6133,7 +6133,7 @@ var MongoDBMCPServersStorage = class MongoDBMCPServersStorage extends MCPServers
6133
6133
  const snapshotConfig = {};
6134
6134
  for (const field of SNAPSHOT_FIELDS$4) if (mcpServer[field] !== void 0) snapshotConfig[field] = mcpServer[field];
6135
6135
  const versionDoc = {
6136
- id: randomUUID(),
6136
+ id: globalThis.crypto.randomUUID(),
6137
6137
  mcpServerId: mcpServer.id,
6138
6138
  versionNumber: 1,
6139
6139
  changedFields: Object.keys(snapshotConfig),
@@ -7329,7 +7329,7 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
7329
7329
  text: `Source thread with id ${sourceThreadId} not found`,
7330
7330
  details: { sourceThreadId }
7331
7331
  });
7332
- const newThreadId = providedThreadId || randomUUID();
7332
+ const newThreadId = providedThreadId || globalThis.crypto.randomUUID();
7333
7333
  if (await this.getThreadById({ threadId: newThreadId })) throw new MastraError({
7334
7334
  id: createStorageErrorId("MONGODB", "CLONE_THREAD", "THREAD_EXISTS"),
7335
7335
  domain: ErrorDomain.STORAGE,
@@ -7379,7 +7379,7 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
7379
7379
  if (sourceMessages.length > 0) {
7380
7380
  const messageDocs = [];
7381
7381
  for (const sourceMsg of sourceMessages) {
7382
- const newMessageId = randomUUID();
7382
+ const newMessageId = globalThis.crypto.randomUUID();
7383
7383
  messageIdMap[sourceMsg.id] = newMessageId;
7384
7384
  let parsedContent = sourceMsg.content;
7385
7385
  if (typeof parsedContent === "string") try {
@@ -7528,7 +7528,7 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
7528
7528
  }
7529
7529
  async initializeObservationalMemory(input) {
7530
7530
  try {
7531
- const id = randomUUID();
7531
+ const id = globalThis.crypto.randomUUID();
7532
7532
  const now = /* @__PURE__ */ new Date();
7533
7533
  const lookupKey = this.getOMKey(input.threadId, input.resourceId);
7534
7534
  const record = {
@@ -7677,7 +7677,7 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
7677
7677
  }
7678
7678
  async createReflectionGeneration(input) {
7679
7679
  try {
7680
- const id = randomUUID();
7680
+ const id = globalThis.crypto.randomUUID();
7681
7681
  const now = /* @__PURE__ */ new Date();
7682
7682
  const lookupKey = this.getOMKey(input.currentRecord.threadId, input.currentRecord.resourceId);
7683
7683
  const record = {
@@ -7943,7 +7943,7 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends MemoryStorage {
7943
7943
  try {
7944
7944
  const collection = await this.getCollection(OM_TABLE);
7945
7945
  const newChunk = {
7946
- id: `ombuf-${randomUUID()}`,
7946
+ id: `ombuf-${globalThis.crypto.randomUUID()}`,
7947
7947
  cycleId: input.chunk.cycleId,
7948
7948
  observations: input.chunk.observations,
7949
7949
  tokenCount: input.chunk.tokenCount,
@@ -8412,7 +8412,7 @@ var NotificationsMongoDB = class NotificationsMongoDB extends NotificationsStora
8412
8412
  }
8413
8413
  const now = input.createdAt ?? /* @__PURE__ */ new Date();
8414
8414
  const record = {
8415
- id: input.id ?? randomUUID(),
8415
+ id: input.id ?? globalThis.crypto.randomUUID(),
8416
8416
  threadId: input.threadId,
8417
8417
  source: input.source,
8418
8418
  kind: input.kind,
@@ -9367,7 +9367,7 @@ var MongoDBPromptBlocksStorage = class MongoDBPromptBlocksStorage extends Prompt
9367
9367
  const snapshotConfig = {};
9368
9368
  for (const field of SNAPSHOT_FIELDS$3) if (promptBlock[field] !== void 0) snapshotConfig[field] = promptBlock[field];
9369
9369
  const versionDoc = {
9370
- id: randomUUID(),
9370
+ id: globalThis.crypto.randomUUID(),
9371
9371
  blockId: promptBlock.id,
9372
9372
  versionNumber: 1,
9373
9373
  changedFields: Object.keys(snapshotConfig),
@@ -10072,7 +10072,7 @@ var MongoDBScorerDefinitionsStorage = class MongoDBScorerDefinitionsStorage exte
10072
10072
  const snapshotConfig = {};
10073
10073
  for (const field of SNAPSHOT_FIELDS$2) if (scorerDefinition[field] !== void 0) snapshotConfig[field] = scorerDefinition[field];
10074
10074
  const versionDoc = {
10075
- id: randomUUID(),
10075
+ id: globalThis.crypto.randomUUID(),
10076
10076
  scorerDefinitionId: scorerDefinition.id,
10077
10077
  versionNumber: 1,
10078
10078
  changedFields: Object.keys(snapshotConfig),
@@ -10545,7 +10545,7 @@ var ScoresStorageMongoDB = class ScoresStorageMongoDB extends ScoresStorage {
10545
10545
  try {
10546
10546
  const now = /* @__PURE__ */ new Date();
10547
10547
  const suppliedId = validatedScore.id;
10548
- const scoreId = suppliedId ?? randomUUID();
10548
+ const scoreId = suppliedId ?? globalThis.crypto.randomUUID();
10549
10549
  const scorer = typeof validatedScore.scorer === "string" ? safelyParseJSON(validatedScore.scorer) : validatedScore.scorer;
10550
10550
  const preprocessStepResult = typeof validatedScore.preprocessStepResult === "string" ? safelyParseJSON(validatedScore.preprocessStepResult) : validatedScore.preprocessStepResult;
10551
10551
  const analyzeStepResult = typeof validatedScore.analyzeStepResult === "string" ? safelyParseJSON(validatedScore.analyzeStepResult) : validatedScore.analyzeStepResult;
@@ -10903,7 +10903,7 @@ var MongoDBSkillsStorage = class MongoDBSkillsStorage extends SkillsStorage {
10903
10903
  const snapshotConfig = {};
10904
10904
  for (const field of SNAPSHOT_FIELDS$1) if (skill[field] !== void 0) snapshotConfig[field] = skill[field];
10905
10905
  const versionDoc = {
10906
- id: randomUUID(),
10906
+ id: globalThis.crypto.randomUUID(),
10907
10907
  skillId: id,
10908
10908
  versionNumber: 1,
10909
10909
  changedFields: Object.keys(snapshotConfig),
@@ -10971,7 +10971,7 @@ var MongoDBSkillsStorage = class MongoDBSkillsStorage extends SkillsStorage {
10971
10971
  ...configFields
10972
10972
  };
10973
10973
  newVersionDoc = {
10974
- id: randomUUID(),
10974
+ id: globalThis.crypto.randomUUID(),
10975
10975
  skillId: id,
10976
10976
  versionNumber: latestVersion.versionNumber + 1,
10977
10977
  changedFields,
@@ -11885,7 +11885,7 @@ var MongoDBWorkspacesStorage = class MongoDBWorkspacesStorage extends Workspaces
11885
11885
  const snapshotConfig = {};
11886
11886
  for (const field of SNAPSHOT_FIELDS) if (workspace[field] !== void 0) snapshotConfig[field] = workspace[field];
11887
11887
  const versionDoc = {
11888
- id: randomUUID(),
11888
+ id: globalThis.crypto.randomUUID(),
11889
11889
  workspaceId: id,
11890
11890
  versionNumber: 1,
11891
11891
  changedFields: Object.keys(snapshotConfig),
@@ -11944,7 +11944,7 @@ var MongoDBWorkspacesStorage = class MongoDBWorkspacesStorage extends Workspaces
11944
11944
  ...configFields
11945
11945
  };
11946
11946
  newVersionDoc = {
11947
- id: randomUUID(),
11947
+ id: globalThis.crypto.randomUUID(),
11948
11948
  workspaceId: id,
11949
11949
  versionNumber: latestVersion.versionNumber + 1,
11950
11950
  changedFields: Object.keys(configFields),