@mastra/clickhouse 0.15.2 → 0.15.3-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 +11 -0
- package/dist/index.cjs +99 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +99 -2
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +8 -0
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +9 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @mastra/clickhouse
|
|
2
2
|
|
|
3
|
+
## 0.15.3-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Update peer deps ([#8154](https://github.com/mastra-ai/mastra/pull/8154))
|
|
8
|
+
|
|
9
|
+
- Clickhouse support for fetching scores by trace and spanId ([#8154](https://github.com/mastra-ai/mastra/pull/8154))
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`504438b`](https://github.com/mastra-ai/mastra/commit/504438b961bde211071186bba63a842c4e3db879), [`a7243e2`](https://github.com/mastra-ai/mastra/commit/a7243e2e58762667a6e3921e755e89d6bb0a3282), [`7fceb0a`](https://github.com/mastra-ai/mastra/commit/7fceb0a327d678e812f90f5387c5bc4f38bd039e), [`df64f9e`](https://github.com/mastra-ai/mastra/commit/df64f9ef814916fff9baedd861c988084e7c41de), [`809eea0`](https://github.com/mastra-ai/mastra/commit/809eea092fa80c3f69b9eaf078d843b57fd2a88e), [`683e5a1`](https://github.com/mastra-ai/mastra/commit/683e5a1466e48b686825b2c11f84680f296138e4), [`3679378`](https://github.com/mastra-ai/mastra/commit/3679378673350aa314741dc826f837b1984149bc), [`7775bc2`](https://github.com/mastra-ai/mastra/commit/7775bc20bb1ad1ab24797fb420e4f96c65b0d8ec), [`db1891a`](https://github.com/mastra-ai/mastra/commit/db1891a4707443720b7cd8a260dc7e1d49b3609c), [`e8f379d`](https://github.com/mastra-ai/mastra/commit/e8f379d390efa264c4e0874f9ac0cf8839b07777), [`652066b`](https://github.com/mastra-ai/mastra/commit/652066bd1efc6bb6813ba950ed1d7573e8b7d9d4), [`ea8d386`](https://github.com/mastra-ai/mastra/commit/ea8d386cd8c5593664515fd5770c06bf2aa980ef), [`c2a4919`](https://github.com/mastra-ai/mastra/commit/c2a4919ba6797d8bdb1509e02287496eef69303e), [`0130986`](https://github.com/mastra-ai/mastra/commit/0130986fc62d0edcc626dd593282661dbb9af141)]:
|
|
12
|
+
- @mastra/core@0.19.0-alpha.1
|
|
13
|
+
|
|
3
14
|
## 0.15.2
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
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 = {
|
|
@@ -1785,9 +1786,23 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
|
|
|
1785
1786
|
}
|
|
1786
1787
|
}
|
|
1787
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
|
+
}
|
|
1788
1803
|
try {
|
|
1789
1804
|
const record = {
|
|
1790
|
-
...
|
|
1805
|
+
...parsedScore
|
|
1791
1806
|
};
|
|
1792
1807
|
await this.client.insert({
|
|
1793
1808
|
table: storage.TABLE_SCORERS,
|
|
@@ -2033,6 +2048,80 @@ var ScoresStorageClickhouse = class extends storage.ScoresStorage {
|
|
|
2033
2048
|
);
|
|
2034
2049
|
}
|
|
2035
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
|
+
}
|
|
2036
2125
|
};
|
|
2037
2126
|
var TracesStorageClickhouse = class extends storage.TracesStorage {
|
|
2038
2127
|
client;
|
|
@@ -2568,7 +2657,8 @@ var ClickhouseStore = class extends storage.MastraStorage {
|
|
|
2568
2657
|
resourceWorkingMemory: true,
|
|
2569
2658
|
hasColumn: true,
|
|
2570
2659
|
createTable: true,
|
|
2571
|
-
deleteMessages: false
|
|
2660
|
+
deleteMessages: false,
|
|
2661
|
+
getScoresBySpan: true
|
|
2572
2662
|
};
|
|
2573
2663
|
}
|
|
2574
2664
|
async getEvalsByAgentName(agentName, type) {
|
|
@@ -2780,6 +2870,13 @@ var ClickhouseStore = class extends storage.MastraStorage {
|
|
|
2780
2870
|
}) {
|
|
2781
2871
|
return this.stores.scores.getScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
|
|
2782
2872
|
}
|
|
2873
|
+
async getScoresBySpan({
|
|
2874
|
+
traceId,
|
|
2875
|
+
spanId,
|
|
2876
|
+
pagination
|
|
2877
|
+
}) {
|
|
2878
|
+
return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
|
|
2879
|
+
}
|
|
2783
2880
|
async close() {
|
|
2784
2881
|
await this.db.close();
|
|
2785
2882
|
}
|