@mastra/mongodb 1.1.0-alpha.0 → 1.1.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/CHANGELOG.md +118 -0
- package/dist/docs/README.md +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +83 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +83 -26
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/agents/index.d.ts +12 -0
- package/dist/storage/domains/agents/index.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { saveScorePayloadSchema } from '@mastra/core/evals';
|
|
|
11
11
|
|
|
12
12
|
// package.json
|
|
13
13
|
var package_default = {
|
|
14
|
-
version: "1.1.0
|
|
14
|
+
version: "1.1.0"};
|
|
15
15
|
var MongoDBFilterTranslator = class extends BaseFilterTranslator {
|
|
16
16
|
getSupportedOperators() {
|
|
17
17
|
return {
|
|
@@ -892,6 +892,21 @@ function resolveMongoDBConfig(config) {
|
|
|
892
892
|
);
|
|
893
893
|
}
|
|
894
894
|
}
|
|
895
|
+
var SNAPSHOT_FIELDS = [
|
|
896
|
+
"name",
|
|
897
|
+
"description",
|
|
898
|
+
"instructions",
|
|
899
|
+
"model",
|
|
900
|
+
"tools",
|
|
901
|
+
"defaultOptions",
|
|
902
|
+
"workflows",
|
|
903
|
+
"agents",
|
|
904
|
+
"integrationTools",
|
|
905
|
+
"inputProcessors",
|
|
906
|
+
"outputProcessors",
|
|
907
|
+
"memory",
|
|
908
|
+
"scorers"
|
|
909
|
+
];
|
|
895
910
|
var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends AgentsStorage {
|
|
896
911
|
#connector;
|
|
897
912
|
#skipDefaultIndexes;
|
|
@@ -997,11 +1012,28 @@ var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends AgentsStorage {
|
|
|
997
1012
|
}
|
|
998
1013
|
const now = /* @__PURE__ */ new Date();
|
|
999
1014
|
const newAgent = {
|
|
1000
|
-
|
|
1015
|
+
id: agent.id,
|
|
1016
|
+
status: "draft",
|
|
1017
|
+
activeVersionId: void 0,
|
|
1018
|
+
authorId: agent.authorId,
|
|
1019
|
+
metadata: agent.metadata,
|
|
1001
1020
|
createdAt: now,
|
|
1002
1021
|
updatedAt: now
|
|
1003
1022
|
};
|
|
1004
1023
|
await collection.insertOne(this.serializeAgent(newAgent));
|
|
1024
|
+
const { id: _id, authorId: _authorId, metadata: _metadata, ...snapshotConfig } = agent;
|
|
1025
|
+
const versionId = crypto.randomUUID();
|
|
1026
|
+
await this.createVersion({
|
|
1027
|
+
id: versionId,
|
|
1028
|
+
agentId: agent.id,
|
|
1029
|
+
versionNumber: 1,
|
|
1030
|
+
...snapshotConfig,
|
|
1031
|
+
changedFields: Object.keys(snapshotConfig),
|
|
1032
|
+
changeMessage: "Initial version"
|
|
1033
|
+
});
|
|
1034
|
+
newAgent.activeVersionId = versionId;
|
|
1035
|
+
newAgent.status = "published";
|
|
1036
|
+
await collection.updateOne({ id: agent.id }, { $set: { activeVersionId: versionId, status: "published" } });
|
|
1005
1037
|
return newAgent;
|
|
1006
1038
|
} catch (error) {
|
|
1007
1039
|
if (error instanceof MastraError) {
|
|
@@ -1034,21 +1066,11 @@ var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends AgentsStorage {
|
|
|
1034
1066
|
const updateDoc = {
|
|
1035
1067
|
updatedAt: /* @__PURE__ */ new Date()
|
|
1036
1068
|
};
|
|
1037
|
-
if (updates.
|
|
1038
|
-
if (updates.
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
if (updates.defaultOptions !== void 0) updateDoc.defaultOptions = updates.defaultOptions;
|
|
1043
|
-
if (updates.workflows !== void 0) updateDoc.workflows = updates.workflows;
|
|
1044
|
-
if (updates.agents !== void 0) updateDoc.agents = updates.agents;
|
|
1045
|
-
if (updates.inputProcessors !== void 0) updateDoc.inputProcessors = updates.inputProcessors;
|
|
1046
|
-
if (updates.outputProcessors !== void 0) updateDoc.outputProcessors = updates.outputProcessors;
|
|
1047
|
-
if (updates.memory !== void 0) updateDoc.memory = updates.memory;
|
|
1048
|
-
if (updates.scorers !== void 0) updateDoc.scorers = updates.scorers;
|
|
1049
|
-
if (updates.integrationTools !== void 0) updateDoc.integrationTools = updates.integrationTools;
|
|
1050
|
-
if (updates.ownerId !== void 0) updateDoc.ownerId = updates.ownerId;
|
|
1051
|
-
if (updates.activeVersionId !== void 0) updateDoc.activeVersionId = updates.activeVersionId;
|
|
1069
|
+
if (updates.authorId !== void 0) updateDoc.authorId = updates.authorId;
|
|
1070
|
+
if (updates.activeVersionId !== void 0) {
|
|
1071
|
+
updateDoc.activeVersionId = updates.activeVersionId;
|
|
1072
|
+
updateDoc.status = "published";
|
|
1073
|
+
}
|
|
1052
1074
|
if (updates.metadata !== void 0) {
|
|
1053
1075
|
const existingMetadata = existingAgent.metadata || {};
|
|
1054
1076
|
updateDoc.metadata = { ...existingMetadata, ...updates.metadata };
|
|
@@ -1153,17 +1175,35 @@ var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends AgentsStorage {
|
|
|
1153
1175
|
);
|
|
1154
1176
|
}
|
|
1155
1177
|
}
|
|
1178
|
+
/**
|
|
1179
|
+
* Transforms a raw MongoDB document into a thin StorageAgentType record.
|
|
1180
|
+
* Only returns metadata-level fields (no config/snapshot fields).
|
|
1181
|
+
*/
|
|
1156
1182
|
transformAgent(doc) {
|
|
1157
|
-
const { _id, ...
|
|
1183
|
+
const { _id, ...rest } = doc;
|
|
1158
1184
|
return {
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1185
|
+
id: rest.id,
|
|
1186
|
+
status: rest.status,
|
|
1187
|
+
activeVersionId: rest.activeVersionId,
|
|
1188
|
+
authorId: rest.authorId,
|
|
1189
|
+
metadata: rest.metadata,
|
|
1190
|
+
createdAt: rest.createdAt instanceof Date ? rest.createdAt : new Date(rest.createdAt),
|
|
1191
|
+
updatedAt: rest.updatedAt instanceof Date ? rest.updatedAt : new Date(rest.updatedAt)
|
|
1162
1192
|
};
|
|
1163
1193
|
}
|
|
1194
|
+
/**
|
|
1195
|
+
* Serializes a thin StorageAgentType record for MongoDB insertion.
|
|
1196
|
+
* Only persists metadata-level fields.
|
|
1197
|
+
*/
|
|
1164
1198
|
serializeAgent(agent) {
|
|
1165
1199
|
return {
|
|
1166
|
-
|
|
1200
|
+
id: agent.id,
|
|
1201
|
+
status: agent.status,
|
|
1202
|
+
activeVersionId: agent.activeVersionId,
|
|
1203
|
+
authorId: agent.authorId,
|
|
1204
|
+
metadata: agent.metadata,
|
|
1205
|
+
createdAt: agent.createdAt,
|
|
1206
|
+
updatedAt: agent.updatedAt
|
|
1167
1207
|
};
|
|
1168
1208
|
}
|
|
1169
1209
|
// ==========================================================================
|
|
@@ -1177,12 +1217,15 @@ var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends AgentsStorage {
|
|
|
1177
1217
|
id: input.id,
|
|
1178
1218
|
agentId: input.agentId,
|
|
1179
1219
|
versionNumber: input.versionNumber,
|
|
1180
|
-
name: input.name ?? void 0,
|
|
1181
|
-
snapshot: input.snapshot,
|
|
1182
1220
|
changedFields: input.changedFields ?? void 0,
|
|
1183
1221
|
changeMessage: input.changeMessage ?? void 0,
|
|
1184
1222
|
createdAt: now
|
|
1185
1223
|
};
|
|
1224
|
+
for (const field of SNAPSHOT_FIELDS) {
|
|
1225
|
+
if (input[field] !== void 0) {
|
|
1226
|
+
versionDoc[field] = input[field];
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1186
1229
|
await collection.insertOne(versionDoc);
|
|
1187
1230
|
return {
|
|
1188
1231
|
...input,
|
|
@@ -1365,12 +1408,26 @@ var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends AgentsStorage {
|
|
|
1365
1408
|
// ==========================================================================
|
|
1366
1409
|
// Private Helper Methods
|
|
1367
1410
|
// ==========================================================================
|
|
1411
|
+
/**
|
|
1412
|
+
* Transforms a raw MongoDB version document into an AgentVersion.
|
|
1413
|
+
* Config fields are returned directly (no nested snapshot object).
|
|
1414
|
+
*/
|
|
1368
1415
|
transformVersion(doc) {
|
|
1369
1416
|
const { _id, ...version } = doc;
|
|
1370
|
-
|
|
1371
|
-
|
|
1417
|
+
const result = {
|
|
1418
|
+
id: version.id,
|
|
1419
|
+
agentId: version.agentId,
|
|
1420
|
+
versionNumber: version.versionNumber,
|
|
1421
|
+
changedFields: version.changedFields,
|
|
1422
|
+
changeMessage: version.changeMessage,
|
|
1372
1423
|
createdAt: version.createdAt instanceof Date ? version.createdAt : new Date(version.createdAt)
|
|
1373
1424
|
};
|
|
1425
|
+
for (const field of SNAPSHOT_FIELDS) {
|
|
1426
|
+
if (version[field] !== void 0) {
|
|
1427
|
+
result[field] = version[field];
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
return result;
|
|
1374
1431
|
}
|
|
1375
1432
|
};
|
|
1376
1433
|
function formatDateForMongoDB(date) {
|