Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOURCE FILE4 * =============================================================================5 * Project : MacLustr LLM API6 * File : web/assets/site/status.js7 * Author : Simon-Pierre Boucher | https://spboucher.ai8 * Contact : admin@spboucher.ai9 * Copyright : (c) 2026 Simon-Pierre Boucher10 * License : None specified (no license file in this repository)11 * =============================================================================12 * END OF SP BOUCHER SOURCE HEADER13 * =============================================================================14 */1516// Status page: only what /api/status and /ready report. Auto-refresh every 30 s.17import { $, h, initChrome, getStatus, fetchJSON, fmtDate, fmtInt, announce } from "/assets/site/core.js";1819initChrome();20const PERIOD = 30;21const hero = $("[data-status-hero]");22const set = (sel, text) => { $(sel).textContent = text; };23const badge = (sel, text, cls) => { const el = $(sel); el.textContent = text; el.className = `badge ${cls}`; };2425const TITLE = {26 operational: "All systems operational",27 unavailable: "Inference is unavailable",28 unreachable: "The API cannot be reached",29};30const SUB = {31 operational: "The gateway answers and an inference engine is available for every public model.",32 unavailable: "The gateway answers, but at least one model has no available engine. Requests to it return 503 until the engine is back.",33 unreachable: "This browser could not get a valid answer from /api/status. The service may be down, restarting, or unreachable from your network.",34};3536async function getReady() {37 try {38 const r = await fetchJSON("/ready", { cache: "no-store" });39 if (r.status === 200) return "ready";40 if (r.status === 503) return "unavailable";41 return "unknown";42 } catch { return "unreachable"; }43}4445let last = null;46async function check() {47 const btn = $("[data-s-refresh]");48 btn.disabled = true;49 const [{ state, data }, ready] = await Promise.all([getStatus(), getReady()]);50 btn.disabled = false;51 hero.dataset.state = state;52 set("[data-status-title]", TITLE[state]);53 set("[data-status-sub]", SUB[state]);5455 const models = data && Array.isArray(data.models) ? data.models : [];56 set("[data-s-model]", models.length ? models.map((m) => m.display_name || m.id).join(", ") : "—");57 set("[data-s-version]", data?.api_version || "—");58 set("[data-s-updated]", data?.last_updated ? fmtDate(data.last_updated) : "—");59 const at = data && typeof data.checked_at === "number" ? new Date(data.checked_at * 1000) : null;60 const checked = $("[data-s-checked]");61 checked.replaceChildren(at ? at.toLocaleTimeString("en-US", { hour: "2-digit", minute: "2-digit", second: "2-digit" }) : "—");62 if (at) checked.append(h("small", null, `${at.toLocaleDateString("en-US", { year: "numeric", month: "short", day: "numeric" })} · server clock`));63 else if (state === "unreachable") checked.append(h("small", null, `Last attempt ${new Date().toLocaleTimeString("en-US")} (this device)`));6465 badge("[data-c-gateway]", state === "unreachable" ? "Unreachable" : "Responding", state === "unreachable" ? "danger" : "ok");66 const R = { ready: ["Ready", "ok"], unavailable: ["Unavailable (503)", "danger"], unreachable: ["Unreachable", "danger"], unknown: ["Unknown", "warn"] };67 badge("[data-c-ready]", ...R[ready]);6869 const list = $("[data-models]");70 if (!models.length) {71 list.replaceChildren(h("div", { class: "check-row" }, h("div", { class: "desc" },72 state === "unreachable" ? "Model information is unavailable while the API cannot be reached." : "No public model is reported.")));73 } else {74 list.replaceChildren(...models.map((m) => h("div", { class: "check-row" },75 h("div", null,76 h("div", { class: "name" }, m.display_name || m.id),77 h("div", { class: "desc tabular" }, [m.id, m.quantization,78 typeof m.context_window === "number" ? `${fmtInt(m.context_window)}-token context` : null].filter(Boolean).join(" · "))),79 h("span", { class: `badge ${m.available ? "ok" : "danger"}` }, m.available ? "Available" : "Unavailable"))));80 }81 if (last !== null && last !== state) announce(`Status changed: ${TITLE[state]}`);82 last = state;83}8485let remaining = PERIOD;86const next = $("[data-s-next]");87function tick() {88 if (document.hidden) return;89 remaining -= 1;90 if (remaining <= 0) { remaining = PERIOD; check(); }91 next.textContent = `Refreshes automatically every ${PERIOD} seconds · next check in ${remaining} s`;92}93$("[data-s-refresh]").addEventListener("click", () => { remaining = PERIOD; check(); });94document.addEventListener("visibilitychange", () => { if (!document.hidden) { remaining = PERIOD; check(); } });95check();96setInterval(tick, 1000);97