/** * Live status for the C0PY API, read from the API's own public /health route. * * Honesty rule (docs/STANDARDS.md): the console never renders an invented * status. If the API cannot be reached, that is what the UI says. */ export type ApiStatus = | { reachable: true; httpStatus: number; status: string; timestamp: string | null; cl0ud: string | null; checkedAt: string; } | { reachable: false; httpStatus: number | null; reason: string; checkedAt: string; }; export const DEFAULT_API_BASE_URL = "https://c0py-api.siax.io"; export function apiBaseUrl(env: Record = process.env): string { const raw = env.C0PY_API_BASE_URL?.trim(); return (raw && raw.length > 0 ? raw : DEFAULT_API_BASE_URL).replace(/\/+$/, ""); } export async function fetchApiStatus( baseUrl: string, fetchImpl: typeof fetch = fetch, timeoutMs = 4000, ): Promise { const checkedAt = new Date().toISOString(); const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), timeoutMs); try { const res = await fetchImpl(`${baseUrl}/health`, { cache: "no-store", signal: controller.signal, headers: { accept: "application/json" }, }); if (!res.ok) { return { reachable: false, httpStatus: res.status, reason: `API /health answered HTTP ${res.status}`, checkedAt }; } const body: unknown = await res.json(); const obj = (body ?? {}) as Record; return { reachable: true, httpStatus: res.status, status: typeof obj.status === "string" ? obj.status : "unknown", timestamp: typeof obj.timestamp === "string" ? obj.timestamp : null, cl0ud: typeof obj.cl0ud === "string" ? obj.cl0ud : null, checkedAt, }; } catch (error) { const reason = error instanceof Error ? error.name === "AbortError" ? `no answer within ${timeoutMs} ms` : error.message : "unknown error"; return { reachable: false, httpStatus: null, reason, checkedAt }; } finally { clearTimeout(timer); } } /** The routes the API actually serves today (apps/api/src). */ export const API_SURFACE: ReadonlyArray<{ method: string; path: string; auth: "public" | "bearer"; purpose: string }> = [ { method: "GET", path: "/health", auth: "public", purpose: "Liveness and CL0UD binding mode" }, { method: "GET", path: "/v1/c0py/registries", auth: "bearer", purpose: "Registered capture registries" }, { method: "GET", path: "/v1/c0py/registries/:id", auth: "bearer", purpose: "One registry and its provenance" }, { method: "GET", path: "/v1/c0py/scans", auth: "bearer", purpose: "Capture/scan runs" }, { method: "GET", path: "/v1/c0py/scans/:id", auth: "bearer", purpose: "One run, its evidence and fidelity" }, ]; /** The canonical pipeline, as declared in README.md / docs/MASTERPLAN.md. */ export const PIPELINE: ReadonlyArray = [ "Source product", "discovery", "Playwright/CDP deterministic capture", "semantic workflow exploration", "Evidence Graph / Canonical IR", "frozen reconstruction specs", "builders (v0 / Lovable / Codex / generic)", "preview deployment", "multidimensional QA", "typed repair loop", ];