@mastra/dynamodb 0.0.0-new-scorer-api-20250801075530 → 0.0.0-partial-response-backport-20251204204441
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 +1118 -0
- package/README.md +0 -4
- package/dist/entities/index.d.ts +19 -0
- package/dist/entities/index.d.ts.map +1 -1
- package/dist/entities/score.d.ts +19 -0
- package/dist/entities/score.d.ts.map +1 -1
- package/dist/index.cjs +243 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +244 -57
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +16 -4
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/operations/index.d.ts.map +1 -1
- package/dist/storage/domains/score/index.d.ts +11 -2
- package/dist/storage/domains/score/index.d.ts.map +1 -1
- package/dist/storage/domains/traces/index.d.ts +1 -1
- package/dist/storage/domains/workflows/index.d.ts +23 -11
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +48 -16
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +29 -12
- package/src/entities/eval.ts +0 -102
- package/src/entities/index.ts +0 -27
- package/src/entities/message.ts +0 -143
- package/src/entities/resource.ts +0 -57
- package/src/entities/score.ts +0 -317
- package/src/entities/thread.ts +0 -66
- package/src/entities/trace.ts +0 -129
- package/src/entities/utils.ts +0 -51
- package/src/entities/workflow-snapshot.ts +0 -56
- package/src/index.ts +0 -1
- package/src/storage/docker-compose.yml +0 -16
- package/src/storage/domains/legacy-evals/index.ts +0 -243
- package/src/storage/domains/memory/index.ts +0 -894
- package/src/storage/domains/operations/index.ts +0 -433
- package/src/storage/domains/score/index.ts +0 -288
- package/src/storage/domains/traces/index.ts +0 -286
- package/src/storage/domains/workflows/index.ts +0 -297
- package/src/storage/index.test.ts +0 -1420
- package/src/storage/index.ts +0 -483
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './storage';
|
|
1
|
+
export * from './storage/index.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { DynamoDBClient, DescribeTableCommand } from '@aws-sdk/client-dynamodb';
|
|
2
2
|
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
|
|
3
3
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
4
|
-
import { MastraStorage, StoreOperations, TracesStorage, TABLE_TRACES, WorkflowsStorage, MemoryStorage, resolveMessageLimit, ScoresStorage, LegacyEvalsStorage, TABLE_RESOURCES, TABLE_SCORERS, TABLE_EVALS, TABLE_WORKFLOW_SNAPSHOT, TABLE_MESSAGES, TABLE_THREADS } from '@mastra/core/storage';
|
|
4
|
+
import { MastraStorage, StoreOperations, TracesStorage, TABLE_TRACES, WorkflowsStorage, MemoryStorage, resolveMessageLimit, ScoresStorage, SCORERS_SCHEMA, LegacyEvalsStorage, TABLE_AI_SPANS, TABLE_RESOURCES, TABLE_SCORERS, TABLE_EVALS, TABLE_WORKFLOW_SNAPSHOT, TABLE_MESSAGES, TABLE_THREADS } from '@mastra/core/storage';
|
|
5
5
|
import { Entity, Service } from 'electrodb';
|
|
6
6
|
import { MessageList } from '@mastra/core/agent';
|
|
7
|
+
import { saveScorePayloadSchema } from '@mastra/core/scores';
|
|
7
8
|
|
|
8
9
|
// src/storage/index.ts
|
|
9
10
|
|
|
@@ -370,6 +371,10 @@ var scoreEntity = new Entity({
|
|
|
370
371
|
type: "string",
|
|
371
372
|
required: false
|
|
372
373
|
},
|
|
374
|
+
spanId: {
|
|
375
|
+
type: "string",
|
|
376
|
+
required: false
|
|
377
|
+
},
|
|
373
378
|
runId: {
|
|
374
379
|
type: "string",
|
|
375
380
|
required: true
|
|
@@ -418,6 +423,10 @@ var scoreEntity = new Entity({
|
|
|
418
423
|
return value;
|
|
419
424
|
}
|
|
420
425
|
},
|
|
426
|
+
preprocessPrompt: {
|
|
427
|
+
type: "string",
|
|
428
|
+
required: false
|
|
429
|
+
},
|
|
421
430
|
preprocessStepResult: {
|
|
422
431
|
type: "string",
|
|
423
432
|
required: false,
|
|
@@ -656,6 +665,11 @@ var scoreEntity = new Entity({
|
|
|
656
665
|
index: "gsi6",
|
|
657
666
|
pk: { field: "gsi6pk", composite: ["entity", "threadId"] },
|
|
658
667
|
sk: { field: "gsi6sk", composite: ["createdAt"] }
|
|
668
|
+
},
|
|
669
|
+
bySpan: {
|
|
670
|
+
index: "gsi7",
|
|
671
|
+
pk: { field: "gsi7pk", composite: ["entity", "traceId", "spanId"] },
|
|
672
|
+
sk: { field: "gsi7sk", composite: ["createdAt"] }
|
|
659
673
|
}
|
|
660
674
|
}
|
|
661
675
|
});
|
|
@@ -1121,6 +1135,20 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1121
1135
|
// transformed by the ElectroDB entity getters.
|
|
1122
1136
|
};
|
|
1123
1137
|
}
|
|
1138
|
+
// Helper function to transform and sort threads
|
|
1139
|
+
transformAndSortThreads(rawThreads, orderBy, sortDirection) {
|
|
1140
|
+
return rawThreads.map((data) => ({
|
|
1141
|
+
...data,
|
|
1142
|
+
// Convert date strings back to Date objects for consistency
|
|
1143
|
+
createdAt: typeof data.createdAt === "string" ? new Date(data.createdAt) : data.createdAt,
|
|
1144
|
+
updatedAt: typeof data.updatedAt === "string" ? new Date(data.updatedAt) : data.updatedAt
|
|
1145
|
+
})).sort((a, b) => {
|
|
1146
|
+
const fieldA = orderBy === "createdAt" ? a.createdAt : a.updatedAt;
|
|
1147
|
+
const fieldB = orderBy === "createdAt" ? b.createdAt : b.updatedAt;
|
|
1148
|
+
const comparison = fieldA.getTime() - fieldB.getTime();
|
|
1149
|
+
return sortDirection === "DESC" ? -comparison : comparison;
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1124
1152
|
async getThreadById({ threadId }) {
|
|
1125
1153
|
this.logger.debug("Getting thread by ID", { threadId });
|
|
1126
1154
|
try {
|
|
@@ -1149,21 +1177,20 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1149
1177
|
);
|
|
1150
1178
|
}
|
|
1151
1179
|
}
|
|
1152
|
-
|
|
1153
|
-
|
|
1180
|
+
/**
|
|
1181
|
+
* @deprecated use getThreadsByResourceIdPaginated instead for paginated results.
|
|
1182
|
+
*/
|
|
1183
|
+
async getThreadsByResourceId(args) {
|
|
1184
|
+
const resourceId = args.resourceId;
|
|
1185
|
+
const orderBy = this.castThreadOrderBy(args.orderBy);
|
|
1186
|
+
const sortDirection = this.castThreadSortDirection(args.sortDirection);
|
|
1187
|
+
this.logger.debug("Getting threads by resource ID", { resourceId, orderBy, sortDirection });
|
|
1154
1188
|
try {
|
|
1155
1189
|
const result = await this.service.entities.thread.query.byResource({ entity: "thread", resourceId }).go();
|
|
1156
1190
|
if (!result.data.length) {
|
|
1157
1191
|
return [];
|
|
1158
1192
|
}
|
|
1159
|
-
return result.data
|
|
1160
|
-
...data,
|
|
1161
|
-
// Convert date strings back to Date objects for consistency
|
|
1162
|
-
createdAt: typeof data.createdAt === "string" ? new Date(data.createdAt) : data.createdAt,
|
|
1163
|
-
updatedAt: typeof data.updatedAt === "string" ? new Date(data.updatedAt) : data.updatedAt
|
|
1164
|
-
// metadata: data.metadata ? JSON.parse(data.metadata) : undefined, // REMOVED by AI
|
|
1165
|
-
// metadata is already transformed by the entity's getter
|
|
1166
|
-
}));
|
|
1193
|
+
return this.transformAndSortThreads(result.data, orderBy, sortDirection);
|
|
1167
1194
|
} catch (error) {
|
|
1168
1195
|
throw new MastraError(
|
|
1169
1196
|
{
|
|
@@ -1185,7 +1212,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1185
1212
|
resourceId: thread.resourceId,
|
|
1186
1213
|
title: thread.title || `Thread ${thread.id}`,
|
|
1187
1214
|
createdAt: thread.createdAt?.toISOString() || now.toISOString(),
|
|
1188
|
-
updatedAt: now.toISOString(),
|
|
1215
|
+
updatedAt: thread.updatedAt?.toISOString() || now.toISOString(),
|
|
1189
1216
|
metadata: thread.metadata ? JSON.stringify(thread.metadata) : void 0
|
|
1190
1217
|
};
|
|
1191
1218
|
try {
|
|
@@ -1292,6 +1319,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1292
1319
|
}) {
|
|
1293
1320
|
this.logger.debug("Getting messages", { threadId, selectBy });
|
|
1294
1321
|
try {
|
|
1322
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
1295
1323
|
const messages = [];
|
|
1296
1324
|
const limit = resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
|
|
1297
1325
|
if (selectBy?.include?.length) {
|
|
@@ -1340,7 +1368,37 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1340
1368
|
id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_FAILED",
|
|
1341
1369
|
domain: ErrorDomain.STORAGE,
|
|
1342
1370
|
category: ErrorCategory.THIRD_PARTY,
|
|
1343
|
-
details: { threadId }
|
|
1371
|
+
details: { threadId, resourceId: resourceId ?? "" }
|
|
1372
|
+
},
|
|
1373
|
+
error
|
|
1374
|
+
);
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
async getMessagesById({
|
|
1378
|
+
messageIds,
|
|
1379
|
+
format
|
|
1380
|
+
}) {
|
|
1381
|
+
this.logger.debug("Getting messages by ID", { messageIds });
|
|
1382
|
+
if (messageIds.length === 0) return [];
|
|
1383
|
+
try {
|
|
1384
|
+
const results = await Promise.all(
|
|
1385
|
+
messageIds.map((id) => this.service.entities.message.query.primary({ entity: "message", id }).go())
|
|
1386
|
+
);
|
|
1387
|
+
const data = results.map((result) => result.data).flat(1);
|
|
1388
|
+
let parsedMessages = data.map((data2) => this.parseMessageData(data2)).filter((msg) => "content" in msg);
|
|
1389
|
+
const uniqueMessages = parsedMessages.filter(
|
|
1390
|
+
(message, index, self) => index === self.findIndex((m) => m.id === message.id)
|
|
1391
|
+
);
|
|
1392
|
+
const list = new MessageList().add(uniqueMessages, "memory");
|
|
1393
|
+
if (format === `v1`) return list.get.all.v1();
|
|
1394
|
+
return list.get.all.v2();
|
|
1395
|
+
} catch (error) {
|
|
1396
|
+
throw new MastraError(
|
|
1397
|
+
{
|
|
1398
|
+
id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_BY_ID_FAILED",
|
|
1399
|
+
domain: ErrorDomain.STORAGE,
|
|
1400
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1401
|
+
details: { messageIds: JSON.stringify(messageIds) }
|
|
1344
1402
|
},
|
|
1345
1403
|
error
|
|
1346
1404
|
);
|
|
@@ -1420,11 +1478,19 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1420
1478
|
}
|
|
1421
1479
|
async getThreadsByResourceIdPaginated(args) {
|
|
1422
1480
|
const { resourceId, page = 0, perPage = 100 } = args;
|
|
1423
|
-
this.
|
|
1481
|
+
const orderBy = this.castThreadOrderBy(args.orderBy);
|
|
1482
|
+
const sortDirection = this.castThreadSortDirection(args.sortDirection);
|
|
1483
|
+
this.logger.debug("Getting threads by resource ID with pagination", {
|
|
1484
|
+
resourceId,
|
|
1485
|
+
page,
|
|
1486
|
+
perPage,
|
|
1487
|
+
orderBy,
|
|
1488
|
+
sortDirection
|
|
1489
|
+
});
|
|
1424
1490
|
try {
|
|
1425
1491
|
const query = this.service.entities.thread.query.byResource({ entity: "thread", resourceId });
|
|
1426
1492
|
const results = await query.go();
|
|
1427
|
-
const allThreads = results.data;
|
|
1493
|
+
const allThreads = this.transformAndSortThreads(results.data, orderBy, sortDirection);
|
|
1428
1494
|
const startIndex = page * perPage;
|
|
1429
1495
|
const endIndex = startIndex + perPage;
|
|
1430
1496
|
const paginatedThreads = allThreads.slice(startIndex, endIndex);
|
|
@@ -1457,6 +1523,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1457
1523
|
const limit = resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
|
|
1458
1524
|
this.logger.debug("Getting messages with pagination", { threadId, page, perPage, fromDate, toDate, limit });
|
|
1459
1525
|
try {
|
|
1526
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
1460
1527
|
let messages = [];
|
|
1461
1528
|
if (selectBy?.include?.length) {
|
|
1462
1529
|
const includeMessages = await this._getIncludedMessages(threadId, selectBy);
|
|
@@ -1503,7 +1570,8 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1503
1570
|
const paginatedMessages = messages.slice(start, end);
|
|
1504
1571
|
const hasMore = end < total;
|
|
1505
1572
|
const list = new MessageList({ threadId, resourceId }).add(paginatedMessages, "memory");
|
|
1506
|
-
|
|
1573
|
+
let finalMessages = format === "v2" ? list.get.all.v2() : list.get.all.v1();
|
|
1574
|
+
finalMessages = finalMessages.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
1507
1575
|
return {
|
|
1508
1576
|
messages: finalMessages,
|
|
1509
1577
|
total,
|
|
@@ -1512,19 +1580,23 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1512
1580
|
hasMore
|
|
1513
1581
|
};
|
|
1514
1582
|
} catch (error) {
|
|
1515
|
-
|
|
1583
|
+
const mastraError = new MastraError(
|
|
1516
1584
|
{
|
|
1517
1585
|
id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_PAGINATED_FAILED",
|
|
1518
1586
|
domain: ErrorDomain.STORAGE,
|
|
1519
1587
|
category: ErrorCategory.THIRD_PARTY,
|
|
1520
|
-
details: { threadId }
|
|
1588
|
+
details: { threadId, resourceId: resourceId ?? "" }
|
|
1521
1589
|
},
|
|
1522
1590
|
error
|
|
1523
1591
|
);
|
|
1592
|
+
this.logger?.trackException?.(mastraError);
|
|
1593
|
+
this.logger?.error?.(mastraError.toString());
|
|
1594
|
+
return { messages: [], total: 0, page, perPage, hasMore: false };
|
|
1524
1595
|
}
|
|
1525
1596
|
}
|
|
1526
1597
|
// Helper method to get included messages with context
|
|
1527
1598
|
async _getIncludedMessages(threadId, selectBy) {
|
|
1599
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
1528
1600
|
if (!selectBy?.include?.length) {
|
|
1529
1601
|
return [];
|
|
1530
1602
|
}
|
|
@@ -1791,7 +1863,8 @@ var StoreOperationsDynamoDB = class extends StoreOperations {
|
|
|
1791
1863
|
[TABLE_EVALS]: "eval",
|
|
1792
1864
|
[TABLE_SCORERS]: "score",
|
|
1793
1865
|
[TABLE_TRACES]: "trace",
|
|
1794
|
-
[TABLE_RESOURCES]: "resource"
|
|
1866
|
+
[TABLE_RESOURCES]: "resource",
|
|
1867
|
+
[TABLE_AI_SPANS]: "ai_span"
|
|
1795
1868
|
};
|
|
1796
1869
|
return mapping[tableName] || null;
|
|
1797
1870
|
}
|
|
@@ -2089,8 +2162,17 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
|
|
|
2089
2162
|
}
|
|
2090
2163
|
// Helper function to parse score data (handle JSON fields)
|
|
2091
2164
|
parseScoreData(data) {
|
|
2165
|
+
const result = {};
|
|
2166
|
+
for (const key of Object.keys(SCORERS_SCHEMA)) {
|
|
2167
|
+
if (["traceId", "resourceId", "threadId", "spanId"].includes(key)) {
|
|
2168
|
+
result[key] = data[key] === "" ? null : data[key];
|
|
2169
|
+
continue;
|
|
2170
|
+
}
|
|
2171
|
+
result[key] = data[key];
|
|
2172
|
+
}
|
|
2173
|
+
result.entity = data.entityData ? data.entityData : null;
|
|
2092
2174
|
return {
|
|
2093
|
-
...
|
|
2175
|
+
...result,
|
|
2094
2176
|
// Convert date strings back to Date objects for consistency
|
|
2095
2177
|
createdAt: data.createdAt ? new Date(data.createdAt) : /* @__PURE__ */ new Date(),
|
|
2096
2178
|
updatedAt: data.updatedAt ? new Date(data.updatedAt) : /* @__PURE__ */ new Date()
|
|
@@ -2118,34 +2200,47 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
|
|
|
2118
2200
|
}
|
|
2119
2201
|
}
|
|
2120
2202
|
async saveScore(score) {
|
|
2121
|
-
|
|
2203
|
+
let validatedScore;
|
|
2204
|
+
try {
|
|
2205
|
+
validatedScore = saveScorePayloadSchema.parse(score);
|
|
2206
|
+
} catch (error) {
|
|
2207
|
+
throw new MastraError(
|
|
2208
|
+
{
|
|
2209
|
+
id: "STORAGE_DYNAMODB_STORE_SAVE_SCORE_FAILED",
|
|
2210
|
+
domain: ErrorDomain.STORAGE,
|
|
2211
|
+
category: ErrorCategory.THIRD_PARTY
|
|
2212
|
+
},
|
|
2213
|
+
error
|
|
2214
|
+
);
|
|
2215
|
+
}
|
|
2122
2216
|
const now = /* @__PURE__ */ new Date();
|
|
2123
2217
|
const scoreId = `score-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
2124
2218
|
const scoreData = {
|
|
2125
2219
|
entity: "score",
|
|
2126
2220
|
id: scoreId,
|
|
2127
|
-
scorerId:
|
|
2128
|
-
traceId:
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2221
|
+
scorerId: validatedScore.scorerId,
|
|
2222
|
+
traceId: validatedScore.traceId || "",
|
|
2223
|
+
spanId: validatedScore.spanId || "",
|
|
2224
|
+
runId: validatedScore.runId,
|
|
2225
|
+
scorer: typeof validatedScore.scorer === "string" ? validatedScore.scorer : JSON.stringify(validatedScore.scorer),
|
|
2226
|
+
preprocessStepResult: typeof validatedScore.preprocessStepResult === "string" ? validatedScore.preprocessStepResult : JSON.stringify(validatedScore.preprocessStepResult),
|
|
2227
|
+
analyzeStepResult: typeof validatedScore.analyzeStepResult === "string" ? validatedScore.analyzeStepResult : JSON.stringify(validatedScore.analyzeStepResult),
|
|
2228
|
+
score: validatedScore.score,
|
|
2229
|
+
reason: validatedScore.reason,
|
|
2230
|
+
preprocessPrompt: validatedScore.preprocessPrompt,
|
|
2231
|
+
generateScorePrompt: validatedScore.generateScorePrompt,
|
|
2232
|
+
generateReasonPrompt: validatedScore.generateReasonPrompt,
|
|
2233
|
+
analyzePrompt: validatedScore.analyzePrompt,
|
|
2234
|
+
input: typeof validatedScore.input === "string" ? validatedScore.input : JSON.stringify(validatedScore.input),
|
|
2235
|
+
output: typeof validatedScore.output === "string" ? validatedScore.output : JSON.stringify(validatedScore.output),
|
|
2236
|
+
additionalContext: typeof validatedScore.additionalContext === "string" ? validatedScore.additionalContext : JSON.stringify(validatedScore.additionalContext),
|
|
2237
|
+
runtimeContext: typeof validatedScore.runtimeContext === "string" ? validatedScore.runtimeContext : JSON.stringify(validatedScore.runtimeContext),
|
|
2238
|
+
entityType: validatedScore.entityType,
|
|
2239
|
+
entityData: typeof validatedScore.entity === "string" ? validatedScore.entity : JSON.stringify(validatedScore.entity),
|
|
2240
|
+
entityId: validatedScore.entityId,
|
|
2241
|
+
source: validatedScore.source,
|
|
2242
|
+
resourceId: validatedScore.resourceId || "",
|
|
2243
|
+
threadId: validatedScore.threadId || "",
|
|
2149
2244
|
createdAt: now.toISOString(),
|
|
2150
2245
|
updatedAt: now.toISOString()
|
|
2151
2246
|
};
|
|
@@ -2174,9 +2269,9 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
|
|
|
2174
2269
|
scorerId,
|
|
2175
2270
|
pagination,
|
|
2176
2271
|
entityId,
|
|
2177
|
-
entityType
|
|
2272
|
+
entityType,
|
|
2273
|
+
source
|
|
2178
2274
|
}) {
|
|
2179
|
-
this.logger.debug("Getting scores by scorer ID", { scorerId, pagination, entityId, entityType });
|
|
2180
2275
|
try {
|
|
2181
2276
|
const query = this.service.entities.score.query.byScorer({ entity: "score", scorerId });
|
|
2182
2277
|
const results = await query.go();
|
|
@@ -2187,6 +2282,9 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
|
|
|
2187
2282
|
if (entityType) {
|
|
2188
2283
|
allScores = allScores.filter((score) => score.entityType === entityType);
|
|
2189
2284
|
}
|
|
2285
|
+
if (source) {
|
|
2286
|
+
allScores = allScores.filter((score) => score.source === source);
|
|
2287
|
+
}
|
|
2190
2288
|
allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
2191
2289
|
const startIndex = pagination.page * pagination.perPage;
|
|
2192
2290
|
const endIndex = startIndex + pagination.perPage;
|
|
@@ -2212,6 +2310,7 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
|
|
|
2212
2310
|
scorerId: scorerId || "",
|
|
2213
2311
|
entityId: entityId || "",
|
|
2214
2312
|
entityType: entityType || "",
|
|
2313
|
+
source: source || "",
|
|
2215
2314
|
page: pagination.page,
|
|
2216
2315
|
perPage: pagination.perPage
|
|
2217
2316
|
}
|
|
@@ -2294,6 +2393,43 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
|
|
|
2294
2393
|
);
|
|
2295
2394
|
}
|
|
2296
2395
|
}
|
|
2396
|
+
async getScoresBySpan({
|
|
2397
|
+
traceId,
|
|
2398
|
+
spanId,
|
|
2399
|
+
pagination
|
|
2400
|
+
}) {
|
|
2401
|
+
this.logger.debug("Getting scores by span", { traceId, spanId, pagination });
|
|
2402
|
+
try {
|
|
2403
|
+
const query = this.service.entities.score.query.bySpan({ entity: "score", traceId, spanId });
|
|
2404
|
+
const results = await query.go();
|
|
2405
|
+
const allScores = results.data.map((data) => this.parseScoreData(data));
|
|
2406
|
+
allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
2407
|
+
const startIndex = pagination.page * pagination.perPage;
|
|
2408
|
+
const endIndex = startIndex + pagination.perPage;
|
|
2409
|
+
const paginatedScores = allScores.slice(startIndex, endIndex);
|
|
2410
|
+
const total = allScores.length;
|
|
2411
|
+
const hasMore = endIndex < total;
|
|
2412
|
+
return {
|
|
2413
|
+
scores: paginatedScores,
|
|
2414
|
+
pagination: {
|
|
2415
|
+
total,
|
|
2416
|
+
page: pagination.page,
|
|
2417
|
+
perPage: pagination.perPage,
|
|
2418
|
+
hasMore
|
|
2419
|
+
}
|
|
2420
|
+
};
|
|
2421
|
+
} catch (error) {
|
|
2422
|
+
throw new MastraError(
|
|
2423
|
+
{
|
|
2424
|
+
id: "STORAGE_DYNAMODB_STORE_GET_SCORES_BY_SPAN_FAILED",
|
|
2425
|
+
domain: ErrorDomain.STORAGE,
|
|
2426
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
2427
|
+
details: { traceId, spanId, page: pagination.page, perPage: pagination.perPage }
|
|
2428
|
+
},
|
|
2429
|
+
error
|
|
2430
|
+
);
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2297
2433
|
};
|
|
2298
2434
|
var TracesStorageDynamoDB = class extends TracesStorage {
|
|
2299
2435
|
service;
|
|
@@ -2544,15 +2680,31 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
|
|
|
2544
2680
|
super();
|
|
2545
2681
|
this.service = service;
|
|
2546
2682
|
}
|
|
2683
|
+
updateWorkflowResults({
|
|
2684
|
+
// workflowName,
|
|
2685
|
+
// runId,
|
|
2686
|
+
// stepId,
|
|
2687
|
+
// result,
|
|
2688
|
+
// runtimeContext,
|
|
2689
|
+
}) {
|
|
2690
|
+
throw new Error("Method not implemented.");
|
|
2691
|
+
}
|
|
2692
|
+
updateWorkflowState({
|
|
2693
|
+
// workflowName,
|
|
2694
|
+
// runId,
|
|
2695
|
+
// opts,
|
|
2696
|
+
}) {
|
|
2697
|
+
throw new Error("Method not implemented.");
|
|
2698
|
+
}
|
|
2547
2699
|
// Workflow operations
|
|
2548
2700
|
async persistWorkflowSnapshot({
|
|
2549
2701
|
workflowName,
|
|
2550
2702
|
runId,
|
|
2703
|
+
resourceId,
|
|
2551
2704
|
snapshot
|
|
2552
2705
|
}) {
|
|
2553
2706
|
this.logger.debug("Persisting workflow snapshot", { workflowName, runId });
|
|
2554
2707
|
try {
|
|
2555
|
-
const resourceId = "resourceId" in snapshot ? snapshot.resourceId : void 0;
|
|
2556
2708
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2557
2709
|
const data = {
|
|
2558
2710
|
entity: "workflow_snapshot",
|
|
@@ -2560,7 +2712,6 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
|
|
|
2560
2712
|
workflow_name: workflowName,
|
|
2561
2713
|
run_id: runId,
|
|
2562
2714
|
snapshot: JSON.stringify(snapshot),
|
|
2563
|
-
// Stringify the snapshot object
|
|
2564
2715
|
createdAt: now,
|
|
2565
2716
|
updatedAt: now,
|
|
2566
2717
|
resourceId
|
|
@@ -2632,6 +2783,11 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
|
|
|
2632
2783
|
});
|
|
2633
2784
|
if (pageResults.data && pageResults.data.length > 0) {
|
|
2634
2785
|
let pageFilteredData = pageResults.data;
|
|
2786
|
+
if (args?.status) {
|
|
2787
|
+
pageFilteredData = pageFilteredData.filter((snapshot) => {
|
|
2788
|
+
return snapshot.snapshot.status === args.status;
|
|
2789
|
+
});
|
|
2790
|
+
}
|
|
2635
2791
|
if (args?.fromDate || args?.toDate) {
|
|
2636
2792
|
pageFilteredData = pageFilteredData.filter((snapshot) => {
|
|
2637
2793
|
const createdAt = new Date(snapshot.createdAt);
|
|
@@ -2678,8 +2834,6 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
|
|
|
2678
2834
|
async getWorkflowRunById(args) {
|
|
2679
2835
|
const { runId, workflowName } = args;
|
|
2680
2836
|
this.logger.debug("Getting workflow run by ID", { runId, workflowName });
|
|
2681
|
-
console.log("workflowName", workflowName);
|
|
2682
|
-
console.log("runId", runId);
|
|
2683
2837
|
try {
|
|
2684
2838
|
if (workflowName) {
|
|
2685
2839
|
this.logger.debug("WorkflowName provided, using direct GET operation.");
|
|
@@ -2689,7 +2843,6 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
|
|
|
2689
2843
|
workflow_name: workflowName,
|
|
2690
2844
|
run_id: runId
|
|
2691
2845
|
}).go();
|
|
2692
|
-
console.log("result", result2);
|
|
2693
2846
|
if (!result2.data) {
|
|
2694
2847
|
return null;
|
|
2695
2848
|
}
|
|
@@ -2794,7 +2947,8 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
2794
2947
|
resourceWorkingMemory: true,
|
|
2795
2948
|
hasColumn: false,
|
|
2796
2949
|
createTable: false,
|
|
2797
|
-
deleteMessages: false
|
|
2950
|
+
deleteMessages: false,
|
|
2951
|
+
getScoresBySpan: true
|
|
2798
2952
|
};
|
|
2799
2953
|
}
|
|
2800
2954
|
/**
|
|
@@ -2889,8 +3043,8 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
2889
3043
|
async getThreadById({ threadId }) {
|
|
2890
3044
|
return this.stores.memory.getThreadById({ threadId });
|
|
2891
3045
|
}
|
|
2892
|
-
async getThreadsByResourceId(
|
|
2893
|
-
return this.stores.memory.getThreadsByResourceId(
|
|
3046
|
+
async getThreadsByResourceId(args) {
|
|
3047
|
+
return this.stores.memory.getThreadsByResourceId(args);
|
|
2894
3048
|
}
|
|
2895
3049
|
async saveThread({ thread }) {
|
|
2896
3050
|
return this.stores.memory.saveThread({ thread });
|
|
@@ -2913,6 +3067,12 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
2913
3067
|
}) {
|
|
2914
3068
|
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
|
|
2915
3069
|
}
|
|
3070
|
+
async getMessagesById({
|
|
3071
|
+
messageIds,
|
|
3072
|
+
format
|
|
3073
|
+
}) {
|
|
3074
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
3075
|
+
}
|
|
2916
3076
|
async saveMessages(args) {
|
|
2917
3077
|
return this.stores.memory.saveMessages(args);
|
|
2918
3078
|
}
|
|
@@ -2936,12 +3096,29 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
2936
3096
|
return this.stores.traces.getTracesPaginated(_args);
|
|
2937
3097
|
}
|
|
2938
3098
|
// Workflow operations
|
|
3099
|
+
async updateWorkflowResults({
|
|
3100
|
+
workflowName,
|
|
3101
|
+
runId,
|
|
3102
|
+
stepId,
|
|
3103
|
+
result,
|
|
3104
|
+
runtimeContext
|
|
3105
|
+
}) {
|
|
3106
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
|
|
3107
|
+
}
|
|
3108
|
+
async updateWorkflowState({
|
|
3109
|
+
workflowName,
|
|
3110
|
+
runId,
|
|
3111
|
+
opts
|
|
3112
|
+
}) {
|
|
3113
|
+
return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
|
|
3114
|
+
}
|
|
2939
3115
|
async persistWorkflowSnapshot({
|
|
2940
3116
|
workflowName,
|
|
2941
3117
|
runId,
|
|
3118
|
+
resourceId,
|
|
2942
3119
|
snapshot
|
|
2943
3120
|
}) {
|
|
2944
|
-
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, snapshot });
|
|
3121
|
+
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
|
|
2945
3122
|
}
|
|
2946
3123
|
async loadWorkflowSnapshot({
|
|
2947
3124
|
workflowName,
|
|
@@ -3022,10 +3199,20 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
3022
3199
|
});
|
|
3023
3200
|
}
|
|
3024
3201
|
async getScoresByScorerId({
|
|
3025
|
-
scorerId
|
|
3026
|
-
|
|
3202
|
+
scorerId,
|
|
3203
|
+
source,
|
|
3204
|
+
entityId,
|
|
3205
|
+
entityType,
|
|
3206
|
+
pagination
|
|
3207
|
+
}) {
|
|
3208
|
+
return this.stores.scores.getScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
|
|
3209
|
+
}
|
|
3210
|
+
async getScoresBySpan({
|
|
3211
|
+
traceId,
|
|
3212
|
+
spanId,
|
|
3213
|
+
pagination
|
|
3027
3214
|
}) {
|
|
3028
|
-
return this.stores.scores.
|
|
3215
|
+
return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
|
|
3029
3216
|
}
|
|
3030
3217
|
};
|
|
3031
3218
|
|