Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions changelog/unreleased/console-lazy-routes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### English

- Split console pages into per-route chunks so the first screen loads less JavaScript; rejected chat attachments now use the console toast instead of a browser alert.
- The overview resource panel now follows the backend's 30s sample cadence instead of polling every 5s, account countdowns share one timer, and runtime logs stop polling while the tab is hidden.
- Request statistics now stream the window once instead of running about ten SQL scans; the local 20k-row benchmark drops from ~227 ms to ~57 ms per call.
- The expanded live card now polls at 800ms instead of 400ms. The 60s concurrency sparkline is hand-drawn SVG, and the inflight depth chart loads only when expanded, keeping the 316 kB chart bundle out of the default console preload.
- The console shell no longer imports HeroUI: header and sidebar controls are dependency-free, the mobile drawer is native, and the update dialog loads on demand. Together with route-level lazy pages, the entry chunk is 422 kB (134.8 kB gzip) and preloads only `jsx-runtime` (12 kB) and GSAP (93 kB), down from the previous 461 + 239 + 94 + 13 kB preload group.

### 中文

- 控制台页面按路由拆包,首屏加载的 JavaScript 更少;聊天不支持的文件改用控制台提示,不再弹浏览器 alert。
- 概览资源面板改为对齐后端 30 秒采样节奏,不再每 5 秒重复请求;账号冷却倒计时共用一个定时器;运行日志在标签页隐藏时停止轮询。
- 请求统计改为单次扫描窗口并在 Go 内聚合,本机 20,000 行基准从约 227 ms/次降到约 57 ms/次。
- 展开态实时卡片轮询从 400ms 放慢到 800ms;60 秒并发曲线改为手绘 SVG,展开后才加载 inflight 深度图表,316 kB 图表包不再进入控制台默认预加载。
- 控制台外壳不再导入 HeroUI:顶栏与侧栏控件改为无依赖原生组件,移动抽屉改为原生实现,版本更新弹窗点击时才加载。配合路由级拆包,入口为 422 kB(gzip 134.8 kB),首屏仅预加载 `jsx-runtime`(12 kB)与 GSAP(93 kB),此前首屏组合为 461 + 239 + 94 + 13 kB。
58 changes: 32 additions & 26 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { Suspense, lazy } from 'react'
import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom'
import { AppLayout } from '@/components/layout/AppLayout'
import { RequireAuth } from '@/components/RequireAuth'
import { RouteFallback } from '@/components/ui/RouteFallback'
import { ApiKeyProvider } from '@/hooks/useApiKey'
import { I18nProvider } from '@/hooks/useI18n'
import { OverviewProvider } from '@/hooks/useOverview'
import { ThemeProvider } from '@/hooks/useTheme'
import { OverviewPage } from '@/pages/OverviewPage'
import { ProvidersPage } from '@/pages/ProvidersPage'
import { AccessPage } from '@/pages/AccessPage'
import { AccountsPage } from '@/pages/AccountsPage'
import { LoginPage } from '@/pages/LoginPage'
import { SystemPage } from '@/pages/SystemPage'
import { LogsPage } from '@/pages/LogsPage'
import { UsagePage } from '@/pages/UsagePage'
import { KeysPage } from '@/pages/KeysPage'

const LoginPage = lazy(() => import('@/pages/LoginPage').then((module) => ({ default: module.LoginPage })))

const OverviewPage = lazy(() => import('@/pages/OverviewPage').then((module) => ({ default: module.OverviewPage })))
const ProvidersPage = lazy(() => import('@/pages/ProvidersPage').then((module) => ({ default: module.ProvidersPage })))
const AccessPage = lazy(() => import('@/pages/AccessPage').then((module) => ({ default: module.AccessPage })))
const AccountsPage = lazy(() => import('@/pages/AccountsPage').then((module) => ({ default: module.AccountsPage })))
const SystemPage = lazy(() => import('@/pages/SystemPage').then((module) => ({ default: module.SystemPage })))
const LogsPage = lazy(() => import('@/pages/LogsPage').then((module) => ({ default: module.LogsPage })))
const UsagePage = lazy(() => import('@/pages/UsagePage').then((module) => ({ default: module.UsagePage })))
const KeysPage = lazy(() => import('@/pages/KeysPage').then((module) => ({ default: module.KeysPage })))

export default function App() {
return (
Expand All @@ -22,24 +26,26 @@ export default function App() {
<ApiKeyProvider>
<OverviewProvider>
<BrowserRouter>
<Routes>
<Route path="/login" element={<LoginPage />} />
<Route element={<RequireAuth />}>
<Route element={<AppLayout />}>
<Route path="/" element={<OverviewPage />} />
<Route path="/auth" element={<Navigate to="/accounts" replace />} />
<Route path="/providers" element={<ProvidersPage />} />
<Route path="/access" element={<AccessPage />} />
<Route path="/accounts" element={<AccountsPage />} />
<Route path="/checkins" element={<Navigate to="/accounts" replace />} />
<Route path="/usage" element={<UsagePage />} />
<Route path="/logs" element={<LogsPage />} />
<Route path="/keys" element={<KeysPage />} />
<Route path="/system" element={<SystemPage />} />
<Route path="*" element={<Navigate to="/" replace />} />
<Suspense fallback={<RouteFallback />}>
<Routes>
<Route path="/login" element={<LoginPage />} />
<Route element={<RequireAuth />}>
<Route element={<AppLayout />}>
<Route path="/" element={<OverviewPage />} />
<Route path="/auth" element={<Navigate to="/accounts" replace />} />
<Route path="/providers" element={<ProvidersPage />} />
<Route path="/access" element={<AccessPage />} />
<Route path="/accounts" element={<AccountsPage />} />
<Route path="/checkins" element={<Navigate to="/accounts" replace />} />
<Route path="/usage" element={<UsagePage />} />
<Route path="/logs" element={<LogsPage />} />
<Route path="/keys" element={<KeysPage />} />
<Route path="/system" element={<SystemPage />} />
<Route path="*" element={<Navigate to="/" replace />} />
</Route>
</Route>
</Route>
</Routes>
</Routes>
</Suspense>
</BrowserRouter>
</OverviewProvider>
</ApiKeyProvider>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/access/ChatComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useRef, type KeyboardEvent, type ReactNode } from 'react'
import { Button, Label, ListBox, Select, TextArea } from '@heroui/react'
import { FileText, PaperPlaneTilt, Plus, Stop, X } from '@phosphor-icons/react'
import { useI18n } from '@/hooks/useI18n'
import { toast } from '@/lib/toast'
import type { ChatAttachment } from './types'
import { IMAGE_ATTACHMENT_MIMES, TEXT_ATTACHMENT_EXTS, attachmentExt } from './types'

Expand Down Expand Up @@ -161,7 +162,7 @@ export function ChatComposer({
}
if (accepted.length) onAttachmentsChange([...attachments, ...accepted])
if (rejected.length) {
window.alert(t('chatAttachUnsupported', { names: rejected.join(', ') }))
toast({ type: 'error', title: t('chatAttachUnsupported', { names: rejected.join(', ') }) })
}
if (fileRef.current) fileRef.current.value = ''
}
Expand Down
9 changes: 2 additions & 7 deletions frontend/src/components/account/AccountCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CopyIcon } from '@/components/motion/CopyIcon'
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
import { useSharedClock } from '@/hooks/useSharedClock'
import { Button, Card, Chip, Dropdown, Input, Label, TextArea, TextField, Tooltip } from '@heroui/react'
import {
ArrowClockwise,
Expand Down Expand Up @@ -122,17 +123,11 @@ export function AccountCard({
const [idCopied, setIdCopied] = useState(false)
const [cooldownsOpen, setCooldownsOpen] = useState(false)
const lastStateRef = useRef<string | null>(null)
const [, refreshCooldowns] = useState(0)
const state = accountState(account)
const cooldown = cooldownLabel(account.down_until || account.cooldown_until)
const restartIn = cooldownLabel(account.next_restart_at)
const modelCooldowns = modelCooldownEntries(account)

useEffect(() => {
if (!cooldown && !restartIn && modelCooldowns.length === 0) return
const timer = window.setInterval(() => refreshCooldowns((value) => value + 1), 1000)
return () => window.clearInterval(timer)
}, [cooldown, restartIn, modelCooldowns.length])
useSharedClock(Boolean(cooldown || restartIn || modelCooldowns.length))

// Transient check-in feedback: a green check / yellow circle / red cross row
// that the page pushes after a manual check-in. It shows for three seconds
Expand Down
77 changes: 31 additions & 46 deletions frontend/src/components/layout/AppHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArrowClockwise, Globe, List, Moon, SignOut, Sun } from '@phosphor-icons/react'
import { Button, Toolbar, Tooltip } from '@heroui/react'
import { ShellIconButton, ShellTooltip } from '@/components/ui/ShellControls'
import { useNavigate } from 'react-router-dom'
import { useI18n } from '@/hooks/useI18n'
import { useOverview } from '@/hooks/useOverview'
Expand All @@ -25,9 +25,9 @@ export function AppHeader({
return (
<header className="relative z-20 shrink-0 border-b border-separator bg-background">
<div className="mx-auto flex w-full max-w-[1480px] items-center gap-4 px-4 py-2 sm:px-6 lg:px-8">
<Button isIconOnly size="sm" variant="ghost" className="lg:hidden" onPress={onMenu} aria-label={t('menu')}>
<ShellIconButton label={t('menu')} className="lg:hidden" onClick={onMenu}>
<List size={17} />
</Button>
</ShellIconButton>

<div className="min-w-0 flex-1">
<div className="flex min-w-0 items-baseline gap-3">
Expand All @@ -37,49 +37,34 @@ export function AppHeader({
</div>
</div>

<Toolbar isAttached>
<Tooltip>
<Tooltip.Trigger>
<Button isIconOnly size="sm" variant="ghost" isPending={loading} onPress={() => void refresh().catch(() => undefined)} aria-label={t('refresh')}>
<ArrowClockwise size={15} />
</Button>
</Tooltip.Trigger>
<Tooltip.Content>{t('refresh')}</Tooltip.Content>
</Tooltip>
<Tooltip>
<Tooltip.Trigger>
<Button isIconOnly size="sm" variant="ghost" onPress={() => setLang(lang === 'zh' ? 'en' : 'zh')} aria-label={lang === 'zh' ? 'English' : '中文'}>
<Globe size={15} />
</Button>
</Tooltip.Trigger>
<Tooltip.Content>{lang === 'zh' ? 'English' : '中文'}</Tooltip.Content>
</Tooltip>
<Tooltip>
<Tooltip.Trigger>
<Button isIconOnly size="sm" variant="ghost" onPress={toggleTheme} aria-label={theme === 'dark' ? 'Light mode' : 'Dark mode'}>
{theme === 'dark' ? <Sun size={15} /> : <Moon size={15} />}
</Button>
</Tooltip.Trigger>
<Tooltip.Content>{theme === 'dark' ? 'Light mode' : 'Dark mode'}</Tooltip.Content>
</Tooltip>
<Tooltip>
<Tooltip.Trigger>
<Button
isIconOnly
size="sm"
variant="ghost"
onPress={() => {
signOut()
navigate('/login', { replace: true })
}}
aria-label={t('signOut')}
>
<SignOut size={15} />
</Button>
</Tooltip.Trigger>
<Tooltip.Content>{t('signOut')}</Tooltip.Content>
</Tooltip>
</Toolbar>
<div className="flex items-center gap-1">
<ShellTooltip label={t('refresh')}>
<ShellIconButton label={t('refresh')} pending={loading} onClick={() => void refresh().catch(() => undefined)}>
<ArrowClockwise size={15} />
</ShellIconButton>
</ShellTooltip>
<ShellTooltip label={lang === 'zh' ? 'English' : '中文'}>
<ShellIconButton label={lang === 'zh' ? 'English' : '中文'} onClick={() => setLang(lang === 'zh' ? 'en' : 'zh')}>
<Globe size={15} />
</ShellIconButton>
</ShellTooltip>
<ShellTooltip label={theme === 'dark' ? 'Light mode' : 'Dark mode'}>
<ShellIconButton label={theme === 'dark' ? 'Light mode' : 'Dark mode'} onClick={toggleTheme}>
{theme === 'dark' ? <Sun size={15} /> : <Moon size={15} />}
</ShellIconButton>
</ShellTooltip>
<ShellTooltip label={t('signOut')}>
<ShellIconButton
label={t('signOut')}
onClick={() => {
signOut()
navigate('/login', { replace: true })
}}
>
<SignOut size={15} />
</ShellIconButton>
</ShellTooltip>
</div>
</div>
</header>
)
Expand Down
14 changes: 9 additions & 5 deletions frontend/src/components/layout/AppLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useState } from 'react'
import { Suspense, useCallback, useState } from 'react'
import { Outlet, useLocation } from 'react-router-dom'
import { AppHeader } from './AppHeader'
import { AppSidebar } from './AppSidebar'
import { RouteFallback } from '@/components/ui/RouteFallback'
import { useI18n } from '@/hooks/useI18n'
import { Toaster } from '@/components/motion/Toaster'

Expand All @@ -19,6 +20,7 @@ const routeKey: Record<string, string> = {

export function AppLayout() {
const [mobileOpen, setMobileOpen] = useState(false)
const closeMobile = useCallback(() => setMobileOpen(false), [])
const location = useLocation()
const { page } = useI18n()
const key = routeKey[location.pathname] || 'home'
Expand All @@ -27,7 +29,7 @@ export function AppLayout() {
return (
<div className="relative flex h-dvh overflow-hidden bg-background text-foreground">
<div className="relative z-10 flex min-h-0 min-w-0 flex-1">
<AppSidebar mobileOpen={mobileOpen} onClose={() => setMobileOpen(false)} />
<AppSidebar mobileOpen={mobileOpen} onClose={closeMobile} />
<div className="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden">
<AppHeader
title={copy.title}
Expand All @@ -36,9 +38,11 @@ export function AppLayout() {
/>
<main className="min-h-0 flex-1 overflow-y-auto">
<div className="mx-auto w-full max-w-[1480px] px-4 pb-12 pt-5 sm:px-6 lg:px-8 lg:pb-16 lg:pt-6">
<div key={location.pathname}>
<Outlet />
</div>
<Suspense fallback={<RouteFallback />}>
<div key={location.pathname}>
<Outlet />
</div>
</Suspense>
</div>
</main>
</div>
Expand Down
Loading
Loading