feat(admin): 补全平台任务观测 + 空间管理 + 基建加 MinIO/实时探针
对照已实现系统功能补 admin 缺失模块(feat/site): - 全平台任务/运行观测:GET /admin/tasks(跨租户查 sundynix_task,join 租户名/提交人邮箱/评测, 按状态/租户筛 + 状态计数;含 HITL 待审批=筛 waiting)+ TasksPage(状态卡+筛+表)。 - 空间(Space)管理:GET /admin/spaces(跨租户列 Space + 成员数子查询 + kind/归档态)+ SpacesPage。 - 基建观测:infra 加 MinIO(126 对象存储);postgres/redis/minio 从启动标志升级为实时 ping (blob.Ping/Postgres.Ping/Redis.Ping),能反映中途掉线。StatusPage 加 minio 标签、6 个依赖。 - 模型健康/熔断:确认 DashboardPage 已有「运行时链路态」渲染 m.health,无需重做。 验证:admin tsc + vitest 41 过、gateway build/vet/test 过;两新页浏览器实测渲染+优雅错误处理; 两新端点起临时 gateway 打真 PG 实测——tasks(counts+3路join)、spaces(成员数子查询)均返真数据。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -314,6 +314,58 @@ export async function adminRefundOrder(id: string, memo: string): Promise<{ stat
|
||||
return { status: d.status ?? "", detail: d.detail };
|
||||
}
|
||||
|
||||
// ---- 全平台任务/运行观测(管理端,来自 sundynix_task 跨租户)----
|
||||
export interface AdminTask {
|
||||
task_id: string;
|
||||
tenant_id: string;
|
||||
tenant_name: string;
|
||||
owner: string;
|
||||
owner_email: string;
|
||||
status: string;
|
||||
detail: string;
|
||||
topic: string;
|
||||
at: string; // RFC3339
|
||||
eval_level: string;
|
||||
eval_overall: number;
|
||||
}
|
||||
|
||||
// adminTasks 全平台任务流 + 状态计数。status 空=全部;tenant 空=全租户;含 HITL 待审批(status=waiting)。
|
||||
export async function adminTasks(
|
||||
status = "",
|
||||
tenant = "",
|
||||
limit = 50,
|
||||
): Promise<{ tasks: AdminTask[]; counts: Record<string, number> }> {
|
||||
const q = new URLSearchParams();
|
||||
if (status) q.set("status", status);
|
||||
if (tenant) q.set("tenant", tenant);
|
||||
q.set("limit", String(limit));
|
||||
const res = guard(await fetch(`${ADMIN}/tasks?${q.toString()}`, { headers: authHeaders() }));
|
||||
const d = (await res.json().catch(() => ({}))) as { tasks?: AdminTask[]; counts?: Record<string, number>; error?: string };
|
||||
if (!res.ok) throw new Error(d.error ?? `tasks failed: ${res.status}`);
|
||||
return { tasks: d.tasks ?? [], counts: d.counts ?? {} };
|
||||
}
|
||||
|
||||
// ---- 全平台空间(Space)观测(管理端,跨租户 sundynix_space)----
|
||||
export interface AdminSpace {
|
||||
id: string;
|
||||
tenant_id: string;
|
||||
tenant_name: string;
|
||||
name: string;
|
||||
kind: string; // personal / project / tenant
|
||||
creator: string;
|
||||
creator_email: string;
|
||||
archived: boolean;
|
||||
members: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export async function adminSpaces(limit = 200): Promise<AdminSpace[]> {
|
||||
const res = guard(await fetch(`${ADMIN}/spaces?limit=${limit}`, { headers: authHeaders() }));
|
||||
const d = (await res.json().catch(() => ({}))) as { spaces?: AdminSpace[]; error?: string };
|
||||
if (!res.ok) throw new Error(d.error ?? `spaces failed: ${res.status}`);
|
||||
return d.spaces ?? [];
|
||||
}
|
||||
|
||||
// ---- 自动评测观测(真数据,来自 sundynix_eval)----
|
||||
export interface EvalDay {
|
||||
day: string; // YYYYMMDD
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { adminSpaces, type AdminSpace } from "../api";
|
||||
|
||||
// 全平台空间(Space)观测:跨租户看所有空间(类型/租户/建者/成员数/归档态)。
|
||||
// Space 是租户与成员之间的中间容器(Tenant > Space > 成员),数据来自 sundynix_space。
|
||||
|
||||
const KIND: Record<string, { label: string; badge: string }> = {
|
||||
personal: { label: "个人", badge: "bg-gray-100 text-gray-500" },
|
||||
project: { label: "项目", badge: "bg-cyan-50 text-cyan-600" },
|
||||
tenant: { label: "全员", badge: "bg-violet-50 text-violet-600" },
|
||||
};
|
||||
const kind = (k: string) => KIND[k] ?? { label: k, badge: "bg-gray-100 text-gray-500" };
|
||||
|
||||
export function SpacesPage() {
|
||||
const [spaces, setSpaces] = useState<AdminSpace[]>([]);
|
||||
const [err, setErr] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [hideArchived, setHideArchived] = useState(true);
|
||||
|
||||
const load = useCallback(() => {
|
||||
setLoading(true);
|
||||
adminSpaces(300)
|
||||
.then((s) => {
|
||||
setSpaces(s);
|
||||
setErr("");
|
||||
})
|
||||
.catch((e) => setErr((e as Error).message))
|
||||
.finally(() => setLoading(false));
|
||||
}, []);
|
||||
useEffect(load, [load]);
|
||||
|
||||
const shown = useMemo(() => (hideArchived ? spaces.filter((s) => !s.archived) : spaces), [spaces, hideArchived]);
|
||||
const stats = useMemo(() => {
|
||||
const byKind: Record<string, number> = {};
|
||||
let archived = 0;
|
||||
for (const s of spaces) {
|
||||
byKind[s.kind] = (byKind[s.kind] ?? 0) + 1;
|
||||
if (s.archived) archived++;
|
||||
}
|
||||
return { total: spaces.length, byKind, archived };
|
||||
}, [spaces]);
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
<div className="flex items-center gap-2 pt-1">
|
||||
<h3 className="text-sm font-semibold text-gray-700">全平台空间(Space)</h3>
|
||||
<span className="text-[11px] text-gray-400">租户与成员之间的中间容器:Agent / 知识库按空间共享</span>
|
||||
</div>
|
||||
|
||||
{/* 计数卡片 */}
|
||||
<div className="grid grid-cols-2 gap-3 lg:grid-cols-4">
|
||||
<Stat label="空间总数" value={stats.total} tone="text-gray-800" />
|
||||
<Stat label="项目空间" value={stats.byKind.project ?? 0} tone="text-cyan-600" />
|
||||
<Stat label="全员空间" value={stats.byKind.tenant ?? 0} tone="text-violet-600" />
|
||||
<Stat label="已归档" value={stats.archived} tone="text-gray-400" />
|
||||
</div>
|
||||
|
||||
<div className="rounded-xl border border-gray-100 bg-white p-5 shadow-sm">
|
||||
<div className="mb-3 flex items-center justify-between">
|
||||
<span className="text-xs text-gray-400">{loading ? "加载中…" : `共 ${shown.length} 个空间`}</span>
|
||||
<div className="flex items-center gap-3">
|
||||
<label className="flex items-center gap-1.5 text-xs text-gray-500">
|
||||
<input type="checkbox" checked={hideArchived} onChange={(e) => setHideArchived(e.target.checked)} />
|
||||
隐藏已归档
|
||||
</label>
|
||||
<button onClick={load} className="rounded-lg border border-gray-200 px-3 py-1.5 text-xs text-gray-500 hover:bg-gray-50">
|
||||
刷新
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{err && <p className="mb-2 text-xs text-rose-500">{err}</p>}
|
||||
|
||||
<div className="max-h-[32rem] overflow-auto">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="sticky top-0 bg-white">
|
||||
<tr className="border-b border-gray-100 text-left text-[11px] uppercase tracking-wide text-gray-400">
|
||||
<th className="py-2 pr-3 font-medium">空间</th>
|
||||
<th className="py-2 pr-3 font-medium">类型</th>
|
||||
<th className="py-2 pr-3 font-medium">租户</th>
|
||||
<th className="py-2 pr-3 font-medium">建者</th>
|
||||
<th className="py-2 pr-3 text-right font-medium">成员</th>
|
||||
<th className="py-2 pr-3 font-medium">创建时间</th>
|
||||
<th className="py-2 font-medium">状态</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{shown.map((s) => (
|
||||
<tr key={s.id} className="border-b border-gray-50 last:border-0">
|
||||
<td className="py-2 pr-3 text-gray-800">{s.name}</td>
|
||||
<td className="py-2 pr-3">
|
||||
<span className={`rounded px-1.5 py-0.5 text-[10px] ${kind(s.kind).badge}`}>{kind(s.kind).label}</span>
|
||||
</td>
|
||||
<td className="py-2 pr-3 text-gray-600">{s.tenant_name || <span className="text-gray-300">{s.tenant_id || "—"}</span>}</td>
|
||||
<td className="py-2 pr-3 text-xs text-gray-500">{s.creator_email || s.creator || "—"}</td>
|
||||
<td className="py-2 pr-3 text-right tabular-nums text-gray-700">{s.members}</td>
|
||||
<td className="py-2 pr-3 text-xs text-gray-500 whitespace-nowrap">{new Date(s.created_at).toLocaleDateString("zh-CN")}</td>
|
||||
<td className="py-2 text-xs">
|
||||
{s.archived ? <span className="text-gray-400">已归档</span> : <span className="text-emerald-600">活跃</span>}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{shown.length === 0 && !loading && (
|
||||
<tr>
|
||||
<td colSpan={7} className="py-8 text-center text-xs text-gray-400">暂无空间</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Stat({ label, value, tone }: { label: string; value: number; tone: string }) {
|
||||
return (
|
||||
<div className="rounded-xl border border-gray-100 bg-white p-4 shadow-sm">
|
||||
<div className="text-xs text-gray-400">{label}</div>
|
||||
<div className={`mt-1 text-2xl font-semibold tabular-nums ${tone}`}>{value}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -15,6 +15,7 @@ const INFRA_META: Record<string, { role: string; port: string; icon: IconName }>
|
||||
nats: { role: "消息总线 · JetStream", port: "4222", icon: "bus" },
|
||||
milvus: { role: "向量库", port: "19530", icon: "db" },
|
||||
neo4j: { role: "图数据库", port: "7687", icon: "bus" },
|
||||
minio: { role: "对象存储 · 报告/正文/blob", port: "9000", icon: "db" },
|
||||
};
|
||||
|
||||
function toolCategory(t: string): string {
|
||||
@@ -187,7 +188,7 @@ export function StatusPage() {
|
||||
</section>
|
||||
|
||||
<section className="rounded-2xl border border-gray-200/70 bg-white p-6 lg:col-span-2">
|
||||
<SectionHead title="基建环境" hint="5 个依赖" />
|
||||
<SectionHead title="基建环境" hint="6 个依赖" />
|
||||
<div className="mt-4 divide-y divide-gray-100">
|
||||
{data.infra.map((s) => (
|
||||
<InfraRow key={s.name} item={s} />
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { adminTasks, type AdminTask } from "../api";
|
||||
|
||||
// 全平台任务/运行观测:跨租户看所有任务(状态分布 + 列表 + 提交人/租户/评测)。
|
||||
// 含 HITL 待审批(筛 waiting)。数据来自 sundynix_task,后端 GET /admin/tasks。
|
||||
|
||||
const STATUS: Record<string, { label: string; badge: string; dot: string }> = {
|
||||
submitted: { label: "已提交", badge: "bg-gray-100 text-gray-500", dot: "bg-gray-400" },
|
||||
running: { label: "运行中", badge: "bg-cyan-50 text-cyan-600", dot: "bg-cyan-500" },
|
||||
done: { label: "完成", badge: "bg-emerald-50 text-emerald-600", dot: "bg-emerald-500" },
|
||||
failed: { label: "失败", badge: "bg-rose-50 text-rose-500", dot: "bg-rose-500" },
|
||||
timeout: { label: "超时", badge: "bg-amber-50 text-amber-600", dot: "bg-amber-500" },
|
||||
waiting: { label: "待审批", badge: "bg-yellow-50 text-yellow-700", dot: "bg-yellow-500" },
|
||||
rejected: { label: "已拒绝", badge: "bg-violet-50 text-violet-600", dot: "bg-violet-500" },
|
||||
};
|
||||
const st = (s: string) => STATUS[s] ?? { label: s, badge: "bg-gray-100 text-gray-500", dot: "bg-gray-400" };
|
||||
|
||||
// 筛选标签顺序(waiting 提前,运维最关心待审批 + 失败)。
|
||||
const FILTERS = ["", "waiting", "running", "failed", "timeout", "done", "rejected"] as const;
|
||||
|
||||
const EVAL_LEVEL: Record<string, string> = {
|
||||
excellent: "text-emerald-600",
|
||||
good: "text-emerald-500",
|
||||
fair: "text-amber-600",
|
||||
poor: "text-rose-500",
|
||||
};
|
||||
|
||||
export function TasksPage() {
|
||||
const [tasks, setTasks] = useState<AdminTask[]>([]);
|
||||
const [counts, setCounts] = useState<Record<string, number>>({});
|
||||
const [filter, setFilter] = useState("");
|
||||
const [err, setErr] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const load = useCallback(() => {
|
||||
setLoading(true);
|
||||
adminTasks(filter, "", 100)
|
||||
.then((r) => {
|
||||
setTasks(r.tasks);
|
||||
setCounts(r.counts);
|
||||
setErr("");
|
||||
})
|
||||
.catch((e) => setErr((e as Error).message))
|
||||
.finally(() => setLoading(false));
|
||||
}, [filter]);
|
||||
useEffect(load, [load]);
|
||||
|
||||
const total = Object.values(counts).reduce((a, b) => a + b, 0);
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
<div className="flex items-center gap-2 pt-1">
|
||||
<h3 className="text-sm font-semibold text-gray-700">全平台任务 / 运行观测</h3>
|
||||
<span className="text-[11px] text-gray-400">跨租户查看所有任务,含 HITL 待审批(筛「待审批」)</span>
|
||||
</div>
|
||||
|
||||
{/* 状态计数卡片 */}
|
||||
<div className="grid grid-cols-3 gap-3 lg:grid-cols-7">
|
||||
<Stat label="全部" value={total} active={filter === ""} onClick={() => setFilter("")} />
|
||||
{FILTERS.filter((f) => f).map((f) => (
|
||||
<Stat key={f} label={st(f).label} value={counts[f] ?? 0} tone={f} active={filter === f} onClick={() => setFilter(f)} />
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="rounded-xl border border-gray-100 bg-white p-5 shadow-sm">
|
||||
<div className="mb-3 flex items-center justify-between">
|
||||
<span className="text-xs text-gray-400">{loading ? "加载中…" : `共 ${tasks.length} 条${filter ? `(${st(filter).label})` : ""}`}</span>
|
||||
<button onClick={load} className="rounded-lg border border-gray-200 px-3 py-1.5 text-xs text-gray-500 hover:bg-gray-50">
|
||||
刷新
|
||||
</button>
|
||||
</div>
|
||||
{err && <p className="mb-2 text-xs text-rose-500">{err}</p>}
|
||||
|
||||
<div className="max-h-[32rem] overflow-auto">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="sticky top-0 bg-white">
|
||||
<tr className="border-b border-gray-100 text-left text-[11px] uppercase tracking-wide text-gray-400">
|
||||
<th className="py-2 pr-3 font-medium">时间</th>
|
||||
<th className="py-2 pr-3 font-medium">任务 / 主题</th>
|
||||
<th className="py-2 pr-3 font-medium">租户</th>
|
||||
<th className="py-2 pr-3 font-medium">提交人</th>
|
||||
<th className="py-2 pr-3 font-medium">状态</th>
|
||||
<th className="py-2 pr-3 font-medium">评测</th>
|
||||
<th className="py-2 font-medium">详情</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{tasks.map((t) => (
|
||||
<tr key={t.task_id} className="border-b border-gray-50 last:border-0 align-top">
|
||||
<td className="py-2 pr-3 text-xs text-gray-500 whitespace-nowrap">{new Date(t.at).toLocaleString("zh-CN")}</td>
|
||||
<td className="py-2 pr-3">
|
||||
<div className="text-gray-800">{t.topic || <code className="text-[11px] text-gray-500">{t.task_id}</code>}</div>
|
||||
{t.topic && <code className="text-[10px] text-gray-300">{t.task_id}</code>}
|
||||
</td>
|
||||
<td className="py-2 pr-3 text-gray-600">{t.tenant_name || <span className="text-gray-300">{t.tenant_id || "—"}</span>}</td>
|
||||
<td className="py-2 pr-3 text-xs text-gray-500">{t.owner_email || t.owner || "—"}</td>
|
||||
<td className="py-2 pr-3">
|
||||
<span className={`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] ${st(t.status).badge}`}>
|
||||
<span className={`h-1.5 w-1.5 rounded-full ${st(t.status).dot}`} />
|
||||
{st(t.status).label}
|
||||
</span>
|
||||
</td>
|
||||
<td className="py-2 pr-3 text-xs">
|
||||
{t.eval_level ? (
|
||||
<span className={EVAL_LEVEL[t.eval_level] ?? "text-gray-500"}>
|
||||
{t.eval_level} · {(t.eval_overall * 100).toFixed(0)}
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-gray-300">—</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="py-2 max-w-[18rem] text-xs text-gray-500">
|
||||
<span className="line-clamp-2" title={t.detail}>{t.detail || "—"}</span>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{tasks.length === 0 && !loading && (
|
||||
<tr>
|
||||
<td colSpan={7} className="py-8 text-center text-xs text-gray-400">暂无任务</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Stat({
|
||||
label,
|
||||
value,
|
||||
tone,
|
||||
active,
|
||||
onClick,
|
||||
}: {
|
||||
label: string;
|
||||
value: number;
|
||||
tone?: string;
|
||||
active: boolean;
|
||||
onClick: () => void;
|
||||
}) {
|
||||
const dot = tone ? st(tone).dot : "bg-gray-400";
|
||||
return (
|
||||
<button
|
||||
onClick={onClick}
|
||||
className={`rounded-xl border p-3 text-left transition ${
|
||||
active ? "border-violet-300 bg-violet-50" : "border-gray-100 bg-white hover:bg-gray-50"
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center gap-1.5 text-[11px] text-gray-400">
|
||||
<span className={`h-1.5 w-1.5 rounded-full ${dot}`} />
|
||||
{label}
|
||||
</div>
|
||||
<div className="mt-1 text-xl font-semibold tabular-nums text-gray-800">{value}</div>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -9,11 +9,13 @@ const UsagePage = lazy(() => import("./pages/UsagePage").then((m) => ({ default:
|
||||
const ModelsPage = lazy(() => import("./pages/ModelsPage").then((m) => ({ default: m.ModelsPage })));
|
||||
const DatasourcesPage = lazy(() => import("./pages/DatasourcesPage").then((m) => ({ default: m.DatasourcesPage })));
|
||||
const StatusPage = lazy(() => import("./pages/StatusPage").then((m) => ({ default: m.StatusPage })));
|
||||
const TasksPage = lazy(() => import("./pages/TasksPage").then((m) => ({ default: m.TasksPage })));
|
||||
const EvalsPage = lazy(() => import("./pages/EvalsPage").then((m) => ({ default: m.EvalsPage })));
|
||||
const TenantsPage = lazy(() => import("./pages/TenantsPage").then((m) => ({ default: m.TenantsPage })));
|
||||
const GuardrailsPage = lazy(() => import("./pages/GuardrailsPage").then((m) => ({ default: m.GuardrailsPage })));
|
||||
const PromptsPage = lazy(() => import("./pages/PromptsPage").then((m) => ({ default: m.PromptsPage })));
|
||||
const AuditPage = lazy(() => import("./pages/AuditPage").then((m) => ({ default: m.AuditPage })));
|
||||
const SpacesPage = lazy(() => import("./pages/SpacesPage").then((m) => ({ default: m.SpacesPage })));
|
||||
|
||||
export interface RouteDef {
|
||||
path: string;
|
||||
@@ -66,6 +68,13 @@ export const routes: RouteDef[] = [
|
||||
ready: true,
|
||||
element: <StatusPage />,
|
||||
},
|
||||
{
|
||||
path: "/tasks",
|
||||
label: "任务观测",
|
||||
group: "运维",
|
||||
ready: true,
|
||||
element: <TasksPage />,
|
||||
},
|
||||
{
|
||||
path: "/evals",
|
||||
label: "自动评测",
|
||||
@@ -87,6 +96,13 @@ export const routes: RouteDef[] = [
|
||||
ready: true,
|
||||
element: <TenantsPage />,
|
||||
},
|
||||
{
|
||||
path: "/spaces",
|
||||
label: "空间",
|
||||
group: "平台",
|
||||
ready: true,
|
||||
element: <SpacesPage />,
|
||||
},
|
||||
{
|
||||
path: "/guardrails",
|
||||
label: "安全护栏",
|
||||
|
||||
Reference in New Issue
Block a user