'use client'; import React, { useEffect, useState } from 'react'; import { CheckCircle2, XCircle, AlertCircle, RefreshCw, Server, Cpu, Radio, Key, Loader2, } from 'lucide-react'; import { getStatus, restartSystem } from '@/lib/api'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from '@/components/ui/alert-dialog'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import type { SystemStatus } from '@/types'; import { pickAppText } from '@/lib/i18n/core'; import { useAppI18n } from '@/lib/i18n/provider'; export default function StatusPage() { const { locale } = useAppI18n(); const [status, setStatus] = useState(null); const [error, setError] = useState(null); const [loading, setLoading] = useState(true); const [restartDialogOpen, setRestartDialogOpen] = useState(false); const [restarting, setRestarting] = useState(false); const [restartError, setRestartError] = useState(null); const loadStatus = async () => { setLoading(true); setError(null); try { const data = await getStatus(); setStatus(data); } catch (err: any) { setError(err.message || pickAppText(locale, '连接后端失败', 'Failed to connect to the backend')); } finally { setLoading(false); } }; useEffect(() => { loadStatus(); }, []); useEffect(() => { if (!restarting) { return; } const intervalId = window.setInterval(async () => { try { await getStatus(); window.location.reload(); } catch { // Ignore failures until the container is back. } }, 3000); return () => { window.clearInterval(intervalId); }; }, [restarting]); const handleRestart = async () => { setRestartError(null); try { await restartSystem(); setRestartDialogOpen(false); setRestarting(true); } catch (err: any) { setRestartError(err.message || pickAppText(locale, '重启失败', 'Restart failed')); } }; if (loading) { return (
); } if (error) { return (

{pickAppText(locale, '无法连接到 Boardware Agent Sandbox 后端', 'Unable to connect to the Boardware Agent Sandbox backend')}

{error}

{pickAppText(locale, '请确认后端服务已启动,并且当前页面可以访问它。', 'Please confirm the backend service is running and reachable from this page.')}

); } if (!status) return null; return (

{pickAppText(locale, '系统状态', 'System status')}

{/* System Info */} {pickAppText(locale, '系统信息', 'System information')}

{pickAppText(locale, '重启当前实例', 'Restart current instance')}

{restarting ? pickAppText(locale, '正在重启当前 docker,服务恢复后页面会自动刷新。', 'Restarting the current Docker container. The page will refresh automatically once the service is back.') : pickAppText(locale, '会重启当前 docker 容器。重启完成后需要重新登录。', 'This restarts the current Docker container. You will need to sign in again afterwards.')}

{restartError ? (

{restartError}

) : null}
{pickAppText(locale, '确认重启当前实例?', 'Restart the current instance?')} {pickAppText(locale, '这会重启当前 docker 容器,页面会短暂不可用。由于当前登录态保存在内存里,重启完成后需要重新登录。', 'This restarts the current Docker container and the page will be temporarily unavailable. Because the current sign-in state is stored in memory, you will need to sign in again after the restart.')} {pickAppText(locale, '取消', 'Cancel')} {restarting ? pickAppText(locale, '重启中...', 'Restarting...') : pickAppText(locale, '确认重启', 'Confirm restart')}
{/* Model Config */} {pickAppText(locale, '智能体配置', 'Agent configuration')} {/* Providers */} {pickAppText(locale, '提供商', 'Providers')}
{status.providers.map((p) => (
{p.has_key ? ( ) : ( )} {p.name} {p.detail && ( {p.detail} )}
))}
{/* Channels */} {pickAppText(locale, '通道', 'Channels')}
{status.channels.map((ch) => (
{ch.enabled ? pickAppText(locale, '开启', 'On') : pickAppText(locale, '关闭', 'Off')} {ch.name}
))}
{/* Cron Summary */} {pickAppText(locale, '调度器', 'Scheduler')}
); } function InfoRow({ label, value, ok, }: { label: string; value: string; ok?: boolean; }) { return (
{label}
{value} {ok !== undefined && (ok ? ( ) : ( ))}
); }