@mastra/dynamodb 0.14.3 → 0.14.6-alpha.0
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 +743 -0
- package/dist/index.cjs +34 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +35 -2
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/operations/index.d.ts.map +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 +19 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +16 -7
- package/src/entities/eval.ts +0 -102
- package/src/entities/index.ts +0 -27
- package/src/entities/message.ts +0 -143
- package/src/entities/resource.ts +0 -57
- package/src/entities/score.ts +0 -317
- package/src/entities/thread.ts +0 -66
- package/src/entities/trace.ts +0 -129
- package/src/entities/utils.ts +0 -51
- package/src/entities/workflow-snapshot.ts +0 -56
- package/src/index.ts +0 -1
- package/src/storage/docker-compose.yml +0 -16
- package/src/storage/domains/legacy-evals/index.ts +0 -243
- package/src/storage/domains/memory/index.ts +0 -987
- package/src/storage/domains/operations/index.ts +0 -433
- package/src/storage/domains/score/index.ts +0 -292
- package/src/storage/domains/traces/index.ts +0 -286
- package/src/storage/domains/workflows/index.ts +0 -297
- package/src/storage/index.test.ts +0 -1420
- package/src/storage/index.ts +0 -504
package/src/storage/index.ts
DELETED
|
@@ -1,504 +0,0 @@
|
|
|
1
|
-
import { DynamoDBClient, DescribeTableCommand } from '@aws-sdk/client-dynamodb';
|
|
2
|
-
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
|
|
3
|
-
import type { MastraMessageContentV2 } from '@mastra/core/agent';
|
|
4
|
-
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
5
|
-
import type { StorageThreadType, MastraMessageV2, MastraMessageV1 } from '@mastra/core/memory';
|
|
6
|
-
|
|
7
|
-
import type { ScoreRowData, ScoringSource } from '@mastra/core/scores';
|
|
8
|
-
import { MastraStorage } from '@mastra/core/storage';
|
|
9
|
-
import type {
|
|
10
|
-
EvalRow,
|
|
11
|
-
StorageGetMessagesArg,
|
|
12
|
-
WorkflowRun,
|
|
13
|
-
WorkflowRuns,
|
|
14
|
-
TABLE_NAMES,
|
|
15
|
-
StorageGetTracesArg,
|
|
16
|
-
PaginationInfo,
|
|
17
|
-
StorageColumn,
|
|
18
|
-
StoragePagination,
|
|
19
|
-
StorageDomains,
|
|
20
|
-
PaginationArgs,
|
|
21
|
-
StorageResourceType,
|
|
22
|
-
ThreadSortOptions,
|
|
23
|
-
} from '@mastra/core/storage';
|
|
24
|
-
import type { Trace } from '@mastra/core/telemetry';
|
|
25
|
-
import type { WorkflowRunState } from '@mastra/core/workflows';
|
|
26
|
-
import type { Service } from 'electrodb';
|
|
27
|
-
import { getElectroDbService } from '../entities';
|
|
28
|
-
import { LegacyEvalsDynamoDB } from './domains/legacy-evals';
|
|
29
|
-
import { MemoryStorageDynamoDB } from './domains/memory';
|
|
30
|
-
import { StoreOperationsDynamoDB } from './domains/operations';
|
|
31
|
-
import { ScoresStorageDynamoDB } from './domains/score';
|
|
32
|
-
import { TracesStorageDynamoDB } from './domains/traces';
|
|
33
|
-
import { WorkflowStorageDynamoDB } from './domains/workflows';
|
|
34
|
-
|
|
35
|
-
export interface DynamoDBStoreConfig {
|
|
36
|
-
region?: string;
|
|
37
|
-
tableName: string;
|
|
38
|
-
endpoint?: string;
|
|
39
|
-
credentials?: {
|
|
40
|
-
accessKeyId: string;
|
|
41
|
-
secretAccessKey: string;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Define a type for our service that allows string indexing
|
|
46
|
-
type MastraService = Service<Record<string, any>> & {
|
|
47
|
-
[key: string]: any;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export class DynamoDBStore extends MastraStorage {
|
|
51
|
-
private tableName: string;
|
|
52
|
-
private client: DynamoDBDocumentClient;
|
|
53
|
-
private service: MastraService;
|
|
54
|
-
protected hasInitialized: Promise<boolean> | null = null;
|
|
55
|
-
stores: StorageDomains;
|
|
56
|
-
|
|
57
|
-
constructor({ name, config }: { name: string; config: DynamoDBStoreConfig }) {
|
|
58
|
-
super({ name });
|
|
59
|
-
|
|
60
|
-
// Validate required config
|
|
61
|
-
try {
|
|
62
|
-
if (!config.tableName || typeof config.tableName !== 'string' || config.tableName.trim() === '') {
|
|
63
|
-
throw new Error('DynamoDBStore: config.tableName must be provided and cannot be empty.');
|
|
64
|
-
}
|
|
65
|
-
// Validate tableName characters (basic check)
|
|
66
|
-
if (!/^[a-zA-Z0-9_.-]{3,255}$/.test(config.tableName)) {
|
|
67
|
-
throw new Error(
|
|
68
|
-
`DynamoDBStore: config.tableName "${config.tableName}" contains invalid characters or is not between 3 and 255 characters long.`,
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const dynamoClient = new DynamoDBClient({
|
|
73
|
-
region: config.region || 'us-east-1',
|
|
74
|
-
endpoint: config.endpoint,
|
|
75
|
-
credentials: config.credentials,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
this.tableName = config.tableName;
|
|
79
|
-
this.client = DynamoDBDocumentClient.from(dynamoClient);
|
|
80
|
-
this.service = getElectroDbService(this.client, this.tableName) as MastraService;
|
|
81
|
-
|
|
82
|
-
const operations = new StoreOperationsDynamoDB({
|
|
83
|
-
service: this.service,
|
|
84
|
-
tableName: this.tableName,
|
|
85
|
-
client: this.client,
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
const traces = new TracesStorageDynamoDB({ service: this.service, operations });
|
|
89
|
-
|
|
90
|
-
const workflows = new WorkflowStorageDynamoDB({ service: this.service });
|
|
91
|
-
|
|
92
|
-
const memory = new MemoryStorageDynamoDB({ service: this.service });
|
|
93
|
-
|
|
94
|
-
const scores = new ScoresStorageDynamoDB({ service: this.service });
|
|
95
|
-
|
|
96
|
-
this.stores = {
|
|
97
|
-
operations,
|
|
98
|
-
legacyEvals: new LegacyEvalsDynamoDB({ service: this.service, tableName: this.tableName }),
|
|
99
|
-
traces,
|
|
100
|
-
workflows,
|
|
101
|
-
memory,
|
|
102
|
-
scores,
|
|
103
|
-
};
|
|
104
|
-
} catch (error) {
|
|
105
|
-
throw new MastraError(
|
|
106
|
-
{
|
|
107
|
-
id: 'STORAGE_DYNAMODB_STORE_CONSTRUCTOR_FAILED',
|
|
108
|
-
domain: ErrorDomain.STORAGE,
|
|
109
|
-
category: ErrorCategory.USER,
|
|
110
|
-
},
|
|
111
|
-
error,
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// We're using a single table design with ElectroDB,
|
|
116
|
-
// so we don't need to create multiple tables
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
get supports() {
|
|
120
|
-
return {
|
|
121
|
-
selectByIncludeResourceScope: true,
|
|
122
|
-
resourceWorkingMemory: true,
|
|
123
|
-
hasColumn: false,
|
|
124
|
-
createTable: false,
|
|
125
|
-
deleteMessages: false,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Validates that the required DynamoDB table exists and is accessible.
|
|
131
|
-
* This does not check the table structure - it assumes the table
|
|
132
|
-
* was created with the correct structure via CDK/CloudFormation.
|
|
133
|
-
*/
|
|
134
|
-
private async validateTableExists(): Promise<boolean> {
|
|
135
|
-
try {
|
|
136
|
-
const command = new DescribeTableCommand({
|
|
137
|
-
TableName: this.tableName,
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
// If the table exists, this call will succeed
|
|
141
|
-
// If the table doesn't exist, it will throw a ResourceNotFoundException
|
|
142
|
-
await this.client.send(command);
|
|
143
|
-
return true;
|
|
144
|
-
} catch (error: any) {
|
|
145
|
-
// If the table doesn't exist, DynamoDB returns a ResourceNotFoundException
|
|
146
|
-
if (error.name === 'ResourceNotFoundException') {
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// For other errors (like permissions issues), we should throw
|
|
151
|
-
throw new MastraError(
|
|
152
|
-
{
|
|
153
|
-
id: 'STORAGE_DYNAMODB_STORE_VALIDATE_TABLE_EXISTS_FAILED',
|
|
154
|
-
domain: ErrorDomain.STORAGE,
|
|
155
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
156
|
-
details: { tableName: this.tableName },
|
|
157
|
-
},
|
|
158
|
-
error,
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Initialize storage, validating the externally managed table is accessible.
|
|
165
|
-
* For the single-table design, we only validate once that we can access
|
|
166
|
-
* the table that was created via CDK/CloudFormation.
|
|
167
|
-
*/
|
|
168
|
-
async init(): Promise<void> {
|
|
169
|
-
if (this.hasInitialized === null) {
|
|
170
|
-
// If no initialization promise exists, create and store it.
|
|
171
|
-
// This assignment ensures that even if multiple calls arrive here concurrently,
|
|
172
|
-
// they will all eventually await the same promise instance created by the first one
|
|
173
|
-
// to complete this assignment.
|
|
174
|
-
this.hasInitialized = this._performInitializationAndStore();
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
try {
|
|
178
|
-
// Await the stored promise.
|
|
179
|
-
// If initialization was successful, this resolves.
|
|
180
|
-
// If it failed, this will re-throw the error caught and re-thrown by _performInitializationAndStore.
|
|
181
|
-
await this.hasInitialized;
|
|
182
|
-
} catch (error) {
|
|
183
|
-
// The error has already been handled by _performInitializationAndStore
|
|
184
|
-
// (i.e., this.hasInitialized was reset). Re-throwing here ensures
|
|
185
|
-
// the caller of init() is aware of the failure.
|
|
186
|
-
throw new MastraError(
|
|
187
|
-
{
|
|
188
|
-
id: 'STORAGE_DYNAMODB_STORE_INIT_FAILED',
|
|
189
|
-
domain: ErrorDomain.STORAGE,
|
|
190
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
191
|
-
details: { tableName: this.tableName },
|
|
192
|
-
},
|
|
193
|
-
error,
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Performs the actual table validation and stores the promise.
|
|
200
|
-
* Handles resetting the stored promise on failure to allow retries.
|
|
201
|
-
*/
|
|
202
|
-
private _performInitializationAndStore(): Promise<boolean> {
|
|
203
|
-
return this.validateTableExists()
|
|
204
|
-
.then(exists => {
|
|
205
|
-
if (!exists) {
|
|
206
|
-
throw new Error(
|
|
207
|
-
`Table ${this.tableName} does not exist or is not accessible. Ensure it's created via CDK/CloudFormation before using this store.`,
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
// Successfully initialized
|
|
211
|
-
return true;
|
|
212
|
-
})
|
|
213
|
-
.catch(err => {
|
|
214
|
-
// Initialization failed. Clear the stored promise to allow future calls to init() to retry.
|
|
215
|
-
this.hasInitialized = null;
|
|
216
|
-
// Re-throw the error so it can be caught by the awaiter in init()
|
|
217
|
-
throw err;
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
async createTable({ tableName, schema }: { tableName: TABLE_NAMES; schema: Record<string, any> }): Promise<void> {
|
|
222
|
-
return this.stores.operations.createTable({ tableName, schema });
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
async alterTable(_args: {
|
|
226
|
-
tableName: TABLE_NAMES;
|
|
227
|
-
schema: Record<string, StorageColumn>;
|
|
228
|
-
ifNotExists: string[];
|
|
229
|
-
}): Promise<void> {
|
|
230
|
-
return this.stores.operations.alterTable(_args);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
async clearTable({ tableName }: { tableName: TABLE_NAMES }): Promise<void> {
|
|
234
|
-
return this.stores.operations.clearTable({ tableName });
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
async dropTable({ tableName }: { tableName: TABLE_NAMES }): Promise<void> {
|
|
238
|
-
return this.stores.operations.dropTable({ tableName });
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
async insert({ tableName, record }: { tableName: TABLE_NAMES; record: Record<string, any> }): Promise<void> {
|
|
242
|
-
return this.stores.operations.insert({ tableName, record });
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
async batchInsert({ tableName, records }: { tableName: TABLE_NAMES; records: Record<string, any>[] }): Promise<void> {
|
|
246
|
-
return this.stores.operations.batchInsert({ tableName, records });
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
async load<R>({ tableName, keys }: { tableName: TABLE_NAMES; keys: Record<string, string> }): Promise<R | null> {
|
|
250
|
-
return this.stores.operations.load({ tableName, keys });
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// Thread operations
|
|
254
|
-
async getThreadById({ threadId }: { threadId: string }): Promise<StorageThreadType | null> {
|
|
255
|
-
return this.stores.memory.getThreadById({ threadId });
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
async getThreadsByResourceId(args: { resourceId: string } & ThreadSortOptions): Promise<StorageThreadType[]> {
|
|
259
|
-
return this.stores.memory.getThreadsByResourceId(args);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
async saveThread({ thread }: { thread: StorageThreadType }): Promise<StorageThreadType> {
|
|
263
|
-
return this.stores.memory.saveThread({ thread });
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
async updateThread({
|
|
267
|
-
id,
|
|
268
|
-
title,
|
|
269
|
-
metadata,
|
|
270
|
-
}: {
|
|
271
|
-
id: string;
|
|
272
|
-
title: string;
|
|
273
|
-
metadata: Record<string, unknown>;
|
|
274
|
-
}): Promise<StorageThreadType> {
|
|
275
|
-
return this.stores.memory.updateThread({ id, title, metadata });
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
async deleteThread({ threadId }: { threadId: string }): Promise<void> {
|
|
279
|
-
return this.stores.memory.deleteThread({ threadId });
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// Message operations
|
|
283
|
-
public async getMessages(args: StorageGetMessagesArg & { format?: 'v1' }): Promise<MastraMessageV1[]>;
|
|
284
|
-
public async getMessages(args: StorageGetMessagesArg & { format: 'v2' }): Promise<MastraMessageV2[]>;
|
|
285
|
-
public async getMessages({
|
|
286
|
-
threadId,
|
|
287
|
-
resourceId,
|
|
288
|
-
selectBy,
|
|
289
|
-
format,
|
|
290
|
-
}: StorageGetMessagesArg & { format?: 'v1' | 'v2' }): Promise<MastraMessageV1[] | MastraMessageV2[]> {
|
|
291
|
-
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
|
|
292
|
-
}
|
|
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
|
-
|
|
306
|
-
async saveMessages(args: { messages: MastraMessageV1[]; format?: undefined | 'v1' }): Promise<MastraMessageV1[]>;
|
|
307
|
-
async saveMessages(args: { messages: MastraMessageV2[]; format: 'v2' }): Promise<MastraMessageV2[]>;
|
|
308
|
-
async saveMessages(
|
|
309
|
-
args: { messages: MastraMessageV1[]; format?: undefined | 'v1' } | { messages: MastraMessageV2[]; format: 'v2' },
|
|
310
|
-
): Promise<MastraMessageV2[] | MastraMessageV1[]> {
|
|
311
|
-
return this.stores.memory.saveMessages(args);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
async getThreadsByResourceIdPaginated(
|
|
315
|
-
args: {
|
|
316
|
-
resourceId: string;
|
|
317
|
-
page: number;
|
|
318
|
-
perPage: number;
|
|
319
|
-
} & ThreadSortOptions,
|
|
320
|
-
): Promise<PaginationInfo & { threads: StorageThreadType[] }> {
|
|
321
|
-
return this.stores.memory.getThreadsByResourceIdPaginated(args);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
async getMessagesPaginated(
|
|
325
|
-
args: StorageGetMessagesArg & { format?: 'v1' | 'v2' },
|
|
326
|
-
): Promise<PaginationInfo & { messages: MastraMessageV1[] | MastraMessageV2[] }> {
|
|
327
|
-
return this.stores.memory.getMessagesPaginated(args);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
async updateMessages(_args: {
|
|
331
|
-
messages: Partial<Omit<MastraMessageV2, 'createdAt'>> &
|
|
332
|
-
{
|
|
333
|
-
id: string;
|
|
334
|
-
content?: { metadata?: MastraMessageContentV2['metadata']; content?: MastraMessageContentV2['content'] };
|
|
335
|
-
}[];
|
|
336
|
-
}): Promise<MastraMessageV2[]> {
|
|
337
|
-
return this.stores.memory.updateMessages(_args);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
// Trace operations
|
|
341
|
-
async getTraces(args: {
|
|
342
|
-
name?: string;
|
|
343
|
-
scope?: string;
|
|
344
|
-
page: number;
|
|
345
|
-
perPage: number;
|
|
346
|
-
attributes?: Record<string, string>;
|
|
347
|
-
filters?: Record<string, any>;
|
|
348
|
-
}): Promise<any[]> {
|
|
349
|
-
return this.stores.traces.getTraces(args);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
async batchTraceInsert({ records }: { records: Record<string, any>[] }): Promise<void> {
|
|
353
|
-
return this.stores.traces.batchTraceInsert({ records });
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
async getTracesPaginated(_args: StorageGetTracesArg): Promise<PaginationInfo & { traces: Trace[] }> {
|
|
357
|
-
return this.stores.traces.getTracesPaginated(_args);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
// Workflow operations
|
|
361
|
-
async persistWorkflowSnapshot({
|
|
362
|
-
workflowName,
|
|
363
|
-
runId,
|
|
364
|
-
snapshot,
|
|
365
|
-
}: {
|
|
366
|
-
workflowName: string;
|
|
367
|
-
runId: string;
|
|
368
|
-
snapshot: WorkflowRunState;
|
|
369
|
-
}): Promise<void> {
|
|
370
|
-
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, snapshot });
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
async loadWorkflowSnapshot({
|
|
374
|
-
workflowName,
|
|
375
|
-
runId,
|
|
376
|
-
}: {
|
|
377
|
-
workflowName: string;
|
|
378
|
-
runId: string;
|
|
379
|
-
}): Promise<WorkflowRunState | null> {
|
|
380
|
-
return this.stores.workflows.loadWorkflowSnapshot({ workflowName, runId });
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
async getWorkflowRuns(args?: {
|
|
384
|
-
workflowName?: string;
|
|
385
|
-
fromDate?: Date;
|
|
386
|
-
toDate?: Date;
|
|
387
|
-
limit?: number;
|
|
388
|
-
offset?: number;
|
|
389
|
-
resourceId?: string;
|
|
390
|
-
}): Promise<WorkflowRuns> {
|
|
391
|
-
return this.stores.workflows.getWorkflowRuns(args);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
async getWorkflowRunById(args: { runId: string; workflowName?: string }): Promise<WorkflowRun | null> {
|
|
395
|
-
return this.stores.workflows.getWorkflowRunById(args);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
async getResourceById({ resourceId }: { resourceId: string }): Promise<StorageResourceType | null> {
|
|
399
|
-
return this.stores.memory.getResourceById({ resourceId });
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
async saveResource({ resource }: { resource: StorageResourceType }): Promise<StorageResourceType> {
|
|
403
|
-
return this.stores.memory.saveResource({ resource });
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
async updateResource({
|
|
407
|
-
resourceId,
|
|
408
|
-
workingMemory,
|
|
409
|
-
metadata,
|
|
410
|
-
}: {
|
|
411
|
-
resourceId: string;
|
|
412
|
-
workingMemory?: string;
|
|
413
|
-
metadata?: Record<string, any>;
|
|
414
|
-
}): Promise<StorageResourceType> {
|
|
415
|
-
return this.stores.memory.updateResource({ resourceId, workingMemory, metadata });
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
// Eval operations
|
|
419
|
-
async getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]> {
|
|
420
|
-
return this.stores.legacyEvals.getEvalsByAgentName(agentName, type);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
async getEvals(
|
|
424
|
-
options: {
|
|
425
|
-
agentName?: string;
|
|
426
|
-
type?: 'test' | 'live';
|
|
427
|
-
} & PaginationArgs,
|
|
428
|
-
): Promise<PaginationInfo & { evals: EvalRow[] }> {
|
|
429
|
-
return this.stores.legacyEvals.getEvals(options);
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* Closes the DynamoDB client connection and cleans up resources.
|
|
434
|
-
* Should be called when the store is no longer needed, e.g., at the end of tests or application shutdown.
|
|
435
|
-
*/
|
|
436
|
-
public async close(): Promise<void> {
|
|
437
|
-
this.logger.debug('Closing DynamoDB client for store:', { name: this.name });
|
|
438
|
-
try {
|
|
439
|
-
this.client.destroy();
|
|
440
|
-
this.logger.debug('DynamoDB client closed successfully for store:', { name: this.name });
|
|
441
|
-
} catch (error) {
|
|
442
|
-
throw new MastraError(
|
|
443
|
-
{
|
|
444
|
-
id: 'STORAGE_DYNAMODB_STORE_CLOSE_FAILED',
|
|
445
|
-
domain: ErrorDomain.STORAGE,
|
|
446
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
447
|
-
},
|
|
448
|
-
error,
|
|
449
|
-
);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
/**
|
|
453
|
-
* SCORERS - Not implemented
|
|
454
|
-
*/
|
|
455
|
-
async getScoreById({ id: _id }: { id: string }): Promise<ScoreRowData | null> {
|
|
456
|
-
return this.stores.scores.getScoreById({ id: _id });
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
async saveScore(_score: ScoreRowData): Promise<{ score: ScoreRowData }> {
|
|
460
|
-
return this.stores.scores.saveScore(_score);
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
async getScoresByRunId({
|
|
464
|
-
runId: _runId,
|
|
465
|
-
pagination: _pagination,
|
|
466
|
-
}: {
|
|
467
|
-
runId: string;
|
|
468
|
-
pagination: StoragePagination;
|
|
469
|
-
}): Promise<{ pagination: PaginationInfo; scores: ScoreRowData[] }> {
|
|
470
|
-
return this.stores.scores.getScoresByRunId({ runId: _runId, pagination: _pagination });
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
async getScoresByEntityId({
|
|
474
|
-
entityId: _entityId,
|
|
475
|
-
entityType: _entityType,
|
|
476
|
-
pagination: _pagination,
|
|
477
|
-
}: {
|
|
478
|
-
pagination: StoragePagination;
|
|
479
|
-
entityId: string;
|
|
480
|
-
entityType: string;
|
|
481
|
-
}): Promise<{ pagination: PaginationInfo; scores: ScoreRowData[] }> {
|
|
482
|
-
return this.stores.scores.getScoresByEntityId({
|
|
483
|
-
entityId: _entityId,
|
|
484
|
-
entityType: _entityType,
|
|
485
|
-
pagination: _pagination,
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
async getScoresByScorerId({
|
|
490
|
-
scorerId,
|
|
491
|
-
source,
|
|
492
|
-
entityId,
|
|
493
|
-
entityType,
|
|
494
|
-
pagination,
|
|
495
|
-
}: {
|
|
496
|
-
scorerId: string;
|
|
497
|
-
entityId?: string;
|
|
498
|
-
entityType?: string;
|
|
499
|
-
source?: ScoringSource;
|
|
500
|
-
pagination: StoragePagination;
|
|
501
|
-
}): Promise<{ pagination: PaginationInfo; scores: ScoreRowData[] }> {
|
|
502
|
-
return this.stores.scores.getScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
|
|
503
|
-
}
|
|
504
|
-
}
|