import { NextResponse } from "next/server";
import { SessionManager } from "@/lib/agents/SessionManager";

export async function POST(request: Request) {
  try {
    const body = await request.json();
    const { id, command } = body;

    if (!id || !command) {
      return NextResponse.json({ error: "Missing required fields 'id' or 'command'." }, { status: 400 });
    }

    const manager = SessionManager.getInstance();
    const success = await manager.injectCommand(id, command);

    return NextResponse.json({ success });
  } catch (error) {
    const errorMessage = error instanceof Error ? error.message : "Unknown error";
    return NextResponse.json({ error: errorMessage }, { status: 500 });
  }
}
