@mastra/dynamodb 0.0.0-transpile-packages-20250731152758 → 0.0.0-unified-sidebar-20251010130811
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 +1024 -0
- package/README.md +0 -4
- package/dist/entities/index.d.ts +29 -0
- package/dist/entities/index.d.ts.map +1 -1
- package/dist/entities/score.d.ts +29 -0
- package/dist/entities/score.d.ts.map +1 -1
- package/dist/index.cjs +253 -52
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +254 -53
- 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 +21 -2
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +47 -8
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +22 -12
- package/src/entities/eval.ts +0 -102
- package/src/entities/index.ts +0 -27
- package/src/entities/message.ts +0 -143
- package/src/entities/resource.ts +0 -57
- package/src/entities/score.ts +0 -285
- 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 -285
- 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, 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,28 @@ var scoreEntity = new Entity({
|
|
|
418
423
|
return value;
|
|
419
424
|
}
|
|
420
425
|
},
|
|
426
|
+
preprocessStepResult: {
|
|
427
|
+
type: "string",
|
|
428
|
+
required: false,
|
|
429
|
+
set: (value) => {
|
|
430
|
+
if (value && typeof value !== "string") {
|
|
431
|
+
return JSON.stringify(value);
|
|
432
|
+
}
|
|
433
|
+
return value;
|
|
434
|
+
},
|
|
435
|
+
get: (value) => {
|
|
436
|
+
if (value && typeof value === "string") {
|
|
437
|
+
try {
|
|
438
|
+
if (value.startsWith("{") || value.startsWith("[")) {
|
|
439
|
+
return JSON.parse(value);
|
|
440
|
+
}
|
|
441
|
+
} catch {
|
|
442
|
+
return value;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return value;
|
|
446
|
+
}
|
|
447
|
+
},
|
|
421
448
|
analyzeStepResult: {
|
|
422
449
|
type: "string",
|
|
423
450
|
required: false,
|
|
@@ -456,10 +483,19 @@ var scoreEntity = new Entity({
|
|
|
456
483
|
type: "string",
|
|
457
484
|
required: false
|
|
458
485
|
},
|
|
486
|
+
// Deprecated in favor of generateReasonPrompt
|
|
459
487
|
reasonPrompt: {
|
|
460
488
|
type: "string",
|
|
461
489
|
required: false
|
|
462
490
|
},
|
|
491
|
+
generateScorePrompt: {
|
|
492
|
+
type: "string",
|
|
493
|
+
required: false
|
|
494
|
+
},
|
|
495
|
+
generateReasonPrompt: {
|
|
496
|
+
type: "string",
|
|
497
|
+
required: false
|
|
498
|
+
},
|
|
463
499
|
input: {
|
|
464
500
|
type: "string",
|
|
465
501
|
required: true,
|
|
@@ -625,6 +661,11 @@ var scoreEntity = new Entity({
|
|
|
625
661
|
index: "gsi6",
|
|
626
662
|
pk: { field: "gsi6pk", composite: ["entity", "threadId"] },
|
|
627
663
|
sk: { field: "gsi6sk", composite: ["createdAt"] }
|
|
664
|
+
},
|
|
665
|
+
bySpan: {
|
|
666
|
+
index: "gsi7",
|
|
667
|
+
pk: { field: "gsi7pk", composite: ["entity", "traceId", "spanId"] },
|
|
668
|
+
sk: { field: "gsi7sk", composite: ["createdAt"] }
|
|
628
669
|
}
|
|
629
670
|
}
|
|
630
671
|
});
|
|
@@ -1090,6 +1131,20 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1090
1131
|
// transformed by the ElectroDB entity getters.
|
|
1091
1132
|
};
|
|
1092
1133
|
}
|
|
1134
|
+
// Helper function to transform and sort threads
|
|
1135
|
+
transformAndSortThreads(rawThreads, orderBy, sortDirection) {
|
|
1136
|
+
return rawThreads.map((data) => ({
|
|
1137
|
+
...data,
|
|
1138
|
+
// Convert date strings back to Date objects for consistency
|
|
1139
|
+
createdAt: typeof data.createdAt === "string" ? new Date(data.createdAt) : data.createdAt,
|
|
1140
|
+
updatedAt: typeof data.updatedAt === "string" ? new Date(data.updatedAt) : data.updatedAt
|
|
1141
|
+
})).sort((a, b) => {
|
|
1142
|
+
const fieldA = orderBy === "createdAt" ? a.createdAt : a.updatedAt;
|
|
1143
|
+
const fieldB = orderBy === "createdAt" ? b.createdAt : b.updatedAt;
|
|
1144
|
+
const comparison = fieldA.getTime() - fieldB.getTime();
|
|
1145
|
+
return sortDirection === "DESC" ? -comparison : comparison;
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1093
1148
|
async getThreadById({ threadId }) {
|
|
1094
1149
|
this.logger.debug("Getting thread by ID", { threadId });
|
|
1095
1150
|
try {
|
|
@@ -1118,21 +1173,20 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1118
1173
|
);
|
|
1119
1174
|
}
|
|
1120
1175
|
}
|
|
1121
|
-
|
|
1122
|
-
|
|
1176
|
+
/**
|
|
1177
|
+
* @deprecated use getThreadsByResourceIdPaginated instead for paginated results.
|
|
1178
|
+
*/
|
|
1179
|
+
async getThreadsByResourceId(args) {
|
|
1180
|
+
const resourceId = args.resourceId;
|
|
1181
|
+
const orderBy = this.castThreadOrderBy(args.orderBy);
|
|
1182
|
+
const sortDirection = this.castThreadSortDirection(args.sortDirection);
|
|
1183
|
+
this.logger.debug("Getting threads by resource ID", { resourceId, orderBy, sortDirection });
|
|
1123
1184
|
try {
|
|
1124
1185
|
const result = await this.service.entities.thread.query.byResource({ entity: "thread", resourceId }).go();
|
|
1125
1186
|
if (!result.data.length) {
|
|
1126
1187
|
return [];
|
|
1127
1188
|
}
|
|
1128
|
-
return result.data
|
|
1129
|
-
...data,
|
|
1130
|
-
// Convert date strings back to Date objects for consistency
|
|
1131
|
-
createdAt: typeof data.createdAt === "string" ? new Date(data.createdAt) : data.createdAt,
|
|
1132
|
-
updatedAt: typeof data.updatedAt === "string" ? new Date(data.updatedAt) : data.updatedAt
|
|
1133
|
-
// metadata: data.metadata ? JSON.parse(data.metadata) : undefined, // REMOVED by AI
|
|
1134
|
-
// metadata is already transformed by the entity's getter
|
|
1135
|
-
}));
|
|
1189
|
+
return this.transformAndSortThreads(result.data, orderBy, sortDirection);
|
|
1136
1190
|
} catch (error) {
|
|
1137
1191
|
throw new MastraError(
|
|
1138
1192
|
{
|
|
@@ -1154,7 +1208,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1154
1208
|
resourceId: thread.resourceId,
|
|
1155
1209
|
title: thread.title || `Thread ${thread.id}`,
|
|
1156
1210
|
createdAt: thread.createdAt?.toISOString() || now.toISOString(),
|
|
1157
|
-
updatedAt: now.toISOString(),
|
|
1211
|
+
updatedAt: thread.updatedAt?.toISOString() || now.toISOString(),
|
|
1158
1212
|
metadata: thread.metadata ? JSON.stringify(thread.metadata) : void 0
|
|
1159
1213
|
};
|
|
1160
1214
|
try {
|
|
@@ -1261,6 +1315,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1261
1315
|
}) {
|
|
1262
1316
|
this.logger.debug("Getting messages", { threadId, selectBy });
|
|
1263
1317
|
try {
|
|
1318
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
1264
1319
|
const messages = [];
|
|
1265
1320
|
const limit = resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
|
|
1266
1321
|
if (selectBy?.include?.length) {
|
|
@@ -1309,7 +1364,37 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1309
1364
|
id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_FAILED",
|
|
1310
1365
|
domain: ErrorDomain.STORAGE,
|
|
1311
1366
|
category: ErrorCategory.THIRD_PARTY,
|
|
1312
|
-
details: { threadId }
|
|
1367
|
+
details: { threadId, resourceId: resourceId ?? "" }
|
|
1368
|
+
},
|
|
1369
|
+
error
|
|
1370
|
+
);
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
async getMessagesById({
|
|
1374
|
+
messageIds,
|
|
1375
|
+
format
|
|
1376
|
+
}) {
|
|
1377
|
+
this.logger.debug("Getting messages by ID", { messageIds });
|
|
1378
|
+
if (messageIds.length === 0) return [];
|
|
1379
|
+
try {
|
|
1380
|
+
const results = await Promise.all(
|
|
1381
|
+
messageIds.map((id) => this.service.entities.message.query.primary({ entity: "message", id }).go())
|
|
1382
|
+
);
|
|
1383
|
+
const data = results.map((result) => result.data).flat(1);
|
|
1384
|
+
let parsedMessages = data.map((data2) => this.parseMessageData(data2)).filter((msg) => "content" in msg);
|
|
1385
|
+
const uniqueMessages = parsedMessages.filter(
|
|
1386
|
+
(message, index, self) => index === self.findIndex((m) => m.id === message.id)
|
|
1387
|
+
);
|
|
1388
|
+
const list = new MessageList().add(uniqueMessages, "memory");
|
|
1389
|
+
if (format === `v1`) return list.get.all.v1();
|
|
1390
|
+
return list.get.all.v2();
|
|
1391
|
+
} catch (error) {
|
|
1392
|
+
throw new MastraError(
|
|
1393
|
+
{
|
|
1394
|
+
id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_BY_ID_FAILED",
|
|
1395
|
+
domain: ErrorDomain.STORAGE,
|
|
1396
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1397
|
+
details: { messageIds: JSON.stringify(messageIds) }
|
|
1313
1398
|
},
|
|
1314
1399
|
error
|
|
1315
1400
|
);
|
|
@@ -1389,11 +1474,19 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1389
1474
|
}
|
|
1390
1475
|
async getThreadsByResourceIdPaginated(args) {
|
|
1391
1476
|
const { resourceId, page = 0, perPage = 100 } = args;
|
|
1392
|
-
this.
|
|
1477
|
+
const orderBy = this.castThreadOrderBy(args.orderBy);
|
|
1478
|
+
const sortDirection = this.castThreadSortDirection(args.sortDirection);
|
|
1479
|
+
this.logger.debug("Getting threads by resource ID with pagination", {
|
|
1480
|
+
resourceId,
|
|
1481
|
+
page,
|
|
1482
|
+
perPage,
|
|
1483
|
+
orderBy,
|
|
1484
|
+
sortDirection
|
|
1485
|
+
});
|
|
1393
1486
|
try {
|
|
1394
1487
|
const query = this.service.entities.thread.query.byResource({ entity: "thread", resourceId });
|
|
1395
1488
|
const results = await query.go();
|
|
1396
|
-
const allThreads = results.data;
|
|
1489
|
+
const allThreads = this.transformAndSortThreads(results.data, orderBy, sortDirection);
|
|
1397
1490
|
const startIndex = page * perPage;
|
|
1398
1491
|
const endIndex = startIndex + perPage;
|
|
1399
1492
|
const paginatedThreads = allThreads.slice(startIndex, endIndex);
|
|
@@ -1426,6 +1519,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1426
1519
|
const limit = resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
|
|
1427
1520
|
this.logger.debug("Getting messages with pagination", { threadId, page, perPage, fromDate, toDate, limit });
|
|
1428
1521
|
try {
|
|
1522
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
1429
1523
|
let messages = [];
|
|
1430
1524
|
if (selectBy?.include?.length) {
|
|
1431
1525
|
const includeMessages = await this._getIncludedMessages(threadId, selectBy);
|
|
@@ -1481,19 +1575,23 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1481
1575
|
hasMore
|
|
1482
1576
|
};
|
|
1483
1577
|
} catch (error) {
|
|
1484
|
-
|
|
1578
|
+
const mastraError = new MastraError(
|
|
1485
1579
|
{
|
|
1486
1580
|
id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_PAGINATED_FAILED",
|
|
1487
1581
|
domain: ErrorDomain.STORAGE,
|
|
1488
1582
|
category: ErrorCategory.THIRD_PARTY,
|
|
1489
|
-
details: { threadId }
|
|
1583
|
+
details: { threadId, resourceId: resourceId ?? "" }
|
|
1490
1584
|
},
|
|
1491
1585
|
error
|
|
1492
1586
|
);
|
|
1587
|
+
this.logger?.trackException?.(mastraError);
|
|
1588
|
+
this.logger?.error?.(mastraError.toString());
|
|
1589
|
+
return { messages: [], total: 0, page, perPage, hasMore: false };
|
|
1493
1590
|
}
|
|
1494
1591
|
}
|
|
1495
1592
|
// Helper method to get included messages with context
|
|
1496
1593
|
async _getIncludedMessages(threadId, selectBy) {
|
|
1594
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
1497
1595
|
if (!selectBy?.include?.length) {
|
|
1498
1596
|
return [];
|
|
1499
1597
|
}
|
|
@@ -1760,7 +1858,8 @@ var StoreOperationsDynamoDB = class extends StoreOperations {
|
|
|
1760
1858
|
[TABLE_EVALS]: "eval",
|
|
1761
1859
|
[TABLE_SCORERS]: "score",
|
|
1762
1860
|
[TABLE_TRACES]: "trace",
|
|
1763
|
-
[TABLE_RESOURCES]: "resource"
|
|
1861
|
+
[TABLE_RESOURCES]: "resource",
|
|
1862
|
+
[TABLE_AI_SPANS]: "ai_span"
|
|
1764
1863
|
};
|
|
1765
1864
|
return mapping[tableName] || null;
|
|
1766
1865
|
}
|
|
@@ -2087,33 +2186,47 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
|
|
|
2087
2186
|
}
|
|
2088
2187
|
}
|
|
2089
2188
|
async saveScore(score) {
|
|
2090
|
-
|
|
2189
|
+
let validatedScore;
|
|
2190
|
+
try {
|
|
2191
|
+
validatedScore = saveScorePayloadSchema.parse(score);
|
|
2192
|
+
} catch (error) {
|
|
2193
|
+
throw new MastraError(
|
|
2194
|
+
{
|
|
2195
|
+
id: "STORAGE_DYNAMODB_STORE_SAVE_SCORE_FAILED",
|
|
2196
|
+
domain: ErrorDomain.STORAGE,
|
|
2197
|
+
category: ErrorCategory.THIRD_PARTY
|
|
2198
|
+
},
|
|
2199
|
+
error
|
|
2200
|
+
);
|
|
2201
|
+
}
|
|
2091
2202
|
const now = /* @__PURE__ */ new Date();
|
|
2092
2203
|
const scoreId = `score-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
2093
2204
|
const scoreData = {
|
|
2094
2205
|
entity: "score",
|
|
2095
2206
|
id: scoreId,
|
|
2096
|
-
scorerId:
|
|
2097
|
-
traceId:
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2207
|
+
scorerId: validatedScore.scorerId,
|
|
2208
|
+
traceId: validatedScore.traceId || "",
|
|
2209
|
+
spanId: validatedScore.spanId || "",
|
|
2210
|
+
runId: validatedScore.runId,
|
|
2211
|
+
scorer: typeof validatedScore.scorer === "string" ? validatedScore.scorer : JSON.stringify(validatedScore.scorer),
|
|
2212
|
+
preprocessStepResult: typeof validatedScore.preprocessStepResult === "string" ? validatedScore.preprocessStepResult : JSON.stringify(validatedScore.preprocessStepResult),
|
|
2213
|
+
analyzeStepResult: typeof validatedScore.analyzeStepResult === "string" ? validatedScore.analyzeStepResult : JSON.stringify(validatedScore.analyzeStepResult),
|
|
2214
|
+
score: validatedScore.score,
|
|
2215
|
+
reason: validatedScore.reason,
|
|
2216
|
+
preprocessPrompt: validatedScore.preprocessPrompt,
|
|
2217
|
+
generateScorePrompt: validatedScore.generateScorePrompt,
|
|
2218
|
+
generateReasonPrompt: validatedScore.generateReasonPrompt,
|
|
2219
|
+
analyzePrompt: validatedScore.analyzePrompt,
|
|
2220
|
+
input: typeof validatedScore.input === "string" ? validatedScore.input : JSON.stringify(validatedScore.input),
|
|
2221
|
+
output: typeof validatedScore.output === "string" ? validatedScore.output : JSON.stringify(validatedScore.output),
|
|
2222
|
+
additionalContext: typeof validatedScore.additionalContext === "string" ? validatedScore.additionalContext : JSON.stringify(validatedScore.additionalContext),
|
|
2223
|
+
runtimeContext: typeof validatedScore.runtimeContext === "string" ? validatedScore.runtimeContext : JSON.stringify(validatedScore.runtimeContext),
|
|
2224
|
+
entityType: validatedScore.entityType,
|
|
2225
|
+
entityData: typeof validatedScore.entity === "string" ? validatedScore.entity : JSON.stringify(validatedScore.entity),
|
|
2226
|
+
entityId: validatedScore.entityId,
|
|
2227
|
+
source: validatedScore.source,
|
|
2228
|
+
resourceId: validatedScore.resourceId || "",
|
|
2229
|
+
threadId: validatedScore.threadId || "",
|
|
2117
2230
|
createdAt: now.toISOString(),
|
|
2118
2231
|
updatedAt: now.toISOString()
|
|
2119
2232
|
};
|
|
@@ -2142,9 +2255,9 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
|
|
|
2142
2255
|
scorerId,
|
|
2143
2256
|
pagination,
|
|
2144
2257
|
entityId,
|
|
2145
|
-
entityType
|
|
2258
|
+
entityType,
|
|
2259
|
+
source
|
|
2146
2260
|
}) {
|
|
2147
|
-
this.logger.debug("Getting scores by scorer ID", { scorerId, pagination, entityId, entityType });
|
|
2148
2261
|
try {
|
|
2149
2262
|
const query = this.service.entities.score.query.byScorer({ entity: "score", scorerId });
|
|
2150
2263
|
const results = await query.go();
|
|
@@ -2155,6 +2268,9 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
|
|
|
2155
2268
|
if (entityType) {
|
|
2156
2269
|
allScores = allScores.filter((score) => score.entityType === entityType);
|
|
2157
2270
|
}
|
|
2271
|
+
if (source) {
|
|
2272
|
+
allScores = allScores.filter((score) => score.source === source);
|
|
2273
|
+
}
|
|
2158
2274
|
allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
2159
2275
|
const startIndex = pagination.page * pagination.perPage;
|
|
2160
2276
|
const endIndex = startIndex + pagination.perPage;
|
|
@@ -2180,6 +2296,7 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
|
|
|
2180
2296
|
scorerId: scorerId || "",
|
|
2181
2297
|
entityId: entityId || "",
|
|
2182
2298
|
entityType: entityType || "",
|
|
2299
|
+
source: source || "",
|
|
2183
2300
|
page: pagination.page,
|
|
2184
2301
|
perPage: pagination.perPage
|
|
2185
2302
|
}
|
|
@@ -2262,6 +2379,43 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
|
|
|
2262
2379
|
);
|
|
2263
2380
|
}
|
|
2264
2381
|
}
|
|
2382
|
+
async getScoresBySpan({
|
|
2383
|
+
traceId,
|
|
2384
|
+
spanId,
|
|
2385
|
+
pagination
|
|
2386
|
+
}) {
|
|
2387
|
+
this.logger.debug("Getting scores by span", { traceId, spanId, pagination });
|
|
2388
|
+
try {
|
|
2389
|
+
const query = this.service.entities.score.query.bySpan({ entity: "score", traceId, spanId });
|
|
2390
|
+
const results = await query.go();
|
|
2391
|
+
const allScores = results.data.map((data) => this.parseScoreData(data));
|
|
2392
|
+
allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
2393
|
+
const startIndex = pagination.page * pagination.perPage;
|
|
2394
|
+
const endIndex = startIndex + pagination.perPage;
|
|
2395
|
+
const paginatedScores = allScores.slice(startIndex, endIndex);
|
|
2396
|
+
const total = allScores.length;
|
|
2397
|
+
const hasMore = endIndex < total;
|
|
2398
|
+
return {
|
|
2399
|
+
scores: paginatedScores,
|
|
2400
|
+
pagination: {
|
|
2401
|
+
total,
|
|
2402
|
+
page: pagination.page,
|
|
2403
|
+
perPage: pagination.perPage,
|
|
2404
|
+
hasMore
|
|
2405
|
+
}
|
|
2406
|
+
};
|
|
2407
|
+
} catch (error) {
|
|
2408
|
+
throw new MastraError(
|
|
2409
|
+
{
|
|
2410
|
+
id: "STORAGE_DYNAMODB_STORE_GET_SCORES_BY_SPAN_FAILED",
|
|
2411
|
+
domain: ErrorDomain.STORAGE,
|
|
2412
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
2413
|
+
details: { traceId, spanId, page: pagination.page, perPage: pagination.perPage }
|
|
2414
|
+
},
|
|
2415
|
+
error
|
|
2416
|
+
);
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2265
2419
|
};
|
|
2266
2420
|
var TracesStorageDynamoDB = class extends TracesStorage {
|
|
2267
2421
|
service;
|
|
@@ -2512,15 +2666,31 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
|
|
|
2512
2666
|
super();
|
|
2513
2667
|
this.service = service;
|
|
2514
2668
|
}
|
|
2669
|
+
updateWorkflowResults({
|
|
2670
|
+
// workflowName,
|
|
2671
|
+
// runId,
|
|
2672
|
+
// stepId,
|
|
2673
|
+
// result,
|
|
2674
|
+
// runtimeContext,
|
|
2675
|
+
}) {
|
|
2676
|
+
throw new Error("Method not implemented.");
|
|
2677
|
+
}
|
|
2678
|
+
updateWorkflowState({
|
|
2679
|
+
// workflowName,
|
|
2680
|
+
// runId,
|
|
2681
|
+
// opts,
|
|
2682
|
+
}) {
|
|
2683
|
+
throw new Error("Method not implemented.");
|
|
2684
|
+
}
|
|
2515
2685
|
// Workflow operations
|
|
2516
2686
|
async persistWorkflowSnapshot({
|
|
2517
2687
|
workflowName,
|
|
2518
2688
|
runId,
|
|
2689
|
+
resourceId,
|
|
2519
2690
|
snapshot
|
|
2520
2691
|
}) {
|
|
2521
2692
|
this.logger.debug("Persisting workflow snapshot", { workflowName, runId });
|
|
2522
2693
|
try {
|
|
2523
|
-
const resourceId = "resourceId" in snapshot ? snapshot.resourceId : void 0;
|
|
2524
2694
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2525
2695
|
const data = {
|
|
2526
2696
|
entity: "workflow_snapshot",
|
|
@@ -2646,8 +2816,6 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
|
|
|
2646
2816
|
async getWorkflowRunById(args) {
|
|
2647
2817
|
const { runId, workflowName } = args;
|
|
2648
2818
|
this.logger.debug("Getting workflow run by ID", { runId, workflowName });
|
|
2649
|
-
console.log("workflowName", workflowName);
|
|
2650
|
-
console.log("runId", runId);
|
|
2651
2819
|
try {
|
|
2652
2820
|
if (workflowName) {
|
|
2653
2821
|
this.logger.debug("WorkflowName provided, using direct GET operation.");
|
|
@@ -2657,7 +2825,6 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
|
|
|
2657
2825
|
workflow_name: workflowName,
|
|
2658
2826
|
run_id: runId
|
|
2659
2827
|
}).go();
|
|
2660
|
-
console.log("result", result2);
|
|
2661
2828
|
if (!result2.data) {
|
|
2662
2829
|
return null;
|
|
2663
2830
|
}
|
|
@@ -2762,7 +2929,8 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
2762
2929
|
resourceWorkingMemory: true,
|
|
2763
2930
|
hasColumn: false,
|
|
2764
2931
|
createTable: false,
|
|
2765
|
-
deleteMessages: false
|
|
2932
|
+
deleteMessages: false,
|
|
2933
|
+
getScoresBySpan: true
|
|
2766
2934
|
};
|
|
2767
2935
|
}
|
|
2768
2936
|
/**
|
|
@@ -2857,8 +3025,8 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
2857
3025
|
async getThreadById({ threadId }) {
|
|
2858
3026
|
return this.stores.memory.getThreadById({ threadId });
|
|
2859
3027
|
}
|
|
2860
|
-
async getThreadsByResourceId(
|
|
2861
|
-
return this.stores.memory.getThreadsByResourceId(
|
|
3028
|
+
async getThreadsByResourceId(args) {
|
|
3029
|
+
return this.stores.memory.getThreadsByResourceId(args);
|
|
2862
3030
|
}
|
|
2863
3031
|
async saveThread({ thread }) {
|
|
2864
3032
|
return this.stores.memory.saveThread({ thread });
|
|
@@ -2881,6 +3049,12 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
2881
3049
|
}) {
|
|
2882
3050
|
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
|
|
2883
3051
|
}
|
|
3052
|
+
async getMessagesById({
|
|
3053
|
+
messageIds,
|
|
3054
|
+
format
|
|
3055
|
+
}) {
|
|
3056
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
3057
|
+
}
|
|
2884
3058
|
async saveMessages(args) {
|
|
2885
3059
|
return this.stores.memory.saveMessages(args);
|
|
2886
3060
|
}
|
|
@@ -2904,12 +3078,29 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
2904
3078
|
return this.stores.traces.getTracesPaginated(_args);
|
|
2905
3079
|
}
|
|
2906
3080
|
// Workflow operations
|
|
3081
|
+
async updateWorkflowResults({
|
|
3082
|
+
workflowName,
|
|
3083
|
+
runId,
|
|
3084
|
+
stepId,
|
|
3085
|
+
result,
|
|
3086
|
+
runtimeContext
|
|
3087
|
+
}) {
|
|
3088
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
|
|
3089
|
+
}
|
|
3090
|
+
async updateWorkflowState({
|
|
3091
|
+
workflowName,
|
|
3092
|
+
runId,
|
|
3093
|
+
opts
|
|
3094
|
+
}) {
|
|
3095
|
+
return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
|
|
3096
|
+
}
|
|
2907
3097
|
async persistWorkflowSnapshot({
|
|
2908
3098
|
workflowName,
|
|
2909
3099
|
runId,
|
|
3100
|
+
resourceId,
|
|
2910
3101
|
snapshot
|
|
2911
3102
|
}) {
|
|
2912
|
-
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, snapshot });
|
|
3103
|
+
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
|
|
2913
3104
|
}
|
|
2914
3105
|
async loadWorkflowSnapshot({
|
|
2915
3106
|
workflowName,
|
|
@@ -2990,10 +3181,20 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
2990
3181
|
});
|
|
2991
3182
|
}
|
|
2992
3183
|
async getScoresByScorerId({
|
|
2993
|
-
scorerId
|
|
2994
|
-
|
|
3184
|
+
scorerId,
|
|
3185
|
+
source,
|
|
3186
|
+
entityId,
|
|
3187
|
+
entityType,
|
|
3188
|
+
pagination
|
|
3189
|
+
}) {
|
|
3190
|
+
return this.stores.scores.getScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
|
|
3191
|
+
}
|
|
3192
|
+
async getScoresBySpan({
|
|
3193
|
+
traceId,
|
|
3194
|
+
spanId,
|
|
3195
|
+
pagination
|
|
2995
3196
|
}) {
|
|
2996
|
-
return this.stores.scores.
|
|
3197
|
+
return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
|
|
2997
3198
|
}
|
|
2998
3199
|
};
|
|
2999
3200
|
|