@mastra/clickhouse 1.17.0-alpha.1 → 1.18.0-alpha.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.17.0-alpha.1"
6
+ version: "1.18.0-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.17.0-alpha.1",
2
+ "version": "1.18.0-alpha.0",
3
3
  "package": "@mastra/clickhouse",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -6248,13 +6248,65 @@ const TRACE_FIELDS = {
6248
6248
  }
6249
6249
  };
6250
6250
  const SPAN_FIELDS = {
6251
+ name: {
6252
+ sql: "s.name",
6253
+ parameterType: "String"
6254
+ },
6251
6255
  spanType: {
6252
6256
  sql: "s.spanType",
6253
6257
  parameterType: "String"
6254
6258
  },
6259
+ model: {
6260
+ sql: "s.model",
6261
+ parameterType: "String"
6262
+ },
6263
+ provider: {
6264
+ sql: "s.provider",
6265
+ parameterType: "String"
6266
+ },
6267
+ startedAt: {
6268
+ sql: "s.startedAt",
6269
+ parameterType: "DateTime64(3, 'UTC')"
6270
+ },
6271
+ endedAt: {
6272
+ sql: "s.endedAt",
6273
+ parameterType: "DateTime64(3, 'UTC')"
6274
+ },
6275
+ durationMs: {
6276
+ sql: "s.durationMs",
6277
+ parameterType: "Float64"
6278
+ },
6279
+ status: {
6280
+ sql: "s.status",
6281
+ parameterType: "String"
6282
+ },
6255
6283
  error: {
6256
6284
  sql: "s.error",
6257
6285
  parameterType: "String"
6286
+ },
6287
+ entityType: {
6288
+ sql: "s.entityType",
6289
+ parameterType: "String"
6290
+ },
6291
+ entityId: {
6292
+ sql: "s.entityId",
6293
+ parameterType: "String"
6294
+ },
6295
+ entityName: {
6296
+ sql: "s.entityName",
6297
+ parameterType: "String"
6298
+ },
6299
+ entityVersionId: {
6300
+ sql: "s.entityVersionId",
6301
+ parameterType: "String"
6302
+ },
6303
+ parentEntityVersionId: {
6304
+ sql: "s.parentEntityVersionId",
6305
+ parameterType: "String"
6306
+ },
6307
+ rootEntityVersionId: {
6308
+ sql: "s.rootEntityVersionId",
6309
+ parameterType: "String"
6258
6310
  }
6259
6311
  };
6260
6312
  const SCORE_FIELDS = {
@@ -6262,9 +6314,37 @@ const SCORE_FIELDS = {
6262
6314
  sql: "s.scorerId",
6263
6315
  parameterType: "String"
6264
6316
  },
6317
+ scorerVersion: {
6318
+ sql: "s.scorerVersion",
6319
+ parameterType: "String"
6320
+ },
6321
+ scoreSource: {
6322
+ sql: "s.scoreSource",
6323
+ parameterType: "String"
6324
+ },
6265
6325
  score: {
6266
6326
  sql: "s.score",
6267
6327
  parameterType: "Float64"
6328
+ },
6329
+ timestamp: {
6330
+ sql: "s.timestamp",
6331
+ parameterType: "DateTime64(3, 'UTC')"
6332
+ },
6333
+ spanId: {
6334
+ sql: "s.spanId",
6335
+ parameterType: "String"
6336
+ },
6337
+ entityVersionId: {
6338
+ sql: "s.entityVersionId",
6339
+ parameterType: "String"
6340
+ },
6341
+ parentEntityVersionId: {
6342
+ sql: "s.parentEntityVersionId",
6343
+ parameterType: "String"
6344
+ },
6345
+ rootEntityVersionId: {
6346
+ sql: "s.rootEntityVersionId",
6347
+ parameterType: "String"
6268
6348
  }
6269
6349
  };
6270
6350
  const TRACE_SELECT = `
@@ -6296,10 +6376,20 @@ function resolveOrderField(field) {
6296
6376
  if (field === "startedAt" || field === "endedAt") return field;
6297
6377
  throw new Error(`Unsupported trusted trace-query field: ${field}`);
6298
6378
  }
6299
- function compileScalarPredicate(predicate, registry, parameters) {
6300
- if (predicate.type === "boolean") return predicate.args.map((arg) => `(${compileScalarPredicate(arg, registry, parameters)})`).join(predicate.operator === "and" ? " AND " : " OR ");
6301
- if (predicate.type === "not") return `NOT (${compileScalarPredicate(predicate.arg, registry, parameters)})`;
6302
- const field = fieldDefinition(registry, predicate.field);
6379
+ function isMetadataField(field) {
6380
+ return field.startsWith("metadata.");
6381
+ }
6382
+ function compileScalarPredicate(predicate, registry, parameters, allowMetadata = false) {
6383
+ if (predicate.type === "boolean") return predicate.args.map((arg) => `(${compileScalarPredicate(arg, registry, parameters, allowMetadata)})`).join(predicate.operator === "and" ? " AND " : " OR ");
6384
+ if (predicate.type === "not") return `NOT (${compileScalarPredicate(predicate.arg, registry, parameters, allowMetadata)})`;
6385
+ const field = isMetadataField(predicate.field) ? (() => {
6386
+ if (!allowMetadata) throw new Error(`Unsupported trusted trace-query field: ${predicate.field}`);
6387
+ const key = parameters.add(predicate.field.slice(9), "String");
6388
+ return {
6389
+ sql: `coalesce(if(mapContains(r.metadataSearch, ${key}), r.metadataSearch[${key}], NULL), nullIf(trim(JSONExtractString(r.metadataRaw, ${key})), ''))`,
6390
+ parameterType: "String"
6391
+ };
6392
+ })() : fieldDefinition(registry, predicate.field);
6303
6393
  if (predicate.type === "presence") return `${predicate.operator === "exists" ? "isNotNull" : "isNull"}(${field.sql})`;
6304
6394
  if (predicate.type === "membership") {
6305
6395
  const values = predicate.values.map((value) => parameters.add(value, field.parameterType)).join(", ");
@@ -6336,7 +6426,7 @@ function compilePredicate(predicate, parameters) {
6336
6426
  }
6337
6427
  if (predicate.type === "boolean") return predicate.args.map((arg) => `(${compilePredicate(arg, parameters)})`).join(predicate.operator === "and" ? " AND " : " OR ");
6338
6428
  if (predicate.type === "not") return `NOT (${compilePredicate(predicate.arg, parameters)})`;
6339
- return compileScalarPredicate(predicate, TRACE_FIELDS, parameters);
6429
+ return compileScalarPredicate(predicate, TRACE_FIELDS, parameters, true);
6340
6430
  }
6341
6431
  function compileClickHouseTraceQuery(plan) {
6342
6432
  const parameters = new ParameterBuilder();
@@ -6359,17 +6449,46 @@ function compileClickHouseTraceQuery(plan) {
6359
6449
  AND startedAt < ${to}
6360
6450
  )`];
6361
6451
  if (relationCollections.has("spans")) ctes.push(`current_spans AS (
6362
- SELECT traceId, spanType, error
6452
+ SELECT
6453
+ traceId,
6454
+ name,
6455
+ spanType,
6456
+ if(JSONType(attributes, 'model') = 'String', JSONExtractString(attributes, 'model'), NULL) AS model,
6457
+ if(JSONType(attributes, 'provider') = 'String', JSONExtractString(attributes, 'provider'), NULL) AS provider,
6458
+ startedAt,
6459
+ endedAt,
6460
+ dateDiff('millisecond', startedAt, endedAt) AS durationMs,
6461
+ if(isNotNull(error), 'error', 'success') AS status,
6462
+ error,
6463
+ entityType,
6464
+ entityId,
6465
+ entityName,
6466
+ entityVersionId,
6467
+ parentEntityVersionId,
6468
+ rootEntityVersionId
6363
6469
  FROM ${TABLE_SPAN_EVENTS}
6364
- WHERE traceId IN (SELECT traceId FROM root_scope)
6470
+ WHERE isNotNull(traceId)
6471
+ AND traceId IN (SELECT traceId FROM root_scope)
6365
6472
  ORDER BY dedupeKey
6366
6473
  LIMIT 1 BY dedupeKey
6367
6474
  )`);
6368
6475
  if (relationCollections.has("scores")) ctes.push(`current_scores AS (
6369
- SELECT traceId, scorerId, score
6476
+ SELECT
6477
+ traceId,
6478
+ spanId,
6479
+ timestamp,
6480
+ scorerId,
6481
+ scorerVersion,
6482
+ scoreSource,
6483
+ score,
6484
+ entityVersionId,
6485
+ parentEntityVersionId,
6486
+ rootEntityVersionId
6370
6487
  FROM ${TABLE_SCORE_EVENTS}
6371
6488
  WHERE isNotNull(traceId)
6372
6489
  AND traceId IN (SELECT traceId FROM root_scope)
6490
+ ORDER BY scoreId, timestamp DESC
6491
+ LIMIT 1 BY scoreId
6373
6492
  )`);
6374
6493
  const predicate = plan.where ? compilePredicate(plan.where, parameters) : "1";
6375
6494
  ctes.push(`candidates AS (