@mastra/dynamodb 0.0.0-new-scorer-api-20250801075530 → 0.0.0-partial-response-backport-20251204204441

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +1118 -0
  2. package/README.md +0 -4
  3. package/dist/entities/index.d.ts +19 -0
  4. package/dist/entities/index.d.ts.map +1 -1
  5. package/dist/entities/score.d.ts +19 -0
  6. package/dist/entities/score.d.ts.map +1 -1
  7. package/dist/index.cjs +243 -56
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.js +244 -57
  11. package/dist/index.js.map +1 -1
  12. package/dist/storage/domains/memory/index.d.ts +16 -4
  13. package/dist/storage/domains/memory/index.d.ts.map +1 -1
  14. package/dist/storage/domains/operations/index.d.ts.map +1 -1
  15. package/dist/storage/domains/score/index.d.ts +11 -2
  16. package/dist/storage/domains/score/index.d.ts.map +1 -1
  17. package/dist/storage/domains/traces/index.d.ts +1 -1
  18. package/dist/storage/domains/workflows/index.d.ts +23 -11
  19. package/dist/storage/domains/workflows/index.d.ts.map +1 -1
  20. package/dist/storage/index.d.ts +48 -16
  21. package/dist/storage/index.d.ts.map +1 -1
  22. package/package.json +29 -12
  23. package/src/entities/eval.ts +0 -102
  24. package/src/entities/index.ts +0 -27
  25. package/src/entities/message.ts +0 -143
  26. package/src/entities/resource.ts +0 -57
  27. package/src/entities/score.ts +0 -317
  28. package/src/entities/thread.ts +0 -66
  29. package/src/entities/trace.ts +0 -129
  30. package/src/entities/utils.ts +0 -51
  31. package/src/entities/workflow-snapshot.ts +0 -56
  32. package/src/index.ts +0 -1
  33. package/src/storage/docker-compose.yml +0 -16
  34. package/src/storage/domains/legacy-evals/index.ts +0 -243
  35. package/src/storage/domains/memory/index.ts +0 -894
  36. package/src/storage/domains/operations/index.ts +0 -433
  37. package/src/storage/domains/score/index.ts +0 -288
  38. package/src/storage/domains/traces/index.ts +0 -286
  39. package/src/storage/domains/workflows/index.ts +0 -297
  40. package/src/storage/index.test.ts +0 -1420
  41. package/src/storage/index.ts +0 -483
package/README.md CHANGED
@@ -138,7 +138,3 @@ This implementation uses a single-table design pattern with ElectroDB, which off
138
138
  3. **Simplified administration**: Only one table to monitor and back up
139
139
  4. **Reduced complexity**: Consistent access patterns across entities
140
140
  5. **Transaction support**: Atomic operations across different entity types
141
-
142
- ## License
143
-
144
- MIT
@@ -534,6 +534,10 @@ export declare function getElectroDbService(client: DynamoDBDocumentClient, tabl
534
534
  type: "string";
535
535
  required: false;
536
536
  };
537
+ spanId: {
538
+ type: "string";
539
+ required: false;
540
+ };
537
541
  runId: {
538
542
  type: "string";
539
543
  required: true;
@@ -550,6 +554,10 @@ export declare function getElectroDbService(client: DynamoDBDocumentClient, tabl
550
554
  set: (value?: Record<string, unknown> | string) => string | undefined;
551
555
  get: (value?: string) => any;
552
556
  };
557
+ preprocessPrompt: {
558
+ type: "string";
559
+ required: false;
560
+ };
553
561
  preprocessStepResult: {
554
562
  type: "string";
555
563
  required: false;
@@ -740,6 +748,17 @@ export declare function getElectroDbService(client: DynamoDBDocumentClient, tabl
740
748
  composite: "createdAt"[];
741
749
  };
742
750
  };
751
+ bySpan: {
752
+ index: string;
753
+ pk: {
754
+ field: string;
755
+ composite: ("entity" | "traceId" | "spanId")[];
756
+ };
757
+ sk: {
758
+ field: string;
759
+ composite: "createdAt"[];
760
+ };
761
+ };
743
762
  };
744
763
  }>;
745
764
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entities/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgBpF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entities/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgBpF"}
@@ -18,6 +18,10 @@ export declare const scoreEntity: Entity<string, string, string, {
18
18
  type: "string";
19
19
  required: false;
20
20
  };
21
+ spanId: {
22
+ type: "string";
23
+ required: false;
24
+ };
21
25
  runId: {
22
26
  type: "string";
23
27
  required: true;
@@ -34,6 +38,10 @@ export declare const scoreEntity: Entity<string, string, string, {
34
38
  set: (value?: Record<string, unknown> | string) => string | undefined;
35
39
  get: (value?: string) => any;
36
40
  };
41
+ preprocessPrompt: {
42
+ type: "string";
43
+ required: false;
44
+ };
37
45
  preprocessStepResult: {
38
46
  type: "string";
39
47
  required: false;
@@ -224,6 +232,17 @@ export declare const scoreEntity: Entity<string, string, string, {
224
232
  composite: "createdAt"[];
225
233
  };
226
234
  };
235
+ bySpan: {
236
+ index: string;
237
+ pk: {
238
+ field: string;
239
+ composite: ("entity" | "traceId" | "spanId")[];
240
+ };
241
+ sk: {
242
+ field: string;
243
+ composite: "createdAt"[];
244
+ };
245
+ };
227
246
  };
228
247
  }>;
229
248
  //# sourceMappingURL=score.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"score.d.ts","sourceRoot":"","sources":["../../src/entities/score.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGnC,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;0BA+BJ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BA8CN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;;;;;0BAoBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkExB,CAAC"}
1
+ {"version":3,"file":"score.d.ts","sourceRoot":"","sources":["../../src/entities/score.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGnC,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAmCJ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;;;;;0BAoBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BA8CN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;;;;;0BAoBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuExB,CAAC"}
package/dist/index.cjs CHANGED
@@ -6,6 +6,7 @@ var error = require('@mastra/core/error');
6
6
  var storage = require('@mastra/core/storage');
7
7
  var electrodb = require('electrodb');
8
8
  var agent = require('@mastra/core/agent');
9
+ var scores = require('@mastra/core/scores');
9
10
 
10
11
  // src/storage/index.ts
11
12
 
@@ -372,6 +373,10 @@ var scoreEntity = new electrodb.Entity({
372
373
  type: "string",
373
374
  required: false
374
375
  },
376
+ spanId: {
377
+ type: "string",
378
+ required: false
379
+ },
375
380
  runId: {
376
381
  type: "string",
377
382
  required: true
@@ -420,6 +425,10 @@ var scoreEntity = new electrodb.Entity({
420
425
  return value;
421
426
  }
422
427
  },
428
+ preprocessPrompt: {
429
+ type: "string",
430
+ required: false
431
+ },
423
432
  preprocessStepResult: {
424
433
  type: "string",
425
434
  required: false,
@@ -658,6 +667,11 @@ var scoreEntity = new electrodb.Entity({
658
667
  index: "gsi6",
659
668
  pk: { field: "gsi6pk", composite: ["entity", "threadId"] },
660
669
  sk: { field: "gsi6sk", composite: ["createdAt"] }
670
+ },
671
+ bySpan: {
672
+ index: "gsi7",
673
+ pk: { field: "gsi7pk", composite: ["entity", "traceId", "spanId"] },
674
+ sk: { field: "gsi7sk", composite: ["createdAt"] }
661
675
  }
662
676
  }
663
677
  });
@@ -1123,6 +1137,20 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1123
1137
  // transformed by the ElectroDB entity getters.
1124
1138
  };
1125
1139
  }
1140
+ // Helper function to transform and sort threads
1141
+ transformAndSortThreads(rawThreads, orderBy, sortDirection) {
1142
+ return rawThreads.map((data) => ({
1143
+ ...data,
1144
+ // Convert date strings back to Date objects for consistency
1145
+ createdAt: typeof data.createdAt === "string" ? new Date(data.createdAt) : data.createdAt,
1146
+ updatedAt: typeof data.updatedAt === "string" ? new Date(data.updatedAt) : data.updatedAt
1147
+ })).sort((a, b) => {
1148
+ const fieldA = orderBy === "createdAt" ? a.createdAt : a.updatedAt;
1149
+ const fieldB = orderBy === "createdAt" ? b.createdAt : b.updatedAt;
1150
+ const comparison = fieldA.getTime() - fieldB.getTime();
1151
+ return sortDirection === "DESC" ? -comparison : comparison;
1152
+ });
1153
+ }
1126
1154
  async getThreadById({ threadId }) {
1127
1155
  this.logger.debug("Getting thread by ID", { threadId });
1128
1156
  try {
@@ -1151,21 +1179,20 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1151
1179
  );
1152
1180
  }
1153
1181
  }
1154
- async getThreadsByResourceId({ resourceId }) {
1155
- this.logger.debug("Getting threads by resource ID", { resourceId });
1182
+ /**
1183
+ * @deprecated use getThreadsByResourceIdPaginated instead for paginated results.
1184
+ */
1185
+ async getThreadsByResourceId(args) {
1186
+ const resourceId = args.resourceId;
1187
+ const orderBy = this.castThreadOrderBy(args.orderBy);
1188
+ const sortDirection = this.castThreadSortDirection(args.sortDirection);
1189
+ this.logger.debug("Getting threads by resource ID", { resourceId, orderBy, sortDirection });
1156
1190
  try {
1157
1191
  const result = await this.service.entities.thread.query.byResource({ entity: "thread", resourceId }).go();
1158
1192
  if (!result.data.length) {
1159
1193
  return [];
1160
1194
  }
1161
- return result.data.map((data) => ({
1162
- ...data,
1163
- // Convert date strings back to Date objects for consistency
1164
- createdAt: typeof data.createdAt === "string" ? new Date(data.createdAt) : data.createdAt,
1165
- updatedAt: typeof data.updatedAt === "string" ? new Date(data.updatedAt) : data.updatedAt
1166
- // metadata: data.metadata ? JSON.parse(data.metadata) : undefined, // REMOVED by AI
1167
- // metadata is already transformed by the entity's getter
1168
- }));
1195
+ return this.transformAndSortThreads(result.data, orderBy, sortDirection);
1169
1196
  } catch (error$1) {
1170
1197
  throw new error.MastraError(
1171
1198
  {
@@ -1187,7 +1214,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1187
1214
  resourceId: thread.resourceId,
1188
1215
  title: thread.title || `Thread ${thread.id}`,
1189
1216
  createdAt: thread.createdAt?.toISOString() || now.toISOString(),
1190
- updatedAt: now.toISOString(),
1217
+ updatedAt: thread.updatedAt?.toISOString() || now.toISOString(),
1191
1218
  metadata: thread.metadata ? JSON.stringify(thread.metadata) : void 0
1192
1219
  };
1193
1220
  try {
@@ -1294,6 +1321,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1294
1321
  }) {
1295
1322
  this.logger.debug("Getting messages", { threadId, selectBy });
1296
1323
  try {
1324
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
1297
1325
  const messages = [];
1298
1326
  const limit = storage.resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
1299
1327
  if (selectBy?.include?.length) {
@@ -1342,7 +1370,37 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1342
1370
  id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_FAILED",
1343
1371
  domain: error.ErrorDomain.STORAGE,
1344
1372
  category: error.ErrorCategory.THIRD_PARTY,
1345
- details: { threadId }
1373
+ details: { threadId, resourceId: resourceId ?? "" }
1374
+ },
1375
+ error$1
1376
+ );
1377
+ }
1378
+ }
1379
+ async getMessagesById({
1380
+ messageIds,
1381
+ format
1382
+ }) {
1383
+ this.logger.debug("Getting messages by ID", { messageIds });
1384
+ if (messageIds.length === 0) return [];
1385
+ try {
1386
+ const results = await Promise.all(
1387
+ messageIds.map((id) => this.service.entities.message.query.primary({ entity: "message", id }).go())
1388
+ );
1389
+ const data = results.map((result) => result.data).flat(1);
1390
+ let parsedMessages = data.map((data2) => this.parseMessageData(data2)).filter((msg) => "content" in msg);
1391
+ const uniqueMessages = parsedMessages.filter(
1392
+ (message, index, self) => index === self.findIndex((m) => m.id === message.id)
1393
+ );
1394
+ const list = new agent.MessageList().add(uniqueMessages, "memory");
1395
+ if (format === `v1`) return list.get.all.v1();
1396
+ return list.get.all.v2();
1397
+ } catch (error$1) {
1398
+ throw new error.MastraError(
1399
+ {
1400
+ id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_BY_ID_FAILED",
1401
+ domain: error.ErrorDomain.STORAGE,
1402
+ category: error.ErrorCategory.THIRD_PARTY,
1403
+ details: { messageIds: JSON.stringify(messageIds) }
1346
1404
  },
1347
1405
  error$1
1348
1406
  );
@@ -1422,11 +1480,19 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1422
1480
  }
1423
1481
  async getThreadsByResourceIdPaginated(args) {
1424
1482
  const { resourceId, page = 0, perPage = 100 } = args;
1425
- this.logger.debug("Getting threads by resource ID with pagination", { resourceId, page, perPage });
1483
+ const orderBy = this.castThreadOrderBy(args.orderBy);
1484
+ const sortDirection = this.castThreadSortDirection(args.sortDirection);
1485
+ this.logger.debug("Getting threads by resource ID with pagination", {
1486
+ resourceId,
1487
+ page,
1488
+ perPage,
1489
+ orderBy,
1490
+ sortDirection
1491
+ });
1426
1492
  try {
1427
1493
  const query = this.service.entities.thread.query.byResource({ entity: "thread", resourceId });
1428
1494
  const results = await query.go();
1429
- const allThreads = results.data;
1495
+ const allThreads = this.transformAndSortThreads(results.data, orderBy, sortDirection);
1430
1496
  const startIndex = page * perPage;
1431
1497
  const endIndex = startIndex + perPage;
1432
1498
  const paginatedThreads = allThreads.slice(startIndex, endIndex);
@@ -1459,6 +1525,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1459
1525
  const limit = storage.resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
1460
1526
  this.logger.debug("Getting messages with pagination", { threadId, page, perPage, fromDate, toDate, limit });
1461
1527
  try {
1528
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
1462
1529
  let messages = [];
1463
1530
  if (selectBy?.include?.length) {
1464
1531
  const includeMessages = await this._getIncludedMessages(threadId, selectBy);
@@ -1505,7 +1572,8 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1505
1572
  const paginatedMessages = messages.slice(start, end);
1506
1573
  const hasMore = end < total;
1507
1574
  const list = new agent.MessageList({ threadId, resourceId }).add(paginatedMessages, "memory");
1508
- const finalMessages = format === "v2" ? list.get.all.v2() : list.get.all.v1();
1575
+ let finalMessages = format === "v2" ? list.get.all.v2() : list.get.all.v1();
1576
+ finalMessages = finalMessages.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
1509
1577
  return {
1510
1578
  messages: finalMessages,
1511
1579
  total,
@@ -1514,19 +1582,23 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1514
1582
  hasMore
1515
1583
  };
1516
1584
  } catch (error$1) {
1517
- throw new error.MastraError(
1585
+ const mastraError = new error.MastraError(
1518
1586
  {
1519
1587
  id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_PAGINATED_FAILED",
1520
1588
  domain: error.ErrorDomain.STORAGE,
1521
1589
  category: error.ErrorCategory.THIRD_PARTY,
1522
- details: { threadId }
1590
+ details: { threadId, resourceId: resourceId ?? "" }
1523
1591
  },
1524
1592
  error$1
1525
1593
  );
1594
+ this.logger?.trackException?.(mastraError);
1595
+ this.logger?.error?.(mastraError.toString());
1596
+ return { messages: [], total: 0, page, perPage, hasMore: false };
1526
1597
  }
1527
1598
  }
1528
1599
  // Helper method to get included messages with context
1529
1600
  async _getIncludedMessages(threadId, selectBy) {
1601
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
1530
1602
  if (!selectBy?.include?.length) {
1531
1603
  return [];
1532
1604
  }
@@ -1793,7 +1865,8 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
1793
1865
  [storage.TABLE_EVALS]: "eval",
1794
1866
  [storage.TABLE_SCORERS]: "score",
1795
1867
  [storage.TABLE_TRACES]: "trace",
1796
- [storage.TABLE_RESOURCES]: "resource"
1868
+ [storage.TABLE_RESOURCES]: "resource",
1869
+ [storage.TABLE_AI_SPANS]: "ai_span"
1797
1870
  };
1798
1871
  return mapping[tableName] || null;
1799
1872
  }
@@ -2091,8 +2164,17 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2091
2164
  }
2092
2165
  // Helper function to parse score data (handle JSON fields)
2093
2166
  parseScoreData(data) {
2167
+ const result = {};
2168
+ for (const key of Object.keys(storage.SCORERS_SCHEMA)) {
2169
+ if (["traceId", "resourceId", "threadId", "spanId"].includes(key)) {
2170
+ result[key] = data[key] === "" ? null : data[key];
2171
+ continue;
2172
+ }
2173
+ result[key] = data[key];
2174
+ }
2175
+ result.entity = data.entityData ? data.entityData : null;
2094
2176
  return {
2095
- ...data,
2177
+ ...result,
2096
2178
  // Convert date strings back to Date objects for consistency
2097
2179
  createdAt: data.createdAt ? new Date(data.createdAt) : /* @__PURE__ */ new Date(),
2098
2180
  updatedAt: data.updatedAt ? new Date(data.updatedAt) : /* @__PURE__ */ new Date()
@@ -2120,34 +2202,47 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2120
2202
  }
2121
2203
  }
2122
2204
  async saveScore(score) {
2123
- this.logger.debug("Saving score", { scorerId: score.scorerId, runId: score.runId });
2205
+ let validatedScore;
2206
+ try {
2207
+ validatedScore = scores.saveScorePayloadSchema.parse(score);
2208
+ } catch (error$1) {
2209
+ throw new error.MastraError(
2210
+ {
2211
+ id: "STORAGE_DYNAMODB_STORE_SAVE_SCORE_FAILED",
2212
+ domain: error.ErrorDomain.STORAGE,
2213
+ category: error.ErrorCategory.THIRD_PARTY
2214
+ },
2215
+ error$1
2216
+ );
2217
+ }
2124
2218
  const now = /* @__PURE__ */ new Date();
2125
2219
  const scoreId = `score-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
2126
2220
  const scoreData = {
2127
2221
  entity: "score",
2128
2222
  id: scoreId,
2129
- scorerId: score.scorerId,
2130
- traceId: score.traceId || "",
2131
- runId: score.runId,
2132
- scorer: typeof score.scorer === "string" ? score.scorer : JSON.stringify(score.scorer),
2133
- preprocessStepResult: typeof score.preprocessStepResult === "string" ? score.preprocessStepResult : JSON.stringify(score.preprocessStepResult),
2134
- analyzeStepResult: typeof score.analyzeStepResult === "string" ? score.analyzeStepResult : JSON.stringify(score.analyzeStepResult),
2135
- score: score.score,
2136
- reason: score.reason,
2137
- preprocessPrompt: score.preprocessPrompt,
2138
- generateScorePrompt: score.generateScorePrompt,
2139
- analyzePrompt: score.analyzePrompt,
2140
- reasonPrompt: score.reasonPrompt,
2141
- input: typeof score.input === "string" ? score.input : JSON.stringify(score.input),
2142
- output: typeof score.output === "string" ? score.output : JSON.stringify(score.output),
2143
- additionalContext: typeof score.additionalContext === "string" ? score.additionalContext : JSON.stringify(score.additionalContext),
2144
- runtimeContext: typeof score.runtimeContext === "string" ? score.runtimeContext : JSON.stringify(score.runtimeContext),
2145
- entityType: score.entityType,
2146
- entityData: typeof score.entity === "string" ? score.entity : JSON.stringify(score.entity),
2147
- entityId: score.entityId,
2148
- source: score.source,
2149
- resourceId: score.resourceId || "",
2150
- threadId: score.threadId || "",
2223
+ scorerId: validatedScore.scorerId,
2224
+ traceId: validatedScore.traceId || "",
2225
+ spanId: validatedScore.spanId || "",
2226
+ runId: validatedScore.runId,
2227
+ scorer: typeof validatedScore.scorer === "string" ? validatedScore.scorer : JSON.stringify(validatedScore.scorer),
2228
+ preprocessStepResult: typeof validatedScore.preprocessStepResult === "string" ? validatedScore.preprocessStepResult : JSON.stringify(validatedScore.preprocessStepResult),
2229
+ analyzeStepResult: typeof validatedScore.analyzeStepResult === "string" ? validatedScore.analyzeStepResult : JSON.stringify(validatedScore.analyzeStepResult),
2230
+ score: validatedScore.score,
2231
+ reason: validatedScore.reason,
2232
+ preprocessPrompt: validatedScore.preprocessPrompt,
2233
+ generateScorePrompt: validatedScore.generateScorePrompt,
2234
+ generateReasonPrompt: validatedScore.generateReasonPrompt,
2235
+ analyzePrompt: validatedScore.analyzePrompt,
2236
+ input: typeof validatedScore.input === "string" ? validatedScore.input : JSON.stringify(validatedScore.input),
2237
+ output: typeof validatedScore.output === "string" ? validatedScore.output : JSON.stringify(validatedScore.output),
2238
+ additionalContext: typeof validatedScore.additionalContext === "string" ? validatedScore.additionalContext : JSON.stringify(validatedScore.additionalContext),
2239
+ runtimeContext: typeof validatedScore.runtimeContext === "string" ? validatedScore.runtimeContext : JSON.stringify(validatedScore.runtimeContext),
2240
+ entityType: validatedScore.entityType,
2241
+ entityData: typeof validatedScore.entity === "string" ? validatedScore.entity : JSON.stringify(validatedScore.entity),
2242
+ entityId: validatedScore.entityId,
2243
+ source: validatedScore.source,
2244
+ resourceId: validatedScore.resourceId || "",
2245
+ threadId: validatedScore.threadId || "",
2151
2246
  createdAt: now.toISOString(),
2152
2247
  updatedAt: now.toISOString()
2153
2248
  };
@@ -2176,9 +2271,9 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2176
2271
  scorerId,
2177
2272
  pagination,
2178
2273
  entityId,
2179
- entityType
2274
+ entityType,
2275
+ source
2180
2276
  }) {
2181
- this.logger.debug("Getting scores by scorer ID", { scorerId, pagination, entityId, entityType });
2182
2277
  try {
2183
2278
  const query = this.service.entities.score.query.byScorer({ entity: "score", scorerId });
2184
2279
  const results = await query.go();
@@ -2189,6 +2284,9 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2189
2284
  if (entityType) {
2190
2285
  allScores = allScores.filter((score) => score.entityType === entityType);
2191
2286
  }
2287
+ if (source) {
2288
+ allScores = allScores.filter((score) => score.source === source);
2289
+ }
2192
2290
  allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
2193
2291
  const startIndex = pagination.page * pagination.perPage;
2194
2292
  const endIndex = startIndex + pagination.perPage;
@@ -2214,6 +2312,7 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2214
2312
  scorerId: scorerId || "",
2215
2313
  entityId: entityId || "",
2216
2314
  entityType: entityType || "",
2315
+ source: source || "",
2217
2316
  page: pagination.page,
2218
2317
  perPage: pagination.perPage
2219
2318
  }
@@ -2296,6 +2395,43 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2296
2395
  );
2297
2396
  }
2298
2397
  }
2398
+ async getScoresBySpan({
2399
+ traceId,
2400
+ spanId,
2401
+ pagination
2402
+ }) {
2403
+ this.logger.debug("Getting scores by span", { traceId, spanId, pagination });
2404
+ try {
2405
+ const query = this.service.entities.score.query.bySpan({ entity: "score", traceId, spanId });
2406
+ const results = await query.go();
2407
+ const allScores = results.data.map((data) => this.parseScoreData(data));
2408
+ allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
2409
+ const startIndex = pagination.page * pagination.perPage;
2410
+ const endIndex = startIndex + pagination.perPage;
2411
+ const paginatedScores = allScores.slice(startIndex, endIndex);
2412
+ const total = allScores.length;
2413
+ const hasMore = endIndex < total;
2414
+ return {
2415
+ scores: paginatedScores,
2416
+ pagination: {
2417
+ total,
2418
+ page: pagination.page,
2419
+ perPage: pagination.perPage,
2420
+ hasMore
2421
+ }
2422
+ };
2423
+ } catch (error$1) {
2424
+ throw new error.MastraError(
2425
+ {
2426
+ id: "STORAGE_DYNAMODB_STORE_GET_SCORES_BY_SPAN_FAILED",
2427
+ domain: error.ErrorDomain.STORAGE,
2428
+ category: error.ErrorCategory.THIRD_PARTY,
2429
+ details: { traceId, spanId, page: pagination.page, perPage: pagination.perPage }
2430
+ },
2431
+ error$1
2432
+ );
2433
+ }
2434
+ }
2299
2435
  };
2300
2436
  var TracesStorageDynamoDB = class extends storage.TracesStorage {
2301
2437
  service;
@@ -2546,15 +2682,31 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
2546
2682
  super();
2547
2683
  this.service = service;
2548
2684
  }
2685
+ updateWorkflowResults({
2686
+ // workflowName,
2687
+ // runId,
2688
+ // stepId,
2689
+ // result,
2690
+ // runtimeContext,
2691
+ }) {
2692
+ throw new Error("Method not implemented.");
2693
+ }
2694
+ updateWorkflowState({
2695
+ // workflowName,
2696
+ // runId,
2697
+ // opts,
2698
+ }) {
2699
+ throw new Error("Method not implemented.");
2700
+ }
2549
2701
  // Workflow operations
2550
2702
  async persistWorkflowSnapshot({
2551
2703
  workflowName,
2552
2704
  runId,
2705
+ resourceId,
2553
2706
  snapshot
2554
2707
  }) {
2555
2708
  this.logger.debug("Persisting workflow snapshot", { workflowName, runId });
2556
2709
  try {
2557
- const resourceId = "resourceId" in snapshot ? snapshot.resourceId : void 0;
2558
2710
  const now = (/* @__PURE__ */ new Date()).toISOString();
2559
2711
  const data = {
2560
2712
  entity: "workflow_snapshot",
@@ -2562,7 +2714,6 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
2562
2714
  workflow_name: workflowName,
2563
2715
  run_id: runId,
2564
2716
  snapshot: JSON.stringify(snapshot),
2565
- // Stringify the snapshot object
2566
2717
  createdAt: now,
2567
2718
  updatedAt: now,
2568
2719
  resourceId
@@ -2634,6 +2785,11 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
2634
2785
  });
2635
2786
  if (pageResults.data && pageResults.data.length > 0) {
2636
2787
  let pageFilteredData = pageResults.data;
2788
+ if (args?.status) {
2789
+ pageFilteredData = pageFilteredData.filter((snapshot) => {
2790
+ return snapshot.snapshot.status === args.status;
2791
+ });
2792
+ }
2637
2793
  if (args?.fromDate || args?.toDate) {
2638
2794
  pageFilteredData = pageFilteredData.filter((snapshot) => {
2639
2795
  const createdAt = new Date(snapshot.createdAt);
@@ -2680,8 +2836,6 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
2680
2836
  async getWorkflowRunById(args) {
2681
2837
  const { runId, workflowName } = args;
2682
2838
  this.logger.debug("Getting workflow run by ID", { runId, workflowName });
2683
- console.log("workflowName", workflowName);
2684
- console.log("runId", runId);
2685
2839
  try {
2686
2840
  if (workflowName) {
2687
2841
  this.logger.debug("WorkflowName provided, using direct GET operation.");
@@ -2691,7 +2845,6 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
2691
2845
  workflow_name: workflowName,
2692
2846
  run_id: runId
2693
2847
  }).go();
2694
- console.log("result", result2);
2695
2848
  if (!result2.data) {
2696
2849
  return null;
2697
2850
  }
@@ -2796,7 +2949,8 @@ var DynamoDBStore = class extends storage.MastraStorage {
2796
2949
  resourceWorkingMemory: true,
2797
2950
  hasColumn: false,
2798
2951
  createTable: false,
2799
- deleteMessages: false
2952
+ deleteMessages: false,
2953
+ getScoresBySpan: true
2800
2954
  };
2801
2955
  }
2802
2956
  /**
@@ -2891,8 +3045,8 @@ var DynamoDBStore = class extends storage.MastraStorage {
2891
3045
  async getThreadById({ threadId }) {
2892
3046
  return this.stores.memory.getThreadById({ threadId });
2893
3047
  }
2894
- async getThreadsByResourceId({ resourceId }) {
2895
- return this.stores.memory.getThreadsByResourceId({ resourceId });
3048
+ async getThreadsByResourceId(args) {
3049
+ return this.stores.memory.getThreadsByResourceId(args);
2896
3050
  }
2897
3051
  async saveThread({ thread }) {
2898
3052
  return this.stores.memory.saveThread({ thread });
@@ -2915,6 +3069,12 @@ var DynamoDBStore = class extends storage.MastraStorage {
2915
3069
  }) {
2916
3070
  return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
2917
3071
  }
3072
+ async getMessagesById({
3073
+ messageIds,
3074
+ format
3075
+ }) {
3076
+ return this.stores.memory.getMessagesById({ messageIds, format });
3077
+ }
2918
3078
  async saveMessages(args) {
2919
3079
  return this.stores.memory.saveMessages(args);
2920
3080
  }
@@ -2938,12 +3098,29 @@ var DynamoDBStore = class extends storage.MastraStorage {
2938
3098
  return this.stores.traces.getTracesPaginated(_args);
2939
3099
  }
2940
3100
  // Workflow operations
3101
+ async updateWorkflowResults({
3102
+ workflowName,
3103
+ runId,
3104
+ stepId,
3105
+ result,
3106
+ runtimeContext
3107
+ }) {
3108
+ return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
3109
+ }
3110
+ async updateWorkflowState({
3111
+ workflowName,
3112
+ runId,
3113
+ opts
3114
+ }) {
3115
+ return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
3116
+ }
2941
3117
  async persistWorkflowSnapshot({
2942
3118
  workflowName,
2943
3119
  runId,
3120
+ resourceId,
2944
3121
  snapshot
2945
3122
  }) {
2946
- return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, snapshot });
3123
+ return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
2947
3124
  }
2948
3125
  async loadWorkflowSnapshot({
2949
3126
  workflowName,
@@ -3024,10 +3201,20 @@ var DynamoDBStore = class extends storage.MastraStorage {
3024
3201
  });
3025
3202
  }
3026
3203
  async getScoresByScorerId({
3027
- scorerId: _scorerId,
3028
- pagination: _pagination
3204
+ scorerId,
3205
+ source,
3206
+ entityId,
3207
+ entityType,
3208
+ pagination
3209
+ }) {
3210
+ return this.stores.scores.getScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
3211
+ }
3212
+ async getScoresBySpan({
3213
+ traceId,
3214
+ spanId,
3215
+ pagination
3029
3216
  }) {
3030
- return this.stores.scores.getScoresByScorerId({ scorerId: _scorerId, pagination: _pagination });
3217
+ return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
3031
3218
  }
3032
3219
  };
3033
3220