@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 CHANGED
@@ -1,5 +1,61 @@
1
1
  # @mastra/clickhouse
2
2
 
3
+ ## 1.0.0-beta.3
4
+
5
+ ### Minor Changes
6
+
7
+ - Add `disableInit` option to all storage adapters ([#10851](https://github.com/mastra-ai/mastra/pull/10851))
8
+
9
+ Adds a new `disableInit` config option to all storage providers that allows users to disable automatic table creation/migrations at runtime. This is useful for CI/CD pipelines where you want to run migrations during deployment with elevated credentials, then run the application with `disableInit: true` so it doesn't attempt schema changes at runtime.
10
+
11
+ ```typescript
12
+ // CI/CD script - run migrations
13
+ const storage = new PostgresStore({
14
+ connectionString: DATABASE_URL,
15
+ id: 'pg-storage',
16
+ });
17
+ await storage.init();
18
+
19
+ // Runtime - skip auto-init
20
+ const storage = new PostgresStore({
21
+ connectionString: DATABASE_URL,
22
+ id: 'pg-storage',
23
+ disableInit: true,
24
+ });
25
+ ```
26
+
27
+ ### Patch Changes
28
+
29
+ - Standardize error IDs across all storage and vector stores using centralized helper functions (`createStorageErrorId` and `createVectorErrorId`). This ensures consistent error ID patterns (`MASTRA_STORAGE_{STORE}_{OPERATION}_{STATUS}` and `MASTRA_VECTOR_{STORE}_{OPERATION}_{STATUS}`) across the codebase for better error tracking and debugging. ([#10913](https://github.com/mastra-ai/mastra/pull/10913))
30
+
31
+ - Updated dependencies [[`3076c67`](https://github.com/mastra-ai/mastra/commit/3076c6778b18988ae7d5c4c5c466366974b2d63f), [`85d7ee1`](https://github.com/mastra-ai/mastra/commit/85d7ee18ff4e14d625a8a30ec6656bb49804989b), [`c6c1092`](https://github.com/mastra-ai/mastra/commit/c6c1092f8fbf76109303f69e000e96fd1960c4ce), [`81dc110`](https://github.com/mastra-ai/mastra/commit/81dc11008d147cf5bdc8996ead1aa61dbdebb6fc), [`7aedb74`](https://github.com/mastra-ai/mastra/commit/7aedb74883adf66af38e270e4068fd42e7a37036), [`8f02d80`](https://github.com/mastra-ai/mastra/commit/8f02d800777397e4b45d7f1ad041988a8b0c6630), [`d7aad50`](https://github.com/mastra-ai/mastra/commit/d7aad501ce61646b76b4b511e558ac4eea9884d0), [`ce0a73a`](https://github.com/mastra-ai/mastra/commit/ce0a73abeaa75b10ca38f9e40a255a645d50ebfb), [`a02e542`](https://github.com/mastra-ai/mastra/commit/a02e542d23179bad250b044b17ff023caa61739f), [`a372c64`](https://github.com/mastra-ai/mastra/commit/a372c640ad1fd12e8f0613cebdc682fc156b4d95), [`8846867`](https://github.com/mastra-ai/mastra/commit/8846867ffa9a3746767618e314bebac08eb77d87), [`42a42cf`](https://github.com/mastra-ai/mastra/commit/42a42cf3132b9786feecbb8c13c583dce5b0e198), [`ae08bf0`](https://github.com/mastra-ai/mastra/commit/ae08bf0ebc6a4e4da992b711c4a389c32ba84cf4), [`21735a7`](https://github.com/mastra-ai/mastra/commit/21735a7ef306963554a69a89b44f06c3bcd85141), [`1d877b8`](https://github.com/mastra-ai/mastra/commit/1d877b8d7b536a251c1a7a18db7ddcf4f68d6f8b)]:
32
+ - @mastra/core@1.0.0-beta.7
33
+
34
+ ## 1.0.0-beta.2
35
+
36
+ ### Patch Changes
37
+
38
+ - feat(storage): support querying messages from multiple threads ([#10663](https://github.com/mastra-ai/mastra/pull/10663))
39
+ - Fixed TypeScript errors where `threadId: string | string[]` was being passed to places expecting `Scalar` type
40
+ - Added proper multi-thread support for `listMessages` across all adapters when `threadId` is an array
41
+ - Updated `_getIncludedMessages` to look up message threadId by ID (since message IDs are globally unique)
42
+ - **upstash**: Added `msg-idx:{messageId}` index for O(1) message lookups (backwards compatible with fallback to scan for old messages, with automatic backfill)
43
+
44
+ - fix: ensure score responses match saved payloads for Mastra Stores. ([#10557](https://github.com/mastra-ai/mastra/pull/10557))
45
+
46
+ - Unify transformScoreRow functions across storage adapters ([#10648](https://github.com/mastra-ai/mastra/pull/10648))
47
+
48
+ Added a unified `transformScoreRow` function in `@mastra/core/storage` that provides schema-driven row transformation for score data. This eliminates code duplication across 10 storage adapters while maintaining store-specific behavior through configurable options:
49
+ - `preferredTimestampFields`: Preferred source fields for timestamps (PostgreSQL, Cloudflare D1)
50
+ - `convertTimestamps`: Convert timestamp strings to Date objects (MSSQL, MongoDB, ClickHouse)
51
+ - `nullValuePattern`: Skip values matching pattern (ClickHouse's `'_null_'`)
52
+ - `fieldMappings`: Map source column names to schema fields (LibSQL's `additionalLLMContext`)
53
+
54
+ Each store adapter now uses the unified function with appropriate options, reducing ~200 lines of duplicate transformation logic while ensuring consistent behavior across all storage backends.
55
+
56
+ - Updated dependencies [[`ac0d2f4`](https://github.com/mastra-ai/mastra/commit/ac0d2f4ff8831f72c1c66c2be809706d17f65789), [`1a0d3fc`](https://github.com/mastra-ai/mastra/commit/1a0d3fc811482c9c376cdf79ee615c23bae9b2d6), [`85a628b`](https://github.com/mastra-ai/mastra/commit/85a628b1224a8f64cd82ea7f033774bf22df7a7e), [`c237233`](https://github.com/mastra-ai/mastra/commit/c23723399ccedf7f5744b3f40997b79246bfbe64), [`15f9e21`](https://github.com/mastra-ai/mastra/commit/15f9e216177201ea6e3f6d0bfb063fcc0953444f), [`ff94dea`](https://github.com/mastra-ai/mastra/commit/ff94dea935f4e34545c63bcb6c29804732698809), [`5b2ff46`](https://github.com/mastra-ai/mastra/commit/5b2ff4651df70c146523a7fca773f8eb0a2272f8), [`db41688`](https://github.com/mastra-ai/mastra/commit/db4168806d007417e2e60b4f68656dca4e5f40c9), [`5ca599d`](https://github.com/mastra-ai/mastra/commit/5ca599d0bb59a1595f19f58473fcd67cc71cef58), [`bff1145`](https://github.com/mastra-ai/mastra/commit/bff114556b3cbadad9b2768488708f8ad0e91475), [`5c8ca24`](https://github.com/mastra-ai/mastra/commit/5c8ca247094e0cc2cdbd7137822fb47241f86e77), [`e191844`](https://github.com/mastra-ai/mastra/commit/e1918444ca3f80e82feef1dad506cd4ec6e2875f), [`22553f1`](https://github.com/mastra-ai/mastra/commit/22553f11c63ee5e966a9c034a349822249584691), [`7237163`](https://github.com/mastra-ai/mastra/commit/72371635dbf96a87df4b073cc48fc655afbdce3d), [`2500740`](https://github.com/mastra-ai/mastra/commit/2500740ea23da067d6e50ec71c625ab3ce275e64), [`873ecbb`](https://github.com/mastra-ai/mastra/commit/873ecbb517586aa17d2f1e99283755b3ebb2863f), [`4f9bbe5`](https://github.com/mastra-ai/mastra/commit/4f9bbe5968f42c86f4930b8193de3c3c17e5bd36), [`02e51fe`](https://github.com/mastra-ai/mastra/commit/02e51feddb3d4155cfbcc42624fd0d0970d032c0), [`8f3fa3a`](https://github.com/mastra-ai/mastra/commit/8f3fa3a652bb77da092f913ec51ae46e3a7e27dc), [`cd29ad2`](https://github.com/mastra-ai/mastra/commit/cd29ad23a255534e8191f249593849ed29160886), [`bdf4d8c`](https://github.com/mastra-ai/mastra/commit/bdf4d8cdc656d8a2c21d81834bfa3bfa70f56c16), [`854e3da`](https://github.com/mastra-ai/mastra/commit/854e3dad5daac17a91a20986399d3a51f54bf68b), [`ce18d38`](https://github.com/mastra-ai/mastra/commit/ce18d38678c65870350d123955014a8432075fd9), [`cccf9c8`](https://github.com/mastra-ai/mastra/commit/cccf9c8b2d2dfc1a5e63919395b83d78c89682a0), [`61a5705`](https://github.com/mastra-ai/mastra/commit/61a570551278b6743e64243b3ce7d73de915ca8a), [`db70a48`](https://github.com/mastra-ai/mastra/commit/db70a48aeeeeb8e5f92007e8ede52c364ce15287), [`f0fdc14`](https://github.com/mastra-ai/mastra/commit/f0fdc14ee233d619266b3d2bbdeea7d25cfc6d13), [`db18bc9`](https://github.com/mastra-ai/mastra/commit/db18bc9c3825e2c1a0ad9a183cc9935f6691bfa1), [`9b37b56`](https://github.com/mastra-ai/mastra/commit/9b37b565e1f2a76c24f728945cc740c2b09be9da), [`41a23c3`](https://github.com/mastra-ai/mastra/commit/41a23c32f9877d71810f37e24930515df2ff7a0f), [`5d171ad`](https://github.com/mastra-ai/mastra/commit/5d171ad9ef340387276b77c2bb3e83e83332d729), [`f03ae60`](https://github.com/mastra-ai/mastra/commit/f03ae60500fe350c9d828621006cdafe1975fdd8), [`d1e74a0`](https://github.com/mastra-ai/mastra/commit/d1e74a0a293866dece31022047f5dbab65a304d0), [`39e7869`](https://github.com/mastra-ai/mastra/commit/39e7869bc7d0ee391077ce291474d8a84eedccff), [`5761926`](https://github.com/mastra-ai/mastra/commit/57619260c4a2cdd598763abbacd90de594c6bc76), [`c900fdd`](https://github.com/mastra-ai/mastra/commit/c900fdd504c41348efdffb205cfe80d48c38fa33), [`604a79f`](https://github.com/mastra-ai/mastra/commit/604a79fecf276e26a54a3fe01bb94e65315d2e0e), [`887f0b4`](https://github.com/mastra-ai/mastra/commit/887f0b4746cdbd7cb7d6b17ac9f82aeb58037ea5), [`2562143`](https://github.com/mastra-ai/mastra/commit/256214336b4faa78646c9c1776612393790d8784), [`ef11a61`](https://github.com/mastra-ai/mastra/commit/ef11a61920fa0ed08a5b7ceedd192875af119749)]:
57
+ - @mastra/core@1.0.0-beta.6
58
+
3
59
  ## 1.0.0-beta.1
4
60
 
5
61
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -116,7 +116,7 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
116
116
  } catch (error$1) {
117
117
  throw new error.MastraError(
118
118
  {
119
- id: "CLICKHOUSE_STORAGE_LIST_MESSAGES_BY_ID_FAILED",
119
+ id: storage.createStorageErrorId("CLICKHOUSE", "LIST_MESSAGES_BY_ID", "FAILED"),
120
120
  domain: error.ErrorDomain.STORAGE,
121
121
  category: error.ErrorCategory.THIRD_PARTY,
122
122
  details: { messageIds: JSON.stringify(messageIds) }
@@ -127,10 +127,12 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
127
127
  }
128
128
  async listMessages(args) {
129
129
  const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
130
+ const rawThreadIds = Array.isArray(threadId) ? threadId : [threadId];
131
+ const threadIds = rawThreadIds.filter((id) => id !== void 0 && id !== null).map((id) => (typeof id === "string" ? id : String(id)).trim()).filter((id) => id.length > 0);
130
132
  if (page < 0) {
131
133
  throw new error.MastraError(
132
134
  {
133
- id: "STORAGE_CLICKHOUSE_LIST_MESSAGES_INVALID_PAGE",
135
+ id: storage.createStorageErrorId("CLICKHOUSE", "LIST_MESSAGES", "INVALID_PAGE"),
134
136
  domain: error.ErrorDomain.STORAGE,
135
137
  category: error.ErrorCategory.USER,
136
138
  details: { page }
@@ -138,20 +140,21 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
138
140
  new Error("page must be >= 0")
139
141
  );
140
142
  }
141
- if (!threadId.trim()) {
143
+ if (threadIds.length === 0) {
142
144
  throw new error.MastraError(
143
145
  {
144
- id: "STORAGE_CLICKHOUSE_LIST_MESSAGES_INVALID_THREAD_ID",
146
+ id: storage.createStorageErrorId("CLICKHOUSE", "LIST_MESSAGES", "INVALID_THREAD_ID"),
145
147
  domain: error.ErrorDomain.STORAGE,
146
148
  category: error.ErrorCategory.THIRD_PARTY,
147
- details: { threadId }
149
+ details: { threadId: Array.isArray(threadId) ? JSON.stringify(threadId) : String(threadId) }
148
150
  },
149
- new Error("threadId must be a non-empty string")
151
+ new Error("threadId must be a non-empty string or array of non-empty strings")
150
152
  );
151
153
  }
152
154
  const perPageForQuery = storage.normalizePerPage(perPageInput, 40);
153
155
  const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPageForQuery);
154
156
  try {
157
+ const threadCondition = threadIds.length === 1 ? `thread_id = {threadId0:String}` : `thread_id IN (${threadIds.map((_, i) => `{threadId${i}:String}`).join(", ")})`;
155
158
  let dataQuery = `
156
159
  SELECT
157
160
  id,
@@ -162,9 +165,12 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
162
165
  thread_id AS "threadId",
163
166
  resourceId
164
167
  FROM ${storage.TABLE_MESSAGES}
165
- WHERE thread_id = {threadId:String}
168
+ WHERE ${threadCondition}
166
169
  `;
167
- const dataParams = { threadId };
170
+ const dataParams = {};
171
+ threadIds.forEach((tid, i) => {
172
+ dataParams[`threadId${i}`] = tid;
173
+ });
168
174
  if (resourceId) {
169
175
  dataQuery += ` AND resourceId = {resourceId:String}`;
170
176
  dataParams.resourceId = resourceId;
@@ -199,8 +205,11 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
199
205
  const rows = await result.json();
200
206
  const paginatedMessages = transformRows(rows.data);
201
207
  const paginatedCount = paginatedMessages.length;
202
- let countQuery = `SELECT count() as total FROM ${storage.TABLE_MESSAGES} WHERE thread_id = {threadId:String}`;
203
- const countParams = { threadId };
208
+ let countQuery = `SELECT count() as total FROM ${storage.TABLE_MESSAGES} WHERE ${threadCondition}`;
209
+ const countParams = {};
210
+ threadIds.forEach((tid, i) => {
211
+ countParams[`threadId${i}`] = tid;
212
+ });
204
213
  if (resourceId) {
205
214
  countQuery += ` AND resourceId = {resourceId:String}`;
206
215
  countParams.resourceId = resourceId;
@@ -239,12 +248,25 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
239
248
  const messageIds = new Set(paginatedMessages.map((m) => m.id));
240
249
  let includeMessages = [];
241
250
  if (include && include.length > 0) {
251
+ const includesNeedingThread = include.filter((inc) => !inc.threadId);
252
+ const threadByMessageId = /* @__PURE__ */ new Map();
253
+ if (includesNeedingThread.length > 0) {
254
+ const { messages: includeLookup } = await this.listMessagesById({
255
+ messageIds: includesNeedingThread.map((inc) => inc.id)
256
+ });
257
+ for (const msg of includeLookup) {
258
+ if (msg.threadId) {
259
+ threadByMessageId.set(msg.id, msg.threadId);
260
+ }
261
+ }
262
+ }
242
263
  const unionQueries = [];
243
264
  const params = [];
244
265
  let paramIdx = 1;
245
266
  for (const inc of include) {
246
267
  const { id, withPreviousMessages = 0, withNextMessages = 0 } = inc;
247
- const searchId = inc.threadId || threadId;
268
+ const searchThreadId = inc.threadId ?? threadByMessageId.get(id);
269
+ if (!searchThreadId) continue;
248
270
  unionQueries.push(`
249
271
  SELECT * FROM (
250
272
  WITH numbered_messages AS (
@@ -266,31 +288,33 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
266
288
  ) AS query_${paramIdx}
267
289
  `);
268
290
  params.push(
269
- { [`var_thread_id_${paramIdx}`]: searchId },
291
+ { [`var_thread_id_${paramIdx}`]: searchThreadId },
270
292
  { [`var_include_id_${paramIdx}`]: id },
271
293
  { [`var_withPreviousMessages_${paramIdx}`]: withPreviousMessages },
272
294
  { [`var_withNextMessages_${paramIdx}`]: withNextMessages }
273
295
  );
274
296
  paramIdx++;
275
297
  }
276
- const finalQuery = unionQueries.join(" UNION ALL ") + ' ORDER BY "createdAt" ASC';
277
- const mergedParams = params.reduce((acc, paramObj) => ({ ...acc, ...paramObj }), {});
278
- const includeResult = await this.client.query({
279
- query: finalQuery,
280
- query_params: mergedParams,
281
- clickhouse_settings: {
282
- date_time_input_format: "best_effort",
283
- date_time_output_format: "iso",
284
- use_client_time_zone: 1,
285
- output_format_json_quote_64bit_integers: 0
286
- }
287
- });
288
- const includeRows = await includeResult.json();
289
- includeMessages = transformRows(includeRows.data);
290
- for (const includeMsg of includeMessages) {
291
- if (!messageIds.has(includeMsg.id)) {
292
- paginatedMessages.push(includeMsg);
293
- messageIds.add(includeMsg.id);
298
+ if (unionQueries.length > 0) {
299
+ const finalQuery = unionQueries.join(" UNION ALL ") + ' ORDER BY "createdAt" ASC';
300
+ const mergedParams = params.reduce((acc, paramObj) => ({ ...acc, ...paramObj }), {});
301
+ const includeResult = await this.client.query({
302
+ query: finalQuery,
303
+ query_params: mergedParams,
304
+ clickhouse_settings: {
305
+ date_time_input_format: "best_effort",
306
+ date_time_output_format: "iso",
307
+ use_client_time_zone: 1,
308
+ output_format_json_quote_64bit_integers: 0
309
+ }
310
+ });
311
+ const includeRows = await includeResult.json();
312
+ includeMessages = transformRows(includeRows.data);
313
+ for (const includeMsg of includeMessages) {
314
+ if (!messageIds.has(includeMsg.id)) {
315
+ paginatedMessages.push(includeMsg);
316
+ messageIds.add(includeMsg.id);
317
+ }
294
318
  }
295
319
  }
296
320
  }
@@ -308,7 +332,10 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
308
332
  }
309
333
  return direction === "ASC" ? String(aValue).localeCompare(String(bValue)) : String(bValue).localeCompare(String(aValue));
310
334
  });
311
- const returnedThreadMessageIds = new Set(finalMessages.filter((m) => m.threadId === threadId).map((m) => m.id));
335
+ const threadIdSet = new Set(threadIds);
336
+ const returnedThreadMessageIds = new Set(
337
+ finalMessages.filter((m) => m.threadId && threadIdSet.has(m.threadId)).map((m) => m.id)
338
+ );
312
339
  const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
313
340
  const hasMore = perPageForResponse === false ? false : allThreadMessagesReturned ? false : offset + paginatedCount < total;
314
341
  return {
@@ -321,11 +348,11 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
321
348
  } catch (error$1) {
322
349
  const mastraError = new error.MastraError(
323
350
  {
324
- id: "STORAGE_CLICKHOUSE_STORE_LIST_MESSAGES_FAILED",
351
+ id: storage.createStorageErrorId("CLICKHOUSE", "LIST_MESSAGES", "FAILED"),
325
352
  domain: error.ErrorDomain.STORAGE,
326
353
  category: error.ErrorCategory.THIRD_PARTY,
327
354
  details: {
328
- threadId,
355
+ threadId: Array.isArray(threadId) ? threadId.join(",") : threadId,
329
356
  resourceId: resourceId ?? ""
330
357
  }
331
358
  },
@@ -484,7 +511,7 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
484
511
  } catch (error$1) {
485
512
  throw new error.MastraError(
486
513
  {
487
- id: "CLICKHOUSE_STORAGE_SAVE_MESSAGES_FAILED",
514
+ id: storage.createStorageErrorId("CLICKHOUSE", "SAVE_MESSAGES", "FAILED"),
488
515
  domain: error.ErrorDomain.STORAGE,
489
516
  category: error.ErrorCategory.THIRD_PARTY
490
517
  },
@@ -529,7 +556,7 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
529
556
  } catch (error$1) {
530
557
  throw new error.MastraError(
531
558
  {
532
- id: "CLICKHOUSE_STORAGE_GET_THREAD_BY_ID_FAILED",
559
+ id: storage.createStorageErrorId("CLICKHOUSE", "GET_THREAD_BY_ID", "FAILED"),
533
560
  domain: error.ErrorDomain.STORAGE,
534
561
  category: error.ErrorCategory.THIRD_PARTY,
535
562
  details: { threadId }
@@ -562,7 +589,7 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
562
589
  } catch (error$1) {
563
590
  throw new error.MastraError(
564
591
  {
565
- id: "CLICKHOUSE_STORAGE_SAVE_THREAD_FAILED",
592
+ id: storage.createStorageErrorId("CLICKHOUSE", "SAVE_THREAD", "FAILED"),
566
593
  domain: error.ErrorDomain.STORAGE,
567
594
  category: error.ErrorCategory.THIRD_PARTY,
568
595
  details: { threadId: thread.id }
@@ -614,7 +641,7 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
614
641
  } catch (error$1) {
615
642
  throw new error.MastraError(
616
643
  {
617
- id: "CLICKHOUSE_STORAGE_UPDATE_THREAD_FAILED",
644
+ id: storage.createStorageErrorId("CLICKHOUSE", "UPDATE_THREAD", "FAILED"),
618
645
  domain: error.ErrorDomain.STORAGE,
619
646
  category: error.ErrorCategory.THIRD_PARTY,
620
647
  details: { threadId: id, title }
@@ -642,7 +669,7 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
642
669
  } catch (error$1) {
643
670
  throw new error.MastraError(
644
671
  {
645
- id: "CLICKHOUSE_STORAGE_DELETE_THREAD_FAILED",
672
+ id: storage.createStorageErrorId("CLICKHOUSE", "DELETE_THREAD", "FAILED"),
646
673
  domain: error.ErrorDomain.STORAGE,
647
674
  category: error.ErrorCategory.THIRD_PARTY,
648
675
  details: { threadId }
@@ -657,7 +684,7 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
657
684
  if (page < 0) {
658
685
  throw new error.MastraError(
659
686
  {
660
- id: "STORAGE_CLICKHOUSE_LIST_THREADS_BY_RESOURCE_ID_INVALID_PAGE",
687
+ id: storage.createStorageErrorId("CLICKHOUSE", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
661
688
  domain: error.ErrorDomain.STORAGE,
662
689
  category: error.ErrorCategory.USER,
663
690
  details: { page }
@@ -742,7 +769,7 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
742
769
  } catch (error$1) {
743
770
  throw new error.MastraError(
744
771
  {
745
- id: "CLICKHOUSE_STORAGE_LIST_THREADS_BY_RESOURCE_ID_FAILED",
772
+ id: storage.createStorageErrorId("CLICKHOUSE", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
746
773
  domain: error.ErrorDomain.STORAGE,
747
774
  category: error.ErrorCategory.THIRD_PARTY,
748
775
  details: { resourceId, page }
@@ -1024,7 +1051,7 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
1024
1051
  } catch (error$1) {
1025
1052
  throw new error.MastraError(
1026
1053
  {
1027
- id: "CLICKHOUSE_STORAGE_UPDATE_MESSAGES_FAILED",
1054
+ id: storage.createStorageErrorId("CLICKHOUSE", "UPDATE_MESSAGES", "FAILED"),
1028
1055
  domain: error.ErrorDomain.STORAGE,
1029
1056
  category: error.ErrorCategory.THIRD_PARTY,
1030
1057
  details: { messageIds: messages.map((m) => m.id).join(",") }
@@ -1060,7 +1087,7 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
1060
1087
  } catch (error$1) {
1061
1088
  throw new error.MastraError(
1062
1089
  {
1063
- id: "CLICKHOUSE_STORAGE_GET_RESOURCE_BY_ID_FAILED",
1090
+ id: storage.createStorageErrorId("CLICKHOUSE", "GET_RESOURCE_BY_ID", "FAILED"),
1064
1091
  domain: error.ErrorDomain.STORAGE,
1065
1092
  category: error.ErrorCategory.THIRD_PARTY,
1066
1093
  details: { resourceId }
@@ -1093,7 +1120,7 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
1093
1120
  } catch (error$1) {
1094
1121
  throw new error.MastraError(
1095
1122
  {
1096
- id: "CLICKHOUSE_STORAGE_SAVE_RESOURCE_FAILED",
1123
+ id: storage.createStorageErrorId("CLICKHOUSE", "SAVE_RESOURCE", "FAILED"),
1097
1124
  domain: error.ErrorDomain.STORAGE,
1098
1125
  category: error.ErrorCategory.THIRD_PARTY,
1099
1126
  details: { resourceId: resource.id }
@@ -1159,7 +1186,7 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
1159
1186
  } catch (error$1) {
1160
1187
  throw new error.MastraError(
1161
1188
  {
1162
- id: "CLICKHOUSE_STORAGE_UPDATE_RESOURCE_FAILED",
1189
+ id: storage.createStorageErrorId("CLICKHOUSE", "UPDATE_RESOURCE", "FAILED"),
1163
1190
  domain: error.ErrorDomain.STORAGE,
1164
1191
  category: error.ErrorCategory.THIRD_PARTY,
1165
1192
  details: { resourceId }
@@ -1247,7 +1274,7 @@ var StoreOperationsClickhouse = class extends storage.StoreOperations {
1247
1274
  } catch (error$1) {
1248
1275
  throw new error.MastraError(
1249
1276
  {
1250
- id: "CLICKHOUSE_STORAGE_CREATE_TABLE_FAILED",
1277
+ id: storage.createStorageErrorId("CLICKHOUSE", "CREATE_TABLE", "FAILED"),
1251
1278
  domain: error.ErrorDomain.STORAGE,
1252
1279
  category: error.ErrorCategory.THIRD_PARTY,
1253
1280
  details: { tableName }
@@ -1286,7 +1313,7 @@ var StoreOperationsClickhouse = class extends storage.StoreOperations {
1286
1313
  } catch (error$1) {
1287
1314
  throw new error.MastraError(
1288
1315
  {
1289
- id: "CLICKHOUSE_STORAGE_ALTER_TABLE_FAILED",
1316
+ id: storage.createStorageErrorId("CLICKHOUSE", "ALTER_TABLE", "FAILED"),
1290
1317
  domain: error.ErrorDomain.STORAGE,
1291
1318
  category: error.ErrorCategory.THIRD_PARTY,
1292
1319
  details: { tableName }
@@ -1310,7 +1337,7 @@ var StoreOperationsClickhouse = class extends storage.StoreOperations {
1310
1337
  } catch (error$1) {
1311
1338
  throw new error.MastraError(
1312
1339
  {
1313
- id: "CLICKHOUSE_STORAGE_CLEAR_TABLE_FAILED",
1340
+ id: storage.createStorageErrorId("CLICKHOUSE", "CLEAR_TABLE", "FAILED"),
1314
1341
  domain: error.ErrorDomain.STORAGE,
1315
1342
  category: error.ErrorCategory.THIRD_PARTY,
1316
1343
  details: { tableName }
@@ -1349,7 +1376,7 @@ var StoreOperationsClickhouse = class extends storage.StoreOperations {
1349
1376
  } catch (error$1) {
1350
1377
  throw new error.MastraError(
1351
1378
  {
1352
- id: "CLICKHOUSE_STORAGE_INSERT_FAILED",
1379
+ id: storage.createStorageErrorId("CLICKHOUSE", "INSERT", "FAILED"),
1353
1380
  domain: error.ErrorDomain.STORAGE,
1354
1381
  category: error.ErrorCategory.THIRD_PARTY,
1355
1382
  details: { tableName }
@@ -1382,7 +1409,7 @@ var StoreOperationsClickhouse = class extends storage.StoreOperations {
1382
1409
  } catch (error$1) {
1383
1410
  throw new error.MastraError(
1384
1411
  {
1385
- id: "CLICKHOUSE_STORAGE_BATCH_INSERT_FAILED",
1412
+ id: storage.createStorageErrorId("CLICKHOUSE", "BATCH_INSERT", "FAILED"),
1386
1413
  domain: error.ErrorDomain.STORAGE,
1387
1414
  category: error.ErrorCategory.THIRD_PARTY,
1388
1415
  details: { tableName }
@@ -1433,7 +1460,7 @@ var StoreOperationsClickhouse = class extends storage.StoreOperations {
1433
1460
  } catch (error$1) {
1434
1461
  throw new error.MastraError(
1435
1462
  {
1436
- id: "CLICKHOUSE_STORAGE_LOAD_FAILED",
1463
+ id: storage.createStorageErrorId("CLICKHOUSE", "LOAD", "FAILED"),
1437
1464
  domain: error.ErrorDomain.STORAGE,
1438
1465
  category: error.ErrorCategory.THIRD_PARTY,
1439
1466
  details: { tableName }
@@ -1451,30 +1478,15 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
1451
1478
  this.client = client;
1452
1479
  this.operations = operations;
1453
1480
  }
1481
+ /**
1482
+ * ClickHouse-specific score row transformation.
1483
+ * Converts timestamps to Date objects and filters out '_null_' values.
1484
+ */
1454
1485
  transformScoreRow(row) {
1455
- const scorer = storage.safelyParseJSON(row.scorer);
1456
- const preprocessStepResult = storage.safelyParseJSON(row.preprocessStepResult);
1457
- const analyzeStepResult = storage.safelyParseJSON(row.analyzeStepResult);
1458
- const metadata = storage.safelyParseJSON(row.metadata);
1459
- const input = storage.safelyParseJSON(row.input);
1460
- const output = storage.safelyParseJSON(row.output);
1461
- const additionalContext = storage.safelyParseJSON(row.additionalContext);
1462
- const requestContext = storage.safelyParseJSON(row.requestContext);
1463
- const entity = storage.safelyParseJSON(row.entity);
1464
- return {
1465
- ...row,
1466
- scorer,
1467
- preprocessStepResult,
1468
- analyzeStepResult,
1469
- metadata,
1470
- input,
1471
- output,
1472
- additionalContext,
1473
- requestContext,
1474
- entity,
1475
- createdAt: new Date(row.createdAt),
1476
- updatedAt: new Date(row.updatedAt)
1477
- };
1486
+ return storage.transformScoreRow(row, {
1487
+ convertTimestamps: true,
1488
+ nullValuePattern: "_null_"
1489
+ });
1478
1490
  }
1479
1491
  async getScoreById({ id }) {
1480
1492
  try {
@@ -1498,7 +1510,7 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
1498
1510
  } catch (error$1) {
1499
1511
  throw new error.MastraError(
1500
1512
  {
1501
- id: "CLICKHOUSE_STORAGE_GET_SCORE_BY_ID_FAILED",
1513
+ id: storage.createStorageErrorId("CLICKHOUSE", "GET_SCORE_BY_ID", "FAILED"),
1502
1514
  domain: error.ErrorDomain.STORAGE,
1503
1515
  category: error.ErrorCategory.THIRD_PARTY,
1504
1516
  details: { scoreId: id }
@@ -1514,7 +1526,7 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
1514
1526
  } catch (error$1) {
1515
1527
  throw new error.MastraError(
1516
1528
  {
1517
- id: "CLICKHOUSE_STORAGE_SAVE_SCORE_FAILED_INVALID_SCORE_PAYLOAD",
1529
+ id: storage.createStorageErrorId("CLICKHOUSE", "SAVE_SCORE", "VALIDATION_FAILED"),
1518
1530
  domain: error.ErrorDomain.STORAGE,
1519
1531
  category: error.ErrorCategory.USER,
1520
1532
  details: { scoreId: score.id }
@@ -1523,9 +1535,15 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
1523
1535
  );
1524
1536
  }
1525
1537
  try {
1526
- const record = {
1527
- ...parsedScore
1528
- };
1538
+ const record = {};
1539
+ for (const key of Object.keys(storage.SCORERS_SCHEMA)) {
1540
+ const value = parsedScore[key];
1541
+ if (key === "createdAt" || key === "updatedAt") {
1542
+ record[key] = (/* @__PURE__ */ new Date()).toISOString();
1543
+ continue;
1544
+ }
1545
+ record[key] = value === void 0 || value === null ? "_null_" : value;
1546
+ }
1529
1547
  await this.client.insert({
1530
1548
  table: storage.TABLE_SCORERS,
1531
1549
  values: [record],
@@ -1540,7 +1558,7 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
1540
1558
  } catch (error$1) {
1541
1559
  throw new error.MastraError(
1542
1560
  {
1543
- id: "CLICKHOUSE_STORAGE_SAVE_SCORE_FAILED",
1561
+ id: storage.createStorageErrorId("CLICKHOUSE", "SAVE_SCORE", "FAILED"),
1544
1562
  domain: error.ErrorDomain.STORAGE,
1545
1563
  category: error.ErrorCategory.THIRD_PARTY,
1546
1564
  details: { scoreId: score.id }
@@ -1610,7 +1628,7 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
1610
1628
  } catch (error$1) {
1611
1629
  throw new error.MastraError(
1612
1630
  {
1613
- id: "CLICKHOUSE_STORAGE_GET_SCORES_BY_RUN_ID_FAILED",
1631
+ id: storage.createStorageErrorId("CLICKHOUSE", "LIST_SCORES_BY_RUN_ID", "FAILED"),
1614
1632
  domain: error.ErrorDomain.STORAGE,
1615
1633
  category: error.ErrorCategory.THIRD_PARTY,
1616
1634
  details: { runId }
@@ -1701,7 +1719,7 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
1701
1719
  } catch (error$1) {
1702
1720
  throw new error.MastraError(
1703
1721
  {
1704
- id: "CLICKHOUSE_STORAGE_GET_SCORES_BY_SCORER_ID_FAILED",
1722
+ id: storage.createStorageErrorId("CLICKHOUSE", "LIST_SCORES_BY_SCORER_ID", "FAILED"),
1705
1723
  domain: error.ErrorDomain.STORAGE,
1706
1724
  category: error.ErrorCategory.THIRD_PARTY,
1707
1725
  details: { scorerId }
@@ -1773,7 +1791,7 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
1773
1791
  } catch (error$1) {
1774
1792
  throw new error.MastraError(
1775
1793
  {
1776
- id: "CLICKHOUSE_STORAGE_GET_SCORES_BY_ENTITY_ID_FAILED",
1794
+ id: storage.createStorageErrorId("CLICKHOUSE", "LIST_SCORES_BY_ENTITY_ID", "FAILED"),
1777
1795
  domain: error.ErrorDomain.STORAGE,
1778
1796
  category: error.ErrorCategory.THIRD_PARTY,
1779
1797
  details: { entityId, entityType }
@@ -1848,7 +1866,7 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
1848
1866
  } catch (error$1) {
1849
1867
  throw new error.MastraError(
1850
1868
  {
1851
- id: "CLICKHOUSE_STORAGE_GET_SCORES_BY_SPAN_FAILED",
1869
+ id: storage.createStorageErrorId("CLICKHOUSE", "LIST_SCORES_BY_SPAN", "FAILED"),
1852
1870
  domain: error.ErrorDomain.STORAGE,
1853
1871
  category: error.ErrorCategory.THIRD_PARTY,
1854
1872
  details: { traceId, spanId }
@@ -1873,14 +1891,24 @@ var WorkflowsStorageClickhouse = class extends storage.WorkflowsStorage {
1873
1891
  // result,
1874
1892
  // requestContext,
1875
1893
  }) {
1876
- throw new Error("Method not implemented.");
1894
+ throw new error.MastraError({
1895
+ id: storage.createStorageErrorId("CLICKHOUSE", "UPDATE_WORKFLOW_RESULTS", "NOT_IMPLEMENTED"),
1896
+ domain: error.ErrorDomain.STORAGE,
1897
+ category: error.ErrorCategory.SYSTEM,
1898
+ text: "Method not implemented."
1899
+ });
1877
1900
  }
1878
1901
  updateWorkflowState({
1879
1902
  // workflowName,
1880
1903
  // runId,
1881
1904
  // opts,
1882
1905
  }) {
1883
- throw new Error("Method not implemented.");
1906
+ throw new error.MastraError({
1907
+ id: storage.createStorageErrorId("CLICKHOUSE", "UPDATE_WORKFLOW_STATE", "NOT_IMPLEMENTED"),
1908
+ domain: error.ErrorDomain.STORAGE,
1909
+ category: error.ErrorCategory.SYSTEM,
1910
+ text: "Method not implemented."
1911
+ });
1884
1912
  }
1885
1913
  async persistWorkflowSnapshot({
1886
1914
  workflowName,
@@ -1921,7 +1949,7 @@ var WorkflowsStorageClickhouse = class extends storage.WorkflowsStorage {
1921
1949
  } catch (error$1) {
1922
1950
  throw new error.MastraError(
1923
1951
  {
1924
- id: "CLICKHOUSE_STORAGE_PERSIST_WORKFLOW_SNAPSHOT_FAILED",
1952
+ id: storage.createStorageErrorId("CLICKHOUSE", "PERSIST_WORKFLOW_SNAPSHOT", "FAILED"),
1925
1953
  domain: error.ErrorDomain.STORAGE,
1926
1954
  category: error.ErrorCategory.THIRD_PARTY,
1927
1955
  details: { workflowName, runId }
@@ -1949,7 +1977,7 @@ var WorkflowsStorageClickhouse = class extends storage.WorkflowsStorage {
1949
1977
  } catch (error$1) {
1950
1978
  throw new error.MastraError(
1951
1979
  {
1952
- id: "CLICKHOUSE_STORAGE_LOAD_WORKFLOW_SNAPSHOT_FAILED",
1980
+ id: storage.createStorageErrorId("CLICKHOUSE", "LOAD_WORKFLOW_SNAPSHOT", "FAILED"),
1953
1981
  domain: error.ErrorDomain.STORAGE,
1954
1982
  category: error.ErrorCategory.THIRD_PARTY,
1955
1983
  details: { workflowName, runId }
@@ -2056,7 +2084,7 @@ var WorkflowsStorageClickhouse = class extends storage.WorkflowsStorage {
2056
2084
  } catch (error$1) {
2057
2085
  throw new error.MastraError(
2058
2086
  {
2059
- id: "CLICKHOUSE_STORAGE_LIST_WORKFLOW_RUNS_FAILED",
2087
+ id: storage.createStorageErrorId("CLICKHOUSE", "LIST_WORKFLOW_RUNS", "FAILED"),
2060
2088
  domain: error.ErrorDomain.STORAGE,
2061
2089
  category: error.ErrorCategory.THIRD_PARTY,
2062
2090
  details: { workflowName: workflowName ?? "", resourceId: resourceId ?? "" }
@@ -2105,7 +2133,7 @@ var WorkflowsStorageClickhouse = class extends storage.WorkflowsStorage {
2105
2133
  } catch (error$1) {
2106
2134
  throw new error.MastraError(
2107
2135
  {
2108
- id: "CLICKHOUSE_STORAGE_GET_WORKFLOW_RUN_BY_ID_FAILED",
2136
+ id: storage.createStorageErrorId("CLICKHOUSE", "GET_WORKFLOW_RUN_BY_ID", "FAILED"),
2109
2137
  domain: error.ErrorDomain.STORAGE,
2110
2138
  category: error.ErrorCategory.THIRD_PARTY,
2111
2139
  details: { runId: runId ?? "", workflowName: workflowName ?? "" }
@@ -2122,7 +2150,7 @@ var ClickhouseStore = class extends storage.MastraStorage {
2122
2150
  ttl = {};
2123
2151
  stores;
2124
2152
  constructor(config) {
2125
- super({ id: config.id, name: "ClickhouseStore" });
2153
+ super({ id: config.id, name: "ClickhouseStore", disableInit: config.disableInit });
2126
2154
  this.db = client.createClient({
2127
2155
  url: config.url,
2128
2156
  username: config.username,
@@ -2168,7 +2196,7 @@ var ClickhouseStore = class extends storage.MastraStorage {
2168
2196
  } catch (error$1) {
2169
2197
  throw new error.MastraError(
2170
2198
  {
2171
- id: "CLICKHOUSE_STORAGE_OPTIMIZE_TABLE_FAILED",
2199
+ id: storage.createStorageErrorId("CLICKHOUSE", "OPTIMIZE_TABLE", "FAILED"),
2172
2200
  domain: error.ErrorDomain.STORAGE,
2173
2201
  category: error.ErrorCategory.THIRD_PARTY,
2174
2202
  details: { tableName }
@@ -2185,7 +2213,7 @@ var ClickhouseStore = class extends storage.MastraStorage {
2185
2213
  } catch (error$1) {
2186
2214
  throw new error.MastraError(
2187
2215
  {
2188
- id: "CLICKHOUSE_STORAGE_MATERIALIZE_TTL_FAILED",
2216
+ id: storage.createStorageErrorId("CLICKHOUSE", "MATERIALIZE_TTL", "FAILED"),
2189
2217
  domain: error.ErrorDomain.STORAGE,
2190
2218
  category: error.ErrorCategory.THIRD_PARTY,
2191
2219
  details: { tableName }