@mastra/mongodb 1.0.0-beta.11 → 1.0.0-beta.13
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 +126 -0
- package/README.md +18 -0
- package/dist/docs/README.md +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/SOURCE_MAP.json +1 -1
- package/dist/docs/memory/01-working-memory.md +10 -6
- package/dist/docs/rag/01-vector-databases.md +13 -8
- package/dist/docs/rag/02-retrieval.md +5 -6
- package/dist/docs/storage/01-reference.md +16 -10
- package/dist/docs/vectors/01-reference.md +21 -6
- package/dist/index.cjs +67 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +67 -27
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +2 -2
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/types.d.ts +14 -2
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/vector/index.d.ts +17 -6
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -13,7 +13,7 @@ var evals = require('@mastra/core/evals');
|
|
|
13
13
|
|
|
14
14
|
// package.json
|
|
15
15
|
var package_default = {
|
|
16
|
-
version: "1.0.0-beta.
|
|
16
|
+
version: "1.0.0-beta.13"};
|
|
17
17
|
var MongoDBFilterTranslator = class extends filter.BaseFilterTranslator {
|
|
18
18
|
getSupportedOperators() {
|
|
19
19
|
return {
|
|
@@ -107,7 +107,7 @@ var MongoDBVector = class extends vector.MastraVector {
|
|
|
107
107
|
client;
|
|
108
108
|
db;
|
|
109
109
|
collections;
|
|
110
|
-
embeddingFieldName
|
|
110
|
+
embeddingFieldName;
|
|
111
111
|
metadataFieldName = "metadata";
|
|
112
112
|
documentFieldName = "document";
|
|
113
113
|
collectionForValidation = null;
|
|
@@ -116,8 +116,11 @@ var MongoDBVector = class extends vector.MastraVector {
|
|
|
116
116
|
euclidean: "euclidean",
|
|
117
117
|
dotproduct: "dotProduct"
|
|
118
118
|
};
|
|
119
|
-
constructor({ id, uri, dbName, options }) {
|
|
119
|
+
constructor({ id, uri, dbName, options, embeddingFieldPath }) {
|
|
120
120
|
super({ id });
|
|
121
|
+
if (!uri) {
|
|
122
|
+
throw new Error('MongoDBVector requires a connection string. Provide "uri" in the constructor options.');
|
|
123
|
+
}
|
|
121
124
|
const client = new mongodb.MongoClient(uri, {
|
|
122
125
|
...options,
|
|
123
126
|
driverInfo: {
|
|
@@ -128,6 +131,7 @@ var MongoDBVector = class extends vector.MastraVector {
|
|
|
128
131
|
this.client = client;
|
|
129
132
|
this.db = this.client.db(dbName);
|
|
130
133
|
this.collections = /* @__PURE__ */ new Map();
|
|
134
|
+
this.embeddingFieldName = embeddingFieldPath ?? "embedding";
|
|
131
135
|
}
|
|
132
136
|
// Public methods
|
|
133
137
|
async connect() {
|
|
@@ -859,11 +863,21 @@ function resolveMongoDBConfig(config) {
|
|
|
859
863
|
);
|
|
860
864
|
}
|
|
861
865
|
}
|
|
866
|
+
const connectionString = config.uri ?? config.url;
|
|
867
|
+
if (!connectionString) {
|
|
868
|
+
throw new error.MastraError({
|
|
869
|
+
id: storage.createStorageErrorId("MONGODB", "CONSTRUCTOR", "MISSING_URI"),
|
|
870
|
+
domain: error.ErrorDomain.STORAGE,
|
|
871
|
+
category: error.ErrorCategory.USER,
|
|
872
|
+
details: { dbName: config?.dbName },
|
|
873
|
+
text: 'MongoDBStore requires a connection string. Provide "uri" (recommended) or "url" in the constructor options.'
|
|
874
|
+
});
|
|
875
|
+
}
|
|
862
876
|
try {
|
|
863
877
|
return MongoDBConnector.fromDatabaseConfig({
|
|
864
878
|
id: "id" in config ? config.id : "domain",
|
|
865
879
|
options: config.options,
|
|
866
|
-
url:
|
|
880
|
+
url: connectionString,
|
|
867
881
|
dbName: config.dbName
|
|
868
882
|
});
|
|
869
883
|
} catch (error$1) {
|
|
@@ -872,7 +886,7 @@ function resolveMongoDBConfig(config) {
|
|
|
872
886
|
id: storage.createStorageErrorId("MONGODB", "CONSTRUCTOR", "FAILED"),
|
|
873
887
|
domain: error.ErrorDomain.STORAGE,
|
|
874
888
|
category: error.ErrorCategory.USER,
|
|
875
|
-
details: { url: config?.url, dbName: config?.dbName }
|
|
889
|
+
details: { uri: config?.uri ?? "", url: config?.url ?? "", dbName: config?.dbName ?? "" }
|
|
876
890
|
},
|
|
877
891
|
error$1
|
|
878
892
|
);
|
|
@@ -1673,25 +1687,48 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends storage.MemorySto
|
|
|
1673
1687
|
);
|
|
1674
1688
|
}
|
|
1675
1689
|
}
|
|
1676
|
-
async
|
|
1690
|
+
async listThreads(args) {
|
|
1691
|
+
const { page = 0, perPage: perPageInput, orderBy, filter } = args;
|
|
1692
|
+
try {
|
|
1693
|
+
this.validatePaginationInput(page, perPageInput ?? 100);
|
|
1694
|
+
} catch (error$1) {
|
|
1695
|
+
throw new error.MastraError(
|
|
1696
|
+
{
|
|
1697
|
+
id: storage.createStorageErrorId("MONGODB", "LIST_THREADS", "INVALID_PAGE"),
|
|
1698
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1699
|
+
category: error.ErrorCategory.USER,
|
|
1700
|
+
details: { page, ...perPageInput !== void 0 && { perPage: perPageInput } }
|
|
1701
|
+
},
|
|
1702
|
+
error$1 instanceof Error ? error$1 : new Error("Invalid pagination parameters")
|
|
1703
|
+
);
|
|
1704
|
+
}
|
|
1705
|
+
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
1706
|
+
try {
|
|
1707
|
+
this.validateMetadataKeys(filter?.metadata);
|
|
1708
|
+
} catch (error$1) {
|
|
1709
|
+
throw new error.MastraError(
|
|
1710
|
+
{
|
|
1711
|
+
id: storage.createStorageErrorId("MONGODB", "LIST_THREADS", "INVALID_METADATA_KEY"),
|
|
1712
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1713
|
+
category: error.ErrorCategory.USER,
|
|
1714
|
+
details: { metadataKeys: filter?.metadata ? Object.keys(filter.metadata).join(", ") : "" }
|
|
1715
|
+
},
|
|
1716
|
+
error$1 instanceof Error ? error$1 : new Error("Invalid metadata key")
|
|
1717
|
+
);
|
|
1718
|
+
}
|
|
1677
1719
|
try {
|
|
1678
|
-
const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
|
|
1679
|
-
if (page < 0) {
|
|
1680
|
-
throw new error.MastraError(
|
|
1681
|
-
{
|
|
1682
|
-
id: storage.createStorageErrorId("MONGODB", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
|
|
1683
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1684
|
-
category: error.ErrorCategory.USER,
|
|
1685
|
-
details: { page }
|
|
1686
|
-
},
|
|
1687
|
-
new Error("page must be >= 0")
|
|
1688
|
-
);
|
|
1689
|
-
}
|
|
1690
|
-
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
1691
1720
|
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
1692
1721
|
const { field, direction } = this.parseOrderBy(orderBy);
|
|
1693
1722
|
const collection = await this.getCollection(storage.TABLE_THREADS);
|
|
1694
|
-
const query = {
|
|
1723
|
+
const query = {};
|
|
1724
|
+
if (filter?.resourceId) {
|
|
1725
|
+
query.resourceId = filter.resourceId;
|
|
1726
|
+
}
|
|
1727
|
+
if (filter?.metadata && Object.keys(filter.metadata).length > 0) {
|
|
1728
|
+
for (const [key, value] of Object.entries(filter.metadata)) {
|
|
1729
|
+
query[`metadata.${key}`] = value;
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1695
1732
|
const total = await collection.countDocuments(query);
|
|
1696
1733
|
if (perPage === 0) {
|
|
1697
1734
|
return {
|
|
@@ -1725,10 +1762,13 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends storage.MemorySto
|
|
|
1725
1762
|
} catch (error$1) {
|
|
1726
1763
|
throw new error.MastraError(
|
|
1727
1764
|
{
|
|
1728
|
-
id: storage.createStorageErrorId("MONGODB", "
|
|
1765
|
+
id: storage.createStorageErrorId("MONGODB", "LIST_THREADS", "FAILED"),
|
|
1729
1766
|
domain: error.ErrorDomain.STORAGE,
|
|
1730
1767
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1731
|
-
details: {
|
|
1768
|
+
details: {
|
|
1769
|
+
...filter?.resourceId && { resourceId: filter.resourceId },
|
|
1770
|
+
hasMetadataFilter: !!filter?.metadata
|
|
1771
|
+
}
|
|
1732
1772
|
},
|
|
1733
1773
|
error$1
|
|
1734
1774
|
);
|
|
@@ -2583,7 +2623,7 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends storage.ScoresSto
|
|
|
2583
2623
|
};
|
|
2584
2624
|
}
|
|
2585
2625
|
const end = perPageInput === false ? total : start + perPage;
|
|
2586
|
-
let cursor = collection.find(query).sort({ createdAt:
|
|
2626
|
+
let cursor = collection.find(query).sort({ createdAt: -1 }).skip(start);
|
|
2587
2627
|
if (perPageInput !== false) {
|
|
2588
2628
|
cursor = cursor.limit(perPage);
|
|
2589
2629
|
}
|
|
@@ -2632,7 +2672,7 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends storage.ScoresSto
|
|
|
2632
2672
|
};
|
|
2633
2673
|
}
|
|
2634
2674
|
const end = perPageInput === false ? total : start + perPage;
|
|
2635
|
-
let cursor = collection.find({ runId }).sort({ createdAt:
|
|
2675
|
+
let cursor = collection.find({ runId }).sort({ createdAt: -1 }).skip(start);
|
|
2636
2676
|
if (perPageInput !== false) {
|
|
2637
2677
|
cursor = cursor.limit(perPage);
|
|
2638
2678
|
}
|
|
@@ -2682,7 +2722,7 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends storage.ScoresSto
|
|
|
2682
2722
|
};
|
|
2683
2723
|
}
|
|
2684
2724
|
const end = perPageInput === false ? total : start + perPage;
|
|
2685
|
-
let cursor = collection.find({ entityId, entityType }).sort({ createdAt:
|
|
2725
|
+
let cursor = collection.find({ entityId, entityType }).sort({ createdAt: -1 }).skip(start);
|
|
2686
2726
|
if (perPageInput !== false) {
|
|
2687
2727
|
cursor = cursor.limit(perPage);
|
|
2688
2728
|
}
|
|
@@ -2733,7 +2773,7 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends storage.ScoresSto
|
|
|
2733
2773
|
};
|
|
2734
2774
|
}
|
|
2735
2775
|
const end = perPageInput === false ? total : start + perPage;
|
|
2736
|
-
let cursor = collection.find(query).sort({ createdAt:
|
|
2776
|
+
let cursor = collection.find(query).sort({ createdAt: -1 }).skip(start);
|
|
2737
2777
|
if (perPageInput !== false) {
|
|
2738
2778
|
cursor = cursor.limit(perPage);
|
|
2739
2779
|
}
|
|
@@ -3026,7 +3066,7 @@ var WorkflowsStorageMongoDB = class _WorkflowsStorageMongoDB extends storage.Wor
|
|
|
3026
3066
|
try {
|
|
3027
3067
|
parsedSnapshot = typeof row.snapshot === "string" ? storage.safelyParseJSON(row.snapshot) : row.snapshot;
|
|
3028
3068
|
} catch (e) {
|
|
3029
|
-
|
|
3069
|
+
this.logger.warn(`Failed to parse snapshot for workflow ${row.workflow_name}: ${e}`);
|
|
3030
3070
|
}
|
|
3031
3071
|
}
|
|
3032
3072
|
return {
|