+
    jHàjM  ã                  óz   € R t ^ RIHt ^ RIHtHt ^ RIHtH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# )zAFail-closed URL identity normalization for model/provider routes.)Úannotations)ÚAnyÚOptional)ÚurlsplitÚ
urlunsplitc               ó    € V ^8„  d   QhRRRR/# )é   Úbase_urlr   ÚreturnÚstr© )Úformats   "Ú>/home/ubuntu/.hermes/hermes-agent/hermes_cli/route_identity.pyÚ__annotate__r   	   s   € ÷ #ñ # sð #¨sñ #ó    c                óX  € \        T ;'       g    R4      pV'       g   R# \        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d   V# RVP                  R^4      ^ ,          9   p \        V4      pVP                  pVP
                  '       d	   V'       g   V# VP
                  P                  4       pRV9   d+   VP                  R^4      w  rgVP                  4        RV 2pMVP                  4       pVP                  p	TP                  P                  R^4      R,          p
T
P                  R	4      '       g   R
T9   d   R	T R2pT	e   YY3R9  d   T R
T	 2pRTP                  9   d)   TP                  P                  R^4      ^ ,           RT 2pTP                  pTP                  R4      '       d   T'       g   TRR p\        YXY³P                   R34      pT'       d   TP                   '       g
   TR,          pT#   \        \        3 d    Tu # i ; i)z<Canonicalize only proven-equivalent endpoint URL components.Ú c              3  ó>   "  € T F  p\        V4      ^ 8*  x € K  	  R# 5i)é    N)Úord)Ú.0Úchars   & r   Ú	<genexpr>Ú+normalize_route_base_url.<locals>.<genexpr>   s   é € Ð
-© Œ3ˆt‹9˜Ö«ùs   ‚TFÚ?Ú#Ú%Ú@Ú[Ú:Ú]NÚ/éÿÿÿÿ>   ©ÚhttpéP   ©Úhttpsi»  )r   ÚanyÚsplitr   ÚhostnameÚschemeÚlowerÚportÚ	TypeErrorÚ
ValueErrorÚnetlocÚrsplitÚ
startswithÚpathÚendswithr   Úquery)r	   ÚrawÚhad_query_delimiterÚparsedr*   r+   ÚaddressÚzoneÚhostr-   Ú
route_hostr3   Ú
normalizeds   &            r   Únormalize_route_base_urlr>   	   sÜ  € ä
ˆh�nˆn˜"Ó
€CßÙß
ƒsÑ
-©Ó
-‡s‡s‚sÑ
-©Ó
-×-Ò-Øˆ
Ø §¡¨3°Ó!2°1Õ!5Ñ5ÐðÜ˜#“ˆØ—?‘?ˆØ�}�}ˆ}§HØˆJØ—‘×$Ñ$Ó&ˆØ�(Œ?Ø$ŸN™N¨3°Ó2‰MˆGØ—m‘m“oÐ& a¨ vÐ.‰Dà—>‘>Ó#ˆDØ�{‰{ˆð —‘×%Ñ% c¨1Ó-¨bÕ1€JØ×Ñ˜S×!Ò! S¨D¤[Ø�4�&˜ˆ{ˆØÒ˜V˜NÐ2PÔPØ��q˜˜ÐˆØ
ˆf�m‰mÔØ—-‘-×&Ñ& s¨AÓ.¨qÕ1Ð2°!°D°6Ð:ˆØ�;‰;€DØ‡}�}�S×Ò×"5Ø�C�RˆyˆÜ˜V¨4·±¸rÐBÓC€Jß 6§<§< <Ø�cÕˆ
ØÐøô ”zÐ"ô ØŠ
ðús   Á90H Â*H Â,A'H ÈH)È(H)Nc               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Úproviderr   r	   Úconfigr
   zOptional[bool]r   )r   s   "r   r   r   /   s(   € ÷ $5ñ $5 #ð $5°ð $5¸cð $5È^ñ $5r   c                óÔ  € ^ RI HpHpHpHp ^ RIHp T! \        T;'       g    R4      4      pV'       g   R# \        T ;'       g    R4      P                  4       P                  4       p	V! V	4      p
V
R9   d   R# \        V\        4      '       d   TM/ pT! Y›P                  R4      ;'       g    / 4      ;'       g    V! W›P                  R4      4      pVe(   VP                  '       d   V! VP                  4      V8H  # V! V
RR	7      pVe,   VP                  '       d   V! VP                  4      V8X  d   R# Vf   Vf   R# ^ R
IHp V! \        V4      4      pVf   R# V! V4      V
8H  # )u.  Whether ``model.base_url`` is *provider*'s own endpoint.

``True``: the host is the provider's registry/plugin endpoint or the endpoint of a
``providers:``/``custom_providers:`` entry that resolves to *provider*, or *provider* is bare
``custom``/``local`` (the URL *is* the route). ``False``: the host is another known provider's
stock endpoint, or *provider* names a user entry with a different endpoint. ``None``: unknown
host (a proxy, a LAN server) â€” nothing here can say whose it is. Offline: the registry lookup
never fetches the models.dev catalog.
)Úget_providerÚnormalize_providerÚresolve_custom_providerÚresolve_user_provider)Úbase_url_hostnamer   NTÚ	providersÚcustom_providersF)Úallow_network)Ú_infer_provider_from_url)ÚcustomÚlocal)Úhermes_cli.providersrC   rD   rE   rF   ÚutilsrG   r   Ústripr,   Ú
isinstanceÚdictÚgetr	   Úagent.model_metadatarK   )r@   r	   rA   rC   rD   rE   rF   rG   r;   r6   Ú	canonicalÚcfgÚ	user_pdefÚpdefrK   Úinferreds   &&&             r   Úprovider_owns_routerZ   /   s>  € ÷ vÓuÝ'áœS § ¨RÓ0Ó1€DßÙÜ
ˆh�nˆn˜"Ó
×
#Ñ
#Ó
%×
+Ñ
+Ó
-€CÙ" 3Ó'€IØÐ'Ô'ñ Ü˜v¤t×,Ò,‰&°"€CÙ% c¯7©7°;Ó+?×+EÐ+EÀ2ÓF÷ *ð *ÑJaØ�W‰WÐ'Ó(óK*€IàÒ ×!3×!3Ð!3Ù  ×!3Ñ!3Ó4¸Ñ<Ð<Ù˜	°Ô7€DØÒ˜DŸMŸM˜MÑ.?ÀÇÁÓ.NÐRVÔ.VÙØ‚|˜	Ò)ÙÝ=Ù'¬¨H«Ó6€HØÒÙÙ˜hÓ'¨9Ñ4Ð4r   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Ú	model_cfgr   r@   rA   r
   ztuple[dict[str, Any], bool]r   )r   s   "r   r   r   V   s)   € ÷ ñ  cð °Sð À#ð ÐQlñ r   c                ón  € \        V \        4      '       g   / R3# \        V P                  R4      ;'       g    R4      P	                  4       pV'       d   \        WV4      MRpV'       d   / R3# Vf   / R3# R Uu/ uF+  qPP                  V4      R9  g   K  WPP                  V4      bK-  	  ppVR3# u upi )u[  Pop the route keys (``base_url``, ``api_mode``) a previous provider left in ``model:``
when the block is re-pointed at *provider* without a fresh route (``hermes config set
model.provider``). Mirrors what a persisted ``/model`` switch writes: the route is synced to
the target, never carried over. Returns ``(popped {key: old value}, unverified)`` where
``unverified`` is True when a base_url of unknown ownership was kept â€” the caller should say so.
A base_url that belongs to *provider* is kept together with its api_mode; with no base_url the
api_mode alone is wire state of the old route and goes.Fr	   r   T)r	   Úapi_mode)Nr   )rQ   rR   r   rS   rP   rZ   Úpop)r\   r@   rA   r	   ÚownedÚkÚpoppeds   &&&    r   Údrop_stale_model_routerc   V   s°   € ô �i¤×&Ò&Ø�5ˆyÐÜ�9—=‘= Ó,×2Ð2°Ó3×9Ñ9Ó;€Hß?GÔ °FÔ;ÈU€EßØ�5ˆyÐØ‚}Ø�4ˆxˆÙ+CÓjÑ+C aÇ}Á}ÐUVÓGWÐ_iÑGiÔ!ˆa—‘˜qÓ!Ò!Ñ+C€FÐjØ�5ˆ=Ðùò ks   Á;B2ÂB2c               ó4   € V ^8„  d   QhRRRRRRRRRRRRRR	/# )
r   Úconfigured_modelr   Úactive_modelÚconfigured_base_urlÚactive_base_urlÚconfigured_providerÚactive_providerr
   Úboolr   )r   s   "r   r   r   j   sB   € ÷ ñ ¨sð À#ð Ð\_ð Ðruð Ø25ðØHKðØPTñr   c                óð   € \        T ;'       g    R4      P                  4       p V '       d+   T \        T;'       g    R4      P                  4       8w  d   R#  ^ RIHp V! W#WE4      #   \         d     R# i ; i)zìTrue when a configured ``model.context_length`` pin no longer matches its runtime route.
Fail-closed: any error during route comparison returns ``True`` (drop the pin) so a stale window
never silently inflates the compression threshold.r   T)Ú_context_route_mismatch)r   rP   Úagent.agent_initrm   Ú	Exception)re   rf   rg   rh   ri   rj   rm   s   &&&&&& r   Úshould_clear_context_pinrp   j   sn   € ô
 Ð+×1Ð1¨rÓ2×8Ñ8Ó:ÐßÐ,´°L×4FÐ4FÀBÓ0G×0MÑ0MÓ0OÔOÙðÝ<Ù&Ð':ÐM`ÓrÐrøÜô Úðús   ÁA& Á&A5Á4A5c               ó    € V ^8„  d   QhRRRR/# )r   Úargsr   r
   rk   r   )r   s   "r   r   r   y   s   € ÷ Dñ D°ð D¸ñ Dr   c               ‡  óV   "  € ^ RI pVP                  ! \        .V O5!  G Rj  x€L
 #  L5i)uÏ   ``should_clear_context_pin`` on a worker thread so async gateway handlers never run it on the
event loop â€” the resolution chain is cache-only (``allow_network=False``) but can still do
cold-start disk I/O.N)ÚasyncioÚ	to_threadrp   )rr   rt   s   * r   Úshould_clear_context_pin_asyncrv   y   s'   é € ó Ø×"Ò"Ô#;ÐC¸dÓC×CÐCÑCùs   ‚ )¢'£))N)Ú__doc__Ú
__future__r   Útypingr   r   Úurllib.parser   r   r>   rZ   rc   rp   rv   r   r   r   Ú<module>r{      s-   ðÙ Gå "ç  ß -õ#÷L$5÷Nõ(÷Dr   