"use client"; import { IconCheck, IconX, IconLoader2 } from "@tabler/icons-react"; import { useAppStore } from "@/components/state-provider"; import type { PrepareStepInfo } from "@/lib/state/slices/session-runtime/types"; type PrepareProgressProps = { sessionId: string; }; function StepIcon({ status }: { status: string }) { if (status === "completed") { return ; } if (status === "failed") { return ; } if (status === "running") { return ; } return
; } function StepRow({ step }: { step: PrepareStepInfo }) { return (
{step.name || "Preparing..."} {step.output && (
            {step.output}
          
)} {step.error && (
            {step.error}
          
)}
); } function useEffectivePrepareStatus(sessionId: string) { const prepareState = useAppStore((state) => state.prepareProgress.bySessionId[sessionId] ?? null); const sessionState = useAppStore((state) => state.taskSessions.items[sessionId]?.state); const profileLabel = useAppStore((state) => { const session = state.taskSessions.items[sessionId]; if (!session?.agent_profile_id) return null; const profile = state.agentProfiles.items.find((p) => p.id === session.agent_profile_id); return profile?.label ?? null; }); if (!prepareState) return { visible: false, status: "preparing", prepareState, profileLabel } as const; if (prepareState.status === "completed") return { visible: false, status: "completed", prepareState, profileLabel } as const; // If session reached a terminal state but prepare status is still "preparing", // treat it as failed (the completed event may not have arrived) const isSessionTerminal = sessionState === "FAILED" || sessionState === "COMPLETED" || sessionState === "CANCELLED"; const status = prepareState.status === "preparing" && isSessionTerminal ? "failed" : prepareState.status; return { visible: true, status, prepareState, profileLabel } as const; } export function PrepareProgress({ sessionId }: PrepareProgressProps) { const { visible, status, prepareState, profileLabel } = useEffectivePrepareStatus(sessionId); if (!visible || !prepareState) return null; const visibleSteps = prepareState.steps.filter( (step) => step.name.trim() !== "" || Boolean(step.output) || Boolean(step.error), ); return (
{status === "preparing" && } {status === "failed" && } {status === "preparing" && "Preparing environment..."} {status === "failed" && (prepareState.errorMessage ?? "Environment preparation failed")} {profileLabel && ( {profileLabel} )}
{visibleSteps.length > 0 && (
{visibleSteps.map((step, i) => ( ))}
)}
); }