Ë
    tPêj™  ã                   ó2  — U d Z ddlmZmZ ddlmZmZmZ ddlm	Z	 ddl
mZmZ ddlmZ ddlmZmZ ddlmZmZmZmZ dd	lmZ  e«       Zeed
<    G d„ de«      Z G d„ de«      Zej;                  ddg ee«      ge¬«       ee«      fdedede	fd„«       Zy)aó  
FastAPI routes for the A2A registration flow.

Today this exposes a single endpoint, ``POST /v1/a2a/discover``, used by the
LiteLLM UI when an admin registers a new A2A agent: the UI hands us the
upstream agent's base URL, we fetch its well-known card, and we return the
raw card so the UI can render the agent's skills/capabilities and let the
admin pick which ones to expose through the proxy. The actual merge into a
LiteLLM-fronted card happens when the agent is saved via ``POST /v1/agents``.
é    )ÚAnyÚFinal)Ú	APIRouterÚDependsÚHTTPException)ÚJSONResponse)Ú	BaseModelÚField)Úverbose_proxy_logger)ÚLitellmUserRolesÚUserAPIKeyAuth)ÚAGENT_CARD_WELL_KNOWN_PATHSÚAgentCardDiscoveryErrorÚDiscoveryModeÚfetch_well_known_card)Úuser_api_key_authÚrouterc                   ó²   — e Zd ZU  edddj	                  e«      › d�¬«      Zeed<    ee	j                  d¬«      Ze	ed	<    ed
d¬«      Zeeef   d
z  ed<   y
)ÚDiscoverAgentRequest.zpBase URL of the upstream agent. Behavior depends on ``discovery_mode``: ``well_known_fallback`` (default) tries z, zq under this URL in order; ``langgraph_platform`` hits ``/.well-known/agent-card.json?assistant_id=<id>`` instead.)ÚdescriptionÚurlzïHow to locate the upstream card. ``well_known_fallback`` for pure A2A agents (try standard paths); ``langgraph_platform`` for LangGraph Platform deployments where the card is shared across assistants and disambiguated by a query parameter.)Údefaultr   Údiscovery_modeNz{Mode-specific parameters. ``langgraph_platform`` requires ``{'assistant_id': <id>}``. ``well_known_fallback`` ignores this.Úparams)Ú__name__Ú
__module__Ú__qualname__r
   Újoinr   r   ÚstrÚ__annotations__r   ÚWELL_KNOWN_FALLBACKr   r   Údictr   © ó    ú`/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/proxy/a2a/endpoints.pyr   r      s‚   … ÙØðKà�y‰yÐ4Ó5Ð6ð 7JðJô	€Cˆó 	ñ %*Ø×1Ñ1ðô	%€N�Mó 	ñ %*ØðPô%€FˆD��c�‰N˜TÑ!ô r$   r   c                   ó,   — e Zd ZU eed<   eeef   ed<   y)ÚDiscoverAgentResponser   Ú
agent_cardN)r   r   r   r   r    r"   r   r#   r$   r%   r'   r'   =   s   … Ø	ƒHØ�S˜#�X‘Ôr$   r'   z/v1/a2a/discoverz[beta] A2A Agents)ÚtagsÚdependenciesÚresponse_modelÚrequestÚuser_api_key_dictÚreturnc              ƒ   óÌ  K  — |j                   t        j                  k7  rt        dd|j                   › �¬«      ‚	 t	        | j
                  | j                  | j                  ¬«      ƒ d{  –—† }t        | j
                  |d
œd¬«      S 7 Œ# t        $ r}t        dt        |«      ¬«      ‚d}~wt        $ r+}t        j                  d|«       t        dd	|› �¬«      ‚d}~ww xY w­w)u  
    Fetch the upstream agent's well-known card so the UI can show the admin
    which skills/capabilities the agent exposes.

    Only proxy admins can call this â€” the UI uses it during agent registration,
    and we don't want arbitrary keys probing internal URLs.

    Example:
    ```bash
    curl -X POST "http://localhost:4000/v1/a2a/discover" \
        -H "Authorization: Bearer <admin_key>" \
        -H "Content-Type: application/json" \
        -d '{"url": "https://upstream-agent.example.com"}'
    ```
    i“  z6Only proxy admins can discover agent cards. Your role=)Ústatus_codeÚdetail)r   r   Ni�  z)Unexpected error during A2A discovery: %siô  zDiscovery failed: )r   r(   zapplication/json)ÚcontentÚ
media_type)Ú	user_roler   ÚPROXY_ADMINr   r   r   r   r   r   r   Ú	Exceptionr   Ú	exceptionr   )r,   r-   ÚcardÚexcs       r%   Údiscover_agent_cardr:   B   sâ   è ø€ ð2 ×"Ñ"Ô&6×&BÑ&BÒBÜØØLÐM^×MhÑMhÐLiÐjô
ð 	
ð

PÜ1Ø�K‰KØ"×1Ñ1Ø—>‘>ô
÷ 
ˆô ØŸ™°4Ñ8Ø%ôð ð
ùô
 #ò >Ü¨´C¸³HÔ=Ð=ûÜò PÜ×&Ñ&Ð'RÐTWÔXÜ¨Ð6HÈÈÐ4NÔOÐOûðPüsF   ‚8C$»/B Á*B	Á+B Á/C$Â	B Â	C!ÂB*Â*C!Â6&CÃC!Ã!C$N)Ú__doc__Útypingr   r   Úfastapir   r   r   Úfastapi.responsesr   Úpydanticr	   r
   Úlitellm._loggingr   Úlitellm.proxy._typesr   r   Úlitellm.proxy.a2a.discoveryr   r   r   r   Ú$litellm.proxy.auth.user_api_key_authr   r   r    r   r'   Úpostr:   r#   r$   r%   ú<module>rE      s´   ðò	÷ ç 5Ñ 5Ý *ß %å 1ß A÷ó õ Cá“€ˆÓ ô˜9ô ô<˜Iô ð
 ‡�ØØ
Ð	ÙÐ+Ó,Ð-Ø(ð	 ó ñ )0Ð0AÓ(Bñ(Ø!ð(à%ð(ð ò(óñ(r$   