Files
c0py/apps/web/src/lib/api-status.ts
T
Claude CodeandClaude Opus 5 a1b3fef1ac
CI (SIAX Cloud) / sonar (push) Skipped
CI (SIAX Cloud) / security (push) Successful in 16s
CI (SIAX Cloud) / contracts (push) Successful in 31s
Component conformance / Component conformance (blocking) (push) Failing after 45s
CI (SIAX Cloud) / quality (push) Successful in 1m53s
CI (SIAX Cloud) / sonar (pull_request) Skipped
CI (SIAX Cloud) / security (pull_request) Successful in 35s
security / scan (pull_request) Failing after 26s
Component conformance / Component conformance (blocking) (pull_request) Failing after 46s
CI (SIAX Cloud) / contracts (pull_request) Successful in 50s
CI (SIAX Cloud) / quality (pull_request) Successful in 2m15s
fix(web): byt ut platshallarsidan mot en riktig C0PY-konsol
c0py.siax.io och c0py-web.siax.io renderade bokstavligen <div>c0py</div>
(4 tecken synlig text) - rotsidan var en platshallare i repot, inte ett
driftfel. Headless-matning 2026-11-11 fran server11: HTTP 200, tom title,
textLen=4, 0 lankar, 0 knappar.

Rotsidan renderar nu riktigt innehall grundat i repots egna fakta:

* produktidentitet och syfte ur README.md,
* LIVE API-status last server-side ur API:ets egen publika /health
  (status, CL0UD-bindning, API-tid, lastid) - och en uttrycklig
  "kunde inte lasas"-text nar API:et inte svarar, aldrig en pahittad status,
* den faktiska API-ytan (/health publik, /v1/c0py/registries|scans bearer)
  enligt apps/api/src,
* den kanoniska pipelinen ur README/MASTERPLAN.

Dessutom:
* /api/health for c0py-web (status, commit, apiBaseUrl) - samma monster som
  ovriga SIAX-produkter; Dockerfile.web skriver commit till /app/.c0py-commit
  och HEALTHCHECK pekar nu pa /api/health i stallet for /,
* app/icon.svg - c0py-surfacen gav 404 pa /favicon.ico vid varje sidladdning,
* 7 enhetstester for statuslasningen (inkl. att fel och timeout INTE
  rapporteras som ok) ersatter noop-testet.

SIAX-design: Inter, blacksvart rubrik #15151B, violett sidkant #5326CC,
morkt identitetsfalt. Inga nya beroenden (lockfilen oforandrad), inga lokala
DES1GN-primitivnamn exporteras.

Verifierat lokalt: validate:architecture OK, typecheck OK, 7/7 webbtester,
next build OK, next start ger 1475 tecken synlig text och /api/health 200
med live API-status (HTTP 200, status ok, cl0ud disabled).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-11-11 01:10:48 +01:00

87 lines
3.2 KiB
TypeScript

/**
* 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<string, string | undefined> = 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<ApiStatus> {
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<string, unknown>;
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<string> = [
"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",
];