import { useEffect, useState } from "react"; import { get, post } from "../api"; import { useT } from "../i18n"; import { confirmDialog, promptDialog, toast } from "../dialogs"; /** Rewind to a message, optionally restoring the files the agent changed since. */ export function RewindDialog({ sessionId, messageId, onDone, onClose }: { sessionId: string; messageId: string; onDone: () => void; onClose: () => void }) { const t = useT(); const [files, setFiles] = useState<{ path: string; created: boolean }[]>(); const [restore, setRestore] = useState(true); const [busy, setBusy] = useState(false); useEffect(() => { get<{ path: string; created: boolean }[]>(`/sessions/${sessionId}/changes?since_message=${messageId}`).then(setFiles).catch(() => setFiles([])); }, [sessionId, messageId]); const go = async () => { setBusy(true); try { await post(`/sessions/${sessionId}/rewind`, { message_id: messageId, restore_files: restore && !!files?.length }); onDone(); } catch (e: any) { toast(e.message); setBusy(false); } }; return (
{t("rewind.intro")}
{files === undefined ? ({t("rewind.noFiles")}
) : ( <>{f.path} {f.created && {t("rewind.willDelete")}}
{t("rewind.bashNote")}
> )}