@mastra/dynamodb 0.0.0-update-scorers-api-20250801170445 → 0.0.0-usechat-duplicate-20251016110554
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 +1048 -0
- package/README.md +0 -4
- package/dist/entities/index.d.ts +15 -0
- package/dist/entities/index.d.ts.map +1 -1
- package/dist/entities/score.d.ts +15 -0
- package/dist/entities/score.d.ts.map +1 -1
- package/dist/index.cjs +222 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +223 -54
- 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 -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/README.md
CHANGED
|
@@ -138,7 +138,3 @@ This implementation uses a single-table design pattern with ElectroDB, which off
|
|
|
138
138
|
3. **Simplified administration**: Only one table to monitor and back up
|
|
139
139
|
4. **Reduced complexity**: Consistent access patterns across entities
|
|
140
140
|
5. **Transaction support**: Atomic operations across different entity types
|
|
141
|
-
|
|
142
|
-
## License
|
|
143
|
-
|
|
144
|
-
MIT
|
package/dist/entities/index.d.ts
CHANGED
|
@@ -534,6 +534,10 @@ export declare function getElectroDbService(client: DynamoDBDocumentClient, tabl
|
|
|
534
534
|
type: "string";
|
|
535
535
|
required: false;
|
|
536
536
|
};
|
|
537
|
+
spanId: {
|
|
538
|
+
type: "string";
|
|
539
|
+
required: false;
|
|
540
|
+
};
|
|
537
541
|
runId: {
|
|
538
542
|
type: "string";
|
|
539
543
|
required: true;
|
|
@@ -740,6 +744,17 @@ export declare function getElectroDbService(client: DynamoDBDocumentClient, tabl
|
|
|
740
744
|
composite: "createdAt"[];
|
|
741
745
|
};
|
|
742
746
|
};
|
|
747
|
+
bySpan: {
|
|
748
|
+
index: string;
|
|
749
|
+
pk: {
|
|
750
|
+
field: string;
|
|
751
|
+
composite: ("entity" | "traceId" | "spanId")[];
|
|
752
|
+
};
|
|
753
|
+
sk: {
|
|
754
|
+
field: string;
|
|
755
|
+
composite: "createdAt"[];
|
|
756
|
+
};
|
|
757
|
+
};
|
|
743
758
|
};
|
|
744
759
|
}>;
|
|
745
760
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entities/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entities/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgBpF"}
|
package/dist/entities/score.d.ts
CHANGED
|
@@ -18,6 +18,10 @@ export declare const scoreEntity: Entity<string, string, string, {
|
|
|
18
18
|
type: "string";
|
|
19
19
|
required: false;
|
|
20
20
|
};
|
|
21
|
+
spanId: {
|
|
22
|
+
type: "string";
|
|
23
|
+
required: false;
|
|
24
|
+
};
|
|
21
25
|
runId: {
|
|
22
26
|
type: "string";
|
|
23
27
|
required: true;
|
|
@@ -224,6 +228,17 @@ export declare const scoreEntity: Entity<string, string, string, {
|
|
|
224
228
|
composite: "createdAt"[];
|
|
225
229
|
};
|
|
226
230
|
};
|
|
231
|
+
bySpan: {
|
|
232
|
+
index: string;
|
|
233
|
+
pk: {
|
|
234
|
+
field: string;
|
|
235
|
+
composite: ("entity" | "traceId" | "spanId")[];
|
|
236
|
+
};
|
|
237
|
+
sk: {
|
|
238
|
+
field: string;
|
|
239
|
+
composite: "createdAt"[];
|
|
240
|
+
};
|
|
241
|
+
};
|
|
227
242
|
};
|
|
228
243
|
}>;
|
|
229
244
|
//# sourceMappingURL=score.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"score.d.ts","sourceRoot":"","sources":["../../src/entities/score.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGnC,eAAO,MAAM,WAAW
|
|
1
|
+
{"version":3,"file":"score.d.ts","sourceRoot":"","sources":["../../src/entities/score.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGnC,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAmCJ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BA8CN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;;;;;0BAoBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuExB,CAAC"}
|
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 scores = require('@mastra/core/scores');
|
|
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
|
|
@@ -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
|
});
|
|
@@ -1123,6 +1133,20 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1123
1133
|
// transformed by the ElectroDB entity getters.
|
|
1124
1134
|
};
|
|
1125
1135
|
}
|
|
1136
|
+
// Helper function to transform and sort threads
|
|
1137
|
+
transformAndSortThreads(rawThreads, orderBy, sortDirection) {
|
|
1138
|
+
return rawThreads.map((data) => ({
|
|
1139
|
+
...data,
|
|
1140
|
+
// Convert date strings back to Date objects for consistency
|
|
1141
|
+
createdAt: typeof data.createdAt === "string" ? new Date(data.createdAt) : data.createdAt,
|
|
1142
|
+
updatedAt: typeof data.updatedAt === "string" ? new Date(data.updatedAt) : data.updatedAt
|
|
1143
|
+
})).sort((a, b) => {
|
|
1144
|
+
const fieldA = orderBy === "createdAt" ? a.createdAt : a.updatedAt;
|
|
1145
|
+
const fieldB = orderBy === "createdAt" ? b.createdAt : b.updatedAt;
|
|
1146
|
+
const comparison = fieldA.getTime() - fieldB.getTime();
|
|
1147
|
+
return sortDirection === "DESC" ? -comparison : comparison;
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1126
1150
|
async getThreadById({ threadId }) {
|
|
1127
1151
|
this.logger.debug("Getting thread by ID", { threadId });
|
|
1128
1152
|
try {
|
|
@@ -1151,21 +1175,20 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1151
1175
|
);
|
|
1152
1176
|
}
|
|
1153
1177
|
}
|
|
1154
|
-
|
|
1155
|
-
|
|
1178
|
+
/**
|
|
1179
|
+
* @deprecated use getThreadsByResourceIdPaginated instead for paginated results.
|
|
1180
|
+
*/
|
|
1181
|
+
async getThreadsByResourceId(args) {
|
|
1182
|
+
const resourceId = args.resourceId;
|
|
1183
|
+
const orderBy = this.castThreadOrderBy(args.orderBy);
|
|
1184
|
+
const sortDirection = this.castThreadSortDirection(args.sortDirection);
|
|
1185
|
+
this.logger.debug("Getting threads by resource ID", { resourceId, orderBy, sortDirection });
|
|
1156
1186
|
try {
|
|
1157
1187
|
const result = await this.service.entities.thread.query.byResource({ entity: "thread", resourceId }).go();
|
|
1158
1188
|
if (!result.data.length) {
|
|
1159
1189
|
return [];
|
|
1160
1190
|
}
|
|
1161
|
-
return result.data
|
|
1162
|
-
...data,
|
|
1163
|
-
// Convert date strings back to Date objects for consistency
|
|
1164
|
-
createdAt: typeof data.createdAt === "string" ? new Date(data.createdAt) : data.createdAt,
|
|
1165
|
-
updatedAt: typeof data.updatedAt === "string" ? new Date(data.updatedAt) : data.updatedAt
|
|
1166
|
-
// metadata: data.metadata ? JSON.parse(data.metadata) : undefined, // REMOVED by AI
|
|
1167
|
-
// metadata is already transformed by the entity's getter
|
|
1168
|
-
}));
|
|
1191
|
+
return this.transformAndSortThreads(result.data, orderBy, sortDirection);
|
|
1169
1192
|
} catch (error$1) {
|
|
1170
1193
|
throw new error.MastraError(
|
|
1171
1194
|
{
|
|
@@ -1187,7 +1210,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1187
1210
|
resourceId: thread.resourceId,
|
|
1188
1211
|
title: thread.title || `Thread ${thread.id}`,
|
|
1189
1212
|
createdAt: thread.createdAt?.toISOString() || now.toISOString(),
|
|
1190
|
-
updatedAt: now.toISOString(),
|
|
1213
|
+
updatedAt: thread.updatedAt?.toISOString() || now.toISOString(),
|
|
1191
1214
|
metadata: thread.metadata ? JSON.stringify(thread.metadata) : void 0
|
|
1192
1215
|
};
|
|
1193
1216
|
try {
|
|
@@ -1294,6 +1317,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1294
1317
|
}) {
|
|
1295
1318
|
this.logger.debug("Getting messages", { threadId, selectBy });
|
|
1296
1319
|
try {
|
|
1320
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
1297
1321
|
const messages = [];
|
|
1298
1322
|
const limit = storage.resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
|
|
1299
1323
|
if (selectBy?.include?.length) {
|
|
@@ -1342,7 +1366,37 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1342
1366
|
id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_FAILED",
|
|
1343
1367
|
domain: error.ErrorDomain.STORAGE,
|
|
1344
1368
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1345
|
-
details: { threadId }
|
|
1369
|
+
details: { threadId, resourceId: resourceId ?? "" }
|
|
1370
|
+
},
|
|
1371
|
+
error$1
|
|
1372
|
+
);
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
async getMessagesById({
|
|
1376
|
+
messageIds,
|
|
1377
|
+
format
|
|
1378
|
+
}) {
|
|
1379
|
+
this.logger.debug("Getting messages by ID", { messageIds });
|
|
1380
|
+
if (messageIds.length === 0) return [];
|
|
1381
|
+
try {
|
|
1382
|
+
const results = await Promise.all(
|
|
1383
|
+
messageIds.map((id) => this.service.entities.message.query.primary({ entity: "message", id }).go())
|
|
1384
|
+
);
|
|
1385
|
+
const data = results.map((result) => result.data).flat(1);
|
|
1386
|
+
let parsedMessages = data.map((data2) => this.parseMessageData(data2)).filter((msg) => "content" in msg);
|
|
1387
|
+
const uniqueMessages = parsedMessages.filter(
|
|
1388
|
+
(message, index, self) => index === self.findIndex((m) => m.id === message.id)
|
|
1389
|
+
);
|
|
1390
|
+
const list = new agent.MessageList().add(uniqueMessages, "memory");
|
|
1391
|
+
if (format === `v1`) return list.get.all.v1();
|
|
1392
|
+
return list.get.all.v2();
|
|
1393
|
+
} catch (error$1) {
|
|
1394
|
+
throw new error.MastraError(
|
|
1395
|
+
{
|
|
1396
|
+
id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_BY_ID_FAILED",
|
|
1397
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1398
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1399
|
+
details: { messageIds: JSON.stringify(messageIds) }
|
|
1346
1400
|
},
|
|
1347
1401
|
error$1
|
|
1348
1402
|
);
|
|
@@ -1422,11 +1476,19 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1422
1476
|
}
|
|
1423
1477
|
async getThreadsByResourceIdPaginated(args) {
|
|
1424
1478
|
const { resourceId, page = 0, perPage = 100 } = args;
|
|
1425
|
-
this.
|
|
1479
|
+
const orderBy = this.castThreadOrderBy(args.orderBy);
|
|
1480
|
+
const sortDirection = this.castThreadSortDirection(args.sortDirection);
|
|
1481
|
+
this.logger.debug("Getting threads by resource ID with pagination", {
|
|
1482
|
+
resourceId,
|
|
1483
|
+
page,
|
|
1484
|
+
perPage,
|
|
1485
|
+
orderBy,
|
|
1486
|
+
sortDirection
|
|
1487
|
+
});
|
|
1426
1488
|
try {
|
|
1427
1489
|
const query = this.service.entities.thread.query.byResource({ entity: "thread", resourceId });
|
|
1428
1490
|
const results = await query.go();
|
|
1429
|
-
const allThreads = results.data;
|
|
1491
|
+
const allThreads = this.transformAndSortThreads(results.data, orderBy, sortDirection);
|
|
1430
1492
|
const startIndex = page * perPage;
|
|
1431
1493
|
const endIndex = startIndex + perPage;
|
|
1432
1494
|
const paginatedThreads = allThreads.slice(startIndex, endIndex);
|
|
@@ -1459,6 +1521,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1459
1521
|
const limit = storage.resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
|
|
1460
1522
|
this.logger.debug("Getting messages with pagination", { threadId, page, perPage, fromDate, toDate, limit });
|
|
1461
1523
|
try {
|
|
1524
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
1462
1525
|
let messages = [];
|
|
1463
1526
|
if (selectBy?.include?.length) {
|
|
1464
1527
|
const includeMessages = await this._getIncludedMessages(threadId, selectBy);
|
|
@@ -1514,19 +1577,23 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1514
1577
|
hasMore
|
|
1515
1578
|
};
|
|
1516
1579
|
} catch (error$1) {
|
|
1517
|
-
|
|
1580
|
+
const mastraError = new error.MastraError(
|
|
1518
1581
|
{
|
|
1519
1582
|
id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_PAGINATED_FAILED",
|
|
1520
1583
|
domain: error.ErrorDomain.STORAGE,
|
|
1521
1584
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1522
|
-
details: { threadId }
|
|
1585
|
+
details: { threadId, resourceId: resourceId ?? "" }
|
|
1523
1586
|
},
|
|
1524
1587
|
error$1
|
|
1525
1588
|
);
|
|
1589
|
+
this.logger?.trackException?.(mastraError);
|
|
1590
|
+
this.logger?.error?.(mastraError.toString());
|
|
1591
|
+
return { messages: [], total: 0, page, perPage, hasMore: false };
|
|
1526
1592
|
}
|
|
1527
1593
|
}
|
|
1528
1594
|
// Helper method to get included messages with context
|
|
1529
1595
|
async _getIncludedMessages(threadId, selectBy) {
|
|
1596
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
1530
1597
|
if (!selectBy?.include?.length) {
|
|
1531
1598
|
return [];
|
|
1532
1599
|
}
|
|
@@ -1793,7 +1860,8 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
|
|
|
1793
1860
|
[storage.TABLE_EVALS]: "eval",
|
|
1794
1861
|
[storage.TABLE_SCORERS]: "score",
|
|
1795
1862
|
[storage.TABLE_TRACES]: "trace",
|
|
1796
|
-
[storage.TABLE_RESOURCES]: "resource"
|
|
1863
|
+
[storage.TABLE_RESOURCES]: "resource",
|
|
1864
|
+
[storage.TABLE_AI_SPANS]: "ai_span"
|
|
1797
1865
|
};
|
|
1798
1866
|
return mapping[tableName] || null;
|
|
1799
1867
|
}
|
|
@@ -2120,34 +2188,47 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2120
2188
|
}
|
|
2121
2189
|
}
|
|
2122
2190
|
async saveScore(score) {
|
|
2123
|
-
|
|
2191
|
+
let validatedScore;
|
|
2192
|
+
try {
|
|
2193
|
+
validatedScore = scores.saveScorePayloadSchema.parse(score);
|
|
2194
|
+
} catch (error$1) {
|
|
2195
|
+
throw new error.MastraError(
|
|
2196
|
+
{
|
|
2197
|
+
id: "STORAGE_DYNAMODB_STORE_SAVE_SCORE_FAILED",
|
|
2198
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2199
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
2200
|
+
},
|
|
2201
|
+
error$1
|
|
2202
|
+
);
|
|
2203
|
+
}
|
|
2124
2204
|
const now = /* @__PURE__ */ new Date();
|
|
2125
2205
|
const scoreId = `score-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
2126
2206
|
const scoreData = {
|
|
2127
2207
|
entity: "score",
|
|
2128
2208
|
id: scoreId,
|
|
2129
|
-
scorerId:
|
|
2130
|
-
traceId:
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2209
|
+
scorerId: validatedScore.scorerId,
|
|
2210
|
+
traceId: validatedScore.traceId || "",
|
|
2211
|
+
spanId: validatedScore.spanId || "",
|
|
2212
|
+
runId: validatedScore.runId,
|
|
2213
|
+
scorer: typeof validatedScore.scorer === "string" ? validatedScore.scorer : JSON.stringify(validatedScore.scorer),
|
|
2214
|
+
preprocessStepResult: typeof validatedScore.preprocessStepResult === "string" ? validatedScore.preprocessStepResult : JSON.stringify(validatedScore.preprocessStepResult),
|
|
2215
|
+
analyzeStepResult: typeof validatedScore.analyzeStepResult === "string" ? validatedScore.analyzeStepResult : JSON.stringify(validatedScore.analyzeStepResult),
|
|
2216
|
+
score: validatedScore.score,
|
|
2217
|
+
reason: validatedScore.reason,
|
|
2218
|
+
preprocessPrompt: validatedScore.preprocessPrompt,
|
|
2219
|
+
generateScorePrompt: validatedScore.generateScorePrompt,
|
|
2220
|
+
generateReasonPrompt: validatedScore.generateReasonPrompt,
|
|
2221
|
+
analyzePrompt: validatedScore.analyzePrompt,
|
|
2222
|
+
input: typeof validatedScore.input === "string" ? validatedScore.input : JSON.stringify(validatedScore.input),
|
|
2223
|
+
output: typeof validatedScore.output === "string" ? validatedScore.output : JSON.stringify(validatedScore.output),
|
|
2224
|
+
additionalContext: typeof validatedScore.additionalContext === "string" ? validatedScore.additionalContext : JSON.stringify(validatedScore.additionalContext),
|
|
2225
|
+
runtimeContext: typeof validatedScore.runtimeContext === "string" ? validatedScore.runtimeContext : JSON.stringify(validatedScore.runtimeContext),
|
|
2226
|
+
entityType: validatedScore.entityType,
|
|
2227
|
+
entityData: typeof validatedScore.entity === "string" ? validatedScore.entity : JSON.stringify(validatedScore.entity),
|
|
2228
|
+
entityId: validatedScore.entityId,
|
|
2229
|
+
source: validatedScore.source,
|
|
2230
|
+
resourceId: validatedScore.resourceId || "",
|
|
2231
|
+
threadId: validatedScore.threadId || "",
|
|
2151
2232
|
createdAt: now.toISOString(),
|
|
2152
2233
|
updatedAt: now.toISOString()
|
|
2153
2234
|
};
|
|
@@ -2176,9 +2257,9 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2176
2257
|
scorerId,
|
|
2177
2258
|
pagination,
|
|
2178
2259
|
entityId,
|
|
2179
|
-
entityType
|
|
2260
|
+
entityType,
|
|
2261
|
+
source
|
|
2180
2262
|
}) {
|
|
2181
|
-
this.logger.debug("Getting scores by scorer ID", { scorerId, pagination, entityId, entityType });
|
|
2182
2263
|
try {
|
|
2183
2264
|
const query = this.service.entities.score.query.byScorer({ entity: "score", scorerId });
|
|
2184
2265
|
const results = await query.go();
|
|
@@ -2189,6 +2270,9 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2189
2270
|
if (entityType) {
|
|
2190
2271
|
allScores = allScores.filter((score) => score.entityType === entityType);
|
|
2191
2272
|
}
|
|
2273
|
+
if (source) {
|
|
2274
|
+
allScores = allScores.filter((score) => score.source === source);
|
|
2275
|
+
}
|
|
2192
2276
|
allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
2193
2277
|
const startIndex = pagination.page * pagination.perPage;
|
|
2194
2278
|
const endIndex = startIndex + pagination.perPage;
|
|
@@ -2214,6 +2298,7 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2214
2298
|
scorerId: scorerId || "",
|
|
2215
2299
|
entityId: entityId || "",
|
|
2216
2300
|
entityType: entityType || "",
|
|
2301
|
+
source: source || "",
|
|
2217
2302
|
page: pagination.page,
|
|
2218
2303
|
perPage: pagination.perPage
|
|
2219
2304
|
}
|
|
@@ -2296,6 +2381,43 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2296
2381
|
);
|
|
2297
2382
|
}
|
|
2298
2383
|
}
|
|
2384
|
+
async getScoresBySpan({
|
|
2385
|
+
traceId,
|
|
2386
|
+
spanId,
|
|
2387
|
+
pagination
|
|
2388
|
+
}) {
|
|
2389
|
+
this.logger.debug("Getting scores by span", { traceId, spanId, pagination });
|
|
2390
|
+
try {
|
|
2391
|
+
const query = this.service.entities.score.query.bySpan({ entity: "score", traceId, spanId });
|
|
2392
|
+
const results = await query.go();
|
|
2393
|
+
const allScores = results.data.map((data) => this.parseScoreData(data));
|
|
2394
|
+
allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
2395
|
+
const startIndex = pagination.page * pagination.perPage;
|
|
2396
|
+
const endIndex = startIndex + pagination.perPage;
|
|
2397
|
+
const paginatedScores = allScores.slice(startIndex, endIndex);
|
|
2398
|
+
const total = allScores.length;
|
|
2399
|
+
const hasMore = endIndex < total;
|
|
2400
|
+
return {
|
|
2401
|
+
scores: paginatedScores,
|
|
2402
|
+
pagination: {
|
|
2403
|
+
total,
|
|
2404
|
+
page: pagination.page,
|
|
2405
|
+
perPage: pagination.perPage,
|
|
2406
|
+
hasMore
|
|
2407
|
+
}
|
|
2408
|
+
};
|
|
2409
|
+
} catch (error$1) {
|
|
2410
|
+
throw new error.MastraError(
|
|
2411
|
+
{
|
|
2412
|
+
id: "STORAGE_DYNAMODB_STORE_GET_SCORES_BY_SPAN_FAILED",
|
|
2413
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2414
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
2415
|
+
details: { traceId, spanId, page: pagination.page, perPage: pagination.perPage }
|
|
2416
|
+
},
|
|
2417
|
+
error$1
|
|
2418
|
+
);
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2299
2421
|
};
|
|
2300
2422
|
var TracesStorageDynamoDB = class extends storage.TracesStorage {
|
|
2301
2423
|
service;
|
|
@@ -2546,15 +2668,31 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
|
|
|
2546
2668
|
super();
|
|
2547
2669
|
this.service = service;
|
|
2548
2670
|
}
|
|
2671
|
+
updateWorkflowResults({
|
|
2672
|
+
// workflowName,
|
|
2673
|
+
// runId,
|
|
2674
|
+
// stepId,
|
|
2675
|
+
// result,
|
|
2676
|
+
// runtimeContext,
|
|
2677
|
+
}) {
|
|
2678
|
+
throw new Error("Method not implemented.");
|
|
2679
|
+
}
|
|
2680
|
+
updateWorkflowState({
|
|
2681
|
+
// workflowName,
|
|
2682
|
+
// runId,
|
|
2683
|
+
// opts,
|
|
2684
|
+
}) {
|
|
2685
|
+
throw new Error("Method not implemented.");
|
|
2686
|
+
}
|
|
2549
2687
|
// Workflow operations
|
|
2550
2688
|
async persistWorkflowSnapshot({
|
|
2551
2689
|
workflowName,
|
|
2552
2690
|
runId,
|
|
2691
|
+
resourceId,
|
|
2553
2692
|
snapshot
|
|
2554
2693
|
}) {
|
|
2555
2694
|
this.logger.debug("Persisting workflow snapshot", { workflowName, runId });
|
|
2556
2695
|
try {
|
|
2557
|
-
const resourceId = "resourceId" in snapshot ? snapshot.resourceId : void 0;
|
|
2558
2696
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2559
2697
|
const data = {
|
|
2560
2698
|
entity: "workflow_snapshot",
|
|
@@ -2680,8 +2818,6 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
|
|
|
2680
2818
|
async getWorkflowRunById(args) {
|
|
2681
2819
|
const { runId, workflowName } = args;
|
|
2682
2820
|
this.logger.debug("Getting workflow run by ID", { runId, workflowName });
|
|
2683
|
-
console.log("workflowName", workflowName);
|
|
2684
|
-
console.log("runId", runId);
|
|
2685
2821
|
try {
|
|
2686
2822
|
if (workflowName) {
|
|
2687
2823
|
this.logger.debug("WorkflowName provided, using direct GET operation.");
|
|
@@ -2691,7 +2827,6 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
|
|
|
2691
2827
|
workflow_name: workflowName,
|
|
2692
2828
|
run_id: runId
|
|
2693
2829
|
}).go();
|
|
2694
|
-
console.log("result", result2);
|
|
2695
2830
|
if (!result2.data) {
|
|
2696
2831
|
return null;
|
|
2697
2832
|
}
|
|
@@ -2796,7 +2931,8 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2796
2931
|
resourceWorkingMemory: true,
|
|
2797
2932
|
hasColumn: false,
|
|
2798
2933
|
createTable: false,
|
|
2799
|
-
deleteMessages: false
|
|
2934
|
+
deleteMessages: false,
|
|
2935
|
+
getScoresBySpan: true
|
|
2800
2936
|
};
|
|
2801
2937
|
}
|
|
2802
2938
|
/**
|
|
@@ -2891,8 +3027,8 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2891
3027
|
async getThreadById({ threadId }) {
|
|
2892
3028
|
return this.stores.memory.getThreadById({ threadId });
|
|
2893
3029
|
}
|
|
2894
|
-
async getThreadsByResourceId(
|
|
2895
|
-
return this.stores.memory.getThreadsByResourceId(
|
|
3030
|
+
async getThreadsByResourceId(args) {
|
|
3031
|
+
return this.stores.memory.getThreadsByResourceId(args);
|
|
2896
3032
|
}
|
|
2897
3033
|
async saveThread({ thread }) {
|
|
2898
3034
|
return this.stores.memory.saveThread({ thread });
|
|
@@ -2915,6 +3051,12 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2915
3051
|
}) {
|
|
2916
3052
|
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
|
|
2917
3053
|
}
|
|
3054
|
+
async getMessagesById({
|
|
3055
|
+
messageIds,
|
|
3056
|
+
format
|
|
3057
|
+
}) {
|
|
3058
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
3059
|
+
}
|
|
2918
3060
|
async saveMessages(args) {
|
|
2919
3061
|
return this.stores.memory.saveMessages(args);
|
|
2920
3062
|
}
|
|
@@ -2938,12 +3080,29 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2938
3080
|
return this.stores.traces.getTracesPaginated(_args);
|
|
2939
3081
|
}
|
|
2940
3082
|
// Workflow operations
|
|
3083
|
+
async updateWorkflowResults({
|
|
3084
|
+
workflowName,
|
|
3085
|
+
runId,
|
|
3086
|
+
stepId,
|
|
3087
|
+
result,
|
|
3088
|
+
runtimeContext
|
|
3089
|
+
}) {
|
|
3090
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
|
|
3091
|
+
}
|
|
3092
|
+
async updateWorkflowState({
|
|
3093
|
+
workflowName,
|
|
3094
|
+
runId,
|
|
3095
|
+
opts
|
|
3096
|
+
}) {
|
|
3097
|
+
return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
|
|
3098
|
+
}
|
|
2941
3099
|
async persistWorkflowSnapshot({
|
|
2942
3100
|
workflowName,
|
|
2943
3101
|
runId,
|
|
3102
|
+
resourceId,
|
|
2944
3103
|
snapshot
|
|
2945
3104
|
}) {
|
|
2946
|
-
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, snapshot });
|
|
3105
|
+
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
|
|
2947
3106
|
}
|
|
2948
3107
|
async loadWorkflowSnapshot({
|
|
2949
3108
|
workflowName,
|
|
@@ -3024,10 +3183,20 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
3024
3183
|
});
|
|
3025
3184
|
}
|
|
3026
3185
|
async getScoresByScorerId({
|
|
3027
|
-
scorerId
|
|
3028
|
-
|
|
3186
|
+
scorerId,
|
|
3187
|
+
source,
|
|
3188
|
+
entityId,
|
|
3189
|
+
entityType,
|
|
3190
|
+
pagination
|
|
3191
|
+
}) {
|
|
3192
|
+
return this.stores.scores.getScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
|
|
3193
|
+
}
|
|
3194
|
+
async getScoresBySpan({
|
|
3195
|
+
traceId,
|
|
3196
|
+
spanId,
|
|
3197
|
+
pagination
|
|
3029
3198
|
}) {
|
|
3030
|
-
return this.stores.scores.
|
|
3199
|
+
return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
|
|
3031
3200
|
}
|
|
3032
3201
|
};
|
|
3033
3202
|
|