fix: surface reviewer response failures

This commit is contained in:
2026-08-14 12:06:25 +02:00
parent 25b2835e73
commit db1a81cfa6
8 changed files with 166 additions and 3 deletions
+22 -1
View File
@@ -1,3 +1,4 @@
import { useRef, useState } from "react";
import { useSessionStore } from "../store/sessionStore";
import { resolve } from "../widgets";
import { postResponse } from "../api/sessions";
@@ -9,9 +10,15 @@ export function WidgetHost({ sessionId }: { sessionId: string | null }) {
const clearPending = useSessionStore((s) => s.clearPending);
const pushToast = useSessionStore((s) => s.pushToast);
const setLastUserEntry = useSessionStore((s) => s.setLastUserEntry);
const [responding, setResponding] = useState(false);
const responseInFlight = useRef(false);
if (!pending) return null;
const Renderer = resolve(pending.widget);
const onRespond = async (r: UiResponse) => {
if (responseInFlight.current) return;
responseInFlight.current = true;
setResponding(true);
if (sessionId) {
try {
await postResponse(sessionId, r);
@@ -24,9 +31,14 @@ export function WidgetHost({ sessionId }: { sessionId: string | null }) {
? `Failed to send response: ${err.message}`
: "Failed to send response.",
});
responseInFlight.current = false;
setResponding(false);
return;
}
}
responseInFlight.current = false;
setResponding(false);
pushToast({ level: "success", text: "Response sent. The model is continuing." });
setLastUserEntry({
kind: "choice",
text:
@@ -40,7 +52,16 @@ export function WidgetHost({ sessionId }: { sessionId: string | null }) {
// widget render. resetKeys on the descriptor id so the next gate starts clean.
return (
<ErrorBoundary resetKeys={[pending.id]} label="step">
<Renderer descriptor={pending} onRespond={onRespond} sessionId={sessionId ?? undefined} />
<div className="space-y-2">
<fieldset disabled={responding} className="min-w-0 border-0 p-0">
<Renderer descriptor={pending} onRespond={onRespond} sessionId={sessionId ?? undefined} />
</fieldset>
{responding && (
<p role="status" aria-live="polite" className="text-sm text-muted-foreground">
Sending response…
</p>
)}
</div>
</ErrorBoundary>
);
}