
    i                         d Z ddlZddlZddlmZmZmZmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZ dd	lm Z m!Z!m"Z" dd
l#m$Z$  G d de      Z%y)z
This file contains the transformation logic for Bedrock Nova Sonic realtime API.

Transforms between OpenAI Realtime API format and Bedrock Nova Sonic format.
    N)AnyListOptionalUnion)verbose_logger)uuid)Logging)BaseRealtimeConfig)OpenAIRealtimeContentPartDoneOpenAIRealtimeDoneEventOpenAIRealtimeEventsOpenAIRealtimeOutputItemDoneOpenAIRealtimeResponseAudioDone&OpenAIRealtimeResponseContentPartAddedOpenAIRealtimeResponseDelta OpenAIRealtimeResponseDoneObjectOpenAIRealtimeResponseTextDone&OpenAIRealtimeStreamResponseBaseObject+OpenAIRealtimeStreamResponseOutputItemAddedOpenAIRealtimeStreamSession!OpenAIRealtimeStreamSessionEvents)ALL_DELTA_TYPESRealtimeResponseTransformInputRealtimeResponseTypedDict)get_empty_usagec                   t   e Zd ZdZd Z	 d-dededee   defdZ	 d-d	ee   dedee   defd
Z	de
fdZ	 d-dedeee      defdZdee   dee   fdZ	 d.dede
defdZdedee   fdZdedee   fdZdedee   fdZdedee   fdZdedee   fdZdedee   fdZ	 d-dededee   dee   fdZdedededefdZdedee   d ee   d!ee   deee   ee   ee   ee   ee   f   f
d"Zded ee   dee   d#eee      deee   eee      f   f
d$Z ded ee   dee   dee   fd%Z!ded ee   dee   d&ee   d#eee      deee   eee      f   fd'Z"dedee   d!ee   deee   ee   ee   ee   f   fd(Z#ded ee   dee   deee   eef   fd)Z$dedee   fd*Z%de&ee'f   deded+e(de)f
d,Z*y)/BedrockRealtimeConfigz>Configuration for Bedrock Nova Sonic realtime transformations.c                    t        t        j                               | _        t        t        j                               | _        t        t        j                               | _        d| _        d| _        d| _        d| _	        d| _
        d| _        d| _        d| _        d	| _        d
| _        d| _        d| _        d| _        d| _        d	| _        d
| _        d| _        y )Ni   g?gffffff?]        matthewbase64SPEECHz
audio/lpcm>  
text/plain)struuid_libuuid4prompt_namecontent_nameaudio_content_name
max_tokenstop_ptemperatureoutput_sample_rate_hertzoutput_sample_size_bitsoutput_channel_countvoice_idoutput_encodingoutput_audio_typeoutput_media_typeinput_sample_rate_hertzinput_sample_size_bitsinput_channel_countinput_encodinginput_audio_typeinput_media_typetext_media_typeselfs    }/Users/manta/Documents/Projects/TheRoad-I1/.venv/lib/python3.12/site-packages/litellm/llms/bedrock/realtime/transformation.py__init__zBedrockRealtimeConfig.__init__)   s    x~~/0 01"%hnn&6"7 
 ).%')$$%!!'!)!- (-$&(##$ & ( ,  ,    Nheadersmodelapi_keyreturnc                     |S )z@Validate environment - no special validation needed for Bedrock. )r?   rC   rD   rE   s       r@   validate_environmentz*BedrockRealtimeConfig.validate_environmentI   s	     rB   api_basec                     |xs dS )z6Get complete URL - handled by aws_sdk_bedrock_runtime. rH   )r?   rJ   rD   rE   s       r@   get_complete_urlz&BedrockRealtimeConfig.get_complete_urlO   s     ~2rB   c                      y)z'Bedrock requires session configuration.TrH   r>   s    r@   requires_session_configurationz4BedrockRealtimeConfig.requires_session_configurationU   s    rB   toolsc           
         ddd| j                   | j                  | j                  diii}| j                  d| j                  i| j
                  | j                  | j                  | j                  | j                  | j                  | j                  dd}|rddi|d	<   d
| j                  |      i|d<   dd|ii}t        j                  ||d      S )z
        Create initial session configuration for Bedrock Nova Sonic.

        Args:
            model: Model ID
            tools: Optional list of tool definitions

        Returns JSON string with session start and prompt start events.
        eventsessionStartinferenceConfiguration	maxTokenstopPr/   	mediaTyperX   sampleRateHertzsampleSizeBitschannelCountvoiceIdencoding	audioType
promptNametextOutputConfigurationaudioOutputConfigurationapplication/jsontoolUseOutputConfigurationrP   toolConfigurationpromptStart)session_startprompt_start)r-   r.   r/   r*   r=   r6   r0   r1   r2   r3   r4   r5   "_transform_tools_to_bedrock_formatjsondumps)r?   rD   rP   rh   prompt_start_configri   s         r@   session_configuration_requestz3BedrockRealtimeConfig.session_configuration_requestY   s    ,%)__ $

'+'7'7/!

 **(3T5I5I'J!33#'#@#@"&">"> $ 9 9== 00!33)
 /A <= @@G8 34  -1D!EF zz+\J
 	
rB   c                 "   g }|D ]  }|j                  d      dk(  s|j                  di       }d|j                  dd      |j                  dd      dt        j                  |j                  di             id	i}|j                  |        |S )
z
        Transform OpenAI tool format to Bedrock tool format.

        Args:
            tools: List of OpenAI format tools

        Returns:
            List of Bedrock format tools
        typefunctiontoolSpecnamerL   descriptionrk   
parameters)rs   rt   inputSchema)getrk   rl   append)r?   rP   bedrock_toolstoolrq   bedrock_tools         r@   rj   z8BedrockRealtimeConfig._transform_tools_to_bedrock_format   s     Dxx:-88J3 (VR 8'/||M2'F"DJJx||L"/M$N(!  $$\2  rB   audio_format	is_outputc                 .    |dk(  r|rdS dS |dv ry|rdS dS )a  
        Map OpenAI audio format to sample rate.

        Args:
            audio_format: OpenAI audio format (pcm16, g711_ulaw, g711_alaw)
            is_output: Whether this is for output (True) or input (False)

        Returns:
            Sample rate in Hz
        pcm16r   r%   )	g711_ulaw	g711_alawi@  rH   )r?   r|   r}   s      r@    _map_audio_format_to_sample_ratez6BedrockRealtimeConfig._map_audio_format_to_sample_rate   s2     7"%505077!u,u,rB   json_messagec           
      X   t        j                  d       g }|j                  di       }d|v r
|d   | _        d|v r
|d   | _        d|v r
|d   | _        d|v r|d   }| j                  |d      | _        d	|v r|d	   }| j                  |d
      | _        d|v r
|d   | _        d|v r
|d   | _        ddd| j                  | j                  | j                  diii}|j                  t        j                  |             | j                  d| j                  i| j                  | j                  | j                   | j"                  | j
                  | j$                  | j&                  dd}|j                  d      }|rddi|d<   d| j)                  |      i|d<   dd|ii}	|j                  t        j                  |	             |j                  d      }
|
rt+        t-        j.                               }dd| j                  |dd
dd| j                  idii}|j                  t        j                  |             dd| j                  ||
dii}|j                  t        j                  |             dd | j                  |d!ii}|j                  t        j                  |             |S )"z
        Transform session.update event to Bedrock session configuration.

        Args:
            json_message: OpenAI session.update message

        Returns:
            List of Bedrock format messages (JSON strings)
        zHandling session.updatesessionmax_response_output_tokensr/   voiceoutput_audio_formatT)r}   input_audio_formatFr0   r7   rR   rS   rT   rU   rX   rY   r`   rP   rd   re   rf   rg   instructionscontentStartTEXTSYSTEMra   contentNamerp   interactiveroletextInputConfiguration	textInputra   r   content
contentEndra   r   )r   debugrw   r-   r/   r3   r   r0   r7   r.   rx   rk   rl   r*   r=   r6   r1   r2   r4   r5   rj   r'   r(   r)   )r?   r   messagessession_configoutput_formatinput_formatrh   rm   rP   ri   r   text_content_nametext_content_start
text_inputtext_content_ends                  r@   transform_session_update_eventz4BedrockRealtimeConfig.transform_session_update_event   s    	67 %)))R8 (>9,-IJDON*-m<D n$*73DM N2*+@AM,0,Q,Q -R -D)
  >1)*>?L+/+P+P ,Q ,D(
 &7,:;U,VD)$6+9:S+TD( ,%)__ $

'+'7'7/!

 	

=12 **(3T5I5I'J!33#'#@#@"&">"> $ 9 9== 00!33)
 ""7+/A <= @@G8 34  -1D!EF

<01 &)).9 #HNN$4 5 "&*&6&6'8 &', (3>@T@T2U%	" OODJJ'9:; &*&6&6'8#/"J OODJJz23  &*&6&6'8#  OODJJ'789rB   c                    t        j                  d       g }t        | d      sdd| j                  | j                  ddd| j
                  | j                  | j                  | j                  | j                  | j                  dd	ii}|j                  t        j                  |             d| _        |j                  d
d      }dd| j                  | j                  |dii}|j                  t        j                  |             |S )z
        Transform input_audio_buffer.append event to Bedrock audio input.

        Args:
            json_message: OpenAI input_audio_buffer.append message

        Returns:
            List of Bedrock format messages (JSON strings)
        z"Handling input_audio_buffer.append_audio_content_startedrR   r   AUDIOTUSER)rX   rZ   r[   r\   r_   r^   )ra   r   rp   r   r   audioInputConfigurationaudiorL   
audioInputr   )r   r   hasattrr*   r,   r<   r7   r8   r9   r;   r:   rx   rk   rl   r   rw   )r?   r   r   audio_content_start
audio_dataaudio_events         r@   )transform_input_audio_buffer_append_eventz?BedrockRealtimeConfig.transform_input_audio_buffer_append_event@  s    	AB  t56"&*&6&6'+'>'> ''+ &)-)>)>/3/K/K.2.I.I,0,D,D)-)>)>(,(;(;4%#& OODJJ':;<*.D' "%%gr2
"&"2"2#'#:#:)
 	

;/0rB   c                     t        j                  d       g }t        | d      rMdd| j                  | j                  dii}|j                  t        j                  |             t        | d       |S )z
        Transform input_audio_buffer.commit event to Bedrock audio content end.

        Args:
            json_message: OpenAI input_audio_buffer.commit message

        Returns:
            List of Bedrock format messages (JSON strings)
        z"Handling input_audio_buffer.commitr   rR   r   r   )	r   r   r   r*   r,   rx   rk   rl   delattr)r?   r   r   audio_content_ends       r@   )transform_input_audio_buffer_commit_eventz?BedrockRealtimeConfig.transform_input_audio_buffer_commit_eventv  su     	AB 412 &*&6&6'+'>'>#! OODJJ'89:D23rB   c           
         t        j                  d       g }|j                  di       }|j                  d      }|dk(  r| j                  |      S |dk(  r|j                  dg       }|D ]  }|j                  d      dk(  st	        t        j                               }dd	| j                  |d
ddd| j                  idii}|j                  t        j                  |             dd| j                  ||j                  dd      dii}	|j                  t        j                  |	             dd| j                  |dii}
|j                  t        j                  |
              |S )z
        Transform conversation.item.create event to Bedrock text input or tool result.

        Args:
            json_message: OpenAI conversation.item.create message

        Returns:
            List of Bedrock format messages (JSON strings)
        z!Handling conversation.item.createitemrp   function_call_outputmessager   
input_textrR   r   r   Tr   rX   r   r   textrL   r   r   r   )r   r   rw   4transform_conversation_item_create_tool_result_eventr'   r(   r)   r*   r=   rx   rk   rl   )r?   r   r   r   	item_typer   content_partr   r   r   r   s              r@   (transform_conversation_item_create_eventz>BedrockRealtimeConfig.transform_conversation_item_create_event  s    	@A +HHV$	 ..LL 
 	!hhy"-G '##F+|;(+HNN,<(=%  *.2.>.>/@(./3(.$/1E1E;"	-"*& OODJJ/A$BC  '.2.>.>/@+7+;+;FB+G*""J OODJJz$:;  (.2.>.>/@+"($ OODJJ/?$@AU !(X rB   c                 0    t        j                  d       g S )z
        Transform response.create event to Bedrock format.

        Args:
            json_message: OpenAI response.create message

        Returns:
            List of Bedrock format messages (JSON strings)
        zHandling response.creater   r   r?   r   s     r@   transform_response_create_eventz5BedrockRealtimeConfig.transform_response_create_event       	78	rB   c                 0    t        j                  d       g S )z
        Transform response.cancel event to Bedrock format.

        Args:
            json_message: OpenAI response.cancel message

        Returns:
            List of Bedrock format messages (JSON strings)
        zHandling response.cancelr   r   s     r@   transform_response_cancel_eventz5BedrockRealtimeConfig.transform_response_cancel_event  r   rB   r   rn   c                    	 t        j                  |      }|j                  d      }|dk(  r| j                  |      S |dk(  r| j                  |      S |dk(  r| j                  |      S |dk(  r| j                  |      S |d	k(  r| j                  |      S |d
k(  r| j                  |      S t        j                  d|        g S # t         j                  $ r  t        j                  d|dd         g cY S w xY w)aE  
        Transform OpenAI realtime request to Bedrock Nova Sonic format.

        Args:
            message: OpenAI format message (JSON string)
            model: Model ID
            session_configuration_request: Previous session config

        Returns:
            List of Bedrock format messages (JSON strings)
        Invalid JSON message: N   rp   zsession.updatezinput_audio_buffer.appendzinput_audio_buffer.commitzconversation.item.createzresponse.createzresponse.cancelzUnknown message type: )rk   loadsJSONDecodeErrorr   warningrw   r   r   r   r   r   r   )r?   r   rD   rn   r   message_types         r@   transform_realtime_requestz0BedrockRealtimeConfig.transform_realtime_request  s   "	::g.L
 $''/ ++66|DD88AA,OO88AA,OO77@@NN..77EE..77EE""%;L>#JKI+ ## 	""%;GDSM?#KLI	s   C 0C98C9rR   logging_objc                     t        j                  d       t        |j                  ddg      }|t	        |t
              r||d<   t        d|t        t        j                                     S )a  
        Transform Bedrock sessionStart event to OpenAI session.created.

        Args:
            event: Bedrock sessionStart event
            model: Model ID
            logging_obj: Logging object

        Returns:
            OpenAI session.created event
        zHandling sessionStartr   r   )id
modalitiesrD   zsession.created)rp   r   event_id)	r   r   r   litellm_trace_id
isinstancer'   r   r   r)   )r?   rR   rD   r   r   s        r@   transform_session_start_eventz3BedrockRealtimeConfig.transform_session_start_event   sj    " 	45-++(
 E3!7$GG0"&
 	
rB   current_response_idcurrent_output_item_idcurrent_conversation_idc                    |d   }|j                  d      }|dk7  rg |||dfS t        j                  d       |sdt        j                          }|sdt        j                          }|sdt        j                          }|j                  d	d
      }|d
k(  rdnd}g }	t        ddt        j                          d|dg |d      }
|	j                  |
       t        d|d|ddddg d      }|	j                  |       t        ddddt        j                          ||dk(  rdddnddd|      }|	j                  |       |	||||fS )a  
        Transform Bedrock contentStart event to OpenAI response events.

        Args:
            event: Bedrock contentStart event
            current_response_id: Current response ID
            current_output_item_id: Current output item ID
            current_conversation_id: Current conversation ID

        Returns:
            Tuple of (events, response_id, output_item_id, conversation_id, delta_type)
        r   r   	ASSISTANTNzHandling ASSISTANT contentStartresp_item_conv_rp   r   r   r   zresponse.createdevent_realtime.responsein_progress)objectr   statusoutputconversation_idrp   r   responsezresponse.output_item.addedr   realtime.itemr   	assistantr   r   rp   r   r   r   )rp   response_idoutput_indexr   zresponse.content_part.addedrL   rp   r   rp   
transcript)rp   content_indexr   r   item_idpartr   )	rw   r   r   r   r)   r   rx   r   r   )r?   rR   r   r   r   content_startr   content_typecurrent_delta_typereturned_messagesresponse_createdoutput_item_addedcontent_part_addeds                r@   transform_content_start_eventz3BedrockRealtimeConfig.transform_content_start_event@  s   2 n-  (;#&'  	>? #$)$**,"8%',TZZ\N%;"&(-djjl^&<# %((8"f,F' 	 9; B#djjl^,-)'#:

 	  !12 H-+,)!'#	
 	  !23 D.djjl^,* &/  ,%R8+
 	  !34 "#
 	
rB   current_delta_chunksc           	          t        j                  d       |d   j                  dd      }|r|sg |fS t        dddt	        j
                          |d||      }|g }|j                  |       |g|fS )	a{  
        Transform Bedrock textOutput event to OpenAI response.text.delta.

        Args:
            event: Bedrock textOutput event
            current_output_item_id: Current output item ID
            current_response_id: Current response ID
            current_delta_chunks: Current delta chunks

        Returns:
            Tuple of (events, updated_delta_chunks)
        zHandling textOutput
textOutputr   rL   zresponse.text.deltar   r   rp   r   r   r   r   r   delta)r   r   rw   r   r   r)   rx   )r?   rR   r   r   r   text_content
text_deltas          r@   transform_text_output_eventz1BedrockRealtimeConfig.transform_text_output_event  s    & 	23\*..y"=%-@+++0&djjl^,*+

  '#% ##J/|111rB   c           	          t        j                  d       |d   j                  dd      }|r|sg S t        dddt	        j
                          |d||      }|gS )	a5  
        Transform Bedrock audioOutput event to OpenAI response.audio.delta.

        Args:
            event: Bedrock audioOutput event
            current_output_item_id: Current output item ID
            current_response_id: Current response ID

        Returns:
            List of OpenAI events
        zHandling audioOutputaudioOutputr   rL   zresponse.audio.deltar   r   r   )r   r   rw   r   r   r)   )r?   rR   r   r   audio_contentaudio_deltas         r@   transform_audio_output_eventz2BedrockRealtimeConfig.transform_audio_output_event  sk    " 	34m,00B?%-@I1'djjl^,*+
 }rB   r   c                 "   |d   }t        j                  d|        |r|sg |fS g }|dk(  rd}|r/dj                  |D 	cg c]  }	|	j                  dd       c}	      }t	        dddt        j                          |d||	      }
|j                  |
       t        d
ddt        j                          |dd|d|      }|j                  |       nw|dk(  rrt        dddt        j                          |d|      }|j                  |       t        d
ddt        j                          |dddd|      }|j                  |       t        ddt        j                          d||ddddg d      }|j                  |       |dfS c c}	w )a  
        Transform Bedrock contentEnd event to OpenAI response done events.

        Args:
            event: Bedrock contentEnd event
            current_output_item_id: Current output item ID
            current_response_id: Current response ID
            current_delta_type: Current delta type (text or audio)
            current_delta_chunks: Current delta chunks

        Returns:
            Tuple of (events, reset_delta_chunks)
        r   zHandling contentEnd: r   rL   r   zresponse.text.doner   r   )rp   r   r   r   r   r   r   zresponse.content_part.doner   )rp   r   r   r   r   r   r   r   zresponse.audio.done)rp   r   r   r   r   r   r   zresponse.output_item.doner   r   	completedr   r   )rp   r   r   r   r   N)r   r   joinrw   r   r   r)   rx   r   r   r   )r?   rR   r   r   r   r   content_endr   accumulated_textchunk	text_donecontent_part_done
audio_doneoutput_item_dones                 r@   transform_content_end_eventz1BedrockRealtimeConfig.transform_content_end_event  s   * L)4[MBC%-@+++8: '!##%779MN9MUYYw+9MN$  7)!$**,0./%I $$Y/ !>1!$**,0.$.>?/! $$%677*8*!$**,0./J $$Z0 !>1!$**,0.%R8/! $$%67 8,djjl^,+,)!%#
 	  !12 !$&&G Os    Fc                 
   t        j                  d       |r|sg dddfS t               }t        ddt	        j
                          t        d|dg ||j                  |j                  |j                  d      	      }|gdddfS )
ac  
        Transform Bedrock promptEnd event to OpenAI response.done.

        Args:
            event: Bedrock promptEnd event
            current_response_id: Current response ID
            current_conversation_id: Current conversation ID

        Returns:
            Tuple of (events, reset_output_item_id, reset_response_id, reset_delta_type)
        zHandling promptEndNzresponse.doner   r   r  )prompt_tokenscompletion_tokenstotal_tokens)r   r   r   r   r   usager   )
r   r   r   r   r   r)   r   r  r  r  )r?   rR   r   r   	usage_objresponse_dones         r@   transform_prompt_end_eventz0BedrockRealtimeConfig.transform_prompt_end_eventb  s    , 	12"*AtT4''#%	/ djjl^,5*&" 7%.%<%<)2)D)D$-$:$:
$ dD00rB   c           
         t        j                  d       |d   }|r|sg ddfS i }d|v r1	 t        |d   t              rt	        j
                  |d         n|d   }|j                  dd      }|j                  dd      }ddlm	} d	d
t        j                          ||d||t	        j                  |      d}	 |t        |	      g||fS # t        j                  $ r i }Y w xY w)aA  
        Transform Bedrock toolUse event to OpenAI format.

        Args:
            event: Bedrock toolUse event
            current_output_item_id: Current output item ID
            current_response_id: Current response ID

        Returns:
            Tuple of (events, tool_call_id, tool_name) for tracking
        zHandling toolUsetoolUserL   input	toolUseIdtoolNamer   )castz%response.function_call_arguments.doner   )rp   r   r   r   r   call_idrs   	arguments)r   r   r   r'   rk   r   r   rw   typingr  r   r)   rl   r   )
r?   rR   r   r   tool_use
tool_inputtool_call_id	tool_namer  function_call_events
             r@   transform_tool_use_eventz.BedrockRealtimeConfig.transform_tool_use_event  s   " 	/0#%-@r2: 
h  "(7"3S9 JJx01!'*   ||K4LLR0	 	  < /.-#J/	/
 &(;<=
 	
+ ''  
 s   0C	 	C! C!c                    t        j                  d       g }|j                  di       }|j                  d      dk(  rt        t	        j
                               }|j                  dd      }|j                  dd      }dd	| j                  |d
dd|dddiddii}|j                  t        j                  |             dd| j                  |t        |t              r|nt        j                  |      dii}|j                  t        j                  |             dd| j                  |dii}	|j                  t        j                  |	             |S )a  
        Transform conversation.item.create with tool result to Bedrock format.

        Args:
            json_message: OpenAI conversation.item.create message with tool result

        Returns:
            List of Bedrock format messages (JSON strings)
        z1Handling conversation.item.create for tool resultr   rp   r   r  rL   r   rR   r   FTOOLr   rX   r&   )r  rp   r   )ra   r   r   rp   r   toolResultInputConfiguration
toolResultr   r   r   )r   r   rw   r'   r(   r)   r*   rx   rk   rl   r   )
r?   r   r   r   tool_content_namer  r   tool_content_starttool_resulttool_content_ends
             r@   r   zJBedrockRealtimeConfig.transform_conversation_item_create_tool_result_event  sb    	PQ +88F55 #HNN$4 5hhy"-GXXh+F "&*&6&6'8', & &)0$*7BL6Q9%"  OODJJ'9:;  &*&6&6'8%fc2 $*!ZZ/#
K OODJJ{34  &*&6&6'8#  OODJJ'789rB   !realtime_response_transform_inputc                    	 t        j                  |      }|j                  d      }|j                  d      }|j                  d
      }	|j                  d	      }
|j                  d      }|j                  d      }g }|j                  di       }d|v r=| j                  |||      }|j                  |       t        j                  ddi      }n*d|v r,| j                  ||||	      \  }}}}	}|j                  |       nd|v r)| j                  ||||
      \  }}
|j                  |       nd|v r%| j                  |||      }|j                  |       nd|v r*| j!                  |||||
      \  }}
|j                  |       nvd|v rE| j#                  |||      \  }}}|j                  |       t        j$                  d| d| d       n-d|v r)| j'                  |||	      \  }}}}|j                  |       ||||
|	|j                  d      ||dS # t         j                  $ r t        |t              r|dd j                  dd      n|dd }t        j                  d|        g |j                  d      |j                  d      |j                  d	      |j                  d
      |j                  d      |j                  d      |j                  d      dcY S w xY w)ab  
        Transform Bedrock Nova Sonic response to OpenAI realtime format.

        Args:
            message: Bedrock format message (JSON string)
            model: Model ID
            logging_obj: Logging object
            realtime_response_transform_input: Current state

        Returns:
            Transformed response with updated state
        Nr   zutf-8replace)errorsr   r   r   r   r   current_item_chunksr   rn   )r   r   r   r   r   r2  r   rn   rR   rS   
configuredTr   r   r   r   r  zTool use event: z (ID: )	promptEnd)rk   r   r   r   bytesdecoder   r   rw   r   rx   rl   r   extendr   r  r  r%  r   r  )r?   r   rD   r   r.  r   message_previewr   r   r   r   r   rn   r   rR   session_createdeventsr"  r#  s                      r@   transform_realtime_responsez1BedrockRealtimeConfig.transform_realtime_response  s   & 	::g.LD "C!F!F$"
 @CC!
 #D"G"G%#
  ADD" 
 ?BBCWX(I(M(M+)
% 9;   "- U""@@ukO $$_5,0JJd7K,L)u$ 22#&'	#&'" $$V,U"+/+K+K&#$	,(F( $$V,e#66-/BF $$V,U"+/+K+K&#"$,(F( $$V,%.2.K.K-/B/+FL) $$V,  #3I;f\NRS!TUE! //*,C&#" $$V, *&<#6$8'>#D#H#H%$ #5-J
 	
u ## 	 gu- $$WY$?Tc] 
 ""%;O;L#MN*K*O*O,+ (I'L'L)( )J(M(M*) ,M+P+P-, (I'L'L)( 'H&K&K(' 2S1V1V32) 	s   H C
K#"K#)N)T)+__name__
__module____qualname____doc__rA   dictr'   r   rI   rM   boolrO   r   rn   rj   intr   r   r   r   r   r   r   r   LiteLLMLoggingObjr   r   tupler   r   r   r   r   r  r  r  r%  r   r   r6  r   r   r<  rH   rB   r@   r   r   &   su   H,B CG$'2:3-	 MQ .1<DSM	 
 9=4
4
!)$t*!54
	4
lT
 tDz 6 48--,0-	-*@4 @DI @D4 4	c4l 	c:ET EdSVi END T#Y D T#Y $ 8<	(( ( (0}	(
 
c(T

 
 '	

 
+
@k
k
 &c]k
 !)	k

 "*#k
 
!"!		#
k
Z(2(2 !)(2 &c]	(2
 't,G'HI(2 
t()8D9T4U+VV	W(2T!! !)! &c]	!
 
"	#!Ff'f' !)f' &c]	f'
 %SMf' 't,G'HIf' 
t()8D9T4U+VV	Wf'P.1.1 &c].1 "*#	.1
 
!"!	#
.1`9
9
 !)9
 &c]	9

 
t()33	49
vA A	cAFZ
sEz"Z
 Z
 '	Z

 ,JZ
 
#Z
rB   r   )&r@  rk   r   r(   r  r   r   r   r   litellm._loggingr   litellm._uuid*litellm.litellm_core_utils.litellm_loggingr	   rD  -litellm.llms.base_llm.realtime.transformationr
   litellm.types.llms.openair   r   r   r   r   r   r   r   r   r   r   r   r   litellm.types.realtimer   r   r   litellm.utilsr   r   rH   rB   r@   <module>rM     sV      - - +  S L    
 *D
. D
rB   