
    +j/                     6   d Z ddlZddlZddlmZmZmZmZ ddlm	Z	 ddl
mZ ddl
mZ ddl
mZ dd	l
mZ  ej        d
          Zdej        defdZ	 ddej        deej                 dej        fdZ G d dej                  Z G d dej                  ZdS )z&[Experimental] Auth Tokens API client.    N)AnyDictListOptional)	urlencode   )_api_module)_common)_tokens_converters)typeszgoogle_genai.tokenssetupreturnc                    g }|                                  D ]U\  }t          |t                    r#|r!fd|                                D             }ng}|                    |           Vd                    |          S )zReturn field_masksc                     g | ]	} d | 
S ). ).0kkks     W/home/wildlama/visual-decline/.venv/lib/python3.11/site-packages/google/genai/tokens.py
<listcomp>z$_get_field_masks.<locals>.<listcomp>$   s#    ...r!{{b{{...    ,)items
isinstancedictkeysextendjoin)r   fieldsvfieldr   s       @r   _get_field_masksr#      s    &kkmm  da!T q ....QVVXX...eece
MM%	&		r   request_dictconfigc                    |                      d          }|r|                     d          r|                     d          | d<   t          | d                   }t          |t                    r*|                     d          |                     d          r(t          |t          j                  r|j        |j        s|| d<   ndt          |t                    r|                     d          !t          |t          j                  r|j        |                     dd           n| d         r|                      d          }t	          j                    	                                
                                }|r&g }|D ] }||v rd| }|                    |           !ng }|r|dz   d                    |          z   n|| d<   n`|                     dd           nI|                      dg           }d                    |          }|r|| d<   n|                     dd           |                      d          s|                     dd           | S )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_setupr6   ,   s   
  :;;* 8*JNN7++ 8* 0:~~g/F/FL+, ",/I"JKKJ 	64  )*JJ/00<

344 = 	65677 = )5- 6 #-l;64  *JJ/00865677 9 )1 {D))))	k	" *4@4D4D
5 5  %577BBDDIIKK	 + 	( 	(E,,,///E

 
 
'
'
'
'	(
  *s
SXXo66
6
6 ; {D))))!!+r22JXXj))N *"0l;{D)))			4	5	5 7/666	r   c                   t    e Zd ZdZ ej        d          dddeej                 dej	        fd            Z
dS )Tokenszb[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                L   t          j        |          }| j        j        rt	          d          t          j        | j        |          }|                    d          }|rd                    |          }nd}|                    d          }|r| dt          |           }|
                    dd           |rt          ||          }d}||j        |j        j        |j        j        }t          j        |          }t          j        |          }| j                            d	|||          }|j        si nt'          j        |j                  }	t           j                            |	|                                
          }
| j                            |
           |
S )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'],
          )
      )
    r:   =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,   r6   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_paramsrL   rC   response_dictreturn_values              r   createzTokens.createw   s   @ 5  O   
I   'J


 l &))&11	 ''(899##H--L 100y..00d Xt$$$  N7fMMl04L#"."/;$+8l*<88L6|DDL''lL H 'mJBBHM1J1JM?11'A'A'C'C 2  L 	%%l333r   __name__
__module____qualname____doc__r
   experimental_warningr   r   CreateAuthTokenConfigOrDictrS   r^   r   r   r   r8   r8   q   s         
  7+ 
 FJO O O ABOO O O	 O O Or   r8   c                   t    e Zd ZdZ ej        d          dddeej                 dej	        fd            Z
dS )AsyncTokenszu[Experimental] Async Auth Tokens API client.

  This class provides asynchronous methods for creating auth tokens.
  r9   Nr:   r%   r   c                Z  K   t          j        |          }| j        j        rt	          d          t          j        | j        |          }|                    d          }|rd                    |          }nd}|                    d          }|r| dt          |           }|
                    dd           t          ||          }d}||j        |j        j        |j        j        }t          j        |          }t          j        |          }| j                            d	|||
           d{V }|j        si nt'          j        |j                  }	t           j                            |	|                                          }
| j                            |
           |
S )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.'
                  ),
              ),
          )
      )
    r:   r<   r=   r>   r?   r@   r%   NrA   )rL   rB   )r   rE   rF   rG   rH   rI   rJ   r*   rK   r   r,   r6   r%   rL   r
   rM   rN   async_requestrP   rQ   rR   rS   rT   r.   rU   rV   s              r   r^   zAsyncTokens.create  s     D 5  O
   
I   'J


 l &))&11	 ''(899##H--L 100y..00dXt$$$ 6lFKKL04L#"."/;$+8l*<88L6|DDL%33!	 4        H 'mJBBHM1J1JM?11'A'A'C'C 2  L 	%%l333r   r_   r   r   r   rg   rg     s         
  7+ 
 FJS S S ABSS S S	 S S Sr   rg   )N)rc   rQ   loggingtypingr   r   r   r   urllib.parser    r	   r
   r   rI   r   	getLoggerlogger
StringDictstrr#   re   r6   
BaseModuler8   rg   r   r   r   <module>rs      s    - ,   , , , , , , , , , , , , " " " " " "             5 5 5 5 5 5      		0	1	1G. 3      ;?B B$BU67B B B B BJY Y Y Y Y[# Y Y Yx] ] ] ] ]+( ] ] ] ] ]r   