+
    iHàj@  ã                  óâ   € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIHtHtH	t	 ]P                  ! 4       tRtR R ltR R ltR R	 ltR
 R lt]P"                  R R l4       tR R lt ! R R4      tR# )a'  Prompt-reading progress from llama-server.

llama-server reads a long prompt for minutes before it writes the first token. Asked with
``return_progress``, it streams a progress chunk after each batch it reads. Hermes uses those
chunks as signs of life: the stall timers stay quiet while the server works, and the router
notices a client hang-up within seconds (it only checks the client socket when it writes).

Compression also leaves the time the server spends reading the prompt out of its total time
limit (``conversation_compression_deadline``).
)ÚannotationsN)ÚAnyÚCallableÚOptionalc               ó    € V ^8„  d   QhRRRR/# )é   Úkwargszdict[str, Any]Úreturn© )Úformats   "Ú@/home/ubuntu/.hermes/hermes-agent/agent/local_prompt_progress.pyÚ__annotate__r      s   € ÷ ,ñ , ð ,°Nñ ,ó    c                óž   € V P                  R4      p\        V\        4      '       d   \        V4      M/ pVP                  RR4       / V CRV/C# )zTCopy of chat-completions *kwargs* that asks llama-server for prompt progress chunks.Ú
extra_bodyÚreturn_progressT)ÚgetÚ
isinstanceÚdictÚ
setdefault)r   r   Úmergeds   &  r   Úwith_prompt_progressr      sK   € à—‘˜LÓ)€JÜ!+¨J¼×!=Ò!=ŒT�*ÔÀ2€FØ
×ÑÐ'¨Ô.Ø+ˆfÐ+�l FÑ+Ð+r   c               ó    € V ^8„  d   QhRRRR/# )r   Úchunkr   r	   zOptional[dict]r
   )r   s   "r   r   r       s   € ÷ ñ ˜3ð  >ñ r   c                ó  € \        V RR4      p\        V\        4      '       d   VP                  R4      MRpVf(   \        V \        4      '       d   V P                  R4      p\        V\        4      '       g   R# \        V RR4      pVf(   \        V \        4      '       d   V P                  R4      pT;'       g    .  FÂ  p\        V\        4      '       d   VP                  R4      M\        VRR4      p\        V\        4      '       d   VP                  R4      M\        VRR4      pV'       d    R# \         FB  p\        V\        4      '       d   VP                  V4      M\        WgR4      pV'       g   K@    R# 	  KÄ  	  V# )zïThe ``prompt_progress`` payload of a progress-only chunk, else None.

A progress chunk carries an empty assistant delta. A chunk with text, tool calls, reasoning or a
finish reason is a real chunk even if a server attaches progress to it.
Úmodel_extraNÚprompt_progressÚchoicesÚfinish_reasonÚdelta)Úgetattrr   r   r   Ú_CONTENT_FIELDS)	r   ÚextraÚprogressr   ÚchoiceÚfinishr   ÚfieldÚvalues	   &        r   r   r       s1  € ô �E˜=¨$Ó/€EÜ/9¸%Ä×/FÒ/Fˆu�y‰yÐ*Ô+ÈD€HØÒœJ u¬d×3Ò3Ø—9‘9Ð.Ó/ˆÜ�h¤×%Ò%ÙÜ�e˜Y¨Ó-€GØ‚œ: e¬T×2Ò2Ø—)‘)˜IÓ&ˆØ—-�-˜R’-ˆÜ0:¸6Ä4×0HÒ0H�—‘˜OÔ,ÌgÐV\Ð^mÐosÓNtˆÜ'1°&¼$×'?Ò'?�—
‘
˜7Ô#ÄWÈVÐU\Ð^bÓEcˆßÚß$ˆEÜ(2°5¼$×(?Ò(?�E—I‘I˜eÔ$ÄWÈUÐ[_ÓE`ˆEß‰uÛó %ñ  ð €Or   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r#   r   ÚkeyÚstrr	   úOptional[int]r
   )r   s   "r   r   r   ;   s!   € ÷ ñ �Tð  ð ¨ñ r   c                ó`   €  \        W,          4      #   \        \        \        3 d     R # i ; i)N)ÚintÚKeyErrorÚ	TypeErrorÚ
ValueError)r#   r)   s   &&r   Ú_countr1   ;   s-   € ðÜ�8•=Ó!Ð!øÜ”i¤Ð,ô Úðús   ‚ “-¬-c               ó    € V ^8„  d   QhRRRR/# )r   r#   r   r	   r+   r
   )r   s   "r   r   r   B   s   € ÷ 	<ñ 	< dð 	<¨}ñ 	<r   c           
     ó.  €  \        V P                  R4      ;'       g    ^ 4      p\        V P                  R4      ;'       g    ^ 4      pT^ 8:  d   R# \	        ^ \        ^d\        Y!,          ^d,          4      4      4      #   \        \        3 d     R# i ; i)zOShare of the prompt the server has read, 0-100, or None without a usable total.ÚtotalÚ	processedN)r-   r   r/   r0   ÚmaxÚminÚround)r#   r4   r5   s   &  r   Úprompt_progress_percentr9   B   sƒ   € ðÜ�H—L‘L Ó)×.Ð.¨QÓ/ˆÜ˜Ÿ™ [Ó1×6Ð6°QÓ7ˆ	ð �„zÙÜˆq”#�cœ5 Õ!2°SÕ!8Ó9Ó:Ó;Ð;øô	 ”zÐ"ô Úðús   ‚A? Ÿ#A? ÁA? Á?BÂBc               ó   € V ^8„  d   QhRR/# )r   Úhookú!Optional[Callable[[float], None]]r
   )r   s   "r   r   r   O   s   € ÷ !ñ !Ð?ñ !r   c              #  ó†   "  € \        \        RR4      pV \        n         Rx € V\        n        R#   T\        n        i ; i5i)zSInstall ``hook(seconds)`` for this thread; it hears each stretch of prompt reading.r;   N)r    Ú_readingr;   )r;   Úpreviouss   & r   Úprompt_reading_hookr@   N   s2   é € ô ”x ¨Ó.€HØ„H„Mð!Ûà ŒŽø˜Œ�üs   ‚A 1 ¤A±>¾Ac               ó   € V ^8„  d   QhRR/# )r   r	   r<   r
   )r   s   "r   r   r   Y   s   € ÷ +ñ +Ð%Fñ +r   c                 ó$   € \        \        RR4      # )zIThis thread's prompt-reading hook (carried into provider daemon threads).r;   N)r    r>   r
   r   r   Úcurrent_prompt_reading_hookrC   Y   s   € ä”8˜V TÓ*Ð*r   c                  ó2   € ] tR t^^tRtR R ltR R ltRtR# )ÚPromptReadingClocka�  Time llama-server spends reading the prompt.

Counted per progress chunk, and only when the server reports more tokens read than before: a
server that keeps reporting without reading anything gets no extra time. Each stretch is the
smaller of the wall time since the previous chunk and the server's own reading time, so time
spent queued or loading the model before the reading starts doesn't count.
c               ó   € V ^8„  d   QhRR/# )r   ÚstartedÚfloatr
   )r   s   "r   r   ÚPromptReadingClock.__annotate__g   s   € ÷ ñ  ñ r   c                	ó<   € Wn         RV n        ^ V n        RV n        R# )é   ç        Néÿÿÿÿ©Ú_markÚ
_processedÚ
_server_msÚseconds)ÚselfrG   s   &&r   Ú__init__ÚPromptReadingClock.__init__g   s   € ØŒ
ØˆŒØˆŒØˆŽr   c               ó    € V ^8„  d   QhRRRR/# )r   r#   r   r	   Úboolr
   )r   s   "r   r   rI   m   s   € ÷ ñ ˜Tð  dñ r   c                ó¾  € \         P                  ! 4       pW P                  ,
          Vuq0n        \        VR4      \        VR4      rTVe   W@P                  8:  d   R# Vf   TMWPP
                  ,
          R,          pYEf   V P
                  MTuV n        V n        \        R\        W64      4      pV ;P                  V,          un        \        4       pVe	   V! V4       R# )zTCount the reading up to this progress chunk; False when it reports nothing new read.r5   Útime_msFiè  rL   T)
ÚtimeÚ	monotonicrO   r1   rP   rQ   r6   r7   rR   rC   )	rS   r#   ÚnowÚwallr5   Ú	server_msÚserverÚspentr;   s	   &&       r   ÚtickÚPromptReadingClock.tickm   s²   € ä�nŠnÓˆØ§¡Õ+¨SÐˆŒjÜ% h°Ó<¼fÀXÈyÓ>Y�9ØÒ 	¯_©_Ô <ÙØ"Ò*‘°¿_¹_Õ1LÐPTÕ0TˆØ+4ÒIZ°d·o²oÐ`iÐ(ˆŒ˜œÜ�Cœ˜TÓ*Ó+ˆØ�Š˜Õ�Ü*Ó,ˆØÒÙ�ŒKÙr   rN   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rT   ra   Ú__static_attributes__r
   r   r   rE   rE   ^   s   † ñõ÷ñ r   rE   )ÚcontentÚ
tool_callsÚreasoning_contentÚ	reasoningÚrefusal)rg   Ú
__future__r   Ú
contextlibÚ	threadingrZ   Útypingr   r   r   Úlocalr>   r!   r   r   r1   r9   Úcontextmanagerr@   rC   rE   r
   r   r   Ú<module>rt      sl   ðñ	õ #ã Û Û ß *Ñ *à�?Š?Ó€àX€õ,õõ6õ	<ð ×Ñô!ó ð!õ+÷
ó r   