import { useState } from "react"; import { patch, post } from "../api"; import { useFetch } from "../hooks"; import { useT } from "../i18n"; import { Icon } from "./Icon"; import { ModelSelect } from "./ModelSelect"; import { Spinner } from "./Activity"; /** Rename a session: type a name, or let a chosen model suggest one. */ export function RenameDialog({ sessionId, title, onClose }: { sessionId: string; title: string; onClose: () => void }) { const t = useT(); const config = useFetch<{ small_model?: string; default_model?: string }>("/config").data; const [value, setValue] = useState(title); const [model, setModel] = useState(""); const [busy, setBusy] = useState<"gen" | "save">(); const [error, setError] = useState(); const chosen = model || config?.small_model || config?.default_model || ""; const generate = async () => { setBusy("gen"); setError(undefined); try { const r = await post<{ title: string }>(`/sessions/${sessionId}/title`, { model: chosen || undefined }); setValue(r.title); } catch (e: any) { setError(e.message); } finally { setBusy(undefined); } }; const save = async () => { setBusy("save"); try { await patch(`/sessions/${sessionId}`, { title: value.trim() }); onClose(); } catch (e: any) { setError(e.message); setBusy(undefined); } }; return (
e.stopPropagation()}>

{t("rename.title")}

setValue(e.target.value)} onKeyDown={(e) => e.key === "Enter" && !busy && void save()} />
{t("rename.generateWith")}
{error &&
{error}
}
); }