Spaces:
Running
Running
File size: 9,264 Bytes
24f95f0 5f91e0b 24f95f0 5f91e0b 24f95f0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | 'use client';
import { useState, useEffect, useCallback } from 'react';
import { usePathname, useRouter } from 'next/navigation';
import { motion, AnimatePresence } from 'framer-motion';
import { getApiBaseUrl } from '@/lib/api';
import {
MessageSquare, Globe, BarChart3, Layers, Activity,
Zap, Shield, Terminal, Settings, Plus,
ChevronLeft, ChevronRight, Menu, X, Brain, Mic
} from 'lucide-react';
const navSections = [
{
label: 'Main',
items: [
{ path: '/', label: 'Chat', icon: MessageSquare },
{ path: '/intel', label: 'Intel', icon: Globe },
{ path: '/markets', label: 'Markets', icon: BarChart3 },
{ path: '/workspace', label: 'Workspace', icon: Brain },
{ path: '/pulse', label: 'Pulse', icon: Activity },
],
},
{
label: 'Guardian',
items: [
{ path: '/guardian/intake', label: 'Forensic Intake', icon: Plus },
{ path: '/guardian/journey', label: 'Journey Graph', icon: Activity },
{ path: '/guardian/dissonance', label: 'Deception Radar', icon: Mic },
],
},
{
label: 'System',
items: [
{ path: '/cases', label: 'Cases', icon: Layers },
{ path: '/simulation', label: 'Simulation', icon: Zap },
{ path: '/sentinel', label: 'Sentinel', icon: Shield },
{ path: '/safety', label: 'Safety Gateway', icon: Zap },
{ path: '/prompts', label: 'Prompts', icon: Terminal },
{ path: '/config', label: 'Config', icon: Settings },
],
},
];
function JanusOrbSmall({ pulse = false }: { pulse?: boolean }) {
return (
<div className="relative w-8 h-8 shrink-0">
<div
className="absolute inset-0 rounded-full"
style={{
background: 'radial-gradient(circle at 35% 35%, #818cf8, #4f46e5 60%, #1e1b4b 100%)',
boxShadow: '0 0 12px rgba(99,102,241,0.3)',
}}
/>
{pulse && (
<div className="absolute inset-0 rounded-full animate-ping opacity-20 bg-indigo-400" />
)}
</div>
);
}
export default function AppShell({ children }: { children: React.ReactNode }) {
const pathname = usePathname();
const router = useRouter();
const [collapsed, setCollapsed] = useState(false);
const [mobileOpen, setMobileOpen] = useState(false);
const [daemonStatus, setDaemonStatus] = useState<any>(null);
const fetchStatus = useCallback(async () => {
const baseUrl = getApiBaseUrl();
try {
const r = await fetch(`${baseUrl}/daemon/status`);
if (r.ok) setDaemonStatus(await r.json());
} catch { /* silent */ }
}, []);
useEffect(() => {
fetchStatus();
const iv = setInterval(fetchStatus, 60000);
return () => clearInterval(iv);
}, [fetchStatus]);
useEffect(() => {
setMobileOpen(false);
}, [pathname]);
const isActive = (path: string) => {
if (path === '/') return pathname === '/';
return pathname?.startsWith(path);
};
const NavContent = ({ isMobile = false }: { isMobile?: boolean }) => (
<>
{/* Logo */}
<div className="flex items-center gap-3 px-4 h-14 border-b border-white/[0.04] shrink-0">
<JanusOrbSmall pulse={daemonStatus?.running} />
{(!collapsed || isMobile) && (
<motion.span
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
className="text-[13px] font-light tracking-[0.2em] text-gradient"
>
JANUS
</motion.span>
)}
</div>
{/* New Chat button */}
<div className="px-3 pt-3 pb-1 shrink-0">
<button
onClick={() => router.push('/')}
className={`w-full flex items-center gap-2 px-3 py-2.5 rounded-xl border border-white/[0.06] hover:border-white/[0.12] hover:bg-white/[0.03] transition-all text-sm text-gray-400 hover:text-gray-200 ${collapsed && !isMobile ? 'justify-center' : ''}`}
>
<Plus size={16} className="shrink-0" />
{(!collapsed || isMobile) && <span className="text-[12px]">New conversation</span>}
</button>
</div>
{/* Nav sections */}
<nav className="flex-1 overflow-y-auto py-2 px-2">
{navSections.map(section => (
<div key={section.label} className="mb-1">
{(!collapsed || isMobile) && (
<div className="px-2 pt-4 pb-1.5 text-[10px] font-medium text-gray-600 uppercase tracking-[0.15em]">
{section.label}
</div>
)}
{collapsed && !isMobile && <div className="h-3" />}
<div className="space-y-0.5">
{section.items.map(item => {
const active = isActive(item.path);
const Icon = item.icon;
return (
<button
key={item.path}
onClick={() => router.push(item.path)}
className={`w-full flex items-center gap-2.5 px-3 py-2 rounded-xl transition-all duration-200 group ${
active
? 'bg-white/[0.06] text-gray-100'
: 'text-gray-500 hover:text-gray-300 hover:bg-white/[0.03]'
} ${collapsed && !isMobile ? 'justify-center px-2' : ''}`}
title={collapsed && !isMobile ? item.label : undefined}
>
<Icon size={16} className={`shrink-0 ${active ? 'text-indigo-400' : 'group-hover:text-gray-400'}`} />
{(!collapsed || isMobile) && (
<span className="text-[12px] truncate">{item.label}</span>
)}
</button>
);
})}
</div>
</div>
))}
</nav>
{/* Status footer */}
{(!collapsed || isMobile) && (
<div className="px-4 py-3 border-t border-white/[0.04] shrink-0">
<div className="flex items-center gap-2">
<div className={`w-1.5 h-1.5 rounded-full ${daemonStatus?.running ? 'bg-emerald-400' : 'bg-gray-600'}`} />
<span className="text-[10px] text-gray-600">
{daemonStatus?.running ? 'System active' : 'Offline'}
</span>
</div>
{daemonStatus?.circadian && (
<div className="text-[10px] text-gray-700 mt-0.5 capitalize ml-3.5">
{daemonStatus.circadian.current_phase} phase
</div>
)}
</div>
)}
</>
);
return (
<div className="h-screen flex overflow-hidden" style={{ background: 'var(--janus-bg)' }}>
{/* Desktop Sidebar */}
<motion.aside
initial={false}
animate={{ width: collapsed ? 68 : 260 }}
transition={{ duration: 0.2, ease: 'easeOut' }}
className="hidden lg:flex flex-col border-r border-white/[0.04] relative shrink-0"
style={{ background: 'rgba(10, 10, 15, 0.8)' }}
>
<NavContent />
{/* Collapse toggle */}
<button
onClick={() => setCollapsed(!collapsed)}
className="absolute top-3 -right-3 w-6 h-6 rounded-full border border-white/[0.08] bg-[#111118] flex items-center justify-center text-gray-600 hover:text-gray-400 hover:border-white/[0.15] transition-all z-10"
>
{collapsed ? <ChevronRight size={12} /> : <ChevronLeft size={12} />}
</button>
</motion.aside>
{/* Mobile Header */}
<div className="lg:hidden fixed top-0 left-0 right-0 h-12 border-b border-white/[0.04] flex items-center justify-between px-4 z-30" style={{ background: 'rgba(10, 10, 15, 0.95)', backdropFilter: 'blur(12px)' }}>
<button onClick={() => setMobileOpen(true)} className="p-1.5 rounded-lg hover:bg-white/[0.05] text-gray-400">
<Menu size={18} />
</button>
<div className="flex items-center gap-2">
<JanusOrbSmall />
<span className="text-[12px] tracking-[0.2em] text-gradient">JANUS</span>
</div>
<div className="w-8" />
</div>
{/* Mobile Overlay */}
<AnimatePresence>
{mobileOpen && (
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
className="fixed inset-0 bg-black/60 z-40 lg:hidden"
onClick={() => setMobileOpen(false)}
/>
)}
</AnimatePresence>
{/* Mobile Drawer */}
<AnimatePresence>
{mobileOpen && (
<motion.div
initial={{ x: -300 }}
animate={{ x: 0 }}
exit={{ x: -300 }}
transition={{ type: 'spring', damping: 28, stiffness: 280 }}
className="fixed top-0 left-0 bottom-0 w-72 z-50 lg:hidden flex flex-col border-r border-white/[0.04]"
style={{ background: 'var(--janus-bg)' }}
>
<div className="absolute top-3 right-3">
<button onClick={() => setMobileOpen(false)} className="p-1 rounded-lg hover:bg-white/[0.05] text-gray-500">
<X size={16} />
</button>
</div>
<NavContent isMobile />
</motion.div>
)}
</AnimatePresence>
{/* Main Content Area */}
<main className="flex-1 min-w-0 overflow-hidden pt-12 lg:pt-0">
{children}
</main>
</div>
);
}
|