@mastra/dynamodb 0.0.0-update-stores-peerDeps-20250723031338 → 0.0.0-usechat-duplicate-20251016110554

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 (63) hide show
  1. package/CHANGELOG.md +1048 -0
  2. package/README.md +0 -4
  3. package/dist/entities/eval.d.ts +102 -0
  4. package/dist/entities/eval.d.ts.map +1 -0
  5. package/dist/entities/index.d.ts +761 -0
  6. package/dist/entities/index.d.ts.map +1 -0
  7. package/dist/entities/message.d.ts +100 -0
  8. package/dist/entities/message.d.ts.map +1 -0
  9. package/dist/entities/resource.d.ts +54 -0
  10. package/dist/entities/resource.d.ts.map +1 -0
  11. package/dist/entities/score.d.ts +244 -0
  12. package/dist/entities/score.d.ts.map +1 -0
  13. package/dist/entities/thread.d.ts +69 -0
  14. package/dist/entities/thread.d.ts.map +1 -0
  15. package/dist/entities/trace.d.ts +127 -0
  16. package/dist/entities/trace.d.ts.map +1 -0
  17. package/dist/entities/utils.d.ts +21 -0
  18. package/dist/entities/utils.d.ts.map +1 -0
  19. package/dist/entities/workflow-snapshot.d.ts +74 -0
  20. package/dist/entities/workflow-snapshot.d.ts.map +1 -0
  21. package/dist/index.cjs +256 -52
  22. package/dist/index.cjs.map +1 -0
  23. package/dist/index.d.ts +2 -2
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +257 -53
  26. package/dist/index.js.map +1 -0
  27. package/dist/storage/domains/legacy-evals/index.d.ts +19 -0
  28. package/dist/storage/domains/legacy-evals/index.d.ts.map +1 -0
  29. package/dist/storage/domains/memory/index.d.ts +89 -0
  30. package/dist/storage/domains/memory/index.d.ts.map +1 -0
  31. package/dist/storage/domains/operations/index.d.ts +69 -0
  32. package/dist/storage/domains/operations/index.d.ts.map +1 -0
  33. package/dist/storage/domains/score/index.d.ts +51 -0
  34. package/dist/storage/domains/score/index.d.ts.map +1 -0
  35. package/dist/storage/domains/traces/index.d.ts +28 -0
  36. package/dist/storage/domains/traces/index.d.ts.map +1 -0
  37. package/dist/storage/domains/workflows/index.d.ts +51 -0
  38. package/dist/storage/domains/workflows/index.d.ts.map +1 -0
  39. package/dist/storage/index.d.ts +259 -0
  40. package/dist/storage/index.d.ts.map +1 -0
  41. package/package.json +24 -14
  42. package/dist/_tsup-dts-rollup.d.cts +0 -1976
  43. package/dist/_tsup-dts-rollup.d.ts +0 -1976
  44. package/dist/index.d.cts +0 -2
  45. package/src/entities/eval.ts +0 -102
  46. package/src/entities/index.ts +0 -27
  47. package/src/entities/message.ts +0 -143
  48. package/src/entities/resource.ts +0 -57
  49. package/src/entities/score.ts +0 -285
  50. package/src/entities/thread.ts +0 -66
  51. package/src/entities/trace.ts +0 -129
  52. package/src/entities/utils.ts +0 -51
  53. package/src/entities/workflow-snapshot.ts +0 -56
  54. package/src/index.ts +0 -1
  55. package/src/storage/docker-compose.yml +0 -16
  56. package/src/storage/domains/legacy-evals/index.ts +0 -243
  57. package/src/storage/domains/memory/index.ts +0 -894
  58. package/src/storage/domains/operations/index.ts +0 -433
  59. package/src/storage/domains/score/index.ts +0 -285
  60. package/src/storage/domains/traces/index.ts +0 -286
  61. package/src/storage/domains/workflows/index.ts +0 -297
  62. package/src/storage/index.test.ts +0 -1420
  63. package/src/storage/index.ts +0 -482
@@ -0,0 +1,74 @@
1
+ import { Entity } from 'electrodb';
2
+ export declare const workflowSnapshotEntity: Entity<string, string, string, {
3
+ model: {
4
+ entity: string;
5
+ version: string;
6
+ service: string;
7
+ };
8
+ attributes: {
9
+ workflow_name: {
10
+ type: "string";
11
+ required: true;
12
+ };
13
+ run_id: {
14
+ type: "string";
15
+ required: true;
16
+ };
17
+ snapshot: {
18
+ type: "string";
19
+ required: true;
20
+ set: (value?: any) => any;
21
+ get: (value?: string) => any;
22
+ };
23
+ resourceId: {
24
+ type: "string";
25
+ required: false;
26
+ };
27
+ createdAt: {
28
+ readonly type: "string";
29
+ readonly required: true;
30
+ readonly readOnly: true;
31
+ readonly set: (value?: Date | string) => string;
32
+ readonly default: () => string;
33
+ };
34
+ updatedAt: {
35
+ readonly type: "string";
36
+ readonly required: true;
37
+ readonly set: (value?: Date | string) => string;
38
+ readonly default: () => string;
39
+ };
40
+ metadata: {
41
+ readonly type: "string";
42
+ readonly set: (value?: Record<string, unknown> | string) => string | undefined;
43
+ readonly get: (value?: string) => any;
44
+ };
45
+ entity: {
46
+ type: "string";
47
+ required: true;
48
+ };
49
+ };
50
+ indexes: {
51
+ primary: {
52
+ pk: {
53
+ field: string;
54
+ composite: ("entity" | "workflow_name")[];
55
+ };
56
+ sk: {
57
+ field: string;
58
+ composite: "run_id"[];
59
+ };
60
+ };
61
+ gsi2: {
62
+ index: string;
63
+ pk: {
64
+ field: string;
65
+ composite: ("entity" | "run_id")[];
66
+ };
67
+ sk: {
68
+ field: string;
69
+ composite: "workflow_name"[];
70
+ };
71
+ };
72
+ };
73
+ }>;
74
+ //# sourceMappingURL=workflow-snapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-snapshot.d.ts","sourceRoot":"","sources":["../../src/entities/workflow-snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGnC,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;0BAwBf,GAAG;0BAOH,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqBxB,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,28 @@ var scoreEntity = new electrodb.Entity({
420
425
  return value;
421
426
  }
422
427
  },
428
+ preprocessStepResult: {
429
+ type: "string",
430
+ required: false,
431
+ set: (value) => {
432
+ if (value && typeof value !== "string") {
433
+ return JSON.stringify(value);
434
+ }
435
+ return value;
436
+ },
437
+ get: (value) => {
438
+ if (value && typeof value === "string") {
439
+ try {
440
+ if (value.startsWith("{") || value.startsWith("[")) {
441
+ return JSON.parse(value);
442
+ }
443
+ } catch {
444
+ return value;
445
+ }
446
+ }
447
+ return value;
448
+ }
449
+ },
423
450
  analyzeStepResult: {
424
451
  type: "string",
425
452
  required: false,
@@ -458,10 +485,19 @@ var scoreEntity = new electrodb.Entity({
458
485
  type: "string",
459
486
  required: false
460
487
  },
488
+ // Deprecated in favor of generateReasonPrompt
461
489
  reasonPrompt: {
462
490
  type: "string",
463
491
  required: false
464
492
  },
493
+ generateScorePrompt: {
494
+ type: "string",
495
+ required: false
496
+ },
497
+ generateReasonPrompt: {
498
+ type: "string",
499
+ required: false
500
+ },
465
501
  input: {
466
502
  type: "string",
467
503
  required: true,
@@ -627,6 +663,11 @@ var scoreEntity = new electrodb.Entity({
627
663
  index: "gsi6",
628
664
  pk: { field: "gsi6pk", composite: ["entity", "threadId"] },
629
665
  sk: { field: "gsi6sk", composite: ["createdAt"] }
666
+ },
667
+ bySpan: {
668
+ index: "gsi7",
669
+ pk: { field: "gsi7pk", composite: ["entity", "traceId", "spanId"] },
670
+ sk: { field: "gsi7sk", composite: ["createdAt"] }
630
671
  }
631
672
  }
632
673
  });
@@ -1092,6 +1133,20 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1092
1133
  // transformed by the ElectroDB entity getters.
1093
1134
  };
1094
1135
  }
1136
+ // Helper function to transform and sort threads
1137
+ transformAndSortThreads(rawThreads, orderBy, sortDirection) {
1138
+ return rawThreads.map((data) => ({
1139
+ ...data,
1140
+ // Convert date strings back to Date objects for consistency
1141
+ createdAt: typeof data.createdAt === "string" ? new Date(data.createdAt) : data.createdAt,
1142
+ updatedAt: typeof data.updatedAt === "string" ? new Date(data.updatedAt) : data.updatedAt
1143
+ })).sort((a, b) => {
1144
+ const fieldA = orderBy === "createdAt" ? a.createdAt : a.updatedAt;
1145
+ const fieldB = orderBy === "createdAt" ? b.createdAt : b.updatedAt;
1146
+ const comparison = fieldA.getTime() - fieldB.getTime();
1147
+ return sortDirection === "DESC" ? -comparison : comparison;
1148
+ });
1149
+ }
1095
1150
  async getThreadById({ threadId }) {
1096
1151
  this.logger.debug("Getting thread by ID", { threadId });
1097
1152
  try {
@@ -1120,21 +1175,20 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1120
1175
  );
1121
1176
  }
1122
1177
  }
1123
- async getThreadsByResourceId({ resourceId }) {
1124
- this.logger.debug("Getting threads by resource ID", { resourceId });
1178
+ /**
1179
+ * @deprecated use getThreadsByResourceIdPaginated instead for paginated results.
1180
+ */
1181
+ async getThreadsByResourceId(args) {
1182
+ const resourceId = args.resourceId;
1183
+ const orderBy = this.castThreadOrderBy(args.orderBy);
1184
+ const sortDirection = this.castThreadSortDirection(args.sortDirection);
1185
+ this.logger.debug("Getting threads by resource ID", { resourceId, orderBy, sortDirection });
1125
1186
  try {
1126
1187
  const result = await this.service.entities.thread.query.byResource({ entity: "thread", resourceId }).go();
1127
1188
  if (!result.data.length) {
1128
1189
  return [];
1129
1190
  }
1130
- return result.data.map((data) => ({
1131
- ...data,
1132
- // Convert date strings back to Date objects for consistency
1133
- createdAt: typeof data.createdAt === "string" ? new Date(data.createdAt) : data.createdAt,
1134
- updatedAt: typeof data.updatedAt === "string" ? new Date(data.updatedAt) : data.updatedAt
1135
- // metadata: data.metadata ? JSON.parse(data.metadata) : undefined, // REMOVED by AI
1136
- // metadata is already transformed by the entity's getter
1137
- }));
1191
+ return this.transformAndSortThreads(result.data, orderBy, sortDirection);
1138
1192
  } catch (error$1) {
1139
1193
  throw new error.MastraError(
1140
1194
  {
@@ -1156,7 +1210,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1156
1210
  resourceId: thread.resourceId,
1157
1211
  title: thread.title || `Thread ${thread.id}`,
1158
1212
  createdAt: thread.createdAt?.toISOString() || now.toISOString(),
1159
- updatedAt: now.toISOString(),
1213
+ updatedAt: thread.updatedAt?.toISOString() || now.toISOString(),
1160
1214
  metadata: thread.metadata ? JSON.stringify(thread.metadata) : void 0
1161
1215
  };
1162
1216
  try {
@@ -1263,6 +1317,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1263
1317
  }) {
1264
1318
  this.logger.debug("Getting messages", { threadId, selectBy });
1265
1319
  try {
1320
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
1266
1321
  const messages = [];
1267
1322
  const limit = storage.resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
1268
1323
  if (selectBy?.include?.length) {
@@ -1311,7 +1366,37 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1311
1366
  id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_FAILED",
1312
1367
  domain: error.ErrorDomain.STORAGE,
1313
1368
  category: error.ErrorCategory.THIRD_PARTY,
1314
- details: { threadId }
1369
+ details: { threadId, resourceId: resourceId ?? "" }
1370
+ },
1371
+ error$1
1372
+ );
1373
+ }
1374
+ }
1375
+ async getMessagesById({
1376
+ messageIds,
1377
+ format
1378
+ }) {
1379
+ this.logger.debug("Getting messages by ID", { messageIds });
1380
+ if (messageIds.length === 0) return [];
1381
+ try {
1382
+ const results = await Promise.all(
1383
+ messageIds.map((id) => this.service.entities.message.query.primary({ entity: "message", id }).go())
1384
+ );
1385
+ const data = results.map((result) => result.data).flat(1);
1386
+ let parsedMessages = data.map((data2) => this.parseMessageData(data2)).filter((msg) => "content" in msg);
1387
+ const uniqueMessages = parsedMessages.filter(
1388
+ (message, index, self) => index === self.findIndex((m) => m.id === message.id)
1389
+ );
1390
+ const list = new agent.MessageList().add(uniqueMessages, "memory");
1391
+ if (format === `v1`) return list.get.all.v1();
1392
+ return list.get.all.v2();
1393
+ } catch (error$1) {
1394
+ throw new error.MastraError(
1395
+ {
1396
+ id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_BY_ID_FAILED",
1397
+ domain: error.ErrorDomain.STORAGE,
1398
+ category: error.ErrorCategory.THIRD_PARTY,
1399
+ details: { messageIds: JSON.stringify(messageIds) }
1315
1400
  },
1316
1401
  error$1
1317
1402
  );
@@ -1391,11 +1476,19 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1391
1476
  }
1392
1477
  async getThreadsByResourceIdPaginated(args) {
1393
1478
  const { resourceId, page = 0, perPage = 100 } = args;
1394
- this.logger.debug("Getting threads by resource ID with pagination", { resourceId, page, perPage });
1479
+ const orderBy = this.castThreadOrderBy(args.orderBy);
1480
+ const sortDirection = this.castThreadSortDirection(args.sortDirection);
1481
+ this.logger.debug("Getting threads by resource ID with pagination", {
1482
+ resourceId,
1483
+ page,
1484
+ perPage,
1485
+ orderBy,
1486
+ sortDirection
1487
+ });
1395
1488
  try {
1396
1489
  const query = this.service.entities.thread.query.byResource({ entity: "thread", resourceId });
1397
1490
  const results = await query.go();
1398
- const allThreads = results.data;
1491
+ const allThreads = this.transformAndSortThreads(results.data, orderBy, sortDirection);
1399
1492
  const startIndex = page * perPage;
1400
1493
  const endIndex = startIndex + perPage;
1401
1494
  const paginatedThreads = allThreads.slice(startIndex, endIndex);
@@ -1428,6 +1521,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1428
1521
  const limit = storage.resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
1429
1522
  this.logger.debug("Getting messages with pagination", { threadId, page, perPage, fromDate, toDate, limit });
1430
1523
  try {
1524
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
1431
1525
  let messages = [];
1432
1526
  if (selectBy?.include?.length) {
1433
1527
  const includeMessages = await this._getIncludedMessages(threadId, selectBy);
@@ -1483,19 +1577,23 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1483
1577
  hasMore
1484
1578
  };
1485
1579
  } catch (error$1) {
1486
- throw new error.MastraError(
1580
+ const mastraError = new error.MastraError(
1487
1581
  {
1488
1582
  id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_PAGINATED_FAILED",
1489
1583
  domain: error.ErrorDomain.STORAGE,
1490
1584
  category: error.ErrorCategory.THIRD_PARTY,
1491
- details: { threadId }
1585
+ details: { threadId, resourceId: resourceId ?? "" }
1492
1586
  },
1493
1587
  error$1
1494
1588
  );
1589
+ this.logger?.trackException?.(mastraError);
1590
+ this.logger?.error?.(mastraError.toString());
1591
+ return { messages: [], total: 0, page, perPage, hasMore: false };
1495
1592
  }
1496
1593
  }
1497
1594
  // Helper method to get included messages with context
1498
1595
  async _getIncludedMessages(threadId, selectBy) {
1596
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
1499
1597
  if (!selectBy?.include?.length) {
1500
1598
  return [];
1501
1599
  }
@@ -1762,7 +1860,8 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
1762
1860
  [storage.TABLE_EVALS]: "eval",
1763
1861
  [storage.TABLE_SCORERS]: "score",
1764
1862
  [storage.TABLE_TRACES]: "trace",
1765
- [storage.TABLE_RESOURCES]: "resource"
1863
+ [storage.TABLE_RESOURCES]: "resource",
1864
+ [storage.TABLE_AI_SPANS]: "ai_span"
1766
1865
  };
1767
1866
  return mapping[tableName] || null;
1768
1867
  }
@@ -2089,33 +2188,47 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2089
2188
  }
2090
2189
  }
2091
2190
  async saveScore(score) {
2092
- this.logger.debug("Saving score", { scorerId: score.scorerId, runId: score.runId });
2191
+ let validatedScore;
2192
+ try {
2193
+ validatedScore = scores.saveScorePayloadSchema.parse(score);
2194
+ } catch (error$1) {
2195
+ throw new error.MastraError(
2196
+ {
2197
+ id: "STORAGE_DYNAMODB_STORE_SAVE_SCORE_FAILED",
2198
+ domain: error.ErrorDomain.STORAGE,
2199
+ category: error.ErrorCategory.THIRD_PARTY
2200
+ },
2201
+ error$1
2202
+ );
2203
+ }
2093
2204
  const now = /* @__PURE__ */ new Date();
2094
2205
  const scoreId = `score-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
2095
2206
  const scoreData = {
2096
2207
  entity: "score",
2097
2208
  id: scoreId,
2098
- scorerId: score.scorerId,
2099
- traceId: score.traceId || "",
2100
- runId: score.runId,
2101
- scorer: typeof score.scorer === "string" ? score.scorer : JSON.stringify(score.scorer),
2102
- extractStepResult: typeof score.extractStepResult === "string" ? score.extractStepResult : JSON.stringify(score.extractStepResult),
2103
- analyzeStepResult: typeof score.analyzeStepResult === "string" ? score.analyzeStepResult : JSON.stringify(score.analyzeStepResult),
2104
- score: score.score,
2105
- reason: score.reason,
2106
- extractPrompt: score.extractPrompt,
2107
- analyzePrompt: score.analyzePrompt,
2108
- reasonPrompt: score.reasonPrompt,
2109
- input: typeof score.input === "string" ? score.input : JSON.stringify(score.input),
2110
- output: typeof score.output === "string" ? score.output : JSON.stringify(score.output),
2111
- additionalContext: typeof score.additionalContext === "string" ? score.additionalContext : JSON.stringify(score.additionalContext),
2112
- runtimeContext: typeof score.runtimeContext === "string" ? score.runtimeContext : JSON.stringify(score.runtimeContext),
2113
- entityType: score.entityType,
2114
- entityData: typeof score.entity === "string" ? score.entity : JSON.stringify(score.entity),
2115
- entityId: score.entityId,
2116
- source: score.source,
2117
- resourceId: score.resourceId || "",
2118
- threadId: score.threadId || "",
2209
+ scorerId: validatedScore.scorerId,
2210
+ traceId: validatedScore.traceId || "",
2211
+ spanId: validatedScore.spanId || "",
2212
+ runId: validatedScore.runId,
2213
+ scorer: typeof validatedScore.scorer === "string" ? validatedScore.scorer : JSON.stringify(validatedScore.scorer),
2214
+ preprocessStepResult: typeof validatedScore.preprocessStepResult === "string" ? validatedScore.preprocessStepResult : JSON.stringify(validatedScore.preprocessStepResult),
2215
+ analyzeStepResult: typeof validatedScore.analyzeStepResult === "string" ? validatedScore.analyzeStepResult : JSON.stringify(validatedScore.analyzeStepResult),
2216
+ score: validatedScore.score,
2217
+ reason: validatedScore.reason,
2218
+ preprocessPrompt: validatedScore.preprocessPrompt,
2219
+ generateScorePrompt: validatedScore.generateScorePrompt,
2220
+ generateReasonPrompt: validatedScore.generateReasonPrompt,
2221
+ analyzePrompt: validatedScore.analyzePrompt,
2222
+ input: typeof validatedScore.input === "string" ? validatedScore.input : JSON.stringify(validatedScore.input),
2223
+ output: typeof validatedScore.output === "string" ? validatedScore.output : JSON.stringify(validatedScore.output),
2224
+ additionalContext: typeof validatedScore.additionalContext === "string" ? validatedScore.additionalContext : JSON.stringify(validatedScore.additionalContext),
2225
+ runtimeContext: typeof validatedScore.runtimeContext === "string" ? validatedScore.runtimeContext : JSON.stringify(validatedScore.runtimeContext),
2226
+ entityType: validatedScore.entityType,
2227
+ entityData: typeof validatedScore.entity === "string" ? validatedScore.entity : JSON.stringify(validatedScore.entity),
2228
+ entityId: validatedScore.entityId,
2229
+ source: validatedScore.source,
2230
+ resourceId: validatedScore.resourceId || "",
2231
+ threadId: validatedScore.threadId || "",
2119
2232
  createdAt: now.toISOString(),
2120
2233
  updatedAt: now.toISOString()
2121
2234
  };
@@ -2144,9 +2257,9 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2144
2257
  scorerId,
2145
2258
  pagination,
2146
2259
  entityId,
2147
- entityType
2260
+ entityType,
2261
+ source
2148
2262
  }) {
2149
- this.logger.debug("Getting scores by scorer ID", { scorerId, pagination, entityId, entityType });
2150
2263
  try {
2151
2264
  const query = this.service.entities.score.query.byScorer({ entity: "score", scorerId });
2152
2265
  const results = await query.go();
@@ -2157,6 +2270,9 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2157
2270
  if (entityType) {
2158
2271
  allScores = allScores.filter((score) => score.entityType === entityType);
2159
2272
  }
2273
+ if (source) {
2274
+ allScores = allScores.filter((score) => score.source === source);
2275
+ }
2160
2276
  allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
2161
2277
  const startIndex = pagination.page * pagination.perPage;
2162
2278
  const endIndex = startIndex + pagination.perPage;
@@ -2182,6 +2298,7 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2182
2298
  scorerId: scorerId || "",
2183
2299
  entityId: entityId || "",
2184
2300
  entityType: entityType || "",
2301
+ source: source || "",
2185
2302
  page: pagination.page,
2186
2303
  perPage: pagination.perPage
2187
2304
  }
@@ -2264,6 +2381,43 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2264
2381
  );
2265
2382
  }
2266
2383
  }
2384
+ async getScoresBySpan({
2385
+ traceId,
2386
+ spanId,
2387
+ pagination
2388
+ }) {
2389
+ this.logger.debug("Getting scores by span", { traceId, spanId, pagination });
2390
+ try {
2391
+ const query = this.service.entities.score.query.bySpan({ entity: "score", traceId, spanId });
2392
+ const results = await query.go();
2393
+ const allScores = results.data.map((data) => this.parseScoreData(data));
2394
+ allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
2395
+ const startIndex = pagination.page * pagination.perPage;
2396
+ const endIndex = startIndex + pagination.perPage;
2397
+ const paginatedScores = allScores.slice(startIndex, endIndex);
2398
+ const total = allScores.length;
2399
+ const hasMore = endIndex < total;
2400
+ return {
2401
+ scores: paginatedScores,
2402
+ pagination: {
2403
+ total,
2404
+ page: pagination.page,
2405
+ perPage: pagination.perPage,
2406
+ hasMore
2407
+ }
2408
+ };
2409
+ } catch (error$1) {
2410
+ throw new error.MastraError(
2411
+ {
2412
+ id: "STORAGE_DYNAMODB_STORE_GET_SCORES_BY_SPAN_FAILED",
2413
+ domain: error.ErrorDomain.STORAGE,
2414
+ category: error.ErrorCategory.THIRD_PARTY,
2415
+ details: { traceId, spanId, page: pagination.page, perPage: pagination.perPage }
2416
+ },
2417
+ error$1
2418
+ );
2419
+ }
2420
+ }
2267
2421
  };
2268
2422
  var TracesStorageDynamoDB = class extends storage.TracesStorage {
2269
2423
  service;
@@ -2514,15 +2668,31 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
2514
2668
  super();
2515
2669
  this.service = service;
2516
2670
  }
2671
+ updateWorkflowResults({
2672
+ // workflowName,
2673
+ // runId,
2674
+ // stepId,
2675
+ // result,
2676
+ // runtimeContext,
2677
+ }) {
2678
+ throw new Error("Method not implemented.");
2679
+ }
2680
+ updateWorkflowState({
2681
+ // workflowName,
2682
+ // runId,
2683
+ // opts,
2684
+ }) {
2685
+ throw new Error("Method not implemented.");
2686
+ }
2517
2687
  // Workflow operations
2518
2688
  async persistWorkflowSnapshot({
2519
2689
  workflowName,
2520
2690
  runId,
2691
+ resourceId,
2521
2692
  snapshot
2522
2693
  }) {
2523
2694
  this.logger.debug("Persisting workflow snapshot", { workflowName, runId });
2524
2695
  try {
2525
- const resourceId = "resourceId" in snapshot ? snapshot.resourceId : void 0;
2526
2696
  const now = (/* @__PURE__ */ new Date()).toISOString();
2527
2697
  const data = {
2528
2698
  entity: "workflow_snapshot",
@@ -2648,8 +2818,6 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
2648
2818
  async getWorkflowRunById(args) {
2649
2819
  const { runId, workflowName } = args;
2650
2820
  this.logger.debug("Getting workflow run by ID", { runId, workflowName });
2651
- console.log("workflowName", workflowName);
2652
- console.log("runId", runId);
2653
2821
  try {
2654
2822
  if (workflowName) {
2655
2823
  this.logger.debug("WorkflowName provided, using direct GET operation.");
@@ -2659,7 +2827,6 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
2659
2827
  workflow_name: workflowName,
2660
2828
  run_id: runId
2661
2829
  }).go();
2662
- console.log("result", result2);
2663
2830
  if (!result2.data) {
2664
2831
  return null;
2665
2832
  }
@@ -2763,7 +2930,9 @@ var DynamoDBStore = class extends storage.MastraStorage {
2763
2930
  selectByIncludeResourceScope: true,
2764
2931
  resourceWorkingMemory: true,
2765
2932
  hasColumn: false,
2766
- createTable: false
2933
+ createTable: false,
2934
+ deleteMessages: false,
2935
+ getScoresBySpan: true
2767
2936
  };
2768
2937
  }
2769
2938
  /**
@@ -2858,8 +3027,8 @@ var DynamoDBStore = class extends storage.MastraStorage {
2858
3027
  async getThreadById({ threadId }) {
2859
3028
  return this.stores.memory.getThreadById({ threadId });
2860
3029
  }
2861
- async getThreadsByResourceId({ resourceId }) {
2862
- return this.stores.memory.getThreadsByResourceId({ resourceId });
3030
+ async getThreadsByResourceId(args) {
3031
+ return this.stores.memory.getThreadsByResourceId(args);
2863
3032
  }
2864
3033
  async saveThread({ thread }) {
2865
3034
  return this.stores.memory.saveThread({ thread });
@@ -2882,6 +3051,12 @@ var DynamoDBStore = class extends storage.MastraStorage {
2882
3051
  }) {
2883
3052
  return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
2884
3053
  }
3054
+ async getMessagesById({
3055
+ messageIds,
3056
+ format
3057
+ }) {
3058
+ return this.stores.memory.getMessagesById({ messageIds, format });
3059
+ }
2885
3060
  async saveMessages(args) {
2886
3061
  return this.stores.memory.saveMessages(args);
2887
3062
  }
@@ -2905,12 +3080,29 @@ var DynamoDBStore = class extends storage.MastraStorage {
2905
3080
  return this.stores.traces.getTracesPaginated(_args);
2906
3081
  }
2907
3082
  // Workflow operations
3083
+ async updateWorkflowResults({
3084
+ workflowName,
3085
+ runId,
3086
+ stepId,
3087
+ result,
3088
+ runtimeContext
3089
+ }) {
3090
+ return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
3091
+ }
3092
+ async updateWorkflowState({
3093
+ workflowName,
3094
+ runId,
3095
+ opts
3096
+ }) {
3097
+ return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
3098
+ }
2908
3099
  async persistWorkflowSnapshot({
2909
3100
  workflowName,
2910
3101
  runId,
3102
+ resourceId,
2911
3103
  snapshot
2912
3104
  }) {
2913
- return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, snapshot });
3105
+ return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
2914
3106
  }
2915
3107
  async loadWorkflowSnapshot({
2916
3108
  workflowName,
@@ -2991,11 +3183,23 @@ var DynamoDBStore = class extends storage.MastraStorage {
2991
3183
  });
2992
3184
  }
2993
3185
  async getScoresByScorerId({
2994
- scorerId: _scorerId,
2995
- pagination: _pagination
3186
+ scorerId,
3187
+ source,
3188
+ entityId,
3189
+ entityType,
3190
+ pagination
3191
+ }) {
3192
+ return this.stores.scores.getScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
3193
+ }
3194
+ async getScoresBySpan({
3195
+ traceId,
3196
+ spanId,
3197
+ pagination
2996
3198
  }) {
2997
- return this.stores.scores.getScoresByScorerId({ scorerId: _scorerId, pagination: _pagination });
3199
+ return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
2998
3200
  }
2999
3201
  };
3000
3202
 
3001
3203
  exports.DynamoDBStore = DynamoDBStore;
3204
+ //# sourceMappingURL=index.cjs.map
3205
+ //# sourceMappingURL=index.cjs.map