@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.
- package/CHANGELOG.md +928 -0
- package/README.md +0 -4
- package/dist/index.cjs +130 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +131 -30
- 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 +22 -12
- 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.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
|
-
|
|
1153
|
-
|
|
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
|
|
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 {
|
|
@@ -1292,6 +1305,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1292
1305
|
}) {
|
|
1293
1306
|
this.logger.debug("Getting messages", { threadId, selectBy });
|
|
1294
1307
|
try {
|
|
1308
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
1295
1309
|
const messages = [];
|
|
1296
1310
|
const limit = resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
|
|
1297
1311
|
if (selectBy?.include?.length) {
|
|
@@ -1340,7 +1354,37 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1340
1354
|
id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_FAILED",
|
|
1341
1355
|
domain: ErrorDomain.STORAGE,
|
|
1342
1356
|
category: ErrorCategory.THIRD_PARTY,
|
|
1343
|
-
details: { threadId }
|
|
1357
|
+
details: { threadId, resourceId: resourceId ?? "" }
|
|
1358
|
+
},
|
|
1359
|
+
error
|
|
1360
|
+
);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
async getMessagesById({
|
|
1364
|
+
messageIds,
|
|
1365
|
+
format
|
|
1366
|
+
}) {
|
|
1367
|
+
this.logger.debug("Getting messages by ID", { messageIds });
|
|
1368
|
+
if (messageIds.length === 0) return [];
|
|
1369
|
+
try {
|
|
1370
|
+
const results = await Promise.all(
|
|
1371
|
+
messageIds.map((id) => this.service.entities.message.query.primary({ entity: "message", id }).go())
|
|
1372
|
+
);
|
|
1373
|
+
const data = results.map((result) => result.data).flat(1);
|
|
1374
|
+
let parsedMessages = data.map((data2) => this.parseMessageData(data2)).filter((msg) => "content" in msg);
|
|
1375
|
+
const uniqueMessages = parsedMessages.filter(
|
|
1376
|
+
(message, index, self) => index === self.findIndex((m) => m.id === message.id)
|
|
1377
|
+
);
|
|
1378
|
+
const list = new MessageList().add(uniqueMessages, "memory");
|
|
1379
|
+
if (format === `v1`) return list.get.all.v1();
|
|
1380
|
+
return list.get.all.v2();
|
|
1381
|
+
} catch (error) {
|
|
1382
|
+
throw new MastraError(
|
|
1383
|
+
{
|
|
1384
|
+
id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_BY_ID_FAILED",
|
|
1385
|
+
domain: ErrorDomain.STORAGE,
|
|
1386
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1387
|
+
details: { messageIds: JSON.stringify(messageIds) }
|
|
1344
1388
|
},
|
|
1345
1389
|
error
|
|
1346
1390
|
);
|
|
@@ -1420,11 +1464,19 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1420
1464
|
}
|
|
1421
1465
|
async getThreadsByResourceIdPaginated(args) {
|
|
1422
1466
|
const { resourceId, page = 0, perPage = 100 } = args;
|
|
1423
|
-
this.
|
|
1467
|
+
const orderBy = this.castThreadOrderBy(args.orderBy);
|
|
1468
|
+
const sortDirection = this.castThreadSortDirection(args.sortDirection);
|
|
1469
|
+
this.logger.debug("Getting threads by resource ID with pagination", {
|
|
1470
|
+
resourceId,
|
|
1471
|
+
page,
|
|
1472
|
+
perPage,
|
|
1473
|
+
orderBy,
|
|
1474
|
+
sortDirection
|
|
1475
|
+
});
|
|
1424
1476
|
try {
|
|
1425
1477
|
const query = this.service.entities.thread.query.byResource({ entity: "thread", resourceId });
|
|
1426
1478
|
const results = await query.go();
|
|
1427
|
-
const allThreads = results.data;
|
|
1479
|
+
const allThreads = this.transformAndSortThreads(results.data, orderBy, sortDirection);
|
|
1428
1480
|
const startIndex = page * perPage;
|
|
1429
1481
|
const endIndex = startIndex + perPage;
|
|
1430
1482
|
const paginatedThreads = allThreads.slice(startIndex, endIndex);
|
|
@@ -1457,6 +1509,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1457
1509
|
const limit = resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
|
|
1458
1510
|
this.logger.debug("Getting messages with pagination", { threadId, page, perPage, fromDate, toDate, limit });
|
|
1459
1511
|
try {
|
|
1512
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
1460
1513
|
let messages = [];
|
|
1461
1514
|
if (selectBy?.include?.length) {
|
|
1462
1515
|
const includeMessages = await this._getIncludedMessages(threadId, selectBy);
|
|
@@ -1512,19 +1565,23 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1512
1565
|
hasMore
|
|
1513
1566
|
};
|
|
1514
1567
|
} catch (error) {
|
|
1515
|
-
|
|
1568
|
+
const mastraError = new MastraError(
|
|
1516
1569
|
{
|
|
1517
1570
|
id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_PAGINATED_FAILED",
|
|
1518
1571
|
domain: ErrorDomain.STORAGE,
|
|
1519
1572
|
category: ErrorCategory.THIRD_PARTY,
|
|
1520
|
-
details: { threadId }
|
|
1573
|
+
details: { threadId, resourceId: resourceId ?? "" }
|
|
1521
1574
|
},
|
|
1522
1575
|
error
|
|
1523
1576
|
);
|
|
1577
|
+
this.logger?.trackException?.(mastraError);
|
|
1578
|
+
this.logger?.error?.(mastraError.toString());
|
|
1579
|
+
return { messages: [], total: 0, page, perPage, hasMore: false };
|
|
1524
1580
|
}
|
|
1525
1581
|
}
|
|
1526
1582
|
// Helper method to get included messages with context
|
|
1527
1583
|
async _getIncludedMessages(threadId, selectBy) {
|
|
1584
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
1528
1585
|
if (!selectBy?.include?.length) {
|
|
1529
1586
|
return [];
|
|
1530
1587
|
}
|
|
@@ -1791,7 +1848,8 @@ var StoreOperationsDynamoDB = class extends StoreOperations {
|
|
|
1791
1848
|
[TABLE_EVALS]: "eval",
|
|
1792
1849
|
[TABLE_SCORERS]: "score",
|
|
1793
1850
|
[TABLE_TRACES]: "trace",
|
|
1794
|
-
[TABLE_RESOURCES]: "resource"
|
|
1851
|
+
[TABLE_RESOURCES]: "resource",
|
|
1852
|
+
[TABLE_AI_SPANS]: "ai_span"
|
|
1795
1853
|
};
|
|
1796
1854
|
return mapping[tableName] || null;
|
|
1797
1855
|
}
|
|
@@ -2174,9 +2232,9 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
|
|
|
2174
2232
|
scorerId,
|
|
2175
2233
|
pagination,
|
|
2176
2234
|
entityId,
|
|
2177
|
-
entityType
|
|
2235
|
+
entityType,
|
|
2236
|
+
source
|
|
2178
2237
|
}) {
|
|
2179
|
-
this.logger.debug("Getting scores by scorer ID", { scorerId, pagination, entityId, entityType });
|
|
2180
2238
|
try {
|
|
2181
2239
|
const query = this.service.entities.score.query.byScorer({ entity: "score", scorerId });
|
|
2182
2240
|
const results = await query.go();
|
|
@@ -2187,6 +2245,9 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
|
|
|
2187
2245
|
if (entityType) {
|
|
2188
2246
|
allScores = allScores.filter((score) => score.entityType === entityType);
|
|
2189
2247
|
}
|
|
2248
|
+
if (source) {
|
|
2249
|
+
allScores = allScores.filter((score) => score.source === source);
|
|
2250
|
+
}
|
|
2190
2251
|
allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
2191
2252
|
const startIndex = pagination.page * pagination.perPage;
|
|
2192
2253
|
const endIndex = startIndex + pagination.perPage;
|
|
@@ -2212,6 +2273,7 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
|
|
|
2212
2273
|
scorerId: scorerId || "",
|
|
2213
2274
|
entityId: entityId || "",
|
|
2214
2275
|
entityType: entityType || "",
|
|
2276
|
+
source: source || "",
|
|
2215
2277
|
page: pagination.page,
|
|
2216
2278
|
perPage: pagination.perPage
|
|
2217
2279
|
}
|
|
@@ -2544,15 +2606,31 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
|
|
|
2544
2606
|
super();
|
|
2545
2607
|
this.service = service;
|
|
2546
2608
|
}
|
|
2609
|
+
updateWorkflowResults({
|
|
2610
|
+
// workflowName,
|
|
2611
|
+
// runId,
|
|
2612
|
+
// stepId,
|
|
2613
|
+
// result,
|
|
2614
|
+
// runtimeContext,
|
|
2615
|
+
}) {
|
|
2616
|
+
throw new Error("Method not implemented.");
|
|
2617
|
+
}
|
|
2618
|
+
updateWorkflowState({
|
|
2619
|
+
// workflowName,
|
|
2620
|
+
// runId,
|
|
2621
|
+
// opts,
|
|
2622
|
+
}) {
|
|
2623
|
+
throw new Error("Method not implemented.");
|
|
2624
|
+
}
|
|
2547
2625
|
// Workflow operations
|
|
2548
2626
|
async persistWorkflowSnapshot({
|
|
2549
2627
|
workflowName,
|
|
2550
2628
|
runId,
|
|
2629
|
+
resourceId,
|
|
2551
2630
|
snapshot
|
|
2552
2631
|
}) {
|
|
2553
2632
|
this.logger.debug("Persisting workflow snapshot", { workflowName, runId });
|
|
2554
2633
|
try {
|
|
2555
|
-
const resourceId = "resourceId" in snapshot ? snapshot.resourceId : void 0;
|
|
2556
2634
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2557
2635
|
const data = {
|
|
2558
2636
|
entity: "workflow_snapshot",
|
|
@@ -2678,8 +2756,6 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
|
|
|
2678
2756
|
async getWorkflowRunById(args) {
|
|
2679
2757
|
const { runId, workflowName } = args;
|
|
2680
2758
|
this.logger.debug("Getting workflow run by ID", { runId, workflowName });
|
|
2681
|
-
console.log("workflowName", workflowName);
|
|
2682
|
-
console.log("runId", runId);
|
|
2683
2759
|
try {
|
|
2684
2760
|
if (workflowName) {
|
|
2685
2761
|
this.logger.debug("WorkflowName provided, using direct GET operation.");
|
|
@@ -2689,7 +2765,6 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
|
|
|
2689
2765
|
workflow_name: workflowName,
|
|
2690
2766
|
run_id: runId
|
|
2691
2767
|
}).go();
|
|
2692
|
-
console.log("result", result2);
|
|
2693
2768
|
if (!result2.data) {
|
|
2694
2769
|
return null;
|
|
2695
2770
|
}
|
|
@@ -2889,8 +2964,8 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
2889
2964
|
async getThreadById({ threadId }) {
|
|
2890
2965
|
return this.stores.memory.getThreadById({ threadId });
|
|
2891
2966
|
}
|
|
2892
|
-
async getThreadsByResourceId(
|
|
2893
|
-
return this.stores.memory.getThreadsByResourceId(
|
|
2967
|
+
async getThreadsByResourceId(args) {
|
|
2968
|
+
return this.stores.memory.getThreadsByResourceId(args);
|
|
2894
2969
|
}
|
|
2895
2970
|
async saveThread({ thread }) {
|
|
2896
2971
|
return this.stores.memory.saveThread({ thread });
|
|
@@ -2913,6 +2988,12 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
2913
2988
|
}) {
|
|
2914
2989
|
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
|
|
2915
2990
|
}
|
|
2991
|
+
async getMessagesById({
|
|
2992
|
+
messageIds,
|
|
2993
|
+
format
|
|
2994
|
+
}) {
|
|
2995
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
2996
|
+
}
|
|
2916
2997
|
async saveMessages(args) {
|
|
2917
2998
|
return this.stores.memory.saveMessages(args);
|
|
2918
2999
|
}
|
|
@@ -2936,12 +3017,29 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
2936
3017
|
return this.stores.traces.getTracesPaginated(_args);
|
|
2937
3018
|
}
|
|
2938
3019
|
// Workflow operations
|
|
3020
|
+
async updateWorkflowResults({
|
|
3021
|
+
workflowName,
|
|
3022
|
+
runId,
|
|
3023
|
+
stepId,
|
|
3024
|
+
result,
|
|
3025
|
+
runtimeContext
|
|
3026
|
+
}) {
|
|
3027
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
|
|
3028
|
+
}
|
|
3029
|
+
async updateWorkflowState({
|
|
3030
|
+
workflowName,
|
|
3031
|
+
runId,
|
|
3032
|
+
opts
|
|
3033
|
+
}) {
|
|
3034
|
+
return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
|
|
3035
|
+
}
|
|
2939
3036
|
async persistWorkflowSnapshot({
|
|
2940
3037
|
workflowName,
|
|
2941
3038
|
runId,
|
|
3039
|
+
resourceId,
|
|
2942
3040
|
snapshot
|
|
2943
3041
|
}) {
|
|
2944
|
-
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, snapshot });
|
|
3042
|
+
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
|
|
2945
3043
|
}
|
|
2946
3044
|
async loadWorkflowSnapshot({
|
|
2947
3045
|
workflowName,
|
|
@@ -3022,10 +3120,13 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
3022
3120
|
});
|
|
3023
3121
|
}
|
|
3024
3122
|
async getScoresByScorerId({
|
|
3025
|
-
scorerId
|
|
3026
|
-
|
|
3123
|
+
scorerId,
|
|
3124
|
+
source,
|
|
3125
|
+
entityId,
|
|
3126
|
+
entityType,
|
|
3127
|
+
pagination
|
|
3027
3128
|
}) {
|
|
3028
|
-
return this.stores.scores.getScoresByScorerId({ scorerId
|
|
3129
|
+
return this.stores.scores.getScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
|
|
3029
3130
|
}
|
|
3030
3131
|
};
|
|
3031
3132
|
|