@mastra/clickhouse 1.22.0 → 1.22.1-alpha.1

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.22.0"
6
+ version: "1.22.1-alpha.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.22.0",
2
+ "version": "1.22.1-alpha.1",
3
3
  "package": "@mastra/clickhouse",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -27,7 +27,6 @@ let _mastra_core_storage = require("@mastra/core/storage");
27
27
  _mastra_core_storage = __toESM(_mastra_core_storage, 1);
28
28
  let _mastra_core_agent = require("@mastra/core/agent");
29
29
  let _mastra_core_base = require("@mastra/core/base");
30
- let crypto$1 = require("crypto");
31
30
  let _mastra_core_utils = require("@mastra/core/utils");
32
31
  let _mastra_core_features = require("@mastra/core/features");
33
32
  let zod_v4 = require("zod/v4");
@@ -3890,6 +3889,8 @@ function rowToLightSpanRecord(row) {
3890
3889
  entityType: nullableEntityType(row.entityType),
3891
3890
  entityId: nullableString(row.entityId),
3892
3891
  entityName: nullableString(row.entityName),
3892
+ threadId: nullableString(row.threadId),
3893
+ resourceId: nullableString(row.resourceId),
3893
3894
  error,
3894
3895
  status: (0, _mastra_core_storage.computeTraceStatus)({
3895
3896
  error,
@@ -4725,6 +4726,7 @@ function getAggregationSql$2(aggregation, measure = "valueNumber") {
4725
4726
  case "max": return `max(${measure})`;
4726
4727
  case "count": return `toFloat64(count(${measure}))`;
4727
4728
  case "last": return `argMax(${measure}, timestamp)`;
4729
+ case "count_distinct": return `toFloat64(uniq(${measure}))`;
4728
4730
  default: return `sum(${measure})`;
4729
4731
  }
4730
4732
  }
@@ -4838,7 +4840,7 @@ async function batchCreateFeedback(client, args) {
4838
4840
  async function deleteFeedback(client, args, replication) {
4839
4841
  if (args.feedbackIds.length === 0) return;
4840
4842
  const request = await recordDeletionRequest(client, {
4841
- requestId: (0, crypto$1.randomUUID)(),
4843
+ requestId: globalThis.crypto.randomUUID(),
4842
4844
  organizationId: args.organizationId,
4843
4845
  resourceId: args.resourceId,
4844
4846
  signal: "feedback",
@@ -6178,6 +6180,7 @@ function getAggregationSql(aggregation, measure = "score") {
6178
6180
  case "max": return `max(${measure})`;
6179
6181
  case "count": return `toFloat64(count(${measure}))`;
6180
6182
  case "last": return `argMax(${measure}, timestamp)`;
6183
+ case "count_distinct": return `toFloat64(uniq(${measure}))`;
6181
6184
  default: return `sum(${measure})`;
6182
6185
  }
6183
6186
  }
@@ -6293,7 +6296,7 @@ async function batchCreateScores(client, args) {
6293
6296
  async function deleteScores(client, args, replication) {
6294
6297
  if (args.scoreIds.length === 0) return;
6295
6298
  const request = await recordDeletionRequest(client, {
6296
- requestId: (0, crypto$1.randomUUID)(),
6299
+ requestId: globalThis.crypto.randomUUID(),
6297
6300
  organizationId: args.organizationId,
6298
6301
  resourceId: args.resourceId,
6299
6302
  signal: "scores",
@@ -6435,7 +6438,7 @@ async function getScoreById(client, scoreId) {
6435
6438
  return rows[0] ? rowToScoreRecord(rows[0]) : null;
6436
6439
  }
6437
6440
  async function getScoreAggregate(client, args) {
6438
- const aggSql = getAggregationSql(args.aggregation);
6441
+ const aggSql = `if(count() = 0, NULL, ${getAggregationSql(args.aggregation)})`;
6439
6442
  const identity = buildScoreIdentityFilter(args);
6440
6443
  const combined = mergeFilters(identity, buildScoresFilterConditions(args.filters));
6441
6444
  const whereClause = toWhereClause(combined);
@@ -7468,6 +7471,8 @@ const LIGHT_TRACE_ROOT_FIELDS = [
7468
7471
  "entityType",
7469
7472
  "entityId",
7470
7473
  "entityName",
7474
+ "threadId",
7475
+ "resourceId",
7471
7476
  "error",
7472
7477
  "metadataRaw",
7473
7478
  "input"
@@ -7667,17 +7672,6 @@ function buildTraceCursor(row) {
7667
7672
  }
7668
7673
  //#endregion
7669
7674
  //#region src/storage/domains/observability/v-next/tracing.ts
7670
- /**
7671
- * Tracing operations for ClickHouse v-next observability.
7672
- *
7673
- * Owns: batchCreateSpans, getSpan, getSpans, getTrace, getTraceLight,
7674
- * listBranches, batchDeleteTraces, dangerouslyClearSpanEvents.
7675
- * Delegates to trace-roots.ts: listTraces, getRootSpan.
7676
- *
7677
- * `listBranches` reads from the MV-fed `mastra_trace_branches` table (one row
7678
- * per branch anchor span). It lives here -- alongside the other read paths
7679
- * over the trace data -- since branches are conceptually a subset of traces.
7680
- */
7681
7675
  const BRANCH_SPAN_TYPE_SQL_LIST = _mastra_core_storage.BRANCH_SPAN_TYPES.map((t) => `'${t}'`).join(", ");
7682
7676
  /** Insert a single completed span. */
7683
7677
  async function createSpan(client, args) {
@@ -7844,7 +7838,7 @@ async function getTraceLight(client, args) {
7844
7838
  async function batchDeleteTraces(client, args, replication) {
7845
7839
  if (args.traceIds.length === 0) return;
7846
7840
  const request = await recordDeletionRequest(client, {
7847
- requestId: (0, crypto$1.randomUUID)(),
7841
+ requestId: globalThis.crypto.randomUUID(),
7848
7842
  organizationId: args.organizationId,
7849
7843
  resourceId: args.resourceId,
7850
7844
  signal: "traces",
@@ -8497,11 +8491,11 @@ async function detectDeltaCursorStrategy(client, override, existingStrategy) {
8497
8491
  if (override) return override;
8498
8492
  if (existingStrategy && existingStrategy !== "mixed") return existingStrategy;
8499
8493
  try {
8500
- await client.query({
8494
+ await (await client.query({
8501
8495
  query: `SELECT generateSerialID({counterName:String}) AS cursorId`,
8502
8496
  query_params: { counterName: "mastra_observability_delta_cursor_probe" },
8503
8497
  format: "JSONEachRow"
8504
- });
8498
+ })).json();
8505
8499
  return "serial";
8506
8500
  } catch {
8507
8501
  return "fallback";
@@ -8605,11 +8599,11 @@ var ObservabilityStorageClickhouseVNext = class extends _mastra_core_storage.Obs
8605
8599
  if (this.#deltaCursorStrategy !== null) await reconcileScoreDeltaMv(this.#client, this.#replication, this.#deltaCursorStrategy, this.logger);
8606
8600
  await backfillCurrentScores(this.#client);
8607
8601
  if (this.#retention) await this.applyRetention();
8608
- if (this.#deltaCursorStrategy === "serial") for (const counterName of DELTA_CURSOR_COUNTER_NAMES) await this.#client.query({
8602
+ if (this.#deltaCursorStrategy === "serial") for (const counterName of DELTA_CURSOR_COUNTER_NAMES) await (await this.#client.query({
8609
8603
  query: `SELECT generateSerialID({counterName:String}) AS cursorId`,
8610
8604
  query_params: { counterName },
8611
8605
  format: "JSONEachRow"
8612
- });
8606
+ })).json();
8613
8607
  } catch (error) {
8614
8608
  if (error instanceof _mastra_core_error.MastraError) throw error;
8615
8609
  const causeMessage = error instanceof Error ? error.message : String(error);