@mastra/dynamodb 0.0.0-update-scorers-api-20250801170445 → 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.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './storage';
1
+ export * from './storage/index.js';
2
2
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { DynamoDBClient, DescribeTableCommand } from '@aws-sdk/client-dynamodb';
2
2
  import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
3
3
  import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
4
- import { MastraStorage, StoreOperations, TracesStorage, TABLE_TRACES, WorkflowsStorage, MemoryStorage, resolveMessageLimit, ScoresStorage, LegacyEvalsStorage, TABLE_RESOURCES, TABLE_SCORERS, TABLE_EVALS, TABLE_WORKFLOW_SNAPSHOT, TABLE_MESSAGES, TABLE_THREADS } from '@mastra/core/storage';
4
+ import { MastraStorage, StoreOperations, TracesStorage, TABLE_TRACES, WorkflowsStorage, MemoryStorage, resolveMessageLimit, ScoresStorage, LegacyEvalsStorage, TABLE_AI_SPANS, TABLE_RESOURCES, TABLE_SCORERS, TABLE_EVALS, TABLE_WORKFLOW_SNAPSHOT, TABLE_MESSAGES, TABLE_THREADS } from '@mastra/core/storage';
5
5
  import { Entity, Service } from 'electrodb';
6
6
  import { MessageList } from '@mastra/core/agent';
7
7
 
@@ -1121,6 +1121,20 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1121
1121
  // transformed by the ElectroDB entity getters.
1122
1122
  };
1123
1123
  }
1124
+ // Helper function to transform and sort threads
1125
+ transformAndSortThreads(rawThreads, orderBy, sortDirection) {
1126
+ return rawThreads.map((data) => ({
1127
+ ...data,
1128
+ // Convert date strings back to Date objects for consistency
1129
+ createdAt: typeof data.createdAt === "string" ? new Date(data.createdAt) : data.createdAt,
1130
+ updatedAt: typeof data.updatedAt === "string" ? new Date(data.updatedAt) : data.updatedAt
1131
+ })).sort((a, b) => {
1132
+ const fieldA = orderBy === "createdAt" ? a.createdAt : a.updatedAt;
1133
+ const fieldB = orderBy === "createdAt" ? b.createdAt : b.updatedAt;
1134
+ const comparison = fieldA.getTime() - fieldB.getTime();
1135
+ return sortDirection === "DESC" ? -comparison : comparison;
1136
+ });
1137
+ }
1124
1138
  async getThreadById({ threadId }) {
1125
1139
  this.logger.debug("Getting thread by ID", { threadId });
1126
1140
  try {
@@ -1149,21 +1163,20 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1149
1163
  );
1150
1164
  }
1151
1165
  }
1152
- async getThreadsByResourceId({ resourceId }) {
1153
- this.logger.debug("Getting threads by resource ID", { resourceId });
1166
+ /**
1167
+ * @deprecated use getThreadsByResourceIdPaginated instead for paginated results.
1168
+ */
1169
+ async getThreadsByResourceId(args) {
1170
+ const resourceId = args.resourceId;
1171
+ const orderBy = this.castThreadOrderBy(args.orderBy);
1172
+ const sortDirection = this.castThreadSortDirection(args.sortDirection);
1173
+ this.logger.debug("Getting threads by resource ID", { resourceId, orderBy, sortDirection });
1154
1174
  try {
1155
1175
  const result = await this.service.entities.thread.query.byResource({ entity: "thread", resourceId }).go();
1156
1176
  if (!result.data.length) {
1157
1177
  return [];
1158
1178
  }
1159
- return result.data.map((data) => ({
1160
- ...data,
1161
- // Convert date strings back to Date objects for consistency
1162
- createdAt: typeof data.createdAt === "string" ? new Date(data.createdAt) : data.createdAt,
1163
- updatedAt: typeof data.updatedAt === "string" ? new Date(data.updatedAt) : data.updatedAt
1164
- // metadata: data.metadata ? JSON.parse(data.metadata) : undefined, // REMOVED by AI
1165
- // metadata is already transformed by the entity's getter
1166
- }));
1179
+ return this.transformAndSortThreads(result.data, orderBy, sortDirection);
1167
1180
  } catch (error) {
1168
1181
  throw new MastraError(
1169
1182
  {
@@ -1185,7 +1198,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1185
1198
  resourceId: thread.resourceId,
1186
1199
  title: thread.title || `Thread ${thread.id}`,
1187
1200
  createdAt: thread.createdAt?.toISOString() || now.toISOString(),
1188
- updatedAt: now.toISOString(),
1201
+ updatedAt: thread.updatedAt?.toISOString() || now.toISOString(),
1189
1202
  metadata: thread.metadata ? JSON.stringify(thread.metadata) : void 0
1190
1203
  };
1191
1204
  try {
@@ -1346,6 +1359,36 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1346
1359
  );
1347
1360
  }
1348
1361
  }
1362
+ async getMessagesById({
1363
+ messageIds,
1364
+ format
1365
+ }) {
1366
+ this.logger.debug("Getting messages by ID", { messageIds });
1367
+ if (messageIds.length === 0) return [];
1368
+ try {
1369
+ const results = await Promise.all(
1370
+ messageIds.map((id) => this.service.entities.message.query.primary({ entity: "message", id }).go())
1371
+ );
1372
+ const data = results.map((result) => result.data).flat(1);
1373
+ let parsedMessages = data.map((data2) => this.parseMessageData(data2)).filter((msg) => "content" in msg);
1374
+ const uniqueMessages = parsedMessages.filter(
1375
+ (message, index, self) => index === self.findIndex((m) => m.id === message.id)
1376
+ );
1377
+ const list = new MessageList().add(uniqueMessages, "memory");
1378
+ if (format === `v1`) return list.get.all.v1();
1379
+ return list.get.all.v2();
1380
+ } catch (error) {
1381
+ throw new MastraError(
1382
+ {
1383
+ id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_BY_ID_FAILED",
1384
+ domain: ErrorDomain.STORAGE,
1385
+ category: ErrorCategory.THIRD_PARTY,
1386
+ details: { messageIds: JSON.stringify(messageIds) }
1387
+ },
1388
+ error
1389
+ );
1390
+ }
1391
+ }
1349
1392
  async saveMessages(args) {
1350
1393
  const { messages, format = "v1" } = args;
1351
1394
  this.logger.debug("Saving messages", { count: messages.length });
@@ -1420,11 +1463,19 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1420
1463
  }
1421
1464
  async getThreadsByResourceIdPaginated(args) {
1422
1465
  const { resourceId, page = 0, perPage = 100 } = args;
1423
- this.logger.debug("Getting threads by resource ID with pagination", { resourceId, page, perPage });
1466
+ const orderBy = this.castThreadOrderBy(args.orderBy);
1467
+ const sortDirection = this.castThreadSortDirection(args.sortDirection);
1468
+ this.logger.debug("Getting threads by resource ID with pagination", {
1469
+ resourceId,
1470
+ page,
1471
+ perPage,
1472
+ orderBy,
1473
+ sortDirection
1474
+ });
1424
1475
  try {
1425
1476
  const query = this.service.entities.thread.query.byResource({ entity: "thread", resourceId });
1426
1477
  const results = await query.go();
1427
- const allThreads = results.data;
1478
+ const allThreads = this.transformAndSortThreads(results.data, orderBy, sortDirection);
1428
1479
  const startIndex = page * perPage;
1429
1480
  const endIndex = startIndex + perPage;
1430
1481
  const paginatedThreads = allThreads.slice(startIndex, endIndex);
@@ -1791,7 +1842,8 @@ var StoreOperationsDynamoDB = class extends StoreOperations {
1791
1842
  [TABLE_EVALS]: "eval",
1792
1843
  [TABLE_SCORERS]: "score",
1793
1844
  [TABLE_TRACES]: "trace",
1794
- [TABLE_RESOURCES]: "resource"
1845
+ [TABLE_RESOURCES]: "resource",
1846
+ [TABLE_AI_SPANS]: "ai_span"
1795
1847
  };
1796
1848
  return mapping[tableName] || null;
1797
1849
  }
@@ -2174,9 +2226,9 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
2174
2226
  scorerId,
2175
2227
  pagination,
2176
2228
  entityId,
2177
- entityType
2229
+ entityType,
2230
+ source
2178
2231
  }) {
2179
- this.logger.debug("Getting scores by scorer ID", { scorerId, pagination, entityId, entityType });
2180
2232
  try {
2181
2233
  const query = this.service.entities.score.query.byScorer({ entity: "score", scorerId });
2182
2234
  const results = await query.go();
@@ -2187,6 +2239,9 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
2187
2239
  if (entityType) {
2188
2240
  allScores = allScores.filter((score) => score.entityType === entityType);
2189
2241
  }
2242
+ if (source) {
2243
+ allScores = allScores.filter((score) => score.source === source);
2244
+ }
2190
2245
  allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
2191
2246
  const startIndex = pagination.page * pagination.perPage;
2192
2247
  const endIndex = startIndex + pagination.perPage;
@@ -2212,6 +2267,7 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
2212
2267
  scorerId: scorerId || "",
2213
2268
  entityId: entityId || "",
2214
2269
  entityType: entityType || "",
2270
+ source: source || "",
2215
2271
  page: pagination.page,
2216
2272
  perPage: pagination.perPage
2217
2273
  }
@@ -2544,6 +2600,22 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
2544
2600
  super();
2545
2601
  this.service = service;
2546
2602
  }
2603
+ updateWorkflowResults({
2604
+ // workflowName,
2605
+ // runId,
2606
+ // stepId,
2607
+ // result,
2608
+ // runtimeContext,
2609
+ }) {
2610
+ throw new Error("Method not implemented.");
2611
+ }
2612
+ updateWorkflowState({
2613
+ // workflowName,
2614
+ // runId,
2615
+ // opts,
2616
+ }) {
2617
+ throw new Error("Method not implemented.");
2618
+ }
2547
2619
  // Workflow operations
2548
2620
  async persistWorkflowSnapshot({
2549
2621
  workflowName,
@@ -2889,8 +2961,8 @@ var DynamoDBStore = class extends MastraStorage {
2889
2961
  async getThreadById({ threadId }) {
2890
2962
  return this.stores.memory.getThreadById({ threadId });
2891
2963
  }
2892
- async getThreadsByResourceId({ resourceId }) {
2893
- return this.stores.memory.getThreadsByResourceId({ resourceId });
2964
+ async getThreadsByResourceId(args) {
2965
+ return this.stores.memory.getThreadsByResourceId(args);
2894
2966
  }
2895
2967
  async saveThread({ thread }) {
2896
2968
  return this.stores.memory.saveThread({ thread });
@@ -2913,6 +2985,12 @@ var DynamoDBStore = class extends MastraStorage {
2913
2985
  }) {
2914
2986
  return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
2915
2987
  }
2988
+ async getMessagesById({
2989
+ messageIds,
2990
+ format
2991
+ }) {
2992
+ return this.stores.memory.getMessagesById({ messageIds, format });
2993
+ }
2916
2994
  async saveMessages(args) {
2917
2995
  return this.stores.memory.saveMessages(args);
2918
2996
  }
@@ -2936,6 +3014,22 @@ var DynamoDBStore = class extends MastraStorage {
2936
3014
  return this.stores.traces.getTracesPaginated(_args);
2937
3015
  }
2938
3016
  // Workflow operations
3017
+ async updateWorkflowResults({
3018
+ workflowName,
3019
+ runId,
3020
+ stepId,
3021
+ result,
3022
+ runtimeContext
3023
+ }) {
3024
+ return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
3025
+ }
3026
+ async updateWorkflowState({
3027
+ workflowName,
3028
+ runId,
3029
+ opts
3030
+ }) {
3031
+ return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
3032
+ }
2939
3033
  async persistWorkflowSnapshot({
2940
3034
  workflowName,
2941
3035
  runId,
@@ -3022,10 +3116,13 @@ var DynamoDBStore = class extends MastraStorage {
3022
3116
  });
3023
3117
  }
3024
3118
  async getScoresByScorerId({
3025
- scorerId: _scorerId,
3026
- pagination: _pagination
3119
+ scorerId,
3120
+ source,
3121
+ entityId,
3122
+ entityType,
3123
+ pagination
3027
3124
  }) {
3028
- return this.stores.scores.getScoresByScorerId({ scorerId: _scorerId, pagination: _pagination });
3125
+ return this.stores.scores.getScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
3029
3126
  }
3030
3127
  };
3031
3128