'use client'; import React from 'react'; import Link from 'next/link'; import Image from 'next/image'; import { usePathname, useRouter } from 'next/navigation'; import { MessageSquare, Activity, Clock, Puzzle, Blocks, HelpCircle, FolderOpen, Store, LogIn, UserPlus, Bot, ServerCog, Mail, LogOut, UserCircle2 } from 'lucide-react'; import { logout } from '@/lib/api'; import { useChatStore } from '@/lib/store'; const NAV_ITEMS = [ { name: '对话', href: '/', icon: MessageSquare }, { name: '状态', href: '/status', icon: Activity }, { name: '定时任务', href: '/cron', icon: Clock }, { name: '技能', href: '/skills', icon: Puzzle }, { name: '插件', href: '/plugins', icon: Blocks }, { name: '智能体', href: '/agents', icon: Bot }, { name: 'MCP', href: '/mcp', icon: ServerCog }, { name: 'Outlook', href: '/outlook', icon: Mail }, { name: '市场', href: '/marketplace', icon: Store }, { name: '文件', href: '/files', icon: FolderOpen }, { name: '帮助', href: '/help', icon: HelpCircle }, ]; const AUTH_ITEMS = [ { name: '登录', href: '/login', icon: LogIn }, { name: '注册', href: '/register', icon: UserPlus }, ]; function ConnectionDot() { const wsStatus = useChatStore((s) => s.wsStatus); const nanobotReady = useChatStore((s) => s.nanobotReady); const isOnline = wsStatus === 'connected' && nanobotReady === true; const isChecking = wsStatus === 'connected' && nanobotReady === null; const isConnecting = wsStatus === 'connecting' || isChecking; const isOffline = wsStatus === 'disconnected' || (wsStatus === 'connected' && nanobotReady === false); const color = isOnline ? 'bg-green-500' : isConnecting ? 'bg-yellow-500' : 'bg-red-500'; const label = isOnline ? '已连接' : isChecking ? '检查中' : wsStatus === 'connecting' ? '连接中' : isOffline && wsStatus === 'connected' ? '服务离线' : '未连接'; return (
{label}
); } const Header = () => { const pathname = usePathname(); const router = useRouter(); const user = useChatStore((s) => s.user); const isAuthLoading = useChatStore((s) => s.isAuthLoading); const setUser = useChatStore((s) => s.setUser); const handleLogout = async () => { await logout(); setUser(null); router.replace('/login'); router.refresh(); }; return (
Boardware logo Boardware Agent Sandbox
{user ? ( <>
{user.username}
) : !isAuthLoading ? ( AUTH_ITEMS.map((item) => { const isActive = pathname.startsWith(item.href); const Icon = item.icon; return ( {item.name} ); }) ) : null}
); }; export default Header;