+
    iHàjÁ  ã                  óª   € R t ^ RIHt ^ RIHtHtHt RtRtR R lt	R R lt
R R	 ltRR R lltRR R lltR R ltR R ltR R ltRR R lltR
# )a§  Credential ownership for ``providers:`` entries whose pool slug is also a built-in's pool id.

``providers.deepseek`` pools under the slug ``deepseek``, which ``load_pool`` also seeds from the
built-in DeepSeek provider's env vars and auth files. Those rows are the built-in's accounts. Every
acquisition of a pool for the custom entry's runtime (main, frozen and auxiliary resolution, a
URL-matched bare ``custom`` route, restoring the primary after a fallback, a delegated child's pool)
takes the entry-scoped view from here, so the built-in's account never stands in for the entry's
declared credential. The built-in provider itself still loads, and persists, the whole pool.
)Úannotations)ÚAnyÚCallableÚOptionalÚcustom_entryc               ó    € V ^8„  d   QhRRRR/# )é   Úentryr   ÚreturnÚbool© )Úformats   "Ú</home/ubuntu/.hermes/hermes-agent/agent/custom_entry_pool.pyÚ__annotate__r      s   € ÷ oñ o Sð o¨Tñ oó    c                ó  a € \        S \        4      '       d   RS 9   d   \        S R,          4      # \        S \        4      ;'       dC    \        ;QJ d#    V 3R l\         4       F  '       g   K   R# 	  R# ! V 3R l\         4       4      # )z¶Whether a custom entry names its own credential (``api_key`` / ``key_env`` / ``key_cmd``). A
snapshot's provenance carries the verdict itself, since it never copies an inline secret.Údeclares_credentialc              3  óˆ   <"  € T F7  p\        SP                  V4      ;'       g    R 4      P                  4       x € K9  	  R# 5i©Ú N©ÚstrÚgetÚstrip©Ú.0Úkr	   s   & €r   Ú	<genexpr>Ú,entry_declares_credential.<locals>.<genexpr>   s4   øé € Ð*nÑTmÈq¬3¨u¯y©y¸«|×/AÐ/A¸rÓ+B×+HÑ+H×+JÐ+JÓTmùó
   ƒ!A¥ATF)Ú
isinstanceÚdictr   ÚanyÚ_DECLARED_CREDENTIAL_KEYS)r	   s   fr   Úentry_declares_credentialr$      se   ø€ ô �%œ×ÒÐ#8¸EÔ#AÜ�EÐ/Õ0Ó1Ð1Ü�eœTÓ"×nÐn§s£sÔ*nÕTmÓ*n§s¤sÐn¢sÐn sÔ*nÕTmÓ*nÓ'nÐnr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úrowr   r	   r
   r   r   )r   s   "r   r   r      s!   € ÷ :ñ :˜Cð :¨ð :°ñ :r   c                óì   a€ ^ RI Hp \        \        V RR4      ;'       g    R4      P	                  4       pV3R lR 4        Uu0 uF  qD'       g   K  RV 2kK  	  ppV! V4      ;'       g    W59   # u upi )z¼Ownership by provenance: ``hermes auth add`` (manual) rows, and rows seeded from the entry's
own ``key_env``. Rows the built-in seeded from its registry env vars or auth files are foreign.)Ú_is_manual_sourceÚsourcer   c              3  óˆ   <"  € T F7  p\        SP                  V4      ;'       g    R 4      P                  4       x € K9  	  R# 5ir   r   r   s   & €r   r   Ú%row_owned_by_entry.<locals>.<genexpr>!   s4   øé € Ð)nÑSmÈa¬#¨e¯i©i¸«l×.@Ð.@¸bÓ*A×*GÑ*G×*IÐ*IÓSmùr   zenv:)Úkey_envÚapi_key_env)Úagent.credential_poolr(   r   Úgetattrr   )r&   r	   r(   r)   ÚnameÚown_envs   &f    r   Úrow_owned_by_entryr2      so   ø€ õ 8Ü”˜˜h¨Ó+×1Ð1¨rÓ2×8Ñ8Ó:€FÜ)nÑSmÔ)nÓwÑ)n ÓrvŒ}��d�V‹}Ñ)n€GÐwÙ˜VÓ$×9Ð9¨Ñ(9Ð9ùò xs   Á	A1Á	A1c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Úpoolr   Úpool_keyr   r	   úOptional[dict[str, Any]]r
   r   )r   s   "r   r   r   %   s*   € ÷ ñ ˜Cð ¨3ð Ð7Oð ÐTWñ r   c                óœ  € ^ RI HpHp V e<   \        T;'       g    R4      P	                  V4      '       g   \        V4      '       g   V # V P                  4       pV Uu. uF  p\        Wb4      '       g   K  VNK  	  pp\        V4      \        V4      8X  d   V # V'       g   R# V! V P                  V4      pV P                  Vn
        V# u upi )a¿  The rows of ``pool`` the custom ``entry`` owns: the pool itself when it owns them all, else a
view of them, or None when it owns none. ``custom:<name>`` pools are seeded from the entry's own
config and stay whole; so does any pool for an entry that declares no credential (as before).

The view shares the loaded rows and token baselines, so persisting it merges into the stored
pool under its lock and leaves the built-in's omitted rows on disk.
)ÚCUSTOM_POOL_PREFIXÚCredentialPoolNr   )r.   r8   r9   r   Ú
startswithr$   Úentriesr2   ÚlenÚproviderÚ_persisted_token_pairs)	r4   r5   r	   r8   r9   Úrowsr&   ÚownedÚviews	   &&&      r   Úentry_scoped_poolrB   %   s§   € ÷ IØ‚|”s˜8Ÿ>˜> rÓ*×5Ñ5Ð6H×IÒIÔQjÐkp×QqÒQqØˆØ�<‰<‹>€DÙ ÓC™D�SÔ$6°s×$B�SˆS™D€EÐCÜ
ˆ5ƒz”S˜“YÔØˆßÙÙ˜$Ÿ-™-¨Ó/€DØ"&×"=Ñ"=€DÔØ€Kùò Ds   ÁC	Á6C	Nc               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Úbase_urlúOptional[str]Úprovider_nameÚconfigúOptional[dict]r
   ú$Optional[tuple[str, dict[str, Any]]]r   )r   s   "r   r   r   ;   s2   € ÷ @ñ @Øð@Ø,9ð@ØJXð@à)ñ@r   c                ó&  aa€ ^ RI Ho V '       g   R# SP                  V 4      o\        W4      ;pe;   SP                  V^,          P	                  R4      4      pV'       d
   VS8w  d   R# T# \        VV3R lSP                  V4       4       R4      # )zü``(normalized_name, entry)`` of the configured custom entry that owns ``base_url``: by name
first (a named entry's pool never serves another URL), else by URL. ``config`` is a frozen
route's config, whose entry owns the endpoint even after a live edit.©Úcredential_poolNrD   c              3  ó�   <"  € T F;  w  rS'       g   K  SP                  VP                  R 4      4      S8X  g   K6  W3x € K=  	  R# 5i)rD   N)Ú	_norm_urlr   )r   ÚnÚeÚcpÚurls   &  €€r   r   Ú,custom_entry_for_endpoint.<locals>.<genexpr>H   s>   øé € ÐxÑ$E™D˜AÌ”ÐQS×Q]ÑQ]Ð^_×^cÑ^cÐdnÓ^oÓQpÐtwÑQw”�!•Ó$Eùs   ƒA”"A»A)ÚagentrL   rN   Únamed_custom_entryr   ÚnextÚ_iter_custom_providers)rD   rF   rG   ÚnamedÚ	entry_urlrQ   rR   s   &&&  @@r   Úcustom_entry_for_endpointrZ   ;   sz   ù€ õ ,ßÙØ
�,‰,�xÓ
 €CÜ# MÓ:Ð:ˆÒGØ—L‘L  q¥§¡¨jÓ!9Ó:ˆ	ß  Y°#Ô%5ˆtÐ@¸5Ð@ÜÕx B×$=Ñ$=¸fÔ$EÓxÐz~ÓÐr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   rF   rE   rG   rH   r
   rI   r   )r   s   "r   r   r   K   s'   € ÷ Tñ T mð T¸^ð TÐW{ñ Tr   c                ó¸   aa€ ^ RI Ho V '       d   SP                  V 4      M	\        4       oS'       d'   \	        VV3R lSP                  V4       4       R4      # R# )z_``(normalized_name, entry)`` of the configured custom entry ``provider_name`` names, else None.rK   c              3  ón   <"  € T F*  w  rSSP                  W4      ,          '       g   K%  W3x € K,  	  R # 5i©N)Ú_custom_entry_name_aliases)r   rO   rP   ÚaliasesrQ   s   &  €€r   r   Ú%named_custom_entry.<locals>.<genexpr>O   s0   øé € ÐwÑ$E™D˜AÈÐSU×SpÑSpÐqrÓSv×IvÑIv”�!•Ó$Eùs   ƒ"5ª5N)rT   rL   Ú_requested_custom_name_aliasesÚsetrV   rW   )rF   rG   r`   rQ   s   &&@@r   rU   rU   K   sS   ù€ å+ßBOˆb×/Ñ/°Ô>ÔUXÓUZ€G÷ CJŒ4Õw B×$=Ñ$=¸fÔ$EÓwÐy}Ó~ð  Tð  PTð  Tr   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   r=   rE   r5   r   ÚloadzCallable[[str], Any]r
   r   r   )r   s   "r   r   r   R   s0   € ÷ Jñ J Mð J¸Sð JÐH\ð JÐadñ Jr   c                ó  € V! V4      pVeG   \        T ;'       g    R4      P                  4       P                  4       P                  R4      '       g   V# \	        V 4      p\        Y1V'       d   V^,          4      # R4      # )a
  ``load(pool_key)`` for an auxiliary pool read (the key peek, credential recovery). A pinned
``custom:<name>`` normalizes to its entry's slug, which may also be a same-named built-in's pool,
so it gets the entry-scoped view; a bare built-in name keeps its whole pool.Nr   zcustom:)r   r   Úlowerr:   rU   rB   )r=   r5   re   r4   Úmatchs   &&&  r   Úpool_for_aux_providerri   R   si   € ñ �‹>€DØ‚|œ3˜xŸ~˜~¨2Ó.×4Ñ4Ó6×<Ñ<Ó>×IÑIÈ)×TÒTØˆÜ˜xÓ(€EÜ˜T¿¨U°1­XÓIÐIÀDÓIÐIr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r=   rE   Úrequested_providerr
   ztuple[bool, Optional[str]]r   )r   s   "r   r   r   ]   s'   € ÷ [ñ [˜}ð [À-ð [ÐTnñ [r   c                ó@  a€ ^ RI Ho W3 Uu. uF4  p\        T;'       g    R4      P                  4       P	                  4       NK6  	  pp\
        ;QJ d    V3R lV 4       F  '       g   K   RM	  RM! V3R lV 4       4      pV\        V3R lV 4       R4      3# u upi )zZ``(is_custom, custom:<name> or None)`` for a runtime's provider / requested_provider pair.)r8   r   c              3  ó^   <"  € T F"  qR 8H  ;'       g    VP                  S4      x € K$  	  R# 5i)ÚcustomN©r:   ©r   Úvr8   s   & €r   r   Ú#_custom_identity.<locals>.<genexpr>a   s(   øé € ÐWÉJÀq�h‘×BÐB !§,¡,Ð/AÓ"BÔBËJùs   ƒ-“-TFc              3  óX   <"  € T F  qP                  S4      '       g   K  Vx € K!  	  R # 5ir^   ro   rp   s   & €r   r   rr   b   s   øé € ÐS¡J˜q·,±,Ð?Q×2RŸš£Jùs   ƒ* 
*N)r.   r8   r   r   rg   r"   rV   )r=   rk   rq   Ú
identitiesrn   r8   s   &&   @r   Ú_custom_identityru   ]   sz   ø€ å8Ø9AÑ8VÓWÑ8V°1”#�a—g�g˜2“,×$Ñ$Ó&×,Ñ,Ö.Ñ8V€JÐWß‹SÔWÉJÓW�S�SŠSÔWÉJÓWÓW€FØ”4ÔS¡JÓSÐUYÓZÐZÐZùò Xs
   �B 'Bc               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r=   rE   rk   rD   r
   r6   r   )r   s   "r   r   r   e   s4   € ÷ 	fñ 	f -ð 	fÀ]ð 	fÐ^kð 	fð  qIñ 	fr   c                óÆ   € \        W4      w  r4V'       d   \        W$4      ;pf   R# Vw  rgR Uu/ uF  qˆVP                  V4      bK  	  p	pRV/V	CR\        V4      /C# u upi )a  Credential provenance of the entry that owns a custom runtime, for its ``_primary_runtime``
snapshot: matched in the config the route runs on (the frozen scope, else the profile's), the way
resolution matched it. Names only, never a secret. None for a built-in or an unowned endpoint.Nr0   r   )Úprovider_keyrD   r,   r-   )ru   rZ   r   r$   )
r=   rk   rD   rn   r0   rh   Ú	norm_namer	   r   Ú
provenances
   &&&       r   Úruntime_entry_ownerr{   e   ss   € ô $ HÓA�L€FßÔ8¸ÓHÐH�eÒQÙØÑ€IÙ+aÓbÑ+a a�U—Y‘Y˜q“\’/Ñ+a€JÐbØ�IÐe ÐeÐ-BÔD]Ð^cÓDdÑeÐeùò cs   ¯Ac          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r   r=   rE   rD   rk   Úsnapshotr6   r
   r   r   )r   s   "r   r   r   q   s=   € ÷ `ñ `Øð`Ø'4ð`ØJWð`à&ð`ð 	ñ`r   c                óì  € ^ RI HpHpHp \	        W4      w  rxV'       g   V! W4      p	V	'       d	   V! V	4      # R# T;'       g    / P                  \        4      p
Ve   V'       d   V
'       g   R# V
'       d   V
R,          V
3M
\        W4      pV'       d)   V'       g	   V
'       d   V! V!  ;'       g    R.^ ,          MV! W4      p	V	'       d(   \        V! V	4      Y›'       d   V^,          4      # R4      # R# )a‘  The pool for a runtime snapshot's identity. A custom runtime (``custom`` or ``custom:<name>``)
is the entry's, so it gets the entry-scoped view; a built-in identity loads its whole pool.
Ownership and the pool key come from the runtime identity, never from the pool slug, which both
share: a ``custom:<name>`` identity keys on its own entry, not the first entry on its URL.

``snapshot`` is the ``_primary_runtime`` being restored: the owner it recorded wins over live
config, so an edit can't reassign the endpoint or drop the entry's declared credential. A named
identity whose snapshot recorded no owner gets None and keeps the snapshot's own credential.)Ú_pool_keys_for_custom_entryÚ	load_poolÚresolve_runtime_pool_keyNr0   r   )	r.   r   r€   r�   ru   r   ÚSNAPSHOT_OWNER_KEYrZ   rB   )r=   rD   rk   r}   r   r€   r�   rn   r0   ÚkeyÚownerrh   s   &&&&        r   Úload_runtime_poolr…   q   sÉ   € ÷ gÑfÜ# HÓA�L€FßÙ& xÓ:ˆß!$‰y˜‹~Ð.¨$Ð.Ø�^ˆ^˜× Ñ Ô!3Ó4€EØÒ§¯UÙß&+ˆU�6�]˜EÑ"Ô1JÈ8Ó1Z€Eß>CÏ×QVÑ&¨Ñ.×6Ð6°2°$¸Ö
:Ñ]uÐv~ó  ^J€CßRUÔ™Y s›^¨S¾e°%¸µ(ÓNÐ_ÈÓNÐ_Ð[_Ð_r   )Úapi_keyr,   r-   Úkey_cmd)NNr^   )Ú__doc__Ú
__future__r   Útypingr   r   r   r#   r‚   r$   r2   rB   rZ   rU   ri   ru   r{   r…   r   r   r   Ú<module>r‹      s[   ðñõ #ç *Ñ *àLÐ à#Ð õoõ:õ÷,@÷ TõJõ[õ	f÷`ñ `r   