@mastra/dynamodb 0.0.0-remove-unused-model-providers-api-20251030210744 → 0.0.0-safe-stringify-telemetry-20251205024938
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 +45 -13
- package/dist/entities/index.d.ts +5 -1
- package/dist/entities/index.d.ts.map +1 -1
- package/dist/entities/score.d.ts +5 -1
- package/dist/entities/score.d.ts.map +1 -1
- package/dist/index.cjs +476 -161
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +477 -162
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/legacy-evals/index.d.ts +19 -0
- package/dist/storage/domains/legacy-evals/index.d.ts.map +1 -0
- package/dist/storage/domains/memory/index.d.ts +7 -8
- 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.map +1 -1
- package/dist/storage/domains/traces/index.d.ts +28 -0
- package/dist/storage/domains/traces/index.d.ts.map +1 -0
- package/dist/storage/domains/workflows/index.d.ts +3 -3
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +34 -4
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +13 -6
package/dist/index.cjs
CHANGED
|
@@ -425,6 +425,10 @@ var scoreEntity = new electrodb.Entity({
|
|
|
425
425
|
return value;
|
|
426
426
|
}
|
|
427
427
|
},
|
|
428
|
+
preprocessPrompt: {
|
|
429
|
+
type: "string",
|
|
430
|
+
required: false
|
|
431
|
+
},
|
|
428
432
|
preprocessStepResult: {
|
|
429
433
|
type: "string",
|
|
430
434
|
required: false,
|
|
@@ -564,7 +568,7 @@ var scoreEntity = new electrodb.Entity({
|
|
|
564
568
|
return value;
|
|
565
569
|
}
|
|
566
570
|
},
|
|
567
|
-
|
|
571
|
+
runtimeContext: {
|
|
568
572
|
type: "string",
|
|
569
573
|
required: false,
|
|
570
574
|
set: (value) => {
|
|
@@ -935,6 +939,187 @@ function getElectroDbService(client, tableName) {
|
|
|
935
939
|
}
|
|
936
940
|
);
|
|
937
941
|
}
|
|
942
|
+
var LegacyEvalsDynamoDB = class extends storage.LegacyEvalsStorage {
|
|
943
|
+
service;
|
|
944
|
+
tableName;
|
|
945
|
+
constructor({ service, tableName }) {
|
|
946
|
+
super();
|
|
947
|
+
this.service = service;
|
|
948
|
+
this.tableName = tableName;
|
|
949
|
+
}
|
|
950
|
+
// Eval operations
|
|
951
|
+
async getEvalsByAgentName(agentName, type) {
|
|
952
|
+
this.logger.debug("Getting evals for agent", { agentName, type });
|
|
953
|
+
try {
|
|
954
|
+
const query = this.service.entities.eval.query.byAgent({ entity: "eval", agent_name: agentName });
|
|
955
|
+
const results = await query.go({ order: "desc", limit: 100 });
|
|
956
|
+
if (!results.data.length) {
|
|
957
|
+
return [];
|
|
958
|
+
}
|
|
959
|
+
let filteredData = results.data;
|
|
960
|
+
if (type) {
|
|
961
|
+
filteredData = filteredData.filter((evalRecord) => {
|
|
962
|
+
try {
|
|
963
|
+
const testInfo = evalRecord.test_info && typeof evalRecord.test_info === "string" ? JSON.parse(evalRecord.test_info) : void 0;
|
|
964
|
+
if (type === "test" && !testInfo) {
|
|
965
|
+
return false;
|
|
966
|
+
}
|
|
967
|
+
if (type === "live" && testInfo) {
|
|
968
|
+
return false;
|
|
969
|
+
}
|
|
970
|
+
} catch (e) {
|
|
971
|
+
this.logger.warn("Failed to parse test_info during filtering", { record: evalRecord, error: e });
|
|
972
|
+
}
|
|
973
|
+
return true;
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
return filteredData.map((evalRecord) => {
|
|
977
|
+
try {
|
|
978
|
+
return {
|
|
979
|
+
input: evalRecord.input,
|
|
980
|
+
output: evalRecord.output,
|
|
981
|
+
// Safely parse result and test_info
|
|
982
|
+
result: evalRecord.result && typeof evalRecord.result === "string" ? JSON.parse(evalRecord.result) : void 0,
|
|
983
|
+
agentName: evalRecord.agent_name,
|
|
984
|
+
createdAt: evalRecord.created_at,
|
|
985
|
+
// Keep as string from DDB?
|
|
986
|
+
metricName: evalRecord.metric_name,
|
|
987
|
+
instructions: evalRecord.instructions,
|
|
988
|
+
runId: evalRecord.run_id,
|
|
989
|
+
globalRunId: evalRecord.global_run_id,
|
|
990
|
+
testInfo: evalRecord.test_info && typeof evalRecord.test_info === "string" ? JSON.parse(evalRecord.test_info) : void 0
|
|
991
|
+
};
|
|
992
|
+
} catch (parseError) {
|
|
993
|
+
this.logger.error("Failed to parse eval record", { record: evalRecord, error: parseError });
|
|
994
|
+
return {
|
|
995
|
+
agentName: evalRecord.agent_name,
|
|
996
|
+
createdAt: evalRecord.created_at,
|
|
997
|
+
runId: evalRecord.run_id,
|
|
998
|
+
globalRunId: evalRecord.global_run_id
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
});
|
|
1002
|
+
} catch (error$1) {
|
|
1003
|
+
throw new error.MastraError(
|
|
1004
|
+
{
|
|
1005
|
+
id: "STORAGE_DYNAMODB_STORE_GET_EVALS_BY_AGENT_NAME_FAILED",
|
|
1006
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1007
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1008
|
+
details: { agentName }
|
|
1009
|
+
},
|
|
1010
|
+
error$1
|
|
1011
|
+
);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
async getEvals(options = {}) {
|
|
1015
|
+
const { agentName, type, page = 0, perPage = 100, dateRange } = options;
|
|
1016
|
+
this.logger.debug("Getting evals with pagination", { agentName, type, page, perPage, dateRange });
|
|
1017
|
+
try {
|
|
1018
|
+
let query;
|
|
1019
|
+
if (agentName) {
|
|
1020
|
+
query = this.service.entities.eval.query.byAgent({ entity: "eval", agent_name: agentName });
|
|
1021
|
+
} else {
|
|
1022
|
+
query = this.service.entities.eval.query.byEntity({ entity: "eval" });
|
|
1023
|
+
}
|
|
1024
|
+
const results = await query.go({
|
|
1025
|
+
order: "desc",
|
|
1026
|
+
pages: "all"
|
|
1027
|
+
// Get all pages to apply filtering and pagination
|
|
1028
|
+
});
|
|
1029
|
+
if (!results.data.length) {
|
|
1030
|
+
return {
|
|
1031
|
+
evals: [],
|
|
1032
|
+
total: 0,
|
|
1033
|
+
page,
|
|
1034
|
+
perPage,
|
|
1035
|
+
hasMore: false
|
|
1036
|
+
};
|
|
1037
|
+
}
|
|
1038
|
+
let filteredData = results.data;
|
|
1039
|
+
if (type) {
|
|
1040
|
+
filteredData = filteredData.filter((evalRecord) => {
|
|
1041
|
+
try {
|
|
1042
|
+
const testInfo = evalRecord.test_info && typeof evalRecord.test_info === "string" ? JSON.parse(evalRecord.test_info) : void 0;
|
|
1043
|
+
if (type === "test" && !testInfo) {
|
|
1044
|
+
return false;
|
|
1045
|
+
}
|
|
1046
|
+
if (type === "live" && testInfo) {
|
|
1047
|
+
return false;
|
|
1048
|
+
}
|
|
1049
|
+
} catch (e) {
|
|
1050
|
+
this.logger.warn("Failed to parse test_info during filtering", { record: evalRecord, error: e });
|
|
1051
|
+
}
|
|
1052
|
+
return true;
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
if (dateRange) {
|
|
1056
|
+
const fromDate = dateRange.start;
|
|
1057
|
+
const toDate = dateRange.end;
|
|
1058
|
+
filteredData = filteredData.filter((evalRecord) => {
|
|
1059
|
+
const recordDate = new Date(evalRecord.created_at);
|
|
1060
|
+
if (fromDate && recordDate < fromDate) {
|
|
1061
|
+
return false;
|
|
1062
|
+
}
|
|
1063
|
+
if (toDate && recordDate > toDate) {
|
|
1064
|
+
return false;
|
|
1065
|
+
}
|
|
1066
|
+
return true;
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
const total = filteredData.length;
|
|
1070
|
+
const start = page * perPage;
|
|
1071
|
+
const end = start + perPage;
|
|
1072
|
+
const paginatedData = filteredData.slice(start, end);
|
|
1073
|
+
const evals = paginatedData.map((evalRecord) => {
|
|
1074
|
+
try {
|
|
1075
|
+
return {
|
|
1076
|
+
input: evalRecord.input,
|
|
1077
|
+
output: evalRecord.output,
|
|
1078
|
+
result: evalRecord.result && typeof evalRecord.result === "string" ? JSON.parse(evalRecord.result) : void 0,
|
|
1079
|
+
agentName: evalRecord.agent_name,
|
|
1080
|
+
createdAt: evalRecord.created_at,
|
|
1081
|
+
metricName: evalRecord.metric_name,
|
|
1082
|
+
instructions: evalRecord.instructions,
|
|
1083
|
+
runId: evalRecord.run_id,
|
|
1084
|
+
globalRunId: evalRecord.global_run_id,
|
|
1085
|
+
testInfo: evalRecord.test_info && typeof evalRecord.test_info === "string" ? JSON.parse(evalRecord.test_info) : void 0
|
|
1086
|
+
};
|
|
1087
|
+
} catch (parseError) {
|
|
1088
|
+
this.logger.error("Failed to parse eval record", { record: evalRecord, error: parseError });
|
|
1089
|
+
return {
|
|
1090
|
+
agentName: evalRecord.agent_name,
|
|
1091
|
+
createdAt: evalRecord.created_at,
|
|
1092
|
+
runId: evalRecord.run_id,
|
|
1093
|
+
globalRunId: evalRecord.global_run_id
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
});
|
|
1097
|
+
const hasMore = end < total;
|
|
1098
|
+
return {
|
|
1099
|
+
evals,
|
|
1100
|
+
total,
|
|
1101
|
+
page,
|
|
1102
|
+
perPage,
|
|
1103
|
+
hasMore
|
|
1104
|
+
};
|
|
1105
|
+
} catch (error$1) {
|
|
1106
|
+
throw new error.MastraError(
|
|
1107
|
+
{
|
|
1108
|
+
id: "STORAGE_DYNAMODB_STORE_GET_EVALS_FAILED",
|
|
1109
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1110
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1111
|
+
details: {
|
|
1112
|
+
agentName: agentName || "all",
|
|
1113
|
+
type: type || "all",
|
|
1114
|
+
page,
|
|
1115
|
+
perPage
|
|
1116
|
+
}
|
|
1117
|
+
},
|
|
1118
|
+
error$1
|
|
1119
|
+
);
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
};
|
|
938
1123
|
var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
939
1124
|
service;
|
|
940
1125
|
constructor({ service }) {
|
|
@@ -1039,7 +1224,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1039
1224
|
resourceId: thread.resourceId,
|
|
1040
1225
|
title: threadData.title,
|
|
1041
1226
|
createdAt: thread.createdAt || now,
|
|
1042
|
-
updatedAt:
|
|
1227
|
+
updatedAt: now,
|
|
1043
1228
|
metadata: thread.metadata
|
|
1044
1229
|
};
|
|
1045
1230
|
} catch (error$1) {
|
|
@@ -1191,7 +1376,10 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1191
1376
|
);
|
|
1192
1377
|
}
|
|
1193
1378
|
}
|
|
1194
|
-
async
|
|
1379
|
+
async getMessagesById({
|
|
1380
|
+
messageIds,
|
|
1381
|
+
format
|
|
1382
|
+
}) {
|
|
1195
1383
|
this.logger.debug("Getting messages by ID", { messageIds });
|
|
1196
1384
|
if (messageIds.length === 0) return [];
|
|
1197
1385
|
try {
|
|
@@ -1204,6 +1392,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1204
1392
|
(message, index, self) => index === self.findIndex((m) => m.id === message.id)
|
|
1205
1393
|
);
|
|
1206
1394
|
const list = new agent.MessageList().add(uniqueMessages, "memory");
|
|
1395
|
+
if (format === `v1`) return list.get.all.v1();
|
|
1207
1396
|
return list.get.all.v2();
|
|
1208
1397
|
} catch (error$1) {
|
|
1209
1398
|
throw new error.MastraError(
|
|
@@ -1217,150 +1406,6 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1217
1406
|
);
|
|
1218
1407
|
}
|
|
1219
1408
|
}
|
|
1220
|
-
async listMessages(args) {
|
|
1221
|
-
const { threadId, resourceId, include, filter, limit, offset = 0, orderBy } = args;
|
|
1222
|
-
if (!threadId.trim()) {
|
|
1223
|
-
throw new error.MastraError(
|
|
1224
|
-
{
|
|
1225
|
-
id: "STORAGE_DYNAMODB_LIST_MESSAGES_INVALID_THREAD_ID",
|
|
1226
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1227
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
1228
|
-
details: { threadId }
|
|
1229
|
-
},
|
|
1230
|
-
new Error("threadId must be a non-empty string")
|
|
1231
|
-
);
|
|
1232
|
-
}
|
|
1233
|
-
try {
|
|
1234
|
-
let perPage = 40;
|
|
1235
|
-
if (limit !== void 0) {
|
|
1236
|
-
if (limit === false) {
|
|
1237
|
-
perPage = Number.MAX_SAFE_INTEGER;
|
|
1238
|
-
} else if (limit === 0) {
|
|
1239
|
-
perPage = 0;
|
|
1240
|
-
} else if (typeof limit === "number" && limit > 0) {
|
|
1241
|
-
perPage = limit;
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
const page = perPage === 0 ? 0 : Math.floor(offset / perPage);
|
|
1245
|
-
const sortField = orderBy?.field || "createdAt";
|
|
1246
|
-
const sortDirection = orderBy?.direction || "DESC";
|
|
1247
|
-
this.logger.debug("Getting messages with listMessages", {
|
|
1248
|
-
threadId,
|
|
1249
|
-
resourceId,
|
|
1250
|
-
limit,
|
|
1251
|
-
offset,
|
|
1252
|
-
perPage,
|
|
1253
|
-
page,
|
|
1254
|
-
sortField,
|
|
1255
|
-
sortDirection
|
|
1256
|
-
});
|
|
1257
|
-
const query = this.service.entities.message.query.byThread({ entity: "message", threadId });
|
|
1258
|
-
const results = await query.go();
|
|
1259
|
-
let allThreadMessages = results.data.map((data) => this.parseMessageData(data)).filter((msg) => "content" in msg && typeof msg.content === "object");
|
|
1260
|
-
if (resourceId) {
|
|
1261
|
-
allThreadMessages = allThreadMessages.filter((msg) => msg.resourceId === resourceId);
|
|
1262
|
-
}
|
|
1263
|
-
if (filter?.dateRange) {
|
|
1264
|
-
const dateRange = filter.dateRange;
|
|
1265
|
-
allThreadMessages = allThreadMessages.filter((msg) => {
|
|
1266
|
-
const createdAt = new Date(msg.createdAt).getTime();
|
|
1267
|
-
if (dateRange.start) {
|
|
1268
|
-
const startTime = dateRange.start instanceof Date ? dateRange.start.getTime() : new Date(dateRange.start).getTime();
|
|
1269
|
-
if (createdAt < startTime) return false;
|
|
1270
|
-
}
|
|
1271
|
-
if (dateRange.end) {
|
|
1272
|
-
const endTime = dateRange.end instanceof Date ? dateRange.end.getTime() : new Date(dateRange.end).getTime();
|
|
1273
|
-
if (createdAt > endTime) return false;
|
|
1274
|
-
}
|
|
1275
|
-
return true;
|
|
1276
|
-
});
|
|
1277
|
-
}
|
|
1278
|
-
allThreadMessages.sort((a, b) => {
|
|
1279
|
-
const aValue = sortField === "createdAt" ? new Date(a.createdAt).getTime() : a[sortField];
|
|
1280
|
-
const bValue = sortField === "createdAt" ? new Date(b.createdAt).getTime() : b[sortField];
|
|
1281
|
-
if (aValue === bValue) {
|
|
1282
|
-
return a.id.localeCompare(b.id);
|
|
1283
|
-
}
|
|
1284
|
-
return sortDirection === "ASC" ? aValue - bValue : bValue - aValue;
|
|
1285
|
-
});
|
|
1286
|
-
const total = allThreadMessages.length;
|
|
1287
|
-
const paginatedMessages = allThreadMessages.slice(offset, offset + perPage);
|
|
1288
|
-
const paginatedCount = paginatedMessages.length;
|
|
1289
|
-
if (total === 0 && paginatedCount === 0) {
|
|
1290
|
-
return {
|
|
1291
|
-
messages: [],
|
|
1292
|
-
total: 0,
|
|
1293
|
-
page,
|
|
1294
|
-
perPage,
|
|
1295
|
-
hasMore: false
|
|
1296
|
-
};
|
|
1297
|
-
}
|
|
1298
|
-
const messageIds = new Set(paginatedMessages.map((m) => m.id));
|
|
1299
|
-
let includeMessages = [];
|
|
1300
|
-
if (include && include.length > 0) {
|
|
1301
|
-
const selectBy = { include };
|
|
1302
|
-
includeMessages = await this._getIncludedMessages(threadId, selectBy);
|
|
1303
|
-
for (const includeMsg of includeMessages) {
|
|
1304
|
-
if (!messageIds.has(includeMsg.id)) {
|
|
1305
|
-
paginatedMessages.push(includeMsg);
|
|
1306
|
-
messageIds.add(includeMsg.id);
|
|
1307
|
-
}
|
|
1308
|
-
}
|
|
1309
|
-
}
|
|
1310
|
-
const list = new agent.MessageList().add(paginatedMessages, "memory");
|
|
1311
|
-
let finalMessages = list.get.all.v2();
|
|
1312
|
-
finalMessages = finalMessages.sort((a, b) => {
|
|
1313
|
-
const aValue = sortField === "createdAt" ? new Date(a.createdAt).getTime() : a[sortField];
|
|
1314
|
-
const bValue = sortField === "createdAt" ? new Date(b.createdAt).getTime() : b[sortField];
|
|
1315
|
-
if (aValue === bValue) {
|
|
1316
|
-
return a.id.localeCompare(b.id);
|
|
1317
|
-
}
|
|
1318
|
-
return sortDirection === "ASC" ? aValue - bValue : bValue - aValue;
|
|
1319
|
-
});
|
|
1320
|
-
const returnedThreadMessageIds = new Set(finalMessages.filter((m) => m.threadId === threadId).map((m) => m.id));
|
|
1321
|
-
const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
|
|
1322
|
-
const hasMore = limit === false ? false : allThreadMessagesReturned ? false : offset + paginatedCount < total;
|
|
1323
|
-
return {
|
|
1324
|
-
messages: finalMessages,
|
|
1325
|
-
total,
|
|
1326
|
-
page,
|
|
1327
|
-
perPage,
|
|
1328
|
-
hasMore
|
|
1329
|
-
};
|
|
1330
|
-
} catch (error$1) {
|
|
1331
|
-
const mastraError = new error.MastraError(
|
|
1332
|
-
{
|
|
1333
|
-
id: "STORAGE_DYNAMODB_STORE_LIST_MESSAGES_FAILED",
|
|
1334
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1335
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
1336
|
-
details: {
|
|
1337
|
-
threadId,
|
|
1338
|
-
resourceId: resourceId ?? ""
|
|
1339
|
-
}
|
|
1340
|
-
},
|
|
1341
|
-
error$1
|
|
1342
|
-
);
|
|
1343
|
-
this.logger?.error?.(mastraError.toString());
|
|
1344
|
-
this.logger?.trackException?.(mastraError);
|
|
1345
|
-
return {
|
|
1346
|
-
messages: [],
|
|
1347
|
-
total: 0,
|
|
1348
|
-
page: Math.floor(offset / (limit === false ? Number.MAX_SAFE_INTEGER : limit || 40)),
|
|
1349
|
-
perPage: limit === false ? Number.MAX_SAFE_INTEGER : limit || 40,
|
|
1350
|
-
hasMore: false
|
|
1351
|
-
};
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
/**
|
|
1355
|
-
* @todo When migrating from getThreadsByResourceIdPaginated to this method,
|
|
1356
|
-
* implement orderBy and sortDirection support for full sorting capabilities
|
|
1357
|
-
*/
|
|
1358
|
-
async listThreadsByResourceId(args) {
|
|
1359
|
-
const { resourceId, limit, offset } = args;
|
|
1360
|
-
const page = Math.floor(offset / limit);
|
|
1361
|
-
const perPage = limit;
|
|
1362
|
-
return this.getThreadsByResourceIdPaginated({ resourceId, page, perPage });
|
|
1363
|
-
}
|
|
1364
1409
|
async saveMessages(args) {
|
|
1365
1410
|
const { messages, format = "v1" } = args;
|
|
1366
1411
|
this.logger.debug("Saving messages", { count: messages.length });
|
|
@@ -1527,7 +1572,8 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1527
1572
|
const paginatedMessages = messages.slice(start, end);
|
|
1528
1573
|
const hasMore = end < total;
|
|
1529
1574
|
const list = new agent.MessageList({ threadId, resourceId }).add(paginatedMessages, "memory");
|
|
1530
|
-
|
|
1575
|
+
let finalMessages = format === "v2" ? list.get.all.v2() : list.get.all.v1();
|
|
1576
|
+
finalMessages = finalMessages.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
1531
1577
|
return {
|
|
1532
1578
|
messages: finalMessages,
|
|
1533
1579
|
total,
|
|
@@ -1816,6 +1862,7 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
|
|
|
1816
1862
|
[storage.TABLE_THREADS]: "thread",
|
|
1817
1863
|
[storage.TABLE_MESSAGES]: "message",
|
|
1818
1864
|
[storage.TABLE_WORKFLOW_SNAPSHOT]: "workflow_snapshot",
|
|
1865
|
+
[storage.TABLE_EVALS]: "eval",
|
|
1819
1866
|
[storage.TABLE_SCORERS]: "score",
|
|
1820
1867
|
[storage.TABLE_TRACES]: "trace",
|
|
1821
1868
|
[storage.TABLE_RESOURCES]: "resource",
|
|
@@ -2004,10 +2051,6 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
|
|
|
2004
2051
|
if (!item.id) throw new Error(`Missing required key 'id' for entity 'score'`);
|
|
2005
2052
|
key.id = item.id;
|
|
2006
2053
|
break;
|
|
2007
|
-
case "resource":
|
|
2008
|
-
if (!item.id) throw new Error(`Missing required key 'id' for entity 'resource'`);
|
|
2009
|
-
key.id = item.id;
|
|
2010
|
-
break;
|
|
2011
2054
|
default:
|
|
2012
2055
|
this.logger.warn(`Unknown entity type encountered during clearTable: ${entityName}`);
|
|
2013
2056
|
throw new Error(`Cannot construct delete key for unknown entity type: ${entityName}`);
|
|
@@ -2121,8 +2164,17 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2121
2164
|
}
|
|
2122
2165
|
// Helper function to parse score data (handle JSON fields)
|
|
2123
2166
|
parseScoreData(data) {
|
|
2167
|
+
const result = {};
|
|
2168
|
+
for (const key of Object.keys(storage.SCORERS_SCHEMA)) {
|
|
2169
|
+
if (["traceId", "resourceId", "threadId", "spanId"].includes(key)) {
|
|
2170
|
+
result[key] = data[key] === "" ? null : data[key];
|
|
2171
|
+
continue;
|
|
2172
|
+
}
|
|
2173
|
+
result[key] = data[key];
|
|
2174
|
+
}
|
|
2175
|
+
result.entity = data.entityData ? data.entityData : null;
|
|
2124
2176
|
return {
|
|
2125
|
-
...
|
|
2177
|
+
...result,
|
|
2126
2178
|
// Convert date strings back to Date objects for consistency
|
|
2127
2179
|
createdAt: data.createdAt ? new Date(data.createdAt) : /* @__PURE__ */ new Date(),
|
|
2128
2180
|
updatedAt: data.updatedAt ? new Date(data.updatedAt) : /* @__PURE__ */ new Date()
|
|
@@ -2184,7 +2236,7 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2184
2236
|
input: typeof validatedScore.input === "string" ? validatedScore.input : JSON.stringify(validatedScore.input),
|
|
2185
2237
|
output: typeof validatedScore.output === "string" ? validatedScore.output : JSON.stringify(validatedScore.output),
|
|
2186
2238
|
additionalContext: typeof validatedScore.additionalContext === "string" ? validatedScore.additionalContext : JSON.stringify(validatedScore.additionalContext),
|
|
2187
|
-
|
|
2239
|
+
runtimeContext: typeof validatedScore.runtimeContext === "string" ? validatedScore.runtimeContext : JSON.stringify(validatedScore.runtimeContext),
|
|
2188
2240
|
entityType: validatedScore.entityType,
|
|
2189
2241
|
entityData: typeof validatedScore.entity === "string" ? validatedScore.entity : JSON.stringify(validatedScore.entity),
|
|
2190
2242
|
entityId: validatedScore.entityId,
|
|
@@ -2381,6 +2433,239 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2381
2433
|
}
|
|
2382
2434
|
}
|
|
2383
2435
|
};
|
|
2436
|
+
var TracesStorageDynamoDB = class extends storage.TracesStorage {
|
|
2437
|
+
service;
|
|
2438
|
+
operations;
|
|
2439
|
+
constructor({ service, operations }) {
|
|
2440
|
+
super();
|
|
2441
|
+
this.service = service;
|
|
2442
|
+
this.operations = operations;
|
|
2443
|
+
}
|
|
2444
|
+
// Trace operations
|
|
2445
|
+
async getTraces(args) {
|
|
2446
|
+
const { name, scope, page, perPage } = args;
|
|
2447
|
+
this.logger.debug("Getting traces", { name, scope, page, perPage });
|
|
2448
|
+
try {
|
|
2449
|
+
let query;
|
|
2450
|
+
if (name) {
|
|
2451
|
+
query = this.service.entities.trace.query.byName({ entity: "trace", name });
|
|
2452
|
+
} else if (scope) {
|
|
2453
|
+
query = this.service.entities.trace.query.byScope({ entity: "trace", scope });
|
|
2454
|
+
} else {
|
|
2455
|
+
this.logger.warn("Performing a scan operation on traces - consider using a more specific query");
|
|
2456
|
+
query = this.service.entities.trace.scan;
|
|
2457
|
+
}
|
|
2458
|
+
let items = [];
|
|
2459
|
+
let cursor = null;
|
|
2460
|
+
let pagesFetched = 0;
|
|
2461
|
+
const startPage = page > 0 ? page : 1;
|
|
2462
|
+
do {
|
|
2463
|
+
const results = await query.go({ cursor, limit: perPage });
|
|
2464
|
+
pagesFetched++;
|
|
2465
|
+
if (pagesFetched === startPage) {
|
|
2466
|
+
items = results.data;
|
|
2467
|
+
break;
|
|
2468
|
+
}
|
|
2469
|
+
cursor = results.cursor;
|
|
2470
|
+
if (!cursor && results.data.length > 0 && pagesFetched < startPage) {
|
|
2471
|
+
break;
|
|
2472
|
+
}
|
|
2473
|
+
} while (cursor && pagesFetched < startPage);
|
|
2474
|
+
return items;
|
|
2475
|
+
} catch (error$1) {
|
|
2476
|
+
throw new error.MastraError(
|
|
2477
|
+
{
|
|
2478
|
+
id: "STORAGE_DYNAMODB_STORE_GET_TRACES_FAILED",
|
|
2479
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2480
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
2481
|
+
},
|
|
2482
|
+
error$1
|
|
2483
|
+
);
|
|
2484
|
+
}
|
|
2485
|
+
}
|
|
2486
|
+
async batchTraceInsert({ records }) {
|
|
2487
|
+
this.logger.debug("Batch inserting traces", { count: records.length });
|
|
2488
|
+
if (!records.length) {
|
|
2489
|
+
return;
|
|
2490
|
+
}
|
|
2491
|
+
try {
|
|
2492
|
+
const recordsToSave = records.map((rec) => ({ entity: "trace", ...rec }));
|
|
2493
|
+
await this.operations.batchInsert({
|
|
2494
|
+
tableName: storage.TABLE_TRACES,
|
|
2495
|
+
records: recordsToSave
|
|
2496
|
+
// Pass records with 'entity' included
|
|
2497
|
+
});
|
|
2498
|
+
} catch (error$1) {
|
|
2499
|
+
throw new error.MastraError(
|
|
2500
|
+
{
|
|
2501
|
+
id: "STORAGE_DYNAMODB_STORE_BATCH_TRACE_INSERT_FAILED",
|
|
2502
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2503
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
2504
|
+
details: { count: records.length }
|
|
2505
|
+
},
|
|
2506
|
+
error$1
|
|
2507
|
+
);
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2510
|
+
async getTracesPaginated(args) {
|
|
2511
|
+
const { name, scope, page = 0, perPage = 100, attributes, filters, dateRange } = args;
|
|
2512
|
+
this.logger.debug("Getting traces with pagination", { name, scope, page, perPage, attributes, filters, dateRange });
|
|
2513
|
+
try {
|
|
2514
|
+
let query;
|
|
2515
|
+
if (name) {
|
|
2516
|
+
query = this.service.entities.trace.query.byName({ entity: "trace", name });
|
|
2517
|
+
} else if (scope) {
|
|
2518
|
+
query = this.service.entities.trace.query.byScope({ entity: "trace", scope });
|
|
2519
|
+
} else {
|
|
2520
|
+
this.logger.warn("Performing a scan operation on traces - consider using a more specific query");
|
|
2521
|
+
query = this.service.entities.trace.scan;
|
|
2522
|
+
}
|
|
2523
|
+
const results = await query.go({
|
|
2524
|
+
order: "desc",
|
|
2525
|
+
pages: "all"
|
|
2526
|
+
// Get all pages to apply filtering and pagination
|
|
2527
|
+
});
|
|
2528
|
+
if (!results.data.length) {
|
|
2529
|
+
return {
|
|
2530
|
+
traces: [],
|
|
2531
|
+
total: 0,
|
|
2532
|
+
page,
|
|
2533
|
+
perPage,
|
|
2534
|
+
hasMore: false
|
|
2535
|
+
};
|
|
2536
|
+
}
|
|
2537
|
+
let filteredData = results.data;
|
|
2538
|
+
if (attributes) {
|
|
2539
|
+
filteredData = filteredData.filter((item) => {
|
|
2540
|
+
try {
|
|
2541
|
+
let itemAttributes = {};
|
|
2542
|
+
if (item.attributes) {
|
|
2543
|
+
if (typeof item.attributes === "string") {
|
|
2544
|
+
if (item.attributes === "[object Object]") {
|
|
2545
|
+
itemAttributes = {};
|
|
2546
|
+
} else {
|
|
2547
|
+
try {
|
|
2548
|
+
itemAttributes = JSON.parse(item.attributes);
|
|
2549
|
+
} catch {
|
|
2550
|
+
itemAttributes = {};
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
} else if (typeof item.attributes === "object") {
|
|
2554
|
+
itemAttributes = item.attributes;
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
return Object.entries(attributes).every(([key, value]) => itemAttributes[key] === value);
|
|
2558
|
+
} catch (e) {
|
|
2559
|
+
this.logger.warn("Failed to parse attributes during filtering", { item, error: e });
|
|
2560
|
+
return false;
|
|
2561
|
+
}
|
|
2562
|
+
});
|
|
2563
|
+
}
|
|
2564
|
+
if (dateRange?.start) {
|
|
2565
|
+
filteredData = filteredData.filter((item) => {
|
|
2566
|
+
const itemDate = new Date(item.createdAt);
|
|
2567
|
+
return itemDate >= dateRange.start;
|
|
2568
|
+
});
|
|
2569
|
+
}
|
|
2570
|
+
if (dateRange?.end) {
|
|
2571
|
+
filteredData = filteredData.filter((item) => {
|
|
2572
|
+
const itemDate = new Date(item.createdAt);
|
|
2573
|
+
return itemDate <= dateRange.end;
|
|
2574
|
+
});
|
|
2575
|
+
}
|
|
2576
|
+
const total = filteredData.length;
|
|
2577
|
+
const start = page * perPage;
|
|
2578
|
+
const end = start + perPage;
|
|
2579
|
+
const paginatedData = filteredData.slice(start, end);
|
|
2580
|
+
const traces = paginatedData.map((item) => {
|
|
2581
|
+
let attributes2;
|
|
2582
|
+
if (item.attributes) {
|
|
2583
|
+
if (typeof item.attributes === "string") {
|
|
2584
|
+
if (item.attributes === "[object Object]") {
|
|
2585
|
+
attributes2 = void 0;
|
|
2586
|
+
} else {
|
|
2587
|
+
try {
|
|
2588
|
+
attributes2 = JSON.parse(item.attributes);
|
|
2589
|
+
} catch {
|
|
2590
|
+
attributes2 = void 0;
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
} else if (typeof item.attributes === "object") {
|
|
2594
|
+
attributes2 = item.attributes;
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
let status;
|
|
2598
|
+
if (item.status) {
|
|
2599
|
+
if (typeof item.status === "string") {
|
|
2600
|
+
try {
|
|
2601
|
+
status = JSON.parse(item.status);
|
|
2602
|
+
} catch {
|
|
2603
|
+
status = void 0;
|
|
2604
|
+
}
|
|
2605
|
+
} else if (typeof item.status === "object") {
|
|
2606
|
+
status = item.status;
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
2609
|
+
let events;
|
|
2610
|
+
if (item.events) {
|
|
2611
|
+
if (typeof item.events === "string") {
|
|
2612
|
+
try {
|
|
2613
|
+
events = JSON.parse(item.events);
|
|
2614
|
+
} catch {
|
|
2615
|
+
events = void 0;
|
|
2616
|
+
}
|
|
2617
|
+
} else if (Array.isArray(item.events)) {
|
|
2618
|
+
events = item.events;
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
let links;
|
|
2622
|
+
if (item.links) {
|
|
2623
|
+
if (typeof item.links === "string") {
|
|
2624
|
+
try {
|
|
2625
|
+
links = JSON.parse(item.links);
|
|
2626
|
+
} catch {
|
|
2627
|
+
links = void 0;
|
|
2628
|
+
}
|
|
2629
|
+
} else if (Array.isArray(item.links)) {
|
|
2630
|
+
links = item.links;
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
return {
|
|
2634
|
+
id: item.id,
|
|
2635
|
+
parentSpanId: item.parentSpanId,
|
|
2636
|
+
name: item.name,
|
|
2637
|
+
traceId: item.traceId,
|
|
2638
|
+
scope: item.scope,
|
|
2639
|
+
kind: item.kind,
|
|
2640
|
+
attributes: attributes2,
|
|
2641
|
+
status,
|
|
2642
|
+
events,
|
|
2643
|
+
links,
|
|
2644
|
+
other: item.other,
|
|
2645
|
+
startTime: item.startTime,
|
|
2646
|
+
endTime: item.endTime,
|
|
2647
|
+
createdAt: item.createdAt
|
|
2648
|
+
};
|
|
2649
|
+
});
|
|
2650
|
+
return {
|
|
2651
|
+
traces,
|
|
2652
|
+
total,
|
|
2653
|
+
page,
|
|
2654
|
+
perPage,
|
|
2655
|
+
hasMore: end < total
|
|
2656
|
+
};
|
|
2657
|
+
} catch (error$1) {
|
|
2658
|
+
throw new error.MastraError(
|
|
2659
|
+
{
|
|
2660
|
+
id: "STORAGE_DYNAMODB_STORE_GET_TRACES_PAGINATED_FAILED",
|
|
2661
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2662
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
2663
|
+
},
|
|
2664
|
+
error$1
|
|
2665
|
+
);
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
};
|
|
2384
2669
|
function formatWorkflowRun(snapshotData) {
|
|
2385
2670
|
return {
|
|
2386
2671
|
workflowName: snapshotData.workflow_name,
|
|
@@ -2402,7 +2687,7 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
|
|
|
2402
2687
|
// runId,
|
|
2403
2688
|
// stepId,
|
|
2404
2689
|
// result,
|
|
2405
|
-
//
|
|
2690
|
+
// runtimeContext,
|
|
2406
2691
|
}) {
|
|
2407
2692
|
throw new Error("Method not implemented.");
|
|
2408
2693
|
}
|
|
@@ -2429,7 +2714,6 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
|
|
|
2429
2714
|
workflow_name: workflowName,
|
|
2430
2715
|
run_id: runId,
|
|
2431
2716
|
snapshot: JSON.stringify(snapshot),
|
|
2432
|
-
// Stringify the snapshot object
|
|
2433
2717
|
createdAt: now,
|
|
2434
2718
|
updatedAt: now,
|
|
2435
2719
|
resourceId
|
|
@@ -2475,7 +2759,7 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
|
|
|
2475
2759
|
);
|
|
2476
2760
|
}
|
|
2477
2761
|
}
|
|
2478
|
-
async
|
|
2762
|
+
async getWorkflowRuns(args) {
|
|
2479
2763
|
this.logger.debug("Getting workflow runs", { args });
|
|
2480
2764
|
try {
|
|
2481
2765
|
const limit = args?.limit || 10;
|
|
@@ -2501,6 +2785,11 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
|
|
|
2501
2785
|
});
|
|
2502
2786
|
if (pageResults.data && pageResults.data.length > 0) {
|
|
2503
2787
|
let pageFilteredData = pageResults.data;
|
|
2788
|
+
if (args?.status) {
|
|
2789
|
+
pageFilteredData = pageFilteredData.filter((snapshot) => {
|
|
2790
|
+
return snapshot.snapshot.status === args.status;
|
|
2791
|
+
});
|
|
2792
|
+
}
|
|
2504
2793
|
if (args?.fromDate || args?.toDate) {
|
|
2505
2794
|
pageFilteredData = pageFilteredData.filter((snapshot) => {
|
|
2506
2795
|
const createdAt = new Date(snapshot.createdAt);
|
|
@@ -2631,11 +2920,14 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2631
2920
|
tableName: this.tableName,
|
|
2632
2921
|
client: this.client
|
|
2633
2922
|
});
|
|
2923
|
+
const traces = new TracesStorageDynamoDB({ service: this.service, operations });
|
|
2634
2924
|
const workflows = new WorkflowStorageDynamoDB({ service: this.service });
|
|
2635
2925
|
const memory = new MemoryStorageDynamoDB({ service: this.service });
|
|
2636
2926
|
const scores = new ScoresStorageDynamoDB({ service: this.service });
|
|
2637
2927
|
this.stores = {
|
|
2638
2928
|
operations,
|
|
2929
|
+
legacyEvals: new LegacyEvalsDynamoDB({ service: this.service, tableName: this.tableName }),
|
|
2930
|
+
traces,
|
|
2639
2931
|
workflows,
|
|
2640
2932
|
memory,
|
|
2641
2933
|
scores
|
|
@@ -2777,6 +3069,12 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2777
3069
|
}) {
|
|
2778
3070
|
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
|
|
2779
3071
|
}
|
|
3072
|
+
async getMessagesById({
|
|
3073
|
+
messageIds,
|
|
3074
|
+
format
|
|
3075
|
+
}) {
|
|
3076
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
3077
|
+
}
|
|
2780
3078
|
async saveMessages(args) {
|
|
2781
3079
|
return this.stores.memory.saveMessages(args);
|
|
2782
3080
|
}
|
|
@@ -2789,15 +3087,25 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2789
3087
|
async updateMessages(_args) {
|
|
2790
3088
|
return this.stores.memory.updateMessages(_args);
|
|
2791
3089
|
}
|
|
3090
|
+
// Trace operations
|
|
3091
|
+
async getTraces(args) {
|
|
3092
|
+
return this.stores.traces.getTraces(args);
|
|
3093
|
+
}
|
|
3094
|
+
async batchTraceInsert({ records }) {
|
|
3095
|
+
return this.stores.traces.batchTraceInsert({ records });
|
|
3096
|
+
}
|
|
3097
|
+
async getTracesPaginated(_args) {
|
|
3098
|
+
return this.stores.traces.getTracesPaginated(_args);
|
|
3099
|
+
}
|
|
2792
3100
|
// Workflow operations
|
|
2793
3101
|
async updateWorkflowResults({
|
|
2794
3102
|
workflowName,
|
|
2795
3103
|
runId,
|
|
2796
3104
|
stepId,
|
|
2797
3105
|
result,
|
|
2798
|
-
|
|
3106
|
+
runtimeContext
|
|
2799
3107
|
}) {
|
|
2800
|
-
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result,
|
|
3108
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
|
|
2801
3109
|
}
|
|
2802
3110
|
async updateWorkflowState({
|
|
2803
3111
|
workflowName,
|
|
@@ -2820,8 +3128,8 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2820
3128
|
}) {
|
|
2821
3129
|
return this.stores.workflows.loadWorkflowSnapshot({ workflowName, runId });
|
|
2822
3130
|
}
|
|
2823
|
-
async
|
|
2824
|
-
return this.stores.workflows.
|
|
3131
|
+
async getWorkflowRuns(args) {
|
|
3132
|
+
return this.stores.workflows.getWorkflowRuns(args);
|
|
2825
3133
|
}
|
|
2826
3134
|
async getWorkflowRunById(args) {
|
|
2827
3135
|
return this.stores.workflows.getWorkflowRunById(args);
|
|
@@ -2839,6 +3147,13 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2839
3147
|
}) {
|
|
2840
3148
|
return this.stores.memory.updateResource({ resourceId, workingMemory, metadata });
|
|
2841
3149
|
}
|
|
3150
|
+
// Eval operations
|
|
3151
|
+
async getEvalsByAgentName(agentName, type) {
|
|
3152
|
+
return this.stores.legacyEvals.getEvalsByAgentName(agentName, type);
|
|
3153
|
+
}
|
|
3154
|
+
async getEvals(options) {
|
|
3155
|
+
return this.stores.legacyEvals.getEvals(options);
|
|
3156
|
+
}
|
|
2842
3157
|
/**
|
|
2843
3158
|
* Closes the DynamoDB client connection and cleans up resources.
|
|
2844
3159
|
* Should be called when the store is no longer needed, e.g., at the end of tests or application shutdown.
|