@mastra/clickhouse 0.0.0-update-stores-peerDeps-20250723031338 → 0.0.0-usechat-duplicate-20251016110554
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 +495 -2
- package/dist/index.cjs +259 -22
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +259 -24
- package/dist/index.js.map +1 -0
- package/dist/storage/domains/legacy-evals/index.d.ts +21 -0
- package/dist/storage/domains/legacy-evals/index.d.ts.map +1 -0
- package/dist/storage/domains/memory/index.d.ts +87 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -0
- package/dist/storage/domains/operations/index.d.ts +42 -0
- package/dist/storage/domains/operations/index.d.ts.map +1 -0
- package/dist/storage/domains/scores/index.d.ts +54 -0
- package/dist/storage/domains/scores/index.d.ts.map +1 -0
- package/dist/storage/domains/traces/index.d.ts +21 -0
- package/dist/storage/domains/traces/index.d.ts.map +1 -0
- package/dist/storage/domains/utils.d.ts +28 -0
- package/dist/storage/domains/utils.d.ts.map +1 -0
- package/dist/storage/domains/workflows/index.d.ts +55 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +245 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/package.json +25 -11
- package/dist/_tsup-dts-rollup.d.cts +0 -478
- package/dist/_tsup-dts-rollup.d.ts +0 -478
- package/dist/index.d.cts +0 -2
- package/docker-compose.yaml +0 -15
- package/eslint.config.js +0 -6
- package/src/index.ts +0 -1
- package/src/storage/domains/legacy-evals/index.ts +0 -246
- package/src/storage/domains/memory/index.ts +0 -1393
- package/src/storage/domains/operations/index.ts +0 -319
- package/src/storage/domains/scores/index.ts +0 -326
- package/src/storage/domains/traces/index.ts +0 -275
- package/src/storage/domains/utils.ts +0 -86
- package/src/storage/domains/workflows/index.ts +0 -285
- package/src/storage/index.test.ts +0 -26
- package/src/storage/index.ts +0 -402
- package/tsconfig.json +0 -5
- package/vitest.config.ts +0 -12
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createClient } from '@clickhouse/client';
|
|
2
2
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
3
|
-
import {
|
|
3
|
+
import { TABLE_AI_SPANS, TABLE_RESOURCES, TABLE_SCORERS, TABLE_EVALS, TABLE_THREADS, TABLE_TRACES, TABLE_WORKFLOW_SNAPSHOT, TABLE_MESSAGES, MastraStorage, StoreOperations, TABLE_SCHEMAS, WorkflowsStorage, ScoresStorage, safelyParseJSON, LegacyEvalsStorage, TracesStorage, MemoryStorage, resolveMessageLimit } from '@mastra/core/storage';
|
|
4
4
|
import { MessageList } from '@mastra/core/agent';
|
|
5
|
+
import { saveScorePayloadSchema } from '@mastra/core/scores';
|
|
5
6
|
|
|
6
7
|
// src/storage/index.ts
|
|
7
8
|
var TABLE_ENGINES = {
|
|
@@ -11,7 +12,9 @@ var TABLE_ENGINES = {
|
|
|
11
12
|
[TABLE_THREADS]: `ReplacingMergeTree()`,
|
|
12
13
|
[TABLE_EVALS]: `MergeTree()`,
|
|
13
14
|
[TABLE_SCORERS]: `MergeTree()`,
|
|
14
|
-
[TABLE_RESOURCES]: `ReplacingMergeTree()
|
|
15
|
+
[TABLE_RESOURCES]: `ReplacingMergeTree()`,
|
|
16
|
+
// TODO: verify this is the correct engine for ai spans when implementing clickhouse storage
|
|
17
|
+
[TABLE_AI_SPANS]: `ReplacingMergeTree()`
|
|
15
18
|
};
|
|
16
19
|
var COLUMN_TYPES = {
|
|
17
20
|
text: "String",
|
|
@@ -20,7 +23,8 @@ var COLUMN_TYPES = {
|
|
|
20
23
|
jsonb: "String",
|
|
21
24
|
integer: "Int64",
|
|
22
25
|
float: "Float64",
|
|
23
|
-
bigint: "Int64"
|
|
26
|
+
bigint: "Int64",
|
|
27
|
+
boolean: "Bool"
|
|
24
28
|
};
|
|
25
29
|
function transformRow(row) {
|
|
26
30
|
if (!row) {
|
|
@@ -252,6 +256,7 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
252
256
|
format
|
|
253
257
|
}) {
|
|
254
258
|
try {
|
|
259
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
255
260
|
const messages = [];
|
|
256
261
|
const limit = resolveMessageLimit({ last: selectBy?.last, defaultLimit: 40 });
|
|
257
262
|
const include = selectBy?.include || [];
|
|
@@ -366,6 +371,62 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
366
371
|
);
|
|
367
372
|
}
|
|
368
373
|
}
|
|
374
|
+
async getMessagesById({
|
|
375
|
+
messageIds,
|
|
376
|
+
format
|
|
377
|
+
}) {
|
|
378
|
+
if (messageIds.length === 0) return [];
|
|
379
|
+
try {
|
|
380
|
+
const result = await this.client.query({
|
|
381
|
+
query: `
|
|
382
|
+
SELECT
|
|
383
|
+
id,
|
|
384
|
+
content,
|
|
385
|
+
role,
|
|
386
|
+
type,
|
|
387
|
+
toDateTime64(createdAt, 3) as createdAt,
|
|
388
|
+
thread_id AS "threadId",
|
|
389
|
+
"resourceId"
|
|
390
|
+
FROM "${TABLE_MESSAGES}"
|
|
391
|
+
WHERE id IN {messageIds:Array(String)}
|
|
392
|
+
ORDER BY "createdAt" DESC
|
|
393
|
+
`,
|
|
394
|
+
query_params: {
|
|
395
|
+
messageIds
|
|
396
|
+
},
|
|
397
|
+
clickhouse_settings: {
|
|
398
|
+
// Allows to insert serialized JS Dates (such as '2023-12-06T10:54:48.000Z')
|
|
399
|
+
date_time_input_format: "best_effort",
|
|
400
|
+
date_time_output_format: "iso",
|
|
401
|
+
use_client_time_zone: 1,
|
|
402
|
+
output_format_json_quote_64bit_integers: 0
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
const rows = await result.json();
|
|
406
|
+
const messages = transformRows(rows.data);
|
|
407
|
+
messages.forEach((message) => {
|
|
408
|
+
if (typeof message.content === "string") {
|
|
409
|
+
try {
|
|
410
|
+
message.content = JSON.parse(message.content);
|
|
411
|
+
} catch {
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
const list = new MessageList().add(messages, "memory");
|
|
416
|
+
if (format === `v1`) return list.get.all.v1();
|
|
417
|
+
return list.get.all.v2();
|
|
418
|
+
} catch (error) {
|
|
419
|
+
throw new MastraError(
|
|
420
|
+
{
|
|
421
|
+
id: "CLICKHOUSE_STORAGE_GET_MESSAGES_BY_ID_FAILED",
|
|
422
|
+
domain: ErrorDomain.STORAGE,
|
|
423
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
424
|
+
details: { messageIds: JSON.stringify(messageIds) }
|
|
425
|
+
},
|
|
426
|
+
error
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
369
430
|
async saveMessages(args) {
|
|
370
431
|
const { messages, format = "v1" } = args;
|
|
371
432
|
if (messages.length === 0) return messages;
|
|
@@ -788,11 +849,12 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
788
849
|
}
|
|
789
850
|
}
|
|
790
851
|
async getMessagesPaginated(args) {
|
|
852
|
+
const { threadId, resourceId, selectBy, format = "v1" } = args;
|
|
853
|
+
const page = selectBy?.pagination?.page || 0;
|
|
854
|
+
const perPageInput = selectBy?.pagination?.perPage;
|
|
855
|
+
const perPage = perPageInput !== void 0 ? perPageInput : resolveMessageLimit({ last: selectBy?.last, defaultLimit: 20 });
|
|
791
856
|
try {
|
|
792
|
-
|
|
793
|
-
const page = selectBy?.pagination?.page || 0;
|
|
794
|
-
const perPageInput = selectBy?.pagination?.perPage;
|
|
795
|
-
const perPage = perPageInput !== void 0 ? perPageInput : resolveMessageLimit({ last: selectBy?.last, defaultLimit: 20 });
|
|
857
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
796
858
|
const offset = page * perPage;
|
|
797
859
|
const dateRange = selectBy?.pagination?.dateRange;
|
|
798
860
|
const fromDate = dateRange?.start;
|
|
@@ -951,14 +1013,21 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
951
1013
|
hasMore: offset + perPage < total
|
|
952
1014
|
};
|
|
953
1015
|
} catch (error) {
|
|
954
|
-
|
|
1016
|
+
const mastraError = new MastraError(
|
|
955
1017
|
{
|
|
956
1018
|
id: "CLICKHOUSE_STORAGE_GET_MESSAGES_PAGINATED_FAILED",
|
|
957
1019
|
domain: ErrorDomain.STORAGE,
|
|
958
|
-
category: ErrorCategory.THIRD_PARTY
|
|
1020
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1021
|
+
details: {
|
|
1022
|
+
threadId,
|
|
1023
|
+
resourceId: resourceId ?? ""
|
|
1024
|
+
}
|
|
959
1025
|
},
|
|
960
1026
|
error
|
|
961
1027
|
);
|
|
1028
|
+
this.logger?.trackException?.(mastraError);
|
|
1029
|
+
this.logger?.error?.(mastraError.toString());
|
|
1030
|
+
return { messages: [], total: 0, page, perPage: perPageInput || 40, hasMore: false };
|
|
962
1031
|
}
|
|
963
1032
|
}
|
|
964
1033
|
async updateMessages(args) {
|
|
@@ -1041,7 +1110,7 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
1041
1110
|
UPDATE ${setClauses.join(", ")}
|
|
1042
1111
|
WHERE id = {var_id_${paramIdx}:String}
|
|
1043
1112
|
`;
|
|
1044
|
-
console.
|
|
1113
|
+
console.info("Updating message:", id, "with query:", updateQuery, "values:", values);
|
|
1045
1114
|
updatePromises.push(
|
|
1046
1115
|
this.client.command({
|
|
1047
1116
|
query: updateQuery,
|
|
@@ -1100,7 +1169,7 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
|
|
|
1100
1169
|
}
|
|
1101
1170
|
}
|
|
1102
1171
|
if (needsRetry) {
|
|
1103
|
-
console.
|
|
1172
|
+
console.info("Update not applied correctly, retrying with DELETE + INSERT for message:", id);
|
|
1104
1173
|
await this.client.command({
|
|
1105
1174
|
query: `DELETE FROM ${TABLE_MESSAGES} WHERE id = {messageId:String}`,
|
|
1106
1175
|
query_params: { messageId: id },
|
|
@@ -1552,7 +1621,7 @@ var StoreOperationsClickhouse = class extends StoreOperations {
|
|
|
1552
1621
|
use_client_time_zone: 1
|
|
1553
1622
|
}
|
|
1554
1623
|
});
|
|
1555
|
-
console.
|
|
1624
|
+
console.info("INSERT RESULT", result);
|
|
1556
1625
|
} catch (error) {
|
|
1557
1626
|
throw new MastraError(
|
|
1558
1627
|
{
|
|
@@ -1611,7 +1680,7 @@ var StoreOperationsClickhouse = class extends StoreOperations {
|
|
|
1611
1680
|
const hasUpdatedAt = TABLE_SCHEMAS[tableName]?.updatedAt;
|
|
1612
1681
|
const selectClause = `SELECT *, toDateTime64(createdAt, 3) as createdAt${hasUpdatedAt ? ", toDateTime64(updatedAt, 3) as updatedAt" : ""}`;
|
|
1613
1682
|
const result = await this.client.query({
|
|
1614
|
-
query: `${selectClause} FROM ${tableName} ${engine.startsWith("ReplacingMergeTree") ? "FINAL" : ""} WHERE ${conditions}`,
|
|
1683
|
+
query: `${selectClause} FROM ${tableName} ${engine.startsWith("ReplacingMergeTree") ? "FINAL" : ""} WHERE ${conditions} ORDER BY createdAt DESC LIMIT 1`,
|
|
1615
1684
|
query_params: values,
|
|
1616
1685
|
clickhouse_settings: {
|
|
1617
1686
|
// Allows to insert serialized JS Dates (such as '2023-12-06T10:54:48.000Z')
|
|
@@ -1660,7 +1729,7 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
|
|
|
1660
1729
|
}
|
|
1661
1730
|
transformScoreRow(row) {
|
|
1662
1731
|
const scorer = safelyParseJSON(row.scorer);
|
|
1663
|
-
const
|
|
1732
|
+
const preprocessStepResult = safelyParseJSON(row.preprocessStepResult);
|
|
1664
1733
|
const analyzeStepResult = safelyParseJSON(row.analyzeStepResult);
|
|
1665
1734
|
const metadata = safelyParseJSON(row.metadata);
|
|
1666
1735
|
const input = safelyParseJSON(row.input);
|
|
@@ -1671,7 +1740,7 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
|
|
|
1671
1740
|
return {
|
|
1672
1741
|
...row,
|
|
1673
1742
|
scorer,
|
|
1674
|
-
|
|
1743
|
+
preprocessStepResult,
|
|
1675
1744
|
analyzeStepResult,
|
|
1676
1745
|
metadata,
|
|
1677
1746
|
input,
|
|
@@ -1715,9 +1784,23 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
|
|
|
1715
1784
|
}
|
|
1716
1785
|
}
|
|
1717
1786
|
async saveScore(score) {
|
|
1787
|
+
let parsedScore;
|
|
1788
|
+
try {
|
|
1789
|
+
parsedScore = saveScorePayloadSchema.parse(score);
|
|
1790
|
+
} catch (error) {
|
|
1791
|
+
throw new MastraError(
|
|
1792
|
+
{
|
|
1793
|
+
id: "CLICKHOUSE_STORAGE_SAVE_SCORE_FAILED_INVALID_SCORE_PAYLOAD",
|
|
1794
|
+
domain: ErrorDomain.STORAGE,
|
|
1795
|
+
category: ErrorCategory.USER,
|
|
1796
|
+
details: { scoreId: score.id }
|
|
1797
|
+
},
|
|
1798
|
+
error
|
|
1799
|
+
);
|
|
1800
|
+
}
|
|
1718
1801
|
try {
|
|
1719
1802
|
const record = {
|
|
1720
|
-
...
|
|
1803
|
+
...parsedScore
|
|
1721
1804
|
};
|
|
1722
1805
|
await this.client.insert({
|
|
1723
1806
|
table: TABLE_SCORERS,
|
|
@@ -1810,12 +1893,30 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
|
|
|
1810
1893
|
}
|
|
1811
1894
|
async getScoresByScorerId({
|
|
1812
1895
|
scorerId,
|
|
1896
|
+
entityId,
|
|
1897
|
+
entityType,
|
|
1898
|
+
source,
|
|
1813
1899
|
pagination
|
|
1814
1900
|
}) {
|
|
1901
|
+
let whereClause = `scorerId = {var_scorerId:String}`;
|
|
1902
|
+
if (entityId) {
|
|
1903
|
+
whereClause += ` AND entityId = {var_entityId:String}`;
|
|
1904
|
+
}
|
|
1905
|
+
if (entityType) {
|
|
1906
|
+
whereClause += ` AND entityType = {var_entityType:String}`;
|
|
1907
|
+
}
|
|
1908
|
+
if (source) {
|
|
1909
|
+
whereClause += ` AND source = {var_source:String}`;
|
|
1910
|
+
}
|
|
1815
1911
|
try {
|
|
1816
1912
|
const countResult = await this.client.query({
|
|
1817
|
-
query: `SELECT COUNT(*) as count FROM ${TABLE_SCORERS} WHERE
|
|
1818
|
-
query_params: {
|
|
1913
|
+
query: `SELECT COUNT(*) as count FROM ${TABLE_SCORERS} WHERE ${whereClause}`,
|
|
1914
|
+
query_params: {
|
|
1915
|
+
var_scorerId: scorerId,
|
|
1916
|
+
var_entityId: entityId,
|
|
1917
|
+
var_entityType: entityType,
|
|
1918
|
+
var_source: source
|
|
1919
|
+
},
|
|
1819
1920
|
format: "JSONEachRow"
|
|
1820
1921
|
});
|
|
1821
1922
|
const countRows = await countResult.json();
|
|
@@ -1837,11 +1938,14 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
|
|
|
1837
1938
|
}
|
|
1838
1939
|
const offset = pagination.page * pagination.perPage;
|
|
1839
1940
|
const result = await this.client.query({
|
|
1840
|
-
query: `SELECT * FROM ${TABLE_SCORERS} WHERE
|
|
1941
|
+
query: `SELECT * FROM ${TABLE_SCORERS} WHERE ${whereClause} ORDER BY createdAt DESC LIMIT {var_limit:Int64} OFFSET {var_offset:Int64}`,
|
|
1841
1942
|
query_params: {
|
|
1842
1943
|
var_scorerId: scorerId,
|
|
1843
1944
|
var_limit: pagination.perPage,
|
|
1844
|
-
var_offset: offset
|
|
1945
|
+
var_offset: offset,
|
|
1946
|
+
var_entityId: entityId,
|
|
1947
|
+
var_entityType: entityType,
|
|
1948
|
+
var_source: source
|
|
1845
1949
|
},
|
|
1846
1950
|
format: "JSONEachRow",
|
|
1847
1951
|
clickhouse_settings: {
|
|
@@ -1942,6 +2046,80 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
|
|
|
1942
2046
|
);
|
|
1943
2047
|
}
|
|
1944
2048
|
}
|
|
2049
|
+
async getScoresBySpan({
|
|
2050
|
+
traceId,
|
|
2051
|
+
spanId,
|
|
2052
|
+
pagination
|
|
2053
|
+
}) {
|
|
2054
|
+
try {
|
|
2055
|
+
const countResult = await this.client.query({
|
|
2056
|
+
query: `SELECT COUNT(*) as count FROM ${TABLE_SCORERS} WHERE traceId = {var_traceId:String} AND spanId = {var_spanId:String}`,
|
|
2057
|
+
query_params: {
|
|
2058
|
+
var_traceId: traceId,
|
|
2059
|
+
var_spanId: spanId
|
|
2060
|
+
},
|
|
2061
|
+
format: "JSONEachRow"
|
|
2062
|
+
});
|
|
2063
|
+
const countRows = await countResult.json();
|
|
2064
|
+
let total = 0;
|
|
2065
|
+
if (Array.isArray(countRows) && countRows.length > 0 && countRows[0]) {
|
|
2066
|
+
const countObj = countRows[0];
|
|
2067
|
+
total = Number(countObj.count);
|
|
2068
|
+
}
|
|
2069
|
+
if (!total) {
|
|
2070
|
+
return {
|
|
2071
|
+
pagination: {
|
|
2072
|
+
total: 0,
|
|
2073
|
+
page: pagination.page,
|
|
2074
|
+
perPage: pagination.perPage,
|
|
2075
|
+
hasMore: false
|
|
2076
|
+
},
|
|
2077
|
+
scores: []
|
|
2078
|
+
};
|
|
2079
|
+
}
|
|
2080
|
+
const limit = pagination.perPage + 1;
|
|
2081
|
+
const offset = pagination.page * pagination.perPage;
|
|
2082
|
+
const result = await this.client.query({
|
|
2083
|
+
query: `SELECT * FROM ${TABLE_SCORERS} WHERE traceId = {var_traceId:String} AND spanId = {var_spanId:String} ORDER BY createdAt DESC LIMIT {var_limit:Int64} OFFSET {var_offset:Int64}`,
|
|
2084
|
+
query_params: {
|
|
2085
|
+
var_traceId: traceId,
|
|
2086
|
+
var_spanId: spanId,
|
|
2087
|
+
var_limit: limit,
|
|
2088
|
+
var_offset: offset
|
|
2089
|
+
},
|
|
2090
|
+
format: "JSONEachRow",
|
|
2091
|
+
clickhouse_settings: {
|
|
2092
|
+
date_time_input_format: "best_effort",
|
|
2093
|
+
date_time_output_format: "iso",
|
|
2094
|
+
use_client_time_zone: 1,
|
|
2095
|
+
output_format_json_quote_64bit_integers: 0
|
|
2096
|
+
}
|
|
2097
|
+
});
|
|
2098
|
+
const rows = await result.json();
|
|
2099
|
+
const transformedRows = Array.isArray(rows) ? rows.map((row) => this.transformScoreRow(row)) : [];
|
|
2100
|
+
const hasMore = transformedRows.length > pagination.perPage;
|
|
2101
|
+
const scores = hasMore ? transformedRows.slice(0, pagination.perPage) : transformedRows;
|
|
2102
|
+
return {
|
|
2103
|
+
pagination: {
|
|
2104
|
+
total,
|
|
2105
|
+
page: pagination.page,
|
|
2106
|
+
perPage: pagination.perPage,
|
|
2107
|
+
hasMore
|
|
2108
|
+
},
|
|
2109
|
+
scores
|
|
2110
|
+
};
|
|
2111
|
+
} catch (error) {
|
|
2112
|
+
throw new MastraError(
|
|
2113
|
+
{
|
|
2114
|
+
id: "CLICKHOUSE_STORAGE_GET_SCORES_BY_SPAN_FAILED",
|
|
2115
|
+
domain: ErrorDomain.STORAGE,
|
|
2116
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
2117
|
+
details: { traceId, spanId }
|
|
2118
|
+
},
|
|
2119
|
+
error
|
|
2120
|
+
);
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
1945
2123
|
};
|
|
1946
2124
|
var TracesStorageClickhouse = class extends TracesStorage {
|
|
1947
2125
|
client;
|
|
@@ -2194,9 +2372,26 @@ var WorkflowsStorageClickhouse = class extends WorkflowsStorage {
|
|
|
2194
2372
|
this.operations = operations;
|
|
2195
2373
|
this.client = client;
|
|
2196
2374
|
}
|
|
2375
|
+
updateWorkflowResults({
|
|
2376
|
+
// workflowName,
|
|
2377
|
+
// runId,
|
|
2378
|
+
// stepId,
|
|
2379
|
+
// result,
|
|
2380
|
+
// runtimeContext,
|
|
2381
|
+
}) {
|
|
2382
|
+
throw new Error("Method not implemented.");
|
|
2383
|
+
}
|
|
2384
|
+
updateWorkflowState({
|
|
2385
|
+
// workflowName,
|
|
2386
|
+
// runId,
|
|
2387
|
+
// opts,
|
|
2388
|
+
}) {
|
|
2389
|
+
throw new Error("Method not implemented.");
|
|
2390
|
+
}
|
|
2197
2391
|
async persistWorkflowSnapshot({
|
|
2198
2392
|
workflowName,
|
|
2199
2393
|
runId,
|
|
2394
|
+
resourceId,
|
|
2200
2395
|
snapshot
|
|
2201
2396
|
}) {
|
|
2202
2397
|
try {
|
|
@@ -2207,11 +2402,13 @@ var WorkflowsStorageClickhouse = class extends WorkflowsStorage {
|
|
|
2207
2402
|
const now = /* @__PURE__ */ new Date();
|
|
2208
2403
|
const persisting = currentSnapshot ? {
|
|
2209
2404
|
...currentSnapshot,
|
|
2405
|
+
resourceId,
|
|
2210
2406
|
snapshot: JSON.stringify(snapshot),
|
|
2211
2407
|
updatedAt: now.toISOString()
|
|
2212
2408
|
} : {
|
|
2213
2409
|
workflow_name: workflowName,
|
|
2214
2410
|
run_id: runId,
|
|
2411
|
+
resourceId,
|
|
2215
2412
|
snapshot: JSON.stringify(snapshot),
|
|
2216
2413
|
createdAt: now.toISOString(),
|
|
2217
2414
|
updatedAt: now.toISOString()
|
|
@@ -2393,6 +2590,7 @@ var WorkflowsStorageClickhouse = class extends WorkflowsStorage {
|
|
|
2393
2590
|
resourceId
|
|
2394
2591
|
FROM ${TABLE_WORKFLOW_SNAPSHOT} ${TABLE_ENGINES[TABLE_WORKFLOW_SNAPSHOT].startsWith("ReplacingMergeTree") ? "FINAL" : ""}
|
|
2395
2592
|
${whereClause}
|
|
2593
|
+
ORDER BY createdAt DESC LIMIT 1
|
|
2396
2594
|
`,
|
|
2397
2595
|
query_params: values,
|
|
2398
2596
|
format: "JSONEachRow"
|
|
@@ -2456,7 +2654,9 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
2456
2654
|
selectByIncludeResourceScope: true,
|
|
2457
2655
|
resourceWorkingMemory: true,
|
|
2458
2656
|
hasColumn: true,
|
|
2459
|
-
createTable: true
|
|
2657
|
+
createTable: true,
|
|
2658
|
+
deleteMessages: false,
|
|
2659
|
+
getScoresBySpan: true
|
|
2460
2660
|
};
|
|
2461
2661
|
}
|
|
2462
2662
|
async getEvalsByAgentName(agentName, type) {
|
|
@@ -2527,12 +2727,29 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
2527
2727
|
async load({ tableName, keys }) {
|
|
2528
2728
|
return this.stores.operations.load({ tableName, keys });
|
|
2529
2729
|
}
|
|
2730
|
+
async updateWorkflowResults({
|
|
2731
|
+
workflowName,
|
|
2732
|
+
runId,
|
|
2733
|
+
stepId,
|
|
2734
|
+
result,
|
|
2735
|
+
runtimeContext
|
|
2736
|
+
}) {
|
|
2737
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
|
|
2738
|
+
}
|
|
2739
|
+
async updateWorkflowState({
|
|
2740
|
+
workflowName,
|
|
2741
|
+
runId,
|
|
2742
|
+
opts
|
|
2743
|
+
}) {
|
|
2744
|
+
return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
|
|
2745
|
+
}
|
|
2530
2746
|
async persistWorkflowSnapshot({
|
|
2531
2747
|
workflowName,
|
|
2532
2748
|
runId,
|
|
2749
|
+
resourceId,
|
|
2533
2750
|
snapshot
|
|
2534
2751
|
}) {
|
|
2535
|
-
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, snapshot });
|
|
2752
|
+
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
|
|
2536
2753
|
}
|
|
2537
2754
|
async loadWorkflowSnapshot({
|
|
2538
2755
|
workflowName,
|
|
@@ -2595,6 +2812,12 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
2595
2812
|
}) {
|
|
2596
2813
|
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
|
|
2597
2814
|
}
|
|
2815
|
+
async getMessagesById({
|
|
2816
|
+
messageIds,
|
|
2817
|
+
format
|
|
2818
|
+
}) {
|
|
2819
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
2820
|
+
}
|
|
2598
2821
|
async saveMessages(args) {
|
|
2599
2822
|
return this.stores.memory.saveMessages(args);
|
|
2600
2823
|
}
|
|
@@ -2638,13 +2861,25 @@ var ClickhouseStore = class extends MastraStorage {
|
|
|
2638
2861
|
}
|
|
2639
2862
|
async getScoresByScorerId({
|
|
2640
2863
|
scorerId,
|
|
2864
|
+
pagination,
|
|
2865
|
+
entityId,
|
|
2866
|
+
entityType,
|
|
2867
|
+
source
|
|
2868
|
+
}) {
|
|
2869
|
+
return this.stores.scores.getScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
|
|
2870
|
+
}
|
|
2871
|
+
async getScoresBySpan({
|
|
2872
|
+
traceId,
|
|
2873
|
+
spanId,
|
|
2641
2874
|
pagination
|
|
2642
2875
|
}) {
|
|
2643
|
-
return this.stores.scores.
|
|
2876
|
+
return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
|
|
2644
2877
|
}
|
|
2645
2878
|
async close() {
|
|
2646
2879
|
await this.db.close();
|
|
2647
2880
|
}
|
|
2648
2881
|
};
|
|
2649
2882
|
|
|
2650
|
-
export { ClickhouseStore };
|
|
2883
|
+
export { COLUMN_TYPES, ClickhouseStore, TABLE_ENGINES };
|
|
2884
|
+
//# sourceMappingURL=index.js.map
|
|
2885
|
+
//# sourceMappingURL=index.js.map
|