@mastra/clickhouse 1.16.0-alpha.1 → 1.16.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 +32 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +2 -226
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -227
- package/dist/index.js.map +1 -1
- package/dist/storage/index.d.ts +1 -2
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/storage/domains/background-tasks/index.d.ts +0 -21
- package/dist/storage/domains/background-tasks/index.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @mastra/clickhouse
|
|
2
2
|
|
|
3
|
+
## 1.16.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added support for filtering scores by metadata key-value pairs in listScores. ([#22047](https://github.com/mastra-ai/mastra/pull/22047))
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
const result = await storage.listScores({
|
|
11
|
+
filters: { metadata: { env: 'prod' } },
|
|
12
|
+
});
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Each top-level metadata key is matched with exact equality against the stored value. Nested objects and arrays compare structurally (key order doesn't matter) with no partial/subset matching, and an empty metadata filter is a no-op.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Fixed ClickHouse observability discovery refreshable materialized views failing with error 36 when their target tables use a Replicated engine inside a non-Replicated (Atomic) database. The discovery views now refresh in APPEND mode, and existing deployments with the old view definitions are migrated automatically on startup (only the views are recreated; discovery data is kept). Fixes https://github.com/mastra-ai/mastra/issues/21168 ([#22103](https://github.com/mastra-ai/mastra/pull/22103))
|
|
20
|
+
|
|
21
|
+
- Enforce atomic conditional background task state updates so cancellation cannot be overwritten during dispatch. Background task storage is no longer exposed by Cloudflare KV or ClickHouse, which cannot provide the required compare-and-set semantics. ([#22228](https://github.com/mastra-ai/mastra/pull/22228))
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [[`79f04a7`](https://github.com/mastra-ai/mastra/commit/79f04a7f6c6829da541139f638f2f1d267916e08), [`65edab1`](https://github.com/mastra-ai/mastra/commit/65edab1c233d17b8f163bad12fca410d0e6f16b1), [`1e47b75`](https://github.com/mastra-ai/mastra/commit/1e47b7520cab4cfaa8daed52f17e2e6d14ff7539), [`ab20a38`](https://github.com/mastra-ai/mastra/commit/ab20a38d0275f8d85e0f3833bd87ef487bcc609f), [`fd4d5fe`](https://github.com/mastra-ai/mastra/commit/fd4d5fe4f943699b85db5e74404f190d5a6b8c2a), [`ae8790c`](https://github.com/mastra-ai/mastra/commit/ae8790c4bfaa088d2ab279d1dcc06f326b9fd109), [`2c85f42`](https://github.com/mastra-ai/mastra/commit/2c85f428e04ccd63ea31a7ec80b5b327afdad555), [`11bbeb9`](https://github.com/mastra-ai/mastra/commit/11bbeb9b108ef2264e05acefc6dafb9cbb342921), [`48ef1f1`](https://github.com/mastra-ai/mastra/commit/48ef1f1d24eedafbb07f64e659a81b52b67b8bf6), [`aa3a85d`](https://github.com/mastra-ai/mastra/commit/aa3a85daf094c683bb97efdf4b6a696d2e474af5), [`d29d06f`](https://github.com/mastra-ai/mastra/commit/d29d06fe00bbd35b4571150ea04c59d2ed783c71), [`e6516df`](https://github.com/mastra-ai/mastra/commit/e6516dfcdae4f4ac0e7971d84359a81385ee602f), [`1a485f3`](https://github.com/mastra-ai/mastra/commit/1a485f3538f5ec64d58bd8b5e1e99de0c695c87b), [`0d37487`](https://github.com/mastra-ai/mastra/commit/0d37487d9f349388a3f1cef6a536cf9dcc4b6273), [`8661d7d`](https://github.com/mastra-ai/mastra/commit/8661d7d7179f0a024456aabdd8679bcecd09ac28), [`dbbfeb8`](https://github.com/mastra-ai/mastra/commit/dbbfeb85ec949dc9ebc0755e1ad262e4f5eba8db), [`575e343`](https://github.com/mastra-ai/mastra/commit/575e343900451021d96110916497d334af7bc252), [`0b2a3d1`](https://github.com/mastra-ai/mastra/commit/0b2a3d1783875c5b97b7b36ab3d03d7360e0dde7), [`6bb5d71`](https://github.com/mastra-ai/mastra/commit/6bb5d7193fe9166b219f0fccae17db7a5ae86e65), [`3cc9d00`](https://github.com/mastra-ai/mastra/commit/3cc9d00b2b4333e0377a5e9df5eff92c17ce7630), [`cacb839`](https://github.com/mastra-ai/mastra/commit/cacb8392d9e74189b56d857290b0615f98a2683d), [`57de7d6`](https://github.com/mastra-ai/mastra/commit/57de7d644ba7146edb4e9e6111ec4fa98c3a59e9), [`c8e4cea`](https://github.com/mastra-ai/mastra/commit/c8e4ceac9a390d78c8327dff3cdb2861dd71957f), [`ed01e9a`](https://github.com/mastra-ai/mastra/commit/ed01e9a807514a904374bf687a7b8f18750f6f78), [`b47b26e`](https://github.com/mastra-ai/mastra/commit/b47b26e6fe95cb8a3482be2c5e52de157fe59d0b), [`0d37487`](https://github.com/mastra-ai/mastra/commit/0d37487d9f349388a3f1cef6a536cf9dcc4b6273), [`733a537`](https://github.com/mastra-ai/mastra/commit/733a537489a858b5880b2e98809334fba895a221), [`e8e299c`](https://github.com/mastra-ai/mastra/commit/e8e299cc6abdfc39947e2fec25803493015d3882), [`edfc548`](https://github.com/mastra-ai/mastra/commit/edfc548886bc7bae17b681f8b6b41a47eb32bcd2), [`b05f486`](https://github.com/mastra-ai/mastra/commit/b05f48612984d5fe2447ea2d6cdd5c604d285b97), [`a8a4871`](https://github.com/mastra-ai/mastra/commit/a8a4871215f51da95c47129602157ce5372f634a), [`eb9ecaa`](https://github.com/mastra-ai/mastra/commit/eb9ecaa89c36e889749e3b825cfc507ce7f7980b), [`4ff3ee2`](https://github.com/mastra-ai/mastra/commit/4ff3ee2bff7ed07528b4817f8f49639031c72a4d), [`9207dfa`](https://github.com/mastra-ai/mastra/commit/9207dfab8062e5fc68b751684797ff86fe0b4e70), [`5165cdc`](https://github.com/mastra-ai/mastra/commit/5165cdcdcf50e144bb8113278535196cc9b07065), [`e737014`](https://github.com/mastra-ai/mastra/commit/e737014e0fc7035759762bb5b48baef1d6c0f6a7), [`6bb5d71`](https://github.com/mastra-ai/mastra/commit/6bb5d7193fe9166b219f0fccae17db7a5ae86e65), [`f591643`](https://github.com/mastra-ai/mastra/commit/f591643becdf0be9bddce6ba1748e64bc30d77f1), [`63796ba`](https://github.com/mastra-ai/mastra/commit/63796ba0fda60253be17535e68f6bbbf1e6ffa09), [`b1ad324`](https://github.com/mastra-ai/mastra/commit/b1ad324d657f3544b0701332aef7eb10e9a36258), [`61c566d`](https://github.com/mastra-ai/mastra/commit/61c566dd2f2cde2b23ed8f139924e530d4202214), [`c24754c`](https://github.com/mastra-ai/mastra/commit/c24754c1fb6fe144e5051e536e98c8a18b0214ac), [`12c61d2`](https://github.com/mastra-ai/mastra/commit/12c61d280c8cb208bc3c8dbcbe5dcc60cf9d1cd0), [`c46eb09`](https://github.com/mastra-ai/mastra/commit/c46eb09ce4987509af57a0ac582c61241a6dd2f1), [`9ee8120`](https://github.com/mastra-ai/mastra/commit/9ee8120ce17f76b9f617489e05a283353742690a), [`d975e92`](https://github.com/mastra-ai/mastra/commit/d975e924d4936f46c386bd3dee39c671720289f6), [`45dd6ee`](https://github.com/mastra-ai/mastra/commit/45dd6ee089bd7df0d0c98a10098e483fd388e04a), [`4e9a228`](https://github.com/mastra-ai/mastra/commit/4e9a2283d5fd6ed1b70a2751eb3dc2cbf82ada20), [`d6ce34a`](https://github.com/mastra-ai/mastra/commit/d6ce34aeceb06ddf3d595a1eed5cc74f481a46a1), [`f95f468`](https://github.com/mastra-ai/mastra/commit/f95f468cf1e7c2b924a13826494f98b8f2ccd581), [`30ed33e`](https://github.com/mastra-ai/mastra/commit/30ed33ee14084a26019aba15fceadda6d6ddefaf), [`04a815f`](https://github.com/mastra-ai/mastra/commit/04a815fc8971d29e97fcdcc5008a1eb472fc00ff), [`1cfa878`](https://github.com/mastra-ai/mastra/commit/1cfa8784d8da0dfaa0317e5048bc48b6084a5ea5), [`9a12ef3`](https://github.com/mastra-ai/mastra/commit/9a12ef3fccf3f4186db0f294f4ee1f02cf4d8db2), [`32d3583`](https://github.com/mastra-ai/mastra/commit/32d358332cb8ac2306b83b73cf3536e74dbd435e), [`7960688`](https://github.com/mastra-ai/mastra/commit/7960688828e04eaf3106e34f7758fa580257eef6), [`91ad69d`](https://github.com/mastra-ai/mastra/commit/91ad69d64994c89199b0c55399e64ed91c61df2f), [`8dc408d`](https://github.com/mastra-ai/mastra/commit/8dc408d34438f9e13297f792c11a5cfd6cf952e1), [`c92def1`](https://github.com/mastra-ai/mastra/commit/c92def10a13c822972c96f0a4ca6ffc1f4258aed), [`63041eb`](https://github.com/mastra-ai/mastra/commit/63041eb4c50b520a0a80e03d4cd6ea99f67715a0), [`c118318`](https://github.com/mastra-ai/mastra/commit/c1183181c9804303db4b511c2e2648f8b714712b), [`c5eaec5`](https://github.com/mastra-ai/mastra/commit/c5eaec5a860d80d0e3805e67db0414b87ac8cbed), [`fc07c64`](https://github.com/mastra-ai/mastra/commit/fc07c6465043e08e99193a6751a01c56ffc2e7a1), [`cced745`](https://github.com/mastra-ai/mastra/commit/cced745a056ec2225c5bc702e32d848847aa8b65), [`542dee2`](https://github.com/mastra-ai/mastra/commit/542dee254167f974ff8cbbbfc0ce10f9a2616a7b), [`3c19dce`](https://github.com/mastra-ai/mastra/commit/3c19dcef8e73062a80627a4927eae3ec11145afd), [`aca2869`](https://github.com/mastra-ai/mastra/commit/aca2869b2031982f3c4a2f52525c9be7cf123ef8), [`a58483c`](https://github.com/mastra-ai/mastra/commit/a58483cff1a9d41fce7c931843f48cb0ac450f64), [`a58483c`](https://github.com/mastra-ai/mastra/commit/a58483cff1a9d41fce7c931843f48cb0ac450f64), [`e6f8450`](https://github.com/mastra-ai/mastra/commit/e6f845074d478527026b18d85031b23353e1d0a4), [`895e9df`](https://github.com/mastra-ai/mastra/commit/895e9dfc17d6f34299eca64e317ded9e5f5e5ef8), [`e66b2ba`](https://github.com/mastra-ai/mastra/commit/e66b2ba100db63eaeab6e21e1ea34b113f2ec781), [`3e8727e`](https://github.com/mastra-ai/mastra/commit/3e8727e11ec1a5d733acedb5c872896394be18c1)]:
|
|
24
|
+
- @mastra/core@1.62.0
|
|
25
|
+
|
|
26
|
+
## 1.16.0-alpha.2
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- Enforce atomic conditional background task state updates so cancellation cannot be overwritten during dispatch. Background task storage is no longer exposed by Cloudflare KV or ClickHouse, which cannot provide the required compare-and-set semantics. ([#22228](https://github.com/mastra-ai/mastra/pull/22228))
|
|
31
|
+
|
|
32
|
+
- Updated dependencies [[`aa3a85d`](https://github.com/mastra-ai/mastra/commit/aa3a85daf094c683bb97efdf4b6a696d2e474af5), [`d29d06f`](https://github.com/mastra-ai/mastra/commit/d29d06fe00bbd35b4571150ea04c59d2ed783c71), [`e6516df`](https://github.com/mastra-ai/mastra/commit/e6516dfcdae4f4ac0e7971d84359a81385ee602f), [`0b2a3d1`](https://github.com/mastra-ai/mastra/commit/0b2a3d1783875c5b97b7b36ab3d03d7360e0dde7), [`6bb5d71`](https://github.com/mastra-ai/mastra/commit/6bb5d7193fe9166b219f0fccae17db7a5ae86e65), [`57de7d6`](https://github.com/mastra-ai/mastra/commit/57de7d644ba7146edb4e9e6111ec4fa98c3a59e9), [`e8e299c`](https://github.com/mastra-ai/mastra/commit/e8e299cc6abdfc39947e2fec25803493015d3882), [`edfc548`](https://github.com/mastra-ai/mastra/commit/edfc548886bc7bae17b681f8b6b41a47eb32bcd2), [`a8a4871`](https://github.com/mastra-ai/mastra/commit/a8a4871215f51da95c47129602157ce5372f634a), [`5165cdc`](https://github.com/mastra-ai/mastra/commit/5165cdcdcf50e144bb8113278535196cc9b07065), [`6bb5d71`](https://github.com/mastra-ai/mastra/commit/6bb5d7193fe9166b219f0fccae17db7a5ae86e65), [`9ee8120`](https://github.com/mastra-ai/mastra/commit/9ee8120ce17f76b9f617489e05a283353742690a), [`d975e92`](https://github.com/mastra-ai/mastra/commit/d975e924d4936f46c386bd3dee39c671720289f6), [`1cfa878`](https://github.com/mastra-ai/mastra/commit/1cfa8784d8da0dfaa0317e5048bc48b6084a5ea5), [`c118318`](https://github.com/mastra-ai/mastra/commit/c1183181c9804303db4b511c2e2648f8b714712b), [`fc07c64`](https://github.com/mastra-ai/mastra/commit/fc07c6465043e08e99193a6751a01c56ffc2e7a1), [`542dee2`](https://github.com/mastra-ai/mastra/commit/542dee254167f974ff8cbbbfc0ce10f9a2616a7b), [`a58483c`](https://github.com/mastra-ai/mastra/commit/a58483cff1a9d41fce7c931843f48cb0ac450f64), [`a58483c`](https://github.com/mastra-ai/mastra/commit/a58483cff1a9d41fce7c931843f48cb0ac450f64), [`895e9df`](https://github.com/mastra-ai/mastra/commit/895e9dfc17d6f34299eca64e317ded9e5f5e5ef8)]:
|
|
33
|
+
- @mastra/core@1.62.0-alpha.8
|
|
34
|
+
|
|
3
35
|
## 1.16.0-alpha.1
|
|
4
36
|
|
|
5
37
|
### Patch Changes
|
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.16.0
|
|
6
|
+
version: "1.16.0"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
package/dist/index.cjs
CHANGED
|
@@ -2,8 +2,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
let _clickhouse_client = require("@clickhouse/client");
|
|
3
3
|
let _mastra_core_error = require("@mastra/core/error");
|
|
4
4
|
let _mastra_core_storage = require("@mastra/core/storage");
|
|
5
|
-
let _mastra_core_base = require("@mastra/core/base");
|
|
6
5
|
let _mastra_core_agent = require("@mastra/core/agent");
|
|
6
|
+
let _mastra_core_base = require("@mastra/core/base");
|
|
7
7
|
let _mastra_core_utils = require("@mastra/core/utils");
|
|
8
8
|
let _mastra_core_features = require("@mastra/core/features");
|
|
9
9
|
let _mastra_core_evals = require("@mastra/core/evals");
|
|
@@ -745,228 +745,6 @@ var ClickhouseDB = class extends _mastra_core_base.MastraBase {
|
|
|
745
745
|
}
|
|
746
746
|
};
|
|
747
747
|
//#endregion
|
|
748
|
-
//#region src/storage/domains/background-tasks/index.ts
|
|
749
|
-
function serializeJson(v) {
|
|
750
|
-
if (typeof v === "object" && v != null) return JSON.stringify(v);
|
|
751
|
-
return v ?? "";
|
|
752
|
-
}
|
|
753
|
-
function readNullableDate(val) {
|
|
754
|
-
if (val == null || val === "") return void 0;
|
|
755
|
-
const d = new Date(val);
|
|
756
|
-
if (Number.isNaN(d.getTime()) || d.getTime() === 0) return void 0;
|
|
757
|
-
return d;
|
|
758
|
-
}
|
|
759
|
-
function rowToTask(row) {
|
|
760
|
-
const parseJson = (val) => {
|
|
761
|
-
if (val == null || val === "") return void 0;
|
|
762
|
-
if (typeof val === "string") try {
|
|
763
|
-
return JSON.parse(val);
|
|
764
|
-
} catch {
|
|
765
|
-
return val;
|
|
766
|
-
}
|
|
767
|
-
return val;
|
|
768
|
-
};
|
|
769
|
-
return {
|
|
770
|
-
id: row.id,
|
|
771
|
-
status: row.status,
|
|
772
|
-
toolName: row.tool_name,
|
|
773
|
-
toolCallId: row.tool_call_id,
|
|
774
|
-
args: parseJson(row.args) ?? {},
|
|
775
|
-
agentId: row.agent_id,
|
|
776
|
-
threadId: row.thread_id || void 0,
|
|
777
|
-
resourceId: row.resource_id || void 0,
|
|
778
|
-
runId: row.run_id ?? "",
|
|
779
|
-
result: parseJson(row.result),
|
|
780
|
-
error: parseJson(row.error),
|
|
781
|
-
suspendPayload: parseJson(row.suspend_payload),
|
|
782
|
-
retryCount: Number(row.retry_count ?? 0),
|
|
783
|
-
maxRetries: Number(row.max_retries ?? 0),
|
|
784
|
-
timeoutMs: Number(row.timeout_ms ?? 3e5),
|
|
785
|
-
createdAt: new Date(row.createdAt),
|
|
786
|
-
startedAt: readNullableDate(row.startedAt),
|
|
787
|
-
suspendedAt: readNullableDate(row.suspendedAt),
|
|
788
|
-
completedAt: readNullableDate(row.completedAt)
|
|
789
|
-
};
|
|
790
|
-
}
|
|
791
|
-
var BackgroundTasksStorageClickhouse = class extends _mastra_core_storage.BackgroundTasksStorage {
|
|
792
|
-
client;
|
|
793
|
-
#db;
|
|
794
|
-
constructor(config) {
|
|
795
|
-
super();
|
|
796
|
-
const { client, ttl, replication } = resolveClickhouseConfig(config);
|
|
797
|
-
this.client = client;
|
|
798
|
-
this.#db = new ClickhouseDB({
|
|
799
|
-
client,
|
|
800
|
-
ttl,
|
|
801
|
-
replication
|
|
802
|
-
});
|
|
803
|
-
}
|
|
804
|
-
async init() {
|
|
805
|
-
await this.#db.createTable({
|
|
806
|
-
tableName: _mastra_core_storage.TABLE_BACKGROUND_TASKS,
|
|
807
|
-
schema: _mastra_core_storage.TABLE_SCHEMAS[_mastra_core_storage.TABLE_BACKGROUND_TASKS]
|
|
808
|
-
});
|
|
809
|
-
await this.#db.alterTable({
|
|
810
|
-
tableName: _mastra_core_storage.TABLE_BACKGROUND_TASKS,
|
|
811
|
-
schema: _mastra_core_storage.TABLE_SCHEMAS[_mastra_core_storage.TABLE_BACKGROUND_TASKS],
|
|
812
|
-
ifNotExists: ["suspend_payload", "suspendedAt"]
|
|
813
|
-
});
|
|
814
|
-
}
|
|
815
|
-
async dangerouslyClearAll() {
|
|
816
|
-
await this.#db.clearTable({ tableName: _mastra_core_storage.TABLE_BACKGROUND_TASKS });
|
|
817
|
-
}
|
|
818
|
-
async createTask(task) {
|
|
819
|
-
await this.client.insert({
|
|
820
|
-
table: _mastra_core_storage.TABLE_BACKGROUND_TASKS,
|
|
821
|
-
values: [{
|
|
822
|
-
id: task.id,
|
|
823
|
-
tool_call_id: task.toolCallId,
|
|
824
|
-
tool_name: task.toolName,
|
|
825
|
-
agent_id: task.agentId,
|
|
826
|
-
thread_id: task.threadId ?? "",
|
|
827
|
-
resource_id: task.resourceId ?? "",
|
|
828
|
-
run_id: task.runId,
|
|
829
|
-
status: task.status,
|
|
830
|
-
args: serializeJson(task.args),
|
|
831
|
-
result: serializeJson(task.result),
|
|
832
|
-
error: serializeJson(task.error),
|
|
833
|
-
suspend_payload: serializeJson(task.suspendPayload),
|
|
834
|
-
retry_count: task.retryCount,
|
|
835
|
-
max_retries: task.maxRetries,
|
|
836
|
-
timeout_ms: task.timeoutMs,
|
|
837
|
-
createdAt: task.createdAt.toISOString(),
|
|
838
|
-
startedAt: task.startedAt?.toISOString() ?? "1970-01-01T00:00:00.000Z",
|
|
839
|
-
suspendedAt: task.suspendedAt?.toISOString() ?? "1970-01-01T00:00:00.000Z",
|
|
840
|
-
completedAt: task.completedAt?.toISOString() ?? "1970-01-01T00:00:00.000Z"
|
|
841
|
-
}],
|
|
842
|
-
format: "JSONEachRow",
|
|
843
|
-
clickhouse_settings: { date_time_input_format: "best_effort" }
|
|
844
|
-
});
|
|
845
|
-
}
|
|
846
|
-
async updateTask(taskId, update) {
|
|
847
|
-
const existing = await this.getTask(taskId);
|
|
848
|
-
if (!existing) return;
|
|
849
|
-
const merged = { ...existing };
|
|
850
|
-
if ("status" in update) merged.status = update.status;
|
|
851
|
-
if ("result" in update) merged.result = update.result;
|
|
852
|
-
if ("error" in update) merged.error = update.error;
|
|
853
|
-
if ("suspendPayload" in update) merged.suspendPayload = update.suspendPayload;
|
|
854
|
-
if ("retryCount" in update) merged.retryCount = update.retryCount;
|
|
855
|
-
if ("startedAt" in update) merged.startedAt = update.startedAt;
|
|
856
|
-
if ("suspendedAt" in update) merged.suspendedAt = update.suspendedAt;
|
|
857
|
-
if ("completedAt" in update) merged.completedAt = update.completedAt;
|
|
858
|
-
await this.createTask(merged);
|
|
859
|
-
}
|
|
860
|
-
async getTask(taskId) {
|
|
861
|
-
const rows = await (await this.client.query({
|
|
862
|
-
query: `SELECT * FROM ${_mastra_core_storage.TABLE_BACKGROUND_TASKS} FINAL WHERE id = {var_id:String} LIMIT 1`,
|
|
863
|
-
query_params: { var_id: taskId },
|
|
864
|
-
format: "JSONEachRow",
|
|
865
|
-
clickhouse_settings: { date_time_input_format: "best_effort" }
|
|
866
|
-
})).json();
|
|
867
|
-
return rows.length > 0 ? rowToTask(rows[0]) : null;
|
|
868
|
-
}
|
|
869
|
-
buildFilterClause(filter) {
|
|
870
|
-
const conditions = [];
|
|
871
|
-
const params = {};
|
|
872
|
-
if (filter.status) {
|
|
873
|
-
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
874
|
-
conditions.push(`status IN ({var_statuses:Array(String)})`);
|
|
875
|
-
params.var_statuses = statuses;
|
|
876
|
-
}
|
|
877
|
-
if (filter.agentId) {
|
|
878
|
-
conditions.push(`agent_id = {var_agent:String}`);
|
|
879
|
-
params.var_agent = filter.agentId;
|
|
880
|
-
}
|
|
881
|
-
if (filter.threadId) {
|
|
882
|
-
conditions.push(`thread_id = {var_thread:String}`);
|
|
883
|
-
params.var_thread = filter.threadId;
|
|
884
|
-
}
|
|
885
|
-
if (filter.runId) {
|
|
886
|
-
conditions.push(`run_id = {var_run:String}`);
|
|
887
|
-
params.var_run = filter.runId;
|
|
888
|
-
}
|
|
889
|
-
if (filter.toolName) {
|
|
890
|
-
conditions.push(`tool_name = {var_tool:String}`);
|
|
891
|
-
params.var_tool = filter.toolName;
|
|
892
|
-
}
|
|
893
|
-
if (filter.toolCallId) {
|
|
894
|
-
conditions.push(`tool_call_id = {var_tool_call:String}`);
|
|
895
|
-
params.var_tool_call = filter.toolCallId;
|
|
896
|
-
}
|
|
897
|
-
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
|
|
898
|
-
if (filter.fromDate) {
|
|
899
|
-
conditions.push(`${dateCol} >= parseDateTimeBestEffort({var_from_date:String})`);
|
|
900
|
-
params.var_from_date = filter.fromDate.toISOString();
|
|
901
|
-
}
|
|
902
|
-
if (filter.toDate) {
|
|
903
|
-
conditions.push(`${dateCol} < parseDateTimeBestEffort({var_to_date:String})`);
|
|
904
|
-
params.var_to_date = filter.toDate.toISOString();
|
|
905
|
-
}
|
|
906
|
-
return {
|
|
907
|
-
where: conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "",
|
|
908
|
-
params
|
|
909
|
-
};
|
|
910
|
-
}
|
|
911
|
-
async listTasks(filter) {
|
|
912
|
-
const { where, params } = this.buildFilterClause(filter);
|
|
913
|
-
const countRows = await (await this.client.query({
|
|
914
|
-
query: `SELECT count() as count FROM ${_mastra_core_storage.TABLE_BACKGROUND_TASKS} FINAL ${where}`,
|
|
915
|
-
query_params: params,
|
|
916
|
-
format: "JSONEachRow",
|
|
917
|
-
clickhouse_settings: { date_time_input_format: "best_effort" }
|
|
918
|
-
})).json();
|
|
919
|
-
const total = Number(countRows[0]?.count ?? 0);
|
|
920
|
-
let sql = `SELECT * FROM ${_mastra_core_storage.TABLE_BACKGROUND_TASKS} FINAL ${where} ORDER BY ${filter.orderBy === "startedAt" ? "startedAt" : filter.orderBy === "suspendedAt" ? "suspendedAt" : filter.orderBy === "completedAt" ? "completedAt" : "createdAt"} ${filter.orderDirection === "desc" ? "DESC" : "ASC"}`;
|
|
921
|
-
if (filter.perPage != null) {
|
|
922
|
-
sql += ` LIMIT {var_limit:UInt32}`;
|
|
923
|
-
params.var_limit = filter.perPage;
|
|
924
|
-
if (filter.page != null) {
|
|
925
|
-
sql += ` OFFSET {var_offset:UInt32}`;
|
|
926
|
-
params.var_offset = filter.page * filter.perPage;
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
return {
|
|
930
|
-
tasks: (await (await this.client.query({
|
|
931
|
-
query: sql,
|
|
932
|
-
query_params: params,
|
|
933
|
-
format: "JSONEachRow",
|
|
934
|
-
clickhouse_settings: { date_time_input_format: "best_effort" }
|
|
935
|
-
})).json()).map(rowToTask),
|
|
936
|
-
total
|
|
937
|
-
};
|
|
938
|
-
}
|
|
939
|
-
async deleteTask(taskId) {
|
|
940
|
-
await this.client.command({
|
|
941
|
-
query: `DELETE FROM ${_mastra_core_storage.TABLE_BACKGROUND_TASKS} WHERE id = {var_id:String}`,
|
|
942
|
-
query_params: { var_id: taskId }
|
|
943
|
-
});
|
|
944
|
-
}
|
|
945
|
-
async deleteTasks(filter) {
|
|
946
|
-
const { where, params } = this.buildFilterClause(filter);
|
|
947
|
-
if (!where) return;
|
|
948
|
-
await this.client.command({
|
|
949
|
-
query: `DELETE FROM ${_mastra_core_storage.TABLE_BACKGROUND_TASKS} ${where}`,
|
|
950
|
-
query_params: params
|
|
951
|
-
});
|
|
952
|
-
}
|
|
953
|
-
async getRunningCount() {
|
|
954
|
-
const rows = await (await this.client.query({
|
|
955
|
-
query: `SELECT count() as count FROM ${_mastra_core_storage.TABLE_BACKGROUND_TASKS} FINAL WHERE status = 'running'`,
|
|
956
|
-
format: "JSONEachRow"
|
|
957
|
-
})).json();
|
|
958
|
-
return Number(rows[0]?.count ?? 0);
|
|
959
|
-
}
|
|
960
|
-
async getRunningCountByAgent(agentId) {
|
|
961
|
-
const rows = await (await this.client.query({
|
|
962
|
-
query: `SELECT count() as count FROM ${_mastra_core_storage.TABLE_BACKGROUND_TASKS} FINAL WHERE status = 'running' AND agent_id = {var_agent:String}`,
|
|
963
|
-
query_params: { var_agent: agentId },
|
|
964
|
-
format: "JSONEachRow"
|
|
965
|
-
})).json();
|
|
966
|
-
return Number(rows[0]?.count ?? 0);
|
|
967
|
-
}
|
|
968
|
-
};
|
|
969
|
-
//#endregion
|
|
970
748
|
//#region src/storage/domains/memory/index.ts
|
|
971
749
|
/**
|
|
972
750
|
* Serialize metadata object to JSON string for storage in ClickHouse.
|
|
@@ -8618,8 +8396,7 @@ var ClickhouseStore = class extends _mastra_core_storage.MastraCompositeStore {
|
|
|
8618
8396
|
workflows,
|
|
8619
8397
|
scores,
|
|
8620
8398
|
memory,
|
|
8621
|
-
observability
|
|
8622
|
-
backgroundTasks: new BackgroundTasksStorageClickhouse(domainConfig)
|
|
8399
|
+
observability
|
|
8623
8400
|
};
|
|
8624
8401
|
}
|
|
8625
8402
|
async optimizeTable({ tableName }) {
|
|
@@ -8705,7 +8482,6 @@ var ClickhouseStoreVNext = class extends ClickhouseStore {
|
|
|
8705
8482
|
}
|
|
8706
8483
|
};
|
|
8707
8484
|
//#endregion
|
|
8708
|
-
exports.BackgroundTasksStorageClickhouse = BackgroundTasksStorageClickhouse;
|
|
8709
8485
|
exports.COLUMN_TYPES = COLUMN_TYPES;
|
|
8710
8486
|
exports.ClickhouseStore = ClickhouseStore;
|
|
8711
8487
|
exports.ClickhouseStoreVNext = ClickhouseStoreVNext;
|