import { useState } from "react"; import { patch } from "../api"; import { toast } from "../dialogs"; import { useFetch } from "../hooks"; import { useT } from "../i18n"; import { Spinner } from "./Activity"; import { Icon } from "./Icon"; interface SkillInfo { name: string; description: string; files: string[]; user?: boolean; } /** Switch skills on for one chat: their full instructions go into every turn. */ export function ChatSkillsDialog({ sessionId, cwd, active, onClose }: { sessionId: string; cwd: string; active: string[]; onClose: () => void }) { const t = useT(); const { data } = useFetch<{ skills: SkillInfo[] }>(`/commands?cwd=${encodeURIComponent(cwd)}`); const [picked, setPicked] = useState(active); const [filter, setFilter] = useState(""); const [busy, setBusy] = useState(false); const all = data?.skills ?? []; // Chosen skills first, then the rest. const shown = all .filter((s) => !filter.trim() || `${s.name} ${s.description}`.toLowerCase().includes(filter.trim().toLowerCase())) .sort((a, b) => Number(picked.includes(b.name)) - Number(picked.includes(a.name)) || a.name.localeCompare(b.name)); const toggle = (n: string) => setPicked((p) => (p.includes(n) ? p.filter((x) => x !== n) : [...p, n])); const save = async () => { setBusy(true); try { await patch(`/sessions/${sessionId}`, { skills: picked }); onClose(); } catch (e: any) { toast(e.message); setBusy(false); } }; return (
e.stopPropagation()}>

{t("skills.chatTitle")}

{t("skills.chatHint")}
{!data ? ( ) : all.length === 0 ? (
{t("skills.empty")}
) : ( <> {all.length > 6 && setFilter(e.target.value)} />}
{shown.map((s) => ( ))}
{picked.length > 4 &&
{t("skills.manyActive")}
} )}
); }