import { useEffect, useState } from "preact/hooks"; import { t } from "../../i18n"; import { api, apiErrorText } from "../../features/customize/api"; import { custTab } from "../../features/customize/actions"; import { nestedEditor } from "../../features/customize/state"; import { asList, asString, confirmAction, hint, } from "../../features/customize/host"; import { useAlive } from "./use-timer-lease"; import { markCustomizeFailed, markCustomizeLoaded } from "../../features/customize/load"; import { Hdr, IconGhost, Pill, Subhead, Toggle } from "./ui"; export function SpecialistsTab() { const alive = useAlive(); const [err, setErr] = useState(null); const [builtin, setBuiltin] = useState[]>([]); const [custom, setCustom] = useState[]>([]); useEffect(() => { void (async () => { try { const d = await api("/specialists"); if (!alive()) return; setBuiltin(asList(d.builtin) as Record[]); setCustom(asList(d.specialists) as Record[]); markCustomizeLoaded(); } catch (e) { if (!alive()) return; const message = t("versions.load.err", (e as Error).message); setErr(message); markCustomizeFailed(message); } })(); }, [alive]); if (err) return
{err}
; return (
{t("cust.specialists.yours")}
{custom.map((s) => (
{asString(s.name)} custom
{asString(s.description)}
{ nestedEditor.value = { kind: "specialist", name: asString(s.name) }; }} /> { if (!confirmAction(t("cust.specialists.deleteConfirm", asString(s.name)))) return; try { await api(`/specialists/${encodeURIComponent(asString(s.name))}`, { method: "DELETE", }); custTab("specialists"); } catch (e) { hint(t("toast.deleteFailed", apiErrorText(e)), true); } }} />
))} {t("cust.specialists.builtinRoles")} {builtin.map((ag) => ( ))}
); } function BuiltinRow({ ag }: { ag: Record }) { const [on, setOn] = useState(ag.enabled !== false); return (
{asString(ag.name)} {asString(ag.mode, "agent")} {ag.supportsPlanMode ? ( <> {" "} plan ) : null}
{asString(ag.description)}
{ const next = !on; setOn(next); try { await api(`/agents/${encodeURIComponent(asString(ag.name))}/enabled`, { method: "PUT", body: JSON.stringify({ enabled: next }), }); } catch { setOn(!next); } }} />
); }