+
    iHàj.  ã                   óš   € R 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Ht ]P                   ! ]4      t ! R R	4      tR# )
zCDisplay and heartbeat phase of the request-local streaming monitor.N)ÚSimpleNamespace)Úurlsplit)Úchat_completion_wait_notice)Úis_local_endpoint)Úis_loopback_host)Ú
SleepWatchc                   óz   a € ] tR t^t o V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R	 lR
 ltRt	V t
R# )ÚStreamingWaitMonitorc                ó&   <€ V ^8„  d   QhRS[ RS[/# ©é   ÚnowÚreturn©ÚfloatÚbool)ÚformatÚ__classdict__s   "€ÚI/home/ubuntu/.hermes/hermes-agent/agent/chat_completion_stream_monitor.pyÚ__annotate__Ú!StreamingWaitMonitor.__annotate__   s   ø€ ÷ ñ ©5ð ±Tñ ó    c                óÂ  € ^ RI Hp V P                  pV P                  V4      '       d   R# WP                  R,          ,
          R8  g   WP
                  ,
          R8  d   R# Wn        V! V P                  V P                  4      pVep   RVn        VP                  P                  4        V P                  P                  V4       V P                  P                  R4       R^ VuVn        Vn        Vn        R# VP                  '       dU   V;P                  ^,          un        VP                  ^8¼  d+   R^ uVn        Vn        V P                  P                  R	4       R# )
ad  Managed local server: surface a cold model's weight-load progress
instead of the 60s neutral "waiting on <model>" notice. Polled ~1s only while no
REAL chunk arrived for 2s+ (never during healthy token flow); in-memory,
no network. True while loading = heartbeat liveness, skip the rest of
this iteration (the stale detector's local floor dwarfs any load).)Ú_managed_local_load_noticeTÚtg       @ç      ð?FNzlocal model loadingÚ )Úagent.chat_completion_localr   Ú_monÚ_show_prompt_progressÚlast_chunk_timeÚlast_load_pollÚagentÚ
api_kwargsÚwait_notice_started_tsÚwait_noticeÚresetÚ_emit_wait_noticeÚ_touch_activityÚload_notice_shownÚload_notice_missesÚlast_heartbeat)Úselfr   r   ÚmÚ_load_notices   &&   r   Ú_poll_local_load_noticeÚ,StreamingWaitMonitor._poll_local_load_notice   s  € õ 	Kà�I‰IˆØ×%Ñ% c×*Ò*ÙØ×%Ñ% cÕ*Õ*¨SÔ0°C×:JÑ:JÕ4JÈSÔ4PÙØÔÙ1°$·*±*¸d¿o¹oÓNˆØÒ#Ø'+ˆAÔ$Ø�M‰M×ÑÔ!Ø�J‰J×(Ñ(¨Ô6Ø�J‰J×&Ñ&Ð'<Ô=ØJNÐPQÐSVÐGˆAÔ Ô!5°qÔ7GÙØ××Ðà× Ò  AÕ%Õ Ø×#Ñ# qÔ(Ø<AÀ1Ð9�Ô# QÔ%9Ø—
‘
×,Ñ,¨RÔ0Ùr   c                ó&   <€ V ^8„  d   QhRS[ RS[/# r   r   )r   r   s   "€r   r   r   /   s   ø€ ÷ ñ ©ð ±4ñ r   c                óÊ  € ^ RI Hp V P                  p\        V RR4      p\        \        V RR4      RR4      p\	        V\
        4      ;'       d    \        VP                  R4      4      pV'       d   VR,          f   R# V'       d?   VP                  '       d+   R^ uVn        Vn	        V P                  P                  R	4       R# WR
,          ,
          R8”  g   WP                  ,
          R8  d   R# Wn        V! VR,          4      pRVn        VP                  P                  4        V P                  P                  Ve   RV R2MR4       R^ VuVn        Vn	        Vn        R# )zàPrompt progress straight from the stream's own progress chunks (llama-server with
``return_progress``), at most once a second until the first token. Clears the line
when the first token arrives. True when it showed progress.)Úprompt_progress_percentÚprompt_progressNÚclientsÚdiagÚfirst_chunk_atÚprogressFr   r   ç      N@r   u   âš™ processing prompt â€” Ú%u   âš™ processing promptT)Úagent.local_prompt_progressr3   r   ÚgetattrÚ
isinstanceÚdictr   Úgetr)   r*   r"   r'   r!   r$   r%   r&   r+   )r,   r   r3   r-   Ústater6   Úfirst_tokenÚpercents   &&      r   r   Ú*StreamingWaitMonitor._show_prompt_progress/   s3  € õ 	Hà�I‰IˆÜ˜Ð/°Ó6ˆÜ”w˜t Y°Ó5°v¸tÓDˆÜ  ¤tÓ,×QÐQ´°d·h±hÐ?OÓ6PÓ1Qˆß˜˜jÕ)Ò1ÙßØ×"×"Ð"Ø<AÀ1Ð9�Ô# QÔ%9Ø—
‘
×,Ñ,¨RÔ0ÙØ�s•Õ˜dÔ" c×,<Ñ,<Õ&<¸sÔ&BÙØÔÙ)¨%°
Õ*;Ó<ˆØ#'ˆÔ Ø	�‰×ÑÔØ�
‰
×$Ñ$Ø7>Ò7JÐ(¨¨	°Ñ3ÐPgô	iàFJÈAÈsÐCˆÔ˜QÔ1°1Ô3CÙr   c                ó$   <€ V ^8„  d   QhRS[ RR/# )r   Úsleptr   N)r   )r   r   s   "€r   r   r   K   s   ø€ ÷ 
Zñ 
Z¡ð 
Z¨4ñ 
Zr   c                óŒ  € V^ 8:  d   R# \         P                   ! 4       p\        V P                  R,          V,           V4      V P                  R&   \        V P                  P                  V,           V4      V P                  n        \
        P                  RV4       V P                  P                  R\        V4       R24       R# )zôThe computer slept and froze this request with a server on the same machine: move the
stall clock past the sleep, so the request gets its full patience again after wake. Never
past now: a chunk can land between the sleep reading and this write.Nr   zQComputer slept for %.0fs during a model request; the stall timer skips that time.z%resumed after the computer slept for Ús)
ÚtimeÚminr    r   r+   ÚloggerÚinfor"   r(   Úint)r,   rE   r   s   && r   Ú_skip_sleepÚ StreamingWaitMonitor._skip_sleepK   s“   € ð �AŒ:ÙÜ�iŠi‹kˆÜ$'¨×(<Ñ(<¸SÕ(AÀEÕ(IÈ3Ó$Oˆ×Ñ˜SÑ!Ü#& t§y¡y×'?Ñ'?À%Õ'GÈÓ#Mˆ�	‰	Ô Ü�‰ÐgÐinÔoØ�
‰
×"Ñ"Ð%JÌ3ÈuË:È,ÐVWÐ#XÖYr   c                ó$   <€ V ^8„  d   QhRS[ RR/# )r   Úwaiting_secsr   N)rL   )r   r   s   "€r   r   r   W   s   ø€ ÷ hñ h¡sð h¨tñ hr   c                óÀ  € VR8¼  Ed7   V P                   pVe   V\        R4      8w  d   RW!,
          3MRp\        \        V RR4      RR4      p\        V\        4      '       d   VP                  R4      '       d   RMR	pV P                  P                  P                  WS4      '       g%   V P                  P                  R
V RV R24       R# V P                  P                  V P                  n        V P                  P                  \        P                  ! V P                   P                  RR4      WV4      4       R# V P                  P                  R
V R24       R# )ztGateway inactivity heartbeat: the start-to-first-chunk gap (thinking,
local prefill) can exceed the gateway timeout.r9   NÚinfzstream staler5   r6   r7   Ú
post_chunkÚfirst_chunkzwaiting for stream response (zs, Ú)Úmodelzthe providerzs, no chunks yet))Ú_stream_stale_timeoutr   r<   r=   r>   r?   r   r%   Úshould_emitr"   r(   r+   r$   r'   ÚwnÚwait_notice_textr#   )r,   rP   ÚstaleÚwatchdogr6   Úphases   &&    r   Ú
_heartbeatÚStreamingWaitMonitor._heartbeatW   s*  € ð ˜4Õð ×.Ñ.ˆEØAFÒARÐW\Ô`eÐfkÓ`lÔWl˜¨Õ(<Ñ=ÐrvˆHÜœ7 4¨°DÓ9¸6À4ÓHˆDÜ$.¨t´T×$:Ò$:¸t¿x¹xÐHX×?YÒ?Y‘LÐ_lˆEØ—9‘9×(Ñ(×4Ñ4°U×EÒEØ—
‘
×*Ñ*Ð-JÈ<È.ÐX[Ð\aÐ[bÐbcÐ+dÔeÙØ/3¯y©y×/GÑ/GˆD�I‰IÔ,Ø�J‰J×(Ñ(¬×)<Ò)<Ø—‘×#Ñ# G¨^Ó<¸lÐS[ó*]ö ^ð �J‰J×&Ñ&Ð)FÀ|ÀnÐTeÐ'fÖgr   c                ó   <€ V ^8„  d   QhRR/# )r   r   N© )r   r   s   "€r   r   r   k   s   ø€ ÷ #ñ #˜tñ #r   c           	     óT  € R p\        \        P                  ! 4       RR^ R\        P                  ! 4       R7      V n        \        V P                  P                  4      ;'       d     \        V P                  P                  4      pV P                  P                  '       dE   \        \        V P                  P                  4      P                  4      '       d   \        RR7      MRpV P                  P                  4       '       Eg!   V P                  P                  RR7       Ve    V P!                  VP#                  4       4       \        P                  ! 4       pV'       d   V P%                  V4      '       d   K–  V P                  P&                  e}   V P(                  R,          V P                  P&                  8”  dQ   V P                  P+                  R	4       RV P                  n        V P                  P,                  P/                  4        W@P                  P0                  ,
          V8¼  dB   W@P                  n        V P3                  \5        W@P(                  R,          ,
          4      4       \        P                  ! 4       V P(                  R,          ,
          pWPP6                  8”  dG   RV P                  n        V P                  P,                  P/                  4        V P9                  V4       V P                  P:                  '       g   EK.  V P=                  V4       R# R# )
g      >@g        FN)r+   r!   r)   r*   r$   r%   g333333Ó?)Úinterval)Útimeoutr   r   )r   rH   rY   ÚWaitNoticeStater   r   r"   Úbase_urlr   r   r   Úhostnamer   Ú
_call_doneÚis_setÚwaitrM   rE   r/   r$   r    r'   r%   r&   r+   r^   rL   rW   Ú_kill_stale_streamÚ_interrupt_requestedÚ_abort_for_interrupt)r,   Ú_HEARTBEAT_INTERVALÚ_is_local_baseÚsleep_watchÚ_hb_nowÚ_stale_elapseds   &     r   Ú_monitor_loopÚ"StreamingWaitMonitor._monitor_loopk   s(  € Ø"ÐÜ#ÜŸ9š9›;°sØ#¸ÐRVÜ×*Ò*Ó,ô
ˆŒ	ô
 ˜dŸj™j×1Ñ1Ó2×]Ð]Ô7HÈÏÉ×I\ÑI\Ó7]ˆà37·:±:×3F×3FÐ3FÜ+¬H°T·Z±Z×5HÑ5HÓ,I×,RÑ,R×SÒSô "¨3Õ/ØY]ð 	à—/‘/×(Ñ(×*Ó*Ø�O‰O× Ñ ¨Ð Ô-ØÒ&Ø× Ñ  ×!2Ñ!2Ó!4Ô5Ü—i’i“kˆGß $×">Ñ">¸w×"GÒ"GÙð —	‘	×0Ñ0Ò<Ø×,Ñ,¨SÕ1°D·I±I×4TÑ4TÔTØ—
‘
×,Ñ,¨RÔ0Ø37�—	‘	Ô0Ø—	‘	×%Ñ%×+Ñ+Ô-ØŸ™×1Ñ1Õ1Ð5HÔHØ+2—	‘	Ô(Ø—‘¤ G×.BÑ.BÀ3Õ.GÕ$GÓ HÔIÜ!ŸYšY›[¨4×+?Ñ+?ÀÕ+DÕDˆNØ× :Ñ :Ô:Ø37�—	‘	Ô0Ø—	‘	×%Ñ%×+Ñ+Ô-Ø×'Ñ'¨Ô7Ø�z‰z×.×.Ó.Ø×)Ñ)¨.Ô9Ùñ1 +r   )r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r/   r   rM   r^   rs   Ú__static_attributes__Ú__classdictcell__)r   s   @r   r	   r	      s;   ø‡ € ÷ð ÷<ð ÷8
Zð 
Z÷hð h÷(#ö #r   r	   )Ú__doc__ÚloggingrH   Útypesr   Úurllib.parser   r"   r   rY   Úagent.model_metadatar   Úagent.proxy_bypassr   Úagent.sleep_clockr   Ú	getLoggerru   rJ   r	   ra   r   r   Ú<module>rƒ      s<   ðÙ Iã Û Ý !Ý !å 3Ý 2Ý /Ý (à	×	Ò	˜8Ó	$€÷~ó ~r   