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