MCPcopy
hub / github.com/CodebuffAI/codebuff / getTracesWithRelabels

Function getTracesWithRelabels

packages/bigquery/src/client.ts:357–412  ·  view source on GitHub ↗
(
  model: string,
  limit: number = 100,
  dataset: string = DATASET,
)

Source from the content-addressed store, hash-verified

355}
356
357export async function getTracesWithRelabels(
358 model: string,
359 limit: number = 100,
360 dataset: string = DATASET,
361) {
362 // Get traces that DO have matching relabels for the specified model
363 const query = `
364 SELECT
365 ANY_VALUE(t) as trace,
366 ARRAY_AGG(r ORDER BY r.created_at DESC LIMIT 1)[OFFSET(0)] as relabel
367 FROM \`${dataset}.${TRACES_TABLE}\` t
368 INNER JOIN (
369 SELECT *
370 FROM \`${dataset}.${RELABELS_TABLE}\` r
371 WHERE r.model = '${model}'
372 ) r
373 ON t.agent_step_id = r.agent_step_id
374 AND t.user_id = r.user_id
375 AND JSON_EXTRACT_SCALAR(t.payload, '$.user_input_id') = JSON_EXTRACT_SCALAR(r.payload, '$.user_input_id')
376 WHERE t.type = 'get-relevant-files'
377 AND JSON_EXTRACT_SCALAR(t.payload, '$.output') IS NOT NULL
378 AND JSON_EXTRACT_SCALAR(r.payload, '$.output') IS NOT NULL
379 GROUP BY t.agent_step_id
380 ORDER BY MAX(t.created_at) DESC
381 LIMIT ${limit}
382 `
383
384 const [rows] = await getClient().query(query)
385
386 // Filter out any results where either trace or relabel data is missing
387 const res = rows
388 .filter((row) => row.trace && row.relabel)
389 .map((row) => ({
390 trace: row.trace as GetRelevantFilesTrace,
391 relabel: row.relabel as Relabel,
392 }))
393
394 // Parse the payload as JSON if it's a string
395 return res.map((row) => ({
396 ...row,
397 trace: {
398 ...row.trace,
399 payload:
400 typeof row.trace.payload === 'string'
401 ? JSON.parse(row.trace.payload)
402 : row.trace.payload,
403 },
404 relabel: {
405 ...row.relabel,
406 payload:
407 typeof row.relabel.payload === 'string'
408 ? JSON.parse(row.relabel.payload)
409 : row.relabel.payload,
410 },
411 })) as { trace: GetRelevantFilesTrace; relabel: Relabel }[]
412}
413
414export async function getTracesAndRelabelsForUser(

Callers

nothing calls this directly

Calls 2

getClientFunction · 0.85
parseMethod · 0.80

Tested by

no test coverage detected