@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.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { DynamoDBClient, DescribeTableCommand } from '@aws-sdk/client-dynamodb';
2
2
  import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
3
3
  import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
4
- import { MastraStorage, StoreOperations, WorkflowsStorage, normalizePerPage, MemoryStorage, calculatePagination, ScoresStorage, TABLE_SPANS, TABLE_RESOURCES, TABLE_TRACES, TABLE_SCORERS, TABLE_WORKFLOW_SNAPSHOT, TABLE_MESSAGES, TABLE_THREADS } from '@mastra/core/storage';
4
+ import { MastraStorage, createStorageErrorId, StoreOperations, WorkflowsStorage, normalizePerPage, MemoryStorage, calculatePagination, ScoresStorage, SCORERS_SCHEMA, TABLE_SPANS, TABLE_RESOURCES, TABLE_TRACES, TABLE_SCORERS, TABLE_WORKFLOW_SNAPSHOT, TABLE_MESSAGES, TABLE_THREADS } from '@mastra/core/storage';
5
5
  import { Entity, Service } from 'electrodb';
6
6
  import { MessageList } from '@mastra/core/agent';
7
7
  import { saveScorePayloadSchema } from '@mastra/core/evals';
@@ -423,6 +423,10 @@ var scoreEntity = new Entity({
423
423
  return value;
424
424
  }
425
425
  },
426
+ preprocessPrompt: {
427
+ type: "string",
428
+ required: false
429
+ },
426
430
  preprocessStepResult: {
427
431
  type: "string",
428
432
  required: false,
@@ -983,7 +987,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
983
987
  } catch (error) {
984
988
  throw new MastraError(
985
989
  {
986
- id: "STORAGE_DYNAMODB_STORE_GET_THREAD_BY_ID_FAILED",
990
+ id: createStorageErrorId("DYNAMODB", "GET_THREAD_BY_ID", "FAILED"),
987
991
  domain: ErrorDomain.STORAGE,
988
992
  category: ErrorCategory.THIRD_PARTY,
989
993
  details: { threadId }
@@ -1017,7 +1021,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1017
1021
  } catch (error) {
1018
1022
  throw new MastraError(
1019
1023
  {
1020
- id: "STORAGE_DYNAMODB_STORE_SAVE_THREAD_FAILED",
1024
+ id: createStorageErrorId("DYNAMODB", "SAVE_THREAD", "FAILED"),
1021
1025
  domain: ErrorDomain.STORAGE,
1022
1026
  category: ErrorCategory.THIRD_PARTY,
1023
1027
  details: { threadId: thread.id }
@@ -1059,7 +1063,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1059
1063
  } catch (error) {
1060
1064
  throw new MastraError(
1061
1065
  {
1062
- id: "STORAGE_DYNAMODB_STORE_UPDATE_THREAD_FAILED",
1066
+ id: createStorageErrorId("DYNAMODB", "UPDATE_THREAD", "FAILED"),
1063
1067
  domain: ErrorDomain.STORAGE,
1064
1068
  category: ErrorCategory.THIRD_PARTY,
1065
1069
  details: { threadId: id }
@@ -1091,7 +1095,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1091
1095
  } catch (error) {
1092
1096
  throw new MastraError(
1093
1097
  {
1094
- id: "STORAGE_DYNAMODB_STORE_DELETE_THREAD_FAILED",
1098
+ id: createStorageErrorId("DYNAMODB", "DELETE_THREAD", "FAILED"),
1095
1099
  domain: ErrorDomain.STORAGE,
1096
1100
  category: ErrorCategory.THIRD_PARTY,
1097
1101
  details: { threadId }
@@ -1117,7 +1121,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1117
1121
  } catch (error) {
1118
1122
  throw new MastraError(
1119
1123
  {
1120
- id: "STORAGE_DYNAMODB_STORE_LIST_MESSAGES_BY_ID_FAILED",
1124
+ id: createStorageErrorId("DYNAMODB", "LIST_MESSAGES_BY_ID", "FAILED"),
1121
1125
  domain: ErrorDomain.STORAGE,
1122
1126
  category: ErrorCategory.THIRD_PARTY,
1123
1127
  details: { messageIds: JSON.stringify(messageIds) }
@@ -1128,15 +1132,16 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1128
1132
  }
1129
1133
  async listMessages(args) {
1130
1134
  const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
1131
- if (!threadId.trim()) {
1135
+ const threadIds = Array.isArray(threadId) ? threadId : [threadId];
1136
+ if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
1132
1137
  throw new MastraError(
1133
1138
  {
1134
- id: "STORAGE_DYNAMODB_LIST_MESSAGES_INVALID_THREAD_ID",
1139
+ id: createStorageErrorId("DYNAMODB", "LIST_MESSAGES", "INVALID_THREAD_ID"),
1135
1140
  domain: ErrorDomain.STORAGE,
1136
1141
  category: ErrorCategory.THIRD_PARTY,
1137
- details: { threadId }
1142
+ details: { threadId: Array.isArray(threadId) ? threadId.join(",") : threadId }
1138
1143
  },
1139
- new Error("threadId must be a non-empty string")
1144
+ new Error("threadId must be a non-empty string or array of non-empty strings")
1140
1145
  );
1141
1146
  }
1142
1147
  const perPage = normalizePerPage(perPageInput, 40);
@@ -1145,7 +1150,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1145
1150
  if (page < 0) {
1146
1151
  throw new MastraError(
1147
1152
  {
1148
- id: "STORAGE_DYNAMODB_LIST_MESSAGES_INVALID_PAGE",
1153
+ id: createStorageErrorId("DYNAMODB", "LIST_MESSAGES", "INVALID_PAGE"),
1149
1154
  domain: ErrorDomain.STORAGE,
1150
1155
  category: ErrorCategory.USER,
1151
1156
  details: { page }
@@ -1209,7 +1214,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1209
1214
  let includeMessages = [];
1210
1215
  if (include && include.length > 0) {
1211
1216
  const selectBy = { include };
1212
- includeMessages = await this._getIncludedMessages(threadId, selectBy);
1217
+ includeMessages = await this._getIncludedMessages(selectBy);
1213
1218
  for (const includeMsg of includeMessages) {
1214
1219
  if (!messageIds.has(includeMsg.id)) {
1215
1220
  paginatedMessages.push(includeMsg);
@@ -1243,11 +1248,11 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1243
1248
  } catch (error) {
1244
1249
  const mastraError = new MastraError(
1245
1250
  {
1246
- id: "STORAGE_DYNAMODB_STORE_LIST_MESSAGES_FAILED",
1251
+ id: createStorageErrorId("DYNAMODB", "LIST_MESSAGES", "FAILED"),
1247
1252
  domain: ErrorDomain.STORAGE,
1248
1253
  category: ErrorCategory.THIRD_PARTY,
1249
1254
  details: {
1250
- threadId,
1255
+ threadId: Array.isArray(threadId) ? threadId.join(",") : threadId,
1251
1256
  resourceId: resourceId ?? ""
1252
1257
  }
1253
1258
  },
@@ -1326,7 +1331,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1326
1331
  } catch (error) {
1327
1332
  throw new MastraError(
1328
1333
  {
1329
- id: "STORAGE_DYNAMODB_STORE_SAVE_MESSAGES_FAILED",
1334
+ id: createStorageErrorId("DYNAMODB", "SAVE_MESSAGES", "FAILED"),
1330
1335
  domain: ErrorDomain.STORAGE,
1331
1336
  category: ErrorCategory.THIRD_PARTY,
1332
1337
  details: { count: messages.length }
@@ -1341,7 +1346,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1341
1346
  if (page < 0) {
1342
1347
  throw new MastraError(
1343
1348
  {
1344
- id: "STORAGE_DYNAMODB_LIST_THREADS_BY_RESOURCE_ID_INVALID_PAGE",
1349
+ id: createStorageErrorId("DYNAMODB", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
1345
1350
  domain: ErrorDomain.STORAGE,
1346
1351
  category: ErrorCategory.USER,
1347
1352
  details: { page }
@@ -1376,7 +1381,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1376
1381
  } catch (error) {
1377
1382
  throw new MastraError(
1378
1383
  {
1379
- id: "DYNAMODB_STORAGE_LIST_THREADS_BY_RESOURCE_ID_FAILED",
1384
+ id: createStorageErrorId("DYNAMODB", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
1380
1385
  domain: ErrorDomain.STORAGE,
1381
1386
  category: ErrorCategory.THIRD_PARTY,
1382
1387
  details: { resourceId, page, perPage }
@@ -1386,19 +1391,23 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1386
1391
  }
1387
1392
  }
1388
1393
  // Helper method to get included messages with context
1389
- async _getIncludedMessages(threadId, selectBy) {
1390
- if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
1394
+ async _getIncludedMessages(selectBy) {
1391
1395
  if (!selectBy?.include?.length) {
1392
1396
  return [];
1393
1397
  }
1394
1398
  const includeMessages = [];
1395
1399
  for (const includeItem of selectBy.include) {
1396
1400
  try {
1397
- const { id, threadId: targetThreadId, withPreviousMessages = 0, withNextMessages = 0 } = includeItem;
1398
- const searchThreadId = targetThreadId || threadId;
1401
+ const { id, withPreviousMessages = 0, withNextMessages = 0 } = includeItem;
1402
+ const targetResult = await this.service.entities.message.get({ entity: "message", id }).go();
1403
+ if (!targetResult.data) {
1404
+ this.logger.warn("Target message not found", { id });
1405
+ continue;
1406
+ }
1407
+ const targetMessageData = targetResult.data;
1408
+ const searchThreadId = targetMessageData.threadId;
1399
1409
  this.logger.debug("Getting included messages for", {
1400
1410
  id,
1401
- targetThreadId,
1402
1411
  searchThreadId,
1403
1412
  withPreviousMessages,
1404
1413
  withNextMessages
@@ -1421,7 +1430,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1421
1430
  });
1422
1431
  const targetIndex = allMessages.findIndex((msg) => msg.id === id);
1423
1432
  if (targetIndex === -1) {
1424
- this.logger.warn("Target message not found", { id, threadId: searchThreadId });
1433
+ this.logger.warn("Target message not found in thread", { id, threadId: searchThreadId });
1425
1434
  continue;
1426
1435
  }
1427
1436
  this.logger.debug("Found target message at index", { id, targetIndex, totalMessages: allMessages.length });
@@ -1506,7 +1515,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1506
1515
  } catch (error) {
1507
1516
  throw new MastraError(
1508
1517
  {
1509
- id: "STORAGE_DYNAMODB_STORE_UPDATE_MESSAGES_FAILED",
1518
+ id: createStorageErrorId("DYNAMODB", "UPDATE_MESSAGES", "FAILED"),
1510
1519
  domain: ErrorDomain.STORAGE,
1511
1520
  category: ErrorCategory.THIRD_PARTY,
1512
1521
  details: { count: messages.length }
@@ -1535,7 +1544,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1535
1544
  } catch (error) {
1536
1545
  throw new MastraError(
1537
1546
  {
1538
- id: "STORAGE_DYNAMODB_STORE_GET_RESOURCE_BY_ID_FAILED",
1547
+ id: createStorageErrorId("DYNAMODB", "GET_RESOURCE_BY_ID", "FAILED"),
1539
1548
  domain: ErrorDomain.STORAGE,
1540
1549
  category: ErrorCategory.THIRD_PARTY,
1541
1550
  details: { resourceId }
@@ -1567,7 +1576,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1567
1576
  } catch (error) {
1568
1577
  throw new MastraError(
1569
1578
  {
1570
- id: "STORAGE_DYNAMODB_STORE_SAVE_RESOURCE_FAILED",
1579
+ id: createStorageErrorId("DYNAMODB", "SAVE_RESOURCE", "FAILED"),
1571
1580
  domain: ErrorDomain.STORAGE,
1572
1581
  category: ErrorCategory.THIRD_PARTY,
1573
1582
  details: { resourceId: resource.id }
@@ -1616,7 +1625,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1616
1625
  } catch (error) {
1617
1626
  throw new MastraError(
1618
1627
  {
1619
- id: "STORAGE_DYNAMODB_STORE_UPDATE_RESOURCE_FAILED",
1628
+ id: createStorageErrorId("DYNAMODB", "UPDATE_RESOURCE", "FAILED"),
1620
1629
  domain: ErrorDomain.STORAGE,
1621
1630
  category: ErrorCategory.THIRD_PARTY,
1622
1631
  details: { resourceId }
@@ -1716,7 +1725,7 @@ var StoreOperationsDynamoDB = class extends StoreOperations {
1716
1725
  }
1717
1726
  throw new MastraError(
1718
1727
  {
1719
- id: "STORAGE_DYNAMODB_STORE_VALIDATE_TABLE_EXISTS_FAILED",
1728
+ id: createStorageErrorId("DYNAMODB", "VALIDATE_TABLE_EXISTS", "FAILED"),
1720
1729
  domain: ErrorDomain.STORAGE,
1721
1730
  category: ErrorCategory.THIRD_PARTY,
1722
1731
  details: { tableName: this.tableName }
@@ -1749,7 +1758,7 @@ var StoreOperationsDynamoDB = class extends StoreOperations {
1749
1758
  this.logger.error("Error validating table access", { tableName: this.tableName, error });
1750
1759
  throw new MastraError(
1751
1760
  {
1752
- id: "STORAGE_DYNAMODB_STORE_VALIDATE_TABLE_ACCESS_FAILED",
1761
+ id: createStorageErrorId("DYNAMODB", "VALIDATE_TABLE_ACCESS", "FAILED"),
1753
1762
  domain: ErrorDomain.STORAGE,
1754
1763
  category: ErrorCategory.THIRD_PARTY,
1755
1764
  details: { tableName: this.tableName }
@@ -1763,7 +1772,7 @@ var StoreOperationsDynamoDB = class extends StoreOperations {
1763
1772
  const entityName = this.getEntityNameForTable(tableName);
1764
1773
  if (!entityName || !this.service.entities[entityName]) {
1765
1774
  throw new MastraError({
1766
- id: "STORAGE_DYNAMODB_STORE_INSERT_INVALID_ARGS",
1775
+ id: createStorageErrorId("DYNAMODB", "INSERT", "INVALID_ARGS"),
1767
1776
  domain: ErrorDomain.STORAGE,
1768
1777
  category: ErrorCategory.USER,
1769
1778
  text: "No entity defined for tableName",
@@ -1776,7 +1785,7 @@ var StoreOperationsDynamoDB = class extends StoreOperations {
1776
1785
  } catch (error) {
1777
1786
  throw new MastraError(
1778
1787
  {
1779
- id: "STORAGE_DYNAMODB_STORE_INSERT_FAILED",
1788
+ id: createStorageErrorId("DYNAMODB", "INSERT", "FAILED"),
1780
1789
  domain: ErrorDomain.STORAGE,
1781
1790
  category: ErrorCategory.THIRD_PARTY,
1782
1791
  details: { tableName }
@@ -1795,7 +1804,7 @@ var StoreOperationsDynamoDB = class extends StoreOperations {
1795
1804
  const entityName = this.getEntityNameForTable(tableName);
1796
1805
  if (!entityName || !this.service.entities[entityName]) {
1797
1806
  throw new MastraError({
1798
- id: "STORAGE_DYNAMODB_STORE_CLEAR_TABLE_INVALID_ARGS",
1807
+ id: createStorageErrorId("DYNAMODB", "CLEAR_TABLE", "INVALID_ARGS"),
1799
1808
  domain: ErrorDomain.STORAGE,
1800
1809
  category: ErrorCategory.USER,
1801
1810
  text: "No entity defined for tableName",
@@ -1858,7 +1867,7 @@ var StoreOperationsDynamoDB = class extends StoreOperations {
1858
1867
  } catch (error) {
1859
1868
  throw new MastraError(
1860
1869
  {
1861
- id: "STORAGE_DYNAMODB_STORE_CLEAR_TABLE_FAILED",
1870
+ id: createStorageErrorId("DYNAMODB", "CLEAR_TABLE", "FAILED"),
1862
1871
  domain: ErrorDomain.STORAGE,
1863
1872
  category: ErrorCategory.THIRD_PARTY,
1864
1873
  details: { tableName }
@@ -1875,7 +1884,7 @@ var StoreOperationsDynamoDB = class extends StoreOperations {
1875
1884
  const entityName = this.getEntityNameForTable(tableName);
1876
1885
  if (!entityName || !this.service.entities[entityName]) {
1877
1886
  throw new MastraError({
1878
- id: "STORAGE_DYNAMODB_STORE_BATCH_INSERT_INVALID_ARGS",
1887
+ id: createStorageErrorId("DYNAMODB", "BATCH_INSERT", "INVALID_ARGS"),
1879
1888
  domain: ErrorDomain.STORAGE,
1880
1889
  category: ErrorCategory.USER,
1881
1890
  text: "No entity defined for tableName",
@@ -1903,7 +1912,7 @@ var StoreOperationsDynamoDB = class extends StoreOperations {
1903
1912
  } catch (error) {
1904
1913
  throw new MastraError(
1905
1914
  {
1906
- id: "STORAGE_DYNAMODB_STORE_BATCH_INSERT_FAILED",
1915
+ id: createStorageErrorId("DYNAMODB", "BATCH_INSERT", "FAILED"),
1907
1916
  domain: ErrorDomain.STORAGE,
1908
1917
  category: ErrorCategory.THIRD_PARTY,
1909
1918
  details: { tableName }
@@ -1920,7 +1929,7 @@ var StoreOperationsDynamoDB = class extends StoreOperations {
1920
1929
  const entityName = this.getEntityNameForTable(tableName);
1921
1930
  if (!entityName || !this.service.entities[entityName]) {
1922
1931
  throw new MastraError({
1923
- id: "STORAGE_DYNAMODB_STORE_LOAD_INVALID_ARGS",
1932
+ id: createStorageErrorId("DYNAMODB", "LOAD", "INVALID_ARGS"),
1924
1933
  domain: ErrorDomain.STORAGE,
1925
1934
  category: ErrorCategory.USER,
1926
1935
  text: "No entity defined for tableName",
@@ -1938,7 +1947,7 @@ var StoreOperationsDynamoDB = class extends StoreOperations {
1938
1947
  } catch (error) {
1939
1948
  throw new MastraError(
1940
1949
  {
1941
- id: "STORAGE_DYNAMODB_STORE_LOAD_FAILED",
1950
+ id: createStorageErrorId("DYNAMODB", "LOAD", "FAILED"),
1942
1951
  domain: ErrorDomain.STORAGE,
1943
1952
  category: ErrorCategory.THIRD_PARTY,
1944
1953
  details: { tableName }
@@ -1954,14 +1963,28 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
1954
1963
  super();
1955
1964
  this.service = service;
1956
1965
  }
1957
- // Helper function to parse score data (handle JSON fields)
1966
+ /**
1967
+ * DynamoDB-specific score row transformation.
1968
+ *
1969
+ * Note: This implementation does NOT use coreTransformScoreRow because:
1970
+ * 1. ElectroDB already parses JSON fields via its entity getters
1971
+ * 2. DynamoDB stores empty strings for null values (which need special handling)
1972
+ * 3. 'entity' is a reserved ElectroDB key, so we use 'entityData' column
1973
+ */
1958
1974
  parseScoreData(data) {
1975
+ const result = {};
1976
+ for (const key of Object.keys(SCORERS_SCHEMA)) {
1977
+ if (["traceId", "resourceId", "threadId", "spanId"].includes(key)) {
1978
+ result[key] = data[key] === "" ? null : data[key];
1979
+ continue;
1980
+ }
1981
+ result[key] = data[key];
1982
+ }
1983
+ result.entity = data.entityData ?? null;
1959
1984
  return {
1960
- ...data,
1961
- // Convert date strings back to Date objects for consistency
1985
+ ...result,
1962
1986
  createdAt: data.createdAt ? new Date(data.createdAt) : /* @__PURE__ */ new Date(),
1963
1987
  updatedAt: data.updatedAt ? new Date(data.updatedAt) : /* @__PURE__ */ new Date()
1964
- // JSON fields are already transformed by the entity's getters
1965
1988
  };
1966
1989
  }
1967
1990
  async getScoreById({ id }) {
@@ -1975,7 +1998,7 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
1975
1998
  } catch (error) {
1976
1999
  throw new MastraError(
1977
2000
  {
1978
- id: "STORAGE_DYNAMODB_STORE_GET_SCORE_BY_ID_FAILED",
2001
+ id: createStorageErrorId("DYNAMODB", "GET_SCORE_BY_ID", "FAILED"),
1979
2002
  domain: ErrorDomain.STORAGE,
1980
2003
  category: ErrorCategory.THIRD_PARTY,
1981
2004
  details: { id }
@@ -1991,7 +2014,7 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
1991
2014
  } catch (error) {
1992
2015
  throw new MastraError(
1993
2016
  {
1994
- id: "STORAGE_DYNAMODB_STORE_SAVE_SCORE_FAILED",
2017
+ id: createStorageErrorId("DYNAMODB", "SAVE_SCORE", "VALIDATION_FAILED"),
1995
2018
  domain: ErrorDomain.STORAGE,
1996
2019
  category: ErrorCategory.THIRD_PARTY
1997
2020
  },
@@ -2000,35 +2023,33 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
2000
2023
  }
2001
2024
  const now = /* @__PURE__ */ new Date();
2002
2025
  const scoreId = `score-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
2003
- const scoreData = {
2004
- entity: "score",
2005
- id: scoreId,
2006
- scorerId: validatedScore.scorerId,
2007
- traceId: validatedScore.traceId || "",
2008
- spanId: validatedScore.spanId || "",
2009
- runId: validatedScore.runId,
2010
- scorer: typeof validatedScore.scorer === "string" ? validatedScore.scorer : JSON.stringify(validatedScore.scorer),
2011
- preprocessStepResult: typeof validatedScore.preprocessStepResult === "string" ? validatedScore.preprocessStepResult : JSON.stringify(validatedScore.preprocessStepResult),
2012
- analyzeStepResult: typeof validatedScore.analyzeStepResult === "string" ? validatedScore.analyzeStepResult : JSON.stringify(validatedScore.analyzeStepResult),
2013
- score: validatedScore.score,
2014
- reason: validatedScore.reason,
2015
- preprocessPrompt: validatedScore.preprocessPrompt,
2016
- generateScorePrompt: validatedScore.generateScorePrompt,
2017
- generateReasonPrompt: validatedScore.generateReasonPrompt,
2018
- analyzePrompt: validatedScore.analyzePrompt,
2019
- input: typeof validatedScore.input === "string" ? validatedScore.input : JSON.stringify(validatedScore.input),
2020
- output: typeof validatedScore.output === "string" ? validatedScore.output : JSON.stringify(validatedScore.output),
2021
- additionalContext: typeof validatedScore.additionalContext === "string" ? validatedScore.additionalContext : JSON.stringify(validatedScore.additionalContext),
2022
- requestContext: typeof validatedScore.requestContext === "string" ? validatedScore.requestContext : JSON.stringify(validatedScore.requestContext),
2023
- entityType: validatedScore.entityType,
2024
- entityData: typeof validatedScore.entity === "string" ? validatedScore.entity : JSON.stringify(validatedScore.entity),
2025
- entityId: validatedScore.entityId,
2026
- source: validatedScore.source,
2027
- resourceId: validatedScore.resourceId || "",
2028
- threadId: validatedScore.threadId || "",
2029
- createdAt: now.toISOString(),
2030
- updatedAt: now.toISOString()
2031
- };
2026
+ const scorer = typeof validatedScore.scorer === "string" ? validatedScore.scorer : JSON.stringify(validatedScore.scorer);
2027
+ const preprocessStepResult = typeof validatedScore.preprocessStepResult === "string" ? validatedScore.preprocessStepResult : JSON.stringify(validatedScore.preprocessStepResult);
2028
+ const analyzeStepResult = typeof validatedScore.analyzeStepResult === "string" ? validatedScore.analyzeStepResult : JSON.stringify(validatedScore.analyzeStepResult);
2029
+ const input = typeof validatedScore.input === "string" ? validatedScore.input : JSON.stringify(validatedScore.input);
2030
+ const output = typeof validatedScore.output === "string" ? validatedScore.output : JSON.stringify(validatedScore.output);
2031
+ const requestContext = typeof validatedScore.requestContext === "string" ? validatedScore.requestContext : JSON.stringify(validatedScore.requestContext);
2032
+ const entity = typeof validatedScore.entity === "string" ? validatedScore.entity : JSON.stringify(validatedScore.entity);
2033
+ const scoreData = Object.fromEntries(
2034
+ Object.entries({
2035
+ ...validatedScore,
2036
+ entity: "score",
2037
+ id: scoreId,
2038
+ scorer,
2039
+ preprocessStepResult,
2040
+ analyzeStepResult,
2041
+ input,
2042
+ output,
2043
+ requestContext,
2044
+ entityData: entity,
2045
+ traceId: validatedScore.traceId || "",
2046
+ resourceId: validatedScore.resourceId || "",
2047
+ threadId: validatedScore.threadId || "",
2048
+ spanId: validatedScore.spanId || "",
2049
+ createdAt: now.toISOString(),
2050
+ updatedAt: now.toISOString()
2051
+ }).filter(([_, value]) => value !== void 0 && value !== null)
2052
+ );
2032
2053
  try {
2033
2054
  await this.service.entities.score.upsert(scoreData).go();
2034
2055
  const savedScore = {
@@ -2041,7 +2062,7 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
2041
2062
  } catch (error) {
2042
2063
  throw new MastraError(
2043
2064
  {
2044
- id: "STORAGE_DYNAMODB_STORE_SAVE_SCORE_FAILED",
2065
+ id: createStorageErrorId("DYNAMODB", "SAVE_SCORE", "FAILED"),
2045
2066
  domain: ErrorDomain.STORAGE,
2046
2067
  category: ErrorCategory.THIRD_PARTY,
2047
2068
  details: { scorerId: score.scorerId, runId: score.runId }
@@ -2089,7 +2110,7 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
2089
2110
  } catch (error) {
2090
2111
  throw new MastraError(
2091
2112
  {
2092
- id: "STORAGE_DYNAMODB_STORE_GET_SCORES_BY_SCORER_ID_FAILED",
2113
+ id: createStorageErrorId("DYNAMODB", "LIST_SCORES_BY_SCORER_ID", "FAILED"),
2093
2114
  domain: ErrorDomain.STORAGE,
2094
2115
  category: ErrorCategory.THIRD_PARTY,
2095
2116
  details: {
@@ -2133,7 +2154,7 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
2133
2154
  } catch (error) {
2134
2155
  throw new MastraError(
2135
2156
  {
2136
- id: "STORAGE_DYNAMODB_STORE_GET_SCORES_BY_RUN_ID_FAILED",
2157
+ id: createStorageErrorId("DYNAMODB", "LIST_SCORES_BY_RUN_ID", "FAILED"),
2137
2158
  domain: ErrorDomain.STORAGE,
2138
2159
  category: ErrorCategory.THIRD_PARTY,
2139
2160
  details: { runId, page: pagination.page, perPage: pagination.perPage }
@@ -2172,7 +2193,7 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
2172
2193
  } catch (error) {
2173
2194
  throw new MastraError(
2174
2195
  {
2175
- id: "STORAGE_DYNAMODB_STORE_GET_SCORES_BY_ENTITY_ID_FAILED",
2196
+ id: createStorageErrorId("DYNAMODB", "LIST_SCORES_BY_ENTITY_ID", "FAILED"),
2176
2197
  domain: ErrorDomain.STORAGE,
2177
2198
  category: ErrorCategory.THIRD_PARTY,
2178
2199
  details: { entityId, entityType, page: pagination.page, perPage: pagination.perPage }
@@ -2210,7 +2231,7 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
2210
2231
  } catch (error) {
2211
2232
  throw new MastraError(
2212
2233
  {
2213
- id: "STORAGE_DYNAMODB_STORE_GET_SCORES_BY_SPAN_FAILED",
2234
+ id: createStorageErrorId("DYNAMODB", "LIST_SCORES_BY_SPAN", "FAILED"),
2214
2235
  domain: ErrorDomain.STORAGE,
2215
2236
  category: ErrorCategory.THIRD_PARTY,
2216
2237
  details: { traceId, spanId, page: pagination.page, perPage: pagination.perPage }
@@ -2276,7 +2297,7 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
2276
2297
  } catch (error) {
2277
2298
  throw new MastraError(
2278
2299
  {
2279
- id: "STORAGE_DYNAMODB_STORE_PERSIST_WORKFLOW_SNAPSHOT_FAILED",
2300
+ id: createStorageErrorId("DYNAMODB", "PERSIST_WORKFLOW_SNAPSHOT", "FAILED"),
2280
2301
  domain: ErrorDomain.STORAGE,
2281
2302
  category: ErrorCategory.THIRD_PARTY,
2282
2303
  details: { workflowName, runId }
@@ -2304,7 +2325,7 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
2304
2325
  } catch (error) {
2305
2326
  throw new MastraError(
2306
2327
  {
2307
- id: "STORAGE_DYNAMODB_STORE_LOAD_WORKFLOW_SNAPSHOT_FAILED",
2328
+ id: createStorageErrorId("DYNAMODB", "LOAD_WORKFLOW_SNAPSHOT", "FAILED"),
2308
2329
  domain: ErrorDomain.STORAGE,
2309
2330
  category: ErrorCategory.THIRD_PARTY,
2310
2331
  details: { workflowName, runId }
@@ -2321,7 +2342,7 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
2321
2342
  if (page < 0) {
2322
2343
  throw new MastraError(
2323
2344
  {
2324
- id: "DYNAMODB_STORE_INVALID_PAGE",
2345
+ id: createStorageErrorId("DYNAMODB", "LIST_WORKFLOW_RUNS", "INVALID_PAGE"),
2325
2346
  domain: ErrorDomain.STORAGE,
2326
2347
  category: ErrorCategory.USER,
2327
2348
  details: { page }
@@ -2391,7 +2412,7 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
2391
2412
  } catch (error) {
2392
2413
  throw new MastraError(
2393
2414
  {
2394
- id: "STORAGE_DYNAMODB_STORE_LIST_WORKFLOW_RUNS_FAILED",
2415
+ id: createStorageErrorId("DYNAMODB", "LIST_WORKFLOW_RUNS", "FAILED"),
2395
2416
  domain: ErrorDomain.STORAGE,
2396
2417
  category: ErrorCategory.THIRD_PARTY,
2397
2418
  details: { workflowName: args?.workflowName || "", resourceId: args?.resourceId || "" }
@@ -2445,7 +2466,7 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
2445
2466
  } catch (error) {
2446
2467
  throw new MastraError(
2447
2468
  {
2448
- id: "STORAGE_DYNAMODB_STORE_GET_WORKFLOW_RUN_BY_ID_FAILED",
2469
+ id: createStorageErrorId("DYNAMODB", "GET_WORKFLOW_RUN_BY_ID", "FAILED"),
2449
2470
  domain: ErrorDomain.STORAGE,
2450
2471
  category: ErrorCategory.THIRD_PARTY,
2451
2472
  details: { runId, workflowName: args?.workflowName || "" }
@@ -2464,7 +2485,7 @@ var DynamoDBStore = class extends MastraStorage {
2464
2485
  hasInitialized = null;
2465
2486
  stores;
2466
2487
  constructor({ name, config }) {
2467
- super({ id: config.id, name });
2488
+ super({ id: config.id, name, disableInit: config.disableInit });
2468
2489
  try {
2469
2490
  if (!config.tableName || typeof config.tableName !== "string" || config.tableName.trim() === "") {
2470
2491
  throw new Error("DynamoDBStore: config.tableName must be provided and cannot be empty.");
@@ -2499,7 +2520,7 @@ var DynamoDBStore = class extends MastraStorage {
2499
2520
  } catch (error) {
2500
2521
  throw new MastraError(
2501
2522
  {
2502
- id: "STORAGE_DYNAMODB_STORE_CONSTRUCTOR_FAILED",
2523
+ id: createStorageErrorId("DYNAMODB", "CONSTRUCTOR", "FAILED"),
2503
2524
  domain: ErrorDomain.STORAGE,
2504
2525
  category: ErrorCategory.USER
2505
2526
  },
@@ -2535,7 +2556,7 @@ var DynamoDBStore = class extends MastraStorage {
2535
2556
  }
2536
2557
  throw new MastraError(
2537
2558
  {
2538
- id: "STORAGE_DYNAMODB_STORE_VALIDATE_TABLE_EXISTS_FAILED",
2559
+ id: createStorageErrorId("DYNAMODB", "VALIDATE_TABLE_EXISTS", "FAILED"),
2539
2560
  domain: ErrorDomain.STORAGE,
2540
2561
  category: ErrorCategory.THIRD_PARTY,
2541
2562
  details: { tableName: this.tableName }
@@ -2558,7 +2579,7 @@ var DynamoDBStore = class extends MastraStorage {
2558
2579
  } catch (error) {
2559
2580
  throw new MastraError(
2560
2581
  {
2561
- id: "STORAGE_DYNAMODB_STORE_INIT_FAILED",
2582
+ id: createStorageErrorId("DYNAMODB", "INIT", "FAILED"),
2562
2583
  domain: ErrorDomain.STORAGE,
2563
2584
  category: ErrorCategory.THIRD_PARTY,
2564
2585
  details: { tableName: this.tableName }
@@ -2693,7 +2714,7 @@ var DynamoDBStore = class extends MastraStorage {
2693
2714
  } catch (error) {
2694
2715
  throw new MastraError(
2695
2716
  {
2696
- id: "STORAGE_DYNAMODB_STORE_CLOSE_FAILED",
2717
+ id: createStorageErrorId("DYNAMODB", "CLOSE", "FAILED"),
2697
2718
  domain: ErrorDomain.STORAGE,
2698
2719
  category: ErrorCategory.THIRD_PARTY
2699
2720
  },