@mastra/clickhouse 0.14.2 → 0.14.3-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 +9 -0
- package/package.json +17 -4
- package/.turbo/turbo-build.log +0 -4
- package/docker-compose.yaml +0 -15
- package/eslint.config.js +0 -6
- package/src/index.ts +0 -2
- package/src/storage/domains/legacy-evals/index.ts +0 -246
- package/src/storage/domains/memory/index.ts +0 -1473
- package/src/storage/domains/operations/index.ts +0 -319
- package/src/storage/domains/scores/index.ts +0 -351
- package/src/storage/domains/traces/index.ts +0 -275
- package/src/storage/domains/utils.ts +0 -90
- package/src/storage/domains/workflows/index.ts +0 -323
- package/src/storage/index.test.ts +0 -26
- package/src/storage/index.ts +0 -456
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -5
- package/tsup.config.ts +0 -17
- package/vitest.config.ts +0 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @mastra/clickhouse
|
|
2
2
|
|
|
3
|
+
## 0.14.3-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#7343](https://github.com/mastra-ai/mastra/pull/7343) [`de3cbc6`](https://github.com/mastra-ai/mastra/commit/de3cbc61079211431bd30487982ea3653517278e) Thanks [@LekoArts](https://github.com/LekoArts)! - Update the `package.json` file to include additional fields like `repository`, `homepage` or `files`.
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`85ef90b`](https://github.com/mastra-ai/mastra/commit/85ef90bb2cd4ae4df855c7ac175f7d392c55c1bf), [`de3cbc6`](https://github.com/mastra-ai/mastra/commit/de3cbc61079211431bd30487982ea3653517278e)]:
|
|
10
|
+
- @mastra/core@0.15.3-alpha.5
|
|
11
|
+
|
|
3
12
|
## 0.14.2
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/clickhouse",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.3-alpha.0",
|
|
4
4
|
"description": "Clickhouse provider for Mastra - includes db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"./package.json": "./package.json"
|
|
20
20
|
},
|
|
21
|
-
"license": "
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@clickhouse/client": "^1.12.1"
|
|
24
24
|
},
|
|
@@ -29,14 +29,27 @@
|
|
|
29
29
|
"tsup": "^8.5.0",
|
|
30
30
|
"typescript": "^5.8.3",
|
|
31
31
|
"vitest": "^3.2.4",
|
|
32
|
-
"@internal/storage-test-utils": "0.0.30",
|
|
33
32
|
"@internal/lint": "0.0.34",
|
|
34
|
-
"@mastra/core": "0.15.
|
|
33
|
+
"@mastra/core": "0.15.3-alpha.5",
|
|
34
|
+
"@internal/storage-test-utils": "0.0.30",
|
|
35
35
|
"@internal/types-builder": "0.0.9"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@mastra/core": ">=0.14.2-0 <0.16.0-0"
|
|
39
39
|
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"CHANGELOG.md"
|
|
43
|
+
],
|
|
44
|
+
"homepage": "https://mastra.ai",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/mastra-ai/mastra.git",
|
|
48
|
+
"directory": "stores/clickhouse"
|
|
49
|
+
},
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/mastra-ai/mastra/issues"
|
|
52
|
+
},
|
|
40
53
|
"scripts": {
|
|
41
54
|
"build": "tsup --silent --config tsup.config.ts",
|
|
42
55
|
"build:watch": "tsup --watch --silent --config tsup.config.ts",
|
package/.turbo/turbo-build.log
DELETED
package/docker-compose.yaml
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
services:
|
|
2
|
-
db:
|
|
3
|
-
image: clickhouse/clickhouse-server:latest
|
|
4
|
-
container_name: 'clickhouse-test-db'
|
|
5
|
-
ports:
|
|
6
|
-
- '8123:8123'
|
|
7
|
-
- '9000:9000'
|
|
8
|
-
environment:
|
|
9
|
-
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1
|
|
10
|
-
CLICKHOUSE_USER: ${CLICKHOUSE_USER:-default}
|
|
11
|
-
CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD:-password}
|
|
12
|
-
volumes:
|
|
13
|
-
- clickhouse_data:/var/lib/clickhouse
|
|
14
|
-
volumes:
|
|
15
|
-
clickhouse_data:
|
package/eslint.config.js
DELETED
package/src/index.ts
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import type { ClickHouseClient } from '@clickhouse/client';
|
|
2
|
-
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
3
|
-
import type { MetricResult, TestInfo } from '@mastra/core/eval';
|
|
4
|
-
import { LegacyEvalsStorage, TABLE_EVALS } from '@mastra/core/storage';
|
|
5
|
-
import type { EvalRow, PaginationArgs, PaginationInfo } from '@mastra/core/storage';
|
|
6
|
-
import type { StoreOperationsClickhouse } from '../operations';
|
|
7
|
-
import { transformRow } from '../utils';
|
|
8
|
-
|
|
9
|
-
export class LegacyEvalsStorageClickhouse extends LegacyEvalsStorage {
|
|
10
|
-
protected client: ClickHouseClient;
|
|
11
|
-
protected operations: StoreOperationsClickhouse;
|
|
12
|
-
constructor({ client, operations }: { client: ClickHouseClient; operations: StoreOperationsClickhouse }) {
|
|
13
|
-
super();
|
|
14
|
-
this.client = client;
|
|
15
|
-
this.operations = operations;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
private transformEvalRow(row: Record<string, any>): EvalRow {
|
|
19
|
-
row = transformRow(row);
|
|
20
|
-
|
|
21
|
-
// Handle result field with proper null checks
|
|
22
|
-
let resultValue: any;
|
|
23
|
-
try {
|
|
24
|
-
if (row.result && typeof row.result === 'string' && row.result.trim() !== '') {
|
|
25
|
-
resultValue = JSON.parse(row.result);
|
|
26
|
-
} else if (typeof row.result === 'object' && row.result !== null) {
|
|
27
|
-
resultValue = row.result;
|
|
28
|
-
} else if (row.result === null || row.result === undefined || row.result === '') {
|
|
29
|
-
// Create a default result if none exists
|
|
30
|
-
resultValue = { score: 0 };
|
|
31
|
-
} else {
|
|
32
|
-
throw new Error(`Invalid or empty result field: ${JSON.stringify(row.result)}`);
|
|
33
|
-
}
|
|
34
|
-
} catch (error) {
|
|
35
|
-
console.error('Error parsing result field:', row.result, error);
|
|
36
|
-
throw new MastraError({
|
|
37
|
-
id: 'CLICKHOUSE_STORAGE_INVALID_RESULT_FORMAT',
|
|
38
|
-
text: `Invalid result format: ${JSON.stringify(row.result)}`,
|
|
39
|
-
domain: ErrorDomain.STORAGE,
|
|
40
|
-
category: ErrorCategory.USER,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Handle test_info field with proper null checks
|
|
45
|
-
let testInfoValue: TestInfo | undefined;
|
|
46
|
-
try {
|
|
47
|
-
if (
|
|
48
|
-
row.test_info &&
|
|
49
|
-
typeof row.test_info === 'string' &&
|
|
50
|
-
row.test_info.trim() !== '' &&
|
|
51
|
-
row.test_info !== 'null'
|
|
52
|
-
) {
|
|
53
|
-
testInfoValue = JSON.parse(row.test_info);
|
|
54
|
-
} else if (typeof row.test_info === 'object' && row.test_info !== null) {
|
|
55
|
-
testInfoValue = row.test_info;
|
|
56
|
-
}
|
|
57
|
-
} catch {
|
|
58
|
-
// If test_info parsing fails, we'll leave it as undefined
|
|
59
|
-
testInfoValue = undefined;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (!resultValue || typeof resultValue !== 'object' || !('score' in resultValue)) {
|
|
63
|
-
throw new MastraError({
|
|
64
|
-
id: 'CLICKHOUSE_STORAGE_INVALID_METRIC_FORMAT',
|
|
65
|
-
text: `Invalid MetricResult format: ${JSON.stringify(resultValue)}`,
|
|
66
|
-
domain: ErrorDomain.STORAGE,
|
|
67
|
-
category: ErrorCategory.USER,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
input: row.input as string,
|
|
73
|
-
output: row.output as string,
|
|
74
|
-
result: resultValue as MetricResult,
|
|
75
|
-
agentName: row.agent_name as string,
|
|
76
|
-
metricName: row.metric_name as string,
|
|
77
|
-
instructions: row.instructions as string,
|
|
78
|
-
testInfo: testInfoValue as TestInfo,
|
|
79
|
-
globalRunId: row.global_run_id as string,
|
|
80
|
-
runId: row.run_id as string,
|
|
81
|
-
createdAt: row.created_at as string,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]> {
|
|
86
|
-
try {
|
|
87
|
-
const baseQuery = `SELECT *, toDateTime64(created_at, 3) as createdAt FROM ${TABLE_EVALS} WHERE agent_name = {var_agent_name:String}`;
|
|
88
|
-
const typeCondition =
|
|
89
|
-
type === 'test'
|
|
90
|
-
? " AND test_info IS NOT NULL AND test_info != 'null' AND JSONExtractString(test_info, 'testPath') IS NOT NULL AND JSONExtractString(test_info, 'testPath') != ''"
|
|
91
|
-
: type === 'live'
|
|
92
|
-
? " AND (test_info IS NULL OR test_info = 'null' OR JSONExtractString(test_info, 'testPath') IS NULL OR JSONExtractString(test_info, 'testPath') = '')"
|
|
93
|
-
: '';
|
|
94
|
-
|
|
95
|
-
const result = await this.client.query({
|
|
96
|
-
query: `${baseQuery}${typeCondition} ORDER BY createdAt DESC`,
|
|
97
|
-
query_params: { var_agent_name: agentName },
|
|
98
|
-
clickhouse_settings: {
|
|
99
|
-
date_time_input_format: 'best_effort',
|
|
100
|
-
date_time_output_format: 'iso',
|
|
101
|
-
use_client_time_zone: 1,
|
|
102
|
-
output_format_json_quote_64bit_integers: 0,
|
|
103
|
-
},
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
if (!result) {
|
|
107
|
-
return [];
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const rows = await result.json();
|
|
111
|
-
return rows.data.map((row: any) => this.transformEvalRow(row));
|
|
112
|
-
} catch (error: any) {
|
|
113
|
-
if (error?.message?.includes('no such table') || error?.message?.includes('does not exist')) {
|
|
114
|
-
return [];
|
|
115
|
-
}
|
|
116
|
-
throw new MastraError(
|
|
117
|
-
{
|
|
118
|
-
id: 'CLICKHOUSE_STORAGE_GET_EVALS_BY_AGENT_FAILED',
|
|
119
|
-
domain: ErrorDomain.STORAGE,
|
|
120
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
121
|
-
details: { agentName, type: type ?? null },
|
|
122
|
-
},
|
|
123
|
-
error,
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
async getEvals(
|
|
129
|
-
options: {
|
|
130
|
-
agentName?: string;
|
|
131
|
-
type?: 'test' | 'live';
|
|
132
|
-
} & PaginationArgs = {},
|
|
133
|
-
): Promise<PaginationInfo & { evals: EvalRow[] }> {
|
|
134
|
-
const { agentName, type, page = 0, perPage = 100, dateRange } = options;
|
|
135
|
-
const fromDate = dateRange?.start;
|
|
136
|
-
const toDate = dateRange?.end;
|
|
137
|
-
|
|
138
|
-
const conditions: string[] = [];
|
|
139
|
-
const queryParams: Record<string, any> = {};
|
|
140
|
-
|
|
141
|
-
if (agentName) {
|
|
142
|
-
conditions.push(`agent_name = {var_agent_name:String}`);
|
|
143
|
-
queryParams.var_agent_name = agentName;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (type === 'test') {
|
|
147
|
-
conditions.push(
|
|
148
|
-
`(test_info IS NOT NULL AND test_info != 'null' AND JSONExtractString(test_info, 'testPath') IS NOT NULL AND JSONExtractString(test_info, 'testPath') != '')`,
|
|
149
|
-
);
|
|
150
|
-
} else if (type === 'live') {
|
|
151
|
-
conditions.push(
|
|
152
|
-
`(test_info IS NULL OR test_info = 'null' OR JSONExtractString(test_info, 'testPath') IS NULL OR JSONExtractString(test_info, 'testPath') = '')`,
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (fromDate) {
|
|
157
|
-
conditions.push(`created_at >= parseDateTime64BestEffort({var_from_date:String})`);
|
|
158
|
-
queryParams.var_from_date = fromDate.toISOString();
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (toDate) {
|
|
162
|
-
conditions.push(`created_at <= parseDateTime64BestEffort({var_to_date:String})`);
|
|
163
|
-
queryParams.var_to_date = toDate.toISOString();
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
167
|
-
|
|
168
|
-
try {
|
|
169
|
-
const countResult = await this.client.query({
|
|
170
|
-
query: `SELECT COUNT(*) as count FROM ${TABLE_EVALS} ${whereClause}`,
|
|
171
|
-
query_params: {
|
|
172
|
-
...(agentName ? { var_agent_name: agentName } : {}),
|
|
173
|
-
...(fromDate ? { var_from_date: fromDate.toISOString() } : {}),
|
|
174
|
-
...(toDate ? { var_to_date: toDate.toISOString() } : {}),
|
|
175
|
-
},
|
|
176
|
-
clickhouse_settings: {
|
|
177
|
-
date_time_input_format: 'best_effort',
|
|
178
|
-
date_time_output_format: 'iso',
|
|
179
|
-
use_client_time_zone: 1,
|
|
180
|
-
output_format_json_quote_64bit_integers: 0,
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
const countData = await countResult.json();
|
|
185
|
-
const total = Number((countData.data?.[0] as any)?.count ?? 0);
|
|
186
|
-
|
|
187
|
-
const currentOffset = page * perPage;
|
|
188
|
-
const hasMore = currentOffset + perPage < total;
|
|
189
|
-
|
|
190
|
-
if (total === 0) {
|
|
191
|
-
return {
|
|
192
|
-
evals: [],
|
|
193
|
-
total: 0,
|
|
194
|
-
page,
|
|
195
|
-
perPage,
|
|
196
|
-
hasMore: false,
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const dataResult = await this.client.query({
|
|
201
|
-
query: `SELECT *, toDateTime64(createdAt, 3) as createdAt FROM ${TABLE_EVALS} ${whereClause} ORDER BY created_at DESC LIMIT {var_limit:UInt32} OFFSET {var_offset:UInt32}`,
|
|
202
|
-
query_params: {
|
|
203
|
-
...(agentName ? { var_agent_name: agentName } : {}),
|
|
204
|
-
...(fromDate ? { var_from_date: fromDate.toISOString() } : {}),
|
|
205
|
-
...(toDate ? { var_to_date: toDate.toISOString() } : {}),
|
|
206
|
-
var_limit: perPage || 100,
|
|
207
|
-
var_offset: currentOffset || 0,
|
|
208
|
-
},
|
|
209
|
-
clickhouse_settings: {
|
|
210
|
-
date_time_input_format: 'best_effort',
|
|
211
|
-
date_time_output_format: 'iso',
|
|
212
|
-
use_client_time_zone: 1,
|
|
213
|
-
output_format_json_quote_64bit_integers: 0,
|
|
214
|
-
},
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
const rows = await dataResult.json();
|
|
218
|
-
return {
|
|
219
|
-
evals: rows.data.map((row: any) => this.transformEvalRow(row)),
|
|
220
|
-
total,
|
|
221
|
-
page,
|
|
222
|
-
perPage,
|
|
223
|
-
hasMore,
|
|
224
|
-
};
|
|
225
|
-
} catch (error: any) {
|
|
226
|
-
if (error?.message?.includes('no such table') || error?.message?.includes('does not exist')) {
|
|
227
|
-
return {
|
|
228
|
-
evals: [],
|
|
229
|
-
total: 0,
|
|
230
|
-
page,
|
|
231
|
-
perPage,
|
|
232
|
-
hasMore: false,
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
throw new MastraError(
|
|
236
|
-
{
|
|
237
|
-
id: 'CLICKHOUSE_STORAGE_GET_EVALS_FAILED',
|
|
238
|
-
domain: ErrorDomain.STORAGE,
|
|
239
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
240
|
-
details: { agentName: agentName ?? 'all', type: type ?? 'all' },
|
|
241
|
-
},
|
|
242
|
-
error,
|
|
243
|
-
);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|