import { handleOrchestratorCommand } from '@/lib/runtime.js';
import { requireSession } from '@/lib/auth.js';
export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';
export async function POST(req) {
  try {
    const session = await requireSession(req);
    const body = await req.json();
    // Attach user_id to orchestrator context so downstream tools can attribute work
    return Response.json(handleOrchestratorCommand({ ...body, user_id: session.user_id }));
  } catch (err) {
    if (err && typeof err === 'object' && err.status) {
      return Response.json({ error: err.error || 'unauthorized' }, { status: err.status });
    }
    return Response.json({ error: err.message }, { status: 400 });
  }
}
