@mastra/dynamodb 0.0.0-rag-chunk-extract-llm-option-20250926183645 → 0.0.0-remove-unused-model-providers-api-20251030210744
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 +141 -3
- package/dist/entities/index.d.ts +1 -1
- package/dist/entities/score.d.ts +1 -1
- package/dist/index.cjs +158 -455
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +159 -456
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +8 -7
- 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/workflows/index.d.ts +3 -10
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +4 -41
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +10 -10
- package/dist/storage/domains/legacy-evals/index.d.ts +0 -19
- package/dist/storage/domains/legacy-evals/index.d.ts.map +0 -1
- package/dist/storage/domains/traces/index.d.ts +0 -28
- package/dist/storage/domains/traces/index.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -564,7 +564,7 @@ var scoreEntity = new electrodb.Entity({
|
|
|
564
564
|
return value;
|
|
565
565
|
}
|
|
566
566
|
},
|
|
567
|
-
|
|
567
|
+
requestContext: {
|
|
568
568
|
type: "string",
|
|
569
569
|
required: false,
|
|
570
570
|
set: (value) => {
|
|
@@ -935,187 +935,6 @@ function getElectroDbService(client, tableName) {
|
|
|
935
935
|
}
|
|
936
936
|
);
|
|
937
937
|
}
|
|
938
|
-
var LegacyEvalsDynamoDB = class extends storage.LegacyEvalsStorage {
|
|
939
|
-
service;
|
|
940
|
-
tableName;
|
|
941
|
-
constructor({ service, tableName }) {
|
|
942
|
-
super();
|
|
943
|
-
this.service = service;
|
|
944
|
-
this.tableName = tableName;
|
|
945
|
-
}
|
|
946
|
-
// Eval operations
|
|
947
|
-
async getEvalsByAgentName(agentName, type) {
|
|
948
|
-
this.logger.debug("Getting evals for agent", { agentName, type });
|
|
949
|
-
try {
|
|
950
|
-
const query = this.service.entities.eval.query.byAgent({ entity: "eval", agent_name: agentName });
|
|
951
|
-
const results = await query.go({ order: "desc", limit: 100 });
|
|
952
|
-
if (!results.data.length) {
|
|
953
|
-
return [];
|
|
954
|
-
}
|
|
955
|
-
let filteredData = results.data;
|
|
956
|
-
if (type) {
|
|
957
|
-
filteredData = filteredData.filter((evalRecord) => {
|
|
958
|
-
try {
|
|
959
|
-
const testInfo = evalRecord.test_info && typeof evalRecord.test_info === "string" ? JSON.parse(evalRecord.test_info) : void 0;
|
|
960
|
-
if (type === "test" && !testInfo) {
|
|
961
|
-
return false;
|
|
962
|
-
}
|
|
963
|
-
if (type === "live" && testInfo) {
|
|
964
|
-
return false;
|
|
965
|
-
}
|
|
966
|
-
} catch (e) {
|
|
967
|
-
this.logger.warn("Failed to parse test_info during filtering", { record: evalRecord, error: e });
|
|
968
|
-
}
|
|
969
|
-
return true;
|
|
970
|
-
});
|
|
971
|
-
}
|
|
972
|
-
return filteredData.map((evalRecord) => {
|
|
973
|
-
try {
|
|
974
|
-
return {
|
|
975
|
-
input: evalRecord.input,
|
|
976
|
-
output: evalRecord.output,
|
|
977
|
-
// Safely parse result and test_info
|
|
978
|
-
result: evalRecord.result && typeof evalRecord.result === "string" ? JSON.parse(evalRecord.result) : void 0,
|
|
979
|
-
agentName: evalRecord.agent_name,
|
|
980
|
-
createdAt: evalRecord.created_at,
|
|
981
|
-
// Keep as string from DDB?
|
|
982
|
-
metricName: evalRecord.metric_name,
|
|
983
|
-
instructions: evalRecord.instructions,
|
|
984
|
-
runId: evalRecord.run_id,
|
|
985
|
-
globalRunId: evalRecord.global_run_id,
|
|
986
|
-
testInfo: evalRecord.test_info && typeof evalRecord.test_info === "string" ? JSON.parse(evalRecord.test_info) : void 0
|
|
987
|
-
};
|
|
988
|
-
} catch (parseError) {
|
|
989
|
-
this.logger.error("Failed to parse eval record", { record: evalRecord, error: parseError });
|
|
990
|
-
return {
|
|
991
|
-
agentName: evalRecord.agent_name,
|
|
992
|
-
createdAt: evalRecord.created_at,
|
|
993
|
-
runId: evalRecord.run_id,
|
|
994
|
-
globalRunId: evalRecord.global_run_id
|
|
995
|
-
};
|
|
996
|
-
}
|
|
997
|
-
});
|
|
998
|
-
} catch (error$1) {
|
|
999
|
-
throw new error.MastraError(
|
|
1000
|
-
{
|
|
1001
|
-
id: "STORAGE_DYNAMODB_STORE_GET_EVALS_BY_AGENT_NAME_FAILED",
|
|
1002
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1003
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
1004
|
-
details: { agentName }
|
|
1005
|
-
},
|
|
1006
|
-
error$1
|
|
1007
|
-
);
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
async getEvals(options = {}) {
|
|
1011
|
-
const { agentName, type, page = 0, perPage = 100, dateRange } = options;
|
|
1012
|
-
this.logger.debug("Getting evals with pagination", { agentName, type, page, perPage, dateRange });
|
|
1013
|
-
try {
|
|
1014
|
-
let query;
|
|
1015
|
-
if (agentName) {
|
|
1016
|
-
query = this.service.entities.eval.query.byAgent({ entity: "eval", agent_name: agentName });
|
|
1017
|
-
} else {
|
|
1018
|
-
query = this.service.entities.eval.query.byEntity({ entity: "eval" });
|
|
1019
|
-
}
|
|
1020
|
-
const results = await query.go({
|
|
1021
|
-
order: "desc",
|
|
1022
|
-
pages: "all"
|
|
1023
|
-
// Get all pages to apply filtering and pagination
|
|
1024
|
-
});
|
|
1025
|
-
if (!results.data.length) {
|
|
1026
|
-
return {
|
|
1027
|
-
evals: [],
|
|
1028
|
-
total: 0,
|
|
1029
|
-
page,
|
|
1030
|
-
perPage,
|
|
1031
|
-
hasMore: false
|
|
1032
|
-
};
|
|
1033
|
-
}
|
|
1034
|
-
let filteredData = results.data;
|
|
1035
|
-
if (type) {
|
|
1036
|
-
filteredData = filteredData.filter((evalRecord) => {
|
|
1037
|
-
try {
|
|
1038
|
-
const testInfo = evalRecord.test_info && typeof evalRecord.test_info === "string" ? JSON.parse(evalRecord.test_info) : void 0;
|
|
1039
|
-
if (type === "test" && !testInfo) {
|
|
1040
|
-
return false;
|
|
1041
|
-
}
|
|
1042
|
-
if (type === "live" && testInfo) {
|
|
1043
|
-
return false;
|
|
1044
|
-
}
|
|
1045
|
-
} catch (e) {
|
|
1046
|
-
this.logger.warn("Failed to parse test_info during filtering", { record: evalRecord, error: e });
|
|
1047
|
-
}
|
|
1048
|
-
return true;
|
|
1049
|
-
});
|
|
1050
|
-
}
|
|
1051
|
-
if (dateRange) {
|
|
1052
|
-
const fromDate = dateRange.start;
|
|
1053
|
-
const toDate = dateRange.end;
|
|
1054
|
-
filteredData = filteredData.filter((evalRecord) => {
|
|
1055
|
-
const recordDate = new Date(evalRecord.created_at);
|
|
1056
|
-
if (fromDate && recordDate < fromDate) {
|
|
1057
|
-
return false;
|
|
1058
|
-
}
|
|
1059
|
-
if (toDate && recordDate > toDate) {
|
|
1060
|
-
return false;
|
|
1061
|
-
}
|
|
1062
|
-
return true;
|
|
1063
|
-
});
|
|
1064
|
-
}
|
|
1065
|
-
const total = filteredData.length;
|
|
1066
|
-
const start = page * perPage;
|
|
1067
|
-
const end = start + perPage;
|
|
1068
|
-
const paginatedData = filteredData.slice(start, end);
|
|
1069
|
-
const evals = paginatedData.map((evalRecord) => {
|
|
1070
|
-
try {
|
|
1071
|
-
return {
|
|
1072
|
-
input: evalRecord.input,
|
|
1073
|
-
output: evalRecord.output,
|
|
1074
|
-
result: evalRecord.result && typeof evalRecord.result === "string" ? JSON.parse(evalRecord.result) : void 0,
|
|
1075
|
-
agentName: evalRecord.agent_name,
|
|
1076
|
-
createdAt: evalRecord.created_at,
|
|
1077
|
-
metricName: evalRecord.metric_name,
|
|
1078
|
-
instructions: evalRecord.instructions,
|
|
1079
|
-
runId: evalRecord.run_id,
|
|
1080
|
-
globalRunId: evalRecord.global_run_id,
|
|
1081
|
-
testInfo: evalRecord.test_info && typeof evalRecord.test_info === "string" ? JSON.parse(evalRecord.test_info) : void 0
|
|
1082
|
-
};
|
|
1083
|
-
} catch (parseError) {
|
|
1084
|
-
this.logger.error("Failed to parse eval record", { record: evalRecord, error: parseError });
|
|
1085
|
-
return {
|
|
1086
|
-
agentName: evalRecord.agent_name,
|
|
1087
|
-
createdAt: evalRecord.created_at,
|
|
1088
|
-
runId: evalRecord.run_id,
|
|
1089
|
-
globalRunId: evalRecord.global_run_id
|
|
1090
|
-
};
|
|
1091
|
-
}
|
|
1092
|
-
});
|
|
1093
|
-
const hasMore = end < total;
|
|
1094
|
-
return {
|
|
1095
|
-
evals,
|
|
1096
|
-
total,
|
|
1097
|
-
page,
|
|
1098
|
-
perPage,
|
|
1099
|
-
hasMore
|
|
1100
|
-
};
|
|
1101
|
-
} catch (error$1) {
|
|
1102
|
-
throw new error.MastraError(
|
|
1103
|
-
{
|
|
1104
|
-
id: "STORAGE_DYNAMODB_STORE_GET_EVALS_FAILED",
|
|
1105
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1106
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
1107
|
-
details: {
|
|
1108
|
-
agentName: agentName || "all",
|
|
1109
|
-
type: type || "all",
|
|
1110
|
-
page,
|
|
1111
|
-
perPage
|
|
1112
|
-
}
|
|
1113
|
-
},
|
|
1114
|
-
error$1
|
|
1115
|
-
);
|
|
1116
|
-
}
|
|
1117
|
-
}
|
|
1118
|
-
};
|
|
1119
938
|
var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
1120
939
|
service;
|
|
1121
940
|
constructor({ service }) {
|
|
@@ -1220,7 +1039,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1220
1039
|
resourceId: thread.resourceId,
|
|
1221
1040
|
title: threadData.title,
|
|
1222
1041
|
createdAt: thread.createdAt || now,
|
|
1223
|
-
updatedAt: now,
|
|
1042
|
+
updatedAt: thread.updatedAt || now,
|
|
1224
1043
|
metadata: thread.metadata
|
|
1225
1044
|
};
|
|
1226
1045
|
} catch (error$1) {
|
|
@@ -1372,10 +1191,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1372
1191
|
);
|
|
1373
1192
|
}
|
|
1374
1193
|
}
|
|
1375
|
-
async
|
|
1376
|
-
messageIds,
|
|
1377
|
-
format
|
|
1378
|
-
}) {
|
|
1194
|
+
async listMessagesById({ messageIds }) {
|
|
1379
1195
|
this.logger.debug("Getting messages by ID", { messageIds });
|
|
1380
1196
|
if (messageIds.length === 0) return [];
|
|
1381
1197
|
try {
|
|
@@ -1388,7 +1204,6 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1388
1204
|
(message, index, self) => index === self.findIndex((m) => m.id === message.id)
|
|
1389
1205
|
);
|
|
1390
1206
|
const list = new agent.MessageList().add(uniqueMessages, "memory");
|
|
1391
|
-
if (format === `v1`) return list.get.all.v1();
|
|
1392
1207
|
return list.get.all.v2();
|
|
1393
1208
|
} catch (error$1) {
|
|
1394
1209
|
throw new error.MastraError(
|
|
@@ -1402,6 +1217,150 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1402
1217
|
);
|
|
1403
1218
|
}
|
|
1404
1219
|
}
|
|
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
|
+
}
|
|
1405
1364
|
async saveMessages(args) {
|
|
1406
1365
|
const { messages, format = "v1" } = args;
|
|
1407
1366
|
this.logger.debug("Saving messages", { count: messages.length });
|
|
@@ -1857,7 +1816,6 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
|
|
|
1857
1816
|
[storage.TABLE_THREADS]: "thread",
|
|
1858
1817
|
[storage.TABLE_MESSAGES]: "message",
|
|
1859
1818
|
[storage.TABLE_WORKFLOW_SNAPSHOT]: "workflow_snapshot",
|
|
1860
|
-
[storage.TABLE_EVALS]: "eval",
|
|
1861
1819
|
[storage.TABLE_SCORERS]: "score",
|
|
1862
1820
|
[storage.TABLE_TRACES]: "trace",
|
|
1863
1821
|
[storage.TABLE_RESOURCES]: "resource",
|
|
@@ -2046,6 +2004,10 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
|
|
|
2046
2004
|
if (!item.id) throw new Error(`Missing required key 'id' for entity 'score'`);
|
|
2047
2005
|
key.id = item.id;
|
|
2048
2006
|
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;
|
|
2049
2011
|
default:
|
|
2050
2012
|
this.logger.warn(`Unknown entity type encountered during clearTable: ${entityName}`);
|
|
2051
2013
|
throw new Error(`Cannot construct delete key for unknown entity type: ${entityName}`);
|
|
@@ -2222,7 +2184,7 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2222
2184
|
input: typeof validatedScore.input === "string" ? validatedScore.input : JSON.stringify(validatedScore.input),
|
|
2223
2185
|
output: typeof validatedScore.output === "string" ? validatedScore.output : JSON.stringify(validatedScore.output),
|
|
2224
2186
|
additionalContext: typeof validatedScore.additionalContext === "string" ? validatedScore.additionalContext : JSON.stringify(validatedScore.additionalContext),
|
|
2225
|
-
|
|
2187
|
+
requestContext: typeof validatedScore.requestContext === "string" ? validatedScore.requestContext : JSON.stringify(validatedScore.requestContext),
|
|
2226
2188
|
entityType: validatedScore.entityType,
|
|
2227
2189
|
entityData: typeof validatedScore.entity === "string" ? validatedScore.entity : JSON.stringify(validatedScore.entity),
|
|
2228
2190
|
entityId: validatedScore.entityId,
|
|
@@ -2419,239 +2381,6 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2419
2381
|
}
|
|
2420
2382
|
}
|
|
2421
2383
|
};
|
|
2422
|
-
var TracesStorageDynamoDB = class extends storage.TracesStorage {
|
|
2423
|
-
service;
|
|
2424
|
-
operations;
|
|
2425
|
-
constructor({ service, operations }) {
|
|
2426
|
-
super();
|
|
2427
|
-
this.service = service;
|
|
2428
|
-
this.operations = operations;
|
|
2429
|
-
}
|
|
2430
|
-
// Trace operations
|
|
2431
|
-
async getTraces(args) {
|
|
2432
|
-
const { name, scope, page, perPage } = args;
|
|
2433
|
-
this.logger.debug("Getting traces", { name, scope, page, perPage });
|
|
2434
|
-
try {
|
|
2435
|
-
let query;
|
|
2436
|
-
if (name) {
|
|
2437
|
-
query = this.service.entities.trace.query.byName({ entity: "trace", name });
|
|
2438
|
-
} else if (scope) {
|
|
2439
|
-
query = this.service.entities.trace.query.byScope({ entity: "trace", scope });
|
|
2440
|
-
} else {
|
|
2441
|
-
this.logger.warn("Performing a scan operation on traces - consider using a more specific query");
|
|
2442
|
-
query = this.service.entities.trace.scan;
|
|
2443
|
-
}
|
|
2444
|
-
let items = [];
|
|
2445
|
-
let cursor = null;
|
|
2446
|
-
let pagesFetched = 0;
|
|
2447
|
-
const startPage = page > 0 ? page : 1;
|
|
2448
|
-
do {
|
|
2449
|
-
const results = await query.go({ cursor, limit: perPage });
|
|
2450
|
-
pagesFetched++;
|
|
2451
|
-
if (pagesFetched === startPage) {
|
|
2452
|
-
items = results.data;
|
|
2453
|
-
break;
|
|
2454
|
-
}
|
|
2455
|
-
cursor = results.cursor;
|
|
2456
|
-
if (!cursor && results.data.length > 0 && pagesFetched < startPage) {
|
|
2457
|
-
break;
|
|
2458
|
-
}
|
|
2459
|
-
} while (cursor && pagesFetched < startPage);
|
|
2460
|
-
return items;
|
|
2461
|
-
} catch (error$1) {
|
|
2462
|
-
throw new error.MastraError(
|
|
2463
|
-
{
|
|
2464
|
-
id: "STORAGE_DYNAMODB_STORE_GET_TRACES_FAILED",
|
|
2465
|
-
domain: error.ErrorDomain.STORAGE,
|
|
2466
|
-
category: error.ErrorCategory.THIRD_PARTY
|
|
2467
|
-
},
|
|
2468
|
-
error$1
|
|
2469
|
-
);
|
|
2470
|
-
}
|
|
2471
|
-
}
|
|
2472
|
-
async batchTraceInsert({ records }) {
|
|
2473
|
-
this.logger.debug("Batch inserting traces", { count: records.length });
|
|
2474
|
-
if (!records.length) {
|
|
2475
|
-
return;
|
|
2476
|
-
}
|
|
2477
|
-
try {
|
|
2478
|
-
const recordsToSave = records.map((rec) => ({ entity: "trace", ...rec }));
|
|
2479
|
-
await this.operations.batchInsert({
|
|
2480
|
-
tableName: storage.TABLE_TRACES,
|
|
2481
|
-
records: recordsToSave
|
|
2482
|
-
// Pass records with 'entity' included
|
|
2483
|
-
});
|
|
2484
|
-
} catch (error$1) {
|
|
2485
|
-
throw new error.MastraError(
|
|
2486
|
-
{
|
|
2487
|
-
id: "STORAGE_DYNAMODB_STORE_BATCH_TRACE_INSERT_FAILED",
|
|
2488
|
-
domain: error.ErrorDomain.STORAGE,
|
|
2489
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
2490
|
-
details: { count: records.length }
|
|
2491
|
-
},
|
|
2492
|
-
error$1
|
|
2493
|
-
);
|
|
2494
|
-
}
|
|
2495
|
-
}
|
|
2496
|
-
async getTracesPaginated(args) {
|
|
2497
|
-
const { name, scope, page = 0, perPage = 100, attributes, filters, dateRange } = args;
|
|
2498
|
-
this.logger.debug("Getting traces with pagination", { name, scope, page, perPage, attributes, filters, dateRange });
|
|
2499
|
-
try {
|
|
2500
|
-
let query;
|
|
2501
|
-
if (name) {
|
|
2502
|
-
query = this.service.entities.trace.query.byName({ entity: "trace", name });
|
|
2503
|
-
} else if (scope) {
|
|
2504
|
-
query = this.service.entities.trace.query.byScope({ entity: "trace", scope });
|
|
2505
|
-
} else {
|
|
2506
|
-
this.logger.warn("Performing a scan operation on traces - consider using a more specific query");
|
|
2507
|
-
query = this.service.entities.trace.scan;
|
|
2508
|
-
}
|
|
2509
|
-
const results = await query.go({
|
|
2510
|
-
order: "desc",
|
|
2511
|
-
pages: "all"
|
|
2512
|
-
// Get all pages to apply filtering and pagination
|
|
2513
|
-
});
|
|
2514
|
-
if (!results.data.length) {
|
|
2515
|
-
return {
|
|
2516
|
-
traces: [],
|
|
2517
|
-
total: 0,
|
|
2518
|
-
page,
|
|
2519
|
-
perPage,
|
|
2520
|
-
hasMore: false
|
|
2521
|
-
};
|
|
2522
|
-
}
|
|
2523
|
-
let filteredData = results.data;
|
|
2524
|
-
if (attributes) {
|
|
2525
|
-
filteredData = filteredData.filter((item) => {
|
|
2526
|
-
try {
|
|
2527
|
-
let itemAttributes = {};
|
|
2528
|
-
if (item.attributes) {
|
|
2529
|
-
if (typeof item.attributes === "string") {
|
|
2530
|
-
if (item.attributes === "[object Object]") {
|
|
2531
|
-
itemAttributes = {};
|
|
2532
|
-
} else {
|
|
2533
|
-
try {
|
|
2534
|
-
itemAttributes = JSON.parse(item.attributes);
|
|
2535
|
-
} catch {
|
|
2536
|
-
itemAttributes = {};
|
|
2537
|
-
}
|
|
2538
|
-
}
|
|
2539
|
-
} else if (typeof item.attributes === "object") {
|
|
2540
|
-
itemAttributes = item.attributes;
|
|
2541
|
-
}
|
|
2542
|
-
}
|
|
2543
|
-
return Object.entries(attributes).every(([key, value]) => itemAttributes[key] === value);
|
|
2544
|
-
} catch (e) {
|
|
2545
|
-
this.logger.warn("Failed to parse attributes during filtering", { item, error: e });
|
|
2546
|
-
return false;
|
|
2547
|
-
}
|
|
2548
|
-
});
|
|
2549
|
-
}
|
|
2550
|
-
if (dateRange?.start) {
|
|
2551
|
-
filteredData = filteredData.filter((item) => {
|
|
2552
|
-
const itemDate = new Date(item.createdAt);
|
|
2553
|
-
return itemDate >= dateRange.start;
|
|
2554
|
-
});
|
|
2555
|
-
}
|
|
2556
|
-
if (dateRange?.end) {
|
|
2557
|
-
filteredData = filteredData.filter((item) => {
|
|
2558
|
-
const itemDate = new Date(item.createdAt);
|
|
2559
|
-
return itemDate <= dateRange.end;
|
|
2560
|
-
});
|
|
2561
|
-
}
|
|
2562
|
-
const total = filteredData.length;
|
|
2563
|
-
const start = page * perPage;
|
|
2564
|
-
const end = start + perPage;
|
|
2565
|
-
const paginatedData = filteredData.slice(start, end);
|
|
2566
|
-
const traces = paginatedData.map((item) => {
|
|
2567
|
-
let attributes2;
|
|
2568
|
-
if (item.attributes) {
|
|
2569
|
-
if (typeof item.attributes === "string") {
|
|
2570
|
-
if (item.attributes === "[object Object]") {
|
|
2571
|
-
attributes2 = void 0;
|
|
2572
|
-
} else {
|
|
2573
|
-
try {
|
|
2574
|
-
attributes2 = JSON.parse(item.attributes);
|
|
2575
|
-
} catch {
|
|
2576
|
-
attributes2 = void 0;
|
|
2577
|
-
}
|
|
2578
|
-
}
|
|
2579
|
-
} else if (typeof item.attributes === "object") {
|
|
2580
|
-
attributes2 = item.attributes;
|
|
2581
|
-
}
|
|
2582
|
-
}
|
|
2583
|
-
let status;
|
|
2584
|
-
if (item.status) {
|
|
2585
|
-
if (typeof item.status === "string") {
|
|
2586
|
-
try {
|
|
2587
|
-
status = JSON.parse(item.status);
|
|
2588
|
-
} catch {
|
|
2589
|
-
status = void 0;
|
|
2590
|
-
}
|
|
2591
|
-
} else if (typeof item.status === "object") {
|
|
2592
|
-
status = item.status;
|
|
2593
|
-
}
|
|
2594
|
-
}
|
|
2595
|
-
let events;
|
|
2596
|
-
if (item.events) {
|
|
2597
|
-
if (typeof item.events === "string") {
|
|
2598
|
-
try {
|
|
2599
|
-
events = JSON.parse(item.events);
|
|
2600
|
-
} catch {
|
|
2601
|
-
events = void 0;
|
|
2602
|
-
}
|
|
2603
|
-
} else if (Array.isArray(item.events)) {
|
|
2604
|
-
events = item.events;
|
|
2605
|
-
}
|
|
2606
|
-
}
|
|
2607
|
-
let links;
|
|
2608
|
-
if (item.links) {
|
|
2609
|
-
if (typeof item.links === "string") {
|
|
2610
|
-
try {
|
|
2611
|
-
links = JSON.parse(item.links);
|
|
2612
|
-
} catch {
|
|
2613
|
-
links = void 0;
|
|
2614
|
-
}
|
|
2615
|
-
} else if (Array.isArray(item.links)) {
|
|
2616
|
-
links = item.links;
|
|
2617
|
-
}
|
|
2618
|
-
}
|
|
2619
|
-
return {
|
|
2620
|
-
id: item.id,
|
|
2621
|
-
parentSpanId: item.parentSpanId,
|
|
2622
|
-
name: item.name,
|
|
2623
|
-
traceId: item.traceId,
|
|
2624
|
-
scope: item.scope,
|
|
2625
|
-
kind: item.kind,
|
|
2626
|
-
attributes: attributes2,
|
|
2627
|
-
status,
|
|
2628
|
-
events,
|
|
2629
|
-
links,
|
|
2630
|
-
other: item.other,
|
|
2631
|
-
startTime: item.startTime,
|
|
2632
|
-
endTime: item.endTime,
|
|
2633
|
-
createdAt: item.createdAt
|
|
2634
|
-
};
|
|
2635
|
-
});
|
|
2636
|
-
return {
|
|
2637
|
-
traces,
|
|
2638
|
-
total,
|
|
2639
|
-
page,
|
|
2640
|
-
perPage,
|
|
2641
|
-
hasMore: end < total
|
|
2642
|
-
};
|
|
2643
|
-
} catch (error$1) {
|
|
2644
|
-
throw new error.MastraError(
|
|
2645
|
-
{
|
|
2646
|
-
id: "STORAGE_DYNAMODB_STORE_GET_TRACES_PAGINATED_FAILED",
|
|
2647
|
-
domain: error.ErrorDomain.STORAGE,
|
|
2648
|
-
category: error.ErrorCategory.THIRD_PARTY
|
|
2649
|
-
},
|
|
2650
|
-
error$1
|
|
2651
|
-
);
|
|
2652
|
-
}
|
|
2653
|
-
}
|
|
2654
|
-
};
|
|
2655
2384
|
function formatWorkflowRun(snapshotData) {
|
|
2656
2385
|
return {
|
|
2657
2386
|
workflowName: snapshotData.workflow_name,
|
|
@@ -2673,7 +2402,7 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
|
|
|
2673
2402
|
// runId,
|
|
2674
2403
|
// stepId,
|
|
2675
2404
|
// result,
|
|
2676
|
-
//
|
|
2405
|
+
// requestContext,
|
|
2677
2406
|
}) {
|
|
2678
2407
|
throw new Error("Method not implemented.");
|
|
2679
2408
|
}
|
|
@@ -2746,7 +2475,7 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
|
|
|
2746
2475
|
);
|
|
2747
2476
|
}
|
|
2748
2477
|
}
|
|
2749
|
-
async
|
|
2478
|
+
async listWorkflowRuns(args) {
|
|
2750
2479
|
this.logger.debug("Getting workflow runs", { args });
|
|
2751
2480
|
try {
|
|
2752
2481
|
const limit = args?.limit || 10;
|
|
@@ -2902,14 +2631,11 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2902
2631
|
tableName: this.tableName,
|
|
2903
2632
|
client: this.client
|
|
2904
2633
|
});
|
|
2905
|
-
const traces = new TracesStorageDynamoDB({ service: this.service, operations });
|
|
2906
2634
|
const workflows = new WorkflowStorageDynamoDB({ service: this.service });
|
|
2907
2635
|
const memory = new MemoryStorageDynamoDB({ service: this.service });
|
|
2908
2636
|
const scores = new ScoresStorageDynamoDB({ service: this.service });
|
|
2909
2637
|
this.stores = {
|
|
2910
2638
|
operations,
|
|
2911
|
-
legacyEvals: new LegacyEvalsDynamoDB({ service: this.service, tableName: this.tableName }),
|
|
2912
|
-
traces,
|
|
2913
2639
|
workflows,
|
|
2914
2640
|
memory,
|
|
2915
2641
|
scores
|
|
@@ -3051,12 +2777,6 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
3051
2777
|
}) {
|
|
3052
2778
|
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
|
|
3053
2779
|
}
|
|
3054
|
-
async getMessagesById({
|
|
3055
|
-
messageIds,
|
|
3056
|
-
format
|
|
3057
|
-
}) {
|
|
3058
|
-
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
3059
|
-
}
|
|
3060
2780
|
async saveMessages(args) {
|
|
3061
2781
|
return this.stores.memory.saveMessages(args);
|
|
3062
2782
|
}
|
|
@@ -3069,25 +2789,15 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
3069
2789
|
async updateMessages(_args) {
|
|
3070
2790
|
return this.stores.memory.updateMessages(_args);
|
|
3071
2791
|
}
|
|
3072
|
-
// Trace operations
|
|
3073
|
-
async getTraces(args) {
|
|
3074
|
-
return this.stores.traces.getTraces(args);
|
|
3075
|
-
}
|
|
3076
|
-
async batchTraceInsert({ records }) {
|
|
3077
|
-
return this.stores.traces.batchTraceInsert({ records });
|
|
3078
|
-
}
|
|
3079
|
-
async getTracesPaginated(_args) {
|
|
3080
|
-
return this.stores.traces.getTracesPaginated(_args);
|
|
3081
|
-
}
|
|
3082
2792
|
// Workflow operations
|
|
3083
2793
|
async updateWorkflowResults({
|
|
3084
2794
|
workflowName,
|
|
3085
2795
|
runId,
|
|
3086
2796
|
stepId,
|
|
3087
2797
|
result,
|
|
3088
|
-
|
|
2798
|
+
requestContext
|
|
3089
2799
|
}) {
|
|
3090
|
-
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result,
|
|
2800
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, requestContext });
|
|
3091
2801
|
}
|
|
3092
2802
|
async updateWorkflowState({
|
|
3093
2803
|
workflowName,
|
|
@@ -3110,8 +2820,8 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
3110
2820
|
}) {
|
|
3111
2821
|
return this.stores.workflows.loadWorkflowSnapshot({ workflowName, runId });
|
|
3112
2822
|
}
|
|
3113
|
-
async
|
|
3114
|
-
return this.stores.workflows.
|
|
2823
|
+
async listWorkflowRuns(args) {
|
|
2824
|
+
return this.stores.workflows.listWorkflowRuns(args);
|
|
3115
2825
|
}
|
|
3116
2826
|
async getWorkflowRunById(args) {
|
|
3117
2827
|
return this.stores.workflows.getWorkflowRunById(args);
|
|
@@ -3129,13 +2839,6 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
3129
2839
|
}) {
|
|
3130
2840
|
return this.stores.memory.updateResource({ resourceId, workingMemory, metadata });
|
|
3131
2841
|
}
|
|
3132
|
-
// Eval operations
|
|
3133
|
-
async getEvalsByAgentName(agentName, type) {
|
|
3134
|
-
return this.stores.legacyEvals.getEvalsByAgentName(agentName, type);
|
|
3135
|
-
}
|
|
3136
|
-
async getEvals(options) {
|
|
3137
|
-
return this.stores.legacyEvals.getEvals(options);
|
|
3138
|
-
}
|
|
3139
2842
|
/**
|
|
3140
2843
|
* Closes the DynamoDB client connection and cleans up resources.
|
|
3141
2844
|
* Should be called when the store is no longer needed, e.g., at the end of tests or application shutdown.
|