/** * SetupTab/EmbedderHealthCard.tsx — embedder health probe card (Part A). * * Round-trips a test embed through the active embedder and shows ✓ working / * ✗ unreachable + latency + dimensions. Polls every 30s. */ import type React from "react"; import { useState, useEffect, useCallback } from "react"; import type { EmbedderHealthResponse } from "@contracts"; import { fetchEmbedderHealth } from "../../api/client"; const styles: Record = { section: { background: "#1a1a2e", borderRadius: "8px", padding: "1rem", marginBottom: "1rem", border: "1px solid #2a2a4e", }, sectionTitle: { fontSize: "1.1rem", fontWeight: 700, marginTop: 0, marginBottom: "0.75rem", color: "#e0e0e0", borderBottom: "1px solid #333", paddingBottom: "0.5rem", }, label: { fontWeight: 600, color: "#a0a0c0", marginRight: "0.5rem" }, value: { color: "#e0e0e0" }, row: { marginBottom: "0.4rem", fontSize: "0.9rem" }, }; export default function EmbedderHealthCard(): React.ReactElement { const [health, setHealth] = useState(null); const [error, setError] = useState(null); const loadHealth = useCallback(() => { fetchEmbedderHealth() .then(setHealth) .catch((e: unknown) => setError(e instanceof Error ? e.message : String(e)), ); }, []); useEffect(() => { loadHealth(); }, [loadHealth]); // Poll health every 30s useEffect(() => { const id = setInterval(loadHealth, 30000); return () => clearInterval(id); }, [loadHealth]); const ok = health?.status === "ok"; const statusText = health?.status === "ok" ? "Working" : health?.status === "unreachable" ? "Unreachable" : "Error"; const color = ok ? "#4caf50" : "#f44336"; const icon = ok ? "✓" : "✗"; return (

Embedder Health

{error && (

Error: {error}

)} {!health && !error && (

Probing embedder...

)} {health && ( <>
{icon} {statusText}: {health.dim} dims {health.latencyMs !== undefined && ( ({health.latencyMs.toFixed(1)} ms) )}
Endpoint: {health.url ?? ( built-in (no URL) )}
{health.error && (

{health.error}

)} )}
); }