+
    iHàj#  ã                  óÄ   € R t ^ RIHt ^ RIHt ^ RIt^ RIHt ^ RIH	t	H
t
 ^ RIHt ^ RIHt ]P                  ! R4      t] ! R	 R
4      4       tR R ltR R ltR R ltR# )aÑ  Per-attempt request assembly for the conversation turn's retry loop: re-apply the
reasoning echo pad and prompt-cache decoration for the CURRENT provider (a fallback may
differ from the primary), build ``api_kwargs``, run the surrogate/ASCII chokepoints, Codex
preflight, OpenRouter cache bypass, Copilot ``x-initiator``, the LLM request middleware,
the ``pre_api_request`` hook and the debug dump. Nothing here imports
``agent.conversation_loop`` at module level.
)Úannotations)Ú	dataclassN)ÚAny)Úsanitize_outbound_kwargsÚ strip_images_for_rejecting_model)Úobserve_request_tools)Úenv_var_enabledzagent.conversation_loopc                  ób   € ] tR t^t$ RtR]R&   R]R&   R]R&   R]R&   R]R&   R]R	&   R]R
&   RtR# )ÚApiRequestBuildzoAlways ``action == "fallthrough"``; the fields are the request-local values the caller
rebinds for the attempt.ÚstrÚactionr   Úapi_messagesÚ_moa_prepared_requestÚtools_for_apiÚ
api_kwargsÚ_original_api_kwargsÚ_llm_middleware_trace© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__Ú__static_attributes__r   ó    Ú;/home/ubuntu/.hermes/hermes-agent/agent/turn_api_request.pyr
   r
      s1   ‡ ñ ð ƒKØÓØÓØÓØƒOØÓØ×r   r
   c               ó(   € V ^8„  d   QhRRRRRRRR/# )é   r   r   Úkeyr   ÚvalueÚreturnÚNoner   )Úformats   "r   Ú__annotate__r$   $   s(   € ÷ &ñ & #ð &¨Cð &¸ð &Àñ &r   c                ó^   € \        V P                  R4      ;'       g    / 4      pW#V&   W0R&   R# )zPCopy-on-write header set (the dict may be shared with the transport's defaults).Úextra_headersN)ÚdictÚget)r   r   r    Ú_xhs   &&& r   Ú_set_extra_headerr*   $   s,   € ä
ˆz�~‰~˜oÓ.×4Ð4°"Ó
5€CØˆ�HØ"%ˆÓr   c               óT   € V ^8„  d   QhRRRRRRRRRRRRRRR	RR
RRRRRRRRRRRRR/# )r   Úagentr   r   r   r   ÚmessagesÚoriginal_user_messageÚapprox_tokensÚtotal_charsÚretry_countÚapi_call_countÚapi_request_idÚapi_start_timeÚeffective_task_idÚturn_idr!   r"   r   )r#   s   "r   r$   r$   +   s“   € ÷ /ñ /Øð/Øð/Ø/2ð/ØKNð/Ø]`ð/àð/à/2ð/àADð/àSVð/ð ð/ð *-ð/ð ?Bð/ð WZð/ð ð	/ð
 
ñ/r   c       
   	     ó2  € ^ RI Hp  ^ RIHpHp V! R4      '       Edg   VP                  R4      p\        V\        4      '       g   VP                  R4      p\        V\        4      '       g   TpT! R/ RVbRVbRV
bR	V P                  ;'       g    R
bRVbR\        V4      bRV P                  ;'       g    R
bRV P                  bRV P                  bRV P                  bRV P                  bRV	bRVbR\        V\        4      '       d   \        V4      M. bRV! VV4      bR\        V4      bR\        V P                  ;'       g    . 4      bRVbRVbRV P                   bRVbR\        V4      bRV P#                  V4      b  R# R#   \$         d     R# i ; i) é    )Ú_system_prompt_for_hooks)Úhas_hookÚinvoke_hookÚpre_api_requestr-   ÚinputÚtask_idr6   r3   Ú
session_idÚ Úuser_messageÚconversation_historyÚplatformÚmodelÚproviderÚbase_urlÚapi_moder2   r1   Úrequest_messagesÚsystem_promptÚmessage_countÚ
tool_countÚapprox_input_tokensÚrequest_char_countÚ
max_tokensÚ
started_atÚmiddleware_traceÚrequestN)r<   )Úagent.conversation_loopr9   Úhermes_cli.lifecycler:   r;   r(   Ú
isinstanceÚlistr?   rC   rD   rE   rF   rG   ÚlenÚtoolsrN   Ú_api_request_payload_for_hookÚ	Exception)r,   r   r   r   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r9   r:   Ú_invoke_hookrH   s   &&&&$$$$$$$$$$    r   Ú_fire_pre_api_request_hookr[   +   sâ  € õ Að'ßNÙÐ%×&Ó&Ø)Ÿ~™~¨jÓ9ÐÜÐ.´×5Ò5Ø#-§>¡>°'Ó#:Ð ÜÐ.´×5Ò5Ø#/Ð ñ
 ò á)ðñ  ðñ  .ð	ð
 !×+Ñ+×1Ð1¨røðñ 3ðô &*¨(¤^ðð Ÿ™×-Ð-¨2øðð —k’kðð Ÿšðð Ÿšðð Ÿšðñ  .ðñ (ðô <FÐFVÔX\×;]Ò;]¤Ð&6Ô!7Ðceøðñ  7°zÐCSÔTð!ô" " ,Ô/ð#ô$ ˜uŸ{™{×0Ð0¨bÔ1ð%ñ& %2ð'ñ( $/ð)ð* !×+Ò+ð+ñ, *ð-ô. "&Ð&;Ô!<ð/ð0 ×;Ñ;¸JÔGó1ñ 'øôH ô Úðús*   ˆF ŸA0F Â%F Â6BF Å=F ÆFÆFc                óX   € V ^8„  d   QhRRRRRRRRRRRRRRR	RR
RRRRRRRRRRRRRRR/# )r   r,   r   r   r   r   Úsystem_messager-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r!   r
   r   )r#   s   "r   r$   r$   ]   s°   € ÷ \ñ \Øð\Ø!$ð\Ø=@ð\ØQTð\àð\à#&ð\à?Bð\àSVð\ð ð\ð $'ð\ð 9<ð\ð NQð\ð ð	\ð -0ð	\ð ;>ð	\ð
 ñ\r   c               ó`  € ^ RI HpHp V P                  4        RV n        V P                  V4       V! WWBVR7      w  rp\        W4       \        W4       W0P                  8X  d   V P                  V4      pMV P                  WR7      p\        V V4       V P                  R8X  d@   V P                  4       P                  VRV P                  4       V P                  4       R7      pV P                   ^ 8”  d$   V P#                  4       '       d   \%        VRR	4       \'        V R
R4      '       d+   V P                  4       '       d   \%        VRR4       RV n         ^ RIHp T! TYÞTV P.                  ;'       g    RV P0                  ;'       g    RV P2                  V P4                  V P6                  V P                  V
R7      pVP8                  pVP:                  pVP<                  p\C        V VVVVWgW‰V
W¼WÞR7       \E        R4      '       d   V PG                  VRR7       Vec   V P4                  R8X  dR   V! V PH                  4      '       d   VVR&   M3\J        PM                  R\O        V PH                  4      PP                  4       \S        RWVVVV4      #   \>         d    \A        T4      p. p LÉi ; i)z†Assemble the attempt's request in the original order (every mutation happens BEFORE
middleware/hooks/debug dumps observe the payload).)Ú%_moa_client_consumes_prepared_requestÚ%_redecorate_prompt_cache_for_providerN)r]   Úmoa_preparedr   )r   Úcodex_responsesF)Úallow_streamÚis_github_responsesÚsanitize_harmony_tokenszX-OpenRouter-CacheÚfalseÚ_is_user_initiated_turnzx-initiatorÚuser)Úapply_llm_request_middlewarer@   )
r>   r6   r3   r?   rC   rD   rE   rF   rG   r2   )
r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   ÚHERMES_DUMP_REQUESTSÚ	preflight)ÚreasonÚmoar   z_MoA client replaced mid-turn (client=%s); sending the prepared prompt without the MoA handshakeÚfallthrough)*rR   r_   r`   Ú_reset_stream_delivery_trackingÚ_last_api_first_chunk_atÚ$_reapply_reasoning_echo_for_providerr   r   rW   Ú_build_api_kwargsr   rG   Ú_get_transportÚpreflight_kwargsÚ_is_copilot_urlÚ_is_codex_backendÚ_empty_content_retriesÚ_is_openrouter_urlr*   Úgetattrrg   Úhermes_cli.middlewareri   r?   rC   rD   rE   rF   ÚpayloadÚoriginal_payloadÚtracerY   r'   r[   r   Ú_dump_api_request_debugÚclientÚloggerÚwarningÚtyper   r
   )r,   r   r   r   r]   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r_   r`   r   ri   Ú_llm_request_mwr   r   s   &$$$$$$$$$$$$$$       r   Úbuild_api_requestr„   ]   sŠ  € ÷ð 
×)Ñ)Ô+à%)€EÔ"ð 
×.Ñ.¨|Ô<á-Ø°Ø'ô	
ñ 7€L¨ô % UÔ9Ü˜%Ô/ØŸ™Ô#Ø×,Ñ,¨\Ó:‰
à×,Ñ,¨\Ð,ÓWˆ
ô ˜U JÔ/Ø‡~�~Ð*Ô*Ø×)Ñ)Ó+×<Ñ<Ø UÀ×@UÑ@UÓ@WØ$)×$;Ñ$;Ó$=ð =ó 
ˆ
ð ×#Ñ# aÔ'¨E×,DÑ,D×,FÒ,FÜ˜*Ð&:¸GÔDô ˆuÐ/°×7Ò7¸E×<QÑ<Q×<SÒ<SÜ˜* m°VÔ<Ø(-ˆÔ%ð#ÝFá6ØÐ 1ÐSaØ×'Ñ'×-Ð-¨2¸¿¹×8LÐ8LÈ"ÐTY×T_ÑT_Ø—^‘^¨e¯n©nÀuÇ~Á~Ø)ô	
ˆð %×,Ñ,ˆ
Ø.×?Ñ?ÐØ /× 5Ñ 5Ðô
 Øˆz˜<Ð)>ÈØ3ØÈØ%Ø+õô Ð-×.Ò.Ø×%Ñ% j¸Ð%ÔEð Ò(¨U¯^©^¸uÔ-DÙ0°·±×>Ò>Ø2GˆJÐ.Ò/ä�N‰Nð<ä�U—\‘\Ó"×+Ñ+ôô
 Ø�|¸MÈ:ØÐ3óð øô9 ô #Ü# JÓ/ÐØ "Òð#ús   ÅJ Å5J Æ
AJ ÊJ-Ê,J-)r   Ú
__future__r   Údataclassesr   ÚloggingÚtypingr   Úagent.message_sanitizationr   r   Ú2hermes_cli.observability.shared_metrics_efficiencyr   Úutilsr   Ú	getLoggerr€   r
   r*   r[   r„   r   r   r   Ú<module>r�      s\   ðñõ #å !Û Ý ç aÝ TÝ !à	×	Ò	Ð4Ó	5€ð ÷
ð 
ó ð
õ&õ/÷d\r   