"use client"; import { Bot, Building2, Cable, LayoutDashboard, ListChecks, MessagesSquare, Moon, Plus, Settings, Sun, Users, } from "lucide-react"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { useEffect, useState } from "react"; import { DispatchModal } from "./DispatchModal"; import { useLive } from "./LiveProvider"; import { Dot } from "./ui"; import { getApiKey, keyShapeWarning, onApiKeyChange, setApiKey } from "@/lib/api"; import { setTheme, useTheme } from "@/lib/theme"; import { Field, Input, Modal, PixelButton, useConfirm } from "./ui"; const NAV = [ { href: "/", label: "总览", icon: LayoutDashboard }, { href: "/office", label: "办公室", icon: Building2 }, { href: "/workbench", label: "工作台", icon: MessagesSquare }, { href: "/agents", label: "Agents", icon: Bot }, { href: "/tasks", label: "任务", icon: ListChecks }, { href: "/teams", label: "团队", icon: Users }, { href: "/connect", label: "接入", icon: Cable }, { href: "/settings", label: "设置", icon: Settings }, ]; const SOCKET_LABEL: Record = { open: "实时", connecting: "连接中", closed: "已断线", }; export function TopBar() { const pathname = usePathname(); const { status } = useLive(); const theme = useTheme(); const confirm = useConfirm(); const [editing, setEditing] = useState(false); const [dispatching, setDispatching] = useState(false); const [key, setKey] = useState(""); useEffect(() => { setKey(getApiKey()); return onApiKeyChange(() => setKey(getApiKey())); }, []); const active = (href: string) => href === "/" ? pathname === "/" : pathname === href || pathname.startsWith(href + "/"); return (
🕹️ AgentHub
setDispatching(true)}> 派活 setTheme(theme === "dark" ? "light" : "dark")} aria-label={theme === "dark" ? "切换到亮色模式" : "切换到暗色模式"} aria-pressed={theme === "light"} > {theme === "dark" ? : } {theme === "dark" ? "亮色" : "暗色"} {SOCKET_LABEL[status] ?? status} setEditing(true)}> {key ? "API Key 已配置" : "配置 API Key"} {key && ( { const ok = await confirm({ title: "清除本机登录?", confirmLabel: "清除", danger: true, }); if (!ok) return; setApiKey(""); setKey(""); }} > 退出登录 )}
{dispatching && setDispatching(false)} />} {editing && ( setEditing(false)} footer={ <> setEditing(false)}>取消 {getApiKey() && ( { const ok = await confirm({ title: "清除本机登录?", confirmLabel: "清除", danger: true, }); if (!ok) return; setApiKey(""); setKey(""); setEditing(false); }} > 清除登录 )} { setApiKey(key); setEditing(false); }} > 保存 } >
setKey(event.target.value)} />
)}
); }