@mastra/dynamodb 0.13.3 → 0.14.0-alpha.1
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 +71 -16
- 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 +71 -16
- 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 +81 -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 +42 -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 +32 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +220 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/package.json +9 -8
- package/src/entities/score.ts +32 -0
- package/src/storage/domains/memory/index.ts +56 -19
- package/src/storage/domains/score/index.ts +6 -3
- package/src/storage/index.ts +10 -7
- package/dist/_tsup-dts-rollup.d.cts +0 -1977
- package/dist/_tsup-dts-rollup.d.ts +0 -1977
- package/dist/index.d.cts +0 -2
|
@@ -3,7 +3,12 @@ import type { MastraMessageContentV2 } from '@mastra/core/agent';
|
|
|
3
3
|
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
4
4
|
import type { StorageThreadType, MastraMessageV1, MastraMessageV2 } from '@mastra/core/memory';
|
|
5
5
|
import { MemoryStorage, resolveMessageLimit } from '@mastra/core/storage';
|
|
6
|
-
import type {
|
|
6
|
+
import type {
|
|
7
|
+
PaginationInfo,
|
|
8
|
+
StorageGetMessagesArg,
|
|
9
|
+
StorageResourceType,
|
|
10
|
+
ThreadSortOptions,
|
|
11
|
+
} from '@mastra/core/storage';
|
|
7
12
|
import type { Service } from 'electrodb';
|
|
8
13
|
|
|
9
14
|
export class MemoryStorageDynamoDB extends MemoryStorage {
|
|
@@ -27,6 +32,24 @@ export class MemoryStorageDynamoDB extends MemoryStorage {
|
|
|
27
32
|
};
|
|
28
33
|
}
|
|
29
34
|
|
|
35
|
+
// Helper function to transform and sort threads
|
|
36
|
+
private transformAndSortThreads(rawThreads: any[], orderBy: string, sortDirection: string): StorageThreadType[] {
|
|
37
|
+
return rawThreads
|
|
38
|
+
.map((data: any) => ({
|
|
39
|
+
...data,
|
|
40
|
+
// Convert date strings back to Date objects for consistency
|
|
41
|
+
createdAt: typeof data.createdAt === 'string' ? new Date(data.createdAt) : data.createdAt,
|
|
42
|
+
updatedAt: typeof data.updatedAt === 'string' ? new Date(data.updatedAt) : data.updatedAt,
|
|
43
|
+
}))
|
|
44
|
+
.sort((a: StorageThreadType, b: StorageThreadType) => {
|
|
45
|
+
const fieldA = orderBy === 'createdAt' ? a.createdAt : a.updatedAt;
|
|
46
|
+
const fieldB = orderBy === 'createdAt' ? b.createdAt : b.updatedAt;
|
|
47
|
+
|
|
48
|
+
const comparison = fieldA.getTime() - fieldB.getTime();
|
|
49
|
+
return sortDirection === 'DESC' ? -comparison : comparison;
|
|
50
|
+
}) as StorageThreadType[];
|
|
51
|
+
}
|
|
52
|
+
|
|
30
53
|
async getThreadById({ threadId }: { threadId: string }): Promise<StorageThreadType | null> {
|
|
31
54
|
this.logger.debug('Getting thread by ID', { threadId });
|
|
32
55
|
try {
|
|
@@ -59,8 +82,16 @@ export class MemoryStorageDynamoDB extends MemoryStorage {
|
|
|
59
82
|
}
|
|
60
83
|
}
|
|
61
84
|
|
|
62
|
-
|
|
63
|
-
|
|
85
|
+
/**
|
|
86
|
+
* @deprecated use getThreadsByResourceIdPaginated instead for paginated results.
|
|
87
|
+
*/
|
|
88
|
+
public async getThreadsByResourceId(args: { resourceId: string } & ThreadSortOptions): Promise<StorageThreadType[]> {
|
|
89
|
+
const resourceId = args.resourceId;
|
|
90
|
+
const orderBy = this.castThreadOrderBy(args.orderBy);
|
|
91
|
+
const sortDirection = this.castThreadSortDirection(args.sortDirection);
|
|
92
|
+
|
|
93
|
+
this.logger.debug('Getting threads by resource ID', { resourceId, orderBy, sortDirection });
|
|
94
|
+
|
|
64
95
|
try {
|
|
65
96
|
const result = await this.service.entities.thread.query.byResource({ entity: 'thread', resourceId }).go();
|
|
66
97
|
|
|
@@ -68,15 +99,8 @@ export class MemoryStorageDynamoDB extends MemoryStorage {
|
|
|
68
99
|
return [];
|
|
69
100
|
}
|
|
70
101
|
|
|
71
|
-
//
|
|
72
|
-
return result.data
|
|
73
|
-
...data,
|
|
74
|
-
// Convert date strings back to Date objects for consistency
|
|
75
|
-
createdAt: typeof data.createdAt === 'string' ? new Date(data.createdAt) : data.createdAt,
|
|
76
|
-
updatedAt: typeof data.updatedAt === 'string' ? new Date(data.updatedAt) : data.updatedAt,
|
|
77
|
-
// metadata: data.metadata ? JSON.parse(data.metadata) : undefined, // REMOVED by AI
|
|
78
|
-
// metadata is already transformed by the entity's getter
|
|
79
|
-
})) as StorageThreadType[];
|
|
102
|
+
// Use shared helper method for transformation and sorting
|
|
103
|
+
return this.transformAndSortThreads(result.data, orderBy, sortDirection);
|
|
80
104
|
} catch (error) {
|
|
81
105
|
throw new MastraError(
|
|
82
106
|
{
|
|
@@ -417,13 +441,24 @@ export class MemoryStorageDynamoDB extends MemoryStorage {
|
|
|
417
441
|
}
|
|
418
442
|
}
|
|
419
443
|
|
|
420
|
-
async getThreadsByResourceIdPaginated(
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
444
|
+
async getThreadsByResourceIdPaginated(
|
|
445
|
+
args: {
|
|
446
|
+
resourceId: string;
|
|
447
|
+
page?: number;
|
|
448
|
+
perPage?: number;
|
|
449
|
+
} & ThreadSortOptions,
|
|
450
|
+
): Promise<PaginationInfo & { threads: StorageThreadType[] }> {
|
|
425
451
|
const { resourceId, page = 0, perPage = 100 } = args;
|
|
426
|
-
this.
|
|
452
|
+
const orderBy = this.castThreadOrderBy(args.orderBy);
|
|
453
|
+
const sortDirection = this.castThreadSortDirection(args.sortDirection);
|
|
454
|
+
|
|
455
|
+
this.logger.debug('Getting threads by resource ID with pagination', {
|
|
456
|
+
resourceId,
|
|
457
|
+
page,
|
|
458
|
+
perPage,
|
|
459
|
+
orderBy,
|
|
460
|
+
sortDirection,
|
|
461
|
+
});
|
|
427
462
|
|
|
428
463
|
try {
|
|
429
464
|
// Query threads by resource ID using the GSI
|
|
@@ -431,7 +466,9 @@ export class MemoryStorageDynamoDB extends MemoryStorage {
|
|
|
431
466
|
|
|
432
467
|
// Get all threads for this resource ID (DynamoDB doesn't support OFFSET/LIMIT)
|
|
433
468
|
const results = await query.go();
|
|
434
|
-
|
|
469
|
+
|
|
470
|
+
// Use shared helper method for transformation and sorting
|
|
471
|
+
const allThreads = this.transformAndSortThreads(results.data, orderBy, sortDirection);
|
|
435
472
|
|
|
436
473
|
// Apply pagination in memory
|
|
437
474
|
const startIndex = page * perPage;
|
|
@@ -58,13 +58,16 @@ export class ScoresStorageDynamoDB extends ScoresStorage {
|
|
|
58
58
|
traceId: score.traceId || '',
|
|
59
59
|
runId: score.runId,
|
|
60
60
|
scorer: typeof score.scorer === 'string' ? score.scorer : JSON.stringify(score.scorer),
|
|
61
|
-
|
|
62
|
-
typeof score.
|
|
61
|
+
preprocessStepResult:
|
|
62
|
+
typeof score.preprocessStepResult === 'string'
|
|
63
|
+
? score.preprocessStepResult
|
|
64
|
+
: JSON.stringify(score.preprocessStepResult),
|
|
63
65
|
analyzeStepResult:
|
|
64
66
|
typeof score.analyzeStepResult === 'string' ? score.analyzeStepResult : JSON.stringify(score.analyzeStepResult),
|
|
65
67
|
score: score.score,
|
|
66
68
|
reason: score.reason,
|
|
67
|
-
|
|
69
|
+
preprocessPrompt: score.preprocessPrompt,
|
|
70
|
+
generateScorePrompt: score.generateScorePrompt,
|
|
68
71
|
analyzePrompt: score.analyzePrompt,
|
|
69
72
|
reasonPrompt: score.reasonPrompt,
|
|
70
73
|
input: typeof score.input === 'string' ? score.input : JSON.stringify(score.input),
|
package/src/storage/index.ts
CHANGED
|
@@ -19,6 +19,7 @@ import type {
|
|
|
19
19
|
StorageDomains,
|
|
20
20
|
PaginationArgs,
|
|
21
21
|
StorageResourceType,
|
|
22
|
+
ThreadSortOptions,
|
|
22
23
|
} from '@mastra/core/storage';
|
|
23
24
|
import type { Trace } from '@mastra/core/telemetry';
|
|
24
25
|
import type { WorkflowRunState } from '@mastra/core/workflows';
|
|
@@ -254,8 +255,8 @@ export class DynamoDBStore extends MastraStorage {
|
|
|
254
255
|
return this.stores.memory.getThreadById({ threadId });
|
|
255
256
|
}
|
|
256
257
|
|
|
257
|
-
async getThreadsByResourceId(
|
|
258
|
-
return this.stores.memory.getThreadsByResourceId(
|
|
258
|
+
async getThreadsByResourceId(args: { resourceId: string } & ThreadSortOptions): Promise<StorageThreadType[]> {
|
|
259
|
+
return this.stores.memory.getThreadsByResourceId(args);
|
|
259
260
|
}
|
|
260
261
|
|
|
261
262
|
async saveThread({ thread }: { thread: StorageThreadType }): Promise<StorageThreadType> {
|
|
@@ -298,11 +299,13 @@ export class DynamoDBStore extends MastraStorage {
|
|
|
298
299
|
return this.stores.memory.saveMessages(args);
|
|
299
300
|
}
|
|
300
301
|
|
|
301
|
-
async getThreadsByResourceIdPaginated(
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
302
|
+
async getThreadsByResourceIdPaginated(
|
|
303
|
+
args: {
|
|
304
|
+
resourceId: string;
|
|
305
|
+
page: number;
|
|
306
|
+
perPage: number;
|
|
307
|
+
} & ThreadSortOptions,
|
|
308
|
+
): Promise<PaginationInfo & { threads: StorageThreadType[] }> {
|
|
306
309
|
return this.stores.memory.getThreadsByResourceIdPaginated(args);
|
|
307
310
|
}
|
|
308
311
|
|