@mastra/mongodb 1.3.1 → 1.4.0-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/CHANGELOG.md +127 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +1600 -350
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1599 -352
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/agents/index.d.ts +0 -1
- package/dist/storage/domains/agents/index.d.ts.map +1 -1
- package/dist/storage/domains/blobs/index.d.ts +21 -0
- package/dist/storage/domains/blobs/index.d.ts.map +1 -0
- package/dist/storage/domains/mcp-clients/index.d.ts +0 -1
- package/dist/storage/domains/mcp-clients/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/prompt-blocks/index.d.ts +0 -1
- package/dist/storage/domains/prompt-blocks/index.d.ts.map +1 -1
- package/dist/storage/domains/scorer-definitions/index.d.ts +0 -1
- package/dist/storage/domains/scorer-definitions/index.d.ts.map +1 -1
- package/dist/storage/domains/skills/index.d.ts +35 -0
- package/dist/storage/domains/skills/index.d.ts.map +1 -0
- package/dist/storage/domains/workspaces/index.d.ts +35 -0
- package/dist/storage/domains/workspaces/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +4 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -14,7 +14,7 @@ var evals = require('@mastra/core/evals');
|
|
|
14
14
|
|
|
15
15
|
// package.json
|
|
16
16
|
var package_default = {
|
|
17
|
-
version: "1.
|
|
17
|
+
version: "1.4.0-alpha.0"};
|
|
18
18
|
var MongoDBFilterTranslator = class extends filter.BaseFilterTranslator {
|
|
19
19
|
getSupportedOperators() {
|
|
20
20
|
return {
|
|
@@ -910,7 +910,10 @@ var SNAPSHOT_FIELDS = [
|
|
|
910
910
|
"memory",
|
|
911
911
|
"scorers",
|
|
912
912
|
"mcpClients",
|
|
913
|
-
"requestContextSchema"
|
|
913
|
+
"requestContextSchema",
|
|
914
|
+
"workspace",
|
|
915
|
+
"skills",
|
|
916
|
+
"skillsFormat"
|
|
914
917
|
];
|
|
915
918
|
var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends storage.AgentsStorage {
|
|
916
919
|
#connector;
|
|
@@ -1109,46 +1112,16 @@ var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends storage.AgentsSto
|
|
|
1109
1112
|
const metadataFields = {
|
|
1110
1113
|
authorId: updates.authorId,
|
|
1111
1114
|
activeVersionId: updates.activeVersionId,
|
|
1112
|
-
metadata: updates.metadata
|
|
1115
|
+
metadata: updates.metadata,
|
|
1116
|
+
status: updates.status
|
|
1113
1117
|
};
|
|
1114
|
-
const configFields = {};
|
|
1115
|
-
for (const field of SNAPSHOT_FIELDS) {
|
|
1116
|
-
if (updates[field] !== void 0) {
|
|
1117
|
-
configFields[field] = updates[field];
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
if (Object.keys(configFields).length > 0) {
|
|
1121
|
-
const latestVersion = await this.getLatestVersion(id);
|
|
1122
|
-
const nextVersionNumber = latestVersion ? latestVersion.versionNumber + 1 : 1;
|
|
1123
|
-
if (!latestVersion) {
|
|
1124
|
-
throw new error.MastraError({
|
|
1125
|
-
id: storage.createStorageErrorId("MONGODB", "UPDATE_AGENT", "NO_VERSION"),
|
|
1126
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1127
|
-
category: error.ErrorCategory.USER,
|
|
1128
|
-
text: `Cannot update config fields for agent ${id} - no versions exist`,
|
|
1129
|
-
details: { id }
|
|
1130
|
-
});
|
|
1131
|
-
}
|
|
1132
|
-
const sanitizedConfigFields = Object.fromEntries(
|
|
1133
|
-
Object.entries(configFields).map(([key, value]) => [key, value === null ? void 0 : value])
|
|
1134
|
-
);
|
|
1135
|
-
const versionInput = {
|
|
1136
|
-
id: crypto.randomUUID(),
|
|
1137
|
-
agentId: id,
|
|
1138
|
-
versionNumber: nextVersionNumber,
|
|
1139
|
-
...this.extractSnapshotFields(latestVersion),
|
|
1140
|
-
// Start from latest version
|
|
1141
|
-
...sanitizedConfigFields,
|
|
1142
|
-
// Apply updates (null values converted to undefined)
|
|
1143
|
-
changedFields: Object.keys(configFields),
|
|
1144
|
-
changeMessage: `Updated: ${Object.keys(configFields).join(", ")}`
|
|
1145
|
-
};
|
|
1146
|
-
await this.createVersion(versionInput);
|
|
1147
|
-
}
|
|
1148
1118
|
if (metadataFields.authorId !== void 0) updateDoc.authorId = metadataFields.authorId;
|
|
1149
1119
|
if (metadataFields.activeVersionId !== void 0) {
|
|
1150
1120
|
updateDoc.activeVersionId = metadataFields.activeVersionId;
|
|
1151
1121
|
}
|
|
1122
|
+
if (metadataFields.status !== void 0) {
|
|
1123
|
+
updateDoc.status = metadataFields.status;
|
|
1124
|
+
}
|
|
1152
1125
|
if (metadataFields.metadata !== void 0) {
|
|
1153
1126
|
const existingMetadata = existingAgent.metadata || {};
|
|
1154
1127
|
updateDoc.metadata = { ...existingMetadata, ...metadataFields.metadata };
|
|
@@ -1199,7 +1172,7 @@ var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends storage.AgentsSto
|
|
|
1199
1172
|
}
|
|
1200
1173
|
async list(args) {
|
|
1201
1174
|
try {
|
|
1202
|
-
const { page = 0, perPage: perPageInput, orderBy } = args || {};
|
|
1175
|
+
const { page = 0, perPage: perPageInput, orderBy, authorId, metadata, status } = args || {};
|
|
1203
1176
|
const { field, direction } = this.parseOrderBy(orderBy);
|
|
1204
1177
|
if (page < 0) {
|
|
1205
1178
|
throw new error.MastraError(
|
|
@@ -1215,7 +1188,19 @@ var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends storage.AgentsSto
|
|
|
1215
1188
|
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
1216
1189
|
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
1217
1190
|
const collection = await this.getCollection(storage.TABLE_AGENTS);
|
|
1218
|
-
const
|
|
1191
|
+
const filter = {};
|
|
1192
|
+
if (status) {
|
|
1193
|
+
filter.status = status;
|
|
1194
|
+
}
|
|
1195
|
+
if (authorId) {
|
|
1196
|
+
filter.authorId = authorId;
|
|
1197
|
+
}
|
|
1198
|
+
if (metadata) {
|
|
1199
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
1200
|
+
filter[`metadata.${key}`] = value;
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
const total = await collection.countDocuments(filter);
|
|
1219
1204
|
if (total === 0 || perPage === 0) {
|
|
1220
1205
|
return {
|
|
1221
1206
|
agents: [],
|
|
@@ -1226,7 +1211,7 @@ var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends storage.AgentsSto
|
|
|
1226
1211
|
};
|
|
1227
1212
|
}
|
|
1228
1213
|
const sortOrder = direction === "ASC" ? 1 : -1;
|
|
1229
|
-
let cursor = collection.find(
|
|
1214
|
+
let cursor = collection.find(filter).sort({ [field]: sortOrder }).skip(offset);
|
|
1230
1215
|
if (perPageInput !== false) {
|
|
1231
1216
|
cursor = cursor.limit(perPage);
|
|
1232
1217
|
}
|
|
@@ -1489,15 +1474,6 @@ var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends storage.AgentsSto
|
|
|
1489
1474
|
/**
|
|
1490
1475
|
* Extracts just the snapshot config fields from a version.
|
|
1491
1476
|
*/
|
|
1492
|
-
extractSnapshotFields(version) {
|
|
1493
|
-
const result = {};
|
|
1494
|
-
for (const field of SNAPSHOT_FIELDS) {
|
|
1495
|
-
if (version[field] !== void 0) {
|
|
1496
|
-
result[field] = version[field];
|
|
1497
|
-
}
|
|
1498
|
-
}
|
|
1499
|
-
return result;
|
|
1500
|
-
}
|
|
1501
1477
|
/**
|
|
1502
1478
|
* Transforms a raw MongoDB version document into an AgentVersion.
|
|
1503
1479
|
* Config fields are returned directly (no nested snapshot object).
|
|
@@ -1520,6 +1496,201 @@ var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends storage.AgentsSto
|
|
|
1520
1496
|
return result;
|
|
1521
1497
|
}
|
|
1522
1498
|
};
|
|
1499
|
+
var MongoDBBlobStore = class _MongoDBBlobStore extends storage.BlobStore {
|
|
1500
|
+
#connector;
|
|
1501
|
+
#skipDefaultIndexes;
|
|
1502
|
+
#indexes;
|
|
1503
|
+
static MANAGED_COLLECTIONS = [storage.TABLE_SKILL_BLOBS];
|
|
1504
|
+
constructor(config) {
|
|
1505
|
+
super();
|
|
1506
|
+
this.#connector = resolveMongoDBConfig(config);
|
|
1507
|
+
this.#skipDefaultIndexes = config.skipDefaultIndexes;
|
|
1508
|
+
this.#indexes = config.indexes?.filter(
|
|
1509
|
+
(idx) => _MongoDBBlobStore.MANAGED_COLLECTIONS.includes(idx.collection)
|
|
1510
|
+
);
|
|
1511
|
+
}
|
|
1512
|
+
async getCollection(name) {
|
|
1513
|
+
return this.#connector.getCollection(name);
|
|
1514
|
+
}
|
|
1515
|
+
getDefaultIndexDefinitions() {
|
|
1516
|
+
return [{ collection: storage.TABLE_SKILL_BLOBS, keys: { hash: 1 }, options: { unique: true } }];
|
|
1517
|
+
}
|
|
1518
|
+
async createDefaultIndexes() {
|
|
1519
|
+
if (this.#skipDefaultIndexes) {
|
|
1520
|
+
return;
|
|
1521
|
+
}
|
|
1522
|
+
for (const indexDef of this.getDefaultIndexDefinitions()) {
|
|
1523
|
+
try {
|
|
1524
|
+
const collection = await this.getCollection(indexDef.collection);
|
|
1525
|
+
await collection.createIndex(indexDef.keys, indexDef.options);
|
|
1526
|
+
} catch (error) {
|
|
1527
|
+
this.logger?.warn?.(`Failed to create index on ${indexDef.collection}:`, error);
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
async createCustomIndexes() {
|
|
1532
|
+
if (!this.#indexes || this.#indexes.length === 0) {
|
|
1533
|
+
return;
|
|
1534
|
+
}
|
|
1535
|
+
for (const indexDef of this.#indexes) {
|
|
1536
|
+
try {
|
|
1537
|
+
const collection = await this.getCollection(indexDef.collection);
|
|
1538
|
+
await collection.createIndex(indexDef.keys, indexDef.options);
|
|
1539
|
+
} catch (error) {
|
|
1540
|
+
this.logger?.warn?.(`Failed to create custom index on ${indexDef.collection}:`, error);
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
async init() {
|
|
1545
|
+
await this.createDefaultIndexes();
|
|
1546
|
+
await this.createCustomIndexes();
|
|
1547
|
+
}
|
|
1548
|
+
async put(entry) {
|
|
1549
|
+
try {
|
|
1550
|
+
const collection = await this.getCollection(storage.TABLE_SKILL_BLOBS);
|
|
1551
|
+
const doc = {
|
|
1552
|
+
hash: entry.hash,
|
|
1553
|
+
content: entry.content,
|
|
1554
|
+
size: entry.size,
|
|
1555
|
+
mimeType: entry.mimeType ?? null,
|
|
1556
|
+
createdAt: entry.createdAt ?? /* @__PURE__ */ new Date()
|
|
1557
|
+
};
|
|
1558
|
+
await collection.updateOne({ hash: entry.hash }, { $setOnInsert: doc }, { upsert: true });
|
|
1559
|
+
} catch (error$1) {
|
|
1560
|
+
throw new error.MastraError(
|
|
1561
|
+
{
|
|
1562
|
+
id: storage.createStorageErrorId("MONGODB", "PUT_BLOB", "FAILED"),
|
|
1563
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1564
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1565
|
+
details: { hash: entry.hash }
|
|
1566
|
+
},
|
|
1567
|
+
error$1
|
|
1568
|
+
);
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
async get(hash) {
|
|
1572
|
+
try {
|
|
1573
|
+
const collection = await this.getCollection(storage.TABLE_SKILL_BLOBS);
|
|
1574
|
+
const result = await collection.findOne({ hash });
|
|
1575
|
+
if (!result) {
|
|
1576
|
+
return null;
|
|
1577
|
+
}
|
|
1578
|
+
return this.#parseDoc(result);
|
|
1579
|
+
} catch (error$1) {
|
|
1580
|
+
throw new error.MastraError(
|
|
1581
|
+
{
|
|
1582
|
+
id: storage.createStorageErrorId("MONGODB", "GET_BLOB", "FAILED"),
|
|
1583
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1584
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1585
|
+
details: { hash }
|
|
1586
|
+
},
|
|
1587
|
+
error$1
|
|
1588
|
+
);
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
async has(hash) {
|
|
1592
|
+
try {
|
|
1593
|
+
const collection = await this.getCollection(storage.TABLE_SKILL_BLOBS);
|
|
1594
|
+
const result = await collection.findOne({ hash }, { projection: { _id: 1 } });
|
|
1595
|
+
return result !== null;
|
|
1596
|
+
} catch (error$1) {
|
|
1597
|
+
throw new error.MastraError(
|
|
1598
|
+
{
|
|
1599
|
+
id: storage.createStorageErrorId("MONGODB", "HAS_BLOB", "FAILED"),
|
|
1600
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1601
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1602
|
+
details: { hash }
|
|
1603
|
+
},
|
|
1604
|
+
error$1
|
|
1605
|
+
);
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
async delete(hash) {
|
|
1609
|
+
try {
|
|
1610
|
+
const collection = await this.getCollection(storage.TABLE_SKILL_BLOBS);
|
|
1611
|
+
const result = await collection.deleteOne({ hash });
|
|
1612
|
+
return result.deletedCount > 0;
|
|
1613
|
+
} catch (error$1) {
|
|
1614
|
+
throw new error.MastraError(
|
|
1615
|
+
{
|
|
1616
|
+
id: storage.createStorageErrorId("MONGODB", "DELETE_BLOB", "FAILED"),
|
|
1617
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1618
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1619
|
+
details: { hash }
|
|
1620
|
+
},
|
|
1621
|
+
error$1
|
|
1622
|
+
);
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
async putMany(entries) {
|
|
1626
|
+
if (entries.length === 0) return;
|
|
1627
|
+
try {
|
|
1628
|
+
const collection = await this.getCollection(storage.TABLE_SKILL_BLOBS);
|
|
1629
|
+
const operations = entries.map((entry) => ({
|
|
1630
|
+
updateOne: {
|
|
1631
|
+
filter: { hash: entry.hash },
|
|
1632
|
+
update: {
|
|
1633
|
+
$setOnInsert: {
|
|
1634
|
+
hash: entry.hash,
|
|
1635
|
+
content: entry.content,
|
|
1636
|
+
size: entry.size,
|
|
1637
|
+
mimeType: entry.mimeType ?? null,
|
|
1638
|
+
createdAt: entry.createdAt ?? /* @__PURE__ */ new Date()
|
|
1639
|
+
}
|
|
1640
|
+
},
|
|
1641
|
+
upsert: true
|
|
1642
|
+
}
|
|
1643
|
+
}));
|
|
1644
|
+
await collection.bulkWrite(operations);
|
|
1645
|
+
} catch (error$1) {
|
|
1646
|
+
throw new error.MastraError(
|
|
1647
|
+
{
|
|
1648
|
+
id: storage.createStorageErrorId("MONGODB", "PUT_MANY_BLOBS", "FAILED"),
|
|
1649
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1650
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1651
|
+
details: { count: entries.length }
|
|
1652
|
+
},
|
|
1653
|
+
error$1
|
|
1654
|
+
);
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
async getMany(hashes) {
|
|
1658
|
+
const result = /* @__PURE__ */ new Map();
|
|
1659
|
+
if (hashes.length === 0) return result;
|
|
1660
|
+
try {
|
|
1661
|
+
const collection = await this.getCollection(storage.TABLE_SKILL_BLOBS);
|
|
1662
|
+
const docs = await collection.find({ hash: { $in: hashes } }).toArray();
|
|
1663
|
+
for (const doc of docs) {
|
|
1664
|
+
const entry = this.#parseDoc(doc);
|
|
1665
|
+
result.set(entry.hash, entry);
|
|
1666
|
+
}
|
|
1667
|
+
return result;
|
|
1668
|
+
} catch (error$1) {
|
|
1669
|
+
throw new error.MastraError(
|
|
1670
|
+
{
|
|
1671
|
+
id: storage.createStorageErrorId("MONGODB", "GET_MANY_BLOBS", "FAILED"),
|
|
1672
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1673
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1674
|
+
details: { count: hashes.length }
|
|
1675
|
+
},
|
|
1676
|
+
error$1
|
|
1677
|
+
);
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
async dangerouslyClearAll() {
|
|
1681
|
+
const collection = await this.getCollection(storage.TABLE_SKILL_BLOBS);
|
|
1682
|
+
await collection.deleteMany({});
|
|
1683
|
+
}
|
|
1684
|
+
#parseDoc(doc) {
|
|
1685
|
+
return {
|
|
1686
|
+
hash: doc.hash,
|
|
1687
|
+
content: doc.content,
|
|
1688
|
+
size: Number(doc.size),
|
|
1689
|
+
mimeType: doc.mimeType || void 0,
|
|
1690
|
+
createdAt: doc.createdAt instanceof Date ? doc.createdAt : new Date(doc.createdAt)
|
|
1691
|
+
};
|
|
1692
|
+
}
|
|
1693
|
+
};
|
|
1523
1694
|
var SNAPSHOT_FIELDS2 = ["name", "description", "servers"];
|
|
1524
1695
|
var MongoDBMCPClientsStorage = class _MongoDBMCPClientsStorage extends storage.MCPClientsStorage {
|
|
1525
1696
|
#connector;
|
|
@@ -1695,40 +1866,9 @@ var MongoDBMCPClientsStorage = class _MongoDBMCPClientsStorage extends storage.M
|
|
|
1695
1866
|
metadata: updates.metadata,
|
|
1696
1867
|
status: updates.status
|
|
1697
1868
|
};
|
|
1698
|
-
const configFields = {};
|
|
1699
|
-
for (const field of SNAPSHOT_FIELDS2) {
|
|
1700
|
-
if (updates[field] !== void 0) {
|
|
1701
|
-
configFields[field] = updates[field];
|
|
1702
|
-
}
|
|
1703
|
-
}
|
|
1704
|
-
if (Object.keys(configFields).length > 0) {
|
|
1705
|
-
const latestVersion = await this.getLatestVersion(id);
|
|
1706
|
-
if (!latestVersion) {
|
|
1707
|
-
throw new error.MastraError({
|
|
1708
|
-
id: storage.createStorageErrorId("MONGODB", "UPDATE_MCP_CLIENT", "NO_VERSION"),
|
|
1709
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1710
|
-
category: error.ErrorCategory.USER,
|
|
1711
|
-
text: `Cannot update config fields for MCP client ${id} - no versions exist`,
|
|
1712
|
-
details: { id }
|
|
1713
|
-
});
|
|
1714
|
-
}
|
|
1715
|
-
const existingSnapshot = this.extractSnapshotFields(latestVersion);
|
|
1716
|
-
await this.createVersion({
|
|
1717
|
-
id: crypto.randomUUID(),
|
|
1718
|
-
mcpClientId: id,
|
|
1719
|
-
versionNumber: latestVersion.versionNumber + 1,
|
|
1720
|
-
...existingSnapshot,
|
|
1721
|
-
...configFields,
|
|
1722
|
-
changedFields: Object.keys(configFields),
|
|
1723
|
-
changeMessage: `Updated: ${Object.keys(configFields).join(", ")}`
|
|
1724
|
-
});
|
|
1725
|
-
}
|
|
1726
1869
|
if (metadataFields.authorId !== void 0) updateDoc.authorId = metadataFields.authorId;
|
|
1727
1870
|
if (metadataFields.activeVersionId !== void 0) {
|
|
1728
1871
|
updateDoc.activeVersionId = metadataFields.activeVersionId;
|
|
1729
|
-
if (metadataFields.status === void 0) {
|
|
1730
|
-
updateDoc.status = "published";
|
|
1731
|
-
}
|
|
1732
1872
|
}
|
|
1733
1873
|
if (metadataFields.status !== void 0) {
|
|
1734
1874
|
updateDoc.status = metadataFields.status;
|
|
@@ -1783,7 +1923,7 @@ var MongoDBMCPClientsStorage = class _MongoDBMCPClientsStorage extends storage.M
|
|
|
1783
1923
|
}
|
|
1784
1924
|
async list(args) {
|
|
1785
1925
|
try {
|
|
1786
|
-
const { page = 0, perPage: perPageInput, orderBy, authorId, metadata } = args || {};
|
|
1926
|
+
const { page = 0, perPage: perPageInput, orderBy, authorId, metadata, status = "published" } = args || {};
|
|
1787
1927
|
const { field, direction } = this.parseOrderBy(orderBy);
|
|
1788
1928
|
if (page < 0) {
|
|
1789
1929
|
throw new error.MastraError(
|
|
@@ -1800,6 +1940,7 @@ var MongoDBMCPClientsStorage = class _MongoDBMCPClientsStorage extends storage.M
|
|
|
1800
1940
|
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
1801
1941
|
const collection = await this.getCollection(storage.TABLE_MCP_CLIENTS);
|
|
1802
1942
|
const filter = {};
|
|
1943
|
+
filter.status = status;
|
|
1803
1944
|
if (authorId) {
|
|
1804
1945
|
filter.authorId = authorId;
|
|
1805
1946
|
}
|
|
@@ -2088,15 +2229,6 @@ var MongoDBMCPClientsStorage = class _MongoDBMCPClientsStorage extends storage.M
|
|
|
2088
2229
|
}
|
|
2089
2230
|
return result;
|
|
2090
2231
|
}
|
|
2091
|
-
extractSnapshotFields(version) {
|
|
2092
|
-
const result = {};
|
|
2093
|
-
for (const field of SNAPSHOT_FIELDS2) {
|
|
2094
|
-
if (version[field] !== void 0) {
|
|
2095
|
-
result[field] = version[field];
|
|
2096
|
-
}
|
|
2097
|
-
}
|
|
2098
|
-
return result;
|
|
2099
|
-
}
|
|
2100
2232
|
};
|
|
2101
2233
|
function formatDateForMongoDB(date) {
|
|
2102
2234
|
return typeof date === "string" ? new Date(date) : date;
|
|
@@ -2527,8 +2659,10 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends storage.MemorySto
|
|
|
2527
2659
|
content: typeof message.content === "object" ? JSON.stringify(message.content) : message.content,
|
|
2528
2660
|
role: message.role,
|
|
2529
2661
|
type: message.type || "v2",
|
|
2530
|
-
createdAt: formatDateForMongoDB(time),
|
|
2531
2662
|
resourceId: message.resourceId
|
|
2663
|
+
},
|
|
2664
|
+
$setOnInsert: {
|
|
2665
|
+
createdAt: formatDateForMongoDB(time)
|
|
2532
2666
|
}
|
|
2533
2667
|
},
|
|
2534
2668
|
upsert: true
|
|
@@ -4609,40 +4743,9 @@ var MongoDBPromptBlocksStorage = class _MongoDBPromptBlocksStorage extends stora
|
|
|
4609
4743
|
metadata: updates.metadata,
|
|
4610
4744
|
status: updates.status
|
|
4611
4745
|
};
|
|
4612
|
-
const configFields = {};
|
|
4613
|
-
for (const field of SNAPSHOT_FIELDS3) {
|
|
4614
|
-
if (updates[field] !== void 0) {
|
|
4615
|
-
configFields[field] = updates[field];
|
|
4616
|
-
}
|
|
4617
|
-
}
|
|
4618
|
-
if (Object.keys(configFields).length > 0) {
|
|
4619
|
-
const latestVersion = await this.getLatestVersion(id);
|
|
4620
|
-
if (!latestVersion) {
|
|
4621
|
-
throw new error.MastraError({
|
|
4622
|
-
id: storage.createStorageErrorId("MONGODB", "UPDATE_PROMPT_BLOCK", "NO_VERSION"),
|
|
4623
|
-
domain: error.ErrorDomain.STORAGE,
|
|
4624
|
-
category: error.ErrorCategory.USER,
|
|
4625
|
-
text: `Cannot update config fields for prompt block ${id} - no versions exist`,
|
|
4626
|
-
details: { id }
|
|
4627
|
-
});
|
|
4628
|
-
}
|
|
4629
|
-
const existingSnapshot = this.extractSnapshotFields(latestVersion);
|
|
4630
|
-
await this.createVersion({
|
|
4631
|
-
id: crypto.randomUUID(),
|
|
4632
|
-
blockId: id,
|
|
4633
|
-
versionNumber: latestVersion.versionNumber + 1,
|
|
4634
|
-
...existingSnapshot,
|
|
4635
|
-
...configFields,
|
|
4636
|
-
changedFields: Object.keys(configFields),
|
|
4637
|
-
changeMessage: `Updated: ${Object.keys(configFields).join(", ")}`
|
|
4638
|
-
});
|
|
4639
|
-
}
|
|
4640
4746
|
if (metadataFields.authorId !== void 0) updateDoc.authorId = metadataFields.authorId;
|
|
4641
4747
|
if (metadataFields.activeVersionId !== void 0) {
|
|
4642
4748
|
updateDoc.activeVersionId = metadataFields.activeVersionId;
|
|
4643
|
-
if (metadataFields.status === void 0) {
|
|
4644
|
-
updateDoc.status = "published";
|
|
4645
|
-
}
|
|
4646
4749
|
}
|
|
4647
4750
|
if (metadataFields.status !== void 0) {
|
|
4648
4751
|
updateDoc.status = metadataFields.status;
|
|
@@ -4697,7 +4800,7 @@ var MongoDBPromptBlocksStorage = class _MongoDBPromptBlocksStorage extends stora
|
|
|
4697
4800
|
}
|
|
4698
4801
|
async list(args) {
|
|
4699
4802
|
try {
|
|
4700
|
-
const { page = 0, perPage: perPageInput, orderBy, authorId, metadata } = args || {};
|
|
4803
|
+
const { page = 0, perPage: perPageInput, orderBy, authorId, metadata, status = "published" } = args || {};
|
|
4701
4804
|
const { field, direction } = this.parseOrderBy(orderBy);
|
|
4702
4805
|
if (page < 0) {
|
|
4703
4806
|
throw new error.MastraError(
|
|
@@ -4714,6 +4817,7 @@ var MongoDBPromptBlocksStorage = class _MongoDBPromptBlocksStorage extends stora
|
|
|
4714
4817
|
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
4715
4818
|
const collection = await this.getCollection(storage.TABLE_PROMPT_BLOCKS);
|
|
4716
4819
|
const filter = {};
|
|
4820
|
+
filter.status = status;
|
|
4717
4821
|
if (authorId) {
|
|
4718
4822
|
filter.authorId = authorId;
|
|
4719
4823
|
}
|
|
@@ -5002,15 +5106,6 @@ var MongoDBPromptBlocksStorage = class _MongoDBPromptBlocksStorage extends stora
|
|
|
5002
5106
|
}
|
|
5003
5107
|
return result;
|
|
5004
5108
|
}
|
|
5005
|
-
extractSnapshotFields(version) {
|
|
5006
|
-
const result = {};
|
|
5007
|
-
for (const field of SNAPSHOT_FIELDS3) {
|
|
5008
|
-
if (version[field] !== void 0) {
|
|
5009
|
-
result[field] = version[field];
|
|
5010
|
-
}
|
|
5011
|
-
}
|
|
5012
|
-
return result;
|
|
5013
|
-
}
|
|
5014
5109
|
};
|
|
5015
5110
|
var SNAPSHOT_FIELDS4 = [
|
|
5016
5111
|
"name",
|
|
@@ -5191,40 +5286,9 @@ var MongoDBScorerDefinitionsStorage = class _MongoDBScorerDefinitionsStorage ext
|
|
|
5191
5286
|
metadata: updates.metadata,
|
|
5192
5287
|
status: updates.status
|
|
5193
5288
|
};
|
|
5194
|
-
const configFields = {};
|
|
5195
|
-
for (const field of SNAPSHOT_FIELDS4) {
|
|
5196
|
-
if (updates[field] !== void 0) {
|
|
5197
|
-
configFields[field] = updates[field];
|
|
5198
|
-
}
|
|
5199
|
-
}
|
|
5200
|
-
if (Object.keys(configFields).length > 0) {
|
|
5201
|
-
const latestVersion = await this.getLatestVersion(id);
|
|
5202
|
-
if (!latestVersion) {
|
|
5203
|
-
throw new error.MastraError({
|
|
5204
|
-
id: storage.createStorageErrorId("MONGODB", "UPDATE_SCORER_DEFINITION", "NO_VERSION"),
|
|
5205
|
-
domain: error.ErrorDomain.STORAGE,
|
|
5206
|
-
category: error.ErrorCategory.USER,
|
|
5207
|
-
text: `Cannot update config fields for scorer definition ${id} - no versions exist`,
|
|
5208
|
-
details: { id }
|
|
5209
|
-
});
|
|
5210
|
-
}
|
|
5211
|
-
const existingSnapshot = this.extractSnapshotFields(latestVersion);
|
|
5212
|
-
await this.createVersion({
|
|
5213
|
-
id: crypto.randomUUID(),
|
|
5214
|
-
scorerDefinitionId: id,
|
|
5215
|
-
versionNumber: latestVersion.versionNumber + 1,
|
|
5216
|
-
...existingSnapshot,
|
|
5217
|
-
...configFields,
|
|
5218
|
-
changedFields: Object.keys(configFields),
|
|
5219
|
-
changeMessage: `Updated: ${Object.keys(configFields).join(", ")}`
|
|
5220
|
-
});
|
|
5221
|
-
}
|
|
5222
5289
|
if (metadataFields.authorId !== void 0) updateDoc.authorId = metadataFields.authorId;
|
|
5223
5290
|
if (metadataFields.activeVersionId !== void 0) {
|
|
5224
5291
|
updateDoc.activeVersionId = metadataFields.activeVersionId;
|
|
5225
|
-
if (metadataFields.status === void 0) {
|
|
5226
|
-
updateDoc.status = "published";
|
|
5227
|
-
}
|
|
5228
5292
|
}
|
|
5229
5293
|
if (metadataFields.status !== void 0) {
|
|
5230
5294
|
updateDoc.status = metadataFields.status;
|
|
@@ -5279,7 +5343,7 @@ var MongoDBScorerDefinitionsStorage = class _MongoDBScorerDefinitionsStorage ext
|
|
|
5279
5343
|
}
|
|
5280
5344
|
async list(args) {
|
|
5281
5345
|
try {
|
|
5282
|
-
const { page = 0, perPage: perPageInput, orderBy, authorId, metadata } = args || {};
|
|
5346
|
+
const { page = 0, perPage: perPageInput, orderBy, authorId, metadata, status } = args || {};
|
|
5283
5347
|
const { field, direction } = this.parseOrderBy(orderBy);
|
|
5284
5348
|
if (page < 0) {
|
|
5285
5349
|
throw new error.MastraError(
|
|
@@ -5296,6 +5360,9 @@ var MongoDBScorerDefinitionsStorage = class _MongoDBScorerDefinitionsStorage ext
|
|
|
5296
5360
|
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
5297
5361
|
const collection = await this.getCollection(storage.TABLE_SCORER_DEFINITIONS);
|
|
5298
5362
|
const filter = {};
|
|
5363
|
+
if (status) {
|
|
5364
|
+
filter.status = status;
|
|
5365
|
+
}
|
|
5299
5366
|
if (authorId) {
|
|
5300
5367
|
filter.authorId = authorId;
|
|
5301
5368
|
}
|
|
@@ -5584,15 +5651,6 @@ var MongoDBScorerDefinitionsStorage = class _MongoDBScorerDefinitionsStorage ext
|
|
|
5584
5651
|
}
|
|
5585
5652
|
return result;
|
|
5586
5653
|
}
|
|
5587
|
-
extractSnapshotFields(version) {
|
|
5588
|
-
const result = {};
|
|
5589
|
-
for (const field of SNAPSHOT_FIELDS4) {
|
|
5590
|
-
if (version[field] !== void 0) {
|
|
5591
|
-
result[field] = version[field];
|
|
5592
|
-
}
|
|
5593
|
-
}
|
|
5594
|
-
return result;
|
|
5595
|
-
}
|
|
5596
5654
|
};
|
|
5597
5655
|
function transformScoreRow(row) {
|
|
5598
5656
|
return storage.transformScoreRow(row, {
|
|
@@ -5962,43 +6020,50 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends storage.ScoresSto
|
|
|
5962
6020
|
}
|
|
5963
6021
|
}
|
|
5964
6022
|
};
|
|
5965
|
-
var
|
|
6023
|
+
var SNAPSHOT_FIELDS5 = [
|
|
6024
|
+
"name",
|
|
6025
|
+
"description",
|
|
6026
|
+
"instructions",
|
|
6027
|
+
"license",
|
|
6028
|
+
"compatibility",
|
|
6029
|
+
"source",
|
|
6030
|
+
"references",
|
|
6031
|
+
"scripts",
|
|
6032
|
+
"assets",
|
|
6033
|
+
"metadata",
|
|
6034
|
+
"tree"
|
|
6035
|
+
];
|
|
6036
|
+
var MongoDBSkillsStorage = class _MongoDBSkillsStorage extends storage.SkillsStorage {
|
|
5966
6037
|
#connector;
|
|
5967
6038
|
#skipDefaultIndexes;
|
|
5968
6039
|
#indexes;
|
|
5969
|
-
|
|
5970
|
-
static MANAGED_COLLECTIONS = [storage.TABLE_WORKFLOW_SNAPSHOT];
|
|
6040
|
+
static MANAGED_COLLECTIONS = [storage.TABLE_SKILLS, storage.TABLE_SKILL_VERSIONS];
|
|
5971
6041
|
constructor(config) {
|
|
5972
6042
|
super();
|
|
5973
6043
|
this.#connector = resolveMongoDBConfig(config);
|
|
5974
6044
|
this.#skipDefaultIndexes = config.skipDefaultIndexes;
|
|
5975
6045
|
this.#indexes = config.indexes?.filter(
|
|
5976
|
-
(idx) =>
|
|
6046
|
+
(idx) => _MongoDBSkillsStorage.MANAGED_COLLECTIONS.includes(idx.collection)
|
|
5977
6047
|
);
|
|
5978
6048
|
}
|
|
5979
6049
|
async getCollection(name) {
|
|
5980
6050
|
return this.#connector.getCollection(name);
|
|
5981
6051
|
}
|
|
5982
|
-
async init() {
|
|
5983
|
-
await this.createDefaultIndexes();
|
|
5984
|
-
await this.createCustomIndexes();
|
|
5985
|
-
}
|
|
5986
|
-
/**
|
|
5987
|
-
* Returns default index definitions for the workflows domain collections.
|
|
5988
|
-
*/
|
|
5989
6052
|
getDefaultIndexDefinitions() {
|
|
5990
6053
|
return [
|
|
5991
|
-
{ collection: storage.
|
|
5992
|
-
{ collection: storage.
|
|
5993
|
-
{ collection: storage.
|
|
5994
|
-
{ collection: storage.
|
|
5995
|
-
{ collection: storage.
|
|
5996
|
-
{
|
|
6054
|
+
{ collection: storage.TABLE_SKILLS, keys: { id: 1 }, options: { unique: true } },
|
|
6055
|
+
{ collection: storage.TABLE_SKILLS, keys: { status: 1 } },
|
|
6056
|
+
{ collection: storage.TABLE_SKILLS, keys: { createdAt: -1 } },
|
|
6057
|
+
{ collection: storage.TABLE_SKILLS, keys: { authorId: 1 } },
|
|
6058
|
+
{ collection: storage.TABLE_SKILL_VERSIONS, keys: { id: 1 }, options: { unique: true } },
|
|
6059
|
+
{
|
|
6060
|
+
collection: storage.TABLE_SKILL_VERSIONS,
|
|
6061
|
+
keys: { skillId: 1, versionNumber: -1 },
|
|
6062
|
+
options: { unique: true }
|
|
6063
|
+
},
|
|
6064
|
+
{ collection: storage.TABLE_SKILL_VERSIONS, keys: { skillId: 1 } }
|
|
5997
6065
|
];
|
|
5998
6066
|
}
|
|
5999
|
-
/**
|
|
6000
|
-
* Creates default indexes for optimal query performance.
|
|
6001
|
-
*/
|
|
6002
6067
|
async createDefaultIndexes() {
|
|
6003
6068
|
if (this.#skipDefaultIndexes) {
|
|
6004
6069
|
return;
|
|
@@ -6012,9 +6077,6 @@ var WorkflowsStorageMongoDB = class _WorkflowsStorageMongoDB extends storage.Wor
|
|
|
6012
6077
|
}
|
|
6013
6078
|
}
|
|
6014
6079
|
}
|
|
6015
|
-
/**
|
|
6016
|
-
* Creates custom user-defined indexes for this domain's collections.
|
|
6017
|
-
*/
|
|
6018
6080
|
async createCustomIndexes() {
|
|
6019
6081
|
if (!this.#indexes || this.#indexes.length === 0) {
|
|
6020
6082
|
return;
|
|
@@ -6028,216 +6090,1395 @@ var WorkflowsStorageMongoDB = class _WorkflowsStorageMongoDB extends storage.Wor
|
|
|
6028
6090
|
}
|
|
6029
6091
|
}
|
|
6030
6092
|
}
|
|
6031
|
-
async
|
|
6032
|
-
|
|
6033
|
-
await
|
|
6034
|
-
}
|
|
6035
|
-
updateWorkflowResults({
|
|
6036
|
-
// workflowName,
|
|
6037
|
-
// runId,
|
|
6038
|
-
// stepId,
|
|
6039
|
-
// result,
|
|
6040
|
-
// requestContext,
|
|
6041
|
-
}) {
|
|
6042
|
-
throw new Error("Method not implemented.");
|
|
6043
|
-
}
|
|
6044
|
-
updateWorkflowState({
|
|
6045
|
-
// workflowName,
|
|
6046
|
-
// runId,
|
|
6047
|
-
// opts,
|
|
6048
|
-
}) {
|
|
6049
|
-
throw new Error("Method not implemented.");
|
|
6093
|
+
async init() {
|
|
6094
|
+
await this.createDefaultIndexes();
|
|
6095
|
+
await this.createCustomIndexes();
|
|
6050
6096
|
}
|
|
6051
|
-
async
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
createdAt,
|
|
6057
|
-
updatedAt
|
|
6058
|
-
}) {
|
|
6059
|
-
try {
|
|
6060
|
-
const now = /* @__PURE__ */ new Date();
|
|
6061
|
-
const collection = await this.getCollection(storage.TABLE_WORKFLOW_SNAPSHOT);
|
|
6062
|
-
await collection.updateOne(
|
|
6063
|
-
{ workflow_name: workflowName, run_id: runId },
|
|
6064
|
-
{
|
|
6065
|
-
$set: {
|
|
6066
|
-
workflow_name: workflowName,
|
|
6067
|
-
run_id: runId,
|
|
6068
|
-
resourceId,
|
|
6069
|
-
snapshot,
|
|
6070
|
-
updatedAt: updatedAt ?? now
|
|
6071
|
-
},
|
|
6072
|
-
$setOnInsert: {
|
|
6073
|
-
createdAt: createdAt ?? now
|
|
6074
|
-
}
|
|
6075
|
-
},
|
|
6076
|
-
{ upsert: true }
|
|
6077
|
-
);
|
|
6078
|
-
} catch (error$1) {
|
|
6079
|
-
throw new error.MastraError(
|
|
6080
|
-
{
|
|
6081
|
-
id: storage.createStorageErrorId("MONGODB", "PERSIST_WORKFLOW_SNAPSHOT", "FAILED"),
|
|
6082
|
-
domain: error.ErrorDomain.STORAGE,
|
|
6083
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
6084
|
-
details: { workflowName, runId }
|
|
6085
|
-
},
|
|
6086
|
-
error$1
|
|
6087
|
-
);
|
|
6088
|
-
}
|
|
6097
|
+
async dangerouslyClearAll() {
|
|
6098
|
+
const versionsCollection = await this.getCollection(storage.TABLE_SKILL_VERSIONS);
|
|
6099
|
+
await versionsCollection.deleteMany({});
|
|
6100
|
+
const skillsCollection = await this.getCollection(storage.TABLE_SKILLS);
|
|
6101
|
+
await skillsCollection.deleteMany({});
|
|
6089
6102
|
}
|
|
6090
|
-
|
|
6091
|
-
|
|
6092
|
-
|
|
6093
|
-
|
|
6103
|
+
// ==========================================================================
|
|
6104
|
+
// Skill CRUD
|
|
6105
|
+
// ==========================================================================
|
|
6106
|
+
async getById(id) {
|
|
6094
6107
|
try {
|
|
6095
|
-
const collection = await this.getCollection(storage.
|
|
6096
|
-
const result = await collection.findOne({
|
|
6097
|
-
workflow_name: workflowName,
|
|
6098
|
-
run_id: runId
|
|
6099
|
-
});
|
|
6108
|
+
const collection = await this.getCollection(storage.TABLE_SKILLS);
|
|
6109
|
+
const result = await collection.findOne({ id });
|
|
6100
6110
|
if (!result) {
|
|
6101
6111
|
return null;
|
|
6102
6112
|
}
|
|
6103
|
-
return
|
|
6113
|
+
return this.transformSkill(result);
|
|
6104
6114
|
} catch (error$1) {
|
|
6105
6115
|
throw new error.MastraError(
|
|
6106
6116
|
{
|
|
6107
|
-
id: storage.createStorageErrorId("MONGODB", "
|
|
6117
|
+
id: storage.createStorageErrorId("MONGODB", "GET_SKILL_BY_ID", "FAILED"),
|
|
6108
6118
|
domain: error.ErrorDomain.STORAGE,
|
|
6109
6119
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
6110
|
-
details: {
|
|
6120
|
+
details: { id }
|
|
6111
6121
|
},
|
|
6112
6122
|
error$1
|
|
6113
6123
|
);
|
|
6114
6124
|
}
|
|
6115
6125
|
}
|
|
6116
|
-
async
|
|
6117
|
-
const
|
|
6126
|
+
async create(input) {
|
|
6127
|
+
const { skill } = input;
|
|
6118
6128
|
try {
|
|
6119
|
-
const
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
|
|
6123
|
-
|
|
6124
|
-
|
|
6125
|
-
|
|
6126
|
-
|
|
6127
|
-
|
|
6129
|
+
const collection = await this.getCollection(storage.TABLE_SKILLS);
|
|
6130
|
+
const id = skill.id;
|
|
6131
|
+
const existing = await collection.findOne({ id });
|
|
6132
|
+
if (existing) {
|
|
6133
|
+
throw new error.MastraError({
|
|
6134
|
+
id: storage.createStorageErrorId("MONGODB", "CREATE_SKILL", "ALREADY_EXISTS"),
|
|
6135
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6136
|
+
category: error.ErrorCategory.USER,
|
|
6137
|
+
details: { id },
|
|
6138
|
+
text: `Skill with id ${id} already exists`
|
|
6139
|
+
});
|
|
6128
6140
|
}
|
|
6129
|
-
|
|
6130
|
-
|
|
6131
|
-
|
|
6132
|
-
|
|
6133
|
-
|
|
6141
|
+
const now = /* @__PURE__ */ new Date();
|
|
6142
|
+
const newSkill = {
|
|
6143
|
+
id,
|
|
6144
|
+
status: "draft",
|
|
6145
|
+
activeVersionId: void 0,
|
|
6146
|
+
authorId: skill.authorId,
|
|
6147
|
+
createdAt: now,
|
|
6148
|
+
updatedAt: now
|
|
6149
|
+
};
|
|
6150
|
+
await collection.insertOne(this.serializeSkill(newSkill));
|
|
6151
|
+
const snapshotConfig = {};
|
|
6152
|
+
for (const field of SNAPSHOT_FIELDS5) {
|
|
6153
|
+
if (skill[field] !== void 0) {
|
|
6154
|
+
snapshotConfig[field] = skill[field];
|
|
6134
6155
|
}
|
|
6135
6156
|
}
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
|
|
6149
|
-
details: { page: options.page }
|
|
6150
|
-
},
|
|
6151
|
-
new Error("page must be >= 0")
|
|
6152
|
-
);
|
|
6153
|
-
}
|
|
6154
|
-
total = await collection.countDocuments(query);
|
|
6155
|
-
const normalizedPerPage = storage.normalizePerPage(options.perPage, Number.MAX_SAFE_INTEGER);
|
|
6156
|
-
if (normalizedPerPage === 0) {
|
|
6157
|
-
return { runs: [], total };
|
|
6158
|
-
}
|
|
6159
|
-
const offset = options.page * normalizedPerPage;
|
|
6160
|
-
cursor = cursor.skip(offset);
|
|
6161
|
-
cursor = cursor.limit(Math.min(normalizedPerPage, 2147483647));
|
|
6157
|
+
const versionId = crypto.randomUUID();
|
|
6158
|
+
try {
|
|
6159
|
+
await this.createVersion({
|
|
6160
|
+
id: versionId,
|
|
6161
|
+
skillId: id,
|
|
6162
|
+
versionNumber: 1,
|
|
6163
|
+
...snapshotConfig,
|
|
6164
|
+
changedFields: Object.keys(snapshotConfig),
|
|
6165
|
+
changeMessage: "Initial version"
|
|
6166
|
+
});
|
|
6167
|
+
} catch (versionError) {
|
|
6168
|
+
await collection.deleteOne({ id });
|
|
6169
|
+
throw versionError;
|
|
6162
6170
|
}
|
|
6163
|
-
|
|
6164
|
-
const runs = results.map((row) => this.parseWorkflowRun(row));
|
|
6165
|
-
return {
|
|
6166
|
-
runs,
|
|
6167
|
-
total: total || runs.length
|
|
6168
|
-
};
|
|
6171
|
+
return newSkill;
|
|
6169
6172
|
} catch (error$1) {
|
|
6173
|
+
if (error$1 instanceof error.MastraError) {
|
|
6174
|
+
throw error$1;
|
|
6175
|
+
}
|
|
6170
6176
|
throw new error.MastraError(
|
|
6171
6177
|
{
|
|
6172
|
-
id: storage.createStorageErrorId("MONGODB", "
|
|
6178
|
+
id: storage.createStorageErrorId("MONGODB", "CREATE_SKILL", "FAILED"),
|
|
6173
6179
|
domain: error.ErrorDomain.STORAGE,
|
|
6174
6180
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
6175
|
-
details: {
|
|
6181
|
+
details: { name: skill.name }
|
|
6176
6182
|
},
|
|
6177
6183
|
error$1
|
|
6178
6184
|
);
|
|
6179
6185
|
}
|
|
6180
6186
|
}
|
|
6181
|
-
async
|
|
6187
|
+
async update(input) {
|
|
6188
|
+
const { id, ...updates } = input;
|
|
6182
6189
|
try {
|
|
6183
|
-
const
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6190
|
+
const collection = await this.getCollection(storage.TABLE_SKILLS);
|
|
6191
|
+
const existingSkill = await collection.findOne({ id });
|
|
6192
|
+
if (!existingSkill) {
|
|
6193
|
+
throw new error.MastraError({
|
|
6194
|
+
id: storage.createStorageErrorId("MONGODB", "UPDATE_SKILL", "NOT_FOUND"),
|
|
6195
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6196
|
+
category: error.ErrorCategory.USER,
|
|
6197
|
+
details: { id },
|
|
6198
|
+
text: `Skill with id ${id} not found`
|
|
6199
|
+
});
|
|
6189
6200
|
}
|
|
6190
|
-
const
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6201
|
+
const updateDoc = {
|
|
6202
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
6203
|
+
};
|
|
6204
|
+
const metadataFields = {
|
|
6205
|
+
authorId: updates.authorId,
|
|
6206
|
+
activeVersionId: updates.activeVersionId,
|
|
6207
|
+
status: updates.status
|
|
6208
|
+
};
|
|
6209
|
+
const configFields = {};
|
|
6210
|
+
for (const field of SNAPSHOT_FIELDS5) {
|
|
6211
|
+
if (updates[field] !== void 0) {
|
|
6212
|
+
configFields[field] = updates[field];
|
|
6213
|
+
}
|
|
6194
6214
|
}
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6215
|
+
if (Object.keys(configFields).length > 0) {
|
|
6216
|
+
const latestVersion = await this.getLatestVersion(id);
|
|
6217
|
+
if (!latestVersion) {
|
|
6218
|
+
throw new error.MastraError({
|
|
6219
|
+
id: storage.createStorageErrorId("MONGODB", "UPDATE_SKILL", "NO_VERSION"),
|
|
6220
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6221
|
+
category: error.ErrorCategory.USER,
|
|
6222
|
+
text: `Cannot update config fields for skill ${id} - no versions exist`,
|
|
6223
|
+
details: { id }
|
|
6224
|
+
});
|
|
6225
|
+
}
|
|
6226
|
+
const existingSnapshot = this.extractSnapshotFields(latestVersion);
|
|
6227
|
+
await this.createVersion({
|
|
6228
|
+
id: crypto.randomUUID(),
|
|
6229
|
+
skillId: id,
|
|
6230
|
+
versionNumber: latestVersion.versionNumber + 1,
|
|
6231
|
+
...existingSnapshot,
|
|
6232
|
+
...configFields,
|
|
6233
|
+
changedFields: Object.keys(configFields),
|
|
6234
|
+
changeMessage: `Updated: ${Object.keys(configFields).join(", ")}`
|
|
6235
|
+
});
|
|
6236
|
+
}
|
|
6237
|
+
if (metadataFields.authorId !== void 0) updateDoc.authorId = metadataFields.authorId;
|
|
6238
|
+
if (metadataFields.activeVersionId !== void 0) {
|
|
6239
|
+
updateDoc.activeVersionId = metadataFields.activeVersionId;
|
|
6240
|
+
if (metadataFields.status === void 0) {
|
|
6241
|
+
updateDoc.status = "published";
|
|
6242
|
+
}
|
|
6243
|
+
}
|
|
6244
|
+
if (metadataFields.status !== void 0) {
|
|
6245
|
+
updateDoc.status = metadataFields.status;
|
|
6246
|
+
}
|
|
6247
|
+
await collection.updateOne({ id }, { $set: updateDoc });
|
|
6248
|
+
const updatedSkill = await collection.findOne({ id });
|
|
6249
|
+
if (!updatedSkill) {
|
|
6250
|
+
throw new error.MastraError({
|
|
6251
|
+
id: storage.createStorageErrorId("MONGODB", "UPDATE_SKILL", "NOT_FOUND_AFTER_UPDATE"),
|
|
6252
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6253
|
+
category: error.ErrorCategory.SYSTEM,
|
|
6254
|
+
text: `Skill with id ${id} was deleted during update`,
|
|
6255
|
+
details: { id }
|
|
6256
|
+
});
|
|
6257
|
+
}
|
|
6258
|
+
return this.transformSkill(updatedSkill);
|
|
6259
|
+
} catch (error$1) {
|
|
6260
|
+
if (error$1 instanceof error.MastraError) {
|
|
6261
|
+
throw error$1;
|
|
6262
|
+
}
|
|
6263
|
+
throw new error.MastraError(
|
|
6264
|
+
{
|
|
6265
|
+
id: storage.createStorageErrorId("MONGODB", "UPDATE_SKILL", "FAILED"),
|
|
6266
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6267
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
6268
|
+
details: { id }
|
|
6269
|
+
},
|
|
6270
|
+
error$1
|
|
6271
|
+
);
|
|
6272
|
+
}
|
|
6273
|
+
}
|
|
6274
|
+
async delete(id) {
|
|
6275
|
+
try {
|
|
6276
|
+
await this.deleteVersionsByParentId(id);
|
|
6277
|
+
const collection = await this.getCollection(storage.TABLE_SKILLS);
|
|
6278
|
+
await collection.deleteOne({ id });
|
|
6279
|
+
} catch (error$1) {
|
|
6280
|
+
throw new error.MastraError(
|
|
6281
|
+
{
|
|
6282
|
+
id: storage.createStorageErrorId("MONGODB", "DELETE_SKILL", "FAILED"),
|
|
6283
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6284
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
6285
|
+
details: { id }
|
|
6286
|
+
},
|
|
6287
|
+
error$1
|
|
6288
|
+
);
|
|
6289
|
+
}
|
|
6290
|
+
}
|
|
6291
|
+
async list(args) {
|
|
6292
|
+
try {
|
|
6293
|
+
const { page = 0, perPage: perPageInput, orderBy, authorId, metadata } = args || {};
|
|
6294
|
+
const { field, direction } = this.parseOrderBy(orderBy);
|
|
6295
|
+
if (page < 0) {
|
|
6296
|
+
throw new error.MastraError(
|
|
6297
|
+
{
|
|
6298
|
+
id: storage.createStorageErrorId("MONGODB", "LIST_SKILLS", "INVALID_PAGE"),
|
|
6299
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6300
|
+
category: error.ErrorCategory.USER,
|
|
6301
|
+
details: { page }
|
|
6302
|
+
},
|
|
6303
|
+
new Error("page must be >= 0")
|
|
6304
|
+
);
|
|
6305
|
+
}
|
|
6306
|
+
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
6307
|
+
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
6308
|
+
const collection = await this.getCollection(storage.TABLE_SKILLS);
|
|
6309
|
+
const filter = {};
|
|
6310
|
+
if (authorId) {
|
|
6311
|
+
filter.authorId = authorId;
|
|
6312
|
+
}
|
|
6313
|
+
if (metadata) {
|
|
6314
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
6315
|
+
filter[`metadata.${key}`] = value;
|
|
6316
|
+
}
|
|
6317
|
+
}
|
|
6318
|
+
const total = await collection.countDocuments(filter);
|
|
6319
|
+
if (total === 0 || perPage === 0) {
|
|
6320
|
+
return {
|
|
6321
|
+
skills: [],
|
|
6322
|
+
total,
|
|
6323
|
+
page,
|
|
6324
|
+
perPage: perPageForResponse,
|
|
6325
|
+
hasMore: false
|
|
6326
|
+
};
|
|
6327
|
+
}
|
|
6328
|
+
const sortOrder = direction === "ASC" ? 1 : -1;
|
|
6329
|
+
let cursor = collection.find(filter).sort({ [field]: sortOrder }).skip(offset);
|
|
6330
|
+
if (perPageInput !== false) {
|
|
6331
|
+
cursor = cursor.limit(perPage);
|
|
6332
|
+
}
|
|
6333
|
+
const results = await cursor.toArray();
|
|
6334
|
+
const skills = results.map((doc) => this.transformSkill(doc));
|
|
6335
|
+
return {
|
|
6336
|
+
skills,
|
|
6337
|
+
total,
|
|
6338
|
+
page,
|
|
6339
|
+
perPage: perPageForResponse,
|
|
6340
|
+
hasMore: perPageInput !== false && offset + perPage < total
|
|
6341
|
+
};
|
|
6342
|
+
} catch (error$1) {
|
|
6343
|
+
if (error$1 instanceof error.MastraError) {
|
|
6344
|
+
throw error$1;
|
|
6345
|
+
}
|
|
6346
|
+
throw new error.MastraError(
|
|
6347
|
+
{
|
|
6348
|
+
id: storage.createStorageErrorId("MONGODB", "LIST_SKILLS", "FAILED"),
|
|
6349
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6350
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
6351
|
+
},
|
|
6352
|
+
error$1
|
|
6353
|
+
);
|
|
6354
|
+
}
|
|
6355
|
+
}
|
|
6356
|
+
// ==========================================================================
|
|
6357
|
+
// Skill Version Methods
|
|
6358
|
+
// ==========================================================================
|
|
6359
|
+
async createVersion(input) {
|
|
6360
|
+
try {
|
|
6361
|
+
const collection = await this.getCollection(storage.TABLE_SKILL_VERSIONS);
|
|
6362
|
+
const now = /* @__PURE__ */ new Date();
|
|
6363
|
+
const versionDoc = {
|
|
6364
|
+
id: input.id,
|
|
6365
|
+
skillId: input.skillId,
|
|
6366
|
+
versionNumber: input.versionNumber,
|
|
6367
|
+
changedFields: input.changedFields ?? void 0,
|
|
6368
|
+
changeMessage: input.changeMessage ?? void 0,
|
|
6369
|
+
createdAt: now
|
|
6370
|
+
};
|
|
6371
|
+
for (const field of SNAPSHOT_FIELDS5) {
|
|
6372
|
+
if (input[field] !== void 0) {
|
|
6373
|
+
versionDoc[field] = input[field];
|
|
6374
|
+
}
|
|
6375
|
+
}
|
|
6376
|
+
await collection.insertOne(versionDoc);
|
|
6377
|
+
return {
|
|
6378
|
+
...input,
|
|
6379
|
+
createdAt: now
|
|
6380
|
+
};
|
|
6381
|
+
} catch (error$1) {
|
|
6382
|
+
throw new error.MastraError(
|
|
6383
|
+
{
|
|
6384
|
+
id: storage.createStorageErrorId("MONGODB", "CREATE_SKILL_VERSION", "FAILED"),
|
|
6385
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6386
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
6387
|
+
details: { versionId: input.id, skillId: input.skillId }
|
|
6388
|
+
},
|
|
6389
|
+
error$1
|
|
6390
|
+
);
|
|
6391
|
+
}
|
|
6392
|
+
}
|
|
6393
|
+
async getVersion(id) {
|
|
6394
|
+
try {
|
|
6395
|
+
const collection = await this.getCollection(storage.TABLE_SKILL_VERSIONS);
|
|
6396
|
+
const result = await collection.findOne({ id });
|
|
6397
|
+
if (!result) {
|
|
6398
|
+
return null;
|
|
6399
|
+
}
|
|
6400
|
+
return this.transformVersion(result);
|
|
6401
|
+
} catch (error$1) {
|
|
6402
|
+
throw new error.MastraError(
|
|
6403
|
+
{
|
|
6404
|
+
id: storage.createStorageErrorId("MONGODB", "GET_SKILL_VERSION", "FAILED"),
|
|
6405
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6406
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
6407
|
+
details: { versionId: id }
|
|
6408
|
+
},
|
|
6409
|
+
error$1
|
|
6410
|
+
);
|
|
6411
|
+
}
|
|
6412
|
+
}
|
|
6413
|
+
async getVersionByNumber(skillId, versionNumber) {
|
|
6414
|
+
try {
|
|
6415
|
+
const collection = await this.getCollection(storage.TABLE_SKILL_VERSIONS);
|
|
6416
|
+
const result = await collection.findOne({ skillId, versionNumber });
|
|
6417
|
+
if (!result) {
|
|
6418
|
+
return null;
|
|
6419
|
+
}
|
|
6420
|
+
return this.transformVersion(result);
|
|
6421
|
+
} catch (error$1) {
|
|
6422
|
+
throw new error.MastraError(
|
|
6423
|
+
{
|
|
6424
|
+
id: storage.createStorageErrorId("MONGODB", "GET_SKILL_VERSION_BY_NUMBER", "FAILED"),
|
|
6425
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6426
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
6427
|
+
details: { skillId, versionNumber }
|
|
6428
|
+
},
|
|
6429
|
+
error$1
|
|
6430
|
+
);
|
|
6431
|
+
}
|
|
6432
|
+
}
|
|
6433
|
+
async getLatestVersion(skillId) {
|
|
6434
|
+
try {
|
|
6435
|
+
const collection = await this.getCollection(storage.TABLE_SKILL_VERSIONS);
|
|
6436
|
+
const result = await collection.find({ skillId }).sort({ versionNumber: -1 }).limit(1).toArray();
|
|
6437
|
+
if (!result || result.length === 0) {
|
|
6438
|
+
return null;
|
|
6439
|
+
}
|
|
6440
|
+
return this.transformVersion(result[0]);
|
|
6441
|
+
} catch (error$1) {
|
|
6442
|
+
throw new error.MastraError(
|
|
6443
|
+
{
|
|
6444
|
+
id: storage.createStorageErrorId("MONGODB", "GET_LATEST_SKILL_VERSION", "FAILED"),
|
|
6445
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6446
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
6447
|
+
details: { skillId }
|
|
6448
|
+
},
|
|
6449
|
+
error$1
|
|
6450
|
+
);
|
|
6451
|
+
}
|
|
6452
|
+
}
|
|
6453
|
+
async listVersions(input) {
|
|
6454
|
+
const { skillId, page = 0, perPage: perPageInput, orderBy } = input;
|
|
6455
|
+
if (page < 0) {
|
|
6456
|
+
throw new error.MastraError(
|
|
6457
|
+
{
|
|
6458
|
+
id: storage.createStorageErrorId("MONGODB", "LIST_SKILL_VERSIONS", "INVALID_PAGE"),
|
|
6459
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6460
|
+
category: error.ErrorCategory.USER,
|
|
6461
|
+
details: { page }
|
|
6462
|
+
},
|
|
6463
|
+
new Error("page must be >= 0")
|
|
6464
|
+
);
|
|
6465
|
+
}
|
|
6466
|
+
const perPage = storage.normalizePerPage(perPageInput, 20);
|
|
6467
|
+
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
6468
|
+
try {
|
|
6469
|
+
const { field, direction } = this.parseVersionOrderBy(orderBy);
|
|
6470
|
+
const collection = await this.getCollection(storage.TABLE_SKILL_VERSIONS);
|
|
6471
|
+
const total = await collection.countDocuments({ skillId });
|
|
6472
|
+
if (total === 0 || perPage === 0) {
|
|
6473
|
+
return {
|
|
6474
|
+
versions: [],
|
|
6475
|
+
total,
|
|
6476
|
+
page,
|
|
6477
|
+
perPage: perPageForResponse,
|
|
6478
|
+
hasMore: false
|
|
6479
|
+
};
|
|
6480
|
+
}
|
|
6481
|
+
const sortOrder = direction === "ASC" ? 1 : -1;
|
|
6482
|
+
let cursor = collection.find({ skillId }).sort({ [field]: sortOrder }).skip(offset);
|
|
6483
|
+
if (perPageInput !== false) {
|
|
6484
|
+
cursor = cursor.limit(perPage);
|
|
6485
|
+
}
|
|
6486
|
+
const results = await cursor.toArray();
|
|
6487
|
+
const versions = results.map((doc) => this.transformVersion(doc));
|
|
6488
|
+
return {
|
|
6489
|
+
versions,
|
|
6490
|
+
total,
|
|
6491
|
+
page,
|
|
6492
|
+
perPage: perPageForResponse,
|
|
6493
|
+
hasMore: perPageInput !== false && offset + perPage < total
|
|
6494
|
+
};
|
|
6495
|
+
} catch (error$1) {
|
|
6496
|
+
throw new error.MastraError(
|
|
6497
|
+
{
|
|
6498
|
+
id: storage.createStorageErrorId("MONGODB", "LIST_SKILL_VERSIONS", "FAILED"),
|
|
6499
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6500
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
6501
|
+
details: { skillId }
|
|
6502
|
+
},
|
|
6503
|
+
error$1
|
|
6504
|
+
);
|
|
6505
|
+
}
|
|
6506
|
+
}
|
|
6507
|
+
async deleteVersion(id) {
|
|
6508
|
+
try {
|
|
6509
|
+
const collection = await this.getCollection(storage.TABLE_SKILL_VERSIONS);
|
|
6510
|
+
await collection.deleteOne({ id });
|
|
6511
|
+
} catch (error$1) {
|
|
6512
|
+
throw new error.MastraError(
|
|
6513
|
+
{
|
|
6514
|
+
id: storage.createStorageErrorId("MONGODB", "DELETE_SKILL_VERSION", "FAILED"),
|
|
6515
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6516
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
6517
|
+
details: { versionId: id }
|
|
6518
|
+
},
|
|
6519
|
+
error$1
|
|
6520
|
+
);
|
|
6521
|
+
}
|
|
6522
|
+
}
|
|
6523
|
+
async deleteVersionsByParentId(skillId) {
|
|
6524
|
+
try {
|
|
6525
|
+
const collection = await this.getCollection(storage.TABLE_SKILL_VERSIONS);
|
|
6526
|
+
await collection.deleteMany({ skillId });
|
|
6527
|
+
} catch (error$1) {
|
|
6528
|
+
throw new error.MastraError(
|
|
6529
|
+
{
|
|
6530
|
+
id: storage.createStorageErrorId("MONGODB", "DELETE_VERSIONS_BY_SKILL_ID", "FAILED"),
|
|
6531
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6532
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
6533
|
+
details: { skillId }
|
|
6534
|
+
},
|
|
6535
|
+
error$1
|
|
6536
|
+
);
|
|
6537
|
+
}
|
|
6538
|
+
}
|
|
6539
|
+
async countVersions(skillId) {
|
|
6540
|
+
try {
|
|
6541
|
+
const collection = await this.getCollection(storage.TABLE_SKILL_VERSIONS);
|
|
6542
|
+
return await collection.countDocuments({ skillId });
|
|
6543
|
+
} catch (error$1) {
|
|
6544
|
+
throw new error.MastraError(
|
|
6545
|
+
{
|
|
6546
|
+
id: storage.createStorageErrorId("MONGODB", "COUNT_SKILL_VERSIONS", "FAILED"),
|
|
6547
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6548
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
6549
|
+
details: { skillId }
|
|
6550
|
+
},
|
|
6551
|
+
error$1
|
|
6552
|
+
);
|
|
6553
|
+
}
|
|
6554
|
+
}
|
|
6555
|
+
// ==========================================================================
|
|
6556
|
+
// Private Helper Methods
|
|
6557
|
+
// ==========================================================================
|
|
6558
|
+
transformSkill(doc) {
|
|
6559
|
+
const { _id, ...rest } = doc;
|
|
6560
|
+
return {
|
|
6561
|
+
id: rest.id,
|
|
6562
|
+
status: rest.status,
|
|
6563
|
+
activeVersionId: rest.activeVersionId,
|
|
6564
|
+
authorId: rest.authorId,
|
|
6565
|
+
createdAt: rest.createdAt instanceof Date ? rest.createdAt : new Date(rest.createdAt),
|
|
6566
|
+
updatedAt: rest.updatedAt instanceof Date ? rest.updatedAt : new Date(rest.updatedAt)
|
|
6567
|
+
};
|
|
6568
|
+
}
|
|
6569
|
+
serializeSkill(skill) {
|
|
6570
|
+
return {
|
|
6571
|
+
id: skill.id,
|
|
6572
|
+
status: skill.status,
|
|
6573
|
+
activeVersionId: skill.activeVersionId,
|
|
6574
|
+
authorId: skill.authorId,
|
|
6575
|
+
createdAt: skill.createdAt,
|
|
6576
|
+
updatedAt: skill.updatedAt
|
|
6577
|
+
};
|
|
6578
|
+
}
|
|
6579
|
+
transformVersion(doc) {
|
|
6580
|
+
const { _id, ...version } = doc;
|
|
6581
|
+
const result = {
|
|
6582
|
+
id: version.id,
|
|
6583
|
+
skillId: version.skillId,
|
|
6584
|
+
versionNumber: version.versionNumber,
|
|
6585
|
+
changedFields: version.changedFields,
|
|
6586
|
+
changeMessage: version.changeMessage,
|
|
6587
|
+
createdAt: version.createdAt instanceof Date ? version.createdAt : new Date(version.createdAt)
|
|
6588
|
+
};
|
|
6589
|
+
for (const field of SNAPSHOT_FIELDS5) {
|
|
6590
|
+
if (version[field] !== void 0) {
|
|
6591
|
+
result[field] = version[field];
|
|
6592
|
+
}
|
|
6593
|
+
}
|
|
6594
|
+
return result;
|
|
6595
|
+
}
|
|
6596
|
+
extractSnapshotFields(version) {
|
|
6597
|
+
const result = {};
|
|
6598
|
+
for (const field of SNAPSHOT_FIELDS5) {
|
|
6599
|
+
if (version[field] !== void 0) {
|
|
6600
|
+
result[field] = version[field];
|
|
6601
|
+
}
|
|
6602
|
+
}
|
|
6603
|
+
return result;
|
|
6604
|
+
}
|
|
6605
|
+
};
|
|
6606
|
+
var WorkflowsStorageMongoDB = class _WorkflowsStorageMongoDB extends storage.WorkflowsStorage {
|
|
6607
|
+
#connector;
|
|
6608
|
+
#skipDefaultIndexes;
|
|
6609
|
+
#indexes;
|
|
6610
|
+
/** Collections managed by this domain */
|
|
6611
|
+
static MANAGED_COLLECTIONS = [storage.TABLE_WORKFLOW_SNAPSHOT];
|
|
6612
|
+
constructor(config) {
|
|
6613
|
+
super();
|
|
6614
|
+
this.#connector = resolveMongoDBConfig(config);
|
|
6615
|
+
this.#skipDefaultIndexes = config.skipDefaultIndexes;
|
|
6616
|
+
this.#indexes = config.indexes?.filter(
|
|
6617
|
+
(idx) => _WorkflowsStorageMongoDB.MANAGED_COLLECTIONS.includes(idx.collection)
|
|
6618
|
+
);
|
|
6619
|
+
}
|
|
6620
|
+
async getCollection(name) {
|
|
6621
|
+
return this.#connector.getCollection(name);
|
|
6622
|
+
}
|
|
6623
|
+
async init() {
|
|
6624
|
+
await this.createDefaultIndexes();
|
|
6625
|
+
await this.createCustomIndexes();
|
|
6626
|
+
}
|
|
6627
|
+
/**
|
|
6628
|
+
* Returns default index definitions for the workflows domain collections.
|
|
6629
|
+
*/
|
|
6630
|
+
getDefaultIndexDefinitions() {
|
|
6631
|
+
return [
|
|
6632
|
+
{ collection: storage.TABLE_WORKFLOW_SNAPSHOT, keys: { workflow_name: 1, run_id: 1 }, options: { unique: true } },
|
|
6633
|
+
{ collection: storage.TABLE_WORKFLOW_SNAPSHOT, keys: { run_id: 1 } },
|
|
6634
|
+
{ collection: storage.TABLE_WORKFLOW_SNAPSHOT, keys: { workflow_name: 1 } },
|
|
6635
|
+
{ collection: storage.TABLE_WORKFLOW_SNAPSHOT, keys: { resourceId: 1 } },
|
|
6636
|
+
{ collection: storage.TABLE_WORKFLOW_SNAPSHOT, keys: { createdAt: -1 } },
|
|
6637
|
+
{ collection: storage.TABLE_WORKFLOW_SNAPSHOT, keys: { "snapshot.status": 1 } }
|
|
6638
|
+
];
|
|
6639
|
+
}
|
|
6640
|
+
/**
|
|
6641
|
+
* Creates default indexes for optimal query performance.
|
|
6642
|
+
*/
|
|
6643
|
+
async createDefaultIndexes() {
|
|
6644
|
+
if (this.#skipDefaultIndexes) {
|
|
6645
|
+
return;
|
|
6646
|
+
}
|
|
6647
|
+
for (const indexDef of this.getDefaultIndexDefinitions()) {
|
|
6648
|
+
try {
|
|
6649
|
+
const collection = await this.getCollection(indexDef.collection);
|
|
6650
|
+
await collection.createIndex(indexDef.keys, indexDef.options);
|
|
6651
|
+
} catch (error) {
|
|
6652
|
+
this.logger?.warn?.(`Failed to create index on ${indexDef.collection}:`, error);
|
|
6653
|
+
}
|
|
6654
|
+
}
|
|
6655
|
+
}
|
|
6656
|
+
/**
|
|
6657
|
+
* Creates custom user-defined indexes for this domain's collections.
|
|
6658
|
+
*/
|
|
6659
|
+
async createCustomIndexes() {
|
|
6660
|
+
if (!this.#indexes || this.#indexes.length === 0) {
|
|
6661
|
+
return;
|
|
6662
|
+
}
|
|
6663
|
+
for (const indexDef of this.#indexes) {
|
|
6664
|
+
try {
|
|
6665
|
+
const collection = await this.getCollection(indexDef.collection);
|
|
6666
|
+
await collection.createIndex(indexDef.keys, indexDef.options);
|
|
6667
|
+
} catch (error) {
|
|
6668
|
+
this.logger?.warn?.(`Failed to create custom index on ${indexDef.collection}:`, error);
|
|
6669
|
+
}
|
|
6670
|
+
}
|
|
6671
|
+
}
|
|
6672
|
+
async dangerouslyClearAll() {
|
|
6673
|
+
const collection = await this.getCollection(storage.TABLE_WORKFLOW_SNAPSHOT);
|
|
6674
|
+
await collection.deleteMany({});
|
|
6675
|
+
}
|
|
6676
|
+
updateWorkflowResults({
|
|
6677
|
+
// workflowName,
|
|
6678
|
+
// runId,
|
|
6679
|
+
// stepId,
|
|
6680
|
+
// result,
|
|
6681
|
+
// requestContext,
|
|
6682
|
+
}) {
|
|
6683
|
+
throw new Error("Method not implemented.");
|
|
6684
|
+
}
|
|
6685
|
+
updateWorkflowState({
|
|
6686
|
+
// workflowName,
|
|
6687
|
+
// runId,
|
|
6688
|
+
// opts,
|
|
6689
|
+
}) {
|
|
6690
|
+
throw new Error("Method not implemented.");
|
|
6691
|
+
}
|
|
6692
|
+
async persistWorkflowSnapshot({
|
|
6693
|
+
workflowName,
|
|
6694
|
+
runId,
|
|
6695
|
+
resourceId,
|
|
6696
|
+
snapshot,
|
|
6697
|
+
createdAt,
|
|
6698
|
+
updatedAt
|
|
6699
|
+
}) {
|
|
6700
|
+
try {
|
|
6701
|
+
const now = /* @__PURE__ */ new Date();
|
|
6702
|
+
const collection = await this.getCollection(storage.TABLE_WORKFLOW_SNAPSHOT);
|
|
6703
|
+
await collection.updateOne(
|
|
6704
|
+
{ workflow_name: workflowName, run_id: runId },
|
|
6705
|
+
{
|
|
6706
|
+
$set: {
|
|
6707
|
+
workflow_name: workflowName,
|
|
6708
|
+
run_id: runId,
|
|
6709
|
+
resourceId,
|
|
6710
|
+
snapshot,
|
|
6711
|
+
updatedAt: updatedAt ?? now
|
|
6712
|
+
},
|
|
6713
|
+
$setOnInsert: {
|
|
6714
|
+
createdAt: createdAt ?? now
|
|
6715
|
+
}
|
|
6716
|
+
},
|
|
6717
|
+
{ upsert: true }
|
|
6718
|
+
);
|
|
6719
|
+
} catch (error$1) {
|
|
6720
|
+
throw new error.MastraError(
|
|
6721
|
+
{
|
|
6722
|
+
id: storage.createStorageErrorId("MONGODB", "PERSIST_WORKFLOW_SNAPSHOT", "FAILED"),
|
|
6723
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6724
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
6725
|
+
details: { workflowName, runId }
|
|
6726
|
+
},
|
|
6727
|
+
error$1
|
|
6728
|
+
);
|
|
6729
|
+
}
|
|
6730
|
+
}
|
|
6731
|
+
async loadWorkflowSnapshot({
|
|
6732
|
+
workflowName,
|
|
6733
|
+
runId
|
|
6734
|
+
}) {
|
|
6735
|
+
try {
|
|
6736
|
+
const collection = await this.getCollection(storage.TABLE_WORKFLOW_SNAPSHOT);
|
|
6737
|
+
const result = await collection.findOne({
|
|
6738
|
+
workflow_name: workflowName,
|
|
6739
|
+
run_id: runId
|
|
6740
|
+
});
|
|
6741
|
+
if (!result) {
|
|
6742
|
+
return null;
|
|
6743
|
+
}
|
|
6744
|
+
return typeof result.snapshot === "string" ? storage.safelyParseJSON(result.snapshot) : result.snapshot;
|
|
6745
|
+
} catch (error$1) {
|
|
6746
|
+
throw new error.MastraError(
|
|
6747
|
+
{
|
|
6748
|
+
id: storage.createStorageErrorId("MONGODB", "LOAD_WORKFLOW_SNAPSHOT", "FAILED"),
|
|
6749
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6750
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
6751
|
+
details: { workflowName, runId }
|
|
6752
|
+
},
|
|
6753
|
+
error$1
|
|
6754
|
+
);
|
|
6755
|
+
}
|
|
6756
|
+
}
|
|
6757
|
+
async listWorkflowRuns(args) {
|
|
6758
|
+
const options = args || {};
|
|
6759
|
+
try {
|
|
6760
|
+
const query = {};
|
|
6761
|
+
if (options.workflowName) {
|
|
6762
|
+
query["workflow_name"] = options.workflowName;
|
|
6763
|
+
}
|
|
6764
|
+
if (options.status) {
|
|
6765
|
+
query["snapshot.status"] = options.status;
|
|
6766
|
+
}
|
|
6767
|
+
if (options.fromDate) {
|
|
6768
|
+
query["createdAt"] = { $gte: options.fromDate };
|
|
6769
|
+
}
|
|
6770
|
+
if (options.toDate) {
|
|
6771
|
+
if (query["createdAt"]) {
|
|
6772
|
+
query["createdAt"].$lte = options.toDate;
|
|
6773
|
+
} else {
|
|
6774
|
+
query["createdAt"] = { $lte: options.toDate };
|
|
6775
|
+
}
|
|
6776
|
+
}
|
|
6777
|
+
if (options.resourceId) {
|
|
6778
|
+
query["resourceId"] = options.resourceId;
|
|
6779
|
+
}
|
|
6780
|
+
const collection = await this.getCollection(storage.TABLE_WORKFLOW_SNAPSHOT);
|
|
6781
|
+
let total = 0;
|
|
6782
|
+
let cursor = collection.find(query).sort({ createdAt: -1 });
|
|
6783
|
+
if (options.page !== void 0 && typeof options.perPage === "number") {
|
|
6784
|
+
if (options.page < 0) {
|
|
6785
|
+
throw new error.MastraError(
|
|
6786
|
+
{
|
|
6787
|
+
id: storage.createStorageErrorId("MONGODB", "LIST_WORKFLOW_RUNS", "INVALID_PAGE"),
|
|
6788
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6789
|
+
category: error.ErrorCategory.USER,
|
|
6790
|
+
details: { page: options.page }
|
|
6791
|
+
},
|
|
6792
|
+
new Error("page must be >= 0")
|
|
6793
|
+
);
|
|
6794
|
+
}
|
|
6795
|
+
total = await collection.countDocuments(query);
|
|
6796
|
+
const normalizedPerPage = storage.normalizePerPage(options.perPage, Number.MAX_SAFE_INTEGER);
|
|
6797
|
+
if (normalizedPerPage === 0) {
|
|
6798
|
+
return { runs: [], total };
|
|
6799
|
+
}
|
|
6800
|
+
const offset = options.page * normalizedPerPage;
|
|
6801
|
+
cursor = cursor.skip(offset);
|
|
6802
|
+
cursor = cursor.limit(Math.min(normalizedPerPage, 2147483647));
|
|
6803
|
+
}
|
|
6804
|
+
const results = await cursor.toArray();
|
|
6805
|
+
const runs = results.map((row) => this.parseWorkflowRun(row));
|
|
6806
|
+
return {
|
|
6807
|
+
runs,
|
|
6808
|
+
total: total || runs.length
|
|
6809
|
+
};
|
|
6810
|
+
} catch (error$1) {
|
|
6811
|
+
throw new error.MastraError(
|
|
6812
|
+
{
|
|
6813
|
+
id: storage.createStorageErrorId("MONGODB", "LIST_WORKFLOW_RUNS", "FAILED"),
|
|
6814
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6815
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
6816
|
+
details: { workflowName: options.workflowName || "unknown" }
|
|
6817
|
+
},
|
|
6818
|
+
error$1
|
|
6819
|
+
);
|
|
6820
|
+
}
|
|
6821
|
+
}
|
|
6822
|
+
async getWorkflowRunById(args) {
|
|
6823
|
+
try {
|
|
6824
|
+
const query = {};
|
|
6825
|
+
if (args.runId) {
|
|
6826
|
+
query["run_id"] = args.runId;
|
|
6827
|
+
}
|
|
6828
|
+
if (args.workflowName) {
|
|
6829
|
+
query["workflow_name"] = args.workflowName;
|
|
6830
|
+
}
|
|
6831
|
+
const collection = await this.getCollection(storage.TABLE_WORKFLOW_SNAPSHOT);
|
|
6832
|
+
const result = await collection.findOne(query);
|
|
6833
|
+
if (!result) {
|
|
6834
|
+
return null;
|
|
6835
|
+
}
|
|
6836
|
+
return this.parseWorkflowRun(result);
|
|
6837
|
+
} catch (error$1) {
|
|
6838
|
+
throw new error.MastraError(
|
|
6839
|
+
{
|
|
6199
6840
|
id: storage.createStorageErrorId("MONGODB", "GET_WORKFLOW_RUN_BY_ID", "FAILED"),
|
|
6200
6841
|
domain: error.ErrorDomain.STORAGE,
|
|
6201
6842
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
6202
|
-
details: { runId: args.runId }
|
|
6843
|
+
details: { runId: args.runId }
|
|
6844
|
+
},
|
|
6845
|
+
error$1
|
|
6846
|
+
);
|
|
6847
|
+
}
|
|
6848
|
+
}
|
|
6849
|
+
async deleteWorkflowRunById({ runId, workflowName }) {
|
|
6850
|
+
try {
|
|
6851
|
+
const collection = await this.getCollection(storage.TABLE_WORKFLOW_SNAPSHOT);
|
|
6852
|
+
await collection.deleteOne({ workflow_name: workflowName, run_id: runId });
|
|
6853
|
+
} catch (error$1) {
|
|
6854
|
+
throw new error.MastraError(
|
|
6855
|
+
{
|
|
6856
|
+
id: storage.createStorageErrorId("MONGODB", "DELETE_WORKFLOW_RUN_BY_ID", "FAILED"),
|
|
6857
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6858
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
6859
|
+
details: { runId, workflowName }
|
|
6860
|
+
},
|
|
6861
|
+
error$1
|
|
6862
|
+
);
|
|
6863
|
+
}
|
|
6864
|
+
}
|
|
6865
|
+
parseWorkflowRun(row) {
|
|
6866
|
+
let parsedSnapshot = row.snapshot;
|
|
6867
|
+
if (typeof parsedSnapshot === "string") {
|
|
6868
|
+
try {
|
|
6869
|
+
parsedSnapshot = typeof row.snapshot === "string" ? storage.safelyParseJSON(row.snapshot) : row.snapshot;
|
|
6870
|
+
} catch (e) {
|
|
6871
|
+
this.logger.warn(`Failed to parse snapshot for workflow ${row.workflow_name}: ${e}`);
|
|
6872
|
+
}
|
|
6873
|
+
}
|
|
6874
|
+
return {
|
|
6875
|
+
workflowName: row.workflow_name,
|
|
6876
|
+
runId: row.run_id,
|
|
6877
|
+
snapshot: parsedSnapshot,
|
|
6878
|
+
createdAt: row.createdAt ? new Date(row.createdAt) : /* @__PURE__ */ new Date(),
|
|
6879
|
+
updatedAt: row.updatedAt ? new Date(row.updatedAt) : /* @__PURE__ */ new Date(),
|
|
6880
|
+
resourceId: row.resourceId
|
|
6881
|
+
};
|
|
6882
|
+
}
|
|
6883
|
+
};
|
|
6884
|
+
var SNAPSHOT_FIELDS6 = [
|
|
6885
|
+
"name",
|
|
6886
|
+
"description",
|
|
6887
|
+
"filesystem",
|
|
6888
|
+
"sandbox",
|
|
6889
|
+
"mounts",
|
|
6890
|
+
"search",
|
|
6891
|
+
"skills",
|
|
6892
|
+
"tools",
|
|
6893
|
+
"autoSync",
|
|
6894
|
+
"operationTimeout"
|
|
6895
|
+
];
|
|
6896
|
+
var MongoDBWorkspacesStorage = class _MongoDBWorkspacesStorage extends storage.WorkspacesStorage {
|
|
6897
|
+
#connector;
|
|
6898
|
+
#skipDefaultIndexes;
|
|
6899
|
+
#indexes;
|
|
6900
|
+
static MANAGED_COLLECTIONS = [storage.TABLE_WORKSPACES, storage.TABLE_WORKSPACE_VERSIONS];
|
|
6901
|
+
constructor(config) {
|
|
6902
|
+
super();
|
|
6903
|
+
this.#connector = resolveMongoDBConfig(config);
|
|
6904
|
+
this.#skipDefaultIndexes = config.skipDefaultIndexes;
|
|
6905
|
+
this.#indexes = config.indexes?.filter(
|
|
6906
|
+
(idx) => _MongoDBWorkspacesStorage.MANAGED_COLLECTIONS.includes(idx.collection)
|
|
6907
|
+
);
|
|
6908
|
+
}
|
|
6909
|
+
async getCollection(name) {
|
|
6910
|
+
return this.#connector.getCollection(name);
|
|
6911
|
+
}
|
|
6912
|
+
getDefaultIndexDefinitions() {
|
|
6913
|
+
return [
|
|
6914
|
+
{ collection: storage.TABLE_WORKSPACES, keys: { id: 1 }, options: { unique: true } },
|
|
6915
|
+
{ collection: storage.TABLE_WORKSPACES, keys: { status: 1 } },
|
|
6916
|
+
{ collection: storage.TABLE_WORKSPACES, keys: { createdAt: -1 } },
|
|
6917
|
+
{ collection: storage.TABLE_WORKSPACES, keys: { authorId: 1 } },
|
|
6918
|
+
{ collection: storage.TABLE_WORKSPACE_VERSIONS, keys: { id: 1 }, options: { unique: true } },
|
|
6919
|
+
{
|
|
6920
|
+
collection: storage.TABLE_WORKSPACE_VERSIONS,
|
|
6921
|
+
keys: { workspaceId: 1, versionNumber: -1 },
|
|
6922
|
+
options: { unique: true }
|
|
6923
|
+
},
|
|
6924
|
+
{ collection: storage.TABLE_WORKSPACE_VERSIONS, keys: { workspaceId: 1 } }
|
|
6925
|
+
];
|
|
6926
|
+
}
|
|
6927
|
+
async createDefaultIndexes() {
|
|
6928
|
+
if (this.#skipDefaultIndexes) {
|
|
6929
|
+
return;
|
|
6930
|
+
}
|
|
6931
|
+
for (const indexDef of this.getDefaultIndexDefinitions()) {
|
|
6932
|
+
try {
|
|
6933
|
+
const collection = await this.getCollection(indexDef.collection);
|
|
6934
|
+
await collection.createIndex(indexDef.keys, indexDef.options);
|
|
6935
|
+
} catch (error) {
|
|
6936
|
+
this.logger?.warn?.(`Failed to create index on ${indexDef.collection}:`, error);
|
|
6937
|
+
}
|
|
6938
|
+
}
|
|
6939
|
+
}
|
|
6940
|
+
async createCustomIndexes() {
|
|
6941
|
+
if (!this.#indexes || this.#indexes.length === 0) {
|
|
6942
|
+
return;
|
|
6943
|
+
}
|
|
6944
|
+
for (const indexDef of this.#indexes) {
|
|
6945
|
+
try {
|
|
6946
|
+
const collection = await this.getCollection(indexDef.collection);
|
|
6947
|
+
await collection.createIndex(indexDef.keys, indexDef.options);
|
|
6948
|
+
} catch (error) {
|
|
6949
|
+
this.logger?.warn?.(`Failed to create custom index on ${indexDef.collection}:`, error);
|
|
6950
|
+
}
|
|
6951
|
+
}
|
|
6952
|
+
}
|
|
6953
|
+
async init() {
|
|
6954
|
+
await this.createDefaultIndexes();
|
|
6955
|
+
await this.createCustomIndexes();
|
|
6956
|
+
}
|
|
6957
|
+
async dangerouslyClearAll() {
|
|
6958
|
+
const versionsCollection = await this.getCollection(storage.TABLE_WORKSPACE_VERSIONS);
|
|
6959
|
+
await versionsCollection.deleteMany({});
|
|
6960
|
+
const workspacesCollection = await this.getCollection(storage.TABLE_WORKSPACES);
|
|
6961
|
+
await workspacesCollection.deleteMany({});
|
|
6962
|
+
}
|
|
6963
|
+
// ==========================================================================
|
|
6964
|
+
// Workspace CRUD
|
|
6965
|
+
// ==========================================================================
|
|
6966
|
+
async getById(id) {
|
|
6967
|
+
try {
|
|
6968
|
+
const collection = await this.getCollection(storage.TABLE_WORKSPACES);
|
|
6969
|
+
const result = await collection.findOne({ id });
|
|
6970
|
+
if (!result) {
|
|
6971
|
+
return null;
|
|
6972
|
+
}
|
|
6973
|
+
return this.transformWorkspace(result);
|
|
6974
|
+
} catch (error$1) {
|
|
6975
|
+
throw new error.MastraError(
|
|
6976
|
+
{
|
|
6977
|
+
id: storage.createStorageErrorId("MONGODB", "GET_WORKSPACE_BY_ID", "FAILED"),
|
|
6978
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6979
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
6980
|
+
details: { id }
|
|
6981
|
+
},
|
|
6982
|
+
error$1
|
|
6983
|
+
);
|
|
6984
|
+
}
|
|
6985
|
+
}
|
|
6986
|
+
async create(input) {
|
|
6987
|
+
const { workspace } = input;
|
|
6988
|
+
try {
|
|
6989
|
+
const collection = await this.getCollection(storage.TABLE_WORKSPACES);
|
|
6990
|
+
const slug = workspace.name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "");
|
|
6991
|
+
const id = slug || workspace.id;
|
|
6992
|
+
if (!id) {
|
|
6993
|
+
throw new error.MastraError({
|
|
6994
|
+
id: storage.createStorageErrorId("MONGODB", "CREATE_WORKSPACE", "INVALID_NAME"),
|
|
6995
|
+
domain: error.ErrorDomain.STORAGE,
|
|
6996
|
+
category: error.ErrorCategory.USER,
|
|
6997
|
+
text: `Cannot derive a valid ID from workspace name "${workspace.name}"`,
|
|
6998
|
+
details: { name: workspace.name }
|
|
6999
|
+
});
|
|
7000
|
+
}
|
|
7001
|
+
const existing = await collection.findOne({ id });
|
|
7002
|
+
if (existing) {
|
|
7003
|
+
throw new error.MastraError({
|
|
7004
|
+
id: storage.createStorageErrorId("MONGODB", "CREATE_WORKSPACE", "ALREADY_EXISTS"),
|
|
7005
|
+
domain: error.ErrorDomain.STORAGE,
|
|
7006
|
+
category: error.ErrorCategory.USER,
|
|
7007
|
+
details: { id },
|
|
7008
|
+
text: `Workspace with id ${id} already exists`
|
|
7009
|
+
});
|
|
7010
|
+
}
|
|
7011
|
+
const now = /* @__PURE__ */ new Date();
|
|
7012
|
+
const newWorkspace = {
|
|
7013
|
+
id,
|
|
7014
|
+
status: "draft",
|
|
7015
|
+
activeVersionId: void 0,
|
|
7016
|
+
authorId: workspace.authorId,
|
|
7017
|
+
metadata: workspace.metadata,
|
|
7018
|
+
createdAt: now,
|
|
7019
|
+
updatedAt: now
|
|
7020
|
+
};
|
|
7021
|
+
await collection.insertOne(this.serializeWorkspace(newWorkspace));
|
|
7022
|
+
const snapshotConfig = {};
|
|
7023
|
+
for (const field of SNAPSHOT_FIELDS6) {
|
|
7024
|
+
if (workspace[field] !== void 0) {
|
|
7025
|
+
snapshotConfig[field] = workspace[field];
|
|
7026
|
+
}
|
|
7027
|
+
}
|
|
7028
|
+
const versionId = crypto.randomUUID();
|
|
7029
|
+
try {
|
|
7030
|
+
await this.createVersion({
|
|
7031
|
+
id: versionId,
|
|
7032
|
+
workspaceId: id,
|
|
7033
|
+
versionNumber: 1,
|
|
7034
|
+
...snapshotConfig,
|
|
7035
|
+
changedFields: Object.keys(snapshotConfig),
|
|
7036
|
+
changeMessage: "Initial version"
|
|
7037
|
+
});
|
|
7038
|
+
} catch (versionError) {
|
|
7039
|
+
await collection.deleteOne({ id });
|
|
7040
|
+
throw versionError;
|
|
7041
|
+
}
|
|
7042
|
+
return newWorkspace;
|
|
7043
|
+
} catch (error$1) {
|
|
7044
|
+
if (error$1 instanceof error.MastraError) {
|
|
7045
|
+
throw error$1;
|
|
7046
|
+
}
|
|
7047
|
+
throw new error.MastraError(
|
|
7048
|
+
{
|
|
7049
|
+
id: storage.createStorageErrorId("MONGODB", "CREATE_WORKSPACE", "FAILED"),
|
|
7050
|
+
domain: error.ErrorDomain.STORAGE,
|
|
7051
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
7052
|
+
details: { name: workspace.name }
|
|
7053
|
+
},
|
|
7054
|
+
error$1
|
|
7055
|
+
);
|
|
7056
|
+
}
|
|
7057
|
+
}
|
|
7058
|
+
async update(input) {
|
|
7059
|
+
const { id, ...updates } = input;
|
|
7060
|
+
try {
|
|
7061
|
+
const collection = await this.getCollection(storage.TABLE_WORKSPACES);
|
|
7062
|
+
const existingWorkspace = await collection.findOne({ id });
|
|
7063
|
+
if (!existingWorkspace) {
|
|
7064
|
+
throw new error.MastraError({
|
|
7065
|
+
id: storage.createStorageErrorId("MONGODB", "UPDATE_WORKSPACE", "NOT_FOUND"),
|
|
7066
|
+
domain: error.ErrorDomain.STORAGE,
|
|
7067
|
+
category: error.ErrorCategory.USER,
|
|
7068
|
+
details: { id },
|
|
7069
|
+
text: `Workspace with id ${id} not found`
|
|
7070
|
+
});
|
|
7071
|
+
}
|
|
7072
|
+
const updateDoc = {
|
|
7073
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
7074
|
+
};
|
|
7075
|
+
const metadataFields = {
|
|
7076
|
+
authorId: updates.authorId,
|
|
7077
|
+
activeVersionId: updates.activeVersionId,
|
|
7078
|
+
metadata: updates.metadata,
|
|
7079
|
+
status: updates.status
|
|
7080
|
+
};
|
|
7081
|
+
const configFields = {};
|
|
7082
|
+
for (const field of SNAPSHOT_FIELDS6) {
|
|
7083
|
+
if (updates[field] !== void 0) {
|
|
7084
|
+
configFields[field] = updates[field];
|
|
7085
|
+
}
|
|
7086
|
+
}
|
|
7087
|
+
if (Object.keys(configFields).length > 0) {
|
|
7088
|
+
const latestVersion = await this.getLatestVersion(id);
|
|
7089
|
+
if (!latestVersion) {
|
|
7090
|
+
throw new error.MastraError({
|
|
7091
|
+
id: storage.createStorageErrorId("MONGODB", "UPDATE_WORKSPACE", "NO_VERSION"),
|
|
7092
|
+
domain: error.ErrorDomain.STORAGE,
|
|
7093
|
+
category: error.ErrorCategory.USER,
|
|
7094
|
+
text: `Cannot update config fields for workspace ${id} - no versions exist`,
|
|
7095
|
+
details: { id }
|
|
7096
|
+
});
|
|
7097
|
+
}
|
|
7098
|
+
const existingSnapshot = this.extractSnapshotFields(latestVersion);
|
|
7099
|
+
await this.createVersion({
|
|
7100
|
+
id: crypto.randomUUID(),
|
|
7101
|
+
workspaceId: id,
|
|
7102
|
+
versionNumber: latestVersion.versionNumber + 1,
|
|
7103
|
+
...existingSnapshot,
|
|
7104
|
+
...configFields,
|
|
7105
|
+
changedFields: Object.keys(configFields),
|
|
7106
|
+
changeMessage: `Updated: ${Object.keys(configFields).join(", ")}`
|
|
7107
|
+
});
|
|
7108
|
+
}
|
|
7109
|
+
if (metadataFields.authorId !== void 0) updateDoc.authorId = metadataFields.authorId;
|
|
7110
|
+
if (metadataFields.activeVersionId !== void 0) {
|
|
7111
|
+
updateDoc.activeVersionId = metadataFields.activeVersionId;
|
|
7112
|
+
if (metadataFields.status === void 0) {
|
|
7113
|
+
updateDoc.status = "published";
|
|
7114
|
+
}
|
|
7115
|
+
}
|
|
7116
|
+
if (metadataFields.status !== void 0) {
|
|
7117
|
+
updateDoc.status = metadataFields.status;
|
|
7118
|
+
}
|
|
7119
|
+
if (metadataFields.metadata !== void 0) {
|
|
7120
|
+
const existingMetadata = existingWorkspace.metadata || {};
|
|
7121
|
+
updateDoc.metadata = { ...existingMetadata, ...metadataFields.metadata };
|
|
7122
|
+
}
|
|
7123
|
+
await collection.updateOne({ id }, { $set: updateDoc });
|
|
7124
|
+
const updatedWorkspace = await collection.findOne({ id });
|
|
7125
|
+
if (!updatedWorkspace) {
|
|
7126
|
+
throw new error.MastraError({
|
|
7127
|
+
id: storage.createStorageErrorId("MONGODB", "UPDATE_WORKSPACE", "NOT_FOUND_AFTER_UPDATE"),
|
|
7128
|
+
domain: error.ErrorDomain.STORAGE,
|
|
7129
|
+
category: error.ErrorCategory.SYSTEM,
|
|
7130
|
+
text: `Workspace with id ${id} was deleted during update`,
|
|
7131
|
+
details: { id }
|
|
7132
|
+
});
|
|
7133
|
+
}
|
|
7134
|
+
return this.transformWorkspace(updatedWorkspace);
|
|
7135
|
+
} catch (error$1) {
|
|
7136
|
+
if (error$1 instanceof error.MastraError) {
|
|
7137
|
+
throw error$1;
|
|
7138
|
+
}
|
|
7139
|
+
throw new error.MastraError(
|
|
7140
|
+
{
|
|
7141
|
+
id: storage.createStorageErrorId("MONGODB", "UPDATE_WORKSPACE", "FAILED"),
|
|
7142
|
+
domain: error.ErrorDomain.STORAGE,
|
|
7143
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
7144
|
+
details: { id }
|
|
7145
|
+
},
|
|
7146
|
+
error$1
|
|
7147
|
+
);
|
|
7148
|
+
}
|
|
7149
|
+
}
|
|
7150
|
+
async delete(id) {
|
|
7151
|
+
try {
|
|
7152
|
+
await this.deleteVersionsByParentId(id);
|
|
7153
|
+
const collection = await this.getCollection(storage.TABLE_WORKSPACES);
|
|
7154
|
+
await collection.deleteOne({ id });
|
|
7155
|
+
} catch (error$1) {
|
|
7156
|
+
throw new error.MastraError(
|
|
7157
|
+
{
|
|
7158
|
+
id: storage.createStorageErrorId("MONGODB", "DELETE_WORKSPACE", "FAILED"),
|
|
7159
|
+
domain: error.ErrorDomain.STORAGE,
|
|
7160
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
7161
|
+
details: { id }
|
|
7162
|
+
},
|
|
7163
|
+
error$1
|
|
7164
|
+
);
|
|
7165
|
+
}
|
|
7166
|
+
}
|
|
7167
|
+
async list(args) {
|
|
7168
|
+
try {
|
|
7169
|
+
const { page = 0, perPage: perPageInput, orderBy, authorId, metadata } = args || {};
|
|
7170
|
+
const { field, direction } = this.parseOrderBy(orderBy);
|
|
7171
|
+
if (page < 0) {
|
|
7172
|
+
throw new error.MastraError(
|
|
7173
|
+
{
|
|
7174
|
+
id: storage.createStorageErrorId("MONGODB", "LIST_WORKSPACES", "INVALID_PAGE"),
|
|
7175
|
+
domain: error.ErrorDomain.STORAGE,
|
|
7176
|
+
category: error.ErrorCategory.USER,
|
|
7177
|
+
details: { page }
|
|
7178
|
+
},
|
|
7179
|
+
new Error("page must be >= 0")
|
|
7180
|
+
);
|
|
7181
|
+
}
|
|
7182
|
+
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
7183
|
+
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
7184
|
+
const collection = await this.getCollection(storage.TABLE_WORKSPACES);
|
|
7185
|
+
const filter = {};
|
|
7186
|
+
if (authorId) {
|
|
7187
|
+
filter.authorId = authorId;
|
|
7188
|
+
}
|
|
7189
|
+
if (metadata) {
|
|
7190
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
7191
|
+
filter[`metadata.${key}`] = value;
|
|
7192
|
+
}
|
|
7193
|
+
}
|
|
7194
|
+
const total = await collection.countDocuments(filter);
|
|
7195
|
+
if (total === 0 || perPage === 0) {
|
|
7196
|
+
return {
|
|
7197
|
+
workspaces: [],
|
|
7198
|
+
total,
|
|
7199
|
+
page,
|
|
7200
|
+
perPage: perPageForResponse,
|
|
7201
|
+
hasMore: false
|
|
7202
|
+
};
|
|
7203
|
+
}
|
|
7204
|
+
const sortOrder = direction === "ASC" ? 1 : -1;
|
|
7205
|
+
let cursor = collection.find(filter).sort({ [field]: sortOrder }).skip(offset);
|
|
7206
|
+
if (perPageInput !== false) {
|
|
7207
|
+
cursor = cursor.limit(perPage);
|
|
7208
|
+
}
|
|
7209
|
+
const results = await cursor.toArray();
|
|
7210
|
+
const workspaces = results.map((doc) => this.transformWorkspace(doc));
|
|
7211
|
+
return {
|
|
7212
|
+
workspaces,
|
|
7213
|
+
total,
|
|
7214
|
+
page,
|
|
7215
|
+
perPage: perPageForResponse,
|
|
7216
|
+
hasMore: perPageInput !== false && offset + perPage < total
|
|
7217
|
+
};
|
|
7218
|
+
} catch (error$1) {
|
|
7219
|
+
if (error$1 instanceof error.MastraError) {
|
|
7220
|
+
throw error$1;
|
|
7221
|
+
}
|
|
7222
|
+
throw new error.MastraError(
|
|
7223
|
+
{
|
|
7224
|
+
id: storage.createStorageErrorId("MONGODB", "LIST_WORKSPACES", "FAILED"),
|
|
7225
|
+
domain: error.ErrorDomain.STORAGE,
|
|
7226
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
7227
|
+
},
|
|
7228
|
+
error$1
|
|
7229
|
+
);
|
|
7230
|
+
}
|
|
7231
|
+
}
|
|
7232
|
+
// ==========================================================================
|
|
7233
|
+
// Workspace Version Methods
|
|
7234
|
+
// ==========================================================================
|
|
7235
|
+
async createVersion(input) {
|
|
7236
|
+
try {
|
|
7237
|
+
const collection = await this.getCollection(storage.TABLE_WORKSPACE_VERSIONS);
|
|
7238
|
+
const now = /* @__PURE__ */ new Date();
|
|
7239
|
+
const versionDoc = {
|
|
7240
|
+
id: input.id,
|
|
7241
|
+
workspaceId: input.workspaceId,
|
|
7242
|
+
versionNumber: input.versionNumber,
|
|
7243
|
+
changedFields: input.changedFields ?? void 0,
|
|
7244
|
+
changeMessage: input.changeMessage ?? void 0,
|
|
7245
|
+
createdAt: now
|
|
7246
|
+
};
|
|
7247
|
+
for (const field of SNAPSHOT_FIELDS6) {
|
|
7248
|
+
if (input[field] !== void 0) {
|
|
7249
|
+
versionDoc[field] = input[field];
|
|
7250
|
+
}
|
|
7251
|
+
}
|
|
7252
|
+
await collection.insertOne(versionDoc);
|
|
7253
|
+
return {
|
|
7254
|
+
...input,
|
|
7255
|
+
createdAt: now
|
|
7256
|
+
};
|
|
7257
|
+
} catch (error$1) {
|
|
7258
|
+
throw new error.MastraError(
|
|
7259
|
+
{
|
|
7260
|
+
id: storage.createStorageErrorId("MONGODB", "CREATE_WORKSPACE_VERSION", "FAILED"),
|
|
7261
|
+
domain: error.ErrorDomain.STORAGE,
|
|
7262
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
7263
|
+
details: { versionId: input.id, workspaceId: input.workspaceId }
|
|
6203
7264
|
},
|
|
6204
7265
|
error$1
|
|
6205
7266
|
);
|
|
6206
7267
|
}
|
|
6207
7268
|
}
|
|
6208
|
-
async
|
|
7269
|
+
async getVersion(id) {
|
|
6209
7270
|
try {
|
|
6210
|
-
const collection = await this.getCollection(storage.
|
|
6211
|
-
await collection.
|
|
7271
|
+
const collection = await this.getCollection(storage.TABLE_WORKSPACE_VERSIONS);
|
|
7272
|
+
const result = await collection.findOne({ id });
|
|
7273
|
+
if (!result) {
|
|
7274
|
+
return null;
|
|
7275
|
+
}
|
|
7276
|
+
return this.transformVersion(result);
|
|
6212
7277
|
} catch (error$1) {
|
|
6213
7278
|
throw new error.MastraError(
|
|
6214
7279
|
{
|
|
6215
|
-
id: storage.createStorageErrorId("MONGODB", "
|
|
7280
|
+
id: storage.createStorageErrorId("MONGODB", "GET_WORKSPACE_VERSION", "FAILED"),
|
|
6216
7281
|
domain: error.ErrorDomain.STORAGE,
|
|
6217
7282
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
6218
|
-
details: {
|
|
7283
|
+
details: { versionId: id }
|
|
6219
7284
|
},
|
|
6220
7285
|
error$1
|
|
6221
7286
|
);
|
|
6222
7287
|
}
|
|
6223
7288
|
}
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6230
|
-
|
|
7289
|
+
async getVersionByNumber(workspaceId, versionNumber) {
|
|
7290
|
+
try {
|
|
7291
|
+
const collection = await this.getCollection(storage.TABLE_WORKSPACE_VERSIONS);
|
|
7292
|
+
const result = await collection.findOne({ workspaceId, versionNumber });
|
|
7293
|
+
if (!result) {
|
|
7294
|
+
return null;
|
|
7295
|
+
}
|
|
7296
|
+
return this.transformVersion(result);
|
|
7297
|
+
} catch (error$1) {
|
|
7298
|
+
throw new error.MastraError(
|
|
7299
|
+
{
|
|
7300
|
+
id: storage.createStorageErrorId("MONGODB", "GET_WORKSPACE_VERSION_BY_NUMBER", "FAILED"),
|
|
7301
|
+
domain: error.ErrorDomain.STORAGE,
|
|
7302
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
7303
|
+
details: { workspaceId, versionNumber }
|
|
7304
|
+
},
|
|
7305
|
+
error$1
|
|
7306
|
+
);
|
|
7307
|
+
}
|
|
7308
|
+
}
|
|
7309
|
+
async getLatestVersion(workspaceId) {
|
|
7310
|
+
try {
|
|
7311
|
+
const collection = await this.getCollection(storage.TABLE_WORKSPACE_VERSIONS);
|
|
7312
|
+
const result = await collection.find({ workspaceId }).sort({ versionNumber: -1 }).limit(1).toArray();
|
|
7313
|
+
if (!result || result.length === 0) {
|
|
7314
|
+
return null;
|
|
7315
|
+
}
|
|
7316
|
+
return this.transformVersion(result[0]);
|
|
7317
|
+
} catch (error$1) {
|
|
7318
|
+
throw new error.MastraError(
|
|
7319
|
+
{
|
|
7320
|
+
id: storage.createStorageErrorId("MONGODB", "GET_LATEST_WORKSPACE_VERSION", "FAILED"),
|
|
7321
|
+
domain: error.ErrorDomain.STORAGE,
|
|
7322
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
7323
|
+
details: { workspaceId }
|
|
7324
|
+
},
|
|
7325
|
+
error$1
|
|
7326
|
+
);
|
|
7327
|
+
}
|
|
7328
|
+
}
|
|
7329
|
+
async listVersions(input) {
|
|
7330
|
+
const { workspaceId, page = 0, perPage: perPageInput, orderBy } = input;
|
|
7331
|
+
if (page < 0) {
|
|
7332
|
+
throw new error.MastraError(
|
|
7333
|
+
{
|
|
7334
|
+
id: storage.createStorageErrorId("MONGODB", "LIST_WORKSPACE_VERSIONS", "INVALID_PAGE"),
|
|
7335
|
+
domain: error.ErrorDomain.STORAGE,
|
|
7336
|
+
category: error.ErrorCategory.USER,
|
|
7337
|
+
details: { page }
|
|
7338
|
+
},
|
|
7339
|
+
new Error("page must be >= 0")
|
|
7340
|
+
);
|
|
7341
|
+
}
|
|
7342
|
+
const perPage = storage.normalizePerPage(perPageInput, 20);
|
|
7343
|
+
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
7344
|
+
try {
|
|
7345
|
+
const { field, direction } = this.parseVersionOrderBy(orderBy);
|
|
7346
|
+
const collection = await this.getCollection(storage.TABLE_WORKSPACE_VERSIONS);
|
|
7347
|
+
const total = await collection.countDocuments({ workspaceId });
|
|
7348
|
+
if (total === 0 || perPage === 0) {
|
|
7349
|
+
return {
|
|
7350
|
+
versions: [],
|
|
7351
|
+
total,
|
|
7352
|
+
page,
|
|
7353
|
+
perPage: perPageForResponse,
|
|
7354
|
+
hasMore: false
|
|
7355
|
+
};
|
|
7356
|
+
}
|
|
7357
|
+
const sortOrder = direction === "ASC" ? 1 : -1;
|
|
7358
|
+
let cursor = collection.find({ workspaceId }).sort({ [field]: sortOrder }).skip(offset);
|
|
7359
|
+
if (perPageInput !== false) {
|
|
7360
|
+
cursor = cursor.limit(perPage);
|
|
6231
7361
|
}
|
|
7362
|
+
const results = await cursor.toArray();
|
|
7363
|
+
const versions = results.map((doc) => this.transformVersion(doc));
|
|
7364
|
+
return {
|
|
7365
|
+
versions,
|
|
7366
|
+
total,
|
|
7367
|
+
page,
|
|
7368
|
+
perPage: perPageForResponse,
|
|
7369
|
+
hasMore: perPageInput !== false && offset + perPage < total
|
|
7370
|
+
};
|
|
7371
|
+
} catch (error$1) {
|
|
7372
|
+
throw new error.MastraError(
|
|
7373
|
+
{
|
|
7374
|
+
id: storage.createStorageErrorId("MONGODB", "LIST_WORKSPACE_VERSIONS", "FAILED"),
|
|
7375
|
+
domain: error.ErrorDomain.STORAGE,
|
|
7376
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
7377
|
+
details: { workspaceId }
|
|
7378
|
+
},
|
|
7379
|
+
error$1
|
|
7380
|
+
);
|
|
7381
|
+
}
|
|
7382
|
+
}
|
|
7383
|
+
async deleteVersion(id) {
|
|
7384
|
+
try {
|
|
7385
|
+
const collection = await this.getCollection(storage.TABLE_WORKSPACE_VERSIONS);
|
|
7386
|
+
await collection.deleteOne({ id });
|
|
7387
|
+
} catch (error$1) {
|
|
7388
|
+
throw new error.MastraError(
|
|
7389
|
+
{
|
|
7390
|
+
id: storage.createStorageErrorId("MONGODB", "DELETE_WORKSPACE_VERSION", "FAILED"),
|
|
7391
|
+
domain: error.ErrorDomain.STORAGE,
|
|
7392
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
7393
|
+
details: { versionId: id }
|
|
7394
|
+
},
|
|
7395
|
+
error$1
|
|
7396
|
+
);
|
|
7397
|
+
}
|
|
7398
|
+
}
|
|
7399
|
+
async deleteVersionsByParentId(workspaceId) {
|
|
7400
|
+
try {
|
|
7401
|
+
const collection = await this.getCollection(storage.TABLE_WORKSPACE_VERSIONS);
|
|
7402
|
+
await collection.deleteMany({ workspaceId });
|
|
7403
|
+
} catch (error$1) {
|
|
7404
|
+
throw new error.MastraError(
|
|
7405
|
+
{
|
|
7406
|
+
id: storage.createStorageErrorId("MONGODB", "DELETE_VERSIONS_BY_WORKSPACE_ID", "FAILED"),
|
|
7407
|
+
domain: error.ErrorDomain.STORAGE,
|
|
7408
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
7409
|
+
details: { workspaceId }
|
|
7410
|
+
},
|
|
7411
|
+
error$1
|
|
7412
|
+
);
|
|
7413
|
+
}
|
|
7414
|
+
}
|
|
7415
|
+
async countVersions(workspaceId) {
|
|
7416
|
+
try {
|
|
7417
|
+
const collection = await this.getCollection(storage.TABLE_WORKSPACE_VERSIONS);
|
|
7418
|
+
return await collection.countDocuments({ workspaceId });
|
|
7419
|
+
} catch (error$1) {
|
|
7420
|
+
throw new error.MastraError(
|
|
7421
|
+
{
|
|
7422
|
+
id: storage.createStorageErrorId("MONGODB", "COUNT_WORKSPACE_VERSIONS", "FAILED"),
|
|
7423
|
+
domain: error.ErrorDomain.STORAGE,
|
|
7424
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
7425
|
+
details: { workspaceId }
|
|
7426
|
+
},
|
|
7427
|
+
error$1
|
|
7428
|
+
);
|
|
6232
7429
|
}
|
|
7430
|
+
}
|
|
7431
|
+
// ==========================================================================
|
|
7432
|
+
// Private Helper Methods
|
|
7433
|
+
// ==========================================================================
|
|
7434
|
+
transformWorkspace(doc) {
|
|
7435
|
+
const { _id, ...rest } = doc;
|
|
6233
7436
|
return {
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
7437
|
+
id: rest.id,
|
|
7438
|
+
status: rest.status,
|
|
7439
|
+
activeVersionId: rest.activeVersionId,
|
|
7440
|
+
authorId: rest.authorId,
|
|
7441
|
+
metadata: rest.metadata,
|
|
7442
|
+
createdAt: rest.createdAt instanceof Date ? rest.createdAt : new Date(rest.createdAt),
|
|
7443
|
+
updatedAt: rest.updatedAt instanceof Date ? rest.updatedAt : new Date(rest.updatedAt)
|
|
7444
|
+
};
|
|
7445
|
+
}
|
|
7446
|
+
serializeWorkspace(workspace) {
|
|
7447
|
+
return {
|
|
7448
|
+
id: workspace.id,
|
|
7449
|
+
status: workspace.status,
|
|
7450
|
+
activeVersionId: workspace.activeVersionId,
|
|
7451
|
+
authorId: workspace.authorId,
|
|
7452
|
+
metadata: workspace.metadata,
|
|
7453
|
+
createdAt: workspace.createdAt,
|
|
7454
|
+
updatedAt: workspace.updatedAt
|
|
7455
|
+
};
|
|
7456
|
+
}
|
|
7457
|
+
transformVersion(doc) {
|
|
7458
|
+
const { _id, ...version } = doc;
|
|
7459
|
+
const result = {
|
|
7460
|
+
id: version.id,
|
|
7461
|
+
workspaceId: version.workspaceId,
|
|
7462
|
+
versionNumber: version.versionNumber,
|
|
7463
|
+
changedFields: version.changedFields,
|
|
7464
|
+
changeMessage: version.changeMessage,
|
|
7465
|
+
createdAt: version.createdAt instanceof Date ? version.createdAt : new Date(version.createdAt)
|
|
6240
7466
|
};
|
|
7467
|
+
for (const field of SNAPSHOT_FIELDS6) {
|
|
7468
|
+
if (version[field] !== void 0) {
|
|
7469
|
+
result[field] = version[field];
|
|
7470
|
+
}
|
|
7471
|
+
}
|
|
7472
|
+
return result;
|
|
7473
|
+
}
|
|
7474
|
+
extractSnapshotFields(version) {
|
|
7475
|
+
const result = {};
|
|
7476
|
+
for (const field of SNAPSHOT_FIELDS6) {
|
|
7477
|
+
if (version[field] !== void 0) {
|
|
7478
|
+
result[field] = version[field];
|
|
7479
|
+
}
|
|
7480
|
+
}
|
|
7481
|
+
return result;
|
|
6241
7482
|
}
|
|
6242
7483
|
};
|
|
6243
7484
|
|
|
@@ -6261,6 +7502,9 @@ var MongoDBStore = class extends storage.MastraCompositeStore {
|
|
|
6261
7502
|
const promptBlocks = new MongoDBPromptBlocksStorage(domainConfig);
|
|
6262
7503
|
const scorerDefinitions = new MongoDBScorerDefinitionsStorage(domainConfig);
|
|
6263
7504
|
const mcpClients = new MongoDBMCPClientsStorage(domainConfig);
|
|
7505
|
+
const workspaces = new MongoDBWorkspacesStorage(domainConfig);
|
|
7506
|
+
const skills = new MongoDBSkillsStorage(domainConfig);
|
|
7507
|
+
const blobs = new MongoDBBlobStore(domainConfig);
|
|
6264
7508
|
this.stores = {
|
|
6265
7509
|
memory,
|
|
6266
7510
|
scores,
|
|
@@ -6269,7 +7513,10 @@ var MongoDBStore = class extends storage.MastraCompositeStore {
|
|
|
6269
7513
|
agents,
|
|
6270
7514
|
promptBlocks,
|
|
6271
7515
|
scorerDefinitions,
|
|
6272
|
-
mcpClients
|
|
7516
|
+
mcpClients,
|
|
7517
|
+
workspaces,
|
|
7518
|
+
skills,
|
|
7519
|
+
blobs
|
|
6273
7520
|
};
|
|
6274
7521
|
}
|
|
6275
7522
|
/**
|
|
@@ -6391,11 +7638,14 @@ Example Complex Query:
|
|
|
6391
7638
|
exports.MONGODB_PROMPT = MONGODB_PROMPT;
|
|
6392
7639
|
exports.MemoryStorageMongoDB = MemoryStorageMongoDB;
|
|
6393
7640
|
exports.MongoDBAgentsStorage = MongoDBAgentsStorage;
|
|
7641
|
+
exports.MongoDBBlobStore = MongoDBBlobStore;
|
|
6394
7642
|
exports.MongoDBMCPClientsStorage = MongoDBMCPClientsStorage;
|
|
6395
7643
|
exports.MongoDBPromptBlocksStorage = MongoDBPromptBlocksStorage;
|
|
6396
7644
|
exports.MongoDBScorerDefinitionsStorage = MongoDBScorerDefinitionsStorage;
|
|
7645
|
+
exports.MongoDBSkillsStorage = MongoDBSkillsStorage;
|
|
6397
7646
|
exports.MongoDBStore = MongoDBStore;
|
|
6398
7647
|
exports.MongoDBVector = MongoDBVector;
|
|
7648
|
+
exports.MongoDBWorkspacesStorage = MongoDBWorkspacesStorage;
|
|
6399
7649
|
exports.ObservabilityMongoDB = ObservabilityMongoDB;
|
|
6400
7650
|
exports.ScoresStorageMongoDB = ScoresStorageMongoDB;
|
|
6401
7651
|
exports.WorkflowsStorageMongoDB = WorkflowsStorageMongoDB;
|