export type ComponentStatus = "ready" | "unavailable" | "not_configured" export type Health = { status: "ready" | "not_ready" checked_at: string components: { postgresql: { status: ComponentStatus }; redis: { status: ComponentStatus } } } export async function getHealth(signal?: AbortSignal): Promise { const response = await fetch("/api/v1/system/health", { signal, headers: { Accept: "application/json" } }) if (!response.ok && response.status !== 503) throw new Error(`服务请求失败(${response.status})`) const data: unknown = await response.json() if (!data || typeof data !== "object" || !("status" in data) || !("components" in data) || !("checked_at" in data)) throw new Error("服务返回了无效的状态数据") const health = data as Health const statuses = ["ready", "unavailable", "not_configured"] if (!["ready", "not_ready"].includes(health.status) || typeof health.checked_at !== "string" || !statuses.includes(health.components?.postgresql?.status) || !statuses.includes(health.components?.redis?.status)) throw new Error("服务返回了无效的状态数据") return health }