@mastra/clickhouse 0.0.0-zod-v4-compat-part-2-20250822105954 → 0.0.0-zod-v4-stuff-20250825154219

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/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export * from './storage';
1
+ export * from './storage/index.js';
2
+ export { TABLE_ENGINES, COLUMN_TYPES } from './storage/domains/utils.js';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createClient } from '@clickhouse/client';
2
2
  import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
3
- import { MastraStorage, StoreOperations, TABLE_SCHEMAS, TABLE_WORKFLOW_SNAPSHOT, WorkflowsStorage, ScoresStorage, safelyParseJSON, TABLE_SCORERS, LegacyEvalsStorage, TABLE_EVALS, TracesStorage, TABLE_TRACES, MemoryStorage, resolveMessageLimit, TABLE_MESSAGES, TABLE_THREADS, TABLE_RESOURCES } from '@mastra/core/storage';
3
+ import { TABLE_RESOURCES, TABLE_SCORERS, TABLE_EVALS, TABLE_THREADS, TABLE_TRACES, TABLE_WORKFLOW_SNAPSHOT, TABLE_MESSAGES, MastraStorage, StoreOperations, TABLE_SCHEMAS, WorkflowsStorage, ScoresStorage, safelyParseJSON, LegacyEvalsStorage, TracesStorage, MemoryStorage, resolveMessageLimit } from '@mastra/core/storage';
4
4
  import { MessageList } from '@mastra/core/agent';
5
5
 
6
6
  // src/storage/index.ts
@@ -366,6 +366,62 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
366
366
  );
367
367
  }
368
368
  }
369
+ async getMessagesById({
370
+ messageIds,
371
+ format
372
+ }) {
373
+ if (messageIds.length === 0) return [];
374
+ try {
375
+ const result = await this.client.query({
376
+ query: `
377
+ SELECT
378
+ id,
379
+ content,
380
+ role,
381
+ type,
382
+ toDateTime64(createdAt, 3) as createdAt,
383
+ thread_id AS "threadId",
384
+ "resourceId"
385
+ FROM "${TABLE_MESSAGES}"
386
+ WHERE id IN {messageIds:Array(String)}
387
+ ORDER BY "createdAt" DESC
388
+ `,
389
+ query_params: {
390
+ messageIds
391
+ },
392
+ clickhouse_settings: {
393
+ // Allows to insert serialized JS Dates (such as '2023-12-06T10:54:48.000Z')
394
+ date_time_input_format: "best_effort",
395
+ date_time_output_format: "iso",
396
+ use_client_time_zone: 1,
397
+ output_format_json_quote_64bit_integers: 0
398
+ }
399
+ });
400
+ const rows = await result.json();
401
+ const messages = transformRows(rows.data);
402
+ messages.forEach((message) => {
403
+ if (typeof message.content === "string") {
404
+ try {
405
+ message.content = JSON.parse(message.content);
406
+ } catch {
407
+ }
408
+ }
409
+ });
410
+ const list = new MessageList().add(messages, "memory");
411
+ if (format === `v1`) return list.get.all.v1();
412
+ return list.get.all.v2();
413
+ } catch (error) {
414
+ throw new MastraError(
415
+ {
416
+ id: "CLICKHOUSE_STORAGE_GET_MESSAGES_BY_ID_FAILED",
417
+ domain: ErrorDomain.STORAGE,
418
+ category: ErrorCategory.THIRD_PARTY,
419
+ details: { messageIds: JSON.stringify(messageIds) }
420
+ },
421
+ error
422
+ );
423
+ }
424
+ }
369
425
  async saveMessages(args) {
370
426
  const { messages, format = "v1" } = args;
371
427
  if (messages.length === 0) return messages;
@@ -1611,7 +1667,7 @@ var StoreOperationsClickhouse = class extends StoreOperations {
1611
1667
  const hasUpdatedAt = TABLE_SCHEMAS[tableName]?.updatedAt;
1612
1668
  const selectClause = `SELECT *, toDateTime64(createdAt, 3) as createdAt${hasUpdatedAt ? ", toDateTime64(updatedAt, 3) as updatedAt" : ""}`;
1613
1669
  const result = await this.client.query({
1614
- query: `${selectClause} FROM ${tableName} ${engine.startsWith("ReplacingMergeTree") ? "FINAL" : ""} WHERE ${conditions}`,
1670
+ query: `${selectClause} FROM ${tableName} ${engine.startsWith("ReplacingMergeTree") ? "FINAL" : ""} WHERE ${conditions} ORDER BY createdAt DESC LIMIT 1`,
1615
1671
  query_params: values,
1616
1672
  clickhouse_settings: {
1617
1673
  // Allows to insert serialized JS Dates (such as '2023-12-06T10:54:48.000Z')
@@ -1660,7 +1716,7 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
1660
1716
  }
1661
1717
  transformScoreRow(row) {
1662
1718
  const scorer = safelyParseJSON(row.scorer);
1663
- const extractStepResult = safelyParseJSON(row.extractStepResult);
1719
+ const preprocessStepResult = safelyParseJSON(row.preprocessStepResult);
1664
1720
  const analyzeStepResult = safelyParseJSON(row.analyzeStepResult);
1665
1721
  const metadata = safelyParseJSON(row.metadata);
1666
1722
  const input = safelyParseJSON(row.input);
@@ -1671,7 +1727,7 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
1671
1727
  return {
1672
1728
  ...row,
1673
1729
  scorer,
1674
- extractStepResult,
1730
+ preprocessStepResult,
1675
1731
  analyzeStepResult,
1676
1732
  metadata,
1677
1733
  input,
@@ -1810,12 +1866,30 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
1810
1866
  }
1811
1867
  async getScoresByScorerId({
1812
1868
  scorerId,
1869
+ entityId,
1870
+ entityType,
1871
+ source,
1813
1872
  pagination
1814
1873
  }) {
1874
+ let whereClause = `scorerId = {var_scorerId:String}`;
1875
+ if (entityId) {
1876
+ whereClause += ` AND entityId = {var_entityId:String}`;
1877
+ }
1878
+ if (entityType) {
1879
+ whereClause += ` AND entityType = {var_entityType:String}`;
1880
+ }
1881
+ if (source) {
1882
+ whereClause += ` AND source = {var_source:String}`;
1883
+ }
1815
1884
  try {
1816
1885
  const countResult = await this.client.query({
1817
- query: `SELECT COUNT(*) as count FROM ${TABLE_SCORERS} WHERE scorerId = {var_scorerId:String}`,
1818
- query_params: { var_scorerId: scorerId },
1886
+ query: `SELECT COUNT(*) as count FROM ${TABLE_SCORERS} WHERE ${whereClause}`,
1887
+ query_params: {
1888
+ var_scorerId: scorerId,
1889
+ var_entityId: entityId,
1890
+ var_entityType: entityType,
1891
+ var_source: source
1892
+ },
1819
1893
  format: "JSONEachRow"
1820
1894
  });
1821
1895
  const countRows = await countResult.json();
@@ -1837,11 +1911,14 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
1837
1911
  }
1838
1912
  const offset = pagination.page * pagination.perPage;
1839
1913
  const result = await this.client.query({
1840
- query: `SELECT * FROM ${TABLE_SCORERS} WHERE scorerId = {var_scorerId:String} ORDER BY createdAt DESC LIMIT {var_limit:Int64} OFFSET {var_offset:Int64}`,
1914
+ query: `SELECT * FROM ${TABLE_SCORERS} WHERE ${whereClause} ORDER BY createdAt DESC LIMIT {var_limit:Int64} OFFSET {var_offset:Int64}`,
1841
1915
  query_params: {
1842
1916
  var_scorerId: scorerId,
1843
1917
  var_limit: pagination.perPage,
1844
- var_offset: offset
1918
+ var_offset: offset,
1919
+ var_entityId: entityId,
1920
+ var_entityType: entityType,
1921
+ var_source: source
1845
1922
  },
1846
1923
  format: "JSONEachRow",
1847
1924
  clickhouse_settings: {
@@ -2393,6 +2470,7 @@ var WorkflowsStorageClickhouse = class extends WorkflowsStorage {
2393
2470
  resourceId
2394
2471
  FROM ${TABLE_WORKFLOW_SNAPSHOT} ${TABLE_ENGINES[TABLE_WORKFLOW_SNAPSHOT].startsWith("ReplacingMergeTree") ? "FINAL" : ""}
2395
2472
  ${whereClause}
2473
+ ORDER BY createdAt DESC LIMIT 1
2396
2474
  `,
2397
2475
  query_params: values,
2398
2476
  format: "JSONEachRow"
@@ -2596,6 +2674,12 @@ var ClickhouseStore = class extends MastraStorage {
2596
2674
  }) {
2597
2675
  return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
2598
2676
  }
2677
+ async getMessagesById({
2678
+ messageIds,
2679
+ format
2680
+ }) {
2681
+ return this.stores.memory.getMessagesById({ messageIds, format });
2682
+ }
2599
2683
  async saveMessages(args) {
2600
2684
  return this.stores.memory.saveMessages(args);
2601
2685
  }
@@ -2639,15 +2723,18 @@ var ClickhouseStore = class extends MastraStorage {
2639
2723
  }
2640
2724
  async getScoresByScorerId({
2641
2725
  scorerId,
2642
- pagination
2726
+ pagination,
2727
+ entityId,
2728
+ entityType,
2729
+ source
2643
2730
  }) {
2644
- return this.stores.scores.getScoresByScorerId({ scorerId, pagination });
2731
+ return this.stores.scores.getScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
2645
2732
  }
2646
2733
  async close() {
2647
2734
  await this.db.close();
2648
2735
  }
2649
2736
  };
2650
2737
 
2651
- export { ClickhouseStore };
2738
+ export { COLUMN_TYPES, ClickhouseStore, TABLE_ENGINES };
2652
2739
  //# sourceMappingURL=index.js.map
2653
2740
  //# sourceMappingURL=index.js.map