Ë
    tPêjc"  ã                   ó<  — U d Z ddlZddlmZ ddlmZ ddlmZmZm	Z	 e	d   Z
dZeee
df      ed<   d	Zeed
<    ej                  d«      Zeed<   dede
dz  fd„Zdeeef   dz  defd„ZdddddœiZeeeeeef   f      ed<   dg igZeeeeee   f         ed<   dhZeed<   h d£Zeed<   ddddgd œgZeeeeef         ed!<   d"gZeee      ed#<   d$Zeed%<   d&edeeef   fd'„Zd(edeeef   fd)„Zddd*œd+eeef   dz  d,ed(ed-edz  d.edz  deeef   fd/„Z y)0aL  
Pure logic for merging an upstream A2A agent card with LiteLLM-specific overrides.

The merge produces the card that LiteLLM exposes to A2A clients at
``/a2a/{agent_id}/.well-known/agent-card.json``. The upstream card is taken as
the base; specific fields are replaced so all traffic flows through the proxy
and uses LiteLLM auth.
é    N)ÚMapping)Údeepcopy)ÚAnyÚFinalÚLiteral)z0.3ú1.0.ÚSUPPORTED_A2A_PROTOCOL_VERSIONSr   ÚLITELLM_A2A_PROTOCOL_VERSIONze^(\d+\.\d+)(?:\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?)?$Ú_PROTOCOL_VERSION_PATTERNÚversionÚreturnc                 óª   ‡— t        | t        «      syt        j                  | «      }|€y|j	                  d«      Št        ˆfd„t        D «       d«      S )a“  Map a raw ``protocolVersion`` value to the supported canonical major.minor version.

    Accepts the bare major.minor convention of the 1.0 spec (``"0.3"``, ``"1.0"``) and the
    full semver forms older SDKs emit (``"0.3.0"``, ``"1.0.1"``, including prerelease and
    build suffixes like ``"0.3.0-rc1"``). Malformed strings, versions outside the
    supported set, and non-strings yield ``None``.
    Né   c              3   ó.   •K  — | ]  }|‰k(  sŒ	|–— Œ y ­w)N© )Ú.0Ú	supportedÚmajor_minors     €úa/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/proxy/a2a/agent_card.pyú	<genexpr>z-normalize_protocol_version.<locals>.<genexpr>,   s   øè ø€ Òh˜yÈyÐ\gÓOg”Ñhùs   ƒ
Ž)Ú
isinstanceÚstrr   ÚmatchÚgroupÚnextr	   )r   r   r   s     @r   Únormalize_protocol_versionr      sL   ø€ ô �gœsÔ#ØÜ,×2Ñ2°7Ó;€EØ€}ØØŸ™ Q›€KÜÓhÔ,KÔhÐjnÓoÐoó    Úcardc                 óR   — t        | r| j                  d«      nd«      }|�|S t        S )zKReturn the validated protocol version an agent card pins, else the default.ÚprotocolVersionN)r   Úgetr
   )r   Ú
normalizeds     r   Úresolve_served_protocol_versionr#   /   s-   € ä2ÑRV°4·8±8Ð<MÔ3NÐ\`Óa€JØ#Ð/ˆ:ÐQÔ5QÐQr   Ú
LiteLLMKeyÚhttpÚbearerzLiteLLM virtual key)ÚtypeÚschemeÚdescriptionÚLITELLM_SECURITY_SCHEMESÚLITELLM_SECURITY_REQUIREMENTSÚ	streamingÚ_ALLOWED_CAPABILITY_KEYS>   ÚurlÚnameÚskillsÚiconUrlr   ÚproviderÚsecurityÚ
signaturesr)   Úcapabilitiesr    ÚsecuritySchemesÚdocumentationUrlÚdefaultInputModesÚdefaultOutputModesÚpreferredTransportÚsupportedInterfacesÚ!supportsAuthenticatedExtendedCardÚ_ALLOWED_TOP_LEVEL_KEYSÚchatÚChatz*Conversational interaction with the agent.)Úidr/   r)   ÚtagsÚ_DEFAULT_SKILLSÚtextÚ_DEFAULT_MODESz1.0.0Ú_DEFAULT_AGENT_VERSIONÚupstream_capabilitiesc                 ó¤   — t        | t        «      si S | j                  «       D ��ci c]  \  }}|t        v sŒt	        |«      sŒ||“Œ c}}S c c}}w )zDReturn a capabilities dict containing only allowlisted, truthy keys.)r   ÚdictÚitemsr-   Úbool)rF   ÚkeyÚvalues      r   Ú_filter_capabilitiesrM   „   sQ   € äÐ+¬TÔ2Øˆ	à%:×%@Ñ%@Ó%B÷Ù!�s˜EÀcÔMeÒFeÔjnÐotÕjuˆˆU‰
óð ùó s   ¦A·AÁAÚproxy_base_urlc                 ó   — d| dœS )NzLiteLLM Proxy)Úorganizationr.   r   )rN   s    r   Ú_default_litellm_providerrQ   �   s   € Ø+°NÑCÐCr   )r/   r)   Úupstream_cardÚ	proxy_urlr/   r)   c                ó®  — | rt        t        | «      «      ni }t        | «      }||d<   |r||d<   |r||d<   |j                  d«      s	t        |d<   t        |j                  d«      «      |d<   |j                  d«      st        t        «      |d<   |j                  d«      st        t        «      |d<   |j                  d«      st        t        «      |d<   |j                  d	«      st        |«      |d	<   |d
|dœg|d<   t        t        «      |d<   t        t        «      |d<   |j                  «       D ��ci c]  \  }}|t        v sŒ||“Œ c}}S c c}}w )a•  
    Build the LiteLLM-fronted agent card.

    Args:
        upstream_card: Card returned by the upstream agent's well-known endpoint.
            May be ``None``/empty when the upstream did not expose one.
        proxy_url: Full URL clients should hit to invoke this agent through
            the proxy, e.g. ``https://proxy.example.com/a2a/<agent_id>``.
        proxy_base_url: Root URL of the LiteLLM proxy, used as a fallback when
            we synthesize a provider record.
        name: User-supplied agent name from the LiteLLM UI. Takes precedence
            over the upstream card's ``name``.
        description: User-supplied description from the LiteLLM UI. Takes
            precedence over the upstream card's ``description``.

    Returns:
        A dict suitable for serving as the proxy's agent card. Only keys in
        the v1.0 AgentCard schema (plus ``supportedInterfaces``) are emitted.
    r    r/   r)   r   r5   r0   r8   r9   r2   ÚJSONRPC)r.   ÚprotocolBindingr    r;   r6   r3   )r   rH   r#   r!   rE   rM   rB   ÚlistrD   rQ   r*   r+   rI   r=   )	rR   rS   rN   r/   r)   ÚbaseÚserved_versionrK   rL   s	            r   Úmerge_agent_cardrZ   ‘   sR  € ñ6 DQ¤(¬4°Ó+>Ô"?ÐVX€Dô <¸MÓJ€NØ,€DÐ	ÑáØˆˆV‰ÙØ)ˆˆ]Ñà�8‰8�IÔÜ0ˆˆY‰ä/°·±¸Ó0HÓI€DˆÑà�8‰8�HÔÜ!¤/Ó2ˆˆX‰Ø�8‰8Ð'Ô(Ü$(¬Ó$8ˆÐ Ñ!Ø�8‰8Ð(Ô)Ü%)¬.Ó%9ˆÐ!Ñ"à�8‰8�JÔÜ4°^ÓDˆˆZÑð Ø(Ø-ñ	
ð#€DÐ	Ñô 'Ô'?Ó@€DÐ	Ñô
  Ô =Ó>€DˆÑà)-¯©«×X™:˜3 ¸Ô@WÒ9WˆC�‰JÓXÐXùÓXs   Ä7EÅE)!Ú__doc__ÚreÚcollections.abcr   Úcopyr   Útypingr   r   r   ÚSupportedA2AVersionr	   ÚtupleÚ__annotations__r
   Úcompiler   Úobjectr   r   r#   r*   rH   r+   rW   r-   r=   rB   rD   rE   rM   rQ   rZ   r   r   r   ú<module>re      s:  ðòó 
Ý #Ý ß &Ñ &à˜lÑ+Ð ð KYÐ   uÐ-@À#Ð-EÑ'FÑ!GÓ Xð ',Ð ˜eÓ +ð $. 2§:¡:Øló$Ð ˜5ó ð
p¨ð pÐ3FÈÑ3Mó pð"R¨'°#°s°(Ñ*;¸dÑ*Bð RÀsó Rð ØØØ,ñð>Ð ˜%  S¨$¨s°C¨x©.Ð%8Ñ 9Ñ:ó ð FRÐSUÐDVÐCWÐ ˜u T¨$¨s°D¸±I¨~Ñ*>Ñ%?Ñ@Ó Wð $/ -Ð ˜%Ó /ò"Ð ˜ó ð8 ØØCØ�ñ	ð0€��t˜D  c ™NÑ+Ñ,ó ð %+ 8€��d˜3‘iÑ Ó +ð
 !(Ð ˜Ó 'ð°ð ¸¸SÀ#¸X¹ó ðD¨cð D°d¸3À¸8±nó Dð Ø"òHYØ˜3 ˜8Ñ$ tÑ+ðHYð ðHYð ð	HYð
 �‰*ðHYð �t‘ðHYð 
ˆ#ˆsˆ(�^ôHYr   