+
Status
+
Pravaha checks itself live: the database, every AI model and the Cloudinary credits the media runs on.
+
+
}>
+
+
+
+
+
+
+ Database
+
+
+
+ {fast.database.ok ? "Reachable" : "Unreachable"}
+ {fast.database.ms} ms
+
+ Neon Postgres: sessions, time-coded moments and the full-text index.
+
+
+
+
+ Cloudinary credits
+
+ {c ? (
+ <>
+
+
+ {c.used.toFixed(1)} of {c.limit}
+
+ {c.pct}% used
+
+
+
+ Transformations {c.transformations.toFixed(2)} · storage {c.storage.toFixed(2)} · bandwidth {c.bandwidth.toFixed(2)}
+ {c.reportedOn ? ` · reported ${c.reportedOn}` : ""}
+
+ >
+ ) : (
+ Usage couldn't be read right now.
+ )}
+
+
+
+
}>
+
+
+
+ {fast.library && (
+
+
+ In the library
+
+
+ {[
+ [fast.library.sessions, "published sessions"],
+ [fast.library.moments, "moments indexed"],
+ [fast.library.studyPacks, "Study Packs"],
+ [fast.library.questionsAsked, "questions asked"],
+ ].map(([n, label]) => (
+
+
- {n}
+ - {label}
+
+ ))}
+
+
+ )}
+
+
+ Version {fast.version} · checked {new Date(fast.checkedAt).toLocaleTimeString("en-IN")} · JSON at{" "}
+ /api/status
+
+
+ );
+}
+
+async function Verdict({ fast }: { fast: FastStatus }) {
+ const { level, reasons } = verdict(fast, await aiStatus());
+ const head = HEADLINE[level];
+ return (
+
+
+ AI models
+
+ {ai.models ? (
+ <>
+
+ {up} of {ai.models.length} answering. Ask tries them in order, so one failing model doesn't stop answers. If all fail, it shows the closest clips.
+
+
+ {ai.models.map((m) => (
+ -
+
+
+ {m.model}
+
+ {m.ok ? `${m.ms} ms` : m.kind ? KIND[m.kind] : "error"}
+
+ ))}
+
+ {ai.probedAt && Probed {new Date(ai.probedAt).toLocaleTimeString("en-IN")}; refreshed every 5 minutes.
}
+ >
+ ) : (
+ No AI provider is configured. Ask shows the most relevant clips without an AI answer.
+ )}
+
+ );
+}
diff --git a/src/lib/status-level.ts b/src/lib/status-level.ts
new file mode 100644
index 0000000..926871c
--- /dev/null
+++ b/src/lib/status-level.ts
@@ -0,0 +1,40 @@
+// How the public status page turns raw checks into one plain verdict. Pure, so it is unit-tested.
+
+export type CreditLevel = "ok" | "warn" | "critical";
+export type Overall = "operational" | "degraded" | "outage";
+
+export const CREDIT_WARN_PCT = 80;
+export const CREDIT_CRITICAL_PCT = 95;
+
+export function creditLevel(usedPct: number): CreditLevel {
+ return usedPct >= CREDIT_CRITICAL_PCT ? "critical" : usedPct >= CREDIT_WARN_PCT ? "warn" : "ok";
+}
+
+// Public pages show a category, never a raw provider error.
+export type FailureKind = "quota" | "overloaded" | "error";
+
+export function failureKind(message: string | undefined): FailureKind {
+ if (!message) return "error";
+ if (/\b(401|403|429)\b|RESOURCE_EXHAUSTED|PERMISSION_DENIED|quota|rate.?limit/i.test(message)) return "quota";
+ if (/\b(500|502|503|504)\b|UNAVAILABLE|high demand|overloaded/i.test(message)) return "overloaded";
+ return "error";
+}
+
+type Inputs = {
+ database: boolean;
+ aiConfigured: boolean;
+ aiOk: number | null; // models answering, or null when no live probe is available
+ aiTotal: number;
+ credits: CreditLevel | null; // null when Cloudinary's usage couldn't be read
+};
+
+// outage: learners can't be served (no database). degraded: the product works but something that matters is
+// failing, so say so (no AI model answering means Ask falls back to showing clips; credits nearly gone means
+// new clips and reels could stop). Anything else is operational; individual model failures are shown, not alarmed.
+export function overallStatus({ database, aiConfigured, aiOk, aiTotal, credits }: Inputs): { level: Overall; reasons: string[] } {
+ if (!database) return { level: "outage", reasons: ["The database isn't reachable."] };
+ const reasons: string[] = [];
+ if (aiConfigured && aiTotal > 0 && aiOk === 0) reasons.push("No AI model is answering. Ask falls back to showing the most relevant clips.");
+ if (credits === "critical") reasons.push("Cloudinary credits are almost used up. New clips and reels may stop generating.");
+ return { level: reasons.length ? "degraded" : "operational", reasons };
+}
diff --git a/src/lib/status.ts b/src/lib/status.ts
new file mode 100644
index 0000000..16c95c2
--- /dev/null
+++ b/src/lib/status.ts
@@ -0,0 +1,137 @@
+import "server-only";
+
+import { probeModels } from "@/lib/ai";
+import { cld } from "@/lib/cloudinary";
+import { query } from "@/lib/db";
+import { env } from "@/lib/env";
+import { log } from "@/lib/log";
+import { creditLevel, failureKind, overallStatus, type CreditLevel, type FailureKind, type Overall } from "@/lib/status-level";
+
+// The public status page's data: database, every AI model, Cloudinary credits and what the library holds.
+// Expensive checks are cached per server instance so a busy page can't spend tokens or API calls:
+// AI probes (five tiny calls) every 5 minutes, Cloudinary's usage report every 10.
+
+const AI_TTL_MS = 5 * 60_000;
+const USAGE_TTL_MS = 10 * 60_000;
+const DB_TIMEOUT_MS = 3000;
+
+function cached