import { NextRequest, NextResponse } from "next/server";
import { getAgent } from "@/lib/agent-registry";
import { createChannelClient } from "@/lib/channel-client";

export async function GET(
  _request: NextRequest,
  { params }: { params: Promise<{ agent: string }> }
) {
  const { agent: agentName } = await params;
  const agent = await getAgent(agentName);
  if (!agent) {
    return NextResponse.json({ error: "Agent not found" }, { status: 404 });
  }

  try {
    const client = createChannelClient(agent.channelUrl, agent.secret);
    const health = await client.getHealth();
    return NextResponse.json({ online: true, ...health });
  } catch {
    return NextResponse.json({ online: false }, { status: 200 });
  }
}
