
    i                     B    d Z ddlZddlmZmZ ddlmZ  G d de      Zy)a_  
Vertex AI Realtime (BidiGenerateContent) config.

Extends GeminiRealtimeConfig but adapts the WSS URL and auth header for the
Vertex AI endpoint instead of Google AI Studio.

URL pattern:
  wss://{location}-aiplatform.googleapis.com/ws/
      google.cloud.aiplatform.v1.LlmBidiService/BidiGenerateContent

Auth: OAuth2 Bearer token (not an API key).
    N)ListOptional)GeminiRealtimeConfigc            
            e Zd ZdZdedededdfdZ	 ddee   d	ed
ee   defdZ	 dded	ed
ee   defdZ	ddedefdZ
d	edefdZ	 dded	edee   dee   f fdZ xZS )VertexAIRealtimeConfigz
    Realtime config for Vertex AI (BidiGenerateContent).

    ``access_token`` and ``project`` must be pre-resolved by the caller
    (they require async I/O) and injected at construction time.
    access_tokenprojectlocationreturnNc                 .    || _         || _        || _        y N)_access_token_project	_location)selfr   r	   r
   s       /Users/manta/Documents/Projects/TheRoad-I1/.venv/lib/python3.12/site-packages/litellm/llms/vertex_ai/realtime/transformation.py__init__zVertexAIRealtimeConfig.__init__   s    )!    api_basemodelapi_keyc                     |r8|j                  d      }|j                  dd      j                  dd      }| dS | j                  }|dk(  rd}n| d	}d| dS )
z
        Build the Vertex AI Live WSS endpoint URL.

        If *api_base* is provided it overrides the default aiplatform host,
        allowing enterprise / VPC-SC deployments to point at a custom gateway.
        /zhttps://zwss://zhttp://zws://zA/ws/google.cloud.aiplatform.v1.LlmBidiService/BidiGenerateContentglobalzaiplatform.googleapis.comz-aiplatform.googleapis.com)rstripreplacer   )r   r   r   r   baser
   hosts          r   get_complete_urlz'VertexAIRealtimeConfig.get_complete_url%   ss     ??3'D<<
H5==iQDV\]]>>x.DZ9:Dv^__r   headersc                 v    t        |      }d| j                   |d<   | j                  r| j                  |d<   |S )u   
        Return headers with a Bearer token for Vertex AI.

        ``api_key`` is intentionally ignored — Vertex AI uses OAuth2 tokens,
        not API keys.  The token was resolved at config-construction time.
        zBearer Authorizationzx-goog-user-project)dictr   r   )r   r    r   r   s       r   validate_environmentz+VertexAIRealtimeConfig.validate_environmentC   s@     w-%,T-?-?,@#A ==-1]]G)*r   input_audio_formatc                 2    dddd}|j                  |d      S )Nzaudio/pcm;rate=16000z
audio/pcmuz
audio/pcma)pcm16	g711_ulaw	g711_alawzapplication/octet-stream)get)r   r%   
mime_typess      r   get_audio_mime_typez*VertexAIRealtimeConfig.get_audio_mime_typeY   s'    +%%


 ~~02LMMr   c                     ddl m} ddlm} dg}d| j                   d| j
                   d| }|d|id	d
ddii i d}t        j                  d|i      S )ad  
        Return the JSON setup message for Vertex AI Live.

        Vertex AI requires the fully-qualified model path:
        ``projects/{project}/locations/{location}/publishers/google/models/{model}``

        Also enables automatic activity detection (server VAD) and output
        audio transcription so the proxy forwards transcript events.
        r   )BidiGenerateContentSetup)GeminiResponseModalitiesAUDIOz	projects/z/locations/z/publishers/google/models/responseModalitiesautomaticActivityDetectionFi   )disabledsilenceDurationMs)r   generationConfigrealtimeInputConfiginputAudioTranscriptionoutputAudioTranscriptionsetup)litellm.types.llms.geminir.   litellm.types.llms.vertex_air/   r   r   jsondumps)r   r   r.   r/   response_modalitiesfull_model_pathsetup_configs          r   session_configuration_requestz4VertexAIRealtimeConfig.session_configuration_requeste   s     	GI?Fi$..)(1 	 %!57J K - %),/$ (*(*2
 zz7L122r   messagerA   c                 |    t        j                  |      }|j                  d      dk(  rg S t        |   |||      S )u  
        Translate OpenAI realtime client messages to Vertex AI format.

        ``session.update`` is intentionally ignored (returns []) because
        Vertex AI only accepts a single ``setup`` message at the start of
        the connection — sending a second one causes a 1007 close error.
        The initial setup (sent automatically before bidirectional_forward)
        already includes AUDIO modality and server VAD, so there is nothing
        more to configure.
        typezsession.update)r<   loadsr*   supertransform_realtime_request)r   rB   r   rA   json_message	__class__s        r   rG   z1VertexAIRealtimeConfig.transform_realtime_request   sF      zz'*F#'77Iw1U9
 	
r   r   )r'   )__name__
__module____qualname____doc__strr   r   r   r#   r$   r,   rA   r   rG   __classcell__)rI   s   @r   r   r      s   "S "3 "# "$ " "&	`3-` ` #	`
 
`D "&	  #	
 
,Nc N N"33 "33 "3X 8<	

 
 (0}	

 
c
 
r   r   )rM   r<   typingr   r   +litellm.llms.gemini.realtime.transformationr   r    r   r   <module>rS      s$     ! LP
1 P
r   