Ë
    uPêj�"  ã                   ó´   — d Z ddlZddlmZmZ ddlmZmZ ddlZddl	m
Z
mZmZmZmZmZ ddlmZ ddlmZ erddlmZ d	d
lmZ eZeZneZeZ G d„ de«      Zy)a‚  
Base transformation class for Interactions API implementations.

This follows the same pattern as BaseResponsesAPIConfig for the Responses API.

Per OpenAPI spec (https://ai.google.dev/static/api/interactions.openapi.json):
- Create: POST /{api_version}/interactions
- Get: GET /{api_version}/interactions/{interaction_id}
- Delete: DELETE /{api_version}/interactions/{interaction_id}
é    N)ÚABCÚabstractmethod)ÚTYPE_CHECKINGÚAny)ÚCancelInteractionResultÚDeleteInteractionResultÚInteractionInputÚ$InteractionsAPIOptionalRequestParamsÚInteractionsAPIResponseÚ InteractionsAPIStreamingResponse)ÚGenericLiteLLMParams)ÚLlmProviders)ÚLoggingé   ©ÚBaseLLMExceptionc                   ó  — e Zd ZdZd„ Zeedefd„«       «       Ze	d„ «       Z
ededee   fd„«       Zededed	ed
z  defd„«       Ze	 	 	 d$ded
z  ded
z  ded
z  d	ed
z  ded
z  defd„«       Zeded
z  ded
z  ded
z  ded	ededefd„«       Zeded
z  dej.                  dedefd„«       Zeded
z  dededefd„«       Zededed	ededeeef   f
d„«       Zedej.                  dedefd„«       Zededed	ededeeef   f
d„«       Z edej.                  dedede!fd„«       Z"ededed	ededeeef   f
d„«       Z#edej.                  dede$fd„«       Z%ded e&deejN                  z  de(fd!„Z)	 d%ded
z  ded
z  d"ed
z  defd#„Z*y
)&ÚBaseInteractionsAPIConfiga†  
    Base configuration class for Google Interactions API implementations.

    Per OpenAPI spec, the Interactions API supports two types of interactions:
    - Model interactions (with model parameter)
    - Agent interactions (with agent parameter)

    Implementations should override the abstract methods to provide
    provider-specific transformations for requests and responses.
    c                  ó   — y ©N© ©Úselfs    úv/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/llms/base_llm/interactions/transformation.pyÚ__init__z"BaseInteractionsAPIConfig.__init__5   s   € Øó    Úreturnc                  ó   — y)z#Return the LLM provider identifier.Nr   r   s    r   Úcustom_llm_providerz-BaseInteractionsAPIConfig.custom_llm_provider8   ó   � r   c                 ó  — | j                   j                  «       D ��ci c]`  \  }}|j                  d«      sJ|j                  d«      s9t        |t        j
                  t        j                  t        t        f«      s|�||“Œb c}}S c c}}w )NÚ__Ú_abc)	Ú__dict__ÚitemsÚ
startswithÚ
isinstanceÚtypesÚFunctionTypeÚBuiltinFunctionTypeÚclassmethodÚstaticmethod)ÚclsÚkÚvs      r   Ú
get_configz$BaseInteractionsAPIConfig.get_config=   s€   € ð Ÿ™×*Ñ*Ó,÷
á��1Ø—<‘< Ô%Ø—L‘L Ô(ÜØä×&Ñ&Ü×-Ñ-ÜÜ ð	ôð �ð ˆq‰Dó
ð 	
ùó 
s   žA%BÚmodelc                  ó   — y)zN
        Return the list of supported parameters for the given model.
        Nr   )r   r1   s     r   Úget_supported_paramsz.BaseInteractionsAPIConfig.get_supported_paramsP   r    r   ÚheadersÚlitellm_paramsNc                 ó   — i S )zN
        Validate and prepare environment settings including headers.
        r   )r   r4   r1   r5   s       r   Úvalidate_environmentz.BaseInteractionsAPIConfig.validate_environmentV   s	   € ð
 ˆ	r   Úapi_baseÚagentÚstreamc                 ó    — |€t        d«      ‚|S )aÕ  
        Get the complete URL for the interaction request.

        Per OpenAPI spec: POST /{api_version}/interactions

        Args:
            api_base: Base URL for the API
            model: The model name (for model interactions)
            agent: The agent name (for agent interactions)
            litellm_params: LiteLLM parameters
            stream: Whether this is a streaming request

        Returns:
            The complete URL for the request
        zapi_base is required)Ú
ValueError)r   r8   r1   r9   r5   r:   s         r   Úget_complete_urlz*BaseInteractionsAPIConfig.get_complete_url]   s   € ð0 ÐÜÐ3Ó4Ð4Øˆr   ÚinputÚoptional_paramsc                  ó   — y)a­  
        Transform the input request into the provider's expected format.

        Per OpenAPI spec, the request body should be either:
        - CreateModelInteractionParams (with model)
        - CreateAgentInteractionParams (with agent)

        Args:
            model: The model name (for model interactions)
            agent: The agent name (for agent interactions)
            input: The input content (string, content object, or list)
            optional_params: Optional parameters for the request
            litellm_params: LiteLLM-specific parameters
            headers: Request headers

        Returns:
            The transformed request body as a dictionary
        Nr   )r   r1   r9   r>   r?   r5   r4   s          r   Útransform_requestz+BaseInteractionsAPIConfig.transform_requesty   r    r   Úraw_responseÚlogging_objc                  ó   — y)z”
        Transform the raw HTTP response into an InteractionsAPIResponse.

        Per OpenAPI spec, the response is an Interaction object.
        Nr   )r   r1   rB   rC   s       r   Útransform_responsez,BaseInteractionsAPIConfig.transform_response–   r    r   Úparsed_chunkc                  ó   — y)z¯
        Transform a parsed streaming response chunk into an InteractionsAPIStreamingResponse.

        Per OpenAPI spec, streaming uses SSE with various event types.
        Nr   )r   r1   rF   rC   s       r   Útransform_streaming_responsez6BaseInteractionsAPIConfig.transform_streaming_response£   r    r   Úinteraction_idc                  ó   — y)zÙ
        Transform the get interaction request into URL and query params.

        Per OpenAPI spec: GET /{api_version}/interactions/{interaction_id}

        Returns:
            Tuple of (URL, query_params)
        Nr   ©r   rI   r8   r5   r4   s        r   Ú!transform_get_interaction_requestz;BaseInteractionsAPIConfig.transform_get_interaction_request´   r    r   c                  ó   — y)z9
        Transform the get interaction response.
        Nr   ©r   rB   rC   s      r   Ú"transform_get_interaction_responsez<BaseInteractionsAPIConfig.transform_get_interaction_responseÅ   r    r   c                  ó   — y)z×
        Transform the delete interaction request into URL and body.

        Per OpenAPI spec: DELETE /{api_version}/interactions/{interaction_id}

        Returns:
            Tuple of (URL, request_body)
        Nr   rK   s        r   Ú$transform_delete_interaction_requestz>BaseInteractionsAPIConfig.transform_delete_interaction_requestÓ   r    r   c                  ó   — y)z<
        Transform the delete interaction response.
        Nr   )r   rB   rC   rI   s       r   Ú%transform_delete_interaction_responsez?BaseInteractionsAPIConfig.transform_delete_interaction_responseä   r    r   c                  ó   — y)zˆ
        Transform the cancel interaction request into URL and body.

        Returns:
            Tuple of (URL, request_body)
        Nr   rK   s        r   Ú$transform_cancel_interaction_requestz>BaseInteractionsAPIConfig.transform_cancel_interaction_requestó   r    r   c                  ó   — y)z<
        Transform the cancel interaction response.
        Nr   rN   s      r   Ú%transform_cancel_interaction_responsez?BaseInteractionsAPIConfig.transform_cancel_interaction_response  r    r   Úerror_messageÚstatus_codec                 ó$   — ddl m}  ||||¬«      ‚)zC
        Get the appropriate exception class for an error.
        r   r   )rY   Úmessager4   )Úchat.transformationr   )r   rX   rY   r4   r   s        r   Úget_error_classz)BaseInteractionsAPIConfig.get_error_class  s   € õ 	;áØ#Ø!Øô
ð 	
r   r   c                  ó   — y)z¥
        Returns True if litellm should fake a stream for the given model.

        Override in subclasses if the provider doesn't support native streaming.
        Fr   )r   r1   r:   r   s       r   Úshould_fake_streamz,BaseInteractionsAPIConfig.should_fake_stream  s   € ð r   )NNNr   )+Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r   r   r+   r0   ÚstrÚlistr3   Údictr   r7   Úboolr=   r	   r
   rA   ÚhttpxÚResponseÚLiteLLMLoggingObjr   rE   r   rH   ÚtuplerL   rO   rQ   r   rS   rU   r   rW   ÚintÚHeadersr   r]   r_   r   r   r   r   r   )   sê  „ ñ	òð Øð2 \ò 2ó ó ð2ð ñ
ó ð
ð$ ð¨#ð °$°s±)ò ó ðð
 ð¨Dð ¸ð ÐNbÐeiÑNið Ðnrò ó ðð ð
 !Ø&*Ø"ñà˜‘*ðð �T‰zðð �T‰zð	ð
 ˜t™ðð �t‘ðð 
òó ðð6 ðà�T‰zðð �T‰zðð   $Ñ&ð	ð
 >ðð -ðð ðð 
òó ðð8 ð
à�T‰zð
ð —n‘nð
ð 'ð	
ð
 
!ò
ó ð
ð ð
à�T‰zð
ð ð
ð 'ð	
ð
 
*ò
ó ð
ð  ðàðð ðð -ð	ð
 ðð 
ˆs�DˆyÑ	òó ðð  ðà—n‘nðð 'ðð 
!ò	ó ðð ðàðð ðð -ð	ð
 ðð 
ˆs�DˆyÑ	òó ðð  ðà—n‘nðð 'ðð ð	ð
 
!òó ðð ðàðð ðð -ð	ð
 ðð 
ˆs�DˆyÑ	òó ðð ðà—n‘nðð 'ðð 
!ò	ó ðð

¨Sð 

¸sð 

ÈTÐTY×TaÑTaÑMað 

Ðfvó 

ð  +/ñ	à�T‰zðð �t‘ðð ! 4™Zð	ð
 
ôr   r   )rc   r(   Úabcr   r   Útypingr   r   ri   Úlitellm.types.interactionsr   r   r	   r
   r   r   Úlitellm.types.routerr   Úlitellm.types.utilsr   Ú*litellm.litellm_core_utils.litellm_loggingr   Ú_LiteLLMLoggingObjr\   r   Ú_BaseLLMExceptionrk   r   r   r   r   ú<module>rw      sY   ðñ	ó ß #ß %ã ÷÷ õ 6Ý ,áÝXåKà*ÐØ(ÑàÐØÐô~ õ ~r   