()
| 480 | } |
| 481 | |
| 482 | async function main() { |
| 483 | const args = parseArgs() |
| 484 | const outputPath = resolve(args.outPath) |
| 485 | const generatedAt = new Date().toISOString() |
| 486 | |
| 487 | console.log( |
| 488 | [ |
| 489 | `Querying ${args.dataset}.message`, |
| 490 | args.startDate || args.endDate |
| 491 | ? `window: ${args.startDate ?? '-infinity'} to ${args.endDate ?? 'now'}` |
| 492 | : `window: ${args.lookbackDays}d ending ${args.beforeDays}d ago`, |
| 493 | args.totalSessions |
| 494 | ? `total sessions: ${args.totalSessions} (${args.sampleMode})` |
| 495 | : `sessions per agent: ${args.sessionsPerAgent}`, |
| 496 | `min representative messages: ${args.minMessages}`, |
| 497 | args.clientId ? `client_id: ${args.clientId}` : undefined, |
| 498 | ] |
| 499 | .filter(Boolean) |
| 500 | .join('\n'), |
| 501 | ) |
| 502 | console.log('') |
| 503 | |
| 504 | const candidates = await fetchCandidateSessions(args) |
| 505 | const representativeRows = await fetchRepresentativeRows( |
| 506 | args, |
| 507 | candidates.map((candidate) => candidate.representative_message_id), |
| 508 | ) |
| 509 | const traces = candidates.map((candidate) => |
| 510 | buildTrace(candidate, representativeRows), |
| 511 | ) |
| 512 | |
| 513 | if (!args.skipAggregate) { |
| 514 | await mkdir(dirname(outputPath), { recursive: true }) |
| 515 | await Bun.write( |
| 516 | outputPath, |
| 517 | JSON.stringify( |
| 518 | { |
| 519 | generated_at: generatedAt, |
| 520 | dataset: OUTPUT_DATASET_NAME, |
| 521 | lookback_days: args.lookbackDays, |
| 522 | before_days: args.beforeDays, |
| 523 | start_date: args.startDate, |
| 524 | end_date: args.endDate, |
| 525 | sample_mode: args.sampleMode, |
| 526 | trace_count: traces.length, |
| 527 | traces, |
| 528 | }, |
| 529 | null, |
| 530 | 2, |
| 531 | ), |
| 532 | ) |
| 533 | } |
| 534 | const traceFiles = await writeTraceFiles({ |
| 535 | outputPath, |
| 536 | traceDir: args.traceDir, |
| 537 | dataset: OUTPUT_DATASET_NAME, |
| 538 | generatedAt, |
| 539 | traces, |
no test coverage detected