Files
boss/src/app/api/v1/master-agent/evolution/config/route.ts

45 lines
1.6 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { requireRequestSession } from "@/lib/boss-auth";
import { jsonNoStore } from "@/lib/api-response";
import { setMasterAgentEvolutionMode } from "@/lib/master-agent-evolution";
export const runtime = "nodejs";
export async function GET(request: NextRequest) {
const session = await requireRequestSession(request);
if (!session) {
return jsonNoStore({ ok: false, message: "UNAUTHORIZED" }, { status: 401 });
}
return jsonNoStore({ ok: false, message: "METHOD_NOT_ALLOWED" }, { status: 405 });
}
export async function POST(request: NextRequest) {
const session = await requireRequestSession(request);
if (!session) {
return NextResponse.json({ ok: false, message: "UNAUTHORIZED" }, { status: 401 });
}
if (session.role !== "highest_admin") {
return NextResponse.json({ ok: false, message: "FORBIDDEN" }, { status: 403 });
}
const rawBody = await request.text().catch(() => "");
let body: unknown;
try {
body = JSON.parse(rawBody);
} catch {
return NextResponse.json({ ok: false, message: "INVALID_JSON_PAYLOAD" }, { status: 400 });
}
if (!body || typeof body !== "object" || Array.isArray(body)) {
return NextResponse.json({ ok: false, message: "INVALID_EVOLUTION_CONFIG_PAYLOAD" }, { status: 400 });
}
const payload = body as { mode?: unknown };
if (payload.mode !== "controlled" && payload.mode !== "autonomous") {
return NextResponse.json({ ok: false, message: "INVALID_EVOLUTION_MODE" }, { status: 400 });
}
const config = await setMasterAgentEvolutionMode(payload.mode);
return NextResponse.json({ ok: true, config });
}