/** * Intelligent Optimizer Panel - Protocol 13 * Displays real-time optimizer state: phase, strategy, progress, confidence */ import { useEffect, useState } from 'react'; interface OptimizerState { available: boolean; current_phase?: string; current_strategy?: string; trial_number?: number; total_trials?: number; is_multi_objective?: boolean; latest_recommendation?: { strategy: string; confidence: number; reasoning: string; }; } export function OptimizerPanel({ studyId }: { studyId: string }) { const [state, setState] = useState(null); const [error, setError] = useState(null); useEffect(() => { const fetchState = async () => { try { const res = await fetch(`/api/optimization/studies/${studyId}/optimizer-state`); if (!res.ok) { throw new Error(`HTTP ${res.status}`); } const data = await res.json(); setState(data); setError(null); } catch (err) { console.error('Failed to fetch optimizer state:', err); setError('Failed to load'); } }; fetchState(); const interval = setInterval(fetchState, 1000); // Update every second return () => clearInterval(interval); }, [studyId]); if (error) { return (

Intelligent Optimizer

{error}
); } if (!state?.available) { return null; } // Format phase name for display const formatPhase = (phase?: string) => { if (!phase) return 'Unknown'; return phase .split('_') .map(word => word.charAt(0).toUpperCase() + word.slice(1)) .join(' '); }; // Format strategy name for display const formatStrategy = (strategy?: string) => { if (!strategy) return 'Not set'; return strategy.toUpperCase(); }; const progress = state.trial_number && state.total_trials ? (state.trial_number / state.total_trials) * 100 : 0; return (

Intelligent Optimizer {state.is_multi_objective && ( Multi-Objective )}

{/* Phase */}
Phase
{formatPhase(state.current_phase)}
{/* Strategy */}
Current Strategy
{formatStrategy(state.current_strategy)}
{/* Progress */}
Progress
{state.trial_number || 0} / {state.total_trials || 0} trials
{/* Confidence (if available) */} {state.latest_recommendation && (
Confidence
{(state.latest_recommendation.confidence * 100).toFixed(0)}%
)} {/* Reasoning (if available) */} {state.latest_recommendation && (
Reasoning
{state.latest_recommendation.reasoning}
)}
); }