@mastra/clickhouse 1.24.0-alpha.1 → 1.25.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.24.0-alpha.1"
6
+ version: "1.25.0-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.24.0-alpha.1",
2
+ "version": "1.25.0-alpha.0",
3
3
  "package": "@mastra/clickhouse",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -232,6 +232,19 @@ The same `client` form is accepted by `ObservabilityStorageClickhouse` and `Obse
232
232
 
233
233
  `ClickhouseStore` also accepts every option from `ClickHouseClientConfigOptions` (such as `database`, `request_timeout`, `compression`, `keep_alive`, and `max_open_connections`).
234
234
 
235
+ `ClickhouseStore` and `ObservabilityStorageClickhouseVNext` apply `clickhouse_settings` to every query they run. On ClickHouse services that keep data in object storage, such as ClickHouse Cloud, limiting read-ahead lowers the memory each observability query uses, but queries that miss the local cache can run slower:
236
+
237
+ ```typescript
238
+ const observabilityStore = new ObservabilityStorageClickhouseVNext({
239
+ url: process.env.CLICKHOUSE_URL!,
240
+ username: process.env.CLICKHOUSE_USERNAME!,
241
+ password: process.env.CLICKHOUSE_PASSWORD!,
242
+ clickhouse_settings: {
243
+ filesystem_prefetches_limit: 8,
244
+ },
245
+ })
246
+ ```
247
+
235
248
  ### Replicated clusters
236
249
 
237
250
  Use `replication` when Mastra writes to a multi-replica ClickHouse cluster through a load balancer.
@@ -210,6 +210,40 @@ export const mastra = new Mastra({
210
210
 
211
211
  **domains.experiments** (`ExperimentsStorage`): Storage for experiment runs and per-item experiment results.
212
212
 
213
+ **domains.workflowDefinitions** (`WorkflowDefinitionsStorage`): Storage for persisted workflow definitions.
214
+
215
+ **domains.promptBlocks** (`PromptBlocksStorage`): Storage for stored prompt blocks and their versions.
216
+
217
+ **domains.scorerDefinitions** (`ScorerDefinitionsStorage`): Storage for stored scorer definitions and their versions.
218
+
219
+ **domains.mcpClients** (`MCPClientsStorage`): Storage for stored MCP client configurations and their versions.
220
+
221
+ **domains.mcpServers** (`MCPServersStorage`): Storage for stored MCP server configurations and their versions.
222
+
223
+ **domains.workspaces** (`WorkspacesStorage`): Storage for stored workspace configurations and their versions.
224
+
225
+ **domains.skills** (`SkillsStorage`): Storage for stored skill definitions and their versions.
226
+
227
+ **domains.favorites** (`FavoritesStorage`): Storage for user favorites on stored entities.
228
+
229
+ **domains.blobs** (`BlobStore`): Content-addressable storage for file contents used by skill versioning.
230
+
231
+ **domains.backgroundTasks** (`BackgroundTasksStorage`): Storage for background task state.
232
+
233
+ **domains.schedules** (`SchedulesStorage`): Storage for schedules that the scheduler fires.
234
+
235
+ **domains.channels** (`ChannelsStorage`): Storage for channel installations and configuration.
236
+
237
+ **domains.harness** (`HarnessStorage`): Storage for harness sessions.
238
+
239
+ **domains.toolProviderConnections** (`ToolProviderConnectionsStorage`): Storage for authorized tool provider connections.
240
+
241
+ **domains.notifications** (`NotificationsStorage`): Storage for notifications and their delivery state.
242
+
243
+ **domains.threadState** (`ThreadStateStorage`): Storage for per-thread agent state, such as task lists and goals.
244
+
245
+ **domains.knowledge** (`KnowledgeStorage`): Storage for knowledge nodes and records. Experimental.
246
+
213
247
  ## Initialization
214
248
 
215
249
  `MastraCompositeStore` initializes each configured domain independently. When passed to the Mastra class, `init()` is called automatically:
@@ -95,29 +95,32 @@ Set the `retention` field on the store config.
95
95
 
96
96
  Each domain specifies its age-prunable tables and the timestamp column that anchors comparison, chosen so `maxAge` matches the meaning of the data. Append-only logs use creation time, live state uses last activity, and jobs or runs use completion time so in-flight work isn't pruned.
97
97
 
98
- | Domain | Table key | Anchor column | `maxAge` measures |
99
- | ----------------- | ------------------ | ---------------- | ---------------------------------------------------------------- |
100
- | `memory` | `threads` | `createdAt` | Thread age |
101
- | `memory` | `messages` | `createdAt` | Message age |
102
- | `memory` | `resources` | `createdAt` | Resource age |
103
- | `threadState` | `threadState` | `updatedAt` | Inactivity: state for still-active threads survives |
104
- | `observability` | `spans` | `startedAt` | Span age |
105
- | `observability` | `metrics` | `timestamp` | Metric event age (vNext only) |
106
- | `observability` | `logs` | `timestamp` | Log event age (vNext only) |
107
- | `observability` | `scores` | `timestamp` | Score event age (vNext only) |
108
- | `observability` | `feedback` | `timestamp` | Feedback event age (vNext only) |
109
- | `scores` | `scorers` | `createdAt` | Score record age |
110
- | `workflows` | `workflowSnapshot` | `updatedAt` | Inactivity, suspended or long-running workflows survive |
111
- | `backgroundTasks` | `backgroundTasks` | `completedAt` | Time since completion, in-flight tasks (`NULL`) are never pruned |
112
- | `experiments` | `experiments` | `completedAt` | Time since completion, running experiments are never pruned |
113
- | `notifications` | `notifications` | `createdAt` | Notification age |
114
- | `harness` | `sessions` | `createdAt` | Session record age |
115
- | `schedules` | `triggers` | `actual_fire_at` | Fire-history age (epoch-ms column) |
98
+ | Domain | Table key | Anchor column | `maxAge` measures |
99
+ | ----------------- | ------------------ | ---------------- | -------------------------------------------------------------------------------------------------------------------------------- |
100
+ | `memory` | `threads` | `createdAt` | Thread age |
101
+ | `memory` | `messages` | `createdAt` | Message age |
102
+ | `memory` | `resources` | `createdAt` | Resource age |
103
+ | `memory` | `runFences` | `retiredAt` | Time since the durable agent execution holding the fence settled. Fences of running executions (`NULL`) are never pruned |
104
+ | `threadState` | `threadState` | `updatedAt` | Inactivity: state for still-active threads survives |
105
+ | `observability` | `spans` | `startedAt` | Span age |
106
+ | `observability` | `metrics` | `timestamp` | Metric event age (vNext only) |
107
+ | `observability` | `logs` | `timestamp` | Log event age (vNext only) |
108
+ | `observability` | `scores` | `timestamp` | Score event age (vNext only) |
109
+ | `observability` | `feedback` | `timestamp` | Feedback event age (vNext only) |
110
+ | `scores` | `scorers` | `createdAt` | Score record age |
111
+ | `workflows` | `workflowSnapshot` | `updatedAt` | Inactivity, suspended or long-running workflows survive |
112
+ | `workflows` | `runOwnership` | `updatedAt` | Inactivity. A running durable agent execution renews its claim every 10 seconds, so keep `maxAge` well above its 30-second lease |
113
+ | `backgroundTasks` | `backgroundTasks` | `completedAt` | Time since completion, in-flight tasks (`NULL`) are never pruned |
114
+ | `experiments` | `experiments` | `completedAt` | Time since completion, running experiments are never pruned |
115
+ | `notifications` | `notifications` | `createdAt` | Notification age |
116
+ | `harness` | `sessions` | `createdAt` | Session record age |
117
+ | `schedules` | `triggers` | `actual_fire_at` | Fire-history age (epoch-ms column) |
116
118
 
117
119
  > **Note:**
118
120
  >
119
121
  > - The memory `observational_memory` table has no timestamp anchor, so it can't be age-pruned and isn't a valid retention key.
120
122
  > - Experiments prune as whole units: an aged experiment's result rows are deleted together with it (results cascade with their parent), so a run is never left partially deleted. Retention doesn't have a separate `results` key.
123
+ > - `runOwnership` and `runFences` hold the run fencing records of durable agents, one small record per run in each. If the `runOwnership` `maxAge` is too short, a running execution can lose its run, but an execution that lost a run still can't write. A fence is retired only when its execution settles, so the fence of a run that crashed and was never recovered is never pruned.
121
124
  > - For `schedules`, the growth table is the fire history (`schedule_triggers`, one row per fire): schedule definitions are config and aren't pruned.
122
125
  > - On PostgreSQL, timestamp anchors use the timezone-aware mirror columns (for example `createdAtZ`, `completedAtZ`).
123
126
  > - DuckDB observability stores append-only events for all five signals. Its `spans` policy uses the event `timestamp` column rather than `startedAt`.
package/dist/index.cjs CHANGED
@@ -360,6 +360,7 @@ function resolveClickhouseConfig(config) {
360
360
  username: config.username,
361
361
  password: config.password,
362
362
  clickhouse_settings: {
363
+ ...config.clickhouse_settings,
363
364
  date_time_input_format: "best_effort",
364
365
  date_time_output_format: "iso",
365
366
  use_client_time_zone: 1,
@@ -7106,18 +7107,14 @@ function compileClickHouseTraceScope(selection, relationCollections, parameters,
7106
7107
  const to = parameters.add(selection.timeRange.to, "DateTime64(3, 'UTC')");
7107
7108
  const tenant = compileTenantScope(scope, parameters);
7108
7109
  const ctes = [`current_roots AS (
7109
- SELECT * FROM (
7110
- SELECT *
7111
- FROM ${TABLE_TRACE_ROOTS}
7112
- WHERE traceId IN (
7113
- SELECT traceId
7114
- FROM ${TABLE_TRACE_ROOTS} r
7115
- WHERE startedAt >= ${from}
7116
- AND startedAt < ${to}${tenant}${seedConjuncts.map((conjunct) => `\n AND (${compilePredicate(conjunct, parameters)})`).join("")}
7117
- )
7118
- ORDER BY dedupeKey
7119
- LIMIT 1 BY dedupeKey
7120
- )
7110
+ SELECT *
7111
+ FROM ${TABLE_TRACE_ROOTS}
7112
+ WHERE traceId IN (
7113
+ SELECT traceId
7114
+ FROM ${TABLE_TRACE_ROOTS} r
7115
+ WHERE startedAt >= ${from}
7116
+ AND startedAt < ${to}${tenant}${seedConjuncts.map((conjunct) => `\n AND (${compilePredicate(conjunct, parameters)})`).join("")}
7117
+ )${tenant}
7121
7118
  ORDER BY traceId, dedupeKey
7122
7119
  LIMIT 1 BY traceId
7123
7120
  )`, `root_scope AS (