
    Oj/                     h   S r SSKrSSKrSSKJrJrJrJr  SSKJ	r	  SSK
Jr  SSK
Jr  SSK
Jr  SS	K
Jr  \R                   " S
5      rS\R$                  S\4S jr SS\R$                  S\\R*                     S\R$                  4S jjr " S S\R.                  5      r " S S\R.                  5      rg)z&[Experimental] Auth Tokens API client.    N)AnyDictListOptional)	urlencode   )_api_module)_common)_tokens_converters)typeszgoogle_genai.tokenssetupreturnc                    / nU R                  5        HZ  u  p#[        U[        5      (       a,  U(       a%  UR                  5        Vs/ s H	  oB SU 3PM     nnOU/nUR	                  U5        M\     SR                  U5      $ s  snf )zReturn field_masks.,)items
isinstancedictkeysextendjoin)r   fieldskvkkfields         U/var/www/html/leaf-doctor-v1/venv/lib/python3.13/site-packages/google/genai/tokens.py_get_field_masksr      su    &kkmda!Tq%&VVX.XrAbT{Xe.ece
MM%  
&	 /s   Brequest_dictconfigc                    U R                  S5      nU(       Ga  UR                  S5      (       Ga  UR                  S5      U S'   [        U S   5      n[        U[        5      (       a(  UR                  S5      b  UR                  S5      (       a=  [        U[        R
                  5      (       a$  UR                  b  UR                  (       d  X0S'   GOZ[        U[        5      (       a  UR                  S5      b,  [        U[        R
                  5      (       a   UR                  c  U R                  SS5        OU S   (       a  U R                  S5      n[        R                  " 5       R                  5       R                  5       nU(       a'  / nU H  nXu;   a  SU 3nUR                  U5        M      O/ nU(       a  US-   SR                  U5      -   OUU S'   OTU R                  SS5        OAU R                  S/ 5      nSR                  U5      nU(       a  XS'   OU R                  SS5        U R                  S5      (       d  U R                  SS5        U $ )z"Converts bidiGenerateContentSetup.bidiGenerateContentSetupr   lock_additional_fieldsN	fieldMaskzgenerationConfig.r   )getr   r   r   r   CreateAuthTokenConfigr#   popGenerationConfig
model_dumpr   appendr   )	r   r    
bidi_setup
field_maskadditional_fields_listgeneration_config_listfield_mask_listr   field_mask_strs	            r   "_convert_bidi_setup_to_token_setupr1   ,   s   
  :;*JNN7++ 0:~~g/FL+, ",/I"JKJ 	64  JJ/0<

344656677))5-- #-;64  JJ/08656677))1 {D)	k	"4@4D4D
5  %557BBDIIK	+E,'w/E

 
 
' ,
   s
SXXo6
6 ; {D)!!+r2JXXj)N"0;{D)			4	5	5/6	    c                       \ rS rSrSr\R                  " S5      SS.S\\R                     S\R                  4S jj5       rS	rg)
Tokensq   z^[Experimental] Auth Tokens API client.

This class provides methods for creating auth tokens.
[The SDK's token creation implementation is experimental, and may change in future versions.Nr    r    r   c                   [         R                  " US9nU R                  R                  (       a  [	        S5      e[
        R                  " U R                  U5      nUR                  S5      nU(       a  SR                  U5      nOSnUR                  S5      nU(       a  U S[        U5       3nUR                  SS5        U(       a  [        X15      nSnUb:  UR                  b-  UR                  R                  b  UR                  R                  n[        R                  " U5      n[        R                   " U5      nU R                  R#                  S	XSU5      nUR$                  (       d  0 O[&        R(                  " UR$                  5      n	[         R*                  R-                  XR/                  5       S
9n
U R                  R1                  U
5        U
$ )a  [Experimental] Creates an auth token.

Args:
  config (CreateAuthTokenConfig): Optional configuration for the request.

The CreateAuthTokenConfig's `live_constrained_parameters` attrubite
Can be used to lock the parameters of the live session so they
can't be changed client side. This behavior has two basic modes depending on
whether `lock_additional_fields` is set:

If you do not pass `lock_additional_fields` the entire
`live_constrained_parameters` is locked and can't be changed
by the token's user.

If you set `lock_additional_fields`, then the non-null fields of
`live_constrained_parameters` are locked, and any additional fields
specified in `lock_additional_fields`.

Usage:

.. code-block:: python

  # Case 1: If LiveEphemeralParameters is unset, unlock LiveConnectConfig
  # when using the token in Live API sessions. Each session connection can
  # use a different configuration.

  config = types.CreateAuthTokenConfig(
      uses=10,
      expire_time='2025-05-01T00:00:00Z',
  )
  auth_token = client.auth_tokens.create(config=config)

.. code-block:: python

  # Case 2: If LiveEphemeralParameters is set, lock all fields in
  # LiveConnectConfig when using the token in Live API sessions. For
  # example, changing `output_audio_transcription` in the Live API
  # connection will be ignored by the API.

  auth_token = client.auth_tokens.create(
      config=types.CreateAuthTokenConfig(
          uses=10,
          live_constrained_parameters=types.LiveEphemeralParameters(
              model='gemini-live-2.5-flash-preview',
              config=types.LiveConnectConfig(
                  system_instruction='You are an LLM called Gemini.'
              ),
          ),
      )
  )

.. code-block:: python

  # Case 3: If LiveEphemeralParameters is set and lockAdditionalFields is
  # empty, lock LiveConnectConfig with set fields (e.g.
  # system_instruction in this example) when using the token in Live API
  # sessions.
  auth_token = client.auth_tokens.create(
      config=types.CreateAuthTokenConfig(
          uses=10,
          live_constrained_parameters=types.LiveEphemeralParameters(
              config=types.LiveConnectConfig(
                  system_instruction='You are an LLM called Gemini.'
              ),
          ),
          lock_additional_fields=[],
      )
  )

.. code-block:: python

  # Case 4: If LiveEphemeralParameters is set and lockAdditionalFields is
  # set, lock LiveConnectConfig with set and additional fields (e.g.
  # system_instruction, temperature in this example) when using the token
  # in Live API sessions.
  auth_token = client.auth_tokens.create(
      config=types.CreateAuthTokenConfig(
          uses=10,
          live_constrained_parameters=types.LiveEphemeralParameters(
              model='gemini-live-2.5-flash-preview',
              config=types.LiveConnectConfig(
                  system_instruction='You are an LLM called Gemini.'
              ),
          ),
          lock_additional_fields=['temperature'],
      )
  )
r7   =This method is only supported in the Gemini Developer client._urlauth_tokens_query?r    Npostresponsekwargs)r   CreateAuthTokenParameters_api_clientvertexai
ValueErrortokens_converters#_CreateAuthTokenParameters_to_mldevr%   
format_mapr   r'   r1   r    http_optionsr
   convert_to_dictencode_unserializable_typesrequestbodyjsonloads	AuthToken_from_responser)   _verify_responseselfr    parameter_modelr   request_url_dictpathquery_paramsrI   r@   response_dictreturn_values              r   createTokens.createw   s   @ 55O   
I  'JJ



l &))&1	''(89##H-LvQy./0d Xt$ 7Ml04L#"".""//;$++88l**<8L66|DL''LH 'mmBHMM1JM??11'A'A'C 2 L 	%%l3r2    __name__
__module____qualname____firstlineno____doc__r
   experimental_warningr   r   CreateAuthTokenConfigOrDictrP   r[   __static_attributes__r]   r2   r   r4   r4   q   sU    
 +
 FJO A ABOO	Or2   r4   c                       \ rS rSrSr\R                  " S5      SS.S\\R                     S\R                  4S jj5       rS	rg)
AsyncTokensi  zq[Experimental] Async Auth Tokens API client.

This class provides asynchronous methods for creating auth tokens.
r6   Nr7   r    r   c                  #    [         R                  " US9nU R                  R                  (       a  [	        S5      e[
        R                  " U R                  U5      nUR                  S5      nU(       a  SR                  U5      nOSnUR                  S5      nU(       a  U S[        U5       3nUR                  SS5        [        X15      nSnUb:  UR                  b-  UR                  R                  b  UR                  R                  n[        R                  " U5      n[        R                   " U5      nU R                  R#                  S	UUUS
9I Sh  vN nUR$                  (       d  0 O[&        R(                  " UR$                  5      n	[         R*                  R-                  XR/                  5       S9n
U R                  R1                  U
5        U
$  N7f)a  Creates an auth token asynchronously. Support in v1alpha only.

Args:
  config (CreateAuthTokenConfig): Optional configuration for the request.

Usage:

.. code-block:: python

  client = genai.Client(
      api_key=API_KEY,
      http_options=types.HttpOptions(api_version='v1alpha'),
  )

  auth_token = await client.aio.tokens.create(
      config=types.CreateAuthTokenConfig(
          uses=10,
          live_constrained_parameters=types.LiveEphemeralParameters(
              model='gemini-live-2.5-flash-preview',
              config=types.LiveConnectConfig(
                  system_instruction='You are an LLM called Gemini.'
              ),
          ),
      )
  )
r7   r9   r:   r;   r<   r=   r    Nr>   )rI   r?   )r   rB   rC   rD   rE   rF   rG   r%   rH   r   r'   r1   r    rI   r
   rJ   rK   async_requestrM   rN   rO   rP   rQ   r)   rR   rS   s              r   r[   AsyncTokens.create  s    D 55O
   
I  'JJ



l &))&1	''(89##H-LvQy./0dXt$ 6lKL04L#"".""//;$++88l**<8L66|DL%%33!	 4  H 'mmBHMM1JM??11'A'A'C 2 L 	%%l3s   EGGB Gr]   r^   r]   r2   r   rh   rh     sU    
 +
 FJS A ABSS	Sr2   rh   )N)rc   rN   loggingtypingr   r   r   r   urllib.parser    r	   r
   r   rF   r   	getLoggerlogger
StringDictstrr   re   r1   
BaseModuler4   rh   r]   r2   r   <module>ru      s     -   , , "   5 			0	1G.. 3   ;?B$$BU667B BJY[## Yx]+(( ]r2   