@mastra/dynamodb 0.0.0-zod-v4-compat-part-2-20250822105954 → 0.0.0-zod-v4-stuff-20250825154219

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.
@@ -550,6 +550,12 @@ export declare function getElectroDbService(client: DynamoDBDocumentClient, tabl
550
550
  set: (value?: Record<string, unknown> | string) => string | undefined;
551
551
  get: (value?: string) => any;
552
552
  };
553
+ preprocessStepResult: {
554
+ type: "string";
555
+ required: false;
556
+ set: (value?: Record<string, unknown> | string) => string | undefined;
557
+ get: (value?: string) => any;
558
+ };
553
559
  analyzeStepResult: {
554
560
  type: "string";
555
561
  required: false;
@@ -576,6 +582,14 @@ export declare function getElectroDbService(client: DynamoDBDocumentClient, tabl
576
582
  type: "string";
577
583
  required: false;
578
584
  };
585
+ generateScorePrompt: {
586
+ type: "string";
587
+ required: false;
588
+ };
589
+ generateReasonPrompt: {
590
+ type: "string";
591
+ required: false;
592
+ };
579
593
  input: {
580
594
  type: "string";
581
595
  required: true;
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgBpF"}
@@ -34,6 +34,12 @@ export declare const scoreEntity: Entity<string, string, string, {
34
34
  set: (value?: Record<string, unknown> | string) => string | undefined;
35
35
  get: (value?: string) => any;
36
36
  };
37
+ preprocessStepResult: {
38
+ type: "string";
39
+ required: false;
40
+ set: (value?: Record<string, unknown> | string) => string | undefined;
41
+ get: (value?: string) => any;
42
+ };
37
43
  analyzeStepResult: {
38
44
  type: "string";
39
45
  required: false;
@@ -60,6 +66,14 @@ export declare const scoreEntity: Entity<string, string, string, {
60
66
  type: "string";
61
67
  required: false;
62
68
  };
69
+ generateScorePrompt: {
70
+ type: "string";
71
+ required: false;
72
+ };
73
+ generateReasonPrompt: {
74
+ type: "string";
75
+ required: false;
76
+ };
63
77
  input: {
64
78
  type: "string";
65
79
  required: true;
@@ -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;;;;;0BAgB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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"}
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);
@@ -2099,11 +2181,12 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2099
2181
  traceId: score.traceId || "",
2100
2182
  runId: score.runId,
2101
2183
  scorer: typeof score.scorer === "string" ? score.scorer : JSON.stringify(score.scorer),
2102
- extractStepResult: typeof score.extractStepResult === "string" ? score.extractStepResult : JSON.stringify(score.extractStepResult),
2184
+ preprocessStepResult: typeof score.preprocessStepResult === "string" ? score.preprocessStepResult : JSON.stringify(score.preprocessStepResult),
2103
2185
  analyzeStepResult: typeof score.analyzeStepResult === "string" ? score.analyzeStepResult : JSON.stringify(score.analyzeStepResult),
2104
2186
  score: score.score,
2105
2187
  reason: score.reason,
2106
- extractPrompt: score.extractPrompt,
2188
+ preprocessPrompt: score.preprocessPrompt,
2189
+ generateScorePrompt: score.generateScorePrompt,
2107
2190
  analyzePrompt: score.analyzePrompt,
2108
2191
  reasonPrompt: score.reasonPrompt,
2109
2192
  input: typeof score.input === "string" ? score.input : JSON.stringify(score.input),
@@ -2144,9 +2227,9 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2144
2227
  scorerId,
2145
2228
  pagination,
2146
2229
  entityId,
2147
- entityType
2230
+ entityType,
2231
+ source
2148
2232
  }) {
2149
- this.logger.debug("Getting scores by scorer ID", { scorerId, pagination, entityId, entityType });
2150
2233
  try {
2151
2234
  const query = this.service.entities.score.query.byScorer({ entity: "score", scorerId });
2152
2235
  const results = await query.go();
@@ -2157,6 +2240,9 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2157
2240
  if (entityType) {
2158
2241
  allScores = allScores.filter((score) => score.entityType === entityType);
2159
2242
  }
2243
+ if (source) {
2244
+ allScores = allScores.filter((score) => score.source === source);
2245
+ }
2160
2246
  allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
2161
2247
  const startIndex = pagination.page * pagination.perPage;
2162
2248
  const endIndex = startIndex + pagination.perPage;
@@ -2182,6 +2268,7 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2182
2268
  scorerId: scorerId || "",
2183
2269
  entityId: entityId || "",
2184
2270
  entityType: entityType || "",
2271
+ source: source || "",
2185
2272
  page: pagination.page,
2186
2273
  perPage: pagination.perPage
2187
2274
  }
@@ -2859,8 +2946,8 @@ var DynamoDBStore = class extends storage.MastraStorage {
2859
2946
  async getThreadById({ threadId }) {
2860
2947
  return this.stores.memory.getThreadById({ threadId });
2861
2948
  }
2862
- async getThreadsByResourceId({ resourceId }) {
2863
- return this.stores.memory.getThreadsByResourceId({ resourceId });
2949
+ async getThreadsByResourceId(args) {
2950
+ return this.stores.memory.getThreadsByResourceId(args);
2864
2951
  }
2865
2952
  async saveThread({ thread }) {
2866
2953
  return this.stores.memory.saveThread({ thread });
@@ -2883,6 +2970,12 @@ var DynamoDBStore = class extends storage.MastraStorage {
2883
2970
  }) {
2884
2971
  return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
2885
2972
  }
2973
+ async getMessagesById({
2974
+ messageIds,
2975
+ format
2976
+ }) {
2977
+ return this.stores.memory.getMessagesById({ messageIds, format });
2978
+ }
2886
2979
  async saveMessages(args) {
2887
2980
  return this.stores.memory.saveMessages(args);
2888
2981
  }
@@ -2992,10 +3085,13 @@ var DynamoDBStore = class extends storage.MastraStorage {
2992
3085
  });
2993
3086
  }
2994
3087
  async getScoresByScorerId({
2995
- scorerId: _scorerId,
2996
- pagination: _pagination
3088
+ scorerId,
3089
+ source,
3090
+ entityId,
3091
+ entityType,
3092
+ pagination
2997
3093
  }) {
2998
- return this.stores.scores.getScoresByScorerId({ scorerId: _scorerId, pagination: _pagination });
3094
+ return this.stores.scores.getScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
2999
3095
  }
3000
3096
  };
3001
3097