feat: agent session retry + follow-up UX
- retry/route.ts: reset failed/stopped session and re-fire agent runner with optional continueTask follow-up text - build/page.tsx: Retry button and Follow up input appear on failed/stopped sessions so users can continue without losing context or creating a duplicate session; task input hint clarifies each Run = new session Made-with: Cursor
This commit is contained in:
@@ -278,6 +278,9 @@ function AgentMode({ projectId, appName, appPath }: { projectId: string; appName
|
||||
const [approveMsg, setApproveMsg] = useState("");
|
||||
const [showApproveInput, setShowApproveInput] = useState(false);
|
||||
const [approveResult, setApproveResult] = useState<string | null>(null);
|
||||
const [retrying, setRetrying] = useState(false);
|
||||
const [followUp, setFollowUp] = useState("");
|
||||
const [showFollowUp, setShowFollowUp] = useState(false);
|
||||
const outputRef = useCallback((el: HTMLDivElement | null) => {
|
||||
if (el) el.scrollTop = el.scrollHeight;
|
||||
}, []);
|
||||
@@ -346,6 +349,24 @@ function AgentMode({ projectId, appName, appPath }: { projectId: string; appName
|
||||
setActiveSession(prev => prev ? { ...prev, status: "stopped" } : null);
|
||||
};
|
||||
|
||||
const handleRetry = async (continueTask?: string) => {
|
||||
if (!activeSessionId) return;
|
||||
setRetrying(true);
|
||||
try {
|
||||
const r = await fetch(`/api/projects/${projectId}/agent/sessions/${activeSessionId}/retry`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ continueTask: continueTask?.trim() || undefined }),
|
||||
});
|
||||
const d = await r.json();
|
||||
if (d.sessionId) {
|
||||
setActiveSession(prev => prev ? { ...prev, status: "running", output: [], error: null } : null);
|
||||
setShowFollowUp(false);
|
||||
setFollowUp("");
|
||||
}
|
||||
} finally { setRetrying(false); }
|
||||
};
|
||||
|
||||
const handleApprove = async () => {
|
||||
if (!activeSessionId || !approveMsg.trim()) return;
|
||||
setApproving(true);
|
||||
@@ -459,6 +480,57 @@ function AgentMode({ projectId, appName, appPath }: { projectId: string; appName
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Retry / follow-up panel for failed or stopped sessions */}
|
||||
{["failed", "stopped"].includes(activeSession.status) && (
|
||||
<div style={{ borderTop: "1px solid #e8e4dc", background: "#fff", padding: "12px 20px", flexShrink: 0 }}>
|
||||
{showFollowUp ? (
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
|
||||
<div style={{ fontSize: "0.72rem", color: "#6b6560", fontFamily: "Outfit, sans-serif" }}>
|
||||
Add a follow-up instruction (optional) then retry:
|
||||
</div>
|
||||
<div style={{ display: "flex", gap: 8, alignItems: "flex-end" }}>
|
||||
<textarea
|
||||
autoFocus
|
||||
value={followUp}
|
||||
onChange={e => setFollowUp(e.target.value)}
|
||||
onKeyDown={e => { if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) handleRetry(followUp); if (e.key === "Escape") setShowFollowUp(false); }}
|
||||
placeholder="e.g. Also update the TypeScript types, or just leave blank to retry as-is…"
|
||||
rows={2}
|
||||
style={{ flex: 1, resize: "none", border: "1px solid #e8e4dc", borderRadius: 7, padding: "8px 11px", fontSize: "0.78rem", fontFamily: "Outfit, sans-serif", outline: "none", background: "#faf8f5" }}
|
||||
/>
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: 6 }}>
|
||||
<button onClick={() => handleRetry(followUp)} disabled={retrying}
|
||||
style={{ padding: "8px 14px", background: "#1a1a1a", color: "#fff", border: "none", borderRadius: 7, fontSize: "0.75rem", fontWeight: 600, cursor: "pointer", fontFamily: "Outfit, sans-serif", whiteSpace: "nowrap" }}>
|
||||
{retrying ? "Retrying…" : "Retry"}
|
||||
</button>
|
||||
<button onClick={() => setShowFollowUp(false)}
|
||||
style={{ padding: "6px 14px", background: "transparent", color: "#a09a90", border: "1px solid #e8e4dc", borderRadius: 7, fontSize: "0.73rem", cursor: "pointer", fontFamily: "Outfit, sans-serif" }}>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ fontSize: "0.63rem", color: "#b5b0a6", fontFamily: "Outfit, sans-serif" }}>
|
||||
⌘↵ to retry · Esc to cancel · Same session, fresh run
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ display: "flex", gap: 8, alignItems: "center" }}>
|
||||
<div style={{ fontSize: "0.75rem", color: activeSession.status === "failed" ? "#c62828" : "#a09a90", fontFamily: "Outfit, sans-serif", flex: 1 }}>
|
||||
{activeSession.status === "failed" ? "Session failed — retry without losing context" : "Session stopped"}
|
||||
</div>
|
||||
<button onClick={() => handleRetry()} disabled={retrying}
|
||||
style={{ padding: "7px 14px", background: "#fef9f0", color: "#92400e", border: "1px solid #fde68a", borderRadius: 7, fontSize: "0.75rem", fontWeight: 600, cursor: "pointer", fontFamily: "Outfit, sans-serif", whiteSpace: "nowrap" }}>
|
||||
{retrying ? "Retrying…" : "↺ Retry"}
|
||||
</button>
|
||||
<button onClick={() => setShowFollowUp(true)}
|
||||
style={{ padding: "7px 14px", background: "#f0ece4", color: "#1a1a1a", border: "1px solid #e8e4dc", borderRadius: 7, fontSize: "0.75rem", cursor: "pointer", fontFamily: "Outfit, sans-serif", whiteSpace: "nowrap" }}>
|
||||
Follow up…
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Changed files */}
|
||||
{activeSession.changed_files.length > 0 && (
|
||||
<div style={{ borderTop: "1px solid #e8e4dc", background: "#fff", padding: "12px 20px", flexShrink: 0 }}>
|
||||
@@ -576,7 +648,7 @@ function AgentMode({ projectId, appName, appPath }: { projectId: string; appName
|
||||
</button>
|
||||
</div>
|
||||
<div style={{ fontSize: "0.65rem", color: "#b5b0a6", marginTop: 5, fontFamily: "Outfit, sans-serif" }}>
|
||||
⌘↵ to run · Session persists if you close the browser
|
||||
⌘↵ to start · Each task is a new session · Use "Follow up" on a failed session to continue it
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user