@mastra/clickhouse 0.2.7-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.
@@ -0,0 +1,23 @@
1
+
2
+ > @mastra/clickhouse@0.2.7-alpha.1 build /home/runner/work/mastra/mastra/stores/clickhouse
3
+ > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
4
+
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.4.0
8
+ TSC Build start
9
+ TSC ⚡️ Build success in 8308ms
10
+ DTS Build start
11
+ CLI Target: es2022
12
+ Analysis will use the bundled TypeScript version 5.8.2
13
+ Writing package typings: /home/runner/work/mastra/mastra/stores/clickhouse/dist/_tsup-dts-rollup.d.ts
14
+ Analysis will use the bundled TypeScript version 5.8.2
15
+ Writing package typings: /home/runner/work/mastra/mastra/stores/clickhouse/dist/_tsup-dts-rollup.d.cts
16
+ DTS ⚡️ Build success in 10391ms
17
+ CLI Cleaning output folder
18
+ ESM Build start
19
+ CJS Build start
20
+ ESM dist/index.js 19.85 KB
21
+ ESM ⚡️ Build success in 754ms
22
+ CJS dist/index.cjs 19.95 KB
23
+ CJS ⚡️ Build success in 752ms
package/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # @mastra/clickhouse
2
+
3
+ ## 0.2.7-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - dbbbf80: Added clickhouse storage
8
+ - Updated dependencies [56c31b7]
9
+ - Updated dependencies [dbbbf80]
10
+ - Updated dependencies [99d43b9]
11
+ - @mastra/core@0.8.0-alpha.2
package/LICENSE ADDED
@@ -0,0 +1,44 @@
1
+ Elastic License 2.0 (ELv2)
2
+
3
+ **Acceptance**
4
+ By using the software, you agree to all of the terms and conditions below.
5
+
6
+ **Copyright License**
7
+ The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
8
+
9
+ **Limitations**
10
+ You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
11
+
12
+ You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
13
+
14
+ You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
15
+
16
+ **Patents**
17
+ The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
18
+
19
+ **Notices**
20
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
21
+
22
+ If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
23
+
24
+ **No Other Rights**
25
+ These terms do not imply any licenses other than those expressly granted in these terms.
26
+
27
+ **Termination**
28
+ If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
29
+
30
+ **No Liability**
31
+ As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
32
+
33
+ **Definitions**
34
+ The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
35
+
36
+ _you_ refers to the individual or entity agreeing to these terms.
37
+
38
+ _your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
39
+
40
+ _your licenses_ are all the licenses granted to you for the software under these terms.
41
+
42
+ _use_ means anything you do with the software requiring one of your licenses.
43
+
44
+ _trademark_ means trademarks, service marks, and similar rights.
package/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # @mastra/clickhouse
2
+
3
+ Clickhouse implementation for Mastra, providing efficient storage capabilities with support for threads, messages, and workflow snapshots.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @mastra/clickhouse
9
+ ```
10
+
11
+ ## Prerequisites
12
+
13
+ - Clickhouse server (version 21.8 or higher recommended)
14
+ - Node.js 16 or higher
15
+
16
+ ## Usage
17
+
18
+ ```typescript
19
+ import { ClickhouseStore } from '@mastra/clickhouse';
20
+
21
+ const store = new ClickhouseStore({
22
+ url: 'http://localhost:8123',
23
+ username: 'default',
24
+ password: 'password',
25
+ });
26
+
27
+ // Create a thread
28
+ await store.saveThread({
29
+ id: 'thread-123',
30
+ resourceId: 'resource-456',
31
+ title: 'My Thread',
32
+ metadata: { key: 'value' },
33
+ createdAt: new Date(),
34
+ updatedAt: new Date(),
35
+ });
36
+
37
+ // Add messages to thread
38
+ await store.saveMessages([
39
+ {
40
+ id: 'msg-789',
41
+ threadId: 'thread-123',
42
+ role: 'user',
43
+ type: 'text',
44
+ content: [{ type: 'text', text: 'Hello' }],
45
+ createdAt: new Date(),
46
+ },
47
+ ]);
48
+
49
+ // Query threads and messages
50
+ const savedThread = await store.getThreadById({ threadId: 'thread-123' });
51
+ const messages = await store.getMessages({ threadId: 'thread-123' });
52
+
53
+ // Clean up
54
+ await store.close();
55
+ ```
56
+
57
+ ## Configuration
58
+
59
+ The Clickhouse store can be initialized with the following configuration:
60
+
61
+ ```typescript
62
+ type ClickhouseConfig = {
63
+ url: string; // Clickhouse HTTP interface URL
64
+ username: string; // Database username
65
+ password: string; // Database password
66
+ };
67
+ ```
68
+
69
+ ## Features
70
+
71
+ ### Storage Features
72
+
73
+ - Thread and message storage with JSON support
74
+ - Efficient batch operations
75
+ - Rich metadata support
76
+ - Timestamp tracking
77
+ - Workflow snapshot persistence
78
+ - Optimized for high-volume data ingestion
79
+ - Uses Clickhouse's MergeTree and ReplacingMergeTree engines for optimal performance
80
+
81
+ ### Table Engines
82
+
83
+ The store uses different table engines for different types of data:
84
+
85
+ - `MergeTree()`: Used for messages, traces, and evals
86
+ - `ReplacingMergeTree()`: Used for threads and workflow snapshots
87
+
88
+ ## Storage Methods
89
+
90
+ ### Thread Operations
91
+
92
+ - `saveThread(thread)`: Create or update a thread
93
+ - `getThreadById({ threadId })`: Get a thread by ID
94
+ - `updateThread({ id, title, metadata })`: Update thread title and metadata
95
+ - `deleteThread({ threadId })`: Delete a thread and its messages
96
+
97
+ ### Message Operations
98
+
99
+ - `saveMessages(messages)`: Save multiple messages
100
+ - `getMessages({ threadId, selectBy? })`: Get messages for a thread with optional filtering
101
+ - `deleteMessages(messageIds)`: Delete specific messages
102
+
103
+ ### Workflow Operations
104
+
105
+ - `persistWorkflowSnapshot({ workflowName, runId, snapshot })`: Save workflow state
106
+ - `loadWorkflowSnapshot({ workflowName, runId })`: Load workflow state
107
+
108
+ ## Data Types
109
+
110
+ The store supports the following data types:
111
+
112
+ - `text`: String
113
+ - `timestamp`: DateTime64(3)
114
+ - `uuid`: String
115
+ - `jsonb`: String (JSON serialized)
116
+ - `integer`: Int64
117
+ - `bigint`: Int64
118
+
119
+ ## Related Links
120
+
121
+ - [Clickhouse Documentation](https://clickhouse.com/docs)
122
+ - [Clickhouse Node.js Client](https://github.com/clickhouse/clickhouse-js)
@@ -0,0 +1,83 @@
1
+ import type { EvalRow } from '@mastra/core/storage';
2
+ import { MastraStorage } from '@mastra/core/storage';
3
+ import type { MessageType } from '@mastra/core/memory';
4
+ import type { StorageColumn } from '@mastra/core/storage';
5
+ import type { StorageGetMessagesArg } from '@mastra/core/storage';
6
+ import type { StorageThreadType } from '@mastra/core/memory';
7
+ import type { TABLE_NAMES } from '@mastra/core/storage';
8
+ import type { WorkflowRunState } from '@mastra/core/workflows';
9
+
10
+ declare type ClickhouseConfig = {
11
+ url: string;
12
+ username: string;
13
+ password: string;
14
+ };
15
+ export { ClickhouseConfig }
16
+ export { ClickhouseConfig as ClickhouseConfig_alias_1 }
17
+
18
+ declare class ClickhouseStore extends MastraStorage {
19
+ private db;
20
+ constructor(config: ClickhouseConfig);
21
+ getEvalsByAgentName(_agentName: string, _type?: 'test' | 'live'): Promise<EvalRow[]>;
22
+ batchInsert({ tableName, records }: {
23
+ tableName: TABLE_NAMES;
24
+ records: Record<string, any>[];
25
+ }): Promise<void>;
26
+ getTraces({ name, scope, page, perPage, attributes, }: {
27
+ name?: string;
28
+ scope?: string;
29
+ page: number;
30
+ perPage: number;
31
+ attributes?: Record<string, string>;
32
+ }): Promise<any[]>;
33
+ createTable({ tableName, schema, }: {
34
+ tableName: TABLE_NAMES;
35
+ schema: Record<string, StorageColumn>;
36
+ }): Promise<void>;
37
+ clearTable({ tableName }: {
38
+ tableName: TABLE_NAMES;
39
+ }): Promise<void>;
40
+ insert({ tableName, record }: {
41
+ tableName: TABLE_NAMES;
42
+ record: Record<string, any>;
43
+ }): Promise<void>;
44
+ load<R>({ tableName, keys }: {
45
+ tableName: TABLE_NAMES;
46
+ keys: Record<string, string>;
47
+ }): Promise<R | null>;
48
+ getThreadById({ threadId }: {
49
+ threadId: string;
50
+ }): Promise<StorageThreadType | null>;
51
+ getThreadsByResourceId({ resourceId }: {
52
+ resourceId: string;
53
+ }): Promise<StorageThreadType[]>;
54
+ saveThread({ thread }: {
55
+ thread: StorageThreadType;
56
+ }): Promise<StorageThreadType>;
57
+ updateThread({ id, title, metadata, }: {
58
+ id: string;
59
+ title: string;
60
+ metadata: Record<string, unknown>;
61
+ }): Promise<StorageThreadType>;
62
+ deleteThread({ threadId }: {
63
+ threadId: string;
64
+ }): Promise<void>;
65
+ getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T>;
66
+ saveMessages({ messages }: {
67
+ messages: MessageType[];
68
+ }): Promise<MessageType[]>;
69
+ persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
70
+ workflowName: string;
71
+ runId: string;
72
+ snapshot: WorkflowRunState;
73
+ }): Promise<void>;
74
+ loadWorkflowSnapshot({ workflowName, runId, }: {
75
+ workflowName: string;
76
+ runId: string;
77
+ }): Promise<WorkflowRunState | null>;
78
+ close(): Promise<void>;
79
+ }
80
+ export { ClickhouseStore }
81
+ export { ClickhouseStore as ClickhouseStore_alias_1 }
82
+
83
+ export { }
@@ -0,0 +1,83 @@
1
+ import type { EvalRow } from '@mastra/core/storage';
2
+ import { MastraStorage } from '@mastra/core/storage';
3
+ import type { MessageType } from '@mastra/core/memory';
4
+ import type { StorageColumn } from '@mastra/core/storage';
5
+ import type { StorageGetMessagesArg } from '@mastra/core/storage';
6
+ import type { StorageThreadType } from '@mastra/core/memory';
7
+ import type { TABLE_NAMES } from '@mastra/core/storage';
8
+ import type { WorkflowRunState } from '@mastra/core/workflows';
9
+
10
+ declare type ClickhouseConfig = {
11
+ url: string;
12
+ username: string;
13
+ password: string;
14
+ };
15
+ export { ClickhouseConfig }
16
+ export { ClickhouseConfig as ClickhouseConfig_alias_1 }
17
+
18
+ declare class ClickhouseStore extends MastraStorage {
19
+ private db;
20
+ constructor(config: ClickhouseConfig);
21
+ getEvalsByAgentName(_agentName: string, _type?: 'test' | 'live'): Promise<EvalRow[]>;
22
+ batchInsert({ tableName, records }: {
23
+ tableName: TABLE_NAMES;
24
+ records: Record<string, any>[];
25
+ }): Promise<void>;
26
+ getTraces({ name, scope, page, perPage, attributes, }: {
27
+ name?: string;
28
+ scope?: string;
29
+ page: number;
30
+ perPage: number;
31
+ attributes?: Record<string, string>;
32
+ }): Promise<any[]>;
33
+ createTable({ tableName, schema, }: {
34
+ tableName: TABLE_NAMES;
35
+ schema: Record<string, StorageColumn>;
36
+ }): Promise<void>;
37
+ clearTable({ tableName }: {
38
+ tableName: TABLE_NAMES;
39
+ }): Promise<void>;
40
+ insert({ tableName, record }: {
41
+ tableName: TABLE_NAMES;
42
+ record: Record<string, any>;
43
+ }): Promise<void>;
44
+ load<R>({ tableName, keys }: {
45
+ tableName: TABLE_NAMES;
46
+ keys: Record<string, string>;
47
+ }): Promise<R | null>;
48
+ getThreadById({ threadId }: {
49
+ threadId: string;
50
+ }): Promise<StorageThreadType | null>;
51
+ getThreadsByResourceId({ resourceId }: {
52
+ resourceId: string;
53
+ }): Promise<StorageThreadType[]>;
54
+ saveThread({ thread }: {
55
+ thread: StorageThreadType;
56
+ }): Promise<StorageThreadType>;
57
+ updateThread({ id, title, metadata, }: {
58
+ id: string;
59
+ title: string;
60
+ metadata: Record<string, unknown>;
61
+ }): Promise<StorageThreadType>;
62
+ deleteThread({ threadId }: {
63
+ threadId: string;
64
+ }): Promise<void>;
65
+ getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T>;
66
+ saveMessages({ messages }: {
67
+ messages: MessageType[];
68
+ }): Promise<MessageType[]>;
69
+ persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
70
+ workflowName: string;
71
+ runId: string;
72
+ snapshot: WorkflowRunState;
73
+ }): Promise<void>;
74
+ loadWorkflowSnapshot({ workflowName, runId, }: {
75
+ workflowName: string;
76
+ runId: string;
77
+ }): Promise<WorkflowRunState | null>;
78
+ close(): Promise<void>;
79
+ }
80
+ export { ClickhouseStore }
81
+ export { ClickhouseStore as ClickhouseStore_alias_1 }
82
+
83
+ export { }