@mastra/clickhouse 0.10.2 → 0.11.0-alpha.1

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.
@@ -1,23 +1,23 @@
1
1
 
2
- > @mastra/clickhouse@0.10.2-alpha.2 build /home/runner/work/mastra/mastra/stores/clickhouse
2
+ > @mastra/clickhouse@0.11.0-alpha.1 build /home/runner/work/mastra/mastra/stores/clickhouse
3
3
  > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.5.0
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 8061ms
9
+ TSC ⚡️ Build success in 9187ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.8.3
13
13
  Writing package typings: /home/runner/work/mastra/mastra/stores/clickhouse/dist/_tsup-dts-rollup.d.ts
14
14
  Analysis will use the bundled TypeScript version 5.8.3
15
15
  Writing package typings: /home/runner/work/mastra/mastra/stores/clickhouse/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 10801ms
16
+ DTS ⚡️ Build success in 12431ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- ESM dist/index.js 30.35 KB
21
- ESM ⚡️ Build success in 1199ms
22
- CJS dist/index.cjs 30.60 KB
23
- CJS ⚡️ Build success in 1200ms
20
+ CJS dist/index.cjs 31.44 KB
21
+ CJS ⚡️ Build success in 1042ms
22
+ ESM dist/index.js 31.18 KB
23
+ ESM ⚡️ Build success in 1043ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @mastra/clickhouse
2
2
 
3
+ ## 0.11.0-alpha.1
4
+
5
+ ### Minor Changes
6
+
7
+ - 704d1ca: Thread Timestamp Auto-Update Enhancement
8
+ Added automatic thread updatedAt timestamp updates when messages are saved across all storage providers
9
+ Enhanced user experience: Threads now accurately reflect their latest activity with automatic timestamp updates when new messages are added
10
+ Universal implementation: Consistent behavior across all 7 storage backends (ClickHouse, Cloudflare D1, DynamoDB, MongoDB, PostgreSQL, Upstash, LibSQL)
11
+ Performance optimized: Updates execute in parallel with message saving operations for minimal performance impact
12
+ Backwards compatible: No breaking changes - existing code continues to work unchanged
13
+ Improved conversation ordering: Chat interfaces can now properly sort threads by actual last activity
14
+ This enhancement resolves the issue where active conversations appeared stale due to outdated thread timestamps, providing better conversation management and user experience in chat applications.
15
+
16
+ ## 0.10.3-alpha.0
17
+
18
+ ### Patch Changes
19
+
20
+ - 63f6b7d: dependencies updates:
21
+ - Updated dependency [`@clickhouse/client@^1.11.2` ↗︎](https://www.npmjs.com/package/@clickhouse/client/v/1.11.2) (from `^1.11.0`, in `dependencies`)
22
+ - Updated dependencies [63f6b7d]
23
+ - Updated dependencies [36f1c36]
24
+ - Updated dependencies [10d352e]
25
+ - Updated dependencies [53d3c37]
26
+ - @mastra/core@0.10.6-alpha.0
27
+
3
28
  ## 0.10.2
4
29
 
5
30
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -523,15 +523,18 @@ var ClickhouseStore = class extends storage.MastraStorage {
523
523
  };
524
524
  await this.db.insert({
525
525
  table: storage.TABLE_THREADS,
526
+ format: "JSONEachRow",
526
527
  values: [
527
528
  {
528
- ...updatedThread,
529
+ id: updatedThread.id,
530
+ resourceId: updatedThread.resourceId,
531
+ title: updatedThread.title,
532
+ metadata: updatedThread.metadata,
533
+ createdAt: updatedThread.createdAt,
529
534
  updatedAt: updatedThread.updatedAt.toISOString()
530
535
  }
531
536
  ],
532
- format: "JSONEachRow",
533
537
  clickhouse_settings: {
534
- // Allows to insert serialized JS Dates (such as '2023-12-06T10:54:48.000Z')
535
538
  date_time_input_format: "best_effort",
536
539
  use_client_time_zone: 1,
537
540
  output_format_json_quote_64bit_integers: 0
@@ -686,24 +689,47 @@ var ClickhouseStore = class extends storage.MastraStorage {
686
689
  if (!thread) {
687
690
  throw new Error(`Thread ${threadId} not found`);
688
691
  }
689
- await this.db.insert({
690
- table: storage.TABLE_MESSAGES,
691
- format: "JSONEachRow",
692
- values: messages.map((message) => ({
693
- id: message.id,
694
- thread_id: threadId,
695
- content: typeof message.content === "string" ? message.content : JSON.stringify(message.content),
696
- createdAt: message.createdAt.toISOString(),
697
- role: message.role,
698
- type: message.type || "v2"
699
- })),
700
- clickhouse_settings: {
701
- // Allows to insert serialized JS Dates (such as '2023-12-06T10:54:48.000Z')
702
- date_time_input_format: "best_effort",
703
- use_client_time_zone: 1,
704
- output_format_json_quote_64bit_integers: 0
705
- }
706
- });
692
+ await Promise.all([
693
+ // Insert messages
694
+ this.db.insert({
695
+ table: storage.TABLE_MESSAGES,
696
+ format: "JSONEachRow",
697
+ values: messages.map((message) => ({
698
+ id: message.id,
699
+ thread_id: threadId,
700
+ content: typeof message.content === "string" ? message.content : JSON.stringify(message.content),
701
+ createdAt: message.createdAt.toISOString(),
702
+ role: message.role,
703
+ type: message.type || "v2"
704
+ })),
705
+ clickhouse_settings: {
706
+ // Allows to insert serialized JS Dates (such as '2023-12-06T10:54:48.000Z')
707
+ date_time_input_format: "best_effort",
708
+ use_client_time_zone: 1,
709
+ output_format_json_quote_64bit_integers: 0
710
+ }
711
+ }),
712
+ // Update thread's updatedAt timestamp
713
+ this.db.insert({
714
+ table: storage.TABLE_THREADS,
715
+ format: "JSONEachRow",
716
+ values: [
717
+ {
718
+ id: thread.id,
719
+ resourceId: thread.resourceId,
720
+ title: thread.title,
721
+ metadata: thread.metadata,
722
+ createdAt: thread.createdAt,
723
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
724
+ }
725
+ ],
726
+ clickhouse_settings: {
727
+ date_time_input_format: "best_effort",
728
+ use_client_time_zone: 1,
729
+ output_format_json_quote_64bit_integers: 0
730
+ }
731
+ })
732
+ ]);
707
733
  const list = new agent.MessageList({ threadId, resourceId }).add(messages, "memory");
708
734
  if (format === `v2`) return list.get.all.v2();
709
735
  return list.get.all.v1();
package/dist/index.js CHANGED
@@ -521,15 +521,18 @@ var ClickhouseStore = class extends MastraStorage {
521
521
  };
522
522
  await this.db.insert({
523
523
  table: TABLE_THREADS,
524
+ format: "JSONEachRow",
524
525
  values: [
525
526
  {
526
- ...updatedThread,
527
+ id: updatedThread.id,
528
+ resourceId: updatedThread.resourceId,
529
+ title: updatedThread.title,
530
+ metadata: updatedThread.metadata,
531
+ createdAt: updatedThread.createdAt,
527
532
  updatedAt: updatedThread.updatedAt.toISOString()
528
533
  }
529
534
  ],
530
- format: "JSONEachRow",
531
535
  clickhouse_settings: {
532
- // Allows to insert serialized JS Dates (such as '2023-12-06T10:54:48.000Z')
533
536
  date_time_input_format: "best_effort",
534
537
  use_client_time_zone: 1,
535
538
  output_format_json_quote_64bit_integers: 0
@@ -684,24 +687,47 @@ var ClickhouseStore = class extends MastraStorage {
684
687
  if (!thread) {
685
688
  throw new Error(`Thread ${threadId} not found`);
686
689
  }
687
- await this.db.insert({
688
- table: TABLE_MESSAGES,
689
- format: "JSONEachRow",
690
- values: messages.map((message) => ({
691
- id: message.id,
692
- thread_id: threadId,
693
- content: typeof message.content === "string" ? message.content : JSON.stringify(message.content),
694
- createdAt: message.createdAt.toISOString(),
695
- role: message.role,
696
- type: message.type || "v2"
697
- })),
698
- clickhouse_settings: {
699
- // Allows to insert serialized JS Dates (such as '2023-12-06T10:54:48.000Z')
700
- date_time_input_format: "best_effort",
701
- use_client_time_zone: 1,
702
- output_format_json_quote_64bit_integers: 0
703
- }
704
- });
690
+ await Promise.all([
691
+ // Insert messages
692
+ this.db.insert({
693
+ table: TABLE_MESSAGES,
694
+ format: "JSONEachRow",
695
+ values: messages.map((message) => ({
696
+ id: message.id,
697
+ thread_id: threadId,
698
+ content: typeof message.content === "string" ? message.content : JSON.stringify(message.content),
699
+ createdAt: message.createdAt.toISOString(),
700
+ role: message.role,
701
+ type: message.type || "v2"
702
+ })),
703
+ clickhouse_settings: {
704
+ // Allows to insert serialized JS Dates (such as '2023-12-06T10:54:48.000Z')
705
+ date_time_input_format: "best_effort",
706
+ use_client_time_zone: 1,
707
+ output_format_json_quote_64bit_integers: 0
708
+ }
709
+ }),
710
+ // Update thread's updatedAt timestamp
711
+ this.db.insert({
712
+ table: TABLE_THREADS,
713
+ format: "JSONEachRow",
714
+ values: [
715
+ {
716
+ id: thread.id,
717
+ resourceId: thread.resourceId,
718
+ title: thread.title,
719
+ metadata: thread.metadata,
720
+ createdAt: thread.createdAt,
721
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
722
+ }
723
+ ],
724
+ clickhouse_settings: {
725
+ date_time_input_format: "best_effort",
726
+ use_client_time_zone: 1,
727
+ output_format_json_quote_64bit_integers: 0
728
+ }
729
+ })
730
+ ]);
705
731
  const list = new MessageList({ threadId, resourceId }).add(messages, "memory");
706
732
  if (format === `v2`) return list.get.all.v2();
707
733
  return list.get.all.v1();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/clickhouse",
3
- "version": "0.10.2",
3
+ "version": "0.11.0-alpha.1",
4
4
  "description": "Clickhouse provider for Mastra - includes db storage capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -20,18 +20,18 @@
20
20
  },
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
- "@clickhouse/client": "^1.11.0"
23
+ "@clickhouse/client": "^1.11.2"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@microsoft/api-extractor": "^7.52.8",
27
- "@types/node": "^20.17.57",
27
+ "@types/node": "^20.19.0",
28
28
  "eslint": "^9.28.0",
29
29
  "tsup": "^8.5.0",
30
- "typescript": "^5.8.2",
31
- "vitest": "^3.2.2",
32
- "@mastra/core": "0.10.4",
33
- "@internal/storage-test-utils": "0.0.7",
34
- "@internal/lint": "0.0.11"
30
+ "typescript": "^5.8.3",
31
+ "vitest": "^3.2.3",
32
+ "@internal/lint": "0.0.12",
33
+ "@mastra/core": "0.10.6-alpha.0",
34
+ "@internal/storage-test-utils": "0.0.8"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@mastra/core": ">=0.10.4-0 <0.11.0"
@@ -133,6 +133,28 @@ describe('ClickhouseStore', () => {
133
133
  const retrievedMessages = await store.getMessages({ threadId: thread.id });
134
134
  expect(retrievedMessages).toHaveLength(0);
135
135
  }, 10e3);
136
+
137
+ it('should update thread updatedAt when a message is saved to it', async () => {
138
+ const thread = createSampleThread();
139
+ await store.saveThread({ thread });
140
+
141
+ // Get the initial thread to capture the original updatedAt
142
+ const initialThread = await store.getThreadById({ threadId: thread.id });
143
+ expect(initialThread).toBeDefined();
144
+ const originalUpdatedAt = initialThread!.updatedAt;
145
+
146
+ // Wait a small amount to ensure different timestamp
147
+ await new Promise(resolve => setTimeout(resolve, 10));
148
+
149
+ // Create and save a message to the thread
150
+ const message = createSampleMessageV1({ threadId: thread.id });
151
+ await store.saveMessages({ messages: [message] });
152
+
153
+ // Retrieve the thread again and check that updatedAt was updated
154
+ const updatedThread = await store.getThreadById({ threadId: thread.id });
155
+ expect(updatedThread).toBeDefined();
156
+ expect(updatedThread!.updatedAt.getTime()).toBeGreaterThan(originalUpdatedAt.getTime());
157
+ }, 10e3);
136
158
  });
137
159
 
138
160
  describe('Message Operations', () => {
@@ -670,15 +670,18 @@ export class ClickhouseStore extends MastraStorage {
670
670
 
671
671
  await this.db.insert({
672
672
  table: TABLE_THREADS,
673
+ format: 'JSONEachRow',
673
674
  values: [
674
675
  {
675
- ...updatedThread,
676
+ id: updatedThread.id,
677
+ resourceId: updatedThread.resourceId,
678
+ title: updatedThread.title,
679
+ metadata: updatedThread.metadata,
680
+ createdAt: updatedThread.createdAt,
676
681
  updatedAt: updatedThread.updatedAt.toISOString(),
677
682
  },
678
683
  ],
679
- format: 'JSONEachRow',
680
684
  clickhouse_settings: {
681
- // Allows to insert serialized JS Dates (such as '2023-12-06T10:54:48.000Z')
682
685
  date_time_input_format: 'best_effort',
683
686
  use_client_time_zone: 1,
684
687
  output_format_json_quote_64bit_integers: 0,
@@ -861,24 +864,48 @@ export class ClickhouseStore extends MastraStorage {
861
864
  throw new Error(`Thread ${threadId} not found`);
862
865
  }
863
866
 
864
- await this.db.insert({
865
- table: TABLE_MESSAGES,
866
- format: 'JSONEachRow',
867
- values: messages.map(message => ({
868
- id: message.id,
869
- thread_id: threadId,
870
- content: typeof message.content === 'string' ? message.content : JSON.stringify(message.content),
871
- createdAt: message.createdAt.toISOString(),
872
- role: message.role,
873
- type: message.type || 'v2',
874
- })),
875
- clickhouse_settings: {
876
- // Allows to insert serialized JS Dates (such as '2023-12-06T10:54:48.000Z')
877
- date_time_input_format: 'best_effort',
878
- use_client_time_zone: 1,
879
- output_format_json_quote_64bit_integers: 0,
880
- },
881
- });
867
+ // Execute message inserts and thread update in parallel for better performance
868
+ await Promise.all([
869
+ // Insert messages
870
+ this.db.insert({
871
+ table: TABLE_MESSAGES,
872
+ format: 'JSONEachRow',
873
+ values: messages.map(message => ({
874
+ id: message.id,
875
+ thread_id: threadId,
876
+ content: typeof message.content === 'string' ? message.content : JSON.stringify(message.content),
877
+ createdAt: message.createdAt.toISOString(),
878
+ role: message.role,
879
+ type: message.type || 'v2',
880
+ })),
881
+ clickhouse_settings: {
882
+ // Allows to insert serialized JS Dates (such as '2023-12-06T10:54:48.000Z')
883
+ date_time_input_format: 'best_effort',
884
+ use_client_time_zone: 1,
885
+ output_format_json_quote_64bit_integers: 0,
886
+ },
887
+ }),
888
+ // Update thread's updatedAt timestamp
889
+ this.db.insert({
890
+ table: TABLE_THREADS,
891
+ format: 'JSONEachRow',
892
+ values: [
893
+ {
894
+ id: thread.id,
895
+ resourceId: thread.resourceId,
896
+ title: thread.title,
897
+ metadata: thread.metadata,
898
+ createdAt: thread.createdAt,
899
+ updatedAt: new Date().toISOString(),
900
+ },
901
+ ],
902
+ clickhouse_settings: {
903
+ date_time_input_format: 'best_effort',
904
+ use_client_time_zone: 1,
905
+ output_format_json_quote_64bit_integers: 0,
906
+ },
907
+ }),
908
+ ]);
882
909
 
883
910
  const list = new MessageList({ threadId, resourceId }).add(messages, 'memory');
884
911
  if (format === `v2`) return list.get.all.v2();