import { useCallback, useRef, useState } from "react"; import { Link } from "react-router-dom"; import { Upload, Image as ImageIcon, PlayCircle, RotateCcw, LayoutList } from "lucide-react"; import { toast } from "sonner"; import { forgesight, fileToBase64 } from "@/lib/api"; import TelemetryWidget from "@/components/TelemetryWidget"; import AgentTranscript from "@/components/AgentTranscript"; import ReportDownloader from "@/components/ReportDownloader"; export default function Console() { const [file, setFile] = useState(null); const [preview, setPreview] = useState(""); const [notes, setNotes] = useState(""); const [spec, setSpec] = useState(""); const [loading, setLoading] = useState(false); const [result, setResult] = useState(null); const [dragActive, setDragActive] = useState(false); const inputRef = useRef(null); const reportRef = useRef(null); const handleFile = useCallback((f) => { if (!f) return; if (!/(jpe?g|png|webp)$/i.test(f.type.split("/")[1] || f.name.split(".").pop())) { toast.error("Only JPEG / PNG / WEBP images are supported"); return; } setFile(f); setPreview(URL.createObjectURL(f)); setResult(null); }, []); const onDrop = (e) => { e.preventDefault(); setDragActive(false); const f = e.dataTransfer.files?.[0]; handleFile(f); }; const runInspection = async () => { if (!file) { toast.error("Upload an image first"); return; } setLoading(true); setResult(null); try { const image_base64 = await fileToBase64(file); const data = await forgesight.createInspection({ image_base64, notes, product_spec: spec, source: "upload", }); setResult(data); toast.success("Inspection complete"); } catch (e) { toast.error(e?.response?.data?.detail || "Inspection failed"); } finally { setLoading(false); } }; const reset = () => { setFile(null); setPreview(""); setNotes(""); setSpec(""); setResult(null); }; const summary = result?.summary; return (
§ CONSOLE · REAL-TIME INFERENCE

Inspection Console

Upload a construction site, road infrastructure, or housing image. Four agents will collaborate to deliver a structural or safety verdict.

{/* LEFT — input */}
Specimen {file && ( )}
{!preview ? (
{ e.preventDefault(); setDragActive(true); }} onDragLeave={() => setDragActive(false)} onDrop={onDrop} className={`fs-drop ${dragActive ? "fs-drop-active" : ""} h-64 flex flex-col items-center justify-center cursor-pointer`} onClick={() => inputRef.current?.click()} data-testid="drop-zone" >
Drop image here
or click to browse · JPG · PNG · WEBP
handleFile(e.target.files?.[0])} data-testid="file-input" />
) : (
specimen
{file?.name?.slice(0, 28)}
)}
Inspector Notes