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 (
{data.summary}