"use client" import { useEffect, useMemo, useState } from 'react' import Sidebar from './components/Sidebar' import SandboxList from './components/SandboxList' import ConfigurationPanel from './components/ConfigurationPanel' import { useSandboxInventory } from './hooks/useSandboxInventory' import { createHydrationSafeDashboardSessionState, loadDashboardSessionState, persistDashboardSessionState, updateDashboardSessionSelection, } from './lib/dashboardSession' export default function Dashboard() { const [theme, setTheme] = useState<'light' | 'dark'>('dark') const [dashboardSession, setDashboardSession] = useState(() => createHydrationSafeDashboardSessionState()) const [isCreateMode, setIsCreateMode] = useState(false) const [isDestroyMode, setIsDestroyMode] = useState(false) const [activeView, setActiveView] = useState<'settings' | 'sandboxes'>('sandboxes') const [deletingSandboxId, setDeletingSandboxId] = useState(null) const [showDeleteConfirm, setShowDeleteConfirm] = useState(false) const inventoryEnabled = activeView === 'sandboxes' || isCreateMode || isDestroyMode const { sandboxes, nemoclaw, loading, error, refresh } = useSandboxInventory({ enabled: inventoryEnabled, }) useEffect(() => { setDashboardSession(loadDashboardSessionState()) }, []) useEffect(() => { persistDashboardSessionState(dashboardSession) }, [dashboardSession]) useEffect(() => { document.documentElement.dataset.theme = theme }, [theme]) const selectedSandbox = useMemo( () => sandboxes.find((sandbox) => sandbox.id === dashboardSession.selectedSandboxId) ?? null, [sandboxes, dashboardSession.selectedSandboxId] ) const toggleTheme = () => { setTheme(theme === 'light' ? 'dark' : 'light') } const handleSandboxSelect = (id: string | null) => { if (isDestroyMode && id) { setDeletingSandboxId(id) setShowDeleteConfirm(true) } else { setDashboardSession((current) => updateDashboardSessionSelection(current, id)) } } const clearSelection = () => { setDashboardSession((current) => updateDashboardSessionSelection(current, null)) } const handleCreateSuccess = async (createdSandboxId: string) => { setIsCreateMode(false) setIsDestroyMode(false) setActiveView('sandboxes') const latest = await refresh() const created = latest.find((sandbox) => sandbox.id === createdSandboxId || sandbox.name === createdSandboxId) setDashboardSession((current) => updateDashboardSessionSelection(current, created?.id ?? createdSandboxId)) } const confirmDelete = () => { console.log('Destroying sandbox:', deletingSandboxId) setShowDeleteConfirm(false) setDeletingSandboxId(null) setIsDestroyMode(false) } const cancelDelete = () => { setShowDeleteConfirm(false) setDeletingSandboxId(null) } return (
sandbox.status === 'running').length} sandboxesTotal={sandboxes.length} isCreateMode={isCreateMode} isDestroyMode={isDestroyMode} activeView={activeView} onSandboxesClick={() => { setActiveView('sandboxes') setIsCreateMode(false) setIsDestroyMode(false) }} onCreateClick={() => { setActiveView('sandboxes') setIsCreateMode(true) setIsDestroyMode(false) clearSelection() }} onDestroyClick={() => { setActiveView('sandboxes') setIsDestroyMode(true) setIsCreateMode(false) }} onSettingsClick={() => { setActiveView('settings') setIsCreateMode(false) setIsDestroyMode(false) clearSelection() }} onExitMode={() => { setIsCreateMode(false) setIsDestroyMode(false) clearSelection() }} />
{activeView === 'settings' ? (

STATUS

Sandboxes

{sandboxes.length}

Running

{sandboxes.filter((sandbox) => sandbox.status === 'running').length}

OpenClaw

{nemoclaw?.available ? 'available' : 'not detected'}

) : isCreateMode ? (

CREATE SANDBOX

Choose a blueprint, name the sandbox, and create it.

) : isDestroyMode ? (

DESTROY SANDBOX

Click on any sandbox below to initiate destruction. All sandboxes are highlighted in red.

) : ( <>

OPENSHELL CONTROL

Manage local OpenShell sandboxes and operator access.

{inventoryEnabled && loading ? (
INITIALIZING...
) : inventoryEnabled && error ? (

Inventory Unavailable

{error}

) : sandboxes.length === 0 ? (

No Sandboxes Detected

No live OpenShell sandboxes reported yet

) : ( )} )}
{showDeleteConfirm && (

WARNING: DESTRUCTIVE ACTION

Destroying this sandbox will permanently delete it and it will not be recoverable. Are you sure?

)}
) }