@mastra/dynamodb 1.0.0-beta.1 → 1.0.0-beta.3

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
@@ -425,6 +425,10 @@ var scoreEntity = new electrodb.Entity({
425
425
  return value;
426
426
  }
427
427
  },
428
+ preprocessPrompt: {
429
+ type: "string",
430
+ required: false
431
+ },
428
432
  preprocessStepResult: {
429
433
  type: "string",
430
434
  required: false,
@@ -985,7 +989,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
985
989
  } catch (error$1) {
986
990
  throw new error.MastraError(
987
991
  {
988
- id: "STORAGE_DYNAMODB_STORE_GET_THREAD_BY_ID_FAILED",
992
+ id: storage.createStorageErrorId("DYNAMODB", "GET_THREAD_BY_ID", "FAILED"),
989
993
  domain: error.ErrorDomain.STORAGE,
990
994
  category: error.ErrorCategory.THIRD_PARTY,
991
995
  details: { threadId }
@@ -1019,7 +1023,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1019
1023
  } catch (error$1) {
1020
1024
  throw new error.MastraError(
1021
1025
  {
1022
- id: "STORAGE_DYNAMODB_STORE_SAVE_THREAD_FAILED",
1026
+ id: storage.createStorageErrorId("DYNAMODB", "SAVE_THREAD", "FAILED"),
1023
1027
  domain: error.ErrorDomain.STORAGE,
1024
1028
  category: error.ErrorCategory.THIRD_PARTY,
1025
1029
  details: { threadId: thread.id }
@@ -1061,7 +1065,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1061
1065
  } catch (error$1) {
1062
1066
  throw new error.MastraError(
1063
1067
  {
1064
- id: "STORAGE_DYNAMODB_STORE_UPDATE_THREAD_FAILED",
1068
+ id: storage.createStorageErrorId("DYNAMODB", "UPDATE_THREAD", "FAILED"),
1065
1069
  domain: error.ErrorDomain.STORAGE,
1066
1070
  category: error.ErrorCategory.THIRD_PARTY,
1067
1071
  details: { threadId: id }
@@ -1093,7 +1097,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1093
1097
  } catch (error$1) {
1094
1098
  throw new error.MastraError(
1095
1099
  {
1096
- id: "STORAGE_DYNAMODB_STORE_DELETE_THREAD_FAILED",
1100
+ id: storage.createStorageErrorId("DYNAMODB", "DELETE_THREAD", "FAILED"),
1097
1101
  domain: error.ErrorDomain.STORAGE,
1098
1102
  category: error.ErrorCategory.THIRD_PARTY,
1099
1103
  details: { threadId }
@@ -1119,7 +1123,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1119
1123
  } catch (error$1) {
1120
1124
  throw new error.MastraError(
1121
1125
  {
1122
- id: "STORAGE_DYNAMODB_STORE_LIST_MESSAGES_BY_ID_FAILED",
1126
+ id: storage.createStorageErrorId("DYNAMODB", "LIST_MESSAGES_BY_ID", "FAILED"),
1123
1127
  domain: error.ErrorDomain.STORAGE,
1124
1128
  category: error.ErrorCategory.THIRD_PARTY,
1125
1129
  details: { messageIds: JSON.stringify(messageIds) }
@@ -1130,15 +1134,16 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1130
1134
  }
1131
1135
  async listMessages(args) {
1132
1136
  const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
1133
- if (!threadId.trim()) {
1137
+ const threadIds = Array.isArray(threadId) ? threadId : [threadId];
1138
+ if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
1134
1139
  throw new error.MastraError(
1135
1140
  {
1136
- id: "STORAGE_DYNAMODB_LIST_MESSAGES_INVALID_THREAD_ID",
1141
+ id: storage.createStorageErrorId("DYNAMODB", "LIST_MESSAGES", "INVALID_THREAD_ID"),
1137
1142
  domain: error.ErrorDomain.STORAGE,
1138
1143
  category: error.ErrorCategory.THIRD_PARTY,
1139
- details: { threadId }
1144
+ details: { threadId: Array.isArray(threadId) ? threadId.join(",") : threadId }
1140
1145
  },
1141
- new Error("threadId must be a non-empty string")
1146
+ new Error("threadId must be a non-empty string or array of non-empty strings")
1142
1147
  );
1143
1148
  }
1144
1149
  const perPage = storage.normalizePerPage(perPageInput, 40);
@@ -1147,7 +1152,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1147
1152
  if (page < 0) {
1148
1153
  throw new error.MastraError(
1149
1154
  {
1150
- id: "STORAGE_DYNAMODB_LIST_MESSAGES_INVALID_PAGE",
1155
+ id: storage.createStorageErrorId("DYNAMODB", "LIST_MESSAGES", "INVALID_PAGE"),
1151
1156
  domain: error.ErrorDomain.STORAGE,
1152
1157
  category: error.ErrorCategory.USER,
1153
1158
  details: { page }
@@ -1211,7 +1216,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1211
1216
  let includeMessages = [];
1212
1217
  if (include && include.length > 0) {
1213
1218
  const selectBy = { include };
1214
- includeMessages = await this._getIncludedMessages(threadId, selectBy);
1219
+ includeMessages = await this._getIncludedMessages(selectBy);
1215
1220
  for (const includeMsg of includeMessages) {
1216
1221
  if (!messageIds.has(includeMsg.id)) {
1217
1222
  paginatedMessages.push(includeMsg);
@@ -1245,11 +1250,11 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1245
1250
  } catch (error$1) {
1246
1251
  const mastraError = new error.MastraError(
1247
1252
  {
1248
- id: "STORAGE_DYNAMODB_STORE_LIST_MESSAGES_FAILED",
1253
+ id: storage.createStorageErrorId("DYNAMODB", "LIST_MESSAGES", "FAILED"),
1249
1254
  domain: error.ErrorDomain.STORAGE,
1250
1255
  category: error.ErrorCategory.THIRD_PARTY,
1251
1256
  details: {
1252
- threadId,
1257
+ threadId: Array.isArray(threadId) ? threadId.join(",") : threadId,
1253
1258
  resourceId: resourceId ?? ""
1254
1259
  }
1255
1260
  },
@@ -1328,7 +1333,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1328
1333
  } catch (error$1) {
1329
1334
  throw new error.MastraError(
1330
1335
  {
1331
- id: "STORAGE_DYNAMODB_STORE_SAVE_MESSAGES_FAILED",
1336
+ id: storage.createStorageErrorId("DYNAMODB", "SAVE_MESSAGES", "FAILED"),
1332
1337
  domain: error.ErrorDomain.STORAGE,
1333
1338
  category: error.ErrorCategory.THIRD_PARTY,
1334
1339
  details: { count: messages.length }
@@ -1343,7 +1348,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1343
1348
  if (page < 0) {
1344
1349
  throw new error.MastraError(
1345
1350
  {
1346
- id: "STORAGE_DYNAMODB_LIST_THREADS_BY_RESOURCE_ID_INVALID_PAGE",
1351
+ id: storage.createStorageErrorId("DYNAMODB", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
1347
1352
  domain: error.ErrorDomain.STORAGE,
1348
1353
  category: error.ErrorCategory.USER,
1349
1354
  details: { page }
@@ -1378,7 +1383,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1378
1383
  } catch (error$1) {
1379
1384
  throw new error.MastraError(
1380
1385
  {
1381
- id: "DYNAMODB_STORAGE_LIST_THREADS_BY_RESOURCE_ID_FAILED",
1386
+ id: storage.createStorageErrorId("DYNAMODB", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
1382
1387
  domain: error.ErrorDomain.STORAGE,
1383
1388
  category: error.ErrorCategory.THIRD_PARTY,
1384
1389
  details: { resourceId, page, perPage }
@@ -1388,19 +1393,23 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1388
1393
  }
1389
1394
  }
1390
1395
  // Helper method to get included messages with context
1391
- async _getIncludedMessages(threadId, selectBy) {
1392
- if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
1396
+ async _getIncludedMessages(selectBy) {
1393
1397
  if (!selectBy?.include?.length) {
1394
1398
  return [];
1395
1399
  }
1396
1400
  const includeMessages = [];
1397
1401
  for (const includeItem of selectBy.include) {
1398
1402
  try {
1399
- const { id, threadId: targetThreadId, withPreviousMessages = 0, withNextMessages = 0 } = includeItem;
1400
- const searchThreadId = targetThreadId || threadId;
1403
+ const { id, withPreviousMessages = 0, withNextMessages = 0 } = includeItem;
1404
+ const targetResult = await this.service.entities.message.get({ entity: "message", id }).go();
1405
+ if (!targetResult.data) {
1406
+ this.logger.warn("Target message not found", { id });
1407
+ continue;
1408
+ }
1409
+ const targetMessageData = targetResult.data;
1410
+ const searchThreadId = targetMessageData.threadId;
1401
1411
  this.logger.debug("Getting included messages for", {
1402
1412
  id,
1403
- targetThreadId,
1404
1413
  searchThreadId,
1405
1414
  withPreviousMessages,
1406
1415
  withNextMessages
@@ -1423,7 +1432,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1423
1432
  });
1424
1433
  const targetIndex = allMessages.findIndex((msg) => msg.id === id);
1425
1434
  if (targetIndex === -1) {
1426
- this.logger.warn("Target message not found", { id, threadId: searchThreadId });
1435
+ this.logger.warn("Target message not found in thread", { id, threadId: searchThreadId });
1427
1436
  continue;
1428
1437
  }
1429
1438
  this.logger.debug("Found target message at index", { id, targetIndex, totalMessages: allMessages.length });
@@ -1508,7 +1517,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1508
1517
  } catch (error$1) {
1509
1518
  throw new error.MastraError(
1510
1519
  {
1511
- id: "STORAGE_DYNAMODB_STORE_UPDATE_MESSAGES_FAILED",
1520
+ id: storage.createStorageErrorId("DYNAMODB", "UPDATE_MESSAGES", "FAILED"),
1512
1521
  domain: error.ErrorDomain.STORAGE,
1513
1522
  category: error.ErrorCategory.THIRD_PARTY,
1514
1523
  details: { count: messages.length }
@@ -1537,7 +1546,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1537
1546
  } catch (error$1) {
1538
1547
  throw new error.MastraError(
1539
1548
  {
1540
- id: "STORAGE_DYNAMODB_STORE_GET_RESOURCE_BY_ID_FAILED",
1549
+ id: storage.createStorageErrorId("DYNAMODB", "GET_RESOURCE_BY_ID", "FAILED"),
1541
1550
  domain: error.ErrorDomain.STORAGE,
1542
1551
  category: error.ErrorCategory.THIRD_PARTY,
1543
1552
  details: { resourceId }
@@ -1569,7 +1578,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1569
1578
  } catch (error$1) {
1570
1579
  throw new error.MastraError(
1571
1580
  {
1572
- id: "STORAGE_DYNAMODB_STORE_SAVE_RESOURCE_FAILED",
1581
+ id: storage.createStorageErrorId("DYNAMODB", "SAVE_RESOURCE", "FAILED"),
1573
1582
  domain: error.ErrorDomain.STORAGE,
1574
1583
  category: error.ErrorCategory.THIRD_PARTY,
1575
1584
  details: { resourceId: resource.id }
@@ -1618,7 +1627,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1618
1627
  } catch (error$1) {
1619
1628
  throw new error.MastraError(
1620
1629
  {
1621
- id: "STORAGE_DYNAMODB_STORE_UPDATE_RESOURCE_FAILED",
1630
+ id: storage.createStorageErrorId("DYNAMODB", "UPDATE_RESOURCE", "FAILED"),
1622
1631
  domain: error.ErrorDomain.STORAGE,
1623
1632
  category: error.ErrorCategory.THIRD_PARTY,
1624
1633
  details: { resourceId }
@@ -1718,7 +1727,7 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
1718
1727
  }
1719
1728
  throw new error.MastraError(
1720
1729
  {
1721
- id: "STORAGE_DYNAMODB_STORE_VALIDATE_TABLE_EXISTS_FAILED",
1730
+ id: storage.createStorageErrorId("DYNAMODB", "VALIDATE_TABLE_EXISTS", "FAILED"),
1722
1731
  domain: error.ErrorDomain.STORAGE,
1723
1732
  category: error.ErrorCategory.THIRD_PARTY,
1724
1733
  details: { tableName: this.tableName }
@@ -1751,7 +1760,7 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
1751
1760
  this.logger.error("Error validating table access", { tableName: this.tableName, error: error$1 });
1752
1761
  throw new error.MastraError(
1753
1762
  {
1754
- id: "STORAGE_DYNAMODB_STORE_VALIDATE_TABLE_ACCESS_FAILED",
1763
+ id: storage.createStorageErrorId("DYNAMODB", "VALIDATE_TABLE_ACCESS", "FAILED"),
1755
1764
  domain: error.ErrorDomain.STORAGE,
1756
1765
  category: error.ErrorCategory.THIRD_PARTY,
1757
1766
  details: { tableName: this.tableName }
@@ -1765,7 +1774,7 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
1765
1774
  const entityName = this.getEntityNameForTable(tableName);
1766
1775
  if (!entityName || !this.service.entities[entityName]) {
1767
1776
  throw new error.MastraError({
1768
- id: "STORAGE_DYNAMODB_STORE_INSERT_INVALID_ARGS",
1777
+ id: storage.createStorageErrorId("DYNAMODB", "INSERT", "INVALID_ARGS"),
1769
1778
  domain: error.ErrorDomain.STORAGE,
1770
1779
  category: error.ErrorCategory.USER,
1771
1780
  text: "No entity defined for tableName",
@@ -1778,7 +1787,7 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
1778
1787
  } catch (error$1) {
1779
1788
  throw new error.MastraError(
1780
1789
  {
1781
- id: "STORAGE_DYNAMODB_STORE_INSERT_FAILED",
1790
+ id: storage.createStorageErrorId("DYNAMODB", "INSERT", "FAILED"),
1782
1791
  domain: error.ErrorDomain.STORAGE,
1783
1792
  category: error.ErrorCategory.THIRD_PARTY,
1784
1793
  details: { tableName }
@@ -1797,7 +1806,7 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
1797
1806
  const entityName = this.getEntityNameForTable(tableName);
1798
1807
  if (!entityName || !this.service.entities[entityName]) {
1799
1808
  throw new error.MastraError({
1800
- id: "STORAGE_DYNAMODB_STORE_CLEAR_TABLE_INVALID_ARGS",
1809
+ id: storage.createStorageErrorId("DYNAMODB", "CLEAR_TABLE", "INVALID_ARGS"),
1801
1810
  domain: error.ErrorDomain.STORAGE,
1802
1811
  category: error.ErrorCategory.USER,
1803
1812
  text: "No entity defined for tableName",
@@ -1860,7 +1869,7 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
1860
1869
  } catch (error$1) {
1861
1870
  throw new error.MastraError(
1862
1871
  {
1863
- id: "STORAGE_DYNAMODB_STORE_CLEAR_TABLE_FAILED",
1872
+ id: storage.createStorageErrorId("DYNAMODB", "CLEAR_TABLE", "FAILED"),
1864
1873
  domain: error.ErrorDomain.STORAGE,
1865
1874
  category: error.ErrorCategory.THIRD_PARTY,
1866
1875
  details: { tableName }
@@ -1877,7 +1886,7 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
1877
1886
  const entityName = this.getEntityNameForTable(tableName);
1878
1887
  if (!entityName || !this.service.entities[entityName]) {
1879
1888
  throw new error.MastraError({
1880
- id: "STORAGE_DYNAMODB_STORE_BATCH_INSERT_INVALID_ARGS",
1889
+ id: storage.createStorageErrorId("DYNAMODB", "BATCH_INSERT", "INVALID_ARGS"),
1881
1890
  domain: error.ErrorDomain.STORAGE,
1882
1891
  category: error.ErrorCategory.USER,
1883
1892
  text: "No entity defined for tableName",
@@ -1905,7 +1914,7 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
1905
1914
  } catch (error$1) {
1906
1915
  throw new error.MastraError(
1907
1916
  {
1908
- id: "STORAGE_DYNAMODB_STORE_BATCH_INSERT_FAILED",
1917
+ id: storage.createStorageErrorId("DYNAMODB", "BATCH_INSERT", "FAILED"),
1909
1918
  domain: error.ErrorDomain.STORAGE,
1910
1919
  category: error.ErrorCategory.THIRD_PARTY,
1911
1920
  details: { tableName }
@@ -1922,7 +1931,7 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
1922
1931
  const entityName = this.getEntityNameForTable(tableName);
1923
1932
  if (!entityName || !this.service.entities[entityName]) {
1924
1933
  throw new error.MastraError({
1925
- id: "STORAGE_DYNAMODB_STORE_LOAD_INVALID_ARGS",
1934
+ id: storage.createStorageErrorId("DYNAMODB", "LOAD", "INVALID_ARGS"),
1926
1935
  domain: error.ErrorDomain.STORAGE,
1927
1936
  category: error.ErrorCategory.USER,
1928
1937
  text: "No entity defined for tableName",
@@ -1940,7 +1949,7 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
1940
1949
  } catch (error$1) {
1941
1950
  throw new error.MastraError(
1942
1951
  {
1943
- id: "STORAGE_DYNAMODB_STORE_LOAD_FAILED",
1952
+ id: storage.createStorageErrorId("DYNAMODB", "LOAD", "FAILED"),
1944
1953
  domain: error.ErrorDomain.STORAGE,
1945
1954
  category: error.ErrorCategory.THIRD_PARTY,
1946
1955
  details: { tableName }
@@ -1956,14 +1965,28 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
1956
1965
  super();
1957
1966
  this.service = service;
1958
1967
  }
1959
- // Helper function to parse score data (handle JSON fields)
1968
+ /**
1969
+ * DynamoDB-specific score row transformation.
1970
+ *
1971
+ * Note: This implementation does NOT use coreTransformScoreRow because:
1972
+ * 1. ElectroDB already parses JSON fields via its entity getters
1973
+ * 2. DynamoDB stores empty strings for null values (which need special handling)
1974
+ * 3. 'entity' is a reserved ElectroDB key, so we use 'entityData' column
1975
+ */
1960
1976
  parseScoreData(data) {
1977
+ const result = {};
1978
+ for (const key of Object.keys(storage.SCORERS_SCHEMA)) {
1979
+ if (["traceId", "resourceId", "threadId", "spanId"].includes(key)) {
1980
+ result[key] = data[key] === "" ? null : data[key];
1981
+ continue;
1982
+ }
1983
+ result[key] = data[key];
1984
+ }
1985
+ result.entity = data.entityData ?? null;
1961
1986
  return {
1962
- ...data,
1963
- // Convert date strings back to Date objects for consistency
1987
+ ...result,
1964
1988
  createdAt: data.createdAt ? new Date(data.createdAt) : /* @__PURE__ */ new Date(),
1965
1989
  updatedAt: data.updatedAt ? new Date(data.updatedAt) : /* @__PURE__ */ new Date()
1966
- // JSON fields are already transformed by the entity's getters
1967
1990
  };
1968
1991
  }
1969
1992
  async getScoreById({ id }) {
@@ -1977,7 +2000,7 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
1977
2000
  } catch (error$1) {
1978
2001
  throw new error.MastraError(
1979
2002
  {
1980
- id: "STORAGE_DYNAMODB_STORE_GET_SCORE_BY_ID_FAILED",
2003
+ id: storage.createStorageErrorId("DYNAMODB", "GET_SCORE_BY_ID", "FAILED"),
1981
2004
  domain: error.ErrorDomain.STORAGE,
1982
2005
  category: error.ErrorCategory.THIRD_PARTY,
1983
2006
  details: { id }
@@ -1993,7 +2016,7 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
1993
2016
  } catch (error$1) {
1994
2017
  throw new error.MastraError(
1995
2018
  {
1996
- id: "STORAGE_DYNAMODB_STORE_SAVE_SCORE_FAILED",
2019
+ id: storage.createStorageErrorId("DYNAMODB", "SAVE_SCORE", "VALIDATION_FAILED"),
1997
2020
  domain: error.ErrorDomain.STORAGE,
1998
2021
  category: error.ErrorCategory.THIRD_PARTY
1999
2022
  },
@@ -2002,35 +2025,33 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2002
2025
  }
2003
2026
  const now = /* @__PURE__ */ new Date();
2004
2027
  const scoreId = `score-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
2005
- const scoreData = {
2006
- entity: "score",
2007
- id: scoreId,
2008
- scorerId: validatedScore.scorerId,
2009
- traceId: validatedScore.traceId || "",
2010
- spanId: validatedScore.spanId || "",
2011
- runId: validatedScore.runId,
2012
- scorer: typeof validatedScore.scorer === "string" ? validatedScore.scorer : JSON.stringify(validatedScore.scorer),
2013
- preprocessStepResult: typeof validatedScore.preprocessStepResult === "string" ? validatedScore.preprocessStepResult : JSON.stringify(validatedScore.preprocessStepResult),
2014
- analyzeStepResult: typeof validatedScore.analyzeStepResult === "string" ? validatedScore.analyzeStepResult : JSON.stringify(validatedScore.analyzeStepResult),
2015
- score: validatedScore.score,
2016
- reason: validatedScore.reason,
2017
- preprocessPrompt: validatedScore.preprocessPrompt,
2018
- generateScorePrompt: validatedScore.generateScorePrompt,
2019
- generateReasonPrompt: validatedScore.generateReasonPrompt,
2020
- analyzePrompt: validatedScore.analyzePrompt,
2021
- input: typeof validatedScore.input === "string" ? validatedScore.input : JSON.stringify(validatedScore.input),
2022
- output: typeof validatedScore.output === "string" ? validatedScore.output : JSON.stringify(validatedScore.output),
2023
- additionalContext: typeof validatedScore.additionalContext === "string" ? validatedScore.additionalContext : JSON.stringify(validatedScore.additionalContext),
2024
- requestContext: typeof validatedScore.requestContext === "string" ? validatedScore.requestContext : JSON.stringify(validatedScore.requestContext),
2025
- entityType: validatedScore.entityType,
2026
- entityData: typeof validatedScore.entity === "string" ? validatedScore.entity : JSON.stringify(validatedScore.entity),
2027
- entityId: validatedScore.entityId,
2028
- source: validatedScore.source,
2029
- resourceId: validatedScore.resourceId || "",
2030
- threadId: validatedScore.threadId || "",
2031
- createdAt: now.toISOString(),
2032
- updatedAt: now.toISOString()
2033
- };
2028
+ const scorer = typeof validatedScore.scorer === "string" ? validatedScore.scorer : JSON.stringify(validatedScore.scorer);
2029
+ const preprocessStepResult = typeof validatedScore.preprocessStepResult === "string" ? validatedScore.preprocessStepResult : JSON.stringify(validatedScore.preprocessStepResult);
2030
+ const analyzeStepResult = typeof validatedScore.analyzeStepResult === "string" ? validatedScore.analyzeStepResult : JSON.stringify(validatedScore.analyzeStepResult);
2031
+ const input = typeof validatedScore.input === "string" ? validatedScore.input : JSON.stringify(validatedScore.input);
2032
+ const output = typeof validatedScore.output === "string" ? validatedScore.output : JSON.stringify(validatedScore.output);
2033
+ const requestContext = typeof validatedScore.requestContext === "string" ? validatedScore.requestContext : JSON.stringify(validatedScore.requestContext);
2034
+ const entity = typeof validatedScore.entity === "string" ? validatedScore.entity : JSON.stringify(validatedScore.entity);
2035
+ const scoreData = Object.fromEntries(
2036
+ Object.entries({
2037
+ ...validatedScore,
2038
+ entity: "score",
2039
+ id: scoreId,
2040
+ scorer,
2041
+ preprocessStepResult,
2042
+ analyzeStepResult,
2043
+ input,
2044
+ output,
2045
+ requestContext,
2046
+ entityData: entity,
2047
+ traceId: validatedScore.traceId || "",
2048
+ resourceId: validatedScore.resourceId || "",
2049
+ threadId: validatedScore.threadId || "",
2050
+ spanId: validatedScore.spanId || "",
2051
+ createdAt: now.toISOString(),
2052
+ updatedAt: now.toISOString()
2053
+ }).filter(([_, value]) => value !== void 0 && value !== null)
2054
+ );
2034
2055
  try {
2035
2056
  await this.service.entities.score.upsert(scoreData).go();
2036
2057
  const savedScore = {
@@ -2043,7 +2064,7 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2043
2064
  } catch (error$1) {
2044
2065
  throw new error.MastraError(
2045
2066
  {
2046
- id: "STORAGE_DYNAMODB_STORE_SAVE_SCORE_FAILED",
2067
+ id: storage.createStorageErrorId("DYNAMODB", "SAVE_SCORE", "FAILED"),
2047
2068
  domain: error.ErrorDomain.STORAGE,
2048
2069
  category: error.ErrorCategory.THIRD_PARTY,
2049
2070
  details: { scorerId: score.scorerId, runId: score.runId }
@@ -2091,7 +2112,7 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2091
2112
  } catch (error$1) {
2092
2113
  throw new error.MastraError(
2093
2114
  {
2094
- id: "STORAGE_DYNAMODB_STORE_GET_SCORES_BY_SCORER_ID_FAILED",
2115
+ id: storage.createStorageErrorId("DYNAMODB", "LIST_SCORES_BY_SCORER_ID", "FAILED"),
2095
2116
  domain: error.ErrorDomain.STORAGE,
2096
2117
  category: error.ErrorCategory.THIRD_PARTY,
2097
2118
  details: {
@@ -2135,7 +2156,7 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2135
2156
  } catch (error$1) {
2136
2157
  throw new error.MastraError(
2137
2158
  {
2138
- id: "STORAGE_DYNAMODB_STORE_GET_SCORES_BY_RUN_ID_FAILED",
2159
+ id: storage.createStorageErrorId("DYNAMODB", "LIST_SCORES_BY_RUN_ID", "FAILED"),
2139
2160
  domain: error.ErrorDomain.STORAGE,
2140
2161
  category: error.ErrorCategory.THIRD_PARTY,
2141
2162
  details: { runId, page: pagination.page, perPage: pagination.perPage }
@@ -2174,7 +2195,7 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2174
2195
  } catch (error$1) {
2175
2196
  throw new error.MastraError(
2176
2197
  {
2177
- id: "STORAGE_DYNAMODB_STORE_GET_SCORES_BY_ENTITY_ID_FAILED",
2198
+ id: storage.createStorageErrorId("DYNAMODB", "LIST_SCORES_BY_ENTITY_ID", "FAILED"),
2178
2199
  domain: error.ErrorDomain.STORAGE,
2179
2200
  category: error.ErrorCategory.THIRD_PARTY,
2180
2201
  details: { entityId, entityType, page: pagination.page, perPage: pagination.perPage }
@@ -2212,7 +2233,7 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2212
2233
  } catch (error$1) {
2213
2234
  throw new error.MastraError(
2214
2235
  {
2215
- id: "STORAGE_DYNAMODB_STORE_GET_SCORES_BY_SPAN_FAILED",
2236
+ id: storage.createStorageErrorId("DYNAMODB", "LIST_SCORES_BY_SPAN", "FAILED"),
2216
2237
  domain: error.ErrorDomain.STORAGE,
2217
2238
  category: error.ErrorCategory.THIRD_PARTY,
2218
2239
  details: { traceId, spanId, page: pagination.page, perPage: pagination.perPage }
@@ -2278,7 +2299,7 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
2278
2299
  } catch (error$1) {
2279
2300
  throw new error.MastraError(
2280
2301
  {
2281
- id: "STORAGE_DYNAMODB_STORE_PERSIST_WORKFLOW_SNAPSHOT_FAILED",
2302
+ id: storage.createStorageErrorId("DYNAMODB", "PERSIST_WORKFLOW_SNAPSHOT", "FAILED"),
2282
2303
  domain: error.ErrorDomain.STORAGE,
2283
2304
  category: error.ErrorCategory.THIRD_PARTY,
2284
2305
  details: { workflowName, runId }
@@ -2306,7 +2327,7 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
2306
2327
  } catch (error$1) {
2307
2328
  throw new error.MastraError(
2308
2329
  {
2309
- id: "STORAGE_DYNAMODB_STORE_LOAD_WORKFLOW_SNAPSHOT_FAILED",
2330
+ id: storage.createStorageErrorId("DYNAMODB", "LOAD_WORKFLOW_SNAPSHOT", "FAILED"),
2310
2331
  domain: error.ErrorDomain.STORAGE,
2311
2332
  category: error.ErrorCategory.THIRD_PARTY,
2312
2333
  details: { workflowName, runId }
@@ -2323,7 +2344,7 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
2323
2344
  if (page < 0) {
2324
2345
  throw new error.MastraError(
2325
2346
  {
2326
- id: "DYNAMODB_STORE_INVALID_PAGE",
2347
+ id: storage.createStorageErrorId("DYNAMODB", "LIST_WORKFLOW_RUNS", "INVALID_PAGE"),
2327
2348
  domain: error.ErrorDomain.STORAGE,
2328
2349
  category: error.ErrorCategory.USER,
2329
2350
  details: { page }
@@ -2393,7 +2414,7 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
2393
2414
  } catch (error$1) {
2394
2415
  throw new error.MastraError(
2395
2416
  {
2396
- id: "STORAGE_DYNAMODB_STORE_LIST_WORKFLOW_RUNS_FAILED",
2417
+ id: storage.createStorageErrorId("DYNAMODB", "LIST_WORKFLOW_RUNS", "FAILED"),
2397
2418
  domain: error.ErrorDomain.STORAGE,
2398
2419
  category: error.ErrorCategory.THIRD_PARTY,
2399
2420
  details: { workflowName: args?.workflowName || "", resourceId: args?.resourceId || "" }
@@ -2447,7 +2468,7 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
2447
2468
  } catch (error$1) {
2448
2469
  throw new error.MastraError(
2449
2470
  {
2450
- id: "STORAGE_DYNAMODB_STORE_GET_WORKFLOW_RUN_BY_ID_FAILED",
2471
+ id: storage.createStorageErrorId("DYNAMODB", "GET_WORKFLOW_RUN_BY_ID", "FAILED"),
2451
2472
  domain: error.ErrorDomain.STORAGE,
2452
2473
  category: error.ErrorCategory.THIRD_PARTY,
2453
2474
  details: { runId, workflowName: args?.workflowName || "" }
@@ -2466,7 +2487,7 @@ var DynamoDBStore = class extends storage.MastraStorage {
2466
2487
  hasInitialized = null;
2467
2488
  stores;
2468
2489
  constructor({ name, config }) {
2469
- super({ id: config.id, name });
2490
+ super({ id: config.id, name, disableInit: config.disableInit });
2470
2491
  try {
2471
2492
  if (!config.tableName || typeof config.tableName !== "string" || config.tableName.trim() === "") {
2472
2493
  throw new Error("DynamoDBStore: config.tableName must be provided and cannot be empty.");
@@ -2501,7 +2522,7 @@ var DynamoDBStore = class extends storage.MastraStorage {
2501
2522
  } catch (error$1) {
2502
2523
  throw new error.MastraError(
2503
2524
  {
2504
- id: "STORAGE_DYNAMODB_STORE_CONSTRUCTOR_FAILED",
2525
+ id: storage.createStorageErrorId("DYNAMODB", "CONSTRUCTOR", "FAILED"),
2505
2526
  domain: error.ErrorDomain.STORAGE,
2506
2527
  category: error.ErrorCategory.USER
2507
2528
  },
@@ -2537,7 +2558,7 @@ var DynamoDBStore = class extends storage.MastraStorage {
2537
2558
  }
2538
2559
  throw new error.MastraError(
2539
2560
  {
2540
- id: "STORAGE_DYNAMODB_STORE_VALIDATE_TABLE_EXISTS_FAILED",
2561
+ id: storage.createStorageErrorId("DYNAMODB", "VALIDATE_TABLE_EXISTS", "FAILED"),
2541
2562
  domain: error.ErrorDomain.STORAGE,
2542
2563
  category: error.ErrorCategory.THIRD_PARTY,
2543
2564
  details: { tableName: this.tableName }
@@ -2560,7 +2581,7 @@ var DynamoDBStore = class extends storage.MastraStorage {
2560
2581
  } catch (error$1) {
2561
2582
  throw new error.MastraError(
2562
2583
  {
2563
- id: "STORAGE_DYNAMODB_STORE_INIT_FAILED",
2584
+ id: storage.createStorageErrorId("DYNAMODB", "INIT", "FAILED"),
2564
2585
  domain: error.ErrorDomain.STORAGE,
2565
2586
  category: error.ErrorCategory.THIRD_PARTY,
2566
2587
  details: { tableName: this.tableName }
@@ -2695,7 +2716,7 @@ var DynamoDBStore = class extends storage.MastraStorage {
2695
2716
  } catch (error$1) {
2696
2717
  throw new error.MastraError(
2697
2718
  {
2698
- id: "STORAGE_DYNAMODB_STORE_CLOSE_FAILED",
2719
+ id: storage.createStorageErrorId("DYNAMODB", "CLOSE", "FAILED"),
2699
2720
  domain: error.ErrorDomain.STORAGE,
2700
2721
  category: error.ErrorCategory.THIRD_PARTY
2701
2722
  },