+
    iHàj/o ã                  óÔ
  € 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
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 ^ RIHtHt ^ RIHtHt ^ RIHtHtHtH t  ^ R	I!H"t" ^ R
I#H$t$ ^ RI%H&t&H't' ^ RI(H)t) ^ RI*H+t+ ^ RI,H-t-H.t. ^ RI/H0t0 ^ RI1H2t2 ^ RI3H4t4 ^ RI5H6t6 ^ RI7H8t8 ^ RI9H:t:H;t;H<t<H=t= ^ RI>H?t?H@t@HAtAHBtCHDtDHEtE ^ RIFHGtGHHtHHItI ^ RIJHKtKHLtL ^ RIMHNtNHOtO ^ RIPHQtQHRtR ^ RISHTtT ^ RIUHVtVHWtWHXtXHYtY ]P´                  ! ][4      t\0 ERmt]RR0t^0 ERmt_Rt`RtaR tbR! tcR" R# ltdR$ te ! R% R&]f4      tgR' R( lthR) R* ltiR+ R, ltjR- R. ltkR/ R0 ltlR1R/R2 R3 lltmR4 R5 ltnR1R/R6 R7 lltoR8 R9 ltpR: R; ltqR1R/R< R= lltr]s! 0 ERm4      ttR> R? ltuR@ RA ltvRB RC ltwRD RE ltxRF RG ltyRH RI ltzRJ RK lt{RL RM lt|RN RO lt}RP RQ lt~RR RS ltRT RU lt€RV RW lt�RX RY lt‚RZtƒR[ R\ lt„R]R^R_R/R` Ra llt…Rb Rc lt†Rd Re lt‡Rf Rg ltˆRh Ri lt‰Rj Rk ltŠRl Rm lt‹Rn Ro ltŒRp Rq lt�Rr Rs ltŽRt Ru lt�Rv Rw lt�RxR/Ry Rz llt‘R{ R| lt’R} R~ lt“Rt”R€ R� lt•R‚ Rƒ lt– ! R„ R…4      t—R† R‡ lt˜ ! Rˆ R‰4      t™RŠtšRŠt›R‹ RŒ ltœ] ! R� RŽ4      4       t�R� R� ltžR‘ R’ ltŸR“ R” lt R• R– lt¡R— t¢R˜ t£R™ t¤Rš t¥R› t¦Rœ t§R� t¨ERRž RŸ llt©ERR  R¡ lltªR¢ t«R£ t¬R¤ R¥ lt­R¦ t®R§ R¨ lt¯R© Rª lt°R« R¬ lt±R­ R® lt²R¯ R° lt³/ ]EPh                  R±b]EPj                  R²b]EPl                  R³b]EPn                  R´b]EPp                  Rµb]EPr                  R¶b]EPt                  R·b]EPv                  R¸b]EPx                  R¹b]EPz                  Rºb]EP|                  R»b]EP~                  R¼b]EP€                  R½b]EP‚                  R¾b]EP„                  R¿b]EP†                  RÀb]EPˆ                  RÁb]EPŠ                  RÂ]EPŒ                  RÃ]EPŽ                  RÄ]EP�                  RÅ]EP’                  RÆ]EP”                  RÇ]EP–                  RÈ/C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ÙERRã Rä lltÚ]:0 ERm,          tÛRå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ó]á/tãRô Rõ ltäRö R÷ ltåRøRRùR^RúRRûR^/Rü ltæERtçRý Rþ ltè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 tïER ER ltðER tñ ! ER ER4      tò ! ER ER]+4      tóERR/ER ER lltô. EROtõR# (  a»  API-call helpers extracted from :class:`AIAgent`: non-streaming and streaming
request drivers, request kwargs builder, assistant-message materializer,
provider-fallback activator, max-iterations handler, per-turn resource cleanup.

Each function takes the parent ``AIAgent`` as ``agent``; AIAgent keeps thin
forwarders. Symbols tests patch on ``run_agent`` (``cleanup_vm`` /
``cleanup_browser``) are resolved through :func:`_ra` at call time.
)ÚannotationsN)Ú	dataclass)ÚSimpleNamespace)ÚAnyÚDictÚOptional)Úget_provider_request_timeoutÚget_provider_stale_timeout)ÚPARTIAL_STREAM_STUB_IDÚFINISH_REASON_LENGTH)ÚFailoverReasonÚ&PROVIDER_STREAM_EMPTY_FRAME_ERROR_CODEÚ#PROVIDER_STREAM_NON_JSON_ERROR_CODEÚ_extract_status_code)Ú!bypass_chat_sdk_request_transform)ÚEmptyStreamError)Ú_streams_llamacppÚstale_giveup)Ú"_chat_completion_capturing_headers)ÚStreamingWaitMonitor)Úis_router_timeout_shimÚrouter_timeout_shim_may_follow)Úeffective_request_overrides)Úsubstitute_api_content)Úis_native_gemini_base_url)Úis_local_endpoint)Úflatten_message_text)ÚPERSISTENCE_ONLY_MESSAGE_FIELDSÚappend_messageÚdata_use_requirementÚstamp_message_timestamp)Ú_sanitize_messages_surrogatesÚ_sanitize_surrogatesÚ_repair_tool_call_argumentsÚnormalize_finish_reasonÚsanitize_outbound_kwargsÚ strip_images_for_rejecting_model)Ú append_streamed_reasoning_detailÚseparate_glued_reasoning_blocksÚstreamed_reasoning_detail_text)Úprompt_progressÚwith_prompt_progress)ÚRunawayStreamWatchÚis_repetition_dominated)Úclaim_stream_writerÚstream_writer_is_current)Úis_persistent_env)Úbase_url_host_matchesÚbase_url_hostnameÚ	env_floatÚenv_intÚerrorÚerror_finishi   g      @ç      N@c                ó>   a a€ \         P                  ! 4       oV V3R l# )z=Bind a no-argument thread target to the caller's ContextVars.c                 ó&   <€ SP                  S 4      # ©N)Úrun©ÚcallbackÚcontexts   €€ÚB/home/ubuntu/.hermes/hermes-agent/agent/chat_completion_helpers.pyÚ<lambda>Ú(_context_thread_target.<locals>.<lambda>Q   s   ø€ �7—;‘;˜xÔ(ó    )ÚcontextvarsÚcopy_contextr<   s   f@r?   Ú_context_thread_targetrE   N   s   ù€ ä×&Ò&Ó(€GÝ(Ð(rB   c               ó    € V ^8„  d   QhRRRR/# )é   ÚlabelÚstrÚreturnÚNone© )Úformats   "r?   Ú__annotate__rN   T   s   € ÷ `ñ `°cð `¸dñ `rB   c               ó  €  ^ RI Hp VP                  RR7      pVe   VP                  4       '       g   R#  T P                  RR7       T P                  4       '       d   \        P                  RT4       R# R#   \         d     R# i ; i)u*  Bounded worker join before raising InterruptedError (#81521).

Raising immediately lets turn teardown race a still-open Relay LLM scope and
corrupt the LIFO stack (CLI EIO / redraw storm). Only joins when Relay managed
execution is live â€” otherwise the join would just delay interrupt detection.
)Úrelay_runtimeF)ÚcreateNç       @©Útimeoutz€%s worker still alive after interrupt abort (2.0s join timeout); Relay teardown will best-effort drain orphaned scopes (#81521).)	ÚagentrP   Úget_runtimeÚmanaged_execution_enabledÚ	ExceptionÚjoinÚis_aliveÚloggerÚwarning)ÚworkerrH   rP   Úruntimes   &$  r?   Ú_join_worker_for_relay_teardownr_   T   s…   € ðÝ'Ø×+Ñ+°5Ð+Ó9ˆØŠ? '×"CÑ"C×"EÒ"EÙð #Fð ‡K�K˜€KÔØ‡�×ÒÜ�‰ð XØY^ö	`ñ øô ô Úðús   ‚1A9 Á9BÂBc                 ó   € ^ RI p V # )zQLazy ``run_agent`` reference so ``patch("run_agent.cleanup_vm")`` etc. intercept.N©Ú	run_agentra   s    r?   Ú_rarc   h   s   € ãØÐrB   c                  óF   a € ] tR t^ntRtRR/R V 3R llltR R ltRtV ;t# )	ÚProviderStreamErrorzKProvider encoded an API error as streaming content instead of an SDK error.ÚheadersNc               ó(   € V ^8„  d   QhRRRRRRRR/# )	rG   Ústatus_codeúOptional[int]ÚbodyÚdictÚraw_textrI   rf   r   rL   )rM   s   "r?   rN   Ú ProviderStreamError.__annotate__q   s)   € ÷ 1ñ 1 }ð 1¸Dð 1ÈCð 1ÐZ]ñ 1rB   c               	óœ   <€ Wn         W n        W0n        \        T;'       g    / R 7      V n        \
        SV `  V P                  4       4       R# ))rf   N)rh   rj   rl   r   ÚresponseÚsuperÚ__init__Ú_format_message)Úselfrh   rj   rl   rf   Ú	__class__s   &$$$$€r?   rq   ÚProviderStreamError.__init__q   s;   ø€ Ø&ÔØŒ	Ø ŒÜ'°·°¸2Ô>ˆŒÜ‰Ñ˜×-Ñ-Ó/Ö0rB   c               ó   € V ^8„  d   QhRR/# ©rG   rJ   rI   rL   )rM   s   "r?   rN   rm   x   s   € ÷ ñ  ñ rB   c                	óþ  € \        V P                  \        4      '       d   V P                  P                  R / 4      M/ p\        V\        4      '       g   / pR.pV P                  '       d   VP                  RV P                   24       VP                  R4      '       d"   VP                  \        VR,          4      4       RP                  V4      pVP                  R4      '       d   VRVR,           2,          pV# )r5   z'Provider stream returned an error eventzHTTP Úcodez - Úmessageú: )Ú
isinstancerj   rk   Úgetrh   ÚappendrI   rY   )rs   Ú	error_objÚpartsÚtexts   &   r?   rr   Ú#ProviderStreamError._format_messagex   sÇ   € Ü2<¸T¿Y¹YÌ×2MÒ2M�D—I‘I—M‘M '¨2Ô.ÐSUˆ	Ü˜)¤T×*Ò*ØˆIØ:Ð;ˆØ××ÐØ�L‰L˜5 ×!1Ñ!1Ð 2Ð3Ô4Ø�=‰=˜× Ò Ø�L‰Lœ˜Y vÕ.Ó/Ô0Ø�z‰z˜%Ó ˆØ�=‰=˜×#Ò#Ø�b˜ 9Õ-Ð.Ð/Õ/ˆDØˆrB   )rj   rl   ro   rh   )	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rq   rr   Ú__static_attributes__Ú__classcell__)rt   s   @r?   re   re   n   s"   ø† ÙUð1Ð`d÷ 1ò 1÷ó rB   re   c               ó    € V ^8„  d   QhRRRR/# )rG   Úvaluer   rJ   ri   rL   )rM   s   "r?   rN   rN   ‡   s   € ÷ 2ñ 2 3ð 2¨=ñ 2rB   c                ó  € \        V \        4      '       d   ^dT u;8:  d
   R8  d    V #  \        V \        4      '       g   R# \        P                  ! RV \        P
                  4      pV'       d   \        VP                  ^4      4      # R# )éd   éX  Nz (?:HTTP_STATUS/)?\b([1-5]\d\d)\b)r|   ÚintrI   ÚreÚsearchÚ
IGNORECASEÚgroup)r‹   Úmatchs   & r?   Ú_status_code_from_valuer•   ‡   sf   € Ü�%œ×Ò #¨Ö"4°Õ"4Øˆð #5ä�eœS×!Ò!ÙÜ�IŠIÐ9¸5Ä"Ç-Á-ÓP€Eß"'Œ3ˆu�{‰{˜1‹~ÓÐ1¨TÐ1rB   c               ó    € V ^8„  d   QhRRRR/# )rG   Úpayloadr   rJ   ri   rL   )rM   s   "r?   rN   rN   �   s   € ÷ ñ  sð ¨}ñ rB   c                ó|  a€ \        V \        4      '       g   R # R Uu. uF  qP                  V4      NK  	  ppV P                  R4      o\        S\        4      '       d   VP                  V3R lR 4       4       VP	                  V P                  R4      4       V F  p\        V4      pVf   K  Vu # 	  R # u upi )Nr5   c              3  óF   <"  € T F  pSP                  V4      x € K  	  R # 5ir:   ©r}   )Ú.0Úkr   s   & €r?   Ú	<genexpr>Ú,_status_code_from_payload.<locals>.<genexpr>—   s   øé € ÐeÑ4d¨q˜)Ÿ-™-¨×*Ð*Ó4dùs   ƒ!ry   )rh   ÚstatusÚhttp_status)rh   rŸ   r    ry   )r|   rk   r}   Úextendr~   r•   )r—   rœ   Ú
candidatesÚ	candidaterh   r   s   &    @r?   Ú_status_code_from_payloadr¤   �   s¡   ø€ Ü�gœt×$Ò$Ùá*RÓSÑ*R Q—+‘+˜a–.Ñ*R€JÐSØ—‘˜GÓ$€IÜ�)œT×"Ò"Ø×ÑÔeÑ4dÓeÔeØ×Ñ�g—k‘k &Ó)Ô*Ûˆ	Ü-¨iÓ8ˆØÔ"ØÒñ  ñ ùò Ts   žB9c               ó    € V ^8„  d   QhRRRR/# )rG   r�   rI   rJ   zOptional[dict]rL   )rM   s   "r?   rN   rN       s   € ÷ ñ  ð ¨ñ rB   c                óz  € T ;'       g    R P                  4       p\        P                  ! \        P                  \
        4      ;_uu_ 4        VP                  R4      '       d;   \        P                  ! V4      p\        V\        4      '       d   TMRuuRRR4       #  RRR4       R#   + '       g   i     R# ; i)Ú Ú{N)
ÚstripÚ
contextlibÚsuppressÚjsonÚJSONDecodeErrorÚ	TypeErrorÚ
startswithÚloadsr|   rk   )r�   ÚstrippedÚdecodeds   &  r?   Ú_json_object_from_textr³       s‚   € Ø—
�
˜×!Ñ!Ó#€HÜ	×	Ò	œT×1Ñ1´9×	=Õ	=Ø×Ñ˜s×#Ò#Ü—j’j Ó*ˆGÜ(¨´$×7Ò7‘7¸T÷ 
>Ò	=Ø#÷ 
>ñ ÷	 
>Ö	=ñ ús   ÁAB)Â)B:	c               ó    € V ^8„  d   QhRRRR/# )rG   r�   rI   rJ   z
list[dict]rL   )rM   s   "r?   rN   rN   ©   s   € ÷ .ñ . Sð .¨Zñ .rB   c                óÐ  aa€ . oRRR. R. R/ /oVV3R lpT ;'       g    RP                  4        EF*  pVP                  R4      pVR8X  d
   V! 4        K%  VP                  R	4      '       d0   SR,          P                  VR
,          P	                  4       4       Kk  VP                  R	4      w  rEpV'       g+   RSR,          VP	                  4       P                  4       &   K±  VP	                  4       P                  4       pVP                  R4      pVR8X  d   VP	                  4       SR&   Kü  VR8X  d   SR,          P                  V4       EK  VSR,          V&   EK-  	  V! 4        S# )z7Parse provider text that looks like Server-Sent Events.ÚeventNÚdataÚcommentsÚfieldsc                 óà  <€ \        SP                  4       4      '       d¿   \        SR ,          4      R U u. uF#  p V SR,          9   g   K  SR,          V ,          NK%  	  up ,           pSP                  RSR,          RRP	                  SR,          4      R \        SR ,          4      R\        SR,          4      R\        R \        \        V4       4       R4      /4       RRR. R . R/ /oR# u up i )	r¸   rh   r¹   r¶   r·   Ú
c              3  ó0   "  € T F  qf   K  Vx € K  	  R # 5ir:   rL   )r›   Úss   & r?   r�   ÚE_parse_provider_sse_events.<locals>._flush_current.<locals>.<genexpr>¼   s   é € ÐaÑ O˜1—Q’QÓ Oùó   ‚Œ
N)rŸ   rh   r    )	ÚanyÚvaluesÚlistr~   rY   rk   ÚnextÚmapr•   )ÚkeyÚstatus_candidatesÚcurrentÚeventss     €€r?   Ú_flush_currentÚ2_parse_provider_sse_events.<locals>._flush_current®   sê   ø€ äˆw�~‰~Ó× Ò Ü $ W¨ZÕ%8Ó 9áCó=áC�CØ˜' (Õ+Ñ+ô '�˜Õ! #×&Ð&ÙCñ=õ !Ðð
 �M‰MØ˜ Õ)Ø˜Ÿ	™	 '¨&¥/Ó2ØœD ¨Õ!4Ó5Øœ$˜w xÕ0Ó1ØœtÙa¤Ô$;Ð=NÔ OÓaÐcgó iðô ð ˜D &¨"¨j¸"¸hÈÐKŠùò=s   ¶C+ÁC+r§   ÚÚ::é   NNÚ )Ú
splitlinesÚrstripr¯   r~   r©   Ú	partitionÚlowerÚremoveprefix)	r�   rÉ   Úraw_lineÚlineÚfieldÚsepr‹   rÇ   rÈ   s	   &      @@r?   Ú_parse_provider_sse_eventsrØ   ©   s5  ù€ à€FØ˜˜f b¨*°b¸(ÀBÐG€GöLð$ —Z�Z˜R×+Ñ+×-ˆØ�‰˜tÓ$ˆØ�2Œ:ÙÔÙØ�?‰?˜3×ÒØ�JÕ×&Ñ& t¨B¥x§~¡~Ó'7Ô8Ùà ŸN™N¨3Ó/Ñˆ�EßØ79ˆG�HÕ˜eŸk™k›m×1Ñ1Ó3Ñ4ÙØ—‘“×#Ñ#Ó%ˆØ×"Ñ" 3Ó'ˆØ�GÔØ$Ÿ{™{›}ˆG�GÓØ�fŒ_Ø�F�O×"Ñ" 5×)à',ˆG�HÕ˜eÔ$ñ) .ñ, ÔØ€MrB   c               ó$   € V ^8„  d   QhRRRRRR/# )rG   r—   rk   rh   ri   rJ   rL   )rM   s   "r?   rN   rN   Ú   s!   € ÷ 'ñ ' $ð '°]ð 'Àtñ 'rB   c                óv  € \        V \        4      '       g   / p M'\        V P                  R4      \        4      '       d   V # V P                  R4      ;'       gB    V P                  R4      ;'       g)    V P                  R4      ;'       g    V'       d   RV 2MRpV P                  R4      ;'       g5    V P                  R4      ;'       g    V P                  R4      ;'       g    R	pR\        V4      /pV'       d   \        V4      VR&   R
 F&  pV P                  V4      '       g   K  W,          WE&   K(  	  RV/# )zDNormalize common provider error payloads to OpenAI-style body.error.r5   ry   Ú
error_codeÚtypeÚHTTP_Úprovider_stream_errorrz   Úerror_descriptionz(Provider stream returned an error event.)Ú
request_idÚparamrÜ   )r|   rk   r}   rI   )r—   rh   ry   rz   Únormalized_errorrÅ   s   &&    r?   Ú_provider_error_bodyrã   Ú   s&  € ä�gœt×$Ò$Ø‰Ü	�G—K‘K Ó(¬$×	/Ò	/ØˆØ�K‰K˜Ó÷ Sð S 7§;¡;¨|Ó#<÷ Sð SÀÇÁÈFÓ@S÷ Sð Sß)4�%˜�}Ñ%Ð:Qð 	à�{‰{˜9Ó%÷ =ð =¨¯©Ð5HÓ)I÷ =ð =ÈWÏ[É[ÐY`ÓMa÷ =ð =Ø<ð à!¤3 w£<Ð0ÐßÜ#& t£9Ð˜Ñ Û.ˆØ�;‰;�s×ÔØ$+¥LÐÓ!ñ /ð Ð%Ð&Ð&rB   ro   c               ó$   € V ^8„  d   QhRRRRRR/# )rG   r5   zjson.JSONDecodeErrorro   r   rJ   re   rL   )rM   s   "r?   rN   rN   í   s$   € ÷ %ñ %Ð9Mð %Øð%Ø0ñ%rB   c          
     óp  € ^ RI Hp \        \        V RR4      ;'       g    R4      P	                  4       pVe   \        VRR4      MRpV'       g"   \        R\        R\        RR/R4      RVR	7      # V! \        V4      R
R7      pVR\         p\        R\        R\        RT;'       g    R/R4      VVR	7      # )u¥  Preserve plain-text SSE data rejected inside the OpenAI SDK: on a non-JSON
``event: error`` the SDK raises from ``sse.json()`` before yielding a chunk,
but ``JSONDecodeError.doc`` still carries the provider's original message.

An EMPTY ``doc`` is the other case: the frame carried no payload at all
(``data:`` / ``event: ping`` / ``id:`` alone â€” legal SSE keepalives and no-ops),
which the SDK's ``json.loads`` rejects the same way. A gateway that is degrading
answers EVERY streaming request with such frames, so this is not the provider's
malformed payload and must not be reported as one: it gets its own code and
the stream helper recovers by retrying without streaming.©Úredact_sensitive_textÚdocr§   Nrf   ry   rz   zMProvider stream returned an empty SSE data frame (keepalive with no payload).©rh   rj   rl   rf   T)Úforcez+Provider stream returned non-JSON SSE data.)Úagent.redactrç   rI   Úgetattrr©   re   rã   r   r"   Ú!_PROVIDER_STREAM_ERROR_TEXT_LIMITr   )r5   ro   rç   rl   rf   Ú	safe_texts   &$    r?   Ú-_provider_stream_error_from_json_decode_errorrï   í   s×   € õ 3Ü”7˜5 %¨Ó,×2Ð2°Ó3×9Ñ9Ó;€HØ4<Ò4HŒg�h 	¨4Ô0Èd€GßÜ"ØÜ%ØÔ?ØÐnðpàóð
 Øô	
ð 		
ñ &Ô&:¸8Ó&DÈDÔQ€IØÐ<Ô<Ð=€IÜØÜ!ØÔ8Ø˜9×UÐUÐ(UðWàó
ð
 Øô	ð 	rB   c               ó    € V ^8„  d   QhRRRR/# ©rG   ÚexcÚBaseExceptionrJ   ÚboolrL   )rM   s   "r?   rN   rN     s   € ÷ kñ k¨}ð kÀñ krB   c                óÎ   € \        V RR4      p\        V\        4      '       d   VP                  R4      MRp\        V\        4      ;'       d    VP                  R4      \        8H  # )z¤True for the translated contentless-SSE-frame error. Re-streaming cannot help
(a degraded gateway answers every stream that way), so the caller must change channel.rj   Nr5   ry   )rì   r|   rk   r}   r   )rò   rj   r   s   &  r?   Ú%_is_provider_stream_empty_frame_errorrö     sR   € ô �3˜ Ó%€DÜ%/°´d×%;Ò%;�—‘˜Ô!À€IÜ�i¤Ó&×jÐj¨9¯=©=¸Ó+@ÔDjÑ+jÐjrB   c               ó   € V ^8„  d   QhRR/# )rG   ro   r   rL   )rM   s   "r?   rN   rN     s   € ÷ hñ h°cñ hrB   c             #  óÒ   "  €  T  Rj  x€L
  R#  L  \         P                   d>   p\        T4      '       d   T! 4       MTpTf   \        T RR4      p\	        Y#R7      ThRp?ii ; i5i)zAYield SDK chunks while translating SDK-level SSE decode failures.Nro   ©ro   )r¬   r­   Úcallablerì   rï   )Ústreamro   r5   Ústream_responses   &$  r?   Ú_iter_provider_stream_chunksrý     s`   é € ðhØ×ÔøÜ×Ñô hÜ(0°×(:Ò(:™(œ*ÀˆØÒ"Ü% f¨j¸$Ó?ˆOÜ;¸EÔ\ÐbgÐgûð	hüs0   ‚A'„ ‰Š ŽA'� ’A$§8AÁA$Á$A'c               ó    € V ^8„  d   QhRRRR/# )rG   r—   r   rJ   rô   rL   )rM   s   "r?   rN   rN   (  s   € ÷ lñ l cð l¨dñ lrB   c                ó`  € \        V \        4      '       g   R # \        V P                  R4      \        \        34      '       d   R# \	        V P                  R4      4      ;'       dI    \	        V P                  R4      ;'       g'    V P                  R4      ;'       g    \        V 4      RJ4      # )Fr5   Trz   ry   rÛ   N)r|   rk   r}   rI   rô   r¤   )r—   s   &r?   Ú_payload_has_error_shaper   (  sŒ   € Ü�gœt×$Ò$ÙÜ�'—+‘+˜gÓ&¬¬s¨×4Ò4ÙÜ�—‘˜IÓ&Ó'÷ lð l¬DØ�‰�FÓ×jÐj˜wŸ{™{¨<Ó8×jÐjÔ<UÐV]Ó<^ÐfjÐ<jó-lð lrB   c               ó    € V ^8„  d   QhRRRR/# )rG   r�   rI   rJ   rô   rL   )rM   s   "r?   rN   rN   1  s   € ÷ ñ ¨3ð °4ñ rB   c                óª  a€ T ;'       g    RP                  4       pV'       g   R# VP                  4       pVP                  R4      pRp\        V4       Fû  w  rVVP	                  R4      pVR8X  d   K  VP                  R4      '       d   RpK:  VP                  R4      w  r‰p
VP                  4       P                  4       oV	'       d   S\        9   d   RpKƒ  V\        V4      ^,
          8H  ;'       d    V'       * pV'       dL   \        ;QJ d#    V3R l\         4       F  '       g   K   RM	  RM! V3R l\         4       4      '       d    R#  R# 	  V# )zEReturn True while pending text still looks like an SSE control block.r§   FrË   rÌ   Tc              3  óD   <"  € T F  qP                  S4      x € K  	  R # 5ir:   )r¯   )r›   Ú	sse_fieldÚ
field_names   & €r?   r�   Ú3_provider_stream_text_may_be_sse.<locals>.<genexpr>J  s"   øé € ð &[Ù>Y°× Ñ  ×,Ð,Ó>Yùs   ƒ )r»   rË   )ÚlstriprÏ   ÚendswithÚ	enumeraterÐ   r¯   rÑ   r©   rÒ   Ú_PROVIDER_STREAM_SSE_FIELDSÚlenrÀ   )r�   r±   ÚlinesÚtrailing_newlineÚsaw_sse_fieldÚindexrÔ   rÕ   rÖ   r×   Ú_valueÚis_last_incompleter  s   &           @r?   Ú _provider_stream_text_may_be_sser  1  s  ø€ à—
�
˜×"Ñ"Ó$€HßÙà×ÑÓ!€EØ×(Ñ(¨Ó6ÐØ€Mä$ UÖ+‰ˆØ�‰˜tÓ$ˆØ�2Œ:ÙØ�?‰?˜3×ÒØ ˆMÙà!Ÿ^™^¨CÓ0Ñˆ�FØ—[‘[“]×(Ñ(Ó*ˆ
ß�:Ô!<Ô<Ø ˆMÙà"¤c¨%£j°1¥nÑ4×MÐMÐ=MÔ9MÐß§#£#ô &[Ý>Yó&[§#§#¢#ô &[Ý>Yó&[÷ #[ò #[âÚñ% ,ð( ÐrB   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	rG   r�   rI   Úfinish_reasonúOptional[str]ro   r   rJ   zOptional[ProviderStreamError]rL   )rM   s   "r?   rN   rN   R  s*   € ÷ ñ ¨3ð ¸}ð ØðØ:ñrB   c               óÞ  a a€ S '       g   R# \        T;'       g    R4      P                  4       \        9  d   R# Ve   \        VRR4      MRoR VV 3R llp\	        S 4       FÆ  p\        VP                  R4      ;'       g    R4      P                  4       P                  4       R8H  p\        VP                  R4      ;'       g    R4      ;'       g    / pVP                  R	4      ;'       g    \        V4      pVe   VR
8¼  g   V'       g   \        V4      '       g   K¾  V! Wg4      u # 	  \        S 4      pVe   V! V\        V4      4      # S P                  4       '       d
   V! / R4      # R# )zGConvert provider-streamed error text into an exception for retry logic.Nr§   rf   c               ó$   € V ^8„  d   QhRRRRRR/# )rG   r—   rk   rh   ri   rJ   re   rL   )rM   s   "r?   rN   Ú6_provider_stream_error_from_text.<locals>.__annotate__]  s"   € ÷ ,ñ ,˜ð ,¨=ð ,Ð=Pñ ,rB   c                ó4   <€ \        V\        W4      SSR 7      # )ré   )re   rã   )r—   rh   rf   r�   s   &&€€r?   Ú_errorÚ0_provider_stream_error_from_text.<locals>._error]  s    ø€ Ü"¨{ÔAUÐV]ÓAkØ 7ô,ð 	,rB   r¶   r5   r·   rh   é�  )
rI   rÒ   Ú%_PROVIDER_STREAM_ERROR_FINISH_REASONSrì   rØ   r}   r©   r³   r¤   r   )	r�   r  ro   r  r¶   Úis_error_eventr—   rh   rf   s	   f&$     @r?   Ú _provider_stream_error_from_textr  R  s6  ù€ ÷ Ùä
ˆ=×Ð˜BÓ×%Ñ%Ó'Ô/TÔTÙà4<Ò4HŒg�h 	¨4Ô0Èd€G÷,ñ ,ô ,¨DÖ1ˆÜ˜UŸY™Y wÓ/×5Ð5°2Ó6×<Ñ<Ó>×DÑDÓFÈ'ÑQˆÜ(¨¯©°6Ó):×)@Ð)@¸bÓA×GÐGÀRˆØ—i‘i Ó.×TÐTÔ2KÈGÓ2Tˆð Ò#¨°sÔ(:¿~ÔQiÐjq×QrÔQrÙ˜'Ó/Ò/ñ 2ô % TÓ*€GØÒÙ�gÔ8¸ÓAÓBÐBà‡z�z‡|‚|Ù�b˜$ÓÐÙrB   c               ó$   € V ^8„  d   QhRRRRRR/# )rG   Úpartúdict[str, Any]Ú
image_costr�   rJ   rL   )rM   s   "r?   rN   rN   v  s&   € ÷ Hñ H˜Nð H¸ð HÀñ HrB   c                ó’   € V P                  R4      pV^,          \        V\        4      '       d   \        V4      ,           # ^ ,           # )a  Char-equivalent of one image content part: the per-image cost learned from provider usage
(x4 chars/token), never the base64 payload length. A single native screenshot priced as text
read as ~100K+ tokens and selected the giant-conversation watchdog tiers (#63871, #76411).r�   )r}   r|   rI   r  )r!  r#  r�   s   && r?   Ú_image_part_charsr%  v  s9   € ð �8‰8�FÓ€DØ˜�>¬*°T¼3×*?Ò*?œS ›YÕGÐGÀQÕGÐGrB   c               ó$   € V ^8„  d   QhRRRRRR/# )rG   r‹   r   r#  r�   rJ   rL   )rM   s   "r?   rN   rN   ~  s!   € ÷ ñ ˜#ð ¨3ð °3ñ rB   c                ó,  a a€ S f   ^ # \        S \        4      '       d¢   S P                  R4      p\        V\        4      '       dX   V\        9   dM   \
        ;QJ d    V 3R lR 4       F  '       g   K   RM	  RM! V 3R lR 4       4      '       d   \        S S4      # \        V3R lS P                  4        4       4      # \        S \        4      '       d-   \        V3R lS  4       4      ^\        S 4      ,          ,           # \        \        S 4      4      # )zR``len(str(value))`` with image content parts priced at ``image_cost`` tokens each.rÜ   c              3  ó,   <"  € T F	  qS9   x € K  	  R # 5ir:   rL   )r›   rœ   r‹   s   & €r?   r�   Ú!_payload_chars.<locals>.<genexpr>†  s$   øé € ð  QRñ  fQÐ`aÐV[ÖQ[ó  fQùó   ƒTFc              3  ó€   <"  € T F3  w  r\        \        V4      4      ^,           \        VS4      ,           x € K5  	  R# 5i)é   N)r  rI   Ú_payload_chars)r›   rœ   Úvr#  s   &  €r?   r�   r)  ˆ  s.   øé € Ð]É}ÁtÀq”3”s˜1“v“; •?¤^°A°zÓ%B×BÒBË}ùs   ƒ;>c              3  ó<   <"  € T F  p\        VS4      x € K  	  R # 5ir:   ©r-  )r›   Úitemr#  s   & €r?   r�   r)  Š  s   øé € ÐFÁ¸”> $¨
×3Ð3Ãùs   ƒ)Ú	image_urlÚimageÚsourceÚfile_id)r|   rk   r}   rI   Ú_IMAGE_PART_TYPESrÀ   r%  ÚsumÚitemsrÂ   r  )r‹   r#  Ú	part_types   ff r?   r-  r-  ~  sÝ   ù€ à‚}ÙÜ�%œ×ÒØ—I‘I˜fÓ%ˆ	ô �i¤×%Ò%¨)Ô7HÔ*HÏSËSô  QRñ  fQó  QRÏSÏSÊSô  QRñ  fQó  QR÷  NRò  NRÜ$ U¨JÓ7Ð7ÜÔ]ÈuÏ{É{Ì}Ó]Ó]Ð]Ü�%œ×ÒÜÔFÁÓFÓFÈÌSÐQVËZÍÕWÐWÜŒs�5‹z‹?ÐrB   c               ó    € V ^8„  d   QhRRRR/# )rG   Úapi_payloadr   rJ   r�   rL   )rM   s   "r?   rN   rN   Ž  s   € ÷ Eñ E°ð E¸ñ ErB   c                óR  a aa€ ^ RI Hp V! 4       oR V3R llo\        S \        4      '       d   \	        V3R lS  4       4      ^,          # \        S \
        4      '       g   S! S 4      ^,          # S P                  R4      p\        V\        4      '       dD   \	        V3R lV 4       4      pRS 9   d   VS! S P                  R4      4      ,          pV^,          # RS 9   d   \	        VV 3R	 lR 4       4      ^,          # \	        V3R
 lS P                  4        4       4      ^,          # )ai  Cheap char/4 context estimate for the stale-call detectors. Handles both
wire shapes so Codex turns don't report ~0 tokens: list -> Chat ``messages``;
dict with ``messages`` (+``tools``); dict with ``input`` (Responses API,
+``instructions``/``tools``); any other dict -> sum of its values. Image parts
cost the learned per-image price, not their base64 length.)Úcurrent_image_token_costc               ó    € V ^8„  d   QhRRRR/# )rG   r‹   r   rJ   r�   rL   )rM   s   "r?   rN   Ú5estimate_request_context_tokens.<locals>.__annotate__˜  s   € ÷ 1ñ 1�cð 1˜cñ 1rB   c                ó   <€ \        V S4      # r:   r0  )r‹   r#  s   &€r?   Ú_charsÚ/estimate_request_context_tokens.<locals>._chars˜  s   ø€ Ü˜e ZÓ0Ð0rB   c              3  ó4   <"  € T F  pS! V4      x € K  	  R # 5ir:   rL   ©r›   r1  rA  s   & €r?   r�   Ú2estimate_request_context_tokens.<locals>.<genexpr>œ  s   øé € Ð8©K D‘6˜$—<�<«Kùó   ƒÚmessagesc              3  ó4   <"  € T F  pS! V4      x € K  	  R # 5ir:   rL   rD  s   & €r?   r�   rE  ¡  s   øé € Ð<±8¨4™& Ÿ,˜,³8ùrF  ÚtoolsÚinputc              3  óR   <"  € T F  pS! SP                  V4      4      x € K  	  R # 5ir:   rš   )r›   rœ   rA  r;  s   & €€r?   r�   rE  ¦  s$   øé € ÐZÑ7Y°!‘6˜+Ÿ/™/¨!Ó,×-Ð-Ó7Yùs   ƒ$'c              3  ó4   <"  € T F  pS! V4      x € K  	  R # 5ir:   rL   )r›   r‹   rA  s   & €r?   r�   rE  §  s   øé € Ð?Ñ*> ‰v�e�}ˆ}Ó*>ùrF  )rJ  ÚinstructionsrI  )Úagent.image_token_costr=  r|   rÂ   r7  rk   r}   rÁ   )r;  r=  rG  Útotal_charsrA  r#  s   f   @@r?   Úestimate_request_context_tokensrP  Ž  sò   ú€ õ @á)Ó+€J÷1ð 1ô �+œt×$Ò$ÜÔ8©KÓ8Ó8¸AÕ=Ð=Ü�k¤4×(Ò(Ù�kÓ" aÕ'Ð'Ø�‰˜zÓ*€HÜ�(œD×!Ò!ÜÔ<±8Ó<Ó<ˆØ�kÔ!Ø™6 +§/¡/°'Ó":Ó;Õ;ˆKØ˜aÕÐØ�+ÔÜÕZÑ7YÓZÓZÐ^_Õ_Ð_ÜÔ?¨+×*<Ñ*<Ô*>Ó?Ó?À1ÕDÐDrB   c               ó   € V ^8„  d   QhRR/# ©rG   rJ   rô   rL   )rM   s   "r?   rN   rN   ª  s   € ÷ <ñ < tñ <rB   c                ó2   € ^ RI Hp V! V 4      P                  # )é    ©Úclassify_responses_route)Úagent.codex_responses_adapterrV  Úis_codex_backend)rU   rV  s   & r?   Ú_is_openai_codex_backendrY  ª  s   € ÝFÙ# EÓ*×;Ñ;Ð;rB   c               ó    € V ^8„  d   QhRRRR/# )rG   Ú
est_tokensr�   rJ   ÚfloatrL   )rM   s   "r?   rN   rN   ¯  s   € ÷ ñ °ð ¸ñ rB   c                ó0   € R F  w  rW8”  g   K  Vu # 	  R# )a  Minimum wall-clock stale timeout for openai-codex by estimated context:
subscription-backed Codex can spend minutes in admission/prefill on
gateway-scale payloads, so the generic default would abort healthy calls.
The floor engages above 10k estimated tokens.ç        ))é † g     À’@)éPÃ  ç      Œ@)é'  g     À‚@rL   )r[  Ú	thresholdÚfloors   &  r?   Ú openai_codex_stale_timeout_floorre  ¯  s#   € ó
 RÑˆ	ØÖ!ØŠLñ Rñ rB   c               ó$   € V ^8„  d   QhRRRRRR/# )rG   Ústale_timeoutr\  r[  r�   rJ   rL   )rM   s   "r?   rN   rN   º  s'   € ÷ 
Sñ 
S°Uð 
SÈð 
SÐPUñ 
SrB   c                ó~   € \        V4      pV'       d   \        W4      p \        RR4      pV^ 8”  d   \        W4      # T # )u�  Apply the openai-codex stale bounds: raise to ``openai_codex_stale_timeout_floor``
so healthy gateway-scale requests aren't aborted mid-prefill, then clamp to the flat
HERMES_CODEX_HARD_TIMEOUT_SECONDS ceiling (#64507, default 1500s â€” above the max
floor, a backstop for a request that emits SOME events then wedges; 0 disables).
Shared by the worker watchdogs and the inline cron path (#69734).Ú!HERMES_CODEX_HARD_TIMEOUT_SECONDSg     p—@)re  Úmaxr3   Úmin)rg  r[  rd  Úhard_timeouts   &&  r?   Ú!_bound_openai_codex_stale_timeoutrm  º  s?   € ô -¨ZÓ8€EßÜ˜MÓ1ˆÜÐ@À&ÓI€LØ/;¸aÔ/?Œ3ˆ}Ó+ÐRÀ]ÐRrB   c               ó    € V ^8„  d   QhRRRR/# )rG   Úraw_sortr   rJ   r  rL   )rM   s   "r?   rN   rN   Ç  s   € ÷ ñ °#ð ¸-ñ rB   c           	     ó  € \        V \        4      '       g   R# V P                  4       P                  4       pV'       g   R# V\        9   d   V# \
        P                  RV RP                  \        \        4      4      4       R# )z;Return a normalized OpenRouter provider.sort value or None.Nz@Ignoring invalid OpenRouter provider.sort value %r (allowed: %s)ú, )	r|   rI   r©   rÒ   Ú _OPENROUTER_PROVIDER_SORT_VALUESr[   r\   rY   Úsorted)ro  Ú
sort_values   & r?   Ú#_validated_openrouter_provider_sortru  Ç  sc   € ä�h¤×$Ò$ÙØ—‘Ó!×'Ñ'Ó)€JßÙØÔ5Ô5ØÐÜ
‡N�NÐUÐW_Ø�	‰	”&Ô9Ó:Ó;ô=árB   c               ó   € V ^8„  d   QhRR/# )rG   rJ   r"  rL   )rM   s   "r?   rN   rN   Õ  s   € ÷ Bñ B¨nñ BrB   c                ó  € RV P                   RV P                  RV P                  RV P                  RV P                  RV P
                  /p/ p\        P                  ! \        4      ;_uu_ 4        ^ RI	H
p ^ RIHp V! 4       P                  R	4      pT! V P                  \        V\         4      '       d   T;'       g    / P                  R
4      MR4      pRRR4       / VCVP#                  4        UUu/ uF  w  rgWa9   g   K  WgbK  	  uppCp\%        VR,          4      VR&   VR,          '       d   RMRVR&   VP#                  4        U	U
u/ uF  w  ršV
'       g   K  WšbK  	  up
p	#   + '       g   i     L™; iu uppi u up
p	i )a<  Build the validated provider-routing object shared by request paths.

``provider_routing.models.<id>`` overlays the flat constructor values for the CURRENT
``agent.model`` (so ``/model`` switches, fallbacks, and delegated children on another
model each get their own pins without any surface re-plumbing the kwargs).ÚonlyÚignoreÚorderÚsortÚrequire_parametersÚdata_collection©Úload_config_readonly)Ú"resolve_per_model_provider_routingÚprovider_routingÚmodelsNT)Úproviders_allowedÚproviders_ignoredÚproviders_orderÚprovider_sortÚprovider_require_parametersÚprovider_data_collectionrª   r«   rX   Úhermes_cli.configr  Úhermes_constantsr€  r}   Úmodelr|   rk   r8  ru  )rU   ÚflatÚ	per_modelr  r€  Ú_prrœ   r.  ÚmergedrÅ   r‹   s   &          r?   Ú_provider_preferences_for_agentr�  Õ  sR  € ð �E×+Ñ+¨X°u×7NÑ7NÐPWÐY^×YnÑYnØ�×#Ñ#Ð%9¸5×;\Ñ;\Ø˜5×9Ñ9ð;€Dð €IÜ	×	Ò	œY×	'Õ	'Ý:ÝGÙ"Ó$×(Ñ(Ð);Ó<ˆÙ6°u·{±{ÔakÐloÔqu×avÒavÀSÇYÀYÈBÇOÁOÐT\ÔD]ð  }Aó  Bˆ	÷	 
(ð
 K�ÐJ¨)¯/©/Ô*;ÔIÑ*;¡$ !¸q¹yœ˜šÑ*;ÒIÐJ€FÜ8¸À½ÓH€Fˆ6�NØ+1Ð2F×+GÔ+G¡4ÈT€FÐÑ Ø)/¯©¬ÔA©™:˜3¼5ŒJˆCŠJ©ÒAÐA÷ 
(×	'üó
 Jùó Bs+   Á/AE'Â>E'Ã4
E:ÄE:ÅF ÅF Å'E7	c               ó   € V ^8„  d   QhRR/# )rG   rJ   z
str | NonerL   )rM   s   "r?   rN   rN   ê  s   € ÷ ñ ¨Jñ rB   c                ór   €  ^ RI Hp V! V 4      #   \         d    \        P	                  RRR7        R# i ; i)z•Rotation-stable logical cache scope for *agent*, or None (transports then
fall back to the physical session_id, so a failure never blocks the build).)Úresolve_prompt_cache_scope_safez$prompt-cache scope resolution failedT©Úexc_infoN)Úagent.prompt_cache_scoper“  rX   r[   Údebug)rU   r“  s   & r?   Ú_prompt_cache_scope_for_agentr˜  ê  s8   € ðÝLÙ.¨uÓ5Ð5øÜô Ü�‰Ð;ÀdˆÔKÚðús   ‚ �"6µ6c               ó$   € V ^8„  d   QhRRRRRR/# )rG   Úanthropic_kwargsrk   Úapi_messagesrÂ   rJ   rL   )rM   s   "r?   rN   rN   õ  s#   € ÷ ñ ÀDð ÐX\ð Ðaeñ rB   c           	     ó>  € \        V RR4      R	9  d   V#  ^ RIHp V! R4      pVeG   VP                  R/ 4      P	                  VP                  \        V RR4      \        V4      R7      4       V#   \         d"   p\        P                  RT4        Rp?T# Rp?ii ; i)
zšThe Nous profile body on the Messages wire, which the profile hook never reaches; never
``provider_preferences`` (OpenAI-wire routing the Portal 400s on).ÚproviderNÚnous©Úget_provider_profileÚ
extra_bodyÚ
session_id)r¢  Údata_usez'Nous Portal extra_body merge failed: %s>   rž  Únousresearchúnous-portal)
rì   Ú	providersr   Ú
setdefaultÚupdateÚbuild_extra_bodyr   rX   r[   r—  )rU   rš  r›  r   Únous_profilerò   s   &&&   r?   Ú&_merge_nous_portal_messages_extra_bodyr«  õ  s°   € ô ˆu�j $Ó'Ð/VÔVØÐðEÝ2Ù+¨FÓ3ˆØÒ#Ø×'Ñ'¨°bÓ9×@Ñ@À×A^ÑA^Ü" 5¨,¸Ó=ÔH\Ð]iÓHjð B_ó Blô mð Ðøô ô EÜ�‰Ð>À×DÐDØÐûðEús   –AA0 Á0BÁ;BÂBc               ó    € V ^8„  d   QhRRRR/# )rG   Úchunkr   rJ   r�   rL   )rM   s   "r?   rN   rN     s   € ÷ ñ  ð ¨ñ rB   c           	     ó¨  a€ ^(oV3R lp\         P                  ! \        4      ;_uu_ 4        \        V RR4      pV'       d`   \        V^ ,          RR4      pVeG   V! VRRR4       \        VRR4      ;'       g    R F   p\        VR	R4      pVf   K  V! VR
R4       K"  	  MV! \        V RR4      RR4       RRR4       S#   + '       g   i     S# ; i)zÔCheap per-chunk size estimate for the stream diagnostic counters: delta
string lengths plus a framing floor (~3x cheaper than ``len(repr(chunk))``
in the agent's hottest loop). Unknown shapes just keep the floor.c                ó†   <€ V F9  p\        WR 4      p\        V\        4      '       g   K'  S\        V4      ,          oK;  	  R # r:   )rì   r|   rI   r  )ÚobjÚattrsÚattrr.  Úsizes   &*  €r?   Ú_addÚ#_estimate_chunk_bytes.<locals>._add  s3   ø€ ãˆDÜ˜ 4Ó(ˆAÜ˜!œS×!Ô!Øœ˜A›•’ó rB   ÚchoicesNÚdeltaÚcontentÚreasoning_contentÚ	reasoningÚ
tool_callsÚfunctionÚ	argumentsÚnamer�   Úpartial_jsonrL   )rª   r«   rX   rì   )r­  r´  r¶  r·  ÚtcÚfnr³  s   &     @r?   Ú_estimate_chunk_bytesrÂ    sÌ   ø€ ð €Dõô 
×	Ò	œY×	'Õ	'Ü˜% ¨DÓ1ˆßÜ˜G A�J¨°Ó6ˆEØÒ Ù�U˜IÐ':¸KÔHÜ! %¨°tÓ<×BÐBÀÒB�BÜ   Z°Ó6�BØ”~Ù˜R ¨fÖ5ñ Cøñ
 ”˜ ¨Ó.°¸ÔG÷ 
(ð €K÷ 
(Ö	'ð €Kús   ¬AC Á9C Â$C Ã C	c               ó   € V ^8„  d   QhRR/# ©rG   rJ   r�   rL   )rM   s   "r?   rN   rN   )  s   € ÷ ñ ˜Cñ rB   c                óh   €  \        \        V R ^ 4      ;'       g    ^ 4      #   \         d     ^ # i ; i)Ú_consecutive_stale_streams)r�   rì   rX   ©rU   s   &r?   Ú_stale_streakrÈ  )  s6   € ðÜ”7˜5Ð">ÀÓB×GÐGÀaÓHÐHøÜô Úðús   ‚" ›" ¢1°1c               ó   € V ^8„  d   QhRR/# ©rG   rJ   rK   rL   )rM   s   "r?   rN   rN   0  s   € ÷ Dñ D ñ DrB   c                ó²   € \         P                  ! \        4      ;_uu_ 4        \        V 4      ^,           V n        RRR4       R#   + '       g   i     R# ; i)rÍ   N)rª   r«   rX   rÈ  rÆ  rÇ  s   &r?   Ú_bump_stale_streakrÌ  0  s4   € Ü	×	Ò	œY×	'Õ	'Ü+8¸Ó+?À!Õ+CˆÔ(÷ 
(×	'×	'Ò	'ús   £AÁA	c               ó   € V ^8„  d   QhRR/# rÊ  rL   )rM   s   "r?   rN   rN   5  s   € ÷ -ñ - $ñ -rB   c                ó’   € \         P                  ! \        4      ;_uu_ 4        ^ V n        RRR4       R#   + '       g   i     R# ; i)rT  N)rª   r«   rX   rÆ  rÇ  s   &r?   Ú_reset_stale_streakrÏ  5  s*   € Ü	×	Ò	œY×	'Õ	'Ø+,ˆÔ(÷ 
(×	'×	'Ò	'ús	   £5µA	ç      >@c               ó$   € V ^8„  d   QhRRRRRR/# )rG   Úelapsedr\  Úresponse_startedrô   rJ   rL   )rM   s   "r?   rN   rN   =  s#   € ÷ 	ñ 	°eð 	ÐRVð 	Ð[_ñ 	rB   c               ó†   € V'       g   V\         8  d   R# \        V 4       \        P                  RV\	        V 4      4       R# )zÄCount a user-aborted pre-response stall toward the stale breaker: past the
wait-notice interval an interrupt is evidence of an unresponsive attempt.
Mid-response and early interrupts stay neutral.FzeInterrupted provider wait counted as stale after %.0fs with no output; consecutive stale attempts=%d.T)Ú_INTERRUPTED_WAIT_STALE_SECONDSrÌ  r[   r\   rÈ  )rU   rÒ  rÓ  s   &&$r?   Ú!_record_interrupted_provider_waitrÖ  =  s9   € ÷ ˜7Ô%DÔDÙÜ�uÔÜ
‡N�Nð )Ø*1´=ÀÓ3GôIárB   ÚinlineFÚhintc               ó0   € V ^8„  d   QhRRRRRRRRRR	R
R/# )rG   Ú
api_kwargsrk   rÒ  r\  rg  r×  rô   rØ  r  rJ   rK   rL   )rM   s   "r?   rN   rN   I  sB   € ÷ Eñ E°Dð EÀ5ð EÐY^ð EØðEØ -ðEØ9=ñErB   c          
     ó4  € VP                  RR4      p\        P                  RV'       d   RMRVW6\        V4      R 4        T P	                  R\        V4       RT R	T;'       g    R
 24       R#   \         d    \        P                  RRR7        R# i ; i)zËLog + status message for a stale non-streaming kill, shared by the worker
poll loop and the inline ``direct_api_call`` watchdog (their kill/state
sequences differ deliberately: different locking models).r‹  Úunknownzk%son-streaming API call stale for %.0fs (threshold %.0fs). model=%s context=~%s tokens. Killing connection.zInline nÚNÚ,õ%   âš ï¸� No response from provider for zs (non-streaming, model: z). zAborting call.zstale status buffering failedTr”  N)r}   r[   r\   rP  Ú_buffer_diagnostic_statusr�   rX   r—  )rU   rÚ  rÒ  rg  r×  rØ  r‹  s   &&&&$$ r?   Ú_report_stale_nonstream_killrá  I  s¡   € ð
 �N‰N˜7 IÓ.€EÜ
‡N�Nð ;ßJP¹JÐVYÐ[bØÔ!@ÀÓ!LÈQÐ OôRðEØ×'Ñ'Ø3´C¸³L°>ÐAZÐ[`ÐZaÐadÐei×e}Ðe}Ðm}Ðd~Ðö	Aøäô EÜ�‰Ð4¸tˆ×DðEús   Á-A1 Á1"BÂBc               ó    € V ^8„  d   QhRRRR/# ©rG   rÒ  r\  rJ   rK   rL   )rM   s   "r?   rN   rN   Y  s   € ÷ Cñ C¨uð C¸ñ CrB   c                ó–   €  V P                  R \        V4       R24       R#   \         d    \        P	                  RRR7        R# i ; i)z&stale non-streaming call killed after r½   zstale activity touch failedTr”  N)Ú_touch_activityr�   rX   r[   r—  )rU   rÒ  s   &&r?   Ú_touch_stale_kill_activityræ  Y  sG   € ðCØ×ÑÐ FÄsÈ7Ã|ÀnÐTUÐVÖWøÜô CÜ�‰Ð2¸Tˆ×BðCús   ‚" ¢"AÁAc               ó   € V ^8„  d   QhRR/# rÊ  rL   )rM   s   "r?   rN   rN   `  s   € ÷ 

ñ 

 $ñ 

rB   c                ól   € \        4       p\        V 4      pV^ 8”  d   W!8¼  d   \        RV R24      hR# R# )u€   Raise immediately when the consecutive-stale streak is past the
give-up threshold â€” no network attempt, no stale-timeout wait.z:Provider has been unresponsive (no response received) for u‚    consecutive stale attempts â€” aborting this call to avoid an indefinite stall. Switch models or start a new session, then retry.N)r   rÈ  ÚRuntimeError)rU   Ú_giveupÚ_streaks   &  r?   Ú_check_stale_giveuprì  `  sI   € ô ‹n€GÜ˜EÓ"€GØ�„{�wÔ)ÜØHØˆið [ð[ó
ð 	
ñ *�{rB   c               ó   € V ^8„  d   QhRR/# )rG   rJ   ztuple[float, bool]rL   )rM   s   "r?   rN   rN   m  s   € ÷ hñ hÐ 2ñ hrB   c                 ó@   € \        RR4      R\        P                  9   3# )uÏ   (HERMES_STREAM_STALE_TIMEOUT or the implicit 180s, explicit) â€” like
``AIAgent._resolved_api_call_stale_timeout_base``; an explicit env value is the
user's deadline, so it is never capped to the run budget.ÚHERMES_STREAM_STALE_TIMEOUTç     €f@)r3   ÚosÚenvironrL   rB   r?   Ú_stream_env_stale_baseró  m  s$   € ô Ð2°EÓ:Ð<YÔ]_×]gÑ]gÑ<gÐgÐgrB   c               ó   € V ^8„  d   QhRR/# ©rG   rJ   r\  rL   )rM   s   "r?   rN   rN   t  s   € ÷ Cñ C Uñ CrB   c                óp   € \        V P                  V P                  4      pVe   V# \        4       ^ ,          # )zWPer-provider ``stale_timeout_seconds`` config, else HERMES_STREAM_STALE_TIMEOUT (180s).)r	   r�  r‹  ró  )rU   Úcfgs   & r?   Ú_configured_stale_baserø  t  s.   € ä
$ U§^¡^°U·[±[Ó
A€CØ’/ˆ3ÐBÔ'=Ó'?ÀÕ'BÐBrB   c               ó   € V ^8„  d   QhRR/# rõ  rL   )rM   s   "r?   rN   rN   z  s   € ÷ Iñ I¨Uñ IrB   c                 ó¦  € Rp \         P                  ! \        4      ;_uu_ 4        ^ RIHp V! 4       p\        V\        4      '       d   VP                  R4      MRp\        V\        4      '       d   VP                  R4      MRp\        V\        \        34      '       d   \        V4      p RRR4       \        RV 4      #   + '       g   i     L; i)zîLocal-provider stale ceiling: ``agent.local_stream_stale_timeout`` (900s) or
HERMES_LOCAL_STREAM_STALE_TIMEOUT. Shared by the stream stale detector and the
Responses first-event watchdog so both give a local server the same prefill grace.ra  r~  rU   NÚlocal_stream_stale_timeoutÚ!HERMES_LOCAL_STREAM_STALE_TIMEOUT)rª   r«   rX   r‰  r  r|   rk   r}   r�   r\  r3   )Úlocal_defaultr  r÷  Ú	agent_cfgr‹   s        r?   Ú#_local_stream_stale_timeout_defaultrÿ  z  s˜   € ð €MÜ	×	Ò	œY×	'Õ	'Ý:Ù"Ó$ˆÜ(2°3¼×(=Ò(=�C—G‘G˜GÔ$À4ˆ	Ü?IÈ)ÔUY×?ZÒ?Z�	—‘Ð:Ô;Ð`dˆÜ�eœc¤5˜\×*Ò*Ü! %›LˆM÷ 
(ô Ð8¸-ÓHÐH÷ 
(×	'ús   ¥BC Ã C	c               ó$   € V ^8„  d   QhRRRRRR/# )rG   Úbaser\  r[  r�   rJ   rL   )rM   s   "r?   rN   rN   ‰  s!   € ÷ ñ ¨5ð ¸cð Àeñ rB   c                óR   € VR8”  d   \        V R4      # VR8”  d   \        V R4      # V # )z€Large contexts: slow models think for minutes before the first token;
scale the threshold or the detector kills healthy streams.r_  ç     Àr@r`  g      n@)rj  )r  r[  s   &&r?   Ú _scale_stale_timeout_for_contextr  ‰  s3   € ð �GÔÜ�4˜ÓÐØ�FÔÜ�4˜ÓÐØ€KrB   c               ó$   € V ^8„  d   QhRRRRRR/# )rG   r  r\  rÚ  rk   rJ   rL   )rM   s   "r?   rN   rN   “  s!   € ÷ 
=ñ 
=˜uð 
=°$ð 
=¸5ñ 
=rB   c                ó(  € ^ RI Hp \        V \        V4      4      pT! VP	                  R4      ;'       g    VP	                  R4      ;'       g    R4      pVf*   VP	                  R4      '       d   \        VR,          4      pVf   V# \        W44      # )a"  Cloud stale-stream patience: ``base`` scaled for context size, then floored for
known reasoning models. ``model`` (OpenAI/Anthropic) wins over ``modelId`` (Bedrock);
Bedrock's dotted, region-prefixed profile id can't match the floor's slug regex
directly, so it is normalized as a fallback.©Ú!get_reasoning_stale_timeout_floorr‹  ÚmodelIdr§   )Úagent.reasoning_timeoutsr  r  rP  r}   Ú_bedrock_reasoning_stale_floorrj  )r  rÚ  r  rT   rd  s   &&   r?   Ú_cloud_stale_timeoutr  “  s   € õ
 KÜ.¨tÔ5TÐU_Ó5`Óa€GÙ-¨j¯n©n¸WÓ.E×.hÐ.hÈÏÉÐXaÓIb×.hÐ.hÐfhÓi€EØ‚}˜Ÿ™¨	×2Ò2Ü.¨z¸)Õ/DÓEˆØ’mˆ7Ð<¬¨WÓ)<Ð<rB   c               ó    € V ^8„  d   QhRRRR/# ©rG   rÚ  rk   rJ   r\  rL   )rM   s   "r?   rN   rN      s   € ÷ 7ñ 7°Dð 7¸Uñ 7rB   c                ó   € \        W4      # )z“Stale-stream patience for a provider that is never a local endpoint (Bedrock):
the OpenAI/Anthropic stale detector's budget minus its local branch.)Ú_cloud_stale_timeout_for©rU   rÚ  s   &&r?   Ú_derive_stream_stale_timeoutr     s   € ô $ EÓ6Ð6rB   c               ó    € V ^8„  d   QhRRRR/# )rG   rT   r\  rJ   rL   )rM   s   "r?   rN   rN   ¦  s   € ÷ 	4ñ 	4 eð 	4°ñ 	4rB   c                óþ   € \        V RR4      p\        V RR4      pV'       d	   V'       g   V# \        V4      \        P                  ! 4       \        V4      ,
          ,
          p\        V\	        RVR,          4      4      # )a  Cap an IMPLICIT stale timeout at half the remaining --run-budget (>= 60s), so one hung
call can't outlive the run and the wrap-up notice stays reachable (#97968). Shared by the
streaming and non-streaming resolvers; callers skip it for explicit user settings.Úrun_budget_secondsNÚ_run_budget_started_atr7   g      à?)rì   r\  Útimerk  rj  )rU   rT   Ú
run_budgetÚstartedÚ	remainings   &&   r?   Úcap_to_run_budgetr  ¦  sb   € ô ˜Ð 4°dÓ;€JÜ�eÐ5°tÓ<€GßŸWØˆÜ�jÓ!¤T§Y¢Y£[´5¸³>Õ%AÕB€IÜˆwœ˜D )¨c¥/Ó2Ó3Ð3rB   c               ó    € V ^8„  d   QhRRRR/# r  rL   )rM   s   "r?   rN   rN   ²  s   € ÷ 
Jñ 
J°ð 
J¸ñ 
JrB   c                ó¦   € \        V P                  V P                  4      pVe   V# \        4       w  r4\	        W14      pV'       d   V# \        W4      # )u  An explicit ``providers.<id>.stale_timeout_seconds`` is the operator's deadline and
wins over every implicit floor â€” the context-size tier as well as the reasoning-model
floor â€” so it can SHORTEN patience for a hung stream (#115024). Only the 180s default
is scaled and floored.)r	   r�  r‹  ró  r  r  )rU   rÚ  Úexplicitr  Úexplicit_envrT   s   &&    r?   r  r  ²  sK   € ô
 *¨%¯.©.¸%¿+¹+ÓF€HØÒØˆÜ/Ó1Ñ€DÜ" 4Ó4€Gß"ˆ7ÐIÔ(9¸%Ó(IÐIrB   c               ó    € V ^8„  d   QhRRRR/# )rG   Úmodel_idÚobjectrJ   zfloat | NonerL   )rM   s   "r?   rN   rN   ¿  s   € ÷ hñ h¨Vð h¸ñ hrB   c                ó  € ^ RI Hp V '       d   \        V \        4      '       g   R# V P	                  4       P                  4       pR F*  pVP                  V4      '       g   K  V\        V4      R p M	  V.pRV9   dK   VP                  VP                  R^4      ^,          4       VP                  VP                  RR^4      4       \        P                  R V 4       4      p\        R \        W4       4       R4      # )a  Map a Bedrock inference-profile id to its reasoning stale-timeout floor.

``us.anthropic.claude-opus-4-6-v1:0`` -> strip the region prefix, then try the
segment after the provider namespace (``claude-opus-4-6-v1:0``) and the id with
the provider dot dashed (``deepseek-r1-v1:0``). The floor table mixes dashed
and dotted versions while Bedrock always dashes, so each candidate is also
tried with digit-dash-digit <-> digit-dot-digit swapped (version separators
only). First non-None wins; None for unknown models.
r  NÚ.Ú-c              3  ó–   "  € T F?  pV\         P                  ! R RV4      \         P                  ! RRV4      3 F  pVx € K	  	  KA  	  R# 5i)z(?<=\d)-(?=\d)r$  z(?<=\d)\.(?=\d)r%  N)r�   Úsub)r›   ÚcandÚforms   &  r?   r�   Ú1_bedrock_reasoning_stale_floor.<locals>.<genexpr>Õ  sI   é € ð iÙ(�Øœ2Ÿ6š6Ð"3°S¸$Ó?ÄÇÂÐHZÐ\_ÐaeÓAfÓgˆDõ 	Ùgñ 	›ùs   ‚AA	c              3  ó0   "  € T F  qf   K  Vx € K  	  R # 5ir:   rL   )r›   Úfs   & r?   r�   r*  Ø  s   é € Ð`ÑN�q—’ÓNùr¿   )zglobal.zus.zeu.zapac.zap.zau.zjp.zca.zsa.zme.zaf.)r
  r  r|   rI   r©   rÒ   r¯   r  r~   ÚrsplitÚreplacerk   ÚfromkeysrÃ   rÄ   )r!  r  r¾  ÚprefixÚbase_candidatesr¢   s   &     r?   r  r  ¿  sß   € õ Kßœ: h´×4Ò4ÙØ�>‰>Ó×!Ñ!Ó#€DÛeˆØ�?‰?˜6×"Ô"Øœ˜F›˜Ð%ˆDÙñ fð �f€OØ
ˆd„{Ø×Ñ˜tŸ{™{¨3°Ó2°1Õ5Ô6Ø×Ñ˜tŸ|™|¨C°°aÓ8Ô9Ü—‘ñ iÙ(óió i€Jô Ñ`œCÐ AÔNÓ`ÐbfÓgÐgrB   Úon_stream_deniedc               ó    € V ^8„  d   QhRRRR/# )rG   rÚ  rk   rû   rô   rL   )rM   s   "r?   rN   rN   Û  s   € ÷  ñ   tð  ¸ñ  rB   c               óì  € ^ RI HpHpHpHpHpHpHp	 V P                  RR4      p
V P                  RR4       V! V
4      pV'       d   VP                  MVP                  pV'       d   R MTp V! R/ V B pT! T4      #   \         dl   pT! Yð4      ;'       g	    T	! Yð4      pTe   T! T! R/ TB 4      u Rp?# Te   T! T4      '       d   T! Y°T4      u Rp?# T! T4      '       d	   T! T
4       h Rp?ii ; i)aÿ  Pop the Hermes routing keys and call ``converse`` / ``converse_stream`` (boto3 directly) with the
adapter's shared recovery: a cachePoint rejection (Nova: toolConfig.tools, #97281) or a replayed sealed
reasoning rejection resends once without the offending blocks inside the same attempt; a streaming IAM
denial hands off to ``on_stream_denied(client, kwargs, exc)``; a stale connection evicts the cached
client so the outer retry builds a fresh pool. Streaming returns the event stream; else a SimpleNamespace.)Ú_get_bedrock_runtime_clientÚinvalidate_runtime_clientÚis_stale_connection_errorÚ is_streaming_access_denied_errorÚnormalize_converse_responseÚ"recover_from_cache_point_rejectionÚ)recover_from_redacted_reasoning_rejectionÚ__bedrock_region__ú	us-east-1Ú__bedrock_converse__Nc                ó&   € V P                  R . 4      # ©rû   rš   )Úraws   &r?   r@   Ú(_bedrock_converse_call.<locals>.<lambda>è  s   € ˜#Ÿ'™' (¨BÔ/rB   rL   )Úagent.bedrock_adapterr5  r6  r7  r8  r9  r:  r;  ÚpopÚconverse_streamÚconverserX   )rÚ  rû   r2  r5  r6  r7  r8  r9  r:  r;  ÚregionÚclientÚmethodÚfinishÚraw_responserò   Úretry_kwargss   &$$              r?   Ú_bedrock_converse_callrM  Û  sý   € ÷W÷ Wñ Wð �^‰^Ð0°+Ó>€FØ‡N�NÐ)¨4Ô0Ù(¨Ó0€Fß'-ˆV×#Ò#°6·?±?€Fß4:Ò/Ð@[€FðÙÑ+ 
Ñ+ˆñ �,ÓÐøô ô 	Ù:¸3ÓK÷ Vð VÙDÀSÓUð 	àÒ#Ù™&Ñ0 <Ñ0Ó1Õ1ØÒ'Ñ,LÈS×,QÒ,QÙ# F¸Ó<Õ<Ù$ S×)Ò)Ù% fÔ-Øûð	ús<   Á-A= Á=C3Â)C.Â1C3Â7C.Ã	C.ÃC3ÃC.Ã%	C.Ã.C3c               ó   € V ^8„  d   QhRR/# ©rG   rÚ  rk   rL   )rM   s   "r?   rN   rN   ø  s   € ÷ !Qñ !Q¸$ñ !QrB   c          	     ób  € V P                   R8X  d%   V P                  W! R4      \        V RR4      R7      # V P                   R8X  d   V! RRR7      pV P                  WR	7      # V P                   R
8X  d   \	        VRR7      # V P
                  R8X  d�   \        \        V P                  RR4      RR4      p\        \        VRR4      4      '       g   VP                  RR4       V P                  P                  P                  P                  ! R/ VB # V! R4      p\        W4      p\        WV4      # )aˆ  Run one non-streaming LLM request for the active api_mode and return it.

Shared by ``interruptible_api_call`` and ``direct_api_call``. ``make_client(reason,
kind=...)`` builds the per-request client (``"openai"`` / ``"anthropic_messages"``)
so callers can register it with their abort/close machinery; bedrock / MoA
manage their own clients. Interrupt/abort/close semantics stay in callers.
Úcodex_responsesÚcodex_stream_requestÚ_codex_on_first_deltaN)rH  Úon_first_deltaÚanthropic_messagesÚanthropic_messages_request©Úkind)rH  Úbedrock_converseFr@  ÚmoaÚchatÚcompletionsÚprepareÚ_moa_prepared_requestÚchat_completion_requestrL   )Úapi_modeÚ_run_codex_streamrì   Ú_anthropic_messages_createrM  r�  rH  rú   rD  r[  r\  rQ   r   r   )rU   rÚ  Úmake_clientÚrequest_clientÚ_completionss   &&$  r?   Ú"_dispatch_nonstreaming_api_requestrf  ø  s"  € ð ‡~�~Ð*Ô*Ø×&Ñ& z¸+ÐF\Ó:]Ü" 5Ð*AÀ4ÓHð 'ó Jð 	Jà‡~�~Ð-Ô-ñ %Ð%AÐH\Ô]ˆØ×/Ñ/°
Ð/ÓRÐRØ‡~�~Ð+Ô+Ü% j¸Ô?Ð?Ø‡~�~˜Ôô œw u§|¡|°V¸TÓBÀMÐSWÓXˆÜœ ¨i¸Ó>×?Ò?Ø�N‰NÐ2°DÔ9Ø�|‰|× Ñ ×,Ñ,×3Ò3ÑA°jÑAÐAÙ Ð!:Ó;€Nô 3°:ÓN€JÜ-¨eÀZÓPÐPrB   c               ó   € V ^8„  d   QhRR/# rR  rL   )rM   s   "r?   rN   rN     s   € ÷ :ñ :¨ñ :rB   c                ó^  € \        V RR4      p\        V RR4      R8X  d   R# \        V RR4      R8X  d   VR9   # VR8w  d   R# \        P                  ! \        4      ;_uu_ 4        ^ R	IHp V! 4       '       d    RRR4       R
#  RRR4       \        V RR4      R8H  #   + '       g   i     L ; i)a>  Whether an OpenAI-wire request should skip the interrupt worker.

Gateway cron turns (#62151) and delegated children (#60203) run inside nested
thread pools that wedge before the socket opens when the request is pushed onto
yet another daemon worker. Running inline drops the deepest layer; interrupts
still work because the inline path registers ``agent._active_request_abort``,
which ``interrupt()`` invokes cross-thread (#72227). Cron also inlines Codex
Responses (#69734): both Codex paths (non-stream, and streaming via
``_stream_codex_passthrough`` -> ``_interruptible_api_call``) reach
``direct_api_call``, whose client comes from ``make_client`` so the inline stale
watchdog can abort it; the stale budget keeps the openai-codex floor/hard cap.
Trade-off: the worker-only Codex TTFB/progress/idle watchdogs don't run inline, so
a Codex call that never sends a first byte waits the full wall-clock stale budget
(600-1200s on large contexts) instead of the ~120s TTFB cutoff. Delegated children
and Native/Bedrock/MoA keep their workers: cancellation and client ownership differ.
r`  Nr�  rZ  FÚplatformÚcronÚchat_completions)Úis_delegated_child_contextTÚsubagent>   rQ  rk  )rì   rª   r«   rX   Úagent.delegation_contextrl  )rU   r`  rl  s   &  r?   Úshould_use_direct_api_callro    s    € ô" �u˜j¨$Ó/€HÜˆu�j $Ó'¨5Ô0ÙÜˆu�j $Ó'¨6Ô1ØÐBÑBÐBØÐ%Ô%Ùô 
×	Ò	œY×	'Õ	'ÝGÙ%×'Ò'Ø÷ 
(Ñ	'à'÷ 
(ô �5˜* dÓ+¨zÑ9Ð9÷	 
(×	'ús   Á$BÂB,	g      .@c               ó    € V ^8„  d   QhRRRR/# r  rL   )rM   s   "r?   rN   rN   C  s   € ÷ ñ °Tð ¸eñ rB   c                óŽ  € \        V RR4      p\        V4      '       d	   V! V4      MRp\        V\        4      '       g   \        V\        \
        34      '       g   \        R4      # \        V RR4      p\        V RR4      R8X  d8   V'       d   \        V4      '       g   \        \        V4      \        V4      4      # \        V4      # )uJ  Stale budget for the inline call via ``agent._compute_non_stream_stale_timeout``,
plus the same openai-codex floor/hard cap the worker path applies (inline cron Codex,
#69734). A non-numeric result (stub agent) leaves the watchdog disarmed; a resolver
that *raises* propagates â€” swallowing into ``inf`` would reinstate the hang.Ú!_compute_non_stream_stale_timeoutNÚinfÚbase_urlr`  rQ  )	rì   rú   r|   rô   r�   r\  r   rm  rP  )rU   rÚ  Úresolverr‹   rt  s   &&   r?   Ú_resolve_direct_stale_timeoutrv  C  s    € ô
 �uÐAÀ4ÓH€HÜ$,¨X×$6Ò$6‰H�ZÔ ¸D€EÜ�%œ×Ò¤j°¼¼e¸×&EÒ&EÜ�U‹|ÐÜ�u˜j¨$Ó/€HÜˆu�j $Ó'Ð+<Ô<ÇhÔSdÐem×SnÒSnÜ0´°u³Ô?^Ð_iÓ?jÓkÐkÜ�‹<ÐrB   c               ó   € V ^8„  d   QhRR/# )rG   rg  r\  rL   )rM   s   "r?   rN   rN   R  s   € ÷ ñ °%ñ rB   c                óº   € \         P                  ! V 4      '       d   V ^ 8:  d   R# \        V R4      p ^ RIpVP	                  WWR7      #   \
         d    T u # i ; i)au  Socket-level backstop for inline non-streaming calls (#85252): the keepalive
client uses ``read=None`` and the stranger-thread abort must not ``close()`` the
FD (#29507), so a hung provider otherwise waits until TCP dies. Returns an
``httpx.Timeout`` with read == stale budget, a float if httpx is unavailable,
or ``None`` when the watchdog is disarmed (non-finite budget).Nr7   ©ÚconnectÚreadÚwriteÚpool)ÚmathÚisfiniterk  ÚhttpxÚTimeoutrX   )rg  Úconn_capÚ_httpxs   &  r?   Ú_inline_nonstream_hard_timeoutr„  R  sY   € ô �=Š=˜×'Ò'¨=¸AÔ+=ÙÜ�= $Ó'€HðÛØ�~‰~ hÈ(ˆ~ÓbÐbøÜô ØÒðús   ³A
 Á
AÁAc                  ó�   € ] tR tRtR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 R lltR R ltR tRtR# )Ú_InlineRequestib  a;  Lifecycle state for one inline non-streaming request (#75301). Every transition
happens under ``lock``: ``done`` stops a late timer bumping the stale streak after
unwind; ``cancelled`` lets an interrupt own the outcome so a racing timer can't
misclassify the kill as staleness; ``stale`` is the one-shot transition.c               ó$   € V ^8„  d   QhRRRRRR/# )rG   rÚ  rk   rg  r\  Ú
call_startrL   )rM   s   "r?   rN   Ú_InlineRequest.__annotate__h  s"   € ÷ ñ ¨$ð ¸uð ÐRWñ rB   c                	óV  € Wn         W n        W0n        W@n        R V n        RV n        RV n        RV n        \        P                  ! 4       V n
        V P                  V n        \        P                  ! 4       V n        \        P                  ! V P                   RRR7      V n        R V n        R # )NFzdirect-api-activity-hbT©Útargetr¾  Údaemon)rU   rÚ  rg  rˆ  rH  ÚdoneÚstaleÚ	cancelledÚ	threadingÚLockÚlockÚabortÚ
abort_hookÚEventÚ_hb_stopÚThreadÚ_activity_heartbeatÚ_hbÚ	_watchdog)rs   rU   rÚ  rg  rˆ  s   &&&&&r?   rq   Ú_InlineRequest.__init__h  s   € ØŒ
Ø$ŒØ*ÔØ$ŒØˆŒØˆŒ	ØˆŒ
ØˆŒÜ—N’NÓ$ˆŒ	ØŸ*™*ˆŒÜ!ŸšÓ)ˆŒÜ×#Ò#¨4×+CÑ+CÐJbÐkoÔpˆŒØˆŽrB   c               ó   € V ^8„  d   QhRR/# rÊ  rL   )rM   s   "r?   rN   r‰  w  s   € ÷ Uñ U Tñ UrB   c                	ó  € V P                   P                  \        4      '       gI   \        P                  ! \
        4      ;_uu_ 4        V P                  P                  R 4       RRR4       Km  R#   + '       g   i     K€  ; i)ú&waiting for non-streaming API responseN)r—  ÚwaitÚ&_DIRECT_API_ACTIVITY_HEARTBEAT_SECONDSrª   r«   rX   rU   rå  ©rs   s   &r?   r™  Ú"_InlineRequest._activity_heartbeatw  sV   € ð —-‘-×$Ñ$Ô%K×LÒLÜ×$Ò$¤Y×/Õ/Ø—
‘
×*Ñ*Ð+SÔT÷ 0Ñ/ñ Mß/×/Ð/ús   ÁA0Á0B	c               ó   € V ^8„  d   QhRR/# rÊ  rL   )rM   s   "r?   rN   r‰  ~  s   € ÷ 8ñ 8˜4ñ 8rB   c                	ó
  € V P                  R 4      '       g   R# \        P                  ! 4       V P                  ,
          p\        V P                  V P
                  WP                  RR7       \        V P                  V4       R# )Ústale_call_killNT)r×  )r”  r  rˆ  rá  rU   rÚ  rg  ræ  )rs   rÒ  s   & r?   Ú	_on_staleÚ_InlineRequest._on_stale~  sV   € ð �z‰zÐ+×,Ò,ÙÜ—)’)“+ §¡Õ/ˆÜ$ T§Z¡Z°·±À'×K]ÑK]ÐfjÕkÜ" 4§:¡:¨wÖ7rB   c               ó   € V ^8„  d   QhRR/# rÊ  rL   )rM   s   "r?   rN   r‰  ‡  s   € ÷ #ñ # ñ #rB   c                óˆ  € V P                   P                  4        \        P                  ! V P                  4      '       d‚   V P                  ^ 8”  do   \
        P                  ! V P                  V P                  4      V n        RV P                  n	        RV P                  n
        V P                  P                  4        R# R# R# )zGStart the activity heartbeat and (for a finite budget) the stale timer.zdirect-api-stale-watchdogTN)rš  Ústartr~  r  rg  r‘  ÚTimerr§  r›  r¾  r�  r¢  s   &r?   Ústart_watchdogsÚ_InlineRequest.start_watchdogs‡  s   € à�‰�‰ÔÜ�=Š=˜×+Ñ+×,Ò,°×1CÑ1CÀaÔ1GÜ&Ÿ_š_¨T×-?Ñ-?ÀÇÁÓPˆDŒNØ"=ˆD�N‰NÔØ$(ˆD�N‰NÔ!Ø�N‰N× Ñ Ö"ñ	 2HÑ,rB   c               ó   € V ^8„  d   QhRR/# rÊ  rL   )rM   s   "r?   rN   r‰  �  s   € ÷ #ñ # ñ #rB   c                	óâ   € V P                   e   V P                   P                  4        V P                  4        V P                  P	                  4        V P
                  P                  RR7       R # )NrR   rS   )r›  ÚcancelÚ	mark_doner—  Úsetrš  rY   r¢  s   &r?   Ústop_watchdogsÚ_InlineRequest.stop_watchdogs�  sH   € Ø�>‰>Ò%Ø�N‰N×!Ñ!Ô#Ø�‰ÔØ�‰×ÑÔØ�‰�‰˜cˆÖ"rB   c               ó$   € V ^8„  d   QhRRRRRR/# )rG   ÚreasonrI   Úlog_msgrJ   rK   rL   )rM   s   "r?   rN   r‰  —  s!   € ÷ 1ñ 1¨Cð 1¸#ð 1À$ñ 1rB   c                	ó’   €  V P                   P                  WR 7       R#   \         d    \        P	                  TRR7        R# i ; i)©r·  Tr”  N)rU   Ú_abort_request_openai_clientrX   r[   r—  )rs   rH  r·  r¸  s   &&&&r?   Ú_abort_clientÚ_InlineRequest._abort_client—  s;   € ð	1Ø�J‰J×3Ñ3°FÐ3ÖJøÜô 	1Ü�L‰L˜¨4ˆL×0ð	1ús   ‚   "AÁAc               ó    € V ^8„  d   QhRRRR/# )rG   r·  rI   rJ   rô   rL   )rM   s   "r?   rN   r‰  �  s   € ÷ ñ ˜Cð  Dñ rB   c           	     óÊ  € V P                   ;_uu_ 4        V P                  '       d    RRR4       R# VR8X  dT   V P                  '       d    RRR4       R# V P                  '       * pV'       d   RV n        \	        V P
                  4       M	RV n        RpV P                  e"   V P                  V P                  VRV R24       VuuRRR4       #   + '       g   i     R# ; i)aR  Abort the inline request from a watchdog/interrupt thread. Returns True
when this call owned the stale transition (the timer reports/bumps once,
never after an interrupt or a completed request). Aborts under the lock
(same contract as _RequestClientRegistry): once released the finally may
cache the client and the NEXT call check it out.NFr¦  TzInline request abort failed (Ú))r“  rŽ  r�  r�  rÌ  rU   rH  r¼  )rs   r·  Únewly_stales   && r?   r”  Ú_InlineRequest.abort�  s®   € ð �Y�Y‹YØ�y�yˆyØ÷ ‰Yð Ð*Ô*Ø—>—>�>Ø ÷ ‰Yð #'§*¡*œn�ßØ!%�D”Jô ' t§z¡zÔ2øð "&�”Ø#�Ø�{‰{Ò&Ø×"Ñ" 4§;¡;°Ð:WÐX^ÐW_Ð_`Ð8aÔbØ÷' �Y�Y‹Yús#   •C³CÁCÁCÁ0ACÃC"	c               ó    € V ^8„  d   QhRRRR/# )rG   r·  rI   rX  rL   )rM   s   "r?   rN   r‰  ¸  s   € ÷ ñ  #ð ¨Sñ rB   c                	ó–  € V P                   P                  WP                  R 7      pV P                  ;_uu_ 4        W0n        V P
                  pV'       d   V P                  VRR4       RRR4       X'       d#   \        R\        V P                  4       R24      hV P                  V P                   n        V#   + '       g   i     LW; i)©r·  rÚ  r¦  z2Inline abort after late client registration failedNzENon-streaming API call timed out before request dispatch (threshold: ús))rU   Ú_create_request_openai_clientrÚ  r“  rH  r�  r¼  ÚTimeoutErrorr�   rg  r•  Ú_active_request_abort)rs   r·  rX  rH  Ústale_before_dispatchs   &&&  r?   rc  Ú_InlineRequest.make_client¸  s£   € ð —‘×9Ñ9À×TcÑTcÐ9ÓdˆØ�Y�Y‹YØ ŒKØ$(§J¡JÐ!ß$ð
 ×"Ñ" 6Ð+<Ð>rÔs÷ ÷ !ÜØWÔX[Ð\`×\nÑ\nÓXoÐWpÐprÐsóuð uà+/¯?©?ˆ�
‰
Ô(Øˆ÷ �Yús   ».B8Â8C	c               ó   € V ^8„  d   QhRR/# rÊ  rL   )rM   s   "r?   rN   r‰  Ë  s   € ÷ ñ ˜4ñ rB   c                	óv   € V P                   ;_uu_ 4        R V n        RRR4       R#   + '       g   i     R# ; i©TN)r“  rŽ  r¢  s   &r?   r²  Ú_InlineRequest.mark_doneË  s   € Ø�Y�Y‹YØˆDŒI÷ �Y�YŠYús   •'§8	c                	óŽ   € V P                   ;_uu_ 4        V P                  R uqn        R R R 4       V#   + '       g   i     X# ; ir:   )r“  rH  )rs   rH  s   & r?   Ú
pop_clientÚ_InlineRequest.pop_clientÏ  s2   € Ø�Y�Y‹YØ"&§+¡+¨tÐˆF”K÷ àˆ÷ ŽYàˆús	   •3³A	)rš  r—  r›  r•  rU   rÚ  rˆ  r�  rH  rŽ  r“  r�  rg  N)Úopenai)rƒ   r„   r…   r†   r‡   rq   r™  r§  r­  r´  r¼  r”  rc  r²  rÑ  rˆ   rL   rB   r?   r†  r†  b  s;   † ñPõ
õUõ8õ#õ#õ1õ÷6õ&örB   r†  c               ó   € V ^8„  d   QhRR/# rO  rL   )rM   s   "r?   rN   rN   Õ  s   € ÷ :Uñ :U tñ :UrB   c           	     óœ  € \        V 4       V P                  R4       \        P                  ! 4       p\        W4      p\	        V4      pVe   RV9  d	   / VCRV/Cp\        WW24      pVP                  4        Rp \        WVP                  R7      p\        V RR4      '       d   \        R4      hVP                  4        \        V 4       RpTVP                  4        \        V R	R4      VP                  J d   RV n        VP!                  4       pVe   T P#                  TV'       d   R
MRR7       # #   \$         d¦    \        T RR4      '       d   \        R4      RhTP&                  ;_uu_ 4        TP(                  p	RRR4       M  + '       g   i     M; iX	'       d@   \+        R\-        \        P                  ! 4       T,
          4       R\-        T4       R24      Rhh i ; i  TP                  4        \        T R	R4      TP                  J d   RT n        TP!                  4       pTe   T P#                  TT'       d   R
MRR7       i i ; i)u]  Run a non-streaming LLM call inline on the conversation thread (cron turns,
delegated children â€” see ``should_use_direct_api_call``): no interrupt worker,
so the nested-pool deadlock cannot occur. An activity heartbeat keeps
``last_activity_ts`` advancing (else the stall monitor interrupts a healthy
wait at ~450s). A stale-call watchdog bounds the request (#80759): the timer
aborts in-flight sockets via the registered hook, and a per-call ``timeout``
equal to the stale budget is the backstop when the abort finds nothing (#85252).
Both surface a retryable ``TimeoutError`` for the outer retry loop.rŸ  NrT   F)rc  Ú_interrupt_requestedz!Agent interrupted during API callTrÉ  Úrequest_completeÚrequest_error_cleanuprº  z'Non-streaming API call timed out after zs with no response (threshold: rÆ  )rì  rå  r  rv  r„  r†  r­  rf  rc  rì   ÚInterruptedErrorr²  rÏ  r´  r•  rÉ  rÑ  Ú_close_request_openai_clientrX   r“  r�  rÈ  r�   )
rU   rÚ  rˆ  rg  rl  ÚrequestÚ	succeededro   rd  Ú	was_stales
   &&        r?   Údirect_api_callrÞ  Õ  s3  € ô ˜ÔØ	×ÑÐBÔCô —’“€JÜ1°%ÓD€Mô 2°-Ó@€LØÒ I°ZÔ$?Ø<˜
Ð< I¨|Ñ<ˆ
Ü˜U°ÓJ€GØ×ÑÔð €Ið UÜ5°eÐU\×UhÑUhÔiˆô �5Ð0°%×8Ò8Ü"Ð#FÓGÐGð
 	×ÑÔÜ˜EÔ"Øˆ	Øà×ÑÔ Ü�5Ð1°4Ó8¸G×<NÑ<NÓNØ*.ˆEÔ'Ø ×+Ñ+Ó-ˆØÒ%Ø×.Ñ.¨~ß-6Ñ)Ð<Sð /õ Uð &øô9 ô Ü�5Ð0°%×8Ò8Ü"Ð#FÓGÈTÐQØ�\�\‹\ØŸ™ˆI÷ �\�\ˆ\úçô Ø9¼#¼d¿iºi»kÈJÕ>VÓ:WÐ9Xð YÜ" =Ó1Ð2°"ð6ó7à<@ðAð 	ðûð0 	×ÑÔ Ü�5Ð1°4Ó8¸G×<NÑ<NÓNØ*.ˆEÔ'Ø ×+Ñ+Ó-ˆØÒ%Ø×.Ñ.¨~ß-6Ñ)Ð<Sð /õ Uð &úsD   Á:D2 Â<G% Ä2>G"Å0FÅ=	G"ÆFÆG"Æ!AG"Ç"G% Ç%AIÉ Ic                  ób   € ] tR tRtRtR tRR/R R llt]R 4       tR	 t	R
 R lt
R R ltRtR# )Ú_RequestClientRegistryi  uz  Per-request client / stream-handle registry shared by the request worker
and the stranger threads (interrupt loop, stale detector) that may abort it.

``kind`` (``"openai"`` / ``"anthropic_messages"`` / ``"stream"``) routes
:meth:`close_once` (#67142). ``"stream"`` registers a stream handle: under the
MoA facade the singleton client has no per-request sockets, so interrupts
must close the stream object itself (#57354).

Thread-ownership rule (#29507): the owning worker pops + fully closes on its
way out. A *stranger* thread only aborts the sockets â€” never ``client.close()``
â€” avoiding the FD-recycling race where a just-closed TLS FD was reassigned to
``kanban.db`` and the live SSL BIO wrote into the SQLite header. The abort
happens under the lock: once released the worker may cache the client and the
NEXT call check it out. Stream handles are safe to close from any thread.
c                	ó~   € Wn         R V n        RV n        R V n        R V n        \
        P                  ! 4       V n        R # )NrÓ  )rU   rH  rX  Ú	owner_tidÚdiagr‘  r’  r“  ©rs   rU   s   &&r?   rq   Ú_RequestClientRegistry.__init__#  s1   € ØŒ
ØˆŒØˆŒ	ØˆŒØˆŒ	Ü—N’NÓ$ˆŽ	rB   rX  rÓ  c               ó   € V ^8„  d   QhRR/# )rG   rX  rI   rL   )rM   s   "r?   rN   Ú#_RequestClientRegistry.__annotate__+  s   € ÷ ñ ¨#ñ rB   c               	ó¸   € V P                   ;_uu_ 4        W\        P                  ! 4       uV n        V n        V n        R R R 4       V#   + '       g   i     T# ; ir:   )r“  r‘  Ú	get_identrH  rX  râ  )rs   rH  rX  s   &&$r?   Ú
set_clientÚ!_RequestClientRegistry.set_client+  s?   € Ø�Y�Y‹YØ5;Ä9×CVÒCVÓCXÐ2ˆDŒK˜œ D¤N÷ àˆ÷ ŽYàˆús   •)AÁA	c                	óv   € V \        V R R4      3 F%  p\        VRR4      p\        V4      '       g   K#  Vu # 	  R# )ro   NÚclose)rì   rú   )rû   Úownerrí  s   &  r?   Ú_stream_close_callableÚ-_RequestClientRegistry._stream_close_callable0  s<   € àœg f¨j¸$Ó?Ó@ˆEÜ˜E 7¨DÓ1ˆEÜ˜�ŒØ’ñ Añ rB   c                	óR   € V P                  V4      f   V# V P                  VRR7      # )Nrû   rW  )rï  rê  ©rs   rû   s   &&r?   Úset_stream_handleÚ(_RequestClientRegistry.set_stream_handle8  s,   € Ø×4Ñ4°VÓ<ÒDˆvÐpÈ$Ï/É/ÐZ`ÐgoÈ/ÓJpÐprB   c               ó    € V ^8„  d   QhRRRR/# ©rG   r·  rI   rJ   rK   rL   )rM   s   "r?   rN   rç  ;  s   € ÷ Yñ Y°3ð Y¸4ñ YrB   c                	óÎ   € V P                  V4      pVf   R #  V! 4        \        P                  RV4       R #   \         d"   p\        P	                  RY$4        R p?R # R p?ii ; i)Nz%Streaming response handle closed (%s)z/Streaming response handle close failed (%s): %s)rï  r[   ÚinforX   r—  )rs   rû   r·  rí  rò   s   &&&  r?   Ú_close_stream_handleÚ+_RequestClientRegistry._close_stream_handle;  sX   € Ø×+Ñ+¨FÓ3ˆØŠ=Ùð	YÙŒGÜ�K‰KÐ?ÀÖHøÜô 	YÜ�L‰LÐJÈF×XÒXûð	Yús   ™8 ¸A$ÁAÁA$c               ó    € V ^8„  d   QhRRRR/# rö  rL   )rM   s   "r?   rN   rç  E  s   € ÷ Sñ S ð S¨ñ SrB   c                	ó¢  € V P                   ;_uu_ 4        V P                  V P                  V P                  rCpVR 8g  ;'       d1    VRJ;'       d%    VRJ;'       d    V\        P
                  ! 4       8g  pV'       dH   VR8X  d   V P                  P                  MV P                  P                  pV! W!R7        RRR4       R# RV n        RV n        RRR4       Xf   R# XR 8X  d   V P                  W!4       R# VR8X  d   V P                  P                  W!R7       R# V P                  P                  W!R7       R#   + '       g   i     Ls; i)rû   NrU  rº  )r“  rH  rX  râ  r‘  ré  rU   Ú_abort_request_anthropic_clientr»  rù  Ú_close_request_anthropic_clientrÚ  )rs   r·  rd  Úrequest_kindrâ  Ústranger_threadr”  s   &&     r?   Ú
close_onceÚ!_RequestClientRegistry.close_onceE  s  € Ø�Y�Y‹YØ6:·k±kÀ4Ç9Á9ÈdÏnÉn¨)ˆNà Ñ(÷ 7ð 7Ø"¨$Ð.÷7ð 7à TÐ)÷7ð 7ð ¤×!4Ò!4Ó!6Ñ6ð	 ÷ ØGSÐWkÔGk˜Ÿ™×CÒCØ"Ÿj™j×EÑEð á�nÕ4Ø÷ ‰Yð ˆDŒKØ!ˆDŒN÷ ð Ò!ÙØ˜8Ô#Ø×%Ñ% nÖ=ØÐ1Ô1Ø�J‰J×6Ñ6°~Ð6ÖUà�J‰J×3Ñ3°NÐ3ÖR÷- �Yús#   •;D>ÁD>Á D>Á>=D>ÃD>Ä>E	)rU   rH  rã  rX  r“  râ  N)rƒ   r„   r…   r†   r‡   rq   rê  Ústaticmethodrï  ró  rù  r  rˆ   rL   rB   r?   rà  rà    sD   † ñò %ð°÷ ð
 ñó ðòqõY÷Sñ SrB   rà  r  c               ó   € V ^8„  d   QhRR/# rõ  rL   )rM   s   "r?   rN   rN   o  s   € ÷ -ñ -¨ñ -rB   c                óh  € ^ RI Hp \        V RR4      p\        V\        4      '       d   VP                  R4      RJ d   R# \        VP                  R4      ;'       g    R4      P                  4       P                  4       pW19  g&   VP                  V4      VP                  R	4      8  d   R# \        # )
zº``HIGH_EFFORT_SILENCE_FLOOR_SECONDS`` when the wire reasoning config is enabled at ``high`` or any
stronger :data:`~agent.reasoning_effort.EFFORT_LADDER` level (xhigh/max/ultra), else 0.)ÚEFFORT_LADDERÚreasoning_configNÚenabledFr^  Úeffortr§   Úhigh)Úagent.reasoning_effortr  rì   r|   rk   r}   rI   r©   rÒ   r  Ú!HIGH_EFFORT_SILENCE_FLOOR_SECONDS)rU   r  r÷  r	  s   &   r?   Ú_high_effort_silence_floorr  o  s�   € õ 5ä
�%Ð+¨TÓ
2€CÜ�cœ4× Ò  C§G¡G¨IÓ$6¸%Ó$?ÙÜ�—‘˜Ó"×(Ð( bÓ)×/Ñ/Ó1×7Ñ7Ó9€FØÔ" m×&9Ñ&9¸&Ó&AÀM×DWÑDWÐX^ÓD_Ô&_ÙÜ,Ð,rB   c                  óz   € ] tR tRt$ RtR]R&   R]R&   R]R&   R]R	&   R]R
&   R]R&   R]R&   R]R&   RtR]R&   RtR# )Ú_NonStreamWatchdogsi}  z3Poll-loop thresholds for one non-streaming request.r\  rg  rô   Úcodexr�   r[  Úttfb_enabledÚttfb_timeoutÚidle_enabledÚidle_timeoutÚidle_requires_progressr^  Úprogress_timeoutrL   N)rƒ   r„   r…   r†   r‡   Ú__annotations__r  rˆ   rL   rB   r?   r  r  }  s>   ‡ á=ØÓØƒKØƒOØÓØÓØÓØÓØ Ó Ø!Ð�e×!rB   r  c               ó    € V ^8„  d   QhRRRR/# )rG   rÚ  rk   rJ   r  rL   )rM   s   "r?   rN   rN   ‹  s#   € ÷ UZñ UZ°Dð UZÐ=Pñ UZrB   c                óö  a€ V P                  V4      pV P                  R8H  p\        V 4      p\        V4      oV'       d   \	        V 4      MRpRp\        V RR4      p\        V4      ;'       d    \        V4      pV'       d    V'       g   \        S4      p\        VS4      p\        V\        V3R lR 4       R4      4      p	Tp
\        RR4      R8g  p\        RR4      pV^ 8:  d   R	p
EMV'       dÁ   V'       g¹   \        R
R4      p\        P                  P                  RR4      P!                  4       P#                  4       R9   pV'       g1   V^ 8”  d*   SV8¼  d#   WÉ8  d   \$        P'                  RWÉSR V4       T	p\        RR4      pV^ 8”  d"   WÏ8”  d   \$        P'                  RWÏSR 4       TpM:V'       g3   V'       d+   \)        4       pVV8”  d   \$        P'                  RW|V4       TpV
'       d   V'       g   \        WÅ4      p\        RR4      R8g  p\        RV	4      pT;'       d    T;'       d    V^ 8„  ;'       d    V'       * p\+        Y#SY¬T;'       d    V^ 8„  TTV'       d   \,        R7	      # RR7	      # )ay  Stale-call timeout plus the Codex Responses stream watchdogs.

The stale detector kills a hung provider early so the retry loop can rotate
credentials / fall back. Codex adds two failure modes: accepting the connection
but never emitting an event (no-event TTFB cutoff; a reconnect succeeds in ~2s)
and stalling after substantive model progress begins (event-idle gap; any parsed SSE
event remains transport activity). Only the implicit official OpenAI Codex policy
for large contexts defers arming until progress; small requests, compatible backends,
and explicit overrides retain the legacy first-event semantics. Tunables:
HERMES_CODEX_TTFB_TIMEOUT_SECONDS,
HERMES_CODEX_EVENT_STALE_TIMEOUT_SECONDS (0 disables each),
HERMES_CODEX_TTFB_DISABLE_ABOVE_TOKENS / HERMES_CODEX_TTFB_STRICT,
HERMES_CODEX_TTFB_MAX_SECONDS (opt-in ceiling, default 0 = none), HERMES_CODEX_HARD_TIMEOUT_SECONDS.
rQ  r^  rt  Nc              3  ó>   <"  € T F  w  rSV8”  g   K  Vx € K  	  R # 5ir:   rL   )r›   rc  Údefaultr[  s   &  €r?   r�   Ú/_resolve_nonstream_watchdogs.<locals>.<genexpr>«  s!   øé € ÐyÑ+^Ñ'�YÐblÐoxÑbx�ŠÓ+^ùs   ƒ“
ç      ^@g      (@Ú!HERMES_CODEX_TTFB_TIMEOUT_SECONDSFÚ&HERMES_CODEX_TTFB_DISABLE_ABOVE_TOKENSg     ˆÃ@ÚHERMES_CODEX_TTFB_STRICTr§   z­Scaling codex-responses no-event TTFB watchdog from %.0fs to %.0fs for large request (context=~%s tokens >= %.0f). Set HERMES_CODEX_TTFB_STRICT=1 to keep the smaller cutoff.rÞ  ÚHERMES_CODEX_TTFB_MAX_SECONDSzyCapping codex-responses no-event TTFB timeout from %.0fs to %.0fs (context=~%s tokens) per HERMES_CODEX_TTFB_MAX_SECONDS.u´   Local provider detected (%s) â€” no-event TTFB watchdog raised from %.0fs to %.0fs (agent.local_stream_stale_timeout); set HERMES_CODEX_TTFB_TIMEOUT_SECONDS for an explicit cutoff.Ú(HERMES_CODEX_EVENT_STALE_TIMEOUT_SECONDS)	rg  r  r[  r  r  r  r  r  r  ))r_  rð  )r`  r  )rb  r7   g      ð¿>   Ú1ÚonÚyesÚtrue)rr  r`  rY  rP  r  rì   rô   r   re  rm  rj  rÃ   r3   rñ  rò  r}   r©   rÒ   r[   rø  rÿ  r  Ú$CODEX_FIRST_PROGRESS_TIMEOUT_SECONDS)rU   rÚ  rg  r  Úopenai_codex_backendÚeffort_floorÚcodex_floorrt  ÚlocalÚidle_defaultr  Úttfb_explicitr  Údisable_aboveÚstrictÚttfb_capÚlocal_ceilingÚidle_explicitr  Úprogress_gatedr[  s   &&                  @r?   Ú_resolve_nonstream_watchdogsr4  ‹  sq  ø€ ð" ×;Ñ;¸JÓG€MØ�N‰NÐ/Ñ/€EÜ3°EÓ:ÐÜ0°Ó<€Jß8=Ô-¨eÔ4À3€LØ€Kô �u˜j¨$Ó/€HÜ�‹N×:Ð:Ô0°Ó:€Eß—UÜ6°zÓBˆÜ9¸-ÈÓTˆä�|¤TÜyÑ+^ÓyØó&ó €Lð €LÜÐAÀ4ÓHÈDÑP€MÜÐ@À%ÓH€LØ�qÔØŠß	—uô "Ð"JÈHÓUˆÜ—‘—‘Ð :¸BÓ?×EÑEÓG×MÑMÓOÐSmÑmˆß˜-¨!Ô+°
¸mÔ0KÐP\ÔPkÜ�K‰Kð MàNZØ˜a�. =ô2ð (ˆLäÐ<¸cÓBˆØ�aŒ<˜LÔ3Ü�K‰Kð JØKWØ˜a�.ô#ð $ˆLøßŸuô <Ó=ˆØ˜<Ô'Ü�K‰Kð tà¨ô7ð )ˆLßŸMä˜<Ó6ˆô
 ÐHÈ$ÓOÐSWÑW€MÜÐGÈÓV€LØ×]Ð]Ð3×]Ð]¸Àa¹×]Ð]ÐP]ÔL]€NÜ¨]ÐT^Ø!È5×KeÐKeÐUaÐdeÑUeØ!¸.÷ BPÔ=ôZð Zð
 VYôZð ZrB   c               ó    € V ^8„  d   QhRRRR/# )rG   rÚ  rk   rJ   r  rL   )rM   s   "r?   rN   rN   ã  s   € ÷ ñ ¨tð ¸ñ rB   c                ó  € \        V R R4      p\        P                  ! \        4      ;_uu_ 4        \	        V4      '       d#   V! VP                  R4      R7      uuRRR4       #  RRR4       R#   + '       g   i     R# ; i)Ú_codex_silent_hang_hintNr‹  ©r‹  )rì   rª   r«   rX   rú   r}   )rU   rÚ  Úhint_fns   && r?   r7  r7  ã  sa   € Ü�eÐ6¸Ó=€GÜ	×	Ò	œY×	'Õ	'Ü�G×ÒÙ §¡°Ó!8Ô9÷ 
(Ò	'Ø÷ 
(ñ ÷ 
(Ö	'ñ ús   °)A/Á/B 	c               ó   € V ^8„  d   QhRR/# rO  rL   )rM   s   "r?   rN   rN   ì  s   € ÷ 6ñ 6¨dñ 6rB   c                óˆ   € \        V 4      '       d   \        W4      # \        V 4       ^ RIHp V! W4      P                  4       # )a?  Run the API call on a worker thread so the caller can detect interrupts
without waiting for the full HTTP round-trip. Each worker gets its own
per-request client (interrupts close only that one); a stale-call detector
kills the connection and raises so the main retry loop can back off / rotate
credentials / fall back.)Ú_NonStreamRequest)ro  rÞ  rì  Úagent.chat_completion_nonstreamr<  r;   )rU   rÚ  r<  s   && r?   Úinterruptible_api_callr>  ì  s9   € ô " %×(Ò(Ü˜uÓ1Ð1Ü˜ÔÝAá˜UÓ/×3Ñ3Ó5Ð5rB   c               ó   € V ^8„  d   QhRR/# rR  rL   )rM   s   "r?   rN   rN   ü  s   € ÷ ñ ¨tñ rB   c                óP   € \        \        V RR4      4      pV'       d   RV n        V# )u?  Consume the one-shot "answer without thinking" continuation flag.

Set by the length-continuation path when a request returned reasoning but NO
visible content (thinking ate the output cap); continuation turns never replay
prior reasoning, so thinking ON would re-burn the budget. When True the caller
overrides the wire reasoning_config with ``{"enabled": False, "effort": "none"}``
for exactly the next call. Prompt-cache cost is bounded to ONE cold prefix write
on config-sensitive providers (Anthropic, OpenAI) â€” far cheaper than four futile
full-budget continuations.
Ú_ephemeral_reasoning_offF)rô   rì   rA  )rU   Úconsumeds   & r?   Ú _consume_ephemeral_reasoning_offrC  ü  s(   € ô ”G˜EÐ#=¸uÓEÓF€HßØ).ˆÔ&Ø€OrB   c                óô  € V P                   p\        V 4      p\        V RR4      '       d
   RV n        R# Vf   ^ RIHp V! V 4      p\        V RR4      '       d~   \        V\        4      '       d`   VP                  R4      RJ g   VP                  R4      R8X  d5   \        V R	R4      '       d   ^ R
I	H
p / VCRRRV/CpWPn        V# RV n        R# Wn        V# V'       d   / T;'       g    / CRRRR/CpWn        V# )u�  ``agent.reasoning_config`` with the one-shot reasoning-off override applied.

Once the route has answered a disable with "reasoning is mandatory"
(``agent._reasoning_disable_rejected``), every disable â€” configured or
the one-shot continuation override â€” is dropped for the rest of the
session: the request goes out without a reasoning config and the route
applies its own default.
Ú_reasoning_effort_rejectedFN)Úunset_reasoning_defaultÚ_reasoning_disable_rejectedr  r	  ÚnoneÚ_reasoning_floor_required)ÚREASONING_FLOOR_EFFORTT)r  rC  rì   Ú_wire_reasoning_configÚagent.reasoning_paramsrF  r|   rk   r}   Úagent.auxiliary_reasoning_floorrJ  )rU   r÷  Úephemeral_offrF  rJ  Úflooreds   &     r?   Ú_reasoning_config_for_wirerP    s   € ð ×
 Ñ
 €CÜ4°UÓ;€MÜˆuÐ2°E×:Ò:ð (,ˆÔ$ÙØ
‚{õ 	CÙ% eÓ,ˆÜˆuÐ3°U×;Ò;ô �cœ4× Ò Ø�G‰G�IÓ %Ó'¨3¯7©7°8Ó+<ÀÔ+Fä�uÐ9¸5×AÒAÝRØT˜SÐT )¨T°8Ð=SÑT�Ø/6Ô,Ø�Ø+/ˆEÔ(ÙØ'*Ô$Øˆ
ßØA�#—)�)˜ÐA˜i¨°¸&ÑAˆð $'Ô Ø€JrB   c           	     óþ  € Ve   \        VR4      '       d   / Vn        V P                  R9   ;'       g    V P                  R8H  pV'       d	   V'       g   V#  ^ RIp^ RIHp \        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      pV'       d&   VP                  V4      pV! V4      w  r'Ve   Wqn        V#   \         d.   p\        P                  R\        T R	R
4      T4        Rp?T# Rp?ii ; i)a6  xAI chat-completions reserves ``tool_search`` and 400s when the bridge declares
it (#95003): rename the wire declaration; ``normalize_response`` maps calls back
via the transport's ``_last_wire_aliases`` (reset here so a stale map can't
reverse-map a name this request never aliased). Deep-copy first (#27907).NÚ_last_wire_aliaseszapi.x.ai)Ú"_rename_tool_search_bridge_for_xaic              3  ó¬   "  € T FJ  p\        V\        4      '       g   K  VP                  R 4      ;'       g    / P                  R4      R8H  x € KL  	  R# 5i)r¼  r¾  Útool_searchN©r|   rk   r}   ©r›   Úts   & r?   r�   Ú4_alias_tool_search_bridge_for_xai.<locals>.<genexpr>M  sC   é € ð 
ÙLYÀqÔ]gÐhiÔko×]pÔBˆQ�U‰U�:Ó×$Ð$ "×)Ñ)¨&Ó1°]ÖBËMùs   ‚AŸA·ATFu7   %sâš ï¸� Failed to alias tool_search bridge for xAI: %sÚ
log_prefixr§   >   Úxaiú	xai-oauth)ÚhasattrrR  r�  Ú_base_url_hostnameÚcopyÚ!agent.transports.chat_completionsrS  rÀ   ÚdeepcopyrX   r[   r\   rì   )	rU   Ú	transportÚtools_for_apiÚis_xai_chatÚ	_copy_xairS  Ú
has_bridgeÚ	alias_maprò   s	   &&&      r?   Ú!_alias_tool_search_bridge_for_xairh  @  s÷   € ð
 Ò¤¨Ð4H×!IÒ!IØ')ˆ	Ô$Ø—.‘.Ð$8Ñ8×bÐb¸E×<TÑ<TÐXbÑ<b€KßŸMØÐðyÛ ÝXß“Sñ 
ÙLYó
—S—S’Sñ 
ÙLYó
ó 
ˆ
÷ Ø%×.Ñ.¨}Ó=ˆMÙ'IÈ-Ó'XÑ$ˆMØÒ$Ø/8Ô,ð Ðøô ô yÜ�‰ÐPÔRYÐZ_ÐamÐoqÓRrÐtw×xÐxØÐûðyús*   ÁC Á,C Â C Â%C ÃC<Ã"C7Ã7C<c                ó6   € \        V RR4      pVe   RV n        V# )zUPop the one-shot ephemeral output cap; whichever path builds the request consumes it.Ú_ephemeral_max_output_tokensN)rì   rj  )rU   Úephemeral_outs   & r?   Ú_consume_ephemeral_max_outputrl  Z  s%   € ä˜EÐ#AÀ4ÓH€MØÒ Ø-1ˆÔ*ØÐrB   c                ó¨  € \        V R R4      p\        V 4      pV P                  4       P                  V P                  V P                  V4      TVe   TMV P                  Y0P                  V P                  4       V'       d   VP                  MR\        V RR4      VP                  R4      R8H  \        \        V RR4      4      R7      p\        WV4      # )Úcontext_compressorNÚ_anthropic_base_urlÚspeedÚfastÚ_oauth_1m_beta_disabledF)r‹  rG  rI  Ú
max_tokensr  Úis_oauthÚpreserve_dotsÚcontext_lengthrt  Ú	fast_modeÚdrop_context_1m_beta)rì   rl  Ú_get_transportÚbuild_kwargsr‹  Ú#_prepare_anthropic_messages_for_apirs  Ú_is_anthropic_oauthÚ_anthropic_preserve_dotsrv  r}   rô   r«  )rU   r›  rc  r  Úrequest_overridesÚctx_lenrk  rš  s   &&&&&   r?   Ú_build_anthropic_kwargsr€  b  sÅ   € Ü�eÐ1°4Ó8€GÜ1°%Ó8€MØ×+Ñ+Ó-×:Ñ:ÀÇÁØ×:Ñ:¸<ÓHÐP]Ø$1Ò$=‘=À5×CSÑCSØ)×4MÑ4MØ×4Ñ4Ó6ß18�w×-Ò-¸dÜ˜Ð 5°tÓ<Ø#×'Ñ'¨Ó0°FÑ:Ü!¤'¨%Ð1JÈEÓ"RÓSð ;ó UÐô 2°%È<ÓXÐXrB   c                ó´   € V P                  4       P                  V P                  YV P                  \	        V R R4      ;'       g    R\	        V RR4      VR7      # )Ú_bedrock_regionNr=  Ú_bedrock_guardrail_config)r‹  rG  rI  rs  rG  Úguardrail_configr  )ry  rz  r‹  rs  rì   )rU   r›  rc  r  s   &&&&r?   Ú_build_bedrock_kwargsr…  s  s[   € à×ÑÓ!×.Ñ.°U·[±[È<Ø×#Ñ#¬G°EÐ;LÈdÓ,S×,bÐ,bÐWbÜ  Ð(CÀTÓJÐ]mð /ó oð orB   c                ó¼  € ^ RI Hp ^ RIHp V! V 4      w  r‰p
V! WWšR7      pV	'       d3    ^ RIp^ RIHpHp VP                  V4      pV! V4      w  r/V! V4      w  r/\        V 4      pV P                  4       P                  V P                   V P#                  V4      TT\        V R	R4      YPP$                  Ve   TMV P&                  V P)                  4       T\        V R
R4      T
Y‰V
'       d   V P+                  4       MR\-        \        V RR4      4      V\        V RR4      R7      #   \         d-   p\        P                  R\        T RR4      T4        Rp?LúRp?ii ; i)rT  rU  )Ú$native_compaction_context_management)rX  Úis_xai_responsesÚis_github_responsesN)Ústrip_pattern_and_formatÚstrip_slash_enumu4   %sâš ï¸� Failed to sanitize tool schemas for xAI: %srZ  r§   r¢  r�  Ú_codex_reasoning_replay_enabledTÚtext_verbosity)r‹  rG  rI  r  r¢  Úcache_scope_idrt  rs  rT   r~  r�  r‰  rX  rˆ  Úgithub_reasoning_extraÚreplay_encrypted_reasoningÚcontext_managementr�  )rW  rV  Úagent.native_compactionr‡  r_  Útools.schema_sanitizerrŠ  r‹  ra  rX   r[   r\   rì   rl  ry  rz  r‹  Ú&_prepare_messages_for_non_vision_modelrt  rs  Ú_resolved_api_call_timeoutÚ#_github_models_reasoning_extra_bodyrô   )rU   r›  rc  r  r~  rŽ  rV  r‡  rX  rˆ  r‰  r‘  Ú_copyrŠ  r‹  Ú_rò   rk  s   &&&&&&            r?   Ú_build_codex_kwargsr™  z  s]  € ÝFÝLÙ>VÐW\Ó>]Ñ;ÐÐ(;ñ >¸eØ)ôTÐ÷
 ð	zÛ ßYØ!ŸN™N¨=Ó9ˆMÙ7¸ÓFÑˆMÙ/°Ó>ÑˆMô 2°%Ó8€MØ×ÑÓ!×.Ñ.°U·[±[Ø×=Ñ=¸lÓKÐS`Ø)´g¸eÀ\ÐSWÓ6XØ%·±Ø$1Ò$=‘=À5×CSÑCSØ×0Ñ0Ó2ÐFWÜ˜ 
¨DÓ1ÐGZØ)ßNa˜u×HÑHÔJÐgkÜ#'¬°Ð7XÐZ^Ó(_Ó#`Ø-¼gÀeÐM]Ð_cÓ>dð /ó 
fð 
føô ô 	zÜ�N‰NÐQÔSZÐ[`ÐbnÐprÓSsÐux×yÑyûð	zús   «1D$ Ä$EÄ/"EÅEc           "     ó´  a € S P                  4       p\        S Wb4      pS P                  4       pS P                  4       pS P                  p	\        V	R 4      ;'       g    \        V	R4      p
S P                  ;'       g    RP                  4       P                  4       R8H  pRRrÜ\        P                  ! \        4      ;_uu_ 4        ^ RIHpHp V! S P                  S P                   4      pVVJ pV'       d   RMTpRRR4       \#        S 4      pV'       d7   RS P$                  ;'       g    RR	\'        \(        P*                  ! 4       4      /MRpRp\        P                  ! \        4      ;_uu_ 4        ^ R
IHp V! S P                  4      pRRR4       \1        S 4      p^ RIHp V! VS P                  S P                   R7      p\7        R5/ RS P                  bRS P9                  V4      bRVbRS P                   bRS P;                  4       bRS P<                  bRVbRS P>                  bRVbRVbR\A        S RR4      bRVbRS PB                  bRT;'       g    RbRS PD                  bRS PG                  4       bRV'       d   S PI                  4       MRbRVb pV'       d   VPJ                  ! R5RV/VB # VPJ                  ! R5/ VBR S P                  ;'       g    RP                  4       R!TR"\        V	R#4      R$TR%T
R&\        V	R'4      R(\L        ;QJ d    V 3R) lR6 4       F  '       g   K   R*M	  RM! V 3R) lR6 4       4      R+\        V	R,4      R-S P                  R.8H  R/V'       d   S PN                  MRR0V'       d   S PP                  MRR1TR2TR3V
'       d   S PS                  4       MRR4S P                  /B #   + '       g   i     ELÁ; i  + '       g   i     ELE; i)7zmodels.github.aizgithubcopilot.comr§   ÚlmstudioFN)Ú_fixed_temperature_for_modelÚOMIT_TEMPERATUREÚ	sessionIdÚhermesÚpromptIdrŸ  )Úshape_wire_carriers)r‹  rt  r‹  rG  rI  rt  rT   rs  Úephemeral_max_output_tokensÚmax_tokens_param_fnr  r~  r¢  rŽ  Úollama_num_ctxÚprovider_preferencesÚopenrouter_min_coding_scoreÚsupports_reasoningÚlmstudio_reasoning_optionsÚqwen_session_metadataÚprovider_profileÚmodel_lowerÚis_openrouterÚis_nousznousresearch.comÚis_qwen_portalÚis_github_modelsÚis_nvidia_nimzintegrate.api.nvidia.comÚis_kimic              3  óP   <"  € T F  p\        SP                  V4      x € K  	  R # 5ir:   )r1   rt  )r›   ÚhrU   s   & €r?   r�   Ú1_build_chat_completions_kwargs.<locals>.<genexpr>Ô  s"   øé € ÐuÑFtÀÔ)¨%¯.©.¸!×<Ð<ÓFtùs   ƒ#&TÚis_tokenhubztokenhub.tencentmaas.comÚis_custom_providerÚcustomÚqwen_prepare_fnÚqwen_prepare_inplace_fnÚfixed_temperatureÚomit_temperaturer�  Úprovider_namerL   )zapi.kimi.comzmoonshot.aizmoonshot.cn)*ry  rh  Ú_is_qwen_portalÚ_is_openrouter_urlÚ_base_url_lowerr1   r�  r©   rÒ   rª   r«   rX   Úagent.auxiliary_clientrœ  r�  r‹  rt  r�  r¢  rI   ÚuuidÚuuid4r¦  r   rl  Úagent.reasoning_carriersr¡  rk   r”  r•  rs  Ú_max_tokens_paramrì   Ú_ollama_num_ctxr¦  Ú_supports_reasoning_extra_bodyÚ"_lmstudio_reasoning_options_cachedrz  rÀ   Ú_qwen_prepare_chat_messagesÚ#_qwen_prepare_chat_messages_inplacer–  )rU   r›  rc  r  r~  rŽ  rb  Ú_is_qwenÚ_is_orÚ_hostÚ_is_ghÚ_is_lmstudioÚ
_omit_tempÚ_fixed_temprœ  r�  Ú_ftÚ_prefsÚ
_qwen_metaÚ_profiler   Ú_ephemeral_outr¡  Ú_commons   f&&&&&                  r?   Ú_build_chat_completions_kwargsr×  �  sÝ  ø€ Ø×$Ñ$Ó&€IÜ5°e¸YÓV€Mà×$Ñ$Ó&€HØ×%Ñ%Ó'€FØ×!Ñ!€EÜ" 5Ð*<Ó=×rÐrÔAVÐW\Ð^qÓAr€FØ—N‘N×(Ð( b×/Ñ/Ó1×7Ñ7Ó9¸ZÑG€Lð $ T�Ü	×	Ò	œY×	'Õ	'ßYÙ*¨5¯;©;¸¿¹ÓGˆØÐ,Ð,ˆ
ß(‘d¨cˆ÷	 
(ô -¨UÓ3€Fç_g�+˜u×/Ñ/×;Ð;°8¸ZÌÌTÏZÊZË\ÓIZÑ[Ðmq€JØ€HÜ	×	Ò	œY×	'Õ	'Ý2Ù'¨¯©Ó7ˆ÷ 
(ô 3°5Ó9€NÝ<Ù& |¸5¿;¹;ÐQV×Q_ÑQ_Ô`€Lô ò 	*˜Ÿšð 	*¨u×/[Ñ/[Ð\hÔ/ið 	*Ùð	*Ø&+§n¢nð	*Ø>C×>^Ñ>^Ô>`ð	*à×#Ò#ð	*áAOð	*ð "×3Ò3ð	*ñ GWð	*ñ ,ð		*ô 9@ÀÀ|ÐUYÔ8Zð		*ñ
 &ð	*ð
 7<×6KÒ6Kð	*ð $Ÿ^˜^ tøð	*ð JO×IjÒIjð	*ð !×?Ñ?ÔAð	*÷ R^ 5×#KÑ#KÔ#MÐcgøð	*ñ )ð	*€G÷ à×%Ò%ÑK°xÐKÀ7ÑKÐKð ×!Ò!ñ Ø
ñà—[‘[×&Ð& B×-Ñ-Ó/ðð ðô & eÐ-?Ó@ð	ð
  ðð  ðô ,¨EÐ3MÓNð÷ “ÔuÑFtÓu——’ÔuÑFtÓuÓuðô *¨%Ð1KÓLðð !Ÿ>™>¨XÑ5ð÷ >F˜×9Ò9È4ð÷ NV × IÒ IÐ[_ðð &ðð $ð÷ OU˜u×HÑHÔJÐZ^ðð  —n‘nò!ð ÷E 
(×	'Ð	'ú÷ 
(×	'Ð	'ús   Ã6N2Å1OÎ2O	ÏO	c               ó$   € V ^8„  d   QhRRRRRR/# ©rG   r›  rÂ   rc  zlist | NonerJ   rk   rL   )rM   s   "r?   rN   rN   à  s"   € ÷ ñ ¨$ð ¸{ð ÐVZñ rB   c           
     ó~   € ^ RI Hp \        WV4      pV! V\        V RR4      \        V RR4      \        V RR4      4      # )ad  Build the keyword arguments dict for the active API mode.

Wraps the per-api_mode builder so the conversation-affinity headers (OpenCode's
``x-opencode-session``, a custom provider's opt-in ``session_affinity_header``) ride on
every request regardless of transport (chat_completions / codex_responses /
anthropic_messages). No-op for every other provider.
)Úmerge_session_affinity_headersr�  Nrt  r¢  )Úagent.opencode_affinityrÛ  Ú_build_api_kwargs_for_moderì   )rU   r›  rc  rÛ  Úkwargss   &&&  r?   Úbuild_api_kwargsrß  à  sH   € õ Gä'¨¸]ÓK€FÙ)ØÜ��z 4Ó(Ü��z 4Ó(Ü��| TÓ*ó	ð rB   c               ó$   € V ^8„  d   QhRRRRRR/# rÙ  rL   )rM   s   "r?   rN   rN   ó  s'   € ÷ lñ l°Dð lÈð lÐ`dñ lrB   c                ó(  € \        V 4      pVf   V P                  p\        V 4      pV P                  R8X  d   \	        WW#V4      # V P                  R8X  d   \        WW#4      # \        V 4      pV P                  R8X  d   \        M\        pV! WW#WE4      # )NrU  rY  rQ  )	rP  rI  r   r`  r€  r…  r˜  r™  r×  )rU   r›  rc  r  r~  rŽ  Úbuilders   &&&    r?   rÝ  rÝ  ó  s“   € ô 2°%Ó8ÐØÒØŸ™ˆô 4°EÓ:ÐØ‡~�~Ð-Ô-Ü& u¸MÐ]nÓoÐoØ‡~�~Ð+Ô+Ü$ U¸-ÓZÐZô 3°5Ó9€NØ%*§^¡^Ð7HÔ%HÕ!ÔNl€GÙ�5¨ÐIZÓkÐkrB   c                ój   €  V P                  RR7      #   \         d    T P                  4       u # i ; i)z“``model_dump(warnings=False)`` (avoids pydantic serializer UserWarnings on
generic-union SDK models), falling back for shims that reject the kwarg.F)Úwarnings)Ú
model_dumpr®   )r°  s   &r?   Ú_model_dump_saferæ    s4   € ð Ø�~‰~ uˆ~Ó-Ð-øÜô  Ø�~‰~ÓÒð ús   ‚ ”2±2c                ó@   € \        V R 4      '       d   \        V 4      # T # )rå  )r]  ræ  ©r‹   s   &r?   Ú_dump_if_modelré    s   € Ü&-¨e°\×&BÒ&BÔ˜EÓ"ÐMÈÐMrB   c               ó   € V ^8„  d   QhRR/# )rG   rJ   r  rL   )rM   s   "r?   rN   rN     s   € ÷ Vñ V¸=ñ VrB   c                óÄ  € V P                  V4      pV'       gh   \        \        VRR4      4      p\        P                  ! RV\        P
                  R7      pV'       d#   RP                  R V 4       4      ;'       g    RpV'       d8   V P                  '       d&   \        P                  ! R\        V4       RV 24       V'       ds   V P                  '       da   V P                  '       gO   V P                  '       g=   \        P                  ! \         4      ;_uu_ 4        V P                  V4       RRR4       V'       d   \#        V4      # T#   + '       g   i     L%; i)	zIStructured reasoning, else inline ``<think>`` blocks embedded in content.r¸  Nz<think>(.*?)</think>©Úflagsú

c              3  óp   "  € T F,  qP                  4       '       g   K  VP                  4       x € K.  	  R # 5ir:   )r©   )r›   Úbs   & r?   r�   Ú,_assistant_reasoning_text.<locals>.<genexpr>  s    é € Ð(V¹L°qÏGÉGÏI¬¨¯©¯¨»Lùs   ‚6ž6zCaptured reasoning (z	 chars): )Ú_extract_reasoningr   rì   r�   ÚfindallÚDOTALLrY   Úverbose_loggingÚloggingr—  r  Úreasoning_callbackÚstream_delta_callbackÚ_stream_callbackrª   r«   rX   r"   )rU   Úassistant_messageÚreasoning_textr¸  Úthink_blockss   &&   r?   Ú_assistant_reasoning_textrý    s÷   € à×-Ñ-Ð.?Ó@€NßÜ&¤wÐ/@À)ÈTÓ'RÓSˆÜ—z’zÐ"9¸7Ì"Ï)É)ÔTˆßØ#Ÿ[™[Ñ(V¹LÓ(VÓV×^Ð^ÐZ^ˆNß˜%×/×/Ð/Ü�ŠÐ,¬S°Ó-@Ð,AÀÈ>ÐJZÐ[Ô\÷
 ˜%×2×2Ð2¸5×;V×;VÐ;VÐ_d×_u×_uÐ_uÜ× Ò ¤×+Õ+Ø×$Ñ$ ^Ô4÷ ,ç3AÔ Ó/ÐUÀ~ÐU÷ ,×+ús   Ä EÅE	c           	     óê   € \        \        \        VR R4      4      4      p\        V\        4      '       d>   V'       d6   V P                  V4      P                  4       pV'       d   ^ RIHp V! V4      pV# )r¸  Nræ   )	r"   r   rì   r|   rI   Ú_strip_think_blocksr©   rë   rç   )rU   rú  r¸  rç   s   &&  r?   Ú_assistant_content_for_storager   (  s]   € ô
 #Ô#7¼Ð@QÐS\Ð^bÓ8cÓ#dÓe€GÜ�'œ3×Ò§GØ×+Ñ+¨GÓ4×:Ñ:Ó<ˆßÝ:Ù+¨GÓ4ˆGØ€NrB   c               ó    € V ^8„  d   QhRRRR/# )rG   r  r�   rJ   rk   rL   )rM   s   "r?   rN   rN   6  s   € ÷ .ñ .°sð .¸tñ .rB   c                óš  € \        VR R4      p\        VRR4      p\        V\        4      '       d   VP                  4       '       g   V P	                  V4      w  rE\        V\        4      '       d   VP                  4       '       gˆ   \        V\        4      '       d(   VP                  4       '       d   VP                  4       pMJ\        VRR4      pT P                  V'       d   \        VRR4      MRV'       d   \        VRR4      MRV4      pVP                  4       p\        VRR4      p\        V\        4      '       d   VP                  4       '       g   V P	                  V4      w  rWT P                  T\        V\        4      '       d   TMR4      pR VRVRVR	VP                  RRVP                  P                  RVP                  P                  //p\        VR
R4      p	V	e   \        V	4      VR
&   ^ RIHp
 V
! VR4      ;'       g    \        VP                  RR4      p\        V\        4      '       d   V'       d   W¸R,          R&   V# )ÚidNÚcall_idr¼  r¾  r§   r½  ú{}Úresponse_item_idrÜ   Úextra_content)rÖ   Úthought_signature)rì   r|   rI   r©   Ú_split_responses_tool_idÚ_deterministic_call_idÚ"_derive_responses_function_call_idrÜ   r¼  r¾  r½  ré  rÃ  rÖ   )rU   Ú	tool_callr  Úraw_idr  r˜  Ú_fnr  Útc_dictÚextrarÖ   Úfn_sigs   &&&         r?   Ú_assistant_tool_call_dictr  6  së  € Ü�Y  dÓ+€FÜ�i ¨DÓ1€GÜ�gœs×#Ò#¨7¯=©=¯?ª?Ø×3Ñ3°FÓ;‰
ˆÜ�gœs×#Ò#¨7¯=©=¯?ª?Ü�fœc×"Ò" v§|¡|§~¢~Ø—l‘l“n‰Gä˜) Z°Ó6ˆCØ×2Ñ2Ïs´7¸3ÀÈÔ3KÐXZß36”˜˜[¨$Ô/¸DÀ%óIˆGà�m‰m‹o€Gä˜yÐ*<¸dÓCÐÜÐ&¬×,Ò,Ð4D×4JÑ4J×4LÒ4LØ#×<Ñ<¸VÓDÑˆØ×?Ñ?ÀÜ&Ð'7¼×=Ò=ÑÀ4óIÐð �W˜i¨Ð2DÐFVØ�	—‘Ø�V˜Y×/Ñ/×4Ñ4°kÀ9×CUÑCU×C_ÑC_Ð`ðb€Gô" �I˜°Ó5€EØÒÜ#1°%Ó#8ˆ�Ñ å.Ù�9Ð1Ó2×lÐl´g¸i×>PÑ>PÐReÐgkÓ6l€FÜ�&œ#×Ò§6Ø39�
ÕÐ/Ñ0Ø€NrB   c               ó    € V ^8„  d   QhRRRR/# )rG   r  rI   rJ   rk   rL   )rM   s   "r?   rN   rN   g  s   € ÷ fñ fÀSð fÈTñ frB   c           
     óð  € \        VRR4      p\        W4      p\        RRR\        W4      RVRV/4      p\        VRR4      pVf>   \        VR	R4      ;'       g    / p\	        V\
        4      '       d   RV9   d
   VR,          pVe   \        V4      VR&   M:V'       d'   V P                  4       '       d   T;'       g    R
VR&   MV'       d   WER&   \        VRR4      '       d¨   . pVP                   F‰  p	\	        V	\
        4      '       d   VP                  V	4       K,  \        V	R4      '       d   VP                  V	P                  4       K[  \        V	R4      '       g   Ko  VP                  \        V	4      4       K‹  	  V'       d   W…R&   R F·  p
\        WR4      pV'       g   K  WµV
&   V
R8X  g   K&  ^ RIHp V! W.4      '       g   K=  \        V P                  RR4      p\!        V4      '       d   T! 4        ^ RIHp V! V R4       \        V RR4      ;p'       g   K’  ^ RIHp T! T\        V RR4      ;'       g    RR7       K¹  	  ^ RIHp V! V4      ;p'       dX   TP/                  VP1                  4        UUu/ uF  w  ppVR8w  g   K  VVbK  	  upp4       . VP3                  RR4      OVNVR&   V'       d/   \5        V4       UUu. uF  w  pp\7        V VV4      NK  	  uppVR&   V# u uppi u uppi )uM  Build a normalized assistant message dict (reasoning, reasoning_details,
optional tool_calls) shared by the tool-call and final-response paths.
Textless turns are NOT padded here: ``repair_empty_non_final_messages`` is the
single owner â€” write-time padding broke codex commentary turns and cannot
survive ``_rows_to_conversation``.r»  NÚroleÚ	assistantr¸  rº  r  r¹  Úmodel_extrarÎ   Úreasoning_detailsÚ__dict__rå  Úcodex_reasoning_items)Ú+has_replayable_native_compaction_checkpointÚ!note_native_compaction_checkpoint)Úset_usage_anchorÚ_current_task_id)Ú_reset_read_dedup_cachesr¢  r§   )r¢  )Úcarrier_recordrÜ   )Úanthropic_content_blocksÚbedrock_content_blocksr  Úcodex_message_itemsrL   )rì   rý  r    r   r|   rk   r"   Ú_needs_thinking_reasoning_padr  r~   r]  r  ræ  rW  r  rn  rú   Úagent.usage_anchorr  Úagent.conversation_compressionr  rÃ  r   r¨  r8  r}   r	  r  )rU   rú  r  Úassistant_tool_callsrû  ÚmsgÚraw_reasoning_contentr  Ú	preservedÚdr²  r‹   r  Únote_checkpointr  Útask_idr  r   Úrecordrœ   r.  ÚirÀ  s   &&&                    r?   Úbuild_assistant_messager0  g  sÛ  € ô #Ð#4°lÀDÓIÐÜ.¨uÓH€NÜ
! 6¨;ØÔ1°%ÓKÈ[ÐZhØ˜ð#(ó )€Cô $Ð$5Ð7JÈDÓQÐØÒ$ÜÐ/°ÀÓE×KÐKÈˆÜ�k¤4×(Ò(Ð-@ÀKÔ-OØ$/Ð0CÕ$DÐ!ØÒ(Ü#7Ð8MÓ#NˆÐÒ ß	 %×"EÑ"E×"GÒ"Gð $2×#8Ð#8°SˆÐÒ ß	ð  $2ÐÑ äÐ Ð"5°t×<Ò<ð ˆ	Ø"×4Ô4ˆAÜ˜!œT×"Ò"Ø× Ñ  Ö#Ü˜˜J×'Ò'Ø× Ñ  §¡Ö,Ü˜˜L×)Ô)Ø× Ñ Ô!1°!Ó!4Ö5ñ 5÷ Ø'0Ð#Ñ$ó wˆÜÐ)°Ó6ˆß‰5Ø�‰IØÐ.Ö.õñ ?¸uÀe×LÔLÜ&-Ø×0Ñ0Ð2UÐW[ó'�Oô   ×0Ò0Ù'Ô)õ Há(¨°Ô5ô #*¨%Ð1CÀTÓ"JÐJ�w×JÐJÝ[á0°ÄWÈUÐT`ÐbfÓEg×EmÐEmÐkm×nñ5 wõ8 8ÙÐ 1Ó2Ð2€vÖ2ð 	�
‰
 V§\¡\¤^ÔC¡^™T˜Q °q¸F±{”D�A�q’D¡^ÒCÔDØ#N S§W¡WÐ-@À"Ó%EÐ#NÀvÐ#NˆÐÑ çÜR[Ð\pÔRqÔrÑRqÉÈÈBÔ6°u¸bÀ!ÖDÑRqÒrˆˆLÑØ€Jùó Dùó ss   É;K,
ÊK,
Ë
K2c               ó$   € V ^8„  d   QhRRRRRR/# )rG   r‹  rI   r�  rJ   rK   rL   )rM   s   "r?   rN   rN   Ð  s!   € ÷ %ñ %°ð %¸sð %Àtñ %rB   c                óh  € \        V RR4      p\        V\        4      '       d	   V'       g   R# RV3RV33 Fr  w  rEV'       g   K  \        \        P
                  ! RV R2V4      4      pV'       g   K=  VR,          pVRVP                  4         V RV W7P                  4       R  2pKt  	  W0n        R# )	uV  Rewrite the cached prompt's ``Model:``/``Provider:`` lines after a provider switch.

Not persisted: the stored row keeps the primary's labels so a restored primary replays a
byte-identical prompt (prefix cache intact). Only the LAST occurrence of each line is touched â€”
earlier matches may be user content (memory snapshots, context files).Ú_cached_system_promptNÚModelÚProviderz(?m)^z: .*$r{   éÿÿÿÿ)	rì   r|   rI   rÂ   r�   Úfinditerr«  Úendr3  )rU   r‹  r�  ÚsprH   r‹   ÚmatchesÚlasts   &&&     r?   Úrewrite_prompt_model_identityr<  Ð  s¬   € ô 
�Ð/°Ó	6€BÜ�bœ#×Ò§bÙØ! 5Ð)¨J¸Ð+AÓB‰ˆßÙÜ”r—{’{ e¨E¨7°%Ð#8¸"Ó=Ó>ˆß‰7Ø˜2•;ˆDØ�}˜Ÿ
™
›Ð%Ð& u g¨R°¨w°r¿(¹(»*¸+°Ð6GÐHŠBñ Cð #%ÖrB   c               ó    € V ^8„  d   QhRRRR/# )rG   Úfbrk   rJ   ztuple[str, str, str]rL   )rM   s   "r?   rN   rN   ã  s   € ÷ ?ñ ?˜Dð ?Ð%9ñ ?rB   c                óf  € \        V P                  R 4      ;'       g    R4      P                  4       P                  4       \        V P                  R4      ;'       g    R4      P                  4       \        V P                  R4      ;'       g    R4      P                  4       P	                  R4      3# )r�  r§   r‹  rt  Ú/)rI   r}   r©   rÒ   rÐ   )r>  s   &r?   Ú_fallback_entry_keyrA  ã  s…   € Ü�—‘�zÓ"×(Ð( bÓ)×/Ñ/Ó1×7Ñ7Ó9¼3¸r¿v¹vÀg»×?TÐ?TÐRTÓ;U×;[Ñ;[Ó;]Ü�—‘�zÓ"×(Ð( bÓ)×/Ñ/Ó1×8Ñ8¸Ó=ð?ð ?rB   c               ó    € V ^8„  d   QhRRRR/# )rG   r>  rk   rJ   r  rL   )rM   s   "r?   rN   rN   è  s   € ÷ 
7ñ 
7¸4ð 
7ÀMñ 
7rB   c                ó  € VP                  R4      ;'       g    RP                  4       P                  4       R8w  d   R#  ^ RIHp V! R4      ;'       g    / p\        ;QJ d<    R TP                  R4      TP                  R	4      3 4       F  '       g   K   R
M1	  RM-! R TP                  R4      TP                  R	4      3 4       4      pT'       d   R# R#   \
         d#   pR\        T4      P                   2u Rp?# Rp?ii ; i)zGReturn a skip reason for fallback entries known to be unusable locally.r�  r§   rž  N)Úget_provider_auth_stateznous_auth_unreadable:c              3  ór   "  € T F-  p\        V\        4      ;'       d    VP                  4       x € K/  	  R # 5ir:   )r|   rI   r©   rW  s   & r?   r�   Ú>_fallback_entry_unavailable_without_network.<locals>.<genexpr>ñ  s*   é € ÐvÑ>u¸”J˜q¤#Ó&×4Ð4¨1¯7©7«9Ô4Ó>uùs   ‚7ž7Úaccess_tokenÚrefresh_tokenTFÚnous_token_missing)	r}   r©   rÒ   Úhermes_cli.authrD  rX   rÜ   rƒ   rÀ   )rU   r>  rD  Ústaterò   Ú	has_tokens   &&    r?   Ú+_fallback_entry_unavailable_without_networkrM  è  sÚ   € à
�‰ˆzÓ× Ð ˜b×'Ñ'Ó)×/Ñ/Ó1°VÔ;Ùð<Ý;Ù'¨Ó/×5Ð5°2ˆ÷ “Ñv¸u¿y¹yÈÓ?XÐZ_×ZcÑZcÐdsÓZtÑ>uÓv——’Ñv¸u¿y¹yÈÓ?XÐZ_×ZcÑZcÐdsÓZtÑ>uÓvÓv€Ißˆ4Ð6Ð"6Ð6øô ô <Ø&¤t¨C£y×'9Ñ'9Ð&:Ð;Õ;ûð<ús$   Á C ÁC ÃDÃ#D Ã:DÄ Dzauthentication failedz!authentication permanently failedzbilling or quota exhaustedz
rate limitzupstream model rate limitzprovider overloadedzprovider server errorzrequest timeoutz#TLS certificate verification failedzcontext window exceededzrequest payload too largezimage payload too largezmodel not foundz#provider policy blocked the requestz"content policy blocked the requestzrequest format rejectedz$adjacent same-role messages rejectedz"encrypted reasoning state rejectedz#multimodal tool content unsupportedzthinking signature rejectedzlong-context tier unavailablez#OAuth long-context beta unavailablezgrammar pattern rejectedúprovider failurec               ó    € V ^8„  d   QhRRRR/# )rG   r·  úFailoverReason | NonerJ   rI   rL   )rM   s   "r?   rN   rN     s   € ÷ jñ jÐ"7ð j¸Cñ jrB   c                ó´   € \         P                  V 4      pT;'       g;    \        \        V RR4      ;'       g    T ;'       g    R4      P	                  RR4      # )zCReturn a concise operator-facing explanation for a fallback switch.r‹   NrN  r˜  rÎ   )Ú_FALLBACK_REASON_LABELSr}   rI   rì   r.  )r·  rH   s   & r?   Ú_fallback_reason_textrS    sN   € ä#×'Ñ'¨Ó/€EØ×iÐi”Cœ ¨°Ó6×VÐV¸&×VÐVÐDVÓW×_Ñ_Ð`cÐehÓiÐirB   c               ó    € V ^8„  d   QhRRRR/# )rG   ÚurlrI   rJ   rô   rL   )rM   s   "r?   rN   rN     s   € ÷ ?ñ ? ð ?¨ñ ?rB   c                ó$   € ^ RI Hp V! V 4      R8H  # )uÇ   Same Messages-only host match as determine_api_mode() / _detect_api_mode_for_url(): api.anthropic.com,
a /anthropic suffix, or Kimi Code's api.kimi.com/coding (its /chat/completions 404s â€” #77256).)Úhost_mandated_api_moderU  )Úhermes_cli.providersrW  )rU  rW  s   & r?   Ú_is_anthropic_wire_urlrY    s   € õ <Ù! #Ó&Ð*>Ñ>Ð>rB   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	rG   r>  rk   Úfb_providerrI   Úfb_base_url_hintr  rJ   ztuple[bool, str]rL   )rM   s   "r?   rN   rN     s)   € ÷ %ñ % ð %°3ð %È-ð %Ð\lñ %rB   c                óJ  € ^ RI HpHp T! V P                  R4      ;'       g    V P                  R4      4      pV'       d   RV3# V'       d5   VR9  d.   V! V4      ;'       g    / P                  R4      pV'       d   RV3# VR8X  g   V'       d   \	        V4      '       d   R# R# )	ad  (explicit, api_mode) for a fallback entry from its ORIGINAL base_url: resolve_provider_client()
rewrites a dual-surface /anthropic base to /v1, losing the Anthropic wire signal. An explicit
``api_mode`` always wins (even "chat_completions") and suppresses later re-detection;
``provider: anthropic`` without a base_url still resolves to anthropic_messages.)Ú_get_named_custom_providerÚ_parse_api_moder`  rb  TÚ	anthropic>   rZ  r·  )FrU  )Frk  )Úhermes_cli.runtime_providerr^  r_  r}   rY  )r>  r[  r\  r^  r_  r  Údeclareds   &&&    r?   Ú_fallback_api_mode_hintrc    s“   € ÷
 Xá˜rŸv™v jÓ1×HÐH°R·V±V¸KÓ5HÓI€HßØ�Xˆ~Ð÷
 �{Ð*;Ô;Ù.¨{Ó;×AÐA¸r×FÑFÀzÓRˆßØ˜�>Ð!Ø�kÔ!×&6Ô;QÐRb×;cÒ;cØ*Ð*Ø$Ð$rB   c               ó(   € V ^8„  d   QhRRRRRRRR/# )rG   r[  rI   Úfb_modelÚfb_base_urlrJ   rL   )rM   s   "r?   rN   rN   5  s*   € ÷ ñ °Cð À3ð ÐUXð Ð]`ñ rB   c                ó¶  € VR8X  d   R# ^ RI Hp ^ RIHp V! W4      pVe	   V! Wb4      # VR9   d   ^ RIHp V! V4      # \        V4      '       d   R# V P                  V4      '       d   R# V P                  V4      '       g   V P                  W!R7      '       d   R# \        V4      pVR	8X  g*   VP                  R
4      '       d   \        VR4      '       d   R# R# )zŸRe-detect api_mode from provider / resolved base URL / model when the hint pass
landed on the chat_completions default (never called for an explicit api_mode).úopenai-codexrQ  )Úopencode_model_api_mode)Ú_opencode_family_for_custom)Únous_api_moderU  rk  )r�  Úbedrockzbedrock-runtime.zamazonaws.comrY  >   rž  r¤  r¥  )Úhermes_cli.modelsri  Ú"hermes_cli.runtime_provider_customrj  rX  rk  rY  Ú_is_azure_openai_urlÚ_is_direct_openai_urlÚ&_provider_model_requires_responses_apir2   r¯   r1   )	rU   r[  re  rf  ri  rj  Úopencode_familyrk  Úhosts	   &&&&     r?   Ú_fallback_api_mode_resolvedrt  5  sÉ   € ð �nÔ$Ù Ý9ÝNÙ1°+ÓK€OØÒ"ñ ' ÓAÐAØÐ=Ô=å6Ù˜XÓ&Ð&Ü˜k×*Ò*á#Ø×!Ñ! +×.Ò.Ù!à×"Ñ" ;×/Ò/°5×3_Ñ3_Ð`hÐ3_×3Ò3Ù Ü˜[Ó)€DØ�iÔ D§O¡OÐ4F×$GÒ$GÔLaÐbmÐo~×LÒLÙ!ÙrB   c               ó$   € V ^8„  d   QhRRRRRR/# )rG   r[  rI   re  rJ   rK   rL   )rM   s   "r?   rN   rN   T  s'   € ÷ pñ p¸ð pÈð pÐPTñ prB   c                ó  € \        V RR4      pVeg   \        VRR4      ;'       g    RP                  4       P                  4       pV'       d,   WA8w  d&   \        P	                  RWV4       R;V n        V n        \        V RR4      fP    ^ RIHp V! V4      pV'       d7   VP                  4       '       d   W`n        \        P	                  RW4       R# R# R# R#   \         d#   p\        P                  RYT4        Rp?R# Rp?ii ; i)	z¼Rebind the credential pool when the provider changes (else rate_limit/billing/auth recovery
mutates the wrong credentials and overwrites the fallback's base_url). Same-provider pool: kept.Ú_credential_poolNr�  r§   znFallback to %s/%s: clearing primary credential pool (pool_provider=%s) to prevent cross-provider contamination©Ú	load_poolz4Fallback to %s/%s: attached fallback credential poolz7Fallback to %s/%s: could not attach credential pool: %s)rì   r©   rÒ   r[   rø  rw  Ú_credential_pool_entry_idÚagent.credential_poolry  Úhas_credentialsrX   r—  )rU   r[  re  Úexisting_poolÚpool_providerry  Úfallback_poolrò   s   &&&     r?   Ú _rebind_fallback_credential_poolr€  T  sõ   € ô ˜EÐ#5°tÓ<€MØÒ Ü  °
¸BÓ?×EÐEÀ2×LÑLÓN×TÑTÓVˆß˜]Ô9Ü�K‰Kð AØ }ô6ð HLÐKˆEÔ" UÔ%DÜˆuÐ(¨$Ó/Ò7ð	pÝ7Ù% kÓ2ˆMß ×!>Ñ!>×!@Ò!@Ø)6Ô&Ü—‘ÐRÐT_Öjñ "A‰}ñ	 8øô ô 	pÜ�L‰LÐRÐT_Ðkn×oÒoûð	pús$   ÂC ÂC Â4C ÃDÃ#D Ä Dc               ó   € V ^8„  d   QhRR/# rÊ  rL   )rM   s   "r?   rN   rN   j  s   € ÷ ñ Ð^bñ rB   c           	     óî   € V\         P                  8w  d   \        P                  RW$V4       R# ^ RIHpHp V! V! 4       4      ;'       g    RpVR8X  d   RMRV R2p	\        P                  RW‚W4WY4       R# )	a  A billing switch is a WARNING naming the profile, both models and the remedy: the gateway
persists the turn as a transient failure otherwise, and nothing in the log says the paid
model was refused for credits or how to fix it (#115702). Other reasons stay INFO.u"   Fallback activated: %s â†’ %s (%s)N)Úget_hermes_homeÚprofile_name_for_homer  zhermes modelz
hermes -p z modelu‘   Profile %s: %s via %s refused for billing/credits â€” using fallback %s via %s. Top up credits, or run `%s` to pick a model this account can use.)r   Úbillingr[   rø  rŠ  rƒ  r„  r\   )
rU   r·  Ú	old_modelÚold_providerre  r[  rƒ  r„  ÚprofileÚremedys
   &&&&&&    r?   Ú_log_fallback_activatedrŠ  j  sn   € ð ”×'Ñ'Ô'Ü�‰Ð8¸)È{Ô[ÙßGÙ#¡OÓ$5Ó6×CÐC¸)€GØ&¨)Ô3‰^¸:ÀgÀYÈfÐ9U€FÜ
‡N�Nð	Là˜L°KörB   c               ó    € V ^8„  d   QhRRRR/# ©rG   r·  rP  rJ   rô   rL   )rM   s   "r?   rN   rN   {  s   € ÷ ñ Ð-Bð Àtñ rB   c                óÊ   € ^ RI Hp V P                  '       dK   W9  dE   \        \	        V R^ 4      ;'       g    ^ \
        P                  ! 4       \        ,           4      V n        R# )záChain exhausted (always False). A non-empty chain walked on a non-rate-limit failure arms a
short cooldown so next turn's restore_primary_runtime stays gated instead of replaying the whole
context across every provider again.)Ú_RATE_LIMIT_FAILOVER_REASONSÚ_rate_limited_untilF)	Úagent.fallback_cooldownrŽ  Ú_fallback_chainrj  rì   r  Ú	monotonicÚ_FALLBACK_EXHAUSTED_COOLDOWN_Sr�  )rU   r·  rŽ  s   && r?   Ú_fallback_chain_exhaustedr”  {  sN   € õ EØ××Ð Ô!KÜ$'Ü�EÐ0°!Ó4×9Ð9¸¼4¿>º>Ó;KÔNlÕ;ló%nˆÔ!árB   c               ó$   € V ^8„  d   QhRRRRRR/# )rG   r[  rI   re  rJ   rô   rL   )rM   s   "r?   rN   rN   †  s!   € ÷ 6ñ 6°#ð 6Àð 6Èñ 6rB   c                ó¸  € \        V RR4      pVe9   \        VRR4      ;'       g    RP                  4       P                  4       V8w  d    ^ RIHp V! V4      pVe/   VP                  4       '       d   VP                  VR7      '       d   R# VP                  VR7      pVRJ ;'       g     V\        P                  ! 4       ,
          R8„  #   \
         d     R# i ; i)	a  True when every credential the candidate would use sits in an exhaustion cooldown longer
than the retry loop's longest wait (the 600s Retry-After cap): switching to it only fails the
turn the same way the primary just did (#89401). A short throttle still gets its chance.rw  Nr�  r§   rx  Fr8  rŽ   )
rì   r©   rÒ   r{  ry  rX   r|  Úhas_availableÚnext_available_atr  )rU   r[  re  r}  ry  Úuntils   &&&   r?   Ú_candidate_pool_exhaustedrš  †  sÉ   € ô �5Ð,¨dÓ3€DØ‚|œ  j°"Ó5×;Ð;¸×BÑBÓD×JÑJÓLÐP[Ô[ð	Ý7Ù˜[Ó)ˆDð ‚|˜4×/Ñ/×1Ò1°T×5GÑ5GÈhÐ5G×5WÒ5WÙØ×"Ñ"¨Ð"Ó2€EØ�Dˆ=×5Ð5˜E¤D§I¢I£KÕ/°#Ñ5Ð5øô ô 	Úð	ús   ÁC
 Ã
CÃCc               ó0   € V ^8„  d   QhRRRRRRRRRR	R
R/# )rG   r>  rk   Úfb_keyÚtupler[  rI   re  Úunavailabler³  rJ   rô   rL   )rM   s   "r?   rN   rN   —  s:   € ÷ !ñ !¨tð !¸Uð !ÐQTð !Ð`cð !Ðruð !Ðz~ñ !rB   c                ó  € W%9   d   \         P                  RV4       R# V'       d	   V'       g   R# ^ RIHp V! WV4      '       d   \         P	                  RW44       R# \        WV4      '       d   \         P                  RW44       R# \        W4      pV'       d+   VP                  V4       \         P                  RW4V4       R# ^ RI	H
pHp	 TP                  \        V RR	4      \        V R
R	4      \        \        V RR	4      ;'       g    R	4      R7      p
TP                  Y4VP                  R4      ;'       g    R	R7      pV	! Wº4      '       d8   \         P                  RY4V
P                   ;'       g    V
P"                  4       R# R# )z¡True when the entry is already unavailable, malformed, locally unusable, or resolves
to the backend that just failed (falling back to it would loop the failure).z/Fallback skip: %s previously marked unavailableT)Ú_is_entitlement_rejectedz@Fallback skip: %s/%s was rejected as unentitled for this accountzKFallback skip: %s/%s credential pool is exhausted (every entry in cooldown)zMFallback skip: %s/%s is not locally usable (%s); suppressing for this session)ÚBackendIdentityÚshould_skip_candidater�  r§   r‹  rt  )r�  r‹  rt  zUFallback skip: chain entry %s/%s resolves to the same backend as the current one (%s)F)r[   r—  r�  r   rø  rš  r\   rM  ÚaddÚagent.backend_identityr¡  r¢  Úbuildrì   rI   r}   rt  r�  )rU   r>  rœ  r[  re  rž  r   Úlocal_skip_reasonr¡  r¢  Úcurrent_identÚfb_idents   &&&&&&      r?   Ú_should_skip_fallback_candidater©  —  sR  € ð ÔÜ�‰ÐFÈÔOÙßŸhÙÝ@Ù °H×=Ò=Ü�‰ÐVÐXcÔnÙÜ  °X×>Ò>Ü�‰ÐdÐfqÔ|ÙÜCÀEÓNÐßØ�‰˜ÔÜ�‰ÐfÐhsð  @Qô  	RÙ÷
 NØ#×)Ñ)´7¸5À*ÈbÓ3QÜ�e˜W bÓ)´C¼ÀÀzÐSUÓ8V×8\Ð8\ÐZ\Ó4]ð *ó _€Mà×$Ñ$¨kÐUW×U[ÑU[Ð\fÓUg×UmÐUmÐkmÐ$Óo€HÙ˜X×5Ò5Ü�‰ØcØ =×#9Ñ#9×#SÐ#S¸]×=SÑ=Sô	Uñ ÙrB   c               ó   € V ^8„  d   QhRR/# rÊ  rL   )rM   s   "r?   rN   rN   »  s   € ÷ 2ñ 2°$ñ 2rB   c                óð  € \        V RR4      pV'       g   R# ^ RIHp T! V P                  V P                  \        V P                  \        4      '       d   V P                  MRV P                  \        V RR4      \        V RR4      R7      pVP                  V P                  W0P                  \        V RR4      V P                  V P                  R	7       \        V R
R4      RJ d   ^ RIHp V! V 4       R# R# )z’Point compression limits at the fallback model's context window (not the primary's),
respecting the explicit model.context_length config override.rn  N)Úget_model_context_lengthr§   Ú_config_context_lengthÚ_custom_providers)rt  Úapi_keyr�  Úconfig_context_lengthÚcustom_providersr¯  )r‹  rv  rt  r¯  r�  r`  Ú _compression_feasibility_checkedFT)Ú"revalidate_compression_feasibility)rì   Úagent.model_metadatar¬  r‹  rt  r|   r¯  rI   r�  Úupdate_modelr`  r&  r³  )rU   Ú
compressorr¬  Úfb_context_lengthr³  s   &    r?   Ú#_update_fallback_context_compressorr¸  »  sÑ   € ô ˜Ð 4°dÓ;€JßÙÝ=Ù0Ø�‰˜eŸn™nÜ!+¨E¯M©M¼3×!?Ò!?�—’ÀRØ—‘Ü% eÐ-EÀtÓLÜ  Ð(;¸TÓBôÐð ×ÑØ�k‰kÐ*;ÇnÁnÜ˜˜y¨"Ó-¸¿¹ÐQV×Q_ÑQ_ð ô ô ˆuÐ8¸%Ó@ÀDÓHÝUÙ*¨5Ö1ñ IrB   c               ó   € V ^8„  d   QhRR/# rÊ  rL   )rM   s   "r?   rN   rN   Õ  s   € ÷ }ñ }°4ñ }rB   c                ó8  €  ^ RI Hp ^ RIHp T! V! 4       ;'       g    / V P                  4      V n        \        P                  RV P                  V P
                  4       R#   \         d-   p\        P                  RT P                  T4        Rp?R# Rp?ii ; i)zœPer-model override > global reasoning_effort (YAML False = disabled); a config load
failure keeps the current reasoning_config rather than killing the swap.)Úload_config)Úresolve_reasoning_configz*Fallback %s: reasoning_config resolved: %szGFailed to resolve reasoning_config for fallback %s; keeping current: %sN)
r‰  r»  rŠ  r¼  r‹  r  r[   rø  rX   r—  )rU   r»  r¼  Ú_reasoning_errs   &   r?   Ú$_reresolve_fallback_reasoning_configr¾  Õ  sv   € ð}õ 	2Ý=Ù!9¹+»-×:MÐ:MÈ2ÈuÏ{É{Ó![ˆÔÜ�‰Ð@À%Ç+Á+Èu×OeÑOeÖføÜô }Ü�‰Ð^Ð`e×`kÑ`kÐm{×|Ò|ûð}ús   ‚A" žAA" Á"BÁ-!BÂBc               ó(   € V ^8„  d   QhRRRRRRRR/# )rG   r†  rI   r‡  Úold_base_urlrJ   rK   rL   )rM   s   "r?   rN   rN   ã  s0   € ÷ pñ p°3ð pÀcð pÐY\ð pÐaeñ prB   c           	     óà  €  ^ RI HpHp \        V RR4      ;'       g    . pV! W!W6R7      ;'       g    / p\	        \        V R/ 4      ;'       g    / 4      pVP                  R4      p	\        V	\        4      '       df   V'       d^   V	P                  4        U
Uu/ uF  w  r«W§9   d   W·V
,          8X  d   K  W«bK  	  pp
pV'       d   WÈR&   MVP                  RR4       W€n	        V! W4       \        P                  RV P                  \        V R/ 4      ;'       g    / P                  R4      4       R# u upp
i   \         d-   p\        P                  RT P                  T4        Rp?R# Rp?ii ; i)	u[  Drop the OLD provider's custom_providers-contributed extra_body keys, then merge the fallback
provider's own. KEY-SCOPED: a key is dropped only if its value still equals what the old provider's
config injected â€” a caller override of the same key won at init and differs, so it survives;
keys the new provider redefines are re-added by the merge.)Ú%_custom_provider_extra_body_for_agentÚ!_merge_custom_provider_extra_bodyr®  N)r�  r‹  rt  r±  r~  r¡  z$Fallback %s: extra_body resolved: %szAFailed to resolve extra_body for fallback %s; keeping current: %s)Úagent.agent_initrÂ  rÃ  rì   rk   r}   r|   r8  rD  r~  r[   rø  r‹  rX   r—  )rU   r†  r‡  rÀ  rÂ  rÃ  r±  Úold_provider_ebÚ	overridesÚexisting_ebrœ   r.  ÚscrubbedÚ_eb_errs   &&&&          r?   Ú_rescope_fallback_extra_bodyrÊ  ã  sS  € ð
pßmÜ" 5Ð*=¸tÓD×JÐJÈÐÙ?ÈÐq}ô  b÷  hð  hð  fhˆÜœ Ð(;¸RÓ@×FÐFÀBÓGˆ	Ø—m‘m LÓ1ˆÜ�k¤4×(Ò(¯_Ø)4×):Ñ):Ô)<ÔwÑ)<¡ ÀQÔEYÐ^_ÐstÕcuÑ^uœ˜šÑ)<ˆHÑwßØ*2˜,Ò'à—‘˜l¨DÔ1Ø&/Ô#Ù)¨%ÔBÜ�‰Ð:¸E¿K¹KÌ'ÐRWÐYlÐnpÓJq×JwÐJwÐuw×I|ÑI|ð  ~Jó  JKö  	Lùó xøô ô pÜ�‰ÐXÐZ_×ZeÑZeÐgn×oÒoûðpúsL   ‚D6 žD6 ²D6 Á5D6 ÂD6 ÂD0Â3D0Â9AD6 ÄD6 Ä0D6 Ä6E-Å!E(Å(E-c               ó    € V ^8„  d   QhRRRR/# )rG   ÚnoticerI   rJ   rK   rL   )rM   s   "r?   rN   rN   û  s   € ÷ Yñ Y¨3ð Y°4ñ YrB   c                óÎ   € V P                  V4       \        V RR4      p\        V\        4      '       d   VP	                  V4       R# V'       d   \        V4      V.MV.V n        R# )z¡Buffer the switch notice for terminal failure AND retain it as a durable one-shot for
_emit_pending_fallback_notice (a successful fallback clears retry chatter).Ú_pending_fallback_noticeN)rà  rì   r|   rÂ   r~   rI   rÎ  )rU   rÌ  Úpendings   && r?   Ú_buffer_fallback_noticerÐ  û  sS   € ð 
×#Ñ# FÔ+Ü�eÐ7¸Ó>€GÜ�'œ4× Ò Ø�‰�vÖçCJ¬#¨g«,¸Ñ)?ÐQWÐPXˆÖ&rB   c               ó    € V ^8„  d   QhRRRR/# rŒ  rL   )rM   s   "r?   rN   rN     s   € ÷ :ñ :Ð)>ð :ÐY]ñ :rB   c                ó˜  € ^ RI HpHp V! WV4      '       d   R# V! WVR7      p V P                  \	        V P
                  4      8¼  d   \        W4      # V P
                  V P                  ,          pV ;P                  ^,          un        \        V4      p\        V RR4      f   \        4       V n
        V P                  pVP                  R4      ;'       g    RP                  4       P                  4       p	VP                  R	4      ;'       g    RP                  4       p
\        WWyW¨4      '       d   EK   ^ R
IHp V! WWš4      pVf+   \"        P%                  RV	4       VP'                  V4       EKO  Vw  rÞV P(                  p
\+        W
V	4       RV RV R\-        V4       RV
 RV	 R2pVeR   \/        ^ \0        P2                  ! V P4                  \6        P8                  ! 4       ,
          4      4      pVRV R2,          p\;        W4       RV n        \?        V
4      \?        V	4      3V n         \C        WWÞW©4       ^ RI"H#p V! WéVR7       \I        V 4       ^ RI%H&p V! V P(                  V PN                  W™R8H  R7      V n(        R#   \R         d<   pT	R8X  d   TP'                  T4       \"        PU                  RT
T4        Rp?EK   Rp?ii ; i)u  Switch to the next fallback model/provider in the chain; False when exhausted. Swaps client,
model slug and provider in place so the retry loop continues on the new backend; client
construction goes through resolve_provider_client (no duplicated providerâ†’key mappings).)Ú_arm_rate_limit_cooldownÚswitch_deferred_by_resetF)Úreset_atTÚ_unavailable_fallback_keysNr�  r§   r‹  )Úbind_route_entryz.Fallback to %s failed: provider not configuredu   âš ï¸� Model fallback: z via z unavailable (z	); using r$  z Primary retry eligible in ~z s; recovery is not guaranteed.)Úrecord_fallback)Úfrom_providerÚto_providerr·  )Ú&resolve_native_compaction_capabilitiesrh  )r‹  rt  r�  rX  rž  z"Failed to activate fallback %s: %s)+r�  rÓ  rÔ  Ú_fallback_indexr  r‘  r”  rA  rì   r³  rÖ  r}   r©   rÒ   r©  Úagent.route_bindingr×  r[   r\   r£  r‹  r<  rS  rj  r~  Úceilr�  r  r’  rÐ  Ú_provider_fallback_activerI   Ú_provider_fallback_routerŠ  Ú.hermes_cli.observability.shared_metrics_eventsrØ  rÏ  r’  rÛ  rt  Úruntime_capabilitiesrX   r5   )rU   r·  rÕ  rÓ  rÔ  Úcooldown_secondsr>  rœ  rž  r[  re  r×  Úboundr†  r‡  rÌ  r  rØ  rÛ  Úes   &&&                 r?   Útry_activate_fallbackræ    s€  € ÷ [Ù ¨x×8Ò8ÙÙ/°ÈÔQÐØ
Ø× Ñ ¤C¨×(=Ñ(=Ó$>Ô>Ü,¨UÓ;Ð;Ø×"Ñ" 5×#8Ñ#8Õ9ˆØ×Ò Õ"ÕÜ$ RÓ(ˆÜ�5Ð6¸Ó=ÒEÜ/2«uˆEÔ,Ø×6Ñ6ˆØ—v‘v˜jÓ)×/Ð/¨R×6Ñ6Ó8×>Ñ>Ó@ˆØ—F‘F˜7“O×)Ð) r×0Ñ0Ó2ˆÜ*¨5°fÈ8×aÒaÚð$	Ý<Ù$ U°ÓFˆEØŠ}Ü—‘ÐOÐQ\Ô]Ø—‘ Ô'ÚØ&+Ñ#ˆIØ—{‘{ˆHÜ)¨%¸;ÔGð *¨)¨°E¸,¸ð HÜ)¨&Ó1Ð2°)¸H¸:ÀUÈ;È-ÐWXðZð ð  Ò+Ü ¤4§9¢9¨U×-FÑ-FÌÏÊÓIYÕ-YÓ#ZÓ[�	ØÐ8¸¸ÐCbÐcÕc�Ü# EÔ2ð /3ˆEÔ+Ü.1°(«m¼SÀÓ=MÐ-NˆEÔ*Ü# E°9ÈHÔbÝVÙ¨,ÐX^Õ_ô   Ô&ÝVÙ)OØ—k‘k¨E¯N©NÀ[ð  sAñ  dAô*BˆEÔ&áøÜô 	Ø˜fÔ$Ø—‘ Ô'Ü�L‰LÐ=¸xÈÔKÞûð		ús   Ä6:J Å3DJ ÊK	Ê/KËK	z>I reached the iteration limit and couldn't generate a summary.c               ó    € V ^8„  d   QhRRRR/# )rG   rG  rÂ   rJ   rL   )rM   s   "r?   rN   rN   K  s   € ÷ Lñ L°Tð L¸dñ LrB   c                ó&  € V P                  4       pV P                  pV'       dO   V P                  R8X  d>   \        \        V RR4      RR4      pT;'       g    / P	                  R4      ;'       g    Tp. pV F¡  pVP                  4       pV P                  Wg4       \         F  pVP                  VR4       K  	  VP	                  R4      R8X  d   VP                  RR4       \        V4       V'       d   V P                  WsR	7       VP                  V4       K£  	  V P                  ;'       g    R
p	V P                  '       d)   V	R,           V P                  ,           P                  4       p	V	'       d   RRRV	/.V,           p\        V P                   ;'       g    R4       F6  w  r«TP#                  V	'       d   ^M^ V
,           VP                  4       4       K8  	  V P%                  V4      p^ RIHpHp V! W]! V 4      4       \-        W4       V P/                  V4      pV Fg  p\1        V\2        4      '       g   K  V Uu. uF6  p\1        V\4        4      '       g   K  VP7                  R4      '       g   K4  VNK8  	  up F  pW K  	  Ki  	  V FD  p\1        VP	                  R4      \4        4      '       g   K*  VR,          P                  4       VR&   KF  	  ^ RIHpHp V! V4       V Uu. uF  pV! V4      NK  	  pp\?        V4       V# u upi u upi )a«  Wire-ready messages for the summary call, mirroring the main loop's api_messages build
(sidecar substitution, tool-call repair, thinking-only drop, underscore-key sweep).

``reasoning_details`` is kept: the anthropic_messages converter rebuilds signed thinking
blocks from it, and the chat-completions transport already drops it on the wire for routes
that do not replay it (``_chat_summary_attempt`` -> ``_build_api_kwargs``).rZ  rH  NÚlast_aggregator_slotr‹  r  Útoolr¾  r8  r§   rî  Úsystemr¸  )Ú evict_stale_outbound_tool_imagesÚoutbound_retired_image_idsr˜  )Ú_canonicalize_api_tool_callsÚ_clone_message_for_sendrL   ) Ú_should_sanitize_tool_callsr‹  r�  rì   r}   r_  Ú_copy_reasoning_content_for_apiÚ_SUMMARY_FOREIGN_MESSAGE_KEYSrD  r   Ú#_sanitize_tool_calls_for_strict_apir~   r3  Úephemeral_system_promptr©   r	  Úprefill_messagesÚinsertÚ_sanitize_api_messagesÚagent.context_compressorrì  rí  r&   Ú#_drop_thinking_only_and_merge_usersr|   rk   rI   r¯   Úagent.conversation_looprî  rï  r!   )rU   rG  Úneeds_sanitizeÚsanitize_modelÚagg_slotr›  r(  Úapi_msgrÅ   Úeffective_systemÚidxÚpfmrì  rí  rœ   Úinternal_keyrî  rï  Úms   &&                 r?   Ú_iteration_summary_api_messagesr  K  s—  € ð ×6Ñ6Ó8€NØ—[‘[€Nß˜%Ÿ.™.¨EÔ1äœ7 5¨(°DÓ9Ð;QÐSWÓXˆØ"Ÿ.˜. b×-Ñ-¨gÓ6×HÐH¸.ˆØ€LÛˆØ—(‘(“*ˆØ×-Ñ-¨cÔ;ß0ˆCØ�K‰K˜˜TÖ"ñ 1ð
 �;‰;�vÓ &Ô(Ø�K‰K˜ Ô%ô 	˜wÔ'ßØ×5Ñ5°gÐ5ÔTØ×Ñ˜GÖ$ñ- ð0 ×2Ñ2×8Ð8°bÐØ×$×$Ð$Ø,¨vÕ5¸×8UÑ8UÕU×\Ñ\Ó^ÐßØ ¨9Ð6FÐGÐHÈ<ÕWˆÜ˜e×4Ñ4×:Ð:¸Ö;‰ˆØ×Ñ×"2™Q¸¸SÕ@À#Ç(Á(Ã*ÖMñ <ð ×/Ñ/°Ó=€LçeÙ$ \Ð3MÈeÓ3TÔUô % UÔ9ð ×<Ñ<¸\ÓJ€LÛˆÜ�gœt×$Ô$Ù,3Ó `©G q´zÀ!ÄS×7I¤ÈaÏlÉlÐ[^×N_§ ©GÔ `�ØÒ)ó !añ  ó  ˆÜ�g—k‘k )Ó,¬c×2Ô2Ø!(¨Õ!3×!9Ñ!9Ó!;ˆG�IÓñ  ÷ ^Ù  Ô.ñ 9EÓE¹°1Ñ+¨AÖ.¹€LÐEÜ! ,Ô/ØÐùò !aùò Fs   È?L	ÉL	É5L	Ë)Lc               ó    € V ^8„  d   QhRRRR/# )rG   Úapi_request_idrI   Úretry_countr�   rL   )rM   s   "r?   rN   rN   š  s   € ÷ ñ °ð ÐY\ñ rB   c               óþ   € ^ RI Hp TP                  Y#\        \	        V RR4      ;'       g    R4      \        \	        V RR4      ;'       g    R4      R\        \	        V RR4      ;'       g    R4      RVRR	R
V/RR7      # )rT  ©Ú	relay_llmr�  r§   r‹  r`  rk  r  Ú	call_roleÚiteration_summaryr  T)r¾  Ú
model_nameÚmetadataÚdefer_logical_completion)rU   r
  Úexecute_currentrI   rì   )rU   r  rÛ  r=   r  r
  s   &&&&$ r?   Ú_managed_summary_callr  š  sŠ   € ÝØ×$Ñ$ØÜ”˜ 
¨BÓ/×=Ð=°:Ó>Ì3ÌwÐW\Ð^eÐgiÓOj×OpÐOpÐnpÓKqØœc¤'¨%°¸RÓ"@×"VÐ"VÐDVÓWØ˜n¨kÐ;NÐP]Ð_jðlà!%ð %ó ð rB   c               ó   € V ^8„  d   QhRR/# rw   rL   )rM   s   "r?   rN   rN   ¥  s   € ÷ 
.ñ 
.¸#ñ 
.rB   c                ó*  € \        V4      '       d   \        P                  R 4       R# V P                  4       P                  ! V3/ VB pVP
                  '       d   \        P                  R4       VP                  ;'       g    RP                  4       # )z:Iteration summary returned a router timeout shim; retryingr§   z5Iteration summary emitted tool calls; discarding them)r   r[   r\   ry  Únormalize_responser»  r¸  r©   )rU   ro   Únormalize_kwargsÚ
normalizeds   &&, r?   Ú_summary_textr  ¥  st   € Ü˜h×'Ò'ä�‰ÐSÔTÙØ×%Ñ%Ó'×:Ò:¸8ÑXÐGWÑX€JØ××Ðô 	�‰ÐNÔOØ×Ñ×$Ð$ "×+Ñ+Ó-Ð-rB   c               ó    € V ^8„  d   QhRRRR/# ©rG   r›  rÂ   r  rI   rL   )rM   s   "r?   rN   rN   ²  s   € ÷ ñ °ð Àcñ rB   c                ó   a a€ R  V V3R llpV# )c               ó    € V ^8„  d   QhRRRR/# ©rG   r  r�   rJ   rI   rL   )rM   s   "r?   rN   Ú,_codex_summary_attempt.<locals>.__annotate__³  s   € ÷ 
Qñ 
Q˜cð 
Q cñ 
QrB   c                óÈ   <€ SP                  S4      pVP                  R R4       VP                  RR4       VP                  RR4       \        SSP                  V4      4      # )rI  NÚtool_choiceÚparallel_tool_calls)Ú_build_api_kwargsrD  r  Ú_interruptible_api_call)r  Úcodex_kwargsrU   r›  s   & €€r?   Ú_attemptÚ(_codex_summary_attempt.<locals>._attempt³  s`   ø€ Ø×.Ñ.¨|Ó<ˆð 	×Ñ˜ $Ô'Ø×Ñ˜¨Ô-Ø×ÑÐ.°Ô5ô ˜U E×$AÑ$AÀ,Ó$OÓPÐPrB   rL   ©rU   r›  r  r$  s   ff& r?   Ú_codex_summary_attemptr'  ²  s   ù€ ÷
Qñ 
Qð €OrB   c               ó    € V ^8„  d   QhRRRR/# r  rL   )rM   s   "r?   rN   rN   Á  s   € ÷ 
ñ 
°Dð 
È#ñ 
rB   c                ó"   a aa€ R  V VV3R llpV# )c               ó    € V ^8„  d   QhRRRR/# r  rL   )rM   s   "r?   rN   Ú0_anthropic_summary_attempt.<locals>.__annotate__Â  s   € ÷ [ñ [˜cð [ cñ [rB   c                óR  <€ SP                  4       P                  SP                  SR SP                  SP                  SP
                  SP                  4       \        SRR 4      R7      p\        SVS4      p\        SSVSP                  V R7      p\        SVSP
                  R7      # )Nro  )r‹  rG  rI  rs  r  rt  ru  rt  ©r  )Ústrip_tool_prefix)ry  rz  r‹  rs  r  r|  r}  rì   r«  r  r"  r  )r  Úant_kwro   rU   r›  r  s   &  €€€r?   r$  Ú,_anthropic_summary_attempt.<locals>._attemptÂ  s¡   ø€ Ø×%Ñ%Ó'×4Ñ4Ø—+‘+¨¸DÈU×M]ÑM]Ø"×3Ñ3¸e×>WÑ>WØ×8Ñ8Ó:ÄWÈUÐTiÐkoÓEpð 5ó rˆô 8¸¸vÀ|ÓTˆÜ(Ø�> 6¨5×+HÑ+HÐVaôcˆä˜U HÀ×@YÑ@YÔZÐZrB   rL   r&  s   fff r?   Ú_anthropic_summary_attemptr1  Á  s   ú€ ÷[ò [ð €OrB   c               ó    € V ^8„  d   QhRRRR/# r  rL   )rM   s   "r?   rN   rN   Î  s   € ÷ ñ ¨tð ÀSñ rB   c                ó  a aa€ S P                  V4      o\        S S4       ^ RIHp S P                  R8X  dK   V! S P
                  4      '       d3   S P
                  P                  P                  P                  V4      SR&   R V VV3R llpV# )rT  )Ú%_moa_client_consumes_prepared_requestrZ  r^  c               ó    € V ^8„  d   QhRRRR/# r  rL   )rM   s   "r?   rN   Ú+_chat_summary_attempt.<locals>.__annotate__Û  s   € ÷ .ñ .˜cð . cñ .rB   c                óP   <€ \        SSSSP                  V R 7      p\        SV4      # )r-  )r  r"  r  )r  ro   rU   r  Úsummary_kwargss   & €€€r?   r$  Ú'_chat_summary_attempt.<locals>._attemptÛ  s0   ø€ ô )Ø�> >°5×3PÑ3PØ#ô%ˆô ˜U HÓ-Ð-rB   )	r!  r%   rú  r4  r�  rH  r[  r\  r]  )rU   r›  r  r4  r$  r8  s   f&f  @r?   Ú_chat_summary_attemptr:  Î  sw   ú€ ð
 ×,Ñ,¨\Ó:€Nô ˜U NÔ3ÝMØ‡~�~˜ÔÑ#HÈÏÉ×#VÒ#VØ27·,±,×2CÑ2C×2OÑ2O×2WÑ2WÐXdÓ2eˆÐ.Ñ/÷.ò .ð €OrB   rQ  rU  c               ó$   € V ^8„  d   QhRRRRRR/# )rG   rG  rÂ   Úapi_call_countr�   rJ   rI   rL   )rM   s   "r?   rN   rN   è  s!   € ÷ 4ñ 4¨4ð 4Àð 4Èñ 4rB   c                óÄ  € RV P                    R2p\        V RR4      '       d   \        P                  V4       MV P	                  VRR7       R\
        P                  ! 4        2pRp^ R	IHp \        VR
RRV/4      p \        W4      p\        P                  V P                  \        4      p	V	! WV4      p
\        pR Fn  pV
! V4      pV'       g   K  RV9   d7   \         P"                  ! RRV\         P$                  R7      P'                  4       pV'       d   Rp\        VR
RRV/4       Tp M	   ^ RIHp VP7                  WER7       V#   \(         d*    RpT'       d   TR,          TJ d   TP+                  4        h \,         d;   p\        P                  RT4       ^ RIHp T! RT P                   R7      p Rp?LŒRp?ii ; i  ^ RIHp TP7                  YER7       i ; i)zSRequest a summary when max iterations are reached. Returns the final response text.u$   âš ï¸�  Reached maximum iterations (z). Requesting summary...Úsuppress_status_outputFT©Ú
diagnosticziteration-summary:Úfailed)ÚMAX_ITERATIONS_SUMMARY_REQUESTr  Úuserr¸  z<think>z<think>.*?</think>\s*r§   rì  Úsuccessr  r�  z"Failed to get summary response: %s)Ú	site_copyÚmax_iterations_no_summary)ÚlimitNr	  )Úoutcome)rT  rÍ   r6  )Úmax_iterationsrì   r[   r\   Ú_safe_printrÁ  rÂ  rø  rB  r   r  Ú_SUMMARY_ATTEMPT_BUILDERSr}   r`  r:  Ú_EMPTY_SUMMARY_RESPONSEr�   r'  rô  r©   rÙ  rD  rX   Úagent.turn_failure_copyrE  rU   r
  Úcomplete_logical_call)rU   rG  r<  r\   Úsummary_api_request_idÚsummary_call_outcomerB  Únudger›  Úbuild_attemptÚattemptÚfinal_responser  r�   rå  rE  r
  s   &&&              r?   Úhandle_max_iterationsrU  è  s¹  € à4°U×5IÑ5IÐ4JÐJbÐc€GÜˆuÐ.°×6Ò6ô 	�‰�wÕà×Ñ˜'¨dÐÔ3à1´$·*²*³,°Ð@ÐØ#Ðõ HÜ˜8 f¨f°iÐA_Ð%`Óa€Eð ^Ü6°uÓGˆÜ1×5Ñ5°e·n±nÔF[Ó\ˆÙ Ð5KÓLˆô 1ˆÛ!ˆKÙ˜;Ó'ˆDßÙØ˜DÔ Ü—v’vÐ6¸¸DÌÏ	É	ÔR×XÑXÓZ�ßØ'0Ð$Ü˜x¨&°+¸yÈ$Ð)OÔPØ!%�Ùò "õ0 	$Ø×'Ñ'Ð(>Ð'Ô]àÐøô ô ð  +Ðß˜ �¨Ó-Ø�L‰LŒNØÜô \Ü�‰Ð;¸QÔ?Ý5Ù"Ð#>Àe×FZÑFZÔ[�ûð\ûõ
 	$Ø×'Ñ'Ð(>Ð'Õ]úsO   Á>BE ÄE Ä-G Ä.E Ä0G ÅGÅ &GÆGÆ0F=Æ8G Æ=GÇG ÇGc               ó    € V ^8„  d   QhRRRR/# )rG   r-  rI   rJ   rK   rL   )rM   s   "r?   rN   rN   	  s   € ÷ Zñ Z¨3ð Z°4ñ ZrB   c                ó†  aa€ R R loR\         RV3R l3RV3R lRV3R	 l33 FO  w  r#rE V! S4      '       d4   V P                  '       d    \        P                  ! R
V RS R24       KF  KH  V! 4        KQ  	  R#   \         d<   pT P                  '       d   \
        P                  RTST4        Rp?K�   Rp?K–  Rp?ii ; i)zýPer-turn VM + browser cleanup for a task. Skips ``cleanup_vm`` for persistent
terminal envs (``_cleanup_inactive_envs`` reaps them after ``terminal.lifetime_seconds``)
and ``cleanup_browser`` in headed mode (the inactivity reaper handles idle sessions).c               ó   € V ^8„  d   QhRR/# rR  rL   )rM   s   "r?   rN   Ú,cleanup_task_resources.<locals>.__annotate__#	  s   € ÷ @ñ @�Tñ @rB   c                 ó�   €  ^ RI Hp  V ! 4       #   \         d,    \        \        P
                  P                  R4      4      u # i ; i)rT  ©Ú_is_headed_modeÚAGENT_BROWSER_HEADED)Útools.browser_tool_cloudr\  rX   rô   rñ  rò  r}   r[  s    r?   Ú_headedÚ'cleanup_task_resources.<locals>._headed#	  s>   € ð	@Ý@Ù"Ó$Ð$øÜô 	@ÜœŸ
™
Ÿ™Ð'=Ó>Ó?Ò?ð	@ús   ‚ �3AÁAÚVMzcleanup_vm for persistent envc                 ó6   <€ \        4       P                  S 4      # r:   )rc   Ú
cleanup_vm©r-  s   €r?   r@   Ú(cleanup_task_resources.<locals>.<lambda>+	  s   ø€ Ì3Ë5×K[ÑK[Ð\cÔKdrB   Úbrowserc                ó   <€ S! 4       # r:   rL   )Ú_tidr_  s   &€r?   r@   re  ,	  s   ø€ ¡¤rB   z"cleanup_browser for headed sessionc                 ó6   <€ \        4       P                  S 4      # r:   )rc   Úcleanup_browserrd  s   €r?   r@   re  ,	  s   ø€ ÔZ]ÓZ_×ZoÑZoÐpwÔZxrB   zSkipping per-turn rÎ   z; idle reaper will handle it.z$Failed to cleanup %s for task %s: %sN)r0   rõ  rö  r—  rX   r[   r\   )rU   r-  rH   ÚskipÚ	skip_whatÚcleanuprå  r_  s   &f     @r?   Úcleanup_task_resourcesrn  	  sº   ù€ õ@ð 
Ô Ð"AÔCdÐeØ	Ô*Ð,PÔRxÐyó,Ñ'ˆ�Yð	ZÙ�G�}Š}Ø×(×(Ð(Ü—M’MÐ$6°y°kÀÀ7À)ÐKhÐ"iÖjñ )ñ –	ó,øô ô 	ZØ×$×$Ð$Ü—‘ÐEÀuÈgÐWX×YÒYõ %ûð	Zús#   ¬A:ÁA:Á-A:Á:C Â*B;Â;C Údropped_tool_namesÚoverflow_terminalr`  Ú	clean_eofc               óþ   € VR8X  d;   \        \        RT T\        RT;'       g    RR7      .RRTT;'       g    RVVR7      # \        \        T\        ^ \        WRVR	7      \        R
7      .TT;'       g    RVVR7      # )aÀ  Stub for an SSE stream that ended without ``finish_reason`` after
delivering content. Tagged ``PARTIAL_STREAM_STUB_ID`` + ``FINISH_REASON_LENGTH``
so the loop enters its continuation/retry path instead of accepting
truncated output as a complete turn (#32086).

``overflow_terminal`` (``full_content=None``): the stream died on a
context-overflow error. Seeding the recovered text as a continuation stub
would grow every later request into the same overflow (#106260); the loop
treats the marker as terminal and ends the turn via the recovery contract.

``api_mode="anthropic_messages"`` returns a Messages-shaped stub (``content``
block list + ``stop_reason="max_tokens"``) so AnthropicTransport validates it
and the loop continues instead of entering the invalid-response retry ladder
(#45908). Empty content keeps one empty text block: validate_response rejects
an empty list for ``max_tokens``.

``clean_eof``: the stream ended with no transport exception and no
``finish_reason`` (server/intermediary closed cleanly). Only the two
clean-EOF sites in ``_finish_chat_stream`` pass True; the stub built after a
real transport exception keeps False so the loop can word the two failure
modes differently (#102766).
rU  rz   r�   r§   )rÜ   r�   rs  N)r  rÜ   r  r‹  r¸  Ústop_reasonÚstop_sequenceÚusageÚ_dropped_tool_namesÚ_overflow_terminalÚ
_clean_eof)r  r¸  r»  r¹  ©r  rz   r  )r  r‹  r¶  ru  rv  rw  rx  )r   r
   r   )	r  Úfull_contentÚfull_reasoningr  Ú	usage_objro  rp  r`  rq  s	   &&&&&$$$$r?   Ú_build_partial_stream_stubr}  9	  s£   € ð0 Ð'Ô'ÜÜ%ØØØÜ$¨&°|×7IÐ7IÀrÔJÐKØ$ØØØ 2× :Ð :°dØ0Ø ô
ð 	
ô Ü!ØÜ ØÜ#¨ÐPTØ"0ô2ä.ô	
ð ð Ø.×6Ð6°$Ø,Øôð rB   c               ó    € V ^8„  d   QhRRRR/# rñ   rL   )rM   s   "r?   rN   rN   x	  s   € ÷ 	`ñ 	` ð 	`°4ñ 	`rB   c                ó  a€ \        V RR4      R
9  d   R# \        V RR4      ;'       g    R RV  2P                  4       oRS9   ;'       d;    \        ;QJ d    V3R lR 4       F  '       g   K   R	# 	  R# ! V3R lR 4       4      # )a$  A 400/422 whose body names ``stream_options`` as an unknown/extra field: strict
OpenAI-compatible endpoints (Azure AI Foundry MaaS, Pydantic ``extra_forbidden``) reject
the usage extension outright (#9705). Distinct from "stream not supported", which flips
the whole session to non-streaming.rh   NFrj   r§   rÎ   Ústream_optionsc              3  ó,   <"  € T F	  qS9   x € K  	  R # 5ir:   rL   )r›   rœ   rj   s   & €r?   r�   Ú*_rejects_stream_options.<locals>.<genexpr>€	  s   øé € ð ,`Ù^�aˆTŽ	Ó^ùr*  T)r  i¦  )r  únot supportedÚunrecognizedÚ
unexpectedrÜ  )rì   rÒ   rÀ   )rò   rj   s   &@r?   Ú_rejects_stream_optionsr†  x	  sš   ø€ ô
 ˆs�M 4Ó(°
Ô:ÙÜ�c˜6 2Ó&×,Ð,¨"Ð-¨Q¨s¨eÐ4×:Ñ:Ó<€DØ˜tÑ#÷ `ð `¯«ô ,`Ù^ó,`¯¬ð `ªð `¨ô ,`Ù^ó,`ó )`ð `rB   c               ó    € V ^8„  d   QhRRRR/# )rG   Údelayr\  rJ   rK   rL   )rM   s   "r?   rN   rN   „	  s   € ÷ 	(ñ 	(¨Uð 	(°tñ 	(rB   c                ó  € \         P                  ! 4       \        RV4      ,           p\        V RR4      '       gH   V\         P                  ! 4       ,
          pV^ 8:  d   R# \         P                  ! \        RV4      4       KZ  R# )zÂSleep ``delay`` seconds in 0.1s steps, returning early as soon as the agent
is interrupted (so /stop is never held hostage by a backoff; the retry loop's
own interrupt check then ends the call).r^  rÖ  FNgš™™™™™¹?)r  r’  rj  rì   Úsleeprk  )rU   rˆ  Údeadliner  s   &&  r?   Ú_wait_stream_retry_backoffrŒ  „	  s^   € ô �~Š~Ó¤# c¨5£/Õ1€HÜ�eÐ3°U×;Ò;ØœtŸ~š~Ó/Õ/ˆ	Ø˜Œ>ÙÜ�
Š
”3�s˜IÓ&Ö'ñ	 <rB   c               ó   € V ^8„  d   QhRR/# ©rG   rJ   r�  rL   )rM   s   "r?   rN   rN   �	  s   € ÷ Lñ L¨5ñ LrB   c                 óf   € \         P                  P                  R 4      p V e   V P                  3# R# )r`  rL   )ÚsysÚmodulesr}   ÚAPIConnectionError)r`  s    r?   Ú!_anthropic_connection_error_typesr“  �	  s/   € ô —‘—‘ Ó,€IØ.7Ò.CˆI×(Ñ(Ð*ÐKÈÐKrB   c               ó    € V ^8„  d   QhRRRR/# rñ   rL   )rM   s   "r?   rN   rN   —	  s   € ÷ Dñ D -ð D°Dñ DrB   c                ó  a€ ^ RI Hp \        W4      '       d   \        V RR4      '       d   R# \	        V 4      P                  4       o\        ;QJ d#    V3R l\         4       F  '       g   K   R# 	  R# ! V3R l\         4       4      # )rT  )ÚAPIErrorrh   NFc              3  ó,   <"  € T F	  qS9   x € K  	  R # 5ir:   rL   )r›   ÚphraseÚ	err_lowers   & €r?   r�   Ú+_is_sse_connection_error.<locals>.<genexpr>œ	  s   øé € ÐCÑ1B v˜Ö"Ó1Bùr*  T)rÓ  r–  r|   rì   rI   rÒ   rÀ   Ú_SSE_CONN_PHRASES)rò   Ú	_APIErrorr™  s   & @r?   Ú_is_sse_connection_errorr�  —	  s]   ø€ Ý,Ü�c×%Ò%¬°°mÀT×)JÒ)JÙÜ�C“—‘Ó €Iß‹3ÔCÕ1BÓC�3Œ3ÐCŠ3ÐCˆ3ÔCÕ1BÓCÓCÐCrB   c               ó    € V ^8„  d   QhRRRR/# )rG   Úname_defaultrI   rJ   rk   rL   )rM   s   "r?   rN   rN   Ÿ	  s   € ÷ >ñ >°ð >¸ñ >rB   c                óÆ   € R\        \        V RR4      ;'       g    R4      R\        \        V RR4      ;'       g    T4      R\        \        V RR4      ;'       g    R4      /# )zG``session_id``/``name``/``model_name`` kwargs for ``relay_llm.stream``.r¢  r§   r¾  r�  r  r‹  ©rI   rì   )rU   rŸ  s   &&r?   Ú_relay_stream_identityr¢  Ÿ	  s]   € àœ#œg e¨\¸2Ó>×DÐDÀ"ÓEØ””G˜E :¨rÓ2×BÐB°lÓCØ”cœ' %¨°"Ó5×;Ð;¸Ó<ð>ð >rB   c               ó    € V ^8„  d   QhRRRR/# )rG   r`  rI   rJ   rk   rL   )rM   s   "r?   rN   rN   ¦	  s   € ÷  ñ  ¨Cð  °Dñ  rB   c                ó¤   € \        V R R4      '       d   RM(\        \        V R^ 4      ;'       g    ^ 4      ^ 8”  d   RMRpRVR\        V RR	4      R
V/# )Úis_subagentFÚ	delegatedrÜ  ÚfallbackÚprimaryr`  r  Ú_current_api_request_idNr  )rì   r�   )rU   r`  r  s   && r?   Ú_relay_stream_metadatarª  ¦	  sb   € Ü '¨¨}¸e× DÒ D‘Ü$'¬°Ð7HÈ!Ó(L×(QÐ(QÐPQÓ$RÐUVÔ$V‘jÐ\eð à˜Ð"2´G¸EÐC\Ð^bÓ4cØ�Yð ð  rB   c               ó   € V ^8„  d   QhRR/# rw   rL   )rM   s   "r?   rN   rN   ­	  s   € ÷ ñ  Cñ rB   c           	     óÌ  € \         P                  ! \        4      ;_uu_ 4        \        V R R4      p\	        V\
        \        34      '       d   V'       d
   V^ ,          MRp\        \        VRR4      RR4      p\	        V\        4      '       d   VuuRRR4       #  RRR4       \         P                  ! \        4      ;_uu_ 4        \        V RR4      p\	        V\        4      '       d   VuuRRR4       # \	        V\
        4      '       d*   RP                  R R V 4        4       4      uuRRR4       #  RRR4       R#   + '       g   i     L¬; i  + '       g   i     R# ; i)r¶  Nrz   r¸  r§   c              3  óV   "  € T F  p\        V\        4      '       g   K  Vx € K!  	  R # 5ir:   )r|   rI   rW  s   & r?   r�   Ú%_stream_final_text.<locals>.<genexpr>¹	  s    é € ÐnÑ&W Ô[eÐfgÔil×[mŸ1š1Ó&Wùs   ‚)Ÿ
)c              3  ó<   "  € T F  p\        VR R4      x € K  	  R# 5i)r�   N©rì   )r›   r!  s   & r?   r�   r®  ¹	  s   é € Ð&WÉwÀt¤w¨t°V¸T×'BÐ'BËwùs   ‚)	rª   r«   rX   rì   r|   rÂ   r�  rI   rY   )ro   r¶  Úfirst_choicer¸  s   &   r?   Ú_stream_final_textr²  ­	  s  € Ü	×	Ò	œY×	'Õ	'Ü˜( I¨tÓ4ˆÜ%/°¼$Ä¸×%GÒ%GÏG�w˜q–zÐY]ˆÜœ' ,°	¸4Ó@À)ÈTÓRˆÜ�gœs×#Ò#Ø÷ 
(Ò	'ð $÷	 
(ô 
×	Ò	œY×	'Õ	'Ü˜( I¨tÓ4ˆÜ�gœs×#Ò#Ø÷ 
(Ò	'ô �gœt×$Ò$Ø—7‘7ÑnÑ&WÉwÔ&WÓnÓn÷ 
(Ò	'ð %÷	 
(ñ ÷ 
(×	'ú÷ 
(Ö	'ñ ús#   £1D?Á:D?Ã%EÃ54EÄ?E	ÅE#	c                ó  € \        V RR4      pVe   V! 4         V! 4       p\        T RR4      pTe   T! \        T4      RRR7       T#   \         d,   p\        T RR4      pTe   T! RR\        T4      R7       h Rp?ii ; i)z¶Bracket ``run()`` with the agent's ``_emit_stream_start`` / ``_emit_stream_end``
hooks when present (end carries the final text on success, the error string on
failure) and re-raise.Ú_emit_stream_startNÚ_emit_stream_endr§   F)Ú
final_textÚfinishedr5   T)rì   rX   rI   r²  )rU   r;   r«  ro   rò   r8  s   &&    r?   Ú_with_stream_emittersr¸  ½	  s�   € ô �EÐ/°Ó6€EØÒÙŒðÙ“5ˆô �%Ð+¨TÓ
2€CØ
‚ÙÔ)¨(Ó3¸dÈ$ÕOØ€Oøô ô Ü�eÐ/°Ó6ˆØŠ?Ù˜2¨´S¸³XÕ>Øûð	ús   šA ÁA>Á&A9Á9A>c               ó   € V ^8„  d   QhRR/# rO  rL   )rM   s   "r?   rN   rN   Ñ	  s   € ÷ +ñ +°ñ +rB   c                ó^   a a€ VS n          \        S V V3R l4      RS n         #   RS n         i ; i)zÍCodex streams internally via _run_codex_stream (reached through
_interruptible_api_call); park ``on_first_delta`` on the agent so it can pick
it up, and bracket the call with the stream start/end emitters.c                 ó&   <€ S P                  S4      # r:   )r"  r  s   €€r?   r@   Ú+_stream_codex_passthrough.<locals>.<lambda>×	  s   ø€ °E×4QÑ4QÐR\Ô4]rB   N)rS  r¸  ©rU   rÚ  rT  s   ff&r?   Ú_stream_codex_passthroughr¾  Ñ	  s.   ù€ ð #1€EÔð+Ü$ UÕ,]Ó^à&*ˆÕ#ø dˆÕ#ús   ‹# £	,c                óZ   € ^ RI Hp  V! R\        V 4      /4      #   \         d     R# i ; i)z—Relay finalizer for Bedrock: a stream without messageStop has no complete
response to record, so return None and let the live consumer raise (#109988).©Ústream_converse_with_callbacksrû   N)rC  rÁ  rÂ   r   )rÈ   rÁ  s   & r?   Ú_finalize_bedrock_relay_eventsrÂ  Ü	  s3   € õ EðÙ-¨x¼¸f»Ð.FÓGÐGøÜô Úðús   ˆ ›*©*c                  ó„   € ] tR tRtRtR R ltR R ltR tR tR	 R
 lt	R R lt
R tRR R lltR R ltR tR tRtR# )Ú_BedrockStreamiæ	  zÑBedrock Converse streaming: boto3 ``converse_stream()`` on a worker thread
with real-time delta callbacks, polled by an interrupt / stale-event watchdog
(same UX as the Anthropic and chat_completions streams).c               ó   € V ^8„  d   QhRR/# rO  rL   )rM   s   "r?   rN   Ú_BedrockStream.__annotate__ë	  s   € ÷ Mñ M¨$ñ MrB   c                	ó   € Wn         W n        W0n        R RRR/V n        RV n        RV n        \        P                  ! 4       V n        V P                  V n        VP                  RR4      V n
        \        W4      V n        R# )ro   Nr5   Fr<  r=  )rU   rÚ  rT  ÚresultÚfirst_delta_firedrÓ  r  Ú
started_atÚ
last_eventr}   rG  r  rg  ©rs   rU   rÚ  rT  s   &&&&r?   rq   Ú_BedrockStream.__init__ë	  sn   € ØŒ
Ø$ŒØ,ÔØ! 4¨°$Ð7ˆŒØ!&ˆÔØ %ˆÔô Ÿ)š)›+ˆŒØŸ/™/ˆŒð !—n‘nÐ%9¸;ÓGˆŒä9¸%ÓLˆÖrB   c               ó   € V ^8„  d   QhRR/# rw   rL   )rM   s   "r?   rN   rÆ  ü	  s   € ÷ 9ñ 9˜ñ 9rB   c                	ó:   € V P                   P                  R R4      # )r	  rÜ  )rÚ  r}   r¢  s   &r?   Ú_modelÚ_BedrockStream._modelü	  s   € Ø�‰×"Ñ" 9¨iÓ8Ð8rB   c                	ó  € R V n         V P                  '       gY   V P                  '       dE   R V n        \        P                  ! \
        4      ;_uu_ 4        V P                  4        RRR4       R# R# R#   + '       g   i     R# ; irÎ  )rÓ  rÉ  rT  rª   r«   rX   r¢  s   &r?   Ú_fire_firstÚ_BedrockStream._fire_firstÿ	  s`   € Ø $ˆÔØ×%×%Ð%¨$×*=×*=Ð*=Ø%)ˆDÔ"Ü×$Ò$¤Y×/Õ/Ø×#Ñ#Ô%÷ 0Ñ/ñ +>Ñ%ç/×/Ð/ús   ÁA4Á4B	c                ó   a a€ VV 3R lpV# )zQWrap a delta callback so the first delivered event also fires ``on_first_delta``.c                ó8   <€ SP                  4        S! V 4       R # r:   )rÓ  )r‹   Úfirers   s   &€€r?   Ú_onÚ(_BedrockStream._after_first.<locals>._on
  s   ø€ Ø×ÑÔÙ�ŽKrB   rL   )rs   r×  rØ  s   ff r?   Ú_after_firstÚ_BedrockStream._after_first
  s   ù€ ö	ð ˆ
rB   c               ó   € V ^8„  d   QhRR/# ©rG   Únext_api_kwargsr"  rL   )rM   s   "r?   rN   rÆ  
  s   € ÷ xñ x¨Nñ xrB   c                	óD   € \        \        V4      R V P                  R7      # )T)rû   r2  )rM  rk   Ú_fall_back_to_converse)rs   rÞ  s   &&r?   Ú_open_streamÚ_BedrockStream._open_stream
  s   € Ü%¤d¨?Ó&;ÀDÐ[_×[vÑ[vÔwÐwrB   c               ó    € V ^8„  d   QhRRRR/# )rG   Úfinal_kwargsrk   rò   rX   rL   )rM   s   "r?   rN   rÆ  
  s   € ÷ 
Lñ 
L¸4ð 
LÀiñ 
LrB   c                	óì   € ^ RI Hp RV P                  n        V P                  P	                  RRR7       \
        P                  R\        V4      P                  4       V! VP                  ! R/ VB 4      # )rT  )r9  Tuœ   
âš   AWS IAM denied bedrock:InvokeModelWithResponseStream â€” falling back to non-streaming InvokeModel.
   Grant that action to restore streaming output.
r?  u`   bedrock: converse_stream denied by IAM (%s) â€” using non-streaming converse() for this session.rL   )
rC  r9  rU   Ú_disable_streamingrJ  r[   rø  rÜ   rƒ   rF  )rs   rH  rä  rò   r9  s   &&&& r?   rà  Ú%_BedrockStream._fall_back_to_converse
  sm   € õ 	FØ(,ˆ�
‰
Ô%Ø�
‰
×Ñð  BàNRð 	ô 	Tô 	�‰ð ?Ü@DÀSÃ	×@RÑ@Rô	Tá*¨6¯?ª?Ñ+J¸\Ñ+JÓKÐKrB   c                	óZ  a aaa€ S P                   oR p ^ RI Hp ^ RIHp . oRR /oR VV3R llpR VV3R llpR V 3R	 llp ^ R
IHp V! 4       pVP                  ! \        S P                  4      S P                  3/ \        SR4      BRV3R lRVRSP                  RR RVRR R\        SR4      RR/B pSP                   ;'       g    SP"                  ;'       g    Tp	 T! RV/SP%                  4       '       d   S P'                  SP(                  4      MR S P'                  SP*                  4      V	'       d   S P'                  SP,                  4      MR V3R lVR7      p
VP0                  ;'       g    T
S P2                  R&   Ve   VP5                  4        R # R #   \         d    \        P                  RRR7       Rp ELui ; i  \.         d    TP0                  f   h R p
 L„i ; i  \         d   pTS P2                  R &    R p?L„R p?ii ; i  Te   TP5                  4        i i ; i)!Nr	  rÀ  r‹   c               ó    € V ^8„  d   QhRRRR/# )rG   Ú_streamr   rJ   rK   rL   )rM   s   "r?   rN   Ú,_BedrockStream._worker.<locals>.__annotate__%
  s   € ÷ Cñ C¨ð C°ñ CrB   c                ó$   <€ \        S4      SR &   R# ©r‹   N)r.   )rê  rU   Úwriter_tokens   &€€r?   Ú_stream_createdÚ/_BedrockStream._worker.<locals>._stream_created%
  s   ø€ Ü(;¸EÓ(B�˜WÓ%rB   c               ó    € V ^8„  d   QhRRRR/# )rG   Ú_eventr   rJ   rô   rL   )rM   s   "r?   rN   rë  (
  s   € ÷ Oñ O cð O¨dñ OrB   c                óF   <€ SR ,          pVRJ ;'       g    \        SV4      # rí  )r/   )rò  ÚtokenrU   rî  s   & €€r?   Ú_accept_eventÚ-_BedrockStream._worker.<locals>._accept_event(
  s'   ø€ Ø$ WÕ-�Ø �}×NÐNÔ(@ÀÈÓ(NÐNrB   c               ó   € V ^8„  d   QhRR/# rÊ  rL   )rM   s   "r?   rN   rë  ,
  s   € ÷ .ñ . $ñ .rB   c                 ó<   <€ \         P                   ! 4       S n        R # r:   )r  rË  r¢  s   €r?   Ú_stamp_eventÚ,_BedrockStream._worker.<locals>._stamp_event,
  s   ø€ Ü"&§)¢)£+�–rB   )Ú#has_reasoning_stream_observer_hooksz-plugin reasoning stream observer check failedTr”  Frl  Ú	finalizerc                 ó   <€ \        S 4      # r:   )rÂ  )Úintercepted_eventss   €r?   r@   Ú(_BedrockStream._worker.<locals>.<lambda>8
  s   ø€ Ô"@ÐASÔ"TrB   Úon_stream_createdÚon_chunkÚchunk_adapterc                ó   € V # r:   rL   )r­  s   &r?   r@   rÿ  :
  s   € ©ErB   Úaccept_chunkÚcompleted_response_predicatec                ó.   € \        \        V R R4      4      # )r¶  N)rô   rì   rù   s   &r?   r@   rÿ  ;
  s   € ¼dÄ7È8ÐU^Ð`dÓCeÔ>frB   r  r·  r  rû   c                 ó   <€ S P                   # r:   )rÖ  rÇ  s   €r?   r@   rÿ  C
  s   ø€ ¨u×/IÒ/IrB   )Úon_text_deltaÚon_tool_startÚon_reasoning_deltaÚon_interrupt_checkÚon_eventro   r5   )rU   r
  rC  rÁ  Úagent.plugin_stream_hooksrû  rX   r[   r—  rû   rk   rÚ  rá  r¢  r~   rª  r÷  rø  Ú_has_stream_consumersrÚ  Ú_fire_stream_deltaÚ_fire_tool_gen_startedÚ_fire_reasoning_deltar   rT  rÈ  rí  )rs   rû   r
  rÁ  rï  rõ  rù  rû  Úplugin_reasoning_observerÚwants_reasoningÚstreamed_responserå  rU   rþ  rî  s   f           @@@r?   Ú_workerÚ_BedrockStream._worker
  sJ  û€ Ø—
‘
ˆØˆð/	Ý'ÝLØ!#ÐØ# T˜?ˆL÷Cñ C÷Oñ O÷.ð .ð2ÝYÙ,OÓ,QÐ)ð
 ×%Ò%¤d¨4¯?©?Ó&;¸T×=NÑ=Nñ aÜ(¨°	Ó:ñaäTðað #2ðað =O×<UÑ<Uðañ 2ð	að ANð	añ
 .gðaô 0°°xÓ@ðað \`òaˆFð $×6Ñ6×rÐr¸%×:UÑ:U×rÐrÐYrˆOð
)Ù$BÀHÈfÐCUØQV×QlÑQl×QnÒQn $×"3Ñ"3°E×4LÑ4LÔ"MÐtxØ"&×"3Ñ"3°E×4PÑ4PÓ"QßYh t×'8Ñ'8¸×9TÑ9TÔ'UÐnrÜ'IÐT`ô	%bÐ!ð '-×&;Ñ&;×&PÐ&PÐ?PˆD�K‰K˜
Ñ#ð Ò!Ø—‘–ñ "øô7 ô 2Ü—‘ÐLÐW[�Ô\Ø,1Ó)ð2ûô$ $ô )à×(Ñ(Ò0ØØ$(Ò!ð	)ûô ô 	%Ø#$ˆD�K‰K˜Ö ûð	%ûð Ò!Ø—‘•ð "úsŠ   ”/G, ÁF ÁBG, ÃG, Ã#G
 Ã>=G
 Ä<(G
 Å$G, Å7G, Æ$GÇG, ÇGÇG, Ç
G)Ç&G, Ç(G)Ç)G, Ç,HÇ7HÈH ÈHÈH ÈH*Nc               ó    € V ^8„  d   QhRRRR/# )rG   rz   rI   rJ   rK   rL   )rM   s   "r?   rN   rÆ  P
  s   € ÷ (ñ (¨Sð (À$ñ (rB   c                	ó  € V P                   P                  '       g   R # \        V P                   \        P                  ! 4       V P                  ,
          V P
                  R7       Ve   \        VRR7       \        V4      h)N©rÓ  zBedrock streaming©rH   )rU   rÖ  rÖ  r  rÊ  rÓ  r_   rÙ  )rs   rz   r]   s   &&&r?   Ú_raise_if_interruptedÚ$_BedrockStream._raise_if_interruptedP
  sZ   € Ø�z‰z×.×.Ð.ÙÜ)Ø�J‰JœŸ	š	› d§o¡oÕ5È×H]ÑH]õ	_àÒä+¨FÐ:MÕNÜ˜wÓ'Ð'rB   c               ó    € V ^8„  d   QhRRRR/# ©rG   Ústale_elapsedr\  rJ   rK   rL   )rM   s   "r?   rN   rÆ  Z
  s   € ÷ Tñ T uð T°ñ TrB   c                óT  € V P                   p\        P                  RWP                  V P                  V P                  4       4       VP                  R\        V4       RV P                  4        R24       \        V4        ^ RI	H
p V! V P                  4       \        P                  ! 4       V n        \        V4       \!        R\        V4       R	\        V P                  4       R
24      V P"                  R&   R#   \         d!   p\        P                  RT4        Rp?LˆRp?ii ; i)zcNo event past the stale timeout = wedged stream (the worker would
block in the event loop forever).uk   Bedrock stream stale for %.0fs (threshold %.0fs) â€” no events received. region=%s model=%s. Aborting call.u"   âš ï¸� No events from Bedrock for ú
s (model: z). Aborting...)r6  z)bedrock: stale client eviction failed: %sNz&Bedrock stream produced no events for zs (threshold uF   s) â€” aborting stalled stream so the retry/fallback path can recover.r5   )rU   r[   r\   rg  rG  rÐ  rà  r�   rÌ  rC  r6  rX   r—  r  rË  rì  rÈ  rÈ  )rs   r  rU   r6  Ú
_inval_excs   &&   r?   r§  Ú_BedrockStream._on_staleZ
  s  € ð —
‘
ˆÜ�‰ð ;Ø<I×K]ÑK]Ð_c×_jÑ_jØ�K‰K‹Mô	ð 	×'Ñ'Ð*LÌSÐQ^ÓM_ÐL`Ð`jÐko×kvÑkvÓkxÐjyð  zHð  )Iô  	JÜ˜5Ô!ð
	RÝGÙ% d§k¡kÔ2ô Ÿ)š)›+ˆŒô 	˜EÔ"Ü+Ø4´S¸Ó5GÐ4HÈÔVYÐZ^×ZlÑZlÓVmÐUnð oRð Só Tˆ�‰�GÓøô ô 	RÜ�L‰LÐDÀj×QÑQûð	Rús   ÂC< Ã<D'ÄD"Ä"D'c                	ón  € \         P                  ! \        V P                  4      R R7      pVP	                  4        VP                  4       '       dp   VP                  RR7       V P                  RVR7       \        P                  ! 4       V P                  ,
          pW P                  8”  g   Ks  V P                  V4        V P                  R4       V P                  R,          e   V P                  R,          hV P                  R,          e   \        V P                  4       V P                  R,          # )	T©rŒ  r�  g333333Ó?rS   z)Agent interrupted during Bedrock API call)r]   z7Agent interrupted during Bedrock API call (post-worker)r5   ro   )r‘  r˜  rE   r  r«  rZ   rY   r  r  rË  rg  r§  rÈ  rÏ  rU   )rs   rX  r  s   &  r?   Ú_pollÚ_BedrockStream._pollt
  sÞ   € Ü×ÒÔ$:¸4¿<¹<Ó$HÐQUÔVˆØ	�‰Œ	Ø�j‰j�lŠlØ�F‰F˜3ˆFÔØ×&Ñ&Ð'RÐ[\Ð&Ô]Ü ŸIšI›K¨$¯/©/Õ9ˆMØ×1Ñ1Ö1Ø—‘˜}Ô-Øð 	×"Ñ"Ð#\Ô]Ø�;‰;�wÕÒ+Ø—+‘+˜gÕ&Ð&à�;‰;�zÕ"Ò.Ü §
¡
Ô+Ø�{‰{˜:Õ&Ð&rB   c                	ól   € \        V P                  4       \        V P                  V P                  4      # r:   )rì  rU   r¸  r&  r¢  s   &r?   r;   Ú_BedrockStream.runˆ
  s%   € ô 	˜DŸJ™JÔ'Ü$ T§Z¡Z°·±Ó<Ð<rB   )
rU   rÚ  rÉ  rË  rT  rG  rÓ  rÈ  rg  rÊ  r:   )rƒ   r„   r…   r†   r‡   rq   rÐ  rÓ  rÚ  rá  rà  r  r  r§  r&  r;   rˆ   rL   rB   r?   rÄ  rÄ  æ	  sD   † ñ@õMõ"9ò&òõxõ
Lò2÷h(õTò4'ö(=rB   rÄ  c                  ó   € ] tR tRtRtR R ltR R ltR R lt]R	 R
 l4       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 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4       t]R, R- l4       tR. R/ lt]R0 4       tR1 R2 ltR3 R4 ltR5 R6 lt R7 R8 lt!R9 R: lt"R; R< lt#R= R> lt$R? t%R@ t&]RA 4       t'RBRCRDRCRERCRFRC/RG lt(]RHRI/RJ RK ll4       t)RL t*RM RN lt+RO RP lt,RQ RR lt-RS RT lt.RU RV lt/RW t0RX t1RY RZ lt2R[ R\ lt3R] R^ lt4R_ R` lt5Ra Rb lt6Rc Rd lt7Re t8Rf t9Rgt:RC# )hÚ_StreamingCalli�
  zåOne streaming request on the chat_completions / anthropic_messages wire.
State shared between the request worker and the poll-loop monitor (heartbeat,
stale kill, interrupt abort) lives on the instance, mutated from both threads.c               ó   € V ^8„  d   QhRR/# rO  rL   )rM   s   "r?   rN   Ú_StreamingCall.__annotate__”
  s   € ÷ 1ñ 1¨$ñ 1rB   c                	óü  € Wn         W n        W0n        R V n        RR RR R. /V n        \        V4      V n        RR/V n        RR/V n        RR/V n	        RR/V n
        R\        P                  ! 4       /V n        R	R RR
/V n        R V n        \        P                   ! 4       V n        R^ R\%        4       R^ R^ /V n        \%        4       V n        RR /V n        R ;V n        ;V n        V n        V P3                  4       V n        R # )Nro   r5   Úpartial_tool_namesr‹   FrŽ  r%  rX  Úprogressr^  rÇ   r�  Údiscarded_chunksÚdiscarded_bytesrû   )rU   rÚ  rT  r]   rÈ  rà  ÚclientsÚ_request_cancelledrÉ  Údeltas_were_sentÚprovider_tool_in_flightr  Úlast_chunk_timer*   Ú_stream_stale_timeoutr‘  r’  Ústream_attempt_lockr³  Ústream_attempt_stateÚ_stale_counted_attemptsÚmanaged_stream_holderÚ_writer_tokenÚ_attempt_request_clientÚ_attempt_stream_responseÚ_live_routeÚ_request_routerÌ  s   &&&&r?   rq   Ú_StreamingCall.__init__”
  s	  € ØŒ
Ø$ŒØ,ÔØˆŒØ! 4¨°$Ð8LÈbÐQˆŒÜ-¨eÓ4ˆŒð $+¨EÐ"2ˆÔØ"(¨% ˆÔØ!&¨ ˆÔØ(-¨u ~ˆÔ$à #¤T§Y¢Y£[Ð1ˆÔØ *¨D°#°sÐ;ˆÔð &*ˆÔ"Ü#,§>¢>Ó#3ˆÔ Ø%.°°;ÄÃÐGYÐ[\Ð^oÐqrÐ$sˆÔ!Ü14³ˆÔ$Ø&.°Ð%5ˆÔ"à\`Ð`ˆÔÐ`˜TÔ9¸DÔ<Yà"×.Ñ.Ó0ˆÖrB   c               ó   € V ^8„  d   QhRR/# rŽ  rL   )rM   s   "r?   rN   r-  ²
  s   € ÷ tñ t˜Uñ trB   c                	ó€   a€ V P                   o\        ;QJ d    . V3R  lR 4       F  NK  	  5# ! V3R  lR 4       4      # )c              3  ód   <"  € T F%  p\        \        SVR 4      ;'       g    R 4      x € K'  	  R# 5i)r§   Nr¡  )r›   r²  rU   s   & €r?   r�   Ú-_StreamingCall._live_route.<locals>.<genexpr>´
  s,   øé € ÐsÑEr¸T”Sœ ¨¨bÓ1×7Ð7°R×8Ð8ÓErùs   ƒ0¡0)r‹  r�  rt  r`  )rU   r�  rä  s   &@r?   r@  Ú_StreamingCall._live_route²
  s0   ø€ Ø—
‘
ˆßŒuÔsÑErÓs�uÐsˆuÔsÑErÓsÓsÐsrB   c               ó   € V ^8„  d   QhRR/# rR  rL   )rM   s   "r?   rN   r-  ¶
  s   € ÷ ñ ¨tñ rB   c                ó4  € V P                  4       pWP                  8X  d   R# \        P                  RV P                  ^ ,          V P                  ^,          ;'       g    V P                  ^,          V^ ,          V^,          ;'       g
    V^,          4       R# )a¹  True once ``/model`` (``switch_model``) re-pointed the agent while this request was in
flight. The captured payload names the OLD model and is shaped for the OLD provider, but
every (re)open builds its client from the LIVE agent, so a retry would send a foreign model
slug to the new base_url (404 + a rate-limit hold, #112121). The turn loop rebuilds the
request for the current route on its own next attempt, so hand the error back to it.
FzŸStream retry skipped: model/provider switched mid-request (%s via %s -> %s via %s); handing back to the turn loop to rebuild the request for the current route.T)r@  rA  r[   r\   )rs   Úlives   & r?   Ú_route_switched_under_requestÚ,_StreamingCall._route_switched_under_request¶
  sˆ   € ð ×ÑÓ!ˆØ×&Ñ&Ô&ÙÜ�‰ðZà×Ñ Õ" D×$7Ñ$7¸Õ$:×$TÐ$T¸d×>QÑ>QÐRSÕ>TÐVZÐ[\ÕV]Ð_cÐdeÕ_f×_qÐ_qÐjnÐopÕjqô	
ñ
 rB   c               ó   € V ^8„  d   QhRR/# rÊ  rL   )rM   s   "r?   rN   r-  È
  s   € ÷ ñ ˜Tñ rB   c                ó�   € \         P                  ! \        4      ;_uu_ 4        V ! V!   RRR4       R#   + '       g   i     R# ; i)z@Best-effort callback: never let a display hook break the stream.N)rª   r«   rX   )rÁ  Úargss   &*r?   Ú_quietÚ_StreamingCall._quietÇ
  s+   € ô × Ò ¤×+Õ+Ù�ŠI÷ ,×+×+Ò+ús	   £4´A	c               ó    € V ^8„  d   QhRRRR/# )rG   rû   r   rJ   rL   )rM   s   "r?   rN   r-  Í
  s   € ÷ ñ ¨#ð °#ñ rB   c                	ó"   € WP                   R &   V# r@  )r<  rò  s   &&r?   Ú_set_managed_streamÚ"_StreamingCall._set_managed_streamÍ
  s   € Ø/5×"Ñ" 8Ñ,ØˆrB   c               ó   € V ^8„  d   QhRR/# rÊ  rL   )rM   s   "r?   rN   r-  Ñ
  s   € ÷ Vñ V tñ VrB   c                	óÜ   € \        V P                  P                  R R4      RR4      p\        V4      '       d    V! 4        R# R#   \         d    \
        P                  RRR7        R# i ; i)rû   Nrí  z&Managed provider stream cleanup failedTr”  )rì   r<  rD  rú   rX   r[   r—  )rs   rí  s   & r?   Ú_close_managed_streamÚ$_StreamingCall._close_managed_streamÑ
  sb   € Ü˜×2Ñ2×6Ñ6°xÀÓFÈÐQUÓVˆÜ�E�?Š?ðVÙ–ñ øô ô VÜ—‘ÐEÐPT�×UðVús   ºA Á"A+Á*A+c               ó   € V ^8„  d   QhRR/# rÄ  rL   )rM   s   "r?   rN   r-  Ù
  s   € ÷ ñ  sñ rB   c                	ó8  € V P                   ;_uu_ 4        V P                  R ;;,          ^,          uu&   \        V P                  R ,          4      pRRR4       RRuV P                  R&   V P                  R&   . V P
                  R&   X#   + '       g   i     L@; i)rÇ   NFr%  r0  r/  )r9  r:  r�   r6  r*   rÈ  )rs   Ú
attempt_ids   & r?   Ú_start_stream_attemptÚ$_StreamingCall._start_stream_attemptÙ
  sƒ   € Ø×%×%Ó%Ø×%Ñ% i×0°AÕ5Ó0Ü˜T×6Ñ6°yÕAÓBˆJ÷ &ð
 QVÐW[ÐMˆ×$Ñ$ UÑ+¨T×-AÑ-AÀ*Ñ-MØ,.ˆ�‰Ð(Ñ)ØÐ÷ &×%ús   •<B	Â	B	c               ó    € V ^8„  d   QhRRRR/# rö  rL   )rM   s   "r?   rN   r-  ã
  s   € ÷ Tñ T°Sð T¸Tñ TrB   c                	ó2  € V P                   ;_uu_ 4        \        V P                  R ,          4      pV'       d#   V P                  R,          P                  V4       RRR4       X'       d   \        P                  RW!4       R# R#   + '       g   i     L2; i)rÇ   r�  Nz&Marked stream attempt %s cancelled: %s)r9  r�   r:  r£  r[   r—  )rs   r·  rÇ   s   && r?   Ú_cancel_current_stream_attemptÚ-_StreamingCall._cancel_current_stream_attemptã
  sf   € Ø×%×%Ó%Ü˜$×3Ñ3°IÕ>Ó?ˆGßØ×)Ñ)¨+Õ6×:Ñ:¸7ÔC÷ &÷ Ü�L‰LÐAÀ7ÖSñ ÷	 &×%ús   •ABÂB	c               ó    € V ^8„  d   QhRRRR/# ©rG   Ústream_attempt_idr�   rJ   rô   rL   )rM   s   "r?   rN   r-  ë
  s   € ÷ nñ n¸3ð nÀ4ñ nrB   c                	óÐ   € V P                   ;_uu_ 4        V P                  pV\        VR ,          4      8H  ;'       d    WR,          9  uuRRR4       #   + '       g   i     R# ; i)rÇ   r�  N)r9  r:  r�   )rs   re  rK  s   && r?   Ú_stream_attempt_is_activeÚ(_StreamingCall._stream_attempt_is_activeë
  sL   € Ø×%×%Ó%Ø×-Ñ-ˆEØ$¬¨E°)Õ,<Ó(=Ñ=×mÐmÐBSÐalÕ[mÑBm÷ &×%×%Ó%ús   •4AÁA%	c               ó    € V ^8„  d   QhRRRR/# rd  rL   )rM   s   "r?   rN   r-  ð
  s   € ÷ Oñ O¸sð OÀtñ OrB   c                	ó’   € V P                   ;_uu_ 4        WP                  R ,          9   uuRRR4       #   + '       g   i     R# ; i)r�  N)r9  r:  ©rs   re  s   &&r?   Ú_stream_attempt_was_cancelledÚ,_StreamingCall._stream_attempt_was_cancelledð
  s.   € Ø×%×%Ó%Ø$×(AÑ(AÀ+Õ(NÑN÷ &×%×%Ó%ús	   •5µA	c               ó    € V ^8„  d   QhRRRR/# )rG   re  r�   rJ   rK   rL   )rM   s   "r?   rN   r-  ô
  s   € ÷ 
ñ 
¸Sð 
ÈDñ 
rB   c                	óÐ  €  \        \        V4      4      pV P                  ;_uu_ 4        V P                  pVR;;,          ^,          uu&   VR;;,          V,          uu&   VR,          VR,          reRRR4       X^8H  pV'       d   \
        P                  M\
        P                  ! V'       d   RMRR,           WX4       R#   \         d    ^ p L»i ; i  + '       g   i     Lk; i)rT  r1  r2  Nz3Discarding chunk from superseded stream attempt %s z-Discarded stale stream chunk from attempt %s z((discarded_chunks=%s discarded_bytes=%s))r  ÚreprrX   r9  r:  r[   r\   r—  )rs   re  r­  Úchunk_bytesrK  r1  r2  Úfirsts   &&&     r?   Ú_discard_stale_stream_chunkÚ*_StreamingCall._discard_stale_stream_chunkô
  sÂ   € ð	Üœd 5›kÓ*ˆKð ×%×%Ó%Ø×-Ñ-ˆEØÐ$×%¨Õ*Ó%ØÐ#×$¨Õ3Ó$Ø05Ð6HÕ0IÈ5ÐQbÕKc˜o÷	 &ð
 ! AÑ%ˆß Œ�Š¤f§l¡lÐ	2ßFKÑBð  RAØ8õ9à°ö	
øô ô 	ØŠKð	úç%×%ús   ‚C ªACÃCÃCÃC%	c                	ó¸   € V P                   R ,          '       gA   V P                  '       d-   RV P                   R &   V P                  V P                  4       R# R# R# )rŽ  TN)rÉ  rT  rP  r¢  s   &r?   Ú_fire_first_deltaÚ _StreamingCall._fire_first_delta  sI   € Ø×%Ñ% f×-Ô-°$×2E×2EÐ2EØ-1ˆD×"Ñ" 6Ñ*Ø�K‰K˜×+Ñ+Ö,ñ 3FÑ-rB   c               ó    € V ^8„  d   QhRRRR/# ©rG   r�   rI   rJ   rK   rL   )rM   s   "r?   rN   r-  
  s   € ÷ ,ñ ,˜sð , tñ ,rB   c                	óz   € V P                  4        V P                  P                  V4       R V P                  R&   R# )Tr%  N)rv  rU   r  r5  ©rs   r�   s   &&r?   Ú
_emit_textÚ_StreamingCall._emit_text
  s0   € Ø×ÑÔ Ø�
‰
×%Ñ% dÔ+Ø'+ˆ×Ñ˜eÓ$rB   c               ó   € V ^8„  d   QhRR/# rR  rL   )rM   s   "r?   rN   r-    s   € ÷ añ a¨ñ arB   c                ór   € \        \        V P                  RR4      ;'       g    RP                  4       4      # )zòTrue when visible assistant text actually reached a stream consumer this attempt
(``_fire_stream_delta`` records only scrubbed, delivered text; ``deltas_were_sent``
flips on any content delta, including whitespace/think-only ones nobody saw).Ú _current_streamed_assistant_textr§   )rô   rì   rU   r©   r¢  s   &r?   Ú_visible_text_deliveredÚ&_StreamingCall._visible_text_delivered  s/   € ô ”W˜TŸZ™ZÐ)KÈRÓP×VÐVÐTV×]Ñ]Ó_Ó`Ð`rB   c               ó    € V ^8„  d   QhRRRR/# ry  rL   )rM   s   "r?   rN   r-    s   € ÷ /ñ / Cð /¨Dñ /rB   c                	ó\   € V P                  4        V P                  P                  V4       R # r:   )rv  rU   r  r{  s   &&r?   Ú_emit_reasoningÚ_StreamingCall._emit_reasoning  s    € Ø×ÑÔ Ø�
‰
×(Ñ(¨Ö.rB   c               ó    € V ^8„  d   QhRRRR/# )rG   r¾  rI   rJ   rK   rL   )rM   s   "r?   rN   r-    s   € ÷ 0ñ 0 sð 0¨tñ 0rB   c                	ó\   € V P                  4        V P                  P                  V4       R # r:   )rv  rU   r  )rs   r¾  s   &&r?   Ú_emit_tool_startedÚ!_StreamingCall._emit_tool_started  s    € Ø×ÑÔ Ø�
‰
×)Ñ)¨$Ö/rB   c               ó    € V ^8„  d   QhRRRR/# ry  rL   )rM   s   "r?   rN   r-    s   € ÷ |ñ |¨3ð |°4ñ |rB   c                ór   a a€ S P                   P                  '       d   S P                  V V3R l4       R# R# )zñTool-call turns suppress content streaming (no chatty preamble), but
reasoning tags inside it must still reach the display: route through
the delta callback for tag extraction (the CLI drops non-reasoning text
once the stream box is closed).c                 óp   <€ S P                   P                  S4      S P                   P                  S4      3# r:   )rU   rø  Ú_record_streamed_assistant_textr{  s   €€r?   r@   Ú7_StreamingCall._route_suppressed_text.<locals>.<lambda>#  s)   ø€  §¡×!AÑ!AÀ$Ó!GÈÏÉ×IsÑIsÐtxÓIyÑ zrB   N)rU   rø  rP  r{  s   ffr?   Ú_route_suppressed_textÚ%_StreamingCall._route_suppressed_text  s'   ù€ ð
 �:‰:×+×+Ð+Ø�K‰KÕzÖ{ñ ,rB   c               ó   € V ^8„  d   QhRR/# )rG   rJ   rk   rL   )rM   s   "r?   rN   r-  %  s   € ÷ ñ ˜4ñ rB   c                	óZ   € V P                   P                  4       pWP                  n        V# r:   )rU   Ú_stream_diag_initr3  rã  )rs   rã  s   & r?   Ú	_new_diagÚ_StreamingCall._new_diag%  s#   € Ø�z‰z×+Ñ+Ó-ˆØ �‰ÔØˆrB   c               ó   € V ^8„  d   QhRR/# rÊ  rL   )rM   s   "r?   rN   r-  *  s   € ÷ 	Uñ 	U¨4ñ 	UrB   c                óö  € \         P                   ! 4       V P                  R&   V P                  P                  R4       \        P
                  ! \        4      ;_uu_ 4        \        VP                  R^ 4      4      ^,           VR&   VP                  R4      f   V P                  R,          VR&   \        VP                  R^ 4      4      \        V4      ,           VR&   RRR4       R#   + '       g   i     R# ; i)z=Stamp liveness for a real chunk; diagnostics are best-effort.rX  zreceiving stream responseÚchunksÚfirst_chunk_atNÚbytes)
r  r7  rU   rå  rª   r«   rX   r�   r}   rÂ  )rs   rã  r­  s   &&&r?   Ú_count_chunkÚ_StreamingCall._count_chunk*  s³   € ä$(§I¢I£Kˆ×Ñ˜SÑ!Ø�
‰
×"Ñ"Ð#>Ô?Ü× Ò ¤×+Õ+Ü  §¡¨(°AÓ!6Ó7¸!Õ;ˆD�‰NØ�x‰xÐ(Ó)Ò1Ø)-×)=Ñ)=¸cÕ)B�Ð%Ñ&ä §¡¨°!Ó 4Ó5Ô8MÈeÓ8TÕTˆD�‰M÷ ,×+×+Ò+ús   Á A=C'Ã'C8	c               ó    € V ^8„  d   QhRRRR/# )rG   Úllamacpprô   rJ   rL   )rM   s   "r?   rN   r-  5  s   € ÷ 	ñ 	°ð 	¸$ñ 	rB   c                ó  € V'       d   \        V4      MRpVf   V P                  W4       R# \        P                  ! 4       ;V P                  R&   pWEuV P                   R&   V P                   R&   V P                  P                  R4       R# )z\Count a real chunk; a llama-server prompt-progress chunk (True) is liveness, no first token.NFrX  r0  zmodel reading the promptT)r*   rœ  r  r7  rU   rå  )rs   rã  r­  rŸ  r0  Únows   &&&&  r?   Ú_take_chunkÚ_StreamingCall._take_chunk5  sx   € ç-5”? 5Ô)¸4ˆØÒØ×Ñ˜dÔ*ÙÜ*.¯)ª)«+Ð5ˆ×Ñ˜SÑ! CØFNÐCˆ×Ñ˜ZÑ(¨$×*>Ñ*>¸sÑ*CØ�
‰
×"Ñ"Ð#=Ô>ÙrB   c               ó   € V ^8„  d   QhRR/# rŽ  rL   )rM   s   "r?   rN   r-  A  s   € ÷ 	:ñ 	:ÐTYñ 	:rB   c                óª  € \        VR4      '       d   VP                  '       d   VP                  pVf@   \        \        VRR4      \        4      '       d   VP
                  '       d   VP
                  pVfZ   \        \        VRR4      \        4      '       d9   VP                  '       d'   VP                  pVP                  4       R,          V R&   W#V3# )zDModel, response id and serving provider, as the stream reports them.r‹  Nr  r�  :Né@   NÚserving_provider)r]  r‹  r|   rì   rI   r  r�  r©   )rã  r­  r  Úresponse_idÚupstream_providers   &&&&&r?   Ú_chunk_identityÚ_StreamingCall._chunk_identity@  s©   € ô �5˜'×"Ò" u§{§{ {ØŸ™ˆJØÒ¤:¬g°e¸TÀ4Ó.HÌ#×#NÒ#NÐSX×S[×S[ÐS[ØŸ(™(ˆKØÒ$¬´G¸EÀ:ÈtÓ4TÔVY×)ZÒ)ZÐ_d×_m×_mÐ_mØ %§¡ÐØ'8×'>Ñ'>Ó'@ÀÕ'EˆDÐ#Ñ$ØÐ(9Ð9Ð9rB   c               ó   € V ^8„  d   QhRR/# rÊ  rL   )rM   s   "r?   rN   r-  M  s   € ÷ .ñ .°$ñ .rB   c                ó†   € V'       d9   \        V \        4      '       d!   V P                  R4      '       g   RV R&   R# R# R# R# )zERecord that this attempt saw a terminal finish/stop reason (#102766).Úfinish_reason_seenTNrV  )rã  r  s   &&r?   Ú_mark_finish_seenÚ _StreamingCall._mark_finish_seenL  s8   € ÷ œZ¨¬d×3Ò3¸D¿H¹HÐEY×<ZÒ<ZØ)-ˆDÐ%Ó&ñ =[Ñ3‰=rB   c               ó   € V ^8„  d   QhRR/# )rG   rJ   ztuple[float, float, float]rL   )rM   s   "r?   rN   r-  T  s   € ÷  ñ  Ð"<ñ  rB   c                óH  € \        V P                  P                  V P                  P                  4      pVe   TM\	        RR4      pVe   W!\        VR4      3# \	        RR4      pV P                  pVR8X  dp   V P                  P                  '       dT   \        V P                  P                  4      '       d/   Tp\        P                  RV P                  P                  V4       M9VR8X  d3   Ve/   V\        R4      8w  d   WC8”  d   Tp\        P                  RV4       W#R	3# )
zý``(write, read, connect/pool)`` socket timeouts. Per-provider
``request_timeout_seconds`` wins over HERMES_API_TIMEOUT (1800s) and
HERMES_STREAM_READ_TIMEOUT (120s); connect/pool cover the handshake, not
inference: 30s, or capped at 60s when configured.ÚHERMES_API_TIMEOUTg      œ@r7   ÚHERMES_STREAM_READ_TIMEOUTr  uD   Local provider detected (%s) â€” stream read timeout raised to %.0fsrs  uV   Cloud reasoning stream â€” read timeout raised to %.0fs to match stale-stream detectorrÐ  )r   rU   r�  r‹  r3   rk  r8  rt  r   r[   r—  r\  )rs   r÷  r  r{  r�  s   &    r?   Ú_stream_timeoutsÚ_StreamingCall._stream_timeoutsT  sñ   € ô
 +¨4¯:©:×+>Ñ+>ÀÇ
Á
×@PÑ@PÓQˆØ’o‰s¬9Ð5IÈ6Ó+RˆØŠ?Øœc $¨›oÐ-Ð-ÜÐ5°uÓ=ˆØ×*Ñ*ˆØ�5Œ=˜TŸZ™Z×0×0Ð0Ô5FÀtÇzÁz×GZÑGZ×5[Ò5[ØˆDÜ�L‰LÐ_Ðae×akÑak×atÑatÐvzÕ{Ø�UŒ]˜uÒ0°U¼eÀE»lÔ5JÈuÌ|ð ˆDÜ�L‰LÐqÐswÔxØ˜4ÐÐrB   c           	     ó6  € \        V R4      '       d   V P                  '       d   V P                  MRp\        V RR4      p\        V RR4      pV'       g	   V'       db   \        RVRV/4      ;'       g    \	        V4      p\        RT;'       g    RR\        T;'       g    T 4      /V4      p\        WVV RV 2R	7      h\        V R
R4      pVf=   \        \        V RR4      \        4      '       d   V P                  P                  R
4      pVR9   d   Vf   RpW!3# )a  Chunk with empty ``choices`` -> ``(usage, finish_reason)``. Raises
ProviderStreamError for providers (DeepInfra) that send validation errors
as in-stream chunks (choices=None + error_type/error_message), which
would otherwise surface as a misleading EmptyStreamError plus retries.ru  NÚ
error_typeÚerror_messagery   rz   Úprovider_in_stream_errorr{   )rh   rj   rl   ÚlastOner  Ústop)TrÍ   r&  )r]  ru  rì   r¤   r•   rã   rI   re   r|   rk   r  r}   )r­  r  ru  Ú	_err_typeÚ_err_msgÚ_statusrj   Úlast_ones   &&      r?   Ú_choiceless_chunkÚ _StreamingCall._choiceless_chunki  s  € ô  ' u¨g×6Ò6¸5¿;¿;¸;�—’ÈDˆô ˜E <°Ó6ˆ	Ü˜5 /°4Ó8ˆßŸÜ/°¸ÀIÈxÐ0XÓY×ÐÔ]tÐu~Ó]ˆGÜ'Ø˜×@Ð@Ð&@À)ÌSÐQY×QbÐQbÐ]bÓMcÐdÐfmóoˆDä%°'ÐR[ÐQ\Ð\^Ð_gÐ^hÐOiÔjÐjô ˜5 )¨TÓ2ˆØÒ¤
¬7°5¸-ÈÓ+NÔPT× UÒ UØ×(Ñ(×,Ñ,¨YÓ7ˆHØÐ(Ô(¨]Ò-BØ"ˆMØÐ#Ð#rB   c               ó   € V ^8„  d   QhRR/# )rG   Ústream_kwargsr"  rL   )rM   s   "r?   rN   r-  ƒ  s   € ÷ Gñ G¨~ñ GrB   c                	óè  € \        V P                  P                  4      '       g%   \        V P                  R R4      '       g   RR/VR&   V P                  P                  V P                  P                  RVR7      4      ;q n        \        P                  ! 4       V P                  R&   V P                  P                  R4       \        W4      pVP                  P                  P                  ! R	/ VB # )
Ú_stream_options_unsupportedFÚinclude_usageTr€  Úchat_completion_stream_requestrÅ  rX  z)waiting for provider response (streaming)rL   )r   rU   rt  rì   r3  rê  rÇ  r>  r  r7  rå  r   r[  r\  rQ   )rs   rÄ  rd  s   && r?   Ú_open_chat_streamÚ _StreamingCall._open_chat_streamƒ  sÉ   € ô )¨¯©×)<Ñ)<×=Ò=ÄgÈdÏjÉjÐZwÐy~×FÒFØ/>ÀÐ.EˆMÐ*Ñ+Ø8<¿¹×8OÑ8OØ�J‰J×4Ñ4Ð<\ÐivÐ4Ówó9yð 	yˆÔ5ä$(§I¢I£Kˆ×Ñ˜SÑ!Ø�
‰
×"Ñ"Ð#NÔOô :¸-ÓXˆØ×"Ñ"×.Ñ.×5Ò5ÑF¸ÑFÐFrB   c               ó    € V ^8„  d   QhRRRR/# ©rG   Ú
raw_streamr   rJ   rK   rL   )rM   s   "r?   rN   r-  ‘  s   € ÷ -ñ -¨sð -°tñ -rB   c                	óº  € \        VR R4      ;q n        V P                  P                  V4       V P                  P	                  V4       V P                  P                  V4       V P                  P                  V P                  P                  V4       V P                  P                  V4       \        V P                  4      V n        V P                  V4       R# )ro   N)rì   r?  rU   Ú_capture_rate_limitsÚ_capture_creditsÚ_capture_nous_model_switchÚ_stream_diag_capture_responser3  rã  Ú_check_openrouter_cache_statusr.   r=  Ú_reabort_if_cancelled)rs   rÍ  ro   s   && r?   Ú_chat_stream_createdÚ#_StreamingCall._chat_stream_created‘  sœ   € Ü3:¸:ÀzÐSWÓ3XÐXˆÔ0Ø�
‰
×'Ñ'¨Ô1Ø�
‰
×#Ñ# HÔ-Ø�
‰
×-Ñ-¨hÔ7Ø�
‰
×0Ñ0°·±×1BÑ1BÀHÔMØ�
‰
×1Ñ1°(Ô;Ü0°·±Ó<ˆÔØ×"Ñ" 8Ö,rB   c               ó    € V ^8„  d   QhRRRR/# ©rG   ro   r   rJ   rK   rL   )rM   s   "r?   rN   r-  ›  s   € ÷ Yñ Y¨cð Y°dñ YrB   c                ó
  € V P                   ;_uu_ 4        \        V P                  R,          4      pV P                  R,          ;'       g    W P                  R,          9   pRRR4       X'       g   R# V P	                  V4       V P
                  e^   V P                  P                  R8X  d   V P                  P                  MV P                  P                  pV! V P
                  RR7       R# R#   + '       g   i     L˜; i)uš  Interrupt/stale abort that raced ``create()``: the one-shot pool sweep ran while
the connect/TLS window held no socket yet (``tcp_force_closed=0``), so nothing stopped
the request once it came up and the serve kept generating into a dropped consumer
(#98974). Response headers prove the socket exists now â€” shut it down (shutdown-only,
never a cross-thread close) so the worker unwinds as after a stale kill.rÇ   r‹   r�  NrU  Úcancelled_attempt_late_connectrº  )
r9  r�   r:  r4  Ú_shutdown_stale_attempt_socketr>  rU   r`  rý  r»  )rs   ro   rÇ   r�  r”  s   &&   r?   rÔ  Ú$_StreamingCall._reabort_if_cancelled›  sÇ   € ð ×%×%Ó%Ü˜$×3Ñ3°IÕ>Ó?ˆGØ×/Ñ/°Õ8×mÐm¸G×G`ÑG`ÐalÕGmÑ<mˆI÷ &÷ ÙØ×+Ñ+¨HÔ5Ø×'Ñ'Ò3ð DHÇ:Á:×CVÑCVÐZnÔCn�T—Z‘Z×?Ò?ØŸ*™*×AÑAð á�$×.Ñ.Ð7W×Xñ 4÷ &×%ús   •AC2Ã2D	c               ó$   € V ^8„  d   QhRRRRRR/# )rG   re  r�   r­  r   rJ   rô   rL   )rM   s   "r?   rN   r-  ®  s!   € ÷ ñ °Cð Àð Èñ rB   c                	ó†  a€ \         P                  ! \        4      ;_uu_ 4        \        VR R4      pV'       d
   V^ ,          MRp\        VRR4      o\        SRR4      '       d   RV P                  R&   \        VRR4      '       dL   \
        ;QJ d    V3R lR 4       F  '       g   K   RM	  RM! V3R lR 4       4      '       g    RRR4       R# RRR4       V P                  V4      '       g   R# V P                  R	4      '       g   R# \        P                  ! 4       V P                  R
&   R#   + '       g   i     Lf; i)r¶  Nr·  r»  Tr%  r  c              3  ó>   <"  € T F  p\        SVR 4      x € K  	  R # 5ir:   r°  )r›   r²  r·  s   & €r?   r�   Ú4_StreamingCall._accept_chat_chunk.<locals>.<genexpr>¹  s#   øé € ð BtÙ7r¨t”˜˜t T×*Ð*Ó7rùs   ƒFÚ	StreamingrX  )r¸  r»  r¹  rº  )
rª   r«   rX   rì   r6  rÀ   rg  Ú_writer_still_currentr  r7  )rs   re  r­  r¶  Úchoicer·  s   &&&  @r?   Ú_accept_chat_chunkÚ!_StreamingCall._accept_chat_chunk®  s  ø€ Ü× Ò ¤×+Õ+Ü˜e Y°Ó5ˆGß#*�W˜Q–Z°ˆFÜ˜F G¨TÓ2ˆEô �u˜l¨D×1Ò1Ø6:�×,Ñ,¨UÑ3ô �v˜°×5Ò5¿c»cô BtÙ7róBt¿c¿cºcô BtÙ7róBt÷ ?tò ?tà÷ ,×+Ñ+ð ×-Ñ-Ð.?×@Ò@ÙØ×)Ñ)¨+×6Ò6Ùô %)§I¢I£Kˆ×Ñ˜SÑ!Ù÷) ,×+ús   ¤A-D0ÂD0Â)D0ÃD0Ä0E 	c               ó    € V ^8„  d   QhRRRR/# )rG   rH   rI   rJ   rô   rL   )rM   s   "r?   rN   r-  Å  s   € ÷ ñ ¨3ð °4ñ rB   c                óÂ   € V P                   pVe   \        V P                  V4      '       d   R# \        P	                  RWP
                  P                  RR4      4       R# )zXSingle-writer fence: False (with a warning) once a newer stream claimed the writer slot.Tzq%s attempt superseded by a newer stream; stopping consumption to preserve the single-writer invariant (model=%s).r‹  rÜ  F)r=  r/   rU   r[   r\   rÚ  r}   )rs   rH   rô  s   && r?   râ  Ú$_StreamingCall._writer_still_currentÅ  sR   € à×"Ñ"ˆØŠ=Ô4°T·Z±ZÀ×GÒGÙÜ�‰ð2Ø38¿/¹/×:MÑ:MÈgÐW`Ó:aô	cñ rB   c               ó   € V ^8„  d   QhRR/# ©rG   re  r�   rL   )rM   s   "r?   rN   r-  Ï  s   € ÷ Gñ G¸ñ GrB   c                óü  a aa.a/a0a1a2a3a4a5€ ^ RI o.S P                  4       w  o/o3o0. p. p. p. p. p. o2^ RIHp V! 4       pVP                  o5^ RIHp	 V	! 4       p
R;p;rÍR;rïRpS P                  4       pR;S n        ;S n	        S n
        ^ RIHp V! 4       p\        4       \        4       pp\        4       pRp\        S P                  4      o1R V.V/V0V1V3V 3R llpV2V V53R lp^ R	IHp S P#                  VP$                  ! S P&                  V3/ \)        S P                  R
4      BRVP*                  RS P,                  RVP.                  RV V3R lRR R\1        S P                  R4      RR/B 4      o4S P                  P2                  R8X  d   S P4                  P7                  S44       R V V43R llp\9        S4V 3R lR7       EF`  pS P;                  VVS14      pS P                  P<                  '       d   V! R4        EM'S P?                  S4      '       g   S PA                  SV4       Ki  V'       d   Ks  S PC                  VVWÎV4      w  rÎpVPD                  '       g6   S PG                  VV4      w  ppT;'       g    TpS PI                  VV4       KÑ  VPD                  ^ ,          pVPJ                  p \M        \O        VRR4      4      ;'       g    TpS PI                  VV4       \Q        VR4      '       d   VPR                  '       d   VPR                  p\O        V RR4      ;'       g    \O        V RR4      p!V!f`   \U        \O        V R R4      \V        4      '       d?   V PX                  P[                  R4      ;'       g    V PX                  P[                  R4      p!V
P]                  V V!4      p!V!'       d/   \_        V'       d
   VR.,          MR!V!4      p!VPa                  V!4       \O        V R"R4      p"V"f=   \U        \O        V R R4      \V        4      '       d   V PX                  P[                  R"4      p". p#\U        V"\b        \d        34      '       d   T"MR/ F)  p$V#Pa                  \g        V$4      4       \i        VV$4       K+  	  R!Pk                  V#4      p%V%'       d/   \_        V'       d
   VR.,          MR!V%4      p%VPa                  V%4       T%;'       g    T!p&V&'       dE   S Pm                  V&4       VP]                  V!4      '       g   VP]                  V%4      '       d   Rp EM\O        V R#R4      p'V'f=   \U        \O        V R R4      \V        4      '       d   V PX                  P[                  R#4      p'\U        V'\n        4      '       d   V''       d   VPa                  V'4       \q        \O        V R$R4      R!R%7      p(V('       dù   VPa                  V(4       VP]                  V(4      '       d   R$p EMBS5'       d   S Ps                  V(4       M±S2'       gK   \u        V(4      '       g:   S Pv                  R&,          '       go   \y        R!Pk                  V4      4      '       dO   S2Pa                  V(4       R!Pk                  S24      p)\u        V)4      '       g   \y        V)4      '       g   V! 4        EKÝ  S P{                  V(4       \O        V R'R4      p*V*'       g   EK  V! 4        V* FM  p+VP]                  V+4      p,V,f   K  S P}                  V,4       S P~                  R(,          Pa                  V,4       KO  	  EKc  	  V'       d   V! R)4       S P�                  V4       VPƒ                  4        S P…                  4        S P‡                  S4      '       d   S.P‰                  R*S R+24      hS4PŠ                  e   S P�                  S4PŠ                  4      # S P�                  S4TY#S5V'       d   R,MTWÍVWïVVR-7      p-V
P‘                  V-4       V'       d   RV-nI        V-# )0z#Stream a chat completions response.N)Ú_ToolCallAccumulator)ÚStreamCarriersr  )ÚRelayChatAccumulatorc               ó   € V ^8„  d   QhRR/# rÝ  rL   )rM   s   "r?   rN   Ú;_StreamingCall._call_chat_completions.<locals>.__annotate__ö  s   € ÷ 	cñ 	c¨.ñ 	crB   c                ó†   <€ SP                  SSSSR 7      pS'       d   \        V 4      p SP                  / V CRRRV/C4      # )ry  rû   TrT   )r�  r+   rÉ  )rÞ  rT   rƒ  Úbase_timeoutr‚  rŸ  Úread_timeoutrs   s   & €€€€€€r?   rá  Ú;_StreamingCall._call_chat_completions.<locals>._open_streamö  sK   ø€ Ø—n‘n¨X¸LÐP\Ðck�nÓlˆGßÜ"6°Ó"G�Ø×)Ñ)Ð*a¨_Ð*a¸hÈÈiÐY`Ñ*aÓbÐbrB   c                 óœ   <€ \        S4      p SP                  4        V  F)  pS'       d   SP                  MSP                  ! V4       K+  	  R # r:   )rÂ   Úclearr�  r|  )Úpending_partsr�   Úpending_text_partsrs   Útool_calls_accs     €€€r?   Ú_flush_pending_stream_textÚI_StreamingCall._call_chat_completions.<locals>._flush_pending_stream_textü  s>   ø€ Ü Ð!3Ó4ˆMØ×$Ñ$Ô&Û%�ß0>�×,Ò,ÀDÇOÁOÐSÐUYÖZó &rB   r	  r�  rü  r   r  r  c                ó(   <€ SP                  SV 4      # r:   )rä  )r­  rs   re  s   &€€r?   r@   Ú7_StreamingCall._call_chat_completions.<locals>.<lambda>  s   ø€  t×'>Ñ'>Ð?PÐRWÔ'XrB   r  c                ó   € \        V R 4      # )r¶  )r]  rè  s   &r?   r@   rý    s   € ´w¸uÀiÔ7PrB   r  rk  r  TrZ  c               ó    € V ^8„  d   QhRRRR/# rö  rL   )rM   s   "r?   rN   rð    s   € ÷ 	iñ 	i¨Cð 	i°Dñ 	irB   c                ó¾   <€  SP                  4        R #   \         d=    SP                  e+   SP                  P	                  SP                  T R7        R #  R # i ; i)Nrº  )rí  rX   r>  rU   r»  )r·  rs   rû   s   &€€r?   Ú_close_half_read_streamÚF_StreamingCall._call_chat_completions.<locals>._close_half_read_stream  sR   ø€ ðiØ—‘–øÜô ià×/Ñ/Ò;Ø—J‘J×;Ñ;¸D×<XÑ<XÐagÐ;×hò <ðiús   ƒ •A AÁAc                 ó   <€ S P                   # r:   )r?  r¢  s   €r?   r@   rý    s   ø€ È4×KhÒKhrB   rù   Úinterrupt_stream_close_failedr  ru  r¹  rº  r  r§   r  Úrefusalr¸  )r×   r%  r»  r/  Úrunaway_stream_close_failedzstream attempt z was supersededÚlength)Úflush_pendingr¨  r©  r  Úrefusal_partsr6  rL   )Jr€  rµ  Ú(agent.chat_completion_helpers_tool_callsrì  ÚaccrÃ  rí  r•  r=  r>  r?  Ú#agent.chat_completion_helpers_relayrî  r,   r   rU   r
  rT  rû   rÚ  r¢  ÚfinalizerÕ  Úobserverª  r�  r3  ró  rý   r¢  rÖ  rg  rs  rª  r¶  rÁ  r¯  r·  Ú_normalize_finish_reasonrì   r]  ru  r|   rk   r  r}   Úfeedr(   r~   rÂ   r�  r)   r'   rY   r…  rI   r   r�  r  r5  r   r|  r‰  rÈ  Ú_log_runaway_cutÚmaterializerX  rl  ÚRemoteProtocolErrorrT  Ú_adopt_final_responseÚ_finish_chat_streamÚapplyÚ_runaway_repetition)6rs   re  Úcontent_partsÚreasoning_partsÚdetail_display_partsr	  r  rì  r»  rí  Úcarriersr  r  r|  r¨  r©  r  Ú_diagrî  Úrelay_responseÚcontent_watchÚreasoning_watchÚdetail_watchÚrunawayrá  rú  r
  r  r­  Úis_progressru  rã  r·  rû  Úrd_deltaÚdetail_text_partsÚrdÚdetail_textÚdisplay_reasoningÚdelta_refusalÚdelta_contentrÏ  Údelta_tool_callsÚtc_deltar¾  ro   rƒ  rò  r‚  rŸ  rø  ró  rû   rù  s6   ff                                            @@@@@@@@r?   Ú_call_chat_completionsÚ%_StreamingCall._call_chat_completionsÏ  s(  ÿù€ ãØ/3×/DÑ/DÓ/FÑ,ˆ�l HØ ˆØ "ˆð
 +-Ðð $&ˆØ"$ÐØ(*ÐÝQÙ)Ó+ˆ
Ø#Ÿ™ˆÝ;Ù!Ó#ˆØ15Ð5ˆÐ5˜
Ø*.Ð.ˆØˆØ—‘Ó ˆØ\`Ð`ˆÔÐ`˜TÔ9¸DÔ<YÝLÙ-Ó/ˆô *<Ó)=Ô?QÓ?S�ˆô *Ó+ˆØˆä$ T§Z¡ZÓ0ˆ÷	cõ 	c÷	[õ 	$Ø×)Ñ)¨)×*:Ò*:¸4¿?¹?ÈLñ +lÜ$ T§Z¡Z°Ó<ñ+lØHV×H_ÑH_ð+là"×7Ñ7ð+làBP×BXÑBXð+lõ Yð+lñ *Qð	+lô
 ,¨D¯J©JÐ8JÓKð+lð
 gkò+ló mˆð �:‰:×Ñ %Ô'à�L‰L×*Ñ*¨6Ô2÷	iñ 	iô 2°&ÔCh×iÐiˆEØ×*Ñ*¨5°%¸ÓBˆKØ�z‰z×.×.Ð.Ù'Ð(GÔHÚØ×1Ñ1Ð2C×DÒDØ×0Ñ0Ð1BÀEÔJÙßÙØ9=×9MÑ9MØ�u˜jÐ7Hó:JÑ6ˆJÐ%6à—=—=�=Ø'+×'=Ñ'=¸eÀ]Ó'SÑ$��}Ø!×.Ð. Y�	Ø×&Ñ& u¨mÔ<Ùà—]‘] 1Õ%ˆFØ—L‘LˆEô 5´W¸VÀ_ÐVZÓ5[Ó\×mÐmÐ`mˆMØ×"Ñ" 5¨-Ô8Ü�u˜g×&Ò&¨5¯;¯;¨;Ø!ŸK™K�	ä$ UÐ,?ÀÓF×kÐkÌ'ÐRWÐYdÐfjÓJkˆNð Ò%¬*´W¸UÀMÐSWÓ5XÔZ^×*_Ò*_Ø!&×!2Ñ!2×!6Ñ!6Ð7JÓ!K×!qÐ!qÈu×O`ÑO`×OdÑOdÐepÓOq�à%Ÿ]™]¨5°.ÓAˆNßä!@ß+:�O BÖ'ÀÀNó"T�à×&Ñ& ~Ô6ô
 ˜uÐ&9¸4Ó@ˆHØÒ¤J¬w°u¸mÈTÓ/RÔTX×$YÒ$YØ ×,Ñ,×0Ñ0Ð1DÓE�Ø "ÐÜ",¨X¼¼e°}×"EÒ"E‘hÈ2ÒM�Ø!×(Ñ(Ô)GÈÓ)KÔLÜ0Ð1BÀBÖGñ Nð Ÿ'™'Ð"3Ó4ˆKßÜ=ß0DÐ(¨Ö,È"Èkó[�à$×+Ñ+¨KÔ8Ø +× =Ð =¨~Ðß Ø×$Ñ$Ð%6Ô7Ø"×'Ñ'¨×7Ò7¸<×;LÑ;LÈ[×;YÒ;YØ)�GÚô $ E¨9°dÓ;ˆMØÒ$¬´G¸EÀ=ÐRVÓ4WÔY]×)^Ò)^Ø %× 1Ñ 1× 5Ñ 5°iÓ @�Ü˜-¬×-Ò-·-Ø×$Ñ$ ]Ô3ô 1´¸À	È4Ó1PÐVXÔYˆMßØ×$Ñ$ ]Ô3Ø ×%Ñ% m×4Ò4Ø'�GÚß!Ø×/Ñ/°Õ>ß(Ô,LÈ]×,[Ò,[ð !%× 5Ñ 5°e× <Ô <ÔA_Ð`b×`gÑ`gÐhuÓ`v×AwÒAwØ&×-Ñ-¨mÔ<Ø Ÿg™gÐ&8Ó9�GÜ<¸W×EÒEÔIgÐho×IpÒIpÙ2Ô4Úà—O‘O MÔ2ä& u¨l¸DÓAÐßÒÙ*Ô,Û 0�HØ%Ÿ?™?¨8Ó4�DØÔ'Ø×/Ñ/°Ô5ð Ÿ™Ð$8Õ9×@Ñ@ÀÖFô !1ñM j÷\ Ù#Ð$AÔBØ×!Ñ! 'Ô*Ø×ÑÔ Ø×"Ñ"Ô$Ø×-Ñ-Ð.?×@Ò@Ø×,Ñ,¨Ð?PÐ>QÐQ`Ð-aÓbÐbØ× Ñ Ò,Ø×-Ñ-¨f×.CÑ.CÓDÐDØ×+Ñ+¨F°D¸-ÐZhß‰H ]°JÐYsØ#Ð\mØ'ð ,ó )ˆð 	�‰�xÔ ßà+/ˆHÔ(ØˆrB   c               ó    € V ^8„  d   QhRRRR/# )rG   ÚchannelrI   rJ   rK   rL   )rM   s   "r?   rN   r-  ˜  s   € ÷ >ñ >¨ð >°ñ >rB   c                	óÒ   € \         P                  R \        V P                  RR4      YP                  P                  RR4      \        V P                  RR4      ;'       g    R4       R# )zS%sStream cut: the %s turned into a runaway repetition loop (model=%s, provider=%s).rZ  r§   r‹  rÜ  r�  N)r[   r\   rì   rU   rÚ  r}   )rs   r/  s   &&r?   r  Ú_StreamingCall._log_runaway_cut˜  sN   € Ü�‰ØaÜ�D—J‘J ¨bÓ1°7¿O¹O×<OÑ<OÐPWÐYbÓ<cÜ�D—J‘J 
¨BÓ/×<Ð<°9ö	>rB   c                óì   € \         P                  RV P                  P                  ;'       g    RV P                  P                  ;'       g    R4       RV P                  n        V P                  V4      # )z€Adapter returned a completed response for ``stream=True``: switch the
session to non-streaming and replay its content as deltas.z}Streaming request returned a final response object instead of an iterator; switching %s/%s to non-streaming for this session.rÜ  T)r[   rø  rU   r�  r‹  ræ  Ú_replay_final_response)rs   rT  s   &&r?   r  Ú$_StreamingCall._adopt_final_responsež  s`   € ô 	�‰ð AØBFÇ*Á*×BUÑBU×BbÐBbÐYbØ�J‰J×Ñ×)Ð) 	ô	+ð )-ˆ�
‰
Ô%Ø×*Ñ*¨>Ó:Ð:rB   c                ó°  € VP                   p\        \        V\        \        34      '       d   V'       d
   V^ ,          MRRR4      pVEe   \        VRR4      ;'       g    \        VRR4      pVf`   \        \        VRR4      \
        4      '       d?   VP                  P                  R4      ;'       g    VP                  P                  R4      p\        V\        4      '       d   V'       d   V P                  V4       \        VRR4      p\        V\        4      '       d4   V'       d,   V P                  4        V P                  P                  V4       V# )zKReplay a completed chat-completions response's reasoning/content as deltas.Nrz   r¹  rº  r  r¸  )r¶  rì   r|   rÂ   r�  rk   r  r}   rI   r…  rv  rU   r  )rs   rT  r¶  rz   rû  r¸  s   &&    r?   r3  Ú%_StreamingCall._replay_final_response§  s  € à ×(Ñ(ˆÜ¬
°7¼TÄ5¸M×(JÒ(JÏw˜' !ž*Ð\`ÐbkÐmqÓrˆØÓÜ$ WÐ.AÀ4ÓH×oÐoÌGÐT[Ð]hÐjnÓLoˆNØÒ%¬*´W¸WÀmÐUYÓ5ZÔ\`×*aÒ*aØ!(×!4Ñ!4×!8Ñ!8Ð9LÓ!M×!uÐ!uÐQX×QdÑQd×QhÑQhÐitÓQu�Ü˜.¬#×.Ò.·>Ø×$Ñ$ ^Ô4Ü˜g y°$Ó7ˆGÜ˜'¤3×'Ò'¯GØ×&Ñ&Ô(Ø—
‘
×-Ñ-¨gÔ6ØÐrB   c                ó  € . pRp\        V 4       EF  pW,          pVR,          R,          pV'       dt   VP                  4       '       d^    \        P                  ! V4       VfB   \        V4      '       d1   \        P                  R	VR,          R,          ;'       g    R4       RpMVf   RpVP                  \        VR
,          VR,          VP                  R4      \        VR,          R,          VWeR,          R,          8g  VP                  R4      R7      R7      4       EK  	  T;'       g    RV3#   \        P                   d>    Tf   Rp Lñ\        YeR,          R,          ;'       g    R4      pTR8w  d   Tp EL Rp EL%i ; i)zEMaterialize accumulated tool calls; flag truncated/unrepairable args.Fr¼  r½  NTr¾  Ú?r  zkTool call '%s' has repetition-dominated arguments without a finish_reason; treating as a dropped tool call.r  rÜ   r  r  )r¾  r½  Úargs_repairedr  )r  rÜ   r  r¼  )rs  r©   r¬   r°   r­   r#   r-   r[   r\   r~   r   r}   )rù  r  Úmock_tool_callsÚhas_truncated_tool_argsr   rÀ  r½  Úrepaireds   &&      r?   Ú_assemble_tool_callsÚ#_StreamingCall._assemble_tool_calls·  sx  € ð ˆØ"'ÐÜ˜.×)ˆCØÕ$ˆBØ˜:� {Õ3ˆIß˜YŸ_™_×.Ò.ð;Ü—J’J˜yÔ)ð  !Ò(Ô-DÀY×-OÒ-OÜ—N‘NðJØKMÈjÍ>ÐZ`ÕKa×KhÐKhÐehôjð /3Ð+øØÒ&ð +/Ð'Ø×"Ñ"¤?Ø�d•8 " V¥*¸B¿F¹FÀ?Ó<SÜ(¨b°­n¸VÕ.DÐPYØ7@ÀzÅNÐS^ÕD_Ñ7_Ø;=¿6¹6ÐBUÓ;VôXô$Y÷ Zñ= *ðF ×&Ð& $Ð(?Ð?Ð?øô; ×+Ñ+ô ;ð %Ò,Ø26Ò/ô $?¸yÈZÍ.ÐY_ÕJ`×JgÐJgÐdgÓ#h˜Ø# tÔ+Ø(0›Ià6:Ó3ð;ús$   ÁD5Ä5FÅFÅ.FÆFÆFr¨  Nr©  r  r	  c	               óœ  € RP                  V4      ;'       g    RpRP                  V4      ;'       g    RpV'       g,   V'       d$   ^ RIHp V! V P                  \	        VR7      4      pV P                  WV4      w  ppVf,   V'       g$   V'       g   V'       g   V'       g   \        R4      hV'       dn   Vfj   \        V4       Uu. uF$  pVV,          R,          R,          ;'       g    RNK&  	  pp\        P                  R	V4       \        Y.Y÷TT;'       g    RR
R7      # VfA   V'       g	   V'       d1   V'       g)   Vf%   \        P                  R4       \        W.W÷VR
R7      # V'       d   RMT;'       g    Rp\        T;'       g    RV\        VRR4      R7      pVe   Vh\	        Y.TTRP                  T;'       g    R4      ;'       g    RR7      pV'       d   VVn        \	        T
;'       g&    R\        \        P                   ! 4       4      ,           WxV\	        ^ VVR7      .R7      p\#        V4      '       g   V	! 4        V# u upi )zëAssemble the non-streaming-shaped response after the chunk loop. A
stream ending with no finish_reason is a drop, not a completion: return a
partial-stream stub so the loop fails fast instead of executing empty
args or stamping "stop".r§   N)Úextract_reasoning)r¸  zlProvider returned an empty stream with no finish_reason (possible upstream error or malformed SSE response).r¼  r¾  r8  zßClean EOF, no finish_reason: server ended the stream (no transport exception) while a tool call's arguments were still incomplete (tools=%s). The server or a proxy closed the stream cleanly; not an output-length truncation.T)ro  rq  z¨Clean EOF, no finish_reason: server ended the stream (no transport exception) after delivering text with no tool calls. The server or a proxy closed the stream cleanly.)rq  r  r¼  ro   rù   )r  r¸  r»  r¹  r  zstream-ry  )r  r‹  ru  r�  r¶  rL   )rY   Úagent.agent_runtime_helpersr@  rU   r   r=  r   rs  r[   r\   r}  r  rì   r  rI   rÁ  rÂ  r   )rs   rû   r  r  r  rù  r  r  r|  r  r¨  r©  r  r	  rz  r{  r@  r:  r;  r   Ú_dropped_namesÚeffective_finish_reasonrÞ   rz   ro   s   &&&&&&&&&$$$$$           r?   r  Ú"_StreamingCall._finish_chat_streamá  s#  € ð —w‘w˜}Ó-×5Ð5°ˆØŸ™ Ó1×9Ð9°Tˆß§,õ Fá.¨t¯z©z¼?ÐS_Ô;`ÓaˆNØ37×3LÑ3LÈ^Ó3kÑ0ˆÐ0àÒ ¯¿×Wd×m{Ü"Ø~ó@ð @ç" }Ò'<ô [aÐaoÔZpÓqÑZpÐSV˜~¨cÕ2°:Õ>¸vÕF×MÐMÈ#ÒMÑZpˆNÐqÜ�N‰Nð<ð ô	 ô
 .Ø NÀ	Ð^l×^tÐ^tÐptØô ð  ð Ò §m·×P^ÐclÒctô
 �N‰Nð\ô]ô .¨dÀ.Ð^gÐswÔxÐxß.E¡(ÈM×LcÐLcÐ]cÐÜ @Ø×Ð˜BÐ 7Ä'È&ÐR\Ð^bÓBcô!eÐà Ò,Ø'Ð'Ü! tÈoÐqà—G‘G˜M×/Ð/¨RÓ0×8Ð8°Dô:ˆ÷ ð ):ˆGÔ%ô # k×&TÐ&T°iÄ#ÄdÇjÂjÃlÓBSÕ6SÐ\fØ&Ü$¨1°gÐMdÔeÐfôhˆô
 & h×/Ò/ÙŒOØˆùòO rs   Ã"I	Ã)I	Ú	tool_dropTc               ó   € V ^8„  d   QhRR/# )rG   rE  rô   rL   )rM   s   "r?   rN   r-  $  s   € ÷ ñ ¸ñ rB   c               óD  € \        V RR4      pV'       g   \        V RR4      f   \        R4      hV'       di   \        V RR4      fZ   \        ;QJ d&    R T;'       g    .  4       F  '       g   K   RM	  RM! R T;'       g    .  4       4      '       d   \        R4      hV # )	uf  Raise EmptyStreamError for a message the stream never completed: no
content and no stop_reason (eventless -> retry), or with ``tool_drop`` a
``tool_use`` block and no stop_reason â€” the SSE closed mid tool call and
its input is a partial snapshot (usually ``{}``), so raising blocks the
empty-args execution (bounded retry, or stub/continuation after text).r¸  Nrs  zjProvider returned an empty stream with no stop_reason (possible upstream error or malformed event stream).c              3  óB   "  € T F  p\        VR R4      R8H  x € K  	  R# 5i)rÜ   NÚtool_user°  )r›   Úblocks   & r?   r�   Ú:_StreamingCall._check_anthropic_message.<locals>.<genexpr>.  s#   é € ð OSÙDQ¸5ŒG�E˜6 4Ó(¨JÖ6ÃMùs   ‚TFzStream ended with no stop_reason while a tool_use block was still incomplete; treating as a mid-tool-call stream drop (#80498).)rì   r   rÀ   )rz   rE  r¸  s   &$ r?   Ú_check_anthropic_messageÚ'_StreamingCall._check_anthropic_message#  s¬   € ô ˜' 9¨dÓ3ˆßœ7 7¨M¸4Ó@ÒHÜ"Ø|ó~ð ~çœ ¨-¸Ó>ÒFÏ3Ë3ñ OSØDKÇMÀMÈrÀMóOSÏ3Ï3Ê3ñ OSØDKÇMÀMÈrÀMóOS÷ LSò LSä"ðDóEð Eð ˆrB   c                óf
  a aaaaa€ RpRpRp\         P                   ! 4       S P                  R&   S P                  4       oR;S n        S n        SS n        RRRR/oRp\        4       \        4       rvRp^ RIHp	 ^ RI	H
oHo V	P                  4       p
R VVVVV 3R	 llpR
 VVV 3R llpS P                  V	P                  ! S P                  V3/ \!        S P                  R4      BRV
P"                  RVRV
P$                  RV 3R lR\'        S P                  R4      RR/B 4      p V EF÷  pRpS P)                  SV4       S P                  P*                  '       d    EMÅ\-        VRR4      pVR8X  d   RpKO  VR8X  d+   S P/                  S\-        \-        VRR4      RR4      4       K€  VR8X  d�   \-        VRR4      pV'       dx   \-        VRR4      R8X  dc   Rp\-        VRR4      '       dK   S P1                  VP2                  4       S P4                  R,          P7                  VP2                  4       EK  EK  EK  EK  VR 8X  g   EK   \-        VRR4      pV'       d   \-        VRR4      MRpVR!8X  dM   \-        VR"R#4      pV'       d   V'       g   S P9                  V4       VP;                  V4      '       d   R$p MhEK—  VR%8X  g   EK¡  \-        VR&R#4      '       g   EK·  S P=                  VP>                  4       VP;                  VP>                  4      '       g   EKö  R'p M	  SR,          pS P                  P*                  '       gw   Ves   V'       gk   V'       g   \A        V'       d   R(4      hR)4      hVPC                  4       pV
P#                  4       PE                  R*4      pVe   \-        VR*R4      f   VVn#         S PI                  4        SR,          pVe   VPK                  RRR4       S P                  P*                  '       d   R# T'       dD   S PM                  T4       T
PO                  SR,          PP                  4      pR+Tn)        RTn*        T# Te7   S PW                  TRR,7       TPX                  '       g   S PW                  T4      # S PW                  T
PO                  T4      4      #   SR,          pTe   TPK                  RRR4       i i ; i   S PI                  4        SR,          pTe   TPK                  RRR4       i i   SR,          pTe   TPK                  RRR4       i i ; i; i)-zøStream an Anthropic Messages API response; fires delta callbacks but
returns the native Message from get_final_message(). Runs on the
per-request ``request_client`` so the watchdog can abort this socket
without closing the shared client mid-flight.FrX  NÚmanagerrû   r	  )Únormalize_stream_usageÚsanitize_anthropic_kwargsc               ó   € V ^8„  d   QhRR/# rÝ  rL   )rM   s   "r?   rN   Ú4_StreamingCall._call_anthropic.<locals>.__annotate__K  s   € ÷ 	?ñ 	?°Nñ 	?rB   c                óÆ   <€ \        V 4      pS! V\        SP                  R R4      R7       SP                  P                  ! R/ VB pVSR&   S! VP                  4       4      # )rZ  r§   )rZ  rO  rL   )rk   rì   rU   rG  rû   Ú	__enter__)rÞ  rä  rO  Ú_stream_contextrP  rd  rQ  rs   s   &  €€€€€r?   Ú_open_anthropic_streamÚ>_StreamingCall._call_anthropic.<locals>._open_anthropic_streamK  s]   ø€ Ü Ó0ˆLÙ% l¼wÀtÇzÁzÐS_ÐacÓ?dÕeØ$×-Ñ-×4Ò4ÑD°|ÑDˆGØ)0ˆO˜IÑ&Ù)¨'×*;Ñ*;Ó*=Ó>Ð>rB   c               ó    € V ^8„  d   QhRRRR/# rÌ  rL   )rM   s   "r?   rN   rS  R  s   € ÷ 	1ñ 	1°#ð 	1¸$ñ 	1rB   c                óÀ   <a€ V SR &   \        V RR4      ;oSn        SP                  VVV3R l4       \        SP                  4      Sn        SP                  S4       R# )rû   ro   Nc                 ó<   <€ SP                   P                  S S4      # r:   )rU   rÒ  )r  ro   rs   s   €€€r?   r@   ÚS_StreamingCall._call_anthropic.<locals>._anthropic_stream_created.<locals>.<lambda>X  s   ø€  §
¡
× HÑ HÈÐPXÔ YrB   )rì   r?  rP  r.   rU   r=  rÔ  )rÍ  ro   r  rV  rs   s   &@€€€r?   Ú_anthropic_stream_createdÚA_StreamingCall._call_anthropic.<locals>._anthropic_stream_createdR  sR   ù€ Ø(2ˆO˜HÑ%ô 8?¸zÈ:ÐW[Ó7\Ð\ˆH�tÔ4à�K‰KÖYÔZÜ!4°T·Z±ZÓ!@ˆDÔØ×&Ñ& xÖ0rB   r`  rü  r   r  r  c                ó&   <€ SP                  R 4      # )zAnthropic streaming)râ  )rò  rs   s   &€r?   r@   Ú0_StreamingCall._call_anthropic.<locals>.<lambda>_  s   ø€ ¨×(BÑ(BÐCXÔ(YrB   r  rU  r  TrÜ   Úmessage_stopÚmessage_deltar·  rs  Úcontent_block_startÚcontent_blockrI  r¾  r/  Úcontent_block_deltaÚ
text_deltar�   r§   r¸  Úthinking_deltaÚthinkingrº  zTAnthropic Messages stream ended before message_stop (possible upstream stream drop).zeProvider returned an empty stream with no events (possible upstream error or malformed event stream).Ústop_detailsrs  )rE  )-r  r7  r•  r=  r?  r>  r,   rU   r
  Úagent.anthropic_adapterrP  rQ  ÚAnthropicStreamAccumulatorrT  rû   rÚ  r¢  r  r  rª  rœ  rÖ  rì   r¯  r‰  r¾  rÈ  r~   r|  r  r…  rh  r   Úget_final_messager}   ri  rX  Ú__exit__r  ro   Úcurrent_message_snapshotrs  r  rL  Úoutput_modified)rs   rd  Úhas_tool_useÚsaw_stream_eventÚsaw_message_stopÚbase_final_messageÚ
text_watchÚthinking_watchr!  r
  ÚaccumulatorrW  r]  rû   r¶   Ú
event_typerJ  r·  Ú
delta_typer�   rÍ  Ú_stop_detailsrO  rz   r  rV  rP  rQ  s   ff                      @@@@r?   Ú_call_anthropicÚ_StreamingCall._call_anthropic5  sï  ý€ ð
 ˆà ÐØ ÐÜ$(§I¢I£Kˆ×Ñ˜SÑ!Ø—‘Ó ˆØ=AÐAˆÔ˜TÔ:Ø'5ˆÔ$Ø$ d¨H°dÐ;ˆØ!ÐÜ%7Ó%9Ô;MÓ;O�NØˆå#ß]Ø×:Ñ:Ó<ˆ÷	?ô 	?÷	1ò 	1ð ×)Ñ)¨)×*:Ò*:¸4¿?¹?ÐLbñ +nÜ$ T§Z¡Z°Ó=ñ+nØIT×I]ÑI]ð+nà7ð+nàBM×BUÑBUð+nô Zð+nô ,¨D¯J©JÐ8LÓMð	+nð imò	+nó oˆð
6	7Ü�Ø#'Ð Ø×!Ñ! %¨Ô/Ø—:‘:×2×2Ð2ÚÜ$ U¨F°DÓ9�
Ø Ô/Ø'+Ò$Ø ?Ô2Ø×*Ñ*¨5´'¼'À%ÈÐRVÓ:WÐYfÐhlÓ2mÖnØÐ#8Ô8Ü# E¨?¸DÓA�Eß¤¨°¸Ó!=ÀÔ!KØ'+˜Ü" 5¨&°$×7Ò7Ø ×3Ñ3°E·J±JÔ?ð !ŸK™KÐ(<Õ=×DÑDÀUÇZÁZ×Pò	 8ò "L’uð  Ð#8×8Ü# E¨7°DÓ9�EßAF¤¨°¸Ô!=ÈD�JØ! \Ô1Ü& u¨f°bÓ9˜ß¯Ø ŸO™O¨DÔ1Ø%Ÿ?™?¨4×0Ò0Ø&/˜GÙ!ò 1ð $Ð'7×7¼GÀEÈ:ÐWY×<ZÕ<ZØ×,Ñ,¨U¯^©^Ô<Ø)×.Ñ.¨u¯~©~×>Õ>Ø&1˜GÙ!ñC  ðD )¨Õ2ˆJØ—:‘:×2×2Ð2°zÒ7M×V]ß'Ü*ç+ð oóAð Að @óAð Að &0×%AÑ%AÓ%CÐ"ð !,× 4Ñ 4Ó 6× :Ñ :¸>Ó J�Ø Ò,´Ð9KÈ^Ð]aÓ1bÒ1jØ6CÐ&Ô3ð7Ø×*Ñ*Ô,à)¨)Õ4�ØÒ&Ø×$Ñ$ T¨4°Ô6à�:‰:×*×*Ð*ÙßØ×!Ñ! 'Ô*à!×*Ñ*¨?¸8Õ+D×+]Ñ+]Ó^ˆGØ".ˆGÔØ*.ˆGÔ'ØˆNØÒ)Ø×)Ñ)Ð*<ÈÐ)ÔNØ×)×)Ð)Ø×4Ñ4Ð5GÓHÐHØ×,Ñ,¨[×-AÑ-AÐBTÓ-UÓVÐVøð# *¨)Õ4�ØÒ&Ø×$Ñ$ T¨4°Õ6ð 'ûð	7Ø×*Ñ*Ô,à)¨)Õ4�ØÒ&Ø×$Ñ$ T¨4°Õ6ð 'øð *¨)Õ4�ØÒ&Ø×$Ñ$ T¨4°Õ6ð 'ýsi   Ä#DS ÉAS Ê'S Ê5S ËS Ë9S Ì*S ÍS ÍS ÍA"S Î=R0 Ò0#SÓT0ÓT
Ó("T0Ô
#T-Ô-T0c          
     ó,   € V ^8„  d   QhRRRRRRRRRR	/# )
rG   rS  r�   Úmax_retriesÚmid_tool_callrô   r·  rI   rJ   rK   rL   )rM   s   "r?   rN   r-  ª  s2   € ÷ 0ñ 0¨Cð 0¸cð 0ÐUYð 0Ðcfð 0Ðkoñ 0rB   c          
     ó  € V P                   P                  W^,           V^,           W@P                  P                  R7       V P                   P	                  V4      '       d/   ^ RIHp V! V P                  \        V P                   RR4      4       T P                  V4       V P                  P                  V4       ^ RIHp \        V P                   V! V^,           RRRR	7      4       \        P                  ! 4       V P                  R
&   R# )z­Warn about the drop and tear down the request-local client. Shared
clients are never closed from inside a request (FD-recycle hazard); the
OpenAI primary is replaced lazily.)r5   rS  Úmax_attemptsr~  rã  )Úbuffer_anthropic_tool_inputro  N)Újittered_backoffg      ð?g      @r^  )Ú
base_delayÚ	max_delayÚjitter_ratiorX  )rU   Ú_emit_stream_dropr3  rã  Ú_is_provider_stream_parse_errorrj  r�  rÚ  rì   ra  r  Úagent.retry_utilsr‚  rŒ  r  r7  )rs   rå  rS  r}  r~  r·  r�  r‚  s   &&&&$$  r?   Ú_retry_after_dropÚ _StreamingCall._retry_after_dropª  sÎ   € ð 	�
‰
×$Ñ$Ø q�[°{ÀQµÐVc×jvÑjv×j{Ñj{ð 	%ô 	}à�:‰:×5Ñ5°a×8Ò8ÝKÙ'¨¯©¼ÀÇÁÐMbÐdhÓ9iÔjØ×+Ñ+¨FÔ3Ø�‰×Ñ Ô'õ 	7Ü"Ø�J‰JÑ(¨°1­ÀÐPSÐbeÔfô	hô %)§I¢I£Kˆ×Ñ˜SÓ!rB   c               ó   € V ^8„  d   QhRR/# rÊ  rL   )rM   s   "r?   rN   r-  ¾  s   € ÷ 0
ñ 0
¨Tñ 0
rB   c                óD  € \        V P                  4      '       d   R# \        V4      '       d‚   RV P                  n        \        P                  RV P                  P                  ;'       g    RV P                  P                  ;'       g    R4       V P                  P                  R4       R# ^ RI	H
p V! V4      '       g   R# \        V4      P                  4       pRV9   ;'       d    RV9   pR	V9   dq   V'       gi   V P                  P                  R
8w  g   V P                  P                  R8X  d   R# RV P                  n        V P                  P                  RRR7       R# RV P                  n        V P                  P                  V'       d   RMRRR7       R# )a  Flip to non-streaming for failures streaming itself cannot survive, or that
re-streaming can only repeat: the provider rejecting streams outright,
AnthropicBedrock IAM lacking InvokeModelWithResponseStream, a custom anthropic_messages
provider emitting SSE events out of order (#72833), or a gateway answering
with contentless SSE keepalive frames (a degraded gateway answers every
streaming request that way, so the retry must change channel to make progress).
llama-server stays on streaming: the router can't cancel a non-streamed request.NTu‹   Provider stream returned an empty SSE frame (keepalive, no payload) before any delta â€” switching %s/%s to non-streaming for this session.rÜ  u‰   âš ï¸� Provider stream returned an empty keepalive frame â€” retrying this turn without streaming (streaming stays off for this session).)Ú_is_stream_unavailable_errorrû   rƒ  zunexpected event orderrU  rl  uV   
âš   Provider sent Anthropic stream events out of order. Switching to non-streaming.
r?  uš   
âš   Streaming is not supported for this model/provider. Switching to non-streaming.
   To avoid this delay, set display.streaming: false in config.yaml
uŠ   
âš   AWS IAM denied bedrock:InvokeModelWithResponseStream. Switching to non-streaming.
   Grant that action to restore streaming output.
)r   rU   rö   ræ  r[   r\   r�  r‹  Ú_emit_warningrj  r�  rI   rÒ   r`  rJ  )rs   rå  r�  Ú
_err_lowerÚ_is_stream_unsupporteds   &&   r?   Ú_maybe_disable_streamingÚ'_StreamingCall._maybe_disable_streaming¾  s[  € ô ˜TŸZ™Z×(Ò(ÙÜ0°×3Ò3Ø,0ˆD�J‰JÔ)Ü�N‰NðOà—
‘
×#Ñ#×0Ð0 y°$·*±*×2BÑ2B×2OÐ2OÀiôQð �J‰J×$Ñ$ðLôMñ ÝHÙ+¨A×.Ò.ÙÜ˜“V—\‘\“^ˆ
Ø!)¨ZÑ!7×!YÐ!Y¸OÈzÑ<YÐØ# zÔ1×:Pð �z‰z×"Ñ"Ð&:Ô:¸d¿j¹j×>QÑ>QÐU^Ô>^ÙØ,0ˆD�J‰JÔ)Ø�J‰J×"Ñ"ØjØð #ô ñ à(,ˆ�
‰
Ô%Ø�
‰
×Ñ÷ &ñTðBàð 	ö 	
rB   c               ó(   € V ^8„  d   QhRRRRRRRR/# )rG   rå  rX   rS  r�   r}  rJ   rô   rL   )rM   s   "r?   rN   r-  ð  s/   € ÷ [ñ [ ið [¸#ð [ÈCð [ÐTXñ [rB   c           	     ó¦	  € ^ RI pV P                  R,          '       d,   \        P                  R\	        V4      P
                  4       R# \        WP                  VP                  VP                  34      p\        WP                  VP                  VP                  \        .\        4       O54      pV P                  P!                  V4      p\        V\"        4      pV'       * ;'       d    V'       * ;'       d    \%        V4      p	T;'       g    T;'       g    T	;'       g    Tp
V P&                  R,          '       g–   \)        V P                  RR4      '       gy   \+        V4      '       dh   RV P                  n        ^V n        \        P1                  R\)        VR	R4      4       V P3                  R
4       V P4                  P7                  R
4       R# V P&                  R,          '       d·   \9        V P:                  P=                  R4      4      ;'       g    V P>                  R,          pV'       gp   V PA                  4       '       gZ   \        PC                  RV4       V PE                  V P                  PF                  4       RV P&                  R&   RV PH                  R&   V P&                  R,          '       dÝ   X'       d   V
'       d   W#8  g'   \        PC                  RV4       WP:                  R&   R# V P                  PK                  4       '       d'   V PE                  V P                  PL                  R4       V PE                  V P                  PF                  4       RV P&                  R&   RV PH                  R&   V PO                  WVRRR7       R# V
'       g	   V'       dÝ   W#8  d   V PO                  WVRRR7       R# V P                  PQ                  RW^,           V^,           RV P4                  PR                  R7       V'       g	   V'       d7   V'       d   RMRpV P                  PU                  RV RV^,            R24       Mw^ RI+H,p V! V P                  W^,           V P                  PZ                  R7       M@V P]                  V4       \        P_                  RV4       V Pa                  V4      '       d   R# WP:                  R&   R# )zÀClassify a failed attempt: True = retry; False = stop with
``result["error"]`` set (unless our own interrupt force-closed the
socket). Runs inside the ``except`` so ``logger.exception`` works.Nr‹   uP   Streaming worker caught %s after request cancellation â€” exiting without retry.Fr%  rÆ  TzQEndpoint rejected stream_options (HTTP %s); retrying without it for this session.rh   Ústream_options_rejected_retryr/  z“Stream died after deltas but before any visible text was delivered (0 chars, no tool call in flight); treating as an undelivered stream failure: %srŽ  z9Streaming failed after partial delivery, not retrying: %sr5   u9   

âš  Connection dropped mid tool-call; reconnectingâ€¦

Ústream_mid_tool_retry_cleanup)r~  r·  Ústream_retry_cleanupÚ	exhausted)rX  r5   rS  r€  r~  rã  z0Provider returned malformed streaming data afterz0Provider returned an empty response stream afteru   â�Œ rÎ   uM    attempts. The provider may be experiencing issues â€” try again in a moment.)Úbuffer_connect_exhausted_notice)Úattemptsrt  z$Streaming failed before delivery: %s)1r€  r4  r[   r—  rÜ   rƒ   r|   ÚReadTimeoutÚConnectTimeoutÚPoolTimeoutÚConnectErrorÚ	ReadErrorr  ÚConnectionErrorr“  rU   r‡  r   r�  r5  rì   r†  rÆ  Ú_compat_retriesrø  ra  r3  r  rô   rÈ  r}   r6  r�  r\   rP  Ú_reset_stream_delivery_trackingrÉ  Ú_warning_presentation_enabledr  r‰  Ú_log_stream_retryrã  rà  Úagent.stream_diagr™  rt  r‘  Ú	exceptionÚ&_unmask_server_error_with_nonstreaming)rs   rå  rS  r}  rƒ  Ú_is_timeoutÚ_is_conn_errÚ_is_stream_parse_errÚ_is_empty_streamÚ_is_sse_conn_errÚ_is_transientÚ_partial_tool_in_flightÚ_whatr™  s   &&&&          r?   Ú_handle_stream_errorÚ#_StreamingCall._handle_stream_errorð  sù  € ó 	ð ×"Ñ" 7×+Ô+Ü�L‰LÐkÔmqÐrsÓmt×m}Ñm}Ô~ÙÜ  ×%7Ñ%7¸×9NÑ9NÐPV×PbÑPbÐ$cÓdˆô
 " !×&9Ñ&9¸6×;KÑ;KÈV×MgÑMgÔixð &LÜ'HÓ'Jñ&Ló Mˆà#Ÿz™z×IÑIÈ!ÓLÐÜ% aÔ)9Ó:ÐØ*œ?×_Ð_°<Ô/?×_Ð_ÔD\Ð]^ÓD_ÐØ#×_Ð_ |×_Ð_Ð7G×_Ð_ÐK_ˆà×$Ñ$ U×+Ô+´G¸D¿J¹JÐHeÐgl×4mÒ4mô  sJð  KL÷  sMò  sMà59ˆD�J‰JÔ2Ø#$ˆDÔ Ü�K‰KÐkÜ  =°$Ó7ô9à×/Ñ/Ð0OÔPØ�L‰L×#Ñ#Ð$CÔDÙà× Ñ  ×'Ô'Ü&*¨4¯;©;¯?©?Ð;OÓ+PÓ&Q×&xÐ&xÐUY×UqÑUqÐrwÕUxÐ#ß*°4×3OÑ3O×3QÒ3Qô —‘ð]Ø^_ôað —‘˜DŸJ™J×FÑFÔGØ/4�×%Ñ% eÑ,Ø16�×&Ñ& vÑ.Ø× Ñ  ×'Ô'÷
 ,·À'ÔBWÜ—‘ÐZÐ\]Ô^Ø'(—‘˜GÑ$Ùð �z‰z×7Ñ7×9Ò9Ø—‘˜DŸJ™J×9Ñ9Ð;zÔ{Ø�K‰K˜Ÿ
™
×BÑBÔCØ+0ˆD×!Ñ! %Ñ(Ø-2ˆD×"Ñ" 6Ñ*Ø×"Ñ" 1¨{È$ÐWvÐ"ÔwÙç×,àÔ$Ø×&Ñ& q°;ÈeÐ\rÐ&ÔsÙà�J‰J×(Ñ(¨kÀÐZ[ÍOØ(¨1�_¸EÈÏÉ×HYÑHYð )ô [÷ $×'7ßOcÑKØPð à—
‘
×4Ñ4Ø˜5˜'  ;°¥?Ð"3ð  4Að  BõCõ NÙ/°·
±
¸AÐVWÍÐbf×blÑbl×buÑbuÖvà×)Ñ)¨!Ô,Ü×ÑÐCÀQÔGØ×:Ñ:¸1×=Ò=Ùà �‰�GÑÙrB   c               ó    € V ^8„  d   QhRRRR/# )rG   rå  rX   rJ   rô   rL   )rM   s   "r?   rN   r-  M  s   € ÷ Dñ D¸	ð DÀdñ DrB   c                ó�  a a€ \        S P                  RR4      '       d   R# \        S P                  4      '       d   R# \        V4      pVe!   VR8  g   S P                  R,          '       d   R# \        S P                  RR4      R9  d   R# \
        P                  ! 4       pS P                  P                  pVe   W4,
          \        8  d   R# VS P                  n        S P                  P                  4        UUu/ uF  w  rVVR9  g   K  WVbK  	  pppS P                  p\        R4      S n         \        S P                  V4      o TS n        \"        P%                  RS P                  P(                  ;'       g    RS P                  P*                  ;'       g    R4       S P-                  S P                  P.                  R4        \1        S P                  TT 3R l4      pTS P&                  R&   R# u uppi   \        \        3 d    h \          dq   p	\        T	4      p
T
e:   T
R8  d3   \"        P%                  R	T	4       T	S P&                  R
&    Rp	?	TS n        R# \"        P%                  RT	4        Rp	?	TS n        R# Rp	?	ii ; i  TS n        i ; i  \          d"   p\"        P3                  RT4        Rp?R# Rp?ii ; i)uv  One non-streaming re-issue when a 5xx killed the stream before any delta.

Some gateways validate the request only on their non-streaming path and crash
opaquely ("500 something went wrong") when streaming â€” the real 4xx, with its
actionable message, never reaches the user through stream retries. One
non-streaming probe per 60s window (timestamped on the agent: each outer retry
builds a fresh _StreamingCall, so an instance flag would re-probe every attempt)
surfaces it: on success the response is delivered for this turn WITHOUT latching
non-streaming (a transient gateway 500 must not permanently disable streaming);
on a probe 4xx that error REPLACES the opaque 5xx; any other probe failure keeps
the original error. The successful delivery is bracketed by its own stream
start/end pair (the failed attempt already emitted a terminal end), and a response
that cannot be replayed propagates ``e``. The probe runs on this worker thread while
the stream monitor still polls, so its stale check is suspended for the probe's
duration (the probe has its own non-streaming watchdog). Interrupts re-raise (the outer handler routes them), and a /stop that arrived before
this point suppresses the probe entirely â€” the loop's pre-retry interrupt check owns
that decision, so a pending stop must not buy one more request.
True = handled (caller must not overwrite result); False = propagate ``e``.
rÖ  FNiô  r%  r`  r§   rs  z<Non-streaming unmask probe surfaced the underlying error: %sr5   Tz%Non-streaming unmask probe failed: %szeStreaming 5xx re-issued non-streaming successfully for %s/%s (not latched: the 5xx may be transient).rÜ  uV   âš   Streaming failed with a provider server error; the non-streaming retry succeeded.c                 ó&   <€ SP                  S 4      # r:   )r3  )Úprobers   s   €€r?   r@   ÚG_StreamingCall._unmask_server_error_with_nonstreaming.<locals>.<lambda>‹  s   ø€ À×A\ÑA\Ð]bÔAcrB   z=Non-streaming unmask probe response could not be replayed: %sro   )r§   rk  )rû   r€  )rì   rU   r   r   r5  r  r’  Ú_stream_5xx_probe_tsÚ_STREAM_5XX_PROBE_WINDOW_SrÚ  r8  r8  r\  r>  ÚKeyboardInterruptrÙ  rX   r[   rø  rÈ  r�  r‹  rP  Ú_buffer_statusr¸  r¦  )rs   rå  rŸ   r¡  Ú
last_proberœ   r.  Úprobe_kwargsrg  Ú	probe_errÚprobe_statusÚreplayedÚ
replay_errrµ  s   f&           @r?   r§  Ú5_StreamingCall._unmask_server_error_with_nonstreamingM  sN  ù€ ô( �4—:‘:Ð5°u×=Ò=ÙÜ˜TŸZ™Z×(Ò(áÜ% aÓ(ˆØŠ>˜V cœ\¨T×-BÑ-BÀ5×-IÔ-IÙÜ�4—:‘:˜z¨2Ó.Ð6NÔNÙÜ�nŠnÓˆØ—Z‘Z×4Ñ4ˆ
ØÒ! cÕ&6Ô9SÔ&SÙØ*-ˆ�
‰
Ô'Ø)-¯©×)>Ñ)>Ô)@ÔjÑ)@¡ ÀAÐMiÑDiœ˜šÑ)@ˆÑjØ×2Ñ2ˆÜ%*¨5£\ˆÔ"ð	7Ü*¨4¯:©:°|ÓD‰Eð *7ˆDÔ&Ü�‰ð ?à—J‘J×'Ñ'×4Ð4¨9°d·j±j×6FÑ6F×6SÐ6SÈ)ô	Uð 	�‰�D—J‘J×-Ñ-Ølô	nð	ô -¨T¯Z©ZÕ9cÓdˆHð
 #+ˆ�‰�JÑÙùóC køô
 "Ô#3Ð4ô 	ØÜô 	Ü/°	Ó:ˆLØÒ'¨L¸3Ô,>ä—‘ÐZÐ\eÔfØ'0�—‘˜GÑ$Ûð *7ˆDÖ&ô �K‰KÐ?ÀÔKÛà)6ˆDÖ&ûð	ûð *7ˆDÕ&ûô ô 	ä×ÑÐ\Ð^hÔiÝûð	ús`   Ã>G8ÄG8Ä4G> ÇJ Ç>J
ÈJ
È;JÉJ É"JÉ8J ÊJ
Ê
J Ê	JÊKÊ$K Ë Kc               ó   € V ^8„  d   QhRR/# rê  rL   )rM   s   "r?   rN   r-  “  s   € ÷ 4ñ 4¨Cñ 4rB   c                	óê   € V P                   P                  R 8w  d   V P                  V4      # V P                  P	                  V P                   P                  RR7      R R7      pV P                  V4      # )rU  Úanthropic_stream_requestrº  rW  )rU   r`  r,  r3  rê  Ú _create_request_anthropic_clientrz  )rs   re  rd  s   && r?   Ú
_call_wireÚ_StreamingCall._call_wire“  sk   € Ø�:‰:×ÑÐ"6Ô6Ø×.Ñ.Ð/@ÓAÐAàŸ™×0Ñ0Ø�J‰J×7Ñ7Ð?YÐ7ÓZÐauð 1ó wˆà×#Ñ# NÓ3Ð3rB   c                	óò  a a€ \        R ^4      p^ S n        R	p W!S P                  ,           8  dÆ   V^,          pS P                  4       oS P                  P                  '       d   S P                  R4       \        R4      h \        S P                  V V3R l4      S P                  R&    S P                  4        S P                  P                  S P                  R,          e	   R4       R# R4       R#  S P                  4        S P                  P                  S P                  R,          e   RMR4       R#   \         dö   pS P                  4        S P                  Y2T4      '       gO    Rp?S P                  4        S P                  P                  S P                  R,          e	   R4       R# R4       R# S P                  4       '       d^   TS P                  R&    Rp?S P                  4        S P                  P                  S P                  R,          e	   R4       R# R4       R#  Rp?EK  Rp?ii ; i  \         dc   pTS P                  R&    Rp?S P                  4        S P                  P                  S P                  R,          e	   R4       R# R4       R# Rp?ii ; i  S P                  4        S P                  P                  S P                  R,          e   R4       i R4       i ; i)
ÚHERMES_STREAM_RETRIESÚinterrupt_before_stream_retryz%Agent interrupted before stream retryc                 ó&   <€ S P                  S4      # r:   )rÆ  rk  s   €€r?   r@   Ú&_StreamingCall._call.<locals>.<lambda>­  s   ø€ ¨D¯O©OÐ<MÔ,NrB   ro   NÚstream_request_completeÚstream_error_cleanupr5   r6  )r4   r¡  r]  rU   rÖ  ra  rÙ  r¸  rÈ  rX  r3  r  rX   r°  rK  )rs   Ú_max_stream_retriesÚ_stream_attemptrå  re  s   f   @r?   Ú_callÚ_StreamingCall._call›  sˆ  ù€ Ü%Ð&=¸qÓAÐð  !ˆÔØˆð	nØ!¸$×:NÑ:NÕ$NÔNØ 1Õ$�Ø$(×$>Ñ$>Ó$@Ð!ð —:‘:×2×2Ð2Ø×7Ñ7Ð8WÔXÜ*Ð+RÓSÐSð
Ü.CØŸ
™
Õ$Nó/P�D—K‘K 
Ñ+àð ×&Ñ&Ô(à�L‰L×#Ñ#Ø-1¯[©[¸Õ-DÒ-PÐ)önØVlönð5 Oð0 ×&Ñ&Ô(à�L‰L×#Ñ#Ø-1¯[©[¸Õ-DÒ-PÑ)ÐVlönøô !ô Ø×.Ñ.Ô0Ø×4Ñ4°QÐI\×]Ò]Ûð ×&Ñ&Ô(à�L‰L×#Ñ#Ø-1¯[©[¸Õ-DÒ-PÐ)önØVlönð ×9Ñ9×;Ò;Ø/0˜Ÿ™ GÑ,Ûð ×&Ñ&Ô(à�L‰L×#Ñ#Ø-1¯[©[¸Õ-DÒ-PÐ)önØVlönö <ûð	ûô  ô 	à#$ˆD�K‰K˜Ñ Ûà×&Ñ&Ô(à�L‰L×#Ñ#Ø-1¯[©[¸Õ-DÒ-PÐ)önØVlönûð	ûð
 ×&Ñ&Ô(à�L‰L×#Ñ#Ø-1¯[©[¸Õ-DÒ-PÐ)õnØVlõnúsm   ™AH= Á%H= Â(D: Ä:H:Å(H5Å-H= Æ;H5ÇH5Ç H= È.H= È5H:È:H= È=J*ÉJ%ÉJ- Ê%J*Ê*J- Ê-A	K6c                	óš   €  V P                  4        V P                  P                  4        R #   T P                  P                  4        i ; ir:   )rÑ  Ú
_call_doner³  r¢  s   &r?   Ú	_run_callÚ_StreamingCall._run_callÂ  s1   € ð	"Ø�J‰JŒLà�O‰O×ÑÖ!øˆD�O‰O×ÑÕ!ús	   ‚. ®A
c               ó    € V ^8„  d   QhRRRR/# rØ  rL   )rM   s   "r?   rN   r-  È  s   € ÷ Oñ O°sð O¸tñ OrB   c                óJ  € Ve   WP                   Jd   R#  ^ RIHpHp V! V4      pVe;   V! V4       \        P                  RV P                  P                  RR4      4       R# \        P                  R4       R#   \         d    \        P                  RRR	7        R# i ; i)
u¨  Best-effort ``shutdown()`` on the killed attempt's socket (monitor thread).

The pool sweep in ``close_once`` can miss a connection that is checked
out for the in-flight body read. ``shutdown(SHUT_RDWR)`` is FD-safe
from any thread â€” it wakes the owner's ``recv`` without releasing the
descriptor â€” so the worker unwinds and releases its own response on
the owner thread (``_call``'s ``except``/``finally``). Never
``close()`` here: releasing a live TLS descriptor from a stranger
thread lets the kernel recycle it under the owner's SSL BIO, which is
exactly what the shutdown-only rule in ``_abort_request_slot_client``
forbids (it covers request-local clients too, #30858).
N)Ú_shutdown_socketÚ_socket_from_responsezYShut down the stale stream's socket to unblock the reader (attempt superseded; model=%s).r‹  rÜ  zJStale stream socket shutdown found no socket; pool sweep is the only abortz#Stale stream socket shutdown failedTr”  )
r?  rA  rÙ  rÚ  r[   rø  rÚ  r}   r—  rX   )rs   ro   rÙ  rÚ  Úsocks   &&   r?   rÛ  Ú-_StreamingCall._shutdown_stale_attempt_socketÈ  s“   € ð Ò˜x×/LÑ/LÓLÙð
	Oß[Ù(¨Ó2ˆDØÒÙ  Ô&Ü—‘ð >Ø?C¿¹×?RÑ?RÐSZÐ\eÓ?fôháÜ�L‰LÐeÖføÜô 	OÜ�L‰LÐ>ÈˆL×Nð	Oús   —AA< Á%A< Á<"B"Â!B"c               ó   € V ^8„  d   QhRR/# rÄ  rL   )rM   s   "r?   rN   r-  ã  s   € ÷ Iñ I¨#ñ IrB   c                óÄ   € V P                   ;_uu_ 4        \        V P                  R,          4      pRRR4       XV P                  9   d   ^ # T#   + '       g   i     L%; i)aM  The started attempt the circuit breaker (see ``_stale_streak()``) has not counted
yet, else 0. Like the non-streaming and inline watchdogs, each attempt counts once:
the stale timer re-fires every window while the worker has not dispatched yet or is
still unwinding a kill, and none of those re-kills is another unresponsive attempt.rÇ   N)r9  r�   r:  r;  ©rs   rS  s   & r?   Ú_uncounted_stale_attemptÚ'_StreamingCall._uncounted_stale_attemptã  sK   € ð
 ×%×%Ó%Ü˜$×3Ñ3°IÕ>Ó?ˆG÷ &à˜t×;Ñ;Ô;ˆqÐHÀÐH÷ &×%ús   •AÁA	c               ó   € V ^8„  d   QhRR/# rÊ  rL   )rM   s   "r?   rN   r-  ì  s   € ÷ +ñ + dñ +rB   c                	óš   € V P                  4       pV'       d3   V P                  P                  V4       \        V P                  4       R # R # r:   )rà  r;  r£  rÌ  rU   rß  s   & r?   Ú_count_stale_attemptÚ#_StreamingCall._count_stale_attemptì  s8   € Ø×/Ñ/Ó1ˆßØ×(Ñ(×,Ñ,¨WÔ5Ü˜tŸz™zÖ*ñ rB   c               ó    € V ^8„  d   QhRRRR/# rã  rL   )rM   s   "r?   rN   r-  ò  s   € ÷ añ a¨%ð a°Dñ arB   c           	     óP  € \        V P                  4      p\        P                  RWP                  V P                  P                  RR4      VR 4       V P                  P                  R\        V4       RV P                  P                  RR4       RVR R24       V P                  p\        P                  ! \        4      ;_uu_ 4        V P                  R	4       V P                  P                  R	4       R
R
R
4       V P!                  V4       V P#                  4        \$        P$                  ! 4       V P&                  R&   V P                  P)                  R\        V4       R24       V P                  P+                  R\        V4       R24       R
#   + '       g   i     L¥; i)u2  SSE pings but no chunks: cancel the attempt and abort the request-local
client so the retry loop opens a fresh one. The shared client is never
closed from this (stranger) thread â€” earlier stale-killed workers may
still be unwinding SSL BIOs (FD-recycle corruption); the OpenAI primary
is replaced lazily.uq   Stream stale for %.0fs (threshold %.0fs) â€” no chunks received. model=%s context=~%s tokens. Killing connection.r‹  rÜ  rÞ  rß  r!  z, context: ~z tokens). Reconnecting...Ústale_stream_killNrX  u    âš  no output from provider for u   s â€” reconnecting...zstale stream detected after zs, reconnecting)rP  rÚ  r[   r\   r8  r}   rU   rà  r�   r?  rª   r«   rX   ra  r3  r  rÛ  rä  r  r7  Ú_emit_diagnostic_waitrå  )rs   rÒ  Ú_est_ctxÚ_killed_responses   &&  r?   Ú_kill_stale_streamÚ!_StreamingCall._kill_stale_streamò  sY  € ô 3°4·?±?ÓCˆÜ�‰ØØ×/Ñ/°·±×1DÑ1DÀWÈiÓ1XÐ]eÐfgÐ\hô	
ð 	�
‰
×,Ñ,Ø3´C¸³L°>ÀÈDÏOÉO×L_ÑL_Ð`gÐirÓLsÐKtð uØ! !˜Ð$=ð?ô	@ð  ×8Ñ8ÐÜ× Ò ¤×+Õ+Ø×/Ñ/Ð0CÔDØ�L‰L×#Ñ#Ð$7Ô8÷ ,ð 	×+Ñ+Ð,<Ô=Ø×!Ñ!Ô#ä$(§I¢I£Kˆ×Ñ˜SÑ!Ø�
‰
×(Ñ(Ð+KÌCÐPWËLÈ>ÐYnÐ)oÔpØ�
‰
×"Ñ"Ð%AÄ#ÀgÃ,ÀÈÐ#_Ö`÷ ,×+ús   Ã-FÆF%	c               ó    € V ^8„  d   QhRRRR/# r  rL   )rM   s   "r?   rN   r-    s   € ÷ 0ñ 0°%ð 0¸Dñ 0rB   c                ó¦  € V P                  4       pV'       dZ   WP                  8:  dJ   \        V P                  WP                  R,          R7      '       d   V P
                  P                  V4       RV P                  R&   \        P                  R4       V P                  p\        P                  ! \        4      ;_uu_ 4        V P                  R4       V P                  P!                  R4       RRR4       V P#                  V4       V P$                  e   \'        V P$                  RR	7       RV P(                  R&   R#   + '       g   i     LW; i)
zs/stop seen by the monitor: mark cancelled, abort the request-local
socket, wait for the worker, flag the interrupt.r%  r  Tr‹   zLForce-closing streaming httpx client due to interrupt (not a network error).Ústream_interrupt_abortNrá  r  )rà  r8  rÖ  rU   r5  r;  r£  r4  r[   r—  r?  rª   r«   rX   ra  r3  r  rÛ  r]   r_   Ú_monitor_interrupted)rs   r  rS  rë  s   &&  r?   Ú_abort_for_interruptÚ#_StreamingCall._abort_for_interrupt  s  € ð ×/Ñ/Ó1ˆß�}×(BÑ(BÔBÔGhØ—
‘
˜M×<QÑ<QÐRWÕ<X÷HZó HZà×(Ñ(×,Ñ,¨WÔ5ð ,0ˆ×Ñ Ñ(Ü�‰ÐcÔdð  ×8Ñ8ÐÜ× Ò ¤×+Õ+Ø×/Ñ/Ð0HÔIà�L‰L×#Ñ#Ð$<Ô=÷ ,ð 	×+Ñ+Ð,<Ô=ð �;‰;Ò"Ü+¨D¯K©K¸{ÕKØ+/ˆ×!Ñ! %Ó(÷ ,×+ús   Ã-E Å E	c               ó   € V ^8„  d   QhRR/# rÊ  rL   )rM   s   "r?   rN   r-  *  s   € ÷ [ñ [¨ñ [rB   c                ó–  € \        V P                  4      pVR8X  dˆ   V P                  P                  '       dl   \        V P                  P                  4      '       dG   \	        4       V n        \        P                  RV P                  P                  V P
                  4       R# \        V P                  V P                  4      V n        R# )ut  Set ``_stream_stale_timeout``. Local endpoints (unless the env is set) get
long but FINITE patience â€” 900s / ``agent.local_stream_stale_timeout`` /
HERMES_LOCAL_STREAM_STALE_TIMEOUT â€” an infinite one stalled sessions on a
crashed endpoint forever. Cloud values scale with context size and are
floored for known reasoning models (else BrokenPipeError from the gateway).rð  uB   Local provider detected (%s) â€” stale stream timeout set to %.0fsN)
rø  rU   rt  r   rÿ  r8  r[   r—  r  rÚ  )rs   r  s   & r?   Ú_resolve_stale_timeoutÚ%_StreamingCall._resolve_stale_timeout*  s‡   € ô & d§j¡jÓ1ˆØ�5Œ=˜TŸZ™Z×0×0Ð0Ô5FÀtÇzÁz×GZÑGZ×5[Ò5[Ü)LÓ)NˆDÔ&Ü�L‰LÐ]Ø—
‘
×#Ñ# T×%?Ñ%?ôAáÜ%=¸d¿j¹jÈ$Ï/É/Ó%ZˆÖ"rB   c                óZ  € V P                   R,          p\        V P                  RR4      ;'       g    RP                  4       ;'       g    Rp\	        V P                   P                  R4      ;'       g    . 4      pV'       dÐ   RP                  VR,          4      p\        V4      ^8”  d   VR\        V4      ^,
           R	2,          pR
V R2pT;'       g    RV,           pV P                  P                  4       '       d'   V P                  V P                  P                  V4       \        P                  RT\        T;'       g    R4      V4       Rp\        P                  ! \        4      ;_uu_ 4        ^ RIHp T! T\%        \        V P                  RR4      ;'       g    R4      \%        \        V P                  RR4      ;'       g    R4      R7      pRRR4       \'        V P                  4       Ve‡   VP(                  \*        P,                  8X  dh   \        P                  R\        T;'       g    R4      V4       \/        RRR\        V P                  RR4      RVR\        V P                  RR4      R7      # V'       g+   \        P                  R\        T;'       g    R4      V4       \/        RVR\        V P                  RR4      RV\        V P                  RR4      R7      pVe'   VP(                  \*        P0                  8X  d   RVn        V#   + '       g   i     ELJ; i)u¸  Tokens already reached the platform: a finish_reason="length" stub fires the
continuation machinery; tool_calls=None blocks executing incomplete calls.
Content may be EMPTY (dropped tool call, overflow) â€” the loop skips appending an
empty stub and only sends the nudge (placeholder text leaked into the stitched
response). A text-only death with 0 visible chars never gets here: the error
handler reclassifies it as undelivered (#112419).r5   r€  r§   Nr/  rq  :Né   Nz, +z moreu$   

âš  Stream stalled mid tool-call (zH); the action was not executed. Ask me to retry if you want to continue.z[Partial stream dropped tool call(s) %s after %s chars of text; surfaced warning to user: %s)Úclassify_api_errorr�  r‹  )r�  r‹  zˆPartial stream ended on a context-overflow error after %s chars; NOT seeding a continuation stub (transcript is already over budget): %sr  rÜ  Tr`  )ro  rp  r`  z¡Partial stream delivered before error; returning length-truncated stub with %s chars of recovered content so the loop can continue from where the stream died: %s)ro  r`  )rÈ  rì   rU   r©   rÂ   r}   rY   r  r£  rP  r  r[   r\   rª   r«   rX   Úagent.error_classifierrú  rI   rÏ  r·  r   Úcontext_overflowr}  Úcontent_policy_blockedÚ_content_filter_terminated)	rs   r5   Ú_partial_textÚ_partial_namesÚ	_name_strÚ_warnÚ_clsrú  Ú_stubs	   &        r?   Ú_partial_stream_stubÚ#_StreamingCall._partial_stream_stub8  s°  € ð —‘˜GÕ$ˆÜ  §¡Ð-OÐQSÓT×ZÐZÐXZ×aÑaÓc×kÐkÐgkˆÜ˜dŸk™kŸo™oÐ.BÓC×IÐIÀrÓJˆßàŸ	™	 .°Õ"4Ó5ˆIÜ�>Ó" QÔ&Ø˜s¤3 ~Ó#6¸Õ#:Ð";¸5ÐAÕA�	Ø=¸i¸[ð I@ð AˆEà*×0Ð0¨b°EÕ9ˆMØ�z‰z×7Ñ7×9Ò9Ø—‘˜DŸJ™J×9Ñ9¸5ÔAÜ�N‰NØmØ¤ M×$7Ð$7°RÓ 8¸%ôAð
 ˆÜ× Ò ¤×+Õ+ÝAÙ%Ø¤¤G¨D¯J©J¸
ÀBÓ$G×$MÐ$MÈ2Ó NÔVYÔZaÐbf×blÑblÐnuÐwyÓZz÷  [Að  [Að  Aó  WBôCˆD÷ ,ô 	˜DŸJ™JÔ'ð
 Ò §¡¬~×/NÑ/NÔ NÜ�N‰NðZä�M×'Ð' RÓ(¨%ôô
 .Ø˜T 4¬°·±¸WÀiÓ)PÐRVØ#1ÀTÜ  §¡¨Z¸Ó>ôð ÷
 Ü�N‰Nð\ä�M×'Ð' RÓ(¨%ô1ô +¨;¸ÀtÜ�D—J‘J ¨Ó3°TÈnÜ˜TŸZ™Z¨°TÓ:ô<ˆð Ò §¡¬~×/TÑ/TÔ TØ/3ˆEÔ,Øˆ÷= ,×+Ð+ús   Å6ALÇLÌL*	c                ó  € V P                  4        \        P                  ! 4       V n        RR/V n        \        V P                  4      '       dh   RV n        \        P                  ! \        V P                  4      RRR7      pVP                  4         V P                  4        VP                  RR7       MZ\        P                  ! \        V P                  4      RR	7      V n        V P                  P                  4        V P                  4        V P                  R,          '       d   \        R
4      hV P                  P                  '       d   \        R4      hV P                   R,          e=   V P"                  R,          '       d   V P%                  4       # V P                   R,          hV P                   R,          e   \'        V P                  4       \)        V P*                  P,                  \.        4      '       da   V P*                  P,                  P1                  R4      '       d6   \3        V P*                  P,                  R,          4      V P                  n        V P                   R,          #   TP                  RR7       i ; i)zŽResolve the stale timeout, run the request (worker thread or inline),
drive the heartbeat/stale/interrupt monitor, then translate the outcome.r%  FNzstream-inline-monitorTr‹  rR   rS   r%  z+Agent interrupted during streaming API callz9Agent interrupted during streaming API call (post-worker)r5   ro   rš  )rö  r‘  r–  rÔ  rñ  ro  rU   r]   r˜  rE   Ú_monitor_loopr«  rÕ  rY   rÙ  rÖ  rÈ  r5  r  rÏ  r|   r3  rã  rk   r}   r\  Ú_last_api_first_chunk_at)rs   Úmonitors   & r?   r;   Ú_StreamingCall.runr  sÎ  € ð 	×#Ñ#Ô%ô
 $Ÿ/š/Ó+ˆŒØ%*¨E NˆÔ!Ü% d§j¡j×1Ò1ØˆDŒKÜ×&Ò&Ü-¨d×.@Ñ.@ÓAÐH_ÐhlônˆGà�M‰MŒOð*Ø—‘Ô à—‘ S�Õ)ä#×*Ò*Ô2HÈÏÉÓ2XÐaeÔfˆDŒKØ�K‰K×ÑÔØ×ÑÔ Ø×$Ñ$ U×+Ô+Ü"Ð#PÓQÐQØ�:‰:×*×*Ð*Ü"Ð#^Ó_Ð_Ø�;‰;�wÕÒ+Ø×$Ñ$ U×+Ô+Ø×0Ñ0Ó2Ð2Ø—+‘+˜gÕ&Ð&Ø�;‰;�zÕ"Ò.Ü §
¡
Ô+ä�d—l‘l×'Ñ'¬×.Ò.°4·<±<×3DÑ3D×3HÑ3HÐIY×3ZÒ3ZÜ27¸¿¹×8IÑ8IÐJZÕ8[Ó2\ˆD�J‰JÔ/Ø�{‰{˜:Õ&Ð&øð% —‘ S�Õ)ús   ÂI3 É3J)r>  r?  rÔ  r¡  rñ  r4  rA  r;  r8  r=  rU   rÚ  r3  r5  rÉ  r7  r<  rT  r*   r6  rÈ  r9  r:  r]   );rƒ   r„   r…   r†   r‡   rq   r@  rK  r  rP  rT  rX  r]  ra  rg  rl  rs  rv  r|  r�  r…  r‰  r�  r•  rœ  r¢  rª  r¯  rµ  rÁ  rÉ  rÕ  rÔ  rä  râ  r,  r  r  r3  r=  r  rL  rz  r‰  r‘  r°  r§  rÆ  rÑ  rÕ  rÛ  rà  rä  rì  rò  rö  r  r;   rˆ   rL   rB   r?   r+  r+  �
  s¬  † ñVõ1õ<tõð" ôó ðõ
õVõõTõnõ
Oõ
ò"-õ
,õ
aõ/õ0õ|õõ
	Uõ	ð ô	:ó ð	:ð ô.ó ð.õ ð* ñ$ó ð$õ2Gõ-õYõ&õ.õGõR>ò;òð  ñ'@ó ð'@ðR>Ø=Að>ØUYð>Ømqð>àô>ðD ð¸tö ó ðò"qWõj0õ(0
õd[õzDõL4ò#nòN"õOõ6Iõ+õaõ80õ8[ò8öt$'rB   r+  rT  c               ó   € V ^8„  d   QhRR/# rO  rL   )rM   s   "r?   rN   rN   ™  s   € ÷ Cñ C¸ñ CrB   c               ó  € V P                   '       d   \        R4      hV P                  R8X  d   \        WV4      # V P                  R8X  d   \	        WV4      P                  4       # \        V 4       \        WV4      P                  4       # )a)  Streaming variant of _interruptible_api_call: fires the delta callbacks per
text token (tool-call turns suppress them) and returns a SimpleNamespace in
the non-streaming response shape. codex_responses delegates to the already-
streaming codex runner; cron turns and delegated children run inline.z+Agent interrupted before streaming API callrQ  rY  )rÖ  rÙ  r`  r¾  rÄ  r;   rì  r+  r½  s   &&$r?   Ú interruptible_streaming_api_callr  ™  sw   € ð
 ×!×!Ð!ÜÐLÓMÐMØ‡~�~Ð*Ô*Ü(¨¸NÓKÐKØ‡~�~Ð+Ô+Ü˜e°Ó@×DÑDÓFÐFä˜ÔÜ˜%¨^Ó<×@Ñ@ÓBÐBrB   >   ÚpriceÚlatencyÚ
throughput>   r  r·   r¶   Úretry>   r3  r2  Úinput_imager:   )NN>   rº  Ú	tool_namer  r#  Úplatform_message_idr  )
zconnection lostzconnection resetzconnection closedzconnection terminatedznetwork errorznetwork connectionÚ
terminatedzpeer closedzbroken pipezupstream connect error)rß  r0  rn  rU  r>  r  ræ  )ör‡   Ú
__future__r   rª   rC   r¬   rö  r~  rñ  r�   r�  r‘  r  rÁ  Údataclassesr   Útypesr   Útypingr   r   r   Úhermes_cli.timeoutsr   r	   rŠ  r
   r   rû  r   r   r   r   Úagent.sdk_transform_bypassr   Úagent.errorsr   Úagent.chat_completion_localr   r   Úagent.chat_completion_headersr   Ú$agent.chat_completion_stream_monitorr   r`  r   r   Úagent.fast_moder   Úagent.turn_contextr   Úagent.gemini_native_adapterr   r´  r   Úagent.message_contentr   Úagent.message_metadatar   r   r   r    Úagent.message_sanitizationr!   r"   r#   r$   r  r%   r&   Úagent.reasoning_summariesr'   r(   r)   Úagent.local_prompt_progressr*   r+   Úagent.repetition_guardr,   r-   Úagent.stream_single_writerr.   r/   Útools.terminal_tool_lifecycler0   Úutilsr1   r2   r3   r4   Ú	getLoggerrƒ   r[   rr  r  r
  rí   r“  r¸  rE   r_   rc   rX   re   r•   r¤   r³   rØ   rã   rï   rö   rý   r   r  r  Ú	frozensetr6  r%  r-  rP  rY  re  rm  ru  r�  r˜  r«  rÂ  rÈ  rÌ  rÏ  rÕ  rÖ  rá  ræ  rì  ró  rø  rÿ  r  r  r  r  r  r  rM  rf  ro  r¡  rv  r„  r†  rÞ  rà  r  r'  r  r  r4  r7  r>  rC  rP  rh  rl  r€  r…  r™  r×  rß  rÝ  ræ  ré  rý  r   r  r0  r<  rA  rM  ÚauthÚauth_permanentr…  Ú
rate_limitÚupstream_rate_limitÚ
overloadedÚserver_errorrT   Ússl_cert_verificationrü  Úpayload_too_largeÚimage_too_largeÚmodel_not_foundÚprovider_policy_blockedrý  Úformat_errorÚrole_alternationÚinvalid_encrypted_contentÚ#multimodal_tool_content_unsupportedÚthinking_signatureÚlong_context_tierÚ!oauth_long_context_beta_forbiddenÚllama_cpp_grammar_patternrÜ  rR  rS  rY  rc  rt  r€  rŠ  r”  rš  r©  r¸  r¾  rÊ  rÐ  ræ  rò  rL  r  r  r  r'  r1  r:  rK  rU  rn  r}  r›  r†  rŒ  r“  r�  r¢  rª  r²  r¸  r¾  rÂ  rÄ  r+  r  Ú__all__rL   rB   r?   Ú<module>rC     s  ðñõ #ã Û Û Û Û Û 	Û 	Û 
Û Û Û Ý !Ý !ß &Ñ &ç Xß I÷ó õ IÝ )ß GÝ LÝ Eß dÝ 7Ý 5Ý Aõ 3Ý 6÷ Bó  B÷÷ ÷gñ gç Mß Nß TÝ ;ß NÓ Nà	×	Ò	˜8Ó	$€Û#EÐ  Ø)0°.Ð(AÐ %Û>Ð Ø$(Ð !ð "%Ð ð
 "Ð ò)õ`ò(ô˜)ô õ22õõ õ.õb'ð&%Ø÷%õPkðh¸D÷ hõlõðBØ÷ñB ÓCÓDÐ õHõõ Eõ8<õ
õ
SõõBõ*õõ õHõDõ
-ð
 #'Ð õ	ðEØðEØ04÷Eõ Cõ

õhõCõIõõ
=õ7õ	4õ
Jõhð8 Èt÷  õ:!QõJ:ðF *.Ð &õõ÷ pñ põf:U÷zJSñ JSðf %*Ð !ð (-Ð $õ-ð ÷
"ð 
"ó ð
"õUZõpõ6õ ò"0òfò4òYò"oòfòF@÷Fð ÷&lð lò( òNõVò(õ.õbfõR%õ&?õ

7ðØ×ÒÐ0ðà×!Ò!Ð#Fðð ×ÒÐ8ðð ×Ò˜|ð	ð
 ×&Ò&Ð(Cðð ×ÒÐ4ðð ×ÒÐ!8ðð ×ÒÐ-ðð ×(Ò(Ð*Oðð ×#Ò#Ð%>ðð ×$Ò$Ð&Aðð ×"Ò"Ð$=ðð ×"Ò"Ð$5ðð ×*Ò*Ð,Qðð ×)Ò)Ð+Oðð  ×ÒÐ!:ð!ð" ×#Ò#Ð%Kð#ð$ ×,Ò,Ð.RØ×6Ò6Ð8]Ø×%Ò%Ð'DØ×$Ò$Ð&EØ×4Ò4Ð6[Ø×,Ò,Ð.HØ×ÒÐ.ñ1Ð õ8jõ?õ%õ.õ>põ,õ"õ6õ"!õH2õ4}õpõ0Y÷:ð :ð@ !@ó CKõ !KÐ àZÐ õLõ^õ
.õõ
õð. /Ð0FÐH\Ð^xÐyÐ õ4õnZð43Øð3Ø/4ð3Ø?Cð3ØOTô3ñtÐ õ
	`ö	(÷L÷D÷>÷ ÷ó ÷(+ó÷f=ó f=öRG'Ð)ô G'ñT(CÐPT÷ Cñ Có ‚rB   