import { useState } from "react"; import type { TaskCheckpoint } from "../../lib/api"; import { rewindTask, resumeSupervisor, rewindSupervisorConversation } from "../../lib/api"; interface ResumeControlsProps { taskId: string; contractId: string | null; checkpoints: TaskCheckpoint[]; onActionComplete: () => void; } export function ResumeControls({ taskId, contractId, checkpoints, onActionComplete, }: ResumeControlsProps) { const [showRewindDialog, setShowRewindDialog] = useState(false); const [showSupervisorDialog, setShowSupervisorDialog] = useState(false); const [selectedCheckpoint, setSelectedCheckpoint] = useState(""); const [preserveMode, setPreserveMode] = useState<"discard" | "create_branch">("create_branch"); const [branchName, setBranchName] = useState(""); const [resumeMode, setResumeMode] = useState<"continue" | "restart_phase">("continue"); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const handleRewindTask = async () => { if (!selectedCheckpoint) { setError("Select a checkpoint"); return; } setIsLoading(true); setError(null); try { await rewindTask(taskId, { checkpointId: selectedCheckpoint, preserveMode, branchName: preserveMode === "create_branch" ? branchName || undefined : undefined, }); setShowRewindDialog(false); onActionComplete(); } catch (e) { setError(e instanceof Error ? e.message : "Failed to rewind task"); } finally { setIsLoading(false); } }; const handleResumeSupervisor = async () => { if (!contractId) return; setIsLoading(true); setError(null); try { await resumeSupervisor(contractId, { resumeMode, }); setShowSupervisorDialog(false); onActionComplete(); } catch (e) { setError(e instanceof Error ? e.message : "Failed to resume supervisor"); } finally { setIsLoading(false); } }; const handleRewindConversation = async () => { if (!contractId) return; setIsLoading(true); setError(null); try { await rewindSupervisorConversation(contractId, { byMessageCount: 1, // Rewind by 1 message }); onActionComplete(); } catch (e) { setError(e instanceof Error ? e.message : "Failed to rewind conversation"); } finally { setIsLoading(false); } }; return ( <>
{/* Task controls */} {checkpoints.length > 0 && ( )} {/* Supervisor controls */} {contractId && ( <> )}
{/* Rewind Task Dialog */} {showRewindDialog && (

Rewind Task Code

{error && (
{error}
)}
{preserveMode === "create_branch" && (
setBranchName(e.target.value)} placeholder="Auto-generated if empty" className="w-full font-mono text-xs text-[#9bc3ff] bg-[#0a1525] border border-[rgba(117,170,252,0.25)] px-3 py-2 focus:border-[#3f6fb3] focus:outline-none" />
)}
)} {/* Resume Supervisor Dialog */} {showSupervisorDialog && (

Resume Supervisor

{error && (
{error}
)}
)} ); }