import { useState } from "react"; import { patch } from "../../api"; import { useFetch } from "../../hooks"; import { useT } from "../../i18n"; import type { AgentInfo } from "../../types"; import { ModelSelect } from "../ModelSelect"; type Patch = { path: string[]; value: unknown }; const WRITER_PROMPT = `You are a technical writer. Produce clear, well-structured text (Markdown) for documentation, summaries, step-by-step guides and translations. Return only the finished text.`; function AgentRow({ a, raw, onSaved }: { a: AgentInfo; raw: any; onSaved: (ok: boolean, text: string) => void }) { const t = useT(); const [open, setOpen] = useState(false); const [form, setForm] = useState({ model: a.model ?? "", max_parallel: a.max_parallel ? String(a.max_parallel) : "", description: raw?.description ?? "", tools: (raw?.tools ?? []).join(", "), prompt: raw?.prompt ?? "", mode: raw?.mode ?? a.mode, }); const builtin = a.source === "builtin" || (a.source === "config" && !raw?.prompt && ["build", "plan", "craft", "general", "explore"].includes(a.name)); const save = async () => { const base = ["agents", a.name]; const patches: Patch[] = [ { path: [...base, "model"], value: form.model || null }, { path: [...base, "max_parallel"], value: form.max_parallel ? Number(form.max_parallel) : null }, ]; if (!builtin || form.description) patches.push({ path: [...base, "description"], value: form.description || null }); if (!builtin) { patches.push({ path: [...base, "mode"], value: form.mode }); patches.push({ path: [...base, "tools"], value: form.tools.trim() ? form.tools.split(/[\s,]+/).filter(Boolean) : null }); patches.push({ path: [...base, "prompt"], value: form.prompt || null }); } try { await patch("/config", { patches }); onSaved(true, t("settings.saved")); } catch (e: any) { onSaved(false, e.message); } }; const reset = async () => { if (!confirm(t(builtin ? "agents.resetConfirm" : "agents.deleteConfirm", { name: a.name }))) return; try { await patch("/config", { patches: [{ path: ["agents", a.name], value: null }] }); onSaved(true, t("settings.saved")); } catch (e: any) { onSaved(false, e.message); } }; return (
{a.name}
{a.mode === "primary" ? t("agents.modePrimary") : t("agents.modeSubagent")}
{t(`agents.source.${a.source}` as any)}
{a.read_only && {t("agents.readOnly")}}
/{c.name} – {c.description}{s.name} – {s.description}