import { Stack, Title, Text, Badge, Group, RingProgress, Code } from "@mantine/core"; import { RunInfo } from "../api"; interface Props { run: RunInfo | null; totalSteps: number | null; /** Last log lines, used to surface error context when status is failed/cancelled. */ logLines?: string[]; } const STATUS_COLOR: Record = { queued: "gray", running: "blue", done: "teal", failed: "red", cancelled: "yellow", }; function extractErrorContext(lines: string[] | undefined): string[] { if (!lines || lines.length === 0) return []; // Prefer lines containing ERROR / Last command const idx = lines.findIndex((l) => /ERROR|Last command/i.test(l)); if (idx >= 0) return lines.slice(idx, idx + 4).filter((l) => l.trim()); // Otherwise show the tail return lines.slice(-3).filter((l) => l.trim()); } export function RunStatus({ run, totalSteps, logLines }: Props) { if (!run) { return ( Status No run submitted. ); } const elapsed = run.finished_at > 0 ? run.finished_at - run.started_at : run.started_at > 0 ? (Date.now() / 1000 - run.started_at) : 0; return ( Status Name {run.name ?? run.example} State {run.status} Run id {run.id} Last step {run.last_step ?? "—"} Elapsed {elapsed.toFixed(1)}s {(run.status === "failed" || run.status === "cancelled") && ( {run.status === "cancelled" ? "Cancellation context" : "Error context"} {extractErrorContext(logLines).join("\n") || "(no context available)"} )} 0 && run.last_step != null ? Math.min(100, (run.last_step / totalSteps) * 100) : 0, color: STATUS_COLOR[run.status], }, ]} label={ {run.last_step ?? 0} / {totalSteps ?? "—"} } /> ); }