@mastra/clickhouse 0.11.1-alpha.0 → 0.11.1-alpha.2
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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +26 -0
- package/dist/_tsup-dts-rollup.d.cts +8 -4
- package/dist/_tsup-dts-rollup.d.ts +8 -4
- package/dist/index.cjs +348 -100
- package/dist/index.js +330 -82
- package/package.json +3 -3
- package/src/storage/index.test.ts +78 -0
- package/src/storage/index.ts +362 -99
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createClient } from '@clickhouse/client';
|
|
2
2
|
import { MessageList } from '@mastra/core/agent';
|
|
3
|
+
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
3
4
|
import { TABLE_EVALS, TABLE_THREADS, TABLE_TRACES, TABLE_WORKFLOW_SNAPSHOT, TABLE_MESSAGES, MastraStorage, TABLE_SCHEMAS } from '@mastra/core/storage';
|
|
4
5
|
|
|
5
6
|
// src/storage/index.ts
|
|
@@ -64,7 +65,12 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
64
65
|
const resultValue = JSON.parse(row.result);
|
|
65
66
|
const testInfoValue = row.test_info ? JSON.parse(row.test_info) : void 0;
|
|
66
67
|
if (!resultValue || typeof resultValue !== "object" || !("score" in resultValue)) {
|
|
67
|
-
throw new
|
|
68
|
+
throw new MastraError({
|
|
69
|
+
id: "CLICKHOUSE_STORAGE_INVALID_METRIC_FORMAT",
|
|
70
|
+
text: `Invalid MetricResult format: ${JSON.stringify(resultValue)}`,
|
|
71
|
+
domain: ErrorDomain.STORAGE,
|
|
72
|
+
category: ErrorCategory.USER
|
|
73
|
+
});
|
|
68
74
|
}
|
|
69
75
|
return {
|
|
70
76
|
input: row.input,
|
|
@@ -79,6 +85,18 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
79
85
|
createdAt: row.created_at
|
|
80
86
|
};
|
|
81
87
|
}
|
|
88
|
+
escape(value) {
|
|
89
|
+
if (typeof value === "string") {
|
|
90
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
91
|
+
}
|
|
92
|
+
if (value instanceof Date) {
|
|
93
|
+
return `'${value.toISOString()}'`;
|
|
94
|
+
}
|
|
95
|
+
if (value === null || value === void 0) {
|
|
96
|
+
return "NULL";
|
|
97
|
+
}
|
|
98
|
+
return value.toString();
|
|
99
|
+
}
|
|
82
100
|
async getEvalsByAgentName(agentName, type) {
|
|
83
101
|
try {
|
|
84
102
|
const baseQuery = `SELECT *, toDateTime64(createdAt, 3) as createdAt FROM ${TABLE_EVALS} WHERE agent_name = {var_agent_name:String}`;
|
|
@@ -99,11 +117,18 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
99
117
|
const rows = await result.json();
|
|
100
118
|
return rows.data.map((row) => this.transformEvalRow(row));
|
|
101
119
|
} catch (error) {
|
|
102
|
-
if (error
|
|
120
|
+
if (error?.message?.includes("no such table") || error?.message?.includes("does not exist")) {
|
|
103
121
|
return [];
|
|
104
122
|
}
|
|
105
|
-
|
|
106
|
-
|
|
123
|
+
throw new MastraError(
|
|
124
|
+
{
|
|
125
|
+
id: "CLICKHOUSE_STORAGE_GET_EVALS_BY_AGENT_FAILED",
|
|
126
|
+
domain: ErrorDomain.STORAGE,
|
|
127
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
128
|
+
details: { agentName, type: type ?? null }
|
|
129
|
+
},
|
|
130
|
+
error
|
|
131
|
+
);
|
|
107
132
|
}
|
|
108
133
|
}
|
|
109
134
|
async batchInsert({ tableName, records }) {
|
|
@@ -127,8 +152,15 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
127
152
|
}
|
|
128
153
|
});
|
|
129
154
|
} catch (error) {
|
|
130
|
-
|
|
131
|
-
|
|
155
|
+
throw new MastraError(
|
|
156
|
+
{
|
|
157
|
+
id: "CLICKHOUSE_STORAGE_BATCH_INSERT_FAILED",
|
|
158
|
+
domain: ErrorDomain.STORAGE,
|
|
159
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
160
|
+
details: { tableName }
|
|
161
|
+
},
|
|
162
|
+
error
|
|
163
|
+
);
|
|
132
164
|
}
|
|
133
165
|
}
|
|
134
166
|
async getTraces({
|
|
@@ -176,48 +208,96 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
176
208
|
args.var_to_date = toDate.getTime() / 1e3;
|
|
177
209
|
}
|
|
178
210
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
211
|
+
try {
|
|
212
|
+
const result = await this.db.query({
|
|
213
|
+
query: `SELECT *, toDateTime64(createdAt, 3) as createdAt FROM ${TABLE_TRACES} ${whereClause} ORDER BY "createdAt" DESC LIMIT ${limit} OFFSET ${offset}`,
|
|
214
|
+
query_params: args,
|
|
215
|
+
clickhouse_settings: {
|
|
216
|
+
// Allows to insert serialized JS Dates (such as '2023-12-06T10:54:48.000Z')
|
|
217
|
+
date_time_input_format: "best_effort",
|
|
218
|
+
date_time_output_format: "iso",
|
|
219
|
+
use_client_time_zone: 1,
|
|
220
|
+
output_format_json_quote_64bit_integers: 0
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
if (!result) {
|
|
224
|
+
return [];
|
|
188
225
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
226
|
+
const resp = await result.json();
|
|
227
|
+
const rows = resp.data;
|
|
228
|
+
return rows.map((row) => ({
|
|
229
|
+
id: row.id,
|
|
230
|
+
parentSpanId: row.parentSpanId,
|
|
231
|
+
traceId: row.traceId,
|
|
232
|
+
name: row.name,
|
|
233
|
+
scope: row.scope,
|
|
234
|
+
kind: row.kind,
|
|
235
|
+
status: safelyParseJSON(row.status),
|
|
236
|
+
events: safelyParseJSON(row.events),
|
|
237
|
+
links: safelyParseJSON(row.links),
|
|
238
|
+
attributes: safelyParseJSON(row.attributes),
|
|
239
|
+
startTime: row.startTime,
|
|
240
|
+
endTime: row.endTime,
|
|
241
|
+
other: safelyParseJSON(row.other),
|
|
242
|
+
createdAt: row.createdAt
|
|
243
|
+
}));
|
|
244
|
+
} catch (error) {
|
|
245
|
+
if (error?.message?.includes("no such table") || error?.message?.includes("does not exist")) {
|
|
246
|
+
return [];
|
|
247
|
+
}
|
|
248
|
+
throw new MastraError(
|
|
249
|
+
{
|
|
250
|
+
id: "CLICKHOUSE_STORAGE_GET_TRACES_FAILED",
|
|
251
|
+
domain: ErrorDomain.STORAGE,
|
|
252
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
253
|
+
details: {
|
|
254
|
+
name: name ?? null,
|
|
255
|
+
scope: scope ?? null,
|
|
256
|
+
page,
|
|
257
|
+
perPage,
|
|
258
|
+
attributes: attributes ? JSON.stringify(attributes) : null,
|
|
259
|
+
filters: filters ? JSON.stringify(filters) : null,
|
|
260
|
+
fromDate: fromDate?.toISOString() ?? null,
|
|
261
|
+
toDate: toDate?.toISOString() ?? null
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
error
|
|
265
|
+
);
|
|
266
|
+
}
|
|
211
267
|
}
|
|
212
268
|
async optimizeTable({ tableName }) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
269
|
+
try {
|
|
270
|
+
await this.db.command({
|
|
271
|
+
query: `OPTIMIZE TABLE ${tableName} FINAL`
|
|
272
|
+
});
|
|
273
|
+
} catch (error) {
|
|
274
|
+
throw new MastraError(
|
|
275
|
+
{
|
|
276
|
+
id: "CLICKHOUSE_STORAGE_OPTIMIZE_TABLE_FAILED",
|
|
277
|
+
domain: ErrorDomain.STORAGE,
|
|
278
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
279
|
+
details: { tableName }
|
|
280
|
+
},
|
|
281
|
+
error
|
|
282
|
+
);
|
|
283
|
+
}
|
|
216
284
|
}
|
|
217
285
|
async materializeTtl({ tableName }) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
286
|
+
try {
|
|
287
|
+
await this.db.command({
|
|
288
|
+
query: `ALTER TABLE ${tableName} MATERIALIZE TTL;`
|
|
289
|
+
});
|
|
290
|
+
} catch (error) {
|
|
291
|
+
throw new MastraError(
|
|
292
|
+
{
|
|
293
|
+
id: "CLICKHOUSE_STORAGE_MATERIALIZE_TTL_FAILED",
|
|
294
|
+
domain: ErrorDomain.STORAGE,
|
|
295
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
296
|
+
details: { tableName }
|
|
297
|
+
},
|
|
298
|
+
error
|
|
299
|
+
);
|
|
300
|
+
}
|
|
221
301
|
}
|
|
222
302
|
async createTable({
|
|
223
303
|
tableName,
|
|
@@ -261,8 +341,15 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
261
341
|
}
|
|
262
342
|
});
|
|
263
343
|
} catch (error) {
|
|
264
|
-
|
|
265
|
-
|
|
344
|
+
throw new MastraError(
|
|
345
|
+
{
|
|
346
|
+
id: "CLICKHOUSE_STORAGE_CREATE_TABLE_FAILED",
|
|
347
|
+
domain: ErrorDomain.STORAGE,
|
|
348
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
349
|
+
details: { tableName }
|
|
350
|
+
},
|
|
351
|
+
error
|
|
352
|
+
);
|
|
266
353
|
}
|
|
267
354
|
}
|
|
268
355
|
getSqlType(type) {
|
|
@@ -314,10 +401,15 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
314
401
|
}
|
|
315
402
|
}
|
|
316
403
|
} catch (error) {
|
|
317
|
-
|
|
318
|
-
|
|
404
|
+
throw new MastraError(
|
|
405
|
+
{
|
|
406
|
+
id: "CLICKHOUSE_STORAGE_ALTER_TABLE_FAILED",
|
|
407
|
+
domain: ErrorDomain.STORAGE,
|
|
408
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
409
|
+
details: { tableName }
|
|
410
|
+
},
|
|
411
|
+
error
|
|
319
412
|
);
|
|
320
|
-
throw new Error(`Failed to alter table ${tableName}: ${error}`);
|
|
321
413
|
}
|
|
322
414
|
}
|
|
323
415
|
async clearTable({ tableName }) {
|
|
@@ -333,8 +425,15 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
333
425
|
}
|
|
334
426
|
});
|
|
335
427
|
} catch (error) {
|
|
336
|
-
|
|
337
|
-
|
|
428
|
+
throw new MastraError(
|
|
429
|
+
{
|
|
430
|
+
id: "CLICKHOUSE_STORAGE_CLEAR_TABLE_FAILED",
|
|
431
|
+
domain: ErrorDomain.STORAGE,
|
|
432
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
433
|
+
details: { tableName }
|
|
434
|
+
},
|
|
435
|
+
error
|
|
436
|
+
);
|
|
338
437
|
}
|
|
339
438
|
}
|
|
340
439
|
async insert({ tableName, record }) {
|
|
@@ -357,11 +456,21 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
357
456
|
}
|
|
358
457
|
});
|
|
359
458
|
} catch (error) {
|
|
360
|
-
|
|
361
|
-
|
|
459
|
+
throw new MastraError(
|
|
460
|
+
{
|
|
461
|
+
id: "CLICKHOUSE_STORAGE_INSERT_FAILED",
|
|
462
|
+
domain: ErrorDomain.STORAGE,
|
|
463
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
464
|
+
details: { tableName }
|
|
465
|
+
},
|
|
466
|
+
error
|
|
467
|
+
);
|
|
362
468
|
}
|
|
363
469
|
}
|
|
364
|
-
async load({
|
|
470
|
+
async load({
|
|
471
|
+
tableName,
|
|
472
|
+
keys
|
|
473
|
+
}) {
|
|
365
474
|
try {
|
|
366
475
|
const keyEntries = Object.entries(keys);
|
|
367
476
|
const conditions = keyEntries.map(
|
|
@@ -398,8 +507,15 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
398
507
|
const data = transformRow(rows.data[0]);
|
|
399
508
|
return data;
|
|
400
509
|
} catch (error) {
|
|
401
|
-
|
|
402
|
-
|
|
510
|
+
throw new MastraError(
|
|
511
|
+
{
|
|
512
|
+
id: "CLICKHOUSE_STORAGE_LOAD_FAILED",
|
|
513
|
+
domain: ErrorDomain.STORAGE,
|
|
514
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
515
|
+
details: { tableName }
|
|
516
|
+
},
|
|
517
|
+
error
|
|
518
|
+
);
|
|
403
519
|
}
|
|
404
520
|
}
|
|
405
521
|
async getThreadById({ threadId }) {
|
|
@@ -436,8 +552,15 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
436
552
|
updatedAt: thread.updatedAt
|
|
437
553
|
};
|
|
438
554
|
} catch (error) {
|
|
439
|
-
|
|
440
|
-
|
|
555
|
+
throw new MastraError(
|
|
556
|
+
{
|
|
557
|
+
id: "CLICKHOUSE_STORAGE_GET_THREAD_BY_ID_FAILED",
|
|
558
|
+
domain: ErrorDomain.STORAGE,
|
|
559
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
560
|
+
details: { threadId }
|
|
561
|
+
},
|
|
562
|
+
error
|
|
563
|
+
);
|
|
441
564
|
}
|
|
442
565
|
}
|
|
443
566
|
async getThreadsByResourceId({ resourceId }) {
|
|
@@ -470,8 +593,15 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
470
593
|
updatedAt: thread.updatedAt
|
|
471
594
|
}));
|
|
472
595
|
} catch (error) {
|
|
473
|
-
|
|
474
|
-
|
|
596
|
+
throw new MastraError(
|
|
597
|
+
{
|
|
598
|
+
id: "CLICKHOUSE_STORAGE_GET_THREADS_BY_RESOURCE_ID_FAILED",
|
|
599
|
+
domain: ErrorDomain.STORAGE,
|
|
600
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
601
|
+
details: { resourceId }
|
|
602
|
+
},
|
|
603
|
+
error
|
|
604
|
+
);
|
|
475
605
|
}
|
|
476
606
|
}
|
|
477
607
|
async saveThread({ thread }) {
|
|
@@ -495,8 +625,15 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
495
625
|
});
|
|
496
626
|
return thread;
|
|
497
627
|
} catch (error) {
|
|
498
|
-
|
|
499
|
-
|
|
628
|
+
throw new MastraError(
|
|
629
|
+
{
|
|
630
|
+
id: "CLICKHOUSE_STORAGE_SAVE_THREAD_FAILED",
|
|
631
|
+
domain: ErrorDomain.STORAGE,
|
|
632
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
633
|
+
details: { threadId: thread.id }
|
|
634
|
+
},
|
|
635
|
+
error
|
|
636
|
+
);
|
|
500
637
|
}
|
|
501
638
|
}
|
|
502
639
|
async updateThread({
|
|
@@ -540,8 +677,15 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
540
677
|
});
|
|
541
678
|
return updatedThread;
|
|
542
679
|
} catch (error) {
|
|
543
|
-
|
|
544
|
-
|
|
680
|
+
throw new MastraError(
|
|
681
|
+
{
|
|
682
|
+
id: "CLICKHOUSE_STORAGE_UPDATE_THREAD_FAILED",
|
|
683
|
+
domain: ErrorDomain.STORAGE,
|
|
684
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
685
|
+
details: { threadId: id, title }
|
|
686
|
+
},
|
|
687
|
+
error
|
|
688
|
+
);
|
|
545
689
|
}
|
|
546
690
|
}
|
|
547
691
|
async deleteThread({ threadId }) {
|
|
@@ -561,8 +705,15 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
561
705
|
}
|
|
562
706
|
});
|
|
563
707
|
} catch (error) {
|
|
564
|
-
|
|
565
|
-
|
|
708
|
+
throw new MastraError(
|
|
709
|
+
{
|
|
710
|
+
id: "CLICKHOUSE_STORAGE_DELETE_THREAD_FAILED",
|
|
711
|
+
domain: ErrorDomain.STORAGE,
|
|
712
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
713
|
+
details: { threadId }
|
|
714
|
+
},
|
|
715
|
+
error
|
|
716
|
+
);
|
|
566
717
|
}
|
|
567
718
|
}
|
|
568
719
|
async getMessages({
|
|
@@ -573,7 +724,7 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
573
724
|
}) {
|
|
574
725
|
try {
|
|
575
726
|
const messages = [];
|
|
576
|
-
const limit =
|
|
727
|
+
const limit = this.resolveMessageLimit({ last: selectBy?.last, defaultLimit: 40 });
|
|
577
728
|
const include = selectBy?.include || [];
|
|
578
729
|
if (include.length) {
|
|
579
730
|
const includeResult = await this.db.query({
|
|
@@ -670,8 +821,15 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
670
821
|
if (format === `v2`) return list.get.all.v2();
|
|
671
822
|
return list.get.all.v1();
|
|
672
823
|
} catch (error) {
|
|
673
|
-
|
|
674
|
-
|
|
824
|
+
throw new MastraError(
|
|
825
|
+
{
|
|
826
|
+
id: "CLICKHOUSE_STORAGE_GET_MESSAGES_FAILED",
|
|
827
|
+
domain: ErrorDomain.STORAGE,
|
|
828
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
829
|
+
details: { threadId, resourceId: resourceId ?? "" }
|
|
830
|
+
},
|
|
831
|
+
error
|
|
832
|
+
);
|
|
675
833
|
}
|
|
676
834
|
}
|
|
677
835
|
async saveMessages(args) {
|
|
@@ -687,12 +845,52 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
687
845
|
if (!thread) {
|
|
688
846
|
throw new Error(`Thread ${threadId} not found`);
|
|
689
847
|
}
|
|
848
|
+
const existingResult = await this.db.query({
|
|
849
|
+
query: `SELECT id, thread_id FROM ${TABLE_MESSAGES} WHERE id IN ({ids:Array(String)})`,
|
|
850
|
+
query_params: {
|
|
851
|
+
ids: messages.map((m) => m.id)
|
|
852
|
+
},
|
|
853
|
+
clickhouse_settings: {
|
|
854
|
+
// Allows to insert serialized JS Dates (such as '2023-12-06T10:54:48.000Z')
|
|
855
|
+
date_time_input_format: "best_effort",
|
|
856
|
+
date_time_output_format: "iso",
|
|
857
|
+
use_client_time_zone: 1,
|
|
858
|
+
output_format_json_quote_64bit_integers: 0
|
|
859
|
+
},
|
|
860
|
+
format: "JSONEachRow"
|
|
861
|
+
});
|
|
862
|
+
const existingRows = await existingResult.json();
|
|
863
|
+
const existingSet = new Set(existingRows.map((row) => `${row.id}::${row.thread_id}`));
|
|
864
|
+
const toInsert = messages.filter((m) => !existingSet.has(`${m.id}::${threadId}`));
|
|
865
|
+
const toUpdate = messages.filter((m) => existingSet.has(`${m.id}::${threadId}`));
|
|
866
|
+
const updatePromises = toUpdate.map(
|
|
867
|
+
(message) => this.db.command({
|
|
868
|
+
query: `
|
|
869
|
+
ALTER TABLE ${TABLE_MESSAGES}
|
|
870
|
+
UPDATE content = {var_content:String}, role = {var_role:String}, type = {var_type:String}
|
|
871
|
+
WHERE id = {var_id:String} AND thread_id = {var_thread_id:String}
|
|
872
|
+
`,
|
|
873
|
+
query_params: {
|
|
874
|
+
var_content: typeof message.content === "string" ? message.content : JSON.stringify(message.content),
|
|
875
|
+
var_role: message.role,
|
|
876
|
+
var_type: message.type || "v2",
|
|
877
|
+
var_id: message.id,
|
|
878
|
+
var_thread_id: threadId
|
|
879
|
+
},
|
|
880
|
+
clickhouse_settings: {
|
|
881
|
+
// Allows to insert serialized JS Dates (such as '2023-12-06T10:54:48.000Z')
|
|
882
|
+
date_time_input_format: "best_effort",
|
|
883
|
+
use_client_time_zone: 1,
|
|
884
|
+
output_format_json_quote_64bit_integers: 0
|
|
885
|
+
}
|
|
886
|
+
})
|
|
887
|
+
);
|
|
690
888
|
await Promise.all([
|
|
691
889
|
// Insert messages
|
|
692
890
|
this.db.insert({
|
|
693
891
|
table: TABLE_MESSAGES,
|
|
694
892
|
format: "JSONEachRow",
|
|
695
|
-
values:
|
|
893
|
+
values: toInsert.map((message) => ({
|
|
696
894
|
id: message.id,
|
|
697
895
|
thread_id: threadId,
|
|
698
896
|
content: typeof message.content === "string" ? message.content : JSON.stringify(message.content),
|
|
@@ -707,6 +905,7 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
707
905
|
output_format_json_quote_64bit_integers: 0
|
|
708
906
|
}
|
|
709
907
|
}),
|
|
908
|
+
...updatePromises,
|
|
710
909
|
// Update thread's updatedAt timestamp
|
|
711
910
|
this.db.insert({
|
|
712
911
|
table: TABLE_THREADS,
|
|
@@ -732,8 +931,14 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
732
931
|
if (format === `v2`) return list.get.all.v2();
|
|
733
932
|
return list.get.all.v1();
|
|
734
933
|
} catch (error) {
|
|
735
|
-
|
|
736
|
-
|
|
934
|
+
throw new MastraError(
|
|
935
|
+
{
|
|
936
|
+
id: "CLICKHOUSE_STORAGE_SAVE_MESSAGES_FAILED",
|
|
937
|
+
domain: ErrorDomain.STORAGE,
|
|
938
|
+
category: ErrorCategory.THIRD_PARTY
|
|
939
|
+
},
|
|
940
|
+
error
|
|
941
|
+
);
|
|
737
942
|
}
|
|
738
943
|
}
|
|
739
944
|
async persistWorkflowSnapshot({
|
|
@@ -770,8 +975,15 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
770
975
|
}
|
|
771
976
|
});
|
|
772
977
|
} catch (error) {
|
|
773
|
-
|
|
774
|
-
|
|
978
|
+
throw new MastraError(
|
|
979
|
+
{
|
|
980
|
+
id: "CLICKHOUSE_STORAGE_PERSIST_WORKFLOW_SNAPSHOT_FAILED",
|
|
981
|
+
domain: ErrorDomain.STORAGE,
|
|
982
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
983
|
+
details: { workflowName, runId }
|
|
984
|
+
},
|
|
985
|
+
error
|
|
986
|
+
);
|
|
775
987
|
}
|
|
776
988
|
}
|
|
777
989
|
async loadWorkflowSnapshot({
|
|
@@ -791,8 +1003,15 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
791
1003
|
}
|
|
792
1004
|
return result.snapshot;
|
|
793
1005
|
} catch (error) {
|
|
794
|
-
|
|
795
|
-
|
|
1006
|
+
throw new MastraError(
|
|
1007
|
+
{
|
|
1008
|
+
id: "CLICKHOUSE_STORAGE_LOAD_WORKFLOW_SNAPSHOT_FAILED",
|
|
1009
|
+
domain: ErrorDomain.STORAGE,
|
|
1010
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1011
|
+
details: { workflowName, runId }
|
|
1012
|
+
},
|
|
1013
|
+
error
|
|
1014
|
+
);
|
|
796
1015
|
}
|
|
797
1016
|
}
|
|
798
1017
|
parseWorkflowRun(row) {
|
|
@@ -883,8 +1102,15 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
883
1102
|
});
|
|
884
1103
|
return { runs, total: total || runs.length };
|
|
885
1104
|
} catch (error) {
|
|
886
|
-
|
|
887
|
-
|
|
1105
|
+
throw new MastraError(
|
|
1106
|
+
{
|
|
1107
|
+
id: "CLICKHOUSE_STORAGE_GET_WORKFLOW_RUNS_FAILED",
|
|
1108
|
+
domain: ErrorDomain.STORAGE,
|
|
1109
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1110
|
+
details: { workflowName: workflowName ?? "", resourceId: resourceId ?? "" }
|
|
1111
|
+
},
|
|
1112
|
+
error
|
|
1113
|
+
);
|
|
888
1114
|
}
|
|
889
1115
|
}
|
|
890
1116
|
async getWorkflowRunById({
|
|
@@ -924,8 +1150,15 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
924
1150
|
}
|
|
925
1151
|
return this.parseWorkflowRun(resultJson[0]);
|
|
926
1152
|
} catch (error) {
|
|
927
|
-
|
|
928
|
-
|
|
1153
|
+
throw new MastraError(
|
|
1154
|
+
{
|
|
1155
|
+
id: "CLICKHOUSE_STORAGE_GET_WORKFLOW_RUN_BY_ID_FAILED",
|
|
1156
|
+
domain: ErrorDomain.STORAGE,
|
|
1157
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1158
|
+
details: { runId: runId ?? "", workflowName: workflowName ?? "" }
|
|
1159
|
+
},
|
|
1160
|
+
error
|
|
1161
|
+
);
|
|
929
1162
|
}
|
|
930
1163
|
}
|
|
931
1164
|
async hasColumn(table, column) {
|
|
@@ -937,13 +1170,28 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
937
1170
|
return columns.some((c) => c.name === column);
|
|
938
1171
|
}
|
|
939
1172
|
async getTracesPaginated(_args) {
|
|
940
|
-
throw new
|
|
1173
|
+
throw new MastraError({
|
|
1174
|
+
id: "CLICKHOUSE_STORAGE_GET_TRACES_PAGINATED_FAILED",
|
|
1175
|
+
domain: ErrorDomain.STORAGE,
|
|
1176
|
+
category: ErrorCategory.USER,
|
|
1177
|
+
text: "Method not implemented."
|
|
1178
|
+
});
|
|
941
1179
|
}
|
|
942
1180
|
async getThreadsByResourceIdPaginated(_args) {
|
|
943
|
-
throw new
|
|
1181
|
+
throw new MastraError({
|
|
1182
|
+
id: "CLICKHOUSE_STORAGE_GET_THREADS_BY_RESOURCE_ID_PAGINATED_FAILED",
|
|
1183
|
+
domain: ErrorDomain.STORAGE,
|
|
1184
|
+
category: ErrorCategory.USER,
|
|
1185
|
+
text: "Method not implemented."
|
|
1186
|
+
});
|
|
944
1187
|
}
|
|
945
1188
|
async getMessagesPaginated(_args) {
|
|
946
|
-
throw new
|
|
1189
|
+
throw new MastraError({
|
|
1190
|
+
id: "CLICKHOUSE_STORAGE_GET_MESSAGES_PAGINATED_FAILED",
|
|
1191
|
+
domain: ErrorDomain.STORAGE,
|
|
1192
|
+
category: ErrorCategory.USER,
|
|
1193
|
+
text: "Method not implemented."
|
|
1194
|
+
});
|
|
947
1195
|
}
|
|
948
1196
|
async close() {
|
|
949
1197
|
await this.db.close();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/clickhouse",
|
|
3
|
-
"version": "0.11.1-alpha.
|
|
3
|
+
"version": "0.11.1-alpha.2",
|
|
4
4
|
"description": "Clickhouse provider for Mastra - includes db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@microsoft/api-extractor": "^7.52.8",
|
|
27
27
|
"@types/node": "^20.19.0",
|
|
28
|
-
"eslint": "^9.
|
|
28
|
+
"eslint": "^9.29.0",
|
|
29
29
|
"tsup": "^8.5.0",
|
|
30
30
|
"typescript": "^5.8.3",
|
|
31
31
|
"vitest": "^3.2.3",
|
|
32
32
|
"@internal/lint": "0.0.13",
|
|
33
33
|
"@internal/storage-test-utils": "0.0.9",
|
|
34
|
-
"@mastra/core": "0.10.7-alpha.
|
|
34
|
+
"@mastra/core": "0.10.7-alpha.2"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@mastra/core": ">=0.10.4-0 <0.11.0"
|