import { useState } from "react"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import { AlertTriangle, Check, CircleAlert, Clock3, LoaderCircle, ShieldCheck, Trash2 } from "lucide-react"; import { toast } from "sonner"; import { Button } from "../components/ui/button"; import { apiErrorMessage } from "../api/client"; import { clearWorkspacePreprocessing, runWorkspacePreprocessing, type WorkspacePreprocessingState, type WorkspacePreprocessingStatus, } from "../api/workspace-preprocessing"; const TITLES: Record = { ready: "Complete", required: "Required", running: "Running", blocked: "Blocked", failed: "Failed", }; type PreprocessingProgress = NonNullable; const PROGRESS_LABELS: Record = { catalog_snapshot: "Preparing Catalog snapshot", schema_index: "Building schema and LSH", evidence: "Indexing Evidence", finalizing: "Finalizing", }; const INITIAL_PROGRESS: PreprocessingProgress = { stage: "catalog_snapshot", step: 1, totalSteps: 4, }; function stateClasses(state: WorkspacePreprocessingState | undefined): string { switch (state) { case "ready": return "text-emerald-700"; case "failed": return "text-destructive"; case "required": case "running": case "blocked": return "text-amber-700"; default: return "text-muted-foreground"; } } function StatusIcon({ state }: { state?: WorkspacePreprocessingState }) { if (state === "running") { return