"use client"; import { useEffect, useState } from "react"; import { TriangleAlert } from "lucide-react"; import { api, type HealthResult } from "@/components/api"; const INSTALL_HINTS: Record = { sling: "brew install slingdata-io/sling/sling(或参考 https://docs.slingdata.io)", atlas: "brew install ariga/tap/atlas(或参考 https://atlasgo.io)", }; export function HealthBanner() { const [health, setHealth] = useState(null); const [failed, setFailed] = useState(false); useEffect(() => { api("/api/health") .then(setHealth) .catch(() => setFailed(true)); }, []); if (!health) { if (!failed) return null; return (
无法获取 CLI 健康状态(/api/health 请求失败)。
); } const missing = (["sling", "atlas"] as const).filter((k) => !health[k]); if (missing.length === 0) return null; return (
{missing.map((k) => ( 未检测到 {k} CLI {k === "atlas" ? "(schema 同步不可用)" : "(数据迁移不可用)"} ,安装提示: {INSTALL_HINTS[k]} ))}
); }