@mastra/mongodb 0.14.6-alpha.0 → 0.14.7-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 +18 -0
- package/dist/index.cjs +479 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +480 -36
- package/dist/index.js.map +1 -1
- package/dist/storage/connectors/MongoDBConnector.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts +43 -0
- package/dist/storage/domains/observability/index.d.ts.map +1 -0
- package/dist/storage/domains/operations/index.d.ts +12 -0
- package/dist/storage/domains/operations/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +41 -11
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +13 -6
- package/dist/storage/MongoDBConnector.d.ts +0 -23
- package/dist/storage/MongoDBConnector.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @mastra/mongodb
|
|
2
2
|
|
|
3
|
+
## 0.14.7-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Adds MongoDB Observability support, and MongoDB Storage documentation, examples, and telemetry. ([#8426](https://github.com/mastra-ai/mastra/pull/8426))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`f743dbb`](https://github.com/mastra-ai/mastra/commit/f743dbb8b40d1627b5c10c0e6fc154f4ebb6e394), [`5df9cce`](https://github.com/mastra-ai/mastra/commit/5df9cce1a753438413f64c11eeef8f845745c2a8), [`2060766`](https://github.com/mastra-ai/mastra/commit/20607667bf78ea104cca3e15dfb93ae0b62c9d18), [`2c4438b`](https://github.com/mastra-ai/mastra/commit/2c4438b87817ab7eed818c7990fef010475af1a3)]:
|
|
10
|
+
- @mastra/core@0.23.0-alpha.0
|
|
11
|
+
|
|
12
|
+
## 0.14.6
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Update peerdeps to 0.23.0-0 ([#9043](https://github.com/mastra-ai/mastra/pull/9043))
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`c67ca32`](https://github.com/mastra-ai/mastra/commit/c67ca32e3c2cf69bfc146580770c720220ca44ac), [`efb5ed9`](https://github.com/mastra-ai/mastra/commit/efb5ed946ae7f410bc68c9430beb4b010afd25ec), [`dbc9e12`](https://github.com/mastra-ai/mastra/commit/dbc9e1216ba575ba59ead4afb727a01215f7de4f), [`99e41b9`](https://github.com/mastra-ai/mastra/commit/99e41b94957cdd25137d3ac12e94e8b21aa01b68), [`c28833c`](https://github.com/mastra-ai/mastra/commit/c28833c5b6d8e10eeffd7f7d39129d53b8bca240), [`8ea07b4`](https://github.com/mastra-ai/mastra/commit/8ea07b4bdc73e4218437dbb6dcb0f4b23e745a44), [`ba201b8`](https://github.com/mastra-ai/mastra/commit/ba201b8f8feac4c72350f2dbd52c13c7297ba7b0), [`f053e89`](https://github.com/mastra-ai/mastra/commit/f053e89160dbd0bd3333fc3492f68231b5c7c349), [`4fc4136`](https://github.com/mastra-ai/mastra/commit/4fc413652866a8d2240694fddb2562e9edbb70df), [`b78e04d`](https://github.com/mastra-ai/mastra/commit/b78e04d935a16ecb1e59c5c96e564903527edddd), [`d10baf5`](https://github.com/mastra-ai/mastra/commit/d10baf5a3c924f2a6654e23a3e318ed03f189b76), [`038c55a`](https://github.com/mastra-ai/mastra/commit/038c55a7090fc1b1513a966386d3072617f836ac), [`182f045`](https://github.com/mastra-ai/mastra/commit/182f0458f25bd70aa774e64fd923c8a483eddbf1), [`9a1a485`](https://github.com/mastra-ai/mastra/commit/9a1a4859b855e37239f652bf14b1ecd1029b8c4e), [`9257233`](https://github.com/mastra-ai/mastra/commit/9257233c4ffce09b2bedc2a9adbd70d7a83fa8e2), [`7620d2b`](https://github.com/mastra-ai/mastra/commit/7620d2bddeb4fae4c3c0a0b4e672969795fca11a), [`b2365f0`](https://github.com/mastra-ai/mastra/commit/b2365f038dd4c5f06400428b224af963f399ad50), [`0f1a4c9`](https://github.com/mastra-ai/mastra/commit/0f1a4c984fb4b104b2f0b63ba18c9fa77f567700), [`9029ba3`](https://github.com/mastra-ai/mastra/commit/9029ba34459c8859fed4c6b73efd8e2d0021e7ba), [`426cc56`](https://github.com/mastra-ai/mastra/commit/426cc561c85ae76a112ded2385532a91f9f9f074), [`00931fb`](https://github.com/mastra-ai/mastra/commit/00931fb1a21aa42c4fbc20c2c40dd62466b8fc8f), [`e473bfe`](https://github.com/mastra-ai/mastra/commit/e473bfe416c0b8e876973c2b6a6f13c394b7a93f), [`b78e04d`](https://github.com/mastra-ai/mastra/commit/b78e04d935a16ecb1e59c5c96e564903527edddd), [`2db6160`](https://github.com/mastra-ai/mastra/commit/2db6160e2022ff8827c15d30157e684683b934b5), [`8aeea37`](https://github.com/mastra-ai/mastra/commit/8aeea37efdde347c635a67fed56794943b7f74ec), [`02fe153`](https://github.com/mastra-ai/mastra/commit/02fe15351d6021d214da48ec982a0e9e4150bcee), [`648e2ca`](https://github.com/mastra-ai/mastra/commit/648e2ca42da54838c6ccbdaadc6fadd808fa6b86), [`74567b3`](https://github.com/mastra-ai/mastra/commit/74567b3d237ae3915cd0bca3cf55fa0a64e4e4a4), [`b65c5e0`](https://github.com/mastra-ai/mastra/commit/b65c5e0fe6f3c390a9a8bbcf69304d972c3a4afb), [`15a1733`](https://github.com/mastra-ai/mastra/commit/15a1733074cee8bd37370e1af34cd818e89fa7ac), [`fc2a774`](https://github.com/mastra-ai/mastra/commit/fc2a77468981aaddc3e77f83f0c4ad4a4af140da), [`4e08933`](https://github.com/mastra-ai/mastra/commit/4e08933625464dfde178347af5b6278fcf34188e)]:
|
|
19
|
+
- @mastra/core@0.22.0
|
|
20
|
+
|
|
3
21
|
## 0.14.6-alpha.0
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -10,6 +10,10 @@ var agent = require('@mastra/core/agent');
|
|
|
10
10
|
var scores = require('@mastra/core/scores');
|
|
11
11
|
|
|
12
12
|
// src/vector/index.ts
|
|
13
|
+
|
|
14
|
+
// package.json
|
|
15
|
+
var package_default = {
|
|
16
|
+
version: "0.14.7-alpha.0"};
|
|
13
17
|
var MongoDBFilterTranslator = class extends filter.BaseFilterTranslator {
|
|
14
18
|
getSupportedOperators() {
|
|
15
19
|
return {
|
|
@@ -114,7 +118,14 @@ var MongoDBVector = class extends vector.MastraVector {
|
|
|
114
118
|
};
|
|
115
119
|
constructor({ uri, dbName, options }) {
|
|
116
120
|
super();
|
|
117
|
-
|
|
121
|
+
const client = new mongodb.MongoClient(uri, {
|
|
122
|
+
...options,
|
|
123
|
+
driverInfo: {
|
|
124
|
+
name: "mastra-vector",
|
|
125
|
+
version: package_default.version
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
this.client = client;
|
|
118
129
|
this.db = this.client.db(dbName);
|
|
119
130
|
this.collections = /* @__PURE__ */ new Map();
|
|
120
131
|
}
|
|
@@ -634,8 +645,15 @@ var MongoDBConnector = class _MongoDBConnector {
|
|
|
634
645
|
"MongoDBStore: dbName must be provided and cannot be empty. Passing an empty string may cause fallback to local MongoDB defaults."
|
|
635
646
|
);
|
|
636
647
|
}
|
|
648
|
+
const client = new mongodb.MongoClient(config.url, {
|
|
649
|
+
...config.options,
|
|
650
|
+
driverInfo: {
|
|
651
|
+
name: "mastra-storage",
|
|
652
|
+
version: package_default.version
|
|
653
|
+
}
|
|
654
|
+
});
|
|
637
655
|
return new _MongoDBConnector({
|
|
638
|
-
client
|
|
656
|
+
client,
|
|
639
657
|
dbName: config.dbName,
|
|
640
658
|
handler: void 0
|
|
641
659
|
});
|
|
@@ -1428,6 +1446,286 @@ var MemoryStorageMongoDB = class extends storage.MemoryStorage {
|
|
|
1428
1446
|
}
|
|
1429
1447
|
}
|
|
1430
1448
|
};
|
|
1449
|
+
var ObservabilityMongoDB = class extends storage.ObservabilityStorage {
|
|
1450
|
+
operations;
|
|
1451
|
+
constructor({ operations }) {
|
|
1452
|
+
super();
|
|
1453
|
+
this.operations = operations;
|
|
1454
|
+
}
|
|
1455
|
+
get aiTracingStrategy() {
|
|
1456
|
+
return {
|
|
1457
|
+
preferred: "batch-with-updates",
|
|
1458
|
+
supported: ["batch-with-updates", "insert-only"]
|
|
1459
|
+
};
|
|
1460
|
+
}
|
|
1461
|
+
async createAISpan(span) {
|
|
1462
|
+
try {
|
|
1463
|
+
const startedAt = span.startedAt instanceof Date ? span.startedAt.toISOString() : span.startedAt;
|
|
1464
|
+
const endedAt = span.endedAt instanceof Date ? span.endedAt.toISOString() : span.endedAt;
|
|
1465
|
+
const record = {
|
|
1466
|
+
...span,
|
|
1467
|
+
startedAt,
|
|
1468
|
+
endedAt,
|
|
1469
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1470
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1471
|
+
};
|
|
1472
|
+
return this.operations.insert({ tableName: storage.TABLE_AI_SPANS, record });
|
|
1473
|
+
} catch (error$1) {
|
|
1474
|
+
throw new error.MastraError(
|
|
1475
|
+
{
|
|
1476
|
+
id: "MONGODB_STORE_CREATE_AI_SPAN_FAILED",
|
|
1477
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1478
|
+
category: error.ErrorCategory.USER,
|
|
1479
|
+
details: {
|
|
1480
|
+
spanId: span.spanId,
|
|
1481
|
+
traceId: span.traceId,
|
|
1482
|
+
spanType: span.spanType,
|
|
1483
|
+
spanName: span.name
|
|
1484
|
+
}
|
|
1485
|
+
},
|
|
1486
|
+
error$1
|
|
1487
|
+
);
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
async getAITrace(traceId) {
|
|
1491
|
+
try {
|
|
1492
|
+
const collection = await this.operations.getCollection(storage.TABLE_AI_SPANS);
|
|
1493
|
+
const spans = await collection.find({ traceId }).sort({ startedAt: -1 }).toArray();
|
|
1494
|
+
if (!spans || spans.length === 0) {
|
|
1495
|
+
return null;
|
|
1496
|
+
}
|
|
1497
|
+
return {
|
|
1498
|
+
traceId,
|
|
1499
|
+
spans: spans.map((span) => this.transformSpanFromMongo(span))
|
|
1500
|
+
};
|
|
1501
|
+
} catch (error$1) {
|
|
1502
|
+
throw new error.MastraError(
|
|
1503
|
+
{
|
|
1504
|
+
id: "MONGODB_STORE_GET_AI_TRACE_FAILED",
|
|
1505
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1506
|
+
category: error.ErrorCategory.USER,
|
|
1507
|
+
details: {
|
|
1508
|
+
traceId
|
|
1509
|
+
}
|
|
1510
|
+
},
|
|
1511
|
+
error$1
|
|
1512
|
+
);
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
async updateAISpan({
|
|
1516
|
+
spanId,
|
|
1517
|
+
traceId,
|
|
1518
|
+
updates
|
|
1519
|
+
}) {
|
|
1520
|
+
try {
|
|
1521
|
+
const data = { ...updates };
|
|
1522
|
+
if (data.endedAt instanceof Date) {
|
|
1523
|
+
data.endedAt = data.endedAt.toISOString();
|
|
1524
|
+
}
|
|
1525
|
+
if (data.startedAt instanceof Date) {
|
|
1526
|
+
data.startedAt = data.startedAt.toISOString();
|
|
1527
|
+
}
|
|
1528
|
+
const updateData = {
|
|
1529
|
+
...data,
|
|
1530
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1531
|
+
};
|
|
1532
|
+
await this.operations.update({
|
|
1533
|
+
tableName: storage.TABLE_AI_SPANS,
|
|
1534
|
+
keys: { spanId, traceId },
|
|
1535
|
+
data: updateData
|
|
1536
|
+
});
|
|
1537
|
+
} catch (error$1) {
|
|
1538
|
+
throw new error.MastraError(
|
|
1539
|
+
{
|
|
1540
|
+
id: "MONGODB_STORE_UPDATE_AI_SPAN_FAILED",
|
|
1541
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1542
|
+
category: error.ErrorCategory.USER,
|
|
1543
|
+
details: {
|
|
1544
|
+
spanId,
|
|
1545
|
+
traceId
|
|
1546
|
+
}
|
|
1547
|
+
},
|
|
1548
|
+
error$1
|
|
1549
|
+
);
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
async getAITracesPaginated({
|
|
1553
|
+
filters,
|
|
1554
|
+
pagination
|
|
1555
|
+
}) {
|
|
1556
|
+
const page = pagination?.page ?? 0;
|
|
1557
|
+
const perPage = pagination?.perPage ?? 10;
|
|
1558
|
+
const { entityId, entityType, ...actualFilters } = filters || {};
|
|
1559
|
+
try {
|
|
1560
|
+
const collection = await this.operations.getCollection(storage.TABLE_AI_SPANS);
|
|
1561
|
+
const mongoFilter = {
|
|
1562
|
+
parentSpanId: null,
|
|
1563
|
+
// Only get root spans for traces
|
|
1564
|
+
...actualFilters
|
|
1565
|
+
};
|
|
1566
|
+
if (pagination?.dateRange) {
|
|
1567
|
+
const dateFilter = {};
|
|
1568
|
+
if (pagination.dateRange.start) {
|
|
1569
|
+
dateFilter.$gte = pagination.dateRange.start instanceof Date ? pagination.dateRange.start.toISOString() : pagination.dateRange.start;
|
|
1570
|
+
}
|
|
1571
|
+
if (pagination.dateRange.end) {
|
|
1572
|
+
dateFilter.$lte = pagination.dateRange.end instanceof Date ? pagination.dateRange.end.toISOString() : pagination.dateRange.end;
|
|
1573
|
+
}
|
|
1574
|
+
if (Object.keys(dateFilter).length > 0) {
|
|
1575
|
+
mongoFilter.startedAt = dateFilter;
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
if (entityId && entityType) {
|
|
1579
|
+
let name = "";
|
|
1580
|
+
if (entityType === "workflow") {
|
|
1581
|
+
name = `workflow run: '${entityId}'`;
|
|
1582
|
+
} else if (entityType === "agent") {
|
|
1583
|
+
name = `agent run: '${entityId}'`;
|
|
1584
|
+
} else {
|
|
1585
|
+
const error$1 = new error.MastraError({
|
|
1586
|
+
id: "MONGODB_STORE_GET_AI_TRACES_PAGINATED_FAILED",
|
|
1587
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1588
|
+
category: error.ErrorCategory.USER,
|
|
1589
|
+
details: {
|
|
1590
|
+
entityType
|
|
1591
|
+
},
|
|
1592
|
+
text: `Cannot filter by entity type: ${entityType}`
|
|
1593
|
+
});
|
|
1594
|
+
throw error$1;
|
|
1595
|
+
}
|
|
1596
|
+
mongoFilter.name = name;
|
|
1597
|
+
}
|
|
1598
|
+
const count = await collection.countDocuments(mongoFilter);
|
|
1599
|
+
if (count === 0) {
|
|
1600
|
+
return {
|
|
1601
|
+
pagination: {
|
|
1602
|
+
total: 0,
|
|
1603
|
+
page,
|
|
1604
|
+
perPage,
|
|
1605
|
+
hasMore: false
|
|
1606
|
+
},
|
|
1607
|
+
spans: []
|
|
1608
|
+
};
|
|
1609
|
+
}
|
|
1610
|
+
const spans = await collection.find(mongoFilter).sort({ startedAt: -1 }).skip(page * perPage).limit(perPage).toArray();
|
|
1611
|
+
return {
|
|
1612
|
+
pagination: {
|
|
1613
|
+
total: count,
|
|
1614
|
+
page,
|
|
1615
|
+
perPage,
|
|
1616
|
+
hasMore: spans.length === perPage
|
|
1617
|
+
},
|
|
1618
|
+
spans: spans.map((span) => this.transformSpanFromMongo(span))
|
|
1619
|
+
};
|
|
1620
|
+
} catch (error$1) {
|
|
1621
|
+
throw new error.MastraError(
|
|
1622
|
+
{
|
|
1623
|
+
id: "MONGODB_STORE_GET_AI_TRACES_PAGINATED_FAILED",
|
|
1624
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1625
|
+
category: error.ErrorCategory.USER
|
|
1626
|
+
},
|
|
1627
|
+
error$1
|
|
1628
|
+
);
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
async batchCreateAISpans(args) {
|
|
1632
|
+
try {
|
|
1633
|
+
const records = args.records.map((record) => {
|
|
1634
|
+
const startedAt = record.startedAt instanceof Date ? record.startedAt.toISOString() : record.startedAt;
|
|
1635
|
+
const endedAt = record.endedAt instanceof Date ? record.endedAt.toISOString() : record.endedAt;
|
|
1636
|
+
return {
|
|
1637
|
+
...record,
|
|
1638
|
+
startedAt,
|
|
1639
|
+
endedAt,
|
|
1640
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1641
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1642
|
+
};
|
|
1643
|
+
});
|
|
1644
|
+
return this.operations.batchInsert({
|
|
1645
|
+
tableName: storage.TABLE_AI_SPANS,
|
|
1646
|
+
records
|
|
1647
|
+
});
|
|
1648
|
+
} catch (error$1) {
|
|
1649
|
+
throw new error.MastraError(
|
|
1650
|
+
{
|
|
1651
|
+
id: "MONGODB_STORE_BATCH_CREATE_AI_SPANS_FAILED",
|
|
1652
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1653
|
+
category: error.ErrorCategory.USER
|
|
1654
|
+
},
|
|
1655
|
+
error$1
|
|
1656
|
+
);
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
async batchUpdateAISpans(args) {
|
|
1660
|
+
try {
|
|
1661
|
+
return this.operations.batchUpdate({
|
|
1662
|
+
tableName: storage.TABLE_AI_SPANS,
|
|
1663
|
+
updates: args.records.map((record) => {
|
|
1664
|
+
const data = { ...record.updates };
|
|
1665
|
+
if (data.endedAt instanceof Date) {
|
|
1666
|
+
data.endedAt = data.endedAt.toISOString();
|
|
1667
|
+
}
|
|
1668
|
+
if (data.startedAt instanceof Date) {
|
|
1669
|
+
data.startedAt = data.startedAt.toISOString();
|
|
1670
|
+
}
|
|
1671
|
+
const updateData = {
|
|
1672
|
+
...data,
|
|
1673
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1674
|
+
};
|
|
1675
|
+
return {
|
|
1676
|
+
keys: { spanId: record.spanId, traceId: record.traceId },
|
|
1677
|
+
data: updateData
|
|
1678
|
+
};
|
|
1679
|
+
})
|
|
1680
|
+
});
|
|
1681
|
+
} catch (error$1) {
|
|
1682
|
+
throw new error.MastraError(
|
|
1683
|
+
{
|
|
1684
|
+
id: "MONGODB_STORE_BATCH_UPDATE_AI_SPANS_FAILED",
|
|
1685
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1686
|
+
category: error.ErrorCategory.USER
|
|
1687
|
+
},
|
|
1688
|
+
error$1
|
|
1689
|
+
);
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
async batchDeleteAITraces(args) {
|
|
1693
|
+
try {
|
|
1694
|
+
const collection = await this.operations.getCollection(storage.TABLE_AI_SPANS);
|
|
1695
|
+
await collection.deleteMany({
|
|
1696
|
+
traceId: { $in: args.traceIds }
|
|
1697
|
+
});
|
|
1698
|
+
} catch (error$1) {
|
|
1699
|
+
throw new error.MastraError(
|
|
1700
|
+
{
|
|
1701
|
+
id: "MONGODB_STORE_BATCH_DELETE_AI_TRACES_FAILED",
|
|
1702
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1703
|
+
category: error.ErrorCategory.USER
|
|
1704
|
+
},
|
|
1705
|
+
error$1
|
|
1706
|
+
);
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
/**
|
|
1710
|
+
* Transform MongoDB document to AISpanRecord format
|
|
1711
|
+
*/
|
|
1712
|
+
transformSpanFromMongo(doc) {
|
|
1713
|
+
const { _id, ...span } = doc;
|
|
1714
|
+
if (span.startedAt && typeof span.startedAt === "string") {
|
|
1715
|
+
span.startedAt = span.startedAt;
|
|
1716
|
+
}
|
|
1717
|
+
if (span.endedAt && typeof span.endedAt === "string") {
|
|
1718
|
+
span.endedAt = span.endedAt;
|
|
1719
|
+
}
|
|
1720
|
+
if (span.createdAt && typeof span.createdAt === "string") {
|
|
1721
|
+
span.createdAt = new Date(span.createdAt);
|
|
1722
|
+
}
|
|
1723
|
+
if (span.updatedAt && typeof span.updatedAt === "string") {
|
|
1724
|
+
span.updatedAt = new Date(span.updatedAt);
|
|
1725
|
+
}
|
|
1726
|
+
return span;
|
|
1727
|
+
}
|
|
1728
|
+
};
|
|
1431
1729
|
var StoreOperationsMongoDB = class extends storage.StoreOperations {
|
|
1432
1730
|
#connector;
|
|
1433
1731
|
constructor(config) {
|
|
@@ -1449,19 +1747,18 @@ var StoreOperationsMongoDB = class extends storage.StoreOperations {
|
|
|
1449
1747
|
const collection = await this.getCollection(tableName);
|
|
1450
1748
|
await collection.deleteMany({});
|
|
1451
1749
|
} catch (error$1) {
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
}
|
|
1750
|
+
const mastraError = new error.MastraError(
|
|
1751
|
+
{
|
|
1752
|
+
id: "STORAGE_MONGODB_STORE_CLEAR_TABLE_FAILED",
|
|
1753
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1754
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1755
|
+
details: { tableName }
|
|
1756
|
+
},
|
|
1757
|
+
error$1
|
|
1758
|
+
);
|
|
1759
|
+
this.logger.error(mastraError.message);
|
|
1760
|
+
this.logger?.trackException(mastraError);
|
|
1761
|
+
throw mastraError;
|
|
1465
1762
|
}
|
|
1466
1763
|
}
|
|
1467
1764
|
async dropTable({ tableName }) {
|
|
@@ -1485,6 +1782,9 @@ var StoreOperationsMongoDB = class extends storage.StoreOperations {
|
|
|
1485
1782
|
}
|
|
1486
1783
|
processJsonbFields(tableName, record) {
|
|
1487
1784
|
const schema = storage.TABLE_SCHEMAS[tableName];
|
|
1785
|
+
if (!schema) {
|
|
1786
|
+
return record;
|
|
1787
|
+
}
|
|
1488
1788
|
return Object.fromEntries(
|
|
1489
1789
|
Object.entries(schema).map(([key, value]) => {
|
|
1490
1790
|
if (value.type === "jsonb" && record[key] && typeof record[key] === "string") {
|
|
@@ -1500,19 +1800,18 @@ var StoreOperationsMongoDB = class extends storage.StoreOperations {
|
|
|
1500
1800
|
const recordToInsert = this.processJsonbFields(tableName, record);
|
|
1501
1801
|
await collection.insertOne(recordToInsert);
|
|
1502
1802
|
} catch (error$1) {
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
}
|
|
1803
|
+
const mastraError = new error.MastraError(
|
|
1804
|
+
{
|
|
1805
|
+
id: "STORAGE_MONGODB_STORE_INSERT_FAILED",
|
|
1806
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1807
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1808
|
+
details: { tableName }
|
|
1809
|
+
},
|
|
1810
|
+
error$1
|
|
1811
|
+
);
|
|
1812
|
+
this.logger.error(mastraError.message);
|
|
1813
|
+
this.logger?.trackException(mastraError);
|
|
1814
|
+
throw mastraError;
|
|
1516
1815
|
}
|
|
1517
1816
|
}
|
|
1518
1817
|
async batchInsert({ tableName, records }) {
|
|
@@ -1552,6 +1851,60 @@ var StoreOperationsMongoDB = class extends storage.StoreOperations {
|
|
|
1552
1851
|
);
|
|
1553
1852
|
}
|
|
1554
1853
|
}
|
|
1854
|
+
async update({
|
|
1855
|
+
tableName,
|
|
1856
|
+
keys,
|
|
1857
|
+
data
|
|
1858
|
+
}) {
|
|
1859
|
+
try {
|
|
1860
|
+
const collection = await this.getCollection(tableName);
|
|
1861
|
+
const processedData = this.processJsonbFields(tableName, data);
|
|
1862
|
+
const cleanData = Object.fromEntries(Object.entries(processedData).filter(([_, value]) => value !== void 0));
|
|
1863
|
+
await collection.updateOne(keys, { $set: cleanData });
|
|
1864
|
+
} catch (error$1) {
|
|
1865
|
+
throw new error.MastraError(
|
|
1866
|
+
{
|
|
1867
|
+
id: "STORAGE_MONGODB_STORE_UPDATE_FAILED",
|
|
1868
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1869
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1870
|
+
details: { tableName }
|
|
1871
|
+
},
|
|
1872
|
+
error$1
|
|
1873
|
+
);
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
async batchUpdate({
|
|
1877
|
+
tableName,
|
|
1878
|
+
updates
|
|
1879
|
+
}) {
|
|
1880
|
+
if (!updates.length) {
|
|
1881
|
+
return;
|
|
1882
|
+
}
|
|
1883
|
+
try {
|
|
1884
|
+
const collection = await this.getCollection(tableName);
|
|
1885
|
+
const bulkOps = updates.map(({ keys, data }) => {
|
|
1886
|
+
const processedData = this.processJsonbFields(tableName, data);
|
|
1887
|
+
const cleanData = Object.fromEntries(Object.entries(processedData).filter(([_, value]) => value !== void 0));
|
|
1888
|
+
return {
|
|
1889
|
+
updateOne: {
|
|
1890
|
+
filter: keys,
|
|
1891
|
+
update: { $set: cleanData }
|
|
1892
|
+
}
|
|
1893
|
+
};
|
|
1894
|
+
});
|
|
1895
|
+
await collection.bulkWrite(bulkOps);
|
|
1896
|
+
} catch (error$1) {
|
|
1897
|
+
throw new error.MastraError(
|
|
1898
|
+
{
|
|
1899
|
+
id: "STORAGE_MONGODB_STORE_BATCH_UPDATE_FAILED",
|
|
1900
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1901
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1902
|
+
details: { tableName }
|
|
1903
|
+
},
|
|
1904
|
+
error$1
|
|
1905
|
+
);
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1555
1908
|
};
|
|
1556
1909
|
function transformScoreRow(row) {
|
|
1557
1910
|
let scorerValue = null;
|
|
@@ -2291,13 +2644,17 @@ var MongoDBStore = class extends storage.MastraStorage {
|
|
|
2291
2644
|
const workflows = new WorkflowsStorageMongoDB({
|
|
2292
2645
|
operations
|
|
2293
2646
|
});
|
|
2647
|
+
const observability = new ObservabilityMongoDB({
|
|
2648
|
+
operations
|
|
2649
|
+
});
|
|
2294
2650
|
this.stores = {
|
|
2295
2651
|
operations,
|
|
2296
2652
|
memory,
|
|
2297
2653
|
traces,
|
|
2298
2654
|
legacyEvals,
|
|
2299
2655
|
scores,
|
|
2300
|
-
workflows
|
|
2656
|
+
workflows,
|
|
2657
|
+
observability
|
|
2301
2658
|
};
|
|
2302
2659
|
}
|
|
2303
2660
|
async createTable({
|
|
@@ -2330,6 +2687,9 @@ var MongoDBStore = class extends storage.MastraStorage {
|
|
|
2330
2687
|
async getThreadsByResourceId({ resourceId }) {
|
|
2331
2688
|
return this.stores.memory.getThreadsByResourceId({ resourceId });
|
|
2332
2689
|
}
|
|
2690
|
+
async getThreadsByResourceIdPaginated(_args) {
|
|
2691
|
+
return this.stores.memory.getThreadsByResourceIdPaginated(_args);
|
|
2692
|
+
}
|
|
2333
2693
|
async saveThread({ thread }) {
|
|
2334
2694
|
return this.stores.memory.saveThread({ thread });
|
|
2335
2695
|
}
|
|
@@ -2350,6 +2710,9 @@ var MongoDBStore = class extends storage.MastraStorage {
|
|
|
2350
2710
|
}) {
|
|
2351
2711
|
return this.stores.memory.getMessages({ threadId, selectBy, format });
|
|
2352
2712
|
}
|
|
2713
|
+
async getMessagesPaginated(_args) {
|
|
2714
|
+
return this.stores.memory.getMessagesPaginated(_args);
|
|
2715
|
+
}
|
|
2353
2716
|
async getMessagesById({
|
|
2354
2717
|
messageIds,
|
|
2355
2718
|
format
|
|
@@ -2359,12 +2722,6 @@ var MongoDBStore = class extends storage.MastraStorage {
|
|
|
2359
2722
|
async saveMessages(args) {
|
|
2360
2723
|
return this.stores.memory.saveMessages(args);
|
|
2361
2724
|
}
|
|
2362
|
-
async getThreadsByResourceIdPaginated(_args) {
|
|
2363
|
-
return this.stores.memory.getThreadsByResourceIdPaginated(_args);
|
|
2364
|
-
}
|
|
2365
|
-
async getMessagesPaginated(_args) {
|
|
2366
|
-
return this.stores.memory.getMessagesPaginated(_args);
|
|
2367
|
-
}
|
|
2368
2725
|
async updateMessages(_args) {
|
|
2369
2726
|
return this.stores.memory.updateMessages(_args);
|
|
2370
2727
|
}
|
|
@@ -2374,6 +2731,9 @@ var MongoDBStore = class extends storage.MastraStorage {
|
|
|
2374
2731
|
async getTracesPaginated(args) {
|
|
2375
2732
|
return this.stores.traces.getTracesPaginated(args);
|
|
2376
2733
|
}
|
|
2734
|
+
async batchTraceInsert({ records }) {
|
|
2735
|
+
return this.stores.traces.batchTraceInsert({ records });
|
|
2736
|
+
}
|
|
2377
2737
|
async getWorkflowRuns(args) {
|
|
2378
2738
|
return this.stores.workflows.getWorkflowRuns(args);
|
|
2379
2739
|
}
|
|
@@ -2491,6 +2851,90 @@ var MongoDBStore = class extends storage.MastraStorage {
|
|
|
2491
2851
|
metadata
|
|
2492
2852
|
});
|
|
2493
2853
|
}
|
|
2854
|
+
/**
|
|
2855
|
+
* AI Tracing/Observability
|
|
2856
|
+
*/
|
|
2857
|
+
async createAISpan(span) {
|
|
2858
|
+
if (!this.stores.observability) {
|
|
2859
|
+
throw new error.MastraError({
|
|
2860
|
+
id: "MONGODB_STORE_OBSERVABILITY_NOT_INITIALIZED",
|
|
2861
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2862
|
+
category: error.ErrorCategory.SYSTEM,
|
|
2863
|
+
text: "Observability storage is not initialized"
|
|
2864
|
+
});
|
|
2865
|
+
}
|
|
2866
|
+
return this.stores.observability.createAISpan(span);
|
|
2867
|
+
}
|
|
2868
|
+
async updateAISpan({
|
|
2869
|
+
spanId,
|
|
2870
|
+
traceId,
|
|
2871
|
+
updates
|
|
2872
|
+
}) {
|
|
2873
|
+
if (!this.stores.observability) {
|
|
2874
|
+
throw new error.MastraError({
|
|
2875
|
+
id: "MONGODB_STORE_OBSERVABILITY_NOT_INITIALIZED",
|
|
2876
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2877
|
+
category: error.ErrorCategory.SYSTEM,
|
|
2878
|
+
text: "Observability storage is not initialized"
|
|
2879
|
+
});
|
|
2880
|
+
}
|
|
2881
|
+
return this.stores.observability.updateAISpan({ spanId, traceId, updates });
|
|
2882
|
+
}
|
|
2883
|
+
async getAITrace(traceId) {
|
|
2884
|
+
if (!this.stores.observability) {
|
|
2885
|
+
throw new error.MastraError({
|
|
2886
|
+
id: "MONGODB_STORE_OBSERVABILITY_NOT_INITIALIZED",
|
|
2887
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2888
|
+
category: error.ErrorCategory.SYSTEM,
|
|
2889
|
+
text: "Observability storage is not initialized"
|
|
2890
|
+
});
|
|
2891
|
+
}
|
|
2892
|
+
return this.stores.observability.getAITrace(traceId);
|
|
2893
|
+
}
|
|
2894
|
+
async getAITracesPaginated(args) {
|
|
2895
|
+
if (!this.stores.observability) {
|
|
2896
|
+
throw new error.MastraError({
|
|
2897
|
+
id: "MONGODB_STORE_OBSERVABILITY_NOT_INITIALIZED",
|
|
2898
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2899
|
+
category: error.ErrorCategory.SYSTEM,
|
|
2900
|
+
text: "Observability storage is not initialized"
|
|
2901
|
+
});
|
|
2902
|
+
}
|
|
2903
|
+
return this.stores.observability.getAITracesPaginated(args);
|
|
2904
|
+
}
|
|
2905
|
+
async batchCreateAISpans(args) {
|
|
2906
|
+
if (!this.stores.observability) {
|
|
2907
|
+
throw new error.MastraError({
|
|
2908
|
+
id: "MONGODB_STORE_OBSERVABILITY_NOT_INITIALIZED",
|
|
2909
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2910
|
+
category: error.ErrorCategory.SYSTEM,
|
|
2911
|
+
text: "Observability storage is not initialized"
|
|
2912
|
+
});
|
|
2913
|
+
}
|
|
2914
|
+
return this.stores.observability.batchCreateAISpans(args);
|
|
2915
|
+
}
|
|
2916
|
+
async batchUpdateAISpans(args) {
|
|
2917
|
+
if (!this.stores.observability) {
|
|
2918
|
+
throw new error.MastraError({
|
|
2919
|
+
id: "MONGODB_STORE_OBSERVABILITY_NOT_INITIALIZED",
|
|
2920
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2921
|
+
category: error.ErrorCategory.SYSTEM,
|
|
2922
|
+
text: "Observability storage is not initialized"
|
|
2923
|
+
});
|
|
2924
|
+
}
|
|
2925
|
+
return this.stores.observability.batchUpdateAISpans(args);
|
|
2926
|
+
}
|
|
2927
|
+
async batchDeleteAITraces(args) {
|
|
2928
|
+
if (!this.stores.observability) {
|
|
2929
|
+
throw new error.MastraError({
|
|
2930
|
+
id: "MONGODB_STORE_OBSERVABILITY_NOT_INITIALIZED",
|
|
2931
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2932
|
+
category: error.ErrorCategory.SYSTEM,
|
|
2933
|
+
text: "Observability storage is not initialized"
|
|
2934
|
+
});
|
|
2935
|
+
}
|
|
2936
|
+
return this.stores.observability.batchDeleteAITraces(args);
|
|
2937
|
+
}
|
|
2494
2938
|
};
|
|
2495
2939
|
|
|
2496
2940
|
// src/vector/prompt.ts
|