@mastra/mongodb 1.18.7 → 1.18.8-alpha.0
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/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +108 -70
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +108 -70
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/datasets/index.d.ts.map +1 -1
- package/package.json +4 -4
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.
|
|
12
|
+
var version = "1.18.8-alpha.0";
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/vector/filter.ts
|
|
15
15
|
/**
|
|
@@ -3096,42 +3096,65 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
|
|
|
3096
3096
|
}
|
|
3097
3097
|
async _doUpdateItem(args) {
|
|
3098
3098
|
try {
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3099
|
+
if (!(args.input !== void 0 || args.groundTruth !== void 0 || args.expectedTrajectory !== void 0 || args.toolMocks !== void 0 || args.unmockedToolPolicy !== void 0 || args.scorerIds !== void 0 || args.requestContext !== void 0 || args.metadata !== void 0 || args.source !== void 0)) {
|
|
3100
|
+
const existing = await this.getItemById({ id: args.id });
|
|
3101
|
+
if (!existing) throw new MastraError({
|
|
3102
|
+
id: createStorageErrorId("MONGODB", "UPDATE_ITEM", "NOT_FOUND"),
|
|
3103
|
+
domain: ErrorDomain.STORAGE,
|
|
3104
|
+
category: ErrorCategory.USER,
|
|
3105
|
+
details: { itemId: args.id }
|
|
3106
|
+
});
|
|
3107
|
+
if (existing.datasetId !== args.datasetId) throw new MastraError({
|
|
3108
|
+
id: createStorageErrorId("MONGODB", "UPDATE_ITEM", "DATASET_MISMATCH"),
|
|
3109
|
+
domain: ErrorDomain.STORAGE,
|
|
3110
|
+
category: ErrorCategory.USER,
|
|
3111
|
+
details: {
|
|
3112
|
+
itemId: args.id,
|
|
3113
|
+
expectedDatasetId: args.datasetId,
|
|
3114
|
+
actualDatasetId: existing.datasetId
|
|
3115
|
+
}
|
|
3116
|
+
});
|
|
3117
|
+
return existing;
|
|
3118
|
+
}
|
|
3117
3119
|
const now = /* @__PURE__ */ new Date();
|
|
3118
3120
|
const versionId = randomUUID();
|
|
3119
|
-
const mergedInput = args.input !== void 0 ? args.input : existing.input;
|
|
3120
|
-
const mergedGroundTruth = args.groundTruth !== void 0 ? args.groundTruth : existing.groundTruth;
|
|
3121
|
-
const mergedExpectedTrajectory = args.expectedTrajectory !== void 0 ? args.expectedTrajectory : existing.expectedTrajectory;
|
|
3122
|
-
const mergedToolMocks = args.toolMocks !== void 0 ? args.toolMocks : existing.toolMocks;
|
|
3123
|
-
const mergedUnmockedToolPolicy = args.unmockedToolPolicy !== void 0 ? args.unmockedToolPolicy : existing.unmockedToolPolicy;
|
|
3124
|
-
const mergedScorerIds = args.scorerIds !== void 0 ? args.scorerIds ?? void 0 : existing.scorerIds;
|
|
3125
|
-
const mergedRequestContext = args.requestContext !== void 0 ? args.requestContext : existing.requestContext;
|
|
3126
|
-
const mergedMetadata = args.metadata !== void 0 ? args.metadata : existing.metadata;
|
|
3127
|
-
const mergedSource = args.source !== void 0 ? args.source : existing.source;
|
|
3128
3121
|
const datasetsCollection = await this.getCollection(TABLE_DATASETS);
|
|
3129
3122
|
const itemsCollection = await this.getCollection(TABLE_DATASET_ITEMS);
|
|
3130
3123
|
const versionsCollection = await this.getCollection(TABLE_DATASET_VERSIONS);
|
|
3131
|
-
let
|
|
3132
|
-
let parentOrganizationId = null;
|
|
3133
|
-
let parentProjectId = null;
|
|
3124
|
+
let updated;
|
|
3134
3125
|
await this.#connector.withTransaction(async (session) => {
|
|
3126
|
+
const row = await itemsCollection.findOne({
|
|
3127
|
+
id: args.id,
|
|
3128
|
+
validTo: null,
|
|
3129
|
+
isDeleted: false
|
|
3130
|
+
}, { session });
|
|
3131
|
+
const existing = row ? this.transformItemRow(row) : null;
|
|
3132
|
+
if (!existing) throw new MastraError({
|
|
3133
|
+
id: createStorageErrorId("MONGODB", "UPDATE_ITEM", "NOT_FOUND"),
|
|
3134
|
+
domain: ErrorDomain.STORAGE,
|
|
3135
|
+
category: ErrorCategory.USER,
|
|
3136
|
+
details: { itemId: args.id }
|
|
3137
|
+
});
|
|
3138
|
+
if (existing.datasetId !== args.datasetId) throw new MastraError({
|
|
3139
|
+
id: createStorageErrorId("MONGODB", "UPDATE_ITEM", "DATASET_MISMATCH"),
|
|
3140
|
+
domain: ErrorDomain.STORAGE,
|
|
3141
|
+
category: ErrorCategory.USER,
|
|
3142
|
+
details: {
|
|
3143
|
+
itemId: args.id,
|
|
3144
|
+
expectedDatasetId: args.datasetId,
|
|
3145
|
+
actualDatasetId: existing.datasetId
|
|
3146
|
+
}
|
|
3147
|
+
});
|
|
3148
|
+
if (existing.metadata?.__purged === true) throw new MastraError({
|
|
3149
|
+
id: "DATASET_ITEM_PURGED",
|
|
3150
|
+
domain: ErrorDomain.STORAGE,
|
|
3151
|
+
category: ErrorCategory.USER,
|
|
3152
|
+
details: {
|
|
3153
|
+
datasetId: args.datasetId,
|
|
3154
|
+
itemId: args.id
|
|
3155
|
+
},
|
|
3156
|
+
text: `Purged dataset item cannot be updated: ${args.id}`
|
|
3157
|
+
});
|
|
3135
3158
|
const result = await datasetsCollection.findOneAndUpdate({ id: args.datasetId }, { $inc: { version: 1 } }, {
|
|
3136
3159
|
session,
|
|
3137
3160
|
returnDocument: "after"
|
|
@@ -3142,9 +3165,18 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
|
|
|
3142
3165
|
category: ErrorCategory.USER,
|
|
3143
3166
|
details: { datasetId: args.datasetId }
|
|
3144
3167
|
});
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3168
|
+
const mergedInput = args.input !== void 0 ? args.input : existing.input;
|
|
3169
|
+
const mergedGroundTruth = args.groundTruth !== void 0 ? args.groundTruth : existing.groundTruth;
|
|
3170
|
+
const mergedExpectedTrajectory = args.expectedTrajectory !== void 0 ? args.expectedTrajectory : existing.expectedTrajectory;
|
|
3171
|
+
const mergedToolMocks = args.toolMocks !== void 0 ? args.toolMocks : existing.toolMocks;
|
|
3172
|
+
const mergedUnmockedToolPolicy = args.unmockedToolPolicy !== void 0 ? args.unmockedToolPolicy : existing.unmockedToolPolicy;
|
|
3173
|
+
const mergedScorerIds = args.scorerIds !== void 0 ? args.scorerIds ?? void 0 : existing.scorerIds;
|
|
3174
|
+
const mergedRequestContext = args.requestContext !== void 0 ? args.requestContext : existing.requestContext;
|
|
3175
|
+
const mergedMetadata = args.metadata !== void 0 ? args.metadata : existing.metadata;
|
|
3176
|
+
const mergedSource = args.source !== void 0 ? args.source : existing.source;
|
|
3177
|
+
const newVersion = result.version;
|
|
3178
|
+
const parentOrganizationId = result.organizationId ?? null;
|
|
3179
|
+
const parentProjectId = result.projectId ?? null;
|
|
3148
3180
|
await itemsCollection.updateOne({
|
|
3149
3181
|
id: args.id,
|
|
3150
3182
|
validTo: null,
|
|
@@ -3177,23 +3209,24 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
|
|
|
3177
3209
|
version: newVersion,
|
|
3178
3210
|
createdAt: now
|
|
3179
3211
|
}, { session });
|
|
3212
|
+
updated = {
|
|
3213
|
+
...existing,
|
|
3214
|
+
datasetVersion: newVersion,
|
|
3215
|
+
organizationId: parentOrganizationId,
|
|
3216
|
+
projectId: parentProjectId,
|
|
3217
|
+
input: mergedInput,
|
|
3218
|
+
groundTruth: mergedGroundTruth,
|
|
3219
|
+
expectedTrajectory: mergedExpectedTrajectory,
|
|
3220
|
+
toolMocks: mergedToolMocks,
|
|
3221
|
+
unmockedToolPolicy: mergedUnmockedToolPolicy,
|
|
3222
|
+
scorerIds: mergedScorerIds,
|
|
3223
|
+
requestContext: mergedRequestContext,
|
|
3224
|
+
metadata: mergedMetadata,
|
|
3225
|
+
source: mergedSource,
|
|
3226
|
+
updatedAt: now
|
|
3227
|
+
};
|
|
3180
3228
|
});
|
|
3181
|
-
return
|
|
3182
|
-
...existing,
|
|
3183
|
-
datasetVersion: newVersion,
|
|
3184
|
-
organizationId: parentOrganizationId,
|
|
3185
|
-
projectId: parentProjectId,
|
|
3186
|
-
input: mergedInput,
|
|
3187
|
-
groundTruth: mergedGroundTruth,
|
|
3188
|
-
expectedTrajectory: mergedExpectedTrajectory,
|
|
3189
|
-
toolMocks: mergedToolMocks,
|
|
3190
|
-
unmockedToolPolicy: mergedUnmockedToolPolicy,
|
|
3191
|
-
scorerIds: mergedScorerIds,
|
|
3192
|
-
requestContext: mergedRequestContext,
|
|
3193
|
-
metadata: mergedMetadata,
|
|
3194
|
-
source: mergedSource,
|
|
3195
|
-
updatedAt: now
|
|
3196
|
-
};
|
|
3229
|
+
return updated;
|
|
3197
3230
|
} catch (error) {
|
|
3198
3231
|
if (error instanceof MastraError) throw error;
|
|
3199
3232
|
throw new MastraError({
|
|
@@ -3205,24 +3238,29 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
|
|
|
3205
3238
|
}
|
|
3206
3239
|
async _doDeleteItem({ id, datasetId }) {
|
|
3207
3240
|
try {
|
|
3208
|
-
const existing = await this.getItemById({ id });
|
|
3209
|
-
if (!existing) return;
|
|
3210
|
-
if (existing.datasetId !== datasetId) throw new MastraError({
|
|
3211
|
-
id: createStorageErrorId("MONGODB", "DELETE_ITEM", "DATASET_MISMATCH"),
|
|
3212
|
-
domain: ErrorDomain.STORAGE,
|
|
3213
|
-
category: ErrorCategory.USER,
|
|
3214
|
-
details: {
|
|
3215
|
-
itemId: id,
|
|
3216
|
-
expectedDatasetId: datasetId,
|
|
3217
|
-
actualDatasetId: existing.datasetId
|
|
3218
|
-
}
|
|
3219
|
-
});
|
|
3220
3241
|
const now = /* @__PURE__ */ new Date();
|
|
3221
3242
|
const versionId = randomUUID();
|
|
3222
3243
|
const datasetsCollection = await this.getCollection(TABLE_DATASETS);
|
|
3223
3244
|
const itemsCollection = await this.getCollection(TABLE_DATASET_ITEMS);
|
|
3224
3245
|
const versionsCollection = await this.getCollection(TABLE_DATASET_VERSIONS);
|
|
3225
3246
|
await this.#connector.withTransaction(async (session) => {
|
|
3247
|
+
const row = await itemsCollection.findOne({
|
|
3248
|
+
id,
|
|
3249
|
+
validTo: null,
|
|
3250
|
+
isDeleted: false
|
|
3251
|
+
}, { session });
|
|
3252
|
+
const existing = row ? this.transformItemRow(row) : null;
|
|
3253
|
+
if (!existing) return;
|
|
3254
|
+
if (existing.datasetId !== datasetId) throw new MastraError({
|
|
3255
|
+
id: createStorageErrorId("MONGODB", "DELETE_ITEM", "DATASET_MISMATCH"),
|
|
3256
|
+
domain: ErrorDomain.STORAGE,
|
|
3257
|
+
category: ErrorCategory.USER,
|
|
3258
|
+
details: {
|
|
3259
|
+
itemId: id,
|
|
3260
|
+
expectedDatasetId: datasetId,
|
|
3261
|
+
actualDatasetId: existing.datasetId
|
|
3262
|
+
}
|
|
3263
|
+
});
|
|
3226
3264
|
const result = await datasetsCollection.findOneAndUpdate({ id: datasetId }, { $inc: { version: 1 } }, {
|
|
3227
3265
|
session,
|
|
3228
3266
|
returnDocument: "after"
|
|
@@ -3444,19 +3482,19 @@ var MongoDBDatasetsStorage = class extends DatasetsStorage {
|
|
|
3444
3482
|
details: { datasetId: input.datasetId }
|
|
3445
3483
|
});
|
|
3446
3484
|
const itemsCollection = await this.getCollection(TABLE_DATASET_ITEMS);
|
|
3447
|
-
const currentItems = (await itemsCollection.find({
|
|
3448
|
-
id: { $in: input.itemIds },
|
|
3449
|
-
datasetId: input.datasetId,
|
|
3450
|
-
validTo: null,
|
|
3451
|
-
isDeleted: false
|
|
3452
|
-
}).toArray()).map((row) => this.transformItemRow(row));
|
|
3453
|
-
if (currentItems.length === 0) return;
|
|
3454
3485
|
const now = /* @__PURE__ */ new Date();
|
|
3455
3486
|
const versionId = randomUUID();
|
|
3456
3487
|
const datasetsCollection = await this.getCollection(TABLE_DATASETS);
|
|
3457
3488
|
const versionsCollection = await this.getCollection(TABLE_DATASET_VERSIONS);
|
|
3458
|
-
const currentIds = currentItems.map((i) => i.id);
|
|
3459
3489
|
await this.#connector.withTransaction(async (session) => {
|
|
3490
|
+
const currentItems = (await itemsCollection.find({
|
|
3491
|
+
id: { $in: input.itemIds },
|
|
3492
|
+
datasetId: input.datasetId,
|
|
3493
|
+
validTo: null,
|
|
3494
|
+
isDeleted: false
|
|
3495
|
+
}, { session }).toArray()).map((row) => this.transformItemRow(row));
|
|
3496
|
+
if (currentItems.length === 0) return;
|
|
3497
|
+
const currentIds = currentItems.map((i) => i.id);
|
|
3460
3498
|
const result = await datasetsCollection.findOneAndUpdate({ id: input.datasetId }, { $inc: { version: 1 } }, {
|
|
3461
3499
|
session,
|
|
3462
3500
|
returnDocument: "after"
|