@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/src/entities/score.ts
CHANGED
|
@@ -73,6 +73,28 @@ export const scoreEntity = new Entity({
|
|
|
73
73
|
return value;
|
|
74
74
|
},
|
|
75
75
|
},
|
|
76
|
+
preprocessStepResult: {
|
|
77
|
+
type: 'string',
|
|
78
|
+
required: false,
|
|
79
|
+
set: (value?: Record<string, unknown> | string) => {
|
|
80
|
+
if (value && typeof value !== 'string') {
|
|
81
|
+
return JSON.stringify(value);
|
|
82
|
+
}
|
|
83
|
+
return value;
|
|
84
|
+
},
|
|
85
|
+
get: (value?: string) => {
|
|
86
|
+
if (value && typeof value === 'string') {
|
|
87
|
+
try {
|
|
88
|
+
if (value.startsWith('{') || value.startsWith('[')) {
|
|
89
|
+
return JSON.parse(value);
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return value;
|
|
96
|
+
},
|
|
97
|
+
},
|
|
76
98
|
analyzeStepResult: {
|
|
77
99
|
type: 'string',
|
|
78
100
|
required: false,
|
|
@@ -111,10 +133,20 @@ export const scoreEntity = new Entity({
|
|
|
111
133
|
type: 'string',
|
|
112
134
|
required: false,
|
|
113
135
|
},
|
|
136
|
+
|
|
137
|
+
// Deprecated in favor of generateReasonPrompt
|
|
114
138
|
reasonPrompt: {
|
|
115
139
|
type: 'string',
|
|
116
140
|
required: false,
|
|
117
141
|
},
|
|
142
|
+
generateScorePrompt: {
|
|
143
|
+
type: 'string',
|
|
144
|
+
required: false,
|
|
145
|
+
},
|
|
146
|
+
generateReasonPrompt: {
|
|
147
|
+
type: 'string',
|
|
148
|
+
required: false,
|
|
149
|
+
},
|
|
118
150
|
input: {
|
|
119
151
|
type: 'string',
|
|
120
152
|
required: true,
|
|
@@ -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
|
{
|
|
@@ -101,7 +125,7 @@ export class MemoryStorageDynamoDB extends MemoryStorage {
|
|
|
101
125
|
resourceId: thread.resourceId,
|
|
102
126
|
title: thread.title || `Thread ${thread.id}`,
|
|
103
127
|
createdAt: thread.createdAt?.toISOString() || now.toISOString(),
|
|
104
|
-
updatedAt: now.toISOString(),
|
|
128
|
+
updatedAt: thread.updatedAt?.toISOString() || now.toISOString(),
|
|
105
129
|
metadata: thread.metadata ? JSON.stringify(thread.metadata) : undefined,
|
|
106
130
|
};
|
|
107
131
|
|
|
@@ -326,6 +350,62 @@ export class MemoryStorageDynamoDB extends MemoryStorage {
|
|
|
326
350
|
}
|
|
327
351
|
}
|
|
328
352
|
|
|
353
|
+
public async getMessagesById({
|
|
354
|
+
messageIds,
|
|
355
|
+
format,
|
|
356
|
+
}: {
|
|
357
|
+
messageIds: string[];
|
|
358
|
+
format: 'v1';
|
|
359
|
+
}): Promise<MastraMessageV1[]>;
|
|
360
|
+
public async getMessagesById({
|
|
361
|
+
messageIds,
|
|
362
|
+
format,
|
|
363
|
+
}: {
|
|
364
|
+
messageIds: string[];
|
|
365
|
+
format?: 'v2';
|
|
366
|
+
}): Promise<MastraMessageV2[]>;
|
|
367
|
+
public async getMessagesById({
|
|
368
|
+
messageIds,
|
|
369
|
+
format,
|
|
370
|
+
}: {
|
|
371
|
+
messageIds: string[];
|
|
372
|
+
format?: 'v1' | 'v2';
|
|
373
|
+
}): Promise<MastraMessageV1[] | MastraMessageV2[]> {
|
|
374
|
+
this.logger.debug('Getting messages by ID', { messageIds });
|
|
375
|
+
if (messageIds.length === 0) return [];
|
|
376
|
+
|
|
377
|
+
try {
|
|
378
|
+
const results = await Promise.all(
|
|
379
|
+
messageIds.map(id => this.service.entities.message.query.primary({ entity: 'message', id }).go()),
|
|
380
|
+
);
|
|
381
|
+
|
|
382
|
+
const data = results.map(result => result.data).flat(1);
|
|
383
|
+
|
|
384
|
+
let parsedMessages = data
|
|
385
|
+
.map((data: any) => this.parseMessageData(data))
|
|
386
|
+
.filter((msg: any): msg is MastraMessageV2 => 'content' in msg);
|
|
387
|
+
|
|
388
|
+
// Deduplicate messages by ID (like libsql)
|
|
389
|
+
const uniqueMessages = parsedMessages.filter(
|
|
390
|
+
(message, index, self) => index === self.findIndex(m => m.id === message.id),
|
|
391
|
+
);
|
|
392
|
+
|
|
393
|
+
const list = new MessageList().add(uniqueMessages, 'memory');
|
|
394
|
+
if (format === `v1`) return list.get.all.v1();
|
|
395
|
+
return list.get.all.v2();
|
|
396
|
+
} catch (error) {
|
|
397
|
+
throw new MastraError(
|
|
398
|
+
{
|
|
399
|
+
id: 'STORAGE_DYNAMODB_STORE_GET_MESSAGES_BY_ID_FAILED',
|
|
400
|
+
domain: ErrorDomain.STORAGE,
|
|
401
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
402
|
+
details: { messageIds: JSON.stringify(messageIds) },
|
|
403
|
+
},
|
|
404
|
+
error,
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
329
409
|
async saveMessages(args: { messages: MastraMessageV1[]; format?: undefined | 'v1' }): Promise<MastraMessageV1[]>;
|
|
330
410
|
async saveMessages(args: { messages: MastraMessageV2[]; format: 'v2' }): Promise<MastraMessageV2[]>;
|
|
331
411
|
async saveMessages(
|
|
@@ -417,13 +497,24 @@ export class MemoryStorageDynamoDB extends MemoryStorage {
|
|
|
417
497
|
}
|
|
418
498
|
}
|
|
419
499
|
|
|
420
|
-
async getThreadsByResourceIdPaginated(
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
500
|
+
async getThreadsByResourceIdPaginated(
|
|
501
|
+
args: {
|
|
502
|
+
resourceId: string;
|
|
503
|
+
page?: number;
|
|
504
|
+
perPage?: number;
|
|
505
|
+
} & ThreadSortOptions,
|
|
506
|
+
): Promise<PaginationInfo & { threads: StorageThreadType[] }> {
|
|
425
507
|
const { resourceId, page = 0, perPage = 100 } = args;
|
|
426
|
-
this.
|
|
508
|
+
const orderBy = this.castThreadOrderBy(args.orderBy);
|
|
509
|
+
const sortDirection = this.castThreadSortDirection(args.sortDirection);
|
|
510
|
+
|
|
511
|
+
this.logger.debug('Getting threads by resource ID with pagination', {
|
|
512
|
+
resourceId,
|
|
513
|
+
page,
|
|
514
|
+
perPage,
|
|
515
|
+
orderBy,
|
|
516
|
+
sortDirection,
|
|
517
|
+
});
|
|
427
518
|
|
|
428
519
|
try {
|
|
429
520
|
// Query threads by resource ID using the GSI
|
|
@@ -431,7 +522,9 @@ export class MemoryStorageDynamoDB extends MemoryStorage {
|
|
|
431
522
|
|
|
432
523
|
// Get all threads for this resource ID (DynamoDB doesn't support OFFSET/LIMIT)
|
|
433
524
|
const results = await query.go();
|
|
434
|
-
|
|
525
|
+
|
|
526
|
+
// Use shared helper method for transformation and sorting
|
|
527
|
+
const allThreads = this.transformAndSortThreads(results.data, orderBy, sortDirection);
|
|
435
528
|
|
|
436
529
|
// Apply pagination in memory
|
|
437
530
|
const startIndex = page * perPage;
|
|
@@ -3,6 +3,7 @@ import type { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
|
|
|
3
3
|
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
4
4
|
import {
|
|
5
5
|
StoreOperations,
|
|
6
|
+
TABLE_AI_SPANS,
|
|
6
7
|
TABLE_EVALS,
|
|
7
8
|
TABLE_MESSAGES,
|
|
8
9
|
TABLE_RESOURCES,
|
|
@@ -49,6 +50,7 @@ export class StoreOperationsDynamoDB extends StoreOperations {
|
|
|
49
50
|
[TABLE_SCORERS]: 'score',
|
|
50
51
|
[TABLE_TRACES]: 'trace',
|
|
51
52
|
[TABLE_RESOURCES]: 'resource',
|
|
53
|
+
[TABLE_AI_SPANS]: 'ai_span',
|
|
52
54
|
};
|
|
53
55
|
return mapping[tableName] || null;
|
|
54
56
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
2
|
-
import type { ScoreRowData } from '@mastra/core/scores';
|
|
2
|
+
import type { ScoreRowData, ScoringSource } from '@mastra/core/scores';
|
|
3
3
|
import { ScoresStorage } from '@mastra/core/storage';
|
|
4
4
|
import type { PaginationInfo, StoragePagination } from '@mastra/core/storage';
|
|
5
5
|
import type { Service } from 'electrodb';
|
|
@@ -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),
|
|
@@ -112,14 +115,14 @@ export class ScoresStorageDynamoDB extends ScoresStorage {
|
|
|
112
115
|
pagination,
|
|
113
116
|
entityId,
|
|
114
117
|
entityType,
|
|
118
|
+
source,
|
|
115
119
|
}: {
|
|
116
120
|
scorerId: string;
|
|
117
121
|
pagination: StoragePagination;
|
|
118
122
|
entityId?: string;
|
|
119
123
|
entityType?: string;
|
|
124
|
+
source?: ScoringSource;
|
|
120
125
|
}): Promise<{ pagination: PaginationInfo; scores: ScoreRowData[] }> {
|
|
121
|
-
this.logger.debug('Getting scores by scorer ID', { scorerId, pagination, entityId, entityType });
|
|
122
|
-
|
|
123
126
|
try {
|
|
124
127
|
// Query scores by scorer ID using the GSI
|
|
125
128
|
const query = this.service.entities.score.query.byScorer({ entity: 'score', scorerId });
|
|
@@ -135,6 +138,9 @@ export class ScoresStorageDynamoDB extends ScoresStorage {
|
|
|
135
138
|
if (entityType) {
|
|
136
139
|
allScores = allScores.filter((score: ScoreRowData) => score.entityType === entityType);
|
|
137
140
|
}
|
|
141
|
+
if (source) {
|
|
142
|
+
allScores = allScores.filter((score: ScoreRowData) => score.source === source);
|
|
143
|
+
}
|
|
138
144
|
|
|
139
145
|
// Sort by createdAt DESC (newest first)
|
|
140
146
|
allScores.sort((a: ScoreRowData, b: ScoreRowData) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
@@ -167,6 +173,7 @@ export class ScoresStorageDynamoDB extends ScoresStorage {
|
|
|
167
173
|
scorerId: scorerId || '',
|
|
168
174
|
entityId: entityId || '',
|
|
169
175
|
entityType: entityType || '',
|
|
176
|
+
source: source || '',
|
|
170
177
|
page: pagination.page,
|
|
171
178
|
perPage: pagination.perPage,
|
|
172
179
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
2
2
|
import { WorkflowsStorage } from '@mastra/core/storage';
|
|
3
3
|
import type { WorkflowRun, WorkflowRuns } from '@mastra/core/storage';
|
|
4
|
-
import type { WorkflowRunState } from '@mastra/core/workflows';
|
|
4
|
+
import type { StepResult, WorkflowRunState } from '@mastra/core/workflows';
|
|
5
5
|
import type { Service } from 'electrodb';
|
|
6
6
|
|
|
7
7
|
// Define the structure for workflow snapshot items retrieved from DynamoDB
|
|
@@ -34,6 +34,43 @@ export class WorkflowStorageDynamoDB extends WorkflowsStorage {
|
|
|
34
34
|
this.service = service;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
updateWorkflowResults(
|
|
38
|
+
{
|
|
39
|
+
// workflowName,
|
|
40
|
+
// runId,
|
|
41
|
+
// stepId,
|
|
42
|
+
// result,
|
|
43
|
+
// runtimeContext,
|
|
44
|
+
}: {
|
|
45
|
+
workflowName: string;
|
|
46
|
+
runId: string;
|
|
47
|
+
stepId: string;
|
|
48
|
+
result: StepResult<any, any, any, any>;
|
|
49
|
+
runtimeContext: Record<string, any>;
|
|
50
|
+
},
|
|
51
|
+
): Promise<Record<string, StepResult<any, any, any, any>>> {
|
|
52
|
+
throw new Error('Method not implemented.');
|
|
53
|
+
}
|
|
54
|
+
updateWorkflowState(
|
|
55
|
+
{
|
|
56
|
+
// workflowName,
|
|
57
|
+
// runId,
|
|
58
|
+
// opts,
|
|
59
|
+
}: {
|
|
60
|
+
workflowName: string;
|
|
61
|
+
runId: string;
|
|
62
|
+
opts: {
|
|
63
|
+
status: string;
|
|
64
|
+
result?: StepResult<any, any, any, any>;
|
|
65
|
+
error?: string;
|
|
66
|
+
suspendedPaths?: Record<string, number[]>;
|
|
67
|
+
waitingPaths?: Record<string, number[]>;
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
): Promise<WorkflowRunState | undefined> {
|
|
71
|
+
throw new Error('Method not implemented.');
|
|
72
|
+
}
|
|
73
|
+
|
|
37
74
|
// Workflow operations
|
|
38
75
|
async persistWorkflowSnapshot({
|
|
39
76
|
workflowName,
|
package/src/storage/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { MastraMessageContentV2 } from '@mastra/core/agent';
|
|
|
4
4
|
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
5
5
|
import type { StorageThreadType, MastraMessageV2, MastraMessageV1 } from '@mastra/core/memory';
|
|
6
6
|
|
|
7
|
-
import type { ScoreRowData } from '@mastra/core/scores';
|
|
7
|
+
import type { ScoreRowData, ScoringSource } from '@mastra/core/scores';
|
|
8
8
|
import { MastraStorage } from '@mastra/core/storage';
|
|
9
9
|
import type {
|
|
10
10
|
EvalRow,
|
|
@@ -19,9 +19,10 @@ 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
|
-
import type { WorkflowRunState } from '@mastra/core/workflows';
|
|
25
|
+
import type { StepResult, WorkflowRunState } from '@mastra/core/workflows';
|
|
25
26
|
import type { Service } from 'electrodb';
|
|
26
27
|
import { getElectroDbService } from '../entities';
|
|
27
28
|
import { LegacyEvalsDynamoDB } from './domains/legacy-evals';
|
|
@@ -121,6 +122,7 @@ export class DynamoDBStore extends MastraStorage {
|
|
|
121
122
|
resourceWorkingMemory: true,
|
|
122
123
|
hasColumn: false,
|
|
123
124
|
createTable: false,
|
|
125
|
+
deleteMessages: false,
|
|
124
126
|
};
|
|
125
127
|
}
|
|
126
128
|
|
|
@@ -253,8 +255,8 @@ export class DynamoDBStore extends MastraStorage {
|
|
|
253
255
|
return this.stores.memory.getThreadById({ threadId });
|
|
254
256
|
}
|
|
255
257
|
|
|
256
|
-
async getThreadsByResourceId(
|
|
257
|
-
return this.stores.memory.getThreadsByResourceId(
|
|
258
|
+
async getThreadsByResourceId(args: { resourceId: string } & ThreadSortOptions): Promise<StorageThreadType[]> {
|
|
259
|
+
return this.stores.memory.getThreadsByResourceId(args);
|
|
258
260
|
}
|
|
259
261
|
|
|
260
262
|
async saveThread({ thread }: { thread: StorageThreadType }): Promise<StorageThreadType> {
|
|
@@ -289,6 +291,18 @@ export class DynamoDBStore extends MastraStorage {
|
|
|
289
291
|
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
|
|
290
292
|
}
|
|
291
293
|
|
|
294
|
+
async getMessagesById({ messageIds, format }: { messageIds: string[]; format: 'v1' }): Promise<MastraMessageV1[]>;
|
|
295
|
+
async getMessagesById({ messageIds, format }: { messageIds: string[]; format?: 'v2' }): Promise<MastraMessageV2[]>;
|
|
296
|
+
async getMessagesById({
|
|
297
|
+
messageIds,
|
|
298
|
+
format,
|
|
299
|
+
}: {
|
|
300
|
+
messageIds: string[];
|
|
301
|
+
format?: 'v1' | 'v2';
|
|
302
|
+
}): Promise<MastraMessageV1[] | MastraMessageV2[]> {
|
|
303
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
304
|
+
}
|
|
305
|
+
|
|
292
306
|
async saveMessages(args: { messages: MastraMessageV1[]; format?: undefined | 'v1' }): Promise<MastraMessageV1[]>;
|
|
293
307
|
async saveMessages(args: { messages: MastraMessageV2[]; format: 'v2' }): Promise<MastraMessageV2[]>;
|
|
294
308
|
async saveMessages(
|
|
@@ -297,11 +311,13 @@ export class DynamoDBStore extends MastraStorage {
|
|
|
297
311
|
return this.stores.memory.saveMessages(args);
|
|
298
312
|
}
|
|
299
313
|
|
|
300
|
-
async getThreadsByResourceIdPaginated(
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
314
|
+
async getThreadsByResourceIdPaginated(
|
|
315
|
+
args: {
|
|
316
|
+
resourceId: string;
|
|
317
|
+
page: number;
|
|
318
|
+
perPage: number;
|
|
319
|
+
} & ThreadSortOptions,
|
|
320
|
+
): Promise<PaginationInfo & { threads: StorageThreadType[] }> {
|
|
305
321
|
return this.stores.memory.getThreadsByResourceIdPaginated(args);
|
|
306
322
|
}
|
|
307
323
|
|
|
@@ -342,6 +358,40 @@ export class DynamoDBStore extends MastraStorage {
|
|
|
342
358
|
}
|
|
343
359
|
|
|
344
360
|
// Workflow operations
|
|
361
|
+
async updateWorkflowResults({
|
|
362
|
+
workflowName,
|
|
363
|
+
runId,
|
|
364
|
+
stepId,
|
|
365
|
+
result,
|
|
366
|
+
runtimeContext,
|
|
367
|
+
}: {
|
|
368
|
+
workflowName: string;
|
|
369
|
+
runId: string;
|
|
370
|
+
stepId: string;
|
|
371
|
+
result: StepResult<any, any, any, any>;
|
|
372
|
+
runtimeContext: Record<string, any>;
|
|
373
|
+
}): Promise<Record<string, StepResult<any, any, any, any>>> {
|
|
374
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
async updateWorkflowState({
|
|
378
|
+
workflowName,
|
|
379
|
+
runId,
|
|
380
|
+
opts,
|
|
381
|
+
}: {
|
|
382
|
+
workflowName: string;
|
|
383
|
+
runId: string;
|
|
384
|
+
opts: {
|
|
385
|
+
status: string;
|
|
386
|
+
result?: StepResult<any, any, any, any>;
|
|
387
|
+
error?: string;
|
|
388
|
+
suspendedPaths?: Record<string, number[]>;
|
|
389
|
+
waitingPaths?: Record<string, number[]>;
|
|
390
|
+
};
|
|
391
|
+
}): Promise<WorkflowRunState | undefined> {
|
|
392
|
+
return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
|
|
393
|
+
}
|
|
394
|
+
|
|
345
395
|
async persistWorkflowSnapshot({
|
|
346
396
|
workflowName,
|
|
347
397
|
runId,
|
|
@@ -471,12 +521,18 @@ export class DynamoDBStore extends MastraStorage {
|
|
|
471
521
|
}
|
|
472
522
|
|
|
473
523
|
async getScoresByScorerId({
|
|
474
|
-
scorerId
|
|
475
|
-
|
|
524
|
+
scorerId,
|
|
525
|
+
source,
|
|
526
|
+
entityId,
|
|
527
|
+
entityType,
|
|
528
|
+
pagination,
|
|
476
529
|
}: {
|
|
477
530
|
scorerId: string;
|
|
531
|
+
entityId?: string;
|
|
532
|
+
entityType?: string;
|
|
533
|
+
source?: ScoringSource;
|
|
478
534
|
pagination: StoragePagination;
|
|
479
535
|
}): Promise<{ pagination: PaginationInfo; scores: ScoreRowData[] }> {
|
|
480
|
-
return this.stores.scores.getScoresByScorerId({ scorerId
|
|
536
|
+
return this.stores.scores.getScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
|
|
481
537
|
}
|
|
482
538
|
}
|