
    i#                         d Z ddlZddlmZmZ ddlmZmZmZm	Z	m
Z
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DictListOptionalTupleUnion)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e   defd
       Ze	 	 	 d$dee   dee   dee   d	ee   dee   defd       Zedee   dee   dee   ded	ededefd       Zedee   dej2                  dedefd       Zedee   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j2                  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j2                  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j2                  dede&fd       Z'ded e(de)eejT                  f   de+fd!Z,	 d%dee   dee   d"ee   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    /Users/manta/Documents/Projects/TheRoad-I1/.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   s     	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<<%LL(&&-- 	  qD,
 	
 
s   A%Bmodelc                      y)zN
        Return the list of supported parameters for the given model.
        Nr   )r   r5   s     r   get_supported_paramsz.BaseInteractionsAPIConfig.get_supported_paramsQ   s    
 	r!   headerslitellm_paramsc                     i S )zN
        Validate and prepare environment settings including headers.
        r   )r   r8   r5   r9   s       r   validate_environmentz.BaseInteractionsAPIConfig.validate_environmentX   s	     	r!   N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   r<   r5   r=   r9   r>   s         r   get_complete_urlz*BaseInteractionsAPIConfig.get_complete_urla   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   r5   r=   rB   rC   r9   r8   s          r   transform_requestz+BaseInteractionsAPIConfig.transform_request}   s    8 	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   r5   rF   rG   s       r   transform_responsez,BaseInteractionsAPIConfig.transform_response        	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   r5   rK   rG   s       r   transform_streaming_responsez6BaseInteractionsAPIConfig.transform_streaming_response   rJ   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   rN   r<   r9   r8   s        r   !transform_get_interaction_requestz;BaseInteractionsAPIConfig.transform_get_interaction_request         	r!   c                      y)z9
        Transform the get interaction response.
        Nr   r   rF   rG   s      r   "transform_get_interaction_responsez<BaseInteractionsAPIConfig.transform_get_interaction_response        	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   rP   s        r   $transform_delete_interaction_requestz>BaseInteractionsAPIConfig.transform_delete_interaction_request   rR   r!   c                      y)z<
        Transform the delete interaction response.
        Nr   )r   rF   rG   rN   s       r   %transform_delete_interaction_responsez?BaseInteractionsAPIConfig.transform_delete_interaction_response   s     	r!   c                      y)z
        Transform the cancel interaction request into URL and body.

        Returns:
            Tuple of (URL, request_body)
        Nr   rP   s        r   $transform_cancel_interaction_requestz>BaseInteractionsAPIConfig.transform_cancel_interaction_request   s     	r!   c                      y)z<
        Transform the cancel interaction response.
        Nr   rT   s      r   %transform_cancel_interaction_responsez?BaseInteractionsAPIConfig.transform_cancel_interaction_response  rV   r!   error_messagestatus_codec                 $    ddl m}  ||||      )zC
        Get the appropriate exception class for an error.
        r   r   )r`   messager8   )chat.transformationr   )r   r_   r`   r8   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   r5   r>   r$   s       r   should_fake_streamz,BaseInteractionsAPIConfig.should_fake_stream+  s     r!   )NNNr   ).__name__
__module____qualname____doc__r    propertyr   r   r$   r/   r4   strr   r7   dictr	   r   r;   boolrA   r   r   r   rE   httpxResponseLiteLLMLoggingObjr   rI   r   rM   r
   rQ   rU   rX   r   rZ   r\   r   r^   intr   Headersr   rd   rf   r   r!   r   r   r   )   s   	 \    
 
$ # $s)   $'9ABV9W	  
  $)-!%3- } }	
 !  
 6 } } ()	
 > -  
 : } nn '	
 
!  }  '	
 
* "   -	
  
sDy	 " nn ' 
!	    -	
  
sDy	 " 	nn	 '	 		
 
!	 	   -	
  
sDy	  nn ' 
!	 
 
/2
=B4CV=W
	
$ .2	}  &c]	
 
r!   r   )!rj   r,   abcr   r   typingr   r   r   r   r	   r
   r   ro   litellm.types.interactionsr   r   r   r   r   r   litellm.types.routerr   litellm.types.utilsr   *litellm.litellm_core_utils.litellm_loggingr   _LiteLLMLoggingObjrc   r   _BaseLLMExceptionrq   r   r   r!   r   <module>r|      s_   	  # I I I   6 ,XK*(M Mr!   