@mastra/dynamodb 0.0.0-vnext-20251104230439 → 0.0.0-vnext-20251119160359
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 +284 -3
- package/dist/index.cjs +9 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +10 -74
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +1 -4
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +2 -4
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +13 -10
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, WorkflowsStorage, normalizePerPage, MemoryStorage,
|
|
4
|
+
import { MastraStorage, StoreOperations, WorkflowsStorage, normalizePerPage, MemoryStorage, calculatePagination, ScoresStorage, TABLE_SPANS, TABLE_RESOURCES, TABLE_TRACES, TABLE_SCORERS, 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
|
import { saveScorePayloadSchema } from '@mastra/core/evals';
|
|
@@ -1071,7 +1071,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1071
1071
|
async deleteThread({ threadId }) {
|
|
1072
1072
|
this.logger.debug("Deleting thread", { threadId });
|
|
1073
1073
|
try {
|
|
1074
|
-
const { messages } = await this.
|
|
1074
|
+
const { messages } = await this.listMessages({ threadId, perPage: false });
|
|
1075
1075
|
if (messages.length > 0) {
|
|
1076
1076
|
const batchSize = 25;
|
|
1077
1077
|
for (let i = 0; i < messages.length; i += batchSize) {
|
|
@@ -1100,70 +1100,6 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1100
1100
|
);
|
|
1101
1101
|
}
|
|
1102
1102
|
}
|
|
1103
|
-
async getMessages({
|
|
1104
|
-
threadId,
|
|
1105
|
-
resourceId,
|
|
1106
|
-
selectBy
|
|
1107
|
-
}) {
|
|
1108
|
-
this.logger.debug("Getting messages", { threadId, selectBy });
|
|
1109
|
-
try {
|
|
1110
|
-
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
1111
|
-
const messages = [];
|
|
1112
|
-
const limit = resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
|
|
1113
|
-
if (selectBy?.include?.length) {
|
|
1114
|
-
const includeMessages = await this._getIncludedMessages(threadId, selectBy);
|
|
1115
|
-
if (includeMessages) {
|
|
1116
|
-
messages.push(...includeMessages);
|
|
1117
|
-
}
|
|
1118
|
-
}
|
|
1119
|
-
if (limit !== 0) {
|
|
1120
|
-
const query = this.service.entities.message.query.byThread({ entity: "message", threadId });
|
|
1121
|
-
let results;
|
|
1122
|
-
if (limit !== Number.MAX_SAFE_INTEGER && limit > 0) {
|
|
1123
|
-
results = await query.go({ limit, order: "desc" });
|
|
1124
|
-
results.data = results.data.reverse();
|
|
1125
|
-
} else {
|
|
1126
|
-
results = await query.go();
|
|
1127
|
-
}
|
|
1128
|
-
let allThreadMessages = results.data.map((data) => this.parseMessageData(data)).filter((msg) => "content" in msg);
|
|
1129
|
-
allThreadMessages.sort((a, b) => {
|
|
1130
|
-
const timeA = a.createdAt.getTime();
|
|
1131
|
-
const timeB = b.createdAt.getTime();
|
|
1132
|
-
if (timeA === timeB) {
|
|
1133
|
-
return a.id.localeCompare(b.id);
|
|
1134
|
-
}
|
|
1135
|
-
return timeA - timeB;
|
|
1136
|
-
});
|
|
1137
|
-
messages.push(...allThreadMessages);
|
|
1138
|
-
}
|
|
1139
|
-
messages.sort((a, b) => {
|
|
1140
|
-
const timeA = a.createdAt.getTime();
|
|
1141
|
-
const timeB = b.createdAt.getTime();
|
|
1142
|
-
if (timeA === timeB) {
|
|
1143
|
-
return a.id.localeCompare(b.id);
|
|
1144
|
-
}
|
|
1145
|
-
return timeA - timeB;
|
|
1146
|
-
});
|
|
1147
|
-
const uniqueMessages = messages.filter(
|
|
1148
|
-
(message, index, self) => index === self.findIndex((m) => m.id === message.id)
|
|
1149
|
-
);
|
|
1150
|
-
const list = new MessageList({ threadId, resourceId }).add(
|
|
1151
|
-
uniqueMessages,
|
|
1152
|
-
"memory"
|
|
1153
|
-
);
|
|
1154
|
-
return { messages: list.get.all.db() };
|
|
1155
|
-
} catch (error) {
|
|
1156
|
-
throw new MastraError(
|
|
1157
|
-
{
|
|
1158
|
-
id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_FAILED",
|
|
1159
|
-
domain: ErrorDomain.STORAGE,
|
|
1160
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
1161
|
-
details: { threadId, resourceId: resourceId ?? "" }
|
|
1162
|
-
},
|
|
1163
|
-
error
|
|
1164
|
-
);
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
1103
|
async listMessagesById({ messageIds }) {
|
|
1168
1104
|
this.logger.debug("Getting messages by ID", { messageIds });
|
|
1169
1105
|
if (messageIds.length === 0) return { messages: [] };
|
|
@@ -1217,7 +1153,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
|
|
|
1217
1153
|
new Error("page must be >= 0")
|
|
1218
1154
|
);
|
|
1219
1155
|
}
|
|
1220
|
-
const { field, direction } = this.parseOrderBy(orderBy);
|
|
1156
|
+
const { field, direction } = this.parseOrderBy(orderBy, "ASC");
|
|
1221
1157
|
this.logger.debug("Getting messages with listMessages", {
|
|
1222
1158
|
threadId,
|
|
1223
1159
|
resourceId,
|
|
@@ -1718,7 +1654,7 @@ var StoreOperationsDynamoDB = class extends StoreOperations {
|
|
|
1718
1654
|
[TABLE_SCORERS]: "score",
|
|
1719
1655
|
[TABLE_TRACES]: "trace",
|
|
1720
1656
|
[TABLE_RESOURCES]: "resource",
|
|
1721
|
-
[
|
|
1657
|
+
[TABLE_SPANS]: "ai_span"
|
|
1722
1658
|
};
|
|
1723
1659
|
return mapping[tableName] || null;
|
|
1724
1660
|
}
|
|
@@ -2332,7 +2268,6 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
|
|
|
2332
2268
|
workflow_name: workflowName,
|
|
2333
2269
|
run_id: runId,
|
|
2334
2270
|
snapshot: JSON.stringify(snapshot),
|
|
2335
|
-
// Stringify the snapshot object
|
|
2336
2271
|
createdAt: now,
|
|
2337
2272
|
updatedAt: now,
|
|
2338
2273
|
resourceId
|
|
@@ -2417,6 +2352,11 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
|
|
|
2417
2352
|
});
|
|
2418
2353
|
if (pageResults.data && pageResults.data.length > 0) {
|
|
2419
2354
|
let pageFilteredData = pageResults.data;
|
|
2355
|
+
if (args?.status) {
|
|
2356
|
+
pageFilteredData = pageFilteredData.filter((snapshot) => {
|
|
2357
|
+
return snapshot.snapshot.status === args.status;
|
|
2358
|
+
});
|
|
2359
|
+
}
|
|
2420
2360
|
if (args?.fromDate || args?.toDate) {
|
|
2421
2361
|
pageFilteredData = pageFilteredData.filter((snapshot) => {
|
|
2422
2362
|
const createdAt = new Date(snapshot.createdAt);
|
|
@@ -2524,7 +2464,7 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
2524
2464
|
hasInitialized = null;
|
|
2525
2465
|
stores;
|
|
2526
2466
|
constructor({ name, config }) {
|
|
2527
|
-
super({ name });
|
|
2467
|
+
super({ id: config.id, name });
|
|
2528
2468
|
try {
|
|
2529
2469
|
if (!config.tableName || typeof config.tableName !== "string" || config.tableName.trim() === "") {
|
|
2530
2470
|
throw new Error("DynamoDBStore: config.tableName must be provided and cannot be empty.");
|
|
@@ -2682,10 +2622,6 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
2682
2622
|
async deleteThread({ threadId }) {
|
|
2683
2623
|
return this.stores.memory.deleteThread({ threadId });
|
|
2684
2624
|
}
|
|
2685
|
-
// Message operations
|
|
2686
|
-
async getMessages(args) {
|
|
2687
|
-
return this.stores.memory.getMessages(args);
|
|
2688
|
-
}
|
|
2689
2625
|
async listMessagesById(args) {
|
|
2690
2626
|
return this.stores.memory.listMessagesById(args);
|
|
2691
2627
|
}
|