({ isVisible })
| 61 | }; |
| 62 | |
| 63 | const LlmDebugPanel: React.FC<LlmDebugPanelProps> = ({ isVisible }) => { |
| 64 | const [debugInfo, setDebugInfo] = useState<LlmDebugInfo | null>(null); |
| 65 | const [loading, setLoading] = useState(false); |
| 66 | const [error, setError] = useState<string | null>(null); |
| 67 | |
| 68 | // Sampler params state |
| 69 | const [samplerParams, setSamplerParams] = useState<SamplerParams>(DEFAULT_SAMPLER_PARAMS); |
| 70 | const [samplerDirty, setSamplerDirty] = useState(false); |
| 71 | |
| 72 | // Test generation state |
| 73 | const [testPrompt, setTestPrompt] = useState('Hello, how are you today?'); |
| 74 | const [testResponse, setTestResponse] = useState(''); |
| 75 | const [testMetrics, setTestMetrics] = useState<GenerationMetrics | null>(null); |
| 76 | const [isGenerating, setIsGenerating] = useState(false); |
| 77 | const [capturedImage, setCapturedImage] = useState<string | null>(null); // base64 data URL |
| 78 | const fileInputRef = useRef<HTMLInputElement>(null); |
| 79 | |
| 80 | // Console logs state |
| 81 | const [logs, setLogs] = useState<LogEntry[]>([]); |
| 82 | const logsEndRef = useRef<HTMLDivElement>(null); |
| 83 | |
| 84 | // Fetch debug info |
| 85 | const fetchDebugInfo = useCallback(async () => { |
| 86 | setLoading(true); |
| 87 | setError(null); |
| 88 | try { |
| 89 | const info = await NativeLlmManager.getInstance().getDebugInfo(); |
| 90 | setDebugInfo(info); |
| 91 | if (info.engine.samplerParams) { |
| 92 | setSamplerParams(info.engine.samplerParams); |
| 93 | setSamplerDirty(false); |
| 94 | } |
| 95 | } catch (e) { |
| 96 | setError(e instanceof Error ? e.message : String(e)); |
| 97 | } finally { |
| 98 | setLoading(false); |
| 99 | } |
| 100 | }, []); |
| 101 | |
| 102 | // Initial fetch and log subscription |
| 103 | useEffect(() => { |
| 104 | if (!isVisible) return; |
| 105 | |
| 106 | fetchDebugInfo(); |
| 107 | |
| 108 | // Subscribe to LLM logs |
| 109 | const listener = (entry: LogEntry) => { |
| 110 | if (entry.source === 'LlmEngine' || entry.source === 'NativeLlmManager') { |
| 111 | setLogs(prev => [...prev, entry].slice(-100)); |
| 112 | } |
| 113 | }; |
| 114 | Logger.addListener(listener); |
| 115 | |
| 116 | // Load existing logs |
| 117 | const existingLogs = Logger.getFilteredLogs({ |
| 118 | source: ['LlmEngine', 'NativeLlmManager'], |
| 119 | }).slice(-100); |
| 120 | setLogs(existingLogs); |
nothing calls this directly
no test coverage detected