+
    iHàjÜ+ ã                  óÐ  a € 0 t $ R t^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
t
^ RIHt ^ RIHt ^ RIHtHtHtHtHt ^ RIHt ^ RIHtHtHtHtHt ^ RIHtHtHtH t  ^ R	I!H"t"H#t# ^ R
I$H%t%H&t& ^ RI'H(t( ^ RI)H*t* ^ RI+H,t,H-t-H.t.H/t/ ^ RI0H1t1 ^ RI2H3t3H4t4 ^ RIH5t5 ^ RI6H7t7 ^ RI8H9t9 ^ RI:H;t; ^ RI<H=t=H>t>H?t?H@t@ ]P‚                  ! ]B4      tC^tDER:tERtF]G;QJ d    . R ]( 4       F  NK  	  5M! R ]( 4       4      tH]G;QJ d    . R ]E 4       F  NK  	  5M! R ]E 4       4      tI]P”                  ! R]P–                  ]P˜                  ,          4      tM]P”                  ! RRP�                  ](4       R2]P–                  ]P˜                  ,          4      tO]P”                  ! RRP�                  ](4       R2]P˜                  4      tP]P”                  ! R]F RRP�                  ]E4       R 2]P˜                  4      tQ]P”                  ! R!]F RRP�                  ]E4       R"2]P–                  ]P˜                  ,          4      tRR# tS]T! 0 ER;m4      tUR$tVR% R& ltWR' R( ltXR) R* ltYR+ R, ltZR- R. lt[R/ R0 lt\R1 R2 lt]R3 R4 lt^R5RR6RR7R/R8 R9 llt_/ t`R:]aR;&   ]	PÄ                  ! 4       tcR< R= ltdR> teR? R@ ltfRA RB ltgRC RD lthRE RF ltiRG RH ltjRI RJ ltkRK RL ltlRM RN ltmRO RP ltnRQ RR ltoRS RT ltp]m]n]o]p3tqRU RV ltrRW RX ltsRY RZ lttR[ R\ ltu. ]HO]IO]MN]ON]PN]QN]RN5tvR] R^ ltwR_ R` ltxRa]1Pò                  Rb]1Pô                  Rc]1Pö                  Rd]1Pö                  /t|ER<t}ER=t~Re Rf ltRg Rh lt€Ri t�Rj t‚RkRRlRRmRn/Ro Rp lltƒRq Rr lt„Rs Rt lt…Ru Rv lt†Rw Rx lt‡Ry Rz ltˆ]‰! 4       tŠR{R|R}R/R~ R llt‹R€ tŒR� R‚ lt�Rƒ R„ ltŽR… R† lt�R‡ Rˆ lt�R‰ RŠ lt‘]T! 0 ER>m4      t’]G;QJ d    . R‹ ]( 4       F  NK  	  5M! R‹ ]( 4       4      t“RŒ R� lt”RŽ R� lt•R�R/R‘ R’ llt–R“RR”RR•RR–R/R— R˜ llt—ER?t˜R™ Rš lt™R› Rœ ltšR� Rž lt›RŸ R  ltœER@R¡ R¢ llt�R£RR¤RR¥R/R¦ R§ lltžR¨ R© ltŸRª R« lt R¬ R­ lt¡R® R¯ lt¢R“RR”RR•RR–R/R° R± llt£R² R³ lt¤R´ Rµ lt¥R¶ R· lt¦R¸ R¹ lt§Rº R» lt¨R¼ t©ERAtª]‰! 4       t«R½ R¾ lt¬R¿ RÀ lt­RÁ t®RÂ RÃ lt¯RÄ RÅ lt°RÆ t±RÇ RÈ lt²RÉ RÊ lt³RË RÌ lt´ERBRÍ ltµRÎ t¶ERCRÏ RÐ llt·RÑ RÒ lt¸^t¹RÓtº/ t»RÔ]aRÕ&   ]	PÄ                  ! 4       t¼]½! 4       t¾RÖ]aR×&   / t¿RØ]aRÙ&   RÚ RÛ ltÀRÜ RÝ ltÁRÞ Rß ltÂRà Rá ltÃRâ Rã ltÄRä Rå ltÅRæ Rç ltÆRè Ré ltÇRê Rë ltÈRì Rí ltÉRî Rï ltÊRð Rñ ltËRò Ró ltÌRô Rõ ltÍRö R÷ ltÎRø Rù ltÏRú Rû ltÐRü Rý ltÑ]P”                  ! Rþ4      tÒERDtÓEREtÔERFRÿ ER  lltÕ^tÖERGt×ERtØER@ER ER lltÙER ER ltÚ]P”                  ! ER]P˜                  4      tÛERtÜER ER	 ltÝ]P”                  ! ER
]P˜                  4      tÞER ER ltß0 ERHmtà0 ERImtáER ER ltâER ER ltãER ER ltäER ER ltåER ER ltæER ER ltçER ER ltèER ER ltéER ER ltêER ER  ltëER! ER" ltì]P”                  ! ER#4      tíER$ER%ER&ER'ER(ER)ER*ER+/tîERJtïER, ER- ltðER. ER/ ltñER0 ER1 ltòER2 ER3 ltóER4 ER5 ltôER6 ER7 ltõER8 ER9 ltö. ERKOt÷R# (L  au  Assorted AIAgent runtime helpers (message repair/sanitization, credential recovery, primary
runtime restore, prompt-cache policy, client construction, model switching, tool invocation).
Each function takes the parent ``AIAgent`` as ``agent`` except the stateless message helpers.
``_ra()`` resolves ``run_agent`` lazily so tests patching ``run_agent.X`` keep intercepting.
)ÚannotationsN)Údatetime)ÚPath)ÚAnyÚDictÚListÚOptionalÚTuple)Úget_provider_request_timeout)Ú_FULL_ARGS_LOG_BOUNDÚcoalesce_tool_call_idÚcoerce_tool_nameÚtool_call_id_variantsÚtool_result_id_variants)ÚTOOL_CALL_UIDSÚmerge_tool_call_uidsÚper_occurrence_tool_call_uidsÚrecord_absorbed_message)ÚSTEER_DISPLAY_KINDÚsteer_user_row)Ú_trajectory_normalize_msgÚmake_tool_result_message)ÚTHINK_TAG_NAMES)Úconvert_scratchpad_to_think)ÚSTATUS_EXHAUSTEDÚ_parse_absolute_timestampÚ%credential_pool_entry_serves_endpointÚ credential_pool_matches_provider)ÚFailoverReason)Úparse_retry_after_secondsÚreset_delay_from_message)ÚMERGED_TURN_PREFIX)Údrop_stale_api_content)Ú_INTERRUPTED_PLACEHOLDER)Ú_build_primary_runtime_snapshot)Úbase_url_host_matchesÚbase_url_hostnameÚenv_var_enabledÚatomic_json_writez(?:[\w.-]+:)?c              #  ó¤   "  € T FF  p\         P                  ! R V RV R2\         P                  \         P                  ,          4      x € KH  	  R# 5i)Ú<z>.*?</Ú>N©ÚreÚcompileÚDOTALLÚ
IGNORECASE©Ú.0Únames   & Ú@/home/ubuntu/.hermes/hermes-agent/agent/agent_runtime_helpers.pyÚ	<genexpr>r5   .   s>   é € ð "ÙP_È„B‡J‚J�!�D�6˜ ˜v QÐ'¬¯©´R·]±]Õ)B×CÐCÓP_ùó   ‚AAc           
   #  ó¼   "  € T FR  p\         P                  ! R \         V R\         V R2\         P                  \         P                  ,          4      x € KT  	  R# 5i)r*   z\b[^>]*>.*?</r+   N)r-   r.   Ú
_NS_PREFIXr/   r0   r1   s   & r4   r5   r5   1   sL   é € ð "á$ˆô ‡J‚J�!”J�< ˜v ]´:°,¸t¸fÀAÐFÌÏ	É	ÔTV×TaÑTaÕHa×bÐbÛ$ùs   ‚AAzd(?:(?<=^)|(?<=[\n\r.!?:]))[ \t]*<function\b[^>]*\bname\s*=[^>]*>(?:(?:(?!</function>).)*)</function>z(?:^|\n)[ \t]*<(?:Ú|z)\b[^>]*>.*$z</?(?:z)>\s*z</(?:z(?:z|function))>\s*z(?:^|\n)[ \t]*<zs)\b[^>]*>.*$|(?:^|\n)[ \t]*[\w.:-]*</?arg_(?:key|value)\b[^\n]*|(?:^|\n)[^\n<]*</arg_(?:key|value)>[ \t\r]*(?=\n|$)c                 ó   € ^ RI p V # )z4Lazy ``run_agent`` reference for test-patch routing.N©Ú	run_agentr;   s    r4   Ú_rar=   S   s   € ãØÐó    aú  You are a function calling AI model. You are provided with function signatures within <tools> </tools> XML tags. You may call one or more functions to assist with the user query. If available tools are not relevant in assisting with user query, just respond in natural conversational language. Don't make assumptions about what values to plug into functions. After calling & executing the functions, you will be provided with function results within <tool_response> </tool_response> XML tags. Here are the available tools:
<tools>
{tools}
</tools>
For each function call return a JSON object, with the following pydantic model json schema for each:
{{'title': 'FunctionCall', 'type': 'object', 'properties': {{'name': {{'title': 'Name', 'type': 'string'}}, 'arguments': {{'title': 'Arguments', 'type': 'object'}}}}, 'required': ['name', 'arguments']}}
Each function call should be enclosed within <tool_call> </tool_call> XML tags.
Example:
<tool_call>
{{'name': <function-name>,'arguments': <args-dict>}}
</tool_call>c               ó    € V ^8„  d   QhRRRR/# ©é   Úmsgúdict[str, Any]ÚreturnÚstr© )Úformats   "r4   Ú__annotate__rH   o   s   € ÷ ñ  ð °3ñ r>   c                óˆ   € V P                  R4      '       d+   V R,          P                  4       '       d   RV R,           R2# R# )z?Leading ``<think>`` block from native reasoning tokens, if any.Ú	reasoningz<think>
z

</think>
Ú )ÚgetÚstrip©rB   s   &r4   Ú_trajectory_gpt_prefixrO   o   s<   € à
‡w�wˆ{×Ò  KÕ 0× 6Ñ 6× 8Ò 8Ø˜3˜{Õ+Ð,¨LÐ9Ð9Ùr>   c               ó    € V ^8„  d   QhRRRR/# ©rA   ÚcontentrE   rD   rF   )rG   s   "r4   rH   rH   v   s   € ÷ Pñ P˜sð P sñ Pr>   c                ó&   € RV 9   d   V # RV ,           # )zUEvery gpt turn gets a <think> block (empty if none) for a consistent training format.z<think>z<think>
</think>
rF   ©rR   s   &r4   Ú_with_think_blockrU   v   s   € à 7Ô*ˆ7ÐOÐ0EÈÕ0OÐOr>   c               ó    € V ^8„  d   QhRRRR/# r@   rF   )rG   s   "r4   rH   rH   {   s   € ÷ /ñ / Nð /°sñ /r>   c                ó²  € \        V 4      pV P                  R 4      '       d>   V R ,          P                  4       '       d!   V\        V R ,          4      R,           ,          pV R,           F™  pV'       d   \	        V\
        4      '       g   K#  VR,          R,          p \	        V\        4      '       d   \        P                  ! V4      MTpRVR,          R,          RV/pVR\        P                  ! VR	R
7       R2,          pK›  	  \        V4      P                  4       #   \        P                   d#    \        P                  RTR,          4       / p LŠi ; i)rR   Ú
Ú
tool_callsÚfunctionÚ	argumentsz4Unexpected invalid JSON in trajectory conversion: %s:Néd   Nr3   z<tool_call>
F©Úensure_asciiz
</tool_call>
)rO   rL   rM   r   Ú
isinstanceÚdictrE   ÚjsonÚloadsÚJSONDecodeErrorÚloggerÚwarningÚdumpsrU   Úrstrip)rB   rR   Ú	tool_callÚraw_argsr[   Útool_call_jsons   &     r4   Ú_trajectory_tool_call_turnrk   {   s  € Ü$ SÓ)€GØ
‡w�wˆy×Ò˜c )�n×2Ñ2×4Ò4àÔ.¨s°9­~Ó>ÀÕEÕEˆØ˜×&Ð&ˆ	ß¤
¨9´d× ;Ò ;ÙØ˜ZÕ(¨Õ5ˆð	Ü0:¸8ÄS×0IÒ0IœŸ
š
 8Ô,ÈxˆIð ! )¨JÕ"7¸Õ"?ÀÈiÐXˆØ�]¤4§:¢:¨nÈ5Ô#QÐ"RÐRbÐcÕcŠñ 'ô ˜WÓ%×,Ñ,Ó.Ð.øô ×#Ñ#ô 	Ü�N‰NÐQÐS[Ð\`ÕSaÔbØŠIð	ús   Â.DÄ4EÅEc               ó(   € V ^8„  d   QhRRRRRRRR/# )	rA   rB   rC   Úmessagesúlist[dict[str, Any]]ÚstartÚintrD   ztuple[list[str], int]rF   )rG   s   "r4   rH   rH   �   s+   € ÷ ñ  Nð Ð>Rð Ð[^ð Ðcxñ r>   c                óV  € . pTpV\        V4      8  dó   W,          R,          R8X  dß   W,          pVR,          p VP                  4       P                  R4      '       d   \        P                  ! V4      p\        T4      pT\        T R,          4      8  d   T R,          T,          R,          R,          MRp\        P                  ! RTP                  RR	4      RTRT/R
R7      p	TP                  RT	 R24       T^,          pEK  W43#   \        P
                  \        3 d     L±i ; i)zpCollect the ``<tool_response>`` blocks for the tool run starting at ``start``; returns ``(blocks, next_index)``.ÚroleÚtoolrR   rY   rZ   r3   ÚunknownÚtool_call_idrK   Fr]   z<tool_response>
z
</tool_response>)Ú{Ú[)
ÚlenrM   Ú
startswithra   rb   rc   ÚAttributeErrorrf   rL   Úappend)
rB   rm   ro   Útool_responsesÚjÚtool_msgÚtool_contentÚ
tool_indexÚ	tool_nameÚpayloads
   &&&       r4   Ú_trajectory_tool_responsesrƒ   �   s!  € à€NØ€AØ
Œc�(‹mÔ
 ¥¨FÕ 3°vÔ =Ø•;ˆØ 	Õ*ˆð	Ø×!Ñ!Ó#×.Ñ.¨z×:Ò:Ü#Ÿzšz¨,Ó7�ô ˜Ó(ˆ
ð œC  LÕ 1Ó2Ô2ð �Õ˜jÕ)¨*Õ5°fÖ=àð 	ô
 —*’*Ø˜XŸ\™\¨.¸"Ó=¸vÀyÐR[Ð]iÐjØô
ˆð 	×ÑÐ 1°'°Ð:LÐMÔNØ	ˆQ�‹ØÐÐøô ×$Ñ$¤nÐ5ô 	Ùð	ús   »;D
 Ä
D(Ä'D(c               ó(   € V ^8„  d   QhRRRRRRRR/# )rA   rm   rn   Ú
user_queryrE   Ú	completedÚboolrD   rF   )rG   s   "r4   rH   rH   ª   s0   € ÷ ñ Ð2Fð ÐTWð Ðdhð ð  nBñ r>   c                ó  € V Uu. uF  p\        V4      NK  	  ppRRR\        P                  V P                  4       R7      /RRRV/.p^pV\	        V4      8  Ed&   W,          pVR,          R8X  dÚ   VP                  R4      '       dj   VP                  RR	R\        V4      /4       \        WqV^,           4      w  r‰V'       d.   VP                  RR
RRP                  V4      /4       V	^,
          pMƒ\        V4      \        VR,          ;'       g    R4      ,           p
VP                  RR	R\        V
4      P                  4       /4       M*VR,          R8X  d   VP                  RRRVR,          /4       V^,          pEK6  V# u upi )zAConvert internal message history to trajectory format for saving.ÚfromÚsystemÚvalue)ÚtoolsÚhumanrr   Ú	assistantrY   Úgptrs   rX   rR   rK   Úuser)r   Ú_TRAJECTORY_SYSTEM_PROMPTrG   Ú _format_tools_for_system_messagerx   rL   r{   rk   rƒ   ÚjoinrO   r   rU   rM   )Úagentrm   r…   r†   ÚmÚ
trajectoryÚirB   r|   r}   rR   s   &&&&       r4   Úconvert_to_trajectory_formatr˜   ª   sp  € ñ 7?Ó?±h°Ô)¨!Ö,±h€HÐ?à	�˜7Ô$=×$DÑ$DÈ5×KqÑKqÓKsÐ$DÓ$tÐuØ	�˜' :Ð.ð€Jð
 	
€AØ
Œc�(‹mÕ
Ø�kˆØˆv�;˜+Ô%Ø�w‰w�|×$Ò$Ø×!Ñ! 6¨5°'Ô;UÐVYÓ;ZÐ"[Ô\Ü$>¸sÈaÐRSÍeÓ$TÑ!�ß!Ø×%Ñ% v¨v°wÀÇ	Á	È.Ó@YÐ&ZÔ[Ø˜A��Aøä0°Ó5Ô8SÐTWÐXaÕTb×ThÐThÐfhÓ8iÕi�Ø×!Ñ! 6¨5°'Ô;LÈWÓ;U×;[Ñ;[Ó;]Ð"^Õ_Ø��[˜FÔ"Ø×Ñ˜v w°¸¸Y½ÐHÔIØ	ˆQ�‹ØÐùò- @s   …Fc               ó$   € V ^8„  d   QhRRRRRR/# )rA   r~   r`   ÚmarkerrE   rD   ÚNonerF   )rG   s   "r4   rH   rH   Ç   s!   € ÷ -ñ -¨ð -°sð -¸tñ -r>   c                ó†  € V P                  R 4      p\        V\        4      '       d   VP                  V4      '       d   R# \        V\        \	        R4      34      '       g    \
        P                  ! V4      pV'       d   V RV 2MTT R &   ^ RIH	p V P                  VR4       R#   \         d    \        T4      p LFi ; i)rR   NrX   ©Ú_DB_PERSISTED_MARKER)rL   r_   rE   ry   Útypera   rf   Ú	TypeErrorÚagent.context_compressorrž   Úpop)r~   rš   Úexistingrž   s   &&  r4   Ú_prepend_corruption_markerr¤   Ç   s    € Ø�|‰|˜IÓ&€HÜ�(œC× Ò  X×%8Ñ%8¸×%@Ò%@ÙÜ�h¤¤d¨4£jÐ 1×2Ò2ð	%Ü—z’z (Ó+ˆH÷ 6>˜V˜H B x jÑ1À6€HˆYÑå=Ø‡L�LÐ% tÖ,øô ô 	%Ü˜8“}ŠHð	%ús   Á#B' Â'C Â?C c               ó(   € V ^8„  d   QhRRRRRRRR/# )	rA   rm   Úlistro   rp   rh   r`   rD   úOptional[dict]rF   )rG   s   "r4   rH   rH   Ö   s(   € ÷ ñ  ð ¨Sð ¸Tð Ànñ r>   c                óâ   € WR  Ff  p\        V\        4      '       d   VP                  R4      R8w  d    R# \        VP                  R4      4      \	        V4      ,          '       g   Kd  Vu # 	  R# )zQThe tool result answering ``tool_call`` in the run starting at ``start``, if any.Nrr   rs   ru   )r_   r`   rL   r   r   )rm   ro   rh   Ú	candidates   &&& r4   Ú_find_tool_resultrª   Ö   s\   € à˜fÓ%ˆ	Ü˜)¤T×*Ò*¨i¯m©m¸FÓ.CÀvÔ.MÚÜ" 9§=¡=°Ó#@ÓAÔDYÐZcÓDd×dÖdØÒñ	 &ñ
 r>   c               ó$   € V ^8„  d   QhRRRRRR/# )rA   rm   r¦   Úcursorr§   rD   rp   rF   )rG   s   "r4   rH   rH   à   s!   € ÷ ñ  $ð °ð À3ñ r>   c                óä   € Ve   VP                  R4      MRp^ p\        V\        4      '       dA   V\        \	        V4      \	        V 4      4      8  d   W,          W#,          J d   V^,          pK@  V# )zMLength of the ``is``-identical prefix already validated on the previous call.NÚprefix)rL   r_   r¦   Úminrx   )rm   r¬   Úprev_prefixro   s   &&  r4   Ú_cursor_skip_prefixr±   à   s\   € à*0Ò*<�&—*‘*˜XÔ&À$€KØ€EÜ�+œt×$Ò$Ø”cœ#˜kÓ*¬C°«MÓ:Ô:¸x½ÐR]ÕRdÓ?dØ�Q�JŠEØ€Lr>   rd   Ú
session_idr¬   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	rA   rm   r¦   r²   ú
str | Noner¬   r§   rD   rp   rF   )rG   s   "r4   rH   rH   ê   s2   € ÷ Mñ MØðMØ0:ðMØKYðMàñMr>   c               ó.  € T;'       g    \         P                  ! \        4      p\        V \        4      '       g   ^ # ^ RIHp ^ p\        4       P                  P                  p\        W4      pV\        V 4      8  Ed�   W,          p	\        V	\        4      '       d(   V	P                  R4      R8X  d   V	P                  R4      MRp
\        V
\        4      '       d	   V
'       g   V^,          pK�  V^,           pV
 EF  p\        V\        4      '       d   VP                  R4      MRp\        V\        4      '       g   KE  VP                  R4      pVe-   \        V\        4      '       d0   VP                  4       '       g   RVR&   V	P!                  VR4       KŸ  \        V\        4      '       g   K·  \"        P$                  ! \&        P(                  4      ;_uu_ 4        \&        P*                  ! V4        RRR4       EK  	  V^,          pEK   Ve   V R,          VR&   V#   + '       g   i     M; i\        4       P                  P-                  T4      ;'       g    RpTP                  R	R
4      pTP/                  RT;'       g    RY�;'       g    RTTR\0         4       RTR&   T	P!                  TR4       \3        Y^,           T4      pTf0   T P5                  T\7        TR
8w  d   TMRY4      4       T^,          pM\9        TT4       T^,          pEK  )uâ  Repair corrupted assistant tool-call argument JSON in-place.
``cursor["prefix"]`` holds strong refs (not ``id()``: address reuse aliases) to the
messages validated last call; the ``is``-identical prefix is skipped. Safe because only
the surrogate sanitizers mutate live dicts; every other path replaces dicts, breaking identity.

Safety argument for skipping: a message in the matched prefix was fully scanned before â€” every tool_call
argument was either already valid JSON or was rewritten to ``"{}"`` (valid). The only code paths that
mutate ``function["arguments"]`` on live history dicts between calls are the surrogate / non-ASCII
sanitizers, which substitute characters *inside* JSON string values and cannot invalidate JSON syntax.
Compression, repair, undo, and steer paths replace or reorder message dicts, which breaks the identity
match and forces a re-scan. Holding strong references (the objects themselves, not ``id()``s) makes
address reuse aliasing (#50372-style) impossible.
r�   rr   rŽ   rY   NrZ   r[   ú{}r3   Ú?z‰Corrupted tool_call arguments repaired before request (session=%s, message_index=%s, tool_call_id=%s, function=%s, original_arguments=%r)Ú-rK   ºNNNr®   )ÚloggingÚ	getLoggerÚ__name__r_   r¦   r¡   rž   r=   ÚAIAgentÚ&_TOOL_CALL_ARGUMENTS_CORRUPTION_MARKERr±   rx   r`   rL   rE   rM   r¢   Ú
contextlibÚsuppressra   rc   rb   Ú_get_tool_call_id_staticre   r   rª   Úinsertr   r¤   )rm   rd   r²   r¬   Úlogrž   Úrepairedrš   Úmessage_indexrB   rY   Ú	insert_atrh   rZ   r[   ru   Úfunction_nameÚexisting_tool_msgs   &$$$              r4   Úsanitize_tool_call_argumentsrÉ   ê   s†  € ð  ×
/Ð
/”G×%Ò%¤hÓ/€CÜ�h¤×%Ò%ÙÝ=Ø€HÜ‹U�]‰]×AÑA€FÜ'¨Ó9€MØ
œ#˜h›-Õ
'ØÕ%ˆÜ.8¸¼d×.CÒ.CÈÏÉÐPVËÐ[fÔHf�S—W‘W˜\Ô*Ðlpˆ
Ü˜*¤d×+Ò+·:Ø˜QÕˆMÙØ! AÕ%ˆ	Ü#ˆIÜ4>¸yÌ$×4OÒ4O�y—}‘} ZÔ0ÐUYˆHÜ˜h¬×-Ò-ÙØ Ÿ™ [Ó1ˆIØÒ ¤Z°	¼3×%?Ò%?È	ÏÉ×HYÒHYØ(,�˜Ñ%Ø—‘Ð,¨dÔ3ÙÜ˜i¬×-Ò-ÙÜ×$Ò$¤T×%9Ñ%9×:Õ:Ü—
’
˜9Ô%Ø÷ ;Ò:ñ $ðT 	˜Õ‹ØÒð $ A�;ˆˆxÑØ€O÷I ;×:úô ›5Ÿ=™=×AÑAÀ)ÓL×TÐTÐPTˆLØ$ŸL™L¨°Ó5ˆMð �K‰Kð)à*4×*;Ð*;¸¸]×L_ÐL_Ð\_Ø˜yÐ)>Ô*>Ð?ô	ð %)ˆH�[Ñ!ð �G‰GÐ(¨$Ô/Ü 1°(ÈAÕ<MÈyÓ YÐØ Ò(Ø—‘ØÜ,¸mÈsÔ>R©]ÐXZÐ\bÓqôð ˜Q•‘	ä*Ð+<¸fÔEØ˜�M‹Hs   ÇH È H0zdict[str, tuple[str, float]]Ú_INFLIGHT_TURNS_BY_SESSIONc               ó   € V ^8„  d   QhRR/# )rA   Úturn_idrE   rF   )rG   s   "r4   rH   rH   A  s   € ÷ 'ñ ' Cñ 'r>   c                ó&  € \        V RR4      p\        V RR4      pWn        \        P                  ! 4       V n        RpV'       dZ   W!8w  dT   \        P                  RYV'       d   \        P                  ! 4       V,
          MR\        V RR4      ;'       g    R4       Tp\        V RR4      pV'       dÌ   \        V RR	4      '       g¹   \        P                  ! 4       p\        ;_uu_ 4        \        P                  V4      pW3\        V&   RRR4       WPn	        X'       d`   V^ ,          W39  dQ   \        P                  R
Y^ ,          V^,          '       d   Wg^,          ,
          MRV4       T;'       g
    V^ ,          pV#   + '       g   i     L; i)ab  Tripwire: warn when a turn starts while a previous turn of the same agent or session
(on another agent object) has not finished its persist. Does not prevent the overlap; it
names both turn ids so the dispatch route that bypassed the busy guard is findable in logs.
Returns the previous in-flight turn_id on overlap, else None; takes the slot either way.Ú_inflight_turn_idNÚ_inflight_turn_startedg        u¬   turn %s starting while turn %s (started %.0fs ago) has not completed its turn-end persist (session=%s) â€” concurrent turns on one session; transcript writes may interleaver²   r¸   Ú_persist_disabledFuç   turn %s starting while turn %s (started %.0fs ago) is still in flight on session %s under a different agent object â€” two routing keys are mapped to one session_id; concurrent turns on one session; transcript writes may interleaveg      ð¿)
ÚgetattrrÎ   ÚtimerÏ   rd   re   Ú_INFLIGHT_TURNS_LOCKrÊ   rL   Ú_inflight_turn_session_id)r”   rÌ   ÚprevÚprev_startedÚoverlapr²   ÚnowÚentrys   &&      r4   Únote_turn_startrÚ   A  sG  € ô
 �5Ð-¨tÓ4€DÜ˜5Ð":¸CÓ@€LØ%ÔÜ#'§9¢9£;€EÔ Ø€Gß�”Ü�‰ð?à@Gß*6ŒD�IŠI‹K˜,Ö&¸DÄ'È%ÐQ]Ð_cÓBd×BkÐBkÐhkô		
ð ˆô ˜ ¨dÓ3€Jßœ' %Ð)<¸e×DÒDÜ�iŠi‹kˆß!Ö!Ü.×2Ñ2°:Ó>ˆEØ6=°^Ô& zÑ2÷ "ð
 +5Ô'ß�U˜1•X g _Ô4Ü�N‰NðIð KRÐYZÕS[Ø"'¨§(¤(�˜A•h–°°jôð ×)Ð)  q¥ˆGØ€N÷ "×!ús   Ã) F Æ F	c                ó  € RV n         \        V RR4      '       gX   \        V RR4      ;'       g    \        V RR4      pV'       d.   \        ;_uu_ 4        \        P	                  VR4       RRR4       RV n        R#   + '       g   i     L; i)zÔClear the in-flight marker at turn-end persist (see note_turn_start). Unconditional by
design: on a real overlap the first persist clears the second slot, so the tripwire
under-reports rather than double-reports.NrÐ   FrÔ   r²   )rÎ   rÑ   rÓ   rÊ   r¢   rÔ   )r”   r²   s   & r4   Únote_turn_persistedrÜ   k  sp   € ð #€EÔô �5Ð-¨u×5Ò5Ü˜UÐ$?ÀÓF×lÐlÌ'ÐRWÐYeÐgkÓJlˆ
ßß%Ö%Ü*×.Ñ.¨z¸4Ô@÷ &à&*€EÖ#÷ &×%ús   ÁA;Á;B	c               ó    € V ^8„  d   QhRRRR/# )rA   r•   r`   rD   r‡   rF   )rG   s   "r4   rH   rH   z  s   € ÷ ñ ˜ð  $ñ r>   c                ó    € \        V P                  R4      ;'       g.    V P                  R4      ;'       g    V P                  R4      R8H  4      # )zTCodex Responses interim turn: carries its own continuation state, replayed verbatim.Úcodex_reasoning_itemsÚcodex_message_itemsÚfinish_reasonÚ
incomplete©r‡   rL   )r•   s   &r4   Ú_is_codex_interimrä   z  sN   € äØ	�‰Ð%Ó&÷ 	2ð 	2Ø�5‰5Ð&Ó'÷	2ð 	2à�5‰5�Ó! \Ñ1óð r>   c               ó$   € V ^8„  d   QhRRRRRR/# )rA   rÕ   r`   rB   rD   r‡   rF   )rG   s   "r4   rH   rH   ƒ  s&   € ÷ Mñ M ð M¨4ð M°Dñ Mr>   c           	     óx  € ^ RI Hp \        V P                  R4      ;'       g    . 4      p\        VP                  R4      ;'       g    . 4      pRpV'       d•   W4,           V R&   \	        VP                  \
        4      ;p\        4      '       d\   V'       dT   \        \        \	        V P                  \
        4      ;p\        4      '       d   TM/ V4      \        Wd4      4      V \
        &   RpM$V'       d   W0R&   MRV 9   pV P                  RR4       V P                  R4      pVP                  R4      p	Rp
V	'       * p\	        V\        4      '       dX   \	        V	\        4      '       dB   RpRP                  R VP                  4       V	P                  4       3 4       4      pWÀR&   WÈ8g  p
MV'       g   V	e   W�R&   W˜8g  p
RpRpV P                  R	4      '       g&   VP                  R	4      '       d   VR	,          V R	&   RpV
'       d   \        V 4       V
'       g   V'       g	   V'       d   V P                  VR4       V# )
zŸFold consecutive assistant *msg* into *prev* (union tool_calls, concat text). Returns whether *msg*'s
text survives: multimodal (list) content is never joined.r�   rY   FTNrR   rX   c              3  ó8   "  € T F  q'       g   K  Vx € K  	  R # 5i©NrF   )r2   Úps   & r4   r5   Ú(_merge_assistant_into.<locals>.<genexpr>«  s   é € ÐWÑ&Q ÓUVŸ1š1Ó&Qùs   ‚	�
Úreasoning_content)r¡   rž   r¦   rL   r_   r   r`   r   r   r¢   rE   r“   rM   r"   )rÕ   rB   rž   Ú
prev_callsÚ	new_callsÚcalls_changedÚextraÚownÚprev_contentÚnew_contentÚcontent_rewrittenÚ	text_keptÚjoinedÚreasoning_carrieds   &&            r4   Ú_merge_assistant_intor÷   ƒ  sê  € õ >ä�d—h‘h˜|Ó,×2Ð2°Ó3€JÜ�S—W‘W˜\Ó*×0Ð0¨bÓ1€IØ€MßØ'Õ3ˆˆ\Ñä˜sŸw™w¤~Ó6Ð6�e¼×=Ò=Ç%Ü#7Ü-Ü%¨T¯X©X´nÓ-EÐ&E cÄt×LÒL‘CÐRTÐV`óbä-¨eÓ?ó$AˆD”Ñ ð ‰ß	Ø'ˆ\Òð %¨Ñ,ˆØ�‰�˜tÔ$à—8‘8˜IÓ&€LØ—'‘'˜)Ó$€KØÐØ”€IÜ�,¤×$Ò$¬°KÄ×)EÒ)EØˆ	Ø—‘ÑW |×'9Ñ'9Ó';¸[×=NÑ=NÓ=PÑ&QÓWÓWˆØ ˆY‰ð #Ñ2Ñß˜kÒ5Ø%ˆY‰Ø'Ñ7ÐØˆ	ð ÐØ�8‰8Ð'×(Ò(¨S¯W©WÐ5H×-IÒ-IØ$'Ð(;Õ$<ˆÐ Ñ!Ø Ð÷ Ü˜tÔ$÷ ŸM×->Ø�‰Ð% tÔ,ØÐr>   c               ó(   € V ^8„  d   QhRRRRRRRR/# )rA   ÚsurvivorrC   ÚdroppedÚfoldedr‡   rD   r›   rF   )rG   s   "r4   rH   rH   Ó  s*   € ÷ 3ñ 3 ^ð 3¸nð 3ÐY]ð 3Ðbfñ 3r>   c               ó¸  a
€ ^ RI Ho
HpHp V P	                  R4      p. pVP	                  R4      p\        V\        4      '       d5   \        V\        4      '       g   V^ 8”  d   Wu8w  d   VP                  V4       VP	                  R4      ;'       g    R FU  p\        V\        4      '       g   K  \        V\        4      '       d   K3  V^ 8”  g   K<  W†9  g   KD  VP                  V4       KW  	  V'       d5   V P                  R. 4      p	V F  pWy9  g   K  V	P                  V4       K  	  VP	                  V4      '       d=   \        V P	                  V4      ;'       g    ^ 4      \        W,          4      ,           W&   VP	                  V4      '       d2   V P                  V. 4      P                  V
3R lW,           4       4       V'       d   \        W4       R# R# )a‚  Retire *dropped*'s row ids onto *survivor*; record its uid as a merge witness only when *folded* (its
text survives). An empty incoming turn still merges; stamping an empty list would change a message that
absorbed nothing. A dropped id that equals the survivor's own live id (the display-marker merge adopts
the plain row's id, #94486) is not an absorbed row: the survivor IS that row.)ÚOWN_ROWÚRETIRED_DURABLE_ROWSÚUNNAMED_DURABLE_ROWSÚ_row_idÚ_absorbed_row_idsc              3  óˆ   <"  € T F1  qP                  4        UUu/ uF  w  r#VS8w  g   K  W#bK  	  uppx € K3  	  R # u uppi 5irè   )Úitems)r2   ÚrowÚkÚvrý   s   &   €r4   r5   Ú)_remember_absorbed_row.<locals>.<genexpr>ì  s8   øé € ð =eÙFc¸sŸi™iœkÔ:™k‘d�a¨Q°'©\ŒTˆQŠT™k×:ÓFcùÓ:ùs   ƒAš<ª<°ANrF   )Ú&agent.conversation_compression_archiverý   rþ   rÿ   rL   r_   rp   r‡   r{   Ú
setdefaultÚextendr   )rù   rú   rû   rþ   rÿ   Úown_idÚidsÚrow_idÚolderÚabsorbedrý   s   &&$       @r4   Ú_remember_absorbed_rowr  Ó  st  ø€ ÷
 kÑjà�\‰\˜)Ó$€FØ
€CØ�[‰[˜Ó#€FÜ�&œ#×Ò¤z°&¼$×'?Ò'?ÀFÈQÄJÐSYÔScØ�
‰
�6ÔØ—‘Ð0Ó1×7Ð7°RÒ7ˆÜ�eœS×!Ô!¬*°U¼D×*AÔ*AÀeÈaÆiÐTYÖTdØ�J‰J�uÖñ 8÷ Ø×&Ñ&Ð':¸BÓ?ˆÛˆFØÖ%Ø—‘ Ö'ñ ð ‡{�{Ð'×(Ò(Ü),¨X¯\©\Ð:NÓ-O×-TÐ-TÐSTÓ)UÔX[Ð\cÕ\yÓXzÕ)zˆÑ&à‡{�{Ð'×(Ò(Ø×ÑÐ0°"Ó5×<Ñ<ô =eØFMÖFcó=eô 	e÷ Ü Ö2ñ r>   c               ó$   € V ^8„  d   QhRRRRRR/# )rA   rù   rC   ÚretiredrD   r›   rF   )rG   s   "r4   rH   rH   ô  s&   € ÷ _ñ _ ð _¸.ð _ÈTñ _r>   c                óf  aaa€ ^ RI Ho ^ RIHoHpHoHp R VV3R llpV! V 4      '       Ed   V! V4      '       dó   \        VP                  R4      \        4      '       gÌ   \        V P                  S4      ;'       g    ^ 4      ^,           V S&   \        ;QJ d8    V3R lVP                  V4      ;'       g    R
 4       F  '       g   K   RM-	  RM)! V3R lVP                  V4      ;'       g    R
 4       4      '       g*   V P                  V. 4      P                  V! V4      4       R	# R	# R	# R	# R	# )aM  On a reload without row ids nothing names *retired*'s durable row once the repair takes the dict
out of the list, so *survivor* counts it. A dict that counts rows was loaded too: a merge may have
popped its marker since. Call before the merge rewrites the survivor: *retired*'s own fields are
recorded so the commit can name its row.r�   )rý   rþ   rÿ   Úretired_row_payloadc               ó    € V ^8„  d   QhRRRR/# )rA   ÚmessagerC   rD   r‡   rF   )rG   s   "r4   rH   Ú(_count_unnamed_row.<locals>.__annotate__ý  s   € ÷ \ñ \˜ð \¨4ñ \r>   c                ój   <€ \        V P                  S4      ;'       g    V P                  S4      4      # rè   rã   )r  rÿ   rž   s   &€€r4   ÚloadedÚ"_count_unnamed_row.<locals>.loadedý  s*   ø€ Ü�G—K‘KÐ 4Ó5×ZÐZ¸¿¹ÐEYÓ9ZÓ[Ð[r>   r   c              3  óD   <"  € T F  qP                  S4      x € K  	  R # 5irè   ©rL   ©r2   r  rý   s   & €r4   r5   Ú%_count_unnamed_row.<locals>.<genexpr>  s   øé € ÐWÑ/V¨—7‘7˜7×#Ð#Ó/Vùs   ƒ TFNrF   )r¡   rž   r  rý   rþ   rÿ   r  r_   rL   rp   Úanyr	  r{   )rù   r  rþ   r  r  rý   rÿ   rž   s   &&   @@@r4   Ú_count_unnamed_rowr   ô  s÷   ú€ õ
 >÷Ró R÷\ñ \ñ ˆh×Ó™F 7ŸOšO´J¸w¿{¹{È9Ó?UÔWZ×4[Ò4[Ü),¨X¯\©\Ð:NÓ-O×-TÐ-TÐSTÓ)UÐXYÕ)YˆÐ%Ñ&÷ ‹sÔW¨w¯{©{Ð;OÓ/P×/VÐ/VÐTVÐ/VÓW�s�sŠsÔW¨w¯{©{Ð;OÓ/P×/VÐ/VÐTVÐ/VÓW×WÒWØ×ÑÐ 4°bÓ9×@Ñ@ÑATÐU\ÓA]Ö^ñ Xñ	 5\™OÑr>   c               ó    € V ^8„  d   QhRRRR/# )rA   rù   rC   rD   r›   rF   )rG   s   "r4   rH   rH     s   € ÷ 	oñ 	o ð 	o°4ñ 	or>   c                ó¼  a€ ^ RI Hp ^ RIHoHpHp V P                  V4      ;'       g    RpV P                  V4      '       d™   \        V P                  R4      \        4      '       gr   \        ;QJ d    V3R lV 4       F  '       g   K   RM	  RM! V3R lV 4       4      '       g0   V P                  V. 4      P                  / V! V 4      CSR/C4       R# R# R# R# )	zŸAn assistant fold rewrites *survivor*'s text, so on a reload without row ids its own row no longer
matches it by content. Record its loaded fields first, once.r�   )rý   rþ   r  r   c              3  óv   <"  € T F.  p\        V\        4      ;'       d    VP                  S4      x € K0  	  R # 5irè   ©r_   r`   rL   r  s   & €r4   r5   Ú$_remember_own_row.<locals>.<genexpr>  s,   øé € ÐWÉhÀsœ
 3¬Ó-×BÐB°#·'±'¸'Ó2BÔBËhùs   ƒ9Ÿ9TFNrF   )r¡   rž   r  rý   rþ   r  rL   r_   rp   r  r	  r{   )rù   rž   rþ   r  Úrecordedrý   s   &    @r4   Ú_remember_own_rowr'    s­   ø€ õ >ßiÑià�|‰|Ð0Ó1×7Ð7°R€HØ�‰Ð)×*Ò*´:¸h¿l¹lÈ9Ó>UÔWZ×3[Ò3[ß“CÔWÉhÓW—C—C’CÔWÉhÓW×WÒWØ×ÑÐ0°"Ó5×<Ñ<Ð=mÑ@SÐT\Ó@]Ð=mÐ_fÐhlÑ=mÖnñ Xñ 4\Ñ*r>   c               ó(   € V ^8„  d   QhRRRRRRRR/# )rA   Úkeptú
list[dict]rú   rC   ÚleadingrD   r›   rF   )rG   s   "r4   rH   rH     s/   € ÷ @ñ @˜jð @°>ð @ÈJð @Ð[_ñ @r>   c                óÊ   € V '       g   VP                  V4       R# \        V R,          \        4      '       d+   \        V R,          V4       \	        V R,          VRR7       R# R# )a  A durable row the repair drops was still handed to the caller, so the survivor before it stands
for it. Left unnamed, an in-place compaction takes it for a row another surface appended and
re-sequences it behind the running turn. A drop with no survivor before it waits in *leading*.F©rû   Néÿÿÿÿ)r{   r_   r`   r   r  )r)  rú   r+  s   &&&r4   Ú_retire_dropped_rowr/    sG   € ÷ Ø�‰�wÖÜ	�D˜•Hœd×	#Ò	#Ü˜4 �8 WÔ-Ü˜t B�x¨¸×?ñ 
$r>   c               ó$   € V ^8„  d   QhRRRRRR/# )rA   r)  r*  r+  rD   r›   rF   )rG   s   "r4   rH   rH     s!   € ÷ ?ñ ? 
ð ?°Zð ?ÀDñ ?r>   c                ó¶   € V '       d    \        V ^ ,          \        4      '       d   TMR F+  p\        V ^ ,          V4       \        V ^ ,          VRR7       K-  	  R# )z]Rows dropped ahead of the first survivor sit right before its own row, so it stands for them.Fr-  NrF   )r_   r`   r   r  )r)  r+  rú   s   && r4   Ú_retire_leading_dropsr2    sB   € ç"¤z°$°qµ'¼4×'@Ò'@‘7ÀbÒHˆÜ˜4 �7 GÔ,Ü˜t A�w¨¸×>ó Ir>   c               ó    € V ^8„  d   QhRRRR/# ©rA   rm   r*  rD   ztuple[list[dict], int]rF   )rG   s   "r4   rH   rH   &  s   € ÷ ñ ¨Jð Ð;Qñ r>   c           	     óN  € ^ p. pV  EF  pV'       d'   \        VR,          \        4      '       d
   VR,          MRpVeÐ   VP                  R4      R8X  dº   \        V\        4      '       d¤   VP                  R4      R8X  dŽ   \        V4      '       g}   \        V4      '       gl   VP                  R4      R9   d   \	        W44       \        W4RR7       W2R&   M,\	        WC4       \        V4       \        WC\        WC4      R7       V^,          pEK  VP                  V4       EK  	  W!3# )	zBPass 0: merge consecutive assistant turns (codex interims exempt).Nrr   rŽ   rá   Fr-  r.  >   Úverify_hook_continueÚverification_required)	r_   r`   rL   rä   r   r  r'  r÷   r{   )rm   ÚrepairsÚ	collapsedrB   rÕ   s   &    r4   Ú_merge_consecutive_assistantsr:  &  sî   € à€GØ€IÜˆß )¬j¸À2½Ì×.MÒ.Mˆy˜Ž}ÐSWˆàÒ §¡¨&Ó!1°[Ô!@Ü˜3¤×%Ò%¨#¯'©'°&«/¸[Ô*HÜ% c×*Ò*Ô3DÀT×3JÒ3Jð �x‰x˜Ó(Ð,]Ô]Ü" 3Ô-Ü& s¸Õ?Ø #˜"’ä" 4Ô-Ü! $Ô'Ü& tÔ9NÈtÓ9YÕZØ�q�LˆGÚØ×Ñ˜×ñ% ð& ÐÐr>   c               ó    € V ^8„  d   QhRRRR/# r4  rF   )rG   s   "r4   rH   rH   @  s   € ÷ *ñ * zð *Ð6Lñ *r>   c                óú  € ^ p/ p\        4       p^ p. p. pV  EFN  p\        V\        4      '       d   VP                  R4      MRpVR9   dq   / p\        4       pVR8X  d   VP                  R4      ;'       g    . MR F;  p	\	        V	4      p
V
'       g   K  V
 F  pVP                  W´4       K  	  V^,          pK=  	  M™VR8X  d“   \        VP                  R4      4      pV Uu0 uF"  pW²9   g   K  W+,          V9  g   K  W+,          kK$  	  ppV'       d!   V'       g   \        WWV4       V^,          pEK  V'       d   VP                  \        V4      4       VP                  V4       EKQ  	  \        WV4       WQ3# u upi )	zØPass 1: drop tool results not following a known assistant tool call. Consumes the whole
alias group (call_id/id/response_item_id/composite) so a duplicate keyed on a sibling
alias is not replayed to strict providers.rr   NrŽ   rY   rs   ru   ©rŽ   r�   rF   )Úsetr_   r`   rL   r   r	  r   r/  Úaddr¯   r{   r2  )rm   r8  Úknown_tool_idsÚmatched_tool_groupsÚnext_tool_groupÚfilteredr+  rB   rr   ÚtcÚvariantsÚtc_idÚresult_variantsÚcandidate_groupss   &             r4   Ú_drop_stray_tool_resultsrI  @  sr  € ð €GØ%'€Nô  #›uÐØ€OØ€HØ€GÜˆÜ",¨S´$×"7Ò"7ˆs�w‰w�vŒ¸TˆØÐ(Ô(ð  ˆNÜ"%£%ÐØ7;¸{Ô7J�s—w‘w˜|Ó,×2Ð2°øÐPRÒR�Ü0°Ó4�ß‘8Û!)˜Ø&×1Ñ1°%ÖIñ "*à# qÕ(’Oò Sð �VŒ^Ü5°c·g±g¸nÓ6MÓNˆOá3Bó Ù3B¨%ØÑ*ô &Ø/=Õ/DÐL_Ñ/_ô &�×%Ð%±?ð ð  ÷ ×'7Ü# H°7Ô;Ø˜1•�ÚßØ#×'Ñ'¬Ð,<Ó(=Ô>Ø�‰˜×ñ3 ô4 ˜(Ô,ØÐÐùò s   Ã E8Ã-
E8Ã<E8c               ó    € V ^8„  d   QhRRRR/# r4  rF   )rG   s   "r4   rH   rH   m  s   € ÷ 'ñ '¨:ð 'Ð:Pñ 'r>   c           	     óT  € ^ RI Hp ^ p. p. p\        V 4       EFô  w  rV\        V\        4      '       d?   VP                  R4      R8X  d)   VP                  R4      '       d   \        V4      '       d   VP                  V4       Km  \        4       pW^,           R  F~  p\        V\        4      '       d   VP                  R4      R8X  g    MQVP                  R4      ;'       g    RP                  4       p	V	'       g   Kd  VP                  \        V	4      4       K€  	  VR,           U
u. uF  p
\        V
4      V,          '       g   K  V
NK!  	  pp
\        V4      \        VR,          4      8w  dŽ   V^,          pV'       gL   \        VP                  4        UUu/ uF  w  rÍVR8w  g   K  WÍbK  	  upp4      '       g   \!        W6V4       EK²  V'       d   W¶R&   MVP#                  RR4       VP#                  VR4       VP                  V4       EK÷  	  \%        W44       W23# u up
i u uppi )	zÏPass 2: prune tool_calls not answered in the IMMEDIATELY following tool run (a displaced
result masks the per-call stub pass and strict providers 400). Payload-empty turns are
dropped; codex interims exempt.r�   rr   rŽ   rY   Nrs   ru   rK   )r¡   rž   Ú	enumerater_   r`   rL   rä   r{   r>  rM   Úupdater   r   rx   Ú_msg_has_payloadr  r/  r¢   r2  )rm   rž   r8  Úprunedr+  r—   rB   ÚansweredÚfollowerÚtidrD  Ú
kept_callsr  r  s   &             r4   Ú_prune_unanswered_tool_callsrT  m  s¾  € õ >à€GØ€FØ€GÜ˜H×%‰ˆä�sœD×!Ò! c§g¡g¨f£o¸Ô&DÈÏÉÐQ]×I^ÒI^Ü% c×*Ò*à�M‰M˜#ÔÙÜ›ˆØ  Q¥ Ó(ˆHÜ˜x¬×.Ò.°8·<±<ÀÓ3GÈ6Ô3QÙØ—<‘< Ó/×5Ð5°2×<Ñ<Ó>ˆCß‰sØ—‘Ô 7¸Ó <Ö=ñ )ð $' |Ö#4Ó]Ñ#4˜RÔ8MÈbÓ8QÐT\×8\Ñ8\—b�bÑ#4ˆ
Ð]Üˆz‹?œc # lÕ"3Ó4Ô4Ø�q�LˆGßÔ&6ÈÏÉÌÔ7jÉÁÀÐXYÐ]iÑXi¼¸ºÉÒ7j×&kÒ&kä# F°Ô9ÚßØ$.�LÒ!à—‘˜ dÔ+ð �G‰GÐ(¨$Ô/Ø�‰�c×ñ9 &ô: ˜&Ô*Øˆ?Ðùò! ^ùó 8ks   Ä'HÅHÆH$Æ'H$c               ó    € V ^8„  d   QhRRRR/# r4  rF   )rG   s   "r4   rH   rH   —  s   € ÷ Mñ M zð MÐ6Lñ Mr>   c                ó^  a€ ^ RI HpHp ^ RIHp ^ RIHo R V3R llp^ p. pV  EF  pV'       d'   \        VR,          \        4      '       d
   VR,          MRpVEe¹   VP                  R4      R8X  Ed¢   \        V\        4      '       Ed‹   VP                  R4      R8X  Edt   V! V4      ^ ,          Efb   VP                  R	4      \        8w  EdG   V! VP                  R
R4      4      '       Ed(   V! VP                  R
R4      4      '       Ed	   VP                  R
R4      VP                  R
R4      r©V	'       d   V
'       d   V	R,           V
,           MT	;'       g    T
pRV9   pVP                  V4      '       g   VP                  V4      '       dF   VP                  V4      '       d/   \        VP                  V4      ;'       g    ^4      ^,           Wƒ&   MVP                  VR4       W¸R
&   V	'       d	   W˜\        &   \        V4       VP                  R	4      '       dÁ   VP                  R	4      '       gª   VP                  R4      pVP                  R	R4       VP                  R4      eb   \        V\        4      '       d@   \        V\        4      '       g*   VP!                  R. 4      pWÞ9  d   VP#                  V4       VR,          VR&   VP                  VR4       W¹8w  g	   V'       d   VP                  VR4       \%        W‡RR7       V^,          pEKñ  VP#                  V4       EK  	  We3# )zHPass 3: merge consecutive plain-text user messages (no user input lost).)rž   Úsplit_user_originated_turn)ÚMERGED_DURABLE_ROWS©Ú	SessionDBc               ó    € V ^8„  d   QhRRRR/# ©rA   rR   r   rD   r‡   rF   )rG   s   "r4   rH   Ú._merge_consecutive_users.<locals>.__annotate__�  s   € ÷ cñ c˜Sð c Tñ cr>   c                ót   <€ \        V \        4      ;'       d!    V P                  SP                  4      '       * # rè   )r_   rE   ry   Ú_CONTENT_JSON_PREFIX)rR   rZ  s   &€r4   Ú_plain_textÚ-_merge_consecutive_users.<locals>._plain_text�  s,   ø€ ä˜'¤3Ó'×bÐb°×0BÑ0BÀ9×CaÑCaÓ0bÔ,bÐbr>   Nrr   r�   Údisplay_kindrR   rK   ú

Úapi_contentr   r  Tr-  r.  )r¡   rž   rW  r  rX  Úhermes_staterZ  r_   r`   rL   r   rp   r¢   r!   r"   r‡   r	  r{   r  )rm   rž   rW  rX  r`  r8  ÚmergedrB   rÕ   rñ   rò   Úmerged_contentÚhad_api_sidecarÚmarker_row_idÚabsorbed_idsrZ  s   &              @r4   Ú_merge_consecutive_usersrk  —  sŽ  ø€ çYÝJÝ&÷cð cð €GØ€FÜˆß#¬
°6¸"µ:¼t×(DÒ(Dˆv�bŽzÈ$ˆàÓ §¡¨&Ó!1°VÕ!;Ü˜3¤×%Ó%¨#¯'©'°&«/¸VÕ*Cñ +¨4Ó0°Õ3Ó;ð —‘˜Ó(Ô,>Õ>á˜DŸH™H Y°Ó3×4Ó4¹ÀSÇWÁWÈYÐXZÓE[×9\Ó9\à(,¯©°¸BÓ(?ÀÇÁÈÐTVÓAW˜+ç9EÏ+� Õ&¨Ö4Ð\h×\wÐ\wÐlwð ð ,¨tÑ3ˆOð —‘Ð-×.Ò.°$·(±(Ð;N×2OÒ2OÐUX×U\ÑU\Ð]q×UrÒUrÜ,/°·±Ð9LÓ0M×0RÐ0RÐQRÓ,SÐVWÕ,W�Ò)à—‘Ð,¨dÔ3Ø,�‰O÷ Ø+7Ô'Ñ(ä" 4Ô(ð �x‰x˜×'Ò'°·±¸×0GÒ0GØ $§¡¨Ó 3�Ø—‘˜¨Ô.Ø—7‘7˜9Ó%Ò1Ü! -´×5Ò5¼jÈÔX\×>]Ò>]Ø'+§¡Ð7JÈBÓ'O˜Ø(Ô<Ø(×/Ñ/°Ô>Ø&)¨)¥n�D˜‘Oð —‘Ð-¨tÔ4ð Ô-·Ø—‘Ð-¨tÔ4Ü" 4°TÕ:Ø�q�LˆGÚØ�‰�c×ñA ðB ˆ?Ðr>   c               ó    € V ^8„  d   QhRRRR/# )rA   rm   r*  rD   r›   rF   )rG   s   "r4   rH   rH   ì  s   € ÷ %ñ %°*ð %Àñ %r>   c                ó®   € ^ RI Hp V  FH  p\        V\        4      '       g   K  VP	                  R4      pVP                  V4      pWCJg   KD  WBR&   KJ  	  R# )u‚  Decode any sentinel-encoded row content in place before the alternation passes run, so an
image-bearing turn is never merged as text (#125299). A multimodal turn can re-enter the working set
as its ``\x00json:[â€¦]`` string (e.g. after a proactive prune re-inserts history, #124102). A body
that no longer parses stays a sentinel string; ``_merge_consecutive_users`` refuses to weld it.rY  rR   N)re  rZ  r_   r`   rL   Ú_decode_content)rm   rZ  rB   rR   Údecodeds   &    r4   Ú#_normalize_sentinel_encoded_contentrp  ì  sL   € õ
 'ãˆÜ˜#œt×$Ò$ÙØ—'‘'˜)Ó$ˆØ×+Ñ+¨GÓ4ˆØÕ!Ø$�	‹Nó r>   c               ó    € V ^8„  d   QhRRRR/# ©rA   rm   r*  rD   rp   rF   )rG   s   "r4   rH   rH   þ  s   € ÷ ñ ¨Zð ¸Cñ r>   c                óŒ   € V'       g   ^ # \        V4       ^ pTp\         F  pV! V4      w  r5W%,          pK  	  V^ 8”  d   W1R&   V# )aj  Collapse malformed role-alternation left in the live history; returns repair count.
Providers require strict alternation after the system message (violations: silent empty
responses or 400s); this is the pre-call belt for host-fed, resumed or replayed histories.
Passes in order: decode any sentinel-encoded multimodal rows (so an image is not merged as text);
merge consecutive assistant turns (BEFORE orphan detection so the merged tool_call-id union is
known); drop stray tool results; prune unanswered tool_calls; merge consecutive user turns. A user
turn directly after an assistant turn is valid and left alone.
r¹   )rp  Ú_SEQUENCE_REPAIR_PASSES)r”   rm   r8  ÚcurrentÚrepair_passÚmades   &&    r4   Úrepair_message_sequencerx  þ  sN   € ÷ ÙÜ'¨Ô1Ø€GØ€Gß.ˆÙ# GÓ,‰ˆØ�Šñ /ð �„{à�‰Ø€Nr>   c               ó    € V ^8„  d   QhRRRR/# rr  rF   )rG   s   "r4   rH   rH     s   € ÷ ñ ¸ð Èñ r>   c                óÊ  aaa€ ^ RI Ho \        V RR4      p\        V\        4      '       d&   V^ 8”  d   VRV  Uu0 uF  p\        V4      kK  	  upMRoV Uu0 uF?  p\        V\        4      '       g   K  VP                  S4      '       g   K4  \        V4      kKA  	  upo\        W4      pV^ 8”  d¨   S'       dJ   \        ;QJ d     VV3R lV 4       F  '       g   K   RM	  RM! VV3R lV 4       4      '       d   RV n
        \        V R4      '       dE   Se   \        V3R lV 4       4      V n        V# \        V P                  \        V4      4      V n        V# u upi u upi )a  Run :func:`repair_message_sequence` and keep ``_last_flushed_db_idx`` consistent. Repair
shrinks the list in place; counting identity-preserved survivors of the flushed prefix gives
the exact new cursor, whereas a ``min()`` clamp would skip unflushed rows (used only without a snapshot).r�   Ú_last_flushed_db_idxNc              3  ó|   <"  € T F1  p\        V4      S9   ;'       d    VP                  S4      '       * x € K3  	  R # 5irè   )ÚidrL   )r2   r•   rž   Ústamped_idss   & €€r4   r5   Ú6repair_message_sequence_with_cursor.<locals>.<genexpr>#  s5   øé € ð 
ÙNVÈŒBˆq‹E�[Ñ ×DÐD¨¯©Ð/CÓ)DÔ%DÔDËhùs   ƒ<�<TFc              3  óL   <"  € T F  p\        V4      S9   g   K  ^x € K  	  R# 5i)é   N©r}  )r2   r•   Úflushed_idss   & €r4   r5   r  )  s   øé € Ð0]¹H°qÌÈ1ËÐQ\ÑH\·²»Hùó   ƒ$š
$)r¡   rž   rÑ   r_   rp   r}  r`   rL   rx  r  Ú_db_flush_scan_prefixÚhasattrÚsumr{  r¯   rx   )r”   rm   Úflush_cursorr•   r8  rž   rƒ  r~  s   &&   @@@r4   Ú#repair_message_sequence_with_cursorr‰    s'  ú€ õ >ä˜5Ð"8¸$Ó?€LÜ>HÈÔWZ×>[Ò>[Ð`lÐopÔ`p (¨=¨LÑ"9Ó:Ñ"9˜Q”2�a–5Ñ"9Ò:Ðvz€KÙ"*Ób¡(˜Q¬j¸¼D×.A”5ÀaÇeÁeÐL`×Fa”5”2�a–5¡(Ñb€KÜ% eÓ6€GØ�„{÷ Ÿ3›3õ 
ÙNVó
Ÿ3Ÿ3š3õ 
ÙNVó
÷ 
ò 
ð +/ˆEÔ'Ü�5Ð0×1Ò1ØÒ&Ü-0Ô0]¹HÓ0]Ó-]�Ô*ð €Nô .1°×1KÑ1KÌSÐQYË]Ó-[�Ô*Ø€Nùò! ;ùÚbs   »EÁE Á5E ÂE c               ó    € V ^8„  d   QhRRRR/# )rA   rR   r   rD   rE   rF   )rG   s   "r4   rH   rH   /  s   € ÷ ñ  3ð ¨3ñ r>   c                óJ  € \        V \        4      '       d   V # \        V \        4      '       d   RP                  R V  4       4      # \        V \        4      '       d>   \        V P                  R4      ;'       g    V P                  R4      ;'       g    R4      # \        V 4      # )zïFlatten list/dict content (e.g. Anthropic-via-OpenRouter block lists) to text: a raw list
hitting ``re.sub`` raises TypeError and the loop retries forever. Thinking/reasoning blocks
are dropped outright; their text key varies per provider.rK   c              3  óÞ  "  € T Fã  p\        V\        4      '       g    \        V\        4      '       g   K1  \        VP                  R 4      ;'       g    R4      P	                  4       P                  4       R9  g   Kx  \        VP                  R4      \        4      '       g   KŸ  VP                  R4      '       g   K¸  \        V\        4      '       d   TMVP                  R4      x € Kå  	  R# 5i)rŸ   rK   ÚtextN>   ÚthinkingrJ   Úredacted_thinking)r_   rE   r`   rL   rM   Úlower)r2   Úparts   & r4   r5   Ú(_flatten_content_text.<locals>.<genexpr>6  s³   é € ð 
á�Ü˜$¤×$Ò$Ü˜4¤×&ô @ô ˜Ÿ™ Ó(×.Ð.¨BÓ/×5Ñ5Ó7×=Ñ=Ó?ÐGuÑuô	 @ô
 ˜tŸx™x¨Ó/´×5ô @ð
 ;?¿(¹(À6×:Jô @”J˜t¤S×)Ò)‰D¨t¯x©x¸Ó/?Ô?Ûùs"   ‚.C-µC-Á%C-Á<"C-Â#C-Â<1C-r�  rR   )r_   rE   r¦   r“   r`   rL   rT   s   &r4   Ú_flatten_content_textr“  /  s‡   € ô �'œ3×ÒØˆÜ�'œ4× Ò Ø�w‰wñ 
áó
ó 
ð 	
ô �'œ4× Ò Ü�7—;‘;˜vÓ&×FÐF¨'¯+©+°iÓ*@×FÐFÀBÓGÐGÜˆw‹<Ðr>   c               ó    € V ^8„  d   QhRRRR/# rQ   rF   )rG   s   "r4   rH   rH   P  s   € ÷ ñ  sð ¨sñ r>   c                ó‚   € V'       d   \        V4      MRpV'       d   \        MR F  pVP                  RV4      pK  	  V# )ak  Remove reasoning/thinking blocks from content, returning only visible text: closed tag
pairs, unterminated open tags at a block boundary (mirrors ``gateway/stream_consumer.py``),
stray orphan tags (all case-insensitive variants), and standalone tool-call XML blocks some
open models emit; ``<function>`` is boundary- and ``name=``-gated so prose mentions survive.rK   rF   )r“  Ú_THINK_STRIP_PATTERNSÚsub)r”   rR   Úpatterns   && r4   Ústrip_think_blocksr™  P  s:   € ÷
 18Ô# GÔ,¸R€Gß,3Õ(¸Ò;ˆØ—+‘+˜b 'Ó*Šñ <à€Nr>   c               ó   € V ^8„  d   QhRR/# ©rA   rD   r›   rF   )rG   s   "r4   rH   rH   [  s   € ÷ 
/ñ 
/¨Dñ 
/r>   c                ó¢   € \        V RR4      p Ve   VP                  \        V RR4      4      MRV n        R#   \         d    RT n         R# i ; i)zèRebind ``agent._credential_pool_entry_id`` from the current pool + key. OAuth refreshes
can replace the token before recovery runs, so the key alone cannot attribute a failure;
the stable entry ID can. Cleared when no pool is bound.Ú_credential_poolNÚapi_key)rÑ   Úentry_id_for_api_keyÚ_credential_pool_entry_idÚ	Exception)r”   Úpools   & r4   Úsync_credential_pool_entry_idr£  [  sX   € ô �5Ð,¨dÓ3€Dð/àJNÒJZˆD×%Ñ%¤g¨e°YÀÓ&EÔFÐ`dð 	Ö'øô ô /Ø*.ˆ×'ð/ús   �'8 ¸AÁAé’  é­  é‘  é“  c               ó   € V ^8„  d   QhRR/# )rA   rD   z#tuple[Optional[str], Optional[str]]rF   )rG   s   "r4   rH   rH   p  s   € ÷ 'ñ 'Ð0Sñ 'r>   c                óX  € \        V RR4      ;'       g    Rp\        V RR4      p\        V\        4      '       d   V'       d   TMRpV'       g[   VP                  4       pV'       dC   \        VRR4      pV'       g.   \        VRR4      p\        V\        4      '       d   V'       d   TpW$3# )zÞ``(api_key_hint, credential_id)`` of the key actually dispatched, not ``pool.current()``:
the shared pointer often points at a different healthy entry, and marking it exhausted
can take the whole pool offline from one 429.rž  Nr   Úruntime_api_keyr}  )rÑ   r_   rE   ru  )r”   r¢  Úapi_key_hintÚraw_idÚcredential_idÚcurÚ
current_ids   &&     r4   Ú_failed_credential_identityr°  p  sŒ   € ô ˜5 )¨TÓ2×:Ð:°d€LÜ�UÐ7¸Ó>€FÜ(¨´×5Ò5¿&‘FÀd€MßØ�l‰l‹nˆßÜ" 3Ð(9¸4Ó@ˆLß Ü$ S¨$°Ó5�
Ü˜j¬#×.Ò.·:Ø$.�MØÐ&Ð&r>   c               ó   € V ^8„  d   QhRR/# ©rA   rD   r‡   rF   )rG   s   "r4   rH   rH   ‚  s   € ÷ #ñ #¸dñ #r>   c                ó4  a€ V P                  SV4      '       d   R# VR8w  d   R# RP                  V3R lR 4       4      pRV9   d   R# V P                  ;'       g    RpVR8X  d   \        V R	R4      R
8X  d   R# VR8X  d   RV9   ;'       g    RV9   '       * # R# )zßEntitlement 403s look like auth failures but refresh cannot fix them. Any xai-oauth 403
is entitlement EXCEPT xAI's stale-token signals (``[WKE=unauthenticated:...]``,
"could not be validated"), which must stay refreshable.Tr§  FÚ c              3  ó¸   <"  € T FO  p\        S\        4      '       g   K  \        SP                  V4      ;'       g    R 4      P	                  4       x € KQ  	  R# 5i)rK   N)r_   r`   rE   rL   r�  )r2   r  Úerror_contexts   & €r4   r5   Ú&_is_entitlement_403.<locals>.<genexpr>Š  sJ   øé € ð ñ 8ˆAÜ�m¤T×*ô 	0ŒˆM×Ñ˜aÓ ×&Ð& BÓ'×-Ñ-×/Ð/Û7ùs   ƒA A½AzCoauth authentication is currently not allowed for this organizationrK   Ú	anthropicÚapi_modeÚanthropic_messagesz	xai-oauthz[wke=unauthenticated:z*oauth2 access token could not be validated)r  ÚreasonÚcodeÚerror)Ú_is_entitlement_failurer“   ÚproviderrÑ   )r”   Ústatus_coder¶  Úhaystackr¿  s   &&f  r4   Ú_is_entitlement_403rÂ  ‚  s²   ø€ ð ×$Ñ$ ]°K×@Ò@ÙØ�cÔÙØ�x‰xô ñ 8óó €Hð" MÐPXÔXÙØ�~‰~×#Ð# €HØ�;Ô¤7¨5°*¸bÓ#AÐEYÔ#YÙØ�;Ôà# xÑ/÷ Hð HØ;¸xÑGô
ð 	
ñ r>   c               ó   € \        WV4      '       dD   \        4       P                  P                  R Ve   TMRV P                  ;'       g    R4       RV3# RV/pV'       d   WhR&   VP
                  ! R/ VB p	V	f   V! RR4      '       d   R# RV3# \        V	R
R4      p
V
e“   \        V RR4      f   / V n        V P                  pV P                  V
3pVP                  V^ 4      ^,           W¼&   W¼,          \        8”  d7   \        4       P                  P                  RW¼,          ^,
          V
4       RV3# \        4       P                  P                  R\        V	R
R4      4       V P                  V	4      RJ d   RV3# R	V3# )uƒ   Credential %s â€” entitlement-shaped 403 from %s; skipping pool refresh (account lacks subscription, not a transient auth failure).NÚauthr¿  Fr«  r­  r¦  zauth refresh failedTr}  Ú_auth_pool_refresh_countsu†   Credential auth failure persists after %s refreshes for pool entry %s â€” treating as unrecoverable and allowing fallback to activate.u3   Credential auth failure â€” refreshed pool entry %sr·   rF   ©TF)rÂ  r=   rd   Úinfor¿  Útry_refresh_matchingrÑ   rÅ  rL   Ú_MAX_AUTH_REFRESH_ATTEMPTSre   Ú_swap_credential)r”   r¢  rÀ  Úhas_retried_429r¶  r«  r­  Úrotate_and_swapÚrefresh_kwargsÚ	refreshedÚrefreshed_idÚrefresh_countsÚrefresh_keys   &&$$$$$$     r4   Ú_recover_auth_failurerÒ  ¨  sŠ  € Ü˜5¨}×=Ò=Ü‹�‰×Ñð-à=HÒ=T©kÐZ`Ø�N‰N×(Ð(˜jô		
ð �oÐ%Ð%ð % lÐ3€NßØ*7�Ñ'Ø×)Ò)Ñ;¨NÑ;€IØÒá /°Ð5J× KÒ Kˆ}ÐiÐRWÐYhÐQiÐiô ˜9 d¨DÓ1€LØÒÜ�5Ð5°tÓ<ÒDØ.0ˆEÔ+Ø×8Ñ8ˆØ—~‘~ |Ð4ˆØ&4×&8Ñ&8¸ÀaÓ&HÈ1Õ&LˆÑ#ØÕ&Ô)CÔCÜ‹E�L‰L× Ñ ð(à)7Õ)DÀqÕ)HÈ,ôð
 ˜/Ð)Ð)ÜƒE‡L�L×ÑÐKÌWÐU^Ð`dÐfiÓMjÔkØ×Ñ˜iÓ(¨EÓ1Ø�oÐ%Ð%Ø�Ð Ð r>   c               óê  aaa	a
€ R pS'       d%   \        V3R lV P                  4        4       R 4      pS'       d/   T;'       g%    \        V3R lV P                  4        4       R 4      pVf   V P                  4       pV'       d   \        VRR 4      MR pV\        8X  d8   \        4       P                  P                  RV4       V! RR4      '       d   R# R# RpV'       dñ   \        VP                  R	4      ;'       g    R
4      P                  4       o
\        VP                  R4      ;'       g    R
4      P                  4       o	\        ;QJ d#    V
3R l\         4       F  '       g   K   RM	  RM! V
3R l\         4       4      ;'       gC    \        ;QJ d#    V	3R l\         4       F  '       g   K   RM	  RM! V	3R l\         4       4      pV'       g   V'       g   R# V! RR4      '       d   R# R# )Nc              3  óL   <"  € T F  qP                   S8X  g   K  Vx € K  	  R # 5irè   r‚  ©r2   Úer­  s   & €r4   r5   Ú&_recover_rate_limit.<locals>.<genexpr>Õ  s   øé € ÐQ© A¿4¹4À=Ñ;PŸaša«ùr„  c              3  óL   <"  € T F  qP                   S8X  g   K  Vx € K  	  R # 5irè   )rª  )r2   rÖ  r«  s   & €r4   r5   r×  Ø  s   øé € ÐL™�1×*;Ñ*;¸|Ñ*K�QŠQ›ùr„  Úlast_statusuZ   Credential already exhausted (last_status=%s) â€” rotating immediately instead of retryingr¥  zrate limit, pre-exhaustedTFr»  rK   r  c              3  ó,   <"  € T F	  qS9   x € K  	  R # 5irè   rF   )r2   ÚtÚcontext_reasons   & €r4   r5   r×  ç  s   øé € Ð!ZÑ?Y¸! ~Ö"5Ó?Yùó   ƒc              3  ó,   <"  € T F	  qS9   x € K  	  R # 5irè   rF   )r2   rÛ  Úcontext_messages   & €r4   r5   r×  ç  s   øé € ð b
Ù*E Q�Ö Ó*EùrÝ  z
rate limitrÆ  )FT)ÚnextÚentriesru  rÑ   r   r=   rd   rÇ  rE   rL   r�  r  Ú_USAGE_LIMIT_REASON_TOKENSÚ_USAGE_LIMIT_MESSAGE_TOKENS)r¢  rË  r¶  r«  r­  rÌ  Úcurrent_entryÚcurrent_last_statusÚusage_limit_reachedrß  rÜ  s   &$$dd$   @@r4   Ú_recover_rate_limitrç  Ð  sŽ  û€ ð €MßÜÔQ¨¯©¬ÓQÐSWÓXˆßØ%÷ 
ð 
¬ÜL˜Ÿ™œÓLÈdó*
ˆð ÒØŸ™›ˆßIVœ' -°ÀÔEÐ\`ÐØÔ.Ô.Ü‹�‰×ÑØhØô	
ñ !0°Ð5P× QÒ Qˆ}ÐdÐWdÐdØÐßÜ˜]×.Ñ.¨xÓ8×>Ð>¸BÓ?×EÑEÓGˆÜ˜m×/Ñ/°	Ó:×@Ð@¸bÓA×GÑGÓIˆß!›cÔ!ZÕ?YÓ!ZŸcŸcšcÔ!ZÕ?YÓ!ZÓZ÷ 
ð 
×^aÓ^aô b
Ý*Eób
×^a×^aÒ^aô b
Ý*Eób
ó _
Ð÷ ×#6ØÐÙ+¨C°×>Ò>ˆ=ÐQÀMÐQr>   Úclassified_reasonr¶  Úbilling_unverifiedFc               ó0   € V ^8„  d   QhRRRRRRRRR	RR
R/# )rA   rÀ  zOptional[int]rË  r‡   rè  zOptional[FailoverReason]r¶  zOptional[dict[str, Any]]ré  rD   útuple[bool, bool]rF   )rG   s   "r4   rH   rH   ï  sL   € ÷ {"ñ {"Ø(ð{"Ø;?ð{"à/ð{"ð ,ð{"ð IMð{"ð ñ	{"r>   c               ór  a aaaa
aaa€ S P                   oSf   RV3# \        S RR4      ;'       g    RP                  4       P                  4       p\        SRR4      ;'       g    RP                  4       P                  4       pV'       dH   \	        SV\        S RR4      R7      '       g)   \        4       P                  P                  RWv4       RV3# \        S S4      w  o
oVoSf   \        P                  S4      oR V V
VVVVVV3R	 llpS\        P                  8X  d}   S'       d   S;'       g    / P                  R
4      MRp	V	'       d)   \        4       P                  P                  RV	4       RV3# \        4       P                  P                  R4       RV3# S\        P                  8X  d   V! RR4      '       d   R# RV3# S\        P                  8X  d   \!        SVSS
SVR7      # S\        P"                  8X  d   V! RR4      V3# S\        P$                  8X  d   \'        S SSVSS
SVR7      # RV3# )a]  Attempt credential recovery via pool rotation; returns (recovered, has_retried_429).
Rate limits: retry once, then rotate. Billing: rotate immediately. Auth: refresh before
rotating. ``classified_reason`` beats raw HTTP codes (e.g. Anthropic 400 "out of extra
usage"); ``billing_unverified`` gives the entry a short cooldown, not the one-hour bench.NFr¿  rK   Úbase_url©rí  uu   Credential pool provider mismatch: pool=%s, agent=%s â€” skipping pool mutation to avoid cross-provider contaminationc               ó$   € V ^8„  d   QhRRRRRR/# )rA   Údefault_statusrp   ÚlabelrE   rD   r‡   rF   )rG   s   "r4   rH   Ú2recover_with_credential_pool.<locals>.__annotate__  s!   € ÷ 2ñ 2¨ð 2°Sð 2¸Tñ 2r>   c           
     ó|  <€ Se   SMT pRVRSRS
/pS'       d   SVR&   Se   ^ RI Hp V! SSS4      VR&   \        S	RR4      p\        V\        4      '       d   VP                  4       '       d   WSR&   SP                  ! R/ VB pVf   R	# \        V\        S	R
R4      4      '       g3   \        4       P                  P                  RW!\        VRR4      4       R	# \        4       P                  P                  RW!\        VRR4      4       S	P                  V4      R	JpS'       d%   \        V3R lSP                  4        4       R4      MRpV'       dj   Vef   VP                  \        VRVP                  4      8  d@   \        S	RR4      '       g-   S\        P                   \        P"                  39   d   SS	n        V# )zMRotate away from the failed credential; True when a new entry was swapped in.NrÀ  r¶  r«  r­  )Úpool_failure_reasonÚfailure_reasonÚmodelFrí  uJ   Credential %s (%s) â€” pool entry %s serves another endpoint; not swappingr}  r·   u/   Credential %s (%s) â€” rotated to pool entry %sc              3  óL   <"  € T F  qP                   S8X  g   K  Vx € K  	  R # 5irè   r‚  rÕ  s   & €r4   r5   ÚIrecover_with_credential_pool.<locals>._rotate_and_swap.<locals>.<genexpr>6  s   øé € ÐK¡>˜a·T±T¸]Ñ5JŸš£>ùr„  ÚpriorityÚ_credential_pool_revert_idrF   )Ú%agent.credential_pool_model_cooldownsrô  rÑ   r_   rE   rM   Úmark_exhausted_and_rotater   r=   rd   rÇ  rÊ  rà  rá  rù  r   Ú
rate_limitÚbillingrú  )rð  rñ  Úrotate_statusÚkwargsrô  rö  Ú
next_entryÚswappedÚbenchedr”   r«  ré  r­  Úeffective_reasonr¶  r¢  rÀ  s   &&       €€€€€€€€r4   Ú_rotate_and_swapÚ6recover_with_credential_pool.<locals>._rotate_and_swap  s˜  ø€ à'2Ò'>™ÀNˆà˜=Ø˜]Ø˜Lð
ˆ÷
 Ø&3ˆF�?Ñ#ð Ò'ÝQÙ':Ð;KÈ]Ð\nÓ'oˆFÐ#Ñ$Ü˜˜w¨Ó-ˆÜ�eœS×!Ò! e§k¡k§m¢mØ#�7‰OØ×3Ò3Ñ=°fÑ=ˆ
ØÒÙÜ4°ZÄÈÐPZÐ\`ÓAa×bÒbô ‹E�L‰L×ÑØ\Ø¤g¨j¸$ÀÓ&Dôñ Ü‹�‰×ÑØ=Ø¤'¨*°d¸CÓ"@ô	
ð ×(Ñ(¨Ó4¸EÐAˆßVc”$ÔK 4§<¡<¤>ÓKÈTÔRÐimˆçØÒ#Ø× Ñ ¤7¨:°zÀ7×CSÑCSÓ#TÔTÜ˜EÐ#?À×FÒFØ ¤^×%>Ñ%>Ä×@VÑ@VÐ$WÔWð 0=ˆEÔ,Øˆr>   Úupstream_providerun   Upstream provider %s rate-limited via aggregator â€” skipping credential rotation, deferring to fallback chainuh   Upstream aggregator 429 (provider unknown) â€” skipping credential rotation, deferring to fallback chainr¤  rþ  )rË  r¶  r«  r­  rÌ  é�  zmodel entitlement)rÀ  rË  r¶  r«  r­  rÌ  rÆ  )r�  rÑ   rM   r�  r   r=   rd   re   r°  Ú_STATUS_TO_FAILOVER_REASONrL   r   Úupstream_rate_limitrÇ  rþ  rý  rç  Úmodel_entitlementrÄ  rÒ  )r”   rÀ  rË  rè  r¶  ré  Úcurrent_providerÚpool_providerr  Úupstreamr«  r­  r  r¢  s   fd$$dd    @@@@r4   Úrecover_with_credential_poolr  ï  s8  ÿ€ ð ×!Ñ!€DØ‚|Ø�oÐ%Ð%ô    z°2Ó6×<Ð<¸"×CÑCÓE×KÑKÓMÐÜ˜T :¨rÓ2×8Ð8°b×?Ñ?ÓA×GÑGÓI€MßÔ=ØÐ¬°¸
ÀDÓ)I÷ó ô 	‹�‰×ÑðKàô	
ð
 �oÐ%Ð%Ü"=¸eÀTÓ"JÑ€L�-Ø(ÐØÒÜ5×9Ñ9¸+ÓFÐ÷2÷ 2ðf œ>×=Ñ=Ô=÷ FS�M×'Ð' R×,Ñ,Ð-@ÔAÐX\ˆßÜ‹E�L‰L×ÑðCØDLôð �oÐ%Ð%ô	 ‹E�L‰L×ÑðCôð �oÐ%Ð%Øœ>×1Ñ1Ô1ñ !1°°i× @Ò @ˆ}Ð^ÀuÈoÐF^Ð^Øœ>×4Ñ4Ô4Ü"Ø /ÀØ%°]ÐTdô
ð 	
ð œ>×;Ñ;Ô;ñ   Ð%8Ó9¸?ÐJÐJØœ>×.Ñ.Ô.Ü$Ø�4 [À/Ø'°lÐR_Ø,ô
ð 	
ð
 �/Ð!Ð!r>   c               ó    € V ^8„  d   QhRRRR/# ©rA   ÚrtrC   rD   r›   rF   )rG   s   "r4   rH   rH   m  s   € ÷ 5ñ 5¨^ð 5Àñ 5r>   c                ó0  € VR,          V n         VR,          V n        VP                  RV P                  4      V n        VR,          V n        ^ RIHp V! V P                  V P                  4      '       d   RMVR,          V n        \        V R4      '       d   V P                  P                  4        VR	,          V n        VP                  R
R4      V n        \        VP                  R4      ;'       g    / 4      V n        \        VR,          4      V n        R# )z«Copy the identity/transport fields of a ``_primary_runtime`` snapshot onto ``agent``
(shared by transport recovery and turn-start restore; the caller rebuilds the client).rö  r¿  Úrequested_providerrí  )Úis_actual_routeÚchat_completionsr¹  Ú_transport_cacherž  Úreasoning_echo_flagFÚrequest_overridesÚclient_kwargsN)rö  r¿  rL   r  rí  Úhermes_cli.providersr  r¹  r†  r  Úclearrž  Ú_reasoning_echo_flagr`   r  Ú_client_kwargs)r”   r  r  s   && r4   Ú_apply_primary_runtime_fieldsr  m  sÕ   € ð �W•+€E„KØ˜
•^€E„NØ!Ÿv™vÐ&:¸E¿N¹NÓK€EÔØ˜
•^€E„NÝ4Ù+:¸5¿>¹>È5Ï>É>×+ZÒ+ZÑ'Ð`bÐcmÕ`n€E„NÜˆuÐ(×)Ò)Ø×Ñ×$Ñ$Ô&Ø�y•M€E„MØ!#§¡Ð(=¸uÓ!E€EÔÜ" 2§6¡6Ð*=Ó#>×#DÐ#DÀ"ÓE€EÔÜ  ?Õ 3Ó4€EÖr>   c               ó    € V ^8„  d   QhRRRR/# r  rF   )rG   s   "r4   rH   rH   ~  s   € ÷ 
ñ 
°Nð 
Àtñ 
r>   c                óì   € ^ RI Hp VR,          V n        VR,          V n        V! VR,          VR,          \	        V P
                  V P                  4      R7      V n        VR,          V n        RV n	        R# )zIRebuild the native Anthropic client from a ``_primary_runtime`` snapshot.©Úbuild_anthropic_clientÚanthropic_api_keyÚanthropic_base_url©ÚtimeoutÚis_anthropic_oauthN)
Úagent.anthropic_adapterr#  Ú_anthropic_api_keyÚ_anthropic_base_urlr
   r¿  rö  Ú_anthropic_clientÚ_is_anthropic_oauthÚclient)r”   r  r#  s   && r4   Ú$_build_anthropic_client_from_runtimer/  ~  sh   € å>Ø!Ð"5Õ6€EÔØ "Ð#7Õ 8€EÔÙ4Ø
ÐÕ Ð$8Õ!9Ü,¨U¯^©^¸U¿[¹[ÓIô€EÔð !#Ð#7Õ 8€EÔØ€E†Lr>   c               ó$   € V ^8„  d   QhRRRRRR/# )rA   r  rC   r»  rE   rD   r›   rF   )rG   s   "r4   rH   rH   ‹  s&   € ÷ jñ j ~ð jÀ#ð jÈ$ñ jr>   c               óÜ  € V P                   ;'       g    RP                  4       P                  4       R8X  d'   ^ RIHp V! W P
                  4      V n        RV n        R# V P                   R8X  d7   V P                  R9   d&   ^ RI	H
p V! W P                  V P                  4       R# V P                  R8X  d   \        W4       R# V P                  \        VR,          4      VR	R
7      V n        R# )znRebuild the primary client from a ``_primary_runtime`` snapshot (MoA facade / native Anthropic / OpenAI wire).rK   Úmoa©Úbuild_moa_facadeNÚbedrockrº  ©Úbind_bedrock_runtimer  T©r»  Úshared©rº  Úbedrock_converse)r¿  rM   r�  Úagent.moa_loopr4  rö  r.  r,  r¹  Úagent.bedrock_adapterr7  rí  r/  Ú_create_openai_clientr`   )r”   r  r»  r4  r7  s   &&$  r4   Ú_rebuild_primary_clientr?  ‹  s®   € à�‰×Ð˜"×#Ñ#Ó%×+Ñ+Ó-°Ô6õ 	4Ù'¨¯{©{Ó;ˆŒð
 #'ˆÖØ	�‰˜9Ô	$¨¯©Ð;eÔ)eÝ>Ù˜U§N¡N°E·N±NÖCØ	�‰Ð/Ô	/Ü,¨UÖ7à×2Ñ2´4¸¸?Õ8KÓ3LÐU[ÐdhÐ2ÓiˆŽr>   c               ó(   € V ^8„  d   QhRRRRRRRR/# )rA   Ú	api_errorr¡  Úretry_countrp   Úmax_retriesrD   r‡   rF   )rG   s   "r4   rH   rH      s,   € ÷ &ñ &Øð&Ø14ð&ØCFð&à	ñ&r>   c          
     óf  € \        V4      P                  pV P                  '       g"   V\        9  g   V P	                  4       '       d   R# V P
                  ;'       g    RP                  4       P                  4       R9   d   \        V RR4      R8w  d   R#  \        V RR4      eI   \        P                  ! \        4      ;_uu_ 4        V P                  V P                  RR7       RRR4       V P                  p\        W4       \!        WRR7       \#        ^V,           ^4      pV P%                  V P&                   R	V R
V P
                   RV R2RRR7       \(        P*                  ! V4       R#   + '       g   i     L“; i  \         d"   p\,        P/                  RT4        Rp?R# Rp?ii ; i)z³Rebuild the primary client once and retry after ``max_retries`` exhaust on a transient
transport error. Skipped for aggregators (OpenRouter, Nous) that manage retries server-side.FrK   r¹  Nrº  r.  Úprimary_recovery)r»  u   ðŸ”� Transient z on u    â€” rebuilt client, waiting z"s before one last primary attempt.T)ÚforceÚ
diagnosticz%Primary transport recovery failed: %s>   ÚnousÚnousresearchúnous-portal)rŸ   r¼   Ú_fallback_activatedÚ_TRANSIENT_TRANSPORT_ERRORSÚ_is_openrouter_urlr¿  rM   r�  rÑ   r¿   rÀ   r¡  Ú_retire_shared_openai_clientr.  Ú_primary_runtimer  r?  r¯   Ú_vprintÚ
log_prefixrÒ   Úsleeprd   re   )r”   rA  rB  rC  Ú
error_typer  Ú	wait_timerÖ  s   &&$$    r4   Útry_recover_primary_transportrU     sn  € ô
 �i“×)Ñ)€JØ× × Ð  JÔ6QÔ$QÐUZ×UmÑUm×UoÒUoÙð 
�‰×	Ð	˜2×$Ñ$Ó&×,Ñ,Ó.Ð2YÔYÜ�E˜: tÓ,Ð0DÔDáðô �5˜( DÓ)Ò5Ü×$Ò$¤Y×/Õ/Ø×2Ñ2°5·<±<ÐHZÐ2Ô[÷ 0à×#Ñ#ˆÜ% eÔ0Ü Ð2DÕEÜ˜˜K�¨Ó+ˆ	Ø�‰Ø×ÑÐ  °
¨|¸4ÀÇÁÐ?Oð P'Ø'0 kÐ1SðUØ\`Ðmqð 	ô 	
ô 	�
Š
�9ÔÙ÷ 0×/ûô ô Ü�‰Ð>ÀÔBÝûðús1   Â1F ÃE1Ã&B	F Å1F	Å<F ÆF0ÆF+Æ+F0c               ó$   € V ^8„  d   QhRRRRRR/# )rA   rñ   r   Úcur_contentrD   rF   )rG   s   "r4   rH   rH   É  s!   € ÷ ñ  cð ¸ð Àñ r>   c                ó�  € \        V \        4      '       dE   \        V\        4      '       d/   Y '       d   V'       d   R,           V,           # R,           V,           # \        V \        4      '       d2   \        V\        4      '       d   \        V 4      \        V4      ,           # \        V \        4      '       d>   \        V\        4      '       d(   \        V 4      V'       d   RRRV/.,           # . ,           # \        V \        4      '       d8   \        V\        4      '       d"   V '       d   RRRV /.M. \        V4      ,           # \        # )z¡Merged content for two adjacent user messages (``_UNMERGEABLE`` for unknown shapes):
string+string joins with a blank line; list sides append as separate blocks.rc  rK   rŸ   r�  )r_   rE   r¦   Ú_UNMERGEABLE)rñ   rW  s   &&r4   Ú_merge_user_contentrZ  É  sð   € ô �,¤×$Ò$¬°KÄ×)EÒ)EØ®¿+˜vÕNÐQ\Õ\Ð\È2ÕNÐQ\Õ\Ð\Ü�,¤×%Ò%¬*°[Ä$×*GÒ*GÜ�LÓ!¤D¨Ó$5Õ5Ð5Ü�,¤×%Ò%¬*°[Ä#×*FÒ*FÜ�LÓ!×P[ v¨v°v¸{Ð&KÐ%LÕdÐdÐacÕdÐdÜ�,¤×$Ò$¬°KÄ×)FÒ)Fß<H�&˜& &¨,Ð7Ñ8ÈbÔTXÐYdÓTeÕeÐeÜÐr>   Údrop_codex_reasoning_itemsTÚdrop_nudge_markerc               ó(   € V ^8„  d   QhRRRRRRRR/# )rA   rm   rn   r[  r‡   r\  úOptional[str]rD   rF   )rG   s   "r4   rH   rH   Ú  s.   € ÷ (ñ (Ø"ð(ØCGð(à$ð(ð ñ(r>   c               ó  € V '       g   V # V  Uu. uFc  pVe/   VP                  R4      R8X  d   VP                  R4      V8X  d   K5  \        4       P                  P                  W1R7      '       d   Ka  VNKe  	  pp\	        V 4      \	        V4      ,
          p. p^ pV F©  pV'       d
   VR,          MRp\
        p	VeY   VP                  R4      R8X  dC   VP                  R4      R8X  d-   \        VP                  RR4      VP                  RR4      4      p	V	\
        J d   VP                  V4       K•  / VCRV	/CVR&   V^,          pK«  	  V^ 8X  d
   V^ 8X  d   V # \        4       P                  P                  RWW4       V# u upi )	uJ  Drop thinking-only assistant turns and merge adjacent user messages left behind, on the
per-call ``api_messages`` copy only (``agent.messages`` is never mutated). Drop-and-merge
(not stub text) keeps history honest and preserves role alternation.

``drop_nudge_marker`` (#67321): user rows equal to the marker â€” the synthetic Codex
continuation nudge â€” are dropped too once the turn has crossed to a non-Codex provider;
doing it in this pass keeps alternation valid when the nudge sat between dropped
reasoning-only interims and a tool result rather than next to the user's message.Nrr   r�   rR   )r[  rK   zbPre-call sanitizer: dropped %d thinking-only assistant turn(s), merged %d adjacent user message(s)r.  )
rL   r=   r½   Ú_is_thinking_only_assistantrx   rY  rZ  r{   rd   Údebug)
rm   r[  r\  r•   r)  rú   rf  ÚmergesrÕ   rR   s
   &$$       r4   Ú"drop_thinking_only_and_merge_usersrc  Ú  sc  € ÷ ØˆáóÙˆaØ!Ò-°!·%±%¸³-À6Ô2IÈaÏeÉeÐT]ÓN^ÐbsÑNsô 	
ä“—‘×9Ñ9¸!Ð9×s÷ 	
ˆ‘8ð 	ð ô
 �(‹mœc $›iÕ'€GØ#%€FØ€FÛˆß#ˆv�bŽz¨ˆÜˆØÒ §¡¨Ó 0°FÔ :¸q¿u¹uÀV»}ÐPVÔ?VÜ)¨$¯(©(°9¸bÓ*AÀ1Ç5Á5ÈÐTVÓCWÓXˆGØ”lÓ"ð �M‰M˜!Öà5˜DÐ5 )¨WÑ5ˆF�2‰JØ�a�KŠFñ ð �!„|˜ !œØˆÜƒE‡L�L×Ñð	-Ø.5ôð €Mùò5s   �2E>Á'E>Á2E>c                ó|  € RRrv \        V RR4      pV! V4      '       g   V! 4       ;rhRp\        VP                  R4      ;'       g    R4      P                  4       p	\        VRR 4      ! T	;'       g    RR	7      p
V
e”   V
\        P                  ! 4       8”  dz   \        V R
R4      '       gc   RV n        \        P                  RT;'       g    R\        P                  ! V
4      P                  RR7      V P                  V P                  4       RWg3# RYg3#   \         d    \        P                  RRR7        L(i ; i)zûReset-aware gate: skip a guaranteed-to-fail restore while the primary pool reports a
future reset; fails open on any error/None. Returns ``(blocked, prefetched_pool, prefetched)``
so the rebind step reuses the loaded pool (one auth.json read at most).NFr�  Trö  rK   Únext_available_atc                 ó   € R # rè   rF   )Ú_kwargss   ,r4   Ú<lambda>Ú,_primary_reset_gate_blocks.<locals>.<lambda>  s   € Átr>   ©rö  Ú_restore_wait_loggedzSPrimary %s rate-limited until %s; staying on fallback %s/%s until the reset elapsesr·   Úseconds)Útimespecz?Reset-aware restore gate failed; falling back to per-turn retry©Úexc_info)rÑ   rE   rL   rM   rÒ   rk  rd   rÇ  r   ÚfromtimestampÚ	isoformatr¿  rö  r¡  ra  )r”   r  Úprimary_providerÚprimary_runtime_base_urlÚmatches_primaryÚload_primary_poolÚprefetched_poolÚ
prefetchedr¢  Úprimary_modelÚnext_ats   &&&&&&     r4   Ú_primary_reset_gate_blocksrz    s/  € ð #'¨�ZðgÜ�uÐ0°$Ó7ˆÙ˜t×$Ò$Ù%6Ó%8Ð8ˆOØˆJÜ˜BŸF™F 7›O×1Ð1¨rÓ2×8Ñ8Ó:ˆÜ˜$Ð 3Ñ5KÔLÐS`×ShÐShÐdhÔiˆØÒ 7¬T¯YªY«[Ô#8Ü˜5Ð"8¸%×@Ò@Ø-1�Ô*Ü—‘ð4Ø5E×5LÐ5LÈÜ×*Ò*¨7Ó3×=Ñ=ÀyÐ=ÓQÐSX×SaÑSaØ—K‘Kô	ð ˜Ð4Ð4ð �/Ð-Ð-øô ô gÜ�‰ÐVÐaeˆÖfðgús&   …AD Á+D Á3AD ÃAD Ä"D;Ä:D;c               ó    € V ^8„  d   QhRRRR/# r  rF   )rG   s   "r4   rH   rH      s   € ÷ Kñ K¨^ð KÀñ Kr>   c                óÔ   € R V9   d
   VR ,          MVP                  R4      p\        V\        4      '       d   \        V4      V n        R# R V9   d   \        P                  R4       R# R# )Úruntime_capabilitiesÚcapabilitiesz0Ignoring malformed runtime capabilities snapshotN)rL   r_   r`   r}  rd   re   )r”   r  Úraws   && r4   Ú_restore_runtime_capabilitiesr€     sS   € à(>À"Ô(Dˆ"Ð#Ö
$È"Ï&É&ÐQ_ÓJ`€CÜ�#”t×ÒÜ%)¨#£YˆÖ"Ø	 2Ô	%Ü�‰ÐIÖJñ 
&r>   c               ó   € V ^8„  d   QhRR/# r›  rF   )rG   s   "r4   rH   rH   )  s   € ÷ %
ñ %
ð  QUñ %
r>   c                ó  € \        V RR4      p\        \        VRR4      ;'       g    R4      P                  4       P                  4       pVe<   V'       d4   V! V4      '       g&   RV n        RV n         V'       d   TMV! 4       V n        RV n        \        V RR4      pVe?   TP                  T;'       g    RR7      '       d   TP                  T;'       g    RR7      MRp
V
e'   \        V
RR4      '       g   \        V
RR4      '       g   R# V! V
4      '       dA   V P                  V
4       \        P                  R	\        V
R
R4      \        V
RR4      4       R# \        P                  R\        V
R
R4      \        V
RR4      \        \        V
RR4      ;'       g    R4      P                  4       P                  4       ;'       g    RT;'       g    R4       R#   \         d"   p	\        P                  RY4        Rp	?	ELxRp	?	ii ; i)ac  Rebind and re-select the primary credential pool after a fallback turn. A cross-provider
fallback attaches its own pool, which would trip the provider-mismatch guard on the next
401/429: reload the primary pool, else clear it. The snapshot api_key may be stale after
rotation; re-select the pool's best entry, keeping the snapshot key when none is usable.r�  Nr¿  rK   z;Restore could not reload primary credential pool for %s: %srj  rª  Úaccess_tokenz&Restore re-selected pool entry %s (%s)r}  r·   rñ  zRRestore skipped pool entry %s (%s): provider %s does not match primary provider %s)rÑ   rE   rM   r�  r�  r   r¡  rd   re   Úhas_availableÚselectrÊ  rÇ  )r”   rr  rx  rt  ru  rv  rw  r¢  r  ÚexcrÙ   s   &&&&&&&    r4   Ú_rebind_primary_credential_poolr‡  )  sÉ  € ô
 �5Ð,¨dÓ3€DÜœ  j°"Ó5×;Ð;¸Ó<×BÑBÓD×JÑJÓL€MØÒŸM±/À$×2GÒ2GØ!%ˆÔØ*.ˆÔ'ð	ç8B¡_ÑHYÓH[ˆEÔ"ð
 '+€EÔ#Ü�5Ð,¨dÓ3€DØ8<Ò8HÈT×M_ÑM_Ðfs×f{Ðf{Ðw{ÐM_×M|ÒM|ˆD�K‰K˜m×3Ð3¨tˆKÔ4ð  CG€EØ‚}œW UÐ,=¸t×DÒDÌÐPUÐWeÐgi×HjÒHjÙÙ�u×Òð 	×Ñ˜uÔ%Ü�‰Ø4Ü�E˜4 Ó%¤w¨u°g¸sÓ'Cö	
ô
 	�‰Ø`Ü�E˜4 Ó%¤w¨u°g¸sÓ'CÜ”˜˜z¨2Ó.×4Ð4°"Ó5×;Ñ;Ó=×CÑCÓE×LÐLÈØ×#Ð# ö		
øô' ô 	Ü�N‰NØMÐO_÷ò ûð	ús   Á3G Á;G ÇHÇ%HÈHc               ó   € V ^8„  d   QhRR/# r›  rF   )rG   s   "r4   rH   rH   Q  s   € ÷ ,ñ ,¨$ñ ,r>   c           	     óÆ  € \        V RR4      pV'       g   R# \        V RR4      pVe   \        V RR4      V8X  d
   RV n        R#  VP                  V\        V RR4      R7      pTf   R# T P                  T4      RJd.   \        P                  R	\        TR
R4      \        TRR4      4       RT n        R#   \         d"   p\        P                  RT4        Rp?R# Rp?ii ; i)aU  Move a live session back onto the credential a quota bench rotated it off, once the bench
lifts. New sessions already do this through ``select()``; without it a long-lived (gateway)
session keeps billing the fallback for its whole life (#114501). Credential-only: the
model/base_url/compressor restore stays gated on ``_fallback_activated``.rú  Nr�  r   rö  rj  z"Credential revert check failed: %sFu=   Credential %s (%s) available again â€” reverted pool rotationr}  r·   rñ  )rÑ   rú  Úreclaimr¡  rd   re   rÊ  rÇ  )r”   Ú	revert_idr¢  rÙ   r†  s   &    r4   Ú_revert_credential_rotationrŒ  Q  sÚ   € ô
 ˜Ð;¸TÓB€IßÙÜ�5Ð,¨dÓ3€DØ‚|”w˜uÐ&AÀ4ÓHÈIÔUØ+/ˆÔ(ÙðØ—‘˜Y¬g°e¸WÀdÓ.K�ÓLˆð ‚}ÙØ×Ñ˜eÓ$¨EÓ1Ü�‰ØKÜ�E˜4 Ó%¤w¨u°g¸sÓ'Cô	
ð (,€EÖ$øô ô Ü�‰Ð;¸SÔAÝûðús   ÁB4 Â4C Â?CÃC c               ó   € V ^8„  d   QhRR/# r²  rF   )rG   s   "r4   rH   rH   l  s   € ÷ !ñ !Ðquñ !r>   c                óê  € VR8w  d   R# ^ RI Hp \        P                  ! 4       pV\	        V R\        R4      4      ,
          V8  d   R# W`n         \	        V RR4      pVe   V! V4      '       g   V! 4       pVf   R# T;'       g    RpVP                  VR7      p	V	e   V	\        P                  ! 4       8:  d   R# VP                  VR7      #   \         d    \        P                  R	R
R7        R# i ; i)a$  True when a Codex quota window that the primary pool still has benched has reopened.

A Codex 429 benches the entry, and arms ``_rate_limited_until``, until a ``resets_at`` that can be
days out (weekly window). The window can reopen sooner (redeemed reset, top-up, plan change); the
pool's throttled usage probe notices, but only on ``select()``, which a session pinned to its
fallback never reaches. Fails closed: any doubt leaves both cooldowns in force.

At most one check per probe interval per agent: the probe caches its verdict and nothing clears
it on the next 429, so a "restored" answer the endpoint got wrong would otherwise restore,
fail, and fall back again on every turn of the cached window. Checks in between could only
replay that cached verdict, so they return before loading the pool.
úopenai-codexF)Ú&CODEX_QUOTA_PROBE_MIN_INTERVAL_SECONDSÚ_codex_reopen_checked_atz-infr�  Nrj  z5Early quota-reopen check failed; keeping the cooldownTrn  )Úhermes_cli.auth_codexr�  rÒ   Ú	monotonicrÑ   Úfloatr‘  re  Úlift_reopened_cooldownsr¡  rd   ra  )
r”   rr  rx  rt  ru  r�  rØ   r¢  rö  Úbenched_untils
   &&&&&     r4   Ú_primary_quota_reopened_earlyr—  l  sä   € ð ˜>Ô)ÙÝLÜ
�.Š.Ó
€CØ
ŒW�UÐ6¼¸f»ÓFÕFÐIoÔoÙØ%(Ô"ðÜ�uÐ0°$Ó7ˆØŠ<™¨t×4Ò4Ù$Ó&ˆDØŠ<ÙØ×%Ð% ˆØ×.Ñ.°UÐ.Ó;ˆØÒ  M´T·Y²Y³[Ô$@ÙØ×+Ñ+°%Ð+Ó8Ð8øÜô Ü�‰ÐLÐW[ˆÔ\Úðús*   ÁC Á/C Á<C Â3C Â:C Ã"C2Ã1C2c               ó   € V ^8„  d   QhRR/# r²  rF   )rG   s   "r4   rH   rH   �  s   € ÷ @ñ @ dñ @r>   c                ó  aaaa€ V P                   '       g   ^ V n        \        V 4       R# V P                  o\	        S;'       g    / P                  R4      ;'       g    R4      P                  4       P                  4       o\	        S;'       g    / P                  R4      ;'       g    R4      P                  4       p^ RIH	p ^ RI
Hp V'       d!   V! V SV4      '       g   V! V4      '       d   R# \	        S;'       g    / P                  R4      ;'       g    R4      oR VV3R	 lloVVVV3R
 lp\        V SVSV4      '       d   ^ V n        \        V R^ 4      \        P                   ! 4       8”  d   R# \#        V SSSSV4      w  rVpV'       d   R# RV n        \        V RR4      p\'        V\(        \*        34      '       d   \-        V4      ^8X  g   \        V RR4      \        V RR4      3pR V 4       w  rš\/        \        V RR4      4      p ^ RIHp V! V SSVSWFV4       \4        P7                  RV P8                  V P:                  4       RV n        RV n        V'       d`   \@        PB                  ! \D        4      ;_uu_ 4        V PG                  RV P8                   RV P:                   RV	 RV
 R2	4       RRR4       R# R#   + '       g   i     R# ; i  \D         d"   p\4        PI                  RT4        Rp?R# Rp?ii ; i)z�Restore the primary runtime at the start of a new turn so fallback stays turn-scoped
(long-lived CLI agents and the gateway's cached agents).Fr¿  rK   rö  )Ú_is_entitlement_rejected)Úis_known_non_chat_modelrí  c               ó   € V ^8„  d   QhRR/# r²  rF   )rG   s   "r4   rH   Ú-restore_primary_runtime.<locals>.__annotate__§  s   € ÷ pñ p tñ pr>   c                ó    <€ \        V SSR 7      # )rî  )r   )r©   rr  rs  s   &€€r4   Ú_matches_primaryÚ1restore_primary_runtime.<locals>._matches_primary§  s   ø€ Ü/°	Ð;KÐVnÔoÐor>   c                 ó˜   <€ ^ RI Hp  T ! SSS;'       g    / P                  R4      S;'       g    / 4      pVe   S! V4      '       d   V# R# )z^The primary's pool (entry-scoped for a custom entry); None when absent or provider-mismatched.)Úload_runtime_poolr  N)Úagent.custom_entry_poolr¢  rL   )r¢  r  rŸ  rr  rs  r  s     €€€€r4   Ú_load_primary_poolÚ3restore_primary_runtime.<locals>._load_primary_poolª  sQ   ø€ å=Ù"Ð#3Ð5MÐPR×PXÐPXÐVXÏ~É~Ð^rÓOsÐuw×u}Ðu}Ð{}Ó~ˆØÒ+Ñ0@À×0HÒ0HˆvÐRÈdÐRr>   Ú_rate_limited_untilÚ_provider_fallback_routeNc              3  óL   "  € T F  p\        T;'       g    R 4      x € K  	  R# 5i)rt   N)rE   )r2   r  s   & r4   r5   Ú*restore_primary_runtime.<locals>.<genexpr>¼  s   é € Ð(UÁnÀ¬¨Q¯^¨^°)×)<Ð)<Ãnùs   ‚$•$Ú_provider_fallback_active)Úreinstall_primary_runtimez.Primary runtime restored for new turn: %s (%s)u   âœ… Primary model restored: z via z; fallback z is no longer active.Tz%Failed to restore primary runtime: %s)%rK  Ú_fallback_indexrŒ  rO  rE   rL   rM   r�  Úagent.fallback_cooldownrš  Úhermes_cli.chat_catalogr›  r—  r¦  rÑ   rÒ   r“  rz  rk  r_   r¦   Útuplerx   r‡   Úagent.route_bindingr«  rd   rÇ  rö  r¿  rª  r§  r¿   rÀ   r¡  Ú_emit_diagnostic_statusre   )r”   rx  rš  r›  r¤  Úblockedrv  rw  Úfallback_routeÚprevious_modelÚprevious_providerÚprovider_fallback_activer«  rÖ  rŸ  rr  rs  r  s   &             @@@@r4   Úrestore_primary_runtimer·  �  sª  û€ ð ×$×$Ð$ð !"ˆÔÜ# EÔ*ÙØ	×	Ñ	€BÜ˜BŸH˜H "Ÿ>™>¨*Ó5×;Ð;¸Ó<×BÑBÓD×JÑJÓLÐÜ˜Ÿ˜˜rŸ™ wÓ/×5Ð5°2Ó6×<Ñ<Ó>€MÝ@Ý?ßÙ  Ð(8¸-×HÒHÙ" =×1Ò1ñ Ü" B§H H¨"§>¡>°*Ó#=×#CÐ#CÀÓDÐ÷pñ p÷Sð Sô
 % UÐ,<¸mÐM]Ð_q×rÒrØ$%ˆÔ!ÜˆuÐ+¨QÓ/´$·.².Ó2BÔBÙÜ+EØˆrÐ#Ð%=Ð?OÐQcó,Ñ(€G˜j÷ ÙØ!&€EÔÜ˜UÐ$>ÀÓE€NÜ�~¬¬e }×5Ò5¼#¸nÓ:MÐQRÔ:RÜ! %¨°"Ó5´w¸uÀjÐRTÓ7UÐVˆÙ(UÁnÓ(UÑ%€NÜ#¤G¨EÐ3NÐPUÓ$VÓWÐðÝAÙ!Ø�2Ð'¨Ð8HÐJ\Ðoyô	
ô 	�‰ÐDÀeÇkÁkÐSX×SaÑSaÔbØ*/ˆÔ'Ø)-ˆÔ&ß#ä×$Ò$¤Y×/Õ/Ø×-Ñ-Ø2°5·;±;°-¸uÀUÇ^Á^ÐDTð U Ø .Ð/¨uÐ5FÐ4GÐG\ð^ô÷ 0ó
 ÷ 0Ö/ñ
 ûÜô Ü�‰Ð>ÀÔBÝûðús7   ÈA7K Ê3KÊ8K ËK	ËK ËK ËLË#K?Ë?Lc              #  ó¤   "  € T FF  p\         P                  ! R V RV R2\         P                  \         P                  ,          4      x € KH  	  R# 5i)r*   z>(.*?)</r+   Nr,   )r2   Útags   & r4   r5   r5   Ø  sA   é € ð #áˆô ‡J‚J�!�C�5˜   QÐ'¬¯©´R·]±]Õ)B×CÐCÛùr6   c               ó   € V ^8„  d   QhRR/# ©rA   rD   r^  rF   )rG   s   "r4   rH   rH   Þ  s   € ÷ !1ñ !1°=ñ !1r>   c                ó  aa€ ^ RI Ho . oR VV3R llpV! \        VRR4      4       V! \        VRR4      4       \        VRR4      ;'       g    .  F}  p\        V\        4      '       g   K  T! VP                  R4      ;'       gD    VP                  R	4      ;'       g+    VP                  R
4      ;'       g    VP                  R4      4       K  	  \        VR
R4      pS'       g    \        V\        4      '       dŠ   V Fƒ  p\        V\        4      '       g   K  VP                  R4      R	8X  g   K3  T! S! VP                  R	4      ;'       g    VP                  R4      ;'       g    RRR7      P                  4       4       K…  	  S'       gZ   \        V\        4      '       dD   V'       d<   \         F1  pVP                  V4       F  pV! VP                  4       4       K  	  K3  	  S'       d   RP                  S4      # R# )z¥Reasoning text from ``reasoning`` / ``reasoning_content`` / ``reasoning_details``
(OpenRouter unified), else inline thinking blocks in the content; None when absent.)Úflatten_message_textc               ó   € V ^8„  d   QhRR/# r›  rF   )rG   s   "r4   rH   Ú'extract_reasoning.<locals>.__annotate__å  s   € ÷ ñ �dñ r>   c                ód   <€ S! V R R7      p V '       d   V S9  d   SP                  V 4       R# R# R# )rK   ©ÚsepN)r{   )r�  r½  Úpartss   &€€r4   Ú_addÚextract_reasoning.<locals>._addå  s,   ø€ Ù# D¨bÔ1ˆß�D Ô%Ø�L‰L˜Öñ &‰4r>   rJ   Nrë   Úreasoning_detailsÚsummaryrŽ  rR   r�  rŸ   rK   rÁ  rc  )Úagent.message_contentr½  rÑ   r_   r`   rL   r¦   rM   rE   Ú_INLINE_REASONING_PATTERNSÚfindallr“   )	r”   Úassistant_messagerÄ  ÚdetailrR   Úblockr˜  r½  rÃ  s	   &&     @@r4   Úextract_reasoningrÎ  Þ  s’  ù€ õ ;à€E÷ñ ñ 	ŒÐ" K°Ó	6Ô7ÙŒÐ"Ð$7¸Ó	>Ô?äÐ+Ð-@À$ÓG×MÐMÈ2ÒMˆÜ�fœd×#Ô#Ù�—‘˜IÓ&×oÐo¨&¯*©*°ZÓ*@×oÐoÀFÇJÁJÈyÓDY×oÐoÐ]c×]gÑ]gÐhnÓ]oÖpñ Nô Ð'¨°DÓ9€Gß”Z ¬×.Ò.ó ˆEÜ˜%¤×&Ô&¨5¯9©9°VÓ+<À
Ö+Jñ Ñ)¨%¯)©)°JÓ*?×*ZÐ*ZÀ5Ç9Á9ÈVÓCT×*ZÐ*ZÐXZÐ`bÔc×iÑiÓkÖlñ ÷ ”Z ¬×-Ò-·'ß1ˆGØ Ÿ™¨Ö1�Ù�U—[‘[“]Ö#ó 2ñ 2÷ "'ˆ6�;‰;�uÓÐ0¨DÐ0r>   c               ó    € V ^8„  d   QhRRRR/# ©rA   r½  r¡  rD   rC   rF   )rG   s   "r4   rH   rH     s   € ÷ ñ  ð ¨~ñ r>   c           
     óš  € R \        V 4      P                  R\        V 4      /pTP                  R Uu/ uF  p\	        WR4      ;pf   K  W#bK  	  up4       \	        V RR4      pVe#    \	        VRR4      VR&   VP
                  VR&   V# V# u upi   \         d0   p\        4       P                  P                  RT4        Rp?T# Rp?ii ; i)	rŸ   r  rÀ  NÚresponseÚresponse_statusÚresponse_textz,Could not extract error response details: %s)rÀ  Ú
request_idr¼  ÚparamrŸ   Úbody)
rŸ   r¼   rE   rM  rÑ   r�  r¡  r=   rd   ra  )r½  rÇ  r  r  Úresponse_objrÖ  s   &     r4   Ú_api_error_debug_inforÙ    sÛ   € Ø"¤D¨£K×$8Ñ$8¸)ÄSÈÃZÐP€DØ‡K�KÙTóÙT�Ü˜ 4Ó(Ð(ˆAô 	ˆŠÑTñô ô ˜5 *¨dÓ3€LØÒð	RÜ&-¨l¸MÈ4Ó&PˆDÐ"Ñ#Ø$0×$5Ñ$5ˆD�Ñ!ð €Kˆ4€Kùòøô ô 	RÜ‹E�L‰L×ÑÐMÈq×QÐQØ€Kûð	Rús#   ²BÁ	BÁ(B ÂC
Â$CÃC
r½  c               ó(   € V ^8„  d   QhRRRRRRRR/# )	rA   Ú
api_kwargsrC   r»  rE   r½  zOptional[Exception]rD   zOptional[Path]rF   )rG   s   "r4   rH   rH     s,   € ÷ 1ñ 1Ø%ð1Ø25ð1Ø>Qð1àñ1r>   c               óŠ  €  \         P                  ! V4      P                  4        UUu/ uF  w  rEVf   K  VR8w  g   K  WEbK  	  pppRpV P                  R8H  p V'       d   \	        V RR4      MV P
                  p	\	        V	RR4      ;'       g    \	        V	RR4      pRR	RR
/P                  V P                  R4      pR\        P                  ! 4       P                  4       RV P                  RVRRRRV P                  P!                  R4       V 2RRRV P#                  V4       2RR/RV//pVe   \%        V4      VR&   ^ RIHp V! V P                  4      pV P*                  RV R\        P                  ! 4       P-                  R4       R2,          p^ R IHp \2        P4                  ! VR!^\6        R"7      p\2        P8                  ! V! VR#R$7      4      p\;        VV\6        R%7       V P=                  V P>                   R&V 24       \A        R'4      '       d(   \C        \2        P4                  ! VR!^\6        R"7      4       V# u uppi   \         d0   p
\        4       P                  P                  RT
4        Rp
?
ELßRp
?
ii ; i  \         d4   pT PD                  '       d   \        PG                  R(T4        Rp?R# Rp?ii ; i))zaDump the request body from api_kwargs (minus transport keys) for debugging provider 4xx failures.Nr'  rº  r,  rž  Ú
auth_tokenz,Could not extract API key for debug dump: %sÚcodex_responsesz
/responsesz	/messagesz/chat/completionsÚ	timestampr²   r»  ÚrequestÚmethodÚPOSTÚurlÚ/ÚheadersÚAuthorizationzBearer zContent-Typezapplication/jsonr×  r½  )Ú _safe_session_filename_componentÚrequest_dump_Ú_z%Y%m%d_%H%M%S_%fz.json)Úredact_sensitive_textF)r^   ÚindentÚdefaultT)rF  )rì  u$   ðŸ§¾ Request debug dump written to: ÚHERMES_DUMP_REQUEST_STDOUTz,Failed to dump API request debug payload: %s)$ÚcopyÚdeepcopyr  r¹  rÑ   r.  r¡  r=   rd   ra  rL   r   rØ   rq  r²   rí  rg   Ú_mask_api_key_for_logsrÙ  Úagent.session_persistencerç  Úlogs_dirÚstrftimeÚagent.redactrê  ra   rf   rE   rb   r(   rP  rQ  r'   ÚprintÚverbose_loggingre   )r”   rÛ  r»  r½  r  r  r×  rž  r¸  ÚliverÖ  ÚendpointÚdump_payloadrç  Úsafe_sidÚ	dump_filerê  Ú_serializedÚ_redacted_payloadÚ
dump_errors   &&$$                r4   Údump_api_request_debugrÿ    s‹  € ð-Ü!%§¢¨zÓ!:×!@Ñ!@Ô!BÔgÑ!B™˜Àa”ÐXYÐ]fÑXf”�’Ñ!BˆÑgØˆð —N‘NÐ&:Ñ:ˆ	ð	Rß@I”7˜5Ð"5°tÔ<ÈuÏ|É|ˆDÜ˜d I¨tÓ4×YÐY¼ÀÀlÐTXÓ8YˆGð & |Ð5IÈ;ÐW×[Ñ[Ø�N‰NÐ/ó
ˆð œŸš›×1Ñ1Ó3°\À5×CSÑCSÐU]Ð_eØØ˜& %¨E¯N©N×,AÑ,AÀ#Ó,FÐ+GÈÀzÐ)RØØ# w¨u×/KÑ/KÈGÓ/TÐ.UÐ%VØ"Ð$6ðð ˜ðð
(
ˆð ÒÜ$9¸%Ó$@ˆL˜Ñ!õ 	OÙ3°E×4DÑ4DÓEˆØ—N‘N }°X°J¸aÄÇÂÃ×@WÑ@WÐXjÓ@kÐ?lÐlqÐ%rÕrˆ	õ 	7Ü—j’j ¸EÈ!ÔUXÔYˆÜ ŸJšJÑ'<¸[ÐPTÔ'UÓVÐÜ˜)Ð%6ÄÕDØ�‰˜×)Ñ)Ð*Ð*NÈyÈkÐZÔ[ÜÐ7×8Ò8Ü”$—*’*Ð.¸UÈ1ÔVYÔZÔ[ØÐùóQ høô ô 	RÜ‹E�L‰L×ÑÐMÈq×QÒQûð	RûôB ô Ø× × Ð Ü�N‰NÐIÈ:ÔVÝûðúsc   ‚'J ©I¶I¿IÁJ Á4I ÂI ÂF#J ÉJ ÉJÉ$I<É6J É<JÊJ ÊKÊ(J=Ê=Kr¿  rí  r¹  rö  c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )rA   r¿  r^  rí  r¹  rö  rD   r‡   rF   )rG   s   "r4   rH   rH   F  s=   € ÷ kñ kØ%ðkØ8Eðkàðkà+8ðkð 
ñkr>   c               ó¨   € Ve   TMV P                   ;'       g    RpVe   TMV P                  ;'       g    RpVR8H  ;'       d    \        V4      R8H  # )zEReturn whether this resolved destination accepts native tool markers.rK   rº  úapi.anthropic.com)rí  r¹  r&   )r”   r¿  rí  r¹  rö  Úeff_base_urlÚeff_api_modes   &$$$$  r4   Ú._direct_native_anthropic_tool_cache_capabilityr  F  sT   € ð
  (Ò3‘8¸%¿.¹.×:NÐ:NÈB€LØ'Ò3‘8¸%¿.¹.×:NÐ:NÈB€LØÐ/Ñ/×jÐjÔ4EÀlÓ4SÐWjÑ4jÐjr>   c               ó    € V ^8„  d   QhRRRR/# )rA   Úttlr   rD   r‡   rF   )rG   s   "r4   rH   rH   T  s   € ÷ iñ i #ð i¨$ñ ir>   c                ó„   € V \         9   d   R# V RJ ;'       g)    V RJ ;'       g    \        V 4      P                  4       R9   # )zºTrue when a ``prompt_caching.cache_ttl`` value means caching off (single predicate shared
by ``agent_init`` and the stub policy paths). Unknown values (``"2h"``, ints) are NOT a disable.FN)ÚoffÚfalseÚdisabledÚnoÚnone)ÚVALID_CACHE_TTLSrE   r�  ©r  s   &r4   Úcache_ttl_means_disabledr  T  s?   € ð ÔÔÙØ�%ˆ<×hÐh˜3 $˜;×hÐh¬#¨c«(¯.©.Ó*:Ð>hÑ*hÐhr>   c               ó    € V ^8„  d   QhRRRR/# )rA   rì  r   rD   rF   )rG   s   "r4   rH   rH   \  s   € ÷ ñ ¨ð °ñ r>   c                ó˜   €  ^ RI Hp V! 4       P                  R/ 4      ;'       g    / P                  RR4      #   \         d    T u # i ; i)zYRaw ``prompt_caching.cache_ttl`` config value, or ``default`` when config cannot be read.©Úload_config_readonlyÚprompt_cachingÚ	cache_ttlÚ5m)Úhermes_cli.configr  rL   r¡  )rì  r  s   & r4   Ú_raw_cache_ttl_from_configr  \  sK   € ðÝ:Ù$Ó&×*Ñ*Ð+;¸RÓ@×FÐFÀB×KÑKÈKÐY]Ó^Ð^øÜô ØŠðús   ‚#9 ¦9 ¹A	ÁA	c               ó   € V ^8„  d   QhRR/# r²  rF   )rG   s   "r4   rH   rH   e  s   € ÷ Fñ F¨Tñ Fr>   c                 ó*   € \        \        R4      4      # )aN  True when ``prompt_caching.cache_ttl`` is configured as off (same detection as ``agent_init``).

Same disable detection as ``agent_init`` (via ``cache_ttl_means_disabled``) so stub-based policy paths
(MoA slot decoration, auxiliary fallback replan) honor the same config contract without holding a live
``AIAgent`` (#76085 / #33555).
r  )r  r  rF   r>   r4   Ú#prompt_caching_disabled_from_configr  e  s   € ô $Ô$>¸tÓ$DÓEÐEr>   c               ó   € V ^8„  d   QhRR/# r»  rF   )rG   s   "r4   rH   rH   o  s   € ÷ 4ñ 4˜mñ 4r>   c                 ó6   € \        R4      p V \        9   d   V # R# )a  Configured ``prompt_caching.cache_ttl`` tier (``5m``/``1h``), else None; mirrors
``agent_init`` so stub paths don't regress a configured ``1h`` to 5m. ``auto`` is None here
on purpose: stub/auxiliary calls are machine-paced, so they take the 5m tier ``None`` resolves to.N)r  r  r  s    r4   Úconfigured_cache_ttlr  o  s!   € ô % TÓ
*€CØÔ)Ô)ˆ3Ð3¨tÐ3r>   c               ó   € V ^8„  d   QhRR/# )rA   Úcache_disabledúOptional[bool]rF   )rG   s   "r4   rH   rH   w  s   € ÷ rñ r¨Nñ rr>   c           	     óV   € ^ RI Hp V f   \        4       p V! RRRR\        V 4      R7      # )z±Destination-identity-blank stub for ``anthropic_prompt_cache_policy``; the sole sanctioned
constructor so ``_cache_disabled`` is never omitted (None consults the global config).)ÚSimpleNamespacerK   )r¿  rí  r¹  rö  Ú_cache_disabled)Útypesr$  r  r‡   )r!  r$  s   & r4   Úblank_cache_policy_stubr'  w  s/   € õ &ØÒÜ<Ó>ˆÙ B°¸bÈÔ\`ÐaoÓ\pÔqÐqr>   r!  r  Ústatic_system_prefixc               ó@   € V ^8„  d   QhRRRRRRRRRRR	RR
RRRRRRR/
# )rA   rm   r¦   rŒ   zOptional[list]r¿  rE   rí  r¹  rö  r!  r"  r  r^  r(  rD   ztuple[list, list]rF   )rG   s   "r4   rH   rH   €  s`   € ÷ &%ñ &%Øð&%Ø)ð&%Ø8;ð&%ØGJð&%ØVYð&%àð&%à .ð&%àBOð&%ð (ð&%ð ñ	&%r>   c               óŒ  € ^ RI Hp	Hp
HpHpHp \        V4      p\        W#WER7      p\        V3/ VB w  ppV'       g3   \        P                  ! T ;'       g    . 4      pV! V4       VV! V4      3# T	! YV
! WrVR7      T\        V\        4      '       d   TMR\        V3/ VB V! W#4      R7      pVP                  VP                  3# )ak  Plan request-local cache sections for one resolved destination (MoA / auxiliary senders):
stripped copies (non-caching route) or a ``build_prompt_cache_plan`` layout; never mutates
inputs. ``cache_disabled``/``cache_ttl`` default to live config so the operator's disable and
tier are honored; ``static_system_prefix`` gives the system prompt the main loop's early breakpoint.

``cache_disabled`` threads the operator's ``prompt_caching.cache_ttl`` disable into the blank policy
stub. When omitted, the live config is consulted so MoA/auxiliary paths cannot re-enable markers after
the user turned caching off (#76085).
)Úbuild_prompt_cache_planÚeffective_cache_ttlÚ*envelope_tool_part_cache_markers_supportedÚstrip_anthropic_cache_controlÚ"strip_anthropic_tool_cache_control©r¿  rí  r¹  rö  )r¿  rö  N)r  Únative_anthropicr(  Údirect_native_tool_cacheÚtool_part_markers)Úagent.prompt_cachingr+  r,  r-  r.  r/  r'  r`   Úanthropic_prompt_cache_policyrî  rï  r_   rE   r  rm   rŒ   )rm   rŒ   r¿  rí  r¹  rö  r!  r  r(  r+  r,  r-  r.  r/  ÚstubÚdestÚshould_cacheÚnative_layoutÚcanonical_messagesÚplans   &&$$$$$$$           r4   Ú#plan_cache_sections_for_destinationr<  €  sÈ   € ÷õ ô # >Ó2€DÜ˜¸xÔU€DÜ"?ÀÑ"MÈÑ"MÑ€L�-ßÜ!Ÿ]š]¨8¯>¨>°rÓ:ÐÙ%Ð&8Ô9Ø!Ñ#EÀeÓ#LÐLÐLÙ"Øá% iÈ%ÔPØ&Ü5?Ð@TÔVY×5ZÒ5ZÑ1Ð`dÜ!OÐPTÑ!]ÐX\Ñ!]ñ EÀXÓXô
€Dð �=‰=˜$Ÿ*™*Ð$Ð$r>   c               ó$   € V ^8„  d   QhRRRRRR/# )rA   Úprovider_lowerrE   rí  rD   r‡   rF   )rG   s   "r4   rH   rH   ©  s&   € ÷ oñ o cð o°Sð o¸Tñ or>   c                óT   € \        V R4      ;'       g    \        \        V4      R4      # )z˜True when a route is a LiteLLM proxy: ``litellm`` as a whole delimited token (not
substring) in the provider id or host; a path segment never qualifies.z:-_/z.-)Ú_has_litellm_tokenr&   )r>  rí  s   &&r4   Ú_is_litellm_routerA  ©  s)   € ô ˜n¨fÓ5×nÐnÔ9KÔL]Ð^fÓLgÐimÓ9nÐnr>   c               ó$   € V ^8„  d   QhRRRRRR/# )rA   r‹   rE   Ú
delimitersrD   r‡   rF   )rG   s   "r4   rH   rH   ¯  s&   € ÷ bñ b˜cð b¨sð b°tñ br>   c           
     ó¢   € V '       g   R# RV P                  \        P                  VR\        V4      ,          4      4      P	                  4       9   # )zDTrue when ``value`` contains ``litellm`` as a whole delimited token.FÚlitellmr´  )Ú	translaterE   Ú	maketransrx   Úsplit)r‹   rC  s   &&r4   r@  r@  ¯  s9   € çÙØ˜Ÿ™¬¯©°jÀ#ÌÈJËÕBWÓ(XÓY×_Ñ_ÓaÑaÐar>   c               ó    € V ^8„  d   QhRRRR/# )rA   Ú	eff_modelrE   rD   rë  rF   )rG   s   "r4   rH   rH   ¶  s   € ÷ ñ °3ð Ð;Lñ r>   c                ó"  €  ^ RI Hp ^ RIHp ^ RIHp T! V! 4       P                  R4      ;'       g    / T;'       g    R4      P                  R4      ;'       g    / p\        VP                  R4      ;'       g    R4      P                  4       p\        VP                  R	4      ;'       g    R4      P                  4       pV'       d„   V'       d|   R;r‰\        P                  ! \        4      ;_uu_ 4        V! WgR
7      p
V
P                  R4      ;'       g    RpV
P                  R4      ;'       g    Rp	RRR4       \        WW‰VR7      # R#   + '       g   i     L ; i  \         d"   p\        P                  RT4        Rp?R# Rp?ii ; i)z¡MoA virtual provider: resolve the policy from the preset's real aggregator slot (the
virtual provider matches no caching branch and would silently lose caching).©Úload_config)Úresolve_moa_preset)Úresolve_runtime_providerr2  NÚ
aggregatorr¿  rK   rö  )Ú	requestedÚtarget_modelrí  r¹  r0  z1MoA aggregator cache-policy resolution failed: %s©FF)r  rM  Úhermes_cli.moa_configrN  Úhermes_cli.runtime_providerrO  rL   rE   rM   r¿   rÀ   r¡  r5  rd   ra  )r”   rJ  Ú_load_moa_cfgrN  rO  ÚaggÚagg_providerÚ	agg_modelÚagg_base_urlÚagg_api_moder  Ú_moa_excs   &&          r4   Ú_moa_aggregator_cache_policyr]  ¶  sD  € ðTÝBÝ<ÝHÙ ¡£×!4Ñ!4°UÓ!;×!AÐ!A¸rÀ9×CTÐCTÐPTÓU×YÑYÐZfÓg×mÐmÐkmˆÜ˜3Ÿ7™7 :Ó.×4Ð4°"Ó5×;Ñ;Ó=ˆÜ˜Ÿ™ Ó(×.Ð.¨BÓ/×5Ñ5Ó7ˆ	ßŸIØ*,Ð,ˆLÜ×$Ò$¤Y×/Õ/Ù-¸Ô]�Ø!Ÿv™v jÓ1×7Ð7°R�Ø!Ÿv™v jÓ1×7Ð7°R�÷ 0ô 1Ø°|Ðbkôð ð
 Ð÷ 0×/ûô ô TÜ�‰ÐHÈ(×SÐSØÐûðTús]   ‚0E" ³
E" ¾E" ÁE" Á;1E" Â-E" Ã
E" Ã%E" Ã7<EÄ4EÄ7E" ÅE	ÅE" Å"FÅ-F	Æ	Fc               ó(   € V ^8„  d   QhRRRRRRRR/# )rA   Úeff_providerrE   r>  r  rD   r‡   rF   )rG   s   "r4   rH   rH   Î  s*   € ÷ 4ñ 4¨cð 4À3ð 4ÐVYð 4Ð^bñ 4r>   c                ó@  aa	a
a€ \        V RR4      pV'       dg   ^ RIHo ^ RIHo
 W"P                  R4      0oS
! V4      o	\        ;QJ d"    VV	V
V3R lV 4       F  '       g   K   R# 	  R# ! VV	V
V3R lV 4       4      # Ve   R#  ^ R	IHp V! VRR
7      pVRJ ;'       g?    \        VP                  4      ;'       d"    \        VP                  4      \        V4      8g  #   \         d2   p\        P                  RT4       TP                  R4      u Rp?# Rp?ii ; i)zZCheap identity gate deciding whether a custom-provider capability lookup is worth running.Ú_custom_providersN)Úcustom_provider_aliases)Únormalize_route_base_urlzcustom:c           
   3  óT  <"  € T F�  p\        V\        4      '       g   K  SS! \        VP                  R 4      ;'       g    R4      \        VP                  R4      ;'       g    R4      4      ,          ;'       g%    S;'       d    S! VP                  R4      4      S8H  x € KŸ  	  R# 5i)r3   rK   Úprovider_keyrí  N)r_   r`   rE   rL   )r2   rÙ   rb  Úeff_url_normalizedrc  Úprovider_idss   & €€€€r4   r5   Ú'_route_may_be_custom.<locals>.<genexpr>Ø  s—   øé € ð 
ñ *�¬Z¸¼t×-DônˆLÑ2´3°u·y±yÀÓ7H×7NÐ7NÈBÓ3OÔQTÐUZ×U^ÑU^Ð_mÓUn×UtÐUtÐrtÓQuÓvÕv÷ nð nØ"×lÐlÑ'?ÀÇ	Á	È*Ó@UÓ'VÐZlÑ'lônã)ùs"   ƒB( B(Á "B(Á#B(Á;	B(Â#B(TF)Úget_provider)Úallow_networkz7provider lookup failed during cache-policy pre-gate: %s)rÑ   r  rb  Úhermes_cli.route_identityrc  Úremoveprefixr  ri  r‡   rí  r&   r¡  rd   ra  ry   )r”   r_  r>  r  Úcustom_providersri  Úprovider_defÚ_pd_excrb  rf  rc  rg  s   &&&&    @@@@r4   Ú_route_may_be_customrp  Î  s  û€ ä˜uÐ&9¸4Ó@Ðßõ 	AÝFØ&×(CÑ(CÀIÓ(NÐOˆÙ5°lÓCÐß‹s÷ 
ñ *ó
�sŒsð 	
Šsð 	
ˆs÷ 
ñ *ó
ó 
ð 	
ð
 Ò#Ùð4Ý5ñ $ LÀÔFˆØ˜tÐ#÷ 
ð 
Ü�×&Ñ&Ó'÷ \ð \Ü! ,×"7Ñ"7Ó8Ô<MÈlÓ<[Ñ[ð	
øô ô 4Ü�‰ÐNÐPWÔXØ×(Ñ(¨Ó3Õ3ûð4ús*   ÂC! Â"C! Â?!C! Ã!DÃ,&DÄDÄDc          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )rA   r¿  r^  rí  r¹  rö  rD   rë  rF   )rG   s   "r4   rH   rH   ï  s=   € ÷ oñ oØ%ðoØ8Eðoàðoà+8ðoð ñor>   c          
     óˆ  € \        V RR4      '       d   R# Ve   TMV P                  ;'       g    RpVe   TMV P                  ;'       g    RpVe   TMV P                  ;'       g    RpVe   TMV P                  ;'       g    RpVP                  4       P                  4       R8X  d   \        W4      # \        V\        4      '       d5   VP                  R4      ;'       g    VP                  R4      ;'       g    Rp\        V\        4      '       d   TM\        T;'       g    R4      pVP                  4       p	VP                  4       p
RV	9   p^ R	IHp V! V4      ;'       g    R
V	9   p\        VR4      p\        VR4      pVR8H  pT;'       d    VR8H  ;'       g    \        V4      R8H  pVR9   pVR8H  ;'       d    T;'       d    \!        W¦4      pV'       dS   V'       g   V'       g   \#        WW¦4      '       d1    ^ RIHp V! W†R\        V RR4      R7      pVe   TT;'       d    T3#  V
R9   ;'       g!    \        VR4      ;'       g    \        VR4      pV'       d   V'       d   ^ RIHp V! V4      '       d   R# V'       d   R# V'       g	   V'       d   V'       g	   V'       d   V'       g   R# V'       d
   RV	9   d   R# V'       d   V'       d   R# V'       d   R# V'       d   V'       d   R# ^ RIHpHp V
V9   d   V! V	4      '       d   R# R#   \(         d"   p\*        P-                  RT4        Rp?ELRp?ii ; i) a  Decide whether to apply Anthropic prompt caching; returns ``(should_cache, use_native_layout)``.
Native layout puts markers on inner content blocks (Anthropic wire), else on the message
envelope (OpenRouter / OpenAI-wire proxies; Qwen/Alibaba too). The operator disable is read
from ``_cache_disabled`` (not ``_cache_ttl``, unset during init) so it survives switches
and restores. Branch ORDER is load-bearing (see inline notes).

Qwen / Alibaba-family models on OpenCode, OpenCode Go, and direct Alibaba (DashScope) also honour
Anthropic-style ``cache_control`` markers on OpenAI-wire chat completions. Upstream pi-mono #3392 / pi
#3393 documented this for opencode-go Qwen. Without markers these providers serve zero cache hits,
re-billing the full prompt on every turn.
r%  FNrK   r2  rö  rì  Úclaude)Ú_model_name_is_kimi_familyÚmoonshotzopenrouter.aiznousresearch.comrº  r¸  r  r  )Ú$get_custom_provider_model_capabilityr  ra  )rö  rí  Ú
capabilityrm  z;custom-provider prompt_caching capability lookup failed: %szapi.minimax.iozapi.minimaxi.com)Ú_model_name_suggests_minimax_m3Úqwen)ÚALIBABA_FAMILY_PROVIDERSÚis_qwen_modelrS  >   r  rº  >   Úminimaxú
minimax-cn)TTrÆ  )rÑ   r¿  rí  r¹  rö  rM   r�  r]  r_   r`   rL   rE   Úagent.anthropic_endpointsrt  r%   r&   rA  rp  r  rv  r¡  rd   ra  Úagent.model_metadatarx  r4  rz  r{  )r”   r¿  rí  r¹  rö  r_  r  r  rJ  Úmodel_lowerr>  Ú	is_claudert  Úis_kimiÚis_openrouterÚis_nous_portalÚis_anthropic_wireÚis_native_anthropicÚsupports_cache_markersÚlitellm_openai_wirerv  Úcustom_prompt_cachingÚ_cap_excÚis_minimax_routerx  rz  r{  s   &$$$$                      r4   r5  r5  ï  s  € ô ˆuÐ'¨×/Ò/ØÐØ (Ò 4‘H¸%¿.¹.×OÐOÈR€LØ'Ò3‘8¸%¿.¹.×:NÐ:NÈB€LØ'Ò3‘8¸%¿.¹.×:NÐ:NÈB€LØÒ+‘°·±×CÐCÀ€IØ×ÑÓ×!Ñ!Ó# uÔ,Ü+¨EÓ=Ð=Ü�)œT×"Ò"Ø—M‘M 'Ó*×LÐL¨i¯m©m¸IÓ.F×LÐLÈ"ˆ	Ü'¨	´3×7Ò7‘	¼SÀÇÀÈbÓ=Q€IØ—/‘/Ó#€KØ!×'Ñ'Ó)€NØ˜KÑ'€Iõ EÙ(¨Ó3×PÐP°zÀ[Ñ7P€GÜ)¨,¸ÓH€Mä*¨<Ð9KÓL€NØ$Ð(<Ñ<ÐØ+÷ ð Ø˜Ñ#×]Ð]Ô'8¸Ó'FÐJ]Ñ']ð ð
 *Ð-WÑWÐàÐ*Ñ*×lÐl¨y×lÐlÔ=NÈ~Ó=lð ÷ ßßÜ °^×RÒRð
	bÝNÙ$HØÐCSÜ!(¨Ð0CÀTÓ!Jô%Ð!ð %Ò0à,Ð.C×.YÐ.YÐHYÐYÐYð 1ð 	Ð3Ñ3÷ 	Cð 	CÜ  Ð/?Ó@÷	Cð 	Cä  Ð/AÓBð ÷
 ×-ÝHÙ*¨9×5Ò5ØÐßØÐ÷ 	Ÿ¯i¿7×L]ØÐ÷ ˜& KÔ/ØÐßŸYØÐ÷
 ØÐ÷ ×-ØÐ÷ MØÐ1Ô1±mÀK×6PÒ6PØÐØÐøô_ ô 	bÜ�L‰LÐVÐX`×aÒaûð	bús   Ç?)L È)L ÌMÌ L<Ì<Mc               ó    € V ^8„  d   QhRRRR/# )rA   r  r`   rD   ú
Any | NonerF   )rG   s   "r4   rH   rH   a  s   € ÷ ñ °Dð ¸Zñ r>   c           	     ó*  €  ^ RI Hp Rp\        T RR4      ;'       g    RP	                  4       pT'       d
    T! T4      pTfG   \        TP                  RR4      ;'       g    R4      P	                  4       pT'       d   \        T4      pTf   R#  TP                  ! R/ TB #   \         d     R# i ; i  \         d    Rp L„i ; i  \         d@    \        4       P                  P                  R\        TRT4      ;'       g    RR	R
7        R# i ; i)uG  Ask the registered ProviderProfile for a custom client, if any. Resolves by provider name,
then by ``base_url`` prefix so a URL-only runtime (``acp://â€¦``) still reaches its profile.
A profile that raises is logged and skipped: a third-party plugin must not be able to take
the turn down, it can only fail to provide a client.©Úget_provider_profileNr¿  rK   rí  zWProvider profile %r failed to create a client; falling back to the standard client pathr3   r·   Trn  rF   )Ú	providersr�  r¡  rÑ   rM   rE   rL   Ú_profile_for_base_urlÚcreate_clientr=   rd   re   )r”   r  r�  ÚprofileÚprovider_namerí  s   &&    r4   Ú_provider_supplied_clientr–  a  s  € ð
Ý2ð €GÜ˜U J°Ó3×9Ð9°r×@Ñ@ÓB€Mßð	Ù*¨=Ó9ˆGð ‚Ü�}×(Ñ(¨°RÓ8×>Ð>¸BÓ?×EÑEÓGˆßÜ+¨HÓ5ˆGØ‚ÙðØ×$Ò$Ñ5 }Ñ5Ð5øô! ô Úðûô ô 	ØŠGð	ûô ô Ü‹�‰×ÑØeÜ�G˜V ]Ó3×:Ð:°sÀTð 	ô 	
ò ðús:   ‚B# ¸B5 ÂC Â#B2Â1B2Â5CÃCÃ<DÄ	DÄDc               ó    € V ^8„  d   QhRRRR/# )rA   rí  rE   rD   r�  rF   )rG   s   "r4   rH   rH   �  s   € ÷ ñ  Cð ¨Jñ r>   c                óˆ  €  ^ RI Hp V! 4       pT P                  R4      P	                  4       pT;'       g    .  Fr  p\        \        TRR4      ;'       g    R4      P                  R4      P	                  4       pT'       g   KJ  Y58X  g!   TP                  TR,           4      '       g   Kp  Tu # 	  R#   \         d     R# i ; i)zÿRegistered profile whose own base_url is a prefix of ``base_url`` (provider name did not
resolve). Prefix, not equality: the replaced copilot-acp branch keyed on
``startswith("acp://copilot")``, so a path or user override under the same root must resolve.)Úlist_providersNrä  rí  rK   )r‘  r™  r¡  rg   r�  rE   rÑ   ry   )rí  r™  Ú
candidatesÚtargetr©   rð   s   &     r4   r’  r’  �  s«   € ðÝ,Ù#Ó%ˆ
ð �_‰_˜SÓ!×'Ñ'Ó)€FØ×%Ð% 2Ò%ˆ	Ü”'˜) Z°Ó4×:Ð:¸Ó;×BÑBÀ3ÓG×MÑMÓOˆß‰3�F”M V×%6Ñ%6°s¸Sµy×%AÔ%AØÒñ &ñ øô ô Úðús   ‚B2 Â2CÃ Cc               ó    € V ^8„  d   QhRRRR/# )rA   r  r`   rD   r›   rF   )rG   s   "r4   rH   rH   ’  s   € ÷ Rñ R¨4ð R°Dñ Rr>   c                óä  €  \        \        V P                  RR4      4      R4      '       dˆ   ^ RIHp \        V P                  R4      ;'       g    / 4      pV Uu0 uF  q3P                  4       kK  	  ppV! 4       P                  4        F   w  rVVP                  4       V9  g   K  WbV&   K"  	  W R&   R	# R	# u upi   \         d*    \        4       P                  P                  RRR7        R	# i ; i)
zÔDefense-in-depth: recovery/restore rebuild from a snapshot without re-running header
wiring; a missing Copilot-Integration-Id causes model_not_available_for_integrator 400s.
Only ADD missing keys, never override.rí  rK   zgithubcopilot.com)Úcopilot_default_headersÚdefault_headersz$Copilot default-header guard skippedTrn  N)r%   rE   rL   Úhermes_cli.modelsrž  r`   r�  r  r¡  r=   rd   ra  )r  rž  r£   r  Úexisting_lowerÚhkÚhvs   &      r4   Ú_ensure_copilot_headersr¤  ’  sÑ   € ð
RÜ ¤ ]×%6Ñ%6°zÀ2Ó%FÓ!GÐI\×]Ò]ÝAÜ˜M×-Ñ-Ð.?Ó@×FÐFÀBÓGˆHÙ19Ó:±¨AŸg™gži±ˆNÐ:Ù1Ó3×9Ñ9Ö;‘�Ø—8‘8“: ^Ö3Ø#%˜R“Lñ <ð 08Ð+Ó,ñ ^ùò ;øô
 ô RÜ‹�‰×ÑÐAÈDÐ×QðRús0   ‚AB; ÁB; ÁB6Á3.B; Â&B; Â6B; Â;0C/Ã.C/c               ó$   € V ^8„  d   QhRRRRRR/# )rA   r  r`   r»  rE   r9  r‡   rF   )rG   s   "r4   rH   rH   £  s"   € ÷ ñ °ð Èsð Ð\`ñ r>   c               óœ  € ^ RI HpHp \        VP	                  RR4      ;'       g    R4      pV! V4      '       g   R# VP                  4        UU	u/ uF  w  r‰VR9   g   K  W‰bK  	  p
pp	RV
9  d   V P                  WrR7      pVe   WºR&   V! R	/ V
B p\        4       P                  P                  RW4V P                  4       4       V# u up	pi )
zDNative Gemini client when the base_url is the Gemini API, else None.)ÚGeminiNativeClientÚis_native_gemini_base_urlrí  rK   NÚhttp_client©Úverifyz/Gemini native client created (%s, shared=%s) %s>   rž  r'  rí  r©  rŸ  rF   )Úagent.gemini_native_adapterr§  r¨  rE   rL   r  Ú_build_keepalive_http_clientr=   rd   rÇ  Ú_client_log_context)r”   r  Úhttpx_verifyr»  r9  r§  r¨  rí  r  r  Úsafe_kwargsÚkeepalive_httpr.  s   &&&$$        r4   Ú_gemini_native_clientr²  £  sÒ   € çYÜ�=×$Ñ$ Z°Ó4×:Ð:¸Ó;€HÙ$ X×.Ò.Ùà&×,Ñ,Ô.ôÙ.‘�ØÐTÑTô 	ˆŠÑ.ð ñ ð ˜KÔ'Ø×;Ñ;¸HÐ;ÓZˆØÒ%Ø)7˜Ñ&ÙÑ. +Ñ.€FÜƒE‡L�L×ÑØ9¸6È5×KdÑKdÓKfôð €Mùós   ÁCÁ!Cc               ó(   € V ^8„  d   QhRRRRRRRR/# )	rA   r  r`   r»  rE   r9  r‡   rD   r   rF   )rG   s   "r4   rH   rH   ¸  s/   € ÷ tñ t¨tð tÀð tÈTð tÐVYñ tr>   c          
     óØ  € ^ RI HpHpHp ^ RIHp \        V4      pVP                  R4      '       d   V! VR,          4      VR&    ^ RIH	p V! \        V RR4      4      p	V	eK   V	P                  VP                  RR4      R7      P                  4        F  w  r«VP                  W«4       K  	  \        T RR4      ;'       g    RP%                  4       P'                  4       R8X  d%   ^ RIHp T! T \        T RR4      ;'       g    R4      # TP-                  RR4      pTP-                  RR4      pT! YÞ\/        TP                  RR4      4      R7      pT! 4        T! TP                  R4      4       \1        Y4      pTeA   \        4       P                   P3                  RT P4                  Y#T P7                  4       4       T# ^ RI Hp T P4                  T9   d   \;        YYòTR7      pTe   T# R\/        TP                  R4      ;'       g    R4      9   d@   ^ RIHp TP                  R4      pT! T\A        T\B        \D        34      '       d   TMRR7       RT9  d-   T PG                  TP                  RR4      TR7      pTe   TTR&   TP                  R^ 4       \I        T4       ^ RI%H&p T! YP                  RR4      \/        TP                  RR4      4      R7       ^ R I'H(p TPR                  ! R#/ TB p^ R!I*H+p T! T T4       \        4       P                   P3                  R"Y#T P7                  4       4       T#   \         d*    \        4       P                   P#                  R	R
R7        EL»i ; i)$é    )Ú_to_openai_base_urlÚ_validate_base_urlÚ_validate_proxy_env_urls)Úresolve_httpx_verifyrí  r�  r¿  rK   Nrî  z#Provider client-kwargs hook skippedTrn  r2  r3  rö  rì  Ússl_ca_certÚ
ssl_verify)Ú	ca_bundler»  rí  z:%s client created from provider profile (%s, shared=%s) %s)Ú_GEMINI_NATIVE_PROVIDER_NAMESr8  zbedrock-mantle.)Ú&configure_bedrock_openai_client_kwargsr'  r&  r©  rª  rC  )Úapply_required_codex_headersrž  )rƒ  rí  )Úprocess_bootstrap)Úinstall_served_model_capturez(OpenAI client created (%s, shared=%s) %srF   ),Úagent.auxiliary_clientr¶  r·  r¸  Úagent.ssl_verifyr¹  r`   rL   r‘  r�  rÑ   Úbuild_client_kwargs_extrasr  r	  r¡  r=   rd   ra  rM   r�  r<  r4  r¢   rE   r–  rÇ  r¿  r®  r½  r²  r=  r¾  r_   rp   r”  r­  r¤  Úagent.codex_headersr¿  r”   rÀ  ÚOpenAIÚagent.served_modelrÁ  )r”   r  r»  r9  r¶  r·  r¸  r¹  r�  r”  Úkeyr‹   r4  rº  Ússl_verify_cfgr¯  Úprovider_clientr½  r.  r¾  r'  r±  r¿  rÀ  rÁ  s   &&$$                     r4   Úcreate_openai_clientrË  ¸  s&  € ÷ñ õ
 6ô ˜Ó'€MØ×Ñ˜×$Ò$Ù$7¸ÀjÕ8QÓ$Rˆ�jÑ!ð
QÝ2á&¤w¨u°jÀ"Ó'EÓFˆØÒØ%×@Ñ@Ø&×*Ñ*¨:°rÓ:ð Aó ç‰e‹gò‘
�ð ×(Ñ(¨Ö4ñô 	��z 2Ó&×,Ð,¨"×3Ñ3Ó5×;Ñ;Ó=ÀÔFÝ3Ù ¤w¨u°g¸tÓ'D×'QÐ'QÈ	ÓRÐRØ×#Ñ# M°4Ó8€KØ"×&Ñ& |°TÓ:€NÙ'ØÜ�]×&Ñ& z°2Ó6Ó7ô€Lñ ÔÙ�}×(Ñ(¨Ó4Ô5ô 0°ÓE€OØÒ"Ü‹�‰×ÑØHØ�N‰N˜F¨E×,EÑ,EÓ,Gô	
ð ÐÝDØ‡~�~Ð6Ô6Ü& u¸\ÐagÔhˆØÒØˆMð& œC × 1Ñ 1°*Ó =× CÐ CÀÓDÔDÝPØ×#Ñ# IÓ.ˆÙ.Ø¬j¸Ä3ÌÀ,×.OÒ.O¡7ÐUYõ	
ð ˜MÔ)Ø×;Ñ;¸M×<MÑ<MÈjÐZ\Ó<]ÐfrÐ;ÓsˆØÒ%Ø+9ˆM˜-Ñ(ð ×Ñ˜]¨AÔ.Ü˜MÔ*õ AÙ Ø×$5Ñ$5°iÀÓ$DÜ�]×&Ñ& z°2Ó6Ó7õõ
 (Ø×%Ò%Ñ6¨Ñ6€Få?Ù  ¨Ô/ÜƒE‡L�L×ÑÐ@À&ÐRW×RkÑRkÓRmÔnØ€Møôs ô QÜ‹�‰×ÑÐ@È4Ð×PðQús   ÁA'L5 Ì50M)Í(M)c           	     ó¢  € ^ RI Hp \        V RR4      pVf    ^ RIHpHp V! V! 4       4      pT! T\        V RR4      ;'       g    R\        V RR4      ;'       g    RT;'       g    . R7      p\        \        V R	/ 4      ;'       g    / 4      pVP                  R
R4       V'       d   \        V4      VR
&   Wpn	        R#   \         d    . p LŸi ; i)a[  Re-derive the switched-to provider's ``request_overrides`` (custom_providers ``extra_body``).
Matches by provider key, base_url AND model (same rule as
``agent_init._merge_custom_provider_extra_body``) so a different model at the same endpoint
never inherits another's ``extra_body``. Stale ``extra_body`` cleared; ``service_tier``/``speed`` kept.)Ú%_custom_provider_extra_body_for_agentra  N)rM  Úget_compatible_custom_providersrö  rK   rí  )r¿  rö  rí  rm  r  Ú
extra_body)
Úagent.agent_initrÍ  rÑ   r  rM  rÎ  r¡  r`   r¢   r  )r”   Únew_providerrÍ  rm  rM  rÎ  Únew_extra_bodyÚ	overridess   &&      r4   Ú*_apply_switched_provider_request_overridesrÔ  /  sÐ   € õ
 Gä˜uÐ&9¸4Ó@ÐØÒð	"ßVÙ>¹{»}ÓMÐñ ;Ø¤W¨U°G¸RÓ%@×%FÐ%FÀBÜ˜ 
¨BÓ/×5Ð5°2ÐHX×H^ÐH^Ð\^ô€Nô ”W˜UÐ$7¸Ó<×BÐBÀÓC€IØ‡M�M�, Ô%ßÜ"& ~Ó"6ˆ	�,ÑØ'Öøô ô 	"Ø!Òð	"ús   ™B> Â>CÃCc               ó   € V ^8„  d   QhRR/# )rA   rD   rC   rF   )rG   s   "r4   rH   rH   S  s   € ÷ ñ  ^ñ r>   c           	     óœ   € \          Uu/ uF  q\        W\        4      bK  	  pp\        \        V R/ 4      ;'       g    / 4      VR&   V# u upi )zôSnapshot every field the swap+rebuild mutates so a failed rebuild rolls back atomically
(else a new model name + OLD client 400s next turn). The sentinel distinguishes unset from
None: tests build bare agents via ``__new__`` without all fields.r  )Ú_SWITCH_SNAPSHOT_FIELDSrÑ   Ú_MISSINGr`   )r”   r3   Úsnapshots   &  r4   Ú_snapshot_switch_staterÚ  S  sS   € õ BYÓYÑAX¸”g˜e¬8Ó4Ò4ÑAX€HÐYä!%¤g¨eÐ5EÀrÓ&J×&PÐ&PÈbÓ!Q€HÐÑØ€Oùò Zs   ‰A	c               ó    € V ^8„  d   QhRRRR/# )rA   rÙ  rC   rD   r›   rF   )rG   s   "r4   rH   rH   ]  s   € ÷ (ñ (¨nð (Àñ (r>   c                óæ   € VP                  4        FH  w  r#V\        J d   K  \        P                  ! \        4      ;_uu_ 4        \        WV4       R R R 4       KJ  	  R #   + '       g   i     K_  ; irè   )r  rØ  r¿   rÀ   r¡  Úsetattr)r”   rÙ  r3   r‹   s   &&  r4   Ú_restore_switch_snapshotrÞ  ]  sO   € Ø—~‘~Ö'‰ˆØ”HÓÙÜ× Ò ¤×+Õ+Ü�E Ô'÷ ,Ñ+ó (÷ ,×+Ð+ús   ÁAÁA0c                óê  € ^ RI HpHp	 ^ RIHp
 ^ RIHp V'       g   V! W#VR7      pV'       g
   VR8X  d   RpTpV'       g   Wg8X  d   \        V RR4      pV	! W,4      '       d   R	pV'       d   ^ R
IH	p V! V4      p\        V\        4      '       d   \        V4      MV
! WVVR8H  R7      pVR8X  dA   V! V4      e7   \        V\        4      '       d!   V'       d   \        P                  ! RRV4      pWCV3# )zQResolve ``(api_mode, base_url, destination_capabilities)`` for the switch target.)Údetermine_api_moder  )Ú&resolve_native_compaction_capabilities)Úopencode_provider_familyrj  Úopenaizhttps://api.openai.com/v1rí  rK   r  )Únormalize_actual_base_urlr�  )rö  rí  r¿  Úis_codex_backendrº  z/v1/?$)r  rà  r  Úagent.native_compactionrá  r   râ  rÑ   Úhermes_cli.authrä  r_   r`   rE   r-   r—  )r”   Ú	new_modelrÑ  rí  r¹  r~  Úold_normÚnew_normrà  r  rá  râ  Úeffective_base_urlrä  Údestination_capabilitiess   &&&&&&&&       r4   Ú_resolve_switch_destinationrí  e  sà   € çHÝNÝ:çÙ% lÀIÔNˆß˜ HÔ,à.ˆð "Ðß (Ô"6Ü$ U¨J¸Ó;ÐÙ�|×8Ò8Ø%ˆßÝAÙ0Ð1CÓDˆHô �l¤D×)Ò)ô 	ˆ\Ôá3ØÀ<Ø%¨Ñ7ô
ð ð 	Ð(Ô(Ù$ \Ó2Ò>Ü�x¤×%Ò%ßä—6’6˜) R¨Ó2ˆØÐ7Ð7Ð7r>   c               ó   € V ^8„  d   QhRR/# r›  rF   )rG   s   "r4   rH   rH   Ž  s   € ÷ Eoñ EoÐZ^ñ Eor>   c                ó^  € VR8X  d   ^ RI Hp V! W P                  V4       R# VR8X  d-   VR9   d&   ^ RIHp T! Y;'       g    V P
                  V4       R# VR8X  Ed   ^ RIHp ^ RIH	p	H
p
 VR	8H  pT;'       g=    V P                  ;'       g)    V'       d   V	! \        V R
R4      R7      MR;'       g    RpVR8X  d-   \        V\        4      '       d   V'       d    ^ RIHp V! 4       pV;V n        V n        T;'       g    \        V RR4      V n        V! WÀP*                  \-        V P.                  V P                  4      R7      V n        V
! V P*                  WÁR7      V n        RV n        / V n        R# T;'       g    V P
                  pRT;'       g    V P                  RV/V n         ^ RIHpHpHp T! V P6                  \        T;'       g    R4      V! V! 4       4      4       \-        V P.                  V P                  4      pVe   VV P6                  R&   V PC                  V4       V PE                  \G        V P6                  4      RRR7      V n        R#   \"         d"   p\$        P'                  RT4        Rp?EL•Rp?ii ; i  \"         d    \$        PA                  RRR7        LÅi ; i)z_Build the client for the switched-to destination (MoA facade / native Anthropic / OpenAI wire).r2  )Úbind_moa_runtimeNr5  rº  r6  r"  )Úresolve_anthropic_tokenÚanthropic_route_is_oauthr¸  rö  rj  rK   zminimax-oauth)Ú"build_minimax_oauth_token_providerz`MiniMax OAuth: failed to install per-request token provider on switch (%s); using static bearer.r+  r&  )r¿  rž  rí  )Ú*apply_custom_provider_tls_to_client_kwargsrÎ  r  z6custom-provider TLS resolution skipped on switch_modelTrn  r'  Úswitch_modelr8  r:  )$r<  rð  rö  r=  r7  rí  r)  r#  Úagent.anthropic_credentialsrñ  rò  rž  rÑ   r_   rE   rç  ró  r¡  rd   re   r*  r+  r
   r¿  r,  r-  r.  r  r  rô  rÎ  r  ra  Ú"_apply_client_headers_for_base_urlr>  r`   )r”   rÑ  rž  rí  r¹  rê  rð  r7  r#  rñ  rò  r†  Úeffective_keyró  Ú_mm_excÚeffective_baserô  rÎ  r  r'  s   &&&&&&              r4   Ú_build_switched_clientrû  Ž  sv  € à�5ÔÝ3ñ 	˜§¡¨WÔ5ÙØ�yÔ  XÐ1[Ô%[õ 	?Ù˜U×$>Ð$>°·±ÀÔIÙØÐ'Õ'ÝBßað +¨kÑ9ÐØ÷ ð  5§=¡=÷ ð ßL_Ñ#¬'°%¸À$Ó*GÕHÐeg÷ð àð 	ð
 ˜?Ô*¬z¸-Ì×/MÒ/M×R_ðÝNÙ BÓ D�ð 4AÐ@ˆŒ˜Ô0Ø$,×$[Ð$[´¸Ð?TÐVZÓ0[ˆÔ!Ù"8Ø×4Ñ4Ü0°·±ÀÇÁÓMô#
ˆÔñ %=¸U×=VÑ=VÐXeÔ$}ˆÔ!ØˆŒØ!ˆÔÙØ×/Ð/ §¡€NØ% w×'?Ð'?°%·-±-ÀÈ^Ð\€EÔð^÷	
ñ 	
ñ 	3Ø× Ñ ¤# n×&:Ð&:¸Ó";Ù+Ñ,@Ó,BÓCô	
ô +¨5¯>©>¸5¿;¹;ÓG€GØÒØ*1ˆ×Ñ˜YÑ'ð 
×,Ñ,¨^Ô<Ø×.Ñ.¬t°E×4HÑ4HÓ/IÐR`ÐimÐ.Ón€E†LøôO ô Ü—‘ð;Ø<C÷ò ûðûô> ô ^Ü�‰ÐMÐX\ˆÖ]ð^ús0   ÃI Æ*$J ÇJ ÉJÉ#I?É?JÊ"J,Ê+J,c               ó   € V ^8„  d   QhRR/# r›  rF   )rG   s   "r4   rH   rH   Ö  s   € ÷ *)ñ *)Ð{ñ *)r>   c	                óJ  € RV n         Wn        V;V n        V n        V P	                  4       V n        V'       d   W@n        MWx8w  d   \        RV RV R24      hWPn        \        V R4      '       d   V P                  P                  4        ^ RIHp	 V	! V 4       V'       d   W0n        Wx8w  g   \        V RR4      f#   RV n        RV n         ^ RIHp
 V
! V4      V n        \/        WW4WX4       \1        V 4       R#   \(         d!   p\*        P-                  R	Y+4        Rp?L@Rp?ii ; i)
ziSwap identity/transport fields, reload the pool, rebuild the client (rolled back by the caller on error).Nz1switch_model: no base_url resolved for provider 'z' (switching from 'z5'); refusing to keep the previous provider's endpointr  )Úreset_codex_reasoning_replayr�  )Ú	load_poolzcswitch_model: credential pool reload failed for %s (%s); continuing without pool rotation this turn)Ú_config_context_lengthrö  r¿  r  Ú _read_reasoning_echo_from_configr  rí  Ú
ValueErrorr¹  r†  r  r  Úagent.turn_recovery_codexrþ  rž  rÑ   r�  r   Úagent.credential_poolrÿ  r¡  rd   re   rû  r£  )r”   rè  rÑ  rž  rí  r¹  Úold_providerré  rê  rþ  rÿ  Ú	_pool_excs   &&&&&&&&&   r4   Ú_swap_switch_runtimer  Ö  s"  € ð $(€EÔ Ø„KØ0<Ð<€E„N�UÔ-à!&×!GÑ!GÓ!I€EÔ÷ Ø!�Ø	Ô	ÜðØˆ~Ð0°°ð ?@ð@ó
ð 	
ð
 „NäˆuÐ(×)Ò)Ø×Ñ×$Ñ$Ô&ÝFÙ  Ô'ßØŒð Ôœw uÐ.@À$ÓGÒOà!%ˆÔØ*.ˆÔ'ð	Ý7Ù%.¨|Ó%<ˆEÔ"ô ˜5°À8ÔVÜ! %Ö(øô ô 	Ü�N‰Nð=Ø>J÷ñ ûð	ús   Ã
C7 Ã7D"ÄDÄD"c                ó,  € Rp ^ RI HpHpHp ^ RIHp V! 4       pV! V4      pV! W4      pVf    V! V P                  V P                  VR7      p^ RIH	p	 T	! Y4       Rp
\        T R4      '       d    T P                  T4      p
\        T R4      '       d-   T P                  T
4      '       d   \        P                  R4       Tp\        T R	4      '       d   T P!                  YŠ4      pY+3#   \         d    Rp L©i ; i  \         d    \        Y4       h i ; i)
zpResolve the destination context length (LM Studio preload first); returns ``(custom_providers, effective_len)``.N)rÎ  Ú"get_custom_provider_context_lengthrM  )Ú!config_context_length_for_runtime)rö  rí  rm  )Úset_config_context_lengthÚ_ensure_lmstudio_runtime_loadedÚ_lmstudio_load_was_unverifiedz—LM Studio model activation was rejected or completed without a verifiable active context length during model switch; continuing with configured contextÚ"_effective_lmstudio_context_length)r  rÎ  r	  rM  rÐ  r
  rö  rí  r¡  r  r†  r  rÞ  r  rd   re   r  )r”   rÙ  rm  rÎ  r	  rM  r
  Ú
switch_cfgÚintentr  Úruntime_lenÚ	effectives   &&          r4   Ú_resolve_switch_context_lengthr  	  s   € àÐð÷	
ñ 	
õ 	GÙ “]ˆ
Ù:¸:ÓFÐñ
 3°5ÓEˆØŠ>Ù7Ø—k‘k¨E¯N©NÐM]ôˆFõ
 ;Ù˜eÔ,Ø€KÜˆuÐ7×8Ò8ð	Ø×?Ñ?ÀÓGˆKô ˆuÐ5×6Ò6¸5×;^Ñ;^Ð_j×;kÒ;kÜ�‰ð&ô	
ð
 €IÜˆuÐ:×;Ò;Ø×<Ñ<¸VÓQˆ	ØÐ&Ð&øô) ô ØŠðûô ô 	Ü$ UÔ5Øð	ús   „A
C( Á1C; Ã(C8Ã7C8Ã;Dc               ó   € V ^8„  d   QhRR/# r›  rF   )rG   s   "r4   rH   rH   -	  s   € ÷ .ñ .Ð^bñ .r>   c           	     ó  € ^ RI Hp Vf    ^ RIHpHp V! V! 4       4      p\        V P                  \        4      '       d   V P                  MRp V! V P                  V P                  WpP                  W!R7      pV P                  P                  V P                  VV P                  V P                  V P                  V P                  R7       ^ RIHp	 T	! T 4       R#   \
         d    Rp LËi ; i  \
         d    \        Y4       h i ; i)zQPoint the context compressor at the new model (rolls back the switch on failure).)Úget_model_context_lengthN)rÎ  rM  rK   )rí  rž  r¿  Úconfig_context_lengthrm  )rö  Úcontext_lengthrí  rž  r¿  r¹  )Ú"revalidate_compression_feasibility)r  r  r  rÎ  rM  r¡  r_   rž  rE   rö  rí  r¿  Úcontext_compressorÚupdate_modelr¹  rÞ  Úagent.conversation_compressionr  )
r”   rm  Úeffective_context_lengthrÙ  r  rÎ  rM  Úctx_api_keyÚnew_context_lengthr  s
   &&&&      r4   Ú_update_switch_compressorr   -	  sæ   € å=ØÒð	$ßVÙ>¹{»}ÓMÐô
 $.¨e¯m©m¼S×#AÒ#A�%—-’-Àr€KðÙ5Ø�K‰K %§.¡.¸+×P^ÑP^Ø":ô
Ðð 	× Ñ ×-Ñ-Ø—+‘+Ø-Ø—^‘^Ø—M‘MØ—^‘^Ø—^‘^ð 	.ô 	
õ RÙ& uÖ-øô1 ô 	$Ø#Òð	$ûô$ ô Ü  Ô1Øðús   ŒC ÁA=C0 ÃC-Ã,C-Ã0Dc               ó   € V ^8„  d   QhRR/# r›  rF   )rG   s   "r4   rH   rH   O	  s   € ÷ \ñ \¸tñ \r>   c                ó  € RV n         RV n        RV n        ^ V n        RV n        \        \        V R. 4      ;'       g    . 4      pV'       d_   V'       dW   W#8w  dQ   V Uu. uFD  pVP                  R4      ;'       g    RP                  4       P                  4       W#09  g   KB  VNKF  	  ppW@n
        V'       d
   V^ ,          MRV n         \        W4       R# u upi   \         d    \        P                  RRR7        R# i ; i)	zPPost-switch bookkeeping: fallback reset/prune, request_overrides, billing route.FNÚ_fallback_chainr¿  rK   z4switch_model: request_overrides re-derivation failedTrn  )rK  rª  r§  r¬  rú  r¦   rÑ   rL   rM   r�  r#  Ú_fallback_modelrÔ  r¡  rd   ra  )r”   rÑ  ré  rê  Úfallback_chainrÙ   s   &&&&  r4   Ú_finish_switchr&  O	  sò   € à %€EÔØ&+€EÔ#Ø%)€EÔ"Ø€EÔØ'+€EÔ$ô œ' %Ð):¸BÓ?×EÐEÀ2ÓF€Nß—H Ô!5á-ó
Ù-�eØ—	‘	˜*Ó%×+Ð+¨×2Ñ2Ó4×:Ñ:Ó<ÀXÐDXÑX÷ ˆE™~ð 	ð 
ð +Ôß1?˜N¨1Ö-ÀT€EÔð\Ü2°5ÖGùò
øô ô \Ü�‰ÐKÐVZˆ×[ð\ús$   ÁCÁ;"CÂ"CÃ	C Ã"DÄ Dc               ó   € V ^8„  d   QhRR/# r›  rF   )rG   s   "r4   rH   rH   g	  s   € ÷ \ñ \¨Dñ \r>   c           
     ó  € \        V RR4      p\        V RR4      pVe	   V'       g   R#  VP                  W P                  V P                  \        V RR4      R7       R#   \         d    \
        P                  RRR7        R# i ; i)	zQPersist the billing route so dashboard Model cards show the post-switch provider.Ú_session_dbNr²   r¹  )r¿  rí  Úbilling_modez2Failed to persist billing route after model switchTrn  )rÑ   Úupdate_session_billing_router¿  rí  r¡  rd   re   )r”   Ú
session_dbr²   s   &  r4   Ú_persist_switch_billing_router-  g	  s‚   € ô ˜ ¨tÓ4€JÜ˜ ¨dÓ3€JØÒ§Ùð\Ø×/Ñ/Ø§¡¸%¿.¹.Ü  ¨
°DÓ9ð 	0ö 	
øô ô \Ü�‰ÐKÐVZˆ×[ð\ús   ª3A Á"BÂBc                ó  € V P                   pV P                  pT;'       g    RP                  4       P                  4       p	T;'       g    RP                  4       P                  4       p
\	        WW$WVWš4      w  rTp\        V 4      p \        WW#WEW‰V
4	       \        Y4      w  rÞTe   YÐn
        T P                  Y P                  YQR7      w  T n        T n        \        T R4      '       d   T P                   '       d   \#        YYì4        ^ RIHp ^ RIHp T! T! 4       ;'       g    / T P                   4      T n        \.        P1                  RT P                   T P,                  4       RT n        Y°n        ^ R	IHp T! T 4       \=        Y4      T n        \A        YYš4       \.        P1                  R
YxY4       \C        T 4       R#   \         d    \        Y4       h i ; i  \         d!   p\.        P3                  RT4        Rp?LœRp?ii ; i)a,  Switch the model/provider in-place for a live agent (rebuild clients, caching flags,
compressor). Mirrors ``_try_activate_fallback()`` but also updates ``_primary_runtime`` so
the change persists across turns. A failed swap/rebuild rolls back to the pre-switch
snapshot and re-raises (callers catch).rK   Nr0  r  )Úresolve_reasoning_configrL  z2switch_model: reasoning_config resolved for %s: %sz7switch_model: could not re-resolve reasoning_config: %s)Ú_reset_stale_streakz+Model switched in-place: %s (%s) -> %s (%s))"rö  r¿  rM   r�  rí  rÚ  r  r¡  rÞ  r  ra  Ú_anthropic_prompt_cache_policyrí  Ú_use_prompt_cachingÚ_use_native_cache_layoutr†  r  r   Úhermes_constantsr/  r  rM  Úreasoning_configrd   rÇ  ra  Ú_cached_system_promptr}  Úagent.chat_completion_helpersr0  r$   rO  r&  r-  )r”   rè  rÑ  rž  rí  r¹  r~  Ú	old_modelr  ré  rê  rì  rÙ  rm  r  r/  Ú_sm_load_configÚ_reasoning_errr0  s   &&&&&&&            r4   rõ  rõ  w	  sè  € ð —‘€IØ—>‘>€Lð ×"Ð" ×)Ñ)Ó+×1Ñ1Ó3€HØ×"Ð" ×)Ñ)Ó+×1Ñ1Ó3€HÜ3NØ˜,°(È(ó4Ñ0€HÐ0ô & eÓ,€HðÜØ˜l°XÈÐaiô	
ô 2PÐPUÓ1`Ñ.Ðð Ò#Ø"2ÔØ@E×@dÑ@dØ¯©Àð Aeó AÑ=€EÔ˜uÔ=ô ˆuÐ*×+Ò+°×0H×0HÐ0HÜ! %Ð;SÔ^ð`Ý=ÝDÙ!9¹/Ó:K×:QÐ:QÈrÐSX×S^ÑS^Ó!_ˆÔÜ�‰Ø@À%Ç+Á+Èu×OeÑOeô	
ð #'€EÔð ":Ôõ BÙ˜ÔÜ<¸UÓM€EÔÜ�5¨Ô;Ü
‡K�KØ5Ø ôô " %Ö(øôO ô Ü  Ô1Øðûô, ô `Ü�‰ÐNÐP^×_Ñ_ûð`ús+   ÂG  ÄG Ä#AG Ç GÇHÇ&HÈHc                ó(  €  ^ RI Hp T! YT;'       g    R\        V RR4      ;'       g    RT;'       g    R\        V RR4      ;'       g    R\        V RR4      ;'       g    R\        V4      R7      w  rxYxe   V3# T3#   \         d    RT3u # i ; i)z\Plugin pre-tool-call hook verdict: ``(block_message, function_args)``; failures never block.)Ú_dispatch_pre_tool_call_hooksrK   r²   Ú_current_turn_idÚ_current_api_request_id)Útask_idr²   ru   rÌ   Úapi_request_idÚmiddleware_traceN)Úhermes_cli.pluginsr<  rÑ   r¦   r¡  )	r”   rÇ   Úfunction_argsÚeffective_task_idru   rA  r<  Úblock_messageÚmodified_argss	   &&&&&&   r4   Ú_pre_tool_block_messagerG  º	  s©   € ð#ÝDÙ'DØÐ2C×2IÐ2IÀrÜ˜u l°BÓ7×=Ð=¸2ÈL×L^ÐL^Ð\^Ü˜EÐ#5°rÓ:×@Ð@¸bÜ" 5Ð*CÀRÓH×NÐNÈBÜ!Ð"2Ó3ô(
Ñ$ˆð Ò0I˜}Ð]Ð]È}Ð]Ð]øÜô #Ø�]Ð"Ò"ð#ús2   ‚A? ”A? ª
A? µA? ÁA? Á!A? Á<A? Á?BÂBc               ó@   € V ^8„  d   QhRRRRRRRRRR	R
RRRRRRRRR/
# )rA   rÇ   rE   rC  r`   rD  ru   r^  rm   zlist | NoneÚpre_tool_block_checkedr‡   Úskip_tool_request_middlewareÚtool_request_middleware_tracezOptional[list[dict[str, Any]]]Úskip_tool_execution_middlewarerD   rF   )rG   s   "r4   rH   rH   Ê	  sq   € ÷ Rñ R cð R¸$ð RÐSVð RØ,ðRØ?JðRà)-ðRð 04ðRð 1Oð	Rð
 26ðRð
 CFñRr>   c
                óð  a aaaaa	aaaaaaa€ ^ RI Hp
HoHoHpHp \        S\        4      '       g   / oV! S SS4      p\        T;'       g    . 4      o ^ RI	H
p V'       g#   V! SS3/ VB pVP                  oVP                  oRpT'       g   \!        S SSSSS4      w  poTe/   \"        P$                  ! RT/RR7      pS! S SSTSSRR	TSR
7
       T# \&        P(                  ! 4       oT! S S4      oSe    T
! SSTR7      oR TT TTTTTTTTT3R lloMR TT TTT	T3R lloS	'       d	   S! S4      # ^ RI	Hp T! SSTT3R l3RS/TB #   \         d!   p\        P                  RT4        Rp?LìRp?ii ; i)zÇInvoke a single tool (agent-level or registry-dispatched) and return the result string;
no display logic. Used by the concurrent path; the sequential path keeps its own inline
invocation for display.)ÚInlineToolContextÚapply_transform_tool_resultÚemit_terminal_post_tool_callÚresolve_invoke_tool_executorÚtool_hook_ids)Úapply_tool_request_middlewarez!tool_request middleware error: %sNr½  Fr]   r²  Úplugin_block)	rÇ   rC  ÚresultrD  ru   ÚstatusrS  Úerror_messagerA  )rD  ru   rm   c               ó    € V ^8„  d   QhRRRR/# ©rA   Ú	next_argsr`   rD   r   rF   )rG   s   "r4   rH   Ú!invoke_tool.<locals>.__annotate__ø	  s   € ÷ 	ñ 	 ð 	¨ñ 	r>   c                óà   <€ S! SV S4      p\        V \        4      '       d   T MS	p\        \        P                  ! 4       S,
          R ,          4      pS! SS
VVSSVSR7       S! SS
W!SSVR7      # )iè  )rÇ   rC  rU  rD  ru   Úduration_msrA  )rÇ   rC  rU  rD  ru   r]  )r_   r`   rp   rÒ   r“  )rZ  rU  Ú	call_argsr]  Ú_tool_middleware_tracer”   rO  rD  rP  rC  rÇ   Ú
inline_ctxÚinline_executorru   Útool_start_times   &   €€€€€€€€€€€r4   Ú_executeÚinvoke_tool.<locals>._executeø	  s{   ø€ Ù$ U¨I°zÓBˆFÜ%/°	¼4×%@Ò%@™	ÀmˆIÜœtŸ~š~Ó/°/ÕAÀTÕIÓJˆKÙ(Ø ]À)ØÐ1BÐQ]Ø'Ð:Põñ
 /Ø ]À)Ø"3À,Ð\gôð r>   c               ó    € V ^8„  d   QhRRRR/# rY  rF   )rG   s   "r4   rH   r[  
  s   € ÷ 	tñ 	t ð 	t¨ñ 	tr>   c                ó‚  <€ \        SSP                  ;'       g    R \        SRR 4      ;'       g    R \        SRR 4      ;'       g    R SP                  '       d   \	        SP                  4      MRRR\        SRR4      \        SRR4      \	        S4      R7
      pS'       d   RVR&   ^ RIpVP                  ! SV S3/ VB # )	rK   r=  r>  NTÚenabled_toolsetsÚdisabled_toolsets)
ru   r²   rÌ   r@  Úenabled_toolsÚskip_pre_tool_call_hookrJ  rg  rh  rK  rL  )r`   r²   rÑ   Úvalid_tool_namesr¦   Úmodel_toolsÚhandle_function_call)	rZ  Údispatch_kwargsrl  r_  r”   rD  rÇ   rL  ru   s	   &  €€€€€€r4   rc  rd  
  s¾   ø€ Ü"Ø)°e×6FÑ6F×6LÐ6LÈ"Ü Ð'9¸2Ó>×DÐDÀ"Ü& uÐ.GÈÓL×RÐRÐPRØ>C×>T×>TÐ>Tœd 5×#9Ñ#9Ô:ÐZ^Ø(,È4Ü!(¨Ð0BÀDÓ!IÜ")¨%Ð1DÀdÓ"KÜ.2Ð3IÓ.Jô	ˆO÷ .ØDH�Ð @ÑAÛØ×3Ò3°MÀ9ÐN_ÑsÐcrÑsÐsr>   )Úrun_tool_execution_middlewarec                óL   <€ S! \        V \        4      '       d   V 4      # S4      # rè   )r_   r`   )rZ  rc  rC  s   &€€r4   rh  Úinvoke_tool.<locals>.<lambda>
  s   ø€ ™(´
¸9Äd×0KÒ0K 9Ô_ÐQ^Ô_r>   Úoriginal_args)Úagent.inline_tool_executorsrN  rO  rP  rQ  rR  r_   r`   r¦   Úhermes_cli.middlewarerS  r‚   Útracer¡  rd   ra  rG  ra   rf   rÒ   r“  ro  )r”   rÇ   rC  rD  ru   rm   rI  rJ  rK  rL  rN  rQ  rR  Úhook_idsrS  Ú_tool_request_mwÚ_mw_errrE  rU  ro  rc  r_  rO  rP  r`  ra  rb  s   fffff&&&&f          @@@@@@@r4   Úinvoke_toolry  Ê	  s—  ÿü€ ÷õ ô �m¤T×*Ò*ØˆÙ˜UÐ$5°|ÓD€HÜ!Ð"?×"EÐ"EÀ2ÓFÐðCÝGß+Ù<¸]ÈMÑfÐ]eÑfÐØ,×4Ñ4ˆMØ%5×%;Ñ%;Ð"ð $(€Mß!Ü'>Ø�= -Ð1BÀLÐRhó(
Ñ$ˆ�}ð Ò Ü—’˜W mÐ4À5ÔIˆÙ$Ø ¸mÐTZØ/¸lÐS\Ø%°]Ø3õ		
ð ˆÜ—n’nÓ&€OÙ2°5¸-ÓH€OØÒ"Ù&Ø/¸lÐU]ô
ˆ
÷	÷ 	ó 	÷	tõ 	t÷ &Ù˜Ó&Ð&ÝCÙ(Ø�}Ý_ñð $ðð (0ñð øôo ô CÜ�‰Ð8¸'×BÑBûðCús   ÁE
 Á""E
 Å
E5ÅE0Å0E5c               ó    € V ^8„  d   QhRRRR/# )rA   r�   rE   rD   r´   rF   )rG   s   "r4   rH   rH   
  s   € ÷ /+ñ /+ sð /+¨zñ /+r>   c           	     ó„  € ^ RI Hp V'       g   R# R	 F"  pVP                  V4      pV^ 8”  g   K  VRV pK$  	  V'       g   R# R pR pR R lpVP                  4       pW€P                  9   d   V# V! V4      p	W�P                  9   d   V	# WW–! V4      0p
\        ^4       FO  p\        4       pV
 F4  pV! V4      pV'       g   K  VP                  Wå! V4      V! V4      34       K6  	  W¬,          p
KQ  	  V
 F!  pV'       g   K  WÐP                  9   g   K  Vu # 	  V! W€P                  ^RR7      pV'       d
   V^ ,          # R# )
zØRepair a mismatched tool name (case, separators, CamelCase, ``_tool`` suffixes twice so
``TodoTool_tool`` reduces fully, then fuzzy match) before aborting. Returns the repaired
name if in valid_tool_names, else None.)Úget_close_matchesNc                ób   € V P                  4       P                  R R4      P                  RR4      # )r¸   ré  r´  )r�  Úreplace©Úss   &r4   rh  Ú"repair_tool_call.<locals>.<lambda>5
  s$   € �a—g‘g“i×'Ñ'¨¨SÓ1×9Ñ9¸#¸sÔCr>   c                óN   € \         P                  ! R RV 4      P                  4       # )z(?<!^)(?=[A-Z])ré  )r-   r—  r�  r  s   &r4   rh  r�  6
  s   € œRŸVšVÐ$6¸¸QÓ?×EÑEÔGr>   c               ó    € V ^8„  d   QhRRRR/# )rA   r€  rE   rD   r´   rF   )rG   s   "r4   rH   Ú&repair_tool_call.<locals>.__annotate__8
  s   € ÷ sñ s˜cð s jñ sr>   c                óT   a a€ S P                  4       o\        VV 3R  lR 4       R4      # )c              3  ó’   <"  € T F<  pSP                  V4      '       g   K  SR \        V4      )  P                  R4      x € K>  	  R # 5i)Nz_-)Úendswithrx   rg   )r2   ÚsfxÚlcr€  s   & €€r4   r5   Ú?repair_tool_call.<locals>._strip_tool_suffix.<locals>.<genexpr>:
  s?   øé € ÐkÑ<V°SÐZ\×ZeÑZeÐfi×ZjÔ0�Q�{œ#˜c›(˜�^×*Ñ*¨4×0Ð0Ó<Vùs
   ƒA¡&AN)Ú_toolz-toolrs   )r�  rà  )r€  r‰  s   f@r4   Ú_strip_tool_suffixÚ,repair_tool_call.<locals>._strip_tool_suffix8
  s#   ù€ Ø�W‰W‹YˆÜÕkÑ<VÓkÐmqÓrÐrr>   gffffffæ?)ÚnÚcutoff)Ú"Ú'r*   r+   )Údifflibr|  Úfindr�  rk  Úranger>  rM  )r”   r�   r|  Ú_xml_sepÚ_idxÚ_normÚ_camel_snakerŒ  ÚloweredÚ
normalizedÚcandsré  rï   ÚcÚstrippedÚmatchess   &&              r4   Úrepair_tool_callrŸ  
  s9  € õ *ßÙó )ˆØ�~‰~˜hÓ'ˆØ�!Ž8Ø! % 4Ð(ŠIñ )÷ ÙÙC€EÙG€Lõsð �o‰oÓ€GØ×(Ñ(Ô(ØˆÙ�yÓ!€JØ×+Ñ+Ô+ØÐØ ¨:°|ÀIÓ7NÐO€EÜ�1ŽXˆÜ›%ˆÛˆAÙ)¨!Ó,ˆHß‰xØ—‘˜h¨¨h«¹ÀhÓ9OÐPÖQñ ð 	�Šñ ó ˆß‰1�×,Ñ,Ö,ØŠHñ ñ   ×)?Ñ)?À1ÈSÔQ€Gß ˆ7�1�:Ð* dÐ*r>   g     À‚@údict[str, dict[str, Any]]Ú_empty_heal_log_stater>  Ú_empty_heal_user_notifiedzdict[str, str]Ú_empty_heal_pending_noticec               ó    € V ^8„  d   QhRRRR/# r\  rF   )rG   s   "r4   rH   rH   f
  s   € ÷ 
ñ 
 #ð 
¨$ñ 
r>   c                óþ   € \        V \        4      '       d   \        V P                  4       4      # \        V \        4      '       g   V R9  # \
        ;QJ d    R V  4       F  '       g   K   R# 	  R# ! R V  4       4      # )Nc              3  ó  "  € T F€  p\        V\        4      '       d[   VP                  R 4      R8g  ;'       g?    \        VP                  R4      \        4      ;'       d    VR,          P	                  4       M
\        V4      x € K‚  	  R# 5i)rŸ   r�  N)r_   r`   rL   rE   rM   r‡   )r2   rÍ  s   & r4   r5   Ú'_content_has_payload.<locals>.<genexpr>l
  ss   é € ð ñ ˆEô �eœT×"Ò"ð 
�‰�6Ó	˜fÑ	$×	fÐ	f¬°E·I±I¸fÓ4EÄsÓ)K×)eÐ)eÐPUÐV\ÕP]×PcÑPcÓPeøÜ(,¨U«ô	4ãùs   ‚5B
¸&B
Á+B
TF)NrK   )r_   rE   r‡   rM   r¦   r  rT   s   &r4   Ú_content_has_payloadr¨  f
  sw   € Ü�'œ3×ÒÜ�G—M‘M“OÓ$Ð$Ü�gœt×$Ò$Ø˜jÑ(Ð(ç‹3ñ ñ ó�3Œ3ð Š3ð ˆ3ñ ñ óó ð r>   c               ó    € V ^8„  d   QhRRRR/# )rA   rB   rC   rD   r‡   rF   )rG   s   "r4   rH   rH   s
  s   € ÷ ñ ˜.ð ¨Tñ r>   c                óÎ  € \        V P                  R4      4      ;'       gÅ    \        V P                  R4      ;'       g£    \        V P                  R4      \        4      ;'       d     V R,          P                  4       ;'       g]    V P                  R4      ;'       gD    V P                  R4      ;'       g+    V P                  R4      ;'       g    V P                  R4      4      # )a{  True if ``msg`` carries anything the API treats as non-empty content (text, multimodal
blocks, tool_calls, reasoning). Role-agnostic counterpart of ``AIAgent._is_thinking_only_assistant``.
Codex Responses item carriers persist with content:"" by design (text lives in codex_*_items
and is replayed); treating them as payload keeps the repair from rewriting a designed-empty turn.rR   rY   rë   rJ   rÆ  rà   rß   )r¨  rL   r‡   r_   rE   rM   rN   s   &r4   rN  rN  s
  sÍ   € ô
   §¡¨	Ó 2Ó3÷ ð ´tØ�‰�Ó÷ 	,ð 	,Ü�s—w‘wÐ2Ó3´SÓ9×^Ð^¸cÐBUÕ>V×>\Ñ>\Ó>^÷	,ð 	,à�7‰7�;Ó÷	,ð 	,ð �7‰7Ð&Ó'÷	,ð 	,ð �7‰7Ð(Ó)÷		,ð 	,ð
 �7‰7Ð*Ó+ó8ð r>   c               ó$   € V ^8„  d   QhRRRRRR/# )rA   rB   rC   Úis_finalr‡   rD   rF   )rG   s   "r4   rH   rH   ‚
  s"   € ÷ ñ ¨>ð Èð ÐQUñ r>   c               óª   € V'       g-   \        V \        4      '       d   V P                  R4      R9  d   R# \        V 4      '       d   R# \        V R&   R# )z˜Write the interrupted placeholder onto an empty non-final wire copy; True when filled.
Pass the per-call copy only; durable history must not be mutated.rr   FrR   T)r�   rŽ   )r_   r`   rL   rN  r#   )rB   r¬  s   &$r4   Ú!fill_empty_non_final_wire_payloadr®  ‚
  s@   € ÷ ”z #¤t×,Ò,°·±¸³ÐG\Ô0\ÙÜ˜×ÒÙÜ-€Cˆ	�NÙr>   c               ó   € V ^8„  d   QhRR/# ©rA   rD   rE   rF   )rG   s   "r4   rH   rH   �
  s   € ÷ ñ  #ñ r>   c                 ót   €  ^ RI Hp  \        \        V RR4      ;'       g    R4      #   \         d     R# i ; i)rµ  ©Ú_session_contextr²   NrK   )Úhermes_loggingr³  rE   rÑ   r¡  r²  s    r4   Ú_session_id_for_heal_logrµ  �
  s9   € ðÝ3Ü”7Ð+¨\¸4Ó@×FÐFÀBÓGÐGøÜô Úðús   ‚( ¡( ¨7¶7c               ó   € V ^8„  d   QhRR/# )rA   rD   rp   rF   )rG   s   "r4   rH   rH   •
  s   € ÷ &ñ & Cñ &r>   c                 ó4  € \         P                  ! \        4      ;_uu_ 4        ^ RIHp  V ! 4       P                  R/ 4      ;'       g    / P                  R4      pVe   \        V4      uuRRR4       #  RRR4       \        #   + '       g   i     \        # ; i)zEscalation threshold from ``agent.sanitizer_heal_escalation_threshold``, else the module default (fail-safe on any read error).r  r”   Ú#sanitizer_heal_escalation_thresholdN)r¿   rÀ   r¡  r  r  rL   rp   Ú_EMPTY_HEAL_ESCALATE_AFTER)r  r  s     r4   Ú_heal_escalation_thresholdrº  •
  sv   € ä	×	Ò	œY×	'Õ	'Ý:Ù#Ó%×)Ñ)¨'°2Ó6×<Ð<¸"×AÑAÐBgÓhˆØŠ?Ü�s“8÷	 
(Ò	'ð ÷ 
(ô
 &Ð%÷ 
(Ö	'ô
 &Ð%ús   £ABÂB	c               ó   € V ^8„  d   QhRR/# r»  rF   )rG   s   "r4   rH   rH   Ÿ
  s   € ÷ 9ñ 9¨}ñ 9r>   c                 ó°   € \        4       ;'       g    Rp \        ;_uu_ 4        \        P                  V R4      uuRRR4       #   + '       g   i     R# ; i)zµDrain the one-time user notice for the current session (at most one per session lifetime).
Delivered through the status/warning callback, NEVER appended to the conversation context.r¸   N)rµ  Ú_empty_heal_log_lockr£  r¢   )rÈ  s    r4   Ú%consume_pending_sanitizer_heal_noticer¾  Ÿ
  s9   € ô #Ó
$×
+Ð
+¨€Cß	Ö	Ü)×-Ñ-¨c°4Ó8÷ 
×	×	Ó	ús   £AÁA	c               ó   € V ^8„  d   QhRR/# )rA   rD   r   rF   )rG   s   "r4   rH   rH   §
  s   € ÷ 

ñ 

Ð";ñ 

r>   c                 ó4  € \         ;_uu_ 4        \        P                  4        U Uu/ uFE  w  rV RVP                  RVP                  R^ 4      4      RVP                  R^ 4      RV \        9   /bKG  	  upp uuRRR4       # u upp i   + '       g   i     R# ; i)ztRead-only per-session sanitiser heal counters (``heal_events``, ``messages_healed``, ``escalated``) for diagnostics.Úheal_eventsÚtotal_eventsÚcountÚmessages_healedÚtotal_healedÚ	escalatedN)r½  r¡  r  rL   r¢  )r  r  s     r4   Úget_sanitizer_heal_statsrÇ  §
  s�   € ç	Ö	ô .×3Ñ3Ô5ô
ñ 6‘�ð Ø˜qŸu™u ^°Q·U±U¸7ÀAÓ5FÓGØ! 1§5¡5¨¸Ó#;Ø˜QÔ";Ñ;ðò ñ
 6ò
÷ 
Ò	ùó
÷ 
×	Ð	ús   �B§AB 
Á2BÂ BÂB	c               ó    € V ^8„  d   QhRRRR/# )rA   Úhealedrp   rD   r›   rF   )rG   s   "r4   rH   rH   ´
  s   € ÷ 1ñ 1 cð 1¨dñ 1r>   c                óè  € \        4       ;'       g    Rp\        4       p\        P                  ! 4       p\        ;_uu_ 4        \
        P                  V4      pVe   W4R,          ,
          \        8”  dB   T;'       g    / pR^ RVRRRVP                  R^ 4      RVP                  R^ 4      /;p\
        V&   VR;;,          ^,          uu&   VP                  R^ 4      ^,           VR&   VP                  R^ 4      V ,           VR&   VR,          VR,          VR,          r‡pVR,          '       d    RRR4       R# V^ 8„  ;'       d    Wb8¬  p	V	'       d3   R	VR&   V\        9  d#   \        P                  V4       R
V R2\        V&   RRR4       X	'       d+   \        4       P                  P                  RWXXXV4       R# \        4       P                  P                  RV 4       R#   + '       g   i     Lh; i)zåWARNING on the first heals in a window, one ERROR at the threshold, then silent. The
threshold also queues a ONE-TIME out-of-band user notice (drained by
``consume_pending_sanitizer_heal_notice``); never re-armed by a new window.r¸   NÚwindow_startrÃ  rÆ  FrÂ  rÅ  Tu9   âš ï¸� Your session transcript required repeated repair (uÅ    heal passes so far). Replies keep working, but a corrupted turn is stuck in this session's history â€” run /debug share or `hermes doctor` to capture diagnostics, or /new to start a clean session.u/  Pre-call sanitizer: repeated-heal escalation for session %s â€” healed %d empty non-final message(s) this send; heal pattern: %d heal events / %d messages healed this session (%d in the current session window, threshold %d). The transcript is being repaired on every send; /new drops the poisoned turns.u-  Pre-call sanitizer: healed %d empty non-final message(s) by substituting placeholder content â€” an empty-content turn was in the transcript and would 400 the request ('messages must have non-empty content' / INVALID_REQUEST_BODY). Self-recovering the poisoned transcript in memory; no restart needed.)rµ  rº  rÒ   r“  r½  r¡  rL   Ú_EMPTY_HEAL_WINDOW_Sr¢  r?  r£  r=   rd   r½  re   )
rÉ  rÈ  Ú	thresholdrØ   ÚstateÚpriorrÃ  rÂ  rÅ  Úescalates
   &         r4   Ú_log_empty_non_final_healrÑ  ´
  sÑ  € ô #Ó
$×
+Ð
+¨€CÜ*Ó,€IÜ
�.Š.Ó
€Cß	Ö	Ü%×)Ñ)¨#Ó.ˆØŠ=˜S¨Õ#8Õ8Ô<PÔPØ—K�K˜RˆEà˜˜N¨C°¸eØ §	¡	¨.¸!Ó <¸nÈeÏiÉiÐXfÐhiÓNjð2ð ˆEÔ)¨#Ñ.ð 	ˆg�˜!Õ‹Ø %§	¡	¨.¸!Ó <¸qÕ @ˆˆnÑØ %§	¡	¨.¸!Ó <¸vÕ EˆˆnÑØ,1°'­N¸EÀ.Õ<QÐSXÐYgÕSh˜\ˆØ�×ÔØ÷ 
Ñ	ð ˜q‘=×7Ð7 UÑ%7ˆßØ!%ˆE�+ÑØÔ3Ô3Ü)×-Ñ-¨cÔ2ðØ$�~ð &XðXô +¨3Ñ/÷' 
÷4 Ü‹�‰×ÑðNð PSØ˜,¨¨yô	
ñ 	ÜƒE‡L�L×Ñð	<ð >Dö÷I 
×	ús%   Á:G!Á=B/G!Ä6G!ÅG!Å2G!Ç!G1	c               ó    € V ^8„  d   QhRRRR/# ©rA   rm   rn   rD   rF   )rG   s   "r4   rH   rH   è
  s   € ÷ ñ Ð.Bð ÐG[ñ r>   c                ó¬  € V '       d   \        V 4      ^8  d   V # . p^ p\        V 4      ^,
          p\        V 4       F  w  rEWC8w  dd   \        V\        4      '       dN   VP	                  R4      R9   d8   \        V4      '       g'   VP                  / VCR\        /C4       V^,          pKn  VP                  V4       K�  	  V'       d   \        V4       V# V # )ae  Substitute a placeholder for empty-content non-final messages on the per-call copy.
Anthropic/litellm/Bedrock 400 on any empty non-final message and a persisted stub poisons
every later turn; repairing the wire copy heals the session in memory. Substitution (not
deletion) keeps role alternation and tool-call pairing intact. The final message is untouched.rr   rR   r=  )	rx   rL  r_   r`   rL   rN  r{   r#   rÑ  )rm   rÄ   rÉ  Úlast_idxÚidxrB   s   &     r4   Úrepair_empty_non_final_messagesr×  è
  s³   € ÷
 ”s˜8“} qÔ(ØˆØ%'€HØ€FÜ�8‹}˜qÕ €HÜ˜hÖ'‰ˆàŒ?œz¨#¬t×4Ò4¸¿¹À»ÐLaÔ9aÔjzÐ{~×jÒjà�O‰OÐH˜sÐH IÔ/GÑHÔIØ�a�KŠFà�O‰O˜CÖ ñ (÷ Ü! &Ô)ØˆØ€Or>   c               ó   € V ^8„  d   QhRR/# )rA   rm   rn   rF   )rG   s   "r4   rH   rH      s   € ÷ Uñ UÐ*>ñ Ur>   c           	     ó¤  € V  UUu. uFT  qP                  R4      R8X  g   K  VP                  R4      ;'       g    .  F  p\        V4      ;p'       g   K  W#3NK  	  KV  	  ppp\        4       P                  ! R V 4       !  pV  Uu. uF6  qP                  R4      R8X  g   K  V\	        VP                  R4      4      3NK8  	  pp\        4       P                  ! R V 4       !  pV UUu. uF!  w  rV'       g   K  W…,          '       d   K  VNK#  	  p	ppV UUu. uF  w  r(W‡,          '       d   K  VNK  	  p
ppWWWš3# u uppi u upi u uppi u uppi )a¿  Classify orphaned tool-call / tool-result pairs; single source of truth for GLOBAL orphan
detection. Returns ``(surviving_call_ids, result_call_ids, orphaned_results, missing_tool_calls)``;
every id variant of a tool_call is registered so a result matching any alias survives, and
``orphaned_results`` are the actual dicts (filter by ``id(msg)``). ``sanitize_api_messages``
pairs positionally instead but shares the ``*_id_variants`` alias policy.rr   rŽ   rY   c              3  ó*   "  € T F	  w  rVx € K  	  R # 5irè   rF   ©r2   ré  r  s   &  r4   r5   Ú._classify_tool_call_orphans.<locals>.<genexpr>  s   é € Ð0WÑ?V±t°qµÓ?Vùó   ‚rs   ru   c              3  ó*   "  € T F	  w  rVx € K  	  R # 5irè   rF   rÛ  s   &  r4   r5   rÜ    s   é € Ð-K¹N±D°A­a»NùrÝ  )rL   r   r>  Úunionr   )rm   rB   rD  rE  Úassistant_call_variantsÚsurviving_call_idsÚresult_entriesÚresult_call_idsr  Úorphaned_resultsÚmissing_tool_callss   &          r4   Ú_classify_tool_call_orphansræ     sU  € ñ ôáˆCŸw™w v›°+Ñ=ô 	à—'‘'˜,Ó'×-Ð-¨2Ò-ˆBÜ-¨bÓ1Ð1ˆHÓ1ô 	ˆ‹á-ñ 	Ùð ñ ô $'£5§;¢;Ñ0WÑ?VÓ0WÑ#XÐáKSóÙKSÀC×W^ÑW^Ð_eÓWfÐjpÑWpÔ?ˆÔ% c§g¡g¨nÓ&=Ó>Ó?É8ð ð ô !$£§¢Ñ-K¹NÓ-KÑ L€OÙ*8Ô_©.¡ ¼AœÀq×G]ÑG]Ÿ˜©.ÐÑ_ñ 0ôÙ/‰uˆr¸×8KÑ8K�ˆÑ/ð ñ ð Ð0@ÐTÐTùó#ùòùó `ùós?   †D;¢D;ºD;ÁD;ÂEÂ" EÃ(EÃ9EÄ	EÄEÄ.Ec               ó    € V ^8„  d   QhRRRR/# rÓ  rF   )rG   s   "r4   rH   rH     s   € ÷ ;ñ ;Ð"6ð ;Ð;Oñ ;r>   c                óB  € \        4       P                  P                  pV  FN  pVP                  R4      V9  g   K  \        4       P                  P                  RVP                  R4      4       KP  	  V  Uu. uF  q3P                  R4      V9   g   K  VNK  	  up# u upi )z.Drop messages whose role the API won't accept.rr   z9Pre-call sanitizer: dropping message with invalid role %r)r=   r½   Ú_VALID_API_ROLESrL   rd   ra  )rm   ÚvalidrB   r•   s   &   r4   Ú_drop_invalid_rolesrë    sz   € ä‹E�M‰M×*Ñ*€EÛˆØ�7‰7�6‹? %Ö'Ü‹E�L‰L×ÑÐZÐ\_×\cÑ\cÐdjÓ\kÖlñ ñ  Ó:‘x�!§5¡5¨£=°EÑ#9�AˆA‘xÑ:Ð:ùÒ:s   Á7BÂBc               ó    € V ^8„  d   QhRRRR/# rÓ  rF   )rG   s   "r4   rH   rH   #  s   € ÷ &ñ &Ð,@ð &ÐEYñ &r>   c                óÒ  € . p^ pV  F¨  p\        V\        4      '       d   VP                  R4      R8X  di   RV9   db   \        VR,          \        4      '       d   VR,          '       g6   VP	                  4        UUu/ uF  w  rEVR8w  g   K  WEbK  	  pppV^,          pVP                  V4       Kª  	  V'       g   V # \        4       P                  P                  RV4       V# u uppi )zeStrict providers 400 on ``tool_calls: []``; normalize on shallow copies so history stays byte-stable.rr   rŽ   rY   zOPre-call sanitizer: dropped empty/invalid tool_calls on %d assistant message(s))	r_   r`   rL   r¦   r  r{   r=   rd   ra  )rm   rš  rú   rB   r  r  s   &     r4   Ú_drop_empty_tool_calls_arraysrî  #  sË   € ð (*€JØ€GÛˆä�sœD×!Ò!Ø—‘˜“ ;Ô.ð  Ô#Ü  LÕ 1´4×8Ò8¸SÀ×=NÔ=Nà$'§I¡I¤KÔE¡K™D˜A°1¸Ñ3D”4�1’4¡KˆCÑEØ�q�LˆGØ×Ñ˜#Öñ# ÷$ ØˆÜƒE‡L�L×ÑØYÐ[bôð Ðùó Fs   Á<C#ÂC#c               ó    € V ^8„  d   QhRRRR/# )rA   rm   rn   rD   r›   rF   )rG   s   "r4   rH   rH   L  s   € ÷ %ñ %Ð.Bð %Àtñ %r>   c                ó  € V  EFü  pVP                  R4      R8w  d   K  VP                  R4      ;'       g    . p\        V4       EFµ  w  r4\        V\        4      '       dG   VP                  R4      p\        V\        4      '       d   VP                  R4      M\	        VRR4      pM$\	        VRR4      pV'       d   \	        VRR4      MRp\        V4      pWv8X  d   K™  \        4       P                  P                  RT;'       g    RR	,          V\        4       P                  P                  V4      4       W!P                  R4      J d   \        V4      ;q!R&   \        V\        4      '       d2   \        V\        4      '       d	   / VCRV/CMRVR
R/p/ VCRV/CW#&   EK[  Ve   \	        VR
R4      MRpR\        4       P                  P                  V4      RRRRTR
\        V\        4      '       d   TMR//W#&   EK¸  	  EKÿ  	  R# )až  Coerce every ``function.name`` to the provider-safe ``^[A-Za-z0-9_-]{1,64}$``. An empty/missing
name becomes the ``invalid_tool_call`` sentinel (dropping would unpair the anti-priming result the
dispatch loop keeps for it); an invalid one (``multi_tool_use.parallel``, a shell command a weak
fallback model put in ``name``) is coerced deterministically, because one such stored turn 400s
every later request on a strict endpoint and pins the session to the fallback model (#51944).
Tool calls are rewritten copy-on-write (an SDK object becomes a dict copy) so a shallow per-call
copy never edits persisted history; tool results follow via ``_realign_tool_result_names``.rr   rŽ   rY   rZ   r3   NzSPre-call sanitizer: repairing tool_call with invalid function.name %r -> %r (id=%s)rK   :NéP   Nr[   r¶   r}  rŸ   )rL   rL  r_   r`   rÑ   r   r=   rd   re   r½   rÁ   r¦   rE   )	rm   rB   ÚtcsrÖ  rD  Úfnr3   ÚcoercedÚargss	   &        r4   Ú_repair_invalid_tool_call_namesrö  L  s¹  € ô ˆØ�7‰7�6‹?˜kÔ)ÙØ�g‰g�lÓ#×)Ð) rˆÜ  —~‰GˆCÜ˜"œd×#Ò#Ø—V‘V˜JÓ'�Ü)3°B¼×)=Ò)=�r—v‘v˜f”~Ä7È2ÈvÐW[ÓC\‘ä˜R ¨TÓ2�ß46”w˜r 6¨4Ô0¸D�Ü& tÓ,ˆGØŒÙÜ‹E�L‰L× Ñ ØeØ—�˜˜SÕ! 7¬C«E¯M©M×,RÑ,RÐSUÓ,Vôð —g‘g˜lÓ+Ó+Ü*.¨s«)Ð3�˜,Ñ'Ü˜"œd×#Ò#Ü0:¸2¼t×0DÒ0DÐ,˜Ð,˜F GÒ,È6ÐSZÐ\gÐimÐJn�Ø1˜bÐ1 *¨bÑ1�”à9;º”w˜r ;°Ô5ÈT�àœ#›%Ÿ-™-×@Ñ@ÀÓDØ˜JØ ¨°+ÄzÐRVÔX[×G\ÒG\¹tÐbfÐ gð�”ô+ &ó	 r>   c               ó    € V ^8„  d   QhRRRR/# rÓ  rF   )rG   s   "r4   rH   rH   t  s   € ÷ ñ Ð(<ð ÐAUñ r>   c                ól  € V  Uu. uFL  pVP                  R4      R8X  d2   VP                  R4      ;'       g    RP                  4       '       g   KJ  VNKN  	  pp\        V4      \        V 4      8w  d>   \        4       P                  P                  R\        V 4      \        V4      ,
          4       V# u upi )z×Drop tool results with a missing/empty tool_call_id. Kept explicit (not left to the
positional walk) for its own log line and so the final-chokepoint guarantee holds for
callers skipping ``repair_message_sequence``.rr   rs   ru   rK   zMPre-call sanitizer: dropped %d tool result(s) with missing/empty tool_call_id)rL   rM   rx   r=   rd   ra  )rm   r•   r)  s   &  r4   Ú_drop_results_without_idsrù  t  s–   € ñ
 óÙˆaØ—‘�f“ Ô'°·±°~Ó1F×1LÐ1LÈ"×0SÑ0S×0U÷ 	
ˆ‘8ð 	ð ô ˆ4ƒy”C˜“MÔ!Ü‹�‰×ÑØ[Ü�‹MœC ›IÕ%ô	
ð €Kùòs   …2B1¸B1ÁB1c               ó    € V ^8„  d   QhRRRR/# rÓ  rF   )rG   s   "r4   rH   rH   „  s    € ÷ G6ñ G6Ð,@ð G6ÐEYñ G6r>   c                ó  aa	a
a€ . o	/ o^ p^ oR VV	V3R llpV  Fñ  pVP                  R4      pVR8X  dQ   V! 4        / oVP                  R4      ;'       g    .  F'  p\        V4      pV'       g   K  WV3S\        V4      &   K)  	  MuVR8X  da   \        VP                  R4      4      o
\	        V
3R lSP                  4        4       R	4      pVf   V^,          pK¿  SP                  VR	4       MVR
8X  d   V! 4        S	P                  V4       Kó  	  V! 4        V'       d%   \        4       P                  P                  RV4       S'       d%   \        4       P                  P                  RS4       V'       g	   S'       d   S	# T # )zÒPositional tool_call <-> tool_result pairing: strict providers (DeepSeek v4, Kimi) require
results IMMEDIATELY after their call. Drops positional orphans, stubs unanswered declared
ids; matching is alias-aware.c               ó   € V ^8„  d   QhRR/# r›  rF   )rG   s   "r4   rH   Ú3_pair_tool_calls_positionally.<locals>.__annotate__�  s   € ÷ 
ñ 
 Tñ 
r>   c                 ó  <€ \        S4       Fd  p SV ,          w  rSP                  R RR\        4       P                  P	                  V4      RRR\        V4      ;'       g    T /4       S^,          oKf  	  SP                  4        R# )rr   rs   r3   rR   u2   [Result unavailable â€” see context summary above]ru   N)Úsortedr{   r=   r½   Ú_get_tool_call_name_staticr   r  )rÈ  rD  Ú	_variantsÚdeclared_callsÚpairedÚstubss      €€€r4   Ú_flush_unanswered_stubsÚ>_pair_tool_calls_positionally.<locals>._flush_unanswered_stubs�  s|   ø€ ä˜.Ö)ˆCØ*¨3Õ/‰MˆBØ�M‰MØ˜ ¬«¯©×(PÑ(PÐQSÓ(TØÐOØÔ 5°bÓ 9× @Ð @¸Sðô ð
 �Q�JŠEñ *ð 	×ÑÖr>   rr   rŽ   rY   rs   ru   c              3  óT   <"  € T F  w  pw  r#VS,          '       g   K  Vx € K  	  R # 5irè   rF   )r2   r  Ú_tcr  rG  s   &   €r4   r5   Ú0_pair_tool_calls_positionally.<locals>.<genexpr>¸  s%   øé € Ð_Ñ1G¡+ !¡X cÈ1È×K^ÑK^ŸAšAÓ1Gùs   ƒ(ž
(Nr�   zCPre-call sanitizer: removed %d positionally orphaned tool result(s)zYPre-call sanitizer: added %d stub tool result(s) for positionally unanswered tool call(s))rL   r   r¯   r   rà  r  r¢   r{   r=   rd   ra  )rm   rú   r  rB   rr   rD  rE  Úmatchedr  r  rG  r  s   &       @@@@r4   Ú_pair_tool_calls_positionallyr  „  sU  û€ ð( $&€FØ')€NØ€GØ€E÷
ò 
ó ˆØ�w‰w�v‹ˆØ�;Ôñ $Ô%ØˆNØ—g‘g˜lÓ+×1Ð1¨rÒ1�Ü0°Ó4�ß‘8ð 68°N�N¤3 x£=Ó1ò 2ð �VŒ^Ü5°c·g±g¸nÓ6MÓNˆOÜÔ_°×1EÑ1EÔ1GÓ_ÐaeÓfˆGØŠØ˜1•�Ùà×Ñ˜w¨Õ-Ø�VŒ^á#Ô%Ø�‰�cÖñ1 ñ4 ÔßÜ‹�‰×ÑÐ`ÐbiÔjßÜ‹�‰×Ñð3Ø49ô	
÷ §ˆ6Ð5¨XÐ5r>   c               ó    € V ^8„  d   QhRRRR/# rÓ  rF   )rG   s   "r4   rH   rH   Î  s    € ÷ Eñ EÐ$8ð EÐ=Qñ Er>   c                óœ  € / p/ p^ p. p^ pV  EF  pVP                  R4      pVR8X  Ed*   VP                  R4      '       Ed   . pVP                  R4      ;'       g    .  F  p	\        V	4      p
V
'       d(   W¡P                  4       ,          '       d   V^,          pK=  V
'       d*   TpV^,          pW¢V&   V
 F  pVP                  WË4       K  	  VP	                  V	4       K�  	  V'       d   / VCRV/CpEM	\        V4      \        VP                  R4      ;'       g    . 4      8w  d-   VP                  4        UUu/ uF  w  rÞVR8w  g   K  WÞbK  	  pppMªVR8X  d¤   \        VP                  R4      4      pV Uu0 uF  qîV9   g   K  W,          kK  	  ppV'       d   V'       g   V^,          pEK¢  V'       dG   \        V4      pVP                  V\        4       4       F  pVP                  V4      V8X  g   K  W K  	  VP	                  V4       EK  	  V'       g   V # \        4       P                  P                  RV4       V# u uppi u upi )a4  Deduplicate tool_call_ids (strict providers 400 on duplicates): collapse duplicates within
an assistant message, drop results answering no OUTSTANDING call. Tracks outstanding calls
(not ids ever seen) because llama.cpp reuses one constant id, and whole variant groups so
alias-keyed results are not deleted.rr   rŽ   rY   rs   ru   zBPre-call sanitizer: removed %d duplicate tool_call_id reference(s))rL   r   Úkeysr	  r{   rx   r  r   r¯   r¢   Ú	frozensetr=   rd   ra  )rm   ÚoutstandingÚoutstanding_groupsÚnext_group_idÚdedupedÚremovedrB   rr   Úkept_tcsrD  rE  Úgroup_idÚvariantr  r  rG  rH  s   &                r4   Ú_dedupe_tool_call_idsr  Î  s  € ð
 #%€Kð& 02ÐØ€MØ$&€GØ€GÜˆØ�w‰w�v‹ˆØ�;Õ 3§7¡7¨<×#8Ó#8ØˆHØ—g‘g˜lÓ+×1Ð1¨rÒ1�Ü0°Ó4�ß ×+;Ñ+;Ó+=× =Ô =Ø˜q•L�GÙßØ,�HØ! QÕ&�MØ3; xÑ0Û#+˜Ø#×.Ñ.¨wÖAñ $,à—‘ Ö#ñ 2÷ Ø5˜Ð5˜l¨HÑ5’Ü�X“¤# c§g¡g¨lÓ&;×&AÐ&A¸rÓ"BÔBØ(+¯	©	¬ÔI©¡ °q¸LÑ7H”t�q’t©�ÑIøØ�VŒ^Ü5°c·g±g¸nÓ6MÓNˆOÙ8GÓ\¹°1ÐP[ÑK[¤ § ¹ÐÐ\ß×'7Ø˜1•�Úßô
 Ð/Ó0�Ø1×5Ñ5°hÄ	ÃÖL�GØ"—‘ wÓ/°8Ö;Ø'Ò0ñ  Mð 	�‰�s×ñG ÷H ØˆÜƒE‡L�L×ÑØLÈgôð €Nùó- Jùò  ]s   Ä9IÅ	IÅ8I	ÆI	c               ó    € V ^8„  d   QhRRRR/# rÓ  rF   )rG   s   "r4   rH   rH     s   € ÷ .ñ .Ð)=ð .ÐBVñ .r>   c                ór  € / pV  F³  pVP                  R4      R8X  g   K  VP                  R4      ;'       g    .  Fy  p\        4       P                  P                  V4      ;'       g    RP	                  4       p\        4       P                  P                  V4      pV'       g   Kk  V'       g   Ku  WQV&   K{  	  Kµ  	  . p. pV  F£  pVP                  R4      R8X  dz   TP                  VP                  R4      ;'       g    RP	                  4       4      pVP                  R4      p	V'       d)   V	'       d!   W˜8w  d   / VCRV/CpVP                  W˜34       VP                  V4       K¥  	  V'       g   V # \        4       P                  P                  R\        V4      R	P                  R
 V 4       4      4       V# )z©Align each tool result's wire ``name`` with its call's function name (per-call copy only):
Google 400s on a mismatch, routine when tool_search bridges via ``tool_call``.rr   rŽ   rY   rK   rs   ru   r3   z\Pre-call sanitizer: realigned %d tool result name(s) with their tool_call function name (%s)z, c              3  ó4   "  € T F  w  rV R V 2x € K  	  R# 5i)z -> NrF   )r2   ÚwasrØ   s   &  r4   r5   Ú-_realign_tool_result_names.<locals>.<genexpr>B  s   é € Ð>±I©¨�S�E˜˜c˜UÕ#³Iùs   ‚)rL   r=   r½   rÁ   rM   r   r{   rd   ra  rx   r“   )
rm   Ú
call_namesrB   rD  ÚcidÚnmÚ	realignedÚalignedÚexpectedru  s
   &         r4   Ú_realign_tool_result_namesr$    sd  € ð& "$€JÛˆØ�7‰7�6‹?˜kÖ)Ø—g‘g˜lÓ+×1Ð1¨rÒ1�ä“u—}‘}×=Ñ=¸bÓA×GÐGÀR×NÑNÓP�Ü“U—]‘]×=Ñ=¸bÓA�ß‘3Ÿ2™2Ø&(˜s“Oó 2ñ ð (*€IØ$&€GÛˆØ�7‰7�6‹?˜fÔ$Ø!—~‘~ s§w¡w¨~Ó'>×'DÐ'DÀ"×&KÑ&KÓ&MÓNˆHØ—g‘g˜f“oˆGçŸG¨Ô(;Ø/˜Ð/˜f hÑ/�Ø× Ñ  'Ð!4Ô5Ø�‰�sÖñ ÷ ØˆÜƒE‡L�L×Ñð	'Ü(+¨I«Ø�	‰	Ñ>±IÓ>Ó>ôð
 €Nr>   c               ó    € V ^8„  d   QhRRRR/# rÓ  rF   )rG   s   "r4   rH   rH   G  s   € ÷ 0ñ 0Ð$8ð 0Ð=Qñ 0r>   c                ó²   € \        V 4      p \        V 4      p \        V 4      p \        V 4       \	        V 4      p \        V 4      p \        V 4      p \        V 4      # )zôFix orphaned tool_call / tool_result pairs before every LLM call; runs unconditionally (not
gated on the compressor). Order matters: empty non-final messages are healed first so the
substituted turn participates in the pairing and dedup passes.)rë  r×  rî  rö  rù  r  r  r$  )rm   s   &r4   Úsanitize_api_messagesr'  G  sS   € ô # 8Ó,€HÜ.¨xÓ8€HÜ,¨XÓ6€HÜ# HÔ-Ü(¨Ó2€HÜ,¨XÓ6€HÜ$ XÓ.€HÜ% hÓ/Ð/r>   u@   \b(i['â€™]ll|i will|let me|i can do that|i can help with that)\bc          
     ó,   € V ^8„  d   QhRRRRRRRRR	R/# )
rA   Úuser_messager   Úassistant_contentrE   rm   rn   Úrequire_workspacer‡   rD   rF   )rG   s   "r4   rH   rH   `  s=   € ÷ [ñ [Øð[Ø14ð[Ø@Tð[àð[ð 
ñ[r>   c                ó,  a&a'€ \         ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d   R# T P                  T;'       g    R4      P                  4       P                  4       o&S&'       d   \	        S&4      R8”  d   R# \
        P                  ! R4      p\
        P                  ! R4      p\
        P                  ! R4      p\
        P                  ! R	4      p\
        P                  ! R
4      p	\
        P                  ! R4      p
\
        P                  ! R4      p\
        P                  ! R4      p\
        P                  ! R4      p\
        P                  ! R4      p\
        P                  ! R4      p\
        P                  ! R4      p\
        P                  ! R4      p\
        P                  ! R4      p\
        P                  ! R4      pRpVP                  S&4       Uu0 uF,  pVP                  R4      R8X  g   K  VP                  R4      kK.  	  pp\	        V4      ^8¬  pVP                  RS&4      pVP                  V4       Uu0 uF  pVP                  ^4      kK  	  ppT;'       g    \        V4      pV	P                  S&4      '       Eg   VP                  S&4       EF  pS&RVP                  R4       pV'       g   VP                  V4      '       d   K9  S&VP                  4       R pV
P                  V4      pV'       d(   VRVP                  4        p VVP                  4       R p!MTp Rp!V!P                  4       '       d   VP                  V!4      '       g   K¿  VP                  R4      p"V"R"9   p#\        T#;'       d    VP                  V 4      ;'       gú    V"R8H  ;'       d    VP                  V 4      ;'       gÔ    V"R8H  ;'       d    VP                  V 4      ;'       g®    T#;'       d    VP                  V 4      ;'       g‹    T#;'       d    VP                  V 4      ;'       gh    V"R#9   ;'       d    VP                  V 4      ;'       gB    V"R8H  ;'       d    VP                  V 4      ;'       g    T#;'       d    VP                  V 4      4      p$V$'       g   EK  Rp M	  \        P                  S&4      '       g   V'       g   R# V'       gK   \         ;QJ d#    V&3R l\          4       F  '       g   K   RM	  RM! V&3R l\          4       4      '       g   R# V'       g   R# ^ RIHp% V%! V4      P                  4       P                  4       o'\         ;QJ d#    V'3R l\&         4       F  '       g   K   RM	  RM! V'3R l\&         4       4      ;'       g]    RS'9   ;'       gP    R S'9   ;'       gC    \         ;QJ d#    V&3R! l\&         4       F  '       g   K   R# 	  R# ! V&3R! l\&         4       4      # u upi u upi )$aÿ  Detect a planning/ack message that should continue instead of ending the turn.
``require_workspace=False`` (opt-in for all api_modes) drops the filesystem/repo reference
requirement; short-content + no-prior-tools guardrails always apply. A response must then
contain either a first-person future acknowledgement with an action marker or a narrowly
bounded pronounless action clause with an explicit transition cue; this keeps ordinary
conversational replies such as "I'll help you brainstorm" from tripping it.c              3  óz   "  € T F1  p\        V\        4      ;'       d    VP                  R 4      R8H  x € K3  	  R# 5i©rr   rs   Nr$  )r2   rB   s   & r4   r5   Ú4looks_like_codex_intermediate_ack.<locals>.<genexpr>j  s/   é € Ð
SÉ(À3Œ:�cœ4Ó ×>Ð> S§W¡W¨V£_¸Ñ%>Ô>Ë(ùs   ‚;ž;TFrK   i°  uÝ   (?:^|[.!â€¦â€”â€“]\s+|\n+\s*|,\s+then\s+)(?:(?P<transition>then)\s+)?(?P<action>(?:re)?launching|(?:re)?starting|creating|checking|running|writing|opening|reading|inspecting|reviewing|testing|debugging|searching|fixing)\bz (?:^|\n)\s*(?:[-*+]|\d+[.)])\s*$z(?:^|\s)(\d+)[.)](?=\s)zG\b(?P<label>exit\s+code|attempt|step|retry)\s+(?P<number>\d+)[.)](?=\s)u   \?(?=\s|$|[\"'â€™â€�)\\]])u2   (?:[.!â€¦](?=\s|$)|\?(?=\s|$|[\"'â€™â€�)\\]])|\n+)uå   \s*(?:will\s+report\s+back|then\s+(?:launching|relaunching|starting|restarting|creating)\s+(?:it|(?:the\s+)?(?:session|worker|agent|job|process))|(?:checking|reading|opening|inspecting)\s+(?:the\s+)?(?:log|output))\s*[.!â€¦]?\s*$z‡\s+(?:(?:it|(?:the\s+)?(?:session|worker|agent|job|process)|(?:the\s+)?migration\s+file\s+in\s+the\s+repo)\s+)?now(?:\s*\([^)]*\))?\s*$zl\s+(?:(?:it|(?:the\s+)?(?:(?:repo\s+)?suite|tests?|job|process|server|service))\s+)?now(?:\s*\([^)]*\))?\s*$zR\s+(?:the\s+)?(?:log|output|status|service|session|job)\s+now(?:\s*\([^)]*\))?\s*$uA   \s+now\s*[â€”â€“-]\s*see\s+https?://\S+(?:\s+for\s+progress)?\s*$z^\s+(?:it|(?:the\s+)?(?:session|worker|agent|job|process))\s+on\s+copilot(?:\s+via\s+acpx)?\s*$z)\s+(?:the\s+)?actual\s+(?:log|output)\s*$zI\s+whether\b.*\b(?:healthy|ready|running|available|reachable|working)\s*$zŠ\s+with\s+(?:(?:corrected|updated|new)\s+(?:arguments?|args?|options?|flags?|parameters?)|globals?\s+before\s+(?:the\s+)?agent\s+name)\s*$rñ  ÚstepÚnumberNÚactionÚrunningÚcheckingc              3  ó,   <"  € T F	  qS9   x € K  	  R # 5irè   rF   ©r2   rš   Úassistant_texts   & €r4   r5   r/  ë  s   øé € ð .Ù/B V�.Ö Ó/BùrÝ  ©Ú_summarize_user_message_for_logc              3  ó,   <"  € T F	  qS9   x € K  	  R # 5irè   rF   )r2   rš   Ú	user_texts   & €r4   r5   r/  ÷  s   øé € ÐEÑ.D F�iÖÓ.DùrÝ  z~/rä  c              3  ó,   <"  € T F	  qS9   x € K  	  R # 5irè   rF   r6  s   & €r4   r5   r/  ú  s   øé € ÐMÑ6L¨F˜Ö'Ó6LùrÝ  >   ÚcreatingÚstartingÚ	launchingÚ
restartingÚrelaunching>   ÚopeningÚreadingr4  Ú
inspecting)r  Ú_strip_think_blocksrM   r�  rx   r-   r.   ÚfinditerÚgroupr—  r‡   Úsearchro   ÚendÚ	fullmatchÚ_ACK_FUTURE_REÚ_ACK_ACTION_MARKERSÚagent.codex_responses_adapterr9  Ú_ACK_WORKSPACE_MARKERS)(r”   r)  r*  rm   r+  Úaction_clause_patternÚlist_item_prefix_patternÚnumbered_item_patternÚstatus_number_patternÚquestion_patternÚsentence_boundary_patternÚallowed_trailing_action_patternÚlaunch_now_tail_patternÚrun_now_tail_patternÚcheck_now_tail_patternÚlaunch_url_tail_patternÚprovider_tail_patternÚactual_log_tail_patternÚhealth_check_tail_patternÚlaunch_with_patternÚhas_pronounless_actionÚstatus_matchÚstep_numbersÚhas_step_sequenceÚnumbering_textÚmatchÚnumbered_markersÚhas_numbered_listÚaction_matchÚaction_prefixÚraw_clause_tailÚboundary_matchÚclause_tailÚremaining_textÚaction_wordÚis_launch_actionÚhas_transition_cuer9  r7  r;  s(   &&&&&                                 @@r4   Ú!looks_like_codex_intermediate_ackro  `  sÅ  ù€ ÷ ƒsÑ
SÉ(Ó
S‡s‡s‚sÑ
SÉ(Ó
S×SÒSÙØ×.Ñ.Ð/@×/FÐ/FÀBÓG×MÑMÓO×UÑUÓW€NßœS Ó0°4Ô7Ùô ŸJšJð	1óÐô  "ŸzšzÐ*MÓNÐÜŸJšJÐ'AÓBÐÜŸJšJð	%óÐô —z’zÐ"?Ó@ÐÜ "§
¢
Ø=ó!Ðô ')§j¢jð	ó'Ð#ô !Ÿjšjð	$óÐô
 Ÿ:š:ð	9óÐô  ŸZšZð	$óÐô !Ÿjšjð	&óÐô ŸJšJð	.óÐô !ŸjšjØ4óÐô !#§
¢
ØTó!Ðô Ÿ*š*ð	<óÐð
 #Ðð 2×:Ñ:¸>ÔJóáJˆLØ×Ñ˜gÓ&¨&Ñ0ô 	%ˆ×Ñ˜8Ö$ÙJð ð ô
 ˜LÓ)¨QÑ.ÐØ*×.Ñ.¨r°>ÓB€Nà$9×$BÑ$BÀ>Ô$RóÙ$R˜5ˆ�‰�AŽÑ$Rð ð ð *×CÐC¬TÐ2BÓ-CÐØ×"Ñ" >×2Ó2Ø1×:Ñ:¸>×JˆLØ*Ð+I¨\×-?Ñ-?ÀÓ-IÐJˆMß Ð$<×$CÑ$CÀM×$RÒ$RÙØ,¨\×-=Ñ-=Ó-?Ð-AÐBˆOØ6×=Ñ=¸oÓNˆNßØ-Ð.F°×0DÑ0DÓ0FÐG�Ø!0°×1CÑ1CÓ1EÐ1GÐ!H‘à-�Ø!#�Ø×#Ñ#×%Ò%Ð.M×.WÑ.WØ÷/ò /ñ Ø&×,Ñ,¨XÓ6ˆKØ*ð /ñ  Ðô "&Ø!×TÐTÐ&=×&GÑ&GÈÓ&T÷ Uð UØ 9Ñ,×\Ð\Ð1E×1OÑ1OÐP[Ó1\÷Uð Uð   :Ñ-÷ Fð FØ.×8Ñ8¸ÓE÷	Uð Uð %×WÐWÐ)@×)JÑ)JÈ;Ó)W÷Uð Uð %×UÐUÐ)>×)HÑ)HÈÓ)U÷Uð Uð  Ð#SÑS÷ Gð GØ/×9Ñ9¸+ÓF÷Uð Uð   :Ñ-÷ Ið IØ1×;Ñ;¸KÓH÷Uð Uð  %×SÐSÐ)<×)FÑ)FÀ{Ó)Só#"Ð÷& &ÚØ%)Ð"Ùñ] Kô^ ×!Ñ! .×1Ò1×5KÙß!¯#«#ô .Ý/Bó.¯#¯#ª#ô .Ý/Bó.÷ +ò +ñ çÙõ NÙ/°Ó=×CÑCÓE×KÑKÓM€Iç‹ÔEÕ.DÓE��ŠÔEÕ.DÓEÓE÷ 	Nð 	NØ�9Ñ÷	Nð 	Nà�)Ñ÷	Nð 	N÷ ‹3ÔMÕ6LÓM�3Œ3ð	ò ð	ð ÔMÕ6LÓMÓMð	ùòQùòs   Ç/XÈXÉXz?!,;:)]}c               ó$   € V ^8„  d   QhRRRRRR/# )rA   r�  rE   r)  r   rD   r‡   rF   )rG   s   "r4   rH   rH     s&   € ÷ Jñ J cð J¸ð JÈñ Jr>   c                óÌ  € T ;'       g    RP                  4       pV'       d0   \        V4      \        8”  g   VP                  \        4      '       d   R# V^ ,          \
        9   d0   \        V4      ^8”  d    V^,          P                  4       '       d   R# \        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d;   \        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d   R# ^ RIH	p V'       d	   V! V4      MRp\        ;QJ d&    R V 4       F  '       g   K   R'       * # 	  R'       * # ! R V 4       4      '       * # )u	  Whether a text stop reads as a collapsed fragment rather than a (terse) answer.

"Wrong script" is judged against the conversation: when the user's own message carries
non-ASCII letters, a terse non-Latin reply ("æ˜¯", "Ð“Ð¾Ñ‚Ð¾Ð²Ð¾") is an answer, not a collapse.
rK   FTc              3  ó@   "  € T F  qP                  4       x € K  	  R # 5irè   )Úisalpha©r2   Úchs   & r4   r5   Ú.looks_like_degenerate_final.<locals>.<genexpr>  s   é € Ð(¡a �z‰z�|ˆ|£aùs   ‚c              3  óp   "  € T F,  qP                  4       ;'       d    VP                  4       x € K.  	  R # 5irè   )ÚisasciiÚisalnumrt  s   & r4   r5   rv    s(   é € Ð/ZÑXYÐRT·
±
³×0MÐ0MÀÇÁÃÔ0MÓXYùs   ‚6�6r8  c              3  óz   "  € T F1  qP                  4       ;'       d    VP                  4       '       * x € K3  	  R # 5irè   )rs  rx  rt  s   & r4   r5   rv    s(   é € ÐI¹y¸—:‘:“<×4Ð4¨¯
©
«Ô$4Ô4»yùs   ‚;�;)
rM   rx   Ú_DEGENERATE_FINAL_MAX_CHARSr‡  Ú_SENTENCE_TERMINALSÚ_DEGENERATE_LEADING_PUNCTrs  r  rM  r9  )r�  r)  rÛ  r9  r;  s   &&   r4   Úlooks_like_degenerate_finalr~    sì   € ð 
�ˆ�×ÑÓ€Aß”�A“Ô4Ô4¸¿
¹
ÔCV×8WÒ8WÙØˆ…tÔ(Ô(¬S°«V°a¬Z¸A¸a½D¿L¹L¿NºNÙß‹3Ñ(¡aÓ(�3�3Š3Ñ(¡aÓ(×(Ò(¯C«CÑ/ZÑXYÓ/Z¯C¯CªCÑ/ZÑXYÓ/Z×,ZÒ,ZÙÝMßAMÑ/°Ô=ÐSU€Iß‹sÑI¹yÓI�sŒsÔIÐIŠsÔIÐIˆsÑI¹yÓIÓIÔIÐIr>   c               ó    € V ^8„  d   QhRRRR/# )rA   rm   rn   rD   rp   rF   )rG   s   "r4   rH   rH      s   € ÷ ñ Ð%9ð ¸cñ r>   c                óæ   € ^ p\        T ;'       g    R4       FU  p\        V\        4      '       g   K  VP                  R4      R8X  d    V# VP                  R4      R8X  g   KL  V^,          pKW  	  V# )u/  Tool-result rows after the most recent user row â€” whether the turn did real tool work.

ANY user row ends the window, the continuation nudges included: that is what bounds the
degenerate-final guard to one re-prompt per collapse. Skipping synthetic user rows here
would turn it into a two-nudge loop.
rr   r�   rs   rF   )Úreversedr_   r`   rL   )rm   rÃ  rB   s   &  r4   Útool_results_this_turnr‚     sj   € ð €EÜ˜Ÿ˜ BÖ'ˆÜ˜#œt×$Ò$ÙØ�7‰7�6‹?˜fÔ$Øð €Lð �7‰7�6‹?˜fÖ$Ø�Q�JŠEñ (ð €Lr>   z‡(?:\blet me now\b|\bi(?:['\u2019])?ll now\b|\bi will now\b|\bnow i(?:['\u2019]ll| will)\b|\bnext[,:] i\b)[^.!?\n]{0,100}[.:\u2026]?\s*$r  c               ó    € V ^8„  d   QhRRRR/# ©rA   r�  rE   rD   r‡   rF   )rG   s   "r4   rH   rH   >  s   € ÷ ?ñ ? 3ð ?¨4ñ ?r>   c                ó´   € T ;'       g    RP                  4       pV'       d   \        V4      \        8”  d   R# \        \        P                  VRR 4      4      # )zeWhether ``text`` is a short reply ENDING on an announced next action (stall-guard re-prompt trigger).rK   FNi`ÿÿÿ)rM   rx   Ú#_TRAILING_CONTINUE_INTENT_MAX_CHARSr‡   Ú_TRAILING_CONTINUE_INTENT_RErH  ©r�  rÛ  s   & r4   Útrailing_continue_intentr‰  >  sE   € à	�ˆ�×ÑÓ€Aß”�A“Ô<Ô<ÙÜÔ,×3Ñ3°A°d°e°HÓ=Ó>Ð>r>   a  (?:^|[.!?:\u3002\uff01\uff1f\u2014\u2013\n]\s*|\u2026\s*)(?:let(?:['\u2019]s| me)\b|i(?:['\u2019]ll| will| need to| should| am going to|['\u2019]m going to)\b|next[,:]? i\b|now i(?:['\u2019]ll| will| need to)\b|first[,:]? i(?:['\u2019]ll| will| need to)\b|\u0e08\u0e30\u0e43\u0e2b\u0e49\u0e1c\u0e21|\u0e1c\u0e21\u0e08\u0e30|\u0e15\u0e48\u0e2d\u0e44\u0e1b(?:\u0e08\u0e30|\u0e1c\u0e21\u0e08\u0e30)|\u0e02\u0e2d(?:\u0e40\u0e23\u0e34\u0e48\u0e21|\u0e25\u0e2d\u0e07|\u0e15\u0e23\u0e27\u0e08|\u0e41\u0e01\u0e49|\u0e2a\u0e48\u0e07|\u0e17\u0e33|\u0e14\u0e39)|\u0e08\u0e30(?:\u0e40\u0e23\u0e34\u0e48\u0e21|\u0e25\u0e2d\u0e07|\u0e15\u0e23\u0e27\u0e08|\u0e41\u0e01\u0e49|\u0e2a\u0e48\u0e07|\u0e17\u0e33|\u0e14\u0e39|\u0e23\u0e31\u0e19|\u0e22\u0e34\u0e07))[^.!?\n\u3002\uff01\uff1f]{0,160}(?:[.:\u2026]+)?\s*$c               ó    € V ^8„  d   QhRRRR/# r„  rF   )rG   s   "r4   rH   rH   `  s   € ÷ 	Cñ 	C¨cð 	C°dñ 	Cr>   c                óŒ   € T ;'       g    RP                  4       pV'       g   R# \        \        P                  VRR 4      4      # )zÛWhether promoted reasoning ENDS on a first-person plan to act (stall, not an answer).

No overall length cap: the reasoning block of a stalled model is often 300-1600 chars of
planning monologue; only the tail decides.
rK   FNiÿÿÿ)rM   r‡   Ú _PROMOTED_REASONING_PLAN_TAIL_RErH  rˆ  s   & r4   Ú#promoted_reasoning_announces_actionr�  `  s;   € ð 
�ˆ�×ÑÓ€AßÙÜÔ0×7Ñ7¸¸$¸%¸ÓAÓBÐBr>   c               ó   € V ^8„  d   QhRR/# r°  rF   )rG   s   "r4   rH   rH   p  s   € ÷ Jñ J¨3ñ Jr>   c                ó   a€ \        V RR4      pVRJ g0   \        V\        4      '       d   VP                  4       \        9   d   R# VRJ g0   \        V\        4      '       d   VP                  4       \
        9   d   R# \        V\        4      '       di   V P                  ;'       g    RP                  4       o\        ;QJ d    V3R lV 4       F  '       g   K   RM	  RM! V3R lV 4       4      '       d   R# R# V P                  R	8X  d   R
# R# )a  Intent-ack continuation mode: ``"off"``, ``"codex_only"`` (workspace acks on codex_responses)
or ``"all"``. Mirrors ``agent.tool_use_enforcement``: ``"auto"`` -> codex_only; true-ish -> all;
false-ish -> off; ``list`` -> all when a substring matches the active model name, else off.Ú_intent_ack_continuationÚautoTÚallFr	  rK   c              3  óz   <"  € T F0  p\        V\        4      '       g   K  VP                  4       S9   x € K2  	  R # 5irè   )r_   rE   r�  )r2   ré   r€  s   & €r4   r5   Ú/intent_ack_continuation_mode.<locals>.<genexpr>{  s*   øé € ÐY¹d¸ÄjÐQRÔTW×FXÔ4˜AŸG™G›I¨Ö4»dùs   ƒ; ;rÞ  Ú
codex_only)
rÑ   r_   rE   r�  Ú_INTENT_ACK_ONÚ_INTENT_ACK_OFFr¦   rö  r  r¹  )r”   Úmoder€  s   & @r4   Úintent_ack_continuation_moder™  p  sÄ   ø€ ô �5Ð4°fÓ=€DØˆtƒ|œ
 4¬×-Ò-°$·*±*³,Ä.Ô2PÙØˆuƒ}œ D¬#×.Ò.°4·:±:³<Ä?Ô3RÙÜ�$œ×ÒØ—{‘{×(Ð( b×/Ñ/Ó1ˆß›ÔY¹dÓYŸŸšÔY¹dÓY×YÒYˆuÐdÐ_dÐdà Ÿ>™>Ð->Ô>ˆ<ÐIÀEÐIr>   c               ó$   € V ^8„  d   QhRRRRRR/# )rA   Ú
source_msgr`   Úapi_msgrD   r›   rF   )rG   s   "r4   rH   rH   €  s&   € ÷ Zñ Z°dð ZÀTð ZÈdñ Zr>   c                óB   € ^ RI Hp V! W.V P                  4       O5!   R# )zƒForward reasoning fields onto an API replay message; policy lives in ``agent.message_sanitization.apply_reasoning_content_policy``.)Úapply_reasoning_content_policyN)Úagent.message_sanitizationrž  Ú_reasoning_replay_route)r”   r›  rœ  rž  s   &&& r4   Úcopy_reasoning_content_for_apir¡  €  s   € åIÙ" :ÐY¸×9VÑ9VÓ9XÖYr>   c               ó    € V ^8„  d   QhRRRR/# )rA   Úapi_messagesr¦   rD   rp   rF   )rG   s   "r4   rH   rH   †  s   € ÷ Rñ R¸Tð RÀcñ Rr>   c                ó>   € ^ RI Hp V! V.V P                  4       O5!  # )uD  Reconcile assistant turns' reasoning keys with the CURRENT route after a fallback switch or
a recorded field rejection: ``api_messages`` is shaped for the primary; must-echo providers
(DeepSeek/Kimi/MiMo) 400 without the pad, strict ones (Mistral, Cerebras, Groq) 400/422
with any reasoning key. Idempotent; returns the number of assistant turns changed.

* Switching TO a strict provider that rejects the field (Mistral, Cerebras, Groq, SambaNova, â€¦):
assistant turns built under a reasoning primary carry a ``reasoning_content`` pad (often a single space
``" "``), and the strict provider rejects it with HTTP 400/422 ("Extra inputs are not permitted"). This
is the exact cross-provider fallback bug from #45655 â€” a DeepSeek primary pads history with ``" "``, the
request falls back to Mistral, and Mistral 422s on the stale pad.
)Úreapply_reasoning_echo)rŸ  r¥  r   )r”   r£  r¥  s   && r4   Ú#reapply_reasoning_echo_for_providerr¦  †  s!   € õ BÙ! ,ÐQ°×1NÑ1NÓ1PÓQÐQr>   c               ó   € V ^8„  d   QhRR/# ©rA   r©  r   rF   )rG   s   "r4   rH   rH   –  s   € ÷ ñ ¨cñ r>   c              #  óì  "  € \        4       p \        V RR4      .pT\        \        V RR4      ;'       g    / P                  4       4      ,          pV F‰  pVf   K	  \        VRR4      pVf   \        VRR4      e   TpVf   K1  \	        V4      V9  g   KC  VP                  \	        V4      4       \        V4      P                  R8X  d   \	        V4      MRpWE3x € K‹  	  R#   \         d     R# i ; i5i)u¥  Yield ``(pool, owner)`` pairs reachable from an httpx client, including mounted transports:
keepalive and proxy configs put live connections on ``client._mounts``, which a
``_transport``-only walk misses.

``owner`` is ``None`` for a pool this client owns outright, or the ``_SharedTransport`` view
id when the pool is process-shared with other clients
(``process_bootstrap.build_keepalive_http_client``). Callers must then touch only the
in-flight requests stamped with that owner.

Walking the default transport alone makes ``force_close_tcp_sockets`` return 0 while a stream is still
mid-recv â€” the interrupt logs success and the provider keeps burning the slot (#72975).
Ú
_transportNÚ_mountsÚ_poolÚ_connectionsÚ_SharedTransport)	r>  rÑ   r¦   Úvaluesr}  r?  rŸ   r¼   r¡  )r©  Ú
seen_poolsÚ
transportsÚ	transportr¢  Úowners   &     r4   Ú_iter_httpx_pools_with_ownerr´  –  sâ   é € ô ›5€JðÜ˜k¨<¸Ó>Ð?ˆ
Ø”dœG K°¸DÓA×GÐGÀR×OÑOÓQÓRÕRˆ
Û#ˆIØÒ Ùô ˜9 g¨tÓ4ˆDØŠ|¤¨	°>À4Ó HÒ TØ �ØÔ¤B t£H°JÖ$>Ø—‘œr $›xÔ(Ü)-¨i«×)AÑ)AÐEWÔ)Wœ˜9œÐ]a�Ø�kÔ!ó $øô ô Úðüs6   ‚C4ŽA1C" ÂC" ÂA
C" Ã C4Ã"C1Ã-C4Ã0C1Ã1C4c               ó   € V ^8„  d   QhRR/# r¨  rF   )rG   s   "r4   rH   rH   ·  s   € ÷ ñ ¨#ñ r>   c              #  ó>   "  € \        V 4       F	  w  rVx € K  	  R# 5i)z;Yield httpcore pool objects reachable from an httpx client.N)r´  )r©  r¢  Ú_owners   &  r4   Ú_iter_httpx_pool_objectsr¸  ·  s   é € ä4°[ÖA‰ˆØŒ
ó Bùs   ‚c               ó   € V ^8„  d   QhRR/# )rA   Úconnr   rF   )rG   s   "r4   rH   rH   ½  s   € ÷ "ñ " ñ "r>   c              #  ó  "  € \        4       pV .pV'       ds   VP                  4       pVe   \        V4      V9   d   K.  VP                  \        V4      4       Vx € R F&  p\	        W4R4      pVf   K  VP                  V4       K(  	  Kz  R# 5i)uÕ   Walk nested wrappers: proxy tunnels (``_connection``) plus httpx/httpcore
stream envelopes (``_stream``/``_httpcore_stream``: BoundSyncStream â†’
ResponseStream â†’ connection byte stream â†’ HTTP11/2 connection).N)Ú_connectionÚ_streamÚ_httpcore_stream)r>  r¢   r}  r?  rÑ   r{   )rº  ÚseenÚstackÚobjÚattrÚnxts   &     r4   Ú_connection_candidatesrÄ  ½  sw   é € ô “U€DØˆF€Eß
Ø�i‰i‹kˆØŠ;œ"˜S›' Tœ/ÙØ�‰”�C“ÔØŠ	ÛBˆDÜ˜# TÓ*ˆCØŒØ—‘˜SÖ!ó Cñ ùs   ‚B˜ABÁ3Bc               ó   € V ^8„  d   QhRR/# )rA   r©   r   rF   )rG   s   "r4   rH   rH   Ï  s   € ÷ Hñ H cñ Hr>   c                óŠ   € \        V RR4      ;'       g    \        V RR4      pVe   \        V4      MRpVe   V# \        V 4      # )zTRaw socket behind a connection/stream wrapper yielded by ``_connection_candidates``.Ú_network_streamNr½  )rÑ   Ú_socket_from_stream)r©   ÚstreamÚsocks   &  r4   Ú_socket_from_candidaterË  Ï  sK   € ä�YÐ 1°4Ó8×_Ð_¼GÀIÈyÐZ^Ó<_€FØ*0Ò*<Ô˜vÔ&À$€DØÒ#ˆ4ÐGÔ)<¸YÓ)GÐGr>   c               ó   € V ^8„  d   QhRR/# )rA   rÒ  r   rF   )rG   s   "r4   rH   rH   Ö  s   € ÷ ñ  Cñ r>   c                ó  € \        V RR4      ;'       g    / p\        V\        4      '       d   VP                  R4      MRpV\        V RR4      3 F0  pVf   K	  \	        V4       F  p\        V4      pVf   K  Vu u # 	  K2  	  R# )z£Raw socket behind an httpx response's network stream (``extensions["network_stream"]``
first, then ``response.stream``), or None. Callers own their error handling.Ú
extensionsNÚnetwork_streamrÉ  )rÑ   r_   r`   rL   rÄ  rË  )rÒ  ÚextsÚdirectro   r©   rÊ  s   &     r4   Ú_socket_from_responserÒ  Ö  s€   € ô �8˜\¨4Ó0×6Ð6°B€DÜ+5°d¼D×+AÒ+AˆT�X‰XÐ&Ô'Àt€FØœ' (¨H°dÓ;Ó<ˆØŠ=ÙÜ/°Ö6ˆIÜ)¨)Ó4ˆDØÔØ”ó 7ñ =ñ r>   c               ó   € V ^8„  d   QhRR/# )rA   rÉ  r   rF   )rG   s   "r4   rH   rH   å  s   € ÷ ñ  ñ r>   c           	     ód  € \        V RR4      pVfY   \        \        V RR4      4      '       d=   \        P                  ! \        4      ;_uu_ 4        V P                  R4      pRRR4       Vf   \        \        V RR4      RR4      pVf€   \        \        \        V RR4      RR4      4      '       dY   \        P                  ! \        4      ;_uu_ 4        ^ RIHp V P                  P                  VP                  4      pRRR4       V# V#   + '       g   i     L±; i  + '       g   i     T# ; i)	zIRaw socket behind an httpcore network stream (several backends), or None.Ú_sockNÚget_extra_infoÚsocketrÉ  r½  rï   )ÚSocketAttribute)rÑ   Úcallabler¿   rÀ   r¡  rÖ  Ú	anyio.abcrØ  r½  rï   Ú
raw_socket)rÉ  rÊ  rØ  s   &  r4   rÈ  rÈ  å  sä   € ä�6˜7 DÓ)€DØ‚|œ¤¨Ð1AÀ4Ó!H×IÒIÜ× Ò ¤×+Õ+Ø×(Ñ(¨Ó2ˆD÷ ,à‚|Ü”w˜v x°Ó6¸ÀÓFˆØ‚|œ¤¬°¸ÀDÓ)IÈ7ÐTXÓ!Y×ZÒZä× Ò ¤×+Õ+Ý1Ø—>‘>×'Ñ'¨×(BÑ(BÓCˆD÷ ,ð €Kˆ4€K÷ ,×+ú÷ ,Ö+ð €Kús   ÁDÃ,DÄD	ÄD/	c               ó   € V ^8„  d   QhRR/# )rA   r.  r   rF   )rG   s   "r4   rH   rH   õ  s   € ÷ %ñ %˜sñ %r>   c           	   #  ó  "  €  \        V RR4      p\        \        Vf   T MT4      4      pT'       g   R# ^ RIHp \        4       pT EF$  w  rV\        TRR4      pTf   \        TRR4      pTe   . M\        T;'       g    . 4      p\        \        TRR4      ;'       g    . 4       Fe  p	Te;   \        \        T	RR4      RR4      ;'       g    / p
T
P                  T4      T8w  d   KA  \        T	R	R4      pTf   KT  TP                  T4       Kg  	  T FV  p\        T4       FD  p\        T4      pTf   K  \        T4      T9  g   K&  TP                  \        T4      4       Tx € KF  	  KX  	  EK'  	  R#   \         d     R# i ; i5i)
a%  Yield raw sockets reachable from an OpenAI/httpx client pool. Defensive over private
httpcore internals (``conn._connection``, proxy tunnel wrappers) that vary by release; also
walks mount transports and in-flight ``PoolRequest.connection`` objects (``_connections``
is empty during checkout).Ú_clientN)ÚHERMES_TRANSPORT_OWNER_EXTr­  r¬  Ú	_requestsrà  rÎ  Ú
connection)rÑ   r¦   r´  r¡  Úagent.process_bootstraprß  r>  rL   r{   rÄ  rË  r}  r?  )r.  r©  Úpoolsrß  r¿  r¢  r³  Ú	raw_connsÚconnectionsÚpool_reqrÐ  rº  r©   rÊ  s   &             r4   Ú_iter_pool_socketsrç  õ  sf  é € ð
ä˜f i°Ó6ˆÜÔ1¸KÒ<O±&ÐU`ÓaÓbˆ÷ ÙÝBÜ“U€DÜ‰ˆä˜D .°$Ó7ˆ	ØÒÜ  g¨tÓ4ˆIð "Ò-‘b´4¸	¿¸ÀRÓ3HˆÜœW T¨;¸Ó=×CÐCÀÖDˆHØÒ Üœw x°¸DÓAÀ<ÐQUÓV×\Ð\ÐZ\�Ø—8‘8Ð6Ó7¸5Ô@ÙÜ˜8 \°4Ó8ˆDØÔØ×"Ñ" 4Ö(ñ Eó  ˆDÜ3°DÖ9�	Ü-¨iÓ8�ØÔ#¬¨4«¸Ö(<Ø—H‘HœR ›XÔ&Ø”Jó	 :ô  ó# øô ô ÚðüsQ   ‚F„'E2 «F³AFÁ?FÂ,FÃ)FÃ:4FÄ3FÅ-FÅ2FÅ=FÆ FÆFc               ó$   € V ^8„  d   QhRRRRRR/# )rA   ÚcontextrC   Úretry_afterr   rD   r›   rF   )rG   s   "r4   rH   rH     s!   € ÷ 4ñ 4¨ð 4Àcð 4Èdñ 4r>   c                óx   € R V 9   d   R# \        V4      pVe"   \        P                  ! 4       V,           V R &   R# R# )Úreset_atN)r   rÒ   )ré  rê  rl  s   && r4   Ú_set_reset_from_retry_afterrí    s7   € Ø�WÔÙÜ'¨Ó4€GØÒÜ"Ÿiši›k¨GÕ3ˆ�
Óñ r>   z(\d+(?:\.\d+)?)(ms|h|m|s)Úhg      ¬@r•   g      N@r€  g      ð?Úmsgü©ñÒMbP?c               ó    € V ^8„  d   QhRRRR/# )rA   r�  rE   rD   zOptional[float]rF   )rG   s   "r4   rH   rH   1  s   € ÷ Gñ G 3ð G¨?ñ Gr>   c                ó(  € V P                  4       P                  4       pV'       g   R #  \        V4      #   \         d     Mi ; i\        P                  T4      pT'       d   RP                  R T 4       4      T8w  d   R # \        R T 4       4      # )NrK   c              3  ó6   "  € T F  w  rW,           x € K  	  R # 5irè   rF   ©r2   rŽ  Úus   &  r4   r5   Ú+_duration_string_seconds.<locals>.<genexpr>:  s   é € Ð4©e¡d a˜AŸEšE«eùs   ‚c              3  ó`   "  € T F$  w  r\        V4      \        V,          ,          x € K&  	  R # 5irè   )r”  Ú_DURATION_UNIT_SECONDSró  s   &  r4   r5   rõ  <  s$   é € ÐFÁ¹¸Œu�Q‹xÔ0°Õ3×3Ò3Ãùs   ‚,.)rM   r�  r”  r  Ú_DURATION_COMPONENT_RErÊ  r“   r‡  )r�  r  rÃ  s   &  r4   Ú_duration_string_secondsrù  1  sz   € Ø
�*‰*‹,×
Ñ
Ó
€CßÙðÜ�S‹zÐøÜô Ùðúä"×*Ñ*¨3Ó/€Eß�B—G‘GÑ4©eÓ4Ó4¸Ô;ÙÜÑFÁÓFÓFÐFs   ª
5 µAÁAc               ó$   € V ^8„  d   QhRRRRRR/# )rA   ré  rC   rå  r   rD   r›   rF   )rG   s   "r4   rH   rH   ?  s!   € ÷ ñ ¨Nð ÀSð ÈTñ r>   c                ót  € \          F­  pVP                  V4      p\        V\        4      '       d   VP	                  4       '       g   KB  \        V4      pVf.   \        V4      pVf   R MV\        P                  ! 4       ,
          pVf   K„  V^ 8”  g   K�  \        P                  ! 4       V,           V R&    R # 	  R # )Nrì  )Ú_VENDOR_RESET_HEADERSrL   r_   rE   rM   rù  r   rÒ   )ré  rå  r3   r‹   rl  Úabsolutes   &&    r4   Ú_set_reset_from_vendor_headersrþ  ?  sˆ   € ß%ˆØ—‘˜DÓ!ˆÜ˜%¤×%Ò%¨U¯[©[¯]ª]ÙÜ*¨5Ó1ˆØŠ?Ü0°Ó7ˆHØ&Ò.‘d°H¼t¿yºy»{Õ4JˆGØÔ 7¨Q¦;Ü"&§)¢)£+°Õ"7ˆG�JÑÚó &r>   c               ó    € V ^8„  d   QhRRRR/# rÐ  rF   )rG   s   "r4   rH   rH   M  s   € ÷ $ñ $ Yð $°>ñ $r>   c                ó¼  a	€ / p\        V RR4      p\        V\        4      '       d9   \        VP                  R4      \        4      '       d   VP                  R4      MTMRo	\        S	\        4      '       Ed¾   S	P                  R4      ;'       g+    S	P                  R4      ;'       g    S	P                  R4      p\        V\        4      '       d*   VP                  4       '       d   VP                  4       VR&   S	P                  R4      ;'       g    S	P                  R4      pV'       g7   \        S	P                  R4      \        4      '       d   S	P                  R4      p\        V\        4      '       d*   VP                  4       '       d   VP                  4       VR&   \        V	3R	 lR 4       R4      pVe   WQR
&   MZ\        S	P                  R4      \        \        34      '       d0   \        P                  ! 4       \        S	R,          4      ,           VR
&   \        VS	P                  R4      4       \        \        V RR4      RR4      pV'       dB   \        W4       VP                  R4      pV'       d   R
V9  d   WqR
&   R
V9  d   \        W4       RV9  dC   \	        V 4      P                  4       '       d$   \	        V 4      P                  4       R,          VR&   R
V9  dw   \        VP                  R4      ;'       g    R\        4      '       dH   \        VP                  R4      ;'       g    R4      pVe    \        P                  ! 4       V,           VR
&   V# )z;Extract structured rate-limit details from provider errors.r×  Nr½  r¼  rŸ   r»  r  Úerror_descriptionc              3  óv   <"  € T F.  pSP                  V4      R9  g   K  SP                  V4      x € K0  	  R # 5i)N>   NrK   r  )r2   r  r‚   s   & €r4   r5   Ú,extract_api_error_context.<locals>.<genexpr>\  s0   øé € ÐlÑ.G¨È7Ï;É;ÐWXË>ÐakÑKk”n�g—k‘k !—n�nÓ.Gùs   ƒ9 9rì  Úresets_in_secondsrê  rÒ  rå  zx-ratelimit-reset:Niô  NrK   )Ú	resets_atrì  )rÑ   r_   r`   rL   rE   rM   rà  rp   r”  rÒ   rí  rþ  r    )
r½  ré  r×  r»  r  Úresetrå  Úratelimit_resetÚdelayr‚   s
   &        @r4   Úextract_api_error_contextr	  M  sv  ø€ à €GÜ�5˜& $Ó'€DÜV`ÐaeÔgk×VlÒVl¤J¨t¯x©x¸Ó/@Ä$×$GÒ$Gˆt�x‰x˜Ô ÉTÐrv€GÜ�'œ4× Ó Ø—‘˜VÓ$×SÐS¨¯©°FÓ(;×SÐS¸w¿{¹{È7Ó?SˆÜ�fœc×"Ò" v§|¡|§~¢~Ø &§¡£ˆG�HÑØ—+‘+˜iÓ(×LÐL¨G¯K©KÐ8KÓ,Lˆßœ: g§k¡k°'Ó&:¼C×@Ò@à—k‘k 'Ó*ˆGÜ�gœs×#Ò#¨¯©¯ªØ!(§¡£ˆG�IÑÜÔlÑ.GÓlÐnrÓsˆØÒØ"'�JÒÜ˜Ÿ™Ð$7Ó8¼3Ä¸,×GÒGä"&§)¢)£+´°gÐ>QÕ6RÓ0SÕ"SˆG�JÑÜ# G¨W¯[©[¸Ó-GÔHÜ”g˜e Z°Ó6¸	À4ÓH€GßÜ# GÔ5Ø!Ÿ+™+Ð&9Ó:ˆß˜z°Ô8Ø"1�JÑØ˜WÔ$Ü*¨7Ô<Ø˜Ô¤C¨£J×$4Ñ$4×$6Ò$6Ü  ›Z×-Ñ-Ó/°Õ5ˆ�	ÑØ˜Ô ¤Z°·±¸IÓ0F×0LÐ0LÈ"Ìc×%RÒ%RÜ(¨¯©°YÓ)?×)EÐ)EÀ2ÓFˆØÒÜ"&§)¢)£+°Õ"5ˆG�JÑØ€Nr>   c               ó    € V ^8„  d   QhRRRR/# )rA   Ú
steer_textrE   rD   r›   rF   )rG   s   "r4   rH   rH   t  s   € ÷ -ñ -¨cð -°dñ -r>   c                ó"   € ^ RI Hp V! W4       R# )z]Put drained steer text back so the caller's fallback delivers it as a next-turn user message.)Úrequeue_drained_steerN)Úagent.interrupt_controlr  )r”   r  r  s   && r4   Ú_requeue_pending_steerr  t  s   € å=Ù˜%Ö,r>   c               ó$   € V ^8„  d   QhRRRRRR/# )rA   rm   r¦   Únum_tool_msgsrp   rD   r›   rF   )rG   s   "r4   rH   rH   z  s"   € ÷ &ñ &¸ð &Ècð &ÐVZñ &r>   c                óø  a€ V^ 8:  g	   S'       g   R# V P                  4       pV'       g   R# \        \        S4      ^,
          \        \        S4      V,
          ^,
          R4      R4      p\	        V3R lV 4       R4      pVf   \        W4       R# SP                  \        V4      4       \        4       P                  P                  R\        V4      VR,          \        V4      ^x8”  d   RMR,           4       R# )uÅ  Persist any pending /steer text as a standalone user message.

Called at the end of a tool-call batch, before the next API call.

The steer is emitted as a NEW ``role:"user"`` message appended after the
last tool result (marker text included), so:

- the model still sees the self-describing out-of-band marker (same text,
  same provenance semantics);
- message-role alternation stays legal â€” ``assistant(tool_calls) â†’ tool â†’
  user`` is the documented "user jumped in mid-run" pattern that
  ``repair_message_sequence`` deliberately keeps;
- the appended dict carries no ``_DB_PERSISTED_MARKER`` yet, so the next
  ``_flush_messages_to_session_db`` writes it to the session store â€” the
  steer text finally becomes part of the durable transcript instead of
  being smeared onto an already-persisted tool row that append-only
  persistence never rewrites (replayed histories then diverge from the
  live request bytes and break the provider prompt cache).
Nc              3  ó²   <"  € T FL  p\        SV,          \        4      '       g   K"  SV,          P                  R 4      R8X  g   KA  SV,          x € KN  	  R# 5ir.  r$  )r2   r}   rm   s   & €r4   r5   Ú6apply_pending_steer_to_tool_results.<locals>.<genexpr>•  sC   øé € Ðt© 1´
¸8ÀA½;Ì×0M”;ÐRZÐ[\ÕR]×RaÑRaÐbhÓRiÐmsÑRs”;�8˜A—;’;«ùs   ƒA§AÁAzMDelivered /steer to agent after tool batch (%d chars) as new user message: %s:Néx   Nz...rK   r.  )Ú_drain_pending_steerr”  rx   Úmaxrà  r  r{   r   r=   rd   rÇ  )r”   rm   r  r  Útailr›  s   &f&   r4   Ú#apply_pending_steer_to_tool_resultsr  z  sÃ   ø€ ð( ˜Ô§ÙØ×+Ñ+Ó-€JßÙä”�X“ Õ"¤C¬¨H«¸Õ(EÈÕ(IÈ2Ó$NÐPRÓS€DÜÔt©ÓtÐvzÓ{€FØ‚~ô 	˜uÔ1ÙØ‡O�O”N :Ó.Ô/ÜƒE‡L�L×ÑØWÔY\Ð]gÓYhØ�4Õ¤S¨£_°sÔ%:™EÀÕCör>   c               ó    € V ^8„  d   QhRRRR/# )rA   rÊ  r   rD   r›   rF   )rG   s   "r4   rH   rH   £  s   € ÷ ñ ˜3ð  4ñ r>   c                ó2  € ^ RI p \        V RR4      p\        V4      '       d4   \        P                  ! \
        4      ;_uu_ 4        V! ^ 4       RRR4       V P                  VP                  4       R#   + '       g   i     L-; i  \
         d     R# i ; i)aR  ``shutdown(SHUT_RDWR)`` WITHOUT closing the FD. ``close()`` from a non-owner thread is
unsafe: the SSL BIO caches the raw FD, the kernel recycles it, and a flushed TLS record lands
in the wrong file (once clobbered a SQLite header). ``shutdown()`` is FD-safe from any thread.
Already shut down / not connected / FD invalid are all benign.NÚ
settimeout)r×  rÑ   rÙ  r¿   rÀ   ÚOSErrorÚshutdownÚ	SHUT_RDWR)rÊ  Ú_socketr  s   &  r4   Ú_shutdown_socketr!  £  sp   € ó
 ðä˜T <°Ó6ˆ
Ü�J×ÒÜ×$Ò$¤W×-Õ-Ù˜1”÷ .à�‰�g×'Ñ'Ö(÷ .×-ûô ô Úðús*   †A B Á	A4Á#B Á4B	Á?B ÂBÂBc               ó    € V ^8„  d   QhRRRR/# )rA   r.  r   rD   rp   rF   )rG   s   "r4   rH   rH   ´  s   € ÷ 
ñ 
 Cð 
¨Cñ 
r>   c                óÒ   € ^ p \        V 4       F  p\        V4       V^,          pK  	  V#   \         d0   p\        4       P                  P                  RT4        Rp?T# Rp?ii ; i)z|Abort in-flight TCP I/O on every pool socket via ``_shutdown_socket``. Returns the count
(logged as ``tcp_force_closed=N``).z'Force-close TCP sockets sweep error: %sN)rç  r!  r¡  r=   rd   ra  )r.  Úshutdown_countrÊ  r†  s   &   r4   Úforce_close_tcp_socketsr%  ´  sl   € ð €NðKÜ& vÖ.ˆDÜ˜TÔ"Ø˜aÕŠNñ /ð
 Ðøô ô KÜ‹�‰×ÑÐDÀc×JÐJØÐûðKús   „&, ¬A&·$A!Á!A&)rh   rY   Útool_resultÚfunction_callÚfunction_calls>   ÚmemoryÚclarifyÚgui_tourÚ	setup_mcpÚ	todo_listÚdelegate_taskÚdrive_previewÚread_terminalÚmanage_catalogÚsession_searchÚdesktop_previewÚannotate_previewÚread_window_belowÚmanage_connections)ræ  Úgousagelimit)zusage limit reachedzusage limit has been reached>   Ú	ReadErrorÚPoolTimeoutÚReadTimeoutÚConnectErrorÚConnectTimeoutÚAPITimeoutErrorÚAPIConnectionErrorÚRemoteProtocolError)r  Ú1hrè   )rö  r¿  r  rí  r¹  rž  r.  r,  r*  r+  r-  r   r  r}  r�  r   Ú_codex_reasoning_replay_enabledÚ _codex_reasoning_replay_rejected)rK   rK   rK   N)NNFFNF)z	look intozlook atÚinspectÚscanÚcheckÚanalyzÚreviewÚexploreÚreadÚopenÚrunÚtestÚfixra  rH  r“  Úwalkthroughzreport backÚ	summarize)Ú	directoryzcurrent directoryzcurrent dirÚcwdÚrepoÚ
repositoryÚcodebaseÚprojectÚfolderÚ
filesystemz	file treeÚfilesÚpath)T)Ú.Ú!r·   u   ã€‚u   ï¼�u   ï¼Ÿ>   ÚonÚyesÚtrueÚalways>   r  r	  r
  Únever)zx-ratelimit-reset-requestszx-ratelimit-reset-tokensz"anthropic-ratelimit-requests-resetz anthropic-ratelimit-tokens-reset)rç  r5  r  r'  r˜   r¡  rË  rc  rÿ  r	  rÎ  r%  ry  ro  r<  r  r  rx  rŸ  r·  r'  rÉ   r™  rõ  rU  )øÚ__conditional_annotations__Ú__doc__Ú
__future__r   r¿   rî  ra   rº   r-   Ú	threadingrÒ   r   Úpathlibr   Útypingr   r   r   r   r	   Úhermes_cli.timeoutsr
   rŸ  r   r   r   r   r   Úagent.message_metadatar   r   r   r   Úagent.prompt_builderr   r   Úagent.tool_dispatch_helpersr   r   Úagent.think_scrubberr   Úagent.trajectoryr   r  r   r   r   r   Úagent.error_classifierr   Úagent.retry_utilsr   r    r!   Úagent.turn_contextr"   Ú(agent.agent_runtime_helpers_placeholdersr#   Úagent.primary_runtime_snapshotr$   Úutilsr%   r&   r'   r(   r»   r¼   rd   rÉ  Ú_TOOL_CALL_TAG_NAMESr8   r¯  Ú_REASONING_BLOCK_PATTERNSÚ_TOOL_CALL_BLOCK_PATTERNSr.   r/   r0   Ú_NAMED_FUNCTION_BLOCK_PATTERNr“   Ú%_UNTERMINATED_REASONING_BLOCK_PATTERNÚ_ORPHAN_REASONING_TAG_PATTERNÚ_STRAY_TOOL_CALL_CLOSER_PATTERNÚ_UNTERMINATED_TOOL_CALL_PATTERNr=   r  Ú"AGENT_RUNTIME_POST_HOOK_TOOL_NAMESr‘   rO   rU   rk   rƒ   r˜   r¤   rª   r±   rÉ   rÊ   Ú__annotations__ÚLockrÓ   rÚ   rÜ   rä   r÷   r  r   r'  r/  r2  r:  rI  rT  rk  rt  rp  rx  r‰  r“  r–  r™  r£  rþ  rý  rÄ  r	  râ  rã  r°  rÂ  rÒ  rç  r  r  r/  r?  rU  rZ  ÚobjectrY  rc  rz  r€  r‡  rŒ  r—  r·  rL  rÉ  rÎ  rÙ  rÿ  r  r  r  r  r  r  r'  r<  rA  r@  r]  rp  r5  r–  r’  r¤  r²  rË  rÔ  r×  rØ  rÚ  rÞ  rí  rû  r  r  r   r&  r-  rõ  rG  ry  rŸ  r¹  rÌ  r¡  r½  r>  r¢  r£  r¨  rN  r®  rµ  rº  r¾  rÇ  rÑ  r×  ræ  rë  rî  rö  rù  r  r  r$  r'  rK  rL  rN  ro  r{  r|  r}  r~  r‚  r‡  r†  r‰  rŒ  r�  r–  r—  r™  r¡  r¦  r´  r¸  rÄ  rË  rÒ  rÈ  rç  rí  rø  r÷  rü  rù  rþ  r	  r  r  r!  r%  Ú__all__)ra  s   @r4   Ú<module>r€     s«  øðôõ #Û Û Û Û Û 	Û Û Ý Ý ß 3Õ 3Ý <÷õ ÷bó bç Cß [Ý 0Ý 8÷ó õ 2ß QÝ 5Ý 5Ý MÝ Jß ^Ó ^Ø	×	Ò	˜8Ó	$€ð Ð ÙdÐ à€
ß!˜Eñ "ÙP_ó"ŸE™Eñ "ÙP_ó"ó Ð ÷ "˜Eñ "á$ó"ŸE™Eñ "á$ó"ó Ð ð !#§
¢
ð,à-/¯Y©Y¸¿¹Õ-Fó!Ð ð
 )+¯
ª
Ø˜#Ÿ(™( ?Ó3Ð4°LÐAÀ2Ç9Á9ÈrÏ}É}ÕC\ó)Ð %ð !#§
¢
Øˆc�h‰h�Ó'Ð(¨Ð.°·±ó!Ð ð #%§*¢*ØˆZˆL˜˜CŸH™HÐ%9Ó:Ð;¸?ÐKÈRÏ]É]ó#Ð ð #%§*¢*Ø�z�l # c§h¡hÐ/CÓ&DÐ%Eð F<ð <ð ‡I�I�—‘Õó	#Ð òñ &/ó 0ó &Ð "ð
`ð õõPõ
/õ(õ6õ:-õõðMØ"ðMØ=AðMØ\`÷Mðf <>Ð Ð8Ó =Ø —~’~Ó'Ð õ'òT+õõMõ`3õB_õ(	oõ@õ?õõ4*õZ'õTMðb "Ð#;Ð=YØðÐ õ
%õ$õ.õ4ð4ØðØ!:ðØ<Yðà)ðà+Hðð $ðð &EñÐ õõ
/ð ˆ×	Ñ	  n×&?Ñ&?ÀÀn×FYÑFYØˆ×	Ñ	ðÐ ñ EÐ ÙUÐ õ'õ$#òL%!òPRð>{"à26ð{"ð /3ð{"ð PU÷{"õ|5õ"
õjõ*&õRñ ‹x€ð(ØJNð(à'+÷(òV.õ6Kõ%
õP,õ6!õH@ñH (ó )ó Ð ÷ #˜Uñ #áó#ŸU™Uñ #áó#ó Ð õ!1õHð 1ØTX÷1ðhkØ(,ðkØHLðkà"ðkà;?÷kñ  Ð õiõõFõ4÷rð rð&%à15ð&%àRVð&%ð +/÷&%õRoõbõõ04ðBoØ(,ðoØHLðoà"ðoà;?÷oõdõ@õ"Rõ"õ*tòn(ñ4Ð ñ ‹8€õõ(ò&8õREoõP*)òZ''õT.õD\õ0\õ @)òF#÷ Rð Rõj/+ðp Ð ØÐ Ø35Ð Ð0Ó 5Ø —~’~Ó'Ð ñ "%£Ð ˜3Ó &ð .0Ð ˜NÓ /õ
õõõõ&õ9õ

õ1õhõ0Uõ4;õ&õR%õPõ G6õTEõP.õb0ð —’Ð_Ó`€ñÐ ñÐ ÷[ñ [ðN !Ð ÙCÐ ñ 'Ð ÷Jò J÷$ð(  "Ÿzšzñ&à')§}¡}ó Ð ñ '*Ð #÷?ð* $&§:¢:ñ=ð ‡M�Mó
$Ð  ÷	Có 1€Û1€÷J÷ Z÷R÷ ÷B÷"÷$H÷÷÷ %÷P4ð ŸšÑ$@ÓAÐ Ù™v¡s©D±#±s¹DÁ%ÐHÐ ñÐ ÷G÷÷$÷N-÷&÷R÷"
ó‚r>   