@mastra/clickhouse 0.0.0-switch-to-core-20250424015131 → 0.0.0-vector-query-sources-20250516172905
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 +281 -2
- package/dist/_tsup-dts-rollup.d.cts +15 -13
- package/dist/_tsup-dts-rollup.d.ts +15 -13
- package/dist/index.cjs +93 -21
- package/dist/index.js +93 -21
- package/package.json +5 -5
- package/src/storage/index.test.ts +229 -45
- package/src/storage/index.ts +122 -34
package/CHANGELOG.md
CHANGED
|
@@ -1,15 +1,294 @@
|
|
|
1
1
|
# @mastra/clickhouse
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-vector-query-sources-20250516172905
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
+
- eabdcd9: [MASTRA-3451] SQL Injection Protection
|
|
8
|
+
- Updated dependencies [f53a6ac]
|
|
9
|
+
- Updated dependencies [eabdcd9]
|
|
10
|
+
- Updated dependencies [d0ee3c6]
|
|
11
|
+
- Updated dependencies [23f258c]
|
|
12
|
+
- Updated dependencies [2672a05]
|
|
13
|
+
- @mastra/core@0.0.0-vector-query-sources-20250516172905
|
|
14
|
+
|
|
15
|
+
## 0.3.4
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 302a9f0: fix: do not partition clickhouse trace table
|
|
20
|
+
- Updated dependencies [396be50]
|
|
21
|
+
- Updated dependencies [ab80e7e]
|
|
22
|
+
- Updated dependencies [c3bd795]
|
|
23
|
+
- Updated dependencies [da082f8]
|
|
24
|
+
- Updated dependencies [a5810ce]
|
|
25
|
+
- Updated dependencies [3e9c131]
|
|
26
|
+
- Updated dependencies [3171b5b]
|
|
27
|
+
- Updated dependencies [973e5ac]
|
|
28
|
+
- Updated dependencies [daf942f]
|
|
29
|
+
- Updated dependencies [0b8b868]
|
|
30
|
+
- Updated dependencies [9e1eff5]
|
|
31
|
+
- Updated dependencies [6fa1ad1]
|
|
32
|
+
- Updated dependencies [c28d7a0]
|
|
33
|
+
- Updated dependencies [edf1e88]
|
|
34
|
+
- @mastra/core@0.9.4
|
|
35
|
+
|
|
36
|
+
## 0.3.4-alpha.4
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- Updated dependencies [3e9c131]
|
|
41
|
+
- @mastra/core@0.9.4-alpha.4
|
|
42
|
+
|
|
43
|
+
## 0.3.4-alpha.3
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- 302a9f0: fix: do not partition clickhouse trace table
|
|
48
|
+
- Updated dependencies [396be50]
|
|
49
|
+
- Updated dependencies [c3bd795]
|
|
50
|
+
- Updated dependencies [da082f8]
|
|
51
|
+
- Updated dependencies [a5810ce]
|
|
52
|
+
- @mastra/core@0.9.4-alpha.3
|
|
53
|
+
|
|
54
|
+
## 0.3.4-alpha.2
|
|
55
|
+
|
|
56
|
+
### Patch Changes
|
|
57
|
+
|
|
58
|
+
- Updated dependencies [3171b5b]
|
|
59
|
+
- Updated dependencies [973e5ac]
|
|
60
|
+
- Updated dependencies [9e1eff5]
|
|
61
|
+
- @mastra/core@0.9.4-alpha.2
|
|
62
|
+
|
|
63
|
+
## 0.3.4-alpha.1
|
|
64
|
+
|
|
65
|
+
### Patch Changes
|
|
66
|
+
|
|
67
|
+
- Updated dependencies [ab80e7e]
|
|
68
|
+
- Updated dependencies [6fa1ad1]
|
|
69
|
+
- Updated dependencies [c28d7a0]
|
|
70
|
+
- Updated dependencies [edf1e88]
|
|
71
|
+
- @mastra/core@0.9.4-alpha.1
|
|
72
|
+
|
|
73
|
+
## 0.3.4-alpha.0
|
|
74
|
+
|
|
75
|
+
### Patch Changes
|
|
76
|
+
|
|
77
|
+
- Updated dependencies [daf942f]
|
|
78
|
+
- Updated dependencies [0b8b868]
|
|
79
|
+
- @mastra/core@0.9.4-alpha.0
|
|
80
|
+
|
|
81
|
+
## 0.3.3
|
|
82
|
+
|
|
83
|
+
### Patch Changes
|
|
84
|
+
|
|
85
|
+
- Updated dependencies [e450778]
|
|
86
|
+
- Updated dependencies [8902157]
|
|
87
|
+
- Updated dependencies [ca0dc88]
|
|
88
|
+
- Updated dependencies [526c570]
|
|
89
|
+
- Updated dependencies [d7a6a33]
|
|
90
|
+
- Updated dependencies [9cd1a46]
|
|
91
|
+
- Updated dependencies [b5d2de0]
|
|
92
|
+
- Updated dependencies [644f8ad]
|
|
93
|
+
- Updated dependencies [70dbf51]
|
|
94
|
+
- @mastra/core@0.9.3
|
|
95
|
+
|
|
96
|
+
## 0.3.3-alpha.1
|
|
97
|
+
|
|
98
|
+
### Patch Changes
|
|
99
|
+
|
|
100
|
+
- Updated dependencies [e450778]
|
|
101
|
+
- Updated dependencies [8902157]
|
|
102
|
+
- Updated dependencies [ca0dc88]
|
|
103
|
+
- Updated dependencies [9cd1a46]
|
|
104
|
+
- Updated dependencies [70dbf51]
|
|
105
|
+
- @mastra/core@0.9.3-alpha.1
|
|
106
|
+
|
|
107
|
+
## 0.3.3-alpha.0
|
|
108
|
+
|
|
109
|
+
### Patch Changes
|
|
110
|
+
|
|
111
|
+
- Updated dependencies [526c570]
|
|
112
|
+
- Updated dependencies [b5d2de0]
|
|
113
|
+
- Updated dependencies [644f8ad]
|
|
114
|
+
- @mastra/core@0.9.3-alpha.0
|
|
115
|
+
|
|
116
|
+
## 0.3.2
|
|
117
|
+
|
|
118
|
+
### Patch Changes
|
|
119
|
+
|
|
120
|
+
- 4155f47: Add parameters to filter workflow runs
|
|
121
|
+
Add fromDate and toDate to telemetry parameters
|
|
122
|
+
- Updated dependencies [6052aa6]
|
|
123
|
+
- Updated dependencies [967b41c]
|
|
124
|
+
- Updated dependencies [3d2fb5c]
|
|
125
|
+
- Updated dependencies [26738f4]
|
|
126
|
+
- Updated dependencies [4155f47]
|
|
127
|
+
- Updated dependencies [7eeb2bc]
|
|
128
|
+
- Updated dependencies [b804723]
|
|
129
|
+
- Updated dependencies [8607972]
|
|
130
|
+
- Updated dependencies [ccef9f9]
|
|
131
|
+
- Updated dependencies [0097d50]
|
|
132
|
+
- Updated dependencies [7eeb2bc]
|
|
133
|
+
- Updated dependencies [17826a9]
|
|
134
|
+
- Updated dependencies [7d8b7c7]
|
|
135
|
+
- Updated dependencies [fba031f]
|
|
136
|
+
- Updated dependencies [3a5f1e1]
|
|
137
|
+
- Updated dependencies [51e6923]
|
|
138
|
+
- Updated dependencies [8398d89]
|
|
139
|
+
- @mastra/core@0.9.2
|
|
140
|
+
|
|
141
|
+
## 0.3.2-alpha.6
|
|
142
|
+
|
|
143
|
+
### Patch Changes
|
|
144
|
+
|
|
145
|
+
- Updated dependencies [6052aa6]
|
|
146
|
+
- Updated dependencies [7d8b7c7]
|
|
147
|
+
- Updated dependencies [3a5f1e1]
|
|
148
|
+
- Updated dependencies [8398d89]
|
|
149
|
+
- @mastra/core@0.9.2-alpha.6
|
|
150
|
+
|
|
151
|
+
## 0.3.2-alpha.5
|
|
152
|
+
|
|
153
|
+
### Patch Changes
|
|
154
|
+
|
|
155
|
+
- Updated dependencies [3d2fb5c]
|
|
156
|
+
- Updated dependencies [7eeb2bc]
|
|
157
|
+
- Updated dependencies [8607972]
|
|
158
|
+
- Updated dependencies [7eeb2bc]
|
|
159
|
+
- Updated dependencies [fba031f]
|
|
160
|
+
- @mastra/core@0.9.2-alpha.5
|
|
161
|
+
|
|
162
|
+
## 0.3.2-alpha.4
|
|
163
|
+
|
|
164
|
+
### Patch Changes
|
|
165
|
+
|
|
166
|
+
- Updated dependencies [ccef9f9]
|
|
167
|
+
- Updated dependencies [51e6923]
|
|
168
|
+
- @mastra/core@0.9.2-alpha.4
|
|
169
|
+
|
|
170
|
+
## 0.3.2-alpha.3
|
|
171
|
+
|
|
172
|
+
### Patch Changes
|
|
173
|
+
|
|
174
|
+
- 4155f47: Add parameters to filter workflow runs
|
|
175
|
+
Add fromDate and toDate to telemetry parameters
|
|
176
|
+
- Updated dependencies [967b41c]
|
|
177
|
+
- Updated dependencies [4155f47]
|
|
178
|
+
- Updated dependencies [17826a9]
|
|
179
|
+
- @mastra/core@0.9.2-alpha.3
|
|
180
|
+
|
|
181
|
+
## 0.3.2-alpha.2
|
|
182
|
+
|
|
183
|
+
### Patch Changes
|
|
184
|
+
|
|
185
|
+
- Updated dependencies [26738f4]
|
|
186
|
+
- @mastra/core@0.9.2-alpha.2
|
|
187
|
+
|
|
188
|
+
## 0.3.2-alpha.1
|
|
189
|
+
|
|
190
|
+
### Patch Changes
|
|
191
|
+
|
|
192
|
+
- Updated dependencies [b804723]
|
|
193
|
+
- @mastra/core@0.9.2-alpha.1
|
|
194
|
+
|
|
195
|
+
## 0.3.2-alpha.0
|
|
196
|
+
|
|
197
|
+
### Patch Changes
|
|
198
|
+
|
|
199
|
+
- Updated dependencies [0097d50]
|
|
200
|
+
- @mastra/core@0.9.2-alpha.0
|
|
201
|
+
|
|
202
|
+
## 0.3.1
|
|
203
|
+
|
|
204
|
+
### Patch Changes
|
|
205
|
+
|
|
206
|
+
- 479f490: [MASTRA-3131] Add getWorkflowRunByID and add resourceId as filter for getWorkflowRuns
|
|
207
|
+
- Updated dependencies [405b63d]
|
|
7
208
|
- Updated dependencies [81fb7f6]
|
|
209
|
+
- Updated dependencies [20275d4]
|
|
210
|
+
- Updated dependencies [7d1892c]
|
|
211
|
+
- Updated dependencies [a90a082]
|
|
212
|
+
- Updated dependencies [2d17c73]
|
|
213
|
+
- Updated dependencies [61e92f5]
|
|
214
|
+
- Updated dependencies [35955b0]
|
|
215
|
+
- Updated dependencies [6262bd5]
|
|
216
|
+
- Updated dependencies [c1409ef]
|
|
217
|
+
- Updated dependencies [3e7b69d]
|
|
218
|
+
- Updated dependencies [e4943b8]
|
|
219
|
+
- Updated dependencies [11d4485]
|
|
220
|
+
- Updated dependencies [479f490]
|
|
221
|
+
- Updated dependencies [c23a81c]
|
|
222
|
+
- Updated dependencies [2d4001d]
|
|
223
|
+
- Updated dependencies [c71013a]
|
|
224
|
+
- Updated dependencies [1d3b1cd]
|
|
225
|
+
- @mastra/core@0.9.1
|
|
226
|
+
|
|
227
|
+
## 0.3.1-alpha.8
|
|
228
|
+
|
|
229
|
+
### Patch Changes
|
|
230
|
+
|
|
231
|
+
- Updated dependencies [2d17c73]
|
|
232
|
+
- @mastra/core@0.9.1-alpha.8
|
|
233
|
+
|
|
234
|
+
## 0.3.1-alpha.7
|
|
235
|
+
|
|
236
|
+
### Patch Changes
|
|
237
|
+
|
|
238
|
+
- Updated dependencies [1d3b1cd]
|
|
239
|
+
- @mastra/core@0.9.1-alpha.7
|
|
240
|
+
|
|
241
|
+
## 0.3.1-alpha.6
|
|
242
|
+
|
|
243
|
+
### Patch Changes
|
|
244
|
+
|
|
245
|
+
- Updated dependencies [c23a81c]
|
|
246
|
+
- @mastra/core@0.9.1-alpha.6
|
|
247
|
+
|
|
248
|
+
## 0.3.1-alpha.5
|
|
249
|
+
|
|
250
|
+
### Patch Changes
|
|
251
|
+
|
|
252
|
+
- Updated dependencies [3e7b69d]
|
|
253
|
+
- @mastra/core@0.9.1-alpha.5
|
|
254
|
+
|
|
255
|
+
## 0.3.1-alpha.4
|
|
256
|
+
|
|
257
|
+
### Patch Changes
|
|
258
|
+
|
|
259
|
+
- 479f490: [MASTRA-3131] Add getWorkflowRunByID and add resourceId as filter for getWorkflowRuns
|
|
260
|
+
- Updated dependencies [e4943b8]
|
|
261
|
+
- Updated dependencies [479f490]
|
|
262
|
+
- @mastra/core@0.9.1-alpha.4
|
|
263
|
+
|
|
264
|
+
## 0.3.1-alpha.3
|
|
265
|
+
|
|
266
|
+
### Patch Changes
|
|
267
|
+
|
|
268
|
+
- Updated dependencies [6262bd5]
|
|
269
|
+
- @mastra/core@0.9.1-alpha.3
|
|
270
|
+
|
|
271
|
+
## 0.3.1-alpha.2
|
|
272
|
+
|
|
273
|
+
### Patch Changes
|
|
274
|
+
|
|
275
|
+
- Updated dependencies [405b63d]
|
|
276
|
+
- Updated dependencies [61e92f5]
|
|
277
|
+
- Updated dependencies [c71013a]
|
|
278
|
+
- @mastra/core@0.9.1-alpha.2
|
|
279
|
+
|
|
280
|
+
## 0.3.1-alpha.1
|
|
281
|
+
|
|
282
|
+
### Patch Changes
|
|
283
|
+
|
|
284
|
+
- Updated dependencies [20275d4]
|
|
8
285
|
- Updated dependencies [7d1892c]
|
|
9
286
|
- Updated dependencies [a90a082]
|
|
10
287
|
- Updated dependencies [35955b0]
|
|
288
|
+
- Updated dependencies [c1409ef]
|
|
289
|
+
- Updated dependencies [11d4485]
|
|
11
290
|
- Updated dependencies [2d4001d]
|
|
12
|
-
- @mastra/core@0.
|
|
291
|
+
- @mastra/core@0.9.1-alpha.1
|
|
13
292
|
|
|
14
293
|
## 0.3.1-alpha.0
|
|
15
294
|
|
|
@@ -7,6 +7,8 @@ import type { StorageGetMessagesArg } from '@mastra/core/storage';
|
|
|
7
7
|
import type { StorageThreadType } from '@mastra/core/memory';
|
|
8
8
|
import type { TABLE_NAMES } from '@mastra/core/storage';
|
|
9
9
|
import { TABLE_SCHEMAS } from '@mastra/core/storage';
|
|
10
|
+
import type { WorkflowRun } from '@mastra/core/storage';
|
|
11
|
+
import type { WorkflowRuns } from '@mastra/core/storage';
|
|
10
12
|
import type { WorkflowRunState } from '@mastra/core/workflows';
|
|
11
13
|
|
|
12
14
|
declare type ClickhouseConfig = {
|
|
@@ -43,13 +45,15 @@ declare class ClickhouseStore extends MastraStorage {
|
|
|
43
45
|
tableName: TABLE_NAMES;
|
|
44
46
|
records: Record<string, any>[];
|
|
45
47
|
}): Promise<void>;
|
|
46
|
-
getTraces({ name, scope, page, perPage, attributes, filters, }: {
|
|
48
|
+
getTraces({ name, scope, page, perPage, attributes, filters, fromDate, toDate, }: {
|
|
47
49
|
name?: string;
|
|
48
50
|
scope?: string;
|
|
49
51
|
page: number;
|
|
50
52
|
perPage: number;
|
|
51
53
|
attributes?: Record<string, string>;
|
|
52
54
|
filters?: Record<string, any>;
|
|
55
|
+
fromDate?: Date;
|
|
56
|
+
toDate?: Date;
|
|
53
57
|
}): Promise<any[]>;
|
|
54
58
|
optimizeTable({ tableName }: {
|
|
55
59
|
tableName: TABLE_NAMES;
|
|
@@ -89,7 +93,7 @@ declare class ClickhouseStore extends MastraStorage {
|
|
|
89
93
|
deleteThread({ threadId }: {
|
|
90
94
|
threadId: string;
|
|
91
95
|
}): Promise<void>;
|
|
92
|
-
getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T>;
|
|
96
|
+
getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T[]>;
|
|
93
97
|
saveMessages({ messages }: {
|
|
94
98
|
messages: MessageType[];
|
|
95
99
|
}): Promise<MessageType[]>;
|
|
@@ -102,22 +106,20 @@ declare class ClickhouseStore extends MastraStorage {
|
|
|
102
106
|
workflowName: string;
|
|
103
107
|
runId: string;
|
|
104
108
|
}): Promise<WorkflowRunState | null>;
|
|
105
|
-
|
|
109
|
+
private parseWorkflowRun;
|
|
110
|
+
getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId, }?: {
|
|
106
111
|
workflowName?: string;
|
|
107
112
|
fromDate?: Date;
|
|
108
113
|
toDate?: Date;
|
|
109
114
|
limit?: number;
|
|
110
115
|
offset?: number;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}>;
|
|
119
|
-
total: number;
|
|
120
|
-
}>;
|
|
116
|
+
resourceId?: string;
|
|
117
|
+
}): Promise<WorkflowRuns>;
|
|
118
|
+
getWorkflowRunById({ runId, workflowName, }: {
|
|
119
|
+
runId: string;
|
|
120
|
+
workflowName?: string;
|
|
121
|
+
}): Promise<WorkflowRun | null>;
|
|
122
|
+
private hasColumn;
|
|
121
123
|
close(): Promise<void>;
|
|
122
124
|
}
|
|
123
125
|
export { ClickhouseStore }
|
|
@@ -7,6 +7,8 @@ import type { StorageGetMessagesArg } from '@mastra/core/storage';
|
|
|
7
7
|
import type { StorageThreadType } from '@mastra/core/memory';
|
|
8
8
|
import type { TABLE_NAMES } from '@mastra/core/storage';
|
|
9
9
|
import { TABLE_SCHEMAS } from '@mastra/core/storage';
|
|
10
|
+
import type { WorkflowRun } from '@mastra/core/storage';
|
|
11
|
+
import type { WorkflowRuns } from '@mastra/core/storage';
|
|
10
12
|
import type { WorkflowRunState } from '@mastra/core/workflows';
|
|
11
13
|
|
|
12
14
|
declare type ClickhouseConfig = {
|
|
@@ -43,13 +45,15 @@ declare class ClickhouseStore extends MastraStorage {
|
|
|
43
45
|
tableName: TABLE_NAMES;
|
|
44
46
|
records: Record<string, any>[];
|
|
45
47
|
}): Promise<void>;
|
|
46
|
-
getTraces({ name, scope, page, perPage, attributes, filters, }: {
|
|
48
|
+
getTraces({ name, scope, page, perPage, attributes, filters, fromDate, toDate, }: {
|
|
47
49
|
name?: string;
|
|
48
50
|
scope?: string;
|
|
49
51
|
page: number;
|
|
50
52
|
perPage: number;
|
|
51
53
|
attributes?: Record<string, string>;
|
|
52
54
|
filters?: Record<string, any>;
|
|
55
|
+
fromDate?: Date;
|
|
56
|
+
toDate?: Date;
|
|
53
57
|
}): Promise<any[]>;
|
|
54
58
|
optimizeTable({ tableName }: {
|
|
55
59
|
tableName: TABLE_NAMES;
|
|
@@ -89,7 +93,7 @@ declare class ClickhouseStore extends MastraStorage {
|
|
|
89
93
|
deleteThread({ threadId }: {
|
|
90
94
|
threadId: string;
|
|
91
95
|
}): Promise<void>;
|
|
92
|
-
getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T>;
|
|
96
|
+
getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T[]>;
|
|
93
97
|
saveMessages({ messages }: {
|
|
94
98
|
messages: MessageType[];
|
|
95
99
|
}): Promise<MessageType[]>;
|
|
@@ -102,22 +106,20 @@ declare class ClickhouseStore extends MastraStorage {
|
|
|
102
106
|
workflowName: string;
|
|
103
107
|
runId: string;
|
|
104
108
|
}): Promise<WorkflowRunState | null>;
|
|
105
|
-
|
|
109
|
+
private parseWorkflowRun;
|
|
110
|
+
getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId, }?: {
|
|
106
111
|
workflowName?: string;
|
|
107
112
|
fromDate?: Date;
|
|
108
113
|
toDate?: Date;
|
|
109
114
|
limit?: number;
|
|
110
115
|
offset?: number;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}>;
|
|
119
|
-
total: number;
|
|
120
|
-
}>;
|
|
116
|
+
resourceId?: string;
|
|
117
|
+
}): Promise<WorkflowRuns>;
|
|
118
|
+
getWorkflowRunById({ runId, workflowName, }: {
|
|
119
|
+
runId: string;
|
|
120
|
+
workflowName?: string;
|
|
121
|
+
}): Promise<WorkflowRun | null>;
|
|
122
|
+
private hasColumn;
|
|
121
123
|
close(): Promise<void>;
|
|
122
124
|
}
|
|
123
125
|
export { ClickhouseStore }
|
package/dist/index.cjs
CHANGED
|
@@ -138,7 +138,9 @@ var ClickhouseStore = class extends storage.MastraStorage {
|
|
|
138
138
|
page,
|
|
139
139
|
perPage,
|
|
140
140
|
attributes,
|
|
141
|
-
filters
|
|
141
|
+
filters,
|
|
142
|
+
fromDate,
|
|
143
|
+
toDate
|
|
142
144
|
}) {
|
|
143
145
|
const limit = perPage;
|
|
144
146
|
const offset = page * perPage;
|
|
@@ -166,6 +168,14 @@ var ClickhouseStore = class extends storage.MastraStorage {
|
|
|
166
168
|
args[`var_col_${key}`] = value;
|
|
167
169
|
});
|
|
168
170
|
}
|
|
171
|
+
if (fromDate) {
|
|
172
|
+
conditions.push(`createdAt >= {var_from_date:DateTime64(3)}`);
|
|
173
|
+
args.var_from_date = fromDate.getTime() / 1e3;
|
|
174
|
+
}
|
|
175
|
+
if (toDate) {
|
|
176
|
+
conditions.push(`createdAt <= {var_to_date:DateTime64(3)}`);
|
|
177
|
+
args.var_to_date = toDate.getTime() / 1e3;
|
|
178
|
+
}
|
|
169
179
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
170
180
|
const result = await this.db.query({
|
|
171
181
|
query: `SELECT *, toDateTime64(createdAt, 3) as createdAt FROM ${storage.TABLE_TRACES} ${whereClause} ORDER BY "createdAt" DESC LIMIT ${limit} OFFSET ${offset}`,
|
|
@@ -227,7 +237,6 @@ var ClickhouseStore = class extends storage.MastraStorage {
|
|
|
227
237
|
${["id String"].concat(columns)}
|
|
228
238
|
)
|
|
229
239
|
ENGINE = ${TABLE_ENGINES[tableName]}
|
|
230
|
-
PARTITION BY "createdAt"
|
|
231
240
|
PRIMARY KEY (createdAt, run_id, workflow_name)
|
|
232
241
|
ORDER BY (createdAt, run_id, workflow_name)
|
|
233
242
|
${rowTtl ? `TTL toDateTime(${rowTtl.ttlKey ?? "createdAt"}) + INTERVAL ${rowTtl.interval} ${rowTtl.unit}` : ""}
|
|
@@ -237,7 +246,6 @@ var ClickhouseStore = class extends storage.MastraStorage {
|
|
|
237
246
|
${columns}
|
|
238
247
|
)
|
|
239
248
|
ENGINE = ${TABLE_ENGINES[tableName]}
|
|
240
|
-
PARTITION BY "createdAt"
|
|
241
249
|
PRIMARY KEY (createdAt, ${tableName === storage.TABLE_EVALS ? "run_id" : "id"})
|
|
242
250
|
ORDER BY (createdAt, ${tableName === storage.TABLE_EVALS ? "run_id" : "id"})
|
|
243
251
|
${this.ttl?.[tableName]?.row ? `TTL toDateTime(createdAt) + INTERVAL ${this.ttl[tableName].row.interval} ${this.ttl[tableName].row.unit}` : ""}
|
|
@@ -482,7 +490,7 @@ var ClickhouseStore = class extends storage.MastraStorage {
|
|
|
482
490
|
async deleteThread({ threadId }) {
|
|
483
491
|
try {
|
|
484
492
|
await this.db.command({
|
|
485
|
-
query: `DELETE FROM "${storage.TABLE_MESSAGES}" WHERE thread_id =
|
|
493
|
+
query: `DELETE FROM "${storage.TABLE_MESSAGES}" WHERE thread_id = {var_thread_id:String};`,
|
|
486
494
|
query_params: { var_thread_id: threadId },
|
|
487
495
|
clickhouse_settings: {
|
|
488
496
|
output_format_json_quote_64bit_integers: 0
|
|
@@ -696,12 +704,31 @@ var ClickhouseStore = class extends storage.MastraStorage {
|
|
|
696
704
|
throw error;
|
|
697
705
|
}
|
|
698
706
|
}
|
|
707
|
+
parseWorkflowRun(row) {
|
|
708
|
+
let parsedSnapshot = row.snapshot;
|
|
709
|
+
if (typeof parsedSnapshot === "string") {
|
|
710
|
+
try {
|
|
711
|
+
parsedSnapshot = JSON.parse(row.snapshot);
|
|
712
|
+
} catch (e) {
|
|
713
|
+
console.warn(`Failed to parse snapshot for workflow ${row.workflow_name}: ${e}`);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
return {
|
|
717
|
+
workflowName: row.workflow_name,
|
|
718
|
+
runId: row.run_id,
|
|
719
|
+
snapshot: parsedSnapshot,
|
|
720
|
+
createdAt: new Date(row.createdAt),
|
|
721
|
+
updatedAt: new Date(row.updatedAt),
|
|
722
|
+
resourceId: row.resourceId
|
|
723
|
+
};
|
|
724
|
+
}
|
|
699
725
|
async getWorkflowRuns({
|
|
700
726
|
workflowName,
|
|
701
727
|
fromDate,
|
|
702
728
|
toDate,
|
|
703
729
|
limit,
|
|
704
|
-
offset
|
|
730
|
+
offset,
|
|
731
|
+
resourceId
|
|
705
732
|
} = {}) {
|
|
706
733
|
try {
|
|
707
734
|
const conditions = [];
|
|
@@ -710,6 +737,15 @@ var ClickhouseStore = class extends storage.MastraStorage {
|
|
|
710
737
|
conditions.push(`workflow_name = {var_workflow_name:String}`);
|
|
711
738
|
values.var_workflow_name = workflowName;
|
|
712
739
|
}
|
|
740
|
+
if (resourceId) {
|
|
741
|
+
const hasResourceId = await this.hasColumn(storage.TABLE_WORKFLOW_SNAPSHOT, "resourceId");
|
|
742
|
+
if (hasResourceId) {
|
|
743
|
+
conditions.push(`resourceId = {var_resourceId:String}`);
|
|
744
|
+
values.var_resourceId = resourceId;
|
|
745
|
+
} else {
|
|
746
|
+
console.warn(`[${storage.TABLE_WORKFLOW_SNAPSHOT}] resourceId column not found. Skipping resourceId filter.`);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
713
749
|
if (fromDate) {
|
|
714
750
|
conditions.push(`createdAt >= {var_from_date:DateTime64(3)}`);
|
|
715
751
|
values.var_from_date = fromDate.getTime() / 1e3;
|
|
@@ -738,7 +774,8 @@ var ClickhouseStore = class extends storage.MastraStorage {
|
|
|
738
774
|
run_id,
|
|
739
775
|
snapshot,
|
|
740
776
|
toDateTime64(createdAt, 3) as createdAt,
|
|
741
|
-
toDateTime64(updatedAt, 3) as updatedAt
|
|
777
|
+
toDateTime64(updatedAt, 3) as updatedAt,
|
|
778
|
+
resourceId
|
|
742
779
|
FROM ${storage.TABLE_WORKFLOW_SNAPSHOT} ${TABLE_ENGINES[storage.TABLE_WORKFLOW_SNAPSHOT].startsWith("ReplacingMergeTree") ? "FINAL" : ""}
|
|
743
780
|
${whereClause}
|
|
744
781
|
ORDER BY createdAt DESC
|
|
@@ -751,21 +788,7 @@ var ClickhouseStore = class extends storage.MastraStorage {
|
|
|
751
788
|
const resultJson = await result.json();
|
|
752
789
|
const rows = resultJson;
|
|
753
790
|
const runs = rows.map((row) => {
|
|
754
|
-
|
|
755
|
-
if (typeof parsedSnapshot === "string") {
|
|
756
|
-
try {
|
|
757
|
-
parsedSnapshot = JSON.parse(row.snapshot);
|
|
758
|
-
} catch (e) {
|
|
759
|
-
console.warn(`Failed to parse snapshot for workflow ${row.workflow_name}: ${e}`);
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
return {
|
|
763
|
-
workflowName: row.workflow_name,
|
|
764
|
-
runId: row.run_id,
|
|
765
|
-
snapshot: parsedSnapshot,
|
|
766
|
-
createdAt: new Date(row.createdAt),
|
|
767
|
-
updatedAt: new Date(row.updatedAt)
|
|
768
|
-
};
|
|
791
|
+
return this.parseWorkflowRun(row);
|
|
769
792
|
});
|
|
770
793
|
return { runs, total: total || runs.length };
|
|
771
794
|
} catch (error) {
|
|
@@ -773,6 +796,55 @@ var ClickhouseStore = class extends storage.MastraStorage {
|
|
|
773
796
|
throw error;
|
|
774
797
|
}
|
|
775
798
|
}
|
|
799
|
+
async getWorkflowRunById({
|
|
800
|
+
runId,
|
|
801
|
+
workflowName
|
|
802
|
+
}) {
|
|
803
|
+
try {
|
|
804
|
+
const conditions = [];
|
|
805
|
+
const values = {};
|
|
806
|
+
if (runId) {
|
|
807
|
+
conditions.push(`run_id = {var_runId:String}`);
|
|
808
|
+
values.var_runId = runId;
|
|
809
|
+
}
|
|
810
|
+
if (workflowName) {
|
|
811
|
+
conditions.push(`workflow_name = {var_workflow_name:String}`);
|
|
812
|
+
values.var_workflow_name = workflowName;
|
|
813
|
+
}
|
|
814
|
+
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
815
|
+
const result = await this.db.query({
|
|
816
|
+
query: `
|
|
817
|
+
SELECT
|
|
818
|
+
workflow_name,
|
|
819
|
+
run_id,
|
|
820
|
+
snapshot,
|
|
821
|
+
toDateTime64(createdAt, 3) as createdAt,
|
|
822
|
+
toDateTime64(updatedAt, 3) as updatedAt,
|
|
823
|
+
resourceId
|
|
824
|
+
FROM ${storage.TABLE_WORKFLOW_SNAPSHOT} ${TABLE_ENGINES[storage.TABLE_WORKFLOW_SNAPSHOT].startsWith("ReplacingMergeTree") ? "FINAL" : ""}
|
|
825
|
+
${whereClause}
|
|
826
|
+
`,
|
|
827
|
+
query_params: values,
|
|
828
|
+
format: "JSONEachRow"
|
|
829
|
+
});
|
|
830
|
+
const resultJson = await result.json();
|
|
831
|
+
if (!Array.isArray(resultJson) || resultJson.length === 0) {
|
|
832
|
+
return null;
|
|
833
|
+
}
|
|
834
|
+
return this.parseWorkflowRun(resultJson[0]);
|
|
835
|
+
} catch (error) {
|
|
836
|
+
console.error("Error getting workflow run by ID:", error);
|
|
837
|
+
throw error;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
async hasColumn(table, column) {
|
|
841
|
+
const result = await this.db.query({
|
|
842
|
+
query: `DESCRIBE TABLE ${table}`,
|
|
843
|
+
format: "JSONEachRow"
|
|
844
|
+
});
|
|
845
|
+
const columns = await result.json();
|
|
846
|
+
return columns.some((c) => c.name === column);
|
|
847
|
+
}
|
|
776
848
|
async close() {
|
|
777
849
|
await this.db.close();
|
|
778
850
|
}
|