fix(frontend): wire currentPhase to WorkflowBar (normalized) + WidgetHost error handling

- sessionStore.applyEvent: on ui_request set currentPhase normalized from the
  descriptor's phase to its short id (e.g. "F4_schema_linking" -> "F4"), so
  WorkflowBar actually highlights the active phase; falls back to the existing
  phase when the descriptor has none. setPhase kept for resume/getSession.
- Add pushToast store action; WidgetHost wraps postResponse in try/catch,
  pushes an error toast and keeps the widget pending on failure (clearPending
  only on success) so the user can retry.
- Tests: store currentPhase normalization + no-phase passthrough + pushToast;
  new WorkflowBar.test.tsx asserting the matching phase is highlighted.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-28 13:40:33 +02:00
co-authored by Claude Opus 4.8
parent ddbbe4d1ac
commit 5295e34898
4 changed files with 65 additions and 2 deletions
+16 -1
View File
@@ -6,10 +6,25 @@ import type { UiResponse } from "../api/types";
export function WidgetHost({ sessionId }: { sessionId: string | null }) {
const pending = useSessionStore((s) => s.pendingWidget);
const clearPending = useSessionStore((s) => s.clearPending);
const pushToast = useSessionStore((s) => s.pushToast);
if (!pending) return null;
const Renderer = resolve(pending.widget);
const onRespond = async (r: UiResponse) => {
if (sessionId) await postResponse(sessionId, r);
if (sessionId) {
try {
await postResponse(sessionId, r);
} catch (err) {
// Surface feedback and keep the widget pending so the user can retry.
pushToast({
level: "error",
text:
err instanceof Error
? `Invio risposta fallito: ${err.message}`
: "Invio risposta fallito.",
});
return;
}
}
clearPending();
};
return <Renderer descriptor={pending} onRespond={onRespond} />;