@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.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { createClient } from '@libsql/client';
2
2
  import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
3
+ import { createVectorErrorId, MastraStorage, StoreOperations, TABLE_WORKFLOW_SNAPSHOT, TABLE_SPANS, createStorageErrorId, ScoresStorage, TABLE_SCORERS, normalizePerPage, calculatePagination, transformScoreRow, WorkflowsStorage, MemoryStorage, TABLE_MESSAGES, TABLE_THREADS, TABLE_RESOURCES, ObservabilityStorage, TABLE_SCHEMAS, safelyParseJSON, SPAN_SCHEMA } from '@mastra/core/storage';
3
4
  import { parseSqlIdentifier, parseFieldKey } from '@mastra/core/utils';
4
5
  import { MastraVector } from '@mastra/core/vector';
5
6
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
6
- import { MastraStorage, StoreOperations, TABLE_WORKFLOW_SNAPSHOT, TABLE_SPANS, ScoresStorage, TABLE_SCORERS, normalizePerPage, calculatePagination, safelyParseJSON, WorkflowsStorage, MemoryStorage, TABLE_MESSAGES, TABLE_THREADS, TABLE_RESOURCES, ObservabilityStorage, TABLE_SCHEMAS, SPAN_SCHEMA } from '@mastra/core/storage';
7
7
  import { MessageList } from '@mastra/core/agent';
8
8
  import { saveScorePayloadSchema } from '@mastra/core/evals';
9
9
 
@@ -581,7 +581,7 @@ var LibSQLVector = class extends MastraVector {
581
581
  } catch (error) {
582
582
  throw new MastraError(
583
583
  {
584
- id: "LIBSQL_VECTOR_QUERY_INVALID_ARGS",
584
+ id: createVectorErrorId("LIBSQL", "QUERY", "INVALID_ARGS"),
585
585
  domain: ErrorDomain.STORAGE,
586
586
  category: ErrorCategory.USER
587
587
  },
@@ -623,7 +623,7 @@ var LibSQLVector = class extends MastraVector {
623
623
  } catch (error) {
624
624
  throw new MastraError(
625
625
  {
626
- id: "LIBSQL_VECTOR_QUERY_FAILED",
626
+ id: createVectorErrorId("LIBSQL", "QUERY", "FAILED"),
627
627
  domain: ErrorDomain.STORAGE,
628
628
  category: ErrorCategory.THIRD_PARTY
629
629
  },
@@ -637,7 +637,7 @@ var LibSQLVector = class extends MastraVector {
637
637
  } catch (error) {
638
638
  throw new MastraError(
639
639
  {
640
- id: "LIBSQL_VECTOR_UPSERT_FAILED",
640
+ id: createVectorErrorId("LIBSQL", "UPSERT", "FAILED"),
641
641
  domain: ErrorDomain.STORAGE,
642
642
  category: ErrorCategory.THIRD_PARTY
643
643
  },
@@ -691,7 +691,7 @@ var LibSQLVector = class extends MastraVector {
691
691
  } catch (error) {
692
692
  throw new MastraError(
693
693
  {
694
- id: "LIBSQL_VECTOR_CREATE_INDEX_FAILED",
694
+ id: createVectorErrorId("LIBSQL", "CREATE_INDEX", "FAILED"),
695
695
  domain: ErrorDomain.STORAGE,
696
696
  category: ErrorCategory.THIRD_PARTY,
697
697
  details: { indexName: args.indexName, dimension: args.dimension }
@@ -730,7 +730,7 @@ var LibSQLVector = class extends MastraVector {
730
730
  } catch (error) {
731
731
  throw new MastraError(
732
732
  {
733
- id: "LIBSQL_VECTOR_DELETE_INDEX_FAILED",
733
+ id: createVectorErrorId("LIBSQL", "DELETE_INDEX", "FAILED"),
734
734
  domain: ErrorDomain.STORAGE,
735
735
  category: ErrorCategory.THIRD_PARTY,
736
736
  details: { indexName: args.indexName }
@@ -761,7 +761,7 @@ var LibSQLVector = class extends MastraVector {
761
761
  } catch (error) {
762
762
  throw new MastraError(
763
763
  {
764
- id: "LIBSQL_VECTOR_LIST_INDEXES_FAILED",
764
+ id: createVectorErrorId("LIBSQL", "LIST_INDEXES", "FAILED"),
765
765
  domain: ErrorDomain.STORAGE,
766
766
  category: ErrorCategory.THIRD_PARTY
767
767
  },
@@ -809,7 +809,7 @@ var LibSQLVector = class extends MastraVector {
809
809
  } catch (e) {
810
810
  throw new MastraError(
811
811
  {
812
- id: "LIBSQL_VECTOR_DESCRIBE_INDEX_FAILED",
812
+ id: createVectorErrorId("LIBSQL", "DESCRIBE_INDEX", "FAILED"),
813
813
  domain: ErrorDomain.STORAGE,
814
814
  category: ErrorCategory.THIRD_PARTY,
815
815
  details: { indexName }
@@ -837,7 +837,7 @@ var LibSQLVector = class extends MastraVector {
837
837
  const parsedIndexName = parseSqlIdentifier(indexName, "index name");
838
838
  if ("id" in params && params.id && "filter" in params && params.filter) {
839
839
  throw new MastraError({
840
- id: "LIBSQL_VECTOR_UPDATE_MUTUALLY_EXCLUSIVE_PARAMS",
840
+ id: createVectorErrorId("LIBSQL", "UPDATE_VECTOR", "MUTUALLY_EXCLUSIVE"),
841
841
  domain: ErrorDomain.STORAGE,
842
842
  category: ErrorCategory.USER,
843
843
  details: { indexName },
@@ -846,7 +846,7 @@ var LibSQLVector = class extends MastraVector {
846
846
  }
847
847
  if (!update.vector && !update.metadata) {
848
848
  throw new MastraError({
849
- id: "LIBSQL_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
849
+ id: createVectorErrorId("LIBSQL", "UPDATE_VECTOR", "NO_PAYLOAD"),
850
850
  domain: ErrorDomain.STORAGE,
851
851
  category: ErrorCategory.USER,
852
852
  details: { indexName },
@@ -875,7 +875,7 @@ var LibSQLVector = class extends MastraVector {
875
875
  const filter = params.filter;
876
876
  if (!filter || Object.keys(filter).length === 0) {
877
877
  throw new MastraError({
878
- id: "LIBSQL_VECTOR_UPDATE_EMPTY_FILTER",
878
+ id: createVectorErrorId("LIBSQL", "UPDATE_VECTOR", "EMPTY_FILTER"),
879
879
  domain: ErrorDomain.STORAGE,
880
880
  category: ErrorCategory.USER,
881
881
  details: { indexName },
@@ -886,7 +886,7 @@ var LibSQLVector = class extends MastraVector {
886
886
  const { sql: filterSql, values: filterValues } = buildFilterQuery(translatedFilter);
887
887
  if (!filterSql || filterSql.trim() === "") {
888
888
  throw new MastraError({
889
- id: "LIBSQL_VECTOR_UPDATE_INVALID_FILTER",
889
+ id: createVectorErrorId("LIBSQL", "UPDATE_VECTOR", "INVALID_FILTER"),
890
890
  domain: ErrorDomain.STORAGE,
891
891
  category: ErrorCategory.USER,
892
892
  details: { indexName },
@@ -897,7 +897,7 @@ var LibSQLVector = class extends MastraVector {
897
897
  const matchAllPatterns = ["true", "1 = 1", "1=1"];
898
898
  if (matchAllPatterns.includes(normalizedCondition)) {
899
899
  throw new MastraError({
900
- id: "LIBSQL_VECTOR_UPDATE_MATCH_ALL_FILTER",
900
+ id: createVectorErrorId("LIBSQL", "UPDATE_VECTOR", "MATCH_ALL_FILTER"),
901
901
  domain: ErrorDomain.STORAGE,
902
902
  category: ErrorCategory.USER,
903
903
  details: { indexName, filterSql: normalizedCondition },
@@ -908,7 +908,7 @@ var LibSQLVector = class extends MastraVector {
908
908
  whereValues = filterValues;
909
909
  } else {
910
910
  throw new MastraError({
911
- id: "LIBSQL_VECTOR_UPDATE_MISSING_PARAMS",
911
+ id: createVectorErrorId("LIBSQL", "UPDATE_VECTOR", "NO_TARGET"),
912
912
  domain: ErrorDomain.STORAGE,
913
913
  category: ErrorCategory.USER,
914
914
  details: { indexName },
@@ -935,7 +935,7 @@ var LibSQLVector = class extends MastraVector {
935
935
  }
936
936
  throw new MastraError(
937
937
  {
938
- id: "LIBSQL_VECTOR_UPDATE_VECTOR_FAILED",
938
+ id: createVectorErrorId("LIBSQL", "UPDATE_VECTOR", "FAILED"),
939
939
  domain: ErrorDomain.STORAGE,
940
940
  category: ErrorCategory.THIRD_PARTY,
941
941
  details: errorDetails
@@ -957,7 +957,7 @@ var LibSQLVector = class extends MastraVector {
957
957
  } catch (error) {
958
958
  throw new MastraError(
959
959
  {
960
- id: "LIBSQL_VECTOR_DELETE_VECTOR_FAILED",
960
+ id: createVectorErrorId("LIBSQL", "DELETE_VECTOR", "FAILED"),
961
961
  domain: ErrorDomain.STORAGE,
962
962
  category: ErrorCategory.THIRD_PARTY,
963
963
  details: {
@@ -983,7 +983,7 @@ var LibSQLVector = class extends MastraVector {
983
983
  const parsedIndexName = parseSqlIdentifier(indexName, "index name");
984
984
  if (!filter && !ids) {
985
985
  throw new MastraError({
986
- id: "LIBSQL_VECTOR_DELETE_MISSING_PARAMS",
986
+ id: createVectorErrorId("LIBSQL", "DELETE_VECTORS", "NO_TARGET"),
987
987
  domain: ErrorDomain.STORAGE,
988
988
  category: ErrorCategory.USER,
989
989
  details: { indexName },
@@ -992,7 +992,7 @@ var LibSQLVector = class extends MastraVector {
992
992
  }
993
993
  if (filter && ids) {
994
994
  throw new MastraError({
995
- id: "LIBSQL_VECTOR_DELETE_CONFLICTING_PARAMS",
995
+ id: createVectorErrorId("LIBSQL", "DELETE_VECTORS", "MUTUALLY_EXCLUSIVE"),
996
996
  domain: ErrorDomain.STORAGE,
997
997
  category: ErrorCategory.USER,
998
998
  details: { indexName },
@@ -1004,7 +1004,7 @@ var LibSQLVector = class extends MastraVector {
1004
1004
  if (ids) {
1005
1005
  if (ids.length === 0) {
1006
1006
  throw new MastraError({
1007
- id: "LIBSQL_VECTOR_DELETE_EMPTY_IDS",
1007
+ id: createVectorErrorId("LIBSQL", "DELETE_VECTORS", "EMPTY_IDS"),
1008
1008
  domain: ErrorDomain.STORAGE,
1009
1009
  category: ErrorCategory.USER,
1010
1010
  details: { indexName },
@@ -1017,7 +1017,7 @@ var LibSQLVector = class extends MastraVector {
1017
1017
  } else {
1018
1018
  if (!filter || Object.keys(filter).length === 0) {
1019
1019
  throw new MastraError({
1020
- id: "LIBSQL_VECTOR_DELETE_EMPTY_FILTER",
1020
+ id: createVectorErrorId("LIBSQL", "DELETE_VECTORS", "EMPTY_FILTER"),
1021
1021
  domain: ErrorDomain.STORAGE,
1022
1022
  category: ErrorCategory.USER,
1023
1023
  details: { indexName },
@@ -1028,7 +1028,7 @@ var LibSQLVector = class extends MastraVector {
1028
1028
  const { sql: filterSql, values: filterValues } = buildFilterQuery(translatedFilter);
1029
1029
  if (!filterSql || filterSql.trim() === "") {
1030
1030
  throw new MastraError({
1031
- id: "LIBSQL_VECTOR_DELETE_INVALID_FILTER",
1031
+ id: createVectorErrorId("LIBSQL", "DELETE_VECTORS", "INVALID_FILTER"),
1032
1032
  domain: ErrorDomain.STORAGE,
1033
1033
  category: ErrorCategory.USER,
1034
1034
  details: { indexName },
@@ -1039,7 +1039,7 @@ var LibSQLVector = class extends MastraVector {
1039
1039
  const matchAllPatterns = ["true", "1 = 1", "1=1"];
1040
1040
  if (matchAllPatterns.includes(normalizedCondition)) {
1041
1041
  throw new MastraError({
1042
- id: "LIBSQL_VECTOR_DELETE_MATCH_ALL_FILTER",
1042
+ id: createVectorErrorId("LIBSQL", "DELETE_VECTORS", "MATCH_ALL_FILTER"),
1043
1043
  domain: ErrorDomain.STORAGE,
1044
1044
  category: ErrorCategory.USER,
1045
1045
  details: { indexName, filterSql: normalizedCondition },
@@ -1057,7 +1057,7 @@ var LibSQLVector = class extends MastraVector {
1057
1057
  } catch (error) {
1058
1058
  throw new MastraError(
1059
1059
  {
1060
- id: "LIBSQL_VECTOR_DELETE_VECTORS_FAILED",
1060
+ id: createVectorErrorId("LIBSQL", "DELETE_VECTORS", "FAILED"),
1061
1061
  domain: ErrorDomain.STORAGE,
1062
1062
  category: ErrorCategory.THIRD_PARTY,
1063
1063
  details: {
@@ -1076,7 +1076,7 @@ var LibSQLVector = class extends MastraVector {
1076
1076
  } catch (error) {
1077
1077
  throw new MastraError(
1078
1078
  {
1079
- id: "LIBSQL_VECTOR_TRUNCATE_INDEX_FAILED",
1079
+ id: createVectorErrorId("LIBSQL", "TRUNCATE_INDEX", "FAILED"),
1080
1080
  domain: ErrorDomain.STORAGE,
1081
1081
  category: ErrorCategory.THIRD_PARTY,
1082
1082
  details: { indexName: args.indexName }
@@ -1117,26 +1117,24 @@ var MemoryLibSQL = class extends MemoryStorage {
1117
1117
  if (row.type && row.type !== `v2`) result.type = row.type;
1118
1118
  return result;
1119
1119
  }
1120
- async _getIncludedMessages({
1121
- threadId,
1122
- include
1123
- }) {
1124
- if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
1125
- if (!include) return null;
1120
+ async _getIncludedMessages({ include }) {
1121
+ if (!include || include.length === 0) return null;
1126
1122
  const unionQueries = [];
1127
1123
  const params = [];
1128
1124
  for (const inc of include) {
1129
1125
  const { id, withPreviousMessages = 0, withNextMessages = 0 } = inc;
1130
- const searchId = inc.threadId || threadId;
1131
1126
  unionQueries.push(
1132
1127
  `
1133
1128
  SELECT * FROM (
1134
- WITH numbered_messages AS (
1129
+ WITH target_thread AS (
1130
+ SELECT thread_id FROM "${TABLE_MESSAGES}" WHERE id = ?
1131
+ ),
1132
+ numbered_messages AS (
1135
1133
  SELECT
1136
1134
  id, content, role, type, "createdAt", thread_id, "resourceId",
1137
1135
  ROW_NUMBER() OVER (ORDER BY "createdAt" ASC) as row_num
1138
1136
  FROM "${TABLE_MESSAGES}"
1139
- WHERE thread_id = ?
1137
+ WHERE thread_id = (SELECT thread_id FROM target_thread)
1140
1138
  ),
1141
1139
  target_positions AS (
1142
1140
  SELECT row_num as target_pos
@@ -1151,7 +1149,7 @@ var MemoryLibSQL = class extends MemoryStorage {
1151
1149
  `
1152
1150
  // Keep ASC for final sorting after fetching context
1153
1151
  );
1154
- params.push(searchId, id, withPreviousMessages, withNextMessages);
1152
+ params.push(id, id, withPreviousMessages, withNextMessages);
1155
1153
  }
1156
1154
  const finalQuery = unionQueries.join(" UNION ALL ") + ' ORDER BY "createdAt" ASC';
1157
1155
  const includedResult = await this.client.execute({ sql: finalQuery, args: params });
@@ -1187,7 +1185,7 @@ var MemoryLibSQL = class extends MemoryStorage {
1187
1185
  } catch (error) {
1188
1186
  throw new MastraError(
1189
1187
  {
1190
- id: "LIBSQL_STORE_LIST_MESSAGES_BY_ID_FAILED",
1188
+ id: createStorageErrorId("LIBSQL", "LIST_MESSAGES_BY_ID", "FAILED"),
1191
1189
  domain: ErrorDomain.STORAGE,
1192
1190
  category: ErrorCategory.THIRD_PARTY,
1193
1191
  details: { messageIds: JSON.stringify(messageIds) }
@@ -1198,21 +1196,22 @@ var MemoryLibSQL = class extends MemoryStorage {
1198
1196
  }
1199
1197
  async listMessages(args) {
1200
1198
  const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
1201
- if (!threadId.trim()) {
1199
+ const threadIds = Array.isArray(threadId) ? threadId : [threadId];
1200
+ if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
1202
1201
  throw new MastraError(
1203
1202
  {
1204
- id: "STORAGE_LIBSQL_LIST_MESSAGES_INVALID_THREAD_ID",
1203
+ id: createStorageErrorId("LIBSQL", "LIST_MESSAGES", "INVALID_THREAD_ID"),
1205
1204
  domain: ErrorDomain.STORAGE,
1206
1205
  category: ErrorCategory.THIRD_PARTY,
1207
- details: { threadId }
1206
+ details: { threadId: Array.isArray(threadId) ? threadId.join(",") : threadId }
1208
1207
  },
1209
- new Error("threadId must be a non-empty string")
1208
+ new Error("threadId must be a non-empty string or array of non-empty strings")
1210
1209
  );
1211
1210
  }
1212
1211
  if (page < 0) {
1213
1212
  throw new MastraError(
1214
1213
  {
1215
- id: "LIBSQL_STORE_LIST_MESSAGES_INVALID_PAGE",
1214
+ id: createStorageErrorId("LIBSQL", "LIST_MESSAGES", "INVALID_PAGE"),
1216
1215
  domain: ErrorDomain.STORAGE,
1217
1216
  category: ErrorCategory.USER,
1218
1217
  details: { page }
@@ -1225,8 +1224,9 @@ var MemoryLibSQL = class extends MemoryStorage {
1225
1224
  try {
1226
1225
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
1227
1226
  const orderByStatement = `ORDER BY "${field}" ${direction}`;
1228
- const conditions = [`thread_id = ?`];
1229
- const queryParams = [threadId];
1227
+ const threadPlaceholders = threadIds.map(() => "?").join(", ");
1228
+ const conditions = [`thread_id IN (${threadPlaceholders})`];
1229
+ const queryParams = [...threadIds];
1230
1230
  if (resourceId) {
1231
1231
  conditions.push(`"resourceId" = ?`);
1232
1232
  queryParams.push(resourceId);
@@ -1266,7 +1266,7 @@ var MemoryLibSQL = class extends MemoryStorage {
1266
1266
  }
1267
1267
  const messageIds = new Set(messages.map((m) => m.id));
1268
1268
  if (include && include.length > 0) {
1269
- const includeMessages = await this._getIncludedMessages({ threadId, include });
1269
+ const includeMessages = await this._getIncludedMessages({ include });
1270
1270
  if (includeMessages) {
1271
1271
  for (const includeMsg of includeMessages) {
1272
1272
  if (!messageIds.has(includeMsg.id)) {
@@ -1287,7 +1287,10 @@ var MemoryLibSQL = class extends MemoryStorage {
1287
1287
  }
1288
1288
  return direction === "ASC" ? String(aValue).localeCompare(String(bValue)) : String(bValue).localeCompare(String(aValue));
1289
1289
  });
1290
- const returnedThreadMessageIds = new Set(finalMessages.filter((m) => m.threadId === threadId).map((m) => m.id));
1290
+ const threadIdSet = new Set(threadIds);
1291
+ const returnedThreadMessageIds = new Set(
1292
+ finalMessages.filter((m) => m.threadId && threadIdSet.has(m.threadId)).map((m) => m.id)
1293
+ );
1291
1294
  const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
1292
1295
  const hasMore = perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total;
1293
1296
  return {
@@ -1300,11 +1303,11 @@ var MemoryLibSQL = class extends MemoryStorage {
1300
1303
  } catch (error) {
1301
1304
  const mastraError = new MastraError(
1302
1305
  {
1303
- id: "LIBSQL_STORE_LIST_MESSAGES_FAILED",
1306
+ id: createStorageErrorId("LIBSQL", "LIST_MESSAGES", "FAILED"),
1304
1307
  domain: ErrorDomain.STORAGE,
1305
1308
  category: ErrorCategory.THIRD_PARTY,
1306
1309
  details: {
1307
- threadId,
1310
+ threadId: Array.isArray(threadId) ? threadId.join(",") : threadId,
1308
1311
  resourceId: resourceId ?? ""
1309
1312
  }
1310
1313
  },
@@ -1383,7 +1386,7 @@ var MemoryLibSQL = class extends MemoryStorage {
1383
1386
  } catch (error) {
1384
1387
  throw new MastraError(
1385
1388
  {
1386
- id: "LIBSQL_STORE_SAVE_MESSAGES_FAILED",
1389
+ id: createStorageErrorId("LIBSQL", "SAVE_MESSAGES", "FAILED"),
1387
1390
  domain: ErrorDomain.STORAGE,
1388
1391
  category: ErrorCategory.THIRD_PARTY
1389
1392
  },
@@ -1511,7 +1514,7 @@ var MemoryLibSQL = class extends MemoryStorage {
1511
1514
  } catch (error) {
1512
1515
  throw new MastraError(
1513
1516
  {
1514
- id: "LIBSQL_STORE_DELETE_MESSAGES_FAILED",
1517
+ id: createStorageErrorId("LIBSQL", "DELETE_MESSAGES", "FAILED"),
1515
1518
  domain: ErrorDomain.STORAGE,
1516
1519
  category: ErrorCategory.THIRD_PARTY,
1517
1520
  details: { messageIds: messageIds.join(", ") }
@@ -1609,7 +1612,7 @@ var MemoryLibSQL = class extends MemoryStorage {
1609
1612
  } catch (error) {
1610
1613
  throw new MastraError(
1611
1614
  {
1612
- id: "LIBSQL_STORE_GET_THREAD_BY_ID_FAILED",
1615
+ id: createStorageErrorId("LIBSQL", "GET_THREAD_BY_ID", "FAILED"),
1613
1616
  domain: ErrorDomain.STORAGE,
1614
1617
  category: ErrorCategory.THIRD_PARTY,
1615
1618
  details: { threadId }
@@ -1623,7 +1626,7 @@ var MemoryLibSQL = class extends MemoryStorage {
1623
1626
  if (page < 0) {
1624
1627
  throw new MastraError(
1625
1628
  {
1626
- id: "LIBSQL_STORE_LIST_THREADS_BY_RESOURCE_ID_INVALID_PAGE",
1629
+ id: createStorageErrorId("LIBSQL", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
1627
1630
  domain: ErrorDomain.STORAGE,
1628
1631
  category: ErrorCategory.USER,
1629
1632
  details: { page }
@@ -1677,7 +1680,7 @@ var MemoryLibSQL = class extends MemoryStorage {
1677
1680
  } catch (error) {
1678
1681
  const mastraError = new MastraError(
1679
1682
  {
1680
- id: "LIBSQL_STORE_LIST_THREADS_BY_RESOURCE_ID_FAILED",
1683
+ id: createStorageErrorId("LIBSQL", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
1681
1684
  domain: ErrorDomain.STORAGE,
1682
1685
  category: ErrorCategory.THIRD_PARTY,
1683
1686
  details: { resourceId }
@@ -1708,7 +1711,7 @@ var MemoryLibSQL = class extends MemoryStorage {
1708
1711
  } catch (error) {
1709
1712
  const mastraError = new MastraError(
1710
1713
  {
1711
- id: "LIBSQL_STORE_SAVE_THREAD_FAILED",
1714
+ id: createStorageErrorId("LIBSQL", "SAVE_THREAD", "FAILED"),
1712
1715
  domain: ErrorDomain.STORAGE,
1713
1716
  category: ErrorCategory.THIRD_PARTY,
1714
1717
  details: { threadId: thread.id }
@@ -1728,7 +1731,7 @@ var MemoryLibSQL = class extends MemoryStorage {
1728
1731
  const thread = await this.getThreadById({ threadId: id });
1729
1732
  if (!thread) {
1730
1733
  throw new MastraError({
1731
- id: "LIBSQL_STORE_UPDATE_THREAD_FAILED_THREAD_NOT_FOUND",
1734
+ id: createStorageErrorId("LIBSQL", "UPDATE_THREAD", "NOT_FOUND"),
1732
1735
  domain: ErrorDomain.STORAGE,
1733
1736
  category: ErrorCategory.USER,
1734
1737
  text: `Thread ${id} not found`,
@@ -1755,7 +1758,7 @@ var MemoryLibSQL = class extends MemoryStorage {
1755
1758
  } catch (error) {
1756
1759
  throw new MastraError(
1757
1760
  {
1758
- id: "LIBSQL_STORE_UPDATE_THREAD_FAILED",
1761
+ id: createStorageErrorId("LIBSQL", "UPDATE_THREAD", "FAILED"),
1759
1762
  domain: ErrorDomain.STORAGE,
1760
1763
  category: ErrorCategory.THIRD_PARTY,
1761
1764
  text: `Failed to update thread ${id}`,
@@ -1778,7 +1781,7 @@ var MemoryLibSQL = class extends MemoryStorage {
1778
1781
  } catch (error) {
1779
1782
  throw new MastraError(
1780
1783
  {
1781
- id: "LIBSQL_STORE_DELETE_THREAD_FAILED",
1784
+ id: createStorageErrorId("LIBSQL", "DELETE_THREAD", "FAILED"),
1782
1785
  domain: ErrorDomain.STORAGE,
1783
1786
  category: ErrorCategory.THIRD_PARTY,
1784
1787
  details: { threadId }
@@ -1975,7 +1978,7 @@ var ObservabilityLibSQL = class extends ObservabilityStorage {
1975
1978
  } catch (error) {
1976
1979
  throw new MastraError(
1977
1980
  {
1978
- id: "LIBSQL_STORE_CREATE_SPAN_FAILED",
1981
+ id: createStorageErrorId("LIBSQL", "CREATE_SPAN", "FAILED"),
1979
1982
  domain: ErrorDomain.STORAGE,
1980
1983
  category: ErrorCategory.USER,
1981
1984
  details: {
@@ -2006,7 +2009,7 @@ var ObservabilityLibSQL = class extends ObservabilityStorage {
2006
2009
  } catch (error) {
2007
2010
  throw new MastraError(
2008
2011
  {
2009
- id: "LIBSQL_STORE_GET_TRACE_FAILED",
2012
+ id: createStorageErrorId("LIBSQL", "GET_TRACE", "FAILED"),
2010
2013
  domain: ErrorDomain.STORAGE,
2011
2014
  category: ErrorCategory.USER,
2012
2015
  details: {
@@ -2031,7 +2034,7 @@ var ObservabilityLibSQL = class extends ObservabilityStorage {
2031
2034
  } catch (error) {
2032
2035
  throw new MastraError(
2033
2036
  {
2034
- id: "LIBSQL_STORE_UPDATE_SPAN_FAILED",
2037
+ id: createStorageErrorId("LIBSQL", "UPDATE_SPAN", "FAILED"),
2035
2038
  domain: ErrorDomain.STORAGE,
2036
2039
  category: ErrorCategory.USER,
2037
2040
  details: {
@@ -2066,7 +2069,7 @@ var ObservabilityLibSQL = class extends ObservabilityStorage {
2066
2069
  name = `agent run: '${entityId}'`;
2067
2070
  } else {
2068
2071
  const error = new MastraError({
2069
- id: "LIBSQL_STORE_GET_TRACES_PAGINATED_FAILED",
2072
+ id: createStorageErrorId("LIBSQL", "GET_TRACES_PAGINATED", "INVALID_ENTITY_TYPE"),
2070
2073
  domain: ErrorDomain.STORAGE,
2071
2074
  category: ErrorCategory.USER,
2072
2075
  details: {
@@ -2094,7 +2097,7 @@ var ObservabilityLibSQL = class extends ObservabilityStorage {
2094
2097
  } catch (error) {
2095
2098
  throw new MastraError(
2096
2099
  {
2097
- id: "LIBSQL_STORE_GET_TRACES_PAGINATED_COUNT_FAILED",
2100
+ id: createStorageErrorId("LIBSQL", "GET_TRACES_PAGINATED", "COUNT_FAILED"),
2098
2101
  domain: ErrorDomain.STORAGE,
2099
2102
  category: ErrorCategory.USER
2100
2103
  },
@@ -2135,7 +2138,7 @@ var ObservabilityLibSQL = class extends ObservabilityStorage {
2135
2138
  } catch (error) {
2136
2139
  throw new MastraError(
2137
2140
  {
2138
- id: "LIBSQL_STORE_GET_TRACES_PAGINATED_FAILED",
2141
+ id: createStorageErrorId("LIBSQL", "GET_TRACES_PAGINATED", "FAILED"),
2139
2142
  domain: ErrorDomain.STORAGE,
2140
2143
  category: ErrorCategory.USER
2141
2144
  },
@@ -2157,7 +2160,7 @@ var ObservabilityLibSQL = class extends ObservabilityStorage {
2157
2160
  } catch (error) {
2158
2161
  throw new MastraError(
2159
2162
  {
2160
- id: "LIBSQL_STORE_BATCH_CREATE_SPANS_FAILED",
2163
+ id: createStorageErrorId("LIBSQL", "BATCH_CREATE_SPANS", "FAILED"),
2161
2164
  domain: ErrorDomain.STORAGE,
2162
2165
  category: ErrorCategory.USER
2163
2166
  },
@@ -2177,7 +2180,7 @@ var ObservabilityLibSQL = class extends ObservabilityStorage {
2177
2180
  } catch (error) {
2178
2181
  throw new MastraError(
2179
2182
  {
2180
- id: "LIBSQL_STORE_BATCH_UPDATE_SPANS_FAILED",
2183
+ id: createStorageErrorId("LIBSQL", "BATCH_UPDATE_SPANS", "FAILED"),
2181
2184
  domain: ErrorDomain.STORAGE,
2182
2185
  category: ErrorCategory.USER
2183
2186
  },
@@ -2195,7 +2198,7 @@ var ObservabilityLibSQL = class extends ObservabilityStorage {
2195
2198
  } catch (error) {
2196
2199
  throw new MastraError(
2197
2200
  {
2198
- id: "LIBSQL_STORE_BATCH_DELETE_TRACES_FAILED",
2201
+ id: createStorageErrorId("LIBSQL", "BATCH_DELETE_TRACES", "FAILED"),
2199
2202
  domain: ErrorDomain.STORAGE,
2200
2203
  category: ErrorCategory.USER
2201
2204
  },
@@ -2271,7 +2274,7 @@ var StoreOperationsLibSQL = class extends StoreOperations {
2271
2274
  } catch (error) {
2272
2275
  throw new MastraError(
2273
2276
  {
2274
- id: "LIBSQL_STORE_CREATE_TABLE_FAILED",
2277
+ id: createStorageErrorId("LIBSQL", "CREATE_TABLE", "FAILED"),
2275
2278
  domain: ErrorDomain.STORAGE,
2276
2279
  category: ErrorCategory.THIRD_PARTY,
2277
2280
  details: {
@@ -2415,7 +2418,7 @@ var StoreOperationsLibSQL = class extends StoreOperations {
2415
2418
  ).catch((error) => {
2416
2419
  throw new MastraError(
2417
2420
  {
2418
- id: "LIBSQL_STORE_BATCH_INSERT_FAILED",
2421
+ id: createStorageErrorId("LIBSQL", "BATCH_INSERT", "FAILED"),
2419
2422
  domain: ErrorDomain.STORAGE,
2420
2423
  category: ErrorCategory.THIRD_PARTY,
2421
2424
  details: {
@@ -2441,7 +2444,7 @@ var StoreOperationsLibSQL = class extends StoreOperations {
2441
2444
  ).catch((error) => {
2442
2445
  throw new MastraError(
2443
2446
  {
2444
- id: "LIBSQL_STORE_BATCH_UPDATE_FAILED",
2447
+ id: createStorageErrorId("LIBSQL", "BATCH_UPDATE", "FAILED"),
2445
2448
  domain: ErrorDomain.STORAGE,
2446
2449
  category: ErrorCategory.THIRD_PARTY,
2447
2450
  details: {
@@ -2484,7 +2487,7 @@ var StoreOperationsLibSQL = class extends StoreOperations {
2484
2487
  ).catch((error) => {
2485
2488
  throw new MastraError(
2486
2489
  {
2487
- id: "LIBSQL_STORE_BATCH_DELETE_FAILED",
2490
+ id: createStorageErrorId("LIBSQL", "BATCH_DELETE", "FAILED"),
2488
2491
  domain: ErrorDomain.STORAGE,
2489
2492
  category: ErrorCategory.THIRD_PARTY,
2490
2493
  details: {
@@ -2541,7 +2544,7 @@ var StoreOperationsLibSQL = class extends StoreOperations {
2541
2544
  } catch (error) {
2542
2545
  throw new MastraError(
2543
2546
  {
2544
- id: "LIBSQL_STORE_ALTER_TABLE_FAILED",
2547
+ id: createStorageErrorId("LIBSQL", "ALTER_TABLE", "FAILED"),
2545
2548
  domain: ErrorDomain.STORAGE,
2546
2549
  category: ErrorCategory.THIRD_PARTY,
2547
2550
  details: {
@@ -2559,7 +2562,7 @@ var StoreOperationsLibSQL = class extends StoreOperations {
2559
2562
  } catch (e) {
2560
2563
  const mastraError = new MastraError(
2561
2564
  {
2562
- id: "LIBSQL_STORE_CLEAR_TABLE_FAILED",
2565
+ id: createStorageErrorId("LIBSQL", "CLEAR_TABLE", "FAILED"),
2563
2566
  domain: ErrorDomain.STORAGE,
2564
2567
  category: ErrorCategory.THIRD_PARTY,
2565
2568
  details: {
@@ -2579,7 +2582,7 @@ var StoreOperationsLibSQL = class extends StoreOperations {
2579
2582
  } catch (e) {
2580
2583
  throw new MastraError(
2581
2584
  {
2582
- id: "LIBSQL_STORE_DROP_TABLE_FAILED",
2585
+ id: createStorageErrorId("LIBSQL", "DROP_TABLE", "FAILED"),
2583
2586
  domain: ErrorDomain.STORAGE,
2584
2587
  category: ErrorCategory.THIRD_PARTY,
2585
2588
  details: {
@@ -2642,7 +2645,7 @@ var ScoresLibSQL = class extends ScoresStorage {
2642
2645
  } catch (error) {
2643
2646
  throw new MastraError(
2644
2647
  {
2645
- id: "LIBSQL_STORE_GET_SCORES_BY_RUN_ID_FAILED",
2648
+ id: createStorageErrorId("LIBSQL", "LIST_SCORES_BY_RUN_ID", "FAILED"),
2646
2649
  domain: ErrorDomain.STORAGE,
2647
2650
  category: ErrorCategory.THIRD_PARTY
2648
2651
  },
@@ -2715,7 +2718,7 @@ var ScoresLibSQL = class extends ScoresStorage {
2715
2718
  } catch (error) {
2716
2719
  throw new MastraError(
2717
2720
  {
2718
- id: "LIBSQL_STORE_GET_SCORES_BY_SCORER_ID_FAILED",
2721
+ id: createStorageErrorId("LIBSQL", "LIST_SCORES_BY_SCORER_ID", "FAILED"),
2719
2722
  domain: ErrorDomain.STORAGE,
2720
2723
  category: ErrorCategory.THIRD_PARTY
2721
2724
  },
@@ -2723,45 +2726,14 @@ var ScoresLibSQL = class extends ScoresStorage {
2723
2726
  );
2724
2727
  }
2725
2728
  }
2729
+ /**
2730
+ * LibSQL-specific score row transformation.
2731
+ * Maps additionalLLMContext column to additionalContext field.
2732
+ */
2726
2733
  transformScoreRow(row) {
2727
- const scorerValue = safelyParseJSON(row.scorer);
2728
- const inputValue = safelyParseJSON(row.input ?? "{}");
2729
- const outputValue = safelyParseJSON(row.output ?? "{}");
2730
- const additionalLLMContextValue = row.additionalLLMContext ? safelyParseJSON(row.additionalLLMContext) : null;
2731
- const requestContextValue = row.requestContext ? safelyParseJSON(row.requestContext) : null;
2732
- const metadataValue = row.metadata ? safelyParseJSON(row.metadata) : null;
2733
- const entityValue = row.entity ? safelyParseJSON(row.entity) : null;
2734
- const preprocessStepResultValue = row.preprocessStepResult ? safelyParseJSON(row.preprocessStepResult) : null;
2735
- const analyzeStepResultValue = row.analyzeStepResult ? safelyParseJSON(row.analyzeStepResult) : null;
2736
- return {
2737
- id: row.id,
2738
- traceId: row.traceId,
2739
- spanId: row.spanId,
2740
- runId: row.runId,
2741
- scorer: scorerValue,
2742
- score: row.score,
2743
- reason: row.reason,
2744
- preprocessStepResult: preprocessStepResultValue,
2745
- analyzeStepResult: analyzeStepResultValue,
2746
- analyzePrompt: row.analyzePrompt,
2747
- preprocessPrompt: row.preprocessPrompt,
2748
- generateScorePrompt: row.generateScorePrompt,
2749
- generateReasonPrompt: row.generateReasonPrompt,
2750
- metadata: metadataValue,
2751
- input: inputValue,
2752
- output: outputValue,
2753
- additionalContext: additionalLLMContextValue,
2754
- requestContext: requestContextValue,
2755
- entityType: row.entityType,
2756
- entity: entityValue,
2757
- entityId: row.entityId,
2758
- scorerId: row.scorerId,
2759
- source: row.source,
2760
- resourceId: row.resourceId,
2761
- threadId: row.threadId,
2762
- createdAt: row.createdAt,
2763
- updatedAt: row.updatedAt
2764
- };
2734
+ return transformScoreRow(row, {
2735
+ fieldMappings: { additionalContext: "additionalLLMContext" }
2736
+ });
2765
2737
  }
2766
2738
  async getScoreById({ id }) {
2767
2739
  const result = await this.client.execute({
@@ -2777,7 +2749,7 @@ var ScoresLibSQL = class extends ScoresStorage {
2777
2749
  } catch (error) {
2778
2750
  throw new MastraError(
2779
2751
  {
2780
- id: "LIBSQL_STORE_SAVE_SCORE_FAILED_INVALID_SCORE_PAYLOAD",
2752
+ id: createStorageErrorId("LIBSQL", "SAVE_SCORE", "VALIDATION_FAILED"),
2781
2753
  domain: ErrorDomain.STORAGE,
2782
2754
  category: ErrorCategory.USER,
2783
2755
  details: {
@@ -2807,7 +2779,7 @@ var ScoresLibSQL = class extends ScoresStorage {
2807
2779
  } catch (error) {
2808
2780
  throw new MastraError(
2809
2781
  {
2810
- id: "LIBSQL_STORE_SAVE_SCORE_FAILED",
2782
+ id: createStorageErrorId("LIBSQL", "SAVE_SCORE", "FAILED"),
2811
2783
  domain: ErrorDomain.STORAGE,
2812
2784
  category: ErrorCategory.THIRD_PARTY
2813
2785
  },
@@ -2859,7 +2831,7 @@ var ScoresLibSQL = class extends ScoresStorage {
2859
2831
  } catch (error) {
2860
2832
  throw new MastraError(
2861
2833
  {
2862
- id: "LIBSQL_STORE_GET_SCORES_BY_ENTITY_ID_FAILED",
2834
+ id: createStorageErrorId("LIBSQL", "LIST_SCORES_BY_ENTITY_ID", "FAILED"),
2863
2835
  domain: ErrorDomain.STORAGE,
2864
2836
  category: ErrorCategory.THIRD_PARTY
2865
2837
  },
@@ -2900,7 +2872,7 @@ var ScoresLibSQL = class extends ScoresStorage {
2900
2872
  } catch (error) {
2901
2873
  throw new MastraError(
2902
2874
  {
2903
- id: "LIBSQL_STORE_GET_SCORES_BY_SPAN_FAILED",
2875
+ id: createStorageErrorId("LIBSQL", "LIST_SCORES_BY_SPAN", "FAILED"),
2904
2876
  domain: ErrorDomain.STORAGE,
2905
2877
  category: ErrorCategory.THIRD_PARTY
2906
2878
  },
@@ -3150,7 +3122,7 @@ var WorkflowsLibSQL = class extends WorkflowsStorage {
3150
3122
  } catch (error) {
3151
3123
  throw new MastraError(
3152
3124
  {
3153
- id: "LIBSQL_STORE_GET_WORKFLOW_RUN_BY_ID_FAILED",
3125
+ id: createStorageErrorId("LIBSQL", "GET_WORKFLOW_RUN_BY_ID", "FAILED"),
3154
3126
  domain: ErrorDomain.STORAGE,
3155
3127
  category: ErrorCategory.THIRD_PARTY
3156
3128
  },
@@ -3216,7 +3188,7 @@ var WorkflowsLibSQL = class extends WorkflowsStorage {
3216
3188
  } catch (error) {
3217
3189
  throw new MastraError(
3218
3190
  {
3219
- id: "LIBSQL_STORE_LIST_WORKFLOW_RUNS_FAILED",
3191
+ id: createStorageErrorId("LIBSQL", "LIST_WORKFLOW_RUNS", "FAILED"),
3220
3192
  domain: ErrorDomain.STORAGE,
3221
3193
  category: ErrorCategory.THIRD_PARTY
3222
3194
  },
@@ -3236,7 +3208,7 @@ var LibSQLStore = class extends MastraStorage {
3236
3208
  if (!config.id || typeof config.id !== "string" || config.id.trim() === "") {
3237
3209
  throw new Error("LibSQLStore: id must be provided and cannot be empty.");
3238
3210
  }
3239
- super({ id: config.id, name: `LibSQLStore` });
3211
+ super({ id: config.id, name: `LibSQLStore`, disableInit: config.disableInit });
3240
3212
  this.maxRetries = config.maxRetries ?? 5;
3241
3213
  this.initialBackoffMs = config.initialBackoffMs ?? 100;
3242
3214
  if ("url" in config) {