// Simple in-memory store for workflow ops
// Parent writes ops here, iframe polls and consumes them

let pendingOps: unknown | null = null;
let opsTimestamp = 0;

export async function POST(request: Request) {
  try {
    const body = await request.json();
    pendingOps = body;
    opsTimestamp = Date.now();
    return Response.json({ ok: true });
  } catch {
    return Response.json({ error: "Invalid JSON" }, { status: 400 });
  }
}

export async function GET() {
  if (pendingOps && Date.now() - opsTimestamp < 30000) {
    const ops = pendingOps;
    pendingOps = null; // Consume
    return Response.json({ ops });
  }
  return Response.json({ ops: null });
}
