@mastra/clickhouse 1.26.0-alpha.5 → 1.26.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.
@@ -3,7 +3,7 @@ name: mastra-clickhouse
3
3
  description: Documentation for @mastra/clickhouse. Use when working with @mastra/clickhouse APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/clickhouse"
6
- version: "1.26.0-alpha.5"
6
+ version: "1.26.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.26.0-alpha.5",
2
+ "version": "1.26.0",
3
3
  "package": "@mastra/clickhouse",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
20
20
  value: mod,
21
21
  enumerable: true
22
22
  }) : target, mod));
@@ -1610,6 +1610,7 @@ var MemoryStorageClickhouse = class extends _mastra_core_storage.MemoryStorage {
1610
1610
  metadataIndex++;
1611
1611
  }
1612
1612
  }
1613
+ const idScope = filter?.resourceId ? `WHERE id IN (SELECT id FROM ${_mastra_core_storage.TABLE_THREADS} WHERE resourceId = {resourceId:String})` : "";
1613
1614
  const latestThreads = `
1614
1615
  latest_threads AS (
1615
1616
  SELECT
@@ -1620,7 +1621,7 @@ var MemoryStorageClickhouse = class extends _mastra_core_storage.MemoryStorage {
1620
1621
  toDateTime64(createdAt, 3) as createdAt,
1621
1622
  toDateTime64(updatedAt, 3) as updatedAt
1622
1623
  FROM ${_mastra_core_storage.TABLE_THREADS}
1623
- ${filter?.resourceId ? `WHERE id IN (SELECT id FROM ${_mastra_core_storage.TABLE_THREADS} WHERE resourceId = {resourceId:String})` : ""}
1624
+ ${idScope}
1624
1625
  ORDER BY updatedAt DESC
1625
1626
  LIMIT 1 BY id
1626
1627
  )`;
@@ -2441,9 +2442,7 @@ var ObservabilityStorageClickhouse = class extends _mastra_core_storage.Observab
2441
2442
  case _mastra_core_storage.TraceStatus.RUNNING:
2442
2443
  conditions.push(`endedAt IS NULL AND (error IS NULL OR error = '')`);
2443
2444
  break;
2444
- case _mastra_core_storage.TraceStatus.SUCCESS:
2445
- conditions.push(`endedAt IS NOT NULL AND (error IS NULL OR error = '')`);
2446
- break;
2445
+ case _mastra_core_storage.TraceStatus.SUCCESS: conditions.push(`endedAt IS NOT NULL AND (error IS NULL OR error = '')`);
2447
2446
  }
2448
2447
  if (filters.hasChildError !== void 0) {
2449
2448
  const finalClause = (TABLE_ENGINES[_mastra_core_storage.TABLE_SPANS] ?? "MergeTree()").startsWith("ReplacingMergeTree") ? "FINAL" : "";
@@ -5284,7 +5283,8 @@ async function getFeedbackAggregate(client, args) {
5284
5283
  const aggSql = getAggregationSql$2(args.aggregation);
5285
5284
  const identity = buildFeedbackIdentityFilter(args);
5286
5285
  const combined = mergeFilters$2(identity, buildFeedbackFilterConditions(args.filters));
5287
- const result = await queryJson$2(client, `SELECT ${aggSql} AS value FROM ${TABLE_FEEDBACK_EVENTS} FINAL ${toWhereClause$2(combined)}`, combined.params);
5286
+ const whereClause = toWhereClause$2(combined);
5287
+ const result = await queryJson$2(client, `SELECT ${aggSql} AS value FROM ${TABLE_FEEDBACK_EVENTS} FINAL ${whereClause}`, combined.params);
5288
5288
  const value = result[0]?.value == null ? null : Number(result[0]?.value);
5289
5289
  if (args.comparePeriod && args.filters?.timestamp) {
5290
5290
  const ts = args.filters.timestamp;
@@ -5318,7 +5318,8 @@ async function getFeedbackAggregate(client, args) {
5318
5318
  endExclusive: ts.endExclusive
5319
5319
  }
5320
5320
  }));
5321
- const prevResult = await queryJson$2(client, `SELECT ${aggSql} AS value FROM ${TABLE_FEEDBACK_EVENTS} FINAL ${toWhereClause$2(prevCombined)}`, prevCombined.params);
5321
+ const prevWhereClause = toWhereClause$2(prevCombined);
5322
+ const prevResult = await queryJson$2(client, `SELECT ${aggSql} AS value FROM ${TABLE_FEEDBACK_EVENTS} FINAL ${prevWhereClause}`, prevCombined.params);
5322
5323
  const previousValue = prevResult[0]?.value == null ? null : Number(prevResult[0]?.value);
5323
5324
  let changePercent = null;
5324
5325
  if (previousValue !== null && previousValue !== 0 && value !== null) changePercent = (value - previousValue) / Math.abs(previousValue) * 100;
@@ -6225,8 +6226,10 @@ function buildLegacySpanSelectExprs(legacyColumnTypes) {
6225
6226
  const promotedIn = PROMOTED_METADATA_KEYS.map((k) => `'${k}'`).join(", ");
6226
6227
  const metadataSearchExpr = has("metadata") ? `CAST(arrayFilter(x -> x.1 NOT IN (${promotedIn}) AND trim(BOTH ' ' FROM x.2) != '', arrayMap(x -> (x.1, trim(BOTH ' ' FROM x.2)), JSONExtractKeysAndValues(COALESCE("metadata", '{}'), 'String'))), 'Map(String, String)')` : `CAST(map(), 'Map(String, String)')`;
6227
6228
  let tagsExpr = "[]";
6228
- if (has("tags")) if (legacyColumnTypes.get("tags").includes("Array")) tagsExpr = `arrayFilter(x -> x != '', arrayDistinct(arrayMap(x -> trim(BOTH ' ' FROM x), "tags")))`;
6229
- else tagsExpr = `arrayFilter(x -> x != '', arrayDistinct(arrayMap(x -> trim(BOTH ' ' FROM x), JSONExtract(COALESCE("tags", '[]'), 'Array(String)'))))`;
6229
+ if (has("tags")) {
6230
+ if (legacyColumnTypes.get("tags").includes("Array")) tagsExpr = `arrayFilter(x -> x != '', arrayDistinct(arrayMap(x -> trim(BOTH ' ' FROM x), "tags")))`;
6231
+ else tagsExpr = `arrayFilter(x -> x != '', arrayDistinct(arrayMap(x -> trim(BOTH ' ' FROM x), JSONExtract(COALESCE("tags", '[]'), 'Array(String)'))))`;
6232
+ }
6230
6233
  const exprs = {
6231
6234
  dedupeKey: `concat("traceId", ':', "spanId")`,
6232
6235
  traceId: `"traceId"`,
@@ -6473,10 +6476,11 @@ function toWhereClause(filter) {
6473
6476
  return filter.conditions.length ? `WHERE ${filter.conditions.join(" AND ")}` : "";
6474
6477
  }
6475
6478
  function currentScoresRelation(sourcePredicate) {
6479
+ const whereClause = sourcePredicate ? `WHERE ${sourcePredicate}` : "";
6476
6480
  return `(
6477
6481
  SELECT *
6478
6482
  FROM ${TABLE_SCORE_EVENTS_CURRENT} FINAL
6479
- ${sourcePredicate ? `WHERE ${sourcePredicate}` : ""}
6483
+ ${whereClause}
6480
6484
  )`;
6481
6485
  }
6482
6486
  /**
@@ -8181,7 +8185,7 @@ async function querySpans(client, plan, timeoutMs) {
8181
8185
  if (remaining <= 0) throw new _mastra_core_storage.TraceQueryExecutionError();
8182
8186
  return await runWithClickHouseTraceQueryTimeout(client, {
8183
8187
  timeoutMs: remaining,
8184
- memoryLimitBytes: 512 * 1024 * 1024
8188
+ memoryLimitBytes: 536870912
8185
8189
  }, compiled);
8186
8190
  };
8187
8191
  const selected = (await run(compileClickHouseSpanQuery(plan))).map((row) => ({
@@ -8298,14 +8302,14 @@ function afterCursor(plan, parameters) {
8298
8302
  return `(${terms.join(" OR ")})`;
8299
8303
  }
8300
8304
  const THREAD_QUERY_EXECUTION_LIMITS = {
8301
- memoryLimitBytes: 512 * 1024 * 1024,
8305
+ memoryLimitBytes: 536870912,
8302
8306
  maxThreads: 2,
8303
8307
  maxBlockSize: 4096,
8304
- spillThresholdBytes: 32 * 1024 * 1024
8308
+ spillThresholdBytes: 33554432
8305
8309
  };
8306
8310
  const MAX_CANDIDATE_THREADS = 16384;
8307
8311
  const MAX_CANDIDATE_TRACES = 1e5;
8308
- const MAX_CANDIDATE_ID_BYTES = 4 * 1024 * 1024;
8312
+ const MAX_CANDIDATE_ID_BYTES = 4194304;
8309
8313
  const MAX_FULL_HISTORY_ROOTS = 25e4;
8310
8314
  function canUseThreadCandidates(probe) {
8311
8315
  return Number(probe.threadCount) <= MAX_CANDIDATE_THREADS && Number(probe.traceCount) <= MAX_CANDIDATE_TRACES && Number(probe.threadBytes) + Number(probe.traceBytes) <= MAX_CANDIDATE_ID_BYTES;
@@ -8415,7 +8419,7 @@ function* batches(rows, maxRows = 256) {
8415
8419
  let bytes = 0;
8416
8420
  for (const row of rows) {
8417
8421
  const size = Buffer.byteLength(JSON.stringify(row), "utf8") * 2;
8418
- if (batch.length && (batch.length >= maxRows || bytes + size > 48 * 1024)) {
8422
+ if (batch.length && (batch.length >= maxRows || bytes + size > 49152)) {
8419
8423
  yield batch;
8420
8424
  batch = [];
8421
8425
  bytes = 0;
@@ -9985,7 +9989,7 @@ async function detectExistingDeltaCursorStrategy(client) {
9985
9989
  }
9986
9990
  }
9987
9991
  const TRACE_QUERY_DISCOVERY_DEFAULT_TIMEOUT_MS = 5e3;
9988
- const TRACE_QUERY_DISCOVERY_DEFAULT_MEMORY_LIMIT_BYTES = 256 * 1024 * 1024;
9992
+ const TRACE_QUERY_DISCOVERY_DEFAULT_MEMORY_LIMIT_BYTES = 268435456;
9989
9993
  function resolveTraceQueryDiscoveryMemoryLimitBytes(memoryLimitBytes = TRACE_QUERY_DISCOVERY_DEFAULT_MEMORY_LIMIT_BYTES) {
9990
9994
  if (!Number.isSafeInteger(memoryLimitBytes) || memoryLimitBytes <= 0) throw new RangeError("traceQuery.discovery.memoryLimitBytes must be a positive safe integer");
9991
9995
  return memoryLimitBytes;
@@ -11378,10 +11382,12 @@ var WorkflowsStorageClickhouse = class extends _mastra_core_storage.WorkflowsSto
11378
11382
  conditions.push(`JSONExtractString(snapshot, 'status') = {var_status:String}`);
11379
11383
  values.var_status = status;
11380
11384
  }
11381
- if (resourceId) if (await this.#db.hasColumn(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT, "resourceId")) {
11382
- conditions.push(`resourceId = {var_resourceId:String}`);
11383
- values.var_resourceId = resourceId;
11384
- } else this.logger.warn(`[${_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT}] resourceId column not found. Skipping resourceId filter.`);
11385
+ if (resourceId) {
11386
+ if (await this.#db.hasColumn(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT, "resourceId")) {
11387
+ conditions.push(`resourceId = {var_resourceId:String}`);
11388
+ values.var_resourceId = resourceId;
11389
+ } else this.logger.warn(`[${_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT}] resourceId column not found. Skipping resourceId filter.`);
11390
+ }
11385
11391
  if (fromDate) {
11386
11392
  conditions.push(`createdAt >= {var_from_date:DateTime64(3)}`);
11387
11393
  values.var_from_date = fromDate.getTime() / 1e3;