@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.js
CHANGED
|
@@ -11,7 +11,7 @@ import { saveScorePayloadSchema } from '@mastra/core/evals';
|
|
|
11
11
|
|
|
12
12
|
// package.json
|
|
13
13
|
var package_default = {
|
|
14
|
-
version: "1.0.0-beta.
|
|
14
|
+
version: "1.0.0-beta.13"};
|
|
15
15
|
var MongoDBFilterTranslator = class extends BaseFilterTranslator {
|
|
16
16
|
getSupportedOperators() {
|
|
17
17
|
return {
|
|
@@ -105,7 +105,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
105
105
|
client;
|
|
106
106
|
db;
|
|
107
107
|
collections;
|
|
108
|
-
embeddingFieldName
|
|
108
|
+
embeddingFieldName;
|
|
109
109
|
metadataFieldName = "metadata";
|
|
110
110
|
documentFieldName = "document";
|
|
111
111
|
collectionForValidation = null;
|
|
@@ -114,8 +114,11 @@ var MongoDBVector = class extends MastraVector {
|
|
|
114
114
|
euclidean: "euclidean",
|
|
115
115
|
dotproduct: "dotProduct"
|
|
116
116
|
};
|
|
117
|
-
constructor({ id, uri, dbName, options }) {
|
|
117
|
+
constructor({ id, uri, dbName, options, embeddingFieldPath }) {
|
|
118
118
|
super({ id });
|
|
119
|
+
if (!uri) {
|
|
120
|
+
throw new Error('MongoDBVector requires a connection string. Provide "uri" in the constructor options.');
|
|
121
|
+
}
|
|
119
122
|
const client = new MongoClient(uri, {
|
|
120
123
|
...options,
|
|
121
124
|
driverInfo: {
|
|
@@ -126,6 +129,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
126
129
|
this.client = client;
|
|
127
130
|
this.db = this.client.db(dbName);
|
|
128
131
|
this.collections = /* @__PURE__ */ new Map();
|
|
132
|
+
this.embeddingFieldName = embeddingFieldPath ?? "embedding";
|
|
129
133
|
}
|
|
130
134
|
// Public methods
|
|
131
135
|
async connect() {
|
|
@@ -857,11 +861,21 @@ function resolveMongoDBConfig(config) {
|
|
|
857
861
|
);
|
|
858
862
|
}
|
|
859
863
|
}
|
|
864
|
+
const connectionString = config.uri ?? config.url;
|
|
865
|
+
if (!connectionString) {
|
|
866
|
+
throw new MastraError({
|
|
867
|
+
id: createStorageErrorId("MONGODB", "CONSTRUCTOR", "MISSING_URI"),
|
|
868
|
+
domain: ErrorDomain.STORAGE,
|
|
869
|
+
category: ErrorCategory.USER,
|
|
870
|
+
details: { dbName: config?.dbName },
|
|
871
|
+
text: 'MongoDBStore requires a connection string. Provide "uri" (recommended) or "url" in the constructor options.'
|
|
872
|
+
});
|
|
873
|
+
}
|
|
860
874
|
try {
|
|
861
875
|
return MongoDBConnector.fromDatabaseConfig({
|
|
862
876
|
id: "id" in config ? config.id : "domain",
|
|
863
877
|
options: config.options,
|
|
864
|
-
url:
|
|
878
|
+
url: connectionString,
|
|
865
879
|
dbName: config.dbName
|
|
866
880
|
});
|
|
867
881
|
} catch (error) {
|
|
@@ -870,7 +884,7 @@ function resolveMongoDBConfig(config) {
|
|
|
870
884
|
id: createStorageErrorId("MONGODB", "CONSTRUCTOR", "FAILED"),
|
|
871
885
|
domain: ErrorDomain.STORAGE,
|
|
872
886
|
category: ErrorCategory.USER,
|
|
873
|
-
details: { url: config?.url, dbName: config?.dbName }
|
|
887
|
+
details: { uri: config?.uri ?? "", url: config?.url ?? "", dbName: config?.dbName ?? "" }
|
|
874
888
|
},
|
|
875
889
|
error
|
|
876
890
|
);
|
|
@@ -1671,25 +1685,48 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends MemoryStorage {
|
|
|
1671
1685
|
);
|
|
1672
1686
|
}
|
|
1673
1687
|
}
|
|
1674
|
-
async
|
|
1688
|
+
async listThreads(args) {
|
|
1689
|
+
const { page = 0, perPage: perPageInput, orderBy, filter } = args;
|
|
1690
|
+
try {
|
|
1691
|
+
this.validatePaginationInput(page, perPageInput ?? 100);
|
|
1692
|
+
} catch (error) {
|
|
1693
|
+
throw new MastraError(
|
|
1694
|
+
{
|
|
1695
|
+
id: createStorageErrorId("MONGODB", "LIST_THREADS", "INVALID_PAGE"),
|
|
1696
|
+
domain: ErrorDomain.STORAGE,
|
|
1697
|
+
category: ErrorCategory.USER,
|
|
1698
|
+
details: { page, ...perPageInput !== void 0 && { perPage: perPageInput } }
|
|
1699
|
+
},
|
|
1700
|
+
error instanceof Error ? error : new Error("Invalid pagination parameters")
|
|
1701
|
+
);
|
|
1702
|
+
}
|
|
1703
|
+
const perPage = normalizePerPage(perPageInput, 100);
|
|
1704
|
+
try {
|
|
1705
|
+
this.validateMetadataKeys(filter?.metadata);
|
|
1706
|
+
} catch (error) {
|
|
1707
|
+
throw new MastraError(
|
|
1708
|
+
{
|
|
1709
|
+
id: createStorageErrorId("MONGODB", "LIST_THREADS", "INVALID_METADATA_KEY"),
|
|
1710
|
+
domain: ErrorDomain.STORAGE,
|
|
1711
|
+
category: ErrorCategory.USER,
|
|
1712
|
+
details: { metadataKeys: filter?.metadata ? Object.keys(filter.metadata).join(", ") : "" }
|
|
1713
|
+
},
|
|
1714
|
+
error instanceof Error ? error : new Error("Invalid metadata key")
|
|
1715
|
+
);
|
|
1716
|
+
}
|
|
1675
1717
|
try {
|
|
1676
|
-
const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
|
|
1677
|
-
if (page < 0) {
|
|
1678
|
-
throw new MastraError(
|
|
1679
|
-
{
|
|
1680
|
-
id: createStorageErrorId("MONGODB", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
|
|
1681
|
-
domain: ErrorDomain.STORAGE,
|
|
1682
|
-
category: ErrorCategory.USER,
|
|
1683
|
-
details: { page }
|
|
1684
|
-
},
|
|
1685
|
-
new Error("page must be >= 0")
|
|
1686
|
-
);
|
|
1687
|
-
}
|
|
1688
|
-
const perPage = normalizePerPage(perPageInput, 100);
|
|
1689
1718
|
const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
|
|
1690
1719
|
const { field, direction } = this.parseOrderBy(orderBy);
|
|
1691
1720
|
const collection = await this.getCollection(TABLE_THREADS);
|
|
1692
|
-
const query = {
|
|
1721
|
+
const query = {};
|
|
1722
|
+
if (filter?.resourceId) {
|
|
1723
|
+
query.resourceId = filter.resourceId;
|
|
1724
|
+
}
|
|
1725
|
+
if (filter?.metadata && Object.keys(filter.metadata).length > 0) {
|
|
1726
|
+
for (const [key, value] of Object.entries(filter.metadata)) {
|
|
1727
|
+
query[`metadata.${key}`] = value;
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1693
1730
|
const total = await collection.countDocuments(query);
|
|
1694
1731
|
if (perPage === 0) {
|
|
1695
1732
|
return {
|
|
@@ -1723,10 +1760,13 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends MemoryStorage {
|
|
|
1723
1760
|
} catch (error) {
|
|
1724
1761
|
throw new MastraError(
|
|
1725
1762
|
{
|
|
1726
|
-
id: createStorageErrorId("MONGODB", "
|
|
1763
|
+
id: createStorageErrorId("MONGODB", "LIST_THREADS", "FAILED"),
|
|
1727
1764
|
domain: ErrorDomain.STORAGE,
|
|
1728
1765
|
category: ErrorCategory.THIRD_PARTY,
|
|
1729
|
-
details: {
|
|
1766
|
+
details: {
|
|
1767
|
+
...filter?.resourceId && { resourceId: filter.resourceId },
|
|
1768
|
+
hasMetadataFilter: !!filter?.metadata
|
|
1769
|
+
}
|
|
1730
1770
|
},
|
|
1731
1771
|
error
|
|
1732
1772
|
);
|
|
@@ -2581,7 +2621,7 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends ScoresStorage {
|
|
|
2581
2621
|
};
|
|
2582
2622
|
}
|
|
2583
2623
|
const end = perPageInput === false ? total : start + perPage;
|
|
2584
|
-
let cursor = collection.find(query).sort({ createdAt:
|
|
2624
|
+
let cursor = collection.find(query).sort({ createdAt: -1 }).skip(start);
|
|
2585
2625
|
if (perPageInput !== false) {
|
|
2586
2626
|
cursor = cursor.limit(perPage);
|
|
2587
2627
|
}
|
|
@@ -2630,7 +2670,7 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends ScoresStorage {
|
|
|
2630
2670
|
};
|
|
2631
2671
|
}
|
|
2632
2672
|
const end = perPageInput === false ? total : start + perPage;
|
|
2633
|
-
let cursor = collection.find({ runId }).sort({ createdAt:
|
|
2673
|
+
let cursor = collection.find({ runId }).sort({ createdAt: -1 }).skip(start);
|
|
2634
2674
|
if (perPageInput !== false) {
|
|
2635
2675
|
cursor = cursor.limit(perPage);
|
|
2636
2676
|
}
|
|
@@ -2680,7 +2720,7 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends ScoresStorage {
|
|
|
2680
2720
|
};
|
|
2681
2721
|
}
|
|
2682
2722
|
const end = perPageInput === false ? total : start + perPage;
|
|
2683
|
-
let cursor = collection.find({ entityId, entityType }).sort({ createdAt:
|
|
2723
|
+
let cursor = collection.find({ entityId, entityType }).sort({ createdAt: -1 }).skip(start);
|
|
2684
2724
|
if (perPageInput !== false) {
|
|
2685
2725
|
cursor = cursor.limit(perPage);
|
|
2686
2726
|
}
|
|
@@ -2731,7 +2771,7 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends ScoresStorage {
|
|
|
2731
2771
|
};
|
|
2732
2772
|
}
|
|
2733
2773
|
const end = perPageInput === false ? total : start + perPage;
|
|
2734
|
-
let cursor = collection.find(query).sort({ createdAt:
|
|
2774
|
+
let cursor = collection.find(query).sort({ createdAt: -1 }).skip(start);
|
|
2735
2775
|
if (perPageInput !== false) {
|
|
2736
2776
|
cursor = cursor.limit(perPage);
|
|
2737
2777
|
}
|
|
@@ -3024,7 +3064,7 @@ var WorkflowsStorageMongoDB = class _WorkflowsStorageMongoDB extends WorkflowsSt
|
|
|
3024
3064
|
try {
|
|
3025
3065
|
parsedSnapshot = typeof row.snapshot === "string" ? safelyParseJSON(row.snapshot) : row.snapshot;
|
|
3026
3066
|
} catch (e) {
|
|
3027
|
-
|
|
3067
|
+
this.logger.warn(`Failed to parse snapshot for workflow ${row.workflow_name}: ${e}`);
|
|
3028
3068
|
}
|
|
3029
3069
|
}
|
|
3030
3070
|
return {
|