@mastra/dynamodb 0.0.0-update-scorers-api-20250801170445 → 0.0.0-vector-extension-schema-20250922130418

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 (37) hide show
  1. package/CHANGELOG.md +928 -0
  2. package/README.md +0 -4
  3. package/dist/index.cjs +130 -29
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.js +131 -30
  7. package/dist/index.js.map +1 -1
  8. package/dist/storage/domains/memory/index.d.ts +16 -4
  9. package/dist/storage/domains/memory/index.d.ts.map +1 -1
  10. package/dist/storage/domains/operations/index.d.ts.map +1 -1
  11. package/dist/storage/domains/score/index.d.ts +3 -2
  12. package/dist/storage/domains/score/index.d.ts.map +1 -1
  13. package/dist/storage/domains/traces/index.d.ts +1 -1
  14. package/dist/storage/domains/workflows/index.d.ts +21 -2
  15. package/dist/storage/domains/workflows/index.d.ts.map +1 -1
  16. package/dist/storage/index.d.ts +38 -8
  17. package/dist/storage/index.d.ts.map +1 -1
  18. package/package.json +22 -12
  19. package/src/entities/eval.ts +0 -102
  20. package/src/entities/index.ts +0 -27
  21. package/src/entities/message.ts +0 -143
  22. package/src/entities/resource.ts +0 -57
  23. package/src/entities/score.ts +0 -317
  24. package/src/entities/thread.ts +0 -66
  25. package/src/entities/trace.ts +0 -129
  26. package/src/entities/utils.ts +0 -51
  27. package/src/entities/workflow-snapshot.ts +0 -56
  28. package/src/index.ts +0 -1
  29. package/src/storage/docker-compose.yml +0 -16
  30. package/src/storage/domains/legacy-evals/index.ts +0 -243
  31. package/src/storage/domains/memory/index.ts +0 -894
  32. package/src/storage/domains/operations/index.ts +0 -433
  33. package/src/storage/domains/score/index.ts +0 -288
  34. package/src/storage/domains/traces/index.ts +0 -286
  35. package/src/storage/domains/workflows/index.ts +0 -297
  36. package/src/storage/index.test.ts +0 -1420
  37. 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
package/dist/index.cjs CHANGED
@@ -1123,6 +1123,20 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1123
1123
  // transformed by the ElectroDB entity getters.
1124
1124
  };
1125
1125
  }
1126
+ // Helper function to transform and sort threads
1127
+ transformAndSortThreads(rawThreads, orderBy, sortDirection) {
1128
+ return rawThreads.map((data) => ({
1129
+ ...data,
1130
+ // Convert date strings back to Date objects for consistency
1131
+ createdAt: typeof data.createdAt === "string" ? new Date(data.createdAt) : data.createdAt,
1132
+ updatedAt: typeof data.updatedAt === "string" ? new Date(data.updatedAt) : data.updatedAt
1133
+ })).sort((a, b) => {
1134
+ const fieldA = orderBy === "createdAt" ? a.createdAt : a.updatedAt;
1135
+ const fieldB = orderBy === "createdAt" ? b.createdAt : b.updatedAt;
1136
+ const comparison = fieldA.getTime() - fieldB.getTime();
1137
+ return sortDirection === "DESC" ? -comparison : comparison;
1138
+ });
1139
+ }
1126
1140
  async getThreadById({ threadId }) {
1127
1141
  this.logger.debug("Getting thread by ID", { threadId });
1128
1142
  try {
@@ -1151,21 +1165,20 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1151
1165
  );
1152
1166
  }
1153
1167
  }
1154
- async getThreadsByResourceId({ resourceId }) {
1155
- this.logger.debug("Getting threads by resource ID", { resourceId });
1168
+ /**
1169
+ * @deprecated use getThreadsByResourceIdPaginated instead for paginated results.
1170
+ */
1171
+ async getThreadsByResourceId(args) {
1172
+ const resourceId = args.resourceId;
1173
+ const orderBy = this.castThreadOrderBy(args.orderBy);
1174
+ const sortDirection = this.castThreadSortDirection(args.sortDirection);
1175
+ this.logger.debug("Getting threads by resource ID", { resourceId, orderBy, sortDirection });
1156
1176
  try {
1157
1177
  const result = await this.service.entities.thread.query.byResource({ entity: "thread", resourceId }).go();
1158
1178
  if (!result.data.length) {
1159
1179
  return [];
1160
1180
  }
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
- }));
1181
+ return this.transformAndSortThreads(result.data, orderBy, sortDirection);
1169
1182
  } catch (error$1) {
1170
1183
  throw new error.MastraError(
1171
1184
  {
@@ -1187,7 +1200,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1187
1200
  resourceId: thread.resourceId,
1188
1201
  title: thread.title || `Thread ${thread.id}`,
1189
1202
  createdAt: thread.createdAt?.toISOString() || now.toISOString(),
1190
- updatedAt: now.toISOString(),
1203
+ updatedAt: thread.updatedAt?.toISOString() || now.toISOString(),
1191
1204
  metadata: thread.metadata ? JSON.stringify(thread.metadata) : void 0
1192
1205
  };
1193
1206
  try {
@@ -1294,6 +1307,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1294
1307
  }) {
1295
1308
  this.logger.debug("Getting messages", { threadId, selectBy });
1296
1309
  try {
1310
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
1297
1311
  const messages = [];
1298
1312
  const limit = storage.resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
1299
1313
  if (selectBy?.include?.length) {
@@ -1342,7 +1356,37 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1342
1356
  id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_FAILED",
1343
1357
  domain: error.ErrorDomain.STORAGE,
1344
1358
  category: error.ErrorCategory.THIRD_PARTY,
1345
- details: { threadId }
1359
+ details: { threadId, resourceId: resourceId ?? "" }
1360
+ },
1361
+ error$1
1362
+ );
1363
+ }
1364
+ }
1365
+ async getMessagesById({
1366
+ messageIds,
1367
+ format
1368
+ }) {
1369
+ this.logger.debug("Getting messages by ID", { messageIds });
1370
+ if (messageIds.length === 0) return [];
1371
+ try {
1372
+ const results = await Promise.all(
1373
+ messageIds.map((id) => this.service.entities.message.query.primary({ entity: "message", id }).go())
1374
+ );
1375
+ const data = results.map((result) => result.data).flat(1);
1376
+ let parsedMessages = data.map((data2) => this.parseMessageData(data2)).filter((msg) => "content" in msg);
1377
+ const uniqueMessages = parsedMessages.filter(
1378
+ (message, index, self) => index === self.findIndex((m) => m.id === message.id)
1379
+ );
1380
+ const list = new agent.MessageList().add(uniqueMessages, "memory");
1381
+ if (format === `v1`) return list.get.all.v1();
1382
+ return list.get.all.v2();
1383
+ } catch (error$1) {
1384
+ throw new error.MastraError(
1385
+ {
1386
+ id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_BY_ID_FAILED",
1387
+ domain: error.ErrorDomain.STORAGE,
1388
+ category: error.ErrorCategory.THIRD_PARTY,
1389
+ details: { messageIds: JSON.stringify(messageIds) }
1346
1390
  },
1347
1391
  error$1
1348
1392
  );
@@ -1422,11 +1466,19 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1422
1466
  }
1423
1467
  async getThreadsByResourceIdPaginated(args) {
1424
1468
  const { resourceId, page = 0, perPage = 100 } = args;
1425
- this.logger.debug("Getting threads by resource ID with pagination", { resourceId, page, perPage });
1469
+ const orderBy = this.castThreadOrderBy(args.orderBy);
1470
+ const sortDirection = this.castThreadSortDirection(args.sortDirection);
1471
+ this.logger.debug("Getting threads by resource ID with pagination", {
1472
+ resourceId,
1473
+ page,
1474
+ perPage,
1475
+ orderBy,
1476
+ sortDirection
1477
+ });
1426
1478
  try {
1427
1479
  const query = this.service.entities.thread.query.byResource({ entity: "thread", resourceId });
1428
1480
  const results = await query.go();
1429
- const allThreads = results.data;
1481
+ const allThreads = this.transformAndSortThreads(results.data, orderBy, sortDirection);
1430
1482
  const startIndex = page * perPage;
1431
1483
  const endIndex = startIndex + perPage;
1432
1484
  const paginatedThreads = allThreads.slice(startIndex, endIndex);
@@ -1459,6 +1511,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1459
1511
  const limit = storage.resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
1460
1512
  this.logger.debug("Getting messages with pagination", { threadId, page, perPage, fromDate, toDate, limit });
1461
1513
  try {
1514
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
1462
1515
  let messages = [];
1463
1516
  if (selectBy?.include?.length) {
1464
1517
  const includeMessages = await this._getIncludedMessages(threadId, selectBy);
@@ -1514,19 +1567,23 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1514
1567
  hasMore
1515
1568
  };
1516
1569
  } catch (error$1) {
1517
- throw new error.MastraError(
1570
+ const mastraError = new error.MastraError(
1518
1571
  {
1519
1572
  id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_PAGINATED_FAILED",
1520
1573
  domain: error.ErrorDomain.STORAGE,
1521
1574
  category: error.ErrorCategory.THIRD_PARTY,
1522
- details: { threadId }
1575
+ details: { threadId, resourceId: resourceId ?? "" }
1523
1576
  },
1524
1577
  error$1
1525
1578
  );
1579
+ this.logger?.trackException?.(mastraError);
1580
+ this.logger?.error?.(mastraError.toString());
1581
+ return { messages: [], total: 0, page, perPage, hasMore: false };
1526
1582
  }
1527
1583
  }
1528
1584
  // Helper method to get included messages with context
1529
1585
  async _getIncludedMessages(threadId, selectBy) {
1586
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
1530
1587
  if (!selectBy?.include?.length) {
1531
1588
  return [];
1532
1589
  }
@@ -1793,7 +1850,8 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
1793
1850
  [storage.TABLE_EVALS]: "eval",
1794
1851
  [storage.TABLE_SCORERS]: "score",
1795
1852
  [storage.TABLE_TRACES]: "trace",
1796
- [storage.TABLE_RESOURCES]: "resource"
1853
+ [storage.TABLE_RESOURCES]: "resource",
1854
+ [storage.TABLE_AI_SPANS]: "ai_span"
1797
1855
  };
1798
1856
  return mapping[tableName] || null;
1799
1857
  }
@@ -2176,9 +2234,9 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2176
2234
  scorerId,
2177
2235
  pagination,
2178
2236
  entityId,
2179
- entityType
2237
+ entityType,
2238
+ source
2180
2239
  }) {
2181
- this.logger.debug("Getting scores by scorer ID", { scorerId, pagination, entityId, entityType });
2182
2240
  try {
2183
2241
  const query = this.service.entities.score.query.byScorer({ entity: "score", scorerId });
2184
2242
  const results = await query.go();
@@ -2189,6 +2247,9 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2189
2247
  if (entityType) {
2190
2248
  allScores = allScores.filter((score) => score.entityType === entityType);
2191
2249
  }
2250
+ if (source) {
2251
+ allScores = allScores.filter((score) => score.source === source);
2252
+ }
2192
2253
  allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
2193
2254
  const startIndex = pagination.page * pagination.perPage;
2194
2255
  const endIndex = startIndex + pagination.perPage;
@@ -2214,6 +2275,7 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2214
2275
  scorerId: scorerId || "",
2215
2276
  entityId: entityId || "",
2216
2277
  entityType: entityType || "",
2278
+ source: source || "",
2217
2279
  page: pagination.page,
2218
2280
  perPage: pagination.perPage
2219
2281
  }
@@ -2546,15 +2608,31 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
2546
2608
  super();
2547
2609
  this.service = service;
2548
2610
  }
2611
+ updateWorkflowResults({
2612
+ // workflowName,
2613
+ // runId,
2614
+ // stepId,
2615
+ // result,
2616
+ // runtimeContext,
2617
+ }) {
2618
+ throw new Error("Method not implemented.");
2619
+ }
2620
+ updateWorkflowState({
2621
+ // workflowName,
2622
+ // runId,
2623
+ // opts,
2624
+ }) {
2625
+ throw new Error("Method not implemented.");
2626
+ }
2549
2627
  // Workflow operations
2550
2628
  async persistWorkflowSnapshot({
2551
2629
  workflowName,
2552
2630
  runId,
2631
+ resourceId,
2553
2632
  snapshot
2554
2633
  }) {
2555
2634
  this.logger.debug("Persisting workflow snapshot", { workflowName, runId });
2556
2635
  try {
2557
- const resourceId = "resourceId" in snapshot ? snapshot.resourceId : void 0;
2558
2636
  const now = (/* @__PURE__ */ new Date()).toISOString();
2559
2637
  const data = {
2560
2638
  entity: "workflow_snapshot",
@@ -2680,8 +2758,6 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
2680
2758
  async getWorkflowRunById(args) {
2681
2759
  const { runId, workflowName } = args;
2682
2760
  this.logger.debug("Getting workflow run by ID", { runId, workflowName });
2683
- console.log("workflowName", workflowName);
2684
- console.log("runId", runId);
2685
2761
  try {
2686
2762
  if (workflowName) {
2687
2763
  this.logger.debug("WorkflowName provided, using direct GET operation.");
@@ -2691,7 +2767,6 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
2691
2767
  workflow_name: workflowName,
2692
2768
  run_id: runId
2693
2769
  }).go();
2694
- console.log("result", result2);
2695
2770
  if (!result2.data) {
2696
2771
  return null;
2697
2772
  }
@@ -2891,8 +2966,8 @@ var DynamoDBStore = class extends storage.MastraStorage {
2891
2966
  async getThreadById({ threadId }) {
2892
2967
  return this.stores.memory.getThreadById({ threadId });
2893
2968
  }
2894
- async getThreadsByResourceId({ resourceId }) {
2895
- return this.stores.memory.getThreadsByResourceId({ resourceId });
2969
+ async getThreadsByResourceId(args) {
2970
+ return this.stores.memory.getThreadsByResourceId(args);
2896
2971
  }
2897
2972
  async saveThread({ thread }) {
2898
2973
  return this.stores.memory.saveThread({ thread });
@@ -2915,6 +2990,12 @@ var DynamoDBStore = class extends storage.MastraStorage {
2915
2990
  }) {
2916
2991
  return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
2917
2992
  }
2993
+ async getMessagesById({
2994
+ messageIds,
2995
+ format
2996
+ }) {
2997
+ return this.stores.memory.getMessagesById({ messageIds, format });
2998
+ }
2918
2999
  async saveMessages(args) {
2919
3000
  return this.stores.memory.saveMessages(args);
2920
3001
  }
@@ -2938,12 +3019,29 @@ var DynamoDBStore = class extends storage.MastraStorage {
2938
3019
  return this.stores.traces.getTracesPaginated(_args);
2939
3020
  }
2940
3021
  // Workflow operations
3022
+ async updateWorkflowResults({
3023
+ workflowName,
3024
+ runId,
3025
+ stepId,
3026
+ result,
3027
+ runtimeContext
3028
+ }) {
3029
+ return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
3030
+ }
3031
+ async updateWorkflowState({
3032
+ workflowName,
3033
+ runId,
3034
+ opts
3035
+ }) {
3036
+ return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
3037
+ }
2941
3038
  async persistWorkflowSnapshot({
2942
3039
  workflowName,
2943
3040
  runId,
3041
+ resourceId,
2944
3042
  snapshot
2945
3043
  }) {
2946
- return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, snapshot });
3044
+ return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
2947
3045
  }
2948
3046
  async loadWorkflowSnapshot({
2949
3047
  workflowName,
@@ -3024,10 +3122,13 @@ var DynamoDBStore = class extends storage.MastraStorage {
3024
3122
  });
3025
3123
  }
3026
3124
  async getScoresByScorerId({
3027
- scorerId: _scorerId,
3028
- pagination: _pagination
3125
+ scorerId,
3126
+ source,
3127
+ entityId,
3128
+ entityType,
3129
+ pagination
3029
3130
  }) {
3030
- return this.stores.scores.getScoresByScorerId({ scorerId: _scorerId, pagination: _pagination });
3131
+ return this.stores.scores.getScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
3031
3132
  }
3032
3133
  };
3033
3134