@mastra/clickhouse 1.12.0-alpha.0 → 1.13.0-alpha.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/CHANGELOG.md +38 -6
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-storage-clickhouse.md +1 -1
- package/dist/index.cjs +21 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +22 -2
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +13 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# @mastra/clickhouse
|
|
2
2
|
|
|
3
|
+
## 1.13.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added exact metadata filtering to message history queries across Memory APIs and supported storage providers. ([#19991](https://github.com/mastra-ai/mastra/pull/19991))
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const messages = await memory.recall({
|
|
11
|
+
threadId: 'thread-1',
|
|
12
|
+
filter: {
|
|
13
|
+
metadata: {
|
|
14
|
+
status: 'done',
|
|
15
|
+
priority: 'high',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Multiple fields use AND semantics. Supported values are strings, finite numbers, booleans, and `null`.
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [[`0dca9d0`](https://github.com/mastra-ai/mastra/commit/0dca9d0b1356024a53b72ea6f040db528b126caa)]:
|
|
26
|
+
- @mastra/core@1.54.0-alpha.0
|
|
27
|
+
|
|
28
|
+
## 1.12.0
|
|
29
|
+
|
|
30
|
+
### Minor Changes
|
|
31
|
+
|
|
32
|
+
- Added legacy-to-VNext span migration for ClickHouse observability storage. Customers using `ObservabilityStorageClickhouse` (legacy) can now run `npx mastra migrate` to copy historical spans from `mastra_ai_spans` to the VNext `mastra_span_events` schema. The migration handles column mapping, batches by day for memory safety, deduplicates legacy rows, converts empty-string parentSpanId to NULL for correct root span detection, and supports both old (`Nullable(String)` JSON) and new (`Array(String)`) tags schemas. The legacy table is preserved as a backup after migration. ([#19050](https://github.com/mastra-ai/mastra/pull/19050))
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- Updated dependencies [[`bd6d240`](https://github.com/mastra-ai/mastra/commit/bd6d2402db93dddaef0721667e7e8a030e7c6e16), [`0111486`](https://github.com/mastra-ai/mastra/commit/01114867612593eef5cfa2fda6a1194dfedda841), [`96a3749`](https://github.com/mastra-ai/mastra/commit/96a37492235f5b8076b3e3177d83ed5a5e44a640), [`fe1bda0`](https://github.com/mastra-ai/mastra/commit/fe1bda06f6af92a694a51712db747cda1e7185f0), [`25e7c12`](https://github.com/mastra-ai/mastra/commit/25e7c126a770069ae7fb7ecf1d2adb40e017b009), [`1ce5121`](https://github.com/mastra-ai/mastra/commit/1ce512155d122bb21f47d98383e82ffbf84b39e8), [`fb8aea3`](https://github.com/mastra-ai/mastra/commit/fb8aea384291e77311be3a64ee1717320d5c3c73), [`4adc391`](https://github.com/mastra-ai/mastra/commit/4adc3911075249c352bb4832d2471922826344de), [`a5c6337`](https://github.com/mastra-ai/mastra/commit/a5c6337d23c7686c81a32ce62f550f610543a240), [`3cfc47a`](https://github.com/mastra-ai/mastra/commit/3cfc47a6b89940aadd0f46fb01ae9624a73a865d), [`2bb7817`](https://github.com/mastra-ai/mastra/commit/2bb78176112fde628483de2830528f7eee911e56), [`51d9870`](https://github.com/mastra-ai/mastra/commit/51d987032c689c2855374d0f244f5d654da809d1), [`5cab274`](https://github.com/mastra-ai/mastra/commit/5cab2744250e22d12fefa7b32637dce224233cee), [`7fa27d3`](https://github.com/mastra-ai/mastra/commit/7fa27d3b6f5ed68cd34e454a4d3ad9c482a0cfbc), [`8b97958`](https://github.com/mastra-ai/mastra/commit/8b979589f9aa59ba67cac565949475f2ffeb4ac3), [`8410541`](https://github.com/mastra-ai/mastra/commit/84105412c60ecd3bb33a9838146f59c4b588228f), [`a58dcbb`](https://github.com/mastra-ai/mastra/commit/a58dcbb546d7e1d65ebdc1f39e55f0908fcd9391), [`aa38805`](https://github.com/mastra-ai/mastra/commit/aa38805b878b827403be785eb90688d7172f5a40), [`153bd3b`](https://github.com/mastra-ai/mastra/commit/153bd3b396bdfed6b74cf43de12db8fd2d83c04a), [`45a8e65`](https://github.com/mastra-ai/mastra/commit/45a8e65e1556d1362cb3f25187023c36de26661d), [`e955965`](https://github.com/mastra-ai/mastra/commit/e955965dce575a903e37cf054d28ea99aa48785e), [`2d22570`](https://github.com/mastra-ai/mastra/commit/2d22570c7dfdd02123d0ecc529efb05ccba2d9fc), [`07bb863`](https://github.com/mastra-ai/mastra/commit/07bb8631919c6f7cf377dccd45b096e0f17fbed0), [`c8ed116`](https://github.com/mastra-ai/mastra/commit/c8ed11699f62bcac70102ab4ec84d80d20541da6), [`01b338c`](https://github.com/mastra-ai/mastra/commit/01b338c56271f0219606710e3e8b26dee27ac6c2), [`a99eae8`](https://github.com/mastra-ai/mastra/commit/a99eae8908e500c1b2d12f9d277be616b98617a5), [`860ef7e`](https://github.com/mastra-ai/mastra/commit/860ef7e77d92b63469cbe5857aa1e626197e43e9), [`17e818c`](https://github.com/mastra-ai/mastra/commit/17e818c51a958ba90641b1a959dc38faf8c034e9), [`edce8d2`](https://github.com/mastra-ai/mastra/commit/edce8d2769f19e27a05737c627af2d765472a4f8), [`8a586ec`](https://github.com/mastra-ai/mastra/commit/8a586eca9a4914f31dff6140d0d45ac375b00669), [`4451dfe`](https://github.com/mastra-ai/mastra/commit/4451dfe857428e7abcc0261a507a2e186dae6d47), [`8b7361d`](https://github.com/mastra-ai/mastra/commit/8b7361d35de68b80d05d30a74e0c69e7218fd612), [`1d39058`](https://github.com/mastra-ai/mastra/commit/1d39058e548efd691799985d5c8af2737f1c3bd2), [`3927473`](https://github.com/mastra-ai/mastra/commit/392747323ddb10c643d12be7b9ae913159dfaeed), [`dce50dc`](https://github.com/mastra-ai/mastra/commit/dce50dc9a1c1fcd0f427bb5f6250ec74910cb04b), [`fd13f8e`](https://github.com/mastra-ai/mastra/commit/fd13f8e21990f9904c3eedba3a626bb4a929cdb8), [`634caff`](https://github.com/mastra-ai/mastra/commit/634caff29a9200ad058b67d53f96d9e5832fb8a2), [`f703f87`](https://github.com/mastra-ai/mastra/commit/f703f878de072d51fda557f9c50867d8252bef05), [`3e26c87`](https://github.com/mastra-ai/mastra/commit/3e26c87de0c5bc2583b795ce6ca5889b6b161acb), [`33f2b88`](https://github.com/mastra-ai/mastra/commit/33f2b88842c09a567f906fac4cb61cd5277ced59), [`177010f`](https://github.com/mastra-ai/mastra/commit/177010ff096d2e4b28d89803be5b1a4cad2a0d6b), [`0ad646f`](https://github.com/mastra-ai/mastra/commit/0ad646f71a530f2454664299e5e01bfd13fa12e5), [`b486abf`](https://github.com/mastra-ai/mastra/commit/b486abfa2a7528c6f527e4015c819ea9fa54aaad), [`54a51e0`](https://github.com/mastra-ai/mastra/commit/54a51e0a484fe1ebad3fb1f7ef5282a075709eb7), [`c43f3a9`](https://github.com/mastra-ai/mastra/commit/c43f3a9d1efde99b38789364ba4d0ba670f430e3), [`a5008f2`](https://github.com/mastra-ai/mastra/commit/a5008f22ae710ad9402ea9f2547d8c02f74d384b), [`e2d5f37`](https://github.com/mastra-ai/mastra/commit/e2d5f373bd289be534d5f8694d34465010533df6), [`4ce0163`](https://github.com/mastra-ai/mastra/commit/4ce0163dc86e675a86809685c8ce6c49f1aeb87e), [`4378341`](https://github.com/mastra-ai/mastra/commit/43783412df5ea3dd35f5b1f6e4851e79c346fc89)]:
|
|
37
|
+
- @mastra/core@1.51.0
|
|
38
|
+
|
|
3
39
|
## 1.12.0-alpha.0
|
|
4
40
|
|
|
5
41
|
### Minor Changes
|
|
@@ -282,9 +318,7 @@
|
|
|
282
318
|
**Example**
|
|
283
319
|
|
|
284
320
|
```ts
|
|
285
|
-
const storage = new LibSQLStore({
|
|
286
|
-
/* config */
|
|
287
|
-
});
|
|
321
|
+
const storage = new LibSQLStore({/* config */});
|
|
288
322
|
const favorites = await storage.getStore('favorites');
|
|
289
323
|
|
|
290
324
|
await favorites?.favorite({
|
|
@@ -310,9 +344,7 @@
|
|
|
310
344
|
**Example**
|
|
311
345
|
|
|
312
346
|
```ts
|
|
313
|
-
const storage = new LibSQLStore({
|
|
314
|
-
/* config */
|
|
315
|
-
});
|
|
347
|
+
const storage = new LibSQLStore({/* config */});
|
|
316
348
|
const favorites = await storage.getStore('favorites');
|
|
317
349
|
|
|
318
350
|
await favorites?.favorite({
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-clickhouse
|
|
|
3
3
|
description: Documentation for @mastra/clickhouse. Use when working with @mastra/clickhouse APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/clickhouse"
|
|
6
|
-
version: "1.
|
|
6
|
+
version: "1.13.0-alpha.0"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -131,7 +131,7 @@ bun x mastra migrate
|
|
|
131
131
|
|
|
132
132
|
The migration copies span data from `mastra_ai_spans` into `mastra_span_events` in day-sized batches. It handles column mapping, deduplicates legacy rows, and preserves the original table as a backup. After migration, traces appear in Studio through the vNext adapter.
|
|
133
133
|
|
|
134
|
-
> **Note:** The legacy table
|
|
134
|
+
> **Note:** The legacy table isn't deleted. Drop it manually after verifying the migration.
|
|
135
135
|
|
|
136
136
|
### ClickHouse for every domain
|
|
137
137
|
|
package/dist/index.cjs
CHANGED
|
@@ -1092,6 +1092,23 @@ function parseMetadata(metadata) {
|
|
|
1092
1092
|
return {};
|
|
1093
1093
|
}
|
|
1094
1094
|
}
|
|
1095
|
+
function appendClickhouseMessageMetadataFilter(query, params, metadataFilter) {
|
|
1096
|
+
if (!metadataFilter) return query;
|
|
1097
|
+
let nextQuery = query;
|
|
1098
|
+
Object.entries(metadataFilter).forEach(([key, value], index) => {
|
|
1099
|
+
const keyParam = `metadataKey${index}`;
|
|
1100
|
+
params[keyParam] = key;
|
|
1101
|
+
nextQuery += ` AND isValidJSON(content) AND JSONHas(content, 'metadata') AND JSONHas(JSONExtractRaw(content, 'metadata'), {${keyParam}:String})`;
|
|
1102
|
+
if (value === null) {
|
|
1103
|
+
nextQuery += ` AND JSONExtractRaw(content, 'metadata', {${keyParam}:String}) = 'null'`;
|
|
1104
|
+
return;
|
|
1105
|
+
}
|
|
1106
|
+
const valueParam = `metadataValue${index}`;
|
|
1107
|
+
params[valueParam] = JSON.stringify(value);
|
|
1108
|
+
nextQuery += ` AND JSONExtractRaw(content, 'metadata', {${keyParam}:String}) = {${valueParam}:String}`;
|
|
1109
|
+
});
|
|
1110
|
+
return nextQuery;
|
|
1111
|
+
}
|
|
1095
1112
|
var MemoryStorageClickhouse = class extends storage.MemoryStorage {
|
|
1096
1113
|
client;
|
|
1097
1114
|
#db;
|
|
@@ -1203,6 +1220,7 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
|
|
|
1203
1220
|
}
|
|
1204
1221
|
async listMessages(args) {
|
|
1205
1222
|
const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
|
|
1223
|
+
const metadataFilter = storage.validateStorageMetadataFilter(filter?.metadata);
|
|
1206
1224
|
const rawThreadIds = Array.isArray(threadId) ? threadId : [threadId];
|
|
1207
1225
|
const threadIds = rawThreadIds.filter((id) => id !== void 0 && id !== null).map((id) => (typeof id === "string" ? id : String(id)).trim()).filter((id) => id.length > 0);
|
|
1208
1226
|
if (page < 0) {
|
|
@@ -1263,6 +1281,7 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
|
|
|
1263
1281
|
dataQuery += ` AND createdAt ${endOp} parseDateTime64BestEffort({toDate:String}, 3)`;
|
|
1264
1282
|
dataParams.toDate = endDate;
|
|
1265
1283
|
}
|
|
1284
|
+
dataQuery = appendClickhouseMessageMetadataFilter(dataQuery, dataParams, metadataFilter);
|
|
1266
1285
|
const { field, direction } = this.parseOrderBy(orderBy, "ASC");
|
|
1267
1286
|
dataQuery += ` ORDER BY "${field}" ${direction}`;
|
|
1268
1287
|
if (perPageForQuery === 0 && (!include || include.length === 0)) {
|
|
@@ -1318,6 +1337,7 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
|
|
|
1318
1337
|
countQuery += ` AND createdAt ${endOp} parseDateTime64BestEffort({toDate:String}, 3)`;
|
|
1319
1338
|
countParams.toDate = endDate;
|
|
1320
1339
|
}
|
|
1340
|
+
countQuery = appendClickhouseMessageMetadataFilter(countQuery, countParams, metadataFilter);
|
|
1321
1341
|
const countResult = await this.client.query({
|
|
1322
1342
|
query: countQuery,
|
|
1323
1343
|
query_params: countParams,
|
|
@@ -1356,7 +1376,7 @@ var MemoryStorageClickhouse = class extends storage.MemoryStorage {
|
|
|
1356
1376
|
finalMessages.filter((m) => m.threadId && threadIdSet.has(m.threadId)).map((m) => m.id)
|
|
1357
1377
|
);
|
|
1358
1378
|
const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
|
|
1359
|
-
const hasMore = perPageForResponse === false ? false : allThreadMessagesReturned ? false : offset + paginatedCount < total;
|
|
1379
|
+
const hasMore = metadataFilter && perPageForResponse !== false ? offset + paginatedCount < total : perPageForResponse === false ? false : allThreadMessagesReturned ? false : offset + paginatedCount < total;
|
|
1360
1380
|
return {
|
|
1361
1381
|
messages: finalMessages,
|
|
1362
1382
|
total,
|