@mastra/mongodb 1.18.1-alpha.0 → 1.18.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
@@ -9,7 +9,7 @@ import { MessageList } from "@mastra/core/agent";
9
9
  import { saveScorePayloadSchema } from "@mastra/core/evals";
10
10
  import { skillSnapshotFieldValuesEqual } from "@mastra/core/storage/domains/skills";
11
11
  //#region package.json
12
- var version = "1.18.1-alpha.0";
12
+ var version = "1.18.1";
13
13
  //#endregion
14
14
  //#region src/vector/filter.ts
15
15
  /**
@@ -3677,8 +3677,9 @@ function transformExperimentRow(row) {
3677
3677
  datasetVersion: row.datasetVersion != null ? Number(row.datasetVersion) : null,
3678
3678
  organizationId: row.organizationId ?? null,
3679
3679
  projectId: row.projectId ?? null,
3680
- targetType: row.targetType,
3681
- targetId: row.targetId,
3680
+ targetType: row.targetType ?? null,
3681
+ targetId: row.targetId ?? null,
3682
+ scorerIds: row.scorerIds ?? null,
3682
3683
  status: row.status,
3683
3684
  totalItems: Number(row.totalItems ?? 0),
3684
3685
  succeededCount: Number(row.succeededCount ?? 0),
@@ -3706,6 +3707,7 @@ function transformExperimentResultRow(row) {
3706
3707
  startedAt: toDate(row.startedAt),
3707
3708
  completedAt: toDate(row.completedAt),
3708
3709
  retryCount: Number(row.retryCount ?? 0),
3710
+ attempt: row.attempt != null ? Number(row.attempt) : 0,
3709
3711
  traceId: row.traceId ?? null,
3710
3712
  status: row.status ?? null,
3711
3713
  tags: Array.isArray(row.tags) ? row.tags : parseJsonField(row.tags) ?? null,
@@ -3848,7 +3850,8 @@ var MongoDBExperimentsStorage = class MongoDBExperimentsStorage extends Experime
3848
3850
  collection: TABLE_EXPERIMENT_RESULTS,
3849
3851
  keys: {
3850
3852
  experimentId: 1,
3851
- itemId: 1
3853
+ itemId: 1,
3854
+ attempt: 1
3852
3855
  },
3853
3856
  options: { unique: true }
3854
3857
  },
@@ -3875,6 +3878,9 @@ var MongoDBExperimentsStorage = class MongoDBExperimentsStorage extends Experime
3875
3878
  }
3876
3879
  async createDefaultIndexes() {
3877
3880
  if (this.#skipDefaultIndexes) return;
3881
+ try {
3882
+ await (await this.getCollection(TABLE_EXPERIMENT_RESULTS)).dropIndex("experimentId_1_itemId_1");
3883
+ } catch {}
3878
3884
  for (const indexDef of this.getDefaultIndexDefinitions()) try {
3879
3885
  await (await this.getCollection(indexDef.collection)).createIndex(indexDef.keys, indexDef.options);
3880
3886
  } catch (error) {
@@ -3911,8 +3917,9 @@ var MongoDBExperimentsStorage = class MongoDBExperimentsStorage extends Experime
3911
3917
  datasetVersion: input.datasetVersion ?? null,
3912
3918
  organizationId: input.organizationId ?? null,
3913
3919
  projectId: input.projectId ?? null,
3914
- targetType: input.targetType,
3915
- targetId: input.targetId,
3920
+ targetType: input.targetType ?? null,
3921
+ targetId: input.targetId ?? null,
3922
+ scorerIds: input.scorerIds ?? null,
3916
3923
  status: "pending",
3917
3924
  totalItems: input.totalItems,
3918
3925
  succeededCount: 0,
@@ -4083,6 +4090,7 @@ var MongoDBExperimentsStorage = class MongoDBExperimentsStorage extends Experime
4083
4090
  startedAt: input.startedAt,
4084
4091
  completedAt: input.completedAt,
4085
4092
  retryCount: input.retryCount,
4093
+ attempt: input.attempt ?? 0,
4086
4094
  traceId: input.traceId ?? null,
4087
4095
  status: input.status ?? null,
4088
4096
  tags: input.tags ?? null,
@@ -4105,6 +4113,7 @@ var MongoDBExperimentsStorage = class MongoDBExperimentsStorage extends Experime
4105
4113
  startedAt: input.startedAt,
4106
4114
  completedAt: input.completedAt,
4107
4115
  retryCount: input.retryCount,
4116
+ attempt: input.attempt ?? 0,
4108
4117
  traceId: input.traceId ?? null,
4109
4118
  status: input.status ?? null,
4110
4119
  tags: input.tags ?? null,
@@ -4120,6 +4129,48 @@ var MongoDBExperimentsStorage = class MongoDBExperimentsStorage extends Experime
4120
4129
  }, error);
4121
4130
  }
4122
4131
  }
4132
+ async upsertExperimentResult(input) {
4133
+ const attempt = input.attempt ?? 0;
4134
+ try {
4135
+ return transformExperimentResultRow(await (await this.getCollection(TABLE_EXPERIMENT_RESULTS)).findOneAndUpdate({
4136
+ experimentId: input.experimentId,
4137
+ itemId: input.itemId,
4138
+ $or: [{ attempt }, ...attempt === 0 ? [{ attempt: null }, { attempt: { $exists: false } }] : []]
4139
+ }, {
4140
+ $set: {
4141
+ itemDatasetVersion: input.itemDatasetVersion ?? null,
4142
+ organizationId: input.organizationId ?? null,
4143
+ projectId: input.projectId ?? null,
4144
+ input: input.input,
4145
+ output: input.output ?? null,
4146
+ groundTruth: input.groundTruth ?? null,
4147
+ error: input.error ?? null,
4148
+ startedAt: input.startedAt,
4149
+ completedAt: input.completedAt,
4150
+ retryCount: input.retryCount,
4151
+ attempt,
4152
+ traceId: input.traceId ?? null,
4153
+ status: input.status ?? null,
4154
+ tags: input.tags ?? null,
4155
+ toolMockReport: input.toolMockReport ?? null
4156
+ },
4157
+ $setOnInsert: {
4158
+ id: randomUUID(),
4159
+ createdAt: /* @__PURE__ */ new Date()
4160
+ }
4161
+ }, {
4162
+ upsert: true,
4163
+ returnDocument: "after"
4164
+ }));
4165
+ } catch (error) {
4166
+ throw new MastraError({
4167
+ id: createStorageErrorId("MONGODB", "UPSERT_EXPERIMENT_RESULT", "FAILED"),
4168
+ domain: ErrorDomain.STORAGE,
4169
+ category: ErrorCategory.THIRD_PARTY,
4170
+ details: { experimentId: input.experimentId }
4171
+ }, error);
4172
+ }
4173
+ }
4123
4174
  async updateExperimentResult(input) {
4124
4175
  const updateFields = {};
4125
4176
  if (input.status !== void 0) updateFields.status = input.status;
@@ -10059,7 +10110,8 @@ var ScoresStorageMongoDB = class ScoresStorageMongoDB extends ScoresStorage {
10059
10110
  }
10060
10111
  try {
10061
10112
  const now = /* @__PURE__ */ new Date();
10062
- const scoreId = randomUUID();
10113
+ const suppliedId = validatedScore.id;
10114
+ const scoreId = suppliedId ?? randomUUID();
10063
10115
  const scorer = typeof validatedScore.scorer === "string" ? safelyParseJSON(validatedScore.scorer) : validatedScore.scorer;
10064
10116
  const preprocessStepResult = typeof validatedScore.preprocessStepResult === "string" ? safelyParseJSON(validatedScore.preprocessStepResult) : validatedScore.preprocessStepResult;
10065
10117
  const analyzeStepResult = typeof validatedScore.analyzeStepResult === "string" ? safelyParseJSON(validatedScore.analyzeStepResult) : validatedScore.analyzeStepResult;
@@ -10082,7 +10134,9 @@ var ScoresStorageMongoDB = class ScoresStorageMongoDB extends ScoresStorage {
10082
10134
  createdAt,
10083
10135
  updatedAt
10084
10136
  };
10085
- await (await this.getCollection(TABLE_SCORERS)).insertOne(dataToSave);
10137
+ const collection = await this.getCollection(TABLE_SCORERS);
10138
+ if (suppliedId) await collection.replaceOne({ id: scoreId }, dataToSave, { upsert: true });
10139
+ else await collection.insertOne(dataToSave);
10086
10140
  return { score: dataToSave };
10087
10141
  } catch (error) {
10088
10142
  throw new MastraError({