+
    iHàj  ã                  ó~   € R t ^ RIHt ^ RIt^ RIt^ RIHt ^ RIt]P                  ! ]	4      t
R	tRtR]R]/R R lltR# )
aê  Bounded reads of HTTP error response bodies.

On a non-OK *streaming* response Hermes reads the body for a diagnostic (only ever shown truncated to
a few hundred chars). A bare ``response.read()`` is unbounded two ways: arbitrarily large body
(memory) or a body that stalls forever (hang). ``read_streaming_error_body`` caps bytes and enforces a
hard wall-clock deadline; callers use the returned text instead of ``response.text`` (unbounded /
raises after a partial stream read). ``httpx.iter_bytes()`` blocks *inside* the socket read, so the
read runs on a daemon thread; on timeout we close the response (unblocking the read) and return the
partial bytes. Used by the streaming error-body sites: native Gemini, Gemini Cloud Code, Antigravity.
)ÚannotationsN)ÚListg      $@Ú	max_bytesÚ	timeout_sc               ó(   € V ^8„  d   QhRRRRRRRR/# )	é   Úresponsezhttpx.Responser   Úintr   ÚfloatÚreturnÚstr© )Úformats   "Ú;/home/ubuntu/.hermes/hermes-agent/agent/bounded_response.pyÚ__annotate__r      s2   € ÷ 3>ñ 3>Øð3>ð ð3>ð ð	3>ð
 	ñ3>ó    c               ó  a aaaa€ . oRR/o\         P                  ! 4       oR VVVV V3R llp\         P                  ! VRRR7      P                  4        SP	                  VR7      '       g(   \
        P                  R	V\        R
 S 4       4      4        S P                  4        SR,          '       d(   \
        P                  R\        R S 4       4      S4       RP                  S4      P                  RRR7      #   \         d     Lei ; i)a  Read a non-OK streaming body with a byte cap and a hard deadline.

Returns UTF-8 text (errors replaced) truncated to ``max_bytes``. Never raises: transport errors,
stalls and oversize bodies yield best-effort partial text (or ""), so a read error can't mask the
original failure.
Ú	truncatedFc               ó   € V ^8„  d   QhRR/# )r   r   ÚNoner   )r   s   "r   r   Ú/read_streaming_error_body.<locals>.__annotate__,   s   € ÷ ñ �Dñ r   c                 ó´  <€ ^ p  SP                  4        Fk  pV'       g   K  SV ,
          p\        V4      V8”  d#   V^ 8”  d   SP                  VRV 4       RSR&    M(SP                  V4       V \        V4      ,          p Km  	   SP                  4        R#   \         d!   p\        P                  RT4        Rp?L8Rp?ii ; i  SP                  4        i ; i)é    NTr   z"bounded error-body read failed: %s)Ú
iter_bytesÚlenÚappendÚ	ExceptionÚloggerÚdebugÚset)	ÚtotalÚchunkÚ	remainingÚexcÚchunksÚdoner   r   Ústates	       €€€€€r   Ú_drainÚ)read_streaming_error_body.<locals>._drain,   sº   ø€ Øˆð	Ø!×,Ñ,Ö.�ßÙØ%¨Õ-�	Ü�u“: 	Ô)Ø  1”}ØŸ™ e¨J¨YÐ&7Ô8Ø)-�E˜+Ñ&ÙØ—‘˜eÔ$Øœ˜U›Õ#’ò /ð �H‰HŽJøô ô 	DÜ�L‰LÐ=¸s×CÑCûð	Dûð �H‰H�Jús<   …AB ÁC Á'B ÂC ÂCÂ"B=Â8C Â=CÃC ÃCzbounded-error-body-readT)ÚtargetÚnameÚdaemon)ÚtimeoutzCbounded error-body read: hard timeout after %.1fs (%d bytes so far)c              3  ó8   "  € T F  p\        V4      x € K  	  R # 5i©N©r   ©Ú.0Úcs   & r   Ú	<genexpr>Ú,read_streaming_error_body.<locals>.<genexpr>C   s   é € Ð2©6 aœ3˜qŸ6˜6«6ùó   ‚z4bounded error-body read: capped at %d bytes (max=%d)c              3  ó8   "  € T F  p\        V4      x € K  	  R # 5ir.   r/   r0   s   & r   r3   r4   M   s   é € ÐG_ÑX^ÐSTÌÈAÏÈÓX^ùr5   r   zutf-8Úreplace)Úerrors)Ú	threadingÚEventÚThreadÚstartÚwaitr   r   ÚsumÚcloser   ÚjoinÚdecode)r   r   r   r'   r$   r%   r&   s   fd$ @@@r   Úread_streaming_error_bodyrB      sé   ü€ ð €FØ˜%Ð €EÜ�?Š?Ó€D÷ô ô& ×Ò˜FÐ)BÈ4ÔP×VÑVÔXØ�9‰9˜Yˆ9×'Ò'Ü�‰ØQØ”sÑ2©6Ó2Ó2ô	
ð
Ø�‰Ôð ˆ[×ÔÜ�‰ØBÄCÑG_ÑX^ÓG_ÓD_Ðajô	
ð �8‰8�FÓ×"Ñ" 7°9Ð"Ó=Ð=øô ô Ùðús   ÂC= Ã=DÄ
Di   )Ú__doc__Ú
__future__r   Úloggingr9   Útypingr   ÚhttpxÚ	getLoggerÚ__name__r   ÚDEFAULT_ERROR_BODY_MAX_BYTESÚDEFAULT_ERROR_BODY_TIMEOUT_SrB   r   r   r   Ú<module>rL      sW   ðñ	õ #ã Û Ý ã à	×	Ò	˜8Ó	$€ð  )Ð à#Ð ð3>ð 2ð3>ð 4÷	3>ñ 3>r   