Ë
    uPêjã#  ã                   óø   — U d dl mZ d dlmZmZ d dlZd dlmZmZ d dl	m
Z
 d dlmZ d dlmZ ed   Zdd	eeef   dz  d
edz  fd„Z	 	 	 ddedz  d	eeef   dz  deded
eeef   f
d„ZdZeed<    G d„ de«      Zy)é    )ÚMapping)ÚFinalÚLiteralN)ÚBaseLLMModelInfoÚBaseTokenCounter)Úget_secret_str)ÚAllMessageValues)ÚGenericLiteLLMParams)ÚAuthorizationzapi-keyzApi-KeyzOcp-Apim-Subscription-KeyÚlitellm_paramsÚreturnc                 ó`   — ddl m} | rt        j                  | «      n	t        «       } ||«      S )aY  
    Resolve an Entra ID / OAuth access token for an Azure AI Foundry deployment.

    Accepts the same credential set as the `azure` provider: service principal
    (`tenant_id` / `client_id` / `client_secret`), a pre-fetched `azure_ad_token`, an OIDC
    federated token, username/password, or `DefaultAzureCredential` / managed identity.
    r   )Úget_azure_ad_token)Úlitellm.llms.azure.common_utilsr   r
   Úmodel_validate)r   r   Úparamss      úg/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/llms/azure_ai/common_utils.pyÚget_azure_ai_entra_tokenr      s,   € õ CáDRÔ!×0Ñ0°Ô@ÔXlÓXn€Fá˜fÓ%Ð%ó    Úapi_keyÚapi_key_headerÚapi_key_env_varc                 ól   — | r||dk(  rd| › �iS | iS t        |¬«      }|rdd|› �iS t        d|› d�«      ‚)zÎ
    Build the auth headers for an Azure AI Foundry route.

    Prefers the API key when one is configured, and otherwise falls back to Entra ID / OAuth,
    sending the access token as a bearer token.
    r   zBearer )r   z<Missing Azure AI credentials - set an API key (`api_key` or z¼), or Entra ID / OAuth credentials (`tenant_id` + `client_id` + `client_secret`, `azure_ad_token`, an OIDC token, or a managed identity with `litellm.enable_azure_ad_token_refresh = True`))r   Ú
ValueError)r   r   r   r   Úazure_ad_tokens        r   Úget_azure_ai_auth_headersr      sk   € ñ Ø°~ÈÒ7X '¨'¨Ð 3ÐfÐfÐ^eÐfÐfä-¸^ÔL€NÙØ 7¨>Ð*:Ð!;Ð<Ð<ä
Ø
FÀÐFWð XHð 	Hóð r   Ú!azure_model_router_selected_modelÚ%AZURE_MODEL_ROUTER_SELECTED_MODEL_KEYc                   óê  — e Zd ZdZddedz  fd„Zededed   fd„«       Zede	ee
f   dz  dedz  fd	„«       Ze	 	 ddedz  de	ee
f   dz  defd
„«       Zeddedz  dedz  fd„«       Zeddedz  dedz  fd„«       Zeddedz  dedz  fd„«       Zdedz  fd„Zddedz  dedz  dee   fd„Zededefd„«       Zededefd„«       Ze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fd„Zy)ÚAzureFoundryModelInfoz/Model info for Azure AI / Azure Foundry models.NÚmodelc                 ó   — || _         y ©N)Ú_model)Úselfr!   s     r   Ú__init__zAzureFoundryModelInfo.__init__<   s	   € Øˆ�r   r   )ÚagentsÚmodel_routerÚdefaultc                 óP   — d| v ry| j                  «       }d|v sd|v sd|v sd|v ryy)aY  
        Get the Azure AI route for the given model.

        Similar to BedrockModelInfo.get_bedrock_route().

        Supported routes:
        - agents: azure_ai/agents/<agent_id>
        - model_router: azure_ai/model_router/<actual-model-name> or models with "model-router"/"model_router" in name
        - default: standard models
        zagents/r'   úmodel_router/úmodel-router/zmodel-routerr(   r)   )Úlower)r!   Úmodel_lowers     r   Úget_azure_ai_routez(AzureFoundryModelInfo.get_azure_ai_route?   s@   € ð ˜ÑØà"Ÿ[™[›]ˆà˜{Ñ*Ø +Ñ-Ø Ñ,Ø Ñ,à!Ør   Úhidden_paramsc                 ó\   — | sy| j                  t        «      }t        |t        «      r|r|S y)a  The model Azure Model Router actually served, stamped by ``AzureModelRouterConfig``.

        Reading this beats re-deriving the route from a model string: the stamp is set on the
        code path that was actually taken, so it holds no matter what the caller named the model.
        N)Úgetr   Ú
isinstanceÚstr)r0   Úselecteds     r   Úget_model_router_selected_modelz5AzureFoundryModelInfo.get_model_router_selected_modelX   s/   € ñ ØØ'×+Ñ+Ô,QÓRˆÜ�h¤Ô$©ØˆOØr   c                 ó¦   — t         j                  |«      �y|�$|j                  d«      xs |j                  d«      nd}t        d„ || fD «       «      S )a7  Whether a request went down the Azure Model Router route.

        Prefers the response stamp, then the deployment's litellm model path, and only then the
        caller-supplied name. The last two go through ``get_azure_ai_route`` so the model-router
        name heuristic lives in exactly one place.
        NTÚlitellm_model_namer!   c              3   óp   K  — | ].  }t        |t        «      xr t        j                  |«      d k(  –— Œ0 y­w)r(   N)r3   r4   r    r/   )Ú.0Ú	candidates     r   ú	<genexpr>z=AzureFoundryModelInfo.is_model_router_call.<locals>.<genexpr>v   s:   è ø€ ò 
àô �y¤#Ó&ÒpÔ+@×+SÑ+SÐT]Ó+^ÐbpÑ+pÓpñ
ùs   ‚46)r    r6   r2   Úany)r!   r0   Údeployment_models      r   Úis_model_router_callz*AzureFoundryModelInfo.is_model_router_callf   se   € ô !×@Ñ@ÀÓOÐ[ØàUbÐUnˆM×ÑÐ2Ó3ÒQ°}×7HÑ7HÈÔ7QÐtxð 	ô ñ 
à.°Ð6ô
ó 
ð 	
r   Úapi_basec                 óD   — | xs t         j                  xs t        d«      S )NÚAZURE_AI_API_BASE)Úlitellmr@   r   )r@   s    r   Úget_api_basez"AzureFoundryModelInfo.get_api_base{   s   € àÒRœ7×+Ñ+ÒR¬~Ð>QÓ/RÐRr   r   c                 óD   — | xs t         j                  xs t        d«      S )NÚAZURE_AI_API_KEY)rC   r   r   )r   s    r   Úget_api_keyz!AzureFoundryModelInfo.get_api_key   s   € àÒOœ'Ÿ/™/ÒO¬^Ð<NÓ-OÐOr   Úapi_versionc                 óH   — |xs t         j                  xs t        d«      }|S )NÚAZURE_API_VERSION)rC   rH   r   )r%   rH   s     r   rH   z!AzureFoundryModelInfo.api_versionƒ   s#   € à!Ò_¤W×%8Ñ%8Ò_¼NÐK^Ó<_ˆØÐr   c                 ón   — | j                   r)d| j                   j                  «       v rddlm}  |«       S y)z¦
        Factory method to create a token counter for Azure AI.

        Returns:
            AzureAIAnthropicTokenCounter for Claude models, None otherwise.
        Úclauder   )ÚAzureAIAnthropicTokenCounterN)r$   r-   Ú:litellm.llms.azure_ai.anthropic.count_tokens.token_counterrM   )r%   rM   s     r   Úget_token_counterz'AzureFoundryModelInfo.get_token_counterˆ   s2   € ð �;Š;˜8 t§{¡{×'8Ñ'8Ó':Ñ:õñ 0Ó1Ð1Ør   c                 ó   — g S )zª
        Returns a list of models supported by Azure AI.

        Azure AI doesn't have a standard model listing endpoint,
        so this returns an empty list.
        © )r%   r   r@   s      r   Ú
get_modelsz AzureFoundryModelInfo.get_models˜   s	   € ð ˆ	r   c                 ój   — d| v r| j                  dd«      d   S d| v r| j                  dd«      d   S | S )aX  
        Strip the model_router prefix from model name.

        Examples:
        - "model_router/gpt-4o" -> "gpt-4o"
        - "model-router/gpt-4o" -> "gpt-4o"
        - "gpt-4o" -> "gpt-4o"

        Args:
            model: Model name potentially with model_router prefix

        Returns:
            Model name without the prefix
        r+   é   r,   )Úsplit©r!   s    r   Ústrip_model_router_prefixz/AzureFoundryModelInfo.strip_model_router_prefix¥   sE   € ð  ˜eÑ#Ø—;‘;˜°Ó2°1Ñ5Ð5Ø˜eÑ#Ø—;‘;˜°Ó2°1Ñ5Ð5Øˆr   c                 ó0   — t         j                  | «      } | S )zÐ
        Get the base model name, stripping any Azure AI routing prefixes.

        Args:
            model: Model name potentially with routing prefixes

        Returns:
            Base model name
        )r    rW   rV   s    r   Úget_base_modelz$AzureFoundryModelInfo.get_base_model»   s   € ô &×?Ñ?ÀÓFˆØˆr   c                 ó¨   — t         j                  | «      }|dk(  rddlm}  |«       S d| j	                  «       v rddlm}  |«       S ddlm}  |«       S )a  
        Get the appropriate Azure AI config class for the given model.

        Routes to specialized configs based on model type:
        - Model Router: AzureModelRouterConfig
        - Claude models: AzureAnthropicConfig
        - Default: AzureAIStudioConfig

        Args:
            model: The model name

        Returns:
            The appropriate config instance
        r(   r   )ÚAzureModelRouterConfigrL   )ÚAzureAnthropicConfig)ÚAzureAIStudioConfig)	r    r/   Ú7litellm.llms.azure_ai.azure_model_router.transformationr[   r-   Ú.litellm.llms.azure_ai.anthropic.transformationr\   Ú)litellm.llms.azure_ai.chat.transformationr]   )r!   Úazure_ai_router[   r\   r]   s        r   Úget_azure_ai_config_for_modelz3AzureFoundryModelInfo.get_azure_ai_config_for_modelÊ   sV   € ô  !6× HÑ HÈÓ Oˆà˜^Ò+õñ *Ó+Ð+Ø˜Ÿ™›Ñ&õñ (Ó)Ð)åUá&Ó(Ð(r   ÚheadersÚmessagesÚoptional_paramsr   c                 ó   — t        d«      ‚)z+Azure Foundry sends api key in query paramsz5Azure Foundry does not support environment validation)ÚNotImplementedError)r%   rc   r!   rd   re   r   r   r@   s           r   Úvalidate_environmentz*AzureFoundryModelInfo.validate_environmentí   s   € ô "Ð"YÓZÐZr   r#   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r4   r&   Ústaticmethodr   r/   r   Úobjectr6   Úboolr?   rD   rG   ÚpropertyrH   r   rO   ÚlistrR   rW   rY   rb   Údictr	   rh   rQ   r   r   r    r    9   sM  „ Ù9ñ˜c D™jó ð ð #ð ¨'Ð2UÑ*Vò ó ðð0 ð°w¸sÀF¸{Ñ7KÈdÑ7Rð ÐWZÐ]aÑWaò ó ðð à Ø59ñ
Ø�T‰zð
à˜s F˜{Ñ+¨dÑ2ð
ð 
ò
ó ð
ð( ñS˜s T™zð S°S¸4±Zò Só ðSð ñP˜S 4™Zð P°3¸±:ò Pó ðPð ñ s¨T¡zð ¸SÀ4¹Zò ó ððÐ#3°dÑ#:ó ñ  #¨¡*ð ¸sÀT¹zð ÐUYÐZ]ÑU^ó ð ð¨ð °ò ó ðð* ð˜cð  cò ó ðð ð )¨Sò  )ó ð )ðR #Ø#ñ[àð[ð ð[ð Ð'Ñ(ð	[ð
 ð[ð ð[ð �t‘ð[ð ˜‘*ð[ð 
ô[r   r    r#   )Nr   rF   )Úcollections.abcr   Útypingr   r   rC   Ú litellm.llms.base_llm.base_utilsr   r   Úlitellm.secret_managers.mainr   Úlitellm.types.llms.openair	   Úlitellm.types.routerr
   ÚAzureAIApiKeyHeaderr4   rn   r   r   r   Ú__annotations__r    rQ   r   r   ú<module>r{      sÆ   ðÞ #ß !ã ß OÝ 7Ý 6Ý 5àÐ`ÑaÐ ñ&¨W°S¸&°[Ñ-AÀDÑ-Hð &ÐTWÐZ^ÑT^ó &ð" 37Ø*9Ø-ñ	Ø�4‰Zðà˜C ˜KÑ(¨4Ñ/ðð (ðð ð	ð
 ˆS�#ˆXÑóð4 0SÐ % uÓ Rô[Ð,õ [r   