import { NextRequest, NextResponse } from "next/server"; import { loadConfig, startLlama, stopLlama, restartLlama, removeLlama, type DashboardConfig, } from "@/lib/docker"; export const dynamic = "force-dynamic"; export const runtime = "nodejs"; export async function POST(req: NextRequest) { const body = (await req.json()) as { action: "start" | "stop" | "restart" | "remove"; config?: Partial; }; if (body.action === "start") { const current = await loadConfig(); const cfg: DashboardConfig = { ...current, ...(body.config || {}), } as DashboardConfig; const result = await startLlama(cfg); return NextResponse.json(result, { status: result.ok ? 200 : 500 }); } if (body.action === "stop") { const result = await stopLlama(); return NextResponse.json(result, { status: result.ok ? 200 : 500 }); } if (body.action === "restart") { const result = await restartLlama(); return NextResponse.json(result, { status: result.ok ? 200 : 500 }); } if (body.action === "remove") { const result = await removeLlama(); return NextResponse.json(result, { status: result.ok ? 200 : 500 }); } return NextResponse.json({ error: "unknown action" }, { status: 400 }); }