import { NextResponse } from 'next/server';
import { mintBoxTerminalToken, resolveBoxUsername } from '@/lib/agent-worker-proxy';

export const GET = async () => {
  const resolved = await resolveBoxUsername();
  if (!resolved.ok) return resolved.response;
  const minted = mintBoxTerminalToken(resolved.username);
  return minted
    ? NextResponse.json(minted)
    : NextResponse.json(
        { error: 'Terminal is not configured on this deployment.' },
        { status: 503 },
      );
};
