@mastra/dynamodb 0.0.0-update-scorers-api-20250801170445 → 0.0.0-vector-query-tool-provider-options-20250828222356
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/dist/index.cjs +118 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +119 -22
- 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 +3 -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 +19 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +36 -7
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +9 -8
- package/src/storage/domains/memory/index.ts +113 -20
- package/src/storage/domains/operations/index.ts +2 -0
- package/src/storage/domains/score/index.ts +7 -3
- package/src/storage/domains/workflows/index.ts +38 -1
- package/src/storage/index.ts +67 -12
package/dist/index.cjs
CHANGED
|
@@ -1123,6 +1123,20 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1123
1123
|
// transformed by the ElectroDB entity getters.
|
|
1124
1124
|
};
|
|
1125
1125
|
}
|
|
1126
|
+
// Helper function to transform and sort threads
|
|
1127
|
+
transformAndSortThreads(rawThreads, orderBy, sortDirection) {
|
|
1128
|
+
return rawThreads.map((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
|
+
})).sort((a, b) => {
|
|
1134
|
+
const fieldA = orderBy === "createdAt" ? a.createdAt : a.updatedAt;
|
|
1135
|
+
const fieldB = orderBy === "createdAt" ? b.createdAt : b.updatedAt;
|
|
1136
|
+
const comparison = fieldA.getTime() - fieldB.getTime();
|
|
1137
|
+
return sortDirection === "DESC" ? -comparison : comparison;
|
|
1138
|
+
});
|
|
1139
|
+
}
|
|
1126
1140
|
async getThreadById({ threadId }) {
|
|
1127
1141
|
this.logger.debug("Getting thread by ID", { threadId });
|
|
1128
1142
|
try {
|
|
@@ -1151,21 +1165,20 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1151
1165
|
);
|
|
1152
1166
|
}
|
|
1153
1167
|
}
|
|
1154
|
-
|
|
1155
|
-
|
|
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 });
|
|
1156
1176
|
try {
|
|
1157
1177
|
const result = await this.service.entities.thread.query.byResource({ entity: "thread", resourceId }).go();
|
|
1158
1178
|
if (!result.data.length) {
|
|
1159
1179
|
return [];
|
|
1160
1180
|
}
|
|
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
|
-
}));
|
|
1181
|
+
return this.transformAndSortThreads(result.data, orderBy, sortDirection);
|
|
1169
1182
|
} catch (error$1) {
|
|
1170
1183
|
throw new error.MastraError(
|
|
1171
1184
|
{
|
|
@@ -1187,7 +1200,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1187
1200
|
resourceId: thread.resourceId,
|
|
1188
1201
|
title: thread.title || `Thread ${thread.id}`,
|
|
1189
1202
|
createdAt: thread.createdAt?.toISOString() || now.toISOString(),
|
|
1190
|
-
updatedAt: now.toISOString(),
|
|
1203
|
+
updatedAt: thread.updatedAt?.toISOString() || now.toISOString(),
|
|
1191
1204
|
metadata: thread.metadata ? JSON.stringify(thread.metadata) : void 0
|
|
1192
1205
|
};
|
|
1193
1206
|
try {
|
|
@@ -1348,6 +1361,36 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1348
1361
|
);
|
|
1349
1362
|
}
|
|
1350
1363
|
}
|
|
1364
|
+
async getMessagesById({
|
|
1365
|
+
messageIds,
|
|
1366
|
+
format
|
|
1367
|
+
}) {
|
|
1368
|
+
this.logger.debug("Getting messages by ID", { messageIds });
|
|
1369
|
+
if (messageIds.length === 0) return [];
|
|
1370
|
+
try {
|
|
1371
|
+
const results = await Promise.all(
|
|
1372
|
+
messageIds.map((id) => this.service.entities.message.query.primary({ entity: "message", id }).go())
|
|
1373
|
+
);
|
|
1374
|
+
const data = results.map((result) => result.data).flat(1);
|
|
1375
|
+
let parsedMessages = data.map((data2) => this.parseMessageData(data2)).filter((msg) => "content" in msg);
|
|
1376
|
+
const uniqueMessages = parsedMessages.filter(
|
|
1377
|
+
(message, index, self) => index === self.findIndex((m) => m.id === message.id)
|
|
1378
|
+
);
|
|
1379
|
+
const list = new agent.MessageList().add(uniqueMessages, "memory");
|
|
1380
|
+
if (format === `v1`) return list.get.all.v1();
|
|
1381
|
+
return list.get.all.v2();
|
|
1382
|
+
} catch (error$1) {
|
|
1383
|
+
throw new error.MastraError(
|
|
1384
|
+
{
|
|
1385
|
+
id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_BY_ID_FAILED",
|
|
1386
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1387
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1388
|
+
details: { messageIds: JSON.stringify(messageIds) }
|
|
1389
|
+
},
|
|
1390
|
+
error$1
|
|
1391
|
+
);
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1351
1394
|
async saveMessages(args) {
|
|
1352
1395
|
const { messages, format = "v1" } = args;
|
|
1353
1396
|
this.logger.debug("Saving messages", { count: messages.length });
|
|
@@ -1422,11 +1465,19 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1422
1465
|
}
|
|
1423
1466
|
async getThreadsByResourceIdPaginated(args) {
|
|
1424
1467
|
const { resourceId, page = 0, perPage = 100 } = args;
|
|
1425
|
-
this.
|
|
1468
|
+
const orderBy = this.castThreadOrderBy(args.orderBy);
|
|
1469
|
+
const sortDirection = this.castThreadSortDirection(args.sortDirection);
|
|
1470
|
+
this.logger.debug("Getting threads by resource ID with pagination", {
|
|
1471
|
+
resourceId,
|
|
1472
|
+
page,
|
|
1473
|
+
perPage,
|
|
1474
|
+
orderBy,
|
|
1475
|
+
sortDirection
|
|
1476
|
+
});
|
|
1426
1477
|
try {
|
|
1427
1478
|
const query = this.service.entities.thread.query.byResource({ entity: "thread", resourceId });
|
|
1428
1479
|
const results = await query.go();
|
|
1429
|
-
const allThreads = results.data;
|
|
1480
|
+
const allThreads = this.transformAndSortThreads(results.data, orderBy, sortDirection);
|
|
1430
1481
|
const startIndex = page * perPage;
|
|
1431
1482
|
const endIndex = startIndex + perPage;
|
|
1432
1483
|
const paginatedThreads = allThreads.slice(startIndex, endIndex);
|
|
@@ -1793,7 +1844,8 @@ var StoreOperationsDynamoDB = class extends storage.StoreOperations {
|
|
|
1793
1844
|
[storage.TABLE_EVALS]: "eval",
|
|
1794
1845
|
[storage.TABLE_SCORERS]: "score",
|
|
1795
1846
|
[storage.TABLE_TRACES]: "trace",
|
|
1796
|
-
[storage.TABLE_RESOURCES]: "resource"
|
|
1847
|
+
[storage.TABLE_RESOURCES]: "resource",
|
|
1848
|
+
[storage.TABLE_AI_SPANS]: "ai_span"
|
|
1797
1849
|
};
|
|
1798
1850
|
return mapping[tableName] || null;
|
|
1799
1851
|
}
|
|
@@ -2176,9 +2228,9 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2176
2228
|
scorerId,
|
|
2177
2229
|
pagination,
|
|
2178
2230
|
entityId,
|
|
2179
|
-
entityType
|
|
2231
|
+
entityType,
|
|
2232
|
+
source
|
|
2180
2233
|
}) {
|
|
2181
|
-
this.logger.debug("Getting scores by scorer ID", { scorerId, pagination, entityId, entityType });
|
|
2182
2234
|
try {
|
|
2183
2235
|
const query = this.service.entities.score.query.byScorer({ entity: "score", scorerId });
|
|
2184
2236
|
const results = await query.go();
|
|
@@ -2189,6 +2241,9 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2189
2241
|
if (entityType) {
|
|
2190
2242
|
allScores = allScores.filter((score) => score.entityType === entityType);
|
|
2191
2243
|
}
|
|
2244
|
+
if (source) {
|
|
2245
|
+
allScores = allScores.filter((score) => score.source === source);
|
|
2246
|
+
}
|
|
2192
2247
|
allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
2193
2248
|
const startIndex = pagination.page * pagination.perPage;
|
|
2194
2249
|
const endIndex = startIndex + pagination.perPage;
|
|
@@ -2214,6 +2269,7 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2214
2269
|
scorerId: scorerId || "",
|
|
2215
2270
|
entityId: entityId || "",
|
|
2216
2271
|
entityType: entityType || "",
|
|
2272
|
+
source: source || "",
|
|
2217
2273
|
page: pagination.page,
|
|
2218
2274
|
perPage: pagination.perPage
|
|
2219
2275
|
}
|
|
@@ -2546,6 +2602,22 @@ var WorkflowStorageDynamoDB = class extends storage.WorkflowsStorage {
|
|
|
2546
2602
|
super();
|
|
2547
2603
|
this.service = service;
|
|
2548
2604
|
}
|
|
2605
|
+
updateWorkflowResults({
|
|
2606
|
+
// workflowName,
|
|
2607
|
+
// runId,
|
|
2608
|
+
// stepId,
|
|
2609
|
+
// result,
|
|
2610
|
+
// runtimeContext,
|
|
2611
|
+
}) {
|
|
2612
|
+
throw new Error("Method not implemented.");
|
|
2613
|
+
}
|
|
2614
|
+
updateWorkflowState({
|
|
2615
|
+
// workflowName,
|
|
2616
|
+
// runId,
|
|
2617
|
+
// opts,
|
|
2618
|
+
}) {
|
|
2619
|
+
throw new Error("Method not implemented.");
|
|
2620
|
+
}
|
|
2549
2621
|
// Workflow operations
|
|
2550
2622
|
async persistWorkflowSnapshot({
|
|
2551
2623
|
workflowName,
|
|
@@ -2891,8 +2963,8 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2891
2963
|
async getThreadById({ threadId }) {
|
|
2892
2964
|
return this.stores.memory.getThreadById({ threadId });
|
|
2893
2965
|
}
|
|
2894
|
-
async getThreadsByResourceId(
|
|
2895
|
-
return this.stores.memory.getThreadsByResourceId(
|
|
2966
|
+
async getThreadsByResourceId(args) {
|
|
2967
|
+
return this.stores.memory.getThreadsByResourceId(args);
|
|
2896
2968
|
}
|
|
2897
2969
|
async saveThread({ thread }) {
|
|
2898
2970
|
return this.stores.memory.saveThread({ thread });
|
|
@@ -2915,6 +2987,12 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2915
2987
|
}) {
|
|
2916
2988
|
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
|
|
2917
2989
|
}
|
|
2990
|
+
async getMessagesById({
|
|
2991
|
+
messageIds,
|
|
2992
|
+
format
|
|
2993
|
+
}) {
|
|
2994
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
2995
|
+
}
|
|
2918
2996
|
async saveMessages(args) {
|
|
2919
2997
|
return this.stores.memory.saveMessages(args);
|
|
2920
2998
|
}
|
|
@@ -2938,6 +3016,22 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2938
3016
|
return this.stores.traces.getTracesPaginated(_args);
|
|
2939
3017
|
}
|
|
2940
3018
|
// Workflow operations
|
|
3019
|
+
async updateWorkflowResults({
|
|
3020
|
+
workflowName,
|
|
3021
|
+
runId,
|
|
3022
|
+
stepId,
|
|
3023
|
+
result,
|
|
3024
|
+
runtimeContext
|
|
3025
|
+
}) {
|
|
3026
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
|
|
3027
|
+
}
|
|
3028
|
+
async updateWorkflowState({
|
|
3029
|
+
workflowName,
|
|
3030
|
+
runId,
|
|
3031
|
+
opts
|
|
3032
|
+
}) {
|
|
3033
|
+
return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
|
|
3034
|
+
}
|
|
2941
3035
|
async persistWorkflowSnapshot({
|
|
2942
3036
|
workflowName,
|
|
2943
3037
|
runId,
|
|
@@ -3024,10 +3118,13 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
3024
3118
|
});
|
|
3025
3119
|
}
|
|
3026
3120
|
async getScoresByScorerId({
|
|
3027
|
-
scorerId
|
|
3028
|
-
|
|
3121
|
+
scorerId,
|
|
3122
|
+
source,
|
|
3123
|
+
entityId,
|
|
3124
|
+
entityType,
|
|
3125
|
+
pagination
|
|
3029
3126
|
}) {
|
|
3030
|
-
return this.stores.scores.getScoresByScorerId({ scorerId
|
|
3127
|
+
return this.stores.scores.getScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
|
|
3031
3128
|
}
|
|
3032
3129
|
};
|
|
3033
3130
|
|