@mastra/dynamodb 0.0.0-update-stores-peerDeps-20250723031338 → 0.0.0-vector-query-tool-provider-options-20250828222356

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 (48) hide show
  1. package/dist/entities/eval.d.ts +102 -0
  2. package/dist/entities/eval.d.ts.map +1 -0
  3. package/dist/entities/index.d.ts +746 -0
  4. package/dist/entities/index.d.ts.map +1 -0
  5. package/dist/entities/message.d.ts +100 -0
  6. package/dist/entities/message.d.ts.map +1 -0
  7. package/dist/entities/resource.d.ts +54 -0
  8. package/dist/entities/resource.d.ts.map +1 -0
  9. package/dist/entities/score.d.ts +229 -0
  10. package/dist/entities/score.d.ts.map +1 -0
  11. package/dist/entities/thread.d.ts +69 -0
  12. package/dist/entities/thread.d.ts.map +1 -0
  13. package/dist/entities/trace.d.ts +127 -0
  14. package/dist/entities/trace.d.ts.map +1 -0
  15. package/dist/entities/utils.d.ts +21 -0
  16. package/dist/entities/utils.d.ts.map +1 -0
  17. package/dist/entities/workflow-snapshot.d.ts +74 -0
  18. package/dist/entities/workflow-snapshot.d.ts.map +1 -0
  19. package/dist/index.cjs +156 -24
  20. package/dist/index.cjs.map +1 -0
  21. package/dist/index.d.ts +2 -2
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +157 -25
  24. package/dist/index.js.map +1 -0
  25. package/dist/storage/domains/legacy-evals/index.d.ts +19 -0
  26. package/dist/storage/domains/legacy-evals/index.d.ts.map +1 -0
  27. package/dist/storage/domains/memory/index.d.ts +89 -0
  28. package/dist/storage/domains/memory/index.d.ts.map +1 -0
  29. package/dist/storage/domains/operations/index.d.ts +69 -0
  30. package/dist/storage/domains/operations/index.d.ts.map +1 -0
  31. package/dist/storage/domains/score/index.d.ts +43 -0
  32. package/dist/storage/domains/score/index.d.ts.map +1 -0
  33. package/dist/storage/domains/traces/index.d.ts +28 -0
  34. package/dist/storage/domains/traces/index.d.ts.map +1 -0
  35. package/dist/storage/domains/workflows/index.d.ts +50 -0
  36. package/dist/storage/domains/workflows/index.d.ts.map +1 -0
  37. package/dist/storage/index.d.ts +249 -0
  38. package/dist/storage/index.d.ts.map +1 -0
  39. package/package.json +12 -11
  40. package/src/entities/score.ts +32 -0
  41. package/src/storage/domains/memory/index.ts +113 -20
  42. package/src/storage/domains/operations/index.ts +2 -0
  43. package/src/storage/domains/score/index.ts +13 -6
  44. package/src/storage/domains/workflows/index.ts +38 -1
  45. package/src/storage/index.ts +68 -12
  46. package/dist/_tsup-dts-rollup.d.cts +0 -1976
  47. package/dist/_tsup-dts-rollup.d.ts +0 -1976
  48. package/dist/index.d.cts +0 -2
@@ -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
@@ -420,6 +420,28 @@ var scoreEntity = new electrodb.Entity({
420
420
  return value;
421
421
  }
422
422
  },
423
+ preprocessStepResult: {
424
+ type: "string",
425
+ required: false,
426
+ set: (value) => {
427
+ if (value && typeof value !== "string") {
428
+ return JSON.stringify(value);
429
+ }
430
+ return value;
431
+ },
432
+ get: (value) => {
433
+ if (value && typeof value === "string") {
434
+ try {
435
+ if (value.startsWith("{") || value.startsWith("[")) {
436
+ return JSON.parse(value);
437
+ }
438
+ } catch {
439
+ return value;
440
+ }
441
+ }
442
+ return value;
443
+ }
444
+ },
423
445
  analyzeStepResult: {
424
446
  type: "string",
425
447
  required: false,
@@ -458,10 +480,19 @@ var scoreEntity = new electrodb.Entity({
458
480
  type: "string",
459
481
  required: false
460
482
  },
483
+ // Deprecated in favor of generateReasonPrompt
461
484
  reasonPrompt: {
462
485
  type: "string",
463
486
  required: false
464
487
  },
488
+ generateScorePrompt: {
489
+ type: "string",
490
+ required: false
491
+ },
492
+ generateReasonPrompt: {
493
+ type: "string",
494
+ required: false
495
+ },
465
496
  input: {
466
497
  type: "string",
467
498
  required: true,
@@ -1092,6 +1123,20 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1092
1123
  // transformed by the ElectroDB entity getters.
1093
1124
  };
1094
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
+ }
1095
1140
  async getThreadById({ threadId }) {
1096
1141
  this.logger.debug("Getting thread by ID", { threadId });
1097
1142
  try {
@@ -1120,21 +1165,20 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1120
1165
  );
1121
1166
  }
1122
1167
  }
1123
- async getThreadsByResourceId({ resourceId }) {
1124
- 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 });
1125
1176
  try {
1126
1177
  const result = await this.service.entities.thread.query.byResource({ entity: "thread", resourceId }).go();
1127
1178
  if (!result.data.length) {
1128
1179
  return [];
1129
1180
  }
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
- }));
1181
+ return this.transformAndSortThreads(result.data, orderBy, sortDirection);
1138
1182
  } catch (error$1) {
1139
1183
  throw new error.MastraError(
1140
1184
  {
@@ -1156,7 +1200,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1156
1200
  resourceId: thread.resourceId,
1157
1201
  title: thread.title || `Thread ${thread.id}`,
1158
1202
  createdAt: thread.createdAt?.toISOString() || now.toISOString(),
1159
- updatedAt: now.toISOString(),
1203
+ updatedAt: thread.updatedAt?.toISOString() || now.toISOString(),
1160
1204
  metadata: thread.metadata ? JSON.stringify(thread.metadata) : void 0
1161
1205
  };
1162
1206
  try {
@@ -1317,6 +1361,36 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1317
1361
  );
1318
1362
  }
1319
1363
  }
1364
+ async getMessagesById({
1365
+ messageIds,
1366
+ format
1367
+ }) {
1368
+ this.logger.debug("Getting messages by ID", { messageIds });
1369
+ if (messageIds.length === 0) return [];
1370
+ try {
1371
+ const results = await Promise.all(
1372
+ messageIds.map((id) => this.service.entities.message.query.primary({ entity: "message", id }).go())
1373
+ );
1374
+ const data = results.map((result) => result.data).flat(1);
1375
+ let parsedMessages = data.map((data2) => this.parseMessageData(data2)).filter((msg) => "content" in msg);
1376
+ const uniqueMessages = parsedMessages.filter(
1377
+ (message, index, self) => index === self.findIndex((m) => m.id === message.id)
1378
+ );
1379
+ const list = new agent.MessageList().add(uniqueMessages, "memory");
1380
+ if (format === `v1`) return list.get.all.v1();
1381
+ return list.get.all.v2();
1382
+ } catch (error$1) {
1383
+ throw new error.MastraError(
1384
+ {
1385
+ id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_BY_ID_FAILED",
1386
+ domain: error.ErrorDomain.STORAGE,
1387
+ category: error.ErrorCategory.THIRD_PARTY,
1388
+ details: { messageIds: JSON.stringify(messageIds) }
1389
+ },
1390
+ error$1
1391
+ );
1392
+ }
1393
+ }
1320
1394
  async saveMessages(args) {
1321
1395
  const { messages, format = "v1" } = args;
1322
1396
  this.logger.debug("Saving messages", { count: messages.length });
@@ -1391,11 +1465,19 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1391
1465
  }
1392
1466
  async getThreadsByResourceIdPaginated(args) {
1393
1467
  const { resourceId, page = 0, perPage = 100 } = args;
1394
- this.logger.debug("Getting threads by resource ID with pagination", { resourceId, page, perPage });
1468
+ const orderBy = this.castThreadOrderBy(args.orderBy);
1469
+ const sortDirection = this.castThreadSortDirection(args.sortDirection);
1470
+ this.logger.debug("Getting threads by resource ID with pagination", {
1471
+ resourceId,
1472
+ page,
1473
+ perPage,
1474
+ orderBy,
1475
+ sortDirection
1476
+ });
1395
1477
  try {
1396
1478
  const query = this.service.entities.thread.query.byResource({ entity: "thread", resourceId });
1397
1479
  const results = await query.go();
1398
- const allThreads = results.data;
1480
+ const allThreads = this.transformAndSortThreads(results.data, orderBy, sortDirection);
1399
1481
  const startIndex = page * perPage;
1400
1482
  const endIndex = startIndex + perPage;
1401
1483
  const paginatedThreads = allThreads.slice(startIndex, endIndex);
@@ -1762,7 +1844,8 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
1762
1844
  [storage.TABLE_EVALS]: "eval",
1763
1845
  [storage.TABLE_SCORERS]: "score",
1764
1846
  [storage.TABLE_TRACES]: "trace",
1765
- [storage.TABLE_RESOURCES]: "resource"
1847
+ [storage.TABLE_RESOURCES]: "resource",
1848
+ [storage.TABLE_AI_SPANS]: "ai_span"
1766
1849
  };
1767
1850
  return mapping[tableName] || null;
1768
1851
  }
@@ -2099,11 +2182,12 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2099
2182
  traceId: score.traceId || "",
2100
2183
  runId: score.runId,
2101
2184
  scorer: typeof score.scorer === "string" ? score.scorer : JSON.stringify(score.scorer),
2102
- extractStepResult: typeof score.extractStepResult === "string" ? score.extractStepResult : JSON.stringify(score.extractStepResult),
2185
+ preprocessStepResult: typeof score.preprocessStepResult === "string" ? score.preprocessStepResult : JSON.stringify(score.preprocessStepResult),
2103
2186
  analyzeStepResult: typeof score.analyzeStepResult === "string" ? score.analyzeStepResult : JSON.stringify(score.analyzeStepResult),
2104
2187
  score: score.score,
2105
2188
  reason: score.reason,
2106
- extractPrompt: score.extractPrompt,
2189
+ preprocessPrompt: score.preprocessPrompt,
2190
+ generateScorePrompt: score.generateScorePrompt,
2107
2191
  analyzePrompt: score.analyzePrompt,
2108
2192
  reasonPrompt: score.reasonPrompt,
2109
2193
  input: typeof score.input === "string" ? score.input : JSON.stringify(score.input),
@@ -2144,9 +2228,9 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2144
2228
  scorerId,
2145
2229
  pagination,
2146
2230
  entityId,
2147
- entityType
2231
+ entityType,
2232
+ source
2148
2233
  }) {
2149
- this.logger.debug("Getting scores by scorer ID", { scorerId, pagination, entityId, entityType });
2150
2234
  try {
2151
2235
  const query = this.service.entities.score.query.byScorer({ entity: "score", scorerId });
2152
2236
  const results = await query.go();
@@ -2157,6 +2241,9 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2157
2241
  if (entityType) {
2158
2242
  allScores = allScores.filter((score) => score.entityType === entityType);
2159
2243
  }
2244
+ if (source) {
2245
+ allScores = allScores.filter((score) => score.source === source);
2246
+ }
2160
2247
  allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
2161
2248
  const startIndex = pagination.page * pagination.perPage;
2162
2249
  const endIndex = startIndex + pagination.perPage;
@@ -2182,6 +2269,7 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2182
2269
  scorerId: scorerId || "",
2183
2270
  entityId: entityId || "",
2184
2271
  entityType: entityType || "",
2272
+ source: source || "",
2185
2273
  page: pagination.page,
2186
2274
  perPage: pagination.perPage
2187
2275
  }
@@ -2514,6 +2602,22 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
2514
2602
  super();
2515
2603
  this.service = service;
2516
2604
  }
2605
+ updateWorkflowResults({
2606
+ // workflowName,
2607
+ // runId,
2608
+ // stepId,
2609
+ // result,
2610
+ // runtimeContext,
2611
+ }) {
2612
+ throw new Error("Method not implemented.");
2613
+ }
2614
+ updateWorkflowState({
2615
+ // workflowName,
2616
+ // runId,
2617
+ // opts,
2618
+ }) {
2619
+ throw new Error("Method not implemented.");
2620
+ }
2517
2621
  // Workflow operations
2518
2622
  async persistWorkflowSnapshot({
2519
2623
  workflowName,
@@ -2763,7 +2867,8 @@ var DynamoDBStore = class extends storage.MastraStorage {
2763
2867
  selectByIncludeResourceScope: true,
2764
2868
  resourceWorkingMemory: true,
2765
2869
  hasColumn: false,
2766
- createTable: false
2870
+ createTable: false,
2871
+ deleteMessages: false
2767
2872
  };
2768
2873
  }
2769
2874
  /**
@@ -2858,8 +2963,8 @@ var DynamoDBStore = class extends storage.MastraStorage {
2858
2963
  async getThreadById({ threadId }) {
2859
2964
  return this.stores.memory.getThreadById({ threadId });
2860
2965
  }
2861
- async getThreadsByResourceId({ resourceId }) {
2862
- return this.stores.memory.getThreadsByResourceId({ resourceId });
2966
+ async getThreadsByResourceId(args) {
2967
+ return this.stores.memory.getThreadsByResourceId(args);
2863
2968
  }
2864
2969
  async saveThread({ thread }) {
2865
2970
  return this.stores.memory.saveThread({ thread });
@@ -2882,6 +2987,12 @@ var DynamoDBStore = class extends storage.MastraStorage {
2882
2987
  }) {
2883
2988
  return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
2884
2989
  }
2990
+ async getMessagesById({
2991
+ messageIds,
2992
+ format
2993
+ }) {
2994
+ return this.stores.memory.getMessagesById({ messageIds, format });
2995
+ }
2885
2996
  async saveMessages(args) {
2886
2997
  return this.stores.memory.saveMessages(args);
2887
2998
  }
@@ -2905,6 +3016,22 @@ var DynamoDBStore = class extends storage.MastraStorage {
2905
3016
  return this.stores.traces.getTracesPaginated(_args);
2906
3017
  }
2907
3018
  // Workflow operations
3019
+ async updateWorkflowResults({
3020
+ workflowName,
3021
+ runId,
3022
+ stepId,
3023
+ result,
3024
+ runtimeContext
3025
+ }) {
3026
+ return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
3027
+ }
3028
+ async updateWorkflowState({
3029
+ workflowName,
3030
+ runId,
3031
+ opts
3032
+ }) {
3033
+ return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
3034
+ }
2908
3035
  async persistWorkflowSnapshot({
2909
3036
  workflowName,
2910
3037
  runId,
@@ -2991,11 +3118,16 @@ var DynamoDBStore = class extends storage.MastraStorage {
2991
3118
  });
2992
3119
  }
2993
3120
  async getScoresByScorerId({
2994
- scorerId: _scorerId,
2995
- pagination: _pagination
3121
+ scorerId,
3122
+ source,
3123
+ entityId,
3124
+ entityType,
3125
+ pagination
2996
3126
  }) {
2997
- return this.stores.scores.getScoresByScorerId({ scorerId: _scorerId, pagination: _pagination });
3127
+ return this.stores.scores.getScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
2998
3128
  }
2999
3129
  };
3000
3130
 
3001
3131
  exports.DynamoDBStore = DynamoDBStore;
3132
+ //# sourceMappingURL=index.cjs.map
3133
+ //# sourceMappingURL=index.cjs.map