"""api.v1.discovery — A2A agent discovery endpoint."""
from __future__ import annotations
from fastapi import APIRouter, Request
from agentpaas.registry.discovery import get_agent_card

router = APIRouter(tags=["discovery"])

@router.get("/.well-known/agent.json")
async def agent_discovery(request: Request, agent_id: str = ""):
    base_url = str(request.base_url).rstrip("/")
    if agent_id:
        return get_agent_card(agent_id, base_url)
    return {"service": "AgentPaaS", "protocol": "a2a/1.0", "agents_url": f"{base_url}/api/v1/agents"}
