+
    jHàj  ã                  ó6   € R t ^ RIHt ^ RItR R ltR R ltR# )zLCode-fence helpers shared by the stream consumer and the gateway final send.)ÚannotationsNc               ó    € V ^8„  d   QhRRRR/# ©é   ÚtextÚstrÚreturn© )Úformats   "ÚC/home/ubuntu/.hermes/hermes-agent/gateway/stream_consumer_fences.pyÚ__annotate__r      s   € ÷ Oñ O¨ð O°ñ Oó    c                óV   € \        V \        4      '       d   V P                  RR4      # T # )z–Replace each ``` with \`\`\` so text can be wrapped in an outer ``` block.

Reasoning content that quotes code would otherwise break the outer fence.
ú```z\`\`\`)Ú
isinstancer   Úreplace)r   s   &r   Úescape_code_fences_for_displayr      s&   € ô
 0:¸$Ä×/DÒ/Dˆ4�<‰<˜˜{Ó+ÐNÈ$ÐNr   c               ó    € V ^8„  d   QhRRRR/# r   r	   )r
   s   "r   r   r      s   € ÷ ñ  Cð ¨Cñ r   c                ó|  € \        V \        4      '       d	   V '       g   V # V P                  R4      ^,          ^8X  d   V P                  R4      R,           p \        P
                  ! RRV \        P                  R7      p\        P
                  ! RRV4      pVP                  R4      ^,          ^8X  d
   V R,           p V # )	uo  Append a closing ``` and/or ` if the text has orphaned code markers.

Output truncated mid-code-block (finish_reason="length") would otherwise render
everything after the orphan as one code block / inline span; a spurious close is
far less harmful.  Odd ``` count â†’ fence on its own line; then, with complete
```â€¦``` regions stripped, odd ` count â†’ a backtick.
r   Ú
z
```z	```.*?```Ú )Úflagsz	```[^`]*$Ú`)r   r   ÚcountÚrstripÚreÚsubÚDOTALL)r   Úwithout_fencess   & r   Úensure_closed_code_fencesr      s“   € ô �dœC× Ò ¯Øˆà‡z�z�%Ó˜1Õ Ô!Ø�{‰{˜4Ó  7Õ*ˆô —V’V˜L¨"¨d¼"¿)¹)ÔD€NÜ—V’V˜L¨"¨nÓ=€Nà×Ñ˜CÓ  1Õ$¨Ô)Ø�c�zˆà€Kr   )Ú__doc__Ú
__future__r   r   r   r   r	   r   r   Ú<module>r"      s   ðÙ Rå "ã 	õO÷r   