+
    „WÝjµ  ã                  ó  € R t ^ RIHt ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RI	t
]! 0 Rm4      tR R lt]P                  ! ]4      tR R ltR R	 ltR
 R ltR R ltRR R llt]P,                  ! 4       tR R ltR R ltR R ltR# )u*  Endpoint resolution for llamacpp-alias requests (provider integration).

``provider: llamacpp`` with no explicit base_url resolves, in order, to the managed server (state
file), a detected external llama-server, or â€” during a backend boot race â€” the managed server once
its state file appears.
)Úannotations)ÚsuppressNc               ó    € V ^8„  d   QhRRRR/# )é   Úmodel_idÚstrÚreturn© )Úformats   "ÚUC:\Users\johnn\AppData\Local\hermes\hermes-agent\hermes_cli\local_runtime\endpoint.pyÚ__annotate__r      s   € ÷ 	5ñ 	5˜#ð 	5 #ñ 	5ó    c                ó&   € ^ RI Hp RV! V 4       R2# )a`  Query string for a status read of one router child (``/props``, ``/slots``, ``/metrics``).

The router loads an unloaded model for any request that names it (``--models-autoload``), so a
status read right after an Eject or an idle unload would load the model straight back.
``autoload=false`` makes the router answer 400 "model is not loaded" instead.
)Úquotezmodel=z&autoload=false)Úurllib.parser   )r   r   s   & r   Úchild_queryr      s   € õ #à‘E˜(“OÐ$ OÐ4Ð4r   c               ó    € V ^8„  d   QhRRRR/# )r   ÚpidÚintr   Úboolr	   )r
   s   "r   r   r   "   s   € ÷ 	ñ 	�Cð 	˜Dñ 	r   c                óº   € V '       d   V ^ 8  d   R# \        \        4      ;_uu_ 4        ^ RIpVP                  V 4      uuRRR4       #   + '       g   i     R# ; i)uµ   Liveness for the state file's supervisor-child pid: psutil when available, else True
(optimistic). On Windows ``os.kill(pid, 0)`` TERMINATES the process â€” never use it as a probe.FNT)r   Ú	ExceptionÚpsutilÚ
pid_exists)r   r   s   & r   Ú
_pid_aliver   "   s@   € ÷ �#˜”'ÙÜ	”)×	Õ	Ûà× Ñ  Ó%÷ 
×	×	Ñ	ñ ús   ©A	Á	A	c               ó   € V ^8„  d   QhRR/# )r   r   údict | Noner	   )r
   s   "r   r   r   .   s   € ÷ Gñ G˜ñ Gr   c                 ó  € ^ RI Hp HpHpHp V! 4       pVP                  RR4      p\        V\        4      '       d	   V'       g   R# V ! V4      '       d   V! V4      f   R# MV! V4      f   R# RVRVP                  RR4      /# )é    )Ú	is_modernÚlegacy_recorded_processÚ
read_stateÚrecorded_processÚbase_urlÚ NÚapi_key)Ú!hermes_cli.local_runtime.recoveryr   r    r!   r"   ÚgetÚ
isinstancer   )r   r    r!   r"   Ústater#   s         r   Ú_state_endpointr*   .   s   € ÷ó ñ ‹L€EØ�y‰y˜ RÓ(€HÜ�h¤×$Ò$¯HÙÙ�×ÒÙ˜EÓ"Ò*Ùð +ñ # 5Ó)Ò1ÙØ˜ )¨U¯Y©Y°yÀ"Ó-EÐFÐFr   c               ó   € V ^8„  d   QhRR/# )r   r   ztuple[str, str] | Noner	   )r
   s   "r   r   r   C   s   € ÷ ñ Ð,ñ r   c            	     óR  € \        \        4      ;_uu_ 4        \        4       p V f    RRR4       R# \        V P	                  RR4      4      P                  R^4      ^ ,          pV'       d   V\        V P	                  RR4      4      3MRuuRRR4       #   + '       g   i     R# ; i)a  (base_root, api_key) of the managed router, or None. Resolved through the
ownership-guarded reader, not a raw state-file read: on the shared stable port a foreign
install's server answers /health for anyone, and a raw read would attach callers to someone
else's server.Nr#   r$   z/v1r%   )r   r   r*   r   r'   Úrsplit)r)   Úbases     r   Úmanaged_rootr/   C   s€   € ô
 
”)×	Õ	ÜÓ!ˆØŠ=Ø÷ 
Ñ	ô �5—9‘9˜Z¨Ó,Ó-×4Ñ4°U¸AÓ>¸qÕAˆß8<�”c˜%Ÿ)™) I¨rÓ2Ó3Ñ4À$÷ 
×	×	Ñ	ñ ús   ˜B²ABÂB&	c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r   r.   r   r%   ÚrouteÚ	timeout_sÚfloatr   Úobjectr	   )r
   s   "r   r   r   Q   s/   € ÷ $ñ $˜3ð $¨ð $°Sð $ÀUð $Èvñ $r   c                ó,  € \         P                  P                  V  V 2RRV 2/R7      p\         P                  P                  WCR7      ;_uu_ 4       p\        P
                  ! VP                  4       4      uuRRR4       #   + '       g   i     R# ; i)zUAuthenticated GET against the managed router; raises on any transport/decode failure.ÚAuthorizationzBearer )Úheaders)ÚtimeoutN)ÚurllibÚrequestÚRequestÚurlopenÚjsonÚloadsÚread)r.   r%   r1   r2   ÚreqÚrs   &&&&  r   Úmanaged_get_jsonrB   Q   sq   € ä
�.‰.×
 Ñ
  D 6¨%¨Ð!1Ø*9¸WÀWÀIÐ;NÐ)Oð !ó Q€Cä	�‰×	Ñ	 Ð	×	7Ô	7¸1Ü�zŠz˜!Ÿ&™&›(Ó#÷ 
8×	7×	7Ó	7ús   Á$BÂB	c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úconfigr   Úwait_for_boot_sr3   r   r	   )r
   s   "r   r   r   Y   s#   € ÷ ñ  kð Ø/4ðØ?Jñr   c                óz  € \        4       pV'       d   V# ^ RIHp T ;'       g    / P                  R4      ;'       g    / P                  R4      ;'       g    . pT! \        ;QJ d    . R V 4       F  NK  	  5M! R V 4       4      R7      pV'       d#   VP
                  '       g   RVP                  RR/# V^ 8”  d   \        V 4      '       dn   \        V 4       \        P                  ! 4       V,           p\        P                  ! 4       V8  d-   \        P                  ! R	4       \        4       pV'       g   KD  V# R
# )u  Managed-first, detection-second endpoint for llamacpp aliases.

Boot-race rung: on a fresh backend start there is NO state file yet â€” the lifespan boot thread
is still spawning the server (â‰ˆ1-3 s) while the desktop's readiness probe fires the moment the
WebSocket connects.
)Údetect_serverÚlocal_runtimeÚdetect_portsc              3  ó8   "  € T F  p\        V4      x € K  	  R # 5i)N)r   )Ú.0Úps   & r   Ú	<genexpr>Ú,resolve_llamacpp_endpoint.<locals>.<genexpr>h   s   é € Ð)@¹%°Q¬#¨a¯&¨&»%ùs   ‚)Úextra_portsr#   r%   r$   g      Ð?N)r*   Úhermes_cli.local_runtime.detectrG   r'   ÚtupleÚauth_requiredr#   Ú_boot_in_flightÚ_kick_managed_bootÚtimeÚ	monotonicÚsleep)rD   rE   ÚmanagedrG   ÚportsÚhitÚdeadlines   &&     r   Úresolve_llamacpp_endpointr\   Y   sç   € ô Ó€GßØˆå=à�lˆl˜×Ñ Ó0×6Ð6°B×;Ñ;¸NÓK×QÐQÈr€EÙ
§E¤EÑ)@¹%Ó)@§E¡EÑ)@¹%Ó)@Ó$@Ô
A€Cß
�3×$×$Ð$Ø˜CŸL™L¨)°RÐ8Ð8à˜Ôœ¨v×6Ò6Ü˜6Ô"Ü—>’>Ó# oÕ5ˆÜ�nŠnÓ Ô)Ü�JŠJ�tÔÜ%Ó'ˆGß‰wØ�Ùr   c               ó    € V ^8„  d   QhRRRR/# )r   rD   r   r   r	   )r
   s   "r   r   r   z   s   € ÷ ñ  ð °ñ r   c                ó(   € V e   V # ^ RI Hp V! 4       # )N)Úload_config)Úhermes_cli.configr_   )rD   r_   s   & r   Ú_load_config_if_nonera   z   s   € ØÒØˆÝ-á‹=Ðr   c               ó    € V ^8„  d   QhRRRR/# )r   rD   r   r   ÚNoner	   )r
   s   "r   r   r   ‚   s   € ÷ Bñ B˜{ð B¨tñ Br   c                ó’   a € \         P                  RR7      '       g   R# R V 3R llp^ RIHp V! VRR7      P	                  4        R# )	u¦   Actively start the managed server when resolution finds it missing â€” the wait loop assumes
some OTHER thread is bringing it up, which is true only at backend start.F)ÚblockingNc               ó   € V ^8„  d   QhRR/# )r   r   rc   r	   )r
   s   "r   r   Ú(_kick_managed_boot.<locals>.__annotate__ˆ   s   € ÷ !ñ !�4ñ !r   c                 óâ   <€  ^ RI Hp  V ! \        S4      4       \        P                  4        R#   \         d    \        P                  RRR7        L:i ; i  \        P                  4        i ; i)r   )Úensure_local_runtimez$on-demand managed-server boot failedT)Úexc_infoN)Ú"hermes_cli.local_runtime.bootstrapri   ra   r   ÚloggerÚwarningÚ
_KICK_LOCKÚrelease)ri   rD   s    €r   Ú_bootÚ!_kick_managed_boot.<locals>._bootˆ   sZ   ø€ ð	!ÝOá Ô!5°fÓ!=Ô>ô ×ÑÖ øô ô 	RÜ�N‰NÐAÈDˆNÖQð	Rûô ×ÑÕ ús!   ƒ0 °"AÁA ÁAÁA ÁA.)Úspawn_context_threadzlr-on-demand-boot)Úname)rn   ÚacquireÚagent.memory_providerrr   Ústart)rD   rp   rr   s   f  r   rT   rT   ‚   sA   ø€ ô ×Ñ uÐ×-Ò-Ù÷!ð !õ ;ñ ˜Ð%8Ô9×?Ñ?ÖAr   c               ó    € V ^8„  d   QhRRRR/# )r   rD   r   r   r   r	   )r
   s   "r   r   r   ˜   s   € ÷ 	ñ 	˜Kð 	¨Dñ 	r   c                ó`  € \        \        4      ;_uu_ 4        \        V 4      ;'       g    / P                  R4      ;'       g    / pVP                  R4      '       g    RRR4       R# ^ RIHp T! VP                  R4      ;'       g    R4      RJuuRRR4       #   + '       g   i     R# ; i)zJTrue when the managed runtime is enabled and PM holds an installed engine.rH   ÚenabledNF)Úinstalled_engineÚbackendÚauto)r   r   ra   r'   Ú!hermes_cli.local_runtime.binariesrz   )rD   Úsectionrz   s   &  r   rS   rS   ˜   s„   € ä	”)×	Õ	Ü'¨Ó/×5Ð5°2×:Ñ:¸?ÓK×QÐQÈrˆØ�{‰{˜9×%Ò%Ø÷ 
Ñ	õ 	Gá §¡¨IÓ 6× @Ð @¸&ÓAÈÐM÷ 
×	×	Ñ	ñ ús#   ˜+BÁBÁBÁ)BÂ	BÂB-	>   Úllamacppú	llama-cppú	llama.cpp)Ng       @)Ú__doc__Ú
__future__r   Ú
contextlibr   r=   ÚloggingÚ	threadingrU   Úurllib.requestr9   Ú	frozensetÚLLAMACPP_ALIASESr   Ú	getLoggerÚ__name__rl   r   r*   r/   rB   r\   ÚLockrn   ra   rT   rS   r	   r   r   Ú<module>r�      s|   ðñõ #å Û Û Û Û Û áÒCÓDÐ õ	5ð 
×	Ò	˜8Ó	$€õ	õGõ*õ$÷ð< �^Š^Ó€
õõB÷,	r   