feat: causal lab — debug endpoint + error display in UI

This commit is contained in:
OpenSquared
2026-06-27 23:36:22 +02:00
parent a7f5369d7b
commit 7a0263989a
2 changed files with 48 additions and 2 deletions

View File

@@ -173,11 +173,21 @@ function TabLibrary() {
const [saving, setSaving] = useState(false)
const [editCoefs, setEditCoefs] = useState<Record<string, number>>({})
const [loading, setLoading] = useState(true)
const [apiError, setApiError] = useState<string | null>(null)
const [debugInfo, setDebugInfo] = useState<Record<string, unknown> | null>(null)
useEffect(() => {
setLoading(true)
setLoading(true); setApiError(null)
api(`/api/causal-lab/templates${catFilter ? `?category=${catFilter}` : ''}`)
.then(setTemplates).finally(() => setLoading(false))
.then(data => {
setTemplates(data)
if (data.length === 0) {
// Auto-run debug to show diagnostic
api('/api/causal-lab/debug').then(setDebugInfo).catch(() => {})
}
})
.catch(e => setApiError(String(e)))
.finally(() => setLoading(false))
}, [catFilter])
function selectTemplate(t: Template) {
@@ -213,6 +223,18 @@ function TabLibrary() {
{cats.map(c => <option key={c} value={c}>{CAT_LABELS[c] ?? c}</option>)}
</select>
{apiError && (
<div className="mb-2 p-3 bg-red-900/20 border border-red-700/40 rounded text-xs text-red-300 break-all">
<div className="font-bold mb-1">Erreur API</div>
{apiError}
</div>
)}
{debugInfo && (
<div className="mb-2 p-3 bg-yellow-900/20 border border-yellow-700/40 rounded text-xs text-yellow-200">
<div className="font-bold mb-1">Diagnostic</div>
<pre className="whitespace-pre-wrap">{JSON.stringify(debugInfo, null, 2)}</pre>
</div>
)}
{loading
? <div className="text-slate-500 text-xs p-4">Chargement</div>
: <div className="space-y-1 overflow-y-auto max-h-[calc(100vh-230px)]">