@mastra/clickhouse 0.10.3-alpha.0 → 0.11.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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +47 -0
- package/dist/index.cjs +47 -21
- package/dist/index.js +47 -21
- package/package.json +4 -4
- package/src/storage/index.test.ts +22 -0
- package/src/storage/index.ts +48 -21
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/clickhouse@0.
|
|
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
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.5.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 8474ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/clickhouse/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/clickhouse/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 10940ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[32mCJS[39m [1mdist/index.cjs [22m[
|
|
21
|
-
[32mCJS[39m ⚡️ Build success in
|
|
22
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
23
|
-
[32mESM[39m ⚡️ Build success in
|
|
20
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m31.44 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 974ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m31.18 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 977ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
1
|
# @mastra/clickhouse
|
|
2
2
|
|
|
3
|
+
## 0.11.0
|
|
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
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 63f6b7d: dependencies updates:
|
|
19
|
+
- Updated dependency [`@clickhouse/client@^1.11.2` ↗︎](https://www.npmjs.com/package/@clickhouse/client/v/1.11.2) (from `^1.11.0`, in `dependencies`)
|
|
20
|
+
- Updated dependencies [63f6b7d]
|
|
21
|
+
- Updated dependencies [12a95fc]
|
|
22
|
+
- Updated dependencies [4b0f8a6]
|
|
23
|
+
- Updated dependencies [51264a5]
|
|
24
|
+
- Updated dependencies [8e6f677]
|
|
25
|
+
- Updated dependencies [d70c420]
|
|
26
|
+
- Updated dependencies [ee9af57]
|
|
27
|
+
- Updated dependencies [36f1c36]
|
|
28
|
+
- Updated dependencies [2a16996]
|
|
29
|
+
- Updated dependencies [10d352e]
|
|
30
|
+
- Updated dependencies [9589624]
|
|
31
|
+
- Updated dependencies [53d3c37]
|
|
32
|
+
- Updated dependencies [751c894]
|
|
33
|
+
- Updated dependencies [577ce3a]
|
|
34
|
+
- Updated dependencies [9260b3a]
|
|
35
|
+
- @mastra/core@0.10.6
|
|
36
|
+
|
|
37
|
+
## 0.11.0-alpha.1
|
|
38
|
+
|
|
39
|
+
### Minor Changes
|
|
40
|
+
|
|
41
|
+
- 704d1ca: Thread Timestamp Auto-Update Enhancement
|
|
42
|
+
Added automatic thread updatedAt timestamp updates when messages are saved across all storage providers
|
|
43
|
+
Enhanced user experience: Threads now accurately reflect their latest activity with automatic timestamp updates when new messages are added
|
|
44
|
+
Universal implementation: Consistent behavior across all 7 storage backends (ClickHouse, Cloudflare D1, DynamoDB, MongoDB, PostgreSQL, Upstash, LibSQL)
|
|
45
|
+
Performance optimized: Updates execute in parallel with message saving operations for minimal performance impact
|
|
46
|
+
Backwards compatible: No breaking changes - existing code continues to work unchanged
|
|
47
|
+
Improved conversation ordering: Chat interfaces can now properly sort threads by actual last activity
|
|
48
|
+
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.
|
|
49
|
+
|
|
3
50
|
## 0.10.3-alpha.0
|
|
4
51
|
|
|
5
52
|
### 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
|
-
|
|
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
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
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
|
-
|
|
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
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
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.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Clickhouse provider for Mastra - includes db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"tsup": "^8.5.0",
|
|
30
30
|
"typescript": "^5.8.3",
|
|
31
31
|
"vitest": "^3.2.3",
|
|
32
|
-
"@internal/lint": "0.0.
|
|
33
|
-
"@internal/storage-test-utils": "0.0.
|
|
34
|
-
"@mastra/core": "0.10.6
|
|
32
|
+
"@internal/lint": "0.0.13",
|
|
33
|
+
"@internal/storage-test-utils": "0.0.9",
|
|
34
|
+
"@mastra/core": "0.10.6"
|
|
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', () => {
|
package/src/storage/index.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
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();
|