import React, { useState, useEffect } from 'react' import { Button } from '@/components/ui/button' import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog' import SelectInput from '@/components/form/SelectInput' import { RefreshCw, AlertCircle, Loader2, ChevronDown, ChevronRight, Monitor, HelpCircle, Info } from 'lucide-react' import { serverApi } from '@/lib/api' import { BackendType, type BackendTypeValue } from '@/types/instance' // Helper to get version from environment const getAppVersion = (): string => { try { return (import.meta.env as Record).VITE_APP_VERSION || 'unknown' } catch { return 'unknown' } } interface SystemInfoDialogProps { open: boolean onOpenChange: (open: boolean) => void } interface BackendInfo { version: string devices: string help: string } const BACKEND_OPTIONS = [ { value: BackendType.LLAMA_CPP, label: 'Llama Server' }, { value: BackendType.MLX_LM, label: 'MLX LM' }, { value: BackendType.VLLM, label: 'vLLM' }, ] const SystemInfoDialog: React.FC = ({ open, onOpenChange }) => { const [selectedBackend, setSelectedBackend] = useState(BackendType.LLAMA_CPP) const [backendInfo, setBackendInfo] = useState(null) const [loading, setLoading] = useState(false) const [error, setError] = useState(null) const [showHelp, setShowHelp] = useState(false) // Fetch backend info const fetchBackendInfo = async (backend: BackendTypeValue) => { if (backend !== BackendType.LLAMA_CPP) { setBackendInfo(null) setError(null) return } setLoading(true) setError(null) try { const [version, devices, help] = await Promise.all([ serverApi.getVersion(), serverApi.getDevices(), serverApi.getHelp() ]) setBackendInfo({ version, devices, help }) } catch (err) { setError(err instanceof Error ? err.message : 'Failed to fetch backend info') } finally { setLoading(false) } } // Load data when dialog opens or backend changes useEffect(() => { if (open) { void fetchBackendInfo(selectedBackend) } }, [open, selectedBackend]) const handleBackendChange = (value: string) => { setSelectedBackend(value as BackendTypeValue) setShowHelp(false) // Reset help section when switching backends } const renderBackendSpecificContent = () => { if (selectedBackend !== BackendType.LLAMA_CPP) { return (

Backend Info Not Available

Information for {BACKEND_OPTIONS.find(b => b.value === selectedBackend)?.label} backend is not yet implemented.

) } if (loading && !backendInfo) { return (
Loading backend information...
) } if (error) { return (
{error}
) } if (!backendInfo) { return null } return (
{/* Backend Version Section */}

{BACKEND_OPTIONS.find(b => b.value === selectedBackend)?.label} Version

$ llama-server --version
              {backendInfo.version}
            
{/* Devices Section */}

Available Devices

$ llama-server --list-devices
              {backendInfo.devices}
            
{/* Help Section */}
{showHelp && (
$ llama-server --help
                {backendInfo.help}
              
)}
) } return ( System Information View system and backend-specific environment and capabilities
{/* Llamactl Version Section - Always shown */}

Llamactl Version

                  {getAppVersion()}
                
{/* Backend Selection Section */}

Backend Information

handleBackendChange(value || BackendType.LLAMA_CPP)} options={BACKEND_OPTIONS} className="text-sm" />
{selectedBackend === BackendType.LLAMA_CPP && ( )}
{/* Backend-specific content */} {renderBackendSpecificContent()}
) } export default SystemInfoDialog