@mastra/clickhouse 1.15.1 → 1.15.2
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 +22 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +19 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +20 -24
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/db/replication.d.ts +0 -5
- package/dist/storage/db/replication.d.ts.map +1 -1
- package/dist/storage/db/utils.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/index.d.ts +1 -1
- package/dist/storage/domains/observability/v-next/index.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createClient } from "@clickhouse/client";
|
|
2
2
|
import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
|
|
3
|
-
import { BRANCH_SPAN_TYPES, BackgroundTasksStorage, EntityType, METRIC_DISTINCT_COLUMNS, MastraCompositeStore, MemoryStorage, ObservabilityStorage, SCORERS_SCHEMA, SPAN_SCHEMA, ScoresStorage, TABLE_AGENT_VERSIONS, TABLE_BACKGROUND_TASKS, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, TABLE_FAVORITES, TABLE_HARNESS_SESSIONS, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, TABLE_MESSAGES, TABLE_NOTIFICATIONS, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, TABLE_RESOURCES, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, TABLE_SCHEMAS, TABLE_SCORERS, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, TABLE_SKILLS, TABLE_SKILL_BLOBS, TABLE_SKILL_VERSIONS, TABLE_SPANS, TABLE_THREADS, TABLE_THREAD_STATE, TABLE_TOOL_PROVIDER_CONNECTIONS, TABLE_TRACES, TABLE_WORKFLOW_DEFINITIONS, TABLE_WORKFLOW_SNAPSHOT, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, TraceStatus, WorkflowsStorage, buildInputPreview, calculatePagination, computeTraceStatus, createStorageErrorId, getDefaultValue, getSqlType, listBranchesArgsSchema, listFeedbackArgsSchema, listLogsArgsSchema, listMetricsArgsSchema, listScoresArgsSchema, listTracesArgsSchema, normalizePerPage, safelyParseJSON, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
|
|
3
|
+
import { BRANCH_SPAN_TYPES, BackgroundTasksStorage, EntityType, METRIC_DISTINCT_COLUMNS, MastraCompositeStore, MemoryStorage, ObservabilityStorage, SCORERS_SCHEMA, SPAN_SCHEMA, ScoresStorage, TABLE_AGENT_VERSIONS, TABLE_BACKGROUND_TASKS, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, TABLE_FAVORITES, TABLE_HARNESS_SESSIONS, TABLE_KNOWLEDGE_ACTIVITY, TABLE_KNOWLEDGE_CURSORS, TABLE_KNOWLEDGE_MENTIONS, TABLE_KNOWLEDGE_NODES, TABLE_KNOWLEDGE_RECORDS, TABLE_KNOWLEDGE_SEMANTIC_OUTBOX, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, TABLE_MESSAGES, TABLE_NOTIFICATIONS, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, TABLE_RESOURCES, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, TABLE_SCHEMAS, TABLE_SCORERS, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, TABLE_SKILLS, TABLE_SKILL_BLOBS, TABLE_SKILL_VERSIONS, TABLE_SPANS, TABLE_THREADS, TABLE_THREAD_STATE, TABLE_TOOL_PROVIDER_CONNECTIONS, TABLE_TRACES, TABLE_WORKFLOW_DEFINITIONS, TABLE_WORKFLOW_SNAPSHOT, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, TraceStatus, WorkflowsStorage, buildInputPreview, calculatePagination, computeTraceStatus, createStorageErrorId, getDefaultValue, getSqlType, listBranchesArgsSchema, listFeedbackArgsSchema, listLogsArgsSchema, listMetricsArgsSchema, listScoresArgsSchema, listTracesArgsSchema, normalizePerPage, safelyParseJSON, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
|
|
4
4
|
import { MastraBase } from "@mastra/core/base";
|
|
5
5
|
import { MessageList } from "@mastra/core/agent";
|
|
6
6
|
import { parseFieldKey } from "@mastra/core/utils";
|
|
@@ -165,17 +165,6 @@ function rewriteEngineClauses(sql, replication) {
|
|
|
165
165
|
function applyReplicationToDDL(sql, replication) {
|
|
166
166
|
return addOnClusterToDDL(replication ? rewriteEngineClauses(sql, replication) : sql, replication);
|
|
167
167
|
}
|
|
168
|
-
function buildLocalTableReplicationError(tables) {
|
|
169
|
-
const tableList = tables.map((table) => ` - ${table.name} (${table.engine})`).join("\n");
|
|
170
|
-
return new MastraError({
|
|
171
|
-
id: createStorageErrorId("CLICKHOUSE", "REPLICATION", "LOCAL_TABLES_UNSUPPORTED"),
|
|
172
|
-
domain: ErrorDomain.STORAGE,
|
|
173
|
-
category: ErrorCategory.USER,
|
|
174
|
-
text: `ClickHouse replication is enabled, but existing Mastra tables use non-replicated local engines.
|
|
175
|
-
Mastra will not automatically convert existing local tables to replicated tables.
|
|
176
|
-
Please migrate or recreate these tables manually before enabling replication:\n${tableList}`
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
168
|
//#endregion
|
|
180
169
|
//#region src/storage/db/utils.ts
|
|
181
170
|
const TABLE_ENGINES = {
|
|
@@ -216,7 +205,13 @@ const TABLE_ENGINES = {
|
|
|
216
205
|
mastra_channel_installations: `ReplacingMergeTree()`,
|
|
217
206
|
mastra_channel_config: `ReplacingMergeTree()`,
|
|
218
207
|
[TABLE_THREAD_STATE]: `ReplacingMergeTree()`,
|
|
219
|
-
[TABLE_WORKFLOW_DEFINITIONS]: `ReplacingMergeTree()
|
|
208
|
+
[TABLE_WORKFLOW_DEFINITIONS]: `ReplacingMergeTree()`,
|
|
209
|
+
[TABLE_KNOWLEDGE_NODES]: `ReplacingMergeTree()`,
|
|
210
|
+
[TABLE_KNOWLEDGE_RECORDS]: `ReplacingMergeTree()`,
|
|
211
|
+
[TABLE_KNOWLEDGE_MENTIONS]: `ReplacingMergeTree()`,
|
|
212
|
+
[TABLE_KNOWLEDGE_CURSORS]: `ReplacingMergeTree()`,
|
|
213
|
+
[TABLE_KNOWLEDGE_ACTIVITY]: `ReplacingMergeTree()`,
|
|
214
|
+
[TABLE_KNOWLEDGE_SEMANTIC_OUTBOX]: `ReplacingMergeTree()`
|
|
220
215
|
};
|
|
221
216
|
const COLUMN_TYPES = {
|
|
222
217
|
text: "String",
|
|
@@ -350,12 +345,12 @@ var ClickhouseDB = class extends MastraBase {
|
|
|
350
345
|
}
|
|
351
346
|
async assertExistingTableCompatibleWithReplication(tableName) {
|
|
352
347
|
if (!isReplicationConfigured(this.replication)) return;
|
|
353
|
-
const
|
|
348
|
+
const localTable = (await (await this.client.query({
|
|
354
349
|
query: `SELECT name, engine FROM system.tables WHERE database = currentDatabase() AND name = {tableName:String}`,
|
|
355
350
|
query_params: { tableName },
|
|
356
351
|
format: "JSONEachRow"
|
|
357
|
-
})).json()).
|
|
358
|
-
if (
|
|
352
|
+
})).json()).find((row) => row.engine && !isReplicatedOrSharedEngine(row.engine));
|
|
353
|
+
if (localTable) this.logger.warn(`ClickHouse replication is enabled, but pre-existing table '${localTable.name}' uses local engine '${localTable.engine}'. CREATE TABLE IF NOT EXISTS will leave the existing table untouched.`);
|
|
359
354
|
}
|
|
360
355
|
/**
|
|
361
356
|
* Gets the sorting key (ORDER BY columns) for a table.
|
|
@@ -7031,17 +7026,14 @@ async function filterAppliedRetention(client, entries) {
|
|
|
7031
7026
|
* Silently returns if `system.tables` can't be queried — the rest of init
|
|
7032
7027
|
* will still run and leave any existing tables untouched.
|
|
7033
7028
|
*/
|
|
7034
|
-
async function assertExistingTablesCompatibleWithReplication(client, replication) {
|
|
7029
|
+
async function assertExistingTablesCompatibleWithReplication(client, replication, logger) {
|
|
7035
7030
|
if (!isReplicationConfigured(replication)) return;
|
|
7036
7031
|
const localTable = (await (await client.query({
|
|
7037
7032
|
query: `SELECT name, engine FROM system.tables WHERE database = currentDatabase() AND name IN ({tables:Array(String)})`,
|
|
7038
7033
|
query_params: { tables: [...ALL_TABLE_NAMES] },
|
|
7039
7034
|
format: "JSONEachRow"
|
|
7040
7035
|
})).json()).find((row) => !isReplicatedOrSharedEngine(row.engine));
|
|
7041
|
-
if (localTable)
|
|
7042
|
-
name: localTable.name,
|
|
7043
|
-
engine: localTable.engine
|
|
7044
|
-
}]);
|
|
7036
|
+
if (localTable) logger.warn(`ClickHouse replication is enabled, but pre-existing observability table '${localTable.name}' uses local engine '${localTable.engine}'. CREATE TABLE IF NOT EXISTS will leave existing tables untouched.`);
|
|
7045
7037
|
}
|
|
7046
7038
|
async function reconcileDiscoveryTables(client, replication) {
|
|
7047
7039
|
let engines;
|
|
@@ -7160,7 +7152,7 @@ var ObservabilityStorageClickhouseVNext = class extends ObservabilityStorage {
|
|
|
7160
7152
|
if ((await checkLegacySpanMigrationStatus(this.#client)).needsMigration) this.logger?.warn?.("Legacy span table 'mastra_ai_spans' detected. Run 'npx mastra migrate' to migrate historical spans to the v-next schema.");
|
|
7161
7153
|
} catch {}
|
|
7162
7154
|
try {
|
|
7163
|
-
await assertExistingTablesCompatibleWithReplication(this.#client, this.#replication);
|
|
7155
|
+
await assertExistingTablesCompatibleWithReplication(this.#client, this.#replication, this.logger);
|
|
7164
7156
|
const existingStrategy = await detectExistingDeltaCursorStrategy(this.#client);
|
|
7165
7157
|
if (existingStrategy === "mixed") {
|
|
7166
7158
|
this.#deltaCursorStrategy = null;
|
|
@@ -7244,8 +7236,12 @@ var ObservabilityStorageClickhouseVNext = class extends ObservabilityStorage {
|
|
|
7244
7236
|
};
|
|
7245
7237
|
}
|
|
7246
7238
|
getFeatures() {
|
|
7247
|
-
if (!deltaPollingSupported(this.#deltaCursorStrategy)) return;
|
|
7248
|
-
return [
|
|
7239
|
+
if (!deltaPollingSupported(this.#deltaCursorStrategy)) return ["metrics", "logs"];
|
|
7240
|
+
return [
|
|
7241
|
+
"metrics",
|
|
7242
|
+
"logs",
|
|
7243
|
+
"delta-polling"
|
|
7244
|
+
];
|
|
7249
7245
|
}
|
|
7250
7246
|
async createSpan(args) {
|
|
7251
7247
|
try {
|