Ë
    uPêjX  ã                   ór   — U d dl mZmZ d dlmZ d dlmZ ddlmZ ddl	m
Z
mZmZ dZeed<    G d	„ d
e«      Zy)é    )ÚAnyÚFinal)ÚAuthenticationError)ÚAnthropicMessagesConfigé   )ÚAuthenticator)ÚDEFAULT_GITHUB_COPILOT_API_BASEÚGetAPIKeyErrorÚget_copilot_default_headersz
2026-06-01Ú_MESSAGES_PROXY_API_VERSIONc                   óâ   ‡ — e Zd ZdZdˆ fd„Zededz  fd„«       Zdefd„Z	defd„Z
	 	 dded	ed
ee   dedededz  dedz  deeedz  f   fd„Z	 ddedz  dedz  d	ededededz  defd„Zˆ xZS )Ú$GithubCopilotAnthropicMessagesConfigz¦
    GitHub Copilot implementation of Anthropic messages API.
    Routes requests to Copilot's /v1/messages endpoint with appropriate authentication and headers.
    ÚreturnNc                 ó@   •— t         ‰| �  «        t        «       | _        y ©N)ÚsuperÚ__init__r   Úauthenticator)ÚselfÚ	__class__s    €úx/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/llms/github_copilot/messages/transformation.pyr   z-GithubCopilotAnthropicMessagesConfig.__init__   s   ø€ Ü‰ÑÔÜ*›_ˆÕó    c                  ó   — y)NÚgithub_copilot© ©r   s    r   Úcustom_llm_providerz8GithubCopilotAnthropicMessagesConfig.custom_llm_provider   s   € àr   c                  ó   — y)zÎ
        Copilot's /v1/messages endpoint does not execute ``web_search`` tools, so
        the interception handler must short-circuit web-search-only requests
        instead of routing them here.
        Fr   r   s    r   Úhandles_web_search_nativelyz@GithubCopilotAnthropicMessagesConfig.handles_web_search_natively    s   € ð r   c                  ó   — y)a—  
        Copilot's /v1/messages is a native Anthropic Messages passthrough, so
        ``anthropic-beta`` values injected by ``_update_headers_with_anthropic_beta``
        (context_management, structured outputs, ...) must reach the upstream
        verbatim. The default provider-scoped filter would drop them because
        github_copilot has no entry in ``anthropic_beta_headers_config.json``.
        Fr   r   s    r   Ú$should_filter_anthropic_beta_headerszIGithubCopilotAnthropicMessagesConfig.should_filter_anthropic_beta_headers(   s   € ð r   ÚheadersÚmodelÚmessagesÚoptional_paramsÚlitellm_paramsÚapi_keyÚapi_basec                 ó¬  — | j                   j                  «       xs t        j                  d«      }	 | j                   j	                  «       }	t        |	«      }|j                  «       D ]  \  }}||vsŒ|||<   Œ d|d<   d|d<   t        |d<   d	|vrd
|d	<   | j                  ||d¬«      }||fS # t
        $ r}
t        |dt        |
«      ¬«      ‚d}
~
ww xY w)a;  
        Validate environment for GitHub Copilot and add Copilot-specific headers.

        The caller-supplied ``api_base`` is intentionally ignored. Routing this
        request anywhere other than the authenticated Copilot endpoint would
        leak the Copilot bearer token to a caller-controlled URL.
        ú/r   )r#   Úllm_providerÚmessageNzmessages-proxyzopenai-intentzx-interaction-typezx-github-api-versionzanthropic-versionz
2023-06-01)r   )r   Úget_api_baser	   ÚrstripÚget_api_keyr
   r   Ústrr   Úitemsr   Ú#_update_headers_with_anthropic_beta)r   r"   r#   r$   r%   r&   r'   r(   Údynamic_api_baseÚdynamic_api_keyÚeÚcopilot_headersÚkeyÚvalues                 r   Ú'validate_anthropic_messages_environmentzLGithubCopilotAnthropicMessagesConfig.validate_anthropic_messages_environment2   s	  € ð* $(×#5Ñ#5×#BÑ#BÓ#DÒ#gÔHg×"oÑ"oÐpsÓ"tÐð	Ø%)×%7Ñ%7×%CÑ%CÓ%EˆOô "=¸_Ó!MˆØ)×/Ñ/Ó1ò 	%‰JˆC�Ø˜'Ò!Ø$�˜’ð	%ð $4ˆ�Ñ Ø(8ˆÐ$Ñ%Ü*EˆÐ&Ñ'à gÑ-Ø+7ˆGÐ'Ñ(à×:Ñ:Ø�_Ð:Jð ;ó 
ˆð Ð(Ð(Ð(øô1 ò 	Ü%ØØ-Ü˜A›ôð ûð	ús   ³B. Â.	CÂ7CÃCÚstreamc                 óœ   — |xs" | j                   j                  «       xs t        j                  d«      }|j	                  d«      s|› d�}|S )uþ  
        Return the complete URL for GitHub Copilot /v1/messages endpoint.

        ``api_base`` here is the value already resolved by
        ``validate_anthropic_messages_environment`` (the authenticated Copilot
        host), not the raw caller-supplied base â€” that one is discarded there to
        avoid leaking the Copilot bearer token to a caller-controlled URL. We
        reuse it to avoid a second authenticator read, falling back to a fresh
        resolution only if it was not provided.
        r*   z/v1/messages)r   r-   r	   r.   Úendswith)r   r(   r'   r#   r%   r&   r:   Úresolveds           r   Úget_complete_urlz5GithubCopilotAnthropicMessagesConfig.get_complete_urld   sN   € ð& Òd × 2Ñ 2× ?Ñ ?Ó AÒdÔEd×lÑlÐmpÓqˆØ× Ñ  Ô0Ø"˜ <Ð0ˆHØˆr   )r   N)NNr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr0   r   Úboolr   r!   ÚdictÚlistr   Útupler9   r>   Ú__classcell__)r   s   @r   r   r      s  ø„ ñõ
-ð ð  S¨4¡Zò  ó ð ð¨Tó ð°dó ð" #Ø#ñ0)àð0)ð ð0)ð �s‘)ð	0)ð
 ð0)ð ð0)ð �t‘ð0)ð ˜‘*ð0)ð 
ˆt�S˜4‘ZÐÑ	 ó0)ðr #ñà˜‘*ðð �t‘ðð ð	ð
 ðð ðð �t‘ðð 
÷r   r   N)Útypingr   r   Úlitellm.exceptionsr   ÚHlitellm.llms.anthropic.experimental_pass_through.messages.transformationr   r   r   Úcommon_utilsr	   r
   r   r   Ú__annotations__r   r   r   r   ú<module>rN      s>   ðß Ð å 2õõ *÷ñ ð &2Ð ˜UÓ 1ôhÐ+Bõ hr   