@@ -9,6 +9,7 @@ const GenerationRowSchema = z.object({
99 operation_id : z . string ( ) ,
1010 task_identifier : z . string ( ) ,
1111 response_model : z . string ( ) ,
12+ prompt_version : z . coerce . number ( ) ,
1213 input_tokens : z . coerce . number ( ) ,
1314 output_tokens : z . coerce . number ( ) ,
1415 total_cost : z . coerce . number ( ) ,
@@ -22,6 +23,7 @@ export type GenerationRow = {
2223 operation_id : string ;
2324 task_identifier : string ;
2425 response_model : string ;
26+ prompt_version : number ;
2527 input_tokens : number ;
2628 output_tokens : number ;
2729 total_cost : number ;
@@ -211,11 +213,14 @@ export class PromptPresenter extends BasePresenter {
211213 async listGenerations ( options : {
212214 environmentId : string ;
213215 promptSlug : string ;
214- promptVersion : number ;
216+ promptVersions ? : number [ ] ;
215217 startTime : Date ;
216218 endTime : Date ;
217219 cursor ?: string ;
218220 pageSize ?: number ;
221+ responseModels ?: string [ ] ;
222+ operations ?: string [ ] ;
223+ providers ?: string [ ] ;
219224 } ) : Promise < { generations : GenerationRow [ ] ; pagination : GenerationsPagination } > {
220225 const pageSize = options . pageSize ?? 25 ;
221226 const decodedCursor = options . cursor ? decodeCursor ( options . cursor ) : null ;
@@ -226,26 +231,51 @@ export class PromptPresenter extends BasePresenter {
226231 AND span_id < {cursorSpanId: String}))`
227232 : "" ;
228233
234+ const versionClause = options . promptVersions ?. length
235+ ? `AND prompt_version IN {promptVersions: Array(UInt32)}`
236+ : "" ;
237+ const modelClause = options . responseModels ?. length
238+ ? `AND response_model IN {responseModels: Array(String)}`
239+ : "" ;
240+ const operationClause = options . operations ?. length
241+ ? `AND operation_id IN {operations: Array(String)}`
242+ : "" ;
243+ const providerClause = options . providers ?. length
244+ ? `AND gen_ai_system IN {providers: Array(String)}`
245+ : "" ;
246+
247+ // Build a unique query name based on which optional filters are active
248+ const filterKey = [
249+ decodedCursor ? "c" : "" ,
250+ options . promptVersions ?. length ? "v" : "" ,
251+ options . responseModels ?. length ? "m" : "" ,
252+ options . operations ?. length ? "o" : "" ,
253+ options . providers ?. length ? "p" : "" ,
254+ ] . join ( "" ) ;
255+
229256 const queryFn = this . clickhouse . reader . query ( {
230- name : decodedCursor ? "promptGenerationsListCursor" : " promptGenerationsList" ,
257+ name : ` promptGenerationsList${ filterKey } ` ,
231258 query : `SELECT
232259 run_id, span_id, operation_id, task_identifier, response_model,
260+ prompt_version,
233261 input_tokens, output_tokens, total_cost,
234262 duration / 1000000 AS duration_ms,
235263 formatDateTime(start_time, '%Y-%m-%d %H:%i:%S') AS started_at
236264 FROM trigger_dev.llm_metrics_v1
237265 WHERE environment_id = {environmentId: String}
238266 AND prompt_slug = {promptSlug: String}
239- AND prompt_version = {promptVersion: UInt32 }
267+ ${ versionClause }
240268 AND start_time >= parseDateTimeBestEffort({startTime: String})
241269 AND start_time <= parseDateTimeBestEffort({endTime: String})
242270 ${ cursorClause }
271+ ${ modelClause }
272+ ${ operationClause }
273+ ${ providerClause }
243274 ORDER BY start_time DESC, span_id DESC
244275 LIMIT {fetchLimit: UInt32}` ,
245276 params : z . object ( {
246277 environmentId : z . string ( ) ,
247278 promptSlug : z . string ( ) ,
248- promptVersion : z . number ( ) ,
249279 startTime : z . string ( ) ,
250280 endTime : z . string ( ) ,
251281 fetchLimit : z . number ( ) ,
@@ -255,14 +285,17 @@ export class PromptPresenter extends BasePresenter {
255285 cursorSpanId : z . string ( ) ,
256286 }
257287 : { } ) ,
288+ ...( options . promptVersions ?. length ? { promptVersions : z . array ( z . number ( ) ) } : { } ) ,
289+ ...( options . responseModels ?. length ? { responseModels : z . array ( z . string ( ) ) } : { } ) ,
290+ ...( options . operations ?. length ? { operations : z . array ( z . string ( ) ) } : { } ) ,
291+ ...( options . providers ?. length ? { providers : z . array ( z . string ( ) ) } : { } ) ,
258292 } ) ,
259293 schema : GenerationRowSchema ,
260294 } ) ;
261295
262296 const queryParams : Record < string , unknown > = {
263297 environmentId : options . environmentId ,
264298 promptSlug : options . promptSlug ,
265- promptVersion : options . promptVersion ,
266299 startTime : options . startTime . toISOString ( ) ,
267300 endTime : options . endTime . toISOString ( ) ,
268301 fetchLimit : pageSize + 1 ,
@@ -272,6 +305,18 @@ export class PromptPresenter extends BasePresenter {
272305 queryParams . cursorStartTime = decodedCursor . startTime ;
273306 queryParams . cursorSpanId = decodedCursor . spanId ;
274307 }
308+ if ( options . promptVersions ?. length ) {
309+ queryParams . promptVersions = options . promptVersions ;
310+ }
311+ if ( options . responseModels ?. length ) {
312+ queryParams . responseModels = options . responseModels ;
313+ }
314+ if ( options . operations ?. length ) {
315+ queryParams . operations = options . operations ;
316+ }
317+ if ( options . providers ?. length ) {
318+ queryParams . providers = options . providers ;
319+ }
275320
276321 const [ error , rows ] = await queryFn ( queryParams as any ) ;
277322
0 commit comments