@mastra/dynamodb 0.0.0-taofeeqInngest-20250603090617 → 0.0.0-tsconfig-compile-20250703214351
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/dist/_tsup-dts-rollup.d.cts +1160 -0
- package/dist/_tsup-dts-rollup.d.ts +1160 -0
- package/dist/index.cjs +376 -102
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +352 -78
- package/package.json +31 -17
- package/src/storage/index.test.ts +311 -1
- package/src/storage/index.ts +419 -94
package/dist/index.d.cts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DynamoDBClient, DescribeTableCommand } from '@aws-sdk/client-dynamodb';
|
|
2
2
|
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
|
|
3
3
|
import { MessageList } from '@mastra/core/agent';
|
|
4
|
+
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
4
5
|
import { MastraStorage, TABLE_TRACES, TABLE_EVALS, TABLE_WORKFLOW_SNAPSHOT, TABLE_MESSAGES, TABLE_THREADS } from '@mastra/core/storage';
|
|
5
6
|
import { Entity, Service } from 'electrodb';
|
|
6
7
|
|
|
@@ -558,25 +559,39 @@ function getElectroDbService(client, tableName) {
|
|
|
558
559
|
|
|
559
560
|
// src/storage/index.ts
|
|
560
561
|
var DynamoDBStore = class extends MastraStorage {
|
|
562
|
+
tableName;
|
|
563
|
+
client;
|
|
564
|
+
service;
|
|
565
|
+
hasInitialized = null;
|
|
561
566
|
constructor({ name, config }) {
|
|
562
567
|
super({ name });
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
568
|
+
try {
|
|
569
|
+
if (!config.tableName || typeof config.tableName !== "string" || config.tableName.trim() === "") {
|
|
570
|
+
throw new Error("DynamoDBStore: config.tableName must be provided and cannot be empty.");
|
|
571
|
+
}
|
|
572
|
+
if (!/^[a-zA-Z0-9_.-]{3,255}$/.test(config.tableName)) {
|
|
573
|
+
throw new Error(
|
|
574
|
+
`DynamoDBStore: config.tableName "${config.tableName}" contains invalid characters or is not between 3 and 255 characters long.`
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
const dynamoClient = new DynamoDBClient({
|
|
578
|
+
region: config.region || "us-east-1",
|
|
579
|
+
endpoint: config.endpoint,
|
|
580
|
+
credentials: config.credentials
|
|
581
|
+
});
|
|
582
|
+
this.tableName = config.tableName;
|
|
583
|
+
this.client = DynamoDBDocumentClient.from(dynamoClient);
|
|
584
|
+
this.service = getElectroDbService(this.client, this.tableName);
|
|
585
|
+
} catch (error) {
|
|
586
|
+
throw new MastraError(
|
|
587
|
+
{
|
|
588
|
+
id: "STORAGE_DYNAMODB_STORE_CONSTRUCTOR_FAILED",
|
|
589
|
+
domain: ErrorDomain.STORAGE,
|
|
590
|
+
category: ErrorCategory.USER
|
|
591
|
+
},
|
|
592
|
+
error
|
|
570
593
|
);
|
|
571
594
|
}
|
|
572
|
-
const dynamoClient = new DynamoDBClient({
|
|
573
|
-
region: config.region || "us-east-1",
|
|
574
|
-
endpoint: config.endpoint,
|
|
575
|
-
credentials: config.credentials
|
|
576
|
-
});
|
|
577
|
-
this.tableName = config.tableName;
|
|
578
|
-
this.client = DynamoDBDocumentClient.from(dynamoClient);
|
|
579
|
-
this.service = getElectroDbService(this.client, this.tableName);
|
|
580
595
|
}
|
|
581
596
|
/**
|
|
582
597
|
* This method is modified for DynamoDB with ElectroDB single-table design.
|
|
@@ -600,7 +615,15 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
600
615
|
this.logger.debug(`Table ${this.tableName} exists and is accessible`);
|
|
601
616
|
} catch (error) {
|
|
602
617
|
this.logger.error("Error validating table access", { tableName: this.tableName, error });
|
|
603
|
-
throw
|
|
618
|
+
throw new MastraError(
|
|
619
|
+
{
|
|
620
|
+
id: "STORAGE_DYNAMODB_STORE_VALIDATE_TABLE_ACCESS_FAILED",
|
|
621
|
+
domain: ErrorDomain.STORAGE,
|
|
622
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
623
|
+
details: { tableName: this.tableName }
|
|
624
|
+
},
|
|
625
|
+
error
|
|
626
|
+
);
|
|
604
627
|
}
|
|
605
628
|
}
|
|
606
629
|
/**
|
|
@@ -619,7 +642,15 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
619
642
|
if (error.name === "ResourceNotFoundException") {
|
|
620
643
|
return false;
|
|
621
644
|
}
|
|
622
|
-
throw
|
|
645
|
+
throw new MastraError(
|
|
646
|
+
{
|
|
647
|
+
id: "STORAGE_DYNAMODB_STORE_VALIDATE_TABLE_EXISTS_FAILED",
|
|
648
|
+
domain: ErrorDomain.STORAGE,
|
|
649
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
650
|
+
details: { tableName: this.tableName }
|
|
651
|
+
},
|
|
652
|
+
error
|
|
653
|
+
);
|
|
623
654
|
}
|
|
624
655
|
}
|
|
625
656
|
/**
|
|
@@ -634,7 +665,15 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
634
665
|
try {
|
|
635
666
|
await this.hasInitialized;
|
|
636
667
|
} catch (error) {
|
|
637
|
-
throw
|
|
668
|
+
throw new MastraError(
|
|
669
|
+
{
|
|
670
|
+
id: "STORAGE_DYNAMODB_STORE_INIT_FAILED",
|
|
671
|
+
domain: ErrorDomain.STORAGE,
|
|
672
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
673
|
+
details: { tableName: this.tableName }
|
|
674
|
+
},
|
|
675
|
+
error
|
|
676
|
+
);
|
|
638
677
|
}
|
|
639
678
|
}
|
|
640
679
|
/**
|
|
@@ -654,6 +693,25 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
654
693
|
throw err;
|
|
655
694
|
});
|
|
656
695
|
}
|
|
696
|
+
/**
|
|
697
|
+
* Pre-processes a record to ensure Date objects are converted to ISO strings
|
|
698
|
+
* This is necessary because ElectroDB validation happens before setters are applied
|
|
699
|
+
*/
|
|
700
|
+
preprocessRecord(record) {
|
|
701
|
+
const processed = { ...record };
|
|
702
|
+
if (processed.createdAt instanceof Date) {
|
|
703
|
+
processed.createdAt = processed.createdAt.toISOString();
|
|
704
|
+
}
|
|
705
|
+
if (processed.updatedAt instanceof Date) {
|
|
706
|
+
processed.updatedAt = processed.updatedAt.toISOString();
|
|
707
|
+
}
|
|
708
|
+
if (processed.created_at instanceof Date) {
|
|
709
|
+
processed.created_at = processed.created_at.toISOString();
|
|
710
|
+
}
|
|
711
|
+
return processed;
|
|
712
|
+
}
|
|
713
|
+
async alterTable(_args) {
|
|
714
|
+
}
|
|
657
715
|
/**
|
|
658
716
|
* Clear all items from a logical "table" (entity type)
|
|
659
717
|
*/
|
|
@@ -661,7 +719,13 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
661
719
|
this.logger.debug("DynamoDB clearTable called", { tableName });
|
|
662
720
|
const entityName = this.getEntityNameForTable(tableName);
|
|
663
721
|
if (!entityName || !this.service.entities[entityName]) {
|
|
664
|
-
throw new
|
|
722
|
+
throw new MastraError({
|
|
723
|
+
id: "STORAGE_DYNAMODB_STORE_CLEAR_TABLE_INVALID_ARGS",
|
|
724
|
+
domain: ErrorDomain.STORAGE,
|
|
725
|
+
category: ErrorCategory.USER,
|
|
726
|
+
text: "No entity defined for tableName",
|
|
727
|
+
details: { tableName }
|
|
728
|
+
});
|
|
665
729
|
}
|
|
666
730
|
try {
|
|
667
731
|
const result = await this.service.entities[entityName].scan.go({ pages: "all" });
|
|
@@ -709,37 +773,69 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
709
773
|
}
|
|
710
774
|
this.logger.debug(`Successfully cleared all records for ${tableName}`);
|
|
711
775
|
} catch (error) {
|
|
712
|
-
|
|
713
|
-
|
|
776
|
+
throw new MastraError(
|
|
777
|
+
{
|
|
778
|
+
id: "STORAGE_DYNAMODB_STORE_CLEAR_TABLE_FAILED",
|
|
779
|
+
domain: ErrorDomain.STORAGE,
|
|
780
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
781
|
+
details: { tableName }
|
|
782
|
+
},
|
|
783
|
+
error
|
|
784
|
+
);
|
|
714
785
|
}
|
|
715
786
|
}
|
|
716
787
|
/**
|
|
717
788
|
* Insert a record into the specified "table" (entity)
|
|
718
789
|
*/
|
|
719
|
-
async insert({
|
|
790
|
+
async insert({
|
|
791
|
+
tableName,
|
|
792
|
+
record
|
|
793
|
+
}) {
|
|
720
794
|
this.logger.debug("DynamoDB insert called", { tableName });
|
|
721
795
|
const entityName = this.getEntityNameForTable(tableName);
|
|
722
796
|
if (!entityName || !this.service.entities[entityName]) {
|
|
723
|
-
throw new
|
|
797
|
+
throw new MastraError({
|
|
798
|
+
id: "STORAGE_DYNAMODB_STORE_INSERT_INVALID_ARGS",
|
|
799
|
+
domain: ErrorDomain.STORAGE,
|
|
800
|
+
category: ErrorCategory.USER,
|
|
801
|
+
text: "No entity defined for tableName",
|
|
802
|
+
details: { tableName }
|
|
803
|
+
});
|
|
724
804
|
}
|
|
725
805
|
try {
|
|
726
|
-
const dataToSave = { entity: entityName, ...record };
|
|
806
|
+
const dataToSave = { entity: entityName, ...this.preprocessRecord(record) };
|
|
727
807
|
await this.service.entities[entityName].create(dataToSave).go();
|
|
728
808
|
} catch (error) {
|
|
729
|
-
|
|
730
|
-
|
|
809
|
+
throw new MastraError(
|
|
810
|
+
{
|
|
811
|
+
id: "STORAGE_DYNAMODB_STORE_INSERT_FAILED",
|
|
812
|
+
domain: ErrorDomain.STORAGE,
|
|
813
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
814
|
+
details: { tableName }
|
|
815
|
+
},
|
|
816
|
+
error
|
|
817
|
+
);
|
|
731
818
|
}
|
|
732
819
|
}
|
|
733
820
|
/**
|
|
734
821
|
* Insert multiple records as a batch
|
|
735
822
|
*/
|
|
736
|
-
async batchInsert({
|
|
823
|
+
async batchInsert({
|
|
824
|
+
tableName,
|
|
825
|
+
records
|
|
826
|
+
}) {
|
|
737
827
|
this.logger.debug("DynamoDB batchInsert called", { tableName, count: records.length });
|
|
738
828
|
const entityName = this.getEntityNameForTable(tableName);
|
|
739
829
|
if (!entityName || !this.service.entities[entityName]) {
|
|
740
|
-
throw new
|
|
830
|
+
throw new MastraError({
|
|
831
|
+
id: "STORAGE_DYNAMODB_STORE_BATCH_INSERT_INVALID_ARGS",
|
|
832
|
+
domain: ErrorDomain.STORAGE,
|
|
833
|
+
category: ErrorCategory.USER,
|
|
834
|
+
text: "No entity defined for tableName",
|
|
835
|
+
details: { tableName }
|
|
836
|
+
});
|
|
741
837
|
}
|
|
742
|
-
const recordsToSave = records.map((rec) => ({ entity: entityName, ...rec }));
|
|
838
|
+
const recordsToSave = records.map((rec) => ({ entity: entityName, ...this.preprocessRecord(rec) }));
|
|
743
839
|
const batchSize = 25;
|
|
744
840
|
const batches = [];
|
|
745
841
|
for (let i = 0; i < recordsToSave.length; i += batchSize) {
|
|
@@ -758,18 +854,34 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
758
854
|
}
|
|
759
855
|
}
|
|
760
856
|
} catch (error) {
|
|
761
|
-
|
|
762
|
-
|
|
857
|
+
throw new MastraError(
|
|
858
|
+
{
|
|
859
|
+
id: "STORAGE_DYNAMODB_STORE_BATCH_INSERT_FAILED",
|
|
860
|
+
domain: ErrorDomain.STORAGE,
|
|
861
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
862
|
+
details: { tableName }
|
|
863
|
+
},
|
|
864
|
+
error
|
|
865
|
+
);
|
|
763
866
|
}
|
|
764
867
|
}
|
|
765
868
|
/**
|
|
766
869
|
* Load a record by its keys
|
|
767
870
|
*/
|
|
768
|
-
async load({
|
|
871
|
+
async load({
|
|
872
|
+
tableName,
|
|
873
|
+
keys
|
|
874
|
+
}) {
|
|
769
875
|
this.logger.debug("DynamoDB load called", { tableName, keys });
|
|
770
876
|
const entityName = this.getEntityNameForTable(tableName);
|
|
771
877
|
if (!entityName || !this.service.entities[entityName]) {
|
|
772
|
-
throw new
|
|
878
|
+
throw new MastraError({
|
|
879
|
+
id: "STORAGE_DYNAMODB_STORE_LOAD_INVALID_ARGS",
|
|
880
|
+
domain: ErrorDomain.STORAGE,
|
|
881
|
+
category: ErrorCategory.USER,
|
|
882
|
+
text: "No entity defined for tableName",
|
|
883
|
+
details: { tableName }
|
|
884
|
+
});
|
|
773
885
|
}
|
|
774
886
|
try {
|
|
775
887
|
const keyObject = { entity: entityName, ...keys };
|
|
@@ -780,8 +892,15 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
780
892
|
let data = result.data;
|
|
781
893
|
return data;
|
|
782
894
|
} catch (error) {
|
|
783
|
-
|
|
784
|
-
|
|
895
|
+
throw new MastraError(
|
|
896
|
+
{
|
|
897
|
+
id: "STORAGE_DYNAMODB_STORE_LOAD_FAILED",
|
|
898
|
+
domain: ErrorDomain.STORAGE,
|
|
899
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
900
|
+
details: { tableName }
|
|
901
|
+
},
|
|
902
|
+
error
|
|
903
|
+
);
|
|
785
904
|
}
|
|
786
905
|
}
|
|
787
906
|
// Thread operations
|
|
@@ -794,13 +913,23 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
794
913
|
}
|
|
795
914
|
const data = result.data;
|
|
796
915
|
return {
|
|
797
|
-
...data
|
|
916
|
+
...data,
|
|
917
|
+
// Convert date strings back to Date objects for consistency
|
|
918
|
+
createdAt: typeof data.createdAt === "string" ? new Date(data.createdAt) : data.createdAt,
|
|
919
|
+
updatedAt: typeof data.updatedAt === "string" ? new Date(data.updatedAt) : data.updatedAt
|
|
798
920
|
// metadata: data.metadata ? JSON.parse(data.metadata) : undefined, // REMOVED by AI
|
|
799
921
|
// metadata is already transformed by the entity's getter
|
|
800
922
|
};
|
|
801
923
|
} catch (error) {
|
|
802
|
-
|
|
803
|
-
|
|
924
|
+
throw new MastraError(
|
|
925
|
+
{
|
|
926
|
+
id: "STORAGE_DYNAMODB_STORE_GET_THREAD_BY_ID_FAILED",
|
|
927
|
+
domain: ErrorDomain.STORAGE,
|
|
928
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
929
|
+
details: { threadId }
|
|
930
|
+
},
|
|
931
|
+
error
|
|
932
|
+
);
|
|
804
933
|
}
|
|
805
934
|
}
|
|
806
935
|
async getThreadsByResourceId({ resourceId }) {
|
|
@@ -811,13 +940,23 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
811
940
|
return [];
|
|
812
941
|
}
|
|
813
942
|
return result.data.map((data) => ({
|
|
814
|
-
...data
|
|
943
|
+
...data,
|
|
944
|
+
// Convert date strings back to Date objects for consistency
|
|
945
|
+
createdAt: typeof data.createdAt === "string" ? new Date(data.createdAt) : data.createdAt,
|
|
946
|
+
updatedAt: typeof data.updatedAt === "string" ? new Date(data.updatedAt) : data.updatedAt
|
|
815
947
|
// metadata: data.metadata ? JSON.parse(data.metadata) : undefined, // REMOVED by AI
|
|
816
948
|
// metadata is already transformed by the entity's getter
|
|
817
949
|
}));
|
|
818
950
|
} catch (error) {
|
|
819
|
-
|
|
820
|
-
|
|
951
|
+
throw new MastraError(
|
|
952
|
+
{
|
|
953
|
+
id: "STORAGE_DYNAMODB_STORE_GET_THREADS_BY_RESOURCE_ID_FAILED",
|
|
954
|
+
domain: ErrorDomain.STORAGE,
|
|
955
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
956
|
+
details: { resourceId }
|
|
957
|
+
},
|
|
958
|
+
error
|
|
959
|
+
);
|
|
821
960
|
}
|
|
822
961
|
}
|
|
823
962
|
async saveThread({ thread }) {
|
|
@@ -843,8 +982,15 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
843
982
|
metadata: thread.metadata
|
|
844
983
|
};
|
|
845
984
|
} catch (error) {
|
|
846
|
-
|
|
847
|
-
|
|
985
|
+
throw new MastraError(
|
|
986
|
+
{
|
|
987
|
+
id: "STORAGE_DYNAMODB_STORE_SAVE_THREAD_FAILED",
|
|
988
|
+
domain: ErrorDomain.STORAGE,
|
|
989
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
990
|
+
details: { threadId: thread.id }
|
|
991
|
+
},
|
|
992
|
+
error
|
|
993
|
+
);
|
|
848
994
|
}
|
|
849
995
|
}
|
|
850
996
|
async updateThread({
|
|
@@ -876,8 +1022,15 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
876
1022
|
updatedAt: now
|
|
877
1023
|
};
|
|
878
1024
|
} catch (error) {
|
|
879
|
-
|
|
880
|
-
|
|
1025
|
+
throw new MastraError(
|
|
1026
|
+
{
|
|
1027
|
+
id: "STORAGE_DYNAMODB_STORE_UPDATE_THREAD_FAILED",
|
|
1028
|
+
domain: ErrorDomain.STORAGE,
|
|
1029
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1030
|
+
details: { threadId: id }
|
|
1031
|
+
},
|
|
1032
|
+
error
|
|
1033
|
+
);
|
|
881
1034
|
}
|
|
882
1035
|
}
|
|
883
1036
|
async deleteThread({ threadId }) {
|
|
@@ -885,8 +1038,15 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
885
1038
|
try {
|
|
886
1039
|
await this.service.entities.thread.delete({ entity: "thread", id: threadId }).go();
|
|
887
1040
|
} catch (error) {
|
|
888
|
-
|
|
889
|
-
|
|
1041
|
+
throw new MastraError(
|
|
1042
|
+
{
|
|
1043
|
+
id: "STORAGE_DYNAMODB_STORE_DELETE_THREAD_FAILED",
|
|
1044
|
+
domain: ErrorDomain.STORAGE,
|
|
1045
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1046
|
+
details: { threadId }
|
|
1047
|
+
},
|
|
1048
|
+
error
|
|
1049
|
+
);
|
|
890
1050
|
}
|
|
891
1051
|
}
|
|
892
1052
|
async getMessages({
|
|
@@ -898,8 +1058,9 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
898
1058
|
this.logger.debug("Getting messages", { threadId, selectBy });
|
|
899
1059
|
try {
|
|
900
1060
|
const query = this.service.entities.message.query.byThread({ entity: "message", threadId });
|
|
901
|
-
|
|
902
|
-
|
|
1061
|
+
const limit = this.resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
|
|
1062
|
+
if (limit !== Number.MAX_SAFE_INTEGER) {
|
|
1063
|
+
const results2 = await query.go({ limit, order: "desc" });
|
|
903
1064
|
const list2 = new MessageList({ threadId, resourceId }).add(
|
|
904
1065
|
results2.data.map((data) => this.parseMessageData(data)),
|
|
905
1066
|
"memory"
|
|
@@ -915,8 +1076,15 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
915
1076
|
if (format === `v2`) return list.get.all.v2();
|
|
916
1077
|
return list.get.all.v1();
|
|
917
1078
|
} catch (error) {
|
|
918
|
-
|
|
919
|
-
|
|
1079
|
+
throw new MastraError(
|
|
1080
|
+
{
|
|
1081
|
+
id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_FAILED",
|
|
1082
|
+
domain: ErrorDomain.STORAGE,
|
|
1083
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1084
|
+
details: { threadId }
|
|
1085
|
+
},
|
|
1086
|
+
error
|
|
1087
|
+
);
|
|
920
1088
|
}
|
|
921
1089
|
}
|
|
922
1090
|
async saveMessages(args) {
|
|
@@ -925,6 +1093,10 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
925
1093
|
if (!messages.length) {
|
|
926
1094
|
return [];
|
|
927
1095
|
}
|
|
1096
|
+
const threadId = messages[0]?.threadId;
|
|
1097
|
+
if (!threadId) {
|
|
1098
|
+
throw new Error("Thread ID is required");
|
|
1099
|
+
}
|
|
928
1100
|
const messagesToSave = messages.map((msg) => {
|
|
929
1101
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
930
1102
|
return {
|
|
@@ -952,21 +1124,35 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
952
1124
|
const batch = messagesToSave.slice(i, i + batchSize);
|
|
953
1125
|
batches.push(batch);
|
|
954
1126
|
}
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
1127
|
+
await Promise.all([
|
|
1128
|
+
// Process message batches
|
|
1129
|
+
...batches.map(async (batch) => {
|
|
1130
|
+
for (const messageData of batch) {
|
|
1131
|
+
if (!messageData.entity) {
|
|
1132
|
+
this.logger.error("Missing entity property in message data for create", { messageData });
|
|
1133
|
+
throw new Error("Internal error: Missing entity property during saveMessages");
|
|
1134
|
+
}
|
|
1135
|
+
await this.service.entities.message.put(messageData).go();
|
|
960
1136
|
}
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
1137
|
+
}),
|
|
1138
|
+
// Update thread's updatedAt timestamp
|
|
1139
|
+
this.service.entities.thread.update({ entity: "thread", id: threadId }).set({
|
|
1140
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1141
|
+
}).go()
|
|
1142
|
+
]);
|
|
964
1143
|
const list = new MessageList().add(messages, "memory");
|
|
965
1144
|
if (format === `v1`) return list.get.all.v1();
|
|
966
1145
|
return list.get.all.v2();
|
|
967
1146
|
} catch (error) {
|
|
968
|
-
|
|
969
|
-
|
|
1147
|
+
throw new MastraError(
|
|
1148
|
+
{
|
|
1149
|
+
id: "STORAGE_DYNAMODB_STORE_SAVE_MESSAGES_FAILED",
|
|
1150
|
+
domain: ErrorDomain.STORAGE,
|
|
1151
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1152
|
+
details: { count: messages.length }
|
|
1153
|
+
},
|
|
1154
|
+
error
|
|
1155
|
+
);
|
|
970
1156
|
}
|
|
971
1157
|
}
|
|
972
1158
|
// Helper function to parse message data (handle JSON fields)
|
|
@@ -1012,8 +1198,14 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
1012
1198
|
} while (cursor && pagesFetched < startPage);
|
|
1013
1199
|
return items;
|
|
1014
1200
|
} catch (error) {
|
|
1015
|
-
|
|
1016
|
-
|
|
1201
|
+
throw new MastraError(
|
|
1202
|
+
{
|
|
1203
|
+
id: "STORAGE_DYNAMODB_STORE_GET_TRACES_FAILED",
|
|
1204
|
+
domain: ErrorDomain.STORAGE,
|
|
1205
|
+
category: ErrorCategory.THIRD_PARTY
|
|
1206
|
+
},
|
|
1207
|
+
error
|
|
1208
|
+
);
|
|
1017
1209
|
}
|
|
1018
1210
|
}
|
|
1019
1211
|
async batchTraceInsert({ records }) {
|
|
@@ -1029,8 +1221,15 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
1029
1221
|
// Pass records with 'entity' included
|
|
1030
1222
|
});
|
|
1031
1223
|
} catch (error) {
|
|
1032
|
-
|
|
1033
|
-
|
|
1224
|
+
throw new MastraError(
|
|
1225
|
+
{
|
|
1226
|
+
id: "STORAGE_DYNAMODB_STORE_BATCH_TRACE_INSERT_FAILED",
|
|
1227
|
+
domain: ErrorDomain.STORAGE,
|
|
1228
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1229
|
+
details: { count: records.length }
|
|
1230
|
+
},
|
|
1231
|
+
error
|
|
1232
|
+
);
|
|
1034
1233
|
}
|
|
1035
1234
|
}
|
|
1036
1235
|
// Workflow operations
|
|
@@ -1054,10 +1253,17 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
1054
1253
|
updatedAt: now,
|
|
1055
1254
|
resourceId
|
|
1056
1255
|
};
|
|
1057
|
-
await this.service.entities.workflowSnapshot.
|
|
1256
|
+
await this.service.entities.workflowSnapshot.upsert(data).go();
|
|
1058
1257
|
} catch (error) {
|
|
1059
|
-
|
|
1060
|
-
|
|
1258
|
+
throw new MastraError(
|
|
1259
|
+
{
|
|
1260
|
+
id: "STORAGE_DYNAMODB_STORE_PERSIST_WORKFLOW_SNAPSHOT_FAILED",
|
|
1261
|
+
domain: ErrorDomain.STORAGE,
|
|
1262
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1263
|
+
details: { workflowName, runId }
|
|
1264
|
+
},
|
|
1265
|
+
error
|
|
1266
|
+
);
|
|
1061
1267
|
}
|
|
1062
1268
|
}
|
|
1063
1269
|
async loadWorkflowSnapshot({
|
|
@@ -1077,8 +1283,15 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
1077
1283
|
}
|
|
1078
1284
|
return result.data.snapshot;
|
|
1079
1285
|
} catch (error) {
|
|
1080
|
-
|
|
1081
|
-
|
|
1286
|
+
throw new MastraError(
|
|
1287
|
+
{
|
|
1288
|
+
id: "STORAGE_DYNAMODB_STORE_LOAD_WORKFLOW_SNAPSHOT_FAILED",
|
|
1289
|
+
domain: ErrorDomain.STORAGE,
|
|
1290
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1291
|
+
details: { workflowName, runId }
|
|
1292
|
+
},
|
|
1293
|
+
error
|
|
1294
|
+
);
|
|
1082
1295
|
}
|
|
1083
1296
|
}
|
|
1084
1297
|
async getWorkflowRuns(args) {
|
|
@@ -1139,8 +1352,15 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
1139
1352
|
total
|
|
1140
1353
|
};
|
|
1141
1354
|
} catch (error) {
|
|
1142
|
-
|
|
1143
|
-
|
|
1355
|
+
throw new MastraError(
|
|
1356
|
+
{
|
|
1357
|
+
id: "STORAGE_DYNAMODB_STORE_GET_WORKFLOW_RUNS_FAILED",
|
|
1358
|
+
domain: ErrorDomain.STORAGE,
|
|
1359
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1360
|
+
details: { workflowName: args?.workflowName || "", resourceId: args?.resourceId || "" }
|
|
1361
|
+
},
|
|
1362
|
+
error
|
|
1363
|
+
);
|
|
1144
1364
|
}
|
|
1145
1365
|
}
|
|
1146
1366
|
async getWorkflowRunById(args) {
|
|
@@ -1186,8 +1406,15 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
1186
1406
|
resourceId: matchingRunDbItem.resourceId
|
|
1187
1407
|
};
|
|
1188
1408
|
} catch (error) {
|
|
1189
|
-
|
|
1190
|
-
|
|
1409
|
+
throw new MastraError(
|
|
1410
|
+
{
|
|
1411
|
+
id: "STORAGE_DYNAMODB_STORE_GET_WORKFLOW_RUN_BY_ID_FAILED",
|
|
1412
|
+
domain: ErrorDomain.STORAGE,
|
|
1413
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1414
|
+
details: { runId, workflowName: args?.workflowName || "" }
|
|
1415
|
+
},
|
|
1416
|
+
error
|
|
1417
|
+
);
|
|
1191
1418
|
}
|
|
1192
1419
|
}
|
|
1193
1420
|
// Helper function to format workflow run
|
|
@@ -1265,10 +1492,47 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
1265
1492
|
}
|
|
1266
1493
|
});
|
|
1267
1494
|
} catch (error) {
|
|
1268
|
-
|
|
1269
|
-
|
|
1495
|
+
throw new MastraError(
|
|
1496
|
+
{
|
|
1497
|
+
id: "STORAGE_DYNAMODB_STORE_GET_EVALS_BY_AGENT_NAME_FAILED",
|
|
1498
|
+
domain: ErrorDomain.STORAGE,
|
|
1499
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1500
|
+
details: { agentName }
|
|
1501
|
+
},
|
|
1502
|
+
error
|
|
1503
|
+
);
|
|
1270
1504
|
}
|
|
1271
1505
|
}
|
|
1506
|
+
async getTracesPaginated(_args) {
|
|
1507
|
+
throw new MastraError(
|
|
1508
|
+
{
|
|
1509
|
+
id: "STORAGE_DYNAMODB_STORE_GET_TRACES_PAGINATED_FAILED",
|
|
1510
|
+
domain: ErrorDomain.STORAGE,
|
|
1511
|
+
category: ErrorCategory.THIRD_PARTY
|
|
1512
|
+
},
|
|
1513
|
+
new Error("Method not implemented.")
|
|
1514
|
+
);
|
|
1515
|
+
}
|
|
1516
|
+
async getThreadsByResourceIdPaginated(_args) {
|
|
1517
|
+
throw new MastraError(
|
|
1518
|
+
{
|
|
1519
|
+
id: "STORAGE_DYNAMODB_STORE_GET_THREADS_BY_RESOURCE_ID_PAGINATED_FAILED",
|
|
1520
|
+
domain: ErrorDomain.STORAGE,
|
|
1521
|
+
category: ErrorCategory.THIRD_PARTY
|
|
1522
|
+
},
|
|
1523
|
+
new Error("Method not implemented.")
|
|
1524
|
+
);
|
|
1525
|
+
}
|
|
1526
|
+
async getMessagesPaginated(_args) {
|
|
1527
|
+
throw new MastraError(
|
|
1528
|
+
{
|
|
1529
|
+
id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_PAGINATED_FAILED",
|
|
1530
|
+
domain: ErrorDomain.STORAGE,
|
|
1531
|
+
category: ErrorCategory.THIRD_PARTY
|
|
1532
|
+
},
|
|
1533
|
+
new Error("Method not implemented.")
|
|
1534
|
+
);
|
|
1535
|
+
}
|
|
1272
1536
|
/**
|
|
1273
1537
|
* Closes the DynamoDB client connection and cleans up resources.
|
|
1274
1538
|
* Should be called when the store is no longer needed, e.g., at the end of tests or application shutdown.
|
|
@@ -1279,10 +1543,20 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
1279
1543
|
this.client.destroy();
|
|
1280
1544
|
this.logger.debug("DynamoDB client closed successfully for store:", { name: this.name });
|
|
1281
1545
|
} catch (error) {
|
|
1282
|
-
|
|
1283
|
-
|
|
1546
|
+
throw new MastraError(
|
|
1547
|
+
{
|
|
1548
|
+
id: "STORAGE_DYNAMODB_STORE_CLOSE_FAILED",
|
|
1549
|
+
domain: ErrorDomain.STORAGE,
|
|
1550
|
+
category: ErrorCategory.THIRD_PARTY
|
|
1551
|
+
},
|
|
1552
|
+
error
|
|
1553
|
+
);
|
|
1284
1554
|
}
|
|
1285
1555
|
}
|
|
1556
|
+
async updateMessages(_args) {
|
|
1557
|
+
this.logger.error("updateMessages is not yet implemented in DynamoDBStore");
|
|
1558
|
+
throw new Error("Method not implemented");
|
|
1559
|
+
}
|
|
1286
1560
|
};
|
|
1287
1561
|
|
|
1288
1562
|
export { DynamoDBStore };
|