'use client' import { useState, useEffect } from 'react' import { ChevronRightIcon, CheckCircleIcon } from '@heroicons/react/24/outline' import TermsAndConditions from './components/TermsAndConditions' import LicenseValidation from './components/LicenseValidation' import SystemDetection from './components/SystemDetection' import RepositoryConfiguration from './components/RepositoryConfiguration' import NetworkConfiguration from './components/NetworkConfiguration' import SecuritySetup from './components/SecuritySetup' import AIConfiguration from './components/AIConfiguration' import ServiceDeployment from './components/ServiceDeployment' import ClusterFormation from './components/ClusterFormation' import TestingValidation from './components/TestingValidation' const SETUP_STEPS = [ { id: 'terms', title: 'Terms & Conditions', description: 'Review and accept the software license agreement', component: TermsAndConditions, }, { id: 'license', title: 'License Validation', description: 'Validate your CHORUS license key and email', component: LicenseValidation, }, { id: 'detection', title: 'System Detection', description: 'Detect hardware and validate installation', component: SystemDetection, }, { id: 'repository', title: 'Repository Setup', description: 'Configure Git repository for task management', component: RepositoryConfiguration, }, { id: 'network', title: 'Network Configuration', description: 'Configure network and firewall settings', component: NetworkConfiguration, }, { id: 'security', title: 'Security Setup', description: 'Configure authentication and SSH access', component: SecuritySetup, }, { id: 'ai', title: 'AI Integration', description: 'Configure OpenAI and Ollama/Parallama', component: AIConfiguration, }, { id: 'deployment', title: 'Service Deployment', description: 'Deploy and configure CHORUS agent services', component: ServiceDeployment, }, { id: 'cluster', title: 'Cluster Formation', description: 'Join or create CHORUS agent cluster', component: ClusterFormation, }, { id: 'testing', title: 'Testing & Validation', description: 'Validate configuration and test connectivity', component: TestingValidation, }, ] interface ConfigData { [key: string]: any } export default function SetupPage() { const [currentStep, setCurrentStep] = useState(0) const [completedSteps, setCompletedSteps] = useState(new Set()) const [configData, setConfigData] = useState({}) const [systemInfo, setSystemInfo] = useState(null) // Load persisted data and system information on mount useEffect(() => { loadPersistedData() fetchSystemInfo() }, []) // Save setup state to localStorage whenever it changes useEffect(() => { saveSetupState() }, [currentStep, completedSteps, configData]) const loadPersistedData = () => { try { const savedState = localStorage.getItem('chorus-setup-state') if (savedState) { const state = JSON.parse(savedState) setCurrentStep(state.currentStep || 0) setCompletedSteps(new Set(state.completedSteps || [])) setConfigData(state.configData || {}) } } catch (error) { console.error('Failed to load persisted setup data:', error) } } const saveSetupState = () => { try { const state = { currentStep, completedSteps: Array.from(completedSteps), configData, timestamp: new Date().toISOString() } localStorage.setItem('chorus-setup-state', JSON.stringify(state)) } catch (error) { console.error('Failed to save setup state:', error) } } const clearPersistedData = () => { try { localStorage.removeItem('chorus-setup-state') // Reset state to initial values setCurrentStep(0) setCompletedSteps(new Set()) setConfigData({}) } catch (error) { console.error('Failed to clear persisted data:', error) } } const fetchSystemInfo = async () => { try { const response = await fetch('/api/setup/system') if (response.ok) { const result = await response.json() setSystemInfo(result.system_info) } } catch (error) { console.error('Failed to fetch system info:', error) } } const handleStepComplete = (stepIndex: number, data: any) => { console.log('Setup Page: Step complete', { stepIndex, data, currentConfigData: configData }) setCompletedSteps(prev => new Set([...prev, stepIndex])) setConfigData(prev => { const newConfigData = { ...prev, ...data } console.log('Setup Page: Updated configData', { prev, data, newConfigData }) return newConfigData }) // Auto-advance to next step if (stepIndex < SETUP_STEPS.length - 1) { setCurrentStep(stepIndex + 1) } else { // Setup is complete, clear persisted data after a delay setTimeout(() => { clearPersistedData() }, 2000) } } const handleStepBack = () => { if (currentStep > 0) { setCurrentStep(currentStep - 1) } } const CurrentStepComponent = SETUP_STEPS[currentStep].component // Check if we're resuming from saved data const isResuming = currentStep > 0 || completedSteps.size > 0 || Object.keys(configData).length > 0 return (

CHORUS Agent Setup

Configure your distributed agent orchestration platform in {SETUP_STEPS.length} simple steps.

{/* Resume Setup Notification */} {isResuming && (

Setup Progress Restored

Your previous setup progress has been restored. You're currently on step {currentStep + 1} of {SETUP_STEPS.length}. {completedSteps.size > 0 && ` You've completed ${completedSteps.size} step${completedSteps.size !== 1 ? 's' : ''}.`}

)}
{/* Progress Sidebar */}

Setup Progress

Progress: {completedSteps.size} of {SETUP_STEPS.length} steps
{/* Main Content */}

{SETUP_STEPS[currentStep].title}

Step {currentStep + 1} of {SETUP_STEPS.length}

{SETUP_STEPS[currentStep].description}

handleStepComplete(currentStep, data)} onBack={currentStep > 0 ? handleStepBack : undefined} isCompleted={completedSteps.has(currentStep)} />
) }