import { useEffect, useState } from "react"; import { api } from "../api.js"; import { dirOf, t, useLang } from "../i18n.js"; // Operator copilot (Synapse layer): summary, suggested actions with Approve / Dismiss // (recorded in the decision log, never applied automatically) and an incident report draft. export default function Copilot({ live }) { const { lang } = useLang(); const [data, setData] = useState(null); const [report, setReport] = useState(null); const [decided, setDecided] = useState({}); const [busy, setBusy] = useState(false); const load = () => api(`/copilot?lang=${lang}`).then(setData).catch(() => setData(null)); useEffect(() => { if (live.status !== "running" && live.status !== "finished") return; load(); const id = setInterval(load, 15000); return () => clearInterval(id); }, [lang, live.status, live.scenario]); const decide = async (s, decision) => { await api("/copilot/decision", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ suggestion_id: s.id, title: s.title, decision }) }); setDecided({ ...decided, [s.id]: decision }); }; const draft = async () => { setBusy(true); try { setReport(await api(`/copilot/report?lang=${lang}`, { method: "POST" })); } finally { setBusy(false); } }; if (!data) return null; return (

{t("copilot", lang)}

{data.engine === "llm" ? "LLM" : "rules"} {data.clock?.slice(11)}

{data.summary}

{t("suggestions", lang)}

{data.suggestions.length === 0 && {data.empty_text || "—"}} {data.suggestions.map((s) => (
{s.title}{s.why &&
{s.why}
} {s.citations?.length > 0 &&
{s.citations.map((c) => `#${c}`).join(" ")}
}
{decided[s.id] ? {t(decided[s.id] === "approve" ? "approved" : "dismissed", lang)} : <> }
))}
{report &&
{report.report}
}
); }