( candidate: CandidateRow, representativeRows: Map<string, SessionRow>, )
| 402 | } |
| 403 | |
| 404 | function buildTrace( |
| 405 | candidate: CandidateRow, |
| 406 | representativeRows: Map<string, SessionRow>, |
| 407 | ) { |
| 408 | const representativeRow = representativeRows.get( |
| 409 | candidate.representative_message_id, |
| 410 | ) |
| 411 | |
| 412 | if (!representativeRow) { |
| 413 | throw new Error( |
| 414 | `No representative row found for ${candidate.client_id}: ${candidate.representative_message_id}`, |
| 415 | ) |
| 416 | } |
| 417 | |
| 418 | const request = getRequest(representativeRow) |
| 419 | const messages = buildFinalMessages(representativeRow) |
| 420 | |
| 421 | return { |
| 422 | client_id: candidate.client_id, |
| 423 | model: candidate.model, |
| 424 | summary: { |
| 425 | provider_call_count: Number(candidate.provider_call_count), |
| 426 | first_finished_at: toIso(candidate.first_finished_at), |
| 427 | last_finished_at: toIso(candidate.last_finished_at), |
| 428 | representative_message_id: representativeRow.id, |
| 429 | representative_run_id: representativeRow.run_id, |
| 430 | representative_finished_at: toIso(representativeRow.finished_at), |
| 431 | representative_message_count: representativeRow.message_count, |
| 432 | final_message_count: messages.length, |
| 433 | tool_count: getTools(request).length, |
| 434 | appended_final_response: !!representativeRow.response?.trim(), |
| 435 | }, |
| 436 | tools: getTools(request), |
| 437 | messages, |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | type SessionTrace = ReturnType<typeof buildTrace> |
| 442 |
no test coverage detected