import { getGrokProxyUrl } from "../lib/grokRuntime.js";
export function registerGrokRoutes(app, ctx) {
    app.get("/api/grok/status", async (_req, res) => {
        const grokCfg = ctx.config.grokProvider || {};
        const timeoutMs = grokCfg.statusTimeoutMs || 3000;
        try {
            const r = await fetch(getGrokProxyUrl(ctx, "/v1/models"), {
                signal: AbortSignal.timeout(timeoutMs),
            });
            if (r.ok) {
                const data = await r.json();
                const models = data?.data?.map((m) => m.id).filter(Boolean) || [];
                const hasImageModel = models.some((m) => m.startsWith("grok-imagine"));
                return res.json({ status: hasImageModel ? "ready" : "no_image_model", models });
            }
            return res.json({ status: "error", reason: `HTTP ${r.status}` });
        }
        catch {
            return res.json({ status: "offline" });
        }
    });
}
