@mastra/libsql 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/dist/index.cjs CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  var client = require('@libsql/client');
4
4
  var error = require('@mastra/core/error');
5
+ var storage = require('@mastra/core/storage');
5
6
  var utils = require('@mastra/core/utils');
6
7
  var vector = require('@mastra/core/vector');
7
8
  var filter = require('@mastra/core/vector/filter');
8
- var storage = require('@mastra/core/storage');
9
9
  var agent = require('@mastra/core/agent');
10
10
  var evals = require('@mastra/core/evals');
11
11
 
@@ -583,7 +583,7 @@ var LibSQLVector = class extends vector.MastraVector {
583
583
  } catch (error$1) {
584
584
  throw new error.MastraError(
585
585
  {
586
- id: "LIBSQL_VECTOR_QUERY_INVALID_ARGS",
586
+ id: storage.createVectorErrorId("LIBSQL", "QUERY", "INVALID_ARGS"),
587
587
  domain: error.ErrorDomain.STORAGE,
588
588
  category: error.ErrorCategory.USER
589
589
  },
@@ -625,7 +625,7 @@ var LibSQLVector = class extends vector.MastraVector {
625
625
  } catch (error$1) {
626
626
  throw new error.MastraError(
627
627
  {
628
- id: "LIBSQL_VECTOR_QUERY_FAILED",
628
+ id: storage.createVectorErrorId("LIBSQL", "QUERY", "FAILED"),
629
629
  domain: error.ErrorDomain.STORAGE,
630
630
  category: error.ErrorCategory.THIRD_PARTY
631
631
  },
@@ -639,7 +639,7 @@ var LibSQLVector = class extends vector.MastraVector {
639
639
  } catch (error$1) {
640
640
  throw new error.MastraError(
641
641
  {
642
- id: "LIBSQL_VECTOR_UPSERT_FAILED",
642
+ id: storage.createVectorErrorId("LIBSQL", "UPSERT", "FAILED"),
643
643
  domain: error.ErrorDomain.STORAGE,
644
644
  category: error.ErrorCategory.THIRD_PARTY
645
645
  },
@@ -693,7 +693,7 @@ var LibSQLVector = class extends vector.MastraVector {
693
693
  } catch (error$1) {
694
694
  throw new error.MastraError(
695
695
  {
696
- id: "LIBSQL_VECTOR_CREATE_INDEX_FAILED",
696
+ id: storage.createVectorErrorId("LIBSQL", "CREATE_INDEX", "FAILED"),
697
697
  domain: error.ErrorDomain.STORAGE,
698
698
  category: error.ErrorCategory.THIRD_PARTY,
699
699
  details: { indexName: args.indexName, dimension: args.dimension }
@@ -732,7 +732,7 @@ var LibSQLVector = class extends vector.MastraVector {
732
732
  } catch (error$1) {
733
733
  throw new error.MastraError(
734
734
  {
735
- id: "LIBSQL_VECTOR_DELETE_INDEX_FAILED",
735
+ id: storage.createVectorErrorId("LIBSQL", "DELETE_INDEX", "FAILED"),
736
736
  domain: error.ErrorDomain.STORAGE,
737
737
  category: error.ErrorCategory.THIRD_PARTY,
738
738
  details: { indexName: args.indexName }
@@ -763,7 +763,7 @@ var LibSQLVector = class extends vector.MastraVector {
763
763
  } catch (error$1) {
764
764
  throw new error.MastraError(
765
765
  {
766
- id: "LIBSQL_VECTOR_LIST_INDEXES_FAILED",
766
+ id: storage.createVectorErrorId("LIBSQL", "LIST_INDEXES", "FAILED"),
767
767
  domain: error.ErrorDomain.STORAGE,
768
768
  category: error.ErrorCategory.THIRD_PARTY
769
769
  },
@@ -811,7 +811,7 @@ var LibSQLVector = class extends vector.MastraVector {
811
811
  } catch (e) {
812
812
  throw new error.MastraError(
813
813
  {
814
- id: "LIBSQL_VECTOR_DESCRIBE_INDEX_FAILED",
814
+ id: storage.createVectorErrorId("LIBSQL", "DESCRIBE_INDEX", "FAILED"),
815
815
  domain: error.ErrorDomain.STORAGE,
816
816
  category: error.ErrorCategory.THIRD_PARTY,
817
817
  details: { indexName }
@@ -839,7 +839,7 @@ var LibSQLVector = class extends vector.MastraVector {
839
839
  const parsedIndexName = utils.parseSqlIdentifier(indexName, "index name");
840
840
  if ("id" in params && params.id && "filter" in params && params.filter) {
841
841
  throw new error.MastraError({
842
- id: "LIBSQL_VECTOR_UPDATE_MUTUALLY_EXCLUSIVE_PARAMS",
842
+ id: storage.createVectorErrorId("LIBSQL", "UPDATE_VECTOR", "MUTUALLY_EXCLUSIVE"),
843
843
  domain: error.ErrorDomain.STORAGE,
844
844
  category: error.ErrorCategory.USER,
845
845
  details: { indexName },
@@ -848,7 +848,7 @@ var LibSQLVector = class extends vector.MastraVector {
848
848
  }
849
849
  if (!update.vector && !update.metadata) {
850
850
  throw new error.MastraError({
851
- id: "LIBSQL_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
851
+ id: storage.createVectorErrorId("LIBSQL", "UPDATE_VECTOR", "NO_PAYLOAD"),
852
852
  domain: error.ErrorDomain.STORAGE,
853
853
  category: error.ErrorCategory.USER,
854
854
  details: { indexName },
@@ -877,7 +877,7 @@ var LibSQLVector = class extends vector.MastraVector {
877
877
  const filter = params.filter;
878
878
  if (!filter || Object.keys(filter).length === 0) {
879
879
  throw new error.MastraError({
880
- id: "LIBSQL_VECTOR_UPDATE_EMPTY_FILTER",
880
+ id: storage.createVectorErrorId("LIBSQL", "UPDATE_VECTOR", "EMPTY_FILTER"),
881
881
  domain: error.ErrorDomain.STORAGE,
882
882
  category: error.ErrorCategory.USER,
883
883
  details: { indexName },
@@ -888,7 +888,7 @@ var LibSQLVector = class extends vector.MastraVector {
888
888
  const { sql: filterSql, values: filterValues } = buildFilterQuery(translatedFilter);
889
889
  if (!filterSql || filterSql.trim() === "") {
890
890
  throw new error.MastraError({
891
- id: "LIBSQL_VECTOR_UPDATE_INVALID_FILTER",
891
+ id: storage.createVectorErrorId("LIBSQL", "UPDATE_VECTOR", "INVALID_FILTER"),
892
892
  domain: error.ErrorDomain.STORAGE,
893
893
  category: error.ErrorCategory.USER,
894
894
  details: { indexName },
@@ -899,7 +899,7 @@ var LibSQLVector = class extends vector.MastraVector {
899
899
  const matchAllPatterns = ["true", "1 = 1", "1=1"];
900
900
  if (matchAllPatterns.includes(normalizedCondition)) {
901
901
  throw new error.MastraError({
902
- id: "LIBSQL_VECTOR_UPDATE_MATCH_ALL_FILTER",
902
+ id: storage.createVectorErrorId("LIBSQL", "UPDATE_VECTOR", "MATCH_ALL_FILTER"),
903
903
  domain: error.ErrorDomain.STORAGE,
904
904
  category: error.ErrorCategory.USER,
905
905
  details: { indexName, filterSql: normalizedCondition },
@@ -910,7 +910,7 @@ var LibSQLVector = class extends vector.MastraVector {
910
910
  whereValues = filterValues;
911
911
  } else {
912
912
  throw new error.MastraError({
913
- id: "LIBSQL_VECTOR_UPDATE_MISSING_PARAMS",
913
+ id: storage.createVectorErrorId("LIBSQL", "UPDATE_VECTOR", "NO_TARGET"),
914
914
  domain: error.ErrorDomain.STORAGE,
915
915
  category: error.ErrorCategory.USER,
916
916
  details: { indexName },
@@ -937,7 +937,7 @@ var LibSQLVector = class extends vector.MastraVector {
937
937
  }
938
938
  throw new error.MastraError(
939
939
  {
940
- id: "LIBSQL_VECTOR_UPDATE_VECTOR_FAILED",
940
+ id: storage.createVectorErrorId("LIBSQL", "UPDATE_VECTOR", "FAILED"),
941
941
  domain: error.ErrorDomain.STORAGE,
942
942
  category: error.ErrorCategory.THIRD_PARTY,
943
943
  details: errorDetails
@@ -959,7 +959,7 @@ var LibSQLVector = class extends vector.MastraVector {
959
959
  } catch (error$1) {
960
960
  throw new error.MastraError(
961
961
  {
962
- id: "LIBSQL_VECTOR_DELETE_VECTOR_FAILED",
962
+ id: storage.createVectorErrorId("LIBSQL", "DELETE_VECTOR", "FAILED"),
963
963
  domain: error.ErrorDomain.STORAGE,
964
964
  category: error.ErrorCategory.THIRD_PARTY,
965
965
  details: {
@@ -985,7 +985,7 @@ var LibSQLVector = class extends vector.MastraVector {
985
985
  const parsedIndexName = utils.parseSqlIdentifier(indexName, "index name");
986
986
  if (!filter && !ids) {
987
987
  throw new error.MastraError({
988
- id: "LIBSQL_VECTOR_DELETE_MISSING_PARAMS",
988
+ id: storage.createVectorErrorId("LIBSQL", "DELETE_VECTORS", "NO_TARGET"),
989
989
  domain: error.ErrorDomain.STORAGE,
990
990
  category: error.ErrorCategory.USER,
991
991
  details: { indexName },
@@ -994,7 +994,7 @@ var LibSQLVector = class extends vector.MastraVector {
994
994
  }
995
995
  if (filter && ids) {
996
996
  throw new error.MastraError({
997
- id: "LIBSQL_VECTOR_DELETE_CONFLICTING_PARAMS",
997
+ id: storage.createVectorErrorId("LIBSQL", "DELETE_VECTORS", "MUTUALLY_EXCLUSIVE"),
998
998
  domain: error.ErrorDomain.STORAGE,
999
999
  category: error.ErrorCategory.USER,
1000
1000
  details: { indexName },
@@ -1006,7 +1006,7 @@ var LibSQLVector = class extends vector.MastraVector {
1006
1006
  if (ids) {
1007
1007
  if (ids.length === 0) {
1008
1008
  throw new error.MastraError({
1009
- id: "LIBSQL_VECTOR_DELETE_EMPTY_IDS",
1009
+ id: storage.createVectorErrorId("LIBSQL", "DELETE_VECTORS", "EMPTY_IDS"),
1010
1010
  domain: error.ErrorDomain.STORAGE,
1011
1011
  category: error.ErrorCategory.USER,
1012
1012
  details: { indexName },
@@ -1019,7 +1019,7 @@ var LibSQLVector = class extends vector.MastraVector {
1019
1019
  } else {
1020
1020
  if (!filter || Object.keys(filter).length === 0) {
1021
1021
  throw new error.MastraError({
1022
- id: "LIBSQL_VECTOR_DELETE_EMPTY_FILTER",
1022
+ id: storage.createVectorErrorId("LIBSQL", "DELETE_VECTORS", "EMPTY_FILTER"),
1023
1023
  domain: error.ErrorDomain.STORAGE,
1024
1024
  category: error.ErrorCategory.USER,
1025
1025
  details: { indexName },
@@ -1030,7 +1030,7 @@ var LibSQLVector = class extends vector.MastraVector {
1030
1030
  const { sql: filterSql, values: filterValues } = buildFilterQuery(translatedFilter);
1031
1031
  if (!filterSql || filterSql.trim() === "") {
1032
1032
  throw new error.MastraError({
1033
- id: "LIBSQL_VECTOR_DELETE_INVALID_FILTER",
1033
+ id: storage.createVectorErrorId("LIBSQL", "DELETE_VECTORS", "INVALID_FILTER"),
1034
1034
  domain: error.ErrorDomain.STORAGE,
1035
1035
  category: error.ErrorCategory.USER,
1036
1036
  details: { indexName },
@@ -1041,7 +1041,7 @@ var LibSQLVector = class extends vector.MastraVector {
1041
1041
  const matchAllPatterns = ["true", "1 = 1", "1=1"];
1042
1042
  if (matchAllPatterns.includes(normalizedCondition)) {
1043
1043
  throw new error.MastraError({
1044
- id: "LIBSQL_VECTOR_DELETE_MATCH_ALL_FILTER",
1044
+ id: storage.createVectorErrorId("LIBSQL", "DELETE_VECTORS", "MATCH_ALL_FILTER"),
1045
1045
  domain: error.ErrorDomain.STORAGE,
1046
1046
  category: error.ErrorCategory.USER,
1047
1047
  details: { indexName, filterSql: normalizedCondition },
@@ -1059,7 +1059,7 @@ var LibSQLVector = class extends vector.MastraVector {
1059
1059
  } catch (error$1) {
1060
1060
  throw new error.MastraError(
1061
1061
  {
1062
- id: "LIBSQL_VECTOR_DELETE_VECTORS_FAILED",
1062
+ id: storage.createVectorErrorId("LIBSQL", "DELETE_VECTORS", "FAILED"),
1063
1063
  domain: error.ErrorDomain.STORAGE,
1064
1064
  category: error.ErrorCategory.THIRD_PARTY,
1065
1065
  details: {
@@ -1078,7 +1078,7 @@ var LibSQLVector = class extends vector.MastraVector {
1078
1078
  } catch (error$1) {
1079
1079
  throw new error.MastraError(
1080
1080
  {
1081
- id: "LIBSQL_VECTOR_TRUNCATE_INDEX_FAILED",
1081
+ id: storage.createVectorErrorId("LIBSQL", "TRUNCATE_INDEX", "FAILED"),
1082
1082
  domain: error.ErrorDomain.STORAGE,
1083
1083
  category: error.ErrorCategory.THIRD_PARTY,
1084
1084
  details: { indexName: args.indexName }
@@ -1119,26 +1119,24 @@ var MemoryLibSQL = class extends storage.MemoryStorage {
1119
1119
  if (row.type && row.type !== `v2`) result.type = row.type;
1120
1120
  return result;
1121
1121
  }
1122
- async _getIncludedMessages({
1123
- threadId,
1124
- include
1125
- }) {
1126
- if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
1127
- if (!include) return null;
1122
+ async _getIncludedMessages({ include }) {
1123
+ if (!include || include.length === 0) return null;
1128
1124
  const unionQueries = [];
1129
1125
  const params = [];
1130
1126
  for (const inc of include) {
1131
1127
  const { id, withPreviousMessages = 0, withNextMessages = 0 } = inc;
1132
- const searchId = inc.threadId || threadId;
1133
1128
  unionQueries.push(
1134
1129
  `
1135
1130
  SELECT * FROM (
1136
- WITH numbered_messages AS (
1131
+ WITH target_thread AS (
1132
+ SELECT thread_id FROM "${storage.TABLE_MESSAGES}" WHERE id = ?
1133
+ ),
1134
+ numbered_messages AS (
1137
1135
  SELECT
1138
1136
  id, content, role, type, "createdAt", thread_id, "resourceId",
1139
1137
  ROW_NUMBER() OVER (ORDER BY "createdAt" ASC) as row_num
1140
1138
  FROM "${storage.TABLE_MESSAGES}"
1141
- WHERE thread_id = ?
1139
+ WHERE thread_id = (SELECT thread_id FROM target_thread)
1142
1140
  ),
1143
1141
  target_positions AS (
1144
1142
  SELECT row_num as target_pos
@@ -1153,7 +1151,7 @@ var MemoryLibSQL = class extends storage.MemoryStorage {
1153
1151
  `
1154
1152
  // Keep ASC for final sorting after fetching context
1155
1153
  );
1156
- params.push(searchId, id, withPreviousMessages, withNextMessages);
1154
+ params.push(id, id, withPreviousMessages, withNextMessages);
1157
1155
  }
1158
1156
  const finalQuery = unionQueries.join(" UNION ALL ") + ' ORDER BY "createdAt" ASC';
1159
1157
  const includedResult = await this.client.execute({ sql: finalQuery, args: params });
@@ -1189,7 +1187,7 @@ var MemoryLibSQL = class extends storage.MemoryStorage {
1189
1187
  } catch (error$1) {
1190
1188
  throw new error.MastraError(
1191
1189
  {
1192
- id: "LIBSQL_STORE_LIST_MESSAGES_BY_ID_FAILED",
1190
+ id: storage.createStorageErrorId("LIBSQL", "LIST_MESSAGES_BY_ID", "FAILED"),
1193
1191
  domain: error.ErrorDomain.STORAGE,
1194
1192
  category: error.ErrorCategory.THIRD_PARTY,
1195
1193
  details: { messageIds: JSON.stringify(messageIds) }
@@ -1200,21 +1198,22 @@ var MemoryLibSQL = class extends storage.MemoryStorage {
1200
1198
  }
1201
1199
  async listMessages(args) {
1202
1200
  const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
1203
- if (!threadId.trim()) {
1201
+ const threadIds = Array.isArray(threadId) ? threadId : [threadId];
1202
+ if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
1204
1203
  throw new error.MastraError(
1205
1204
  {
1206
- id: "STORAGE_LIBSQL_LIST_MESSAGES_INVALID_THREAD_ID",
1205
+ id: storage.createStorageErrorId("LIBSQL", "LIST_MESSAGES", "INVALID_THREAD_ID"),
1207
1206
  domain: error.ErrorDomain.STORAGE,
1208
1207
  category: error.ErrorCategory.THIRD_PARTY,
1209
- details: { threadId }
1208
+ details: { threadId: Array.isArray(threadId) ? threadId.join(",") : threadId }
1210
1209
  },
1211
- new Error("threadId must be a non-empty string")
1210
+ new Error("threadId must be a non-empty string or array of non-empty strings")
1212
1211
  );
1213
1212
  }
1214
1213
  if (page < 0) {
1215
1214
  throw new error.MastraError(
1216
1215
  {
1217
- id: "LIBSQL_STORE_LIST_MESSAGES_INVALID_PAGE",
1216
+ id: storage.createStorageErrorId("LIBSQL", "LIST_MESSAGES", "INVALID_PAGE"),
1218
1217
  domain: error.ErrorDomain.STORAGE,
1219
1218
  category: error.ErrorCategory.USER,
1220
1219
  details: { page }
@@ -1227,8 +1226,9 @@ var MemoryLibSQL = class extends storage.MemoryStorage {
1227
1226
  try {
1228
1227
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
1229
1228
  const orderByStatement = `ORDER BY "${field}" ${direction}`;
1230
- const conditions = [`thread_id = ?`];
1231
- const queryParams = [threadId];
1229
+ const threadPlaceholders = threadIds.map(() => "?").join(", ");
1230
+ const conditions = [`thread_id IN (${threadPlaceholders})`];
1231
+ const queryParams = [...threadIds];
1232
1232
  if (resourceId) {
1233
1233
  conditions.push(`"resourceId" = ?`);
1234
1234
  queryParams.push(resourceId);
@@ -1268,7 +1268,7 @@ var MemoryLibSQL = class extends storage.MemoryStorage {
1268
1268
  }
1269
1269
  const messageIds = new Set(messages.map((m) => m.id));
1270
1270
  if (include && include.length > 0) {
1271
- const includeMessages = await this._getIncludedMessages({ threadId, include });
1271
+ const includeMessages = await this._getIncludedMessages({ include });
1272
1272
  if (includeMessages) {
1273
1273
  for (const includeMsg of includeMessages) {
1274
1274
  if (!messageIds.has(includeMsg.id)) {
@@ -1289,7 +1289,10 @@ var MemoryLibSQL = class extends storage.MemoryStorage {
1289
1289
  }
1290
1290
  return direction === "ASC" ? String(aValue).localeCompare(String(bValue)) : String(bValue).localeCompare(String(aValue));
1291
1291
  });
1292
- const returnedThreadMessageIds = new Set(finalMessages.filter((m) => m.threadId === threadId).map((m) => m.id));
1292
+ const threadIdSet = new Set(threadIds);
1293
+ const returnedThreadMessageIds = new Set(
1294
+ finalMessages.filter((m) => m.threadId && threadIdSet.has(m.threadId)).map((m) => m.id)
1295
+ );
1293
1296
  const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
1294
1297
  const hasMore = perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total;
1295
1298
  return {
@@ -1302,11 +1305,11 @@ var MemoryLibSQL = class extends storage.MemoryStorage {
1302
1305
  } catch (error$1) {
1303
1306
  const mastraError = new error.MastraError(
1304
1307
  {
1305
- id: "LIBSQL_STORE_LIST_MESSAGES_FAILED",
1308
+ id: storage.createStorageErrorId("LIBSQL", "LIST_MESSAGES", "FAILED"),
1306
1309
  domain: error.ErrorDomain.STORAGE,
1307
1310
  category: error.ErrorCategory.THIRD_PARTY,
1308
1311
  details: {
1309
- threadId,
1312
+ threadId: Array.isArray(threadId) ? threadId.join(",") : threadId,
1310
1313
  resourceId: resourceId ?? ""
1311
1314
  }
1312
1315
  },
@@ -1385,7 +1388,7 @@ var MemoryLibSQL = class extends storage.MemoryStorage {
1385
1388
  } catch (error$1) {
1386
1389
  throw new error.MastraError(
1387
1390
  {
1388
- id: "LIBSQL_STORE_SAVE_MESSAGES_FAILED",
1391
+ id: storage.createStorageErrorId("LIBSQL", "SAVE_MESSAGES", "FAILED"),
1389
1392
  domain: error.ErrorDomain.STORAGE,
1390
1393
  category: error.ErrorCategory.THIRD_PARTY
1391
1394
  },
@@ -1513,7 +1516,7 @@ var MemoryLibSQL = class extends storage.MemoryStorage {
1513
1516
  } catch (error$1) {
1514
1517
  throw new error.MastraError(
1515
1518
  {
1516
- id: "LIBSQL_STORE_DELETE_MESSAGES_FAILED",
1519
+ id: storage.createStorageErrorId("LIBSQL", "DELETE_MESSAGES", "FAILED"),
1517
1520
  domain: error.ErrorDomain.STORAGE,
1518
1521
  category: error.ErrorCategory.THIRD_PARTY,
1519
1522
  details: { messageIds: messageIds.join(", ") }
@@ -1611,7 +1614,7 @@ var MemoryLibSQL = class extends storage.MemoryStorage {
1611
1614
  } catch (error$1) {
1612
1615
  throw new error.MastraError(
1613
1616
  {
1614
- id: "LIBSQL_STORE_GET_THREAD_BY_ID_FAILED",
1617
+ id: storage.createStorageErrorId("LIBSQL", "GET_THREAD_BY_ID", "FAILED"),
1615
1618
  domain: error.ErrorDomain.STORAGE,
1616
1619
  category: error.ErrorCategory.THIRD_PARTY,
1617
1620
  details: { threadId }
@@ -1625,7 +1628,7 @@ var MemoryLibSQL = class extends storage.MemoryStorage {
1625
1628
  if (page < 0) {
1626
1629
  throw new error.MastraError(
1627
1630
  {
1628
- id: "LIBSQL_STORE_LIST_THREADS_BY_RESOURCE_ID_INVALID_PAGE",
1631
+ id: storage.createStorageErrorId("LIBSQL", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
1629
1632
  domain: error.ErrorDomain.STORAGE,
1630
1633
  category: error.ErrorCategory.USER,
1631
1634
  details: { page }
@@ -1679,7 +1682,7 @@ var MemoryLibSQL = class extends storage.MemoryStorage {
1679
1682
  } catch (error$1) {
1680
1683
  const mastraError = new error.MastraError(
1681
1684
  {
1682
- id: "LIBSQL_STORE_LIST_THREADS_BY_RESOURCE_ID_FAILED",
1685
+ id: storage.createStorageErrorId("LIBSQL", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
1683
1686
  domain: error.ErrorDomain.STORAGE,
1684
1687
  category: error.ErrorCategory.THIRD_PARTY,
1685
1688
  details: { resourceId }
@@ -1710,7 +1713,7 @@ var MemoryLibSQL = class extends storage.MemoryStorage {
1710
1713
  } catch (error$1) {
1711
1714
  const mastraError = new error.MastraError(
1712
1715
  {
1713
- id: "LIBSQL_STORE_SAVE_THREAD_FAILED",
1716
+ id: storage.createStorageErrorId("LIBSQL", "SAVE_THREAD", "FAILED"),
1714
1717
  domain: error.ErrorDomain.STORAGE,
1715
1718
  category: error.ErrorCategory.THIRD_PARTY,
1716
1719
  details: { threadId: thread.id }
@@ -1730,7 +1733,7 @@ var MemoryLibSQL = class extends storage.MemoryStorage {
1730
1733
  const thread = await this.getThreadById({ threadId: id });
1731
1734
  if (!thread) {
1732
1735
  throw new error.MastraError({
1733
- id: "LIBSQL_STORE_UPDATE_THREAD_FAILED_THREAD_NOT_FOUND",
1736
+ id: storage.createStorageErrorId("LIBSQL", "UPDATE_THREAD", "NOT_FOUND"),
1734
1737
  domain: error.ErrorDomain.STORAGE,
1735
1738
  category: error.ErrorCategory.USER,
1736
1739
  text: `Thread ${id} not found`,
@@ -1757,7 +1760,7 @@ var MemoryLibSQL = class extends storage.MemoryStorage {
1757
1760
  } catch (error$1) {
1758
1761
  throw new error.MastraError(
1759
1762
  {
1760
- id: "LIBSQL_STORE_UPDATE_THREAD_FAILED",
1763
+ id: storage.createStorageErrorId("LIBSQL", "UPDATE_THREAD", "FAILED"),
1761
1764
  domain: error.ErrorDomain.STORAGE,
1762
1765
  category: error.ErrorCategory.THIRD_PARTY,
1763
1766
  text: `Failed to update thread ${id}`,
@@ -1780,7 +1783,7 @@ var MemoryLibSQL = class extends storage.MemoryStorage {
1780
1783
  } catch (error$1) {
1781
1784
  throw new error.MastraError(
1782
1785
  {
1783
- id: "LIBSQL_STORE_DELETE_THREAD_FAILED",
1786
+ id: storage.createStorageErrorId("LIBSQL", "DELETE_THREAD", "FAILED"),
1784
1787
  domain: error.ErrorDomain.STORAGE,
1785
1788
  category: error.ErrorCategory.THIRD_PARTY,
1786
1789
  details: { threadId }
@@ -1977,7 +1980,7 @@ var ObservabilityLibSQL = class extends storage.ObservabilityStorage {
1977
1980
  } catch (error$1) {
1978
1981
  throw new error.MastraError(
1979
1982
  {
1980
- id: "LIBSQL_STORE_CREATE_SPAN_FAILED",
1983
+ id: storage.createStorageErrorId("LIBSQL", "CREATE_SPAN", "FAILED"),
1981
1984
  domain: error.ErrorDomain.STORAGE,
1982
1985
  category: error.ErrorCategory.USER,
1983
1986
  details: {
@@ -2008,7 +2011,7 @@ var ObservabilityLibSQL = class extends storage.ObservabilityStorage {
2008
2011
  } catch (error$1) {
2009
2012
  throw new error.MastraError(
2010
2013
  {
2011
- id: "LIBSQL_STORE_GET_TRACE_FAILED",
2014
+ id: storage.createStorageErrorId("LIBSQL", "GET_TRACE", "FAILED"),
2012
2015
  domain: error.ErrorDomain.STORAGE,
2013
2016
  category: error.ErrorCategory.USER,
2014
2017
  details: {
@@ -2033,7 +2036,7 @@ var ObservabilityLibSQL = class extends storage.ObservabilityStorage {
2033
2036
  } catch (error$1) {
2034
2037
  throw new error.MastraError(
2035
2038
  {
2036
- id: "LIBSQL_STORE_UPDATE_SPAN_FAILED",
2039
+ id: storage.createStorageErrorId("LIBSQL", "UPDATE_SPAN", "FAILED"),
2037
2040
  domain: error.ErrorDomain.STORAGE,
2038
2041
  category: error.ErrorCategory.USER,
2039
2042
  details: {
@@ -2068,7 +2071,7 @@ var ObservabilityLibSQL = class extends storage.ObservabilityStorage {
2068
2071
  name = `agent run: '${entityId}'`;
2069
2072
  } else {
2070
2073
  const error$1 = new error.MastraError({
2071
- id: "LIBSQL_STORE_GET_TRACES_PAGINATED_FAILED",
2074
+ id: storage.createStorageErrorId("LIBSQL", "GET_TRACES_PAGINATED", "INVALID_ENTITY_TYPE"),
2072
2075
  domain: error.ErrorDomain.STORAGE,
2073
2076
  category: error.ErrorCategory.USER,
2074
2077
  details: {
@@ -2096,7 +2099,7 @@ var ObservabilityLibSQL = class extends storage.ObservabilityStorage {
2096
2099
  } catch (error$1) {
2097
2100
  throw new error.MastraError(
2098
2101
  {
2099
- id: "LIBSQL_STORE_GET_TRACES_PAGINATED_COUNT_FAILED",
2102
+ id: storage.createStorageErrorId("LIBSQL", "GET_TRACES_PAGINATED", "COUNT_FAILED"),
2100
2103
  domain: error.ErrorDomain.STORAGE,
2101
2104
  category: error.ErrorCategory.USER
2102
2105
  },
@@ -2137,7 +2140,7 @@ var ObservabilityLibSQL = class extends storage.ObservabilityStorage {
2137
2140
  } catch (error$1) {
2138
2141
  throw new error.MastraError(
2139
2142
  {
2140
- id: "LIBSQL_STORE_GET_TRACES_PAGINATED_FAILED",
2143
+ id: storage.createStorageErrorId("LIBSQL", "GET_TRACES_PAGINATED", "FAILED"),
2141
2144
  domain: error.ErrorDomain.STORAGE,
2142
2145
  category: error.ErrorCategory.USER
2143
2146
  },
@@ -2159,7 +2162,7 @@ var ObservabilityLibSQL = class extends storage.ObservabilityStorage {
2159
2162
  } catch (error$1) {
2160
2163
  throw new error.MastraError(
2161
2164
  {
2162
- id: "LIBSQL_STORE_BATCH_CREATE_SPANS_FAILED",
2165
+ id: storage.createStorageErrorId("LIBSQL", "BATCH_CREATE_SPANS", "FAILED"),
2163
2166
  domain: error.ErrorDomain.STORAGE,
2164
2167
  category: error.ErrorCategory.USER
2165
2168
  },
@@ -2179,7 +2182,7 @@ var ObservabilityLibSQL = class extends storage.ObservabilityStorage {
2179
2182
  } catch (error$1) {
2180
2183
  throw new error.MastraError(
2181
2184
  {
2182
- id: "LIBSQL_STORE_BATCH_UPDATE_SPANS_FAILED",
2185
+ id: storage.createStorageErrorId("LIBSQL", "BATCH_UPDATE_SPANS", "FAILED"),
2183
2186
  domain: error.ErrorDomain.STORAGE,
2184
2187
  category: error.ErrorCategory.USER
2185
2188
  },
@@ -2197,7 +2200,7 @@ var ObservabilityLibSQL = class extends storage.ObservabilityStorage {
2197
2200
  } catch (error$1) {
2198
2201
  throw new error.MastraError(
2199
2202
  {
2200
- id: "LIBSQL_STORE_BATCH_DELETE_TRACES_FAILED",
2203
+ id: storage.createStorageErrorId("LIBSQL", "BATCH_DELETE_TRACES", "FAILED"),
2201
2204
  domain: error.ErrorDomain.STORAGE,
2202
2205
  category: error.ErrorCategory.USER
2203
2206
  },
@@ -2273,7 +2276,7 @@ var StoreOperationsLibSQL = class extends storage.StoreOperations {
2273
2276
  } catch (error$1) {
2274
2277
  throw new error.MastraError(
2275
2278
  {
2276
- id: "LIBSQL_STORE_CREATE_TABLE_FAILED",
2279
+ id: storage.createStorageErrorId("LIBSQL", "CREATE_TABLE", "FAILED"),
2277
2280
  domain: error.ErrorDomain.STORAGE,
2278
2281
  category: error.ErrorCategory.THIRD_PARTY,
2279
2282
  details: {
@@ -2417,7 +2420,7 @@ var StoreOperationsLibSQL = class extends storage.StoreOperations {
2417
2420
  ).catch((error$1) => {
2418
2421
  throw new error.MastraError(
2419
2422
  {
2420
- id: "LIBSQL_STORE_BATCH_INSERT_FAILED",
2423
+ id: storage.createStorageErrorId("LIBSQL", "BATCH_INSERT", "FAILED"),
2421
2424
  domain: error.ErrorDomain.STORAGE,
2422
2425
  category: error.ErrorCategory.THIRD_PARTY,
2423
2426
  details: {
@@ -2443,7 +2446,7 @@ var StoreOperationsLibSQL = class extends storage.StoreOperations {
2443
2446
  ).catch((error$1) => {
2444
2447
  throw new error.MastraError(
2445
2448
  {
2446
- id: "LIBSQL_STORE_BATCH_UPDATE_FAILED",
2449
+ id: storage.createStorageErrorId("LIBSQL", "BATCH_UPDATE", "FAILED"),
2447
2450
  domain: error.ErrorDomain.STORAGE,
2448
2451
  category: error.ErrorCategory.THIRD_PARTY,
2449
2452
  details: {
@@ -2486,7 +2489,7 @@ var StoreOperationsLibSQL = class extends storage.StoreOperations {
2486
2489
  ).catch((error$1) => {
2487
2490
  throw new error.MastraError(
2488
2491
  {
2489
- id: "LIBSQL_STORE_BATCH_DELETE_FAILED",
2492
+ id: storage.createStorageErrorId("LIBSQL", "BATCH_DELETE", "FAILED"),
2490
2493
  domain: error.ErrorDomain.STORAGE,
2491
2494
  category: error.ErrorCategory.THIRD_PARTY,
2492
2495
  details: {
@@ -2543,7 +2546,7 @@ var StoreOperationsLibSQL = class extends storage.StoreOperations {
2543
2546
  } catch (error$1) {
2544
2547
  throw new error.MastraError(
2545
2548
  {
2546
- id: "LIBSQL_STORE_ALTER_TABLE_FAILED",
2549
+ id: storage.createStorageErrorId("LIBSQL", "ALTER_TABLE", "FAILED"),
2547
2550
  domain: error.ErrorDomain.STORAGE,
2548
2551
  category: error.ErrorCategory.THIRD_PARTY,
2549
2552
  details: {
@@ -2561,7 +2564,7 @@ var StoreOperationsLibSQL = class extends storage.StoreOperations {
2561
2564
  } catch (e) {
2562
2565
  const mastraError = new error.MastraError(
2563
2566
  {
2564
- id: "LIBSQL_STORE_CLEAR_TABLE_FAILED",
2567
+ id: storage.createStorageErrorId("LIBSQL", "CLEAR_TABLE", "FAILED"),
2565
2568
  domain: error.ErrorDomain.STORAGE,
2566
2569
  category: error.ErrorCategory.THIRD_PARTY,
2567
2570
  details: {
@@ -2581,7 +2584,7 @@ var StoreOperationsLibSQL = class extends storage.StoreOperations {
2581
2584
  } catch (e) {
2582
2585
  throw new error.MastraError(
2583
2586
  {
2584
- id: "LIBSQL_STORE_DROP_TABLE_FAILED",
2587
+ id: storage.createStorageErrorId("LIBSQL", "DROP_TABLE", "FAILED"),
2585
2588
  domain: error.ErrorDomain.STORAGE,
2586
2589
  category: error.ErrorCategory.THIRD_PARTY,
2587
2590
  details: {
@@ -2644,7 +2647,7 @@ var ScoresLibSQL = class extends storage.ScoresStorage {
2644
2647
  } catch (error$1) {
2645
2648
  throw new error.MastraError(
2646
2649
  {
2647
- id: "LIBSQL_STORE_GET_SCORES_BY_RUN_ID_FAILED",
2650
+ id: storage.createStorageErrorId("LIBSQL", "LIST_SCORES_BY_RUN_ID", "FAILED"),
2648
2651
  domain: error.ErrorDomain.STORAGE,
2649
2652
  category: error.ErrorCategory.THIRD_PARTY
2650
2653
  },
@@ -2717,7 +2720,7 @@ var ScoresLibSQL = class extends storage.ScoresStorage {
2717
2720
  } catch (error$1) {
2718
2721
  throw new error.MastraError(
2719
2722
  {
2720
- id: "LIBSQL_STORE_GET_SCORES_BY_SCORER_ID_FAILED",
2723
+ id: storage.createStorageErrorId("LIBSQL", "LIST_SCORES_BY_SCORER_ID", "FAILED"),
2721
2724
  domain: error.ErrorDomain.STORAGE,
2722
2725
  category: error.ErrorCategory.THIRD_PARTY
2723
2726
  },
@@ -2725,45 +2728,14 @@ var ScoresLibSQL = class extends storage.ScoresStorage {
2725
2728
  );
2726
2729
  }
2727
2730
  }
2731
+ /**
2732
+ * LibSQL-specific score row transformation.
2733
+ * Maps additionalLLMContext column to additionalContext field.
2734
+ */
2728
2735
  transformScoreRow(row) {
2729
- const scorerValue = storage.safelyParseJSON(row.scorer);
2730
- const inputValue = storage.safelyParseJSON(row.input ?? "{}");
2731
- const outputValue = storage.safelyParseJSON(row.output ?? "{}");
2732
- const additionalLLMContextValue = row.additionalLLMContext ? storage.safelyParseJSON(row.additionalLLMContext) : null;
2733
- const requestContextValue = row.requestContext ? storage.safelyParseJSON(row.requestContext) : null;
2734
- const metadataValue = row.metadata ? storage.safelyParseJSON(row.metadata) : null;
2735
- const entityValue = row.entity ? storage.safelyParseJSON(row.entity) : null;
2736
- const preprocessStepResultValue = row.preprocessStepResult ? storage.safelyParseJSON(row.preprocessStepResult) : null;
2737
- const analyzeStepResultValue = row.analyzeStepResult ? storage.safelyParseJSON(row.analyzeStepResult) : null;
2738
- return {
2739
- id: row.id,
2740
- traceId: row.traceId,
2741
- spanId: row.spanId,
2742
- runId: row.runId,
2743
- scorer: scorerValue,
2744
- score: row.score,
2745
- reason: row.reason,
2746
- preprocessStepResult: preprocessStepResultValue,
2747
- analyzeStepResult: analyzeStepResultValue,
2748
- analyzePrompt: row.analyzePrompt,
2749
- preprocessPrompt: row.preprocessPrompt,
2750
- generateScorePrompt: row.generateScorePrompt,
2751
- generateReasonPrompt: row.generateReasonPrompt,
2752
- metadata: metadataValue,
2753
- input: inputValue,
2754
- output: outputValue,
2755
- additionalContext: additionalLLMContextValue,
2756
- requestContext: requestContextValue,
2757
- entityType: row.entityType,
2758
- entity: entityValue,
2759
- entityId: row.entityId,
2760
- scorerId: row.scorerId,
2761
- source: row.source,
2762
- resourceId: row.resourceId,
2763
- threadId: row.threadId,
2764
- createdAt: row.createdAt,
2765
- updatedAt: row.updatedAt
2766
- };
2736
+ return storage.transformScoreRow(row, {
2737
+ fieldMappings: { additionalContext: "additionalLLMContext" }
2738
+ });
2767
2739
  }
2768
2740
  async getScoreById({ id }) {
2769
2741
  const result = await this.client.execute({
@@ -2779,7 +2751,7 @@ var ScoresLibSQL = class extends storage.ScoresStorage {
2779
2751
  } catch (error$1) {
2780
2752
  throw new error.MastraError(
2781
2753
  {
2782
- id: "LIBSQL_STORE_SAVE_SCORE_FAILED_INVALID_SCORE_PAYLOAD",
2754
+ id: storage.createStorageErrorId("LIBSQL", "SAVE_SCORE", "VALIDATION_FAILED"),
2783
2755
  domain: error.ErrorDomain.STORAGE,
2784
2756
  category: error.ErrorCategory.USER,
2785
2757
  details: {
@@ -2809,7 +2781,7 @@ var ScoresLibSQL = class extends storage.ScoresStorage {
2809
2781
  } catch (error$1) {
2810
2782
  throw new error.MastraError(
2811
2783
  {
2812
- id: "LIBSQL_STORE_SAVE_SCORE_FAILED",
2784
+ id: storage.createStorageErrorId("LIBSQL", "SAVE_SCORE", "FAILED"),
2813
2785
  domain: error.ErrorDomain.STORAGE,
2814
2786
  category: error.ErrorCategory.THIRD_PARTY
2815
2787
  },
@@ -2861,7 +2833,7 @@ var ScoresLibSQL = class extends storage.ScoresStorage {
2861
2833
  } catch (error$1) {
2862
2834
  throw new error.MastraError(
2863
2835
  {
2864
- id: "LIBSQL_STORE_GET_SCORES_BY_ENTITY_ID_FAILED",
2836
+ id: storage.createStorageErrorId("LIBSQL", "LIST_SCORES_BY_ENTITY_ID", "FAILED"),
2865
2837
  domain: error.ErrorDomain.STORAGE,
2866
2838
  category: error.ErrorCategory.THIRD_PARTY
2867
2839
  },
@@ -2902,7 +2874,7 @@ var ScoresLibSQL = class extends storage.ScoresStorage {
2902
2874
  } catch (error$1) {
2903
2875
  throw new error.MastraError(
2904
2876
  {
2905
- id: "LIBSQL_STORE_GET_SCORES_BY_SPAN_FAILED",
2877
+ id: storage.createStorageErrorId("LIBSQL", "LIST_SCORES_BY_SPAN", "FAILED"),
2906
2878
  domain: error.ErrorDomain.STORAGE,
2907
2879
  category: error.ErrorCategory.THIRD_PARTY
2908
2880
  },
@@ -3152,7 +3124,7 @@ var WorkflowsLibSQL = class extends storage.WorkflowsStorage {
3152
3124
  } catch (error$1) {
3153
3125
  throw new error.MastraError(
3154
3126
  {
3155
- id: "LIBSQL_STORE_GET_WORKFLOW_RUN_BY_ID_FAILED",
3127
+ id: storage.createStorageErrorId("LIBSQL", "GET_WORKFLOW_RUN_BY_ID", "FAILED"),
3156
3128
  domain: error.ErrorDomain.STORAGE,
3157
3129
  category: error.ErrorCategory.THIRD_PARTY
3158
3130
  },
@@ -3218,7 +3190,7 @@ var WorkflowsLibSQL = class extends storage.WorkflowsStorage {
3218
3190
  } catch (error$1) {
3219
3191
  throw new error.MastraError(
3220
3192
  {
3221
- id: "LIBSQL_STORE_LIST_WORKFLOW_RUNS_FAILED",
3193
+ id: storage.createStorageErrorId("LIBSQL", "LIST_WORKFLOW_RUNS", "FAILED"),
3222
3194
  domain: error.ErrorDomain.STORAGE,
3223
3195
  category: error.ErrorCategory.THIRD_PARTY
3224
3196
  },
@@ -3238,7 +3210,7 @@ var LibSQLStore = class extends storage.MastraStorage {
3238
3210
  if (!config.id || typeof config.id !== "string" || config.id.trim() === "") {
3239
3211
  throw new Error("LibSQLStore: id must be provided and cannot be empty.");
3240
3212
  }
3241
- super({ id: config.id, name: `LibSQLStore` });
3213
+ super({ id: config.id, name: `LibSQLStore`, disableInit: config.disableInit });
3242
3214
  this.maxRetries = config.maxRetries ?? 5;
3243
3215
  this.initialBackoffMs = config.initialBackoffMs ?? 100;
3244
3216
  if ("url" in config) {