@mastra/clickhouse 1.0.0-beta.1 → 1.0.0-beta.3
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 +56 -0
- package/dist/index.cjs +120 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +121 -93
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/operations/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +4 -0
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +20 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createClient } from '@clickhouse/client';
|
|
2
2
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
3
|
-
import { TABLE_SPANS, TABLE_RESOURCES, TABLE_SCORERS, TABLE_THREADS, TABLE_TRACES, TABLE_WORKFLOW_SNAPSHOT, TABLE_MESSAGES, MastraStorage, StoreOperations, TABLE_SCHEMAS, WorkflowsStorage, normalizePerPage, ScoresStorage,
|
|
3
|
+
import { TABLE_SPANS, TABLE_RESOURCES, TABLE_SCORERS, TABLE_THREADS, TABLE_TRACES, TABLE_WORKFLOW_SNAPSHOT, TABLE_MESSAGES, MastraStorage, createStorageErrorId, StoreOperations, TABLE_SCHEMAS, WorkflowsStorage, normalizePerPage, ScoresStorage, transformScoreRow, SCORERS_SCHEMA, calculatePagination, MemoryStorage, safelyParseJSON } from '@mastra/core/storage';
|
|
4
4
|
import { MessageList } from '@mastra/core/agent';
|
|
5
5
|
import { saveScorePayloadSchema } from '@mastra/core/evals';
|
|
6
6
|
|
|
@@ -114,7 +114,7 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
114
114
|
} catch (error) {
|
|
115
115
|
throw new MastraError(
|
|
116
116
|
{
|
|
117
|
-
id: "
|
|
117
|
+
id: createStorageErrorId("CLICKHOUSE", "LIST_MESSAGES_BY_ID", "FAILED"),
|
|
118
118
|
domain: ErrorDomain.STORAGE,
|
|
119
119
|
category: ErrorCategory.THIRD_PARTY,
|
|
120
120
|
details: { messageIds: JSON.stringify(messageIds) }
|
|
@@ -125,10 +125,12 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
125
125
|
}
|
|
126
126
|
async listMessages(args) {
|
|
127
127
|
const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
|
|
128
|
+
const rawThreadIds = Array.isArray(threadId) ? threadId : [threadId];
|
|
129
|
+
const threadIds = rawThreadIds.filter((id) => id !== void 0 && id !== null).map((id) => (typeof id === "string" ? id : String(id)).trim()).filter((id) => id.length > 0);
|
|
128
130
|
if (page < 0) {
|
|
129
131
|
throw new MastraError(
|
|
130
132
|
{
|
|
131
|
-
id: "
|
|
133
|
+
id: createStorageErrorId("CLICKHOUSE", "LIST_MESSAGES", "INVALID_PAGE"),
|
|
132
134
|
domain: ErrorDomain.STORAGE,
|
|
133
135
|
category: ErrorCategory.USER,
|
|
134
136
|
details: { page }
|
|
@@ -136,20 +138,21 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
136
138
|
new Error("page must be >= 0")
|
|
137
139
|
);
|
|
138
140
|
}
|
|
139
|
-
if (
|
|
141
|
+
if (threadIds.length === 0) {
|
|
140
142
|
throw new MastraError(
|
|
141
143
|
{
|
|
142
|
-
id: "
|
|
144
|
+
id: createStorageErrorId("CLICKHOUSE", "LIST_MESSAGES", "INVALID_THREAD_ID"),
|
|
143
145
|
domain: ErrorDomain.STORAGE,
|
|
144
146
|
category: ErrorCategory.THIRD_PARTY,
|
|
145
|
-
details: { threadId }
|
|
147
|
+
details: { threadId: Array.isArray(threadId) ? JSON.stringify(threadId) : String(threadId) }
|
|
146
148
|
},
|
|
147
|
-
new Error("threadId must be a non-empty string")
|
|
149
|
+
new Error("threadId must be a non-empty string or array of non-empty strings")
|
|
148
150
|
);
|
|
149
151
|
}
|
|
150
152
|
const perPageForQuery = normalizePerPage(perPageInput, 40);
|
|
151
153
|
const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPageForQuery);
|
|
152
154
|
try {
|
|
155
|
+
const threadCondition = threadIds.length === 1 ? `thread_id = {threadId0:String}` : `thread_id IN (${threadIds.map((_, i) => `{threadId${i}:String}`).join(", ")})`;
|
|
153
156
|
let dataQuery = `
|
|
154
157
|
SELECT
|
|
155
158
|
id,
|
|
@@ -160,9 +163,12 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
160
163
|
thread_id AS "threadId",
|
|
161
164
|
resourceId
|
|
162
165
|
FROM ${TABLE_MESSAGES}
|
|
163
|
-
WHERE
|
|
166
|
+
WHERE ${threadCondition}
|
|
164
167
|
`;
|
|
165
|
-
const dataParams = {
|
|
168
|
+
const dataParams = {};
|
|
169
|
+
threadIds.forEach((tid, i) => {
|
|
170
|
+
dataParams[`threadId${i}`] = tid;
|
|
171
|
+
});
|
|
166
172
|
if (resourceId) {
|
|
167
173
|
dataQuery += ` AND resourceId = {resourceId:String}`;
|
|
168
174
|
dataParams.resourceId = resourceId;
|
|
@@ -197,8 +203,11 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
197
203
|
const rows = await result.json();
|
|
198
204
|
const paginatedMessages = transformRows(rows.data);
|
|
199
205
|
const paginatedCount = paginatedMessages.length;
|
|
200
|
-
let countQuery = `SELECT count() as total FROM ${TABLE_MESSAGES} WHERE
|
|
201
|
-
const countParams = {
|
|
206
|
+
let countQuery = `SELECT count() as total FROM ${TABLE_MESSAGES} WHERE ${threadCondition}`;
|
|
207
|
+
const countParams = {};
|
|
208
|
+
threadIds.forEach((tid, i) => {
|
|
209
|
+
countParams[`threadId${i}`] = tid;
|
|
210
|
+
});
|
|
202
211
|
if (resourceId) {
|
|
203
212
|
countQuery += ` AND resourceId = {resourceId:String}`;
|
|
204
213
|
countParams.resourceId = resourceId;
|
|
@@ -237,12 +246,25 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
237
246
|
const messageIds = new Set(paginatedMessages.map((m) => m.id));
|
|
238
247
|
let includeMessages = [];
|
|
239
248
|
if (include && include.length > 0) {
|
|
249
|
+
const includesNeedingThread = include.filter((inc) => !inc.threadId);
|
|
250
|
+
const threadByMessageId = /* @__PURE__ */ new Map();
|
|
251
|
+
if (includesNeedingThread.length > 0) {
|
|
252
|
+
const { messages: includeLookup } = await this.listMessagesById({
|
|
253
|
+
messageIds: includesNeedingThread.map((inc) => inc.id)
|
|
254
|
+
});
|
|
255
|
+
for (const msg of includeLookup) {
|
|
256
|
+
if (msg.threadId) {
|
|
257
|
+
threadByMessageId.set(msg.id, msg.threadId);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
240
261
|
const unionQueries = [];
|
|
241
262
|
const params = [];
|
|
242
263
|
let paramIdx = 1;
|
|
243
264
|
for (const inc of include) {
|
|
244
265
|
const { id, withPreviousMessages = 0, withNextMessages = 0 } = inc;
|
|
245
|
-
const
|
|
266
|
+
const searchThreadId = inc.threadId ?? threadByMessageId.get(id);
|
|
267
|
+
if (!searchThreadId) continue;
|
|
246
268
|
unionQueries.push(`
|
|
247
269
|
SELECT * FROM (
|
|
248
270
|
WITH numbered_messages AS (
|
|
@@ -264,31 +286,33 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
264
286
|
) AS query_${paramIdx}
|
|
265
287
|
`);
|
|
266
288
|
params.push(
|
|
267
|
-
{ [`var_thread_id_${paramIdx}`]:
|
|
289
|
+
{ [`var_thread_id_${paramIdx}`]: searchThreadId },
|
|
268
290
|
{ [`var_include_id_${paramIdx}`]: id },
|
|
269
291
|
{ [`var_withPreviousMessages_${paramIdx}`]: withPreviousMessages },
|
|
270
292
|
{ [`var_withNextMessages_${paramIdx}`]: withNextMessages }
|
|
271
293
|
);
|
|
272
294
|
paramIdx++;
|
|
273
295
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
query
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
296
|
+
if (unionQueries.length > 0) {
|
|
297
|
+
const finalQuery = unionQueries.join(" UNION ALL ") + ' ORDER BY "createdAt" ASC';
|
|
298
|
+
const mergedParams = params.reduce((acc, paramObj) => ({ ...acc, ...paramObj }), {});
|
|
299
|
+
const includeResult = await this.client.query({
|
|
300
|
+
query: finalQuery,
|
|
301
|
+
query_params: mergedParams,
|
|
302
|
+
clickhouse_settings: {
|
|
303
|
+
date_time_input_format: "best_effort",
|
|
304
|
+
date_time_output_format: "iso",
|
|
305
|
+
use_client_time_zone: 1,
|
|
306
|
+
output_format_json_quote_64bit_integers: 0
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
const includeRows = await includeResult.json();
|
|
310
|
+
includeMessages = transformRows(includeRows.data);
|
|
311
|
+
for (const includeMsg of includeMessages) {
|
|
312
|
+
if (!messageIds.has(includeMsg.id)) {
|
|
313
|
+
paginatedMessages.push(includeMsg);
|
|
314
|
+
messageIds.add(includeMsg.id);
|
|
315
|
+
}
|
|
292
316
|
}
|
|
293
317
|
}
|
|
294
318
|
}
|
|
@@ -306,7 +330,10 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
306
330
|
}
|
|
307
331
|
return direction === "ASC" ? String(aValue).localeCompare(String(bValue)) : String(bValue).localeCompare(String(aValue));
|
|
308
332
|
});
|
|
309
|
-
const
|
|
333
|
+
const threadIdSet = new Set(threadIds);
|
|
334
|
+
const returnedThreadMessageIds = new Set(
|
|
335
|
+
finalMessages.filter((m) => m.threadId && threadIdSet.has(m.threadId)).map((m) => m.id)
|
|
336
|
+
);
|
|
310
337
|
const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
|
|
311
338
|
const hasMore = perPageForResponse === false ? false : allThreadMessagesReturned ? false : offset + paginatedCount < total;
|
|
312
339
|
return {
|
|
@@ -319,11 +346,11 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
319
346
|
} catch (error) {
|
|
320
347
|
const mastraError = new MastraError(
|
|
321
348
|
{
|
|
322
|
-
id: "
|
|
349
|
+
id: createStorageErrorId("CLICKHOUSE", "LIST_MESSAGES", "FAILED"),
|
|
323
350
|
domain: ErrorDomain.STORAGE,
|
|
324
351
|
category: ErrorCategory.THIRD_PARTY,
|
|
325
352
|
details: {
|
|
326
|
-
threadId,
|
|
353
|
+
threadId: Array.isArray(threadId) ? threadId.join(",") : threadId,
|
|
327
354
|
resourceId: resourceId ?? ""
|
|
328
355
|
}
|
|
329
356
|
},
|
|
@@ -482,7 +509,7 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
482
509
|
} catch (error) {
|
|
483
510
|
throw new MastraError(
|
|
484
511
|
{
|
|
485
|
-
id: "
|
|
512
|
+
id: createStorageErrorId("CLICKHOUSE", "SAVE_MESSAGES", "FAILED"),
|
|
486
513
|
domain: ErrorDomain.STORAGE,
|
|
487
514
|
category: ErrorCategory.THIRD_PARTY
|
|
488
515
|
},
|
|
@@ -527,7 +554,7 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
527
554
|
} catch (error) {
|
|
528
555
|
throw new MastraError(
|
|
529
556
|
{
|
|
530
|
-
id: "
|
|
557
|
+
id: createStorageErrorId("CLICKHOUSE", "GET_THREAD_BY_ID", "FAILED"),
|
|
531
558
|
domain: ErrorDomain.STORAGE,
|
|
532
559
|
category: ErrorCategory.THIRD_PARTY,
|
|
533
560
|
details: { threadId }
|
|
@@ -560,7 +587,7 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
560
587
|
} catch (error) {
|
|
561
588
|
throw new MastraError(
|
|
562
589
|
{
|
|
563
|
-
id: "
|
|
590
|
+
id: createStorageErrorId("CLICKHOUSE", "SAVE_THREAD", "FAILED"),
|
|
564
591
|
domain: ErrorDomain.STORAGE,
|
|
565
592
|
category: ErrorCategory.THIRD_PARTY,
|
|
566
593
|
details: { threadId: thread.id }
|
|
@@ -612,7 +639,7 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
612
639
|
} catch (error) {
|
|
613
640
|
throw new MastraError(
|
|
614
641
|
{
|
|
615
|
-
id: "
|
|
642
|
+
id: createStorageErrorId("CLICKHOUSE", "UPDATE_THREAD", "FAILED"),
|
|
616
643
|
domain: ErrorDomain.STORAGE,
|
|
617
644
|
category: ErrorCategory.THIRD_PARTY,
|
|
618
645
|
details: { threadId: id, title }
|
|
@@ -640,7 +667,7 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
640
667
|
} catch (error) {
|
|
641
668
|
throw new MastraError(
|
|
642
669
|
{
|
|
643
|
-
id: "
|
|
670
|
+
id: createStorageErrorId("CLICKHOUSE", "DELETE_THREAD", "FAILED"),
|
|
644
671
|
domain: ErrorDomain.STORAGE,
|
|
645
672
|
category: ErrorCategory.THIRD_PARTY,
|
|
646
673
|
details: { threadId }
|
|
@@ -655,7 +682,7 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
655
682
|
if (page < 0) {
|
|
656
683
|
throw new MastraError(
|
|
657
684
|
{
|
|
658
|
-
id: "
|
|
685
|
+
id: createStorageErrorId("CLICKHOUSE", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
|
|
659
686
|
domain: ErrorDomain.STORAGE,
|
|
660
687
|
category: ErrorCategory.USER,
|
|
661
688
|
details: { page }
|
|
@@ -740,7 +767,7 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
740
767
|
} catch (error) {
|
|
741
768
|
throw new MastraError(
|
|
742
769
|
{
|
|
743
|
-
id: "
|
|
770
|
+
id: createStorageErrorId("CLICKHOUSE", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
|
|
744
771
|
domain: ErrorDomain.STORAGE,
|
|
745
772
|
category: ErrorCategory.THIRD_PARTY,
|
|
746
773
|
details: { resourceId, page }
|
|
@@ -1022,7 +1049,7 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
1022
1049
|
} catch (error) {
|
|
1023
1050
|
throw new MastraError(
|
|
1024
1051
|
{
|
|
1025
|
-
id: "
|
|
1052
|
+
id: createStorageErrorId("CLICKHOUSE", "UPDATE_MESSAGES", "FAILED"),
|
|
1026
1053
|
domain: ErrorDomain.STORAGE,
|
|
1027
1054
|
category: ErrorCategory.THIRD_PARTY,
|
|
1028
1055
|
details: { messageIds: messages.map((m) => m.id).join(",") }
|
|
@@ -1058,7 +1085,7 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
1058
1085
|
} catch (error) {
|
|
1059
1086
|
throw new MastraError(
|
|
1060
1087
|
{
|
|
1061
|
-
id: "
|
|
1088
|
+
id: createStorageErrorId("CLICKHOUSE", "GET_RESOURCE_BY_ID", "FAILED"),
|
|
1062
1089
|
domain: ErrorDomain.STORAGE,
|
|
1063
1090
|
category: ErrorCategory.THIRD_PARTY,
|
|
1064
1091
|
details: { resourceId }
|
|
@@ -1091,7 +1118,7 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
1091
1118
|
} catch (error) {
|
|
1092
1119
|
throw new MastraError(
|
|
1093
1120
|
{
|
|
1094
|
-
id: "
|
|
1121
|
+
id: createStorageErrorId("CLICKHOUSE", "SAVE_RESOURCE", "FAILED"),
|
|
1095
1122
|
domain: ErrorDomain.STORAGE,
|
|
1096
1123
|
category: ErrorCategory.THIRD_PARTY,
|
|
1097
1124
|
details: { resourceId: resource.id }
|
|
@@ -1157,7 +1184,7 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
1157
1184
|
} catch (error) {
|
|
1158
1185
|
throw new MastraError(
|
|
1159
1186
|
{
|
|
1160
|
-
id: "
|
|
1187
|
+
id: createStorageErrorId("CLICKHOUSE", "UPDATE_RESOURCE", "FAILED"),
|
|
1161
1188
|
domain: ErrorDomain.STORAGE,
|
|
1162
1189
|
category: ErrorCategory.THIRD_PARTY,
|
|
1163
1190
|
details: { resourceId }
|
|
@@ -1245,7 +1272,7 @@ var StoreOperationsClickhouse = class extends StoreOperations {
|
|
|
1245
1272
|
} catch (error) {
|
|
1246
1273
|
throw new MastraError(
|
|
1247
1274
|
{
|
|
1248
|
-
id: "
|
|
1275
|
+
id: createStorageErrorId("CLICKHOUSE", "CREATE_TABLE", "FAILED"),
|
|
1249
1276
|
domain: ErrorDomain.STORAGE,
|
|
1250
1277
|
category: ErrorCategory.THIRD_PARTY,
|
|
1251
1278
|
details: { tableName }
|
|
@@ -1284,7 +1311,7 @@ var StoreOperationsClickhouse = class extends StoreOperations {
|
|
|
1284
1311
|
} catch (error) {
|
|
1285
1312
|
throw new MastraError(
|
|
1286
1313
|
{
|
|
1287
|
-
id: "
|
|
1314
|
+
id: createStorageErrorId("CLICKHOUSE", "ALTER_TABLE", "FAILED"),
|
|
1288
1315
|
domain: ErrorDomain.STORAGE,
|
|
1289
1316
|
category: ErrorCategory.THIRD_PARTY,
|
|
1290
1317
|
details: { tableName }
|
|
@@ -1308,7 +1335,7 @@ var StoreOperationsClickhouse = class extends StoreOperations {
|
|
|
1308
1335
|
} catch (error) {
|
|
1309
1336
|
throw new MastraError(
|
|
1310
1337
|
{
|
|
1311
|
-
id: "
|
|
1338
|
+
id: createStorageErrorId("CLICKHOUSE", "CLEAR_TABLE", "FAILED"),
|
|
1312
1339
|
domain: ErrorDomain.STORAGE,
|
|
1313
1340
|
category: ErrorCategory.THIRD_PARTY,
|
|
1314
1341
|
details: { tableName }
|
|
@@ -1347,7 +1374,7 @@ var StoreOperationsClickhouse = class extends StoreOperations {
|
|
|
1347
1374
|
} catch (error) {
|
|
1348
1375
|
throw new MastraError(
|
|
1349
1376
|
{
|
|
1350
|
-
id: "
|
|
1377
|
+
id: createStorageErrorId("CLICKHOUSE", "INSERT", "FAILED"),
|
|
1351
1378
|
domain: ErrorDomain.STORAGE,
|
|
1352
1379
|
category: ErrorCategory.THIRD_PARTY,
|
|
1353
1380
|
details: { tableName }
|
|
@@ -1380,7 +1407,7 @@ var StoreOperationsClickhouse = class extends StoreOperations {
|
|
|
1380
1407
|
} catch (error) {
|
|
1381
1408
|
throw new MastraError(
|
|
1382
1409
|
{
|
|
1383
|
-
id: "
|
|
1410
|
+
id: createStorageErrorId("CLICKHOUSE", "BATCH_INSERT", "FAILED"),
|
|
1384
1411
|
domain: ErrorDomain.STORAGE,
|
|
1385
1412
|
category: ErrorCategory.THIRD_PARTY,
|
|
1386
1413
|
details: { tableName }
|
|
@@ -1431,7 +1458,7 @@ var StoreOperationsClickhouse = class extends StoreOperations {
|
|
|
1431
1458
|
} catch (error) {
|
|
1432
1459
|
throw new MastraError(
|
|
1433
1460
|
{
|
|
1434
|
-
id: "
|
|
1461
|
+
id: createStorageErrorId("CLICKHOUSE", "LOAD", "FAILED"),
|
|
1435
1462
|
domain: ErrorDomain.STORAGE,
|
|
1436
1463
|
category: ErrorCategory.THIRD_PARTY,
|
|
1437
1464
|
details: { tableName }
|
|
@@ -1449,30 +1476,15 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
|
|
|
1449
1476
|
this.client = client;
|
|
1450
1477
|
this.operations = operations;
|
|
1451
1478
|
}
|
|
1479
|
+
/**
|
|
1480
|
+
* ClickHouse-specific score row transformation.
|
|
1481
|
+
* Converts timestamps to Date objects and filters out '_null_' values.
|
|
1482
|
+
*/
|
|
1452
1483
|
transformScoreRow(row) {
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
const input = safelyParseJSON(row.input);
|
|
1458
|
-
const output = safelyParseJSON(row.output);
|
|
1459
|
-
const additionalContext = safelyParseJSON(row.additionalContext);
|
|
1460
|
-
const requestContext = safelyParseJSON(row.requestContext);
|
|
1461
|
-
const entity = safelyParseJSON(row.entity);
|
|
1462
|
-
return {
|
|
1463
|
-
...row,
|
|
1464
|
-
scorer,
|
|
1465
|
-
preprocessStepResult,
|
|
1466
|
-
analyzeStepResult,
|
|
1467
|
-
metadata,
|
|
1468
|
-
input,
|
|
1469
|
-
output,
|
|
1470
|
-
additionalContext,
|
|
1471
|
-
requestContext,
|
|
1472
|
-
entity,
|
|
1473
|
-
createdAt: new Date(row.createdAt),
|
|
1474
|
-
updatedAt: new Date(row.updatedAt)
|
|
1475
|
-
};
|
|
1484
|
+
return transformScoreRow(row, {
|
|
1485
|
+
convertTimestamps: true,
|
|
1486
|
+
nullValuePattern: "_null_"
|
|
1487
|
+
});
|
|
1476
1488
|
}
|
|
1477
1489
|
async getScoreById({ id }) {
|
|
1478
1490
|
try {
|
|
@@ -1496,7 +1508,7 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
|
|
|
1496
1508
|
} catch (error) {
|
|
1497
1509
|
throw new MastraError(
|
|
1498
1510
|
{
|
|
1499
|
-
id: "
|
|
1511
|
+
id: createStorageErrorId("CLICKHOUSE", "GET_SCORE_BY_ID", "FAILED"),
|
|
1500
1512
|
domain: ErrorDomain.STORAGE,
|
|
1501
1513
|
category: ErrorCategory.THIRD_PARTY,
|
|
1502
1514
|
details: { scoreId: id }
|
|
@@ -1512,7 +1524,7 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
|
|
|
1512
1524
|
} catch (error) {
|
|
1513
1525
|
throw new MastraError(
|
|
1514
1526
|
{
|
|
1515
|
-
id: "
|
|
1527
|
+
id: createStorageErrorId("CLICKHOUSE", "SAVE_SCORE", "VALIDATION_FAILED"),
|
|
1516
1528
|
domain: ErrorDomain.STORAGE,
|
|
1517
1529
|
category: ErrorCategory.USER,
|
|
1518
1530
|
details: { scoreId: score.id }
|
|
@@ -1521,9 +1533,15 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
|
|
|
1521
1533
|
);
|
|
1522
1534
|
}
|
|
1523
1535
|
try {
|
|
1524
|
-
const record = {
|
|
1525
|
-
|
|
1526
|
-
|
|
1536
|
+
const record = {};
|
|
1537
|
+
for (const key of Object.keys(SCORERS_SCHEMA)) {
|
|
1538
|
+
const value = parsedScore[key];
|
|
1539
|
+
if (key === "createdAt" || key === "updatedAt") {
|
|
1540
|
+
record[key] = (/* @__PURE__ */ new Date()).toISOString();
|
|
1541
|
+
continue;
|
|
1542
|
+
}
|
|
1543
|
+
record[key] = value === void 0 || value === null ? "_null_" : value;
|
|
1544
|
+
}
|
|
1527
1545
|
await this.client.insert({
|
|
1528
1546
|
table: TABLE_SCORERS,
|
|
1529
1547
|
values: [record],
|
|
@@ -1538,7 +1556,7 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
|
|
|
1538
1556
|
} catch (error) {
|
|
1539
1557
|
throw new MastraError(
|
|
1540
1558
|
{
|
|
1541
|
-
id: "
|
|
1559
|
+
id: createStorageErrorId("CLICKHOUSE", "SAVE_SCORE", "FAILED"),
|
|
1542
1560
|
domain: ErrorDomain.STORAGE,
|
|
1543
1561
|
category: ErrorCategory.THIRD_PARTY,
|
|
1544
1562
|
details: { scoreId: score.id }
|
|
@@ -1608,7 +1626,7 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
|
|
|
1608
1626
|
} catch (error) {
|
|
1609
1627
|
throw new MastraError(
|
|
1610
1628
|
{
|
|
1611
|
-
id: "
|
|
1629
|
+
id: createStorageErrorId("CLICKHOUSE", "LIST_SCORES_BY_RUN_ID", "FAILED"),
|
|
1612
1630
|
domain: ErrorDomain.STORAGE,
|
|
1613
1631
|
category: ErrorCategory.THIRD_PARTY,
|
|
1614
1632
|
details: { runId }
|
|
@@ -1699,7 +1717,7 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
|
|
|
1699
1717
|
} catch (error) {
|
|
1700
1718
|
throw new MastraError(
|
|
1701
1719
|
{
|
|
1702
|
-
id: "
|
|
1720
|
+
id: createStorageErrorId("CLICKHOUSE", "LIST_SCORES_BY_SCORER_ID", "FAILED"),
|
|
1703
1721
|
domain: ErrorDomain.STORAGE,
|
|
1704
1722
|
category: ErrorCategory.THIRD_PARTY,
|
|
1705
1723
|
details: { scorerId }
|
|
@@ -1771,7 +1789,7 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
|
|
|
1771
1789
|
} catch (error) {
|
|
1772
1790
|
throw new MastraError(
|
|
1773
1791
|
{
|
|
1774
|
-
id: "
|
|
1792
|
+
id: createStorageErrorId("CLICKHOUSE", "LIST_SCORES_BY_ENTITY_ID", "FAILED"),
|
|
1775
1793
|
domain: ErrorDomain.STORAGE,
|
|
1776
1794
|
category: ErrorCategory.THIRD_PARTY,
|
|
1777
1795
|
details: { entityId, entityType }
|
|
@@ -1846,7 +1864,7 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
|
|
|
1846
1864
|
} catch (error) {
|
|
1847
1865
|
throw new MastraError(
|
|
1848
1866
|
{
|
|
1849
|
-
id: "
|
|
1867
|
+
id: createStorageErrorId("CLICKHOUSE", "LIST_SCORES_BY_SPAN", "FAILED"),
|
|
1850
1868
|
domain: ErrorDomain.STORAGE,
|
|
1851
1869
|
category: ErrorCategory.THIRD_PARTY,
|
|
1852
1870
|
details: { traceId, spanId }
|
|
@@ -1871,14 +1889,24 @@ var WorkflowsStorageClickhouse = class extends WorkflowsStorage {
|
|
|
1871
1889
|
// result,
|
|
1872
1890
|
// requestContext,
|
|
1873
1891
|
}) {
|
|
1874
|
-
throw new
|
|
1892
|
+
throw new MastraError({
|
|
1893
|
+
id: createStorageErrorId("CLICKHOUSE", "UPDATE_WORKFLOW_RESULTS", "NOT_IMPLEMENTED"),
|
|
1894
|
+
domain: ErrorDomain.STORAGE,
|
|
1895
|
+
category: ErrorCategory.SYSTEM,
|
|
1896
|
+
text: "Method not implemented."
|
|
1897
|
+
});
|
|
1875
1898
|
}
|
|
1876
1899
|
updateWorkflowState({
|
|
1877
1900
|
// workflowName,
|
|
1878
1901
|
// runId,
|
|
1879
1902
|
// opts,
|
|
1880
1903
|
}) {
|
|
1881
|
-
throw new
|
|
1904
|
+
throw new MastraError({
|
|
1905
|
+
id: createStorageErrorId("CLICKHOUSE", "UPDATE_WORKFLOW_STATE", "NOT_IMPLEMENTED"),
|
|
1906
|
+
domain: ErrorDomain.STORAGE,
|
|
1907
|
+
category: ErrorCategory.SYSTEM,
|
|
1908
|
+
text: "Method not implemented."
|
|
1909
|
+
});
|
|
1882
1910
|
}
|
|
1883
1911
|
async persistWorkflowSnapshot({
|
|
1884
1912
|
workflowName,
|
|
@@ -1919,7 +1947,7 @@ var WorkflowsStorageClickhouse = class extends WorkflowsStorage {
|
|
|
1919
1947
|
} catch (error) {
|
|
1920
1948
|
throw new MastraError(
|
|
1921
1949
|
{
|
|
1922
|
-
id: "
|
|
1950
|
+
id: createStorageErrorId("CLICKHOUSE", "PERSIST_WORKFLOW_SNAPSHOT", "FAILED"),
|
|
1923
1951
|
domain: ErrorDomain.STORAGE,
|
|
1924
1952
|
category: ErrorCategory.THIRD_PARTY,
|
|
1925
1953
|
details: { workflowName, runId }
|
|
@@ -1947,7 +1975,7 @@ var WorkflowsStorageClickhouse = class extends WorkflowsStorage {
|
|
|
1947
1975
|
} catch (error) {
|
|
1948
1976
|
throw new MastraError(
|
|
1949
1977
|
{
|
|
1950
|
-
id: "
|
|
1978
|
+
id: createStorageErrorId("CLICKHOUSE", "LOAD_WORKFLOW_SNAPSHOT", "FAILED"),
|
|
1951
1979
|
domain: ErrorDomain.STORAGE,
|
|
1952
1980
|
category: ErrorCategory.THIRD_PARTY,
|
|
1953
1981
|
details: { workflowName, runId }
|
|
@@ -2054,7 +2082,7 @@ var WorkflowsStorageClickhouse = class extends WorkflowsStorage {
|
|
|
2054
2082
|
} catch (error) {
|
|
2055
2083
|
throw new MastraError(
|
|
2056
2084
|
{
|
|
2057
|
-
id: "
|
|
2085
|
+
id: createStorageErrorId("CLICKHOUSE", "LIST_WORKFLOW_RUNS", "FAILED"),
|
|
2058
2086
|
domain: ErrorDomain.STORAGE,
|
|
2059
2087
|
category: ErrorCategory.THIRD_PARTY,
|
|
2060
2088
|
details: { workflowName: workflowName ?? "", resourceId: resourceId ?? "" }
|
|
@@ -2103,7 +2131,7 @@ var WorkflowsStorageClickhouse = class extends WorkflowsStorage {
|
|
|
2103
2131
|
} catch (error) {
|
|
2104
2132
|
throw new MastraError(
|
|
2105
2133
|
{
|
|
2106
|
-
id: "
|
|
2134
|
+
id: createStorageErrorId("CLICKHOUSE", "GET_WORKFLOW_RUN_BY_ID", "FAILED"),
|
|
2107
2135
|
domain: ErrorDomain.STORAGE,
|
|
2108
2136
|
category: ErrorCategory.THIRD_PARTY,
|
|
2109
2137
|
details: { runId: runId ?? "", workflowName: workflowName ?? "" }
|
|
@@ -2120,7 +2148,7 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
2120
2148
|
ttl = {};
|
|
2121
2149
|
stores;
|
|
2122
2150
|
constructor(config) {
|
|
2123
|
-
super({ id: config.id, name: "ClickhouseStore" });
|
|
2151
|
+
super({ id: config.id, name: "ClickhouseStore", disableInit: config.disableInit });
|
|
2124
2152
|
this.db = createClient({
|
|
2125
2153
|
url: config.url,
|
|
2126
2154
|
username: config.username,
|
|
@@ -2166,7 +2194,7 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
2166
2194
|
} catch (error) {
|
|
2167
2195
|
throw new MastraError(
|
|
2168
2196
|
{
|
|
2169
|
-
id: "
|
|
2197
|
+
id: createStorageErrorId("CLICKHOUSE", "OPTIMIZE_TABLE", "FAILED"),
|
|
2170
2198
|
domain: ErrorDomain.STORAGE,
|
|
2171
2199
|
category: ErrorCategory.THIRD_PARTY,
|
|
2172
2200
|
details: { tableName }
|
|
@@ -2183,7 +2211,7 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
2183
2211
|
} catch (error) {
|
|
2184
2212
|
throw new MastraError(
|
|
2185
2213
|
{
|
|
2186
|
-
id: "
|
|
2214
|
+
id: createStorageErrorId("CLICKHOUSE", "MATERIALIZE_TTL", "FAILED"),
|
|
2187
2215
|
domain: ErrorDomain.STORAGE,
|
|
2188
2216
|
category: ErrorCategory.THIRD_PARTY,
|
|
2189
2217
|
details: { tableName }
|