+
    Vi                    8   ^ RI 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t ! R R	4      t]! 4       tR
 R ltR R lt ! R R]4      t]	! RR7       ! R R4      4       t]P0                  P3                  RR4      t]P0                  P3                  RR] 24      tRtR] R2tRtRtRt ]PB                  ! 4       R,          t"R R  lt#]R! 4       t$R" R# lt%R$ R% lt&R& R' lt'R(R)/R* R+ llt(R, R- lt)R. R/ lt*R0 R1 lt+R2 R3 lt,R# )4    )annotationsN)contextmanager)	dataclass)Path)Lock)Optionalc                      ] tR t^tR tRtR# )GoogleColabStatec                	@    R V n         \        4       V n        RV n        R# )FN)
is_checkedr   locksecretselfs   &N/home/ubuntu/hermes-agent/venv/lib/python3.14/site-packages/fal_client/auth.py__init__GoogleColabState.__init__   s    F	%)    )r   r   r   N)__name__
__module____qualname____firstlineno__r   __static_attributes__ r   r   r
   r
      s    *r   r
   c                   V ^8  d   QhRR/# )   returnboolr   )formats   "r   __annotate__r       s       r   c                 t     ^ RI Hp  R\        V ! 4       4      9   #   \         d     R# \         d     R# i ; i)r   get_ipythonzgoogle.colabF)IPythonr#   strModuleNotFoundError	NameErrorr"   s    r   is_google_colabr(      s9    '[]!333  s    7777c                   V ^8  d   QhRR/# r   r   Optional[str]r   )r   s   "r   r    r    %   s     # # #r   c                    \        4       '       g   R # \        P                  ;_uu_ 4        \        P                  '       d   \        P                  uuR R R 4       #  ^ RIHp   T P                  R4      pTP                  4       \        n        R\        n        \        P                  uuR R R 4       #   \         d     R R R 4       R # i ; i  \         d    R \        n         LWi ; i  + '       g   i     R # ; i)N)userdataFAL_KEYT)r(   _colab_stater   r   r   google.colabr-   ImportErrorgetstrip	Exception)r-   tokens     r   get_colab_tokenr6   %   s    				"""&& 
		-	'LL+E"'++-L #'""! 
	  	 
		  	'"&L	' 
		sM   &C)B3$*CC)3C
>C)	C

C)C&#C)%C&&C))C:	c                      ] tR t^;tRtR# )MissingCredentialsErrorr   N)r   r   r   r   r   r   r   r   r8   r8   ;   s    r   r8   T)frozenc                  R    ] tR t^?t$ RtR]R&   R]R&   ]R R l4       tR R ltR	t	R
# )AuthCredentialsz)Represents an authorization header value.r%   schemer5   c                   V ^8  d   QhRR/# r   r   r%   r   )r   s   "r   r    AuthCredentials.__annotate__G   s     - -c -r   c                	8    V P                    R V P                   2# ) )r<   r5   r   s   &r   header_valueAuthCredentials.header_valueF   s    ++a

|,,r   c                   V ^8  d   QhRR/# )r   r   zdict[str, str]r   )r   s   "r   r    r?   J   s     4 4N 4r   c                	    R V P                   /# )Authorization)rB   r   s   &r   
as_headersAuthCredentials.as_headersJ   s    !2!233r   r   N)
r   r   r   r   __doc____annotations__propertyrB   rG   r   r   r   r   r;   r;   ?   s+    3KJ- -4 4r   r;   FAL_RUN_HOSTzfal.runFAL_QUEUE_RUN_HOSTzqueue.zauth.fal.aizhttps://z/oauth/token TwXR51Vz8JbY8GUUMy6EyuVR0fTO7N4Nauth0_tokenz
.portalockz.falc                   V ^8  d   QhRR/# )r   r   r   r   )r   s   "r   r    r    Y   s     O O4 Or   c                 x    \        \        P                  ! R \        \        4      4      4      P                  4       # )FAL_HOME_DIR)r   osgetenvr%   DEFAULT_FAL_HOME
expanduserr   r   r   _get_fal_home_dirrW   Y   s'    		.#.>*?@ALLNNr   c               #  H  "    ^ RI p \        4       \        ,          pTP                  P                  RRR7       T P                  P                  \        T4      R^R7      ;_uu_ 4        Rx  RRR4       R#   \         d	    Rx   R# i ; i  + '       g   i     R# ; i5i)z%Best effort lock shared with fal-cli.NTparentsexist_okF)fail_when_lockedtimeout)	portalockerr4   rW   AUTH_LOCK_FILENAMEparentmkdirutilsTemporaryFileLockr%   )r^   	lock_files     r   _token_lockre   ]   s     
 "#&88I4$7				,	,I 
- 
 
 	
 
  
 
 
s@   B"A8 A!B")B.
B"8BB"
BB"B		B"c                   V ^8  d   QhRR/# )r   r   z#tuple[Optional[str], Optional[str]]r   )r   s   "r   r    r    o   s     7 7> 7r   c                    \        4       \        ,          p V P                  4       '       g   R# V P                  4       P	                  4        Uu. uF*  qP                  4       '       g   K  VP                  4       NK,  	  ppV'       g   R# V^ ,          pR p\        V4      ^8  d
   V^,          pT;'       g    R T;'       g    R 3# u upi )N)NN)rW   AUTH_TOKEN_FILENAMEexists	read_text
splitlinesr3   len)pathlinelinesrefresh_tokenaccess_tokens        r   _read_auth_tokensrr   o   s    !44D;;==&*nn&6&A&A&CT&Cdzz|\TZZ\&CET!HM"&L
5zA~Qx  D,"6"6$66 Us   C*Cc               $    V ^8  d   QhRRRRRR/# )r   rp   r%   rq   r+   r   Noner   )r   s   "r   r    r       s!     ) )c ) )4 )r   c                    \        4       \        ,          pVP                  P                  R R R7       V .pV'       d   VP	                  V4       VP                  RP                  V4      4       R# )TrY   
N)rW   rh   r`   ra   append
write_textjoin)rp   rq   rm   contentss   &&  r   _write_auth_tokensr{      sR    !44DKKdT2H%OODIIh'(r   c                    V ^8  d   QhRRRR/# )r   r5   r%   r   zOptional[int]r   )r   s   "r   r    r       s     
 
3 
= 
r   c                B    V P                  R4      ^,          pR\        V4      ) ^,          ,          p\        P                  ! W,           4      p\        P
                  ! VP                  R4      4      p\        VP                  R4      4      #   \         d     R# i ; i)z?Returns exp claim in seconds since epoch or None if unreadable..=zutf-8expN)
splitrl   base64urlsafe_b64decodejsonloadsdecodeintr2   r4   )r5   payload_segmentpaddingpayloadclaimss   &    r   _decode_jwt_expr      s    ++c*1-#o..23**?+DEGNN7346::e$%% s   BB BBleeway_secondsi,  c               $    V ^8  d   QhRRRRRR/# )r   r5   r%   r   r   r   r   r   )r   s   "r   r    r       s!     / /C /C /$ /r   c               b    \        V 4      pVf   R# \        P                  ! 4       V,           V8  # )NT)r   time)r5   r   r   s   &$ r   _is_access_token_expiredr      s*    
%
 C
{99;'3..r   c                    V ^8  d   QhRRRR/# )r   rp   r%   r   dictr   )r   s   "r   r    r       s        r   c           	         \         P                  ! \        R RR\        RV /^R7      p VP	                  4       pVP                  ^8w  g   RV9  d   \        R4      hV#   \
         d    / p L4i ; i)
grant_typerp   	client_id)datar]   rq   zDFailed to refresh fal auth token. Please run `fal auth login` again.)httpxpostAUTH0_TOKEN_URLAUTH0_CLIENT_IDr   r4   status_coder8   )rp   response
token_datas   &  r   _refresh_access_tokenr      s    zz/]

 H]]_
 s"nJ&F%R
 	
   
s   A A.-A.c                   V ^8  d   QhRR/# r*   r   )r   s   "r   r    r       s      } r   c                    \        4       ;_uu_ 4        \        4       w  rRRR4       X '       g   R# X'       d   \        V4      '       g   V# \        V 4      pVP	                  RV 4      pVR,          p\        4       ;_uu_ 4        \        W44       RRR4       V#   + '       g   i     L; i  + '       g   i     T# ; i)z
Try to reuse tokens created by `fal auth login`.

We share the same file layout as fal-cli:
- refresh token on first line
- optional cached access token on second line
Nrp   rq   )re   rr   r   r   r2   r{   )rp   rq   r   new_refresh
new_accesss        r   _load_bearer_token_from_loginr      s     
&7&9# 
 4\BB&}5J..-@KN+J	;3 
 ! 
 
 s   BB.B+	.B?	c                   V ^8  d   QhRR/# )r   r   r;   r   )r   s   "r   r    r       s       r   c                    \         P                  P                  R4      R8H  p V '       g   \         P                  ! R4      ;p'       d   \	        RV4      # \         P                  ! R4      ;p'       d0   \         P                  ! R4      ;p'       d   \	        RV RV 24      # \        4       ;p'       d   \	        RV4      # \        4       ;p'       d   \	        RV4      # \        R	4      h)
z
Return credentials using this priority:
1) FAL_KEY / FAL_KEY_ID+FAL_KEY_SECRET / Colab secret (unless FAL_FORCE_AUTH_BY_USER=1)
2) Tokens saved by `fal auth login`
FAL_FORCE_AUTH_BY_USER1r.   Key
FAL_KEY_IDFAL_KEY_SECRET:Bearerz_No credentials found. Set FAL_KEY (or FAL_KEY_ID/FAL_KEY_SECRET) or login via `fal auth login`.)rS   environr2   rT   r;   r6   r   r8   )force_user_authkeykey_idfal_key_secretcolab_tokenbearers         r   fetch_auth_credentialsr      s     jjnn%=>#EO))I&&3&"5#..		,//f/ ii(899N9"5VHAn5E*FGG+--[-"5+66.00v0x00
!i r   c                   V ^8  d   QhRR/# r>   r   )r   s   "r   r    r       s      3 r   c                     \        4       p V P                  P                  4       R8w  d   \        R4      hV P                  # )z
Legacy helper kept for backwards compatibility.

It only returns Key-based credentials; user-based auth (Bearer) will raise
MissingCredentialsError so callers don't accidentally send it as a key.
r   zFKey credentials not found. Set FAL_KEY (or FAL_KEY_ID/FAL_KEY_SECRET).)r   r<   lowerr8   r5   )auths    r   fetch_credentialsr      s=     "#D{{e#%T
 	
 ::r   )-
__future__r   r   r   rS   r   
contextlibr   dataclassesr   pathlibr   	threadingr   typingr   r   r
   r/   r(   r6   r4   r8   r;   r   r2   rL   rM   AUTH0_DOMAINr   r   rh   r_   homerU   rW   re   rr   r{   r   r   r   r   r   r   r   r   r   <module>r      s   "   	  % !    * *  !#,	i 	 $4 4 4 zz~~ni8ZZ^^$8F<.:QR \N,74# ! 99;' O  "7")
/# /086r   