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