
    b\jXy                       S SK Jr  S SKrS SKrS SKrS SKJrJrJrJ	r	J
r
JrJrJrJr  S SKJrJr  S SKJrJr  S SKrSSKJrJrJrJr  SSKJrJr  SS	KJrJ r   SS
K!J"r"  SSK#J$r$J%r%  SSK&J'r'  SSK(J)r)  SSK*J+r+J,r,J-r-  SSK.J/r/J0r0  \" \0SS9r1\" \/SS9r2\(       a  S SK3J4r5  Sr6Sr7\/ \84   r9\/ S4   r:\
" S\\Rv                  \Rx                  4   S9r=\
" S\\$\   \%\   4   S9r> " S S5      r? " S S\,\=\>4   5      r@            S%S jrA        S&S jrBS'S  jrC " S! S"\@\Rv                  \$\   4   \5      rD " S# S$\@\Rx                  \%\   4   \ 5      rEg)(    )annotationsN)	TYPE_CHECKINGAnyUnionMappingTypeVarCallableSequence	Awaitablecast)partialcached_property)Selfoverride   )	NOT_GIVENHeadersTimeoutNotGiven)asyncifyis_given)	AnthropicAsyncAnthropic)FinalRequestOptions)StreamAsyncStream)AnthropicError)MiddlewareInput)DEFAULT_MAX_RETRIES
BaseClientmerge_headers   )refresh_credentialsload_default_credentialsgoogle_cloud)extra)Credentialsznhttps://claude.googleapis.com/v1alpha/projects/{project}/locations/{location}/workspaces/{workspace_id}/invokeglobalzstr | Awaitable[str]_HttpxClientT)bound_DefaultStreamTc                  ,    \ rS rSrSrSS jrSS jrSrg)	_GoogleCredentialsState/   u  Holder for the Google credentials object, its refresh lock, and the project
ADC resolved.

Shared between a client and its ``copy()``/``with_options()`` clones (when the
credential configuration is inherited) so a lazily-loaded ADC credential is
minted once — not once per clone — and concurrent loads/refreshes are
serialized: google-auth credential objects are not safe to ``refresh()``
concurrently.
c                R    [         R                  " 5       U l        Xl        S U l        g N)	threadingLock_lockcredentialsadc_project)selfr4   s     X/var/www/website/venv/lib/python3.13/site-packages/anthropic/lib/google_cloud/_client.py__init__ _GoogleCredentialsState.__init__:   s    ^^%
5@'+    c                   U R                      U R                  c  [        5       u  U l        U l        OKU R                  R                  (       d  U R                  R
                  (       d  [        U R                  5        U R                  R
                  nU(       d  [        S5      e[        U[        5      (       d   eUsSSS5        $ ! , (       d  f       g= f)zJReturn a valid access token, loading ADC / refreshing as needed. Blocking.NzKCould not resolve a GCP access token from the configured Google credentials)
r3   r4   _load_adc_credentialsr5   expiredtoken_refresh_credentialsr   
isinstancestr)r6   r>   s     r7   r>   _GoogleCredentialsState.token?   s    ZZ'5J5L2 $"2!!))1A1A1G1G$T%5%56$$**E$%rsseS)))) ZZs   B1C
C)r3   r5   r4   N)r4   GoogleCredentials | NonereturnNonerD   rA   )__name__
__module____qualname____firstlineno____doc__r8   r>   __static_attributes__ r:   r7   r-   r-   /   s    ,
r:   r-   c                      \ rS rSr% SrS\S'   S\S'   S\S'   S\S	'   S
\S'   S
\S'   \\SS j5       5       r\R                  SS j5       r\SS j5       r
SS jrSrg)BaseGoogleCloudClientN   zMarker base so ``_is_base_client()`` keeps these clients off the first-party
credential-discovery chain (it matches only the exact ``Anthropic`` /
``AsyncAnthropic`` classes). Auth is handled entirely by this helper.
str | Noneworkspace_id_projectrA   	_locationr-   _creds_statebool_base_url_deferred_base_url_overriddenc                    U R                   $ r0   )	_base_urlr6   s    r7   base_urlBaseGoogleCloudClient.base_urlZ   s     ~~r:   c                    SU l         U R                  [        U[        R                  5      (       a  UO[        R                  " U5      5      U l        g )NF)rW   _enforce_trailing_slashr@   httpxURLrZ   )r6   urls     r7   r\   r]   _   s=     #(55ZUYY=W=Wc]b]f]fgj]klr:   c                .    U R                   R                  $ )zThe ``google.auth`` credentials in use (explicit or lazily-loaded ADC), if any.

Distinct from ``.credentials``, which is the base client's first-party
credentials provider and is always ``None`` on this client.
)rU   r4   r[   s    r7   google_credentials(BaseGoogleCloudClient.google_credentialsf   s       ,,,r:   c                    U R                   (       d  gU R                  c  [        S5      eU R                  c   e[        R                  U R                  U R                  U R                  S9U l        SU l         g)zDerive and set the real base URL once the project is known.

Called on every request (after the project back-fill from ADC, if any);
a no-op once the base URL has been derived.
NzNo `project` was provided and one could not be resolved from Google credentials. Pass the `project` argument, set the `ANTHROPIC_GOOGLE_CLOUD_PROJECT` environment variable, or provide `base_url` directly.projectlocationrR   F)rW   rS   r   rR   DEFAULT_URL_TEMPLATEformatrT   r\   r[   s    r7   _resolve_deferred_base_url0BaseGoogleCloudClient._resolve_deferred_base_urlo   sw     &&==  H    ,,,,33MMDNNIZIZ 4 
 #(r:   )rZ   rW   r\   N)rD   z	httpx.URL)rb   zhttpx.URL | strrD   rE   )rD   rC   rD   rE   )rG   rH   rI   rJ   rK   __annotations__propertyr   r\   setterrd   rl   rL   rM   r:   r7   rO   rO   N   sz    M N))   __m m - -(r:   rO   c                j    U b  U $ Uc   eUc  U(       a  g[        S5      e[        R                  XUS9$ )zbase_url (arg or ``ANTHROPIC_GOOGLE_CLOUD_BASE_URL``, resolved by the caller)
> derived template.

Returns ``None`` when derivation must wait for the project to be back-filled
from Google credentials on the first request (``allow_deferred_project``).
NzNo `project` was provided. Pass `project`, set the `ANTHROPIC_GOOGLE_CLOUD_PROJECT` environment variable, or provide `base_url` directly.rg   )
ValueErrorrj   rk   r\   rh   ri   rR   allow_deferred_projects        r7   _resolve_base_urlrv      sT      ###!D
 	
  &&wXd&eer:   c                6    U (       a  Uc  Ub  [        S5      eg g )Nzx`skip_auth` is mutually exclusive with `token_provider` and `credentials`; `skip_auth` disables authentication entirely.)rs   	skip_authtoken_providerr4   s      r7   _reject_skip_auth_conflictr{      s+     n0K4K<
 	
 5Lyr:   c                r    S H1  n[        XS5      n[        U[        5      (       d  M&  U(       d  M/  Us  $    g)u{   Best-effort project from an explicit credentials object — service-account /
impersonated credentials usually know theirs.)
project_idquota_project_idN)getattrr@   rA   )r4   attrvalues      r7   _project_from_credentialsr      s5     340eS!!eeL 3 r:   c                    ^  \ rS rSr% SrS\S'   S\S'   SSSSSSS\\SSSSSS	.                             SU 4S
 jjjr\	\
SS j5       5       r\\
SS j5       5       r\
SS j5       rSS jr\
SS j5       r\
SS j5       rSS\\\SS\S\\SSSS0 S.                                 SS jjr\rSrU =r$ )AnthropicGoogleCloud   aS  Synchronous client for the first-party Anthropic API served through Google's
gateway (Claude Platform on Google Cloud).

The whole first-party surface is proxied verbatim (no URL or body rewriting), so
this subclasses the full ``Anthropic`` client. Authentication is a GCP bearer
token; the deprecated Completions endpoint is not exposed.
rQ   rR   rV   
_skip_authNFrh   ri   rR   rz   r4   ry   r\   timeoutmax_retriesdefault_headersdefault_queryhttp_client
middleware_strict_response_validationc                  > [        XdUS9  X`l        X@l        [        U5      U l        Uc  [
        R                  R                  S5      nUc  [        nX l	        Uc  [
        R                  R                  S5      nUc  [
        R                  R                  S5      nUc  Ub  [        U5      nXl        Uc  [
        R                  R                  S5      nUSLU l        Uc  [
        R                  R                  S5      nUc  U(       a  Uc  [        S5      eX0l        [        UU R                  U R                  U R                  U(       + S	9nUSL U l        ["        TU ]I  Ub  UOS
UU	U
UUUUS9  SU l        SU l        g)u
  Construct a new synchronous Claude Platform on Google Cloud client.

Auth precedence (first match wins, unless ``skip_auth=True``):
  1. ``token_provider`` — a callable returning a GCP access token, invoked per request.
  2. ``credentials`` — a ``google.auth`` Credentials object, refreshed as needed.
  3. Application Default Credentials (``google.auth.default``).

Args:
    project: GCP consumer project id (or ``ANTHROPIC_GOOGLE_CLOUD_PROJECT``,
        else ``GOOGLE_CLOUD_PROJECT``). Only needed when the base URL must be
        derived; if omitted there, it is taken from an explicit ``credentials``
        object when it exposes one, or back-filled from ADC on the first request.
    location: GCP location (or ``ANTHROPIC_GOOGLE_CLOUD_LOCATION``). Optional —
        defaults to ``global``, the region the gateway should normally be
        addressed through.
    workspace_id: The Anthropic workspace ID (or ``ANTHROPIC_GOOGLE_CLOUD_WORKSPACE_ID``).
        Required unless ``skip_auth`` is set with an explicit ``base_url``.
    skip_auth: For pre-authenticated proxies — skips token attachment. A
        workspace ID is still needed to derive the base URL; pass ``base_url``
        to construct without one. Mutually exclusive with the credential
        arguments.
rx   NANTHROPIC_GOOGLE_CLOUD_LOCATIONANTHROPIC_GOOGLE_CLOUD_PROJECTGOOGLE_CLOUD_PROJECTANTHROPIC_GOOGLE_CLOUD_BASE_URL#ANTHROPIC_GOOGLE_CLOUD_WORKSPACE_IDyNo workspace ID found. Set the `workspace_id` argument or the `ANTHROPIC_GOOGLE_CLOUD_WORKSPACE_ID` environment variable.rt    r\   r   r   r   r   r   r   r   r{   r   _token_providerr-   rU   osenvirongetDEFAULT_LOCATIONrT   r   rS   rX   rs   rR   rv   rW   superr8   api_key
auth_tokenr6   rh   ri   rR   rz   r4   ry   r\   r   r   r   r   r   r   r   resolved_base_url	__class__s                   r7   r8   AnthropicGoogleCloud.__init__   s   P 	#Ycno#-3K@zz~~&GHH'H!?jjnn%EFG?jjnn%;<G?{6/<Gzz~~&GHH %-D$8!::>>*OPL x7KN  )-MM^^**'0=
 #4t"; +<*G&R#+'#!(C 	 	
" r:   c                    gzQCompletions endpoint is deprecated and not supported for the Google Cloud client.NrM   r[   s    r7   completions AnthropicGoogleCloud.completions2       r:   c                    0 $ r0   rM   r[   s    r7   auth_headers!AnthropicGoogleCloud.auth_headers8  s	    
 	r:   c                    g r0   rM   r6   headerscustom_headerss      r7   _validate_headers&AnthropicGoogleCloud._validate_headers?  s     	r:   c                    U R                   nUbM  U" 5       n[        R                  " U5      (       a)  [        [        U5      R                  5         [        S5      eU$ U R                  R                  5       $ )Nzp`token_provider` returned an awaitable. Async token providers are only supported on `AsyncAnthropicGoogleCloud`.)	r   inspectisawaitabler   r   closer   rU   r>   r6   providerr>   s      r7   
_get_tokenAnthropicGoogleCloud._get_tokenE  sm    ''JE""5))S% &&($@  L  &&((r:   c                   U R                   (       dp  U R                  (       a_  U R                  cB  U R                  c5  U R                  R                  5         U R                  R                  U l        U R                  5         U$ r0   )r   rW   rS   r   rU   r>   r5   rl   r6   optionss     r7   _prepare_options%AnthropicGoogleCloud._prepare_optionsS  s^    4#:#:}}$)=)=)E !!'') $ 1 1 = =++-r:   c                    U R                   (       a  g UR                  R                  S5      b  g SU R                  5        3UR                  S'   g NAuthorizationzBearer r   r   r   r   r6   requests     r7   _prepare_request%AnthropicGoogleCloud._prepare_request`  sC    ????/; -4T__5F4G+H(r:   rh   ri   rR   rz   r4   ry   r\   r   r   r   r   r   set_default_headersr   set_default_query_extra_kwargsc                  Ub  Ub  [        S5      eUb  Ub  [        S5      eU R                  nUb  [        UU5      nOUb  UnU R                  nUb  0 UEUEnOUb  UnUb  UOU R                  n[        U5      =(       d    [        U5      nSnSnU(       a)  [        U5      (       a  UOSn[        U5      (       a  UOSnO)U(       d"  U R                  nU R                  R                  nUc  U R                  (       d  SnOUb  UOU R                  nU R                  " SUb  UOU R                  Ub  UOU R                  [        U5      (       a  UOU R                  UUUU[        U[         5      (       a  U R"                  OUU	=(       d    U R$                  [        U5      (       a  UOU R&                  UU[        U
[         5      (       a  U R(                  OU
U R*                  S.UD6nU(       d  U(       d  U R                  Ul        U$ )u  Create a new client re-using the current options, with optional overrides.

Passing either of ``token_provider`` / ``credentials`` replaces the
inherited credential configuration wholesale — the source not passed is
cleared, so an explicit lower-precedence credential takes effect.
``workspace_id=None`` clears the workspace ID; ``project`` /
``location`` overrides re-derive a template-derived base URL.
NPThe `default_headers` and `set_default_headers` arguments are mutually exclusiveLThe `default_query` and `set_default_query` arguments are mutually exclusiverh   ri   rR   rz   r4   ry   r\   r   r   r   r   r   r   r   rM   rs   _custom_headersr!   _custom_queryr   r   r   rU   r4   rX   r\   r   rS   rT   rR   r@   r   r   _clientr   _middlewarer   r6   rh   ri   rR   rz   r4   ry   r\   r   r   r   r   r   r   r   r   r   r   paramsresolved_skip_authcredential_overriddennew_token_providernew_credentialsnew_base_urlclients                            r7   copyAnthropicGoogleCloud.copym  s   8 &+>+Jopp$):)Fkll&&&#G_=G ,)G##$00-0F*&F*3*?YT__ ( 8 QH[<Q3748 3;N3K3KQU-5k-B-BkO#!%!5!5"//;;OD$=$= 48L'/';8L 
&2G!)!5X4>>)1,)?)?TEVEV-'(!$.w$A$ADLLw#3t||'/'<'<$BRBR# +5j(+K+Kt''Q[(,(H(H
 
" %-? #'"3"3Fr:   
rW   rX   rU   rT   rS   r   r   r   r   rR   )rh   rQ   ri   rQ   rR   rQ   rz   zTokenProvider | Noner4   rC   ry   rV   r\   str | httpx.URL | Noner   !float | Timeout | None | NotGivenr   intr   Mapping[str, str] | Noner   Mapping[str, object] | Noner   httpx.Client | Noner    Sequence[MiddlewareInput] | Noner   rV   rD   rE   rn   rD   zdict[str, str]r   r   r   r   rD   rE   rF   r   r   rD   r   r   zhttpx.RequestrD   rE   )"rh   rQ   ri   rQ   rR   str | None | NotGivenrz   zTokenProvider | None | NotGivenr4   #GoogleCredentials | None | NotGivenry   bool | Noner\   r   r   r   r   r   r   +Sequence[MiddlewareInput] | None | NotGivenr   int | NotGivenr   r   r   r   r   r   r   r   r   Mapping[str, Any]rD   r   rG   rH   rI   rJ   rK   ro   r   r   r8   r   r   r   rp   r   r   r   r   r   r   with_optionsrL   __classcell__r   s   @r7   r   r      sk    
 ###'/304+/5>.4859+/7;,1!g g 	g
 !g -g .g g )g 3g g 2g 3g )g 5g  &*!g" 
#g gR      
  
) 
 
 
I 
I ##.7:C;D!%+/5>+/BK&/488<599=+-%U U 	U
 ,U 8U 9U U )U 3U )U @U $U 2U 6U  3!U" 7#U$ )%U& 
'Un Lr:   r   c                    ^  \ rS rSr% SrS\S'   S\S'   SSSSSSS\\SSSSSS	.                             SU 4S
 jjjr\	\
SS j5       5       r\\
SS j5       5       r\
SS j5       rSS jr\
SS j5       r\
SS j5       rSS\\\SS\S\\SSSS0 S.                                 SS jjr\rSrU =r$ )AsyncAnthropicGoogleCloudi  zAsynchronous client for the first-party Anthropic API served through Google's
gateway (Claude Platform on Google Cloud). See ``AnthropicGoogleCloud``.
rQ   rR   rV   r   NFr   c                  > [        XdUS9  X`l        X@l        [        U5      U l        Uc  [
        R                  R                  S5      nUc  [        nX l	        Uc  [
        R                  R                  S5      nUc  [
        R                  R                  S5      nUc  Ub  [        U5      nXl        Uc  [
        R                  R                  S5      nUSLU l        Uc  [
        R                  R                  S5      nUc  U(       a  Uc  [        S5      eX0l        [        UU R                  U R                  U R                  U(       + S	9nUSL U l        ["        TU ]I  Ub  UOS
UU	U
UUUUS9  SU l        SU l        g)zConstruct a new asynchronous Claude Platform on Google Cloud client.

``token_provider`` may be sync or async; sync providers are run off the
event loop. See ``AnthropicGoogleCloud`` for the full argument and
auth-precedence docs.
rx   Nr   r   r   r   r   r   rt   r   r   r   r   s                   r7   r8   "AsyncAnthropicGoogleCloud.__init__  s   0 	#Ycno#-3K@zz~~&GHH'H!?jjnn%EFG?jjnn%;<G?{6/<Gzz~~&GHH$,D$8!::>>*OPL x7KN  )-MM^^**'0=
 #4t"; +<*G&R#+'#!(C 	 	
 r:   c                    gr   rM   r[   s    r7   r   %AsyncAnthropicGoogleCloud.completions"  r   r:   c                    0 $ r0   rM   r[   s    r7   r   &AsyncAnthropicGoogleCloud.auth_headers(  s	     	r:   c                    g r0   rM   r   s      r7   r   +AsyncAnthropicGoogleCloud._validate_headers-  s    r:   c                  #    U R                   nUb  [        R                  " U5      (       a(  U" 5       I S h  vN n[        U[        5      (       d   eU$ [        U5      " 5       I S h  vN n[        R                  " U5      (       a
  UI S h  vN n[        U[        5      (       d   eU$ [        U R                  R                  5      " 5       I S h  vN $  N Np NM N
7fr0   )	r   r   iscoroutinefunctionr@   rA   r   r   rU   r>   r   s      r7   r   $AsyncAnthropicGoogleCloud._get_token1  s     ''**844&j(!%---- #8,..E""5))#eS))))Ld//556888 )
 /# 9sF   5CC0C(C)$CCACCCCCCc                8  #    U R                   (       d  U R                  (       aq  U R                  cT  U R                  cG  [	        U R
                  R                  5      " 5       I S h  vN   U R
                  R                  U l        U R                  5         U$  N17fr0   )	r   rW   rS   r   r   rU   r>   r5   rl   r   s     r7   r   *AsyncAnthropicGoogleCloud._prepare_optionsB  sq     4#:#:}}$)=)=)E t00667999 $ 1 1 = =++-	 :s   A$B&B'2Bc                   #    U R                   (       a  g UR                  R                  S5      b  g SU R                  5       I S h  vN  3UR                  S'   g  N7fr   r   r   s     r7   r   *AsyncAnthropicGoogleCloud._prepare_requestO  sL     ????/; -44??;L5L4M+N(5Ls   AAAAr   c                  Ub  Ub  [        S5      eUb  Ub  [        S5      eU R                  nUb  [        UU5      nOUb  UnU R                  nUb  0 UEUEnOUb  UnUb  UOU R                  n[        U5      =(       d    [        U5      nSnSnU(       a)  [        U5      (       a  UOSn[        U5      (       a  UOSnO)U(       d"  U R                  nU R                  R                  nUc  U R                  (       d  SnOUb  UOU R                  nU R                  " SUb  UOU R                  Ub  UOU R                  [        U5      (       a  UOU R                  UUUU[        U[         5      (       a  U R"                  OUU	=(       d    U R$                  [        U5      (       a  UOU R&                  UU[        U
[         5      (       a  U R(                  OU
U R*                  S.UD6nU(       d  U(       d  U R                  Ul        U$ )zCreate a new client re-using the current options, with optional overrides.

See ``AnthropicGoogleCloud.copy`` for the override semantics.
Nr   r   r   rM   r   r   s                            r7   r   AsyncAnthropicGoogleCloud.copy\  s   0 &+>+Jopp$):)Fkll&&&#G_=G ,)G##$00-0F*&F*3*?YT__ ( 8 QH[<Q8<48 3;N3K3KQU-5k-B-BkO#!%!5!5"//;;OD$=$= 48L'/';8L 
&2G!)!5X4>>)1,)?)?TEVEV-'(!$.w$A$ADLLw#3t||'/'<'<$BRBR# +5j(+K+Kt''Q[(,(H(H
 
" %-? #'"3"3Fr:   r   )rh   rQ   ri   rQ   rR   rQ   rz   zAsyncTokenProvider | Noner4   rC   ry   rV   r\   r   r   r   r   r   r   r   r   r   r   httpx.AsyncClient | Noner   r   r   rV   rD   rE   rn   r   r   rF   r   r   )"rh   rQ   ri   rQ   rR   r   rz   z$AsyncTokenProvider | None | NotGivenr4   r   ry   r   r\   r   r   r   r   r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   rD   r   r   r   s   @r7   r   r     sk    
 ###'4804+/5>.4859047;,1!Q Q 	Q
 !Q 2Q .Q Q )Q 3Q Q 2Q 3Q .Q 5Q  &*!Q" 
#Q Qf        9" 
 
 
O 
O ##.7?H;D!%+/5>04BK&/488<599=+-%Q Q 	Q
 ,Q =Q 9Q Q )Q 3Q .Q @Q $Q 2Q 6Q  3!Q" 7#Q$ )%Q& 
'Qf Lr:   r   )r\   r   rh   rQ   ri   rA   rR   rQ   ru   rV   rD   r   )ry   rV   rz   object | Noner4   r	  rD   rE   )r4   GoogleCredentialsrD   rQ   )F
__future__r   r   r   r1   typingr   r   r   r   r   r	   r
   r   r   	functoolsr   r   typing_extensionsr   r   r`   _typesr   r   r   r   _utilsr   r   r   r   r   _modelsr   
_streamingr   r   _exceptionsr   r   r   _base_clientr   r    r!   _extras._google_authr#   r$   r<   r?   google.auth.credentialsr'   r
  rj   r   rA   TokenProviderAsyncTokenProviderClientAsyncClientr)   r+   r-   rO   rv   r{   r   r   r   rM   r:   r7   <module>r     s   " 	   c c c . ,  ; ; ( 0 * - ) * J J P   8O 2.I H
 u   S!b"889 uU\\5CTCT5T/UV+5kRUFV9V3WX >4(J}o'EF 4(nf$f f 	f
 f !f f<



 "

 	


 


G0vc{1JKY GTh 5e6G6GUXIY6Y Z\j hr:   