@mastra/dynamodb 0.0.0-update-stores-peerDeps-20250723031338 → 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/entities/eval.d.ts +102 -0
- package/dist/entities/eval.d.ts.map +1 -0
- package/dist/entities/index.d.ts +746 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/message.d.ts +100 -0
- package/dist/entities/message.d.ts.map +1 -0
- package/dist/entities/resource.d.ts +54 -0
- package/dist/entities/resource.d.ts.map +1 -0
- package/dist/entities/score.d.ts +229 -0
- package/dist/entities/score.d.ts.map +1 -0
- package/dist/entities/thread.d.ts +69 -0
- package/dist/entities/thread.d.ts.map +1 -0
- package/dist/entities/trace.d.ts +127 -0
- package/dist/entities/trace.d.ts.map +1 -0
- package/dist/entities/utils.d.ts +21 -0
- package/dist/entities/utils.d.ts.map +1 -0
- package/dist/entities/workflow-snapshot.d.ts +74 -0
- package/dist/entities/workflow-snapshot.d.ts.map +1 -0
- package/dist/index.cjs +156 -24
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +157 -25
- package/dist/index.js.map +1 -0
- package/dist/storage/domains/legacy-evals/index.d.ts +19 -0
- package/dist/storage/domains/legacy-evals/index.d.ts.map +1 -0
- package/dist/storage/domains/memory/index.d.ts +89 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -0
- package/dist/storage/domains/operations/index.d.ts +69 -0
- package/dist/storage/domains/operations/index.d.ts.map +1 -0
- package/dist/storage/domains/score/index.d.ts +43 -0
- package/dist/storage/domains/score/index.d.ts.map +1 -0
- package/dist/storage/domains/traces/index.d.ts +28 -0
- package/dist/storage/domains/traces/index.d.ts.map +1 -0
- package/dist/storage/domains/workflows/index.d.ts +50 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +249 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/package.json +12 -11
- package/src/entities/score.ts +32 -0
- 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 +13 -6
- package/src/storage/domains/workflows/index.ts +38 -1
- package/src/storage/index.ts +68 -12
- package/dist/_tsup-dts-rollup.d.cts +0 -1976
- package/dist/_tsup-dts-rollup.d.ts +0 -1976
- package/dist/index.d.cts +0 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
7
|
|
|
@@ -418,6 +418,28 @@ var scoreEntity = new Entity({
|
|
|
418
418
|
return value;
|
|
419
419
|
}
|
|
420
420
|
},
|
|
421
|
+
preprocessStepResult: {
|
|
422
|
+
type: "string",
|
|
423
|
+
required: false,
|
|
424
|
+
set: (value) => {
|
|
425
|
+
if (value && typeof value !== "string") {
|
|
426
|
+
return JSON.stringify(value);
|
|
427
|
+
}
|
|
428
|
+
return value;
|
|
429
|
+
},
|
|
430
|
+
get: (value) => {
|
|
431
|
+
if (value && typeof value === "string") {
|
|
432
|
+
try {
|
|
433
|
+
if (value.startsWith("{") || value.startsWith("[")) {
|
|
434
|
+
return JSON.parse(value);
|
|
435
|
+
}
|
|
436
|
+
} catch {
|
|
437
|
+
return value;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return value;
|
|
441
|
+
}
|
|
442
|
+
},
|
|
421
443
|
analyzeStepResult: {
|
|
422
444
|
type: "string",
|
|
423
445
|
required: false,
|
|
@@ -456,10 +478,19 @@ var scoreEntity = new Entity({
|
|
|
456
478
|
type: "string",
|
|
457
479
|
required: false
|
|
458
480
|
},
|
|
481
|
+
// Deprecated in favor of generateReasonPrompt
|
|
459
482
|
reasonPrompt: {
|
|
460
483
|
type: "string",
|
|
461
484
|
required: false
|
|
462
485
|
},
|
|
486
|
+
generateScorePrompt: {
|
|
487
|
+
type: "string",
|
|
488
|
+
required: false
|
|
489
|
+
},
|
|
490
|
+
generateReasonPrompt: {
|
|
491
|
+
type: "string",
|
|
492
|
+
required: false
|
|
493
|
+
},
|
|
463
494
|
input: {
|
|
464
495
|
type: "string",
|
|
465
496
|
required: true,
|
|
@@ -1090,6 +1121,20 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1090
1121
|
// transformed by the ElectroDB entity getters.
|
|
1091
1122
|
};
|
|
1092
1123
|
}
|
|
1124
|
+
// Helper function to transform and sort threads
|
|
1125
|
+
transformAndSortThreads(rawThreads, orderBy, sortDirection) {
|
|
1126
|
+
return rawThreads.map((data) => ({
|
|
1127
|
+
...data,
|
|
1128
|
+
// Convert date strings back to Date objects for consistency
|
|
1129
|
+
createdAt: typeof data.createdAt === "string" ? new Date(data.createdAt) : data.createdAt,
|
|
1130
|
+
updatedAt: typeof data.updatedAt === "string" ? new Date(data.updatedAt) : data.updatedAt
|
|
1131
|
+
})).sort((a, b) => {
|
|
1132
|
+
const fieldA = orderBy === "createdAt" ? a.createdAt : a.updatedAt;
|
|
1133
|
+
const fieldB = orderBy === "createdAt" ? b.createdAt : b.updatedAt;
|
|
1134
|
+
const comparison = fieldA.getTime() - fieldB.getTime();
|
|
1135
|
+
return sortDirection === "DESC" ? -comparison : comparison;
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1093
1138
|
async getThreadById({ threadId }) {
|
|
1094
1139
|
this.logger.debug("Getting thread by ID", { threadId });
|
|
1095
1140
|
try {
|
|
@@ -1118,21 +1163,20 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1118
1163
|
);
|
|
1119
1164
|
}
|
|
1120
1165
|
}
|
|
1121
|
-
|
|
1122
|
-
|
|
1166
|
+
/**
|
|
1167
|
+
* @deprecated use getThreadsByResourceIdPaginated instead for paginated results.
|
|
1168
|
+
*/
|
|
1169
|
+
async getThreadsByResourceId(args) {
|
|
1170
|
+
const resourceId = args.resourceId;
|
|
1171
|
+
const orderBy = this.castThreadOrderBy(args.orderBy);
|
|
1172
|
+
const sortDirection = this.castThreadSortDirection(args.sortDirection);
|
|
1173
|
+
this.logger.debug("Getting threads by resource ID", { resourceId, orderBy, sortDirection });
|
|
1123
1174
|
try {
|
|
1124
1175
|
const result = await this.service.entities.thread.query.byResource({ entity: "thread", resourceId }).go();
|
|
1125
1176
|
if (!result.data.length) {
|
|
1126
1177
|
return [];
|
|
1127
1178
|
}
|
|
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
|
-
}));
|
|
1179
|
+
return this.transformAndSortThreads(result.data, orderBy, sortDirection);
|
|
1136
1180
|
} catch (error) {
|
|
1137
1181
|
throw new MastraError(
|
|
1138
1182
|
{
|
|
@@ -1154,7 +1198,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1154
1198
|
resourceId: thread.resourceId,
|
|
1155
1199
|
title: thread.title || `Thread ${thread.id}`,
|
|
1156
1200
|
createdAt: thread.createdAt?.toISOString() || now.toISOString(),
|
|
1157
|
-
updatedAt: now.toISOString(),
|
|
1201
|
+
updatedAt: thread.updatedAt?.toISOString() || now.toISOString(),
|
|
1158
1202
|
metadata: thread.metadata ? JSON.stringify(thread.metadata) : void 0
|
|
1159
1203
|
};
|
|
1160
1204
|
try {
|
|
@@ -1315,6 +1359,36 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1315
1359
|
);
|
|
1316
1360
|
}
|
|
1317
1361
|
}
|
|
1362
|
+
async getMessagesById({
|
|
1363
|
+
messageIds,
|
|
1364
|
+
format
|
|
1365
|
+
}) {
|
|
1366
|
+
this.logger.debug("Getting messages by ID", { messageIds });
|
|
1367
|
+
if (messageIds.length === 0) return [];
|
|
1368
|
+
try {
|
|
1369
|
+
const results = await Promise.all(
|
|
1370
|
+
messageIds.map((id) => this.service.entities.message.query.primary({ entity: "message", id }).go())
|
|
1371
|
+
);
|
|
1372
|
+
const data = results.map((result) => result.data).flat(1);
|
|
1373
|
+
let parsedMessages = data.map((data2) => this.parseMessageData(data2)).filter((msg) => "content" in msg);
|
|
1374
|
+
const uniqueMessages = parsedMessages.filter(
|
|
1375
|
+
(message, index, self) => index === self.findIndex((m) => m.id === message.id)
|
|
1376
|
+
);
|
|
1377
|
+
const list = new MessageList().add(uniqueMessages, "memory");
|
|
1378
|
+
if (format === `v1`) return list.get.all.v1();
|
|
1379
|
+
return list.get.all.v2();
|
|
1380
|
+
} catch (error) {
|
|
1381
|
+
throw new MastraError(
|
|
1382
|
+
{
|
|
1383
|
+
id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_BY_ID_FAILED",
|
|
1384
|
+
domain: ErrorDomain.STORAGE,
|
|
1385
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1386
|
+
details: { messageIds: JSON.stringify(messageIds) }
|
|
1387
|
+
},
|
|
1388
|
+
error
|
|
1389
|
+
);
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1318
1392
|
async saveMessages(args) {
|
|
1319
1393
|
const { messages, format = "v1" } = args;
|
|
1320
1394
|
this.logger.debug("Saving messages", { count: messages.length });
|
|
@@ -1389,11 +1463,19 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1389
1463
|
}
|
|
1390
1464
|
async getThreadsByResourceIdPaginated(args) {
|
|
1391
1465
|
const { resourceId, page = 0, perPage = 100 } = args;
|
|
1392
|
-
this.
|
|
1466
|
+
const orderBy = this.castThreadOrderBy(args.orderBy);
|
|
1467
|
+
const sortDirection = this.castThreadSortDirection(args.sortDirection);
|
|
1468
|
+
this.logger.debug("Getting threads by resource ID with pagination", {
|
|
1469
|
+
resourceId,
|
|
1470
|
+
page,
|
|
1471
|
+
perPage,
|
|
1472
|
+
orderBy,
|
|
1473
|
+
sortDirection
|
|
1474
|
+
});
|
|
1393
1475
|
try {
|
|
1394
1476
|
const query = this.service.entities.thread.query.byResource({ entity: "thread", resourceId });
|
|
1395
1477
|
const results = await query.go();
|
|
1396
|
-
const allThreads = results.data;
|
|
1478
|
+
const allThreads = this.transformAndSortThreads(results.data, orderBy, sortDirection);
|
|
1397
1479
|
const startIndex = page * perPage;
|
|
1398
1480
|
const endIndex = startIndex + perPage;
|
|
1399
1481
|
const paginatedThreads = allThreads.slice(startIndex, endIndex);
|
|
@@ -1760,7 +1842,8 @@ var StoreOperationsDynamoDB = class extends StoreOperations {
|
|
|
1760
1842
|
[TABLE_EVALS]: "eval",
|
|
1761
1843
|
[TABLE_SCORERS]: "score",
|
|
1762
1844
|
[TABLE_TRACES]: "trace",
|
|
1763
|
-
[TABLE_RESOURCES]: "resource"
|
|
1845
|
+
[TABLE_RESOURCES]: "resource",
|
|
1846
|
+
[TABLE_AI_SPANS]: "ai_span"
|
|
1764
1847
|
};
|
|
1765
1848
|
return mapping[tableName] || null;
|
|
1766
1849
|
}
|
|
@@ -2097,11 +2180,12 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
|
|
|
2097
2180
|
traceId: score.traceId || "",
|
|
2098
2181
|
runId: score.runId,
|
|
2099
2182
|
scorer: typeof score.scorer === "string" ? score.scorer : JSON.stringify(score.scorer),
|
|
2100
|
-
|
|
2183
|
+
preprocessStepResult: typeof score.preprocessStepResult === "string" ? score.preprocessStepResult : JSON.stringify(score.preprocessStepResult),
|
|
2101
2184
|
analyzeStepResult: typeof score.analyzeStepResult === "string" ? score.analyzeStepResult : JSON.stringify(score.analyzeStepResult),
|
|
2102
2185
|
score: score.score,
|
|
2103
2186
|
reason: score.reason,
|
|
2104
|
-
|
|
2187
|
+
preprocessPrompt: score.preprocessPrompt,
|
|
2188
|
+
generateScorePrompt: score.generateScorePrompt,
|
|
2105
2189
|
analyzePrompt: score.analyzePrompt,
|
|
2106
2190
|
reasonPrompt: score.reasonPrompt,
|
|
2107
2191
|
input: typeof score.input === "string" ? score.input : JSON.stringify(score.input),
|
|
@@ -2142,9 +2226,9 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
|
|
|
2142
2226
|
scorerId,
|
|
2143
2227
|
pagination,
|
|
2144
2228
|
entityId,
|
|
2145
|
-
entityType
|
|
2229
|
+
entityType,
|
|
2230
|
+
source
|
|
2146
2231
|
}) {
|
|
2147
|
-
this.logger.debug("Getting scores by scorer ID", { scorerId, pagination, entityId, entityType });
|
|
2148
2232
|
try {
|
|
2149
2233
|
const query = this.service.entities.score.query.byScorer({ entity: "score", scorerId });
|
|
2150
2234
|
const results = await query.go();
|
|
@@ -2155,6 +2239,9 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
|
|
|
2155
2239
|
if (entityType) {
|
|
2156
2240
|
allScores = allScores.filter((score) => score.entityType === entityType);
|
|
2157
2241
|
}
|
|
2242
|
+
if (source) {
|
|
2243
|
+
allScores = allScores.filter((score) => score.source === source);
|
|
2244
|
+
}
|
|
2158
2245
|
allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
2159
2246
|
const startIndex = pagination.page * pagination.perPage;
|
|
2160
2247
|
const endIndex = startIndex + pagination.perPage;
|
|
@@ -2180,6 +2267,7 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
|
|
|
2180
2267
|
scorerId: scorerId || "",
|
|
2181
2268
|
entityId: entityId || "",
|
|
2182
2269
|
entityType: entityType || "",
|
|
2270
|
+
source: source || "",
|
|
2183
2271
|
page: pagination.page,
|
|
2184
2272
|
perPage: pagination.perPage
|
|
2185
2273
|
}
|
|
@@ -2512,6 +2600,22 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
|
|
|
2512
2600
|
super();
|
|
2513
2601
|
this.service = service;
|
|
2514
2602
|
}
|
|
2603
|
+
updateWorkflowResults({
|
|
2604
|
+
// workflowName,
|
|
2605
|
+
// runId,
|
|
2606
|
+
// stepId,
|
|
2607
|
+
// result,
|
|
2608
|
+
// runtimeContext,
|
|
2609
|
+
}) {
|
|
2610
|
+
throw new Error("Method not implemented.");
|
|
2611
|
+
}
|
|
2612
|
+
updateWorkflowState({
|
|
2613
|
+
// workflowName,
|
|
2614
|
+
// runId,
|
|
2615
|
+
// opts,
|
|
2616
|
+
}) {
|
|
2617
|
+
throw new Error("Method not implemented.");
|
|
2618
|
+
}
|
|
2515
2619
|
// Workflow operations
|
|
2516
2620
|
async persistWorkflowSnapshot({
|
|
2517
2621
|
workflowName,
|
|
@@ -2761,7 +2865,8 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
2761
2865
|
selectByIncludeResourceScope: true,
|
|
2762
2866
|
resourceWorkingMemory: true,
|
|
2763
2867
|
hasColumn: false,
|
|
2764
|
-
createTable: false
|
|
2868
|
+
createTable: false,
|
|
2869
|
+
deleteMessages: false
|
|
2765
2870
|
};
|
|
2766
2871
|
}
|
|
2767
2872
|
/**
|
|
@@ -2856,8 +2961,8 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
2856
2961
|
async getThreadById({ threadId }) {
|
|
2857
2962
|
return this.stores.memory.getThreadById({ threadId });
|
|
2858
2963
|
}
|
|
2859
|
-
async getThreadsByResourceId(
|
|
2860
|
-
return this.stores.memory.getThreadsByResourceId(
|
|
2964
|
+
async getThreadsByResourceId(args) {
|
|
2965
|
+
return this.stores.memory.getThreadsByResourceId(args);
|
|
2861
2966
|
}
|
|
2862
2967
|
async saveThread({ thread }) {
|
|
2863
2968
|
return this.stores.memory.saveThread({ thread });
|
|
@@ -2880,6 +2985,12 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
2880
2985
|
}) {
|
|
2881
2986
|
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
|
|
2882
2987
|
}
|
|
2988
|
+
async getMessagesById({
|
|
2989
|
+
messageIds,
|
|
2990
|
+
format
|
|
2991
|
+
}) {
|
|
2992
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
2993
|
+
}
|
|
2883
2994
|
async saveMessages(args) {
|
|
2884
2995
|
return this.stores.memory.saveMessages(args);
|
|
2885
2996
|
}
|
|
@@ -2903,6 +3014,22 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
2903
3014
|
return this.stores.traces.getTracesPaginated(_args);
|
|
2904
3015
|
}
|
|
2905
3016
|
// Workflow operations
|
|
3017
|
+
async updateWorkflowResults({
|
|
3018
|
+
workflowName,
|
|
3019
|
+
runId,
|
|
3020
|
+
stepId,
|
|
3021
|
+
result,
|
|
3022
|
+
runtimeContext
|
|
3023
|
+
}) {
|
|
3024
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
|
|
3025
|
+
}
|
|
3026
|
+
async updateWorkflowState({
|
|
3027
|
+
workflowName,
|
|
3028
|
+
runId,
|
|
3029
|
+
opts
|
|
3030
|
+
}) {
|
|
3031
|
+
return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
|
|
3032
|
+
}
|
|
2906
3033
|
async persistWorkflowSnapshot({
|
|
2907
3034
|
workflowName,
|
|
2908
3035
|
runId,
|
|
@@ -2989,11 +3116,16 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
2989
3116
|
});
|
|
2990
3117
|
}
|
|
2991
3118
|
async getScoresByScorerId({
|
|
2992
|
-
scorerId
|
|
2993
|
-
|
|
3119
|
+
scorerId,
|
|
3120
|
+
source,
|
|
3121
|
+
entityId,
|
|
3122
|
+
entityType,
|
|
3123
|
+
pagination
|
|
2994
3124
|
}) {
|
|
2995
|
-
return this.stores.scores.getScoresByScorerId({ scorerId
|
|
3125
|
+
return this.stores.scores.getScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
|
|
2996
3126
|
}
|
|
2997
3127
|
};
|
|
2998
3128
|
|
|
2999
3129
|
export { DynamoDBStore };
|
|
3130
|
+
//# sourceMappingURL=index.js.map
|
|
3131
|
+
//# sourceMappingURL=index.js.map
|