'use client' import { useState, useEffect } from 'react' import { CpuChipIcon, ServerIcon, CircleStackIcon, GlobeAltIcon, CheckCircleIcon, ExclamationTriangleIcon, ArrowPathIcon } from '@heroicons/react/24/outline' interface SystemInfo { hostname: string os: { name: string version: string arch: string } hardware: { cpu: { cores: number model: string } memory: { total: number available: number } storage: { total: number available: number } gpus: Array<{ type: string name: string memory: number }> } network: { interfaces: Array<{ name: string ip: string mac: string speed: string status: string }> primary_interface: string primary_ip: string } software: { docker: { installed: boolean version?: string } ollama: { installed: boolean type?: 'ollama' | 'parallama' version?: string } bzzz: { installed: boolean version?: string } } } interface SystemDetectionProps { systemInfo: SystemInfo | null configData: any onComplete: (data: any) => void onBack?: () => void isCompleted: boolean } export default function SystemDetection({ systemInfo, configData, onComplete, onBack, isCompleted }: SystemDetectionProps) { const [loading, setLoading] = useState(!systemInfo) const [refreshing, setRefreshing] = useState(false) const [detectedInfo, setDetectedInfo] = useState(systemInfo) useEffect(() => { if (!detectedInfo) { refreshSystemInfo() } }, []) const refreshSystemInfo = async () => { setRefreshing(true) try { const response = await fetch('/api/system/detect') if (response.ok) { const info = await response.json() setDetectedInfo(info) } } catch (error) { console.error('Failed to detect system info:', error) } finally { setLoading(false) setRefreshing(false) } } const handleContinue = () => { if (detectedInfo) { onComplete({ system: detectedInfo, validated: true }) } } const formatMemory = (bytes: number) => { return `${Math.round(bytes / (1024 ** 3))} GB` } const formatStorage = (bytes: number) => { return `${Math.round(bytes / (1024 ** 3))} GB` } const getStatusColor = (condition: boolean) => { return condition ? 'text-green-600' : 'text-red-600' } const getStatusIcon = (condition: boolean) => { return condition ? CheckCircleIcon : ExclamationTriangleIcon } if (loading) { return (

Detecting system configuration...

) } if (!detectedInfo) { return (

System Detection Failed

Unable to detect system configuration. Please try again.

) } return (
{/* System Overview */}

System Overview

Hostname
{detectedInfo.hostname}
Operating System
{detectedInfo.os.name} {detectedInfo.os.version} ({detectedInfo.os.arch})
{/* Hardware Information */}
{/* CPU & Memory */}

CPU & Memory

CPU
{detectedInfo.hardware.cpu.cores} cores - {detectedInfo.hardware.cpu.model}
Memory
{formatMemory(detectedInfo.hardware.memory.total)} total, {' '} {formatMemory(detectedInfo.hardware.memory.available)} available
{/* Storage */}

Storage

Disk Space
{formatStorage(detectedInfo.hardware.storage.total)} total, {' '} {formatStorage(detectedInfo.hardware.storage.available)} available
{/* GPU Information */} {detectedInfo.hardware.gpus.length > 0 && (

GPU Configuration ({detectedInfo.hardware.gpus.length} GPU{detectedInfo.hardware.gpus.length !== 1 ? 's' : ''})

{detectedInfo.hardware.gpus.map((gpu, index) => (
{gpu.name}
{gpu.type.toUpperCase()} • {Math.round(gpu.memory / (1024 ** 3))} GB VRAM
))}
)} {/* Network Information */}

Network Configuration

Primary Interface
{detectedInfo.network.primary_interface} ({detectedInfo.network.primary_ip})
{detectedInfo.network.interfaces.length > 1 && (
All Interfaces
{detectedInfo.network.interfaces.map((interface_, index) => (
{interface_.name} {interface_.ip} {interface_.status}
))}
)}
{/* Software Requirements */}

Software Requirements

{[ { name: 'Docker', installed: detectedInfo.software.docker.installed, version: detectedInfo.software.docker.version, required: true }, { name: detectedInfo.software.ollama.type === 'parallama' ? 'Parallama' : 'Ollama', installed: detectedInfo.software.ollama.installed, version: detectedInfo.software.ollama.version, required: false }, { name: 'BZZZ', installed: detectedInfo.software.bzzz.installed, version: detectedInfo.software.bzzz.version, required: true } ].map((software, index) => { const StatusIcon = getStatusIcon(software.installed) return (
{software.name}
{software.version && (
Version: {software.version}
)}
{software.required && ( Required )} {software.installed ? 'Installed' : 'Missing'}
) })}
{/* System Validation */}

System Validation

{[ { check: 'Minimum memory (2GB required)', passed: detectedInfo.hardware.memory.total >= 2 * 1024 ** 3, warning: detectedInfo.hardware.memory.total < 4 * 1024 ** 3 }, { check: 'Available disk space (10GB required)', passed: detectedInfo.hardware.storage.available >= 10 * 1024 ** 3 }, { check: 'Docker installed and running', passed: detectedInfo.software.docker.installed }, { check: 'BZZZ binaries installed', passed: detectedInfo.software.bzzz.installed } ].map((validation, index) => { const StatusIcon = getStatusIcon(validation.passed) return (
{validation.check} {validation.warning && validation.passed && ( (Warning: Recommend 4GB+) )}
) })}
{/* Action Buttons */}
{onBack && ( )}
) }