+
    ~j1                    .   ^ RI Ht ^ RIt^ RIt^ RIHtHtHtHt ^ RI	H
t
 ^ RIHtHt ^ RIt^RIHtHtHt ^RIHt RtR	tR
tRRRR/t ! R R]4      t ! R R]4      tR#R R lltR$RRRRRRRRRRRR/R R llltR%RRRR/R R  lllt ! R! R"4      tR# )&    )annotationsN)AnyCallable	TypedDictcast)Path)LiteralNotRequired)
OAuthErrorOpenAIErrorSubjectTokenProviderError)	to_threadz/urn:ietf:params:oauth:grant-type:token-exchangez#https://auth.openai.com/oauth/tokeni  jwtz$urn:ietf:params:oauth:token-type:jwtidz)urn:ietf:params:oauth:token-type:id_tokenc                  ,    ] tR t^t$ R]R&   R]R&   RtR# )SubjectTokenProviderzLiteral['jwt', 'id']
token_typezCallable[[], str]	get_token N)__name__
__module____qualname____firstlineno____annotations____static_attributes__r       j/Users/mitch_tango/dev/rabbit-r1-livekit/agent/.venv/lib/python3.14/site-packages/openai/auth/_workload.pyr   r      s    $$  r   r   c                  J    ] tR t^t$ RtR]R&    R]R&    R]R&    R]R&   R	tR
# )WorkloadIdentityz(Identity provider resource id in WIFAPI.stridentity_provider_idservice_account_idr   providerzNotRequired[float]refresh_buffer_secondsr   N)r   r   r   r   __doc__r   r   r   r   r   r   r      s&    2GE""..r   r   c                    V ^8  d   QhRRRR/# )   token_file_pathz
str | Pathreturnr   r   )formats   "r   __annotate__r+   +   s     9 999r   c                "   a  R V 3R llpRRRV/# )a7  
Get a subject token provider for Kubernetes clusters with Workload Identity configured.

Cloud providers typically mount the subject token as a file in the container.

Args:
    token_file_path: path to the mounted service account token file. Defaults to `/var/run/secrets/kubernetes.io/serviceaccount/token`.
c                   V ^8  d   QhRR/# r'   r)   r    r   )r*   s   "r   r+   8k8s_service_account_token_provider.<locals>.__annotate__7   s     o os or   c                 $  <  \        SR 4      ;_uu_ 4       p V P                  4       P                  4       pV'       g   \        RS R24      hVuuRRR4       #   + '       g   i     R# ; i  \         d   p\        RS RT 24      ThRp?ii ; i)rzThe token file at z
 is empty.Nz!Failed to read the token file at z: )openreadstripr   	Exception)ftokener(   s      r   r   5k8s_service_account_token_provider.<locals>.get_token7   s    	oos++q(36HHYYc4dee	 ,+++
  	o+.OP_O``bcdbe,fgmnn	os4   A- 7A
A- A*	$A- *A- -B8B

Br   r   r   r   )r(   r   s   f r   "k8s_service_account_token_providerr:   +   s     o o %i88r   	object_id	client_id
msi_res_idapi_versionz
2018-02-01timeout      $@http_clientc               8    V ^8  d   QhRRRRRRRRRRRR	R
RRR/# )r'   resourcer    r;   z
str | Noner<   r=   r>   r?   floatrA   httpx.Client | Noner)   r   r   )r*   s   "r   r+   r+   D   sZ     99 9999 99 	99
 99 99 99 %99 99r   c               :   a aaaaaa R VVVVVV V3R llpRRRV/# )ab  
Get a subject token provider for Azure Managed Identities.

See: https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/how-to-use-vm-token#get-a-token-using-http

Args:
    resource: the resource URI to request a token for. Defaults to `https://management.azure.com/` (Azure Resource Manager).
    object_id: the object ID of the managed identity to use, when multiple are assigned.
    client_id: the client ID of the managed identity to use, when multiple are assigned.
    msi_res_id: the ARM resource ID of the managed identity to use, when multiple are assigned.
    api_version: the Azure IMDS API version. Defaults to `2018-02-01`.
    timeout: the request timeout in seconds. Defaults to 10.0.
    http_client: optional httpx.Client instance to use for requests. If not provided, a new client will be created for each request.
c                   V ^8  d   QhRR/# r.   r   )r*   s   "r   r+   ;azure_managed_identity_token_provider.<locals>.__annotate__]   s     j js jr   c            	     H  <  R p RSRS/pSe   SVR&   Se   SVR&   S
e   S
VR&   S	e   S	P                  WRR/SR	7      pM<\        P                  ! 4       ;_uu_ 4       pVP                  WRR/SR	7      pRRR4       XP                  '       d   \	        R
VP
                   2VR7      hVP                  4       pVP                  R4      pV'       g   \	        RVR7      h\        \        V4      #   + '       g   i     L; i  \         d   p\	        RT 24      ThRp?ii ; i)z5http://169.254.169.254/metadata/identity/oauth2/tokenzapi-versionrC   Nr;   r<   r=   Metadatatrueparamsheadersr?   z4Failed to fetch Azure subject token from IMDS: HTTP responseaccess_tokenz3Azure IMDS response did not include an access_tokenz/Failed to fetch Azure subject token from IMDS: )
gethttpxClientis_errorr   status_codejsonr   r    r5   )urlrM   rP   clientdatar7   r8   r>   r<   rA   r=   r;   rC   r?   s          r   r   8azure_managed_identity_token_provider.<locals>.get_token]   s<   	jIC&3[*h%WF$&/{#$&/{#%'1|$&&??3
TZG[el?m\\^^v%zz#zSYFZdkzlH $    /J8K_K_J`a%  ==?DHH^,E/IT\  U## $^  	j+.]^_]`,abhii	js=   AD C/5D AD D /C?	:D D!DD!r   r   r   r   )rC   r;   r<   r=   r>   r?   rA   r   s   fdddddd r   %azure_managed_identity_token_providerr\   D   s!    2j j@ %i88r   c               (    V ^8  d   QhRRRRRRRR/# )	r'   audiencer    r?   rD   rA   rE   r)   r   r   )r*   s   "r   r+   r+      s2     )8 )8)8 )8 %	)8
 )8r   c               *   a aa R V VV3R llpRRRV/# )a  
Get a subject token provider for GCP VM instances using the instance metadata server.

See: https://cloud.google.com/compute/docs/instances/verifying-instance-identity

Args:
    audience: the unique URI agreed upon by both the instance and the system verifying
        the instance's identity. Defaults to `https://api.openai.com/v1`.
    timeout: the request timeout in seconds. Defaults to 10.0.
    http_client: optional httpx.Client instance to use for requests. If not provided, a new client will be created for each request.
c                   V ^8  d   QhRR/# r.   r   )r*   s   "r   r+   +gcp_id_token_provider.<locals>.__annotate__   s     s ss sr   c            	       <  R p RS/pSe   SP                  WRR/SR7      pM<\        P                  ! 4       ;_uu_ 4       pVP                  WRR/SR7      pRRR4       XP                  '       d   \	        RVP
                   2VR7      hVP                  P                  4       pV'       g   \	        RVR7      hV#   + '       g   i     Lm; i  \         d   p\	        R	T 24      ThRp?ii ; i)
z]http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/identityr^   NzMetadata-FlavorGooglerL   z=Failed to fetch GCP subject token from metadata server: HTTP rO   z+GCP metadata server returned an empty tokenz8Failed to fetch GCP subject token from metadata server: )	rR   rS   rT   rU   r   rV   textr4   r5   )	rX   rM   rP   rY   r7   r8   r^   rA   r?   s	         r   r   (gcp_id_token_provider.<locals>.get_token   s    	sqC (+F&&??3HY[cGdnu?v\\^^v%zz#GXZbFcmtzuH $    /ST\ThThSij%  MM'')E/0]hpqqL $^  	s+.fghfi,jkqrr	ss;   >C B=C 2;C .C =C	C C/C**C/r   r   r   r   )r^   r?   rA   r   s   fdd r   gcp_id_token_providerrf      s     $s s. $Y77r   c                      ] tR t^tR]/R R lltR R ltR R ltR R	 ltR
 R lt	R R lt
R R ltR R ltR R ltR R ltR R ltR R ltRtR# )WorkloadIdentityAuthtoken_exchange_urlc                    V ^8  d   QhRRRR/# )r'   workload_identityr   ri   r    r   )r*   s   "r   r+   !WorkloadIdentityAuth.__annotate__   s      : : ,:  	:r   c               	    Wn         W n        R V n        R V n        R V n        RV n        \        P                  ! 4       V n        \        P                  ! V P                  4      V n
        R # NF)rk   ri   _cached_token"_cached_token_expires_at_monotonic"_cached_token_refresh_at_monotonic_refreshing	threadingLock_lock	Condition
_condition)selfrk   ri   s   &$$r   __init__WorkloadIdentityAuth.__init__   sT     "3"4)-@D/@D/!&^^%
#--djj9r   c                   V ^8  d   QhRR/# r.   r   )r*   s   "r   r+   rl      s     - -3 -r   c           	     	   V P                   ;_uu_ 4        V P                  '       d3   V P                  4       '       d   V P                  P	                  4        KD  V P                  4       '       g;   V P                  4       '       g%   \        \        V P                  4      uuR R R 4       # V P                  '       dv   V P                  '       d   V P                  P	                  4        K.  V P                  pV P                  4       '       d   \        R4      h\        \        V4      uuR R R 4       # RV n        R R R 4        V P                  4        V P                   ;_uu_ 4        V P                  4       '       d   \        R4      h\        \        V P                  4      uuR R R 4       V P                   ;_uu_ 4        RV n        V P                  P                  4        R R R 4       #   + '       g   i     L; i  + '       g   i     # ; i  + '       g   i     M; i T P                   ;_uu_ 4        RT n        T P                  P                  4        R R R 4       R #   + '       g   i     R # ; i  T P                   ;_uu_ 4        RT n        T P                  P                  4        R R R 4       i   + '       g   i     i ; i; i)Nz)Token is unusable after refresh completedTF)ru   rr   _token_unusablerw   wait_needs_refreshr   r    ro   RuntimeError_perform_refresh
notify_all)rx   r7   s   & r   r   WorkloadIdentityAuth.get_token   s   ZZZ"""t';';'='=$$&''))$2E2E2G2GC!3!34 Z &&&OO((***''))&'RSSC' Z  $D "		-!!#''))&'RSSC!3!34 
 #( **, 1 Z0  
 #( **, #( **, s   G)G)1G)0G)G)*G)<G)=G)G)1G)$I7 %;H 
I7 >"G<)G9	<HH	I7 7"I##I4	7K
"J7	.	K
7KK
c                   V ^8  d   QhRR/# r.   r   )r*   s   "r   r+   rl      s     / /s /r   c                	H   "   \        V P                  4      G R j  xL
 #  L5iN)r   r   rx   s   &r   get_token_async$WorkloadIdentityAuth.get_token_async   s     t~~....s   " "c                   V ^8  d   QhRR/# r'   r)   Noner   )r*   s   "r   r+   rl      s     ; ;$ ;r   c                	    V P                   ;_uu_ 4        R V n        R V n        R V n        R R R 4       R #   + '       g   i     R # ; ir   )ru   ro   rp   rq   r   s   &r   invalidate_token%WorkloadIdentityAuth.invalidate_token   s/    ZZZ!%D6:D36:D3 ZZZs	   5A	c                   V ^8  d   QhRR/# r   r   )r*   s   "r   r+   rl      s     d d$ dr   c                	2   V P                  4       p\        P                  ! 4       pVR ,          pV P                  ;_uu_ 4        VR,          V n        W#,           V n        W P                  V4      ,           V n        RRR4       R#   + '       g   i     R# ; i)
expires_inrQ   N)_fetch_token_from_exchangetime	monotonicru   ro   rp   _refresh_delay_secondsrq   )rx   
token_datanowr   s   &   r   r   %WorkloadIdentityAuth._perform_refresh   sj    446
nn-
ZZZ!+N!;D696FD369<W<WXb<c6cD3 ZZZs   8BB	c                   V ^8  d   QhRR/# )r'   r)   dict[str, Any]r   )r*   s   "r   r+   rl      s     9 9N 9r   c                	$   V P                  4       pV P                  R ,          R,          p\        P                  V4      pVf4   \	        RV: RRP                  \        P                  4       4       24      h\        P                  ! 4       ;_uu_ 4       pVP                  V P                  R\        RVRVR	V P                  R	,          R
V P                  R
,          /RR7      pV P                  V4      uuRRR4       #   + '       g   i     R# ; i)r#   r   NzUnsupported token type: z. Supported types: z, 
grant_typesubject_tokensubject_token_typer!   r"   r@   )rW   r?   )_get_subject_tokenrk   SUBJECT_TOKEN_TYPESrR   r   joinkeysrS   rT   postri   TOKEN_EXCHANGE_GRANT_TYPE_handle_token_response)rx   r   r   r   rY   rP   s   &     r   r   /WorkloadIdentityAuth._fetch_token_from_exchange   s    //1++J7E
044Z@%*:.8KDIIViVnVnVpLqKrs  \\^^v{{'' ";#](*<*D,B,BCY,Z($*@*@AU*V  # 
H ..x8 ^^^s   AC>>D	c                    V ^8  d   QhRRRR/# )r'   rP   zhttpx.Responser)   r   r   )r*   s   "r   r+   rl     s     
 
~ 
. 
r   c                	     VP                   '       d   VP                  4       MR pVP                  R9   d   \	        WR7      hVP
                  '       d   Vf   \        R4      hVP                  R4      pVP                  R4      p\        V\        4      '       d	   V'       g   \        R4      h\        V\        \        34      '       g   \        R4      hRVR\        V4      /# \        RVP                   24      h  \         d    R p Li ; i)	N)rP   bodyz4Token exchange succeeded but response body was emptyrQ   r   z<Token exchange response did not include a valid access_tokenz:Token exchange response did not include a valid expires_inz"Token exchange failed with status )i  i  i  )contentrW   
ValueErrorrV   r   
is_successr   rR   
isinstancer    intrD   )rx   rP   r   rQ   r   s   &&   r   r   +WorkloadIdentityAuth._handle_token_response  s    	&.&6&6&68==?DD ?2h::|!"XYY88N3L,/JlC00!"`aaj3,77!"^__"L,j@QRR01E1E0FG
 	
#  	D	s   C= C= =DDc                   V ^8  d   QhRR/# r.   r   )r*   s   "r   r+   rl     s      C r   c                	n    V P                   R ,          pVR,          ! 4       pV'       g   \        R4      hV# )r#   r   z>The workload identity provider returned an empty subject token)rk   r   )rx   r#   r   s   &  r   r   'WorkloadIdentityAuth._get_subject_token  s4    ))*5 -/^__r   c                   V ^8  d   QhRR/# r'   r)   boolr   )r*   s   "r   r+   rl   $  s     C C Cr   c                	N    V P                   R J ;'       g    V P                  4       # r   )ro   _token_expiredr   s   &r   r}   $WorkloadIdentityAuth._token_unusable$  s$    !!T)BBT-@-@-BBr   c                   V ^8  d   QhRR/# r   r   )r*   s   "r   r+   rl   '       K K Kr   c                	f    V P                   f   R# \        P                  ! 4       V P                   8  # )NT)rp   r   r   r   s   &r   r   #WorkloadIdentityAuth._token_expired'  s)    22:~~4#J#JJJr   c                   V ^8  d   QhRR/# r   r   )r*   s   "r   r+   rl   ,  r   r   c                	f    V P                   f   R# \        P                  ! 4       V P                   8  # rn   )rq   r   r   r   s   &r   r   #WorkloadIdentityAuth._needs_refresh,  s)    22:~~4#J#JJJr   c                    V ^8  d   QhRRRR/# )r'   r   rD   r)   r   )r*   s   "r   r+   rl   1  s     7 7 75 7r   c                	    V P                   P                  R \        4      p\        W!^,          4      p\	        W,
          R4      # )r$   g        )rk   rR   DEFAULT_REFRESH_BUFFER_SECONDSminmax)rx   r   configured_buffereffective_buffers   &&  r   r   +WorkloadIdentityAuth._refresh_delay_seconds1  s=     22667OQop0q.A:0#66r   )ro   rp   rq   rw   ru   rr   ri   rk   N)r   r   r   r   DEFAULT_TOKEN_EXCHANGE_URLry   r   r   r   r   r   r   r   r}   r   r   r   r   r   r   r   rh   rh      sQ    : #=	: -:/;d90
0CK
K
7 7r   rh   )z3/var/run/secrets/kubernetes.io/serviceaccount/token)zhttps://management.azure.com/)zhttps://api.openai.com/v1)
__future__r   r   rs   typingr   r   r   r   pathlibr   typing_extensionsr	   r
   rS   _exceptionsr   r   r   _utils._syncr   r   r   r   r   r   r   r:   r\   rf   rh   r   r   r   <module>r      s    "   1 1  2  L L $M B !%  
1
5 !9 !
/y /9299 !99 !	99
 "99 $99 99 (,99 99x)8 )8 (,	)8 )8XH7 H7r   