@mastra/clickhouse 1.11.0-alpha.0 → 1.11.1-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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # @mastra/clickhouse
2
2
 
3
+ ## 1.11.1-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Added optional `organizationId` and `projectId` fields to scores for multi-tenant isolation. Scores can now be saved with tenancy metadata and the `listScoresBy*` methods accept a `filters` option to scope results by organization and project. ([#18331](https://github.com/mastra-ai/mastra/pull/18331))
8
+
9
+ ```ts
10
+ await storage.saveScore({ ...score, organizationId: 'org-a', projectId: 'proj-1' });
11
+
12
+ const result = await storage.listScoresByScorerId({
13
+ scorerId,
14
+ filters: { organizationId: 'org-a', projectId: 'proj-1' },
15
+ });
16
+ ```
17
+
18
+ `projectId` identifies the project scope, separate from `resourceId` which continues to mean the agent memory resource.
19
+
20
+ - Updated dependencies [[`9250acd`](https://github.com/mastra-ai/mastra/commit/9250acd1357f0f1f33d0dcca16f9655084c58eca), [`215f9b0`](https://github.com/mastra-ai/mastra/commit/215f9b0f3f3f6fc165edad360582dd4d3d7ea748), [`c64c2a8`](https://github.com/mastra-ai/mastra/commit/c64c2a8503a50252f9ca6b8e8c54cadee31b92a2), [`06e2680`](https://github.com/mastra-ai/mastra/commit/06e26806b51d2cbd858afdc66daa2b86ff3ba64a), [`1240f05`](https://github.com/mastra-ai/mastra/commit/1240f051c8e5371f1c014448bf37b1a1b9a05e47), [`215f9b0`](https://github.com/mastra-ai/mastra/commit/215f9b0f3f3f6fc165edad360582dd4d3d7ea748), [`24c10d3`](https://github.com/mastra-ai/mastra/commit/24c10d333e6649ac06075903aeeee13a933db3b3), [`24c10d3`](https://github.com/mastra-ai/mastra/commit/24c10d333e6649ac06075903aeeee13a933db3b3), [`24c10d3`](https://github.com/mastra-ai/mastra/commit/24c10d333e6649ac06075903aeeee13a933db3b3), [`24c10d3`](https://github.com/mastra-ai/mastra/commit/24c10d333e6649ac06075903aeeee13a933db3b3), [`215f9b0`](https://github.com/mastra-ai/mastra/commit/215f9b0f3f3f6fc165edad360582dd4d3d7ea748), [`215f9b0`](https://github.com/mastra-ai/mastra/commit/215f9b0f3f3f6fc165edad360582dd4d3d7ea748)]:
21
+ - @mastra/core@1.49.0-alpha.5
22
+
23
+ ## 1.11.0
24
+
25
+ ### Minor Changes
26
+
27
+ - Random bump ([#18178](https://github.com/mastra-ai/mastra/pull/18178))
28
+
29
+ ### Patch Changes
30
+
31
+ - Updated dependencies [[`7c0d868`](https://github.com/mastra-ai/mastra/commit/7c0d868d97d0fdbc04c14d0166dbf44d4c5a4a62), [`d9d2273`](https://github.com/mastra-ai/mastra/commit/d9d2273c702690c9a26eab2aebea879701d4355a), [`b04369d`](https://github.com/mastra-ai/mastra/commit/b04369d6b167c698ef103981171a8bf92808e756), [`8f3c262`](https://github.com/mastra-ai/mastra/commit/8f3c262587b335588a02d96b17fd6aca34c885b3)]:
32
+ - @mastra/core@1.45.0
33
+
3
34
  ## 1.11.0-alpha.0
4
35
 
5
36
  ### Minor Changes
@@ -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.11.0-alpha.0"
6
+ version: "1.11.1-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.11.0-alpha.0",
2
+ "version": "1.11.1-alpha.0",
3
3
  "package": "@mastra/clickhouse",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # ClickHouse storage
2
4
 
3
5
  [ClickHouse](https://clickhouse.com/) is a columnar database designed for analytical workloads. The `@mastra/clickhouse` package provides storage adapters for several Mastra storage domains and is the recommended backend for production observability.
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Composite storage
2
4
 
3
5
  `MastraCompositeStore` can compose storage domains from different providers. Use it when you need different databases for different purposes. For example, use LibSQL for memory and PostgreSQL for workflows.
package/dist/index.cjs CHANGED
@@ -8107,6 +8107,19 @@ var ObservabilityStorageClickhouseVNext = class extends storage.ObservabilitySto
8107
8107
  }
8108
8108
  }
8109
8109
  };
8110
+ function buildTenancyFilter(filters) {
8111
+ const clauses = [];
8112
+ const params = {};
8113
+ if (filters?.organizationId !== void 0) {
8114
+ clauses.push("organizationId = {var_organizationId:String}");
8115
+ params.var_organizationId = filters.organizationId;
8116
+ }
8117
+ if (filters?.projectId !== void 0) {
8118
+ clauses.push("projectId = {var_projectId:String}");
8119
+ params.var_projectId = filters.projectId;
8120
+ }
8121
+ return { sql: clauses.length > 0 ? ` AND ${clauses.join(" AND ")}` : "", params };
8122
+ }
8110
8123
  var ScoresStorageClickhouse = class extends storage.ScoresStorage {
8111
8124
  client;
8112
8125
  #db;
@@ -8227,12 +8240,14 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
8227
8240
  }
8228
8241
  async listScoresByRunId({
8229
8242
  runId,
8230
- pagination
8243
+ pagination,
8244
+ filters
8231
8245
  }) {
8246
+ const tenancy = buildTenancyFilter(filters);
8232
8247
  try {
8233
8248
  const countResult = await this.client.query({
8234
- query: `SELECT COUNT(*) as count FROM ${storage.TABLE_SCORERS} WHERE runId = {var_runId:String}`,
8235
- query_params: { var_runId: runId },
8249
+ query: `SELECT COUNT(*) as count FROM ${storage.TABLE_SCORERS} WHERE runId = {var_runId:String}${tenancy.sql}`,
8250
+ query_params: { var_runId: runId, ...tenancy.params },
8236
8251
  format: "JSONEachRow"
8237
8252
  });
8238
8253
  const countRows = await countResult.json();
@@ -8258,11 +8273,12 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
8258
8273
  const limitValue = perPageInput === false ? total : perPage;
8259
8274
  const end = perPageInput === false ? total : start + perPage;
8260
8275
  const result = await this.client.query({
8261
- query: `SELECT * FROM ${storage.TABLE_SCORERS} WHERE runId = {var_runId:String} ORDER BY createdAt DESC LIMIT {var_limit:Int64} OFFSET {var_offset:Int64}`,
8276
+ query: `SELECT * FROM ${storage.TABLE_SCORERS} WHERE runId = {var_runId:String}${tenancy.sql} ORDER BY createdAt DESC LIMIT {var_limit:Int64} OFFSET {var_offset:Int64}`,
8262
8277
  query_params: {
8263
8278
  var_runId: runId,
8264
8279
  var_limit: limitValue,
8265
- var_offset: start
8280
+ var_offset: start,
8281
+ ...tenancy.params
8266
8282
  },
8267
8283
  format: "JSONEachRow",
8268
8284
  clickhouse_settings: {
@@ -8300,8 +8316,10 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
8300
8316
  entityId,
8301
8317
  entityType,
8302
8318
  source,
8303
- pagination
8319
+ pagination,
8320
+ filters
8304
8321
  }) {
8322
+ const tenancy = buildTenancyFilter(filters);
8305
8323
  let whereClause = `scorerId = {var_scorerId:String}`;
8306
8324
  if (entityId) {
8307
8325
  whereClause += ` AND entityId = {var_entityId:String}`;
@@ -8312,6 +8330,7 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
8312
8330
  if (source) {
8313
8331
  whereClause += ` AND source = {var_source:String}`;
8314
8332
  }
8333
+ whereClause += tenancy.sql;
8315
8334
  try {
8316
8335
  const countResult = await this.client.query({
8317
8336
  query: `SELECT COUNT(*) as count FROM ${storage.TABLE_SCORERS} WHERE ${whereClause}`,
@@ -8319,7 +8338,8 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
8319
8338
  var_scorerId: scorerId,
8320
8339
  var_entityId: entityId,
8321
8340
  var_entityType: entityType,
8322
- var_source: source
8341
+ var_source: source,
8342
+ ...tenancy.params
8323
8343
  },
8324
8344
  format: "JSONEachRow"
8325
8345
  });
@@ -8353,7 +8373,8 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
8353
8373
  var_offset: start,
8354
8374
  var_entityId: entityId,
8355
8375
  var_entityType: entityType,
8356
- var_source: source
8376
+ var_source: source,
8377
+ ...tenancy.params
8357
8378
  },
8358
8379
  format: "JSONEachRow",
8359
8380
  clickhouse_settings: {
@@ -8389,12 +8410,14 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
8389
8410
  async listScoresByEntityId({
8390
8411
  entityId,
8391
8412
  entityType,
8392
- pagination
8413
+ pagination,
8414
+ filters
8393
8415
  }) {
8416
+ const tenancy = buildTenancyFilter(filters);
8394
8417
  try {
8395
8418
  const countResult = await this.client.query({
8396
- query: `SELECT COUNT(*) as count FROM ${storage.TABLE_SCORERS} WHERE entityId = {var_entityId:String} AND entityType = {var_entityType:String}`,
8397
- query_params: { var_entityId: entityId, var_entityType: entityType },
8419
+ query: `SELECT COUNT(*) as count FROM ${storage.TABLE_SCORERS} WHERE entityId = {var_entityId:String} AND entityType = {var_entityType:String}${tenancy.sql}`,
8420
+ query_params: { var_entityId: entityId, var_entityType: entityType, ...tenancy.params },
8398
8421
  format: "JSONEachRow"
8399
8422
  });
8400
8423
  const countRows = await countResult.json();
@@ -8420,12 +8443,13 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
8420
8443
  const limitValue = perPageInput === false ? total : perPage;
8421
8444
  const end = perPageInput === false ? total : start + perPage;
8422
8445
  const result = await this.client.query({
8423
- query: `SELECT * FROM ${storage.TABLE_SCORERS} WHERE entityId = {var_entityId:String} AND entityType = {var_entityType:String} ORDER BY createdAt DESC LIMIT {var_limit:Int64} OFFSET {var_offset:Int64}`,
8446
+ query: `SELECT * FROM ${storage.TABLE_SCORERS} WHERE entityId = {var_entityId:String} AND entityType = {var_entityType:String}${tenancy.sql} ORDER BY createdAt DESC LIMIT {var_limit:Int64} OFFSET {var_offset:Int64}`,
8424
8447
  query_params: {
8425
8448
  var_entityId: entityId,
8426
8449
  var_entityType: entityType,
8427
8450
  var_limit: limitValue,
8428
- var_offset: start
8451
+ var_offset: start,
8452
+ ...tenancy.params
8429
8453
  },
8430
8454
  format: "JSONEachRow",
8431
8455
  clickhouse_settings: {
@@ -8461,14 +8485,17 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
8461
8485
  async listScoresBySpan({
8462
8486
  traceId,
8463
8487
  spanId,
8464
- pagination
8488
+ pagination,
8489
+ filters
8465
8490
  }) {
8491
+ const tenancy = buildTenancyFilter(filters);
8466
8492
  try {
8467
8493
  const countResult = await this.client.query({
8468
- query: `SELECT COUNT(*) as count FROM ${storage.TABLE_SCORERS} WHERE traceId = {var_traceId:String} AND spanId = {var_spanId:String}`,
8494
+ query: `SELECT COUNT(*) as count FROM ${storage.TABLE_SCORERS} WHERE traceId = {var_traceId:String} AND spanId = {var_spanId:String}${tenancy.sql}`,
8469
8495
  query_params: {
8470
8496
  var_traceId: traceId,
8471
- var_spanId: spanId
8497
+ var_spanId: spanId,
8498
+ ...tenancy.params
8472
8499
  },
8473
8500
  format: "JSONEachRow"
8474
8501
  });
@@ -8495,12 +8522,13 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
8495
8522
  const limitValue = perPageInput === false ? total : perPage;
8496
8523
  const end = perPageInput === false ? total : start + perPage;
8497
8524
  const result = await this.client.query({
8498
- query: `SELECT * FROM ${storage.TABLE_SCORERS} WHERE traceId = {var_traceId:String} AND spanId = {var_spanId:String} ORDER BY createdAt DESC LIMIT {var_limit:Int64} OFFSET {var_offset:Int64}`,
8525
+ query: `SELECT * FROM ${storage.TABLE_SCORERS} WHERE traceId = {var_traceId:String} AND spanId = {var_spanId:String}${tenancy.sql} ORDER BY createdAt DESC LIMIT {var_limit:Int64} OFFSET {var_offset:Int64}`,
8499
8526
  query_params: {
8500
8527
  var_traceId: traceId,
8501
8528
  var_spanId: spanId,
8502
8529
  var_limit: limitValue,
8503
- var_offset: start
8530
+ var_offset: start,
8531
+ ...tenancy.params
8504
8532
  },
8505
8533
  format: "JSONEachRow",
8506
8534
  clickhouse_settings: {