Files
sundynix-agentix/sundynix-desktop/frontend/src/lib/health.ts
T
Blizzard 61c1177eba feat(desktop): MVP 驾驶舱外壳 + 类型化节点 Studio + 运行抽屉
按 desktop-ui-plan.md 落 MVP:五区外壳 + 编排 Studio + 底部抽屉 + 健康灯。

- shell: TopBar(垂直切换/健康灯[Gateway/DB 实时,余规划]/身份会话) +
  LeftNav(BUILD/RUN/MANAGE 分组,未就绪模块灰显) + BottomDrawer(输出/轨迹/工具调用/引用/评测)
- studio: 类型化节点目录(输入/检索RAG/Agent/工具/记忆/分支/并行/汇聚/渲染/输出,
  按类配色) + 自定义 TypedNode(状态徽标) + Inspector(按类型渲染配置表单) +
  校验(孤立节点/必填项) + 运行
- views: MemoryView(复用偏好面板) + Placeholder(规划中模块,露出 IA 与依赖)
- lib: run(运行状态机) + health(轮询 billing) + dsl(导出类型化 DSL + validate)
- 删旧 AgentCanvas(被 StudioView 取代)

验证: npm run build(tsc+vite)✓; 真实浏览器跑通——加类型化节点→校验(标出孤立)→运行
→SSE 注入画像(老王)+历史 流入抽屉, 健康灯 Gateway/DB 实时绿

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-10 15:00:32 +08:00

33 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useEffect, useState } from "react";
import { GATEWAY } from "./api";
export interface Health {
gateway: boolean;
persisted: boolean; // Postgres 是否在线(billing.persisted
}
// useHealth 轮询 Gateway 健康(billing 端点同时回报持久化是否就绪)。
// NATS/Milvus/Neo4j 暂未由网关透出,UI 以"未知"呈现(规划:加 /health 聚合)。
export function useHealth(intervalMs = 4000): Health {
const [h, setH] = useState<Health>({ gateway: false, persisted: false });
useEffect(() => {
let alive = true;
const ping = async () => {
try {
const res = await fetch(`${GATEWAY}/api/v1/billing`);
const data = (await res.json()) as { persisted?: boolean };
if (alive) setH({ gateway: res.ok, persisted: Boolean(data.persisted) });
} catch {
if (alive) setH({ gateway: false, persisted: false });
}
};
ping();
const id = setInterval(ping, intervalMs);
return () => {
alive = false;
clearInterval(id);
};
}, [intervalMs]);
return h;
}