+
    i0                       a  R tB0 t R t^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHtH	t	H
t
HtHtHt ^ RIt^ RIt^ RIt^ RIt^RIHt ^RIHt ^RIHt ^RIHt ^RIHt ^RIHt ^R	IHt ^R
IHt ^RIHt  ^RIH!t" ^RI#H$t$ ^RI%H&t& ]PN                  t' ^ RI(H)t) ^ RI(H*t+  ^ RI.H/t/ ]Pb                  '       d   ^ RI2H3t4 ^ RI5H6t7 ^RI8H9t9 ^RIH:t: M+]t4] ^ k ]t7] ^k ]t9] ^k  ^ RI2H3t4 ^ RI5H6t7 ^RI8H9t9 ^RIH:t: ]Pv                  ! R4      t<Rt= ! R R4      t> ! R R]P~                  4      t@R R ltAR#   ], d    ^ RI-H)t) ^ RI-H*t+  Li ; i  ]0 d    Rt/ Li ; i  ]0 d    Rt4Rt7Rt9Rt: Lti ; i)z[Preview] Live API client.N)AnyAsyncIteratorOptionalSequenceUnionget_args)_api_module)_common)_live_converters)
_mcp_utils)_transformers)errors)typesBaseApiClient)get_value_by_path)set_value_by_pathAsyncLiveMusic)_Content_to_mldev)ClientConnection)connect)requests)ClientSession)Tool)McpToGenAiToolAdapter)mcp_to_gemini_toolzgoogle_genai.liveznFunctionResponse request must have an `id` field from the response of a ToolCall.FunctionalCalls in Google AI.c                   *  a  ] tR t^Wt o RtR'V 3R lR lltRRRR/V 3R lR	 lltR
RRR/V 3R lR lltRRRRRRRRRRRRRR/V 3R lR lltV 3R lR lt	V 3R lR lt
V 3R lR ltV 3R lR ltV 3R  lR! ltR(V 3R" lR# lltV 3R$ lR% ltR&tV tR# ))AsyncSessionz[Preview] AsyncSession.Nc                <   < V ^8  d   QhRS[ RS[RS[S[,          /# )   
api_client	websocket
session_id)r   r   r   str)format__classdict__s   "d/Users/igloo/.openclaw/workspace/scratch/fb_ad_env/lib/python3.14/site-packages/google/genai/live.py__annotate__AsyncSession.__annotate__Z   s-     ! !! "! 3-	!    c                *    Wn         W n        W0n        R # N_api_client_wsr#   )selfr!   r"   r#   s   &&&&r'   __init__AsyncSession.__init__Z   s     "H Or*   inputend_of_turnFc                  < V ^8  d   QhRS[ S[S[P                  S[P                  S[P
                  S[P                  S[P                  S[P                  S[	S[P                  ,          3,          ,          RS[ S[
,          RR/# )r    r3   r4   returnN)r   r   r   ContentListUnionContentListUnionDictLiveClientContentOrDictLiveClientRealtimeInputOrDictLiveClientToolResponseOrDictFunctionResponseOrDictr   bool)r%   r&   s   "r'   r(   r)   d   s     14 14 
$$((++1100**u3346
14 D>14 14r*   c                  "   \         P                  ! R\        ^R7       V P                  W4      pV P                  P                  \        P                  ! V4      4      G Rj  xL
  R#  L5i)a  [Deprecated] Send input to the model.

> **Warning**: This method is deprecated and will be removed in a future
version (not before Q3 2025). Please use one of the more specific methods:
`send_client_content`, `send_realtime_input`, or `send_tool_response`
instead.

The method will send the input request to the server.

Args:
  input: The input request to the model.
  end_of_turn: Whether the input is the last message in a turn.

Example usage:

.. code-block:: python

  client = genai.Client(api_key=API_KEY)

  async with client.aio.live.connect(model='...') as session:
    await session.send(input='Hello world!', end_of_turn=True)
    async for message in session.receive():
      print(message)
zThe `session.send` method is deprecated and will be removed in a future version (not before Q3 2025).
Please use one of the more specific methods: `send_client_content`, `send_realtime_input`, or `send_tool_response` instead.
stacklevelN)warningswarnDeprecationWarning_parse_client_messager/   sendjsondumps)r0   r3   r4   client_messages   &$$ r'   rE   AsyncSession.sendd   sS     P MM	B 	 //CN
((--

>2
333s   A!A,#A*$A,turnsturn_completeTc          	         < V ^8  d   QhRS[ S[S[P                  S[P                  S[S[S[P                  S[P                  3,          ,          3,          ,          RS[RR/# )r    rJ   rK   r6   N)r   r   r   ContentContentDictlistr=   )r%   r&   s   "r'   r(   r)      ss     XM XM 
mm5(9(99:;=XM XM XMr*   c               j  "   \         P                  ! W4      P                  RRR7      pV P                  P                  '       d   \
        P                  ! VRR7      pM\        P                  ! VR7      pV P                  P                  \        P                  ! RV/4      4      G Rj  xL
  R#  L5i)a  Send non-realtime, turn based content to the model.

There are two ways to send messages to the live API:
`send_client_content` and `send_realtime_input`.

`send_client_content` messages are added to the model context **in order**.
Having a conversation using `send_client_content` messages is roughly
equivalent to using the `Chat.send_message_stream` method, except that the
state of the `chat` history is stored on the API server.

Because of `send_client_content`'s order guarantee, the model cannot
respond as quickly to `send_client_content` messages as to
`send_realtime_input` messages. This makes the biggest difference when
sending objects that have significant preprocessing time (typically images).

The `send_client_content` message sends a list of `Content` objects,
which has more options than the `media:Blob` sent by `send_realtime_input`.

The main use-cases for `send_client_content` over `send_realtime_input` are:

- Prefilling a conversation context (including sending anything that can't
  be represented as a realtime message), before starting a realtime
  conversation.
- Conducting a non-realtime conversation, similar to `client.chat`, using
  the live api.

Caution: Interleaving `send_client_content` and `send_realtime_input`
  in the same conversation is not recommended and can lead to unexpected
  results.

Args:
  turns: A `Content` object or list of `Content` objects (or equivalent
    dicts).
  turn_complete: if true (the default) the model will reply immediately. If
    false, the model will wait for you to send additional client_content,
    and will not return until you send `turn_complete=True`.

Example:

.. code-block:: python

  import google.genai
  from google.genai import types
  import os

  if os.environ.get('GOOGLE_GENAI_USE_VERTEXAI'):
    MODEL_NAME = 'gemini-2.0-flash-live-preview-04-09'
  else:
    MODEL_NAME = 'gemini-live-2.5-flash-preview';

  client = genai.Client()
  async with client.aio.live.connect(
      model=MODEL_NAME,
      config={"response_modalities": ["TEXT"]}
  ) as session:
    await session.send_client_content(
        turns=types.Content(
            role='user',
            parts=[types.Part(text="Hello world!")]))
    async for msg in session.receive():
      if msg.text:
        print(msg.text)
rF   Tmodeexclude_noneconvert_keysfrom_objectclient_contentN)tt_client_content
model_dumpr.   vertexair	   convert_to_dictlive_converters_LiveClientContent_to_mldevr/   rE   rF   rG   )r0   rJ   rK   rX   client_content_dicts   &$$  r'   send_client_content AsyncSession.send_client_content   s     V ''=HH$ I N    #33
t ,GG$ ((--

$46I#JK
LLLs   B(B3*B1+B3mediaaudioaudio_stream_endvideotextactivity_startactivity_endc                  < V ^8  d   QhRS[ S[P                  ,          RS[ S[P                  ,          RS[ S[,          RS[ S[P                  ,          RS[ S[,          RS[ S[P                  ,          RS[ S[P                  ,          RR	/# )
r    rc   rd   re   rf   rg   rh   ri   r6   N)r   r   BlobImageUnionDict
BlobOrDictr=   r$   ActivityStartOrDictActivityEndOrDict)r%   r&   s   "r'   r(   r)      s     gM gM e../gM e&&'	gM
 !gM e../gM SMgM u889gM U445gM gMr*   c          	       "   / pVe   WR&   Ve   W(R&   Ve   W8R&   Ve   WHR&   Ve   WXR&   Ve   WhR&   Ve   WxR&   \        V4      ^8w  d2   \        R	\        V4       R
\        VP                  4       4       24      h\        P
                  P                  V4      p	V P                  P                  '       d   \        P                  ! V	R7      p
M\        P                  ! V	R7      p
\        P                  ! V
4      p
\        P                  ! V
4      p
V P                  P!                  \"        P$                  ! RV
/4      4      G Rj  xL
  R#  L5i)a*  Send realtime input to the model, only send one argument per call.

Use `send_realtime_input` for realtime audio chunks and video
frames(images).

With `send_realtime_input` the api will respond to audio automatically
based on voice activity detection (VAD).

`send_realtime_input` is optimized for responsivness at the expense of
deterministic ordering. Audio and video tokens are added to the
context when they become available.

Args:
  media: A `Blob`-like object, the realtime media to send.

Example:

.. code-block:: python

  from pathlib import Path

  from google import genai
  from google.genai import types

  import PIL.Image

  import os

  if os.environ.get('GOOGLE_GENAI_USE_VERTEXAI'):
    MODEL_NAME = 'gemini-2.0-flash-live-preview-04-09'
  else:
    MODEL_NAME = 'gemini-live-2.5-flash-preview';


  client = genai.Client()

  async with client.aio.live.connect(
      model=MODEL_NAME,
      config={"response_modalities": ["TEXT"]},
  ) as session:
    await session.send_realtime_input(
        media=PIL.Image.open('image.jpg'))

    audio_bytes = Path('audio.pcm').read_bytes()
    await session.send_realtime_input(
        media=types.Blob(data=audio_bytes, mime_type='audio/pcm;rate=16000'))

    async for msg in session.receive():
      if msg.text is not None:
        print(f'{msg.text}')
Nrc   rd   re   rf   rg   rh   ri   z"Only one argument can be set, got z: rV   realtime_input)len
ValueErrorrO   keysr   LiveSendRealtimeInputParametersmodel_validater.   r\   r^   *_LiveSendRealtimeInputParameters_to_vertex)_LiveSendRealtimeInputParameters_to_mldevr	   r]   encode_unserializable_typesr/   rE   rF   rG   )r0   rc   rd   re   rf   rg   rh   ri   kwargsrp   realtime_input_dicts   &$$$$$$$   r'   send_realtime_input AsyncSession.send_realtime_input   sY    | "$FWoWo##3 WoVn!!/+^
6{a.s6{m <6;;=!"$  ::IIN    

D
D(  
C
C( 
 "112EF!== ((--

$46I#JK
LLLs   B6E9BEE	Ec                r   < V ^8  d   QhRS[ S[P                  S[S[P                  ,          3,          RR/# )r    function_responsesr6   N)r   r   r<   r   )r%   r&   s   "r'   r(   r)   Z  sJ     SK SK  

&
&
5//
02SK SKr*   c                 "   \         P                  ! V4      pV P                  P                  '       d   \        P
                  ! VRR7      pMS\        P
                  ! VRR7      pVP                  R. 4       F%  pVP                  R4      e   K  \        \        4      h	  V P                  P                  \        P                  ! RV/4      4      G Rj  xL
  R#  L5i)a  Send a tool response to the session.

Use `send_tool_response` to reply to `LiveServerToolCall` messages
from the server.

To set the available tools, use the `config.tools` argument
when you connect to the session (`client.live.connect`).

Args:
  function_responses: A `FunctionResponse`-like object or list of
    `FunctionResponse`-like objects.

Example:

.. code-block:: python

  from google import genai
  from google.genai import types

  import os

  if os.environ.get('GOOGLE_GENAI_USE_VERTEXAI'):
    MODEL_NAME = 'gemini-2.0-flash-live-preview-04-09'
  else:
    MODEL_NAME = 'gemini-live-2.5-flash-preview';

  client = genai.Client()

  tools = [{'function_declarations': [{'name': 'turn_on_the_lights'}]}]
  config = {
      "tools": tools,
      "response_modalities": ['TEXT']
  }

  async with client.aio.live.connect(
      model='models/gemini-live-2.5-flash-preview',
      config=config
  ) as session:
    prompt = "Turn on the lights please"
    await session.send_client_content(
        turns={"parts": [{'text': prompt}]}
    )

    async for chunk in session.receive():
        if chunk.server_content:
          if chunk.text is not None:
            print(chunk.text)
        elif chunk.tool_call:
          print(chunk.tool_call)
          print('_'*80)
          function_response=types.FunctionResponse(
                  name='turn_on_the_lights',
                  response={'result': 'ok'},
                  id=chunk.tool_call.function_calls[0].id,
              )
          print(function_response)
          await session.send_tool_response(
              function_responses=function_response
          )

          print('_'*80)
TrT   functionResponsesidNtool_response)rY   t_tool_responser.   r\   r	   r]   getrr   _FUNCTION_RESPONSE_REQUIRES_IDr/   rE   rF   rG   )r0   r~   r   tool_response_dictresponses   &$   r'   send_tool_responseAsyncSession.send_tool_responseZ  s     L %%&89M   "22
d #22
d ),,-@"E(<<%9:
: F ((--

O5G#HI
JJJs   B	CACCCc                D   < V ^8  d   QhRS[ S[P                  ,          /# r    r6   )r   r   LiveServerMessage)r%   r&   s   "r'   r(   r)     s      ]5+B+BC r*   c                  "   V P                  4       G Rj  xL
 ;p'       d=   VP                  '       d$   VP                  P                  '       d   V5x  R# V5x  K\  R#  LJ5i)aV  Receive model responses from the server.

The method will yield the model responses from the server. The returned
responses will represent a complete model turn. When the returned message
is function call, user must call `send` with the function response to
continue the turn.

Yields:
  The model responses from the server.

Example usage:

.. code-block:: python

  client = genai.Client(api_key=API_KEY)

  async with client.aio.live.connect(model='...') as session:
    await session.send(input='Hello world!', end_of_turn=True)
    async for message in session.receive():
      print(message)
N)_receiveserver_contentrK   )r0   results   & r'   receiveAsyncSession.receive  sM     . --/)
)&
)				6#8#8#F#F#Fl	 *)s   A#A!A#A#A#A#c                `   < V ^8  d   QhRS[ S[,          RS[RS[ S[P                  ,          /# )r    stream	mime_typer6   )r   bytesr$   r   r   )r%   r&   s   "r'   r(   r)     s:     F F$U+F8;FU,,-Fr*   c              L  "   \         P                  ! R\        ^R7       \        P                  ! 4       p\        P
                  ! V P                  WV4      4       RpVP                  4       '       g    \        P
                  ! V P                  4       4      p\        P                  ! V\        P
                  ! VP                  4       4      .\        P                  R7      G Rj  xL
  VP                  4       '       d4   VP                  4       5x  \        P                  ! R4      G Rj  xL
  K  K  Ve6   VP                  4       '       g   VP                  4         VG Rj  xL
  R# R# R#  L LE  \         d     KM  i ; i L   \        P                    d     R# i ; i5i)av  [Deprecated] Start a live session from a data stream.

> **Warning**: This method is deprecated and will be removed in a future
version (not before Q2 2025). Please use one of the more specific methods:
`send_client_content`, `send_realtime_input`, or `send_tool_response`
instead.

The interaction terminates when the input stream is complete.
This method will start two async tasks. One task will be used to send the
input stream to the model and the other task will be used to receive the
responses from the model.

Args:
  stream: An iterator that yields the model response.
  mime_type: The MIME type of the data in the stream.

Yields:
  The audio bytes received from the model and server response messages.

Example usage:

.. code-block:: python

  client = genai.Client(api_key=API_KEY)
  config = {'response_modalities': ['AUDIO']}
  async def audio_stream():
    stream = read_audio()
    for data in stream:
      yield data
  async with client.aio.live.connect(model='...', config=config) as session:
    for audio in session.start_stream(stream = audio_stream(),
    mime_type = 'audio/pcm'):
      play_audio_chunk(audio.data)
zSetting `AsyncSession.start_stream` is deprecated, and will be removed in a future release (not before Q3 2025). Please use the `receive`, and `send_realtime_input`, methods instead.r?   N)return_when-q=)rA   rB   rC   asyncioEventcreate_task
_send_loopis_setr   waitFIRST_COMPLETEDdoner   sleepConnectionClosedcancelCancelledError)r0   r   r   
stop_event	recv_tasks   &$$  r'   start_streamAsyncSession.start_stream  sV    J MM	P 	 J:FGI!!''8	ll##JOO$56  //
 	
 	
 >>  "
"g&
&
&  Y^^%5%5	 &6	
 '  	## s   A0F$4A1E4 %E0&E4  ,E4 ,E2-E4 1F$F$ F %F&F *F$0E4 2E4 4F?F$FF$F F!F$ F!!F$c                4   < V ^8  d   QhRS[ P                  /# r   )r   r   )r%   r&   s   "r'   r(   r)     s        e55  r*   c                @  "   \         P                  ! 4       p V P                  P                  R R7      G Rj  xL
 pX'       d    \         P"                  ! V4      pM/ pV P*                  P,                  '       d   \.        P0                  ! V4      pM\.        P2                  ! V4      pV'       g9   V'       d1   \        P                  P                  VP                  R4      VR4       \         P                  P5                  WqP7                  4       R7      #  L  \         d(    T P                  P                  4       G Rj  xL 
 p EL\
         d   pTP                  '       d.   TP                  P                  pTP                  P                  pM,Rp\        P                  P                  P                  TR4      p\        P                  P                  YER4        Rp?ELRp?ii ; i  \         P$                  P&                   d    \)        RT: 24      hi ; i5i)FdecodeN  Abnormal closure.Failed to parse response: coder   ry   )r   r   r/   recv	TypeErrorr   rcvdr   reason
websocketsframesCLOSE_CODE_EXPLANATIONSr   r   APIErrorraise_errorrF   loadsdecoderJSONDecodeErrorrr   r.   r\   r^   _LiveServerMessage_from_vertex_LiveServerMessage_from_mldev_from_responser[   )r0   parameter_modelraw_responseer   r   r   response_dicts   &       r'   r   AsyncSession._receive  s    --/O688===66l H::l+ h   %DDXNm%CCHMmXoo!!(,,v"6$G""11'A'A'C 2  7 7 +88==?**l 6	
vv{{""::>>tEXYoo!!$556 \\)) H5l5EFGGHs   HD DD HG, H;4H0H8AHD (G) EG)H	G)G)BG$H$G))H,/HHc                T   < V ^8  d   QhRS[ S[,          RS[RS[P                  RR/# )r    data_streamr   r   r6   N)r   r   r$   r   r   )r%   r&   s   "r'   r(   r)   6  s<       '  --	
 r*   c                "  "   V  R j  xL
  p\         P                  ! \         P                  ! WBR7      .R7      pV P                  VR7      G R j  xL
  \        P
                  ! R4      G R j  xL
  Kq   Ll L& L
DqTP                  4        R # 5i)Ndatar   media_chunks)r3   r   )r   LiveClientRealtimeInputBlobrE   r   r   set)r0   r   r   r   r   model_inputs   &&&&  r'   r   AsyncSession._send_loop6  s{      " # #d11

BCk IIKI(((MM'"""# )" " NNsJ   BA<A6A<ABA8B/A:0B6A<8B:B<Bc                &  < V ^8  d   QhRS[ S[S[P                  S[P                  S[P
                  S[P                  S[P                  S[P                  S[	S[P                  ,          3,          ,          RS[ S[
,          RS[P                  /# )r    r3   r4   r6   )r   r   r   r7   r8   r9   r:   r;   r<   r   r=   LiveClientMessageDict)r%   r&   s   "r'   r(   r)   F  s     l l
$$((++1100**u3346
l D>l ""lr*   c           
        TpV'       g   \         P                  ! R 4       RRR//# \        V\        4      '       d   V.pEM\        V\        4      '       dt   RV9   dm    \
        P                  ! R#/ VB p\        T\
        P                  4      '       d5   \        TP                  \        4      '       d   TP                  RRR	7      .pM}\        V\
        P                  4      '       d   V.pMY\        V\        4      '       dD   R
V9   d=   RV9   d6   V P                  P                  '       g   RV9  d   \        \         4      hV.p\        V\"        4      '       Edb   \$        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       Ed'   . pV F  p\        V\        4      '       g   K   \
        P&                  ! R#/ VB pTP(                  f,   T P                  P                  '       g   \        \         4      hTP                  RRR7      p\
        P*                  ! TP-                  R
4      TP-                  R4      R7      p	TP-                  R4      '       d   TP-                  R4      T	R&   TP/                  T	4       K  	  \
        P0                  ! \
        P2                  ! VR7      R7      p
V
# \        V\"        4      '       Ed   \$        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       Edi   / p. pV F?  p\        V\5        \
        P6                  4      4      '       g   K.  VP/                  V4       KA  	  V P                  P                  '       d=   \8        P:                  ! V4       Uu. uF  p\<        P>                  ! VRR7      NK  	  ppM.\8        P:                  ! V4       Uu. uF  p\A        Wk4      NK  	  pp. pV Fc  p \
        PB                  ! R#/ VB pTP/                  \
        PD                  ! TP                  RRR7      R,          TPF                  R7      4       Ke  	  \
        P0                  ! \
        PH                  ! WR7      R7      p
V
# \        V\"        4      '       d   \$        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d   Mx\$        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d$   V Uu. uF  pVP                  RRR7      NK  	  ppM\        R\        V4       RV R24      h\
        P0                  ! \
        PJ                  ! VR7      R7      p
V
# \        V\        4      '       EdJ   RV9   g   RV9   dY   RV9   d   VR,          pM	VR,          p\
        P0                  ! \
        PH                  ! VVP-                  R4      R7      R7      p
V
# RV9   d^    \
        PL                  ! R#/ VB p\
        P0                  ! \
        PJ                  ! TP                  RRR7      R,          R7      R7      p
T
# R V9   d^    \
        PN                  ! R#/ VB p\
        P0                  ! \
        P2                  ! TP                  RRR7      R ,          R7      R7      p
T
# \        R\        V4       RV R24      h\        V\
        PL                  4      '       Ed   VP                  RRR7      p\
        P0                  ! \
        PJ                  ! VP-                  R4      R7      R7      p
V
R!,          Ee=   V
R!,          R,          Ee*   \        V
R!,          R,          ^ ,          R,          \        4      '       d   . pV
R!,          R,           F  p\        V\        4      '       g   K   \
        P                  ! R#/ VB p\        T\
        P                  4      '       g   KT  \        TP                  \        4      '       g   Kv  TP                  f   K  TP/                  \
        PP                  ! \R        PT                  ! TP                  4      TPV                  R"7      4       K  	  VV
R!,          R&   V
# \        V\
        PX                  4      '       da   VP                  RRR7      p\
        P0                  ! \
        PH                  ! VP-                  R4      VP-                  R4      R7      R7      p
V
# \        V\
        PN                  4      '       d   V P                  P                  '       gA   VPZ                  e3   VPZ                  ^ ,          P(                  '       g   \        \         4      h\
        P0                  ! \
        P2                  ! VP                  RRR7      P-                  R 4      R7      R7      p
V
# \        V\
        P&                  4      '       d   V P                  P                  '       g"   VP(                  '       g   \        \         4      hVP                  RRR7      p\
        P*                  ! VP-                  R
4      VP-                  R4      R7      p	VP-                  R4      '       d   VP-                  R4      V	R&   \
        P0                  ! \
        P2                  ! V	.R7      R7      p
V
# \        V\"        4      '       Ed+   \        V^ ,          \
        P&                  4      '       Ed   V P                  P                  '       g)   V^ ,          P(                  '       g   \        \         4      h. pV F  pVP                  RRR7      p\
        P*                  ! VP-                  R
4      VP-                  R4      R7      p	VP-                  R4      '       d   VP-                  R4      V	R&   VP/                  V	4       K  	  \
        P0                  ! \
        P2                  ! VR7      R7      p
V
# \        R\        V4       RV R24      h  \        P                   d    \        R\        T4       RT R24      hi ; i  \        P                   d    \        R\        T4       RT R24      hi ; iu upi u upi   \        P                   d    \        R\        T4       RT R24      hi ; iu upi   \        P                   d    \        R\        T4       RT R24      hi ; i  \        P                   d    \        R\        T4       RT R24      hi ; i  \        P                   d    \        R\        T4       RT R24      hi ; i)$z0No input provided. Assume it is the end of turn.rX   rK   Tr   zUnsupported input type "z" or input content ""rF   rQ   namer   r   c              3   v   "   T F/  p\        V\        4      ;'       d    R V9   ;'       d    RV9   x  K1  	  R# 5i)r   r   N
isinstancedict.0cs   & r'   	<genexpr>5AsyncSession._parse_client_message.<locals>.<genexpr>r  s9      5 A 	1d??!??
a? s   999F)rS   rR   )r   r   )r~   )r   c              3   B   "   T F  p\        V\        4      x  K  	  R # 5ir,   )r   r$   r   s   & r'   r   r     s      7$3q
1cOs   rT   parts)r   role)rJ   rK   )rX   c              3   \   "   T F"  p\        V\        4      ;'       d    R V9   x  K$  	  R# 5i)r   Nr   r   bs   & r'   r   r     s&     LOqjD!11fk1Os   ,,c              3   V   "   T F  p\        V\        P                  4      x  K!  	  R # 5ir,   )r   r   r   r   s   & r'   r   r     s     B/Qz!UZZ((/s   ')r   )rp   contentrJ   r   r~   rp   r    ).logginginfor   r$   r   r   r   pydanticValidationErrorrr   typer   r   r[   r.   r\   r   r   anyFunctionResponser   FunctionResponseDictr   appendr   LiveClientToolResponseDictr   	PartUnionrY   
t_contentsr	   r]   r   rM   rN   r   LiveClientContentDictLiveClientRealtimeInputDictr   LiveClientToolResponseBlobDictbase64	b64decoder   LiveClientContentr~   )r0   r3   r4   formatted_input
blob_inputfunction_responses_inputitemfunction_response_inputfunction_response_dictfunction_response_typeddictrH   	to_objectcontent_input_partscontentscontent_dict_listcontent_inputr   content_turnsrp   tool_response_inputrz   formatted_media_chunksr`   function_response_lists   &&&                     r'   rD   "AsyncSession._parse_client_messageF  sZ     !OllEF$ 788%o	E4	 	 Vu_
ZZ(%(

 
J

	+	+

//51 1 !!vD!A
 
E5::	&	&o	E4	 	 Vu_u9L'''T->788o/8,, 5 5 5 5 2 2
 "$!$dD!!&+&<&<&Dt&D# &((0&&///;<<%<%G%G! &H &" +0*D*D+//7/33J?+' &))$//2H2L2L3)$/ %++,GH5 "6 2288!9n~ u 
OX	.	.33 7$37333 7$37 4 4 ')i35!$dHU__566

$
$T
* " 
			"	"	" %89
9 ##Dt<9 	 
 %89
9 d.9 	 

 46$	--/$/- 	  #..Dv.N #''		
 " 2244%nj a 
OX	.	.	LOLLOL	L	L3B/B333B/BBB %
$ LLdL8$ 	 

 &tE{m3GwaP
 	
 22::*nF { 
OT	*	*	o	%O)Co%)'2-))4-44 66#-11/B
l a _,	 88K?K. 44 <<+66!%F 7  "
P C  ?2	 % < < O O
 44::#6#A#A!%F $B $&$(
r c &tE{m3GwaP
 	
 
OU%B%B	C	C+66& 7  22::.22>Bn )
*
6-.~>J-.~>qA&I5  8:"#34^DDDd## ::--j :uzz22z66OO/$++..!++JOO< * 4 4 E. # 	'(	
P I 
OU%<%<	=	=+66& 7  2244'++G4/33ODn@ u 
OU%A%A	B	B (((00<"55a8;;;7882288!0!;!;#& "< "()nd W 
OU%;%;	<	<'''/2D2D2D788.99&  :   %*$>$>%))&1)--j9%! 
 	#	#D	)	),B,F,Ft,L#D)2288"=!>n> 5 
OX	.	.:E224 4 '''/!2D2G2G2G788AC!$!%d!P&+&@&@'++F3+//
;'
# "%%d++.D.H.H.N
%d
+%%&AB " 2288!7n 	 $T%[M1EeWA
N ] %% 
&tE{m3GwaP
 	

8 )) *4;- 8G1 J


 '' 	(e 6' 	.
> '' 	(e 6' 	 '' 	(e 6' 	J ++ ,T%[M :gQ  sZ    p0 :q$!rr)r"	s6s t ?u01q!$1r"1s1t1u 1u4c                   < V ^8  d   QhRR/# )r    r6   Nr   )r%   r&   s   "r'   r(   r)   t  s      4 r*   c                V   "   V P                   P                  4       G R j  xL
  R #  L5ir,   )r/   closer0   s   &r'   r  AsyncSession.closet  s     
((..
s   )')r-   r,   )NF)__name__
__module____qualname____firstlineno____doc__r1   rE   ra   r{   r   r   r   r   r   rD   r  __static_attributes____classdictcell__)r&   s   @r'   r   r   W   s    ! !14 14 %*14 14fXM XM !XM XMtgM 37gM +/	gM
 *.gM 37gM !gM =AgM 9=gM gMRSK SKj :F FP   D  l l\	 r*   r   c                      a a ] tR tRt oRtV3R lV 3R llt]V3R lR l4       t]P                  RR/V3R	 lR
 ll4       t
RtVtV ;t# )	AsyncLiveiy  z[Preview] AsyncLive.c                    < V ^8  d   QhRS[ /# )r    r!   r   )r%   r&   s   "r'   r(   AsyncLive.__annotate__|  s     - - -r*   c                F   < \         SV `  V4       \        V4      V n        R # r,   )superr1   r   _music)r0   r!   	__class__s   &&r'   r1   AsyncLive.__init__|  s    	GZ  ,DKr*   c                    < V ^8  d   QhRS[ /# r   r   )r%   r&   s   "r'   r(   r    s      ^ r*   c                    V P                   # r,   r   r  s   &r'   musicAsyncLive.music  s    ;;r*   configNc                `   < V ^8  d   QhRS[ RS[S[P                  ,          RS[S[,          /# )r    modelr(  r6   )r$   r   r   LiveConnectConfigOrDictr   r   )r%   r&   s   "r'   r(   r    s@     o o o u445	o
 \"or*   c          
      "   \        V\        4      '       d   \        P                  ! R)/ VB pV'       d   VP                  '       d   \        R4      hV P                  P                  4       p\        V\        4      '       d   VP                  R4      p\        P                  ! V P                  V4      p\        V P                  V4      G Rj  xL
 pV P                  P                  '       Ed   V P                  P                  '       Eg   V P                  P                  P                   pV P                  P                  pRpV P                  P                  P"                  p	V	e   V	P%                  4       M/ p
VP'                  R4      '       d^   \(        P*                  ! R\,        P.                  R7       RpR	V 2V
R
&   VR8w  d'   \(        P*                  ! R\,        P.                  R7       V RV RV 2p\0        P2                  ! \4        P6                  ! V P                  \        P8                  ! VVR7      P;                  RR7      R7      4      pVR \0        P<                  ! V4      p\?        VRR.V4       \@        PB                  ! V4      pEM>V P                  P                  '       Ed.   V P                  P                  '       Ed   V P                  P                  pV P                  P                  P                   pV RV R2pV P                  P                  P"                  p	V	e   V	P%                  4       M/ p
\0        P2                  ! \4        PD                  ! V P                  \        P8                  ! VVR7      P;                  RR7      R7      4      pVR \0        P<                  ! V4      p\?        VRR.V4       \@        PB                  ! V4      pEMV P                  P                  P                   pV P                  PF                  ;'       d    V P                  PH                  pV P                  PJ                  '       dY   V'       gQ   V P                  PJ                  pTpV P                  P                  P"                  p	V	e   V	P%                  4       M/ p
EMV RV R2pV P                  PL                  '       g&   \N        PP                  PS                  R.R7      w  ppMV P                  PL                  pVPT                  '       d   VPV                  '       g:   \X        f   \        R4      h\X        PZ                  ! 4       pVP]                  V4       VPT                  pV P                  P                  P"                  p	V	e   V	P%                  4       M/ p
V
P_                  R
4      '       g	   RV 2V
R
&   V P                  PH                  pV P                  PF                  pVP'                  R4      '       d!   V'       d   V'       d   RV RV R2V,           p\0        P2                  ! \4        PD                  ! V P                  \        P8                  ! VVR7      P;                  RR7      R7      4      pVR \0        P<                  ! V4      p\a        V. R*O4       f   \?        V. R*OR .4       \@        PB                  ! V4      pVPb                  '       dC   \d        Pf                  ! VPb                  4      '       d   V
f   / p
\d        Ph                  ! V
4       \k        V3R!V
/V P                  Pl                  B ;_uu_4       GRj  xL
 pVPo                  V4      G Rj  xL
   VPq                  R"R#7      G Rj  xL
 pX'       d    \@        P                  ! V4      pM/ pV P                  P                  '       d   \4        P                  ! V4      pMTp\        P                  P                  VVP;                  4       R'7      pVP                  '       d   VP                  P                  pMRp\        V P                  VVR(7      5x  RRR4      GRj  xL
  R#  EL EL EL L  \r         d    TPq                  4       G Rj  xL 
 p EL\t         dp   pTPv                  '       d.   TPv                  Px                  pTPv                  Pz                  pMR$pR%p\,        P|                  P                  TTR4        Rp?ELRp?ii ; i  \@        P                  P                   d    \        R&T: 24      hi ; i L  + GRj  xL 
 '       g   i     R# ; i5i)+a  [Preview] Connect to the live server.

Note: the live API is currently in preview.

Usage:

.. code-block:: python

  client = genai.Client(api_key=API_KEY)
  config = {}
  async with client.aio.live.connect(model='...', config=config) as session:
    await session.send_client_content(
      turns=types.Content(
        role='user',
        parts=[types.Part(text='hello!')]
      ),
      turn_complete=True
    )
    async for message in session.receive():
      print(message)

Args:
  model: The model to use for the live session.
  config: The configuration for the live session.
  **kwargs: additional keyword arguments.

Yields:
  An AsyncSession object.
zgoogle.genai.client.aio.live.connect() does not support http_options at request-level in LiveConnectConfig yet. Please use the client-level http_options configuration instead.zutf-8NBidiGenerateContentzauth_tokens/zUThe SDK's ephemeral token support is experimental, and may change in future versions.)messagecategoryBidiGenerateContentConstrainedzToken Authorizationv1alphazThe SDK's ephemeral token support is in v1alpha only.Please use client = genai.Client(api_key=token.name, http_options=types.HttpOptions(api_version="v1alpha")) before session connection.z!/ws/google.ai.generativelanguage.z.GenerativeService.)r*  r(  T)rS   )r!   rW   r(  setupr*  z/ws/google.cloud.aiplatform.z#.LlmBidiService/BidiGenerateContentz.https://www.googleapis.com/auth/cloud-platform)scopesz{The requests module is required to refresh google-auth credentials. Please install with `pip install google-auth[requests]`zBearer zpublishers/z	projects/z/locations//AUDIOadditional_headersFr   r   r   r   r   )r!   r"   r#   r   )r3  generationConfigresponseModalities)Ir   r   r   LiveConnectConfighttp_optionsrr   r.   _websocket_base_urlr   r   rY   t_model_t_live_connect_configapi_keyr\   _http_optionsapi_versionheaderscopy
startswithrA   rB   r   ExperimentalWarningr	   r]   r^   _LiveConnectParameters_to_mldevLiveConnectParametersr[   rx   setvrF   rG    _LiveConnectParameters_to_vertexprojectlocationcustom_base_url_credentialsgoogleauthdefaulttokenvalidr   Requestrefreshr   getvtoolsr   has_mcp_tool_usageset_mcp_usage_header
ws_connect_websocket_ssl_ctxrE   r   r   r   r   r   r   r   r   r   r   r   r   r   r   setup_completer#   r   )r0   r*  r(  base_urltransformed_modelr   versionr?  methodoriginal_headersrB  urirequest_dictrequesthas_sufficient_authcreds_auth_reqbearer_tokenrK  rJ  wsr   r   r   r   r   r   setup_responser#   s   &$$                           r'   r   AsyncLive.connect  s    J &$&&00f&%%%B  335H(E"")h		$"2"2E:243C3CVLLO(8(8(A(A(A  ..::g  ((g$f))77??+;+G %%'Rg			N	+	+. //	
 2%+G9#5 i
--0
 11 j9'BUV\U]^c,,

9
9))55)( 

-l x
 88Fl
<'7+->?

<(g				!	!	!d&6&6&?&?&?  ((g  ..::gj4WI=`ac))77??+;+G %%'Rg,,

:
:))55)( 

-l x
 88Fl
<'7+->?

<(g  ..::g



"
"
@
@t'7'7'@'@  
			)	)	)2E ..!++99AA'7'C!!# 	
 
6wi?bc,,,[[((FG ) (% ""//%   [  \  \%%'(
--
!{{++99AA'7'C!!# 	 {{?++'.|n%='/
"!!**h  ((g		%	%m	4	4XyH:Q7:KK 	 ,,

:
:))55)( 

-l x
 88Fl
O 
 	?I	
 

<(g!>!>" " 
%%g. '+/+;+;+N+N  	GGG8WWEW22 
	JZZ-( 				"	"	"'FFxP ..== )C)C)E > n 
	&	&	&#22==

%% K  i Mh  3 'WWY 8666$66==&$&&##D&$778 ||++ 	J77GHI
I	J)   sl  4e,e,	Be,a- e,1e,Be,De,3e,Ee,2e,e,A3e,Ae,e,+Be,=A
e,e,e,Ce,&%e,A
e,a0e,e/a30e5a8
a6a8ed.eAe'4ee,&e'e,0e,3e6a88db
ded(d)A$dede/e

ee,e)	e
e)	!e)	#	e,r%  )r  r  r  r  r  r1   propertyr&  
contextlibasynccontextmanagerr   r  r  __classcell__)r!  r&   s   @@r'   r  r  y  sY     - -   !!o 9=	o o "o or*   r  c                z    V ^8  d   QhR\         R\        \        P                  ,          R\        P                  /# )r    r!   r(  r6   )r   r   r   r+  r:  )r%   s   "r'   r(   r(   w  s7     2 22U2232 2r*   c                   "   Vf   \         P                  ! 4       pM\        V\        4      '       dQ   \	        VR.4      e#   \
        P                  ! \	        VR.4      4      pMR p\         P                  ! R/ VB pW2n        M:VP                  f   R pM!\
        P                  ! \	        VR.4      4      pTpWBn        VP                  RR /R7      pVP                  '       d   . Vn	        VP                   F  p\        e_   \        V\        4      '       dI   \        YfP                  4       G R j  xL
 4      pVP                  P                  VP                  4       Ki  \        e=   \        V\        4      '       d'   VP                  P                  \!        V4      4       K  VP                  P                  V4       K  	  VP"                  e   \$        P&                  ! R\(        ^R7       V#  L5i)Nsystem_instructionrV  )updatezSetting `LiveConnectConfig.generation_config` is deprecated, please set the fields on `LiveConnectConfig` directly. This will become an error in a future version (not before Q3 2025)r?   r   )r   r:  r   r   rU  rY   	t_contentrr  
model_copyrV  McpClientSessionr   
list_toolsextendMcpToolr   r   generation_configrA   rB   rC   )r!   r(  r   converted_system_instructionrr  parameter_model_copytoolmcp_to_genai_tool_adapters   &&      r'   r>  r>  w  s    
 ^--/O&$F)*+7%&[[
v,-
.&" &*"--77O)E&  (;;tF5I4J'KLO);& )33GT?3K!#%%		%*T;K*L*L$9))%
! 	""))*C*I*IJ:dG#<#<""))*<T*BC""))$/ & ++7MM	C 	 
% *s   C G1#AG1/G/0C G1c                    V ^8  d   Qh/ ^ \         9   d   \        P                  ;R&   ^\         9   d   \        P                  ;R&   ^\         9   d   \        P                  ;R&   # )r    rv  ry  r   )__conditional_annotations__typingType)r%   s   "r'   r(   r(      sP        b &%FKK%c !d 6;;e !f +**g !r*   )Cr  r  r   r   rm  rF   r   r  r   r   r   r   r   r   rA   google.authrN  r   r    r   r	   r
   r^   r   r   rY   r   r   r.   r   r   rU  r   rH  
live_musicr   modelsr   r   websockets.asyncio.clientr   r   rY  ModuleNotFoundErrorwebsockets.clientgoogle.auth.transportr   ImportErrorTYPE_CHECKINGmcpr   rv  	mcp.typesr   ry  	_adaptersr   r   	getLoggerloggerr   r   
BaseModuler  r>  r(   )r  s   @r'   <module>r     sO    !       J J       1      & . . & %.. 68=, 
3'.,"%%''**	5)0. 
		.	/< _ _D{&& {|2M"  6056  (" 
 G 	s6   D: #E 'E" :EE	EE"E43E4