import { CircleHelp, Plus, RefreshCcw, Save, Trash2 } from 'lucide-react'; import { useEffect, useState } from 'react'; import { getAgcModelCatalog, saveAgcModelCatalog } from '../api/adminApiClient'; import type { AdminAgcModel, AdminAgcModelCatalog } from '../api/adminApiTypes'; import { useAdminWriteConfirm } from '../components/useAdminWriteConfirm'; import { handlePageError } from './pageUtils'; export function AdminAgcModelsPage({ token, onUnauthorized, }: { token: string; onUnauthorized: (message?: string) => void; }) { const [catalog, setCatalog] = useState(null); const [busy, setBusy] = useState(false); const [error, setError] = useState(''); const [saved, setSaved] = useState(false); const { confirmWrite, confirmDialog } = useAdminWriteConfirm(); async function refresh() { if (!token) return; setBusy(true); setError(''); setSaved(false); try { setCatalog(await getAgcModelCatalog(token)); } catch (error) { handlePageError(error, onUnauthorized, setError); } finally { setBusy(false); } } useEffect(() => { void refresh(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [token]); function update(id: string, patch: Partial) { setSaved(false); setCatalog( (current) => current && { ...current, models: current.models.map((model) => model.id === id ? { ...model, ...patch } : model, ), }, ); } async function save() { if (!catalog || busy) return; if ( !(await confirmWrite({ action: '保存 AGC 模型目录', target: `${catalog.models.length} 个模型`, })) ) return; setBusy(true); setError(''); setSaved(false); try { setCatalog(await saveAgcModelCatalog(token, catalog)); setSaved(true); } catch (error) { handlePageError(error, onUnauthorized, setError); } finally { setBusy(false); } } return (

AGC 模型

管理客户端可用模型与用户看到的名称

版本 v{catalog?.revision ?? '-'}
已启用 {catalog?.models.filter((model) => model.enabled).length ?? 0}
默认模型 {catalog ? (catalog.models.find( (model) => model.id === catalog.defaultModelId, )?.alias ?? '未设置') : '未设置'}
发布状态 {busy ? '处理中' : saved ? '已保存' : '待修改'}

模型目录

客户端仅显示别名,实际模型名仅在这里维护
{error ?

{error}

: null} {saved ?

已保存

: null} {busy ?

正在处理

: null}
{catalog?.models.map((model, index) => ( ))}
别名 实际模型名 启用 默认 操作
update(model.id, { alias: e.target.value }) } /> update(model.id, { modelId: e.target.value }) } /> update(model.id, { enabled: e.target.checked }) } /> { setSaved(false); setCatalog({ ...catalog, defaultModelId: model.id }); }} />
{confirmDialog}
); }