@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.
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +26 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -19
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1587,6 +1587,7 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
1587
1587
|
metadataIndex++;
|
|
1588
1588
|
}
|
|
1589
1589
|
}
|
|
1590
|
+
const idScope = filter?.resourceId ? `WHERE id IN (SELECT id FROM ${TABLE_THREADS} WHERE resourceId = {resourceId:String})` : "";
|
|
1590
1591
|
const latestThreads = `
|
|
1591
1592
|
latest_threads AS (
|
|
1592
1593
|
SELECT
|
|
@@ -1597,7 +1598,7 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
1597
1598
|
toDateTime64(createdAt, 3) as createdAt,
|
|
1598
1599
|
toDateTime64(updatedAt, 3) as updatedAt
|
|
1599
1600
|
FROM ${TABLE_THREADS}
|
|
1600
|
-
${
|
|
1601
|
+
${idScope}
|
|
1601
1602
|
ORDER BY updatedAt DESC
|
|
1602
1603
|
LIMIT 1 BY id
|
|
1603
1604
|
)`;
|
|
@@ -2418,9 +2419,7 @@ var ObservabilityStorageClickhouse = class extends ObservabilityStorage {
|
|
|
2418
2419
|
case TraceStatus.RUNNING:
|
|
2419
2420
|
conditions.push(`endedAt IS NULL AND (error IS NULL OR error = '')`);
|
|
2420
2421
|
break;
|
|
2421
|
-
case TraceStatus.SUCCESS:
|
|
2422
|
-
conditions.push(`endedAt IS NOT NULL AND (error IS NULL OR error = '')`);
|
|
2423
|
-
break;
|
|
2422
|
+
case TraceStatus.SUCCESS: conditions.push(`endedAt IS NOT NULL AND (error IS NULL OR error = '')`);
|
|
2424
2423
|
}
|
|
2425
2424
|
if (filters.hasChildError !== void 0) {
|
|
2426
2425
|
const finalClause = (TABLE_ENGINES[TABLE_SPANS] ?? "MergeTree()").startsWith("ReplacingMergeTree") ? "FINAL" : "";
|
|
@@ -5261,7 +5260,8 @@ async function getFeedbackAggregate(client, args) {
|
|
|
5261
5260
|
const aggSql = getAggregationSql$2(args.aggregation);
|
|
5262
5261
|
const identity = buildFeedbackIdentityFilter(args);
|
|
5263
5262
|
const combined = mergeFilters$2(identity, buildFeedbackFilterConditions(args.filters));
|
|
5264
|
-
const
|
|
5263
|
+
const whereClause = toWhereClause$2(combined);
|
|
5264
|
+
const result = await queryJson$2(client, `SELECT ${aggSql} AS value FROM ${TABLE_FEEDBACK_EVENTS} FINAL ${whereClause}`, combined.params);
|
|
5265
5265
|
const value = result[0]?.value == null ? null : Number(result[0]?.value);
|
|
5266
5266
|
if (args.comparePeriod && args.filters?.timestamp) {
|
|
5267
5267
|
const ts = args.filters.timestamp;
|
|
@@ -5295,7 +5295,8 @@ async function getFeedbackAggregate(client, args) {
|
|
|
5295
5295
|
endExclusive: ts.endExclusive
|
|
5296
5296
|
}
|
|
5297
5297
|
}));
|
|
5298
|
-
const
|
|
5298
|
+
const prevWhereClause = toWhereClause$2(prevCombined);
|
|
5299
|
+
const prevResult = await queryJson$2(client, `SELECT ${aggSql} AS value FROM ${TABLE_FEEDBACK_EVENTS} FINAL ${prevWhereClause}`, prevCombined.params);
|
|
5299
5300
|
const previousValue = prevResult[0]?.value == null ? null : Number(prevResult[0]?.value);
|
|
5300
5301
|
let changePercent = null;
|
|
5301
5302
|
if (previousValue !== null && previousValue !== 0 && value !== null) changePercent = (value - previousValue) / Math.abs(previousValue) * 100;
|
|
@@ -6202,8 +6203,10 @@ function buildLegacySpanSelectExprs(legacyColumnTypes) {
|
|
|
6202
6203
|
const promotedIn = PROMOTED_METADATA_KEYS.map((k) => `'${k}'`).join(", ");
|
|
6203
6204
|
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)')`;
|
|
6204
6205
|
let tagsExpr = "[]";
|
|
6205
|
-
if (has("tags"))
|
|
6206
|
-
|
|
6206
|
+
if (has("tags")) {
|
|
6207
|
+
if (legacyColumnTypes.get("tags").includes("Array")) tagsExpr = `arrayFilter(x -> x != '', arrayDistinct(arrayMap(x -> trim(BOTH ' ' FROM x), "tags")))`;
|
|
6208
|
+
else tagsExpr = `arrayFilter(x -> x != '', arrayDistinct(arrayMap(x -> trim(BOTH ' ' FROM x), JSONExtract(COALESCE("tags", '[]'), 'Array(String)'))))`;
|
|
6209
|
+
}
|
|
6207
6210
|
const exprs = {
|
|
6208
6211
|
dedupeKey: `concat("traceId", ':', "spanId")`,
|
|
6209
6212
|
traceId: `"traceId"`,
|
|
@@ -6450,10 +6453,11 @@ function toWhereClause(filter) {
|
|
|
6450
6453
|
return filter.conditions.length ? `WHERE ${filter.conditions.join(" AND ")}` : "";
|
|
6451
6454
|
}
|
|
6452
6455
|
function currentScoresRelation(sourcePredicate) {
|
|
6456
|
+
const whereClause = sourcePredicate ? `WHERE ${sourcePredicate}` : "";
|
|
6453
6457
|
return `(
|
|
6454
6458
|
SELECT *
|
|
6455
6459
|
FROM ${TABLE_SCORE_EVENTS_CURRENT} FINAL
|
|
6456
|
-
${
|
|
6460
|
+
${whereClause}
|
|
6457
6461
|
)`;
|
|
6458
6462
|
}
|
|
6459
6463
|
/**
|
|
@@ -8158,7 +8162,7 @@ async function querySpans(client, plan, timeoutMs) {
|
|
|
8158
8162
|
if (remaining <= 0) throw new coreStorage.TraceQueryExecutionError();
|
|
8159
8163
|
return await runWithClickHouseTraceQueryTimeout(client, {
|
|
8160
8164
|
timeoutMs: remaining,
|
|
8161
|
-
memoryLimitBytes:
|
|
8165
|
+
memoryLimitBytes: 536870912
|
|
8162
8166
|
}, compiled);
|
|
8163
8167
|
};
|
|
8164
8168
|
const selected = (await run(compileClickHouseSpanQuery(plan))).map((row) => ({
|
|
@@ -8275,14 +8279,14 @@ function afterCursor(plan, parameters) {
|
|
|
8275
8279
|
return `(${terms.join(" OR ")})`;
|
|
8276
8280
|
}
|
|
8277
8281
|
const THREAD_QUERY_EXECUTION_LIMITS = {
|
|
8278
|
-
memoryLimitBytes:
|
|
8282
|
+
memoryLimitBytes: 536870912,
|
|
8279
8283
|
maxThreads: 2,
|
|
8280
8284
|
maxBlockSize: 4096,
|
|
8281
|
-
spillThresholdBytes:
|
|
8285
|
+
spillThresholdBytes: 33554432
|
|
8282
8286
|
};
|
|
8283
8287
|
const MAX_CANDIDATE_THREADS = 16384;
|
|
8284
8288
|
const MAX_CANDIDATE_TRACES = 1e5;
|
|
8285
|
-
const MAX_CANDIDATE_ID_BYTES =
|
|
8289
|
+
const MAX_CANDIDATE_ID_BYTES = 4194304;
|
|
8286
8290
|
const MAX_FULL_HISTORY_ROOTS = 25e4;
|
|
8287
8291
|
function canUseThreadCandidates(probe) {
|
|
8288
8292
|
return Number(probe.threadCount) <= MAX_CANDIDATE_THREADS && Number(probe.traceCount) <= MAX_CANDIDATE_TRACES && Number(probe.threadBytes) + Number(probe.traceBytes) <= MAX_CANDIDATE_ID_BYTES;
|
|
@@ -8392,7 +8396,7 @@ function* batches(rows, maxRows = 256) {
|
|
|
8392
8396
|
let bytes = 0;
|
|
8393
8397
|
for (const row of rows) {
|
|
8394
8398
|
const size = Buffer.byteLength(JSON.stringify(row), "utf8") * 2;
|
|
8395
|
-
if (batch.length && (batch.length >= maxRows || bytes + size >
|
|
8399
|
+
if (batch.length && (batch.length >= maxRows || bytes + size > 49152)) {
|
|
8396
8400
|
yield batch;
|
|
8397
8401
|
batch = [];
|
|
8398
8402
|
bytes = 0;
|
|
@@ -9962,7 +9966,7 @@ async function detectExistingDeltaCursorStrategy(client) {
|
|
|
9962
9966
|
}
|
|
9963
9967
|
}
|
|
9964
9968
|
const TRACE_QUERY_DISCOVERY_DEFAULT_TIMEOUT_MS = 5e3;
|
|
9965
|
-
const TRACE_QUERY_DISCOVERY_DEFAULT_MEMORY_LIMIT_BYTES =
|
|
9969
|
+
const TRACE_QUERY_DISCOVERY_DEFAULT_MEMORY_LIMIT_BYTES = 268435456;
|
|
9966
9970
|
function resolveTraceQueryDiscoveryMemoryLimitBytes(memoryLimitBytes = TRACE_QUERY_DISCOVERY_DEFAULT_MEMORY_LIMIT_BYTES) {
|
|
9967
9971
|
if (!Number.isSafeInteger(memoryLimitBytes) || memoryLimitBytes <= 0) throw new RangeError("traceQuery.discovery.memoryLimitBytes must be a positive safe integer");
|
|
9968
9972
|
return memoryLimitBytes;
|
|
@@ -11355,10 +11359,12 @@ var WorkflowsStorageClickhouse = class extends WorkflowsStorage {
|
|
|
11355
11359
|
conditions.push(`JSONExtractString(snapshot, 'status') = {var_status:String}`);
|
|
11356
11360
|
values.var_status = status;
|
|
11357
11361
|
}
|
|
11358
|
-
if (resourceId)
|
|
11359
|
-
|
|
11360
|
-
|
|
11361
|
-
|
|
11362
|
+
if (resourceId) {
|
|
11363
|
+
if (await this.#db.hasColumn(TABLE_WORKFLOW_SNAPSHOT, "resourceId")) {
|
|
11364
|
+
conditions.push(`resourceId = {var_resourceId:String}`);
|
|
11365
|
+
values.var_resourceId = resourceId;
|
|
11366
|
+
} else this.logger.warn(`[${TABLE_WORKFLOW_SNAPSHOT}] resourceId column not found. Skipping resourceId filter.`);
|
|
11367
|
+
}
|
|
11362
11368
|
if (fromDate) {
|
|
11363
11369
|
conditions.push(`createdAt >= {var_from_date:DateTime64(3)}`);
|
|
11364
11370
|
values.var_from_date = fromDate.getTime() / 1e3;
|