Files
ThothII/frontend/src/store/sessionStore.ts
T
marcopanandClaude Opus 4.8 b056ff334f feat(frontend): phase progress dots (B) + compact sidebar redesign (C)
B — WorkflowBar renders F1..F8 as colored ring-dots (no phase-name text):
green=done, amber=running (subtle pulse), red=error, gray=pending; green
connectors lead the active dot, each dot carries data-state. Lightweight
error signal: sessionStore gains `phaseError`, set when an info event has
level=error during the active phase, cleared on the next ui_request.

C — denser single-line session rows (inline status dot + name, py-1), a
3-level type hierarchy (L1 SESSIONS / L2 section+group headers / L3 names),
and the "No group" label removed (ungrouped render after the last group,
guarded so the empty-state still teaches when there are zero groups).

Live-verified with Playwright (all four dot states, sidebar hierarchy, and
E's deferred activity-panel check). Frontend 93/93, tsc -b clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 17:53:29 +02:00

71 lines
2.6 KiB
TypeScript

import { create } from "zustand";
import type { StreamEvent, WidgetDescriptor } from "../api/types";
interface Entry {
role: "assistant";
text: string;
}
interface SessionState {
pendingWidget: WidgetDescriptor | null;
transcript: Entry[];
toasts: { level: string; text: string }[];
stepMessages: { level: string; text: string }[];
lastUserEntry: { kind: "input" | "choice"; text: string } | null;
lastSystemEvent: StreamEvent | null;
currentPhase: string | null;
phaseError: string | null;
applyEvent: (e: StreamEvent) => void;
clearPending: () => void;
resetSession: () => void;
setPhase: (phase: string | null) => void;
pushToast: (toast: { level: string; text: string }) => void;
setLastUserEntry: (e: { kind: "input" | "choice"; text: string }) => void;
}
const empty = {
pendingWidget: null,
transcript: [] as Entry[],
toasts: [] as { level: string; text: string }[],
stepMessages: [] as { level: string; text: string }[],
lastUserEntry: null as { kind: "input" | "choice"; text: string } | null,
lastSystemEvent: null,
currentPhase: null as string | null,
phaseError: null as string | null,
};
export const useSessionStore = create<SessionState>((set) => ({
...empty,
applyEvent: (e) =>
set((st) => {
if (e.type === "ui_request")
return {
pendingWidget: e.ui_request,
currentPhase: e.ui_request.phase
? e.ui_request.phase.split("_")[0]
: st.currentPhase,
// A new gate means the phase moved on (or re-presented): clear any error flag.
phaseError: null,
};
if (e.type === "text_delta") {
const t = [...st.transcript];
const last = t.at(-1);
if (last && !st.pendingWidget) t[t.length - 1] = { role: "assistant", text: last.text + e.text };
else t.push({ role: "assistant", text: e.text });
return { transcript: t };
}
if (e.type === "info") {
const stepMessages = [...st.stepMessages, { level: e.level ?? "info", text: e.text }];
// An error during the active phase marks that phase red until the next gate.
return e.level === "error" ? { stepMessages, phaseError: st.currentPhase } : { stepMessages };
}
if (e.type === "system_event") return { lastSystemEvent: e };
return {};
}),
clearPending: () => set({ pendingWidget: null }),
resetSession: () => set({ ...empty }),
setPhase: (phase) => set({ currentPhase: phase }),
pushToast: (toast) => set((st) => ({ toasts: [...st.toasts, toast] })),
setLastUserEntry: (e) => set({ lastUserEntry: e, stepMessages: [] }),
}));