@mastra/dynamodb 0.14.5 → 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/package.json +13 -4
- 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 -435
- 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 -334
- package/src/storage/index.test.ts +0 -1420
- package/src/storage/index.ts +0 -538
package/src/entities/thread.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { Entity } from 'electrodb';
|
|
2
|
-
import { baseAttributes } from './utils';
|
|
3
|
-
|
|
4
|
-
export const threadEntity = new Entity({
|
|
5
|
-
model: {
|
|
6
|
-
entity: 'thread',
|
|
7
|
-
version: '1',
|
|
8
|
-
service: 'mastra',
|
|
9
|
-
},
|
|
10
|
-
attributes: {
|
|
11
|
-
entity: {
|
|
12
|
-
type: 'string',
|
|
13
|
-
required: true,
|
|
14
|
-
},
|
|
15
|
-
...baseAttributes,
|
|
16
|
-
id: {
|
|
17
|
-
type: 'string',
|
|
18
|
-
required: true,
|
|
19
|
-
},
|
|
20
|
-
resourceId: {
|
|
21
|
-
type: 'string',
|
|
22
|
-
required: true,
|
|
23
|
-
},
|
|
24
|
-
title: {
|
|
25
|
-
type: 'string',
|
|
26
|
-
required: true,
|
|
27
|
-
},
|
|
28
|
-
metadata: {
|
|
29
|
-
type: 'string',
|
|
30
|
-
required: false,
|
|
31
|
-
// Stringify metadata object on set if it's not already a string
|
|
32
|
-
set: (value?: Record<string, unknown> | string) => {
|
|
33
|
-
if (value && typeof value !== 'string') {
|
|
34
|
-
return JSON.stringify(value);
|
|
35
|
-
}
|
|
36
|
-
return value;
|
|
37
|
-
},
|
|
38
|
-
// Parse JSON string to object on get
|
|
39
|
-
get: (value?: string) => {
|
|
40
|
-
if (value && typeof value === 'string') {
|
|
41
|
-
try {
|
|
42
|
-
// Attempt to parse only if it might be JSON (e.g., starts with { or [)
|
|
43
|
-
if (value.startsWith('{') || value.startsWith('[')) {
|
|
44
|
-
return JSON.parse(value);
|
|
45
|
-
}
|
|
46
|
-
} catch {
|
|
47
|
-
// Ignore parse error, return original string
|
|
48
|
-
return value;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return value;
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
indexes: {
|
|
56
|
-
primary: {
|
|
57
|
-
pk: { field: 'pk', composite: ['entity', 'id'] },
|
|
58
|
-
sk: { field: 'sk', composite: ['id'] },
|
|
59
|
-
},
|
|
60
|
-
byResource: {
|
|
61
|
-
index: 'gsi1',
|
|
62
|
-
pk: { field: 'gsi1pk', composite: ['entity', 'resourceId'] },
|
|
63
|
-
sk: { field: 'gsi1sk', composite: ['createdAt'] },
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
});
|
package/src/entities/trace.ts
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { Entity } from 'electrodb';
|
|
2
|
-
import { baseAttributes } from './utils';
|
|
3
|
-
|
|
4
|
-
export const traceEntity = new Entity({
|
|
5
|
-
model: {
|
|
6
|
-
entity: 'trace',
|
|
7
|
-
version: '1',
|
|
8
|
-
service: 'mastra',
|
|
9
|
-
},
|
|
10
|
-
attributes: {
|
|
11
|
-
entity: {
|
|
12
|
-
type: 'string',
|
|
13
|
-
required: true,
|
|
14
|
-
},
|
|
15
|
-
...baseAttributes,
|
|
16
|
-
id: {
|
|
17
|
-
type: 'string',
|
|
18
|
-
required: true,
|
|
19
|
-
},
|
|
20
|
-
parentSpanId: {
|
|
21
|
-
type: 'string',
|
|
22
|
-
required: false,
|
|
23
|
-
},
|
|
24
|
-
name: {
|
|
25
|
-
type: 'string',
|
|
26
|
-
required: true,
|
|
27
|
-
},
|
|
28
|
-
traceId: {
|
|
29
|
-
type: 'string',
|
|
30
|
-
required: true,
|
|
31
|
-
},
|
|
32
|
-
scope: {
|
|
33
|
-
type: 'string',
|
|
34
|
-
required: true,
|
|
35
|
-
},
|
|
36
|
-
kind: {
|
|
37
|
-
type: 'number',
|
|
38
|
-
required: true,
|
|
39
|
-
},
|
|
40
|
-
attributes: {
|
|
41
|
-
type: 'string', // JSON stringified
|
|
42
|
-
required: false,
|
|
43
|
-
// Stringify object on set
|
|
44
|
-
set: (value?: any) => {
|
|
45
|
-
if (value && typeof value !== 'string') {
|
|
46
|
-
return JSON.stringify(value);
|
|
47
|
-
}
|
|
48
|
-
return value;
|
|
49
|
-
},
|
|
50
|
-
// Parse JSON string to object on get
|
|
51
|
-
get: (value?: string) => {
|
|
52
|
-
return value ? JSON.parse(value) : value;
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
status: {
|
|
56
|
-
type: 'string', // JSON stringified
|
|
57
|
-
required: false,
|
|
58
|
-
// Stringify object on set
|
|
59
|
-
set: (value?: any) => {
|
|
60
|
-
if (value && typeof value !== 'string') {
|
|
61
|
-
return JSON.stringify(value);
|
|
62
|
-
}
|
|
63
|
-
return value;
|
|
64
|
-
},
|
|
65
|
-
// Parse JSON string to object on get
|
|
66
|
-
get: (value?: string) => {
|
|
67
|
-
return value;
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
events: {
|
|
71
|
-
type: 'string', // JSON stringified
|
|
72
|
-
required: false,
|
|
73
|
-
// Stringify object on set
|
|
74
|
-
set: (value?: any) => {
|
|
75
|
-
if (value && typeof value !== 'string') {
|
|
76
|
-
return JSON.stringify(value);
|
|
77
|
-
}
|
|
78
|
-
return value;
|
|
79
|
-
},
|
|
80
|
-
// Parse JSON string to object on get
|
|
81
|
-
get: (value?: string) => {
|
|
82
|
-
return value;
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
links: {
|
|
86
|
-
type: 'string', // JSON stringified
|
|
87
|
-
required: false,
|
|
88
|
-
// Stringify object on set
|
|
89
|
-
set: (value?: any) => {
|
|
90
|
-
if (value && typeof value !== 'string') {
|
|
91
|
-
return JSON.stringify(value);
|
|
92
|
-
}
|
|
93
|
-
return value;
|
|
94
|
-
},
|
|
95
|
-
// Parse JSON string to object on get
|
|
96
|
-
get: (value?: string) => {
|
|
97
|
-
return value;
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
other: {
|
|
101
|
-
type: 'string',
|
|
102
|
-
required: false,
|
|
103
|
-
},
|
|
104
|
-
startTime: {
|
|
105
|
-
type: 'number',
|
|
106
|
-
required: true,
|
|
107
|
-
},
|
|
108
|
-
endTime: {
|
|
109
|
-
type: 'number',
|
|
110
|
-
required: true,
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
indexes: {
|
|
114
|
-
primary: {
|
|
115
|
-
pk: { field: 'pk', composite: ['entity', 'id'] },
|
|
116
|
-
sk: { field: 'sk', composite: [] },
|
|
117
|
-
},
|
|
118
|
-
byName: {
|
|
119
|
-
index: 'gsi1',
|
|
120
|
-
pk: { field: 'gsi1pk', composite: ['entity', 'name'] },
|
|
121
|
-
sk: { field: 'gsi1sk', composite: ['startTime'] },
|
|
122
|
-
},
|
|
123
|
-
byScope: {
|
|
124
|
-
index: 'gsi2',
|
|
125
|
-
pk: { field: 'gsi2pk', composite: ['entity', 'scope'] },
|
|
126
|
-
sk: { field: 'gsi2sk', composite: ['startTime'] },
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
});
|
package/src/entities/utils.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export const baseAttributes = {
|
|
2
|
-
createdAt: {
|
|
3
|
-
type: 'string',
|
|
4
|
-
required: true,
|
|
5
|
-
readOnly: true,
|
|
6
|
-
// Convert Date to ISO string on set
|
|
7
|
-
set: (value?: Date | string) => {
|
|
8
|
-
if (value instanceof Date) {
|
|
9
|
-
return value.toISOString();
|
|
10
|
-
}
|
|
11
|
-
return value || new Date().toISOString();
|
|
12
|
-
},
|
|
13
|
-
// Initialize with current timestamp if not provided
|
|
14
|
-
default: () => new Date().toISOString(),
|
|
15
|
-
},
|
|
16
|
-
updatedAt: {
|
|
17
|
-
type: 'string',
|
|
18
|
-
required: true,
|
|
19
|
-
// Convert Date to ISO string on set
|
|
20
|
-
set: (value?: Date | string) => {
|
|
21
|
-
if (value instanceof Date) {
|
|
22
|
-
return value.toISOString();
|
|
23
|
-
}
|
|
24
|
-
return value || new Date().toISOString();
|
|
25
|
-
},
|
|
26
|
-
// Always use current timestamp when creating/updating
|
|
27
|
-
default: () => new Date().toISOString(),
|
|
28
|
-
},
|
|
29
|
-
metadata: {
|
|
30
|
-
type: 'string', // JSON stringified
|
|
31
|
-
// Stringify objects on set
|
|
32
|
-
set: (value?: Record<string, unknown> | string) => {
|
|
33
|
-
if (value && typeof value !== 'string') {
|
|
34
|
-
return JSON.stringify(value);
|
|
35
|
-
}
|
|
36
|
-
return value;
|
|
37
|
-
},
|
|
38
|
-
// Parse JSON string to object on get
|
|
39
|
-
get: (value?: string) => {
|
|
40
|
-
if (value) {
|
|
41
|
-
try {
|
|
42
|
-
return JSON.parse(value);
|
|
43
|
-
} catch {
|
|
44
|
-
// If parsing fails, return the original string
|
|
45
|
-
return value;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return value;
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
} as const;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { Entity } from 'electrodb';
|
|
2
|
-
import { baseAttributes } from './utils';
|
|
3
|
-
|
|
4
|
-
export const workflowSnapshotEntity = new Entity({
|
|
5
|
-
model: {
|
|
6
|
-
entity: 'workflow_snapshot',
|
|
7
|
-
version: '1',
|
|
8
|
-
service: 'mastra',
|
|
9
|
-
},
|
|
10
|
-
attributes: {
|
|
11
|
-
entity: {
|
|
12
|
-
type: 'string',
|
|
13
|
-
required: true,
|
|
14
|
-
},
|
|
15
|
-
...baseAttributes,
|
|
16
|
-
workflow_name: {
|
|
17
|
-
type: 'string',
|
|
18
|
-
required: true,
|
|
19
|
-
},
|
|
20
|
-
run_id: {
|
|
21
|
-
type: 'string',
|
|
22
|
-
required: true,
|
|
23
|
-
},
|
|
24
|
-
snapshot: {
|
|
25
|
-
type: 'string', // JSON stringified
|
|
26
|
-
required: true,
|
|
27
|
-
// Stringify snapshot object on set
|
|
28
|
-
set: (value?: any) => {
|
|
29
|
-
if (value && typeof value !== 'string') {
|
|
30
|
-
return JSON.stringify(value);
|
|
31
|
-
}
|
|
32
|
-
return value;
|
|
33
|
-
},
|
|
34
|
-
// Parse JSON string to object on get
|
|
35
|
-
get: (value?: string) => {
|
|
36
|
-
return value ? JSON.parse(value) : value;
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
resourceId: {
|
|
40
|
-
type: 'string',
|
|
41
|
-
required: false,
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
indexes: {
|
|
45
|
-
primary: {
|
|
46
|
-
pk: { field: 'pk', composite: ['entity', 'workflow_name'] },
|
|
47
|
-
sk: { field: 'sk', composite: ['run_id'] },
|
|
48
|
-
},
|
|
49
|
-
// GSI to allow querying by run_id efficiently without knowing the workflow_name
|
|
50
|
-
gsi2: {
|
|
51
|
-
index: 'gsi2',
|
|
52
|
-
pk: { field: 'gsi2pk', composite: ['entity', 'run_id'] },
|
|
53
|
-
sk: { field: 'gsi2sk', composite: ['workflow_name'] },
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
});
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './storage';
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
version: '3.8'
|
|
2
|
-
|
|
3
|
-
services:
|
|
4
|
-
dynamodb-local:
|
|
5
|
-
image: amazon/dynamodb-local:latest
|
|
6
|
-
# Use host network mode for simpler connection from tests,
|
|
7
|
-
# or define ports if running in bridge mode.
|
|
8
|
-
# network_mode: host
|
|
9
|
-
ports:
|
|
10
|
-
- '8000:8000' # Map container port 8000 to host port 8000
|
|
11
|
-
command: ['-jar', 'DynamoDBLocal.jar', '-sharedDb']
|
|
12
|
-
volumes:
|
|
13
|
-
- dynamodb_data:/home/dynamodblocal/data
|
|
14
|
-
|
|
15
|
-
volumes:
|
|
16
|
-
dynamodb_data: {}
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
2
|
-
import type { EvalRow, PaginationArgs, PaginationInfo } from '@mastra/core/storage';
|
|
3
|
-
import { LegacyEvalsStorage } from '@mastra/core/storage';
|
|
4
|
-
import type { Service } from 'electrodb';
|
|
5
|
-
|
|
6
|
-
export class LegacyEvalsDynamoDB extends LegacyEvalsStorage {
|
|
7
|
-
service: Service<Record<string, any>>;
|
|
8
|
-
tableName: string;
|
|
9
|
-
|
|
10
|
-
constructor({ service, tableName }: { service: Service<Record<string, any>>; tableName: string }) {
|
|
11
|
-
super();
|
|
12
|
-
this.service = service;
|
|
13
|
-
this.tableName = tableName;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Eval operations
|
|
17
|
-
async getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]> {
|
|
18
|
-
this.logger.debug('Getting evals for agent', { agentName, type });
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
// Query evals by agent name using the GSI
|
|
22
|
-
// Provide *all* composite key components for the 'byAgent' index ('entity', 'agent_name')
|
|
23
|
-
const query = this.service.entities.eval.query.byAgent({ entity: 'eval', agent_name: agentName });
|
|
24
|
-
|
|
25
|
-
// Fetch potentially all items in descending order, using the correct 'order' option
|
|
26
|
-
const results = await query.go({ order: 'desc', limit: 100 }); // Use order: 'desc'
|
|
27
|
-
|
|
28
|
-
if (!results.data.length) {
|
|
29
|
-
return [];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Filter by type if specified
|
|
33
|
-
let filteredData = results.data;
|
|
34
|
-
if (type) {
|
|
35
|
-
filteredData = filteredData.filter((evalRecord: Record<string, any>) => {
|
|
36
|
-
try {
|
|
37
|
-
// Need to handle potential parse errors for test_info
|
|
38
|
-
const testInfo =
|
|
39
|
-
evalRecord.test_info && typeof evalRecord.test_info === 'string'
|
|
40
|
-
? JSON.parse(evalRecord.test_info)
|
|
41
|
-
: undefined;
|
|
42
|
-
|
|
43
|
-
if (type === 'test' && !testInfo) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
if (type === 'live' && testInfo) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
} catch (e) {
|
|
50
|
-
this.logger.warn('Failed to parse test_info during filtering', { record: evalRecord, error: e });
|
|
51
|
-
// Decide how to handle parse errors - exclude or include? Including for now.
|
|
52
|
-
}
|
|
53
|
-
return true;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Format the results - ElectroDB transforms most attributes, but we need to map/parse
|
|
58
|
-
return filteredData.map((evalRecord: Record<string, any>) => {
|
|
59
|
-
try {
|
|
60
|
-
return {
|
|
61
|
-
input: evalRecord.input,
|
|
62
|
-
output: evalRecord.output,
|
|
63
|
-
// Safely parse result and test_info
|
|
64
|
-
result:
|
|
65
|
-
evalRecord.result && typeof evalRecord.result === 'string' ? JSON.parse(evalRecord.result) : undefined,
|
|
66
|
-
agentName: evalRecord.agent_name,
|
|
67
|
-
createdAt: evalRecord.created_at, // Keep as string from DDB?
|
|
68
|
-
metricName: evalRecord.metric_name,
|
|
69
|
-
instructions: evalRecord.instructions,
|
|
70
|
-
runId: evalRecord.run_id,
|
|
71
|
-
globalRunId: evalRecord.global_run_id,
|
|
72
|
-
testInfo:
|
|
73
|
-
evalRecord.test_info && typeof evalRecord.test_info === 'string'
|
|
74
|
-
? JSON.parse(evalRecord.test_info)
|
|
75
|
-
: undefined,
|
|
76
|
-
} as EvalRow;
|
|
77
|
-
} catch (parseError) {
|
|
78
|
-
this.logger.error('Failed to parse eval record', { record: evalRecord, error: parseError });
|
|
79
|
-
// Return a partial record or null/undefined on error?
|
|
80
|
-
// Returning partial for now, might need adjustment based on requirements.
|
|
81
|
-
return {
|
|
82
|
-
agentName: evalRecord.agent_name,
|
|
83
|
-
createdAt: evalRecord.created_at,
|
|
84
|
-
runId: evalRecord.run_id,
|
|
85
|
-
globalRunId: evalRecord.global_run_id,
|
|
86
|
-
} as Partial<EvalRow> as EvalRow; // Cast needed for return type
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
} catch (error) {
|
|
90
|
-
throw new MastraError(
|
|
91
|
-
{
|
|
92
|
-
id: 'STORAGE_DYNAMODB_STORE_GET_EVALS_BY_AGENT_NAME_FAILED',
|
|
93
|
-
domain: ErrorDomain.STORAGE,
|
|
94
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
95
|
-
details: { agentName },
|
|
96
|
-
},
|
|
97
|
-
error,
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async getEvals(
|
|
103
|
-
options: {
|
|
104
|
-
agentName?: string;
|
|
105
|
-
type?: 'test' | 'live';
|
|
106
|
-
} & PaginationArgs = {},
|
|
107
|
-
): Promise<PaginationInfo & { evals: EvalRow[] }> {
|
|
108
|
-
const { agentName, type, page = 0, perPage = 100, dateRange } = options;
|
|
109
|
-
|
|
110
|
-
this.logger.debug('Getting evals with pagination', { agentName, type, page, perPage, dateRange });
|
|
111
|
-
|
|
112
|
-
try {
|
|
113
|
-
let query;
|
|
114
|
-
|
|
115
|
-
if (agentName) {
|
|
116
|
-
// Query by specific agent name
|
|
117
|
-
query = this.service.entities.eval.query.byAgent({ entity: 'eval', agent_name: agentName });
|
|
118
|
-
} else {
|
|
119
|
-
// Query all evals using the primary index
|
|
120
|
-
query = this.service.entities.eval.query.byEntity({ entity: 'eval' });
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// For DynamoDB, we need to fetch all data and apply pagination in memory
|
|
124
|
-
// since DynamoDB doesn't support traditional offset-based pagination
|
|
125
|
-
const results = await query.go({
|
|
126
|
-
order: 'desc',
|
|
127
|
-
pages: 'all', // Get all pages to apply filtering and pagination
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
if (!results.data.length) {
|
|
131
|
-
return {
|
|
132
|
-
evals: [],
|
|
133
|
-
total: 0,
|
|
134
|
-
page,
|
|
135
|
-
perPage,
|
|
136
|
-
hasMore: false,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// Filter by type if specified
|
|
141
|
-
let filteredData = results.data;
|
|
142
|
-
if (type) {
|
|
143
|
-
filteredData = filteredData.filter((evalRecord: Record<string, any>) => {
|
|
144
|
-
try {
|
|
145
|
-
const testInfo =
|
|
146
|
-
evalRecord.test_info && typeof evalRecord.test_info === 'string'
|
|
147
|
-
? JSON.parse(evalRecord.test_info)
|
|
148
|
-
: undefined;
|
|
149
|
-
|
|
150
|
-
if (type === 'test' && !testInfo) {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
if (type === 'live' && testInfo) {
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
} catch (e) {
|
|
157
|
-
this.logger.warn('Failed to parse test_info during filtering', { record: evalRecord, error: e });
|
|
158
|
-
}
|
|
159
|
-
return true;
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Apply date range filtering if specified
|
|
164
|
-
if (dateRange) {
|
|
165
|
-
const fromDate = dateRange.start;
|
|
166
|
-
const toDate = dateRange.end;
|
|
167
|
-
|
|
168
|
-
filteredData = filteredData.filter((evalRecord: Record<string, any>) => {
|
|
169
|
-
const recordDate = new Date(evalRecord.created_at);
|
|
170
|
-
|
|
171
|
-
if (fromDate && recordDate < fromDate) {
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
if (toDate && recordDate > toDate) {
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
return true;
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Apply pagination
|
|
182
|
-
const total = filteredData.length;
|
|
183
|
-
const start = page * perPage;
|
|
184
|
-
const end = start + perPage;
|
|
185
|
-
const paginatedData = filteredData.slice(start, end);
|
|
186
|
-
|
|
187
|
-
// Transform to EvalRow format
|
|
188
|
-
const evals = paginatedData.map((evalRecord: Record<string, any>) => {
|
|
189
|
-
try {
|
|
190
|
-
return {
|
|
191
|
-
input: evalRecord.input,
|
|
192
|
-
output: evalRecord.output,
|
|
193
|
-
result:
|
|
194
|
-
evalRecord.result && typeof evalRecord.result === 'string' ? JSON.parse(evalRecord.result) : undefined,
|
|
195
|
-
agentName: evalRecord.agent_name,
|
|
196
|
-
createdAt: evalRecord.created_at,
|
|
197
|
-
metricName: evalRecord.metric_name,
|
|
198
|
-
instructions: evalRecord.instructions,
|
|
199
|
-
runId: evalRecord.run_id,
|
|
200
|
-
globalRunId: evalRecord.global_run_id,
|
|
201
|
-
testInfo:
|
|
202
|
-
evalRecord.test_info && typeof evalRecord.test_info === 'string'
|
|
203
|
-
? JSON.parse(evalRecord.test_info)
|
|
204
|
-
: undefined,
|
|
205
|
-
} as EvalRow;
|
|
206
|
-
} catch (parseError) {
|
|
207
|
-
this.logger.error('Failed to parse eval record', { record: evalRecord, error: parseError });
|
|
208
|
-
return {
|
|
209
|
-
agentName: evalRecord.agent_name,
|
|
210
|
-
createdAt: evalRecord.created_at,
|
|
211
|
-
runId: evalRecord.run_id,
|
|
212
|
-
globalRunId: evalRecord.global_run_id,
|
|
213
|
-
} as Partial<EvalRow> as EvalRow;
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
const hasMore = end < total;
|
|
218
|
-
|
|
219
|
-
return {
|
|
220
|
-
evals,
|
|
221
|
-
total,
|
|
222
|
-
page,
|
|
223
|
-
perPage,
|
|
224
|
-
hasMore,
|
|
225
|
-
};
|
|
226
|
-
} catch (error) {
|
|
227
|
-
throw new MastraError(
|
|
228
|
-
{
|
|
229
|
-
id: 'STORAGE_DYNAMODB_STORE_GET_EVALS_FAILED',
|
|
230
|
-
domain: ErrorDomain.STORAGE,
|
|
231
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
232
|
-
details: {
|
|
233
|
-
agentName: agentName || 'all',
|
|
234
|
-
type: type || 'all',
|
|
235
|
-
page,
|
|
236
|
-
perPage,
|
|
237
|
-
},
|
|
238
|
-
},
|
|
239
|
-
error,
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|