@mastra/libsql 0.10.4-alpha.0 → 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/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
- } finally {
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
- return this.executeWriteOperationWithRetry(() => this.doUpsert(args), true);
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
- return this.executeWriteOperationWithRetry(() => this.doCreateIndex(args));
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
- return this.executeWriteOperationWithRetry(() => this.doDeleteIndex(args));
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 Error(`Failed to list vector tables: ${error.message}`);
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 Error(`Failed to describe vector table: ${e.message}`);
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 Error("No updates provided");
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
- await this.turso.execute({
766
- sql: query,
767
- args
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
- return this.executeWriteOperationWithRetry(() => this.doDeleteVector(args));
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
- return this.executeWriteOperationWithRetry(() => this._doTruncateIndex(args));
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
- this.logger.error(`Error creating table ${tableName}: ${error}`);
856
- throw error;
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
- this.logger?.error?.(
900
- `Error altering table ${tableName}: ${error instanceof Error ? error.message : String(error)}`
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
- if (e instanceof Error) {
911
- this.logger.error(e.message);
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
- const result = await this.load({
1007
- tableName: storage.TABLE_THREADS,
1008
- keys: { id: threadId }
1009
- });
1010
- if (!result) {
1011
- return null;
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
- this.logger.error(`Error getting threads for resource ${resourceId}:`, error);
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
- this.logger.error(`Error getting threads for resource ${resourceId}:`, error);
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
- await this.insert({
1098
- tableName: storage.TABLE_THREADS,
1099
- record: {
1100
- ...thread,
1101
- metadata: JSON.stringify(thread.metadata)
1102
- }
1103
- });
1104
- return thread;
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 Error(`Thread ${id} not found`);
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
- await this.client.execute({
1124
- sql: `UPDATE ${storage.TABLE_THREADS} SET title = ?, metadata = ? WHERE id = ?`,
1125
- args: [title, JSON.stringify(updatedThread.metadata), id]
1126
- });
1127
- return updatedThread;
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
- await this.client.execute({
1131
- sql: `DELETE FROM ${storage.TABLE_MESSAGES} WHERE thread_id = ?`,
1132
- args: [threadId]
1133
- });
1134
- await this.client.execute({
1135
- sql: `DELETE FROM ${storage.TABLE_THREADS} WHERE id = ?`,
1136
- args: [threadId]
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 = typeof selectBy?.last === `number` ? selectBy.last : 40;
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
- this.logger.error("Error getting messages:", error);
1244
- throw error;
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
- const includeMessages = await this._getIncludedMessages({ threadId, selectBy });
1255
- if (includeMessages) {
1256
- messages.push(...includeMessages);
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
- this.logger.error("Error getting paginated messages:", error);
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,9 +1603,15 @@ 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
- this.logger.error("Failed to save messages in database: " + error?.message);
1351
- throw error;
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
+ );
1352
1615
  }
1353
1616
  }
1354
1617
  async updateMessages({
@@ -1459,12 +1722,19 @@ var LibSQLStore = class extends storage.MastraStorage {
1459
1722
  args: [agentName]
1460
1723
  });
1461
1724
  return result.rows?.map((row) => this.transformEvalRow(row)) ?? [];
1462
- } catch (error) {
1463
- 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")) {
1464
1727
  return [];
1465
1728
  }
1466
- this.logger.error("Failed to get evals for the specified agent: " + error?.message);
1467
- throw error;
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
+ );
1468
1738
  }
1469
1739
  }
1470
1740
  async getEvals(options = {}) {
@@ -1491,33 +1761,44 @@ var LibSQLStore = class extends storage.MastraStorage {
1491
1761
  queryParams.push(toDate.toISOString());
1492
1762
  }
1493
1763
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
1494
- const countResult = await this.client.execute({
1495
- sql: `SELECT COUNT(*) as count FROM ${storage.TABLE_EVALS} ${whereClause}`,
1496
- args: queryParams
1497
- });
1498
- const total = Number(countResult.rows?.[0]?.count ?? 0);
1499
- const currentOffset = page * perPage;
1500
- const hasMore = currentOffset + perPage < total;
1501
- if (total === 0) {
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
+ });
1502
1785
  return {
1503
- evals: [],
1504
- total: 0,
1786
+ evals: dataResult.rows?.map((row) => this.transformEvalRow(row)) ?? [],
1787
+ total,
1505
1788
  page,
1506
1789
  perPage,
1507
- hasMore: false
1790
+ hasMore
1508
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
+ );
1509
1801
  }
1510
- const dataResult = await this.client.execute({
1511
- sql: `SELECT * FROM ${storage.TABLE_EVALS} ${whereClause} ORDER BY created_at DESC LIMIT ? OFFSET ?`,
1512
- args: [...queryParams, perPage, currentOffset]
1513
- });
1514
- return {
1515
- evals: dataResult.rows?.map((row) => this.transformEvalRow(row)) ?? [],
1516
- total,
1517
- page,
1518
- perPage,
1519
- hasMore
1520
- };
1521
1802
  }
1522
1803
  /**
1523
1804
  * @deprecated use getTracesPaginated instead.
@@ -1529,8 +1810,19 @@ var LibSQLStore = class extends storage.MastraStorage {
1529
1810
  end: args.toDate
1530
1811
  };
1531
1812
  }
1532
- const result = await this.getTracesPaginated(args);
1533
- return result.traces;
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
+ }
1534
1826
  }
1535
1827
  async getTracesPaginated(args) {
1536
1828
  const { name, scope, page = 0, perPage = 100, attributes, filters, dateRange } = args;
@@ -1568,49 +1860,60 @@ var LibSQLStore = class extends storage.MastraStorage {
1568
1860
  queryArgs.push(toDate.toISOString());
1569
1861
  }
1570
1862
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
1571
- const countResult = await this.client.execute({
1572
- sql: `SELECT COUNT(*) as count FROM ${storage.TABLE_TRACES} ${whereClause}`,
1573
- args: queryArgs
1574
- });
1575
- const total = Number(countResult.rows?.[0]?.count ?? 0);
1576
- if (total === 0) {
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
+ ) ?? [];
1577
1900
  return {
1578
- traces: [],
1579
- total: 0,
1901
+ traces,
1902
+ total,
1580
1903
  page,
1581
1904
  perPage,
1582
- hasMore: false
1905
+ hasMore: currentOffset + traces.length < total
1583
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
+ );
1584
1916
  }
1585
- const dataResult = await this.client.execute({
1586
- sql: `SELECT * FROM ${storage.TABLE_TRACES} ${whereClause} ORDER BY "startTime" DESC LIMIT ? OFFSET ?`,
1587
- args: [...queryArgs, perPage, currentOffset]
1588
- });
1589
- const traces = dataResult.rows?.map(
1590
- (row) => ({
1591
- id: row.id,
1592
- parentSpanId: row.parentSpanId,
1593
- traceId: row.traceId,
1594
- name: row.name,
1595
- scope: row.scope,
1596
- kind: row.kind,
1597
- status: safelyParseJSON(row.status),
1598
- events: safelyParseJSON(row.events),
1599
- links: safelyParseJSON(row.links),
1600
- attributes: safelyParseJSON(row.attributes),
1601
- startTime: row.startTime,
1602
- endTime: row.endTime,
1603
- other: safelyParseJSON(row.other),
1604
- createdAt: row.createdAt
1605
- })
1606
- ) ?? [];
1607
- return {
1608
- traces,
1609
- total,
1610
- page,
1611
- perPage,
1612
- hasMore: currentOffset + traces.length < total
1613
- };
1614
1917
  }
1615
1918
  async getWorkflowRuns({
1616
1919
  workflowName,
@@ -1659,9 +1962,15 @@ var LibSQLStore = class extends storage.MastraStorage {
1659
1962
  });
1660
1963
  const runs = (result.rows || []).map((row) => this.parseWorkflowRun(row));
1661
1964
  return { runs, total: total || runs.length };
1662
- } catch (error) {
1663
- console.error("Error getting workflow runs:", error);
1664
- throw error;
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
+ );
1665
1974
  }
1666
1975
  }
1667
1976
  async getWorkflowRunById({
@@ -1679,14 +1988,25 @@ var LibSQLStore = class extends storage.MastraStorage {
1679
1988
  args.push(workflowName);
1680
1989
  }
1681
1990
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
1682
- const result = await this.client.execute({
1683
- sql: `SELECT * FROM ${storage.TABLE_WORKFLOW_SNAPSHOT} ${whereClause}`,
1684
- args
1685
- });
1686
- if (!result.rows?.[0]) {
1687
- return null;
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
+ );
1688
2009
  }
1689
- return this.parseWorkflowRun(result.rows[0]);
1690
2010
  }
1691
2011
  async hasColumn(table, column) {
1692
2012
  const result = await this.client.execute({