@mastra/dynamodb 0.0.0-scorers-api-v2-20250801171841 → 0.0.0-scorers-ui-refactored-20250916094952
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/CHANGELOG.md +886 -0
- package/dist/index.cjs +130 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +131 -27
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +16 -4
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/operations/index.d.ts.map +1 -1
- package/dist/storage/domains/score/index.d.ts +3 -2
- package/dist/storage/domains/score/index.d.ts.map +1 -1
- package/dist/storage/domains/traces/index.d.ts +1 -1
- package/dist/storage/domains/workflows/index.d.ts +21 -2
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +38 -8
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +20 -10
- package/src/entities/eval.ts +0 -102
- package/src/entities/index.ts +0 -27
- package/src/entities/message.ts +0 -143
- package/src/entities/resource.ts +0 -57
- package/src/entities/score.ts +0 -317
- package/src/entities/thread.ts +0 -66
- package/src/entities/trace.ts +0 -129
- package/src/entities/utils.ts +0 -51
- package/src/entities/workflow-snapshot.ts +0 -56
- package/src/index.ts +0 -1
- package/src/storage/docker-compose.yml +0 -16
- package/src/storage/domains/legacy-evals/index.ts +0 -243
- package/src/storage/domains/memory/index.ts +0 -894
- package/src/storage/domains/operations/index.ts +0 -433
- package/src/storage/domains/score/index.ts +0 -288
- package/src/storage/domains/traces/index.ts +0 -286
- package/src/storage/domains/workflows/index.ts +0 -297
- package/src/storage/index.test.ts +0 -1420
- package/src/storage/index.ts +0 -483
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
|
-
|
|
1155
|
-
|
|
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
|
|
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.
|
|
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
|
-
|
|
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",
|
|
@@ -2891,8 +2969,8 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2891
2969
|
async getThreadById({ threadId }) {
|
|
2892
2970
|
return this.stores.memory.getThreadById({ threadId });
|
|
2893
2971
|
}
|
|
2894
|
-
async getThreadsByResourceId(
|
|
2895
|
-
return this.stores.memory.getThreadsByResourceId(
|
|
2972
|
+
async getThreadsByResourceId(args) {
|
|
2973
|
+
return this.stores.memory.getThreadsByResourceId(args);
|
|
2896
2974
|
}
|
|
2897
2975
|
async saveThread({ thread }) {
|
|
2898
2976
|
return this.stores.memory.saveThread({ thread });
|
|
@@ -2915,6 +2993,12 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2915
2993
|
}) {
|
|
2916
2994
|
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
|
|
2917
2995
|
}
|
|
2996
|
+
async getMessagesById({
|
|
2997
|
+
messageIds,
|
|
2998
|
+
format
|
|
2999
|
+
}) {
|
|
3000
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
3001
|
+
}
|
|
2918
3002
|
async saveMessages(args) {
|
|
2919
3003
|
return this.stores.memory.saveMessages(args);
|
|
2920
3004
|
}
|
|
@@ -2938,12 +3022,29 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2938
3022
|
return this.stores.traces.getTracesPaginated(_args);
|
|
2939
3023
|
}
|
|
2940
3024
|
// Workflow operations
|
|
3025
|
+
async updateWorkflowResults({
|
|
3026
|
+
workflowName,
|
|
3027
|
+
runId,
|
|
3028
|
+
stepId,
|
|
3029
|
+
result,
|
|
3030
|
+
runtimeContext
|
|
3031
|
+
}) {
|
|
3032
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
|
|
3033
|
+
}
|
|
3034
|
+
async updateWorkflowState({
|
|
3035
|
+
workflowName,
|
|
3036
|
+
runId,
|
|
3037
|
+
opts
|
|
3038
|
+
}) {
|
|
3039
|
+
return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
|
|
3040
|
+
}
|
|
2941
3041
|
async persistWorkflowSnapshot({
|
|
2942
3042
|
workflowName,
|
|
2943
3043
|
runId,
|
|
3044
|
+
resourceId,
|
|
2944
3045
|
snapshot
|
|
2945
3046
|
}) {
|
|
2946
|
-
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, snapshot });
|
|
3047
|
+
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
|
|
2947
3048
|
}
|
|
2948
3049
|
async loadWorkflowSnapshot({
|
|
2949
3050
|
workflowName,
|
|
@@ -3024,10 +3125,13 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
3024
3125
|
});
|
|
3025
3126
|
}
|
|
3026
3127
|
async getScoresByScorerId({
|
|
3027
|
-
scorerId
|
|
3028
|
-
|
|
3128
|
+
scorerId,
|
|
3129
|
+
source,
|
|
3130
|
+
entityId,
|
|
3131
|
+
entityType,
|
|
3132
|
+
pagination
|
|
3029
3133
|
}) {
|
|
3030
|
-
return this.stores.scores.getScoresByScorerId({ scorerId
|
|
3134
|
+
return this.stores.scores.getScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
|
|
3031
3135
|
}
|
|
3032
3136
|
};
|
|
3033
3137
|
|