@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/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createClient } from "@clickhouse/client";
|
|
2
2
|
import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
|
|
3
|
-
import { BRANCH_SPAN_TYPES,
|
|
4
|
-
import { MastraBase } from "@mastra/core/base";
|
|
3
|
+
import { BRANCH_SPAN_TYPES, EntityType, METRIC_DISTINCT_COLUMNS, MastraCompositeStore, MemoryStorage, ObservabilityStorage, SCORERS_SCHEMA, SPAN_SCHEMA, ScoresStorage, TABLE_AGENT_VERSIONS, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, TABLE_FAVORITES, TABLE_HARNESS_SESSIONS, TABLE_KNOWLEDGE_ACTIVITY, TABLE_KNOWLEDGE_CURSORS, TABLE_KNOWLEDGE_MENTIONS, TABLE_KNOWLEDGE_NODES, TABLE_KNOWLEDGE_RECORDS, TABLE_KNOWLEDGE_SEMANTIC_OUTBOX, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, TABLE_MESSAGES, TABLE_NOTIFICATIONS, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, TABLE_RESOURCES, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, TABLE_SCHEMAS, TABLE_SCORERS, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, TABLE_SKILLS, TABLE_SKILL_BLOBS, TABLE_SKILL_VERSIONS, TABLE_SPANS, TABLE_THREADS, TABLE_THREAD_STATE, TABLE_TOOL_PROVIDER_CONNECTIONS, TABLE_TRACES, TABLE_WORKFLOW_DEFINITIONS, TABLE_WORKFLOW_SNAPSHOT, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, TraceStatus, WorkflowsStorage, buildInputPreview, calculatePagination, computeTraceStatus, createStorageErrorId, getDefaultValue, getSqlType, listBranchesArgsSchema, listFeedbackArgsSchema, listLogsArgsSchema, listMetricsArgsSchema, listScoresArgsSchema, listTracesArgsSchema, normalizePerPage, safelyParseJSON, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
|
|
5
4
|
import { MessageList } from "@mastra/core/agent";
|
|
5
|
+
import { MastraBase } from "@mastra/core/base";
|
|
6
6
|
import { parseFieldKey } from "@mastra/core/utils";
|
|
7
7
|
import { coreFeatures } from "@mastra/core/features";
|
|
8
8
|
import { saveScorePayloadSchema } from "@mastra/core/evals";
|
|
@@ -744,228 +744,6 @@ var ClickhouseDB = class extends MastraBase {
|
|
|
744
744
|
}
|
|
745
745
|
};
|
|
746
746
|
//#endregion
|
|
747
|
-
//#region src/storage/domains/background-tasks/index.ts
|
|
748
|
-
function serializeJson(v) {
|
|
749
|
-
if (typeof v === "object" && v != null) return JSON.stringify(v);
|
|
750
|
-
return v ?? "";
|
|
751
|
-
}
|
|
752
|
-
function readNullableDate(val) {
|
|
753
|
-
if (val == null || val === "") return void 0;
|
|
754
|
-
const d = new Date(val);
|
|
755
|
-
if (Number.isNaN(d.getTime()) || d.getTime() === 0) return void 0;
|
|
756
|
-
return d;
|
|
757
|
-
}
|
|
758
|
-
function rowToTask(row) {
|
|
759
|
-
const parseJson = (val) => {
|
|
760
|
-
if (val == null || val === "") return void 0;
|
|
761
|
-
if (typeof val === "string") try {
|
|
762
|
-
return JSON.parse(val);
|
|
763
|
-
} catch {
|
|
764
|
-
return val;
|
|
765
|
-
}
|
|
766
|
-
return val;
|
|
767
|
-
};
|
|
768
|
-
return {
|
|
769
|
-
id: row.id,
|
|
770
|
-
status: row.status,
|
|
771
|
-
toolName: row.tool_name,
|
|
772
|
-
toolCallId: row.tool_call_id,
|
|
773
|
-
args: parseJson(row.args) ?? {},
|
|
774
|
-
agentId: row.agent_id,
|
|
775
|
-
threadId: row.thread_id || void 0,
|
|
776
|
-
resourceId: row.resource_id || void 0,
|
|
777
|
-
runId: row.run_id ?? "",
|
|
778
|
-
result: parseJson(row.result),
|
|
779
|
-
error: parseJson(row.error),
|
|
780
|
-
suspendPayload: parseJson(row.suspend_payload),
|
|
781
|
-
retryCount: Number(row.retry_count ?? 0),
|
|
782
|
-
maxRetries: Number(row.max_retries ?? 0),
|
|
783
|
-
timeoutMs: Number(row.timeout_ms ?? 3e5),
|
|
784
|
-
createdAt: new Date(row.createdAt),
|
|
785
|
-
startedAt: readNullableDate(row.startedAt),
|
|
786
|
-
suspendedAt: readNullableDate(row.suspendedAt),
|
|
787
|
-
completedAt: readNullableDate(row.completedAt)
|
|
788
|
-
};
|
|
789
|
-
}
|
|
790
|
-
var BackgroundTasksStorageClickhouse = class extends BackgroundTasksStorage {
|
|
791
|
-
client;
|
|
792
|
-
#db;
|
|
793
|
-
constructor(config) {
|
|
794
|
-
super();
|
|
795
|
-
const { client, ttl, replication } = resolveClickhouseConfig(config);
|
|
796
|
-
this.client = client;
|
|
797
|
-
this.#db = new ClickhouseDB({
|
|
798
|
-
client,
|
|
799
|
-
ttl,
|
|
800
|
-
replication
|
|
801
|
-
});
|
|
802
|
-
}
|
|
803
|
-
async init() {
|
|
804
|
-
await this.#db.createTable({
|
|
805
|
-
tableName: TABLE_BACKGROUND_TASKS,
|
|
806
|
-
schema: TABLE_SCHEMAS[TABLE_BACKGROUND_TASKS]
|
|
807
|
-
});
|
|
808
|
-
await this.#db.alterTable({
|
|
809
|
-
tableName: TABLE_BACKGROUND_TASKS,
|
|
810
|
-
schema: TABLE_SCHEMAS[TABLE_BACKGROUND_TASKS],
|
|
811
|
-
ifNotExists: ["suspend_payload", "suspendedAt"]
|
|
812
|
-
});
|
|
813
|
-
}
|
|
814
|
-
async dangerouslyClearAll() {
|
|
815
|
-
await this.#db.clearTable({ tableName: TABLE_BACKGROUND_TASKS });
|
|
816
|
-
}
|
|
817
|
-
async createTask(task) {
|
|
818
|
-
await this.client.insert({
|
|
819
|
-
table: TABLE_BACKGROUND_TASKS,
|
|
820
|
-
values: [{
|
|
821
|
-
id: task.id,
|
|
822
|
-
tool_call_id: task.toolCallId,
|
|
823
|
-
tool_name: task.toolName,
|
|
824
|
-
agent_id: task.agentId,
|
|
825
|
-
thread_id: task.threadId ?? "",
|
|
826
|
-
resource_id: task.resourceId ?? "",
|
|
827
|
-
run_id: task.runId,
|
|
828
|
-
status: task.status,
|
|
829
|
-
args: serializeJson(task.args),
|
|
830
|
-
result: serializeJson(task.result),
|
|
831
|
-
error: serializeJson(task.error),
|
|
832
|
-
suspend_payload: serializeJson(task.suspendPayload),
|
|
833
|
-
retry_count: task.retryCount,
|
|
834
|
-
max_retries: task.maxRetries,
|
|
835
|
-
timeout_ms: task.timeoutMs,
|
|
836
|
-
createdAt: task.createdAt.toISOString(),
|
|
837
|
-
startedAt: task.startedAt?.toISOString() ?? "1970-01-01T00:00:00.000Z",
|
|
838
|
-
suspendedAt: task.suspendedAt?.toISOString() ?? "1970-01-01T00:00:00.000Z",
|
|
839
|
-
completedAt: task.completedAt?.toISOString() ?? "1970-01-01T00:00:00.000Z"
|
|
840
|
-
}],
|
|
841
|
-
format: "JSONEachRow",
|
|
842
|
-
clickhouse_settings: { date_time_input_format: "best_effort" }
|
|
843
|
-
});
|
|
844
|
-
}
|
|
845
|
-
async updateTask(taskId, update) {
|
|
846
|
-
const existing = await this.getTask(taskId);
|
|
847
|
-
if (!existing) return;
|
|
848
|
-
const merged = { ...existing };
|
|
849
|
-
if ("status" in update) merged.status = update.status;
|
|
850
|
-
if ("result" in update) merged.result = update.result;
|
|
851
|
-
if ("error" in update) merged.error = update.error;
|
|
852
|
-
if ("suspendPayload" in update) merged.suspendPayload = update.suspendPayload;
|
|
853
|
-
if ("retryCount" in update) merged.retryCount = update.retryCount;
|
|
854
|
-
if ("startedAt" in update) merged.startedAt = update.startedAt;
|
|
855
|
-
if ("suspendedAt" in update) merged.suspendedAt = update.suspendedAt;
|
|
856
|
-
if ("completedAt" in update) merged.completedAt = update.completedAt;
|
|
857
|
-
await this.createTask(merged);
|
|
858
|
-
}
|
|
859
|
-
async getTask(taskId) {
|
|
860
|
-
const rows = await (await this.client.query({
|
|
861
|
-
query: `SELECT * FROM ${TABLE_BACKGROUND_TASKS} FINAL WHERE id = {var_id:String} LIMIT 1`,
|
|
862
|
-
query_params: { var_id: taskId },
|
|
863
|
-
format: "JSONEachRow",
|
|
864
|
-
clickhouse_settings: { date_time_input_format: "best_effort" }
|
|
865
|
-
})).json();
|
|
866
|
-
return rows.length > 0 ? rowToTask(rows[0]) : null;
|
|
867
|
-
}
|
|
868
|
-
buildFilterClause(filter) {
|
|
869
|
-
const conditions = [];
|
|
870
|
-
const params = {};
|
|
871
|
-
if (filter.status) {
|
|
872
|
-
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
873
|
-
conditions.push(`status IN ({var_statuses:Array(String)})`);
|
|
874
|
-
params.var_statuses = statuses;
|
|
875
|
-
}
|
|
876
|
-
if (filter.agentId) {
|
|
877
|
-
conditions.push(`agent_id = {var_agent:String}`);
|
|
878
|
-
params.var_agent = filter.agentId;
|
|
879
|
-
}
|
|
880
|
-
if (filter.threadId) {
|
|
881
|
-
conditions.push(`thread_id = {var_thread:String}`);
|
|
882
|
-
params.var_thread = filter.threadId;
|
|
883
|
-
}
|
|
884
|
-
if (filter.runId) {
|
|
885
|
-
conditions.push(`run_id = {var_run:String}`);
|
|
886
|
-
params.var_run = filter.runId;
|
|
887
|
-
}
|
|
888
|
-
if (filter.toolName) {
|
|
889
|
-
conditions.push(`tool_name = {var_tool:String}`);
|
|
890
|
-
params.var_tool = filter.toolName;
|
|
891
|
-
}
|
|
892
|
-
if (filter.toolCallId) {
|
|
893
|
-
conditions.push(`tool_call_id = {var_tool_call:String}`);
|
|
894
|
-
params.var_tool_call = filter.toolCallId;
|
|
895
|
-
}
|
|
896
|
-
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
|
|
897
|
-
if (filter.fromDate) {
|
|
898
|
-
conditions.push(`${dateCol} >= parseDateTimeBestEffort({var_from_date:String})`);
|
|
899
|
-
params.var_from_date = filter.fromDate.toISOString();
|
|
900
|
-
}
|
|
901
|
-
if (filter.toDate) {
|
|
902
|
-
conditions.push(`${dateCol} < parseDateTimeBestEffort({var_to_date:String})`);
|
|
903
|
-
params.var_to_date = filter.toDate.toISOString();
|
|
904
|
-
}
|
|
905
|
-
return {
|
|
906
|
-
where: conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "",
|
|
907
|
-
params
|
|
908
|
-
};
|
|
909
|
-
}
|
|
910
|
-
async listTasks(filter) {
|
|
911
|
-
const { where, params } = this.buildFilterClause(filter);
|
|
912
|
-
const countRows = await (await this.client.query({
|
|
913
|
-
query: `SELECT count() as count FROM ${TABLE_BACKGROUND_TASKS} FINAL ${where}`,
|
|
914
|
-
query_params: params,
|
|
915
|
-
format: "JSONEachRow",
|
|
916
|
-
clickhouse_settings: { date_time_input_format: "best_effort" }
|
|
917
|
-
})).json();
|
|
918
|
-
const total = Number(countRows[0]?.count ?? 0);
|
|
919
|
-
let sql = `SELECT * FROM ${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"}`;
|
|
920
|
-
if (filter.perPage != null) {
|
|
921
|
-
sql += ` LIMIT {var_limit:UInt32}`;
|
|
922
|
-
params.var_limit = filter.perPage;
|
|
923
|
-
if (filter.page != null) {
|
|
924
|
-
sql += ` OFFSET {var_offset:UInt32}`;
|
|
925
|
-
params.var_offset = filter.page * filter.perPage;
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
return {
|
|
929
|
-
tasks: (await (await this.client.query({
|
|
930
|
-
query: sql,
|
|
931
|
-
query_params: params,
|
|
932
|
-
format: "JSONEachRow",
|
|
933
|
-
clickhouse_settings: { date_time_input_format: "best_effort" }
|
|
934
|
-
})).json()).map(rowToTask),
|
|
935
|
-
total
|
|
936
|
-
};
|
|
937
|
-
}
|
|
938
|
-
async deleteTask(taskId) {
|
|
939
|
-
await this.client.command({
|
|
940
|
-
query: `DELETE FROM ${TABLE_BACKGROUND_TASKS} WHERE id = {var_id:String}`,
|
|
941
|
-
query_params: { var_id: taskId }
|
|
942
|
-
});
|
|
943
|
-
}
|
|
944
|
-
async deleteTasks(filter) {
|
|
945
|
-
const { where, params } = this.buildFilterClause(filter);
|
|
946
|
-
if (!where) return;
|
|
947
|
-
await this.client.command({
|
|
948
|
-
query: `DELETE FROM ${TABLE_BACKGROUND_TASKS} ${where}`,
|
|
949
|
-
query_params: params
|
|
950
|
-
});
|
|
951
|
-
}
|
|
952
|
-
async getRunningCount() {
|
|
953
|
-
const rows = await (await this.client.query({
|
|
954
|
-
query: `SELECT count() as count FROM ${TABLE_BACKGROUND_TASKS} FINAL WHERE status = 'running'`,
|
|
955
|
-
format: "JSONEachRow"
|
|
956
|
-
})).json();
|
|
957
|
-
return Number(rows[0]?.count ?? 0);
|
|
958
|
-
}
|
|
959
|
-
async getRunningCountByAgent(agentId) {
|
|
960
|
-
const rows = await (await this.client.query({
|
|
961
|
-
query: `SELECT count() as count FROM ${TABLE_BACKGROUND_TASKS} FINAL WHERE status = 'running' AND agent_id = {var_agent:String}`,
|
|
962
|
-
query_params: { var_agent: agentId },
|
|
963
|
-
format: "JSONEachRow"
|
|
964
|
-
})).json();
|
|
965
|
-
return Number(rows[0]?.count ?? 0);
|
|
966
|
-
}
|
|
967
|
-
};
|
|
968
|
-
//#endregion
|
|
969
747
|
//#region src/storage/domains/memory/index.ts
|
|
970
748
|
/**
|
|
971
749
|
* Serialize metadata object to JSON string for storage in ClickHouse.
|
|
@@ -8617,8 +8395,7 @@ var ClickhouseStore = class extends MastraCompositeStore {
|
|
|
8617
8395
|
workflows,
|
|
8618
8396
|
scores,
|
|
8619
8397
|
memory,
|
|
8620
|
-
observability
|
|
8621
|
-
backgroundTasks: new BackgroundTasksStorageClickhouse(domainConfig)
|
|
8398
|
+
observability
|
|
8622
8399
|
};
|
|
8623
8400
|
}
|
|
8624
8401
|
async optimizeTable({ tableName }) {
|
|
@@ -8704,6 +8481,6 @@ var ClickhouseStoreVNext = class extends ClickhouseStore {
|
|
|
8704
8481
|
}
|
|
8705
8482
|
};
|
|
8706
8483
|
//#endregion
|
|
8707
|
-
export {
|
|
8484
|
+
export { COLUMN_TYPES, ClickhouseStore, ClickhouseStoreVNext, MemoryStorageClickhouse, ObservabilityStorageClickhouse, ObservabilityStorageClickhouseVNext, ScoresStorageClickhouse, TABLE_ENGINES, WorkflowsStorageClickhouse };
|
|
8708
8485
|
|
|
8709
8486
|
//# sourceMappingURL=index.js.map
|