@mastra/clickhouse 0.13.1 → 0.13.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/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
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;
@@ -2618,6 +2674,12 @@ var ClickhouseStore = class extends MastraStorage {
2618
2674
  }) {
2619
2675
  return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
2620
2676
  }
2677
+ async getMessagesById({
2678
+ messageIds,
2679
+ format
2680
+ }) {
2681
+ return this.stores.memory.getMessagesById({ messageIds, format });
2682
+ }
2621
2683
  async saveMessages(args) {
2622
2684
  return this.stores.memory.saveMessages(args);
2623
2685
  }
@@ -2673,6 +2735,6 @@ var ClickhouseStore = class extends MastraStorage {
2673
2735
  }
2674
2736
  };
2675
2737
 
2676
- export { ClickhouseStore };
2738
+ export { COLUMN_TYPES, ClickhouseStore, TABLE_ENGINES };
2677
2739
  //# sourceMappingURL=index.js.map
2678
2740
  //# sourceMappingURL=index.js.map