import { buildIma2Capabilities } from "../lib/capabilities.js";
import { requireRuntimeContext } from "../lib/runtimeContext.js";
const GROK_PLANNER_MODELS = ["grok-4.3", "gpt-5.5", "gpt-5.4", "gpt-5.4-mini"];
export function registerCapabilitiesRoutes(app, ctxRaw) {
    const ctx = requireRuntimeContext(ctxRaw);
    app.get("/api/capabilities", (_req, res) => {
        res.json(buildIma2Capabilities({
            appConfig: ctx.config,
            packageVersion: ctx.packageVersion,
            source: "server",
            server: ctx.serverUrl || `http://localhost:${ctx.serverActualPort || ctx.config.server.port}`,
        }));
    });
    app.get("/api/config/grok-planner", (_req, res) => {
        res.json({ model: ctx.config.grokProvider.plannerModel, options: GROK_PLANNER_MODELS });
    });
    app.patch("/api/config/grok-planner", (req, res) => {
        const model = req.body?.model;
        if (typeof model !== "string" || !GROK_PLANNER_MODELS.includes(model)) {
            res.status(400).json({ error: `Invalid model. Options: ${GROK_PLANNER_MODELS.join(", ")}` });
            return;
        }
        ctx.config.grokProvider.plannerModel = model;
        res.json({ model });
    });
}
