feat: 独立运维控制台 (sundynix-admin) — LLM 模型配置控制面前端
新增独立 Vite+React 控制台(:5174),运维在此配置控制面,区别于桌面端构建者 UI。 - sundynix-admin: 模型页(列表[激活徽标/脱敏key] + 登记表单 + 测试连接 + 激活/删除) → 调 Gateway /api/v1/admin/models*;数据源/租户/护栏 占位(规划中);Gateway 健康灯 - gateway CORS 补 DELETE(控制台删除模型用) - Makefile admin 目标(Vite :5174); .claude/launch.json 加 admin-console 验证: npm build✓; 真实浏览器跑通——控制台拉到真实模型列表, 填表→测试连接 ✓连接成功(HTTP 200,browser→GW→mock), 保存→表格新增行。激活会经 NATS 热更新 Dispatcher(上一提交已证)。控制台↔控制面↔Dispatcher 全链路打通。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
// 运维控制台 → Gateway 控制面 API。
|
||||
export const GATEWAY: string =
|
||||
(import.meta.env.VITE_GATEWAY as string | undefined) ?? "http://localhost:8080";
|
||||
const ADMIN = `${GATEWAY}/api/v1/admin`;
|
||||
|
||||
export interface Model {
|
||||
id: number;
|
||||
provider: string;
|
||||
base_url: string;
|
||||
api_key: string; // 列表里是脱敏值
|
||||
model: string;
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
export interface ModelInput {
|
||||
id?: number;
|
||||
provider: string;
|
||||
base_url: string;
|
||||
api_key: string;
|
||||
model: string;
|
||||
}
|
||||
|
||||
export async function listModels(): Promise<Model[]> {
|
||||
const res = await fetch(`${ADMIN}/models`);
|
||||
if (!res.ok) throw new Error(`list failed: ${res.status}`);
|
||||
return ((await res.json()) as { models: Model[] }).models;
|
||||
}
|
||||
|
||||
export async function saveModel(m: ModelInput): Promise<number> {
|
||||
const res = await fetch(`${ADMIN}/models`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(m),
|
||||
});
|
||||
const data = (await res.json()) as { id?: number; error?: string };
|
||||
if (!res.ok) throw new Error(data.error ?? `save failed: ${res.status}`);
|
||||
return data.id ?? 0;
|
||||
}
|
||||
|
||||
export async function setActive(id: number): Promise<void> {
|
||||
const res = await fetch(`${ADMIN}/models/${id}/active`, { method: "POST" });
|
||||
if (!res.ok) throw new Error(`activate failed: ${res.status}`);
|
||||
}
|
||||
|
||||
export async function deleteModel(id: number): Promise<void> {
|
||||
const res = await fetch(`${ADMIN}/models/${id}`, { method: "DELETE" });
|
||||
if (!res.ok) throw new Error(`delete failed: ${res.status}`);
|
||||
}
|
||||
|
||||
export async function testModel(m: ModelInput): Promise<{ ok: boolean; message: string }> {
|
||||
const res = await fetch(`${ADMIN}/models/test`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(m),
|
||||
});
|
||||
return (await res.json()) as { ok: boolean; message: string };
|
||||
}
|
||||
|
||||
export async function gatewayOnline(): Promise<boolean> {
|
||||
try {
|
||||
const res = await fetch(`${GATEWAY}/api/v1/billing`);
|
||||
return res.ok;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user