MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / fetchRows

Function fetchRows

scripts/fetch-recent-chat-completion-traces.ts:250–301  ·  view source on GitHub ↗
(args: Args)

Source from the content-addressed store, hash-verified

248}
249
250async function fetchRows(args: Args): Promise<TraceRow[]> {
251 const bigquery = new BigQuery()
252 const table = `\`${args.dataset}.chat_completion_traces\``
253 const fields = `
254 trace_session_id,
255 agent_id,
256 created_at,
257 message_count,
258 message_start_index,
259 TO_JSON_STRING(messages) AS messages_json
260 `
261
262 const query = args.traceSessionId
263 ? `
264 SELECT ${fields}
265 FROM ${table}
266 WHERE trace_session_id = @traceSessionId
267 AND trace_lineage_id = trace_session_id
268 AND created_at >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL @lookbackHours HOUR)
269 ORDER BY trace_session_id, created_at, id
270 `
271 : `
272 WITH recent_rows AS (
273 SELECT *
274 FROM ${table}
275 WHERE created_at >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL @lookbackHours HOUR)
276 AND trace_lineage_id = trace_session_id
277 ),
278 recent_sessions AS (
279 SELECT trace_session_id, MAX(created_at) AS last_created_at
280 FROM recent_rows
281 GROUP BY trace_session_id
282 ORDER BY last_created_at DESC
283 LIMIT @limit
284 )
285 SELECT ${fields}
286 FROM recent_rows
287 JOIN recent_sessions USING (trace_session_id)
288 ORDER BY trace_session_id, created_at, id
289 `
290
291 const [rows] = await bigquery.query({
292 query,
293 params: {
294 limit: args.limit,
295 lookbackHours: args.lookbackHours,
296 ...(args.traceSessionId ? { traceSessionId: args.traceSessionId } : {}),
297 },
298 })
299
300 return rows as TraceRow[]
301}
302
303function printSummary(args: Args, sessions: TraceSession[]) {
304 console.log(

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected