
    Oj                       U d dl mZ d dlZd dlZd dlZd dl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 d dlmZ d dlZd dlmZ ddlm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#m$Z$m%Z%m&Z&m'Z' d	dl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. d	dl/m0Z0m1Z1 ddl2m3Z3 ddl4m5Z5m6Z6 ddl7m8Z8m9Z9 ddl:m;Z;m<Z< ddl=m>Z> ddl?m@Z@mAZA ddlBmCZC ddlDmEZEmFZF ddlGmHZH ddlImJZJ ddlKmLZL ddlMmNZN ddlOmPZPmQZQmRZR ddlSmTZT ddlUmVZV ddlWmXZX ddlYmZZZ dd l[m\Z\ dd!l]m^Z^ dd"l_m`Z` e	rd d#lambZc d d#ldmbZe dd$lfmgZgmhZh d%d&gZi ej                  ek      Zld'emd(<    G d) d%e8      Zn G d* d&e9      Zo G d+ d,      Zp G d- d.      Zq G d/ d0      Zr G d1 d2      Zs G d3 d4      Zt G d5 d6      Zu G d7 d8      Zv G d9 d:      Zw G d; d<      Zx G d= d>ex      Zy G d? d@ex      Zz G dA dBex      Z{ G dC dDex      Z| G dE dFex      Z} G dG dHex      Z~ G dI dJex      Z G dK dL      Z G dM dNe      Z G dO dPe      Z G dQ dRe      Z G dS dTe      Z G dU dVe      Z G dW dXe      Z G dY dZe      Zy)[    )annotationsN)TracebackType)TYPE_CHECKINGAnyUnionCallableIteratorOptional	Awaitablecast)AsyncIterator)	BaseModel   )_legacy_response   )Forks
AsyncForks)BodyOmitQueryHeadersNotGivenomit	not_given)is_givenmaybe_transformstrip_not_givenasync_maybe_transform)SessionsAsyncSessionsSessionsWithRawResponseAsyncSessionsWithRawResponseSessionsWithStreamingResponse"AsyncSessionsWithStreamingResponse)SidebandAsyncSideband)cached_property)FinalRequestOptionsconstruct_type_unchecked)SyncAPIResourceAsyncAPIResource)to_streamed_response_wrapper"async_to_streamed_response_wrapper)live_create_params)OpenAIErrorWebSocketConnectionClosedError)	SendQueue)_merge_mappingsmake_request_options)EventHandlerRegistry)
ErrorEvent)ClientEvent)ServerEvent)ReconnectingEventReconnectingOverridesis_recoverable_close)ClientEventParam)LiveCreateResponse)SessionConfigParam)WebSocketConnectionOptions)MediaSessionConfigParam)SessionUpdateConfigParam)ResponseInputItemParam)ClientConnection)OpenAIAsyncOpenAILive	AsyncLivezlogging.Loggerlogc                      e Zd Zedd       Zedd       Zedd       Zedd       Zedd       Zddde	d	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
i i i dd	d
ddf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)rE   c                ,    t        | j                        S N)r%   _clientselfs    q/var/www/origus_pro_usr/data/www/origus.pro/core/.venv/lib/python3.12/site-packages/openai/resources/live/live.pysidebandzLive.sideband>       %%    c                ,    t        | j                        S rJ   )r   rK   rL   s    rN   forksz
Live.forksB   s    T\\""rQ   c                ,    t        | j                        S rJ   )r   rK   rL   s    rN   sessionszLive.sessionsF   rP   rQ   c                    t        |       S a  
        This property can be used as a prefix for any HTTP method call to return
        the raw response object instead of the parsed content.

        For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
        )LiveWithRawResponserL   s    rN   with_raw_responsezLive.with_raw_responseJ   s     #4((rQ   c                    t        |       S z
        An alternative to `.with_raw_response` that doesn't eagerly read the response body.

        For more information, see https://www.github.com/openai/openai-python#with_streaming_response
        )LiveWithStreamingResponserL   s    rN   with_streaming_responsezLive.with_streaming_responseT   s     )..rQ   Nextra_headersextra_query
extra_bodytimeoutc                   | j                  dt        ||dt        j                        t	        ||||ddi      t
              S )C  Create a Live WebRTC session.

        Start with the
        [Live prompting guide](https://developers.openai.com/api/docs/guides/live-prompting).

        Args:
          session: Startup configuration for the Live session.

          transport: WebRTC transport with the browser's SDP offer.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        /live/sessionssession	transportbearer_authTr_   r`   ra   rb   securitybodyoptionscast_to)_postr   r.   LiveCreateParamsr3   r<   rM   rg   rh   r_   r`   ra   rb   s          rN   createzLive.create]   s^    < zz &!* #33 )+'%'. '!  
 	
rQ            ?       @   c	                >    t        | j                  ||||||||	      S a  Connect to Live without query parameters.

        Send session.start with model and session configuration, then wait for session.started. Follow the [Live prompting guide](https://developers.openai.com/api/docs/guides/live-prompting) before writing instructions.
        )	clientr`   r_   websocket_connection_optionson_reconnectingmax_retriesinitial_delay	max_delaymax_queue_size)LiveConnectionManagerrK   	rM   r`   r_   r{   r|   r}   r~   r   r   s	            rN   connectzLive.connect   s0     %<<#')E+#')

 
	
rQ   )returnr%   )r   r   )r   r   )r   rX   )r   r\   rg   r?   rh   zlive_create_params.Transportr_   zHeaders | Noner`   zQuery | Nonera   zBody | Nonerb   z(float | httpx2.Timeout | None | NotGivenr   r<   )r`   r   r_   r   r{   r>   r|   BCallable[[ReconnectingEvent], ReconnectingOverrides | None] | Noner}   intr~   floatr   r   r   r   r   r   __name__
__module____qualname__r'   rO   rS   rU   rY   r]   r   rs   r    rQ   rN   rE   rE   =   s7   & & # # & & ) ) / / )-$("&<E/
 )/
 0	/
 &/
 "/
  /
 :/
 
/
f  !#CE^b"'

 
 'A	

 \
 
 
 
 
 

rQ   c                      e Zd Zedd       Zedd       Zedd       Zedd       Zedd       Zddde	d	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
i i i dd	d
ddf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)rF   c                ,    t        | j                        S rJ   )r&   rK   rL   s    rN   rO   zAsyncLive.sideband       T\\**rQ   c                ,    t        | j                        S rJ   )r   rK   rL   s    rN   rS   zAsyncLive.forks   s    $,,''rQ   c                ,    t        | j                        S rJ   )r    rK   rL   s    rN   rU   zAsyncLive.sessions   r   rQ   c                    t        |       S rW   )AsyncLiveWithRawResponserL   s    rN   rY   zAsyncLive.with_raw_response   s     (--rQ   c                    t        |       S r[   )AsyncLiveWithStreamingResponserL   s    rN   r]   z!AsyncLive.with_streaming_response   s     .d33rQ   Nr^   c                  K   | j                  dt        ||dt        j                         d{   t	        ||||ddi      t
               d{   S 7 '7 w)rd   re   rf   Nri   Trj   rl   )rp   r   r.   rq   r3   r<   rr   s          rN   rs   zAsyncLive.create   sw     < ZZ,&!* #33  )+'%'. '!   
 
 	

s!   -AA
"AAAArt   ru   rv   rw   c	                >    t        | j                  ||||||||	      S ry   )AsyncLiveConnectionManagerrK   r   s	            rN   r   zAsyncLive.connect   s0     *<<#')E+#')

 
	
rQ   )r   r&   )r   r   )r   r    )r   r   )r   r   r   )r`   r   r_   r   r{   r>   r|   r   r}   r   r~   r   r   r   r   r   r   r   r   r   rQ   rN   rF   rF      s7   + + ( ( + + . . 4 4 )-$("&<E/
 )/
 0	/
 &/
 "/
  /
 :/
 
/
f  !#CE^b"'

 
 'A	

 \
 
 
 
 
 
$
rQ   c                  &    e Zd ZddZedd       Zy)rX   c                Z    || _         t        j                  |j                        | _        y rJ   )_liver   to_raw_response_wrapperrs   rM   lives     rN   __init__zLiveWithRawResponse.__init__  s"    
&>>KK
rQ   c                @    t        | j                  j                        S rJ   )r!   r   rU   rL   s    rN   rU   zLiveWithRawResponse.sessions  s    &tzz':':;;rQ   Nr   rE   r   None)r   r!   r   r   r   r   r'   rU   r   rQ   rN   rX   rX     s    
 < <rQ   rX   c                  &    e Zd ZddZedd       Zy)r   c                Z    || _         t        j                  |j                        | _        y rJ   )r   r   async_to_raw_response_wrapperrs   r   s     rN   r   z!AsyncLiveWithRawResponse.__init__%  s"    
&DDKK
rQ   c                @    t        | j                  j                        S rJ   )r"   r   rU   rL   s    rN   rU   z!AsyncLiveWithRawResponse.sessions,  s    +DJJ,?,?@@rQ   Nr   rF   r   r   )r   r"   r   r   rQ   rN   r   r   $  s    
 A ArQ   r   c                  &    e Zd ZddZedd       Zy)r\   c                F    || _         t        |j                        | _        y rJ   )r   r,   rs   r   s     rN   r   z"LiveWithStreamingResponse.__init__2  s    
2KK
rQ   c                @    t        | j                  j                        S rJ   )r#   r   rU   rL   s    rN   rU   z"LiveWithStreamingResponse.sessions9  s    ,TZZ-@-@AArQ   Nr   )r   r#   r   r   rQ   rN   r\   r\   1  s    
 B BrQ   r\   c                  &    e Zd ZddZedd       Zy)r   c                F    || _         t        |j                        | _        y rJ   )r   r-   rs   r   s     rN   r   z'AsyncLiveWithStreamingResponse.__init__?  s    
8KK
rQ   c                @    t        | j                  j                        S rJ   )r$   r   rU   rL   s    rN   rU   z'AsyncLiveWithStreamingResponse.sessionsF  s    1$**2E2EFFrQ   Nr   )r   r$   r   r   rQ   rN   r   r   >  s    
 G GrQ   r   c            	          e Zd ZU dZded<   ded<   ded<   ddd	d
di i dd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZd dZd!dZd"dZ	d#dZ
dddd$dZd%dZd&dZd'dZ	 d(	 	 	 	 	 d)dZd*dZ	 d(	 	 	 	 	 d)dZd'dZy)+AsyncLiveConnection6Represents a live WebSocket connection to the Live APIAsyncLiveSessionResourcerg   AsyncLiveResponseResourceresponseAsyncWebSocketConnection_connectionNrt   ru   rv   make_wsr|   r}   r~   r   r`   r_   
send_queuec               &   || _         || _        || _        || _        d| _        || _        || _        || _        || _        d| _	        d| _
        |	xs
 t               | _        t        d      | _        t        |       | _        t#        |       | _        y )Nr   Fuse_lock)r   _make_ws_on_reconnecting_max_retries_reconnect_attempt_initial_delay
_max_delay_extra_query_extra_headers_intentionally_closed_is_reconnectingr1   _send_queuer4   _event_handler_registryr   rg   r   r   
rM   
connectionr   r|   r}   r~   r   r`   r_   r   s
             rN   r   zAsyncLiveConnection.__init__S  s     & /'"#+#'+%*" %%4';U'K$/51$7rQ   c                 K   ddl m}m} 	 	 | j                          d{    7 # |$ r Y y|$ rO}| j	                  |       d{  7  s+| j
                  j                         }|rt        d|      | Y d}~Xd}~ww xY wwzq
        An infinite-iterator that will continue to yield events until
        the connection is closed.
        r   )ConnectionClosedOKConnectionClosedErrorNz0WebSocket connection closed with unsent messages)unsent_messageswebsockets.exceptionsr   r   recv
_reconnectr   drainr0   rM   r   r   excunsents        rN   	__aiter__zAsyncLiveConnection.__aiter__q  s     
 	T IIK'' '% ( !__S111!--335F<N,2  ##  2sL   
B+ )+ B+ BBBB 
A0B ;B BBc                (  K   | j                  | j                          d{         }t        t        t        |      t
              rt        d|      j                  d      nt        |dd      }t        |t              r|r|dk7  rd| _	        |S 7 nw)
        Receive the next message from the connection and parses it into a `ServerEvent` object.

        Canceling this method is safe. There's no risk of losing data.
        Ndict[str, object]typeerrorr   
parse_event
recv_bytes
isinstancer   objectdictgetgetattrstrr   rM   event
event_types      rN   r   zAsyncLiveConnection.recv  s        t'8!89 $vu-t4 $e,008- 	 j#&:*:O&'D# "9s   BBA/Bc                  K   | j                   j                  d       d{   }t        j                  dt	        |             | j
                  ra	 t        j                  |      }t        |t              rt        d|      j                  d      nd}t        |t              r|r|dk7  rd| _        |S 7 # t        t        f$ r |cY S w xY ww)	  Receive the next message from the connection as raw bytes.

        Canceling this method is safe. There's no risk of losing data.

        If you want to parse the message into a `ServerEvent` object like `.recv()` does,
        then you can call `.parse_event(data)`.
        FdecodeN$Received WebSocket message: %i bytesr   r   r   r   r   r   rG   debuglenr   jsonloads
ValueErrorRecursionErrorr   r   r   r   r   rM   message
event_datar   s       rN   r   zAsyncLiveConnection.recv_bytes  s      ((--U-;;		8#g,G""%)ZZ%8
 OYYceiNj1:>BB6JptJ*c*zjG>S*+' < / s4    CB5/CB7 (AC7CC
CCc                  K   t        |t              r|j                  ddd      n*t        j                  t        |t               d {         }| j                  r| j                  j                  |       y 	 | j                  j                  |       d {    y 7 U7 # t        $ r | j                  j                  |        w xY wwNTuse_api_namesexclude_defaultsexclude_unset)r   r   to_jsonr   dumpsr   r;   r   r   enqueuer   send	ExceptionrM   r   datas      rN   r  zAsyncLiveConnection.send  s      %+ MMtSWMX"7?O"PPQ 	
   $$T*	""''--- Q . 	$$T*	s<   AC	B
0C;B# B!B# C!B# #&C		Cc                   K   | j                   r?t        |t              r|n|j                  d      }| j                  j                  |       y | j                  j                  |       d {    y 7 wNzutf-8r   r   r   r   r   r  r   r  rM   r  raws      rN   send_rawzAsyncLiveConnection.send_raw  sY       $T3/$T[[5IC$$S)##D)))s   A*A4,A2-A4   codereasonc               h   K   d| _         | j                  j                  ||       d {    y 7 wNTr  r   r   closerM   r  r  s      rN   r  zAsyncLiveConnection.close  s-     %)"$$$v$>>>s   (202c           
         t        t        t        t        j                  |      t        t
        t                          S z
        Converts a raw `str` or `bytes` message into a `ServerEvent` object.

        This is helpful if you're using `.recv_bytes()`.
        )valuetype_r   r7   r)   r   r   r   rM   r  s     rN   r   zAsyncLiveConnection.parse_event  ,     K!9

4@PX\]`bmXn!opprQ   c           	       K   ddl }| j                  | j                  yddlm} d}t        ||      r"|j                  |j                  j                  }t        |      syd| _	        t        | j                  dz   | j                  dz         D ]  }|| _        t        | j                  d|dz
  z  z  | j                        }d	t!        j                          d
z  z   }||z  }t#        || j                  ||| j$                  | j&                        }		 | j                  |	      }
|
|
j+                  d      r	d| _	         y|
d|
v r
|
d   | _        d|
v r
|
d   | _        t,        j/                  d|| j                  |       |j1                  |       d{    | j2                  r	d| _	         y	 | j                  | j$                  | j&                         d{   | _        t,        j/                  d       d| _	        | j7                          d{     y d| _	        y# t(        $ r d| _	        Y  yw xY w7 7 a7 *# t(        $ r Y w xY ww)Attempt to reconnect after a connection failure.

        Returns ``True`` if a new connection was established, ``False`` if the
        caller should re-raise the original exception.
        r   NFr     Tr            ?      ?attemptmax_attemptsdelay
close_coder`   r_   abortr`   r_   ?Reconnecting to WebSocket API (attempt %d/%d) after %.1fs delayReconnected to WebSocket API)asyncior   r   r   r   r   rcvdr  r:   r   ranger   r   minr   r   randomr8   r   r   r  r   rG   infosleepr   r   _flush_send_queue)rM   r   r-  r   r)  r&  
base_delayjitterr(  r   results              rN   r   zAsyncLiveConnection._reconnect  sM     	  (DMM,A?
c01chh6JJ#J/ $T44q8$:K:Ka:OP 2	G&-D#T00A'A+4FGYJFMMOd22F'E%!..% --"11E..u5
 !fjj&9(-%! F*(.}(=D%"f,*0*AD'HHQ!!	 --&&&))(-%)-t7H7H$J]J])^#^ 78(-%,,...a2	h !&I  (-%( ' $_ / s   DIH #A0IH7I.)H=H98H=H;H=I H40I3H44I9H=;H==	I
I	I

Ic                    K   d fd}	  j                   j                  |       d{    y7 # t        $ r t        j	                  d       Y yw xY ww)5Send all queued messages over the current connection.c                X   K   j                   j                  |        d {    y 7 wrJ   r   r  r  rM   s    rN   _sendz4AsyncLiveConnection._flush_send_queue.<locals>._send   s!     ""''---s   *(*N*Failed to flush send queue after reconnect)r  r   r   r   )r   flush_asyncr  rG   warning)rM   r=  s   ` rN   r4  z%AsyncLiveConnection._flush_send_queue  sI     	.	F""..u555 	FKKDE	Fs1   A1 /1 A1 AAAAc                X     | j                   j                  |        S d fd}|S )a-  Adds the handler to the end of the handlers list for the given event type.

        No checks are made to see if the handler has already been added. Multiple calls
        passing the same combination of event type and handler will result in the handler
        being added, and called, multiple times.

        Can be used as a method (returns ``self`` for chaining)::

            connection.on("session.started", my_handler)

        Or as a decorator::

            @connection.on("session.started")
            async def my_handler(event): ...
        c                @    j                   j                  |        | S rJ   r   addfnr   rM   s    rN   	decoratorz)AsyncLiveConnection.on.<locals>.decorator>      ((,,Z<IrQ   rF  Callable[..., Any]r   rJ  rC  rM   r   handlerrG  s   ``  rN   onzAsyncLiveConnection.on(  3    $ ((,,ZAK	 rQ   c                >    | j                   j                  ||       | S z-Remove a previously registered event handler.r   removerM   r   rL  s      rN   offzAsyncLiveConnection.offD      $$++J@rQ   c                \     |  j                   j                  |d        S d fd}|S )bRegister a one-time event handler.

        Automatically removed after first invocation.
        Toncec                D    j                   j                  | d       | S NTrX  rC  rE  s    rN   rG  z+AsyncLiveConnection.once.<locals>.decoratorT  #    ((,,Z$,GIrQ   rI  rC  rK  s   ``  rN   rY  zAsyncLiveConnection.onceI  8     ((,,Zt,LK	 rQ   c                  K   ddl }| 2 3 d{   }|j                  }| j                  j                  |      }| j                  j                  d      }|dk(  r"|s |st	        |t
              rt        d|       |D ]&  } ||      }|j                  |      s| d{    ( |D ]&  } ||      }|j                  |      s| d{    ( 7 7 47 6 yw)al  Run the event loop, dispatching received events to registered handlers.

        Blocks until the connection is closed. This is the push-based
        alternative to iterating with ``async for event in connection``.

        If an ``"error"`` event arrives and no handler is registered for
        ``"error"`` or ``"event"``, an ``OpenAIError`` is raised.
        r   Nr   r   WebSocket error: )r-  r   r   get_handlersr   r5   r/   iscoroutine)rM   r-  r   r   specificgenericrL  r7  s           rN   dispatch_eventsz#AsyncLiveConnection.dispatch_eventsZ  s      	 	! 	!%J33@@LH22??HGW$XgeZ0%(9%&ABB# ! &&v. LL!
 # ! &&v. LL!	! !
 !#  sV   CCCCBCCC $CC
CCCCCC)r   r   r   zFCallable[[Query, Headers], Awaitable[AsyncWebSocketConnection]] | Noner|   r   r}   r   r~   r   r   r   r`   r   r_   r   r   SendQueue | Noner   r   )r   zAsyncIterator[ServerEvent]r   r7   r   bytesr   zClientEvent | ClientEventParamr   r   r  zbytes | strr   r   r  r   r  r   r   r   r  zstr | bytesr   r7   r   r  r   boolr   r   rJ   )r   r   rL  Callable[..., Any] | Noner   zNUnion[AsyncLiveConnection, Callable[[Callable[..., Any]], Callable[..., Any]]])r   r   rL  rJ  r   r   )r   r   r   __doc____annotations__r   r   r   r   r  r  r  r   r   r4  rM  rT  rY  rd  r   rQ   rN   r   r   K  s&   @%%'')) [_^b"!#'+8,8 X	8
 \8 8 8 8 8 8 %8 
8<,$** *.R ?qKZ	F EI(A	W8 EI(A	W"!rQ   r   c                      e Zd ZdZdddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZdd	Z	 d	 	 	 	 	 dd
ZddZ	 d	 	 	 	 	 ddZddZ	e	Z
ddZddZ	 	 	 	 	 	 	 	 ddZy)r   a  
    Context manager over a `AsyncLiveConnection` that is returned by `live.connect()`

    This context manager ensures that the connection will be closed when it exits.

    ---

    Note that if your application doesn't work well with the context manager approach then you
    can call the `.enter()` method directly to initiate a connection.

    **Warning**: You must remember to close the connection with `.close()`.

    ```py
    connection = await client.live.connect(...).enter()
    # ...
    await connection.close()
    ```
    Nrt   ru   rv   rw   r|   r}   r~   r   r   c       	            || _         d | _        || _        || _        || _        || _        || _        || _        || _        t        |	      | _
        t        d      | _        y )N	max_bytesFr   )#_AsyncLiveConnectionManager__client'_AsyncLiveConnectionManager__connection(_AsyncLiveConnectionManager__extra_query*_AsyncLiveConnectionManager__extra_headers9_AsyncLiveConnectionManager__websocket_connection_options,_AsyncLiveConnectionManager__on_reconnecting(_AsyncLiveConnectionManager__max_retries*_AsyncLiveConnectionManager__initial_delay&_AsyncLiveConnectionManager__max_delayr1   '_AsyncLiveConnectionManager__send_queuer4   3_AsyncLiveConnectionManager__event_handler_registry
rM   rz   r`   r_   r{   r|   r}   r~   r   r   s
             rN   r   z#AsyncLiveConnectionManager.__init__  se     8<(,.J+!0(,$%?(<e(L%rQ   c                    t        |t              r|j                  ddd      n"t        j                  t        |t                    }| j                  j                  |       yzQueue a message to be sent when the connection is established.

        This can be called before entering the context manager. Queued messages
        are automatically sent once the WebSocket connection opens.
        Tr   N)	r   r   r   r   r  r   r;   r  r  r  s      rN   r  zAsyncLiveConnectionManager.send  R     %+ MMtSWMXOE3CDE 	
 	!!$'rQ   c                X     | j                   j                  |        S d fd}|S )zRegister an event handler before the connection is established.

        Handlers are transferred to the connection on enter. Supports the
        same method and decorator forms as ``AsyncLiveConnection.on``.
        c                @    j                   j                  |        | S rJ   r  rD  rE  s    rN   rG  z0AsyncLiveConnectionManager.on.<locals>.decorator      ))--j"=IrQ   rI  r  rK  s   ``  rN   rM  zAsyncLiveConnectionManager.on  3     ))--j'BK	 rQ   c                >    | j                   j                  ||       | S rP  )r  rR  rS  s      rN   rT  zAsyncLiveConnectionManager.off      %%,,ZArQ   c                \     |  j                   j                  |d        S d fd}|S )GRegister a one-time event handler before the connection is established.TrX  c                D    j                   j                  | d       | S r[  r  rE  s    rN   rG  z2AsyncLiveConnectionManager.once.<locals>.decorator  #    ))--j"4-HIrQ   rI  r  rK  s   ``  rN   rY  zAsyncLiveConnectionManager.once  8     ))--j'-MK	 rQ   c                  K   | j                  | j                  | j                         d{   }t        || j                  | j                   nd| j                  | j
                  | j                  | j                  | j                  | j                  | j                  	      | _	        | j                  j                  | j                  j                         | j                  j                          d{    | j                  S 7 7 w)ay  
        If your application doesn't work well with the context manager approach then you
        can call this method directly to initiate a connection.

        **Warning**: You must remember to close the connection with `.close()`.

        ```py
        connection = await client.live.connect(...).enter()
        # ...
        await connection.close()
        ```
        Nr   )_connect_wsrz  r{  r   r}  r~  r  r  r  ry  r  
merge_intor   r4  rM   wss     rN   
__aenter__z%AsyncLiveConnectionManager.__aenter__  s      ##D$6$68L8LMM/(,(>(>(JD$$PT 22**..&&**..((

 	%%001B1B1Z1Z[11333   # N 	4s"   *D	DCD	4D5D	D	c           
     Z  K   	 ddl m} | j	                         j                  i | j                  j                  j                  |      }|j                  dddj                  |j                  |j                              }| j                  j                  t        j                  d	t        |      t        |      d
di             d {   }| j                  j	                  |j                         j#                  | j                  j$                  j'                  t)        t*        |j                                    }|j                  dddj                  |j                  |j                              }| j                  j,                  i | j                  j.                  t1        |j2                        r|j2                  ni fD 	ci c]-  }|j5                         D ]  \  }}	|j7                         ||	f / }
}}}	t8        j;                  d       | j<                  rt8        j;                  d        |t        |      fd t?        t        |
jA                               i       d| j<                   d {   S # t        $ r}t        d      |d }~ww xY w7 c c}	}}w 7 +w)Nr   )_WebSocketConnect9You need to install `openai[realtime]` to use this methodparamsr  wsshttphttpsschemer   ri   Tmethodurlheadersrk   Connecting to WebSocket API,Custom WebSocket connection options provideduser_agent_headeradditional_headers)!lib._websocketr  ImportErrorr/   _prepare_url	copy_withrx  base_urlr  r   r  _prepare_optionsr(   	constructr   r   r  copy_merge_paramsqs	stringifyr   r   auth_headersdefault_headersr   r  itemslowerrG   r   r|  r2   valuesrM   r`   r_   r   r   r  rn   
header_setkeyr  r  s              rN   r  z&AsyncLiveConnectionManager._connect_ws  sd    	dF !++--((// , 
 mmD5#A#E#EcjjRUR\R\#]m^66))H]+'.	
 
 mm((5GGMM&&tC'@A
 mmD5#A#E#EcjjRUR\R\#]m^ **--#+GOO#<"		
 	
 )..0	
 U IIK#u%	
	
 	
 			/0..IIDEH
".tGNN4D/ErJ
 11	
 
 	
I  	dYZ`cc	d
	

sT   J+J CJ+JC?J+2J" A=J+=J)>J+	JJJJ+"J+c                   | j                   j                  *t        j                  | j                   j                        }nO| j                   j                  j
                  }|dk(  rdnd}| j                   j                  j                  |      }|j                  j                  d      dz   }|j                  |      S Nr  r  r  r     /s   /live/sessions)raw_path)	rx  websocket_base_urlhttpx2URL	_base_urlr  r  r  rstriprM   r  r  	ws_schememerge_raw_paths        rN   r  z'AsyncLiveConnectionManager._prepare_url(      ==++7zz$--"B"BCH]],,33F && 0eI}}..88	8JH!**11$7:KK!!>!::rQ   c                n   K   | j                   #| j                   j                          d {    y y 7 wrJ   )ry  r  rM   exc_typer   exc_tbs       rN   	__aexit__z$AsyncLiveConnectionManager.__aexit__3  s4      (##))+++ )+s   *535)rz   rD   r`   r   r_   r   r{   r>   r|   r   r}   r   r~   r   r   r   r   r   r   r   ri  rJ   )r   r   rL  rp  r   zUUnion[AsyncLiveConnectionManager, Callable[[Callable[..., Any]], Callable[..., Any]]])r   r   rL  rJ  r   r   )r   r   )r`   r   r_   r   r   r   r   z
httpx2.URLr  ztype[BaseException] | Noner   zBaseException | Noner  zTracebackType | Noner   r   )r   r   r   rq  r   r  rM  rT  rY  r  enterr  r  r  r   rQ   rN   r   r   y  s   4 _c"'M M 	M
 M 'AM \M M M M M 
M2( EI(A	^$ EI(A	^!@ E,
\	;,2,9M,Wk,	,rQ   r   c            	          e Zd ZU dZded<   ded<   ded<   ddd	d
di i dd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZd dZd!dZd"dZ	d#dZ
dddd$dZd%dZd&dZd'dZ	 d(	 	 	 	 	 d)dZd*dZ	 d(	 	 	 	 	 d)dZd'dZy)+LiveConnectionr   LiveSessionResourcerg   LiveResponseResourcer   WebSocketConnectionr   Nrt   ru   rv   r   c               &   || _         || _        || _        || _        d| _        || _        || _        || _        || _        d| _	        d| _
        |	xs
 t               | _        t        d      | _        t        |       | _        t#        |       | _        y )Nr   FTr   )r   r   r   r   r   r   r   r   r   r   r   r1   r   r4   r   r  rg   r  r   r   s
             rN   r   zLiveConnection.__init__B  s     & /'"#+#'+%*" %%4';T'J$*40,T2rQ   c              #     K   ddl m}m} 	 	 | j                          # |$ r Y y|$ rF}| j	                  |      s+| j
                  j                         }|rt        d|      | Y d}~Md}~ww xY wwr   r   r   s        rN   __iter__zLiveConnection.__iter__`  s     
 	Tiik!  & ( s+!--335F<N,2  ##  ,s4   
A4  A4A1A4A1<A,'A4,A11A4c                   | j                  | j                               }t        t        t        |      t
              rt        d|      j                  d      nt        |dd      }t        |t              r|r|dk7  rd| _	        |S )r   r   r   Nr   r   r   r   s      rN   r   zLiveConnection.recvv  sy       !23 $vu-t4 $e,008- 	 j#&:*:O&'D#rQ   c                   | j                   j                  d      }t        j                  dt	        |             | j
                  ra	 t        j                  |      }t        |t              rt        d|      j                  d      nd}t        |t              r|r|dk7  rd| _        |S # t        t        f$ r |cY S w xY w)	r   Fr   r   r   r   Nr   r   r   r   s       rN   r   zLiveConnection.recv_bytes  s     ""''u'5		8#g,G""%)ZZ%8
 OYYceiNj1:>BB6JptJ*c*zjG>S*+' / s   	B+ +B?>B?c                l   t        |t              r|j                  ddd      n"t        j                  t        |t                    }| j                  r| j                  j                  |       y 	 | j                  j                  |       y # t        $ r | j                  j                  |        w xY wr   )r   r   r   r   r  r   r;   r   r   r  r   r  r  r  s      rN   r  zLiveConnection.send  s     %+ MMtSWMXOE3CDE 	
   $$T*	!!$' 	$$T*	s   1B &B3c                    | j                   r?t        |t              r|n|j                  d      }| j                  j                  |       y | j                  j                  |       y r  r	  r
  s      rN   r  zLiveConnection.send_raw  sO      $T3/$T[[5IC$$S)d#rQ   r  r  r  c               L    d| _         | j                  j                  ||       y r  r  r  s      rN   r  zLiveConnection.close  s#    %)"D8rQ   c           
         t        t        t        t        j                  |      t        t
        t                          S r  r  r  s     rN   r   zLiveConnection.parse_event  r  rQ   c           	     Z   | j                   | j                  yddlm} d}t	        ||      r"|j
                  |j
                  j                  }t        |      syd| _        t        | j                  dz   | j                  dz         D ]q  }|| _
        t        | j                  d|dz
  z  z  | j                        }dt        j                         d	z  z   }||z  }t!        || j                  ||| j"                  | j$                  
      }	 | j                  |      }	|	|	j)                  d      r	d| _         y|	d|	v r
|	d   | _        d|	v r
|	d   | _        t*        j-                  d|| j                  |       t/        j0                  |       | j2                  r	d| _         y	 | j                  | j"                  | j$                        | _        t*        j-                  d       d| _        | j7                           y d| _        y# t&        $ r d| _        Y  yw xY w# t&        $ r Y w xY w)r  Fr   r   r!  Tr   r"  r#  r$  r%  r*  r`   r_   r+  r,  )r   r   r   r   r   r.  r  r:   r   r/  r   r   r0  r   r   r1  r8   r   r   r  r   rG   r2  timer3  r   r   r4  )
rM   r   r   r)  r&  r5  r6  r(  r   r7  s
             rN   r   zLiveConnection._reconnect  s(      (DMM,A?
c01chh6JJ#J/ $T44q8$:K:Ka:OP 2	G&-D#T00A'A+4FGYJFMMOd22F'E%!..% --"11E..u5
 !fjj&9(-%! F*(.}(=D%"f,*0*AD'HHQ!!	 JJu))(-%#'==1B1BDDWDW#X 78(-%&&(a2	h !&I  (-%@  s%   H$AHHH	H*)H*c                     	  j                   j                   fd       y# t        $ r t        j	                  d       Y yw xY w)r9  c                :    j                   j                  |       S rJ   r;  r<  s    rN   <lambda>z2LiveConnection._flush_send_queue.<locals>.<lambda>  s    T5E5E5J5J45P rQ   r>  N)r   
flush_syncr  rG   r@  rL   s   `rN   r4  z LiveConnection._flush_send_queue
  s<    	F''(PQ 	FKKDE	Fs   " AAc                X     | j                   j                  |        S d fd}|S )a'  Adds the handler to the end of the handlers list for the given event type.

        No checks are made to see if the handler has already been added. Multiple calls
        passing the same combination of event type and handler will result in the handler
        being added, and called, multiple times.

        Can be used as a method (returns ``self`` for chaining)::

            connection.on("session.started", my_handler)

        Or as a decorator::

            @connection.on("session.started")
            def my_handler(event): ...
        c                @    j                   j                  |        | S rJ   rC  rE  s    rN   rG  z$LiveConnection.on.<locals>.decorator'  rH  rQ   rI  rC  rK  s   ``  rN   rM  zLiveConnection.on  rN  rQ   c                >    | j                   j                  ||       | S rP  rQ  rS  s      rN   rT  zLiveConnection.off-  rU  rQ   c                \     |  j                   j                  |d        S d fd}|S )rW  TrX  c                D    j                   j                  | d       | S r[  rC  rE  s    rN   rG  z&LiveConnection.once.<locals>.decorator=  r\  rQ   rI  rC  rK  s   ``  rN   rY  zLiveConnection.once2  r]  rQ   c                    | D ]  }|j                   }| j                  j                  |      }| j                  j                  d      }|dk(  r"|s |st        |t              rt        d|       |D ]
  } ||        |D ]
  } ||         y)ay  Run the event loop, dispatching received events to registered handlers.

        Blocks the current thread until the connection is closed. This is the push-based
        alternative to iterating with ``for event in connection``.

        If an ``"error"`` event arrives and no handler is registered for
        ``"error"`` or ``"event"``, an ``OpenAIError`` is raised.
        r   r   r_  N)r   r   r`  r   r5   r/   )rM   r   r   rb  rc  rL  s         rN   rd  zLiveConnection.dispatch_eventsC  s      	EJ33@@LH22??HGW$XgeZ0%(9%&ABB#  # 	rQ   )r   r  r   z6Callable[[Query, Headers], WebSocketConnection] | Noner|   r   r}   r   r~   r   r   r   r`   r   r_   r   r   re  r   r   )r   zIterator[ServerEvent]rf  rg  ri  rj  rk  rl  rm  ro  rJ   )r   r   rL  rp  r   zIUnion[LiveConnection, Callable[[Callable[..., Any]], Callable[..., Any]]])r   r   rL  rJ  r   r  )r   r   r   rq  rr  r   r  r   r   r  r  r  r   r   r4  rM  rT  rY  rd  r   rQ   rN   r  r  :  s&   @  ""$$ KO^b"!#'+3'3 H	3
 \3 3 3 3 3 3 %3 
3<,$*$ $(r 9qIVF EI(A	R8 EI(A	R"rQ   r  c                      e Zd ZdZdddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZdd	Z	 d	 	 	 	 	 dd
ZddZ	 d	 	 	 	 	 ddZddZ	e	Z
ddZddZ	 	 	 	 	 	 	 	 ddZy)r   a  Context manager over a `LiveConnection` that is returned by `live.connect()`

    This context manager ensures that the connection will be closed when it exits.

    ---

    Note that if your application doesn't work well with the context manager approach then you
    can call the `.enter()` method directly to initiate a connection.

    **Warning**: You must remember to close the connection with `.close()`.

    ```py
    connection = client.live.connect(...).enter()
    # ...
    connection.close()
    ```
    Nrt   ru   rv   rw   rt  c       	            || _         d | _        || _        || _        || _        || _        || _        || _        || _        t        |	      | _
        t        d      | _        y )Nrv  Tr   )_LiveConnectionManager__client"_LiveConnectionManager__connection#_LiveConnectionManager__extra_query%_LiveConnectionManager__extra_headers4_LiveConnectionManager__websocket_connection_options'_LiveConnectionManager__on_reconnecting#_LiveConnectionManager__max_retries%_LiveConnectionManager__initial_delay!_LiveConnectionManager__max_delayr1   "_LiveConnectionManager__send_queuer4   ._LiveConnectionManager__event_handler_registryr  s
             rN   r   zLiveConnectionManager.__init__o  se     37(,.J+!0(,$%?(<d(K%rQ   c                    t        |t              r|j                  ddd      n"t        j                  t        |t                    }| j                  j                  |       yr  )	r   r   r   r   r  r   r;   r  r  r  s      rN   r  zLiveConnectionManager.send  r  rQ   c                X     | j                   j                  |        S d fd}|S )zRegister an event handler before the connection is established.

        Handlers are transferred to the connection on enter. Supports the
        same method and decorator forms as ``LiveConnection.on``.
        c                @    j                   j                  |        | S rJ   r  rD  rE  s    rN   rG  z+LiveConnectionManager.on.<locals>.decorator  r  rQ   rI  r  rK  s   ``  rN   rM  zLiveConnectionManager.on  r  rQ   c                >    | j                   j                  ||       | S rP  )r  rR  rS  s      rN   rT  zLiveConnectionManager.off  r  rQ   c                \     |  j                   j                  |d        S d fd}|S )r  TrX  c                D    j                   j                  | d       | S r[  r  rE  s    rN   rG  z-LiveConnectionManager.once.<locals>.decorator  r  rQ   rI  r  rK  s   ``  rN   rY  zLiveConnectionManager.once  r  rQ   c                   | j                  | j                  | j                        }t        || j                  | j                   nd| j                  | j
                  | j                  | j                  | j                  | j                  | j                  	      | _	        | j                  j                  | j                  j                         | j                  j                          | j                  S )am  
        If your application doesn't work well with the context manager approach then you
        can call this method directly to initiate a connection.

        **Warning**: You must remember to close the connection with `.close()`.

        ```py
        connection = client.live.connect(...).enter()
        # ...
        connection.close()
        ```
        Nr   )r  r  r  r  r  r  r  r  r  r  r  r  r   r4  r  s     rN   	__enter__zLiveConnectionManager.__enter__  s     d00$2F2FG*(,(>(>(JD$$PT 22**..&&**..((

 	%%001B1B1Z1Z[++-   rQ   c           
     (   	 ddl m} | j	                         j                  i | j                  j                  j                  |      }|j                  dddj                  |j                  |j                              }| j                  j                  t        j                  d	t        |      t        |      d
di            }| j                  j	                  |j                         j#                  | j                  j$                  j'                  t)        t*        |j                                    }|j                  dddj                  |j                  |j                              }| j                  j,                  i | j                  j.                  t1        |j2                        r|j2                  ni fD 	ci c]-  }|j5                         D ]  \  }}	|j7                         ||	f / }
}}}	t8        j;                  d       | j<                  rt8        j;                  d        |t        |      fd t?        t        |
jA                               i       d| j<                  S # t        $ r}t        d      |d }~ww xY wc c}	}}w )Nr   )r   r  r  r  r  r  r  r   ri   Tr  r  r  r  )!websockets.sync.clientr   r  r/   r  r  r  r  r  r   r  r  r(   r  r   r   r  r  r  r  r   r   r  r  r   r  r  r  rG   r   r  r2   r  r  s              rN   r  z!LiveConnectionManager._connect_ws  sK   	d6 !++--((// , 
 mmD5#A#E#EcjjRUR\R\#]m^--00))H]+'.	
 mm((5GGMM&&tC'@A
 mmD5#A#E#EcjjRUR\R\#]m^ **--#+GOO#<"		
 	
 )..0	
 U IIK#u%	
	
 	
 			/0..IIDEH
".tGNN4D/ErJ
 11	
 	
I  	dYZ`cc	d,	
s   I0 2J0	J
9JJ
c                   | j                   j                  *t        j                  | j                   j                        }nO| j                   j                  j
                  }|dk(  rdnd}| j                   j                  j                  |      }|j                  j                  d      dz   }|j                  |      S r  )	r  r  r  r  r  r  r  r  r  r  s        rN   r  z"LiveConnectionManager._prepare_url
  r  rQ   c                R    | j                   | j                   j                          y y rJ   )r  r  r  s       rN   __exit__zLiveConnectionManager.__exit__  s'     (##% )rQ   )rz   rC   r`   r   r_   r   r{   r>   r|   r   r}   r   r~   r   r   r   r   r   r   r   ri  rJ   )r   r   rL  rp  r   zPUnion[LiveConnectionManager, Callable[[Callable[..., Any]], Callable[..., Any]]])r   r   rL  rJ  r   r   )r   r  )r`   r   r_   r   r   r  r  r  )r   r   r   rq  r   r  rM  rT  rY  r  r  r  r  r  r   rQ   rN   r   r   \  s   2 _c"'L L 	L
 L 'AL \L L L L L 
L2( EI(A	Y$ EI(A	Y!@ E,
\	;&2&9M&Wk&	&rQ   r   c                      e Zd ZddZy)BaseLiveConnectionResourcec                    || _         y rJ   r   rM   r   s     rN   r   z#BaseLiveConnectionResource.__init__  
    %rQ   N)r   r  r   r   r   r   r   r   r   rQ   rN   r
  r
        &rQ   r
  c                  ~    e Zd Zed
d       Zedd       Zedd       Zedd       ZedddZ	edddZ
edddZy	)r  c                ,    t        | j                        S rJ   )LiveSessionCommentaryResourcer   rL   s    rN   
commentaryzLiveSessionResource.commentary"      ,T-=-=>>rQ   c                ,    t        | j                        S rJ   )LiveSessionInputAudioResourcer   rL   s    rN   input_audiozLiveSessionResource.input_audio&  r  rQ   c                ,    t        | j                        S rJ   )LiveSessionInstructionsResourcer   rL   s    rN   instructionsz LiveSessionResource.instructions*  s    .t/?/?@@rQ   c                ,    t        | j                        S rJ   )LiveSessionThinkingResourcer   rL   s    rN   thinkingzLiveSessionResource.thinking.  s    *4+;+;<<rQ   event_idc          
     n    | j                   j                  t        t        t	        d|d                   yzRequest that the Live session close.

        The terminal `session.closed` event contains the close reason and final usage.
        zsession.closer   r   Nr   r  r   r;   r   rM   r   s     rN   r  zLiveSessionResource.close2  s+    
 	d#3_oksEt5uvwrQ   c               p    | j                   j                  t        t        t	        d||d                   yzUpdate the delegation settings of an active Live session.

        The server acknowledges accepted changes with `session.updated`.
        zsession.updater   rg   r   Nr$  rM   rg   r   s      rN   updatezLiveSessionResource.update9  s4    
 	 /;KX_mu2v"w	
rQ   c               p    | j                   j                  t        t        t	        d||d                   yzStart a Live session on a primary WebSocket.

        Send this event before other commands and wait for `session.started`.
        zsession.startr(  Nr$  r)  s      rN   startzLiveSessionResource.startD  s1    
 	!?OX_mu3v#wx	
rQ   N)r   r  )r   r  )r   r  )r   r  r   Optional[str] | Omitr   r   rg   r@   r   r/  r   r   rg   r=   r   r/  r   r   r   r   r   r'   r  r  r  r  r   r  r*  r-  r   rQ   rN   r  r  !  su    ? ? ? ? A A = = 9= x ]a 	
 VZ 
rQ   r  c                      e Zd ZedddZy)r  r  c               r    | j                   j                  t        t        t	        d|||d                   yz{
        Provide context the Live model can communicate to the user, optionally for an existing client delegation.
        zsession.commentary.appendr   contentdelegation_idr   Nr$  rM   r7  r8  r   s       rN   appendz$LiveSessionCommentaryResource.appendO  s<     	  ;#*)6$,	
	
rQ   Nr7  r   r8  zOptional[str]r   r/  r   r   r   r   r   r   r:  r   rQ   rN   r  r  N  
    ei 
rQ   r  c                  6    e Zd ZedddZedddZedddZy)r  r  c               p    | j                   j                  t        t        t	        d||d                   yzSend audio to a Live session over its primary WebSocket.

        WebRTC and SIP sessions send audio over their media transport.
        zsession.input_audio.append)r   audior   Nr$  rM   rA  r   s      rN   r:  z$LiveSessionInputAudioResource.appendc  s5    
 	 )EPUck lm	
rQ   c          
     n    | j                   j                  t        t        t	        d|d                   yzMute audio input to the Live model without closing the session.

        The server acknowledges with `session.input_audio.muted`.
        zsession.input_audio.muter#  Nr$  r%  s     rN   mutez"LiveSessionInputAudioResource.muteo  s/    
 	!?<Vdl3m#no	
rQ   c          
     n    | j                   j                  t        t        t	        d|d                   yzResume audio input to a Live model after muting it.

        The server acknowledges with `session.input_audio.unmuted`.
        zsession.input_audio.unmuter#  Nr$  r%  s     rN   unmutez$LiveSessionInputAudioResource.unmutex  s/    
 	!?<Xfn3o#pq	
rQ   NrA  r   r   r/  r   r   r.  r   r   r   r   r:  rE  rH  r   rQ   rN   r  r  b  s    EI 

 8< 
 :> 
rQ   r  c                      e Zd ZedddZy)r  r  c               r    | j                   j                  t        t        t	        d|||d                   yz
        Append instructions to the Live conversation while it is running, optionally associating them with an existing client delegation.
        zsession.instructions.appendr6  Nr$  r9  s       rN   r:  z&LiveSessionInstructionsResource.append  s<     	  =#*)6$,	
	
rQ   Nr;  r<  r   rQ   rN   r  r    r=  rQ   r  c                      e Zd ZedddZy)r  r  c               r    | j                   j                  t        t        t	        d|||d                   yz
        Provide silent reasoning or progress context to the Live model, optionally for an existing client delegation.
        zsession.thinking.appendr6  Nr$  r9  s       rN   r:  z"LiveSessionThinkingResource.append  s<     	  9#*)6$,	
	
rQ   Nr;  r<  r   rQ   rN   r  r    r=  rQ   r  c                  ,    e Zd Zedd       ZedddZy)r  c                ,    t        | j                        S rJ   )LiveResponseItemResourcer   rL   s    rN   itemzLiveResponseResource.item  s    '(8(899rQ   r  c          
     n    | j                   j                  t        t        t	        d|d                   yu   
        Request a response from the Live session’s Responses backend, or continue a
        delegated response waiting for tool results.

        Requires Responses delegation.
        zresponse.creater#  Nr$  r%  s     rN   rs   zLiveResponseResource.create  s/     	!?<M[c3d#ef	
rQ   N)r   rS  r.  r   r   r   r'   rT  r   rs   r   rQ   rN   r  r    s    : : :> 	
rQ   r  c                      e Zd ZedddZy)rS  r  c               p    | j                   j                  t        t        t	        d||d                   yu   Add an input item to the Live session’s Responses backend.

        Requires Responses delegation; use `response.create` to request a response.
        zresponse.item.create)r   rT  r   Nr$  rM   rT  r   s      rN   rs   zLiveResponseItemResource.create  s4    
 	 /;Q[_mu2v"w	
rQ   NrT  rA   r   r/  r   r   r   r   r   r   rs   r   rQ   rN   rS  rS    s
    W[ 	
rQ   rS  c                      e Zd ZddZy)BaseAsyncLiveConnectionResourcec                    || _         y rJ   r  r  s     rN   r   z(BaseAsyncLiveConnectionResource.__init__  r  rQ   N)r   r   r   r   r  r   rQ   rN   r_  r_    r  rQ   r_  c                  ~    e Zd Zed
d       Zedd       Zedd       Zedd       ZedddZ	edddZ
edddZy	)r   c                ,    t        | j                        S rJ   )"AsyncLiveSessionCommentaryResourcer   rL   s    rN   r  z#AsyncLiveSessionResource.commentary      1$2B2BCCrQ   c                ,    t        | j                        S rJ   )"AsyncLiveSessionInputAudioResourcer   rL   s    rN   r  z$AsyncLiveSessionResource.input_audio  rd  rQ   c                ,    t        | j                        S rJ   )$AsyncLiveSessionInstructionsResourcer   rL   s    rN   r  z%AsyncLiveSessionResource.instructions  s    3D4D4DEErQ   c                ,    t        | j                        S rJ   ) AsyncLiveSessionThinkingResourcer   rL   s    rN   r  z!AsyncLiveSessionResource.thinking  s    /0@0@AArQ   r  c          
        K   | j                   j                  t        t        t	        d|d                   d{    y7 wr"  r$  r%  s     rN   r  zAsyncLiveSessionResource.close  s<     
 ##!?OYa3b#cd
 	
 	
   9AAAc                  K   | j                   j                  t        t        t	        d||d                   d{    y7 wr'  r$  r)  s      rN   r*  zAsyncLiveSessionResource.update  sB     
 ## /;KX_mu2v"w
 	
 	
   :AAAc                  K   | j                   j                  t        t        t	        d||d                   d{    y7 wr,  r$  r)  s      rN   r-  zAsyncLiveSessionResource.start  s?     
 ##!?OX_mu3v#wx
 	
 	
rn  N)r   rc  )r   rf  )r   rh  )r   rj  r.  r0  r1  r2  r   rQ   rN   r   r     s{    D D D D F F B B ?C 
 cg 	
 \` 
rQ   r   c                  (    e Zd Zed	 	 	 	 	 	 	 ddZy)rc  r  c                  K   | j                   j                  t        t        t	        d|||d                   d{    y7 wr5  r$  r9  s       rN   r:  z)AsyncLiveSessionCommentaryResource.append  sJ      ##  ;#*)6$,	

 	
 	
   ;AAANr;  r<  r   rQ   rN   rc  rc    *    ^b

.;
G[
	
rQ   rc  c                  6    e Zd ZedddZedddZedddZy)rf  r  c                  K   | j                   j                  t        t        t	        d||d                   d{    y7 wr@  r$  rB  s      rN   r:  z)AsyncLiveSessionInputAudioResource.append  sC     
 ## )EPUck lm
 	
 	
rn  c          
        K   | j                   j                  t        t        t	        d|d                   d{    y7 wrD  r$  r%  s     rN   rE  z'AsyncLiveSessionInputAudioResource.mute  s=     
 ##!?<Vdl3m#no
 	
 	
rl  c          
        K   | j                   j                  t        t        t	        d|d                   d{    y7 wrG  r$  r%  s     rN   rH  z)AsyncLiveSessionInputAudioResource.unmute(  s=     
 ##!?<Xfn3o#pq
 	
 	
rl  NrI  r.  rJ  r   rQ   rN   rf  rf    s!    KO 

 >B 
 @D 
rQ   rf  c                  (    e Zd Zed	 	 	 	 	 	 	 ddZy)rh  r  c                  K   | j                   j                  t        t        t	        d|||d                   d{    y7 wrM  r$  r9  s       rN   r:  z+AsyncLiveSessionInstructionsResource.append3  sJ      ##  =#*)6$,	

 	
 	
rr  Nr;  r<  r   rQ   rN   rh  rh  2  rs  rQ   rh  c                  (    e Zd Zed	 	 	 	 	 	 	 ddZy)rj  r  c                  K   | j                   j                  t        t        t	        d|||d                   d{    y7 wrP  r$  r9  s       rN   r:  z'AsyncLiveSessionThinkingResource.appendI  sJ      ##  9#*)6$,	

 	
 	
rr  Nr;  r<  r   rQ   rN   rj  rj  H  rs  rQ   rj  c                  ,    e Zd Zedd       ZedddZy)r   c                ,    t        | j                        S rJ   )AsyncLiveResponseItemResourcer   rL   s    rN   rT  zAsyncLiveResponseResource.item_  r  rQ   r  c          
        K   | j                   j                  t        t        t	        d|d                   d{    y7 wrV  r$  r%  s     rN   rs   z AsyncLiveResponseResource.createc  s=      ##!?<M[c3d#ef
 	
 	
rl  N)r   r~  r.  rW  r   rQ   rN   r   r   ^  s     ? ? @D 	
rQ   r   c                      e Zd ZedddZy)r~  r  c                  K   | j                   j                  t        t        t	        d||d                   d{    y7 wrZ  r$  r[  s      rN   rs   z$AsyncLiveResponseItemResource.createp  sB     
 ## /;Q[_mu2v"w
 	
 	
rn  Nr\  r]  r   rQ   rN   r~  r~  o  s
    ]a 	
rQ   r~  )
__future__r   r   r  r1  loggingtypesr   typingr   r   r   r   r	   r
   r   r   typing_extensionsr   r  pydanticr   r  r   rS   r   r   _typesr   r   r   r   r   r   r   _utilsr   r   r   r   rU   r   r    r!   r"   r#   r$   rO   r%   r&   _compatr'   _modelsr(   r)   	_resourcer*   r+   	_responser,   r-   
types.liver.   _exceptionsr/   r0   r   r1   _base_clientr2   r3   _event_handlerr4   types.live.error_eventr5   types.live.client_eventr6   types.live.server_eventr7   types.websocket_reconnectionr8   r9   r:   types.live.client_event_paramr;   types.live.live_create_responser<   types.live.session_config_paramr=   "types.websocket_connection_optionsr>   %types.live.media_session_config_paramr?   &types.live.session_update_config_paramr@   )types.responses.response_input_item_paramrA   r  rB   r  websockets.asyncio.clientr   rK   rC   rD   __all__	getLoggerr   rG   rr  rE   rF   rX   r   r\   r   r   r   r  r   r
  r  r  r  r  r  r  rS  r_  r   rc  rf  rh  rj  r   r~  r   rQ   rN   <module>r     s
   #      [ [ [ +     $ K K K W W  . & D : Y , F $ A 2 0 2 2 j j = A A L L N ONV.;
'g''1^ 1j
? j
Zj
  j
Z
< 
<
A 
A
B 
B
G 
Gk! k!\	~, ~,B_ _D	}& }&@& &
*
4 *
Z
$> 
(
$> 
@
&@ 
(
"< 
(
5 
"

9 

& &
,
> ,
^
)H 
,
)H 
@
+J 
,
'F 
,
 ? 
"

$C 

rQ   