@mastra/libsql 0.10.3 → 0.10.4-alpha.1
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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +24 -0
- package/dist/_tsup-dts-rollup.d.cts +10 -0
- package/dist/_tsup-dts-rollup.d.ts +10 -0
- package/dist/index.cjs +548 -149
- package/dist/index.js +537 -138
- package/package.json +4 -4
- package/src/storage/index.test.ts +165 -0
- package/src/storage/index.ts +452 -136
- package/src/vector/index.ts +126 -14
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var client = require('@libsql/client');
|
|
4
|
+
var error = require('@mastra/core/error');
|
|
4
5
|
var utils = require('@mastra/core/utils');
|
|
5
6
|
var vector = require('@mastra/core/vector');
|
|
6
7
|
var filter = require('@mastra/core/vector/filter');
|
|
@@ -556,6 +557,17 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
556
557
|
if (!Array.isArray(queryVector) || !queryVector.every((x) => typeof x === "number" && Number.isFinite(x))) {
|
|
557
558
|
throw new Error("queryVector must be an array of finite numbers");
|
|
558
559
|
}
|
|
560
|
+
} catch (error$1) {
|
|
561
|
+
throw new error.MastraError(
|
|
562
|
+
{
|
|
563
|
+
id: "LIBSQL_VECTOR_QUERY_INVALID_ARGS",
|
|
564
|
+
domain: error.ErrorDomain.STORAGE,
|
|
565
|
+
category: error.ErrorCategory.USER
|
|
566
|
+
},
|
|
567
|
+
error$1
|
|
568
|
+
);
|
|
569
|
+
}
|
|
570
|
+
try {
|
|
559
571
|
const parsedIndexName = utils.parseSqlIdentifier(indexName, "index name");
|
|
560
572
|
const vectorStr = `[${queryVector.join(",")}]`;
|
|
561
573
|
const translatedFilter = this.transformFilter(filter);
|
|
@@ -587,11 +599,30 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
587
599
|
metadata: JSON.parse(metadata ?? "{}"),
|
|
588
600
|
...includeVector && embedding && { vector: JSON.parse(embedding) }
|
|
589
601
|
}));
|
|
590
|
-
}
|
|
602
|
+
} catch (error$1) {
|
|
603
|
+
throw new error.MastraError(
|
|
604
|
+
{
|
|
605
|
+
id: "LIBSQL_VECTOR_QUERY_FAILED",
|
|
606
|
+
domain: error.ErrorDomain.STORAGE,
|
|
607
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
608
|
+
},
|
|
609
|
+
error$1
|
|
610
|
+
);
|
|
591
611
|
}
|
|
592
612
|
}
|
|
593
613
|
upsert(args) {
|
|
594
|
-
|
|
614
|
+
try {
|
|
615
|
+
return this.executeWriteOperationWithRetry(() => this.doUpsert(args), true);
|
|
616
|
+
} catch (error$1) {
|
|
617
|
+
throw new error.MastraError(
|
|
618
|
+
{
|
|
619
|
+
id: "LIBSQL_VECTOR_UPSERT_FAILED",
|
|
620
|
+
domain: error.ErrorDomain.STORAGE,
|
|
621
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
622
|
+
},
|
|
623
|
+
error$1
|
|
624
|
+
);
|
|
625
|
+
}
|
|
595
626
|
}
|
|
596
627
|
async doUpsert({ indexName, vectors, metadata, ids }) {
|
|
597
628
|
const tx = await this.turso.transaction("write");
|
|
@@ -634,7 +665,19 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
634
665
|
}
|
|
635
666
|
}
|
|
636
667
|
createIndex(args) {
|
|
637
|
-
|
|
668
|
+
try {
|
|
669
|
+
return this.executeWriteOperationWithRetry(() => this.doCreateIndex(args));
|
|
670
|
+
} catch (error$1) {
|
|
671
|
+
throw new error.MastraError(
|
|
672
|
+
{
|
|
673
|
+
id: "LIBSQL_VECTOR_CREATE_INDEX_FAILED",
|
|
674
|
+
domain: error.ErrorDomain.STORAGE,
|
|
675
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
676
|
+
details: { indexName: args.indexName, dimension: args.dimension }
|
|
677
|
+
},
|
|
678
|
+
error$1
|
|
679
|
+
);
|
|
680
|
+
}
|
|
638
681
|
}
|
|
639
682
|
async doCreateIndex({ indexName, dimension }) {
|
|
640
683
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
@@ -661,7 +704,19 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
661
704
|
});
|
|
662
705
|
}
|
|
663
706
|
deleteIndex(args) {
|
|
664
|
-
|
|
707
|
+
try {
|
|
708
|
+
return this.executeWriteOperationWithRetry(() => this.doDeleteIndex(args));
|
|
709
|
+
} catch (error$1) {
|
|
710
|
+
throw new error.MastraError(
|
|
711
|
+
{
|
|
712
|
+
id: "LIBSQL_VECTOR_DELETE_INDEX_FAILED",
|
|
713
|
+
domain: error.ErrorDomain.STORAGE,
|
|
714
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
715
|
+
details: { indexName: args.indexName }
|
|
716
|
+
},
|
|
717
|
+
error$1
|
|
718
|
+
);
|
|
719
|
+
}
|
|
665
720
|
}
|
|
666
721
|
async doDeleteIndex({ indexName }) {
|
|
667
722
|
const parsedIndexName = utils.parseSqlIdentifier(indexName, "index name");
|
|
@@ -682,8 +737,15 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
682
737
|
args: []
|
|
683
738
|
});
|
|
684
739
|
return result.rows.map((row) => row.name);
|
|
685
|
-
} catch (error) {
|
|
686
|
-
throw new
|
|
740
|
+
} catch (error$1) {
|
|
741
|
+
throw new error.MastraError(
|
|
742
|
+
{
|
|
743
|
+
id: "LIBSQL_VECTOR_LIST_INDEXES_FAILED",
|
|
744
|
+
domain: error.ErrorDomain.STORAGE,
|
|
745
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
746
|
+
},
|
|
747
|
+
error$1
|
|
748
|
+
);
|
|
687
749
|
}
|
|
688
750
|
}
|
|
689
751
|
/**
|
|
@@ -724,7 +786,15 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
724
786
|
metric
|
|
725
787
|
};
|
|
726
788
|
} catch (e) {
|
|
727
|
-
throw new
|
|
789
|
+
throw new error.MastraError(
|
|
790
|
+
{
|
|
791
|
+
id: "LIBSQL_VECTOR_DESCRIBE_INDEX_FAILED",
|
|
792
|
+
domain: error.ErrorDomain.STORAGE,
|
|
793
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
794
|
+
details: { indexName }
|
|
795
|
+
},
|
|
796
|
+
e
|
|
797
|
+
);
|
|
728
798
|
}
|
|
729
799
|
}
|
|
730
800
|
/**
|
|
@@ -754,7 +824,13 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
754
824
|
args.push(JSON.stringify(update.metadata));
|
|
755
825
|
}
|
|
756
826
|
if (updates.length === 0) {
|
|
757
|
-
throw new
|
|
827
|
+
throw new error.MastraError({
|
|
828
|
+
id: "LIBSQL_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
|
|
829
|
+
domain: error.ErrorDomain.STORAGE,
|
|
830
|
+
category: error.ErrorCategory.USER,
|
|
831
|
+
details: { indexName, id },
|
|
832
|
+
text: "No updates provided"
|
|
833
|
+
});
|
|
758
834
|
}
|
|
759
835
|
args.push(id);
|
|
760
836
|
const query = `
|
|
@@ -762,10 +838,22 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
762
838
|
SET ${updates.join(", ")}
|
|
763
839
|
WHERE vector_id = ?;
|
|
764
840
|
`;
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
841
|
+
try {
|
|
842
|
+
await this.turso.execute({
|
|
843
|
+
sql: query,
|
|
844
|
+
args
|
|
845
|
+
});
|
|
846
|
+
} catch (error$1) {
|
|
847
|
+
throw new error.MastraError(
|
|
848
|
+
{
|
|
849
|
+
id: "LIBSQL_VECTOR_UPDATE_VECTOR_FAILED",
|
|
850
|
+
domain: error.ErrorDomain.STORAGE,
|
|
851
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
852
|
+
details: { indexName, id }
|
|
853
|
+
},
|
|
854
|
+
error$1
|
|
855
|
+
);
|
|
856
|
+
}
|
|
769
857
|
}
|
|
770
858
|
/**
|
|
771
859
|
* Deletes a vector by its ID.
|
|
@@ -775,7 +863,19 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
775
863
|
* @throws Will throw an error if the deletion operation fails.
|
|
776
864
|
*/
|
|
777
865
|
deleteVector(args) {
|
|
778
|
-
|
|
866
|
+
try {
|
|
867
|
+
return this.executeWriteOperationWithRetry(() => this.doDeleteVector(args));
|
|
868
|
+
} catch (error$1) {
|
|
869
|
+
throw new error.MastraError(
|
|
870
|
+
{
|
|
871
|
+
id: "LIBSQL_VECTOR_DELETE_VECTOR_FAILED",
|
|
872
|
+
domain: error.ErrorDomain.STORAGE,
|
|
873
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
874
|
+
details: { indexName: args.indexName, id: args.id }
|
|
875
|
+
},
|
|
876
|
+
error$1
|
|
877
|
+
);
|
|
878
|
+
}
|
|
779
879
|
}
|
|
780
880
|
async doDeleteVector({ indexName, id }) {
|
|
781
881
|
const parsedIndexName = utils.parseSqlIdentifier(indexName, "index name");
|
|
@@ -785,7 +885,19 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
785
885
|
});
|
|
786
886
|
}
|
|
787
887
|
truncateIndex(args) {
|
|
788
|
-
|
|
888
|
+
try {
|
|
889
|
+
return this.executeWriteOperationWithRetry(() => this._doTruncateIndex(args));
|
|
890
|
+
} catch (error$1) {
|
|
891
|
+
throw new error.MastraError(
|
|
892
|
+
{
|
|
893
|
+
id: "LIBSQL_VECTOR_TRUNCATE_INDEX_FAILED",
|
|
894
|
+
domain: error.ErrorDomain.STORAGE,
|
|
895
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
896
|
+
details: { indexName: args.indexName }
|
|
897
|
+
},
|
|
898
|
+
error$1
|
|
899
|
+
);
|
|
900
|
+
}
|
|
789
901
|
}
|
|
790
902
|
async _doTruncateIndex({ indexName }) {
|
|
791
903
|
await this.turso.execute({
|
|
@@ -851,9 +963,18 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
851
963
|
this.logger.debug(`Creating database table`, { tableName, operation: "schema init" });
|
|
852
964
|
const sql = this.getCreateTableSQL(tableName, schema);
|
|
853
965
|
await this.client.execute(sql);
|
|
854
|
-
} catch (error) {
|
|
855
|
-
|
|
856
|
-
|
|
966
|
+
} catch (error$1) {
|
|
967
|
+
throw new error.MastraError(
|
|
968
|
+
{
|
|
969
|
+
id: "LIBSQL_STORE_CREATE_TABLE_FAILED",
|
|
970
|
+
domain: error.ErrorDomain.STORAGE,
|
|
971
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
972
|
+
details: {
|
|
973
|
+
tableName
|
|
974
|
+
}
|
|
975
|
+
},
|
|
976
|
+
error$1
|
|
977
|
+
);
|
|
857
978
|
}
|
|
858
979
|
}
|
|
859
980
|
getSqlType(type) {
|
|
@@ -895,11 +1016,18 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
895
1016
|
this.logger?.debug?.(`Added column ${columnName} to table ${parsedTableName}`);
|
|
896
1017
|
}
|
|
897
1018
|
}
|
|
898
|
-
} catch (error) {
|
|
899
|
-
|
|
900
|
-
|
|
1019
|
+
} catch (error$1) {
|
|
1020
|
+
throw new error.MastraError(
|
|
1021
|
+
{
|
|
1022
|
+
id: "LIBSQL_STORE_ALTER_TABLE_FAILED",
|
|
1023
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1024
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1025
|
+
details: {
|
|
1026
|
+
tableName
|
|
1027
|
+
}
|
|
1028
|
+
},
|
|
1029
|
+
error$1
|
|
901
1030
|
);
|
|
902
|
-
throw new Error(`Failed to alter table ${tableName}: ${error}`);
|
|
903
1031
|
}
|
|
904
1032
|
}
|
|
905
1033
|
async clearTable({ tableName }) {
|
|
@@ -907,9 +1035,19 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
907
1035
|
try {
|
|
908
1036
|
await this.client.execute(`DELETE FROM ${parsedTableName}`);
|
|
909
1037
|
} catch (e) {
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
1038
|
+
const mastraError = new error.MastraError(
|
|
1039
|
+
{
|
|
1040
|
+
id: "LIBSQL_STORE_CLEAR_TABLE_FAILED",
|
|
1041
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1042
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1043
|
+
details: {
|
|
1044
|
+
tableName
|
|
1045
|
+
}
|
|
1046
|
+
},
|
|
1047
|
+
e
|
|
1048
|
+
);
|
|
1049
|
+
this.logger?.trackException?.(mastraError);
|
|
1050
|
+
this.logger?.error?.(mastraError.toString());
|
|
913
1051
|
}
|
|
914
1052
|
}
|
|
915
1053
|
prepareStatement({ tableName, record }) {
|
|
@@ -968,7 +1106,19 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
968
1106
|
return this.executeWriteOperationWithRetry(
|
|
969
1107
|
() => this.doBatchInsert(args),
|
|
970
1108
|
`batch insert into table ${args.tableName}`
|
|
971
|
-
)
|
|
1109
|
+
).catch((error$1) => {
|
|
1110
|
+
throw new error.MastraError(
|
|
1111
|
+
{
|
|
1112
|
+
id: "LIBSQL_STORE_BATCH_INSERT_FAILED",
|
|
1113
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1114
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1115
|
+
details: {
|
|
1116
|
+
tableName: args.tableName
|
|
1117
|
+
}
|
|
1118
|
+
},
|
|
1119
|
+
error$1
|
|
1120
|
+
);
|
|
1121
|
+
});
|
|
972
1122
|
}
|
|
973
1123
|
async doBatchInsert({
|
|
974
1124
|
tableName,
|
|
@@ -1003,17 +1153,29 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
1003
1153
|
return parsed;
|
|
1004
1154
|
}
|
|
1005
1155
|
async getThreadById({ threadId }) {
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1156
|
+
try {
|
|
1157
|
+
const result = await this.load({
|
|
1158
|
+
tableName: storage.TABLE_THREADS,
|
|
1159
|
+
keys: { id: threadId }
|
|
1160
|
+
});
|
|
1161
|
+
if (!result) {
|
|
1162
|
+
return null;
|
|
1163
|
+
}
|
|
1164
|
+
return {
|
|
1165
|
+
...result,
|
|
1166
|
+
metadata: typeof result.metadata === "string" ? JSON.parse(result.metadata) : result.metadata
|
|
1167
|
+
};
|
|
1168
|
+
} catch (error$1) {
|
|
1169
|
+
throw new error.MastraError(
|
|
1170
|
+
{
|
|
1171
|
+
id: "LIBSQL_STORE_GET_THREAD_BY_ID_FAILED",
|
|
1172
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1173
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1174
|
+
details: { threadId }
|
|
1175
|
+
},
|
|
1176
|
+
error$1
|
|
1177
|
+
);
|
|
1012
1178
|
}
|
|
1013
|
-
return {
|
|
1014
|
-
...result,
|
|
1015
|
-
metadata: typeof result.metadata === "string" ? JSON.parse(result.metadata) : result.metadata
|
|
1016
|
-
};
|
|
1017
1179
|
}
|
|
1018
1180
|
/**
|
|
1019
1181
|
* @deprecated use getThreadsByResourceIdPaginated instead for paginated results.
|
|
@@ -1041,8 +1203,18 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
1041
1203
|
return [];
|
|
1042
1204
|
}
|
|
1043
1205
|
return result.rows.map(mapRowToStorageThreadType);
|
|
1044
|
-
} catch (error) {
|
|
1045
|
-
|
|
1206
|
+
} catch (error$1) {
|
|
1207
|
+
const mastraError = new error.MastraError(
|
|
1208
|
+
{
|
|
1209
|
+
id: "LIBSQL_STORE_GET_THREADS_BY_RESOURCE_ID_FAILED",
|
|
1210
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1211
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1212
|
+
details: { resourceId }
|
|
1213
|
+
},
|
|
1214
|
+
error$1
|
|
1215
|
+
);
|
|
1216
|
+
this.logger?.trackException?.(mastraError);
|
|
1217
|
+
this.logger?.error?.(mastraError.toString());
|
|
1046
1218
|
return [];
|
|
1047
1219
|
}
|
|
1048
1220
|
}
|
|
@@ -1088,20 +1260,45 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
1088
1260
|
perPage,
|
|
1089
1261
|
hasMore: currentOffset + threads.length < total
|
|
1090
1262
|
};
|
|
1091
|
-
} catch (error) {
|
|
1092
|
-
|
|
1263
|
+
} catch (error$1) {
|
|
1264
|
+
const mastraError = new error.MastraError(
|
|
1265
|
+
{
|
|
1266
|
+
id: "LIBSQL_STORE_GET_THREADS_BY_RESOURCE_ID_FAILED",
|
|
1267
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1268
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1269
|
+
details: { resourceId }
|
|
1270
|
+
},
|
|
1271
|
+
error$1
|
|
1272
|
+
);
|
|
1273
|
+
this.logger?.trackException?.(mastraError);
|
|
1274
|
+
this.logger?.error?.(mastraError.toString());
|
|
1093
1275
|
return { threads: [], total: 0, page, perPage, hasMore: false };
|
|
1094
1276
|
}
|
|
1095
1277
|
}
|
|
1096
1278
|
async saveThread({ thread }) {
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1279
|
+
try {
|
|
1280
|
+
await this.insert({
|
|
1281
|
+
tableName: storage.TABLE_THREADS,
|
|
1282
|
+
record: {
|
|
1283
|
+
...thread,
|
|
1284
|
+
metadata: JSON.stringify(thread.metadata)
|
|
1285
|
+
}
|
|
1286
|
+
});
|
|
1287
|
+
return thread;
|
|
1288
|
+
} catch (error$1) {
|
|
1289
|
+
const mastraError = new error.MastraError(
|
|
1290
|
+
{
|
|
1291
|
+
id: "LIBSQL_STORE_SAVE_THREAD_FAILED",
|
|
1292
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1293
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1294
|
+
details: { threadId: thread.id }
|
|
1295
|
+
},
|
|
1296
|
+
error$1
|
|
1297
|
+
);
|
|
1298
|
+
this.logger?.trackException?.(mastraError);
|
|
1299
|
+
this.logger?.error?.(mastraError.toString());
|
|
1300
|
+
throw mastraError;
|
|
1301
|
+
}
|
|
1105
1302
|
}
|
|
1106
1303
|
async updateThread({
|
|
1107
1304
|
id,
|
|
@@ -1110,7 +1307,13 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
1110
1307
|
}) {
|
|
1111
1308
|
const thread = await this.getThreadById({ threadId: id });
|
|
1112
1309
|
if (!thread) {
|
|
1113
|
-
throw new
|
|
1310
|
+
throw new error.MastraError({
|
|
1311
|
+
id: "LIBSQL_STORE_UPDATE_THREAD_FAILED_THREAD_NOT_FOUND",
|
|
1312
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1313
|
+
category: error.ErrorCategory.USER,
|
|
1314
|
+
text: `Thread ${id} not found`,
|
|
1315
|
+
details: { threadId: id }
|
|
1316
|
+
});
|
|
1114
1317
|
}
|
|
1115
1318
|
const updatedThread = {
|
|
1116
1319
|
...thread,
|
|
@@ -1120,21 +1323,46 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
1120
1323
|
...metadata
|
|
1121
1324
|
}
|
|
1122
1325
|
};
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1326
|
+
try {
|
|
1327
|
+
await this.client.execute({
|
|
1328
|
+
sql: `UPDATE ${storage.TABLE_THREADS} SET title = ?, metadata = ? WHERE id = ?`,
|
|
1329
|
+
args: [title, JSON.stringify(updatedThread.metadata), id]
|
|
1330
|
+
});
|
|
1331
|
+
return updatedThread;
|
|
1332
|
+
} catch (error$1) {
|
|
1333
|
+
throw new error.MastraError(
|
|
1334
|
+
{
|
|
1335
|
+
id: "LIBSQL_STORE_UPDATE_THREAD_FAILED",
|
|
1336
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1337
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1338
|
+
text: `Failed to update thread ${id}`,
|
|
1339
|
+
details: { threadId: id }
|
|
1340
|
+
},
|
|
1341
|
+
error$1
|
|
1342
|
+
);
|
|
1343
|
+
}
|
|
1128
1344
|
}
|
|
1129
1345
|
async deleteThread({ threadId }) {
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1346
|
+
try {
|
|
1347
|
+
await this.client.execute({
|
|
1348
|
+
sql: `DELETE FROM ${storage.TABLE_MESSAGES} WHERE thread_id = ?`,
|
|
1349
|
+
args: [threadId]
|
|
1350
|
+
});
|
|
1351
|
+
await this.client.execute({
|
|
1352
|
+
sql: `DELETE FROM ${storage.TABLE_THREADS} WHERE id = ?`,
|
|
1353
|
+
args: [threadId]
|
|
1354
|
+
});
|
|
1355
|
+
} catch (error$1) {
|
|
1356
|
+
throw new error.MastraError(
|
|
1357
|
+
{
|
|
1358
|
+
id: "LIBSQL_STORE_DELETE_THREAD_FAILED",
|
|
1359
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1360
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1361
|
+
details: { threadId }
|
|
1362
|
+
},
|
|
1363
|
+
error$1
|
|
1364
|
+
);
|
|
1365
|
+
}
|
|
1138
1366
|
}
|
|
1139
1367
|
parseRow(row) {
|
|
1140
1368
|
let content = row.content;
|
|
@@ -1207,7 +1435,7 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
1207
1435
|
}) {
|
|
1208
1436
|
try {
|
|
1209
1437
|
const messages = [];
|
|
1210
|
-
const limit =
|
|
1438
|
+
const limit = this.resolveMessageLimit({ last: selectBy?.last, defaultLimit: 40 });
|
|
1211
1439
|
if (selectBy?.include?.length) {
|
|
1212
1440
|
const includeMessages = await this._getIncludedMessages({ threadId, selectBy });
|
|
1213
1441
|
if (includeMessages) {
|
|
@@ -1239,9 +1467,16 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
1239
1467
|
const list = new agent.MessageList().add(messages, "memory");
|
|
1240
1468
|
if (format === `v2`) return list.get.all.v2();
|
|
1241
1469
|
return list.get.all.v1();
|
|
1242
|
-
} catch (error) {
|
|
1243
|
-
|
|
1244
|
-
|
|
1470
|
+
} catch (error$1) {
|
|
1471
|
+
throw new error.MastraError(
|
|
1472
|
+
{
|
|
1473
|
+
id: "LIBSQL_STORE_GET_MESSAGES_FAILED",
|
|
1474
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1475
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1476
|
+
details: { threadId }
|
|
1477
|
+
},
|
|
1478
|
+
error$1
|
|
1479
|
+
);
|
|
1245
1480
|
}
|
|
1246
1481
|
}
|
|
1247
1482
|
async getMessagesPaginated(args) {
|
|
@@ -1251,9 +1486,21 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
1251
1486
|
const toDate = dateRange?.end;
|
|
1252
1487
|
const messages = [];
|
|
1253
1488
|
if (selectBy?.include?.length) {
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1489
|
+
try {
|
|
1490
|
+
const includeMessages = await this._getIncludedMessages({ threadId, selectBy });
|
|
1491
|
+
if (includeMessages) {
|
|
1492
|
+
messages.push(...includeMessages);
|
|
1493
|
+
}
|
|
1494
|
+
} catch (error$1) {
|
|
1495
|
+
throw new error.MastraError(
|
|
1496
|
+
{
|
|
1497
|
+
id: "LIBSQL_STORE_GET_MESSAGES_PAGINATED_GET_INCLUDE_MESSAGES_FAILED",
|
|
1498
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1499
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1500
|
+
details: { threadId }
|
|
1501
|
+
},
|
|
1502
|
+
error$1
|
|
1503
|
+
);
|
|
1257
1504
|
}
|
|
1258
1505
|
}
|
|
1259
1506
|
try {
|
|
@@ -1296,8 +1543,18 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
1296
1543
|
perPage,
|
|
1297
1544
|
hasMore: currentOffset + messages.length < total
|
|
1298
1545
|
};
|
|
1299
|
-
} catch (error) {
|
|
1300
|
-
|
|
1546
|
+
} catch (error$1) {
|
|
1547
|
+
const mastraError = new error.MastraError(
|
|
1548
|
+
{
|
|
1549
|
+
id: "LIBSQL_STORE_GET_MESSAGES_PAGINATED_FAILED",
|
|
1550
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1551
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1552
|
+
details: { threadId }
|
|
1553
|
+
},
|
|
1554
|
+
error$1
|
|
1555
|
+
);
|
|
1556
|
+
this.logger?.trackException?.(mastraError);
|
|
1557
|
+
this.logger?.error?.(mastraError.toString());
|
|
1301
1558
|
return { messages: [], total: 0, page, perPage, hasMore: false };
|
|
1302
1559
|
}
|
|
1303
1560
|
}
|
|
@@ -1346,10 +1603,95 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
1346
1603
|
const list = new agent.MessageList().add(messages, "memory");
|
|
1347
1604
|
if (format === `v2`) return list.get.all.v2();
|
|
1348
1605
|
return list.get.all.v1();
|
|
1349
|
-
} catch (error) {
|
|
1350
|
-
|
|
1351
|
-
|
|
1606
|
+
} catch (error$1) {
|
|
1607
|
+
throw new error.MastraError(
|
|
1608
|
+
{
|
|
1609
|
+
id: "LIBSQL_STORE_SAVE_MESSAGES_FAILED",
|
|
1610
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1611
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
1612
|
+
},
|
|
1613
|
+
error$1
|
|
1614
|
+
);
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
async updateMessages({
|
|
1618
|
+
messages
|
|
1619
|
+
}) {
|
|
1620
|
+
if (messages.length === 0) {
|
|
1621
|
+
return [];
|
|
1622
|
+
}
|
|
1623
|
+
const messageIds = messages.map((m) => m.id);
|
|
1624
|
+
const placeholders = messageIds.map(() => "?").join(",");
|
|
1625
|
+
const selectSql = `SELECT * FROM ${storage.TABLE_MESSAGES} WHERE id IN (${placeholders})`;
|
|
1626
|
+
const existingResult = await this.client.execute({ sql: selectSql, args: messageIds });
|
|
1627
|
+
const existingMessages = existingResult.rows.map((row) => this.parseRow(row));
|
|
1628
|
+
if (existingMessages.length === 0) {
|
|
1629
|
+
return [];
|
|
1630
|
+
}
|
|
1631
|
+
const batchStatements = [];
|
|
1632
|
+
const threadIdsToUpdate = /* @__PURE__ */ new Set();
|
|
1633
|
+
const columnMapping = {
|
|
1634
|
+
threadId: "thread_id"
|
|
1635
|
+
};
|
|
1636
|
+
for (const existingMessage of existingMessages) {
|
|
1637
|
+
const updatePayload = messages.find((m) => m.id === existingMessage.id);
|
|
1638
|
+
if (!updatePayload) continue;
|
|
1639
|
+
const { id, ...fieldsToUpdate } = updatePayload;
|
|
1640
|
+
if (Object.keys(fieldsToUpdate).length === 0) continue;
|
|
1641
|
+
threadIdsToUpdate.add(existingMessage.threadId);
|
|
1642
|
+
if (updatePayload.threadId && updatePayload.threadId !== existingMessage.threadId) {
|
|
1643
|
+
threadIdsToUpdate.add(updatePayload.threadId);
|
|
1644
|
+
}
|
|
1645
|
+
const setClauses = [];
|
|
1646
|
+
const args = [];
|
|
1647
|
+
const updatableFields = { ...fieldsToUpdate };
|
|
1648
|
+
if (updatableFields.content) {
|
|
1649
|
+
const newContent = {
|
|
1650
|
+
...existingMessage.content,
|
|
1651
|
+
...updatableFields.content,
|
|
1652
|
+
// Deep merge metadata if it exists on both
|
|
1653
|
+
...existingMessage.content?.metadata && updatableFields.content.metadata ? {
|
|
1654
|
+
metadata: {
|
|
1655
|
+
...existingMessage.content.metadata,
|
|
1656
|
+
...updatableFields.content.metadata
|
|
1657
|
+
}
|
|
1658
|
+
} : {}
|
|
1659
|
+
};
|
|
1660
|
+
setClauses.push(`${utils.parseSqlIdentifier("content", "column name")} = ?`);
|
|
1661
|
+
args.push(JSON.stringify(newContent));
|
|
1662
|
+
delete updatableFields.content;
|
|
1663
|
+
}
|
|
1664
|
+
for (const key in updatableFields) {
|
|
1665
|
+
if (Object.prototype.hasOwnProperty.call(updatableFields, key)) {
|
|
1666
|
+
const dbKey = columnMapping[key] || key;
|
|
1667
|
+
setClauses.push(`${utils.parseSqlIdentifier(dbKey, "column name")} = ?`);
|
|
1668
|
+
let value = updatableFields[key];
|
|
1669
|
+
if (typeof value === "object" && value !== null) {
|
|
1670
|
+
value = JSON.stringify(value);
|
|
1671
|
+
}
|
|
1672
|
+
args.push(value);
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
if (setClauses.length === 0) continue;
|
|
1676
|
+
args.push(id);
|
|
1677
|
+
const sql = `UPDATE ${storage.TABLE_MESSAGES} SET ${setClauses.join(", ")} WHERE id = ?`;
|
|
1678
|
+
batchStatements.push({ sql, args });
|
|
1679
|
+
}
|
|
1680
|
+
if (batchStatements.length === 0) {
|
|
1681
|
+
return existingMessages;
|
|
1682
|
+
}
|
|
1683
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1684
|
+
for (const threadId of threadIdsToUpdate) {
|
|
1685
|
+
if (threadId) {
|
|
1686
|
+
batchStatements.push({
|
|
1687
|
+
sql: `UPDATE ${storage.TABLE_THREADS} SET updatedAt = ? WHERE id = ?`,
|
|
1688
|
+
args: [now, threadId]
|
|
1689
|
+
});
|
|
1690
|
+
}
|
|
1352
1691
|
}
|
|
1692
|
+
await this.client.batch(batchStatements, "write");
|
|
1693
|
+
const updatedResult = await this.client.execute({ sql: selectSql, args: messageIds });
|
|
1694
|
+
return updatedResult.rows.map((row) => this.parseRow(row));
|
|
1353
1695
|
}
|
|
1354
1696
|
transformEvalRow(row) {
|
|
1355
1697
|
const resultValue = JSON.parse(row.result);
|
|
@@ -1380,12 +1722,19 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
1380
1722
|
args: [agentName]
|
|
1381
1723
|
});
|
|
1382
1724
|
return result.rows?.map((row) => this.transformEvalRow(row)) ?? [];
|
|
1383
|
-
} catch (error) {
|
|
1384
|
-
if (error instanceof Error && error.message.includes("no such table")) {
|
|
1725
|
+
} catch (error$1) {
|
|
1726
|
+
if (error$1 instanceof Error && error$1.message.includes("no such table")) {
|
|
1385
1727
|
return [];
|
|
1386
1728
|
}
|
|
1387
|
-
|
|
1388
|
-
|
|
1729
|
+
throw new error.MastraError(
|
|
1730
|
+
{
|
|
1731
|
+
id: "LIBSQL_STORE_GET_EVALS_BY_AGENT_NAME_FAILED",
|
|
1732
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1733
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1734
|
+
details: { agentName }
|
|
1735
|
+
},
|
|
1736
|
+
error$1
|
|
1737
|
+
);
|
|
1389
1738
|
}
|
|
1390
1739
|
}
|
|
1391
1740
|
async getEvals(options = {}) {
|
|
@@ -1412,33 +1761,44 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
1412
1761
|
queryParams.push(toDate.toISOString());
|
|
1413
1762
|
}
|
|
1414
1763
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1764
|
+
try {
|
|
1765
|
+
const countResult = await this.client.execute({
|
|
1766
|
+
sql: `SELECT COUNT(*) as count FROM ${storage.TABLE_EVALS} ${whereClause}`,
|
|
1767
|
+
args: queryParams
|
|
1768
|
+
});
|
|
1769
|
+
const total = Number(countResult.rows?.[0]?.count ?? 0);
|
|
1770
|
+
const currentOffset = page * perPage;
|
|
1771
|
+
const hasMore = currentOffset + perPage < total;
|
|
1772
|
+
if (total === 0) {
|
|
1773
|
+
return {
|
|
1774
|
+
evals: [],
|
|
1775
|
+
total: 0,
|
|
1776
|
+
page,
|
|
1777
|
+
perPage,
|
|
1778
|
+
hasMore: false
|
|
1779
|
+
};
|
|
1780
|
+
}
|
|
1781
|
+
const dataResult = await this.client.execute({
|
|
1782
|
+
sql: `SELECT * FROM ${storage.TABLE_EVALS} ${whereClause} ORDER BY created_at DESC LIMIT ? OFFSET ?`,
|
|
1783
|
+
args: [...queryParams, perPage, currentOffset]
|
|
1784
|
+
});
|
|
1423
1785
|
return {
|
|
1424
|
-
evals: [],
|
|
1425
|
-
total
|
|
1786
|
+
evals: dataResult.rows?.map((row) => this.transformEvalRow(row)) ?? [],
|
|
1787
|
+
total,
|
|
1426
1788
|
page,
|
|
1427
1789
|
perPage,
|
|
1428
|
-
hasMore
|
|
1790
|
+
hasMore
|
|
1429
1791
|
};
|
|
1792
|
+
} catch (error$1) {
|
|
1793
|
+
throw new error.MastraError(
|
|
1794
|
+
{
|
|
1795
|
+
id: "LIBSQL_STORE_GET_EVALS_FAILED",
|
|
1796
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1797
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
1798
|
+
},
|
|
1799
|
+
error$1
|
|
1800
|
+
);
|
|
1430
1801
|
}
|
|
1431
|
-
const dataResult = await this.client.execute({
|
|
1432
|
-
sql: `SELECT * FROM ${storage.TABLE_EVALS} ${whereClause} ORDER BY created_at DESC LIMIT ? OFFSET ?`,
|
|
1433
|
-
args: [...queryParams, perPage, currentOffset]
|
|
1434
|
-
});
|
|
1435
|
-
return {
|
|
1436
|
-
evals: dataResult.rows?.map((row) => this.transformEvalRow(row)) ?? [],
|
|
1437
|
-
total,
|
|
1438
|
-
page,
|
|
1439
|
-
perPage,
|
|
1440
|
-
hasMore
|
|
1441
|
-
};
|
|
1442
1802
|
}
|
|
1443
1803
|
/**
|
|
1444
1804
|
* @deprecated use getTracesPaginated instead.
|
|
@@ -1450,8 +1810,19 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
1450
1810
|
end: args.toDate
|
|
1451
1811
|
};
|
|
1452
1812
|
}
|
|
1453
|
-
|
|
1454
|
-
|
|
1813
|
+
try {
|
|
1814
|
+
const result = await this.getTracesPaginated(args);
|
|
1815
|
+
return result.traces;
|
|
1816
|
+
} catch (error$1) {
|
|
1817
|
+
throw new error.MastraError(
|
|
1818
|
+
{
|
|
1819
|
+
id: "LIBSQL_STORE_GET_TRACES_FAILED",
|
|
1820
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1821
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
1822
|
+
},
|
|
1823
|
+
error$1
|
|
1824
|
+
);
|
|
1825
|
+
}
|
|
1455
1826
|
}
|
|
1456
1827
|
async getTracesPaginated(args) {
|
|
1457
1828
|
const { name, scope, page = 0, perPage = 100, attributes, filters, dateRange } = args;
|
|
@@ -1489,49 +1860,60 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
1489
1860
|
queryArgs.push(toDate.toISOString());
|
|
1490
1861
|
}
|
|
1491
1862
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1863
|
+
try {
|
|
1864
|
+
const countResult = await this.client.execute({
|
|
1865
|
+
sql: `SELECT COUNT(*) as count FROM ${storage.TABLE_TRACES} ${whereClause}`,
|
|
1866
|
+
args: queryArgs
|
|
1867
|
+
});
|
|
1868
|
+
const total = Number(countResult.rows?.[0]?.count ?? 0);
|
|
1869
|
+
if (total === 0) {
|
|
1870
|
+
return {
|
|
1871
|
+
traces: [],
|
|
1872
|
+
total: 0,
|
|
1873
|
+
page,
|
|
1874
|
+
perPage,
|
|
1875
|
+
hasMore: false
|
|
1876
|
+
};
|
|
1877
|
+
}
|
|
1878
|
+
const dataResult = await this.client.execute({
|
|
1879
|
+
sql: `SELECT * FROM ${storage.TABLE_TRACES} ${whereClause} ORDER BY "startTime" DESC LIMIT ? OFFSET ?`,
|
|
1880
|
+
args: [...queryArgs, perPage, currentOffset]
|
|
1881
|
+
});
|
|
1882
|
+
const traces = dataResult.rows?.map(
|
|
1883
|
+
(row) => ({
|
|
1884
|
+
id: row.id,
|
|
1885
|
+
parentSpanId: row.parentSpanId,
|
|
1886
|
+
traceId: row.traceId,
|
|
1887
|
+
name: row.name,
|
|
1888
|
+
scope: row.scope,
|
|
1889
|
+
kind: row.kind,
|
|
1890
|
+
status: safelyParseJSON(row.status),
|
|
1891
|
+
events: safelyParseJSON(row.events),
|
|
1892
|
+
links: safelyParseJSON(row.links),
|
|
1893
|
+
attributes: safelyParseJSON(row.attributes),
|
|
1894
|
+
startTime: row.startTime,
|
|
1895
|
+
endTime: row.endTime,
|
|
1896
|
+
other: safelyParseJSON(row.other),
|
|
1897
|
+
createdAt: row.createdAt
|
|
1898
|
+
})
|
|
1899
|
+
) ?? [];
|
|
1498
1900
|
return {
|
|
1499
|
-
traces
|
|
1500
|
-
total
|
|
1901
|
+
traces,
|
|
1902
|
+
total,
|
|
1501
1903
|
page,
|
|
1502
1904
|
perPage,
|
|
1503
|
-
hasMore:
|
|
1905
|
+
hasMore: currentOffset + traces.length < total
|
|
1504
1906
|
};
|
|
1907
|
+
} catch (error$1) {
|
|
1908
|
+
throw new error.MastraError(
|
|
1909
|
+
{
|
|
1910
|
+
id: "LIBSQL_STORE_GET_TRACES_PAGINATED_FAILED",
|
|
1911
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1912
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
1913
|
+
},
|
|
1914
|
+
error$1
|
|
1915
|
+
);
|
|
1505
1916
|
}
|
|
1506
|
-
const dataResult = await this.client.execute({
|
|
1507
|
-
sql: `SELECT * FROM ${storage.TABLE_TRACES} ${whereClause} ORDER BY "startTime" DESC LIMIT ? OFFSET ?`,
|
|
1508
|
-
args: [...queryArgs, perPage, currentOffset]
|
|
1509
|
-
});
|
|
1510
|
-
const traces = dataResult.rows?.map(
|
|
1511
|
-
(row) => ({
|
|
1512
|
-
id: row.id,
|
|
1513
|
-
parentSpanId: row.parentSpanId,
|
|
1514
|
-
traceId: row.traceId,
|
|
1515
|
-
name: row.name,
|
|
1516
|
-
scope: row.scope,
|
|
1517
|
-
kind: row.kind,
|
|
1518
|
-
status: safelyParseJSON(row.status),
|
|
1519
|
-
events: safelyParseJSON(row.events),
|
|
1520
|
-
links: safelyParseJSON(row.links),
|
|
1521
|
-
attributes: safelyParseJSON(row.attributes),
|
|
1522
|
-
startTime: row.startTime,
|
|
1523
|
-
endTime: row.endTime,
|
|
1524
|
-
other: safelyParseJSON(row.other),
|
|
1525
|
-
createdAt: row.createdAt
|
|
1526
|
-
})
|
|
1527
|
-
) ?? [];
|
|
1528
|
-
return {
|
|
1529
|
-
traces,
|
|
1530
|
-
total,
|
|
1531
|
-
page,
|
|
1532
|
-
perPage,
|
|
1533
|
-
hasMore: currentOffset + traces.length < total
|
|
1534
|
-
};
|
|
1535
1917
|
}
|
|
1536
1918
|
async getWorkflowRuns({
|
|
1537
1919
|
workflowName,
|
|
@@ -1580,9 +1962,15 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
1580
1962
|
});
|
|
1581
1963
|
const runs = (result.rows || []).map((row) => this.parseWorkflowRun(row));
|
|
1582
1964
|
return { runs, total: total || runs.length };
|
|
1583
|
-
} catch (error) {
|
|
1584
|
-
|
|
1585
|
-
|
|
1965
|
+
} catch (error$1) {
|
|
1966
|
+
throw new error.MastraError(
|
|
1967
|
+
{
|
|
1968
|
+
id: "LIBSQL_STORE_GET_WORKFLOW_RUNS_FAILED",
|
|
1969
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1970
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
1971
|
+
},
|
|
1972
|
+
error$1
|
|
1973
|
+
);
|
|
1586
1974
|
}
|
|
1587
1975
|
}
|
|
1588
1976
|
async getWorkflowRunById({
|
|
@@ -1600,14 +1988,25 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
1600
1988
|
args.push(workflowName);
|
|
1601
1989
|
}
|
|
1602
1990
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1991
|
+
try {
|
|
1992
|
+
const result = await this.client.execute({
|
|
1993
|
+
sql: `SELECT * FROM ${storage.TABLE_WORKFLOW_SNAPSHOT} ${whereClause}`,
|
|
1994
|
+
args
|
|
1995
|
+
});
|
|
1996
|
+
if (!result.rows?.[0]) {
|
|
1997
|
+
return null;
|
|
1998
|
+
}
|
|
1999
|
+
return this.parseWorkflowRun(result.rows[0]);
|
|
2000
|
+
} catch (error$1) {
|
|
2001
|
+
throw new error.MastraError(
|
|
2002
|
+
{
|
|
2003
|
+
id: "LIBSQL_STORE_GET_WORKFLOW_RUN_BY_ID_FAILED",
|
|
2004
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2005
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
2006
|
+
},
|
|
2007
|
+
error$1
|
|
2008
|
+
);
|
|
1609
2009
|
}
|
|
1610
|
-
return this.parseWorkflowRun(result.rows[0]);
|
|
1611
2010
|
}
|
|
1612
2011
|
async hasColumn(table, column) {
|
|
1613
2012
|
const result = await this.client.execute({
|