Ë
    uPêj°  ã                   ó”   — d dl mZmZmZ d dlmZ d dlmZ d dlm	Z	m
Z
 d dlmZ dededed	eeeef   fd
„Z ed«      Z G d„ d«      Zy)é    )ÚAnyÚFinalÚTypeVar)ÚBaseContainerConfig)ÚResponsesAPIRequestUtils)Ú$ContainerCreateOptionalRequestParamsÚ"ContainerListOptionalRequestParams)ÚGenericLiteLLMParamsÚcontainer_idÚcustom_llm_providerÚlitellm_paramsÚreturnc                 óà   — t        j                  | «      }|j                  d| «      }|j                  d«      }|r|dk(  r|}|j                  d«      }|r|j                  d«      s||d<   |||fS )z›Decode a LiteLLM-managed container ID for upstream API calls.

    Returns:
        (original_container_id, resolved_provider, updated_litellm_params)
    Úresponse_idr   ÚopenaiÚmodel_id)r   Ú_decode_container_idÚget)r   r   r   ÚdecodedÚoriginal_container_idÚdecoded_providerÚdecoded_model_ids          ú]/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/containers/utils.pyÚ'decode_managed_container_id_for_requestr      s}   € ô .×BÑBÀ<ÓP€GØ#*§;¡;¨}¸lÓ#KÐà%Ÿk™kÐ*?Ó@ÐÙÐ/°8Ò;Ø.Ðà%Ÿk™k¨*Ó5ÐÙ × 2Ñ 2°:Ô >Ø%5ˆ�zÑ"à Ð"5°~ÐEÐEó    ÚTc                   ó°   — e Zd Zededefd„«       Zedededefd„«       Zedede	fd„«       Z
e	 	 dd	ed
edz  deeef   dz  deeef   dz  def
d„«       Zy)ÚContainerRequestUtilsÚpassed_paramsr   c                 óV   — t        «       }g d¢}|D ]  }|| v sŒ| |   €Œ| |   ||<   Œ |S )zLExtract only valid container creation parameters from the passed parameters.)Úexpires_afterÚfile_idsÚextra_headersÚ
extra_body)r   )r   Ú container_create_optional_paramsÚvalid_paramsÚparams       r   Ú-get_requested_container_create_optional_paramzCContainerRequestUtils.get_requested_container_create_optional_param(   sR   € ô
 3WÓ2XÐ(ò
ˆð "ò 	OˆEØ˜Ò%¨-¸Ñ*>Ñ*JØ:GÈÑ:NÐ0°Ò7ð	Oð 0Ð/r   Úcontainer_provider_configr%   c                 ó¤   — | j                  «       }|j                  «       D ��ci c]  \  }}||v sŒ||“Œ }}}| j                  |d¬«      S c c}}w )z3Get the optional parameters for container creation.F)r%   Údrop_params)Úget_supported_openai_paramsÚitemsÚmap_openai_params)r)   r%   Úsupported_paramsÚkÚvÚfiltered_paramss         r   Ú$get_optional_params_container_createz:ContainerRequestUtils.get_optional_params_container_create<   sg   € ð #<×"WÑ"WÓ"YÐð 4T×3YÑ3YÓ3[×!u©4¨1¨aÐ_`ÐdtÒ_t ! Q¡$Ð!uˆÑ!uà(×:Ñ:Ø-<Øð ;ó 
ð 	
ùó "vs
   ¤A±Ac                 óV   — t        «       }g d¢}|D ]  }|| v sŒ| |   €Œ| |   ||<   Œ |S )zHExtract only valid container list parameters from the passed parameters.)ÚafterÚlimitÚorderr#   Úextra_query)r	   )r   Úcontainer_list_optional_paramsr&   r'   s       r   Ú+get_requested_container_list_optional_paramzAContainerRequestUtils.get_requested_container_list_optional_paramL   sR   € ô
 1SÓ0TÐ&ò
ˆð "ò 	MˆEØ˜Ò%¨-¸Ñ*>Ñ*JØ8EÀeÑ8LÐ.¨uÒ5ð	Mð .Ð-r   NÚresponse_objr   Úlitellm_metadatar$   c                 óÖ  — |xs i }|j                  di «      xs i }|j                  d«      }d}|�d}|rzd|v rvd}|€r|d   }t        |t        «      r#|j                  d«      d   j	                  «       }n:t        |t
        «      r*t        |«      dkD  rt        |d   «      j	                  «       }|r7| r5t        | d«      r)t        j                  ||| j                  ¬«      }|| _
        | S )	a  
        Encode container_id in response object with provider/model metadata for routing.

        This mirrors the responses API pattern where response IDs are encoded with
        routing metadata so follow-up calls can route to the correct provider.

        Encodes when:
        1. litellm_metadata contains model_info.id (indicating router/proxy usage), OR
        2. extra_body contains target_model_names (indicating model-specific routing)

        Direct SDK calls with explicit custom_llm_provider and no routing hints return raw IDs.

        Args:
            response_obj: Response object with an `id` attribute (ContainerObject, DeleteContainerResult, etc.)
            custom_llm_provider: Provider name (e.g., "azure", "openai")
            litellm_metadata: Optional litellm_metadata dict that may contain model_info.id
            extra_body: Optional extra_body dict that may contain target_model_names

        Returns:
            The same response object with encoded container_id (if routing metadata present)
        Ú
model_infoÚidFTÚtarget_model_namesú,r   )r   r   r   )r   Ú
isinstanceÚstrÚsplitÚstripÚlistÚlenÚhasattrr   Ú_build_container_idr?   )	r;   r   r<   r$   r>   r   Úshould_encodeÚtarget_modelsÚ
encoded_ids	            r   Úencode_container_id_in_responsez5ContainerRequestUtils.encode_container_id_in_responsea   sþ   € ð: ,Ò1¨rÐØ,<×,@Ñ,@ÀÈrÓ,RÒ,XÐVXˆ
Ø—>‘> $Ó'ˆð ˆð ÐØ ˆMñ Ð.°*Ñ<Ø ˆMàÐØ'1Ð2FÑ'G�ä˜m¬SÔ1Ø,×2Ñ2°3Ó7¸Ñ:×@Ñ@ÓB‘HÜ ¬tÔ4¼¸]Ó9KÈaÒ9OÜ" =°Ñ#3Ó4×:Ñ:Ó<�Hñ ™\¬g°lÀDÔ.IÜ 8× LÑ LØ$7Ø!Ø)Ÿ_™_ô!ˆJð
 )ˆLŒOàÐr   )NN)Ú__name__Ú
__module__Ú__qualname__ÚstaticmethodÚdictr   r(   r   r3   r	   r:   r   rC   r   rM   © r   r   r   r   '   sÞ   „ Øð0Øð0à	-ò0ó ð0ð& ð
Ø#6ð
à*Nð
ð 
ò
ó ð
ð ð.Øð.à	+ò.ó ð.ð( ð 37Ø,0ñ	<Øð<à  4™Zð<ð ˜s C˜x™.¨4Ñ/ð<ð ˜˜c˜‘N TÑ)ð	<ð
 
ò<ó ñ<r   r   N)Útypingr   r   r   Ú/litellm.llms.base_llm.containers.transformationr   Úlitellm.responses.utilsr   Úlitellm.types.containers.mainr   r	   Úlitellm.types.routerr
   rC   Útupler   r   r   rS   r   r   ú<module>rZ      sm   ðß &Ñ &å OÝ <÷õ 6ðFØðFàðFð )ðFð ˆ3�Ð)Ð)Ñ*ó	Fñ0 ˆCƒL€÷wò wr   