+
    iHàj  ã                   ó6   € R t ^ RIHt ^ RIHt  ! R R4      tR# )z\Streamed tool-call delta assembly for the chat-completions stream (and Relay's accumulator).)ÚOptional)Úfieldc                   ór   a € ] tR t^t o RtR 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# )Ú_ToolCallAccumulatora"  Assemble streamed tool-call deltas into complete ``tool_calls`` entries
(``acc``: slot index -> entry dict). Ollama-compatible endpoints reuse index 0
for every call in a parallel batch, distinguishing them only by id, so a new
id at an already-seen raw index is redirected to a fresh slot.c                ój   € / V n         \        4       V n        / V n        / V n        / V n        / V n        R # )N)ÚaccÚsetÚ	_notifiedÚ_last_id_at_idxÚ_active_slot_by_idxÚ_argument_partsÚ	_arg_scan)Úselfs   &ÚM/home/ubuntu/.hermes/hermes-agent/agent/chat_completion_helpers_tool_calls.pyÚ__init__Ú_ToolCallAccumulator.__init__   s3   € ØˆŒÜ!›eˆŒØ%'ˆÔØ)+ˆÔ ð 68ˆÔà+-ˆŽó    c                ó    <€ V ^8„  d   QhRS[ /# ©é   Úreturn)Údict)ÚformatÚ__classdict__s   "€r   Ú__annotate__Ú!_ToolCallAccumulator.__annotate__   s   ø€ ÷ ñ ™Tñ r   c                ó¸   € V P                   P                  4        F1  w  rRP                  V4      V P                  V,          R,          R&   K3  	  V P                  # )z[Join buffered argument deltas into each entry's ``arguments``; idempotent. Returns ``acc``.Ú ÚfunctionÚ	arguments)r   ÚitemsÚjoinr   )r   ÚidxÚpartss   &  r   ÚmaterializeÚ _ToolCallAccumulator.materialize   sE   € à×.Ñ.×4Ñ4Ö6‰JˆCØ57·W±W¸U³^ˆD�H‰H�S�M˜*Õ% kÓ2ñ 7à�x‰xˆr   c                ó&   <€ V ^8„  d   QhRS[ RS[/# ©r   Úslotr   ©ÚintÚbool)r   r   s   "€r   r   r      s   ø€ ÷ ,ñ ,©sð ,±tñ ,r   c                óê   € \        \        VRR4      RR4      pV'       g   R# W0P                  P                  V/ 4      P                  R/ 4      P                  R4      8w  d   R# V P                  V4      # )a�  Whether a fresh id at a reused raw index opens a new call (Ollama parallel batch) or
continues the current one. LM Studio and Kimi send a fresh id on every argument fragment
with no name, and some MiniMax routes resend the same name on each fragment too: only a
named delta can start a call, and a same-name one only once the current call's arguments
have closed (two parallel calls of one tool must still split).r   NÚnameFT)Úgetattrr   ÚgetÚ_arguments_closed)r   Útc_deltar(   r-   s   &&& r   Ú_starts_new_callÚ%_ToolCallAccumulator._starts_new_call   sb   € ô ”w˜x¨°TÓ:¸FÀDÓIˆßÙØ—8‘8—<‘<  bÓ)×-Ñ-¨j¸"Ó=×AÑAÀ&ÓIÔIÙØ×%Ñ% dÓ+Ð+r   c                ó&   <€ V ^8„  d   QhRS[ RS[/# r'   r)   )r   r   s   "€r   r   r   ,   s   ø€ ÷ 8ñ 8¡cð 8©dñ 8r   c                óØ  € V P                   P                  V. 4      pV P                  P                  VR	4      w  r4rVpRP                  W#R 4       F_  pV'       d%   V'       d   RpK  VR8X  d   RpK"  VR8X  d   RpK-  K/  VR8X  d   RpK:  VR9   d   V^,           RrtKM  VR9   g   KV  V^,          pKa  	  \	        V4      WEWg3V P                  V&   T;'       d    V^ 8H  ;'       d    V'       * # )
a	  Structural completion (brackets balanced outside strings), not strict JSON validity, so a
repairable call with a trailing comma still ends its slot. Scans only fragments added since
the last check: linear over the call, and free for providers that never reach here.Fr   NÚ\TÚ"z{[z}])é    r8   FFF)r   r/   r   r!   Úlen)	r   r(   r#   ÚdoneÚdepthÚ	in_stringÚescapedÚstartedÚchs	   &&       r   r0   Ú&_ToolCallAccumulator._arguments_closed,   sÞ   € ð ×$Ñ$×(Ñ(¨¨rÓ2ˆØ37·>±>×3EÑ3EÀdÐLgÓ3hÑ0ˆ�Y¨Ø—'‘'˜% ˜,Ö'ˆBßßØ#’GØ˜4”ZØ"’GØ˜3”YØ %’Iñ à�s”Ø ’	Ø�t”Ø!&¨¥¨D’wØ�t–Ø˜•
’ñ (ô !$ E£
¨E¸gÐOˆ�‰�tÑØ×7Ð7˜5 A™:×7Ð7¨i¬-Ð7r   c                ó0   <€ V ^8„  d   QhRS[ S[,          /# r   )r   Ústr)r   r   s   "€r   r   r   C   s   ø€ ÷ /ñ /¡©¥ñ /r   c                óˆ  € \        VRR4      pVf   ^ p\        VRR4      pT;'       g    Rp\        V\        4      '       d   \        V4      pV P                  P                  W"4       V'       d{   W P                  9   dk   W@P                  V,          8w  dT   V P                  WP                  V,          4      '       d,   \        V P                  RR7      ^,           V P                  V&   V'       d   W@P                  V&   V P                  V,          pV P                  P                  TRT;'       g    RRRRRRR	R/R
R/4      pV P                  P                  V. 4      pV'       d   W6R&   \        VRR4      pV'       d†   \        VRR4      '       d   VP                  VR,          R&   \        VR	R4      '       d   VP                  VP                  4       \        \        VR4      ;p	\        4      '       d   V	'       d   W–R&   \        VR
R4      p
V
fP   \        VR4      '       d>   \        VP                   \"        4      '       d   VP                   M/ P%                  R
4      p
V
e   ^ RIHp V! V
4      VR
&   VR,          R,          pV'       d.   WPP*                  9  d   V P*                  P-                  V4       V# R# )zDMerge one delta; return the tool name the first time it is complete.ÚindexNÚidr   )ÚdefaultÚtyper   r-   r   Úextra_contentÚthought_signatureÚmodel_extra)Ú_dump_if_modeléÿÿÿÿ)r.   Ú
isinstancer*   rB   r   Ú
setdefaultr
   r2   Úmaxr   r   r-   Úappendr   r   ÚhasattrrJ   r   r/   Úagent.chat_completion_helpersrK   r	   Úadd)r   r1   Úraw_idxÚtc_idÚdelta_idr"   Úentryr#   Útc_functionÚfn_sigÚextrarK   r-   s   &&           r   ÚfeedÚ_ToolCallAccumulator.feedC   sP  € ä˜( G¨TÓ2ˆØŠ?ØˆGÜ˜ $¨Ó-ˆØ—;�;˜BˆÜ�eœS×!Ò!Ü˜“JˆEà× Ñ ×+Ñ+¨GÔ=ç˜×$8Ñ$8Ô8¸X×I]ÑI]Ð^eÕIfÔ=fØ×%Ñ% h×0HÑ0HÈÕ0Q×RÒRä03°D·H±HÀbÔ0IÈAÕ0MˆD×$Ñ$ WÑ-ßØ,4× Ñ  Ñ)Ø×&Ñ& wÕ/ˆà—‘×#Ñ#Ø�$˜Ÿ˜  V¨Z¸ÀfÈbÐR]Ð_aÐEbÐdsÐuyÐzó
ˆð ×$Ñ$×/Ñ/°°RÓ8ˆßØ�$‰KÜ˜h¨
°DÓ9ˆßÜ�{ F¨D×1Ò1ð -8×,<Ñ,<��jÕ! &Ñ)Ü�{ K°×6Ò6Ø—‘˜[×2Ñ2Ô3ä¤E¨+Ð7JÓ$KÐK˜&ÌS×QÒQ×V\Ø-3Ð)Ñ*Ü˜ /°4Ó8ˆØŠ=œW X¨}×=Ò=Ü-7¸×8LÑ8LÌd×-SÒ-S�X×)Ò)ÐY[×`Ñ`ÐapÓqˆEØÒÝDÙ%3°EÓ%:ˆE�/Ñ"Ø�ZÕ  Õ(ˆß�CŸ~™~Ô-Ø�N‰N×Ñ˜sÔ#ØˆKÙr   )r   r   r   r
   r	   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r$   r2   r0   r[   Ú__static_attributes__Ú__classdictcell__)r   s   @r   r   r      s8   ø‡ € ñFò
	.÷ð ÷,ð ,÷8ð 8÷./ö /r   r   N)ra   Útypingr   Úagent.reasoning_carriersr   r   © r   r   Ú<module>rg      s   ðÙ bå å *÷jó jr   