import { useState } from "react"; import { post } from "../api"; import { toast } from "../dialogs"; import { useT } from "../i18n"; import { useStore } from "../store"; import { Spinner } from "./Activity"; import { Icon } from "./Icon"; /** Green/red badge of the project's check (tests, build …) for one turn; output and "let the agent fix it" on click. */ export function TurnCheck({ sessionId, messageId, canSend }: { sessionId: string; messageId: string; canSend: boolean }) { const t = useT(); const check = useStore((s) => s.checks[sessionId]?.[messageId]); const [open, setOpen] = useState(false); if (!check) return null; const seconds = check.duration_ms >= 1000 ? ` · ${(check.duration_ms / 1000).toFixed(check.duration_ms >= 10_000 ? 0 : 1)} s` : ""; const label = check.status === "running" ? t("check.running") : check.status === "passed" ? t("check.passed") : check.status === "timeout" ? t("check.timeout") : t("check.failed"); const fix = async () => { try { await post(`/sessions/${sessionId}/prompt`, { text: `${t("check.fixPrompt")}\n\n\`\`\`\n${check.output}\n\`\`\`` }); } catch (e: any) { toast(e.message); } }; return (
{open && check.status !== "running" && (
{check.output || t("check.noOutput")}
{check.status !== "passed" && canSend && ( )}
)}
); }