@mastra/mongodb 1.0.0-beta.2 → 1.0.0-beta.4
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 +56 -0
- package/dist/index.cjs +118 -214
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +118 -214
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/dist/storage/domains/operations/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/utils.d.ts +5 -0
- package/dist/storage/domains/utils.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/types.d.ts +28 -4
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
2
|
+
import { createVectorErrorId, MastraStorage, createStorageErrorId, StoreOperations, TABLE_SCHEMAS, safelyParseJSON, MemoryStorage, TABLE_MESSAGES, normalizePerPage, calculatePagination, TABLE_THREADS, TABLE_RESOURCES, ScoresStorage, TABLE_SCORERS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, ObservabilityStorage, TABLE_SPANS, transformScoreRow as transformScoreRow$1 } from '@mastra/core/storage';
|
|
2
3
|
import { MastraVector } from '@mastra/core/vector';
|
|
3
4
|
import { MongoClient } from 'mongodb';
|
|
4
5
|
import { v4 } from 'uuid';
|
|
5
6
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
6
|
-
import { MastraStorage, StoreOperations, TABLE_SCHEMAS, safelyParseJSON, MemoryStorage, TABLE_MESSAGES, normalizePerPage, calculatePagination, TABLE_THREADS, TABLE_RESOURCES, ScoresStorage, TABLE_SCORERS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, ObservabilityStorage, TABLE_SPANS } from '@mastra/core/storage';
|
|
7
7
|
import { MessageList } from '@mastra/core/agent';
|
|
8
8
|
import { saveScorePayloadSchema } from '@mastra/core/evals';
|
|
9
9
|
|
|
@@ -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.4"};
|
|
15
15
|
var MongoDBFilterTranslator = class extends BaseFilterTranslator {
|
|
16
16
|
getSupportedOperators() {
|
|
17
17
|
return {
|
|
@@ -134,7 +134,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
134
134
|
} catch (error) {
|
|
135
135
|
throw new MastraError(
|
|
136
136
|
{
|
|
137
|
-
id: "
|
|
137
|
+
id: createVectorErrorId("MONGODB", "CONNECT", "FAILED"),
|
|
138
138
|
domain: ErrorDomain.STORAGE,
|
|
139
139
|
category: ErrorCategory.THIRD_PARTY
|
|
140
140
|
},
|
|
@@ -148,7 +148,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
148
148
|
} catch (error) {
|
|
149
149
|
throw new MastraError(
|
|
150
150
|
{
|
|
151
|
-
id: "
|
|
151
|
+
id: createVectorErrorId("MONGODB", "DISCONNECT", "FAILED"),
|
|
152
152
|
domain: ErrorDomain.STORAGE,
|
|
153
153
|
category: ErrorCategory.THIRD_PARTY
|
|
154
154
|
},
|
|
@@ -169,7 +169,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
169
169
|
} catch (error) {
|
|
170
170
|
throw new MastraError(
|
|
171
171
|
{
|
|
172
|
-
id: "
|
|
172
|
+
id: createVectorErrorId("MONGODB", "CREATE_INDEX", "INVALID_ARGS"),
|
|
173
173
|
domain: ErrorDomain.STORAGE,
|
|
174
174
|
category: ErrorCategory.USER,
|
|
175
175
|
details: {
|
|
@@ -222,7 +222,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
222
222
|
if (error.codeName !== "IndexAlreadyExists") {
|
|
223
223
|
throw new MastraError(
|
|
224
224
|
{
|
|
225
|
-
id: "
|
|
225
|
+
id: createVectorErrorId("MONGODB", "CREATE_INDEX", "FAILED"),
|
|
226
226
|
domain: ErrorDomain.STORAGE,
|
|
227
227
|
category: ErrorCategory.THIRD_PARTY
|
|
228
228
|
},
|
|
@@ -235,7 +235,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
235
235
|
} catch (error) {
|
|
236
236
|
throw new MastraError(
|
|
237
237
|
{
|
|
238
|
-
id: "
|
|
238
|
+
id: createVectorErrorId("MONGODB", "CREATE_INDEX", "STORE_METADATA_FAILED"),
|
|
239
239
|
domain: ErrorDomain.STORAGE,
|
|
240
240
|
category: ErrorCategory.THIRD_PARTY,
|
|
241
241
|
details: {
|
|
@@ -312,7 +312,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
312
312
|
} catch (error) {
|
|
313
313
|
throw new MastraError(
|
|
314
314
|
{
|
|
315
|
-
id: "
|
|
315
|
+
id: createVectorErrorId("MONGODB", "UPSERT", "FAILED"),
|
|
316
316
|
domain: ErrorDomain.STORAGE,
|
|
317
317
|
category: ErrorCategory.THIRD_PARTY,
|
|
318
318
|
details: {
|
|
@@ -393,7 +393,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
393
393
|
} catch (error) {
|
|
394
394
|
throw new MastraError(
|
|
395
395
|
{
|
|
396
|
-
id: "
|
|
396
|
+
id: createVectorErrorId("MONGODB", "QUERY", "FAILED"),
|
|
397
397
|
domain: ErrorDomain.STORAGE,
|
|
398
398
|
category: ErrorCategory.THIRD_PARTY,
|
|
399
399
|
details: {
|
|
@@ -411,7 +411,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
411
411
|
} catch (error) {
|
|
412
412
|
throw new MastraError(
|
|
413
413
|
{
|
|
414
|
-
id: "
|
|
414
|
+
id: createVectorErrorId("MONGODB", "LIST_INDEXES", "FAILED"),
|
|
415
415
|
domain: ErrorDomain.STORAGE,
|
|
416
416
|
category: ErrorCategory.THIRD_PARTY
|
|
417
417
|
},
|
|
@@ -440,7 +440,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
440
440
|
} catch (error) {
|
|
441
441
|
throw new MastraError(
|
|
442
442
|
{
|
|
443
|
-
id: "
|
|
443
|
+
id: createVectorErrorId("MONGODB", "DESCRIBE_INDEX", "FAILED"),
|
|
444
444
|
domain: ErrorDomain.STORAGE,
|
|
445
445
|
category: ErrorCategory.THIRD_PARTY,
|
|
446
446
|
details: {
|
|
@@ -463,7 +463,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
463
463
|
} catch (error) {
|
|
464
464
|
throw new MastraError(
|
|
465
465
|
{
|
|
466
|
-
id: "
|
|
466
|
+
id: createVectorErrorId("MONGODB", "DELETE_INDEX", "FAILED"),
|
|
467
467
|
domain: ErrorDomain.STORAGE,
|
|
468
468
|
category: ErrorCategory.THIRD_PARTY,
|
|
469
469
|
details: {
|
|
@@ -488,7 +488,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
488
488
|
const { indexName, update } = params;
|
|
489
489
|
if ("id" in params && params.id && "filter" in params && params.filter) {
|
|
490
490
|
throw new MastraError({
|
|
491
|
-
id: "
|
|
491
|
+
id: createVectorErrorId("MONGODB", "UPDATE_VECTOR", "MUTUALLY_EXCLUSIVE"),
|
|
492
492
|
domain: ErrorDomain.STORAGE,
|
|
493
493
|
category: ErrorCategory.USER,
|
|
494
494
|
details: { indexName },
|
|
@@ -497,7 +497,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
497
497
|
}
|
|
498
498
|
if (!("id" in params || "filter" in params) || !params.id && !params.filter) {
|
|
499
499
|
throw new MastraError({
|
|
500
|
-
id: "
|
|
500
|
+
id: createVectorErrorId("MONGODB", "UPDATE_VECTOR", "NO_TARGET"),
|
|
501
501
|
domain: ErrorDomain.STORAGE,
|
|
502
502
|
category: ErrorCategory.USER,
|
|
503
503
|
text: "Either id or filter must be provided",
|
|
@@ -531,7 +531,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
531
531
|
const filter = params.filter;
|
|
532
532
|
if (!filter || Object.keys(filter).length === 0) {
|
|
533
533
|
throw new MastraError({
|
|
534
|
-
id: "
|
|
534
|
+
id: createVectorErrorId("MONGODB", "UPDATE_VECTOR", "EMPTY_FILTER"),
|
|
535
535
|
domain: ErrorDomain.STORAGE,
|
|
536
536
|
category: ErrorCategory.USER,
|
|
537
537
|
details: { indexName },
|
|
@@ -542,7 +542,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
542
542
|
const transformedFilter = this.transformMetadataFilter(mongoFilter);
|
|
543
543
|
if (!transformedFilter || Object.keys(transformedFilter).length === 0) {
|
|
544
544
|
throw new MastraError({
|
|
545
|
-
id: "
|
|
545
|
+
id: createVectorErrorId("MONGODB", "UPDATE_VECTOR", "INVALID_FILTER"),
|
|
546
546
|
domain: ErrorDomain.STORAGE,
|
|
547
547
|
category: ErrorCategory.USER,
|
|
548
548
|
details: { indexName },
|
|
@@ -564,7 +564,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
564
564
|
}
|
|
565
565
|
throw new MastraError(
|
|
566
566
|
{
|
|
567
|
-
id: "
|
|
567
|
+
id: createVectorErrorId("MONGODB", "UPDATE_VECTOR", "FAILED"),
|
|
568
568
|
domain: ErrorDomain.STORAGE,
|
|
569
569
|
category: ErrorCategory.THIRD_PARTY,
|
|
570
570
|
details: errorDetails
|
|
@@ -587,7 +587,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
587
587
|
} catch (error) {
|
|
588
588
|
throw new MastraError(
|
|
589
589
|
{
|
|
590
|
-
id: "
|
|
590
|
+
id: createVectorErrorId("MONGODB", "DELETE_VECTOR", "FAILED"),
|
|
591
591
|
domain: ErrorDomain.STORAGE,
|
|
592
592
|
category: ErrorCategory.THIRD_PARTY,
|
|
593
593
|
details: {
|
|
@@ -602,7 +602,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
602
602
|
async deleteVectors({ indexName, filter, ids }) {
|
|
603
603
|
if (!filter && !ids) {
|
|
604
604
|
throw new MastraError({
|
|
605
|
-
id: "
|
|
605
|
+
id: createVectorErrorId("MONGODB", "DELETE_VECTORS", "NO_TARGET"),
|
|
606
606
|
domain: ErrorDomain.STORAGE,
|
|
607
607
|
category: ErrorCategory.USER,
|
|
608
608
|
details: { indexName },
|
|
@@ -611,7 +611,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
611
611
|
}
|
|
612
612
|
if (filter && ids) {
|
|
613
613
|
throw new MastraError({
|
|
614
|
-
id: "
|
|
614
|
+
id: createVectorErrorId("MONGODB", "DELETE_VECTORS", "MUTUALLY_EXCLUSIVE"),
|
|
615
615
|
domain: ErrorDomain.STORAGE,
|
|
616
616
|
category: ErrorCategory.USER,
|
|
617
617
|
details: { indexName },
|
|
@@ -623,7 +623,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
623
623
|
if (ids) {
|
|
624
624
|
if (ids.length === 0) {
|
|
625
625
|
throw new MastraError({
|
|
626
|
-
id: "
|
|
626
|
+
id: createVectorErrorId("MONGODB", "DELETE_VECTORS", "EMPTY_IDS"),
|
|
627
627
|
domain: ErrorDomain.STORAGE,
|
|
628
628
|
category: ErrorCategory.USER,
|
|
629
629
|
details: { indexName },
|
|
@@ -634,7 +634,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
634
634
|
} else {
|
|
635
635
|
if (!filter || Object.keys(filter).length === 0) {
|
|
636
636
|
throw new MastraError({
|
|
637
|
-
id: "
|
|
637
|
+
id: createVectorErrorId("MONGODB", "DELETE_VECTORS", "EMPTY_FILTER"),
|
|
638
638
|
domain: ErrorDomain.STORAGE,
|
|
639
639
|
category: ErrorCategory.USER,
|
|
640
640
|
details: { indexName },
|
|
@@ -645,7 +645,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
645
645
|
const transformedFilter = this.transformMetadataFilter(mongoFilter);
|
|
646
646
|
if (!transformedFilter || Object.keys(transformedFilter).length === 0) {
|
|
647
647
|
throw new MastraError({
|
|
648
|
-
id: "
|
|
648
|
+
id: createVectorErrorId("MONGODB", "DELETE_VECTORS", "INVALID_FILTER"),
|
|
649
649
|
domain: ErrorDomain.STORAGE,
|
|
650
650
|
category: ErrorCategory.USER,
|
|
651
651
|
details: { indexName },
|
|
@@ -663,7 +663,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
663
663
|
}
|
|
664
664
|
throw new MastraError(
|
|
665
665
|
{
|
|
666
|
-
id: "
|
|
666
|
+
id: createVectorErrorId("MONGODB", "DELETE_VECTORS", "FAILED"),
|
|
667
667
|
domain: ErrorDomain.STORAGE,
|
|
668
668
|
category: ErrorCategory.THIRD_PARTY,
|
|
669
669
|
details: {
|
|
@@ -836,8 +836,6 @@ var MongoDBConnector = class _MongoDBConnector {
|
|
|
836
836
|
}
|
|
837
837
|
}
|
|
838
838
|
};
|
|
839
|
-
|
|
840
|
-
// src/storage/domains/utils.ts
|
|
841
839
|
function formatDateForMongoDB(date) {
|
|
842
840
|
return typeof date === "string" ? new Date(date) : date;
|
|
843
841
|
}
|
|
@@ -868,18 +866,16 @@ var MemoryStorageMongoDB = class extends MemoryStorage {
|
|
|
868
866
|
if (row.type && row.type !== "v2") result.type = row.type;
|
|
869
867
|
return result;
|
|
870
868
|
}
|
|
871
|
-
async _getIncludedMessages({
|
|
872
|
-
|
|
873
|
-
include
|
|
874
|
-
}) {
|
|
875
|
-
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
876
|
-
if (!include) return null;
|
|
869
|
+
async _getIncludedMessages({ include }) {
|
|
870
|
+
if (!include || include.length === 0) return null;
|
|
877
871
|
const collection = await this.operations.getCollection(TABLE_MESSAGES);
|
|
878
872
|
const includedMessages = [];
|
|
879
873
|
for (const inc of include) {
|
|
880
874
|
const { id, withPreviousMessages = 0, withNextMessages = 0 } = inc;
|
|
881
|
-
const
|
|
882
|
-
|
|
875
|
+
const targetMessage = await collection.findOne({ id });
|
|
876
|
+
if (!targetMessage) continue;
|
|
877
|
+
const messageThreadId = targetMessage.thread_id;
|
|
878
|
+
const allMessages = await collection.find({ thread_id: messageThreadId }).sort({ createdAt: 1 }).toArray();
|
|
883
879
|
const targetIndex = allMessages.findIndex((msg) => msg.id === id);
|
|
884
880
|
if (targetIndex === -1) continue;
|
|
885
881
|
const startIndex = Math.max(0, targetIndex - withPreviousMessages);
|
|
@@ -909,7 +905,7 @@ var MemoryStorageMongoDB = class extends MemoryStorage {
|
|
|
909
905
|
} catch (error) {
|
|
910
906
|
throw new MastraError(
|
|
911
907
|
{
|
|
912
|
-
id: "
|
|
908
|
+
id: createStorageErrorId("MONGODB", "LIST_MESSAGES_BY_ID", "FAILED"),
|
|
913
909
|
domain: ErrorDomain.STORAGE,
|
|
914
910
|
category: ErrorCategory.THIRD_PARTY,
|
|
915
911
|
details: { messageIds: JSON.stringify(messageIds) }
|
|
@@ -920,21 +916,22 @@ var MemoryStorageMongoDB = class extends MemoryStorage {
|
|
|
920
916
|
}
|
|
921
917
|
async listMessages(args) {
|
|
922
918
|
const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
|
|
923
|
-
|
|
919
|
+
const threadIds = Array.isArray(threadId) ? threadId : [threadId];
|
|
920
|
+
if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
|
|
924
921
|
throw new MastraError(
|
|
925
922
|
{
|
|
926
|
-
id: "
|
|
923
|
+
id: createStorageErrorId("MONGODB", "LIST_MESSAGES", "INVALID_THREAD_ID"),
|
|
927
924
|
domain: ErrorDomain.STORAGE,
|
|
928
925
|
category: ErrorCategory.THIRD_PARTY,
|
|
929
|
-
details: { threadId }
|
|
926
|
+
details: { threadId: Array.isArray(threadId) ? threadId.join(",") : threadId }
|
|
930
927
|
},
|
|
931
|
-
new Error("threadId must be a non-empty string")
|
|
928
|
+
new Error("threadId must be a non-empty string or array of non-empty strings")
|
|
932
929
|
);
|
|
933
930
|
}
|
|
934
931
|
if (page < 0) {
|
|
935
932
|
throw new MastraError(
|
|
936
933
|
{
|
|
937
|
-
id: "
|
|
934
|
+
id: createStorageErrorId("MONGODB", "LIST_MESSAGES", "INVALID_PAGE"),
|
|
938
935
|
domain: ErrorDomain.STORAGE,
|
|
939
936
|
category: ErrorCategory.USER,
|
|
940
937
|
details: { page }
|
|
@@ -948,7 +945,7 @@ var MemoryStorageMongoDB = class extends MemoryStorage {
|
|
|
948
945
|
const { field, direction } = this.parseOrderBy(orderBy, "ASC");
|
|
949
946
|
const sortOrder = direction === "ASC" ? 1 : -1;
|
|
950
947
|
const collection = await this.operations.getCollection(TABLE_MESSAGES);
|
|
951
|
-
const query = { thread_id:
|
|
948
|
+
const query = { thread_id: threadIds.length === 1 ? threadIds[0] : { $in: threadIds } };
|
|
952
949
|
if (resourceId) {
|
|
953
950
|
query.resourceId = resourceId;
|
|
954
951
|
}
|
|
@@ -980,7 +977,7 @@ var MemoryStorageMongoDB = class extends MemoryStorage {
|
|
|
980
977
|
}
|
|
981
978
|
const messageIds = new Set(messages.map((m) => m.id));
|
|
982
979
|
if (include && include.length > 0) {
|
|
983
|
-
const includeMessages = await this._getIncludedMessages({
|
|
980
|
+
const includeMessages = await this._getIncludedMessages({ include });
|
|
984
981
|
if (includeMessages) {
|
|
985
982
|
for (const includeMsg of includeMessages) {
|
|
986
983
|
if (!messageIds.has(includeMsg.id)) {
|
|
@@ -1001,7 +998,10 @@ var MemoryStorageMongoDB = class extends MemoryStorage {
|
|
|
1001
998
|
}
|
|
1002
999
|
return direction === "ASC" ? String(aValue).localeCompare(String(bValue)) : String(bValue).localeCompare(String(aValue));
|
|
1003
1000
|
});
|
|
1004
|
-
const
|
|
1001
|
+
const threadIdSet = new Set(threadIds);
|
|
1002
|
+
const returnedThreadMessageIds = new Set(
|
|
1003
|
+
finalMessages.filter((m) => m.threadId && threadIdSet.has(m.threadId)).map((m) => m.id)
|
|
1004
|
+
);
|
|
1005
1005
|
const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
|
|
1006
1006
|
const hasMore = perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total;
|
|
1007
1007
|
return {
|
|
@@ -1014,11 +1014,11 @@ var MemoryStorageMongoDB = class extends MemoryStorage {
|
|
|
1014
1014
|
} catch (error) {
|
|
1015
1015
|
const mastraError = new MastraError(
|
|
1016
1016
|
{
|
|
1017
|
-
id: "
|
|
1017
|
+
id: createStorageErrorId("MONGODB", "LIST_MESSAGES", "FAILED"),
|
|
1018
1018
|
domain: ErrorDomain.STORAGE,
|
|
1019
1019
|
category: ErrorCategory.THIRD_PARTY,
|
|
1020
1020
|
details: {
|
|
1021
|
-
threadId,
|
|
1021
|
+
threadId: Array.isArray(threadId) ? threadId.join(",") : threadId,
|
|
1022
1022
|
resourceId: resourceId ?? ""
|
|
1023
1023
|
}
|
|
1024
1024
|
},
|
|
@@ -1083,7 +1083,7 @@ var MemoryStorageMongoDB = class extends MemoryStorage {
|
|
|
1083
1083
|
} catch (error) {
|
|
1084
1084
|
throw new MastraError(
|
|
1085
1085
|
{
|
|
1086
|
-
id: "
|
|
1086
|
+
id: createStorageErrorId("MONGODB", "SAVE_MESSAGES", "FAILED"),
|
|
1087
1087
|
domain: ErrorDomain.STORAGE,
|
|
1088
1088
|
category: ErrorCategory.THIRD_PARTY
|
|
1089
1089
|
},
|
|
@@ -1181,7 +1181,7 @@ var MemoryStorageMongoDB = class extends MemoryStorage {
|
|
|
1181
1181
|
} catch (error) {
|
|
1182
1182
|
throw new MastraError(
|
|
1183
1183
|
{
|
|
1184
|
-
id: "
|
|
1184
|
+
id: createStorageErrorId("MONGODB", "GET_RESOURCE_BY_ID", "FAILED"),
|
|
1185
1185
|
domain: ErrorDomain.STORAGE,
|
|
1186
1186
|
category: ErrorCategory.THIRD_PARTY,
|
|
1187
1187
|
details: { resourceId }
|
|
@@ -1207,7 +1207,7 @@ var MemoryStorageMongoDB = class extends MemoryStorage {
|
|
|
1207
1207
|
} catch (error) {
|
|
1208
1208
|
throw new MastraError(
|
|
1209
1209
|
{
|
|
1210
|
-
id: "
|
|
1210
|
+
id: createStorageErrorId("MONGODB", "SAVE_RESOURCE", "FAILED"),
|
|
1211
1211
|
domain: ErrorDomain.STORAGE,
|
|
1212
1212
|
category: ErrorCategory.THIRD_PARTY,
|
|
1213
1213
|
details: { resourceId: resource.id }
|
|
@@ -1252,7 +1252,7 @@ var MemoryStorageMongoDB = class extends MemoryStorage {
|
|
|
1252
1252
|
} catch (error) {
|
|
1253
1253
|
throw new MastraError(
|
|
1254
1254
|
{
|
|
1255
|
-
id: "
|
|
1255
|
+
id: createStorageErrorId("MONGODB", "UPDATE_RESOURCE", "FAILED"),
|
|
1256
1256
|
domain: ErrorDomain.STORAGE,
|
|
1257
1257
|
category: ErrorCategory.THIRD_PARTY,
|
|
1258
1258
|
details: { resourceId }
|
|
@@ -1275,7 +1275,7 @@ var MemoryStorageMongoDB = class extends MemoryStorage {
|
|
|
1275
1275
|
} catch (error) {
|
|
1276
1276
|
throw new MastraError(
|
|
1277
1277
|
{
|
|
1278
|
-
id: "
|
|
1278
|
+
id: createStorageErrorId("MONGODB", "GET_THREAD_BY_ID", "FAILED"),
|
|
1279
1279
|
domain: ErrorDomain.STORAGE,
|
|
1280
1280
|
category: ErrorCategory.THIRD_PARTY,
|
|
1281
1281
|
details: { threadId }
|
|
@@ -1290,7 +1290,7 @@ var MemoryStorageMongoDB = class extends MemoryStorage {
|
|
|
1290
1290
|
if (page < 0) {
|
|
1291
1291
|
throw new MastraError(
|
|
1292
1292
|
{
|
|
1293
|
-
id: "
|
|
1293
|
+
id: createStorageErrorId("MONGODB", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
|
|
1294
1294
|
domain: ErrorDomain.STORAGE,
|
|
1295
1295
|
category: ErrorCategory.USER,
|
|
1296
1296
|
details: { page }
|
|
@@ -1336,7 +1336,7 @@ var MemoryStorageMongoDB = class extends MemoryStorage {
|
|
|
1336
1336
|
} catch (error) {
|
|
1337
1337
|
throw new MastraError(
|
|
1338
1338
|
{
|
|
1339
|
-
id: "
|
|
1339
|
+
id: createStorageErrorId("MONGODB", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
|
|
1340
1340
|
domain: ErrorDomain.STORAGE,
|
|
1341
1341
|
category: ErrorCategory.THIRD_PARTY,
|
|
1342
1342
|
details: { resourceId: args.resourceId }
|
|
@@ -1362,7 +1362,7 @@ var MemoryStorageMongoDB = class extends MemoryStorage {
|
|
|
1362
1362
|
} catch (error) {
|
|
1363
1363
|
throw new MastraError(
|
|
1364
1364
|
{
|
|
1365
|
-
id: "
|
|
1365
|
+
id: createStorageErrorId("MONGODB", "SAVE_THREAD", "FAILED"),
|
|
1366
1366
|
domain: ErrorDomain.STORAGE,
|
|
1367
1367
|
category: ErrorCategory.THIRD_PARTY,
|
|
1368
1368
|
details: { threadId: thread.id }
|
|
@@ -1379,7 +1379,7 @@ var MemoryStorageMongoDB = class extends MemoryStorage {
|
|
|
1379
1379
|
const thread = await this.getThreadById({ threadId: id });
|
|
1380
1380
|
if (!thread) {
|
|
1381
1381
|
throw new MastraError({
|
|
1382
|
-
id: "
|
|
1382
|
+
id: createStorageErrorId("MONGODB", "UPDATE_THREAD", "NOT_FOUND"),
|
|
1383
1383
|
domain: ErrorDomain.STORAGE,
|
|
1384
1384
|
category: ErrorCategory.THIRD_PARTY,
|
|
1385
1385
|
details: { threadId: id, status: 404 },
|
|
@@ -1408,7 +1408,7 @@ var MemoryStorageMongoDB = class extends MemoryStorage {
|
|
|
1408
1408
|
} catch (error) {
|
|
1409
1409
|
throw new MastraError(
|
|
1410
1410
|
{
|
|
1411
|
-
id: "
|
|
1411
|
+
id: createStorageErrorId("MONGODB", "UPDATE_THREAD", "FAILED"),
|
|
1412
1412
|
domain: ErrorDomain.STORAGE,
|
|
1413
1413
|
category: ErrorCategory.THIRD_PARTY,
|
|
1414
1414
|
details: { threadId: id }
|
|
@@ -1427,7 +1427,7 @@ var MemoryStorageMongoDB = class extends MemoryStorage {
|
|
|
1427
1427
|
} catch (error) {
|
|
1428
1428
|
throw new MastraError(
|
|
1429
1429
|
{
|
|
1430
|
-
id: "
|
|
1430
|
+
id: createStorageErrorId("MONGODB", "DELETE_THREAD", "FAILED"),
|
|
1431
1431
|
domain: ErrorDomain.STORAGE,
|
|
1432
1432
|
category: ErrorCategory.THIRD_PARTY,
|
|
1433
1433
|
details: { threadId }
|
|
@@ -1464,7 +1464,7 @@ var ObservabilityMongoDB = class extends ObservabilityStorage {
|
|
|
1464
1464
|
} catch (error) {
|
|
1465
1465
|
throw new MastraError(
|
|
1466
1466
|
{
|
|
1467
|
-
id: "
|
|
1467
|
+
id: createStorageErrorId("MONGODB", "CREATE_SPAN", "FAILED"),
|
|
1468
1468
|
domain: ErrorDomain.STORAGE,
|
|
1469
1469
|
category: ErrorCategory.USER,
|
|
1470
1470
|
details: {
|
|
@@ -1492,7 +1492,7 @@ var ObservabilityMongoDB = class extends ObservabilityStorage {
|
|
|
1492
1492
|
} catch (error) {
|
|
1493
1493
|
throw new MastraError(
|
|
1494
1494
|
{
|
|
1495
|
-
id: "
|
|
1495
|
+
id: createStorageErrorId("MONGODB", "GET_TRACE", "FAILED"),
|
|
1496
1496
|
domain: ErrorDomain.STORAGE,
|
|
1497
1497
|
category: ErrorCategory.USER,
|
|
1498
1498
|
details: {
|
|
@@ -1528,7 +1528,7 @@ var ObservabilityMongoDB = class extends ObservabilityStorage {
|
|
|
1528
1528
|
} catch (error) {
|
|
1529
1529
|
throw new MastraError(
|
|
1530
1530
|
{
|
|
1531
|
-
id: "
|
|
1531
|
+
id: createStorageErrorId("MONGODB", "UPDATE_SPAN", "FAILED"),
|
|
1532
1532
|
domain: ErrorDomain.STORAGE,
|
|
1533
1533
|
category: ErrorCategory.USER,
|
|
1534
1534
|
details: {
|
|
@@ -1574,7 +1574,7 @@ var ObservabilityMongoDB = class extends ObservabilityStorage {
|
|
|
1574
1574
|
name = `agent run: '${entityId}'`;
|
|
1575
1575
|
} else {
|
|
1576
1576
|
const error = new MastraError({
|
|
1577
|
-
id: "
|
|
1577
|
+
id: createStorageErrorId("MONGODB", "GET_TRACES_PAGINATED", "INVALID_ENTITY_TYPE"),
|
|
1578
1578
|
domain: ErrorDomain.STORAGE,
|
|
1579
1579
|
category: ErrorCategory.USER,
|
|
1580
1580
|
details: {
|
|
@@ -1611,7 +1611,7 @@ var ObservabilityMongoDB = class extends ObservabilityStorage {
|
|
|
1611
1611
|
} catch (error) {
|
|
1612
1612
|
throw new MastraError(
|
|
1613
1613
|
{
|
|
1614
|
-
id: "
|
|
1614
|
+
id: createStorageErrorId("MONGODB", "GET_TRACES_PAGINATED", "FAILED"),
|
|
1615
1615
|
domain: ErrorDomain.STORAGE,
|
|
1616
1616
|
category: ErrorCategory.USER
|
|
1617
1617
|
},
|
|
@@ -1639,7 +1639,7 @@ var ObservabilityMongoDB = class extends ObservabilityStorage {
|
|
|
1639
1639
|
} catch (error) {
|
|
1640
1640
|
throw new MastraError(
|
|
1641
1641
|
{
|
|
1642
|
-
id: "
|
|
1642
|
+
id: createStorageErrorId("MONGODB", "BATCH_CREATE_SPANS", "FAILED"),
|
|
1643
1643
|
domain: ErrorDomain.STORAGE,
|
|
1644
1644
|
category: ErrorCategory.USER
|
|
1645
1645
|
},
|
|
@@ -1672,7 +1672,7 @@ var ObservabilityMongoDB = class extends ObservabilityStorage {
|
|
|
1672
1672
|
} catch (error) {
|
|
1673
1673
|
throw new MastraError(
|
|
1674
1674
|
{
|
|
1675
|
-
id: "
|
|
1675
|
+
id: createStorageErrorId("MONGODB", "BATCH_UPDATE_SPANS", "FAILED"),
|
|
1676
1676
|
domain: ErrorDomain.STORAGE,
|
|
1677
1677
|
category: ErrorCategory.USER
|
|
1678
1678
|
},
|
|
@@ -1689,7 +1689,7 @@ var ObservabilityMongoDB = class extends ObservabilityStorage {
|
|
|
1689
1689
|
} catch (error) {
|
|
1690
1690
|
throw new MastraError(
|
|
1691
1691
|
{
|
|
1692
|
-
id: "
|
|
1692
|
+
id: createStorageErrorId("MONGODB", "BATCH_DELETE_TRACES", "FAILED"),
|
|
1693
1693
|
domain: ErrorDomain.STORAGE,
|
|
1694
1694
|
category: ErrorCategory.USER
|
|
1695
1695
|
},
|
|
@@ -1740,7 +1740,7 @@ var StoreOperationsMongoDB = class extends StoreOperations {
|
|
|
1740
1740
|
} catch (error) {
|
|
1741
1741
|
const mastraError = new MastraError(
|
|
1742
1742
|
{
|
|
1743
|
-
id: "
|
|
1743
|
+
id: createStorageErrorId("MONGODB", "CLEAR_TABLE", "FAILED"),
|
|
1744
1744
|
domain: ErrorDomain.STORAGE,
|
|
1745
1745
|
category: ErrorCategory.THIRD_PARTY,
|
|
1746
1746
|
details: { tableName }
|
|
@@ -1762,7 +1762,7 @@ var StoreOperationsMongoDB = class extends StoreOperations {
|
|
|
1762
1762
|
}
|
|
1763
1763
|
throw new MastraError(
|
|
1764
1764
|
{
|
|
1765
|
-
id: "
|
|
1765
|
+
id: createStorageErrorId("MONGODB", "DROP_TABLE", "FAILED"),
|
|
1766
1766
|
domain: ErrorDomain.STORAGE,
|
|
1767
1767
|
category: ErrorCategory.THIRD_PARTY,
|
|
1768
1768
|
details: { tableName }
|
|
@@ -1793,7 +1793,7 @@ var StoreOperationsMongoDB = class extends StoreOperations {
|
|
|
1793
1793
|
} catch (error) {
|
|
1794
1794
|
const mastraError = new MastraError(
|
|
1795
1795
|
{
|
|
1796
|
-
id: "
|
|
1796
|
+
id: createStorageErrorId("MONGODB", "INSERT", "FAILED"),
|
|
1797
1797
|
domain: ErrorDomain.STORAGE,
|
|
1798
1798
|
category: ErrorCategory.THIRD_PARTY,
|
|
1799
1799
|
details: { tableName }
|
|
@@ -1816,7 +1816,7 @@ var StoreOperationsMongoDB = class extends StoreOperations {
|
|
|
1816
1816
|
} catch (error) {
|
|
1817
1817
|
throw new MastraError(
|
|
1818
1818
|
{
|
|
1819
|
-
id: "
|
|
1819
|
+
id: createStorageErrorId("MONGODB", "BATCH_INSERT", "FAILED"),
|
|
1820
1820
|
domain: ErrorDomain.STORAGE,
|
|
1821
1821
|
category: ErrorCategory.THIRD_PARTY,
|
|
1822
1822
|
details: { tableName }
|
|
@@ -1833,7 +1833,7 @@ var StoreOperationsMongoDB = class extends StoreOperations {
|
|
|
1833
1833
|
} catch (error) {
|
|
1834
1834
|
throw new MastraError(
|
|
1835
1835
|
{
|
|
1836
|
-
id: "
|
|
1836
|
+
id: createStorageErrorId("MONGODB", "LOAD", "FAILED"),
|
|
1837
1837
|
domain: ErrorDomain.STORAGE,
|
|
1838
1838
|
category: ErrorCategory.THIRD_PARTY,
|
|
1839
1839
|
details: { tableName }
|
|
@@ -1855,7 +1855,7 @@ var StoreOperationsMongoDB = class extends StoreOperations {
|
|
|
1855
1855
|
} catch (error) {
|
|
1856
1856
|
throw new MastraError(
|
|
1857
1857
|
{
|
|
1858
|
-
id: "
|
|
1858
|
+
id: createStorageErrorId("MONGODB", "UPDATE", "FAILED"),
|
|
1859
1859
|
domain: ErrorDomain.STORAGE,
|
|
1860
1860
|
category: ErrorCategory.THIRD_PARTY,
|
|
1861
1861
|
details: { tableName }
|
|
@@ -1887,7 +1887,7 @@ var StoreOperationsMongoDB = class extends StoreOperations {
|
|
|
1887
1887
|
} catch (error) {
|
|
1888
1888
|
throw new MastraError(
|
|
1889
1889
|
{
|
|
1890
|
-
id: "
|
|
1890
|
+
id: createStorageErrorId("MONGODB", "BATCH_UPDATE", "FAILED"),
|
|
1891
1891
|
domain: ErrorDomain.STORAGE,
|
|
1892
1892
|
category: ErrorCategory.THIRD_PARTY,
|
|
1893
1893
|
details: { tableName }
|
|
@@ -1898,98 +1898,9 @@ var StoreOperationsMongoDB = class extends StoreOperations {
|
|
|
1898
1898
|
}
|
|
1899
1899
|
};
|
|
1900
1900
|
function transformScoreRow(row) {
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
scorerValue = typeof row.scorer === "string" ? safelyParseJSON(row.scorer) : row.scorer;
|
|
1905
|
-
} catch (e) {
|
|
1906
|
-
console.warn("Failed to parse scorer:", e);
|
|
1907
|
-
}
|
|
1908
|
-
}
|
|
1909
|
-
let preprocessStepResultValue = null;
|
|
1910
|
-
if (row.preprocessStepResult) {
|
|
1911
|
-
try {
|
|
1912
|
-
preprocessStepResultValue = typeof row.preprocessStepResult === "string" ? safelyParseJSON(row.preprocessStepResult) : row.preprocessStepResult;
|
|
1913
|
-
} catch (e) {
|
|
1914
|
-
console.warn("Failed to parse preprocessStepResult:", e);
|
|
1915
|
-
}
|
|
1916
|
-
}
|
|
1917
|
-
let analyzeStepResultValue = null;
|
|
1918
|
-
if (row.analyzeStepResult) {
|
|
1919
|
-
try {
|
|
1920
|
-
analyzeStepResultValue = typeof row.analyzeStepResult === "string" ? safelyParseJSON(row.analyzeStepResult) : row.analyzeStepResult;
|
|
1921
|
-
} catch (e) {
|
|
1922
|
-
console.warn("Failed to parse analyzeStepResult:", e);
|
|
1923
|
-
}
|
|
1924
|
-
}
|
|
1925
|
-
let inputValue = null;
|
|
1926
|
-
if (row.input) {
|
|
1927
|
-
try {
|
|
1928
|
-
inputValue = typeof row.input === "string" ? safelyParseJSON(row.input) : row.input;
|
|
1929
|
-
} catch (e) {
|
|
1930
|
-
console.warn("Failed to parse input:", e);
|
|
1931
|
-
}
|
|
1932
|
-
}
|
|
1933
|
-
let outputValue = null;
|
|
1934
|
-
if (row.output) {
|
|
1935
|
-
try {
|
|
1936
|
-
outputValue = typeof row.output === "string" ? safelyParseJSON(row.output) : row.output;
|
|
1937
|
-
} catch (e) {
|
|
1938
|
-
console.warn("Failed to parse output:", e);
|
|
1939
|
-
}
|
|
1940
|
-
}
|
|
1941
|
-
let entityValue = null;
|
|
1942
|
-
if (row.entity) {
|
|
1943
|
-
try {
|
|
1944
|
-
entityValue = typeof row.entity === "string" ? safelyParseJSON(row.entity) : row.entity;
|
|
1945
|
-
} catch (e) {
|
|
1946
|
-
console.warn("Failed to parse entity:", e);
|
|
1947
|
-
}
|
|
1948
|
-
}
|
|
1949
|
-
let requestContextValue = null;
|
|
1950
|
-
if (row.requestContext) {
|
|
1951
|
-
try {
|
|
1952
|
-
requestContextValue = typeof row.requestContext === "string" ? safelyParseJSON(row.requestContext) : row.requestContext;
|
|
1953
|
-
} catch (e) {
|
|
1954
|
-
console.warn("Failed to parse requestContext:", e);
|
|
1955
|
-
}
|
|
1956
|
-
}
|
|
1957
|
-
let metadataValue = null;
|
|
1958
|
-
if (row.metadata) {
|
|
1959
|
-
try {
|
|
1960
|
-
metadataValue = typeof row.metadata === "string" ? safelyParseJSON(row.metadata) : row.metadata;
|
|
1961
|
-
} catch (e) {
|
|
1962
|
-
console.warn("Failed to parse metadata:", e);
|
|
1963
|
-
}
|
|
1964
|
-
}
|
|
1965
|
-
return {
|
|
1966
|
-
id: row.id,
|
|
1967
|
-
entityId: row.entityId,
|
|
1968
|
-
entityType: row.entityType,
|
|
1969
|
-
scorerId: row.scorerId,
|
|
1970
|
-
traceId: row.traceId,
|
|
1971
|
-
spanId: row.spanId,
|
|
1972
|
-
runId: row.runId,
|
|
1973
|
-
scorer: scorerValue,
|
|
1974
|
-
preprocessStepResult: preprocessStepResultValue,
|
|
1975
|
-
preprocessPrompt: row.preprocessPrompt,
|
|
1976
|
-
analyzeStepResult: analyzeStepResultValue,
|
|
1977
|
-
generateScorePrompt: row.generateScorePrompt,
|
|
1978
|
-
score: row.score,
|
|
1979
|
-
analyzePrompt: row.analyzePrompt,
|
|
1980
|
-
reasonPrompt: row.reasonPrompt,
|
|
1981
|
-
metadata: metadataValue,
|
|
1982
|
-
input: inputValue,
|
|
1983
|
-
output: outputValue,
|
|
1984
|
-
additionalContext: row.additionalContext,
|
|
1985
|
-
requestContext: requestContextValue,
|
|
1986
|
-
entity: entityValue,
|
|
1987
|
-
source: row.source,
|
|
1988
|
-
resourceId: row.resourceId,
|
|
1989
|
-
threadId: row.threadId,
|
|
1990
|
-
createdAt: new Date(row.createdAt),
|
|
1991
|
-
updatedAt: new Date(row.updatedAt)
|
|
1992
|
-
};
|
|
1901
|
+
return transformScoreRow$1(row, {
|
|
1902
|
+
convertTimestamps: true
|
|
1903
|
+
});
|
|
1993
1904
|
}
|
|
1994
1905
|
var ScoresStorageMongoDB = class extends ScoresStorage {
|
|
1995
1906
|
operations;
|
|
@@ -2008,7 +1919,7 @@ var ScoresStorageMongoDB = class extends ScoresStorage {
|
|
|
2008
1919
|
} catch (error) {
|
|
2009
1920
|
throw new MastraError(
|
|
2010
1921
|
{
|
|
2011
|
-
id: "
|
|
1922
|
+
id: createStorageErrorId("MONGODB", "GET_SCORE_BY_ID", "FAILED"),
|
|
2012
1923
|
domain: ErrorDomain.STORAGE,
|
|
2013
1924
|
category: ErrorCategory.THIRD_PARTY,
|
|
2014
1925
|
details: { id }
|
|
@@ -2024,7 +1935,7 @@ var ScoresStorageMongoDB = class extends ScoresStorage {
|
|
|
2024
1935
|
} catch (error) {
|
|
2025
1936
|
throw new MastraError(
|
|
2026
1937
|
{
|
|
2027
|
-
id: "
|
|
1938
|
+
id: createStorageErrorId("MONGODB", "SAVE_SCORE", "VALIDATION_FAILED"),
|
|
2028
1939
|
domain: ErrorDomain.STORAGE,
|
|
2029
1940
|
category: ErrorCategory.THIRD_PARTY
|
|
2030
1941
|
},
|
|
@@ -2034,36 +1945,29 @@ var ScoresStorageMongoDB = class extends ScoresStorage {
|
|
|
2034
1945
|
try {
|
|
2035
1946
|
const now = /* @__PURE__ */ new Date();
|
|
2036
1947
|
const scoreId = `score-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
2037
|
-
const
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
requestContext: typeof validatedScore.requestContext === "string" ? safelyParseJSON(validatedScore.requestContext) : validatedScore.requestContext,
|
|
2058
|
-
entity: typeof validatedScore.entity === "string" ? safelyParseJSON(validatedScore.entity) : validatedScore.entity,
|
|
2059
|
-
source: validatedScore.source,
|
|
2060
|
-
resourceId: validatedScore.resourceId || "",
|
|
2061
|
-
threadId: validatedScore.threadId || "",
|
|
2062
|
-
createdAt: now,
|
|
2063
|
-
updatedAt: now
|
|
1948
|
+
const scorer = typeof validatedScore.scorer === "string" ? safelyParseJSON(validatedScore.scorer) : validatedScore.scorer;
|
|
1949
|
+
const preprocessStepResult = typeof validatedScore.preprocessStepResult === "string" ? safelyParseJSON(validatedScore.preprocessStepResult) : validatedScore.preprocessStepResult;
|
|
1950
|
+
const analyzeStepResult = typeof validatedScore.analyzeStepResult === "string" ? safelyParseJSON(validatedScore.analyzeStepResult) : validatedScore.analyzeStepResult;
|
|
1951
|
+
const input = typeof validatedScore.input === "string" ? safelyParseJSON(validatedScore.input) : validatedScore.input;
|
|
1952
|
+
const output = typeof validatedScore.output === "string" ? safelyParseJSON(validatedScore.output) : validatedScore.output;
|
|
1953
|
+
const requestContext = typeof validatedScore.requestContext === "string" ? safelyParseJSON(validatedScore.requestContext) : validatedScore.requestContext;
|
|
1954
|
+
const entity = typeof validatedScore.entity === "string" ? safelyParseJSON(validatedScore.entity) : validatedScore.entity;
|
|
1955
|
+
const createdAt = now;
|
|
1956
|
+
const updatedAt = now;
|
|
1957
|
+
const dataToSave = {
|
|
1958
|
+
...validatedScore,
|
|
1959
|
+
scorer,
|
|
1960
|
+
preprocessStepResult,
|
|
1961
|
+
analyzeStepResult,
|
|
1962
|
+
input,
|
|
1963
|
+
output,
|
|
1964
|
+
requestContext,
|
|
1965
|
+
entity,
|
|
1966
|
+
createdAt,
|
|
1967
|
+
updatedAt
|
|
2064
1968
|
};
|
|
2065
1969
|
const collection = await this.operations.getCollection(TABLE_SCORERS);
|
|
2066
|
-
await collection.insertOne(
|
|
1970
|
+
await collection.insertOne(dataToSave);
|
|
2067
1971
|
const savedScore = {
|
|
2068
1972
|
...score,
|
|
2069
1973
|
id: scoreId,
|
|
@@ -2074,7 +1978,7 @@ var ScoresStorageMongoDB = class extends ScoresStorage {
|
|
|
2074
1978
|
} catch (error) {
|
|
2075
1979
|
throw new MastraError(
|
|
2076
1980
|
{
|
|
2077
|
-
id: "
|
|
1981
|
+
id: createStorageErrorId("MONGODB", "SAVE_SCORE", "FAILED"),
|
|
2078
1982
|
domain: ErrorDomain.STORAGE,
|
|
2079
1983
|
category: ErrorCategory.THIRD_PARTY,
|
|
2080
1984
|
details: { scorerId: score.scorerId, runId: score.runId }
|
|
@@ -2136,7 +2040,7 @@ var ScoresStorageMongoDB = class extends ScoresStorage {
|
|
|
2136
2040
|
} catch (error) {
|
|
2137
2041
|
throw new MastraError(
|
|
2138
2042
|
{
|
|
2139
|
-
id: "
|
|
2043
|
+
id: createStorageErrorId("MONGODB", "LIST_SCORES_BY_SCORER_ID", "FAILED"),
|
|
2140
2044
|
domain: ErrorDomain.STORAGE,
|
|
2141
2045
|
category: ErrorCategory.THIRD_PARTY,
|
|
2142
2046
|
details: { scorerId, page: pagination.page, perPage: pagination.perPage }
|
|
@@ -2185,7 +2089,7 @@ var ScoresStorageMongoDB = class extends ScoresStorage {
|
|
|
2185
2089
|
} catch (error) {
|
|
2186
2090
|
throw new MastraError(
|
|
2187
2091
|
{
|
|
2188
|
-
id: "
|
|
2092
|
+
id: createStorageErrorId("MONGODB", "LIST_SCORES_BY_RUN_ID", "FAILED"),
|
|
2189
2093
|
domain: ErrorDomain.STORAGE,
|
|
2190
2094
|
category: ErrorCategory.THIRD_PARTY,
|
|
2191
2095
|
details: { runId, page: pagination.page, perPage: pagination.perPage }
|
|
@@ -2235,7 +2139,7 @@ var ScoresStorageMongoDB = class extends ScoresStorage {
|
|
|
2235
2139
|
} catch (error) {
|
|
2236
2140
|
throw new MastraError(
|
|
2237
2141
|
{
|
|
2238
|
-
id: "
|
|
2142
|
+
id: createStorageErrorId("MONGODB", "LIST_SCORES_BY_ENTITY_ID", "FAILED"),
|
|
2239
2143
|
domain: ErrorDomain.STORAGE,
|
|
2240
2144
|
category: ErrorCategory.THIRD_PARTY,
|
|
2241
2145
|
details: { entityId, entityType, page: pagination.page, perPage: pagination.perPage }
|
|
@@ -2286,7 +2190,7 @@ var ScoresStorageMongoDB = class extends ScoresStorage {
|
|
|
2286
2190
|
} catch (error) {
|
|
2287
2191
|
throw new MastraError(
|
|
2288
2192
|
{
|
|
2289
|
-
id: "
|
|
2193
|
+
id: createStorageErrorId("MONGODB", "LIST_SCORES_BY_SPAN", "FAILED"),
|
|
2290
2194
|
domain: ErrorDomain.STORAGE,
|
|
2291
2195
|
category: ErrorCategory.THIRD_PARTY,
|
|
2292
2196
|
details: { traceId, spanId, page: pagination.page, perPage: pagination.perPage }
|
|
@@ -2343,7 +2247,7 @@ var WorkflowsStorageMongoDB = class extends WorkflowsStorage {
|
|
|
2343
2247
|
} catch (error) {
|
|
2344
2248
|
throw new MastraError(
|
|
2345
2249
|
{
|
|
2346
|
-
id: "
|
|
2250
|
+
id: createStorageErrorId("MONGODB", "PERSIST_WORKFLOW_SNAPSHOT", "FAILED"),
|
|
2347
2251
|
domain: ErrorDomain.STORAGE,
|
|
2348
2252
|
category: ErrorCategory.THIRD_PARTY,
|
|
2349
2253
|
details: { workflowName, runId }
|
|
@@ -2371,7 +2275,7 @@ var WorkflowsStorageMongoDB = class extends WorkflowsStorage {
|
|
|
2371
2275
|
} catch (error) {
|
|
2372
2276
|
throw new MastraError(
|
|
2373
2277
|
{
|
|
2374
|
-
id: "
|
|
2278
|
+
id: createStorageErrorId("MONGODB", "LOAD_WORKFLOW_SNAPSHOT", "FAILED"),
|
|
2375
2279
|
domain: ErrorDomain.STORAGE,
|
|
2376
2280
|
category: ErrorCategory.THIRD_PARTY,
|
|
2377
2281
|
details: { workflowName, runId }
|
|
@@ -2410,7 +2314,7 @@ var WorkflowsStorageMongoDB = class extends WorkflowsStorage {
|
|
|
2410
2314
|
if (options.page < 0) {
|
|
2411
2315
|
throw new MastraError(
|
|
2412
2316
|
{
|
|
2413
|
-
id: "
|
|
2317
|
+
id: createStorageErrorId("MONGODB", "LIST_WORKFLOW_RUNS", "INVALID_PAGE"),
|
|
2414
2318
|
domain: ErrorDomain.STORAGE,
|
|
2415
2319
|
category: ErrorCategory.USER,
|
|
2416
2320
|
details: { page: options.page }
|
|
@@ -2436,7 +2340,7 @@ var WorkflowsStorageMongoDB = class extends WorkflowsStorage {
|
|
|
2436
2340
|
} catch (error) {
|
|
2437
2341
|
throw new MastraError(
|
|
2438
2342
|
{
|
|
2439
|
-
id: "
|
|
2343
|
+
id: createStorageErrorId("MONGODB", "LIST_WORKFLOW_RUNS", "FAILED"),
|
|
2440
2344
|
domain: ErrorDomain.STORAGE,
|
|
2441
2345
|
category: ErrorCategory.THIRD_PARTY,
|
|
2442
2346
|
details: { workflowName: options.workflowName || "unknown" }
|
|
@@ -2463,7 +2367,7 @@ var WorkflowsStorageMongoDB = class extends WorkflowsStorage {
|
|
|
2463
2367
|
} catch (error) {
|
|
2464
2368
|
throw new MastraError(
|
|
2465
2369
|
{
|
|
2466
|
-
id: "
|
|
2370
|
+
id: createStorageErrorId("MONGODB", "GET_WORKFLOW_RUN_BY_ID", "FAILED"),
|
|
2467
2371
|
domain: ErrorDomain.STORAGE,
|
|
2468
2372
|
category: ErrorCategory.THIRD_PARTY,
|
|
2469
2373
|
details: { runId: args.runId }
|
|
@@ -2501,7 +2405,7 @@ var loadConnector = (config) => {
|
|
|
2501
2405
|
} catch (error) {
|
|
2502
2406
|
throw new MastraError(
|
|
2503
2407
|
{
|
|
2504
|
-
id: "
|
|
2408
|
+
id: createStorageErrorId("MONGODB", "CONSTRUCTOR", "FAILED"),
|
|
2505
2409
|
domain: ErrorDomain.STORAGE,
|
|
2506
2410
|
category: ErrorCategory.USER,
|
|
2507
2411
|
details: { connectionHandler: true }
|
|
@@ -2519,7 +2423,7 @@ var loadConnector = (config) => {
|
|
|
2519
2423
|
} catch (error) {
|
|
2520
2424
|
throw new MastraError(
|
|
2521
2425
|
{
|
|
2522
|
-
id: "
|
|
2426
|
+
id: createStorageErrorId("MONGODB", "CONSTRUCTOR", "FAILED"),
|
|
2523
2427
|
domain: ErrorDomain.STORAGE,
|
|
2524
2428
|
category: ErrorCategory.USER,
|
|
2525
2429
|
details: { url: config?.url, dbName: config?.dbName }
|
|
@@ -2542,7 +2446,7 @@ var MongoDBStore = class extends MastraStorage {
|
|
|
2542
2446
|
};
|
|
2543
2447
|
}
|
|
2544
2448
|
constructor(config) {
|
|
2545
|
-
super({ id: config.id, name: "MongoDBStore" });
|
|
2449
|
+
super({ id: config.id, name: "MongoDBStore", disableInit: config.disableInit });
|
|
2546
2450
|
this.stores = {};
|
|
2547
2451
|
this.#connector = loadConnector(config);
|
|
2548
2452
|
const operations = new StoreOperationsMongoDB({
|
|
@@ -2662,7 +2566,7 @@ var MongoDBStore = class extends MastraStorage {
|
|
|
2662
2566
|
} catch (error) {
|
|
2663
2567
|
throw new MastraError(
|
|
2664
2568
|
{
|
|
2665
|
-
id: "
|
|
2569
|
+
id: createStorageErrorId("MONGODB", "CLOSE", "FAILED"),
|
|
2666
2570
|
domain: ErrorDomain.STORAGE,
|
|
2667
2571
|
category: ErrorCategory.USER
|
|
2668
2572
|
},
|
|
@@ -2734,7 +2638,7 @@ var MongoDBStore = class extends MastraStorage {
|
|
|
2734
2638
|
async createSpan(span) {
|
|
2735
2639
|
if (!this.stores.observability) {
|
|
2736
2640
|
throw new MastraError({
|
|
2737
|
-
id: "
|
|
2641
|
+
id: createStorageErrorId("MONGODB", "OBSERVABILITY", "NOT_INITIALIZED"),
|
|
2738
2642
|
domain: ErrorDomain.STORAGE,
|
|
2739
2643
|
category: ErrorCategory.SYSTEM,
|
|
2740
2644
|
text: "Observability storage is not initialized"
|
|
@@ -2749,7 +2653,7 @@ var MongoDBStore = class extends MastraStorage {
|
|
|
2749
2653
|
}) {
|
|
2750
2654
|
if (!this.stores.observability) {
|
|
2751
2655
|
throw new MastraError({
|
|
2752
|
-
id: "
|
|
2656
|
+
id: createStorageErrorId("MONGODB", "OBSERVABILITY", "NOT_INITIALIZED"),
|
|
2753
2657
|
domain: ErrorDomain.STORAGE,
|
|
2754
2658
|
category: ErrorCategory.SYSTEM,
|
|
2755
2659
|
text: "Observability storage is not initialized"
|
|
@@ -2760,7 +2664,7 @@ var MongoDBStore = class extends MastraStorage {
|
|
|
2760
2664
|
async getTrace(traceId) {
|
|
2761
2665
|
if (!this.stores.observability) {
|
|
2762
2666
|
throw new MastraError({
|
|
2763
|
-
id: "
|
|
2667
|
+
id: createStorageErrorId("MONGODB", "OBSERVABILITY", "NOT_INITIALIZED"),
|
|
2764
2668
|
domain: ErrorDomain.STORAGE,
|
|
2765
2669
|
category: ErrorCategory.SYSTEM,
|
|
2766
2670
|
text: "Observability storage is not initialized"
|
|
@@ -2771,7 +2675,7 @@ var MongoDBStore = class extends MastraStorage {
|
|
|
2771
2675
|
async getTracesPaginated(args) {
|
|
2772
2676
|
if (!this.stores.observability) {
|
|
2773
2677
|
throw new MastraError({
|
|
2774
|
-
id: "
|
|
2678
|
+
id: createStorageErrorId("MONGODB", "OBSERVABILITY", "NOT_INITIALIZED"),
|
|
2775
2679
|
domain: ErrorDomain.STORAGE,
|
|
2776
2680
|
category: ErrorCategory.SYSTEM,
|
|
2777
2681
|
text: "Observability storage is not initialized"
|
|
@@ -2782,7 +2686,7 @@ var MongoDBStore = class extends MastraStorage {
|
|
|
2782
2686
|
async batchCreateSpans(args) {
|
|
2783
2687
|
if (!this.stores.observability) {
|
|
2784
2688
|
throw new MastraError({
|
|
2785
|
-
id: "
|
|
2689
|
+
id: createStorageErrorId("MONGODB", "OBSERVABILITY", "NOT_INITIALIZED"),
|
|
2786
2690
|
domain: ErrorDomain.STORAGE,
|
|
2787
2691
|
category: ErrorCategory.SYSTEM,
|
|
2788
2692
|
text: "Observability storage is not initialized"
|
|
@@ -2793,7 +2697,7 @@ var MongoDBStore = class extends MastraStorage {
|
|
|
2793
2697
|
async batchUpdateSpans(args) {
|
|
2794
2698
|
if (!this.stores.observability) {
|
|
2795
2699
|
throw new MastraError({
|
|
2796
|
-
id: "
|
|
2700
|
+
id: createStorageErrorId("MONGODB", "OBSERVABILITY", "NOT_INITIALIZED"),
|
|
2797
2701
|
domain: ErrorDomain.STORAGE,
|
|
2798
2702
|
category: ErrorCategory.SYSTEM,
|
|
2799
2703
|
text: "Observability storage is not initialized"
|
|
@@ -2804,7 +2708,7 @@ var MongoDBStore = class extends MastraStorage {
|
|
|
2804
2708
|
async batchDeleteTraces(args) {
|
|
2805
2709
|
if (!this.stores.observability) {
|
|
2806
2710
|
throw new MastraError({
|
|
2807
|
-
id: "
|
|
2711
|
+
id: createStorageErrorId("MONGODB", "OBSERVABILITY", "NOT_INITIALIZED"),
|
|
2808
2712
|
domain: ErrorDomain.STORAGE,
|
|
2809
2713
|
category: ErrorCategory.SYSTEM,
|
|
2810
2714
|
text: "Observability storage is not initialized"
|