@mastra/clickhouse 1.0.0-beta.8 → 1.0.0-beta.9
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/CHANGELOG.md +49 -0
- package/dist/docs/README.md +31 -0
- package/dist/docs/SKILL.md +32 -0
- package/dist/docs/SOURCE_MAP.json +6 -0
- package/dist/docs/storage/01-reference.md +182 -0
- package/dist/index.cjs +8 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +8 -4
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
# @mastra/clickhouse
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add embedded documentation support for Mastra packages ([#11472](https://github.com/mastra-ai/mastra/pull/11472))
|
|
8
|
+
|
|
9
|
+
Mastra packages now include embedded documentation in the published npm package under `dist/docs/`. This enables coding agents and AI assistants to understand and use the framework by reading documentation directly from `node_modules`.
|
|
10
|
+
|
|
11
|
+
Each package includes:
|
|
12
|
+
- **SKILL.md** - Entry point explaining the package's purpose and capabilities
|
|
13
|
+
- **SOURCE_MAP.json** - Machine-readable index mapping exports to types and implementation files
|
|
14
|
+
- **Topic folders** - Conceptual documentation organized by feature area
|
|
15
|
+
|
|
16
|
+
Documentation is driven by the `packages` frontmatter field in MDX files, which maps docs to their corresponding packages. CI validation ensures all docs include this field.
|
|
17
|
+
|
|
18
|
+
- Added `startExclusive` and `endExclusive` options to `dateRange` filter for message queries. ([#11479](https://github.com/mastra-ai/mastra/pull/11479))
|
|
19
|
+
|
|
20
|
+
**What changed:** The `filter.dateRange` parameter in `listMessages()` and `Memory.recall()` now supports `startExclusive` and `endExclusive` boolean options. When set to `true`, messages with timestamps exactly matching the boundary are excluded from results.
|
|
21
|
+
|
|
22
|
+
**Why this matters:** Enables cursor-based pagination for chat applications. When new messages arrive during a session, offset-based pagination can skip or duplicate messages. Using `endExclusive: true` with the oldest message's timestamp as a cursor ensures consistent pagination without gaps or duplicates.
|
|
23
|
+
|
|
24
|
+
**Example:**
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
// Get first page
|
|
28
|
+
const page1 = await memory.recall({
|
|
29
|
+
threadId: 'thread-123',
|
|
30
|
+
perPage: 10,
|
|
31
|
+
orderBy: { field: 'createdAt', direction: 'DESC' },
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Get next page using cursor-based pagination
|
|
35
|
+
const oldestMessage = page1.messages[page1.messages.length - 1];
|
|
36
|
+
const page2 = await memory.recall({
|
|
37
|
+
threadId: 'thread-123',
|
|
38
|
+
perPage: 10,
|
|
39
|
+
orderBy: { field: 'createdAt', direction: 'DESC' },
|
|
40
|
+
filter: {
|
|
41
|
+
dateRange: {
|
|
42
|
+
end: oldestMessage.createdAt,
|
|
43
|
+
endExclusive: true, // Excludes the cursor message
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
- Updated dependencies [[`d2d3e22`](https://github.com/mastra-ai/mastra/commit/d2d3e22a419ee243f8812a84e3453dd44365ecb0), [`bc72b52`](https://github.com/mastra-ai/mastra/commit/bc72b529ee4478fe89ecd85a8be47ce0127b82a0), [`05b8bee`](https://github.com/mastra-ai/mastra/commit/05b8bee9e50e6c2a4a2bf210eca25ee212ca24fa), [`c042bd0`](https://github.com/mastra-ai/mastra/commit/c042bd0b743e0e86199d0cb83344ca7690e34a9c), [`940a2b2`](https://github.com/mastra-ai/mastra/commit/940a2b27480626ed7e74f55806dcd2181c1dd0c2), [`e0941c3`](https://github.com/mastra-ai/mastra/commit/e0941c3d7fc75695d5d258e7008fd5d6e650800c), [`0c0580a`](https://github.com/mastra-ai/mastra/commit/0c0580a42f697cd2a7d5973f25bfe7da9055038a), [`28f5f89`](https://github.com/mastra-ai/mastra/commit/28f5f89705f2409921e3c45178796c0e0d0bbb64), [`e601b27`](https://github.com/mastra-ai/mastra/commit/e601b272c70f3a5ecca610373aa6223012704892), [`3d3366f`](https://github.com/mastra-ai/mastra/commit/3d3366f31683e7137d126a3a57174a222c5801fb), [`5a4953f`](https://github.com/mastra-ai/mastra/commit/5a4953f7d25bb15ca31ed16038092a39cb3f98b3), [`eb9e522`](https://github.com/mastra-ai/mastra/commit/eb9e522ce3070a405e5b949b7bf5609ca51d7fe2), [`20e6f19`](https://github.com/mastra-ai/mastra/commit/20e6f1971d51d3ff6dd7accad8aaaae826d540ed), [`4f0b3c6`](https://github.com/mastra-ai/mastra/commit/4f0b3c66f196c06448487f680ccbb614d281e2f7), [`74c4f22`](https://github.com/mastra-ai/mastra/commit/74c4f22ed4c71e72598eacc346ba95cdbc00294f), [`81b6a8f`](https://github.com/mastra-ai/mastra/commit/81b6a8ff79f49a7549d15d66624ac1a0b8f5f971), [`e4d366a`](https://github.com/mastra-ai/mastra/commit/e4d366aeb500371dd4210d6aa8361a4c21d87034), [`a4f010b`](https://github.com/mastra-ai/mastra/commit/a4f010b22e4355a5fdee70a1fe0f6e4a692cc29e), [`73b0bb3`](https://github.com/mastra-ai/mastra/commit/73b0bb394dba7c9482eb467a97ab283dbc0ef4db), [`5627a8c`](https://github.com/mastra-ai/mastra/commit/5627a8c6dc11fe3711b3fa7a6ffd6eb34100a306), [`3ff45d1`](https://github.com/mastra-ai/mastra/commit/3ff45d10e0c80c5335a957ab563da72feb623520), [`251df45`](https://github.com/mastra-ai/mastra/commit/251df4531407dfa46d805feb40ff3fb49769f455), [`f894d14`](https://github.com/mastra-ai/mastra/commit/f894d148946629af7b1f452d65a9cf864cec3765), [`c2b9547`](https://github.com/mastra-ai/mastra/commit/c2b9547bf435f56339f23625a743b2147ab1c7a6), [`580b592`](https://github.com/mastra-ai/mastra/commit/580b5927afc82fe460dfdf9a38a902511b6b7e7f), [`58e3931`](https://github.com/mastra-ai/mastra/commit/58e3931af9baa5921688566210f00fb0c10479fa), [`08bb631`](https://github.com/mastra-ai/mastra/commit/08bb631ae2b14684b2678e3549d0b399a6f0561e), [`4fba91b`](https://github.com/mastra-ai/mastra/commit/4fba91bec7c95911dc28e369437596b152b04cd0), [`12b0cc4`](https://github.com/mastra-ai/mastra/commit/12b0cc4077d886b1a552637dedb70a7ade93528c)]:
|
|
50
|
+
- @mastra/core@1.0.0-beta.20
|
|
51
|
+
|
|
3
52
|
## 1.0.0-beta.8
|
|
4
53
|
|
|
5
54
|
### Patch Changes
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @mastra/clickhouse Documentation
|
|
2
|
+
|
|
3
|
+
> Embedded documentation for coding agents
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Read the skill overview
|
|
9
|
+
cat docs/SKILL.md
|
|
10
|
+
|
|
11
|
+
# Get the source map
|
|
12
|
+
cat docs/SOURCE_MAP.json
|
|
13
|
+
|
|
14
|
+
# Read topic documentation
|
|
15
|
+
cat docs/<topic>/01-overview.md
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Structure
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
docs/
|
|
22
|
+
├── SKILL.md # Entry point
|
|
23
|
+
├── README.md # This file
|
|
24
|
+
├── SOURCE_MAP.json # Export index
|
|
25
|
+
├── storage/ (1 files)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Version
|
|
29
|
+
|
|
30
|
+
Package: @mastra/clickhouse
|
|
31
|
+
Version: 1.0.0-beta.9
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: mastra-clickhouse-docs
|
|
3
|
+
description: Documentation for @mastra/clickhouse. Includes links to type definitions and readable implementation code in dist/.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# @mastra/clickhouse Documentation
|
|
7
|
+
|
|
8
|
+
> **Version**: 1.0.0-beta.9
|
|
9
|
+
> **Package**: @mastra/clickhouse
|
|
10
|
+
|
|
11
|
+
## Quick Navigation
|
|
12
|
+
|
|
13
|
+
Use SOURCE_MAP.json to find any export:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
cat docs/SOURCE_MAP.json
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Each export maps to:
|
|
20
|
+
- **types**: `.d.ts` file with JSDoc and API signatures
|
|
21
|
+
- **implementation**: `.js` chunk file with readable source
|
|
22
|
+
- **docs**: Conceptual documentation in `docs/`
|
|
23
|
+
|
|
24
|
+
## Top Exports
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
See SOURCE_MAP.json for the complete list.
|
|
29
|
+
|
|
30
|
+
## Available Topics
|
|
31
|
+
|
|
32
|
+
- [Storage](storage/) - 1 file(s)
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# Storage API Reference
|
|
2
|
+
|
|
3
|
+
> API reference for storage - 1 entries
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Reference: Storage Composition
|
|
9
|
+
|
|
10
|
+
> Documentation for combining multiple storage backends in Mastra.
|
|
11
|
+
|
|
12
|
+
MastraStorage can compose storage domains from different adapters. Use it when you need different databases for different purposes. For example, use LibSQL for memory and PostgreSQL for workflows.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
MastraStorage is included in `@mastra/core`:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @mastra/core@beta
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
You'll also need to install the storage adapters you want to compose:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install @mastra/pg@beta @mastra/libsql@beta
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Storage Domains
|
|
29
|
+
|
|
30
|
+
Mastra organizes storage into five specialized domains, each handling a specific type of data. Each domain can be backed by a different storage adapter, and domain classes are exported from each storage package.
|
|
31
|
+
|
|
32
|
+
| Domain | Description |
|
|
33
|
+
|--------|-------------|
|
|
34
|
+
| `memory` | Conversation persistence for agents. Stores threads (conversation sessions), messages, resources (user identities), and working memory (persistent context across conversations). |
|
|
35
|
+
| `workflows` | Workflow execution state. When workflows suspend for human input, external events, or scheduled resumption, their state is persisted here to enable resumption after server restarts. |
|
|
36
|
+
| `scores` | Evaluation results from Mastra's evals system. Scores and metrics are persisted here for analysis and comparison over time. |
|
|
37
|
+
| `observability` | Telemetry data including traces and spans. Agent interactions, tool calls, and LLM requests generate spans collected into traces for debugging and performance analysis. |
|
|
38
|
+
| `agents` | Agent configurations for stored agents. Enables agents to be defined and updated at runtime without code deployments. |
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
### Basic composition
|
|
43
|
+
|
|
44
|
+
Import domain classes directly from each store package and compose them:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { MastraStorage } from "@mastra/core/storage";
|
|
48
|
+
import { WorkflowsPG, ScoresPG } from "@mastra/pg";
|
|
49
|
+
import { MemoryLibSQL } from "@mastra/libsql";
|
|
50
|
+
import { Mastra } from "@mastra/core";
|
|
51
|
+
|
|
52
|
+
const mastra = new Mastra({
|
|
53
|
+
storage: new MastraStorage({
|
|
54
|
+
id: "composite",
|
|
55
|
+
domains: {
|
|
56
|
+
memory: new MemoryLibSQL({ url: "file:./local.db" }),
|
|
57
|
+
workflows: new WorkflowsPG({ connectionString: process.env.DATABASE_URL }),
|
|
58
|
+
scores: new ScoresPG({ connectionString: process.env.DATABASE_URL }),
|
|
59
|
+
},
|
|
60
|
+
}),
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### With a default storage
|
|
65
|
+
|
|
66
|
+
Use `default` to specify a fallback storage, then override specific domains:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { MastraStorage } from "@mastra/core/storage";
|
|
70
|
+
import { PostgresStore } from "@mastra/pg";
|
|
71
|
+
import { MemoryLibSQL } from "@mastra/libsql";
|
|
72
|
+
import { Mastra } from "@mastra/core";
|
|
73
|
+
|
|
74
|
+
const pgStore = new PostgresStore({
|
|
75
|
+
id: "pg",
|
|
76
|
+
connectionString: process.env.DATABASE_URL,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const mastra = new Mastra({
|
|
80
|
+
storage: new MastraStorage({
|
|
81
|
+
id: "composite",
|
|
82
|
+
default: pgStore,
|
|
83
|
+
domains: {
|
|
84
|
+
memory: new MemoryLibSQL({ url: "file:./local.db" }),
|
|
85
|
+
},
|
|
86
|
+
}),
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Options
|
|
91
|
+
|
|
92
|
+
## Initialization
|
|
93
|
+
|
|
94
|
+
MastraStorage initializes each configured domain independently. When passed to the Mastra class, `init()` is called automatically:
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { MastraStorage } from "@mastra/core/storage";
|
|
98
|
+
import { MemoryPG, WorkflowsPG, ScoresPG } from "@mastra/pg";
|
|
99
|
+
import { Mastra } from "@mastra/core";
|
|
100
|
+
|
|
101
|
+
const storage = new MastraStorage({
|
|
102
|
+
id: "composite",
|
|
103
|
+
domains: {
|
|
104
|
+
memory: new MemoryPG({ connectionString: process.env.DATABASE_URL }),
|
|
105
|
+
workflows: new WorkflowsPG({ connectionString: process.env.DATABASE_URL }),
|
|
106
|
+
scores: new ScoresPG({ connectionString: process.env.DATABASE_URL }),
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const mastra = new Mastra({
|
|
111
|
+
storage, // init() called automatically
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
If using storage directly, call `init()` explicitly:
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import { MastraStorage } from "@mastra/core/storage";
|
|
119
|
+
import { MemoryPG } from "@mastra/pg";
|
|
120
|
+
|
|
121
|
+
const storage = new MastraStorage({
|
|
122
|
+
id: "composite",
|
|
123
|
+
domains: {
|
|
124
|
+
memory: new MemoryPG({ connectionString: process.env.DATABASE_URL }),
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
await storage.init();
|
|
129
|
+
|
|
130
|
+
// Access domain-specific stores via getStore()
|
|
131
|
+
const memoryStore = await storage.getStore("memory");
|
|
132
|
+
const thread = await memoryStore?.getThreadById({ threadId: "..." });
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Use Cases
|
|
136
|
+
|
|
137
|
+
### Separate databases for different workloads
|
|
138
|
+
|
|
139
|
+
Use a local database for development while keeping production data in a managed service:
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
import { MastraStorage } from "@mastra/core/storage";
|
|
143
|
+
import { MemoryPG, WorkflowsPG, ScoresPG } from "@mastra/pg";
|
|
144
|
+
import { MemoryLibSQL } from "@mastra/libsql";
|
|
145
|
+
|
|
146
|
+
const storage = new MastraStorage({
|
|
147
|
+
id: "composite",
|
|
148
|
+
domains: {
|
|
149
|
+
// Use local SQLite for development, PostgreSQL for production
|
|
150
|
+
memory:
|
|
151
|
+
process.env.NODE_ENV === "development"
|
|
152
|
+
? new MemoryLibSQL({ url: "file:./dev.db" })
|
|
153
|
+
: new MemoryPG({ connectionString: process.env.DATABASE_URL }),
|
|
154
|
+
workflows: new WorkflowsPG({ connectionString: process.env.DATABASE_URL }),
|
|
155
|
+
scores: new ScoresPG({ connectionString: process.env.DATABASE_URL }),
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Specialized storage for observability
|
|
161
|
+
|
|
162
|
+
Use a time-series database for traces while keeping other data in PostgreSQL:
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { MastraStorage } from "@mastra/core/storage";
|
|
166
|
+
import { MemoryPG, WorkflowsPG, ScoresPG } from "@mastra/pg";
|
|
167
|
+
import { ObservabilityStorageClickhouse } from "@mastra/clickhouse";
|
|
168
|
+
|
|
169
|
+
const storage = new MastraStorage({
|
|
170
|
+
id: "composite",
|
|
171
|
+
domains: {
|
|
172
|
+
memory: new MemoryPG({ connectionString: process.env.DATABASE_URL }),
|
|
173
|
+
workflows: new WorkflowsPG({ connectionString: process.env.DATABASE_URL }),
|
|
174
|
+
scores: new ScoresPG({ connectionString: process.env.DATABASE_URL }),
|
|
175
|
+
observability: new ObservabilityStorageClickhouse({
|
|
176
|
+
url: process.env.CLICKHOUSE_URL,
|
|
177
|
+
username: process.env.CLICKHOUSE_USERNAME,
|
|
178
|
+
password: process.env.CLICKHOUSE_PASSWORD,
|
|
179
|
+
}),
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
```
|
package/dist/index.cjs
CHANGED
|
@@ -563,12 +563,14 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
|
|
|
563
563
|
}
|
|
564
564
|
if (filter?.dateRange?.start) {
|
|
565
565
|
const startDate = filter.dateRange.start instanceof Date ? filter.dateRange.start.toISOString() : new Date(filter.dateRange.start).toISOString();
|
|
566
|
-
|
|
566
|
+
const startOp = filter.dateRange.startExclusive ? ">" : ">=";
|
|
567
|
+
dataQuery += ` AND createdAt ${startOp} parseDateTime64BestEffort({fromDate:String}, 3)`;
|
|
567
568
|
dataParams.fromDate = startDate;
|
|
568
569
|
}
|
|
569
570
|
if (filter?.dateRange?.end) {
|
|
570
571
|
const endDate = filter.dateRange.end instanceof Date ? filter.dateRange.end.toISOString() : new Date(filter.dateRange.end).toISOString();
|
|
571
|
-
|
|
572
|
+
const endOp = filter.dateRange.endExclusive ? "<" : "<=";
|
|
573
|
+
dataQuery += ` AND createdAt ${endOp} parseDateTime64BestEffort({toDate:String}, 3)`;
|
|
572
574
|
dataParams.toDate = endDate;
|
|
573
575
|
}
|
|
574
576
|
const { field, direction } = this.parseOrderBy(orderBy, "ASC");
|
|
@@ -602,12 +604,14 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
|
|
|
602
604
|
}
|
|
603
605
|
if (filter?.dateRange?.start) {
|
|
604
606
|
const startDate = filter.dateRange.start instanceof Date ? filter.dateRange.start.toISOString() : new Date(filter.dateRange.start).toISOString();
|
|
605
|
-
|
|
607
|
+
const startOp = filter.dateRange.startExclusive ? ">" : ">=";
|
|
608
|
+
countQuery += ` AND createdAt ${startOp} parseDateTime64BestEffort({fromDate:String}, 3)`;
|
|
606
609
|
countParams.fromDate = startDate;
|
|
607
610
|
}
|
|
608
611
|
if (filter?.dateRange?.end) {
|
|
609
612
|
const endDate = filter.dateRange.end instanceof Date ? filter.dateRange.end.toISOString() : new Date(filter.dateRange.end).toISOString();
|
|
610
|
-
|
|
613
|
+
const endOp = filter.dateRange.endExclusive ? "<" : "<=";
|
|
614
|
+
countQuery += ` AND createdAt ${endOp} parseDateTime64BestEffort({toDate:String}, 3)`;
|
|
611
615
|
countParams.toDate = endDate;
|
|
612
616
|
}
|
|
613
617
|
const countResult = await this.client.query({
|