@mastra/dynamodb 0.0.0-vector-extension-schema-20250922130418 → 0.0.0-vnext-20251104230439
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 +265 -3
- package/dist/entities/index.d.ts +16 -1
- package/dist/entities/index.d.ts.map +1 -1
- package/dist/entities/score.d.ts +16 -1
- package/dist/entities/score.d.ts.map +1 -1
- package/dist/index.cjs +327 -648
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +328 -649
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +16 -41
- 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 +12 -4
- package/dist/storage/domains/score/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 +31 -75
- 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
|
@@ -6,6 +6,7 @@ var error = require('@mastra/core/error');
|
|
|
6
6
|
var storage = require('@mastra/core/storage');
|
|
7
7
|
var electrodb = require('electrodb');
|
|
8
8
|
var agent = require('@mastra/core/agent');
|
|
9
|
+
var evals = require('@mastra/core/evals');
|
|
9
10
|
|
|
10
11
|
// src/storage/index.ts
|
|
11
12
|
|
|
@@ -372,6 +373,10 @@ var scoreEntity = new electrodb.Entity({
|
|
|
372
373
|
type: "string",
|
|
373
374
|
required: false
|
|
374
375
|
},
|
|
376
|
+
spanId: {
|
|
377
|
+
type: "string",
|
|
378
|
+
required: false
|
|
379
|
+
},
|
|
375
380
|
runId: {
|
|
376
381
|
type: "string",
|
|
377
382
|
required: true
|
|
@@ -559,7 +564,7 @@ var scoreEntity = new electrodb.Entity({
|
|
|
559
564
|
return value;
|
|
560
565
|
}
|
|
561
566
|
},
|
|
562
|
-
|
|
567
|
+
requestContext: {
|
|
563
568
|
type: "string",
|
|
564
569
|
required: false,
|
|
565
570
|
set: (value) => {
|
|
@@ -658,6 +663,11 @@ var scoreEntity = new electrodb.Entity({
|
|
|
658
663
|
index: "gsi6",
|
|
659
664
|
pk: { field: "gsi6pk", composite: ["entity", "threadId"] },
|
|
660
665
|
sk: { field: "gsi6sk", composite: ["createdAt"] }
|
|
666
|
+
},
|
|
667
|
+
bySpan: {
|
|
668
|
+
index: "gsi7",
|
|
669
|
+
pk: { field: "gsi7pk", composite: ["entity", "traceId", "spanId"] },
|
|
670
|
+
sk: { field: "gsi7sk", composite: ["createdAt"] }
|
|
661
671
|
}
|
|
662
672
|
}
|
|
663
673
|
});
|
|
@@ -925,187 +935,6 @@ function getElectroDbService(client, tableName) {
|
|
|
925
935
|
}
|
|
926
936
|
);
|
|
927
937
|
}
|
|
928
|
-
var LegacyEvalsDynamoDB = class extends storage.LegacyEvalsStorage {
|
|
929
|
-
service;
|
|
930
|
-
tableName;
|
|
931
|
-
constructor({ service, tableName }) {
|
|
932
|
-
super();
|
|
933
|
-
this.service = service;
|
|
934
|
-
this.tableName = tableName;
|
|
935
|
-
}
|
|
936
|
-
// Eval operations
|
|
937
|
-
async getEvalsByAgentName(agentName, type) {
|
|
938
|
-
this.logger.debug("Getting evals for agent", { agentName, type });
|
|
939
|
-
try {
|
|
940
|
-
const query = this.service.entities.eval.query.byAgent({ entity: "eval", agent_name: agentName });
|
|
941
|
-
const results = await query.go({ order: "desc", limit: 100 });
|
|
942
|
-
if (!results.data.length) {
|
|
943
|
-
return [];
|
|
944
|
-
}
|
|
945
|
-
let filteredData = results.data;
|
|
946
|
-
if (type) {
|
|
947
|
-
filteredData = filteredData.filter((evalRecord) => {
|
|
948
|
-
try {
|
|
949
|
-
const testInfo = evalRecord.test_info && typeof evalRecord.test_info === "string" ? JSON.parse(evalRecord.test_info) : void 0;
|
|
950
|
-
if (type === "test" && !testInfo) {
|
|
951
|
-
return false;
|
|
952
|
-
}
|
|
953
|
-
if (type === "live" && testInfo) {
|
|
954
|
-
return false;
|
|
955
|
-
}
|
|
956
|
-
} catch (e) {
|
|
957
|
-
this.logger.warn("Failed to parse test_info during filtering", { record: evalRecord, error: e });
|
|
958
|
-
}
|
|
959
|
-
return true;
|
|
960
|
-
});
|
|
961
|
-
}
|
|
962
|
-
return filteredData.map((evalRecord) => {
|
|
963
|
-
try {
|
|
964
|
-
return {
|
|
965
|
-
input: evalRecord.input,
|
|
966
|
-
output: evalRecord.output,
|
|
967
|
-
// Safely parse result and test_info
|
|
968
|
-
result: evalRecord.result && typeof evalRecord.result === "string" ? JSON.parse(evalRecord.result) : void 0,
|
|
969
|
-
agentName: evalRecord.agent_name,
|
|
970
|
-
createdAt: evalRecord.created_at,
|
|
971
|
-
// Keep as string from DDB?
|
|
972
|
-
metricName: evalRecord.metric_name,
|
|
973
|
-
instructions: evalRecord.instructions,
|
|
974
|
-
runId: evalRecord.run_id,
|
|
975
|
-
globalRunId: evalRecord.global_run_id,
|
|
976
|
-
testInfo: evalRecord.test_info && typeof evalRecord.test_info === "string" ? JSON.parse(evalRecord.test_info) : void 0
|
|
977
|
-
};
|
|
978
|
-
} catch (parseError) {
|
|
979
|
-
this.logger.error("Failed to parse eval record", { record: evalRecord, error: parseError });
|
|
980
|
-
return {
|
|
981
|
-
agentName: evalRecord.agent_name,
|
|
982
|
-
createdAt: evalRecord.created_at,
|
|
983
|
-
runId: evalRecord.run_id,
|
|
984
|
-
globalRunId: evalRecord.global_run_id
|
|
985
|
-
};
|
|
986
|
-
}
|
|
987
|
-
});
|
|
988
|
-
} catch (error$1) {
|
|
989
|
-
throw new error.MastraError(
|
|
990
|
-
{
|
|
991
|
-
id: "STORAGE_DYNAMODB_STORE_GET_EVALS_BY_AGENT_NAME_FAILED",
|
|
992
|
-
domain: error.ErrorDomain.STORAGE,
|
|
993
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
994
|
-
details: { agentName }
|
|
995
|
-
},
|
|
996
|
-
error$1
|
|
997
|
-
);
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
async getEvals(options = {}) {
|
|
1001
|
-
const { agentName, type, page = 0, perPage = 100, dateRange } = options;
|
|
1002
|
-
this.logger.debug("Getting evals with pagination", { agentName, type, page, perPage, dateRange });
|
|
1003
|
-
try {
|
|
1004
|
-
let query;
|
|
1005
|
-
if (agentName) {
|
|
1006
|
-
query = this.service.entities.eval.query.byAgent({ entity: "eval", agent_name: agentName });
|
|
1007
|
-
} else {
|
|
1008
|
-
query = this.service.entities.eval.query.byEntity({ entity: "eval" });
|
|
1009
|
-
}
|
|
1010
|
-
const results = await query.go({
|
|
1011
|
-
order: "desc",
|
|
1012
|
-
pages: "all"
|
|
1013
|
-
// Get all pages to apply filtering and pagination
|
|
1014
|
-
});
|
|
1015
|
-
if (!results.data.length) {
|
|
1016
|
-
return {
|
|
1017
|
-
evals: [],
|
|
1018
|
-
total: 0,
|
|
1019
|
-
page,
|
|
1020
|
-
perPage,
|
|
1021
|
-
hasMore: false
|
|
1022
|
-
};
|
|
1023
|
-
}
|
|
1024
|
-
let filteredData = results.data;
|
|
1025
|
-
if (type) {
|
|
1026
|
-
filteredData = filteredData.filter((evalRecord) => {
|
|
1027
|
-
try {
|
|
1028
|
-
const testInfo = evalRecord.test_info && typeof evalRecord.test_info === "string" ? JSON.parse(evalRecord.test_info) : void 0;
|
|
1029
|
-
if (type === "test" && !testInfo) {
|
|
1030
|
-
return false;
|
|
1031
|
-
}
|
|
1032
|
-
if (type === "live" && testInfo) {
|
|
1033
|
-
return false;
|
|
1034
|
-
}
|
|
1035
|
-
} catch (e) {
|
|
1036
|
-
this.logger.warn("Failed to parse test_info during filtering", { record: evalRecord, error: e });
|
|
1037
|
-
}
|
|
1038
|
-
return true;
|
|
1039
|
-
});
|
|
1040
|
-
}
|
|
1041
|
-
if (dateRange) {
|
|
1042
|
-
const fromDate = dateRange.start;
|
|
1043
|
-
const toDate = dateRange.end;
|
|
1044
|
-
filteredData = filteredData.filter((evalRecord) => {
|
|
1045
|
-
const recordDate = new Date(evalRecord.created_at);
|
|
1046
|
-
if (fromDate && recordDate < fromDate) {
|
|
1047
|
-
return false;
|
|
1048
|
-
}
|
|
1049
|
-
if (toDate && recordDate > toDate) {
|
|
1050
|
-
return false;
|
|
1051
|
-
}
|
|
1052
|
-
return true;
|
|
1053
|
-
});
|
|
1054
|
-
}
|
|
1055
|
-
const total = filteredData.length;
|
|
1056
|
-
const start = page * perPage;
|
|
1057
|
-
const end = start + perPage;
|
|
1058
|
-
const paginatedData = filteredData.slice(start, end);
|
|
1059
|
-
const evals = paginatedData.map((evalRecord) => {
|
|
1060
|
-
try {
|
|
1061
|
-
return {
|
|
1062
|
-
input: evalRecord.input,
|
|
1063
|
-
output: evalRecord.output,
|
|
1064
|
-
result: evalRecord.result && typeof evalRecord.result === "string" ? JSON.parse(evalRecord.result) : void 0,
|
|
1065
|
-
agentName: evalRecord.agent_name,
|
|
1066
|
-
createdAt: evalRecord.created_at,
|
|
1067
|
-
metricName: evalRecord.metric_name,
|
|
1068
|
-
instructions: evalRecord.instructions,
|
|
1069
|
-
runId: evalRecord.run_id,
|
|
1070
|
-
globalRunId: evalRecord.global_run_id,
|
|
1071
|
-
testInfo: evalRecord.test_info && typeof evalRecord.test_info === "string" ? JSON.parse(evalRecord.test_info) : void 0
|
|
1072
|
-
};
|
|
1073
|
-
} catch (parseError) {
|
|
1074
|
-
this.logger.error("Failed to parse eval record", { record: evalRecord, error: parseError });
|
|
1075
|
-
return {
|
|
1076
|
-
agentName: evalRecord.agent_name,
|
|
1077
|
-
createdAt: evalRecord.created_at,
|
|
1078
|
-
runId: evalRecord.run_id,
|
|
1079
|
-
globalRunId: evalRecord.global_run_id
|
|
1080
|
-
};
|
|
1081
|
-
}
|
|
1082
|
-
});
|
|
1083
|
-
const hasMore = end < total;
|
|
1084
|
-
return {
|
|
1085
|
-
evals,
|
|
1086
|
-
total,
|
|
1087
|
-
page,
|
|
1088
|
-
perPage,
|
|
1089
|
-
hasMore
|
|
1090
|
-
};
|
|
1091
|
-
} catch (error$1) {
|
|
1092
|
-
throw new error.MastraError(
|
|
1093
|
-
{
|
|
1094
|
-
id: "STORAGE_DYNAMODB_STORE_GET_EVALS_FAILED",
|
|
1095
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1096
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
1097
|
-
details: {
|
|
1098
|
-
agentName: agentName || "all",
|
|
1099
|
-
type: type || "all",
|
|
1100
|
-
page,
|
|
1101
|
-
perPage
|
|
1102
|
-
}
|
|
1103
|
-
},
|
|
1104
|
-
error$1
|
|
1105
|
-
);
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
};
|
|
1109
938
|
var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
1110
939
|
service;
|
|
1111
940
|
constructor({ service }) {
|
|
@@ -1124,17 +953,17 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1124
953
|
};
|
|
1125
954
|
}
|
|
1126
955
|
// Helper function to transform and sort threads
|
|
1127
|
-
transformAndSortThreads(rawThreads,
|
|
956
|
+
transformAndSortThreads(rawThreads, field, direction) {
|
|
1128
957
|
return rawThreads.map((data) => ({
|
|
1129
958
|
...data,
|
|
1130
959
|
// Convert date strings back to Date objects for consistency
|
|
1131
960
|
createdAt: typeof data.createdAt === "string" ? new Date(data.createdAt) : data.createdAt,
|
|
1132
961
|
updatedAt: typeof data.updatedAt === "string" ? new Date(data.updatedAt) : data.updatedAt
|
|
1133
962
|
})).sort((a, b) => {
|
|
1134
|
-
const fieldA =
|
|
1135
|
-
const fieldB =
|
|
963
|
+
const fieldA = field === "createdAt" ? a.createdAt : a.updatedAt;
|
|
964
|
+
const fieldB = field === "createdAt" ? b.createdAt : b.updatedAt;
|
|
1136
965
|
const comparison = fieldA.getTime() - fieldB.getTime();
|
|
1137
|
-
return
|
|
966
|
+
return direction === "DESC" ? -comparison : comparison;
|
|
1138
967
|
});
|
|
1139
968
|
}
|
|
1140
969
|
async getThreadById({ threadId }) {
|
|
@@ -1165,32 +994,6 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1165
994
|
);
|
|
1166
995
|
}
|
|
1167
996
|
}
|
|
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 });
|
|
1176
|
-
try {
|
|
1177
|
-
const result = await this.service.entities.thread.query.byResource({ entity: "thread", resourceId }).go();
|
|
1178
|
-
if (!result.data.length) {
|
|
1179
|
-
return [];
|
|
1180
|
-
}
|
|
1181
|
-
return this.transformAndSortThreads(result.data, orderBy, sortDirection);
|
|
1182
|
-
} catch (error$1) {
|
|
1183
|
-
throw new error.MastraError(
|
|
1184
|
-
{
|
|
1185
|
-
id: "STORAGE_DYNAMODB_STORE_GET_THREADS_BY_RESOURCE_ID_FAILED",
|
|
1186
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1187
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
1188
|
-
details: { resourceId }
|
|
1189
|
-
},
|
|
1190
|
-
error$1
|
|
1191
|
-
);
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
997
|
async saveThread({ thread }) {
|
|
1195
998
|
this.logger.debug("Saving thread", { threadId: thread.id });
|
|
1196
999
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -1210,7 +1013,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1210
1013
|
resourceId: thread.resourceId,
|
|
1211
1014
|
title: threadData.title,
|
|
1212
1015
|
createdAt: thread.createdAt || now,
|
|
1213
|
-
updatedAt: now,
|
|
1016
|
+
updatedAt: thread.updatedAt || now,
|
|
1214
1017
|
metadata: thread.metadata
|
|
1215
1018
|
};
|
|
1216
1019
|
} catch (error$1) {
|
|
@@ -1270,7 +1073,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1270
1073
|
async deleteThread({ threadId }) {
|
|
1271
1074
|
this.logger.debug("Deleting thread", { threadId });
|
|
1272
1075
|
try {
|
|
1273
|
-
const messages = await this.getMessages({ threadId });
|
|
1076
|
+
const { messages } = await this.getMessages({ threadId });
|
|
1274
1077
|
if (messages.length > 0) {
|
|
1275
1078
|
const batchSize = 25;
|
|
1276
1079
|
for (let i = 0; i < messages.length; i += batchSize) {
|
|
@@ -1302,8 +1105,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1302
1105
|
async getMessages({
|
|
1303
1106
|
threadId,
|
|
1304
1107
|
resourceId,
|
|
1305
|
-
selectBy
|
|
1306
|
-
format
|
|
1108
|
+
selectBy
|
|
1307
1109
|
}) {
|
|
1308
1110
|
this.logger.debug("Getting messages", { threadId, selectBy });
|
|
1309
1111
|
try {
|
|
@@ -1347,9 +1149,11 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1347
1149
|
const uniqueMessages = messages.filter(
|
|
1348
1150
|
(message, index, self) => index === self.findIndex((m) => m.id === message.id)
|
|
1349
1151
|
);
|
|
1350
|
-
const list = new agent.MessageList({ threadId, resourceId }).add(
|
|
1351
|
-
|
|
1352
|
-
|
|
1152
|
+
const list = new agent.MessageList({ threadId, resourceId }).add(
|
|
1153
|
+
uniqueMessages,
|
|
1154
|
+
"memory"
|
|
1155
|
+
);
|
|
1156
|
+
return { messages: list.get.all.db() };
|
|
1353
1157
|
} catch (error$1) {
|
|
1354
1158
|
throw new error.MastraError(
|
|
1355
1159
|
{
|
|
@@ -1362,12 +1166,9 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1362
1166
|
);
|
|
1363
1167
|
}
|
|
1364
1168
|
}
|
|
1365
|
-
async
|
|
1366
|
-
messageIds,
|
|
1367
|
-
format
|
|
1368
|
-
}) {
|
|
1169
|
+
async listMessagesById({ messageIds }) {
|
|
1369
1170
|
this.logger.debug("Getting messages by ID", { messageIds });
|
|
1370
|
-
if (messageIds.length === 0) return [];
|
|
1171
|
+
if (messageIds.length === 0) return { messages: [] };
|
|
1371
1172
|
try {
|
|
1372
1173
|
const results = await Promise.all(
|
|
1373
1174
|
messageIds.map((id) => this.service.entities.message.query.primary({ entity: "message", id }).go())
|
|
@@ -1378,12 +1179,11 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1378
1179
|
(message, index, self) => index === self.findIndex((m) => m.id === message.id)
|
|
1379
1180
|
);
|
|
1380
1181
|
const list = new agent.MessageList().add(uniqueMessages, "memory");
|
|
1381
|
-
|
|
1382
|
-
return list.get.all.v2();
|
|
1182
|
+
return { messages: list.get.all.db() };
|
|
1383
1183
|
} catch (error$1) {
|
|
1384
1184
|
throw new error.MastraError(
|
|
1385
1185
|
{
|
|
1386
|
-
id: "
|
|
1186
|
+
id: "STORAGE_DYNAMODB_STORE_LIST_MESSAGES_BY_ID_FAILED",
|
|
1387
1187
|
domain: error.ErrorDomain.STORAGE,
|
|
1388
1188
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1389
1189
|
details: { messageIds: JSON.stringify(messageIds) }
|
|
@@ -1392,11 +1192,149 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1392
1192
|
);
|
|
1393
1193
|
}
|
|
1394
1194
|
}
|
|
1195
|
+
async listMessages(args) {
|
|
1196
|
+
const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
|
|
1197
|
+
if (!threadId.trim()) {
|
|
1198
|
+
throw new error.MastraError(
|
|
1199
|
+
{
|
|
1200
|
+
id: "STORAGE_DYNAMODB_LIST_MESSAGES_INVALID_THREAD_ID",
|
|
1201
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1202
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1203
|
+
details: { threadId }
|
|
1204
|
+
},
|
|
1205
|
+
new Error("threadId must be a non-empty string")
|
|
1206
|
+
);
|
|
1207
|
+
}
|
|
1208
|
+
const perPage = storage.normalizePerPage(perPageInput, 40);
|
|
1209
|
+
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
1210
|
+
try {
|
|
1211
|
+
if (page < 0) {
|
|
1212
|
+
throw new error.MastraError(
|
|
1213
|
+
{
|
|
1214
|
+
id: "STORAGE_DYNAMODB_LIST_MESSAGES_INVALID_PAGE",
|
|
1215
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1216
|
+
category: error.ErrorCategory.USER,
|
|
1217
|
+
details: { page }
|
|
1218
|
+
},
|
|
1219
|
+
new Error("page must be >= 0")
|
|
1220
|
+
);
|
|
1221
|
+
}
|
|
1222
|
+
const { field, direction } = this.parseOrderBy(orderBy);
|
|
1223
|
+
this.logger.debug("Getting messages with listMessages", {
|
|
1224
|
+
threadId,
|
|
1225
|
+
resourceId,
|
|
1226
|
+
perPageInput,
|
|
1227
|
+
offset,
|
|
1228
|
+
perPage,
|
|
1229
|
+
page,
|
|
1230
|
+
field,
|
|
1231
|
+
direction
|
|
1232
|
+
});
|
|
1233
|
+
const query = this.service.entities.message.query.byThread({ entity: "message", threadId });
|
|
1234
|
+
const results = await query.go();
|
|
1235
|
+
let allThreadMessages = results.data.map((data) => this.parseMessageData(data)).filter((msg) => "content" in msg && typeof msg.content === "object");
|
|
1236
|
+
if (resourceId) {
|
|
1237
|
+
allThreadMessages = allThreadMessages.filter((msg) => msg.resourceId === resourceId);
|
|
1238
|
+
}
|
|
1239
|
+
if (filter?.dateRange) {
|
|
1240
|
+
const dateRange = filter.dateRange;
|
|
1241
|
+
allThreadMessages = allThreadMessages.filter((msg) => {
|
|
1242
|
+
const createdAt = new Date(msg.createdAt).getTime();
|
|
1243
|
+
if (dateRange.start) {
|
|
1244
|
+
const startTime = dateRange.start instanceof Date ? dateRange.start.getTime() : new Date(dateRange.start).getTime();
|
|
1245
|
+
if (createdAt < startTime) return false;
|
|
1246
|
+
}
|
|
1247
|
+
if (dateRange.end) {
|
|
1248
|
+
const endTime = dateRange.end instanceof Date ? dateRange.end.getTime() : new Date(dateRange.end).getTime();
|
|
1249
|
+
if (createdAt > endTime) return false;
|
|
1250
|
+
}
|
|
1251
|
+
return true;
|
|
1252
|
+
});
|
|
1253
|
+
}
|
|
1254
|
+
allThreadMessages.sort((a, b) => {
|
|
1255
|
+
const aValue = field === "createdAt" ? new Date(a.createdAt).getTime() : a[field];
|
|
1256
|
+
const bValue = field === "createdAt" ? new Date(b.createdAt).getTime() : b[field];
|
|
1257
|
+
if (aValue === bValue) {
|
|
1258
|
+
return a.id.localeCompare(b.id);
|
|
1259
|
+
}
|
|
1260
|
+
return direction === "ASC" ? aValue - bValue : bValue - aValue;
|
|
1261
|
+
});
|
|
1262
|
+
const total = allThreadMessages.length;
|
|
1263
|
+
const paginatedMessages = allThreadMessages.slice(offset, offset + perPage);
|
|
1264
|
+
const paginatedCount = paginatedMessages.length;
|
|
1265
|
+
if (total === 0 && paginatedCount === 0 && (!include || include.length === 0)) {
|
|
1266
|
+
return {
|
|
1267
|
+
messages: [],
|
|
1268
|
+
total: 0,
|
|
1269
|
+
page,
|
|
1270
|
+
perPage: perPageForResponse,
|
|
1271
|
+
hasMore: false
|
|
1272
|
+
};
|
|
1273
|
+
}
|
|
1274
|
+
const messageIds = new Set(paginatedMessages.map((m) => m.id));
|
|
1275
|
+
let includeMessages = [];
|
|
1276
|
+
if (include && include.length > 0) {
|
|
1277
|
+
const selectBy = { include };
|
|
1278
|
+
includeMessages = await this._getIncludedMessages(threadId, selectBy);
|
|
1279
|
+
for (const includeMsg of includeMessages) {
|
|
1280
|
+
if (!messageIds.has(includeMsg.id)) {
|
|
1281
|
+
paginatedMessages.push(includeMsg);
|
|
1282
|
+
messageIds.add(includeMsg.id);
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
const list = new agent.MessageList().add(paginatedMessages, "memory");
|
|
1287
|
+
let finalMessages = list.get.all.db();
|
|
1288
|
+
finalMessages = finalMessages.sort((a, b) => {
|
|
1289
|
+
const aValue = field === "createdAt" ? new Date(a.createdAt).getTime() : a[field];
|
|
1290
|
+
const bValue = field === "createdAt" ? new Date(b.createdAt).getTime() : b[field];
|
|
1291
|
+
if (aValue === bValue) {
|
|
1292
|
+
return a.id.localeCompare(b.id);
|
|
1293
|
+
}
|
|
1294
|
+
return direction === "ASC" ? aValue - bValue : bValue - aValue;
|
|
1295
|
+
});
|
|
1296
|
+
const returnedThreadMessageIds = new Set(finalMessages.filter((m) => m.threadId === threadId).map((m) => m.id));
|
|
1297
|
+
const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
|
|
1298
|
+
let hasMore = false;
|
|
1299
|
+
if (perPageInput !== false && !allThreadMessagesReturned) {
|
|
1300
|
+
hasMore = offset + paginatedCount < total;
|
|
1301
|
+
}
|
|
1302
|
+
return {
|
|
1303
|
+
messages: finalMessages,
|
|
1304
|
+
total,
|
|
1305
|
+
page,
|
|
1306
|
+
perPage: perPageForResponse,
|
|
1307
|
+
hasMore
|
|
1308
|
+
};
|
|
1309
|
+
} catch (error$1) {
|
|
1310
|
+
const mastraError = new error.MastraError(
|
|
1311
|
+
{
|
|
1312
|
+
id: "STORAGE_DYNAMODB_STORE_LIST_MESSAGES_FAILED",
|
|
1313
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1314
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1315
|
+
details: {
|
|
1316
|
+
threadId,
|
|
1317
|
+
resourceId: resourceId ?? ""
|
|
1318
|
+
}
|
|
1319
|
+
},
|
|
1320
|
+
error$1
|
|
1321
|
+
);
|
|
1322
|
+
this.logger?.error?.(mastraError.toString());
|
|
1323
|
+
this.logger?.trackException?.(mastraError);
|
|
1324
|
+
return {
|
|
1325
|
+
messages: [],
|
|
1326
|
+
total: 0,
|
|
1327
|
+
page,
|
|
1328
|
+
perPage: perPageForResponse,
|
|
1329
|
+
hasMore: false
|
|
1330
|
+
};
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1395
1333
|
async saveMessages(args) {
|
|
1396
|
-
const { messages
|
|
1334
|
+
const { messages } = args;
|
|
1397
1335
|
this.logger.debug("Saving messages", { count: messages.length });
|
|
1398
1336
|
if (!messages.length) {
|
|
1399
|
-
return [];
|
|
1337
|
+
return { messages: [] };
|
|
1400
1338
|
}
|
|
1401
1339
|
const threadId = messages[0]?.threadId;
|
|
1402
1340
|
if (!threadId) {
|
|
@@ -1450,8 +1388,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1450
1388
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1451
1389
|
}).go();
|
|
1452
1390
|
const list = new agent.MessageList().add(messages, "memory");
|
|
1453
|
-
|
|
1454
|
-
return list.get.all.v2();
|
|
1391
|
+
return { messages: list.get.all.db() };
|
|
1455
1392
|
} catch (error$1) {
|
|
1456
1393
|
throw new error.MastraError(
|
|
1457
1394
|
{
|
|
@@ -1464,37 +1401,48 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1464
1401
|
);
|
|
1465
1402
|
}
|
|
1466
1403
|
}
|
|
1467
|
-
async
|
|
1468
|
-
const { resourceId, page = 0, perPage
|
|
1469
|
-
const
|
|
1470
|
-
|
|
1404
|
+
async listThreadsByResourceId(args) {
|
|
1405
|
+
const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
|
|
1406
|
+
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
1407
|
+
if (page < 0) {
|
|
1408
|
+
throw new error.MastraError(
|
|
1409
|
+
{
|
|
1410
|
+
id: "STORAGE_DYNAMODB_LIST_THREADS_BY_RESOURCE_ID_INVALID_PAGE",
|
|
1411
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1412
|
+
category: error.ErrorCategory.USER,
|
|
1413
|
+
details: { page }
|
|
1414
|
+
},
|
|
1415
|
+
new Error("page must be >= 0")
|
|
1416
|
+
);
|
|
1417
|
+
}
|
|
1418
|
+
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
1419
|
+
const { field, direction } = this.parseOrderBy(orderBy);
|
|
1471
1420
|
this.logger.debug("Getting threads by resource ID with pagination", {
|
|
1472
1421
|
resourceId,
|
|
1473
1422
|
page,
|
|
1474
1423
|
perPage,
|
|
1475
|
-
|
|
1476
|
-
|
|
1424
|
+
field,
|
|
1425
|
+
direction
|
|
1477
1426
|
});
|
|
1478
1427
|
try {
|
|
1479
1428
|
const query = this.service.entities.thread.query.byResource({ entity: "thread", resourceId });
|
|
1480
1429
|
const results = await query.go();
|
|
1481
|
-
const allThreads = this.transformAndSortThreads(results.data,
|
|
1482
|
-
const
|
|
1483
|
-
const
|
|
1484
|
-
const paginatedThreads = allThreads.slice(startIndex, endIndex);
|
|
1430
|
+
const allThreads = this.transformAndSortThreads(results.data, field, direction);
|
|
1431
|
+
const endIndex = offset + perPage;
|
|
1432
|
+
const paginatedThreads = allThreads.slice(offset, endIndex);
|
|
1485
1433
|
const total = allThreads.length;
|
|
1486
|
-
const hasMore =
|
|
1434
|
+
const hasMore = offset + perPage < total;
|
|
1487
1435
|
return {
|
|
1488
1436
|
threads: paginatedThreads,
|
|
1489
1437
|
total,
|
|
1490
1438
|
page,
|
|
1491
|
-
perPage,
|
|
1439
|
+
perPage: perPageForResponse,
|
|
1492
1440
|
hasMore
|
|
1493
1441
|
};
|
|
1494
1442
|
} catch (error$1) {
|
|
1495
1443
|
throw new error.MastraError(
|
|
1496
1444
|
{
|
|
1497
|
-
id: "
|
|
1445
|
+
id: "DYNAMODB_STORAGE_LIST_THREADS_BY_RESOURCE_ID_FAILED",
|
|
1498
1446
|
domain: error.ErrorDomain.STORAGE,
|
|
1499
1447
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1500
1448
|
details: { resourceId, page, perPage }
|
|
@@ -1503,84 +1451,6 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1503
1451
|
);
|
|
1504
1452
|
}
|
|
1505
1453
|
}
|
|
1506
|
-
async getMessagesPaginated(args) {
|
|
1507
|
-
const { threadId, resourceId, selectBy, format = "v1" } = args;
|
|
1508
|
-
const { page = 0, perPage = 40, dateRange } = selectBy?.pagination || {};
|
|
1509
|
-
const fromDate = dateRange?.start;
|
|
1510
|
-
const toDate = dateRange?.end;
|
|
1511
|
-
const limit = storage.resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
|
|
1512
|
-
this.logger.debug("Getting messages with pagination", { threadId, page, perPage, fromDate, toDate, limit });
|
|
1513
|
-
try {
|
|
1514
|
-
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
1515
|
-
let messages = [];
|
|
1516
|
-
if (selectBy?.include?.length) {
|
|
1517
|
-
const includeMessages = await this._getIncludedMessages(threadId, selectBy);
|
|
1518
|
-
if (includeMessages) {
|
|
1519
|
-
messages.push(...includeMessages);
|
|
1520
|
-
}
|
|
1521
|
-
}
|
|
1522
|
-
if (limit !== 0) {
|
|
1523
|
-
const query = this.service.entities.message.query.byThread({ entity: "message", threadId });
|
|
1524
|
-
let results;
|
|
1525
|
-
if (limit !== Number.MAX_SAFE_INTEGER && limit > 0) {
|
|
1526
|
-
results = await query.go({ limit, order: "desc" });
|
|
1527
|
-
results.data = results.data.reverse();
|
|
1528
|
-
} else {
|
|
1529
|
-
results = await query.go();
|
|
1530
|
-
}
|
|
1531
|
-
let allThreadMessages = results.data.map((data) => this.parseMessageData(data)).filter((msg) => "content" in msg);
|
|
1532
|
-
allThreadMessages.sort((a, b) => {
|
|
1533
|
-
const timeA = a.createdAt.getTime();
|
|
1534
|
-
const timeB = b.createdAt.getTime();
|
|
1535
|
-
if (timeA === timeB) {
|
|
1536
|
-
return a.id.localeCompare(b.id);
|
|
1537
|
-
}
|
|
1538
|
-
return timeA - timeB;
|
|
1539
|
-
});
|
|
1540
|
-
const excludeIds = messages.map((m) => m.id);
|
|
1541
|
-
if (excludeIds.length > 0) {
|
|
1542
|
-
allThreadMessages = allThreadMessages.filter((msg) => !excludeIds.includes(msg.id));
|
|
1543
|
-
}
|
|
1544
|
-
messages.push(...allThreadMessages);
|
|
1545
|
-
}
|
|
1546
|
-
messages.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
1547
|
-
if (fromDate || toDate) {
|
|
1548
|
-
messages = messages.filter((msg) => {
|
|
1549
|
-
const createdAt = new Date(msg.createdAt).getTime();
|
|
1550
|
-
if (fromDate && createdAt < new Date(fromDate).getTime()) return false;
|
|
1551
|
-
if (toDate && createdAt > new Date(toDate).getTime()) return false;
|
|
1552
|
-
return true;
|
|
1553
|
-
});
|
|
1554
|
-
}
|
|
1555
|
-
const total = messages.length;
|
|
1556
|
-
const start = page * perPage;
|
|
1557
|
-
const end = start + perPage;
|
|
1558
|
-
const paginatedMessages = messages.slice(start, end);
|
|
1559
|
-
const hasMore = end < total;
|
|
1560
|
-
const list = new agent.MessageList({ threadId, resourceId }).add(paginatedMessages, "memory");
|
|
1561
|
-
const finalMessages = format === "v2" ? list.get.all.v2() : list.get.all.v1();
|
|
1562
|
-
return {
|
|
1563
|
-
messages: finalMessages,
|
|
1564
|
-
total,
|
|
1565
|
-
page,
|
|
1566
|
-
perPage,
|
|
1567
|
-
hasMore
|
|
1568
|
-
};
|
|
1569
|
-
} catch (error$1) {
|
|
1570
|
-
const mastraError = new error.MastraError(
|
|
1571
|
-
{
|
|
1572
|
-
id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_PAGINATED_FAILED",
|
|
1573
|
-
domain: error.ErrorDomain.STORAGE,
|
|
1574
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
1575
|
-
details: { threadId, resourceId: resourceId ?? "" }
|
|
1576
|
-
},
|
|
1577
|
-
error$1
|
|
1578
|
-
);
|
|
1579
|
-
this.logger?.trackException?.(mastraError);
|
|
1580
|
-
this.logger?.error?.(mastraError.toString());
|
|
1581
|
-
return { messages: [], total: 0, page, perPage, hasMore: false };
|
|
1582
|
-
}
|
|
1583
|
-
}
|
|
1584
1454
|
// Helper method to get included messages with context
|
|
1585
1455
|
async _getIncludedMessages(threadId, selectBy) {
|
|
1586
1456
|
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
@@ -1847,7 +1717,6 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
|
|
|
1847
1717
|
[storage.TABLE_THREADS]: "thread",
|
|
1848
1718
|
[storage.TABLE_MESSAGES]: "message",
|
|
1849
1719
|
[storage.TABLE_WORKFLOW_SNAPSHOT]: "workflow_snapshot",
|
|
1850
|
-
[storage.TABLE_EVALS]: "eval",
|
|
1851
1720
|
[storage.TABLE_SCORERS]: "score",
|
|
1852
1721
|
[storage.TABLE_TRACES]: "trace",
|
|
1853
1722
|
[storage.TABLE_RESOURCES]: "resource",
|
|
@@ -2036,6 +1905,10 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
|
|
|
2036
1905
|
if (!item.id) throw new Error(`Missing required key 'id' for entity 'score'`);
|
|
2037
1906
|
key.id = item.id;
|
|
2038
1907
|
break;
|
|
1908
|
+
case "resource":
|
|
1909
|
+
if (!item.id) throw new Error(`Missing required key 'id' for entity 'resource'`);
|
|
1910
|
+
key.id = item.id;
|
|
1911
|
+
break;
|
|
2039
1912
|
default:
|
|
2040
1913
|
this.logger.warn(`Unknown entity type encountered during clearTable: ${entityName}`);
|
|
2041
1914
|
throw new Error(`Cannot construct delete key for unknown entity type: ${entityName}`);
|
|
@@ -2178,34 +2051,47 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2178
2051
|
}
|
|
2179
2052
|
}
|
|
2180
2053
|
async saveScore(score) {
|
|
2181
|
-
|
|
2054
|
+
let validatedScore;
|
|
2055
|
+
try {
|
|
2056
|
+
validatedScore = evals.saveScorePayloadSchema.parse(score);
|
|
2057
|
+
} catch (error$1) {
|
|
2058
|
+
throw new error.MastraError(
|
|
2059
|
+
{
|
|
2060
|
+
id: "STORAGE_DYNAMODB_STORE_SAVE_SCORE_FAILED",
|
|
2061
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2062
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
2063
|
+
},
|
|
2064
|
+
error$1
|
|
2065
|
+
);
|
|
2066
|
+
}
|
|
2182
2067
|
const now = /* @__PURE__ */ new Date();
|
|
2183
2068
|
const scoreId = `score-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
2184
2069
|
const scoreData = {
|
|
2185
2070
|
entity: "score",
|
|
2186
2071
|
id: scoreId,
|
|
2187
|
-
scorerId:
|
|
2188
|
-
traceId:
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2072
|
+
scorerId: validatedScore.scorerId,
|
|
2073
|
+
traceId: validatedScore.traceId || "",
|
|
2074
|
+
spanId: validatedScore.spanId || "",
|
|
2075
|
+
runId: validatedScore.runId,
|
|
2076
|
+
scorer: typeof validatedScore.scorer === "string" ? validatedScore.scorer : JSON.stringify(validatedScore.scorer),
|
|
2077
|
+
preprocessStepResult: typeof validatedScore.preprocessStepResult === "string" ? validatedScore.preprocessStepResult : JSON.stringify(validatedScore.preprocessStepResult),
|
|
2078
|
+
analyzeStepResult: typeof validatedScore.analyzeStepResult === "string" ? validatedScore.analyzeStepResult : JSON.stringify(validatedScore.analyzeStepResult),
|
|
2079
|
+
score: validatedScore.score,
|
|
2080
|
+
reason: validatedScore.reason,
|
|
2081
|
+
preprocessPrompt: validatedScore.preprocessPrompt,
|
|
2082
|
+
generateScorePrompt: validatedScore.generateScorePrompt,
|
|
2083
|
+
generateReasonPrompt: validatedScore.generateReasonPrompt,
|
|
2084
|
+
analyzePrompt: validatedScore.analyzePrompt,
|
|
2085
|
+
input: typeof validatedScore.input === "string" ? validatedScore.input : JSON.stringify(validatedScore.input),
|
|
2086
|
+
output: typeof validatedScore.output === "string" ? validatedScore.output : JSON.stringify(validatedScore.output),
|
|
2087
|
+
additionalContext: typeof validatedScore.additionalContext === "string" ? validatedScore.additionalContext : JSON.stringify(validatedScore.additionalContext),
|
|
2088
|
+
requestContext: typeof validatedScore.requestContext === "string" ? validatedScore.requestContext : JSON.stringify(validatedScore.requestContext),
|
|
2089
|
+
entityType: validatedScore.entityType,
|
|
2090
|
+
entityData: typeof validatedScore.entity === "string" ? validatedScore.entity : JSON.stringify(validatedScore.entity),
|
|
2091
|
+
entityId: validatedScore.entityId,
|
|
2092
|
+
source: validatedScore.source,
|
|
2093
|
+
resourceId: validatedScore.resourceId || "",
|
|
2094
|
+
threadId: validatedScore.threadId || "",
|
|
2209
2095
|
createdAt: now.toISOString(),
|
|
2210
2096
|
updatedAt: now.toISOString()
|
|
2211
2097
|
};
|
|
@@ -2230,7 +2116,7 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2230
2116
|
);
|
|
2231
2117
|
}
|
|
2232
2118
|
}
|
|
2233
|
-
async
|
|
2119
|
+
async listScoresByScorerId({
|
|
2234
2120
|
scorerId,
|
|
2235
2121
|
pagination,
|
|
2236
2122
|
entityId,
|
|
@@ -2251,18 +2137,19 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2251
2137
|
allScores = allScores.filter((score) => score.source === source);
|
|
2252
2138
|
}
|
|
2253
2139
|
allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
2254
|
-
const
|
|
2255
|
-
const
|
|
2256
|
-
const
|
|
2140
|
+
const { page, perPage: perPageInput } = pagination;
|
|
2141
|
+
const perPage = storage.normalizePerPage(perPageInput, Number.MAX_SAFE_INTEGER);
|
|
2142
|
+
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
2257
2143
|
const total = allScores.length;
|
|
2258
|
-
const
|
|
2144
|
+
const end = perPageInput === false ? allScores.length : start + perPage;
|
|
2145
|
+
const paginatedScores = allScores.slice(start, end);
|
|
2259
2146
|
return {
|
|
2260
2147
|
scores: paginatedScores,
|
|
2261
2148
|
pagination: {
|
|
2262
2149
|
total,
|
|
2263
|
-
page
|
|
2264
|
-
perPage:
|
|
2265
|
-
hasMore
|
|
2150
|
+
page,
|
|
2151
|
+
perPage: perPageForResponse,
|
|
2152
|
+
hasMore: end < total
|
|
2266
2153
|
}
|
|
2267
2154
|
};
|
|
2268
2155
|
} catch (error$1) {
|
|
@@ -2284,7 +2171,7 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2284
2171
|
);
|
|
2285
2172
|
}
|
|
2286
2173
|
}
|
|
2287
|
-
async
|
|
2174
|
+
async listScoresByRunId({
|
|
2288
2175
|
runId,
|
|
2289
2176
|
pagination
|
|
2290
2177
|
}) {
|
|
@@ -2294,18 +2181,19 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2294
2181
|
const results = await query.go();
|
|
2295
2182
|
const allScores = results.data.map((data) => this.parseScoreData(data));
|
|
2296
2183
|
allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
2297
|
-
const
|
|
2298
|
-
const
|
|
2299
|
-
const
|
|
2184
|
+
const { page, perPage: perPageInput } = pagination;
|
|
2185
|
+
const perPage = storage.normalizePerPage(perPageInput, Number.MAX_SAFE_INTEGER);
|
|
2186
|
+
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
2300
2187
|
const total = allScores.length;
|
|
2301
|
-
const
|
|
2188
|
+
const end = perPageInput === false ? allScores.length : start + perPage;
|
|
2189
|
+
const paginatedScores = allScores.slice(start, end);
|
|
2302
2190
|
return {
|
|
2303
2191
|
scores: paginatedScores,
|
|
2304
2192
|
pagination: {
|
|
2305
2193
|
total,
|
|
2306
|
-
page
|
|
2307
|
-
perPage:
|
|
2308
|
-
hasMore
|
|
2194
|
+
page,
|
|
2195
|
+
perPage: perPageForResponse,
|
|
2196
|
+
hasMore: end < total
|
|
2309
2197
|
}
|
|
2310
2198
|
};
|
|
2311
2199
|
} catch (error$1) {
|
|
@@ -2320,7 +2208,7 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2320
2208
|
);
|
|
2321
2209
|
}
|
|
2322
2210
|
}
|
|
2323
|
-
async
|
|
2211
|
+
async listScoresByEntityId({
|
|
2324
2212
|
entityId,
|
|
2325
2213
|
entityType,
|
|
2326
2214
|
pagination
|
|
@@ -2332,18 +2220,19 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2332
2220
|
let allScores = results.data.map((data) => this.parseScoreData(data));
|
|
2333
2221
|
allScores = allScores.filter((score) => score.entityType === entityType);
|
|
2334
2222
|
allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
2335
|
-
const
|
|
2336
|
-
const
|
|
2337
|
-
const
|
|
2223
|
+
const { page, perPage: perPageInput } = pagination;
|
|
2224
|
+
const perPage = storage.normalizePerPage(perPageInput, Number.MAX_SAFE_INTEGER);
|
|
2225
|
+
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
2338
2226
|
const total = allScores.length;
|
|
2339
|
-
const
|
|
2227
|
+
const end = perPageInput === false ? allScores.length : start + perPage;
|
|
2228
|
+
const paginatedScores = allScores.slice(start, end);
|
|
2340
2229
|
return {
|
|
2341
2230
|
scores: paginatedScores,
|
|
2342
2231
|
pagination: {
|
|
2343
2232
|
total,
|
|
2344
|
-
page
|
|
2345
|
-
perPage:
|
|
2346
|
-
hasMore
|
|
2233
|
+
page,
|
|
2234
|
+
perPage: perPageForResponse,
|
|
2235
|
+
hasMore: end < total
|
|
2347
2236
|
}
|
|
2348
2237
|
};
|
|
2349
2238
|
} catch (error$1) {
|
|
@@ -2358,234 +2247,39 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2358
2247
|
);
|
|
2359
2248
|
}
|
|
2360
2249
|
}
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
this.service = service;
|
|
2368
|
-
this.operations = operations;
|
|
2369
|
-
}
|
|
2370
|
-
// Trace operations
|
|
2371
|
-
async getTraces(args) {
|
|
2372
|
-
const { name, scope, page, perPage } = args;
|
|
2373
|
-
this.logger.debug("Getting traces", { name, scope, page, perPage });
|
|
2374
|
-
try {
|
|
2375
|
-
let query;
|
|
2376
|
-
if (name) {
|
|
2377
|
-
query = this.service.entities.trace.query.byName({ entity: "trace", name });
|
|
2378
|
-
} else if (scope) {
|
|
2379
|
-
query = this.service.entities.trace.query.byScope({ entity: "trace", scope });
|
|
2380
|
-
} else {
|
|
2381
|
-
this.logger.warn("Performing a scan operation on traces - consider using a more specific query");
|
|
2382
|
-
query = this.service.entities.trace.scan;
|
|
2383
|
-
}
|
|
2384
|
-
let items = [];
|
|
2385
|
-
let cursor = null;
|
|
2386
|
-
let pagesFetched = 0;
|
|
2387
|
-
const startPage = page > 0 ? page : 1;
|
|
2388
|
-
do {
|
|
2389
|
-
const results = await query.go({ cursor, limit: perPage });
|
|
2390
|
-
pagesFetched++;
|
|
2391
|
-
if (pagesFetched === startPage) {
|
|
2392
|
-
items = results.data;
|
|
2393
|
-
break;
|
|
2394
|
-
}
|
|
2395
|
-
cursor = results.cursor;
|
|
2396
|
-
if (!cursor && results.data.length > 0 && pagesFetched < startPage) {
|
|
2397
|
-
break;
|
|
2398
|
-
}
|
|
2399
|
-
} while (cursor && pagesFetched < startPage);
|
|
2400
|
-
return items;
|
|
2401
|
-
} catch (error$1) {
|
|
2402
|
-
throw new error.MastraError(
|
|
2403
|
-
{
|
|
2404
|
-
id: "STORAGE_DYNAMODB_STORE_GET_TRACES_FAILED",
|
|
2405
|
-
domain: error.ErrorDomain.STORAGE,
|
|
2406
|
-
category: error.ErrorCategory.THIRD_PARTY
|
|
2407
|
-
},
|
|
2408
|
-
error$1
|
|
2409
|
-
);
|
|
2410
|
-
}
|
|
2411
|
-
}
|
|
2412
|
-
async batchTraceInsert({ records }) {
|
|
2413
|
-
this.logger.debug("Batch inserting traces", { count: records.length });
|
|
2414
|
-
if (!records.length) {
|
|
2415
|
-
return;
|
|
2416
|
-
}
|
|
2417
|
-
try {
|
|
2418
|
-
const recordsToSave = records.map((rec) => ({ entity: "trace", ...rec }));
|
|
2419
|
-
await this.operations.batchInsert({
|
|
2420
|
-
tableName: storage.TABLE_TRACES,
|
|
2421
|
-
records: recordsToSave
|
|
2422
|
-
// Pass records with 'entity' included
|
|
2423
|
-
});
|
|
2424
|
-
} catch (error$1) {
|
|
2425
|
-
throw new error.MastraError(
|
|
2426
|
-
{
|
|
2427
|
-
id: "STORAGE_DYNAMODB_STORE_BATCH_TRACE_INSERT_FAILED",
|
|
2428
|
-
domain: error.ErrorDomain.STORAGE,
|
|
2429
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
2430
|
-
details: { count: records.length }
|
|
2431
|
-
},
|
|
2432
|
-
error$1
|
|
2433
|
-
);
|
|
2434
|
-
}
|
|
2435
|
-
}
|
|
2436
|
-
async getTracesPaginated(args) {
|
|
2437
|
-
const { name, scope, page = 0, perPage = 100, attributes, filters, dateRange } = args;
|
|
2438
|
-
this.logger.debug("Getting traces with pagination", { name, scope, page, perPage, attributes, filters, dateRange });
|
|
2250
|
+
async listScoresBySpan({
|
|
2251
|
+
traceId,
|
|
2252
|
+
spanId,
|
|
2253
|
+
pagination
|
|
2254
|
+
}) {
|
|
2255
|
+
this.logger.debug("Getting scores by span", { traceId, spanId, pagination });
|
|
2439
2256
|
try {
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
const
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
if (!results.data.length) {
|
|
2455
|
-
return {
|
|
2456
|
-
traces: [],
|
|
2457
|
-
total: 0,
|
|
2257
|
+
const query = this.service.entities.score.query.bySpan({ entity: "score", traceId, spanId });
|
|
2258
|
+
const results = await query.go();
|
|
2259
|
+
const allScores = results.data.map((data) => this.parseScoreData(data));
|
|
2260
|
+
allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
2261
|
+
const { page, perPage: perPageInput } = pagination;
|
|
2262
|
+
const perPage = storage.normalizePerPage(perPageInput, Number.MAX_SAFE_INTEGER);
|
|
2263
|
+
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
2264
|
+
const total = allScores.length;
|
|
2265
|
+
const end = perPageInput === false ? allScores.length : start + perPage;
|
|
2266
|
+
const paginatedScores = allScores.slice(start, end);
|
|
2267
|
+
return {
|
|
2268
|
+
scores: paginatedScores,
|
|
2269
|
+
pagination: {
|
|
2270
|
+
total,
|
|
2458
2271
|
page,
|
|
2459
|
-
perPage,
|
|
2460
|
-
hasMore:
|
|
2461
|
-
};
|
|
2462
|
-
}
|
|
2463
|
-
let filteredData = results.data;
|
|
2464
|
-
if (attributes) {
|
|
2465
|
-
filteredData = filteredData.filter((item) => {
|
|
2466
|
-
try {
|
|
2467
|
-
let itemAttributes = {};
|
|
2468
|
-
if (item.attributes) {
|
|
2469
|
-
if (typeof item.attributes === "string") {
|
|
2470
|
-
if (item.attributes === "[object Object]") {
|
|
2471
|
-
itemAttributes = {};
|
|
2472
|
-
} else {
|
|
2473
|
-
try {
|
|
2474
|
-
itemAttributes = JSON.parse(item.attributes);
|
|
2475
|
-
} catch {
|
|
2476
|
-
itemAttributes = {};
|
|
2477
|
-
}
|
|
2478
|
-
}
|
|
2479
|
-
} else if (typeof item.attributes === "object") {
|
|
2480
|
-
itemAttributes = item.attributes;
|
|
2481
|
-
}
|
|
2482
|
-
}
|
|
2483
|
-
return Object.entries(attributes).every(([key, value]) => itemAttributes[key] === value);
|
|
2484
|
-
} catch (e) {
|
|
2485
|
-
this.logger.warn("Failed to parse attributes during filtering", { item, error: e });
|
|
2486
|
-
return false;
|
|
2487
|
-
}
|
|
2488
|
-
});
|
|
2489
|
-
}
|
|
2490
|
-
if (dateRange?.start) {
|
|
2491
|
-
filteredData = filteredData.filter((item) => {
|
|
2492
|
-
const itemDate = new Date(item.createdAt);
|
|
2493
|
-
return itemDate >= dateRange.start;
|
|
2494
|
-
});
|
|
2495
|
-
}
|
|
2496
|
-
if (dateRange?.end) {
|
|
2497
|
-
filteredData = filteredData.filter((item) => {
|
|
2498
|
-
const itemDate = new Date(item.createdAt);
|
|
2499
|
-
return itemDate <= dateRange.end;
|
|
2500
|
-
});
|
|
2501
|
-
}
|
|
2502
|
-
const total = filteredData.length;
|
|
2503
|
-
const start = page * perPage;
|
|
2504
|
-
const end = start + perPage;
|
|
2505
|
-
const paginatedData = filteredData.slice(start, end);
|
|
2506
|
-
const traces = paginatedData.map((item) => {
|
|
2507
|
-
let attributes2;
|
|
2508
|
-
if (item.attributes) {
|
|
2509
|
-
if (typeof item.attributes === "string") {
|
|
2510
|
-
if (item.attributes === "[object Object]") {
|
|
2511
|
-
attributes2 = void 0;
|
|
2512
|
-
} else {
|
|
2513
|
-
try {
|
|
2514
|
-
attributes2 = JSON.parse(item.attributes);
|
|
2515
|
-
} catch {
|
|
2516
|
-
attributes2 = void 0;
|
|
2517
|
-
}
|
|
2518
|
-
}
|
|
2519
|
-
} else if (typeof item.attributes === "object") {
|
|
2520
|
-
attributes2 = item.attributes;
|
|
2521
|
-
}
|
|
2522
|
-
}
|
|
2523
|
-
let status;
|
|
2524
|
-
if (item.status) {
|
|
2525
|
-
if (typeof item.status === "string") {
|
|
2526
|
-
try {
|
|
2527
|
-
status = JSON.parse(item.status);
|
|
2528
|
-
} catch {
|
|
2529
|
-
status = void 0;
|
|
2530
|
-
}
|
|
2531
|
-
} else if (typeof item.status === "object") {
|
|
2532
|
-
status = item.status;
|
|
2533
|
-
}
|
|
2534
|
-
}
|
|
2535
|
-
let events;
|
|
2536
|
-
if (item.events) {
|
|
2537
|
-
if (typeof item.events === "string") {
|
|
2538
|
-
try {
|
|
2539
|
-
events = JSON.parse(item.events);
|
|
2540
|
-
} catch {
|
|
2541
|
-
events = void 0;
|
|
2542
|
-
}
|
|
2543
|
-
} else if (Array.isArray(item.events)) {
|
|
2544
|
-
events = item.events;
|
|
2545
|
-
}
|
|
2272
|
+
perPage: perPageForResponse,
|
|
2273
|
+
hasMore: end < total
|
|
2546
2274
|
}
|
|
2547
|
-
let links;
|
|
2548
|
-
if (item.links) {
|
|
2549
|
-
if (typeof item.links === "string") {
|
|
2550
|
-
try {
|
|
2551
|
-
links = JSON.parse(item.links);
|
|
2552
|
-
} catch {
|
|
2553
|
-
links = void 0;
|
|
2554
|
-
}
|
|
2555
|
-
} else if (Array.isArray(item.links)) {
|
|
2556
|
-
links = item.links;
|
|
2557
|
-
}
|
|
2558
|
-
}
|
|
2559
|
-
return {
|
|
2560
|
-
id: item.id,
|
|
2561
|
-
parentSpanId: item.parentSpanId,
|
|
2562
|
-
name: item.name,
|
|
2563
|
-
traceId: item.traceId,
|
|
2564
|
-
scope: item.scope,
|
|
2565
|
-
kind: item.kind,
|
|
2566
|
-
attributes: attributes2,
|
|
2567
|
-
status,
|
|
2568
|
-
events,
|
|
2569
|
-
links,
|
|
2570
|
-
other: item.other,
|
|
2571
|
-
startTime: item.startTime,
|
|
2572
|
-
endTime: item.endTime,
|
|
2573
|
-
createdAt: item.createdAt
|
|
2574
|
-
};
|
|
2575
|
-
});
|
|
2576
|
-
return {
|
|
2577
|
-
traces,
|
|
2578
|
-
total,
|
|
2579
|
-
page,
|
|
2580
|
-
perPage,
|
|
2581
|
-
hasMore: end < total
|
|
2582
2275
|
};
|
|
2583
2276
|
} catch (error$1) {
|
|
2584
2277
|
throw new error.MastraError(
|
|
2585
2278
|
{
|
|
2586
|
-
id: "
|
|
2279
|
+
id: "STORAGE_DYNAMODB_STORE_GET_SCORES_BY_SPAN_FAILED",
|
|
2587
2280
|
domain: error.ErrorDomain.STORAGE,
|
|
2588
|
-
category: error.ErrorCategory.THIRD_PARTY
|
|
2281
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
2282
|
+
details: { traceId, spanId, page: pagination.page, perPage: pagination.perPage }
|
|
2589
2283
|
},
|
|
2590
2284
|
error$1
|
|
2591
2285
|
);
|
|
@@ -2613,7 +2307,7 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
|
|
|
2613
2307
|
// runId,
|
|
2614
2308
|
// stepId,
|
|
2615
2309
|
// result,
|
|
2616
|
-
//
|
|
2310
|
+
// requestContext,
|
|
2617
2311
|
}) {
|
|
2618
2312
|
throw new Error("Method not implemented.");
|
|
2619
2313
|
}
|
|
@@ -2686,11 +2380,24 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
|
|
|
2686
2380
|
);
|
|
2687
2381
|
}
|
|
2688
2382
|
}
|
|
2689
|
-
async
|
|
2383
|
+
async listWorkflowRuns(args) {
|
|
2690
2384
|
this.logger.debug("Getting workflow runs", { args });
|
|
2691
2385
|
try {
|
|
2692
|
-
const
|
|
2693
|
-
const
|
|
2386
|
+
const perPage = args?.perPage !== void 0 ? args.perPage : 10;
|
|
2387
|
+
const page = args?.page !== void 0 ? args.page : 0;
|
|
2388
|
+
if (page < 0) {
|
|
2389
|
+
throw new error.MastraError(
|
|
2390
|
+
{
|
|
2391
|
+
id: "DYNAMODB_STORE_INVALID_PAGE",
|
|
2392
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2393
|
+
category: error.ErrorCategory.USER,
|
|
2394
|
+
details: { page }
|
|
2395
|
+
},
|
|
2396
|
+
new Error("page must be >= 0")
|
|
2397
|
+
);
|
|
2398
|
+
}
|
|
2399
|
+
const normalizedPerPage = storage.normalizePerPage(perPage, 10);
|
|
2400
|
+
const offset = page * normalizedPerPage;
|
|
2694
2401
|
let query;
|
|
2695
2402
|
if (args?.workflowName) {
|
|
2696
2403
|
query = this.service.entities.workflow_snapshot.query.primary({
|
|
@@ -2737,7 +2444,7 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
|
|
|
2737
2444
|
return { runs: [], total: 0 };
|
|
2738
2445
|
}
|
|
2739
2446
|
const total = allMatchingSnapshots.length;
|
|
2740
|
-
const paginatedData = allMatchingSnapshots.slice(offset, offset +
|
|
2447
|
+
const paginatedData = allMatchingSnapshots.slice(offset, offset + normalizedPerPage);
|
|
2741
2448
|
const runs = paginatedData.map((snapshot) => formatWorkflowRun(snapshot));
|
|
2742
2449
|
return {
|
|
2743
2450
|
runs,
|
|
@@ -2746,7 +2453,7 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
|
|
|
2746
2453
|
} catch (error$1) {
|
|
2747
2454
|
throw new error.MastraError(
|
|
2748
2455
|
{
|
|
2749
|
-
id: "
|
|
2456
|
+
id: "STORAGE_DYNAMODB_STORE_LIST_WORKFLOW_RUNS_FAILED",
|
|
2750
2457
|
domain: error.ErrorDomain.STORAGE,
|
|
2751
2458
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
2752
2459
|
details: { workflowName: args?.workflowName || "", resourceId: args?.resourceId || "" }
|
|
@@ -2842,14 +2549,11 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2842
2549
|
tableName: this.tableName,
|
|
2843
2550
|
client: this.client
|
|
2844
2551
|
});
|
|
2845
|
-
const traces = new TracesStorageDynamoDB({ service: this.service, operations });
|
|
2846
2552
|
const workflows = new WorkflowStorageDynamoDB({ service: this.service });
|
|
2847
2553
|
const memory = new MemoryStorageDynamoDB({ service: this.service });
|
|
2848
2554
|
const scores = new ScoresStorageDynamoDB({ service: this.service });
|
|
2849
2555
|
this.stores = {
|
|
2850
2556
|
operations,
|
|
2851
|
-
legacyEvals: new LegacyEvalsDynamoDB({ service: this.service, tableName: this.tableName }),
|
|
2852
|
-
traces,
|
|
2853
2557
|
workflows,
|
|
2854
2558
|
memory,
|
|
2855
2559
|
scores
|
|
@@ -2871,7 +2575,8 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2871
2575
|
resourceWorkingMemory: true,
|
|
2872
2576
|
hasColumn: false,
|
|
2873
2577
|
createTable: false,
|
|
2874
|
-
deleteMessages: false
|
|
2578
|
+
deleteMessages: false,
|
|
2579
|
+
listScoresBySpan: true
|
|
2875
2580
|
};
|
|
2876
2581
|
}
|
|
2877
2582
|
/**
|
|
@@ -2966,9 +2671,6 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2966
2671
|
async getThreadById({ threadId }) {
|
|
2967
2672
|
return this.stores.memory.getThreadById({ threadId });
|
|
2968
2673
|
}
|
|
2969
|
-
async getThreadsByResourceId(args) {
|
|
2970
|
-
return this.stores.memory.getThreadsByResourceId(args);
|
|
2971
|
-
}
|
|
2972
2674
|
async saveThread({ thread }) {
|
|
2973
2675
|
return this.stores.memory.saveThread({ thread });
|
|
2974
2676
|
}
|
|
@@ -2982,51 +2684,28 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2982
2684
|
async deleteThread({ threadId }) {
|
|
2983
2685
|
return this.stores.memory.deleteThread({ threadId });
|
|
2984
2686
|
}
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
selectBy,
|
|
2989
|
-
format
|
|
2990
|
-
}) {
|
|
2991
|
-
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
|
|
2687
|
+
// Message operations
|
|
2688
|
+
async getMessages(args) {
|
|
2689
|
+
return this.stores.memory.getMessages(args);
|
|
2992
2690
|
}
|
|
2993
|
-
async
|
|
2994
|
-
|
|
2995
|
-
format
|
|
2996
|
-
}) {
|
|
2997
|
-
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
2691
|
+
async listMessagesById(args) {
|
|
2692
|
+
return this.stores.memory.listMessagesById(args);
|
|
2998
2693
|
}
|
|
2999
2694
|
async saveMessages(args) {
|
|
3000
2695
|
return this.stores.memory.saveMessages(args);
|
|
3001
2696
|
}
|
|
3002
|
-
async getThreadsByResourceIdPaginated(args) {
|
|
3003
|
-
return this.stores.memory.getThreadsByResourceIdPaginated(args);
|
|
3004
|
-
}
|
|
3005
|
-
async getMessagesPaginated(args) {
|
|
3006
|
-
return this.stores.memory.getMessagesPaginated(args);
|
|
3007
|
-
}
|
|
3008
2697
|
async updateMessages(_args) {
|
|
3009
2698
|
return this.stores.memory.updateMessages(_args);
|
|
3010
2699
|
}
|
|
3011
|
-
// Trace operations
|
|
3012
|
-
async getTraces(args) {
|
|
3013
|
-
return this.stores.traces.getTraces(args);
|
|
3014
|
-
}
|
|
3015
|
-
async batchTraceInsert({ records }) {
|
|
3016
|
-
return this.stores.traces.batchTraceInsert({ records });
|
|
3017
|
-
}
|
|
3018
|
-
async getTracesPaginated(_args) {
|
|
3019
|
-
return this.stores.traces.getTracesPaginated(_args);
|
|
3020
|
-
}
|
|
3021
2700
|
// Workflow operations
|
|
3022
2701
|
async updateWorkflowResults({
|
|
3023
2702
|
workflowName,
|
|
3024
2703
|
runId,
|
|
3025
2704
|
stepId,
|
|
3026
2705
|
result,
|
|
3027
|
-
|
|
2706
|
+
requestContext
|
|
3028
2707
|
}) {
|
|
3029
|
-
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result,
|
|
2708
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, requestContext });
|
|
3030
2709
|
}
|
|
3031
2710
|
async updateWorkflowState({
|
|
3032
2711
|
workflowName,
|
|
@@ -3049,8 +2728,8 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
3049
2728
|
}) {
|
|
3050
2729
|
return this.stores.workflows.loadWorkflowSnapshot({ workflowName, runId });
|
|
3051
2730
|
}
|
|
3052
|
-
async
|
|
3053
|
-
return this.stores.workflows.
|
|
2731
|
+
async listWorkflowRuns(args) {
|
|
2732
|
+
return this.stores.workflows.listWorkflowRuns(args);
|
|
3054
2733
|
}
|
|
3055
2734
|
async getWorkflowRunById(args) {
|
|
3056
2735
|
return this.stores.workflows.getWorkflowRunById(args);
|
|
@@ -3068,13 +2747,6 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
3068
2747
|
}) {
|
|
3069
2748
|
return this.stores.memory.updateResource({ resourceId, workingMemory, metadata });
|
|
3070
2749
|
}
|
|
3071
|
-
// Eval operations
|
|
3072
|
-
async getEvalsByAgentName(agentName, type) {
|
|
3073
|
-
return this.stores.legacyEvals.getEvalsByAgentName(agentName, type);
|
|
3074
|
-
}
|
|
3075
|
-
async getEvals(options) {
|
|
3076
|
-
return this.stores.legacyEvals.getEvals(options);
|
|
3077
|
-
}
|
|
3078
2750
|
/**
|
|
3079
2751
|
* Closes the DynamoDB client connection and cleans up resources.
|
|
3080
2752
|
* Should be called when the store is no longer needed, e.g., at the end of tests or application shutdown.
|
|
@@ -3104,31 +2776,38 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
3104
2776
|
async saveScore(_score) {
|
|
3105
2777
|
return this.stores.scores.saveScore(_score);
|
|
3106
2778
|
}
|
|
3107
|
-
async
|
|
2779
|
+
async listScoresByRunId({
|
|
3108
2780
|
runId: _runId,
|
|
3109
2781
|
pagination: _pagination
|
|
3110
2782
|
}) {
|
|
3111
|
-
return this.stores.scores.
|
|
2783
|
+
return this.stores.scores.listScoresByRunId({ runId: _runId, pagination: _pagination });
|
|
3112
2784
|
}
|
|
3113
|
-
async
|
|
2785
|
+
async listScoresByEntityId({
|
|
3114
2786
|
entityId: _entityId,
|
|
3115
2787
|
entityType: _entityType,
|
|
3116
2788
|
pagination: _pagination
|
|
3117
2789
|
}) {
|
|
3118
|
-
return this.stores.scores.
|
|
2790
|
+
return this.stores.scores.listScoresByEntityId({
|
|
3119
2791
|
entityId: _entityId,
|
|
3120
2792
|
entityType: _entityType,
|
|
3121
2793
|
pagination: _pagination
|
|
3122
2794
|
});
|
|
3123
2795
|
}
|
|
3124
|
-
async
|
|
2796
|
+
async listScoresByScorerId({
|
|
3125
2797
|
scorerId,
|
|
3126
2798
|
source,
|
|
3127
2799
|
entityId,
|
|
3128
2800
|
entityType,
|
|
3129
2801
|
pagination
|
|
3130
2802
|
}) {
|
|
3131
|
-
return this.stores.scores.
|
|
2803
|
+
return this.stores.scores.listScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
|
|
2804
|
+
}
|
|
2805
|
+
async listScoresBySpan({
|
|
2806
|
+
traceId,
|
|
2807
|
+
spanId,
|
|
2808
|
+
pagination
|
|
2809
|
+
}) {
|
|
2810
|
+
return this.stores.scores.listScoresBySpan({ traceId, spanId, pagination });
|
|
3132
2811
|
}
|
|
3133
2812
|
};
|
|
3134
2813
|
|