+
    kHàjîj  ã                  ó0  € R t ^ RIHt ^ RIt^ RIHtHtHtHtH	t	 ^2t
Rt^–t^dt^tRt]]]3,          t]P&                  ! R4      t]P&                  ! R4      t]P&                  ! R4      t]P&                  ! R	4      t]P&                  ! R
4      t]P&                  ! R4      t]P&                  ! R4      tR R ltR R lt]P&                  ! R4      t]P&                  ! R4      t]P&                  ! R4      t]P&                  ! R4      t ]P&                  ! R4      t!]P&                  ! R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% R& lt*R' R( lt+R) R* lt,R+ R, lt-R- R. lt.R/ R0 lt/R1 R2 lt0R;R3 R4 llt1R5 R6 lt2R7 R8 lt3R9 R: lt4R# )<u  Render agent markdown into Slack Block Kit blocks.

Opt-in (``slack.extra.rich_blocks: true``) alternative to the flat mrkdwn
``text`` payload produced by :meth:`SlackAdapter.format_message`.  Block Kit
gives us real structural primitives â€” section headers, dividers, and true
*nested* lists via ``rich_text`` â€” that plain mrkdwn can only approximate.

Design constraints (why this module is deliberately conservative):

* **Markdown pipe-tables render as native ``table`` blocks** â€” real grid
  cells with per-column alignment and inline-formatted ``rich_text`` content.
  A table that exceeds Slack's limits (100 rows / 20 cols / 10k aggregate
  cell chars) or won't parse falls back to aligned monospace
  ``rich_text_preformatted`` so a large table never breaks the message.
* **Slack caps a message at 50 blocks** and a ``section``/text object at 3000
  characters.  :func:`render_blocks` enforces both and, if the content simply
  cannot be expressed within them, returns ``None`` so the caller falls back
  to the plain-text path.  A rich render is a nice-to-have; it must never lose
  a message.
* **Every blocks payload MUST ship a ``text`` fallback.**  Slack uses it for
  notifications, screen readers, and old clients.  This module only builds the
  ``blocks`` list; the adapter pairs it with the existing mrkdwn string.

The renderer never raises: any unexpected input degrades to ``None`` (caller
uses plain text).  It is a pure function of its input â€” no Slack client, no
adapter state â€” so it is trivially unit-testable.
)ÚannotationsN)ÚAnyÚDictÚListÚOptionalÚTuplei¸  i'  z ^\s{0,3}([-*_])(?:\s*\1){2,}\s*$z!^\s{0,3}(#{1,6})\s+(.+?)\s*#*\s*$z^\s*(`{3,}|~{3,})(.*)$z^(\s*)(\d+)[.)]\s+(.*)$z^(\s*)[-*+]\s+(.*)$z^\s{0,3}>\s?(.*)$z1^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)+\|?\s*$c               ó    € V ^8„  d   QhRRRR/# )é   ÚlineÚstrÚreturnÚbool© )Úformats   "ÚF/home/ubuntu/.hermes/hermes-agent/plugins/platforms/slack/block_kit.pyÚ__annotate__r   :   s   € ÷ Cñ C˜ð C ñ Có    c                óx   € \        \        P                  V 4      ;'       g    \        P                  V 4      4      # )z=True if ``line`` is a markdown list item (bullet or ordered).)r   Ú
_BULLET_REÚmatchÚ_ORDERED_RE)r
   s   &r   Ú_is_list_liner   :   s+   € ä”
× Ñ  Ó&×AÐA¬+×*;Ñ*;¸DÓ*AÓBÐBr   c               ó    € V ^8„  d   QhRRRR/# )r	   Úspacesr   r   Úintr   )r   s   "r   r   r   ?   s   € ÷ ñ ˜#ð  #ñ r   c                ó`   € ^ pV  F  pYR8X  d   ^M^,          pK  	  \        V^,          ^4      # )zHMap leading whitespace to a nesting level (2 spaces or 1 tab per level).Ú	)Úmin)r   ÚwidthÚchs   &  r   Ú_indent_levelr    ?   s2   € à€EÛˆØ˜D”j‘ aÕ'Šñ äˆu˜�z˜1ÓÐr   z	`([^`]+)`z7(?<!!)\[([^\]]+)\]\(([^()\s]+(?:\([^()]*\)[^()\s]*)*)\)z1<([a-zA-Z][a-zA-Z0-9+.\-]*:[^>|]+)(?:\|([^>]+))?>z(?:\*\*|__)(.+?)(?:\*\*|__)z?(?<![\*_])(?:\*|_)(?![\*_\s])(.+?)(?<![\*_\s])(?:\*|_)(?![\*_])z	~~(.+?)~~c               ó    € V ^8„  d   QhRRRR/# )r	   Útextr   r   úlist[dict[str, Any]]r   )r   s   "r   r   r   X   s   € ÷ @8ñ @8˜3ð @8Ð#7ñ @8r   c                ó¾   aaaaaa€ . oRR V3R llloR VV3R llpR V3R lloR VV3R lloR	 VV3R
 lloR VV3R lloV! V / 4       S;'       g    RRRV /.# )z÷Parse a run of inline markdown into rich_text section child elements.
Produces ``text`` elements (optionally styled bold/italic/strike/code) and ``link`` elements.
Unmatched markup is emitted verbatim as plain text, so this never loses characters.c               ó$   € V ^8„  d   QhRRRRRR/# )r	   Úsr   ÚstylezOptional[dict[str, bool]]r   ÚNoner   )r   s   "r   r   Ú&_inline_elements.<locals>.__annotate__^   s"   € ÷ ñ �Sð Ð!:ð Àdñ r   c                ób   <€ V '       g   R # RRRV /pV'       d   WR&   SP                  V4       R # )NÚtyper"   r'   )Úappend)r&   r'   ÚelÚelementss   && €r   Ú	emit_textÚ#_inline_elements.<locals>.emit_text^   s-   ø€ ßÙØ$ f¨f°aÐ8ˆßØˆw‰KØ�‰˜Ör   c               ó$   € V ^8„  d   QhRRRRRR/# ©r	   r&   r   r'   údict[str, bool]r   r(   r   )r   s   "r   r   r)   i   s!   € ÷ $ñ $�ð $˜Oð $°ñ $r   c                óè   <€ ^ p\         P                  V 4       FJ  pS! WVP                  4        V4       S! VP                  ^4      / VCRR/C4       VP	                  4       pKL  	  S! WR V4       R# )é    ÚcodeTN)Ú_INLINE_CODE_REÚfinditerÚstartÚgroupÚend)r&   r'   ÚposÚmÚ_walk_linksr/   s   &&  €€r   ÚwalkÚ_inline_elements.<locals>.walki   sl   ø€ Øˆä ×)Ñ)¨!Ö,ˆAÙ˜ §¡£	Ð*¨EÔ2Ù�a—g‘g˜a“jÐ"9 UÐ"9¨F°DÑ"9Ô:Ø—%‘%“'ŠCñ -ñ 	�A�d�G˜UÖ#r   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r	   Úurlr   r"   r'   r3   r   r(   r   )r   s   "r   r   r)   q   s(   € ÷ !ñ !˜ð ! 3ð !¨ð !À4ñ !r   c                óf   <€ R RRV RV/pV'       d   \        V4      VR&   SP                  V4       R# )r+   ÚlinkrB   r"   r'   N)Údictr,   )rB   r"   r'   Úlink_elr.   s   &&& €r   Ú
_emit_linkÚ$_inline_elements.<locals>._emit_linkq   s2   ø€ Ø#)¨6°5¸#¸vÀtÐ"LˆßÜ# E›{ˆG�GÑØ�‰˜Ö r   c               ó$   € V ^8„  d   QhRRRRRR/# r2   r   )r   s   "r   r   r)   w   s!   € ÷ *ñ *�sð * ?ð *°tñ *r   c                óü   <€ ^ p\         P                  V 4       FT  pS! WVP                  4        V4       S! VP                  ^4      VP                  ^4      V4       VP	                  4       pKV  	  S! WR V4       R# ©r5   N)Ú_LINK_REr8   r9   r:   r;   )r&   r'   r<   r=   rG   Ú_walk_slack_linkss   &&  €€r   r>   Ú%_inline_elements.<locals>._walk_linksw   si   ø€ ØˆÜ×"Ñ" 1Ö%ˆAÙ˜a a§g¡g£iÐ0°%Ô8Ù�q—w‘w˜q“z 1§7¡7¨1£:¨uÔ5Ø—%‘%“'ŠCñ &ñ 	˜!˜D˜' 5Ö)r   c               ó$   € V ^8„  d   QhRRRRRR/# r2   r   )r   s   "r   r   r)      s!   € ÷ 	'ñ 	'˜Sð 	'¨ð 	'¸Tñ 	'r   c                ó  <€ ^ p\         P                  V 4       F_  pS! WVP                  4        V4       VP                  ^4      pS! YCP                  ^4      ;'       g    TV4       VP	                  4       pKa  	  S! WR V4       R# rK   )Ú_SLACK_LINK_REr8   r9   r:   r;   )r&   r'   r<   r=   rB   rG   Ú_walk_emphasiss   &&   €€r   rM   Ú+_inline_elements.<locals>._walk_slack_links   sv   ø€ ð ˆÜ×(Ñ(¨Ö+ˆAÙ˜1 1§7¡7£9Ð-¨uÔ5Ø—'‘'˜!“*ˆCÙ�sŸG™G A›J×-Ð-¨#¨uÔ5Ø—%‘%“'ŠCñ	 ,ñ
 	�q˜�w Ö&r   c               ó$   € V ^8„  d   QhRRRRRR/# r2   r   )r   s   "r   r   r)   ‰   s!   € ÷ 5ñ 5˜#ð 5 oð 5¸$ñ 5r   c                óŠ  <€ V '       g   R # \         R3\        R3\        R33 F{  w  r#VP                  V 4      pV'       g   K   S! V R VP	                  4        V4       \        V4      pRWS&   S! VP                  ^4      V4       S! WP                  4       R  V4        R # 	  S! Y'       d   \        V4      4       R # R 4       R # )NÚboldÚstrikeÚitalicT)Ú_BOLD_REÚ
_STRIKE_REÚ
_ITALIC_REÚsearchr9   rE   r:   r;   )r&   r'   ÚrxÚkeyr=   Úinner_stylerR   r/   s   &&    €€r   rR   Ú(_inline_elements.<locals>._walk_emphasis‰   s¦   ø€ ßÙä! 6Ð*¬Z¸Ð,BÄZÐQYÐDZÓ[‰GˆBØ—	‘	˜!“ˆAß‰qÙ˜q  1§7¡7£9˜~¨uÔ5Ü" 5›k�Ø#'�Ñ Ù˜qŸw™w q›z¨;Ô7Ù˜q§¡£ ˜|¨UÔ3Úñ \ñ 	�!¦E”T˜%“[Ö4¨tÖ4r   r+   r"   ©Nr   )r"   r?   rG   rR   r>   rM   r.   r/   s   & @@@@@@r   Ú_inline_elementsrb   X   sk   ý€ ð &(€H÷ò ÷$ñ $÷!ð !÷*ñ *÷	'ñ 	'÷5ñ 5ñ 	ˆˆr„NØ×7Ð7˜ ¨°Ð6Ð7Ð7r   c               ó    € V ^8„  d   QhRRRR/# )r	   r.   r#   r   r   )r   s   "r   r   r       s   € ÷ 
2ñ 
2Ð!5ð 
2Ð:Nñ 
2r   c                ó¬   € V  Uu. uF3  qP                  R4      R8X  d   VP                  R4      '       g   K1  VNK5  	  ppT;'       g    RRRR/.# u upi )u¾  Make a rich_text child-element list safe for Slack.
Slack rejects any ``rich_text_section`` / ``rich_text_preformatted`` / ``rich_text_quote`` whose
``elements`` list is empty or contains a ``text`` element of zero length (``invalid_blocks``:
"missing element" / "must be more than 0 characters"). Empty content is common â€” ragged table
rows are padded with ``""``, agents emit empty code fences around empty tool output, blank quote
lines and empty list items occur in the wild â€” so drop zero-length text elements and, if nothing
remains, substitute a single space, which renders as blank yet stays schema-valid. Used by every
rich_text builder so empty content can never poison the whole payload.r+   r"   Ú )Úget)r.   ÚeÚelss   &  r   Ú_nonempty_elementsri       sQ   € ñ Ó
V‘h�§u¡u¨V£}¸Ô'>ÀqÇuÁuÈVÇ}�1ˆ1‘h€CÐ
VØ×1Ð1�F˜F F¨CÐ0Ð1Ð1ùò Ws
   ….A¸Ac               ó    € V ^8„  d   QhRRRR/# )r	   r"   r   r   úOptional[Block]r   )r   s   "r   r   r   ­   s   € ÷ 
\ñ 
\˜ð 
\ ñ 
\r   c           	     óÐ   € \         P                  ! R RV 4      P                  4       pV'       g   R# \        V4      \        8”  d   VR\        ^,
           R,           pRRRRRRVRR	//# )
z[*_~`]Ú Nõ   â€¦r+   Úheaderr"   Ú
plain_textÚemojiT)ÚreÚsubÚstripÚlenÚMAX_HEADER_TEXT)r"   Úcleans   & r   Ú_header_blockrx   ­   se   € ä�FŠF�9˜b $Ó'×-Ñ-Ó/€Eßñ Ü
ˆ5ƒz”OÔ#ØÐ+œ¨!Õ+Ð,¨uÕ4ˆØ�H˜f v¨|¸VÀUÈGÐUYÐ&ZÐ[Ð[r   c               ó   € V ^8„  d   QhRR/# )r	   r   ÚBlockr   )r   s   "r   r   r   º   s   € ÷ ñ ˜ñ r   c                 ó
   € R R/# )r+   Údividerr   r   r   r   Ú_divider_blockr}   º   s   € Ø�IÐÐr   c               ó$   € V ^8„  d   QhRRRRRR/# )r	   Úkindr   Úchildrenr#   r   rz   r   )r   s   "r   r   r   ¾   s'   € ÷ eñ e˜3ð eÐ*>ð eÀ5ñ er   c           	     ó*   € RRRRV R\        V4      /./# )zXOne ``rich_text`` block wrapping a single ``kind`` element (section/quote/preformatted).r+   Ú	rich_textr.   )ri   )r   r€   s   &&r   Ú_rich_text_blockrƒ   ¾   s,   € ð 	�˜Z¨6°4¸ÔEWÐX`ÓEaÐ*bÐ)cðeð er   c               ó    € V ^8„  d   QhRRRR/# ©r	   r"   r   r   rz   r   )r   s   "r   r   r   Ä   s   € ÷ eñ e˜cð e eñ er   c           	     óB   € \        R RRRV P                  R4      /.4      # )Úrich_text_preformattedr+   r"   Ú
)rƒ   Úrstrip©r"   s   &r   Ú_preformatted_blockr‹   Ä   s)   € äÐ4¸ÀÈÐPT×P[ÑP[Ð\`ÓPaÐ7bÐ6cÓdÐdr   c               ó    € V ^8„  d   QhRRRR/# )r	   Úlinesú	list[str]r   rz   r   )r   s   "r   r   r   É   s   € ÷ Añ A˜	ð A eñ Ar   c                ó´   € . p\        V 4       F<  w  r#V'       d   VP                  R RRR/4       VP                  \        V4      4       K>  	  \	        RV4      # )r+   r"   rˆ   Úrich_text_quote)Ú	enumerater,   Úextendrb   rƒ   )r�   Úsection_childrenÚiÚlns   &   r   Ú_quote_blockr–   É   sX   € Ø-/ÐÜ˜5Ö!‰ˆßØ×#Ñ# V¨V°V¸TÐ$BÔCØ×ÑÔ 0°Ó 4Ö5ñ "ô Ð-Ð/?Ó@Ð@r   c               ó    € V ^8„  d   QhRRRR/# )r	   Úitemszlist[tuple[int, bool, str]]r   rz   r   )r   s   "r   r   r   Ò   s   € ÷ 7ñ 7Ð2ð 7°uñ 7r   c                óî   € . pRpRpV  Fd  w  rEpWE3pWs8w  d(   RRRV'       d   RMRRVR. /pVP                  V4       TpVR,          P                  RR	R\        \        V4      4      /4       Kf  	  RR
RV/# )a  Build ONE rich_text block from consecutive list items.
``items`` is a list of ``(indent, ordered, text)``. Each contiguous run sharing the same
(indent, ordered) becomes a ``rich_text_list`` element; indentation changes start a new element,
which is how Slack renders true nesting.Nr+   Úrich_text_listr'   ÚorderedÚbulletÚindentr.   Úrich_text_sectionr‚   )r,   ri   rb   )r˜   r.   ÚcurÚcur_keyr�   r›   r"   r^   s   &       r   Ú_list_blockr¡   Ò   sž   € ð
 &(€HØ$(€CØ*.€GÛ!&Ñˆ˜ØÐˆØŒ>àÐ(¨'Ç±9ÈXØ˜& *¨bð2ˆCð �O‰O˜CÔ ØˆGØˆJ�×ÑØÐ(¨*Ô6HÔIYÐZ^ÓI_Ó6`Ðaö	cñ "'ð �K ¨XÐ6Ð6r   c               ó    € V ^8„  d   QhRRRR/# r…   r   )r   s   "r   r   r   ç   s   € ÷ Iñ I˜ð I ñ Ir   c                ó   € R RRR RRV //# )r+   Úsectionr"   Úmrkdwnr   rŠ   s   &r   Ú_section_blockr¦   ç   s   € Ø�I˜v¨°¸&À$Ð'GÐHÐHr   c               ó    € V ^8„  d   QhRRRR/# )r	   Úsep_liner   r   rŽ   r   )r   s   "r   r   r   ð   s   € ÷ ñ ˜sð  yñ r   c                ó0  € . pV P                  4       P                  R4      P                  R4       Fa  pVP                  4       pVP                  R4      VP                  R4      rTTP	                  V'       d   V'       d   RMV'       d   RMR4       Kc  	  V# )zˆParse a markdown separator row (``|:--|:-:|--:|``) into column aligns.
Returns a list of ``"left"``/``"center"``/``"right"`` per column.Ú|Ú:ÚcenterÚrightÚleft)rt   ÚsplitÚ
startswithÚendswithr,   )r¨   ÚalignsÚcellÚcr®   r­   s   &     r   Ú_parse_alignmentrµ   ð   sp   € ð €FØ—‘Ó ×&Ñ& sÓ+×1Ñ1°#Ö6ˆØ�J‰J‹LˆØ—l‘l 3Ó'¨¯©°C«ˆeØ�‰§$¯5‘hÇ±gÈFÖSñ 7ð €Mr   c               ó    € V ^8„  d   QhRRRR/# )r	   Úrowr   r   rŽ   r   )r   s   "r   r   r   û   s   € ÷ Rñ R�Cð R˜Iñ Rr   c                óæ   € V P                  4       P                  R4      P                  RR4      pVP                  R4       Uu. uF"  q"P                  4       P                  RR4      NK$  	  up# u upi )zŒSplit a markdown table row into trimmed cell strings.
Respects backslash-escaped pipes (``\|``) so they aren't treated as column separators.rª   z\|z PIPE )rt   Úreplacer¯   )r·   Ú	protectedr´   s   &  r   Ú
_split_rowr»   û   s[   € ð —	‘	“×!Ñ! #Ó&×.Ñ.¨u°nÓE€IØ<E¿O¹OÈCÔ<PÓQÑ<P°q�G‰G‹I×Ñ˜n¨cÖ2Ñ<PÑQÐQùÒQs   Á(A.c               ó    € V ^8„  d   QhRRRR/# )r	   r"   r   r   údict[str, Any]r   )r   s   "r   r   r     s   € ÷ Iñ I˜#ð I .ñ Ir   c                ó,   € \        R\        V 4      4      # )a  A ``rich_text`` table cell carrying inline-formatted content.
Empty cells are common (ragged rows are padded with ``""``); Slack rejects a cell whose section
is empty or carries a zero-length text element, so the elements are routed through
``_nonempty_elements``.rž   )rƒ   rb   rŠ   s   &r   Ú_rich_text_cellr¿     s   € ô
 Ð/Ô1AÀ$Ó1GÓHÐHr   c               ó$   € V ^8„  d   QhRRRRRR/# )r	   ÚrowsrŽ   r¨   r   r   rk   r   )r   s   "r   r   r     s!   € ÷ ñ �yð ¨Cð °Oñ r   c                ó  € V  Uu. uF%  q"P                  4       '       g   K  \        V4      NK'  	  ppV'       g   R# \        R V 4       4      p\        V4      \        8”  g   V\
        8”  d   R# V F,  pVP                  R.V\        V4      ,
          ,          4       K.  	  \        R V 4       4      pV\        8”  d   R# \        V4      p\        V4       Uu. uF  qw\        V4      8  d	   Wg,          MRNK  	  pp\        R \        V4       4       RR7      p	VRV	^,             U
u. uF  p
RV
/NK	  	  pp
R	R
RV UUu. uF  qÌ Uu. uF  p\        V4      NK  	  upNK  	  upp/pV'       d   W¾R&   V# u upi u upi u up
i u upi u uppi )u’  Build a native Slack ``table`` block from markdown pipe-table rows.
``rows`` includes the header row (index 0) and body rows; ``sep_line`` is the ``|---|``
alignment row (already consumed by the caller). Returns ``None`` when the table exceeds Slack's
limits (100 rows / 20 cols / 10,000 aggregate cell chars) or parses to nothing â€” the caller then
falls back to the monospace preformatted rendering.Nc              3  ó8   "  € T F  p\        V4      x € K  	  R # 5ira   ©ru   ©Ú.0Úrs   & r   Ú	<genexpr>Ú_table_block.<locals>.<genexpr>  ó   é € Ð'¡˜1”�A—�£ùó   ‚rm   c              3  óH   "  € T F  q F  p\        V4      x € K  	  K  	  R # 5ira   rÄ   ©rÆ   rÇ   r´   s   &  r   rÈ   rÉ     s   é € Ð8¡f ²a°”c˜!—f�f±a‘f£fùs   ‚ "r®   c              3  ó<   "  € T F  w  rVR 8w  g   K  Vx € K  	  R# 5i)r®   Nr   )rÆ   r´   Úas   &  r   rÈ   rÉ   #  s   é € ÐKÑ*;¡$ !¸qÀF¹{ŸAšAÓ*;ùs   ‚’
)ÚdefaultÚalignr+   ÚtablerÁ   Úcolumn_settingséÿÿÿÿ)rt   r»   Úmaxru   ÚMAX_TABLE_ROWSÚMAX_TABLE_COLSr’   ÚsumÚMAX_TABLE_CHARSrµ   Úranger‘   r¿   )rÁ   r¨   rÇ   ÚparsedÚncolsÚtotal_charsr²   r´   ÚpaddedÚlast_non_defaultrÏ   rÓ   r·   r³   Úblocks   &&             r   Ú_table_blockrá     sb  € ñ &*Ó7¡T ¯W©W¯YŒmŒj˜Žm¡T€FÐ7ßÙÜÑ'¡Ó'Ó'€Eä
ˆ6ƒ{”^Ô# u¬~Ô'=ÙÛˆØ	�‰�"�˜¤ Q£�Õ(Ö)ñ äÑ8¡fÓ8Ó8€KØ”_Ô$ÙÜ˜hÓ'€Fô
 AFÀeÄÓMÁ¸1œs 6›{œ?ˆfŽi°Ò6Á€FÐMÜÑK¬)°FÔ*;ÓKÐUWÔXÐØ-3Ð4JÐ6FÈÕ6JÑ-KÓLÑ-K¨˜ “|Ñ-K€OÐLà�˜ÑU[Ô!\ÑU[ÈcÀSÓ"IÁS¸T¤?°4Ö#8ÁSÔ"IÑU[Ò!\ð^€EçØ#2ÐÑ Ø€Lùò1 8ùò" NùâLùâ"IùÓ!\s.   …E4¡E4Ã"E9Ä'E>Ä>FÅFÅFÆFc               ó    € V ^8„  d   QhRRRR/# )r	   rÁ   rŽ   r   r   r   )r   s   "r   r   r   ,  s   € ÷  ñ  ˜	ð   cñ  r   c           	     ó¸  aaa€ V  Uu. uF  p\        V4      NK  	  ppV'       g   RP                  V 4      # \        R V 4       4      pV F,  oSP                  R.V\	        S4      ,
          ,          4       K.  	  \        V4       Uau. uF  o\        V3R lV 4       4      NK  	  upo. p\        V4       F†  w  poRP                  VV3R l\        V4       4       4      pVP                  VP                  4       4       V^ 8X  g   KS  VP                  RP                  V3R l\        V4       4       4      4       Kˆ  	  RP                  V4      # u upi u upi )	zERender markdown pipe-table rows as aligned monospace text (fallback).rˆ   c              3  ó8   "  € T F  p\        V4      x € K  	  R # 5ira   rÄ   rÅ   s   & r   rÈ   Ú _render_table.<locals>.<genexpr>1  rÊ   rË   rm   c              3  óH   <"  € T F  p\        VS,          4      x € K  	  R # 5ira   rÄ   rÍ   s   & €r   rÈ   rå   4  s   øé € Ð,¡V ”#�a˜•d—)�)£Vùs   ƒ"z | c              3  ób   <"  € T F$  pSV,          P                  SV,          4      x € K&  	  R # 5ira   )Úljust)rÆ   r´   rÇ   Úwidthss   & €€r   rÈ   rå   7  s%   øé € ÐF¹°A˜!˜A�$Ÿ*™* V¨A¥Y×/Ð/»ùs   ƒ,/z-+-c              3  óD   <"  € T F  pR SV,          ,          x € K  	  R# 5i)Ú-Nr   )rÆ   r´   ré   s   & €r   rÈ   rå   :  s   øé € Ð'NÁ¸A¨¨f°Q­i¯ªÃùs   ƒ )	r»   ÚjoinrÕ   r’   ru   rÚ   r‘   r,   r‰   )	rÁ   rÇ   rÛ   rÜ   r´   Ú	out_linesÚrir
   ré   s	   &`  `   @r   Ú_render_tablerï   ,  s  ú€ á%)Ó*¡T Œj˜Žm¡T€FÐ*ßØ�y‰y˜‹ÐÜÑ'¡Ó'Ó'€EÛˆØ	�‰�"�˜¤ Q£�Õ(Ö)ñ ä6;¸E´lÔC±l°ŒcÔ,¡VÓ,Ö,±lÑC€FØ€IÜ˜6Ö"‰ˆˆAØ�z‰zÕF¼¸u¼ÓFÓFˆØ×Ñ˜Ÿ™›Ô'Ø�Ž7Ø×Ñ˜UŸZ™ZÔ'NÄÀuÄÓ'NÓNÖOñ	 #ð
 �9‰9�YÓÐùò +ùò Ds   ˆEÂ	Ec               ó    € V ^8„  d   QhRRRR/# )r	   Úmarkdownr   r   úOptional[list[Block]]r   )r   s   "r   r   r   C  s   € ÷ _ñ _˜Cð _Ð4Iñ _r   c                ó"  aaa€ V '       d   V P                  4       '       g   R# T;'       g    R o . oV P                  RR4      P                  R4      p^ p\        V4      p. oR VVV3R llpW48  Eda   W#,          pVP                  4       '       g   V! 4        V^,          pK7  \        P                  V4      pV'       d«   V! 4        VP                  ^4      p. p	V^,          pW48  dN   W#,          P                  4       P                  V4      '       g#   V	P                  W#,          4       V^,          pKS  V^,          pSP                  \        RP                  V	4      4      4       Kþ  \        P                  V4      '       d-   V! 4        SP                  \        4       4       V^,          pEKE  \        P                  V4      p
V
'       dC   V! 4        \        V
P                  ^4      4      pVe   SP                  V4       V^,          pEK¤  RV9   dó   V^,           V8  då   \         P                  W#^,           ,          4      '       d½   V! 4        TpW#^,           ,          pV.pV^,          pW48  dL   RW#,          9   d?   W#,          P                  4       '       d#   VP                  W#,          4       V^,          pKQ  \#        Wí4      pVe   SP                  V4       M#SP                  \        \%        V4      4      4       EK�  \&        P                  V4      '       d|   V! 4        . pW48  dP   \&        P                  W#,          4      pV'       g   M+VP                  VP                  ^4      4       V^,          pKU  SP                  \)        V4      4       EK3  \+        V4      '       Ed   V! 4        . pW48  EdÙ   \,        P                  W#,          4      p\.        P                  W#,          4      pV'       dG   VP                  \1        VP                  ^4      4      RVP                  ^4      34       V^,          pK‹  V'       dG   VP                  \1        VP                  ^4      4      R	VP                  ^4      34       V^,          pKÙ  W#,          P                  4       '       di   W#,          P                  R4      '       dL   V'       dD   VR,          w  pppVVVR
,           W#,          P                  4       ,           3VR&   V^,          pEK]  W#,          P                  4       '       gf   V'       d^   V^,           pVV8  d)   VV,          P                  4       '       g   V^,          pK/  VV8  d   \+        VV,          4      '       d   TpEKÝ  M SP                  \3        V4      4       EKJ  SP                  V4       V^,          pEKg  V! 4        S'       g   R# \        S4      \4        8”  d   R# S#   \6         d     R# i ; i)u9  Convert agent markdown to a Slack Block Kit ``blocks`` list.
Args:
    markdown: The agent's response text (standard markdown).
    mrkdwn_fn: Optional callable converting a markdown paragraph to Slack
        mrkdwn for ``section`` blocks (the adapter passes
        ``format_message``).  When ``None``, the raw paragraph text is used.

Returns:
    A list of Block Kit block dicts, or ``None`` when the content is empty,
    exceeds Slack's structural limits, or hits an unexpected shape â€” the
    caller then falls back to the flat ``text`` payload.  Never raises.Nc                ó   € V # ra   r   )r&   s   &r   Ú<lambda>Úrender_blocks.<locals>.<lambda>Q  s   € ¡!r   z
rˆ   c               ó   € V ^8„  d   QhRR/# )r	   r   r(   r   )r   s   "r   r   Ú#render_blocks.<locals>.__annotate__Z  s   € ÷ 
	5ñ 
	5˜Dñ 
	5r   c                 ó   <€ S'       g   R # RP                  S4      P                  4       p SP                  4        V '       g   R # S! V 4      p\        V\        4       F  pSP                  \        V4      4       K  	  R # )Nrˆ   )rì   rt   ÚclearÚ_split_textÚMAX_SECTION_TEXTr,   r¦   )r"   ÚrenderedÚchunkÚblocksÚfmtÚparas      €€€r   Ú
flush_paraÚ!render_blocks.<locals>.flush_paraZ  s[   ø€ ßÙØ—9‘9˜T“?×(Ñ(Ó*ˆDØ�J‰JŒLßÙÙ˜4“yˆHä$ XÔ/?Ö@�Ø—‘œn¨UÓ3Ö4ó Ar   rª   FTre   )re   r   rÔ   )rt   r¹   r¯   ru   Ú	_FENCE_REr   r:   Úlstripr°   r,   r‹   rì   Ú_HR_REr}   Ú
_HEADER_RErx   Ú_TABLE_SEP_RErá   rï   Ú	_QUOTE_REr–   r   r   r   r    r¡   Ú
MAX_BLOCKSÚ	Exception)rñ   Ú	mrkdwn_fnr�   r”   Únr  r
   ÚfenceÚmarkerÚbodyÚhmro   Ú
header_rowr¨   ÚtrowsrÒ   ÚqlinesÚqmr˜   ÚbmÚomr�   r›   ÚtxtÚjrÿ   r   r  s   &&                       @@@r   Úrender_blocksr  C  s€  ú€ ÷ ˜8Ÿ>™>×+Ò+ÙØ
×
$Ð
$™€CðOØ ˆØ× Ñ  ¨Ó.×4Ñ4°TÓ:ˆØˆÜ�‹JˆØˆ÷
	5ò 
	5ð �eØ•8ˆDð —:‘:—<’<Ù”Ø�Q•�Ùô —O‘O DÓ)ˆEßÙ”ØŸ™ Q›�Ø"$�Ø�Q•�Ø”e E¥H§O¡OÓ$5×$@Ñ$@À×$HÒ$HØ—K‘K ¥Ô)Ø˜•F’AØ�Q•�Ø—‘Ô1°$·)±)¸D³/ÓBÔCÙô �|‰|˜D×!Ò!Ù”Ø—‘œnÓ.Ô/Ø�Q•�Úô ×!Ñ! $Ó'ˆBßÙ”Ü& r§x¡x°£{Ó3�ØÒ%Ø—M‘M &Ô)Ø�Q•�Úð �dŒ{˜q 1�u qœy¬]×-@Ñ-@ÀÈ1ÅuÅ×-NÒ-NÙ”Ø!�
Ø  Q¥�<�Ø#˜�Ø�Q•�Ø”e  u¥x¤°EµH·N±N×4DÒ4DØ—L‘L ¥Ô*Ø˜•F’Aô % UÓ5�ØÒ$Ø—M‘M %Õ(à—M‘MÔ"5´mÀEÓ6JÓ"KÔLÚô �‰˜t×$Ò$Ù”Ø$&�Ø”eÜ"Ÿ™¨­Ó2�BßØØ—M‘M "§(¡(¨1£+Ô.Ø˜•F’AØ—‘œl¨6Ó2Ô3Úô ˜T×"Ó"Ù”Ø57�Ø•eÜ#×)Ñ)¨%­(Ó3�BÜ$×*Ñ*¨5­8Ó4�BßØŸ™¤m°B·H±H¸Q³KÓ&@À%ÈÏÉÐRSËÐ%UÔVØ˜Q�šßØŸ™¤m°B·H±H¸Q³KÓ&@À$ÈÏÉÐQRËÐ%TÔUØ˜Q�šØ�Ÿ™×)Ò)¨e­h×.AÑ.AÀ+×.NÒ.N×SXà/4°R­yÑ,˜ ¨Ø%+¨W°c¸CµiÀ%Å(Ç.Á.ÓBRÕ6RÐ$S˜˜b™	Ø˜Q�›Ø"�XŸ^™^×-Ò-·%ð  �E˜Ø !œe¨E°!­H¯N©N×,<Ò,<Ø �FšAØ˜qœ5¤]°5¸µ8×%<Ò%<Ø !›Aà!àØ—‘œk¨%Ó0Ô1Úð �K‰K˜ÔØ��F‹AÙŒçÙÜˆv‹;œÔ#ñ ØˆøÜô âðúsU   ²BW? ÃCW? ÆAW? ÇEW? Ì'D(W? ÑBW? ÓA&W? Ô>,W? Õ+A9W? ×'W? ×=W? ×?XØXc               ó$   € V ^8„  d   QhRRRRRR/# )r	   r"   r   Úlimitr   r   rŽ   r   )r   s   "r   r   r   å  s!   € ÷  ñ  �cð   #ð  ¨)ñ  r   c                óD  € \        V 4      V8:  d   V .# RV 9   d   \        V^,
          V^,          ^4      MTp. pT p\        V4      V8”  dF   VP                  R^ V4      pV^ 8:  d   TpVP                  VRV 4       WER P	                  R4      pKU  V'       d   VP                  V4       \        V4      ^8”  dg   RV 9   d`   . pRpV FS  pV'       d
   RV,           pVP                  R4      ^,          ^8H  p	V	'       d
   VR,          pT	pVP                  V4       KU  	  TpV# )a˜  Split ``text`` into <= ``limit``-char chunks on line, then hard, boundaries.
Chunks are fence-balanced: when a split lands inside a ``` code span that survived into section
text (the renderer normally routes fenced blocks to ``rich_text_preformatted``, but mrkdwn text
can still carry fences), the fence is closed at the end of the chunk and reopened on the next so
each section renders correctly on its own.z```rˆ   NFz```
z
```)ru   rÕ   Úrfindr,   r  Úcount)
r"   r  Úsplit_limitÚoutÚ	remainingÚcutÚbalancedÚreopenrþ   Úodds
   &&        r   rû   rû   å  s  € ô ˆ4ƒy�EÔØˆvˆà38¸D´=”#�e˜a•i ¨!¥¨QÔ/Àe€KØ€CØ€IÜ
ˆi‹.˜;Ô
&Ø�o‰o˜d A {Ó3ˆØ�!Œ8ØˆCØ�
‰
�9˜T˜c�?Ô#Ø˜d�O×*Ñ*¨4Ó0Š	ßØ�
‰
�9ÔÜ
ˆ3ƒx�!„|˜ œØ ˆØˆÛˆEßØ %��Ø—+‘+˜eÓ$ qÕ(¨AÑ-ˆCßØ˜Õ �ØˆFØ�O‰O˜EÖ"ñ ð ˆØ€Jr   c               ó$   € V ^8„  d   QhRRRRRR/# )r	   Útext_objr½   r  r   r   r   )r   s   "r   r   r     s!   € ÷ ñ ˜nð °Sð ¸^ñ r   c                ó¾   € V P                  R4      ;'       g    Rp\        V4      V8:  d   V # \        V 4      pVRV^,
           P                  4       R,           VR&   V# )zAReturn ``text_obj`` with its ``text`` clamped to ``limit`` chars.r"   rm   Nrn   )rf   ru   rE   r‰   )r(  r  r  Úclampeds   &&  r   Ú_clamp_text_objr+    sY   € à
�,‰,�vÓ
×
$Ð
$ "€CÜ
ˆ3ƒx�5ÔØˆÜ�8‹n€GØ˜+˜E A�IÐ&×-Ñ-Ó/°%Õ7€GˆF�OØ€Nr   c               ó    € V ^8„  d   QhRRRR/# )r	   rÿ   rò   r   r   )r   s   "r   r   r     s    € ÷ Vñ VÐ1ð VÐ6Kñ Vr   c                óÈ  € V '       g   R#  . pV  EF   p\        V\        4      '       d   VP                  R4      '       g   K3  VR,          pVR8X  dÐ   VP                  R4      p\        VP                  R4      4      ;'       g    \        VP                  R4      4      p\        V\        4      '       d`   VP                  R4      ;'       g    RP	                  4       '       g   V'       g   Kß  \        V\        4      pWdJd   \        V4      pWbR&   EMŠV'       g   EK  EM}VR8X  d€   VP                  R4      p\        V\        4      '       d0   VP                  R4      ;'       g    RP	                  4       '       g   EKr  \        V\        4      pWdJd   \        V4      pWbR&   EM÷VR	8X  dÑ   VP                  R
4      ;'       g    . pV'       g   EKÅ  V Uu. uFA  p\        V\        4      '       d'   VP                  R4      R9   d   \        V\        4      MTNKC  	  p	p\        ;QJ d%    R \        W—4       4       F  '       g   K   RM	  RM! R \        W—4       4       4      '       d   \        V4      pW’R
&   EM VR9   d   VP                  R
4      '       g   EK�  MþVR8X  dø   VP                  R4      '       g   EK²  VP                  R4      p
\        V
\        4      '       d·   \        ;QJ d    R V
 4       F  '       g   K   RM	  RM! R V
 4       4      '       d}   V
 Uu. uF  p\        V\        4      '       d   TM/ NK  	  ppV'       d"   VR,          '       g   VP                  4        K)  \        V4      pV'       d   WÂR&   MVP                  RR4       VP                  V4       EK£  	  V'       g   R# VR\         # u upi u upi   \         d     R# i ; i)u  Clamp an outbound ``blocks`` payload to Slack's hard limits.
Defensive boundary applied wherever the adapter attaches ``blocks`` to
``chat.postMessage`` / ``chat.update``.  One oversized or malformed block
fails the WHOLE call with ``invalid_blocks`` â€” approval cards then never
update and messages silently drop â€” so instead of trusting every builder,
the payload is normalized just before the API call:

* ``section`` / ``context`` text objects are truncated to the 3000-char
  cap with an ellipsis (Slack HTML-escapes ``< > &`` on storage, so text
  echoed back through interaction payloads can exceed the limit that the
  send path originally budgeted for â€” see #53693 / #62054).
* ``header`` text is truncated to its 150-char cap.
* Empty blocks (no text / no elements / no rows) are dropped â€” Slack
  rejects zero-length text objects and empty element lists.
* ``table.column_settings`` entries must all be objects; ``null`` entries
  (emitted by older renderers, per the "use null to skip" misreading of
  the schema) are replaced with ``{}`` and default trailing entries are
  trimmed (#56615).
* The payload is capped at Slack's 50-block maximum.

Returns the sanitized list, or ``None`` when nothing valid remains â€” the
caller then sends the plain ``text`` fallback alone.  Never raises.Nr+   r¤   r"   ÚfieldsÚ	accessoryrm   ro   Úcontextr.   c              3  ó,   "  € T F
  w  rWJx € K  	  R # 5ira   r   )rÆ   r´   rg   s   &  r   rÈ   Ú"sanitize_blocks.<locals>.<genexpr>T  s   é € ÐIÑ.H¡d a�q•zÓ.Hùs   ‚TFrÒ   rÁ   rÓ   c              3  óL   "  € T F  p\        V\        4      '       * x € K  	  R # 5ira   )Ú
isinstancerE   )rÆ   Úcss   & r   rÈ   r2  ^  s    é € Ð5bÑYaÐSU¼*ÀRÌÓ:N×6NÑ6NÓYaùs   ‚"$)r¥   rp   )r‚   ÚactionsÚcontext_actionsrÔ   )r4  rE   rf   r   rt   r+  rü   rv   ÚanyÚzipÚlistÚpopr,   r
  r  )rÿ   r!  rà   Úbtyper(  Úhas_bodyr*  r.   r-   Úclamped_elsÚsettingsr5  Úfixeds   &            r   Úsanitize_blocksrA    s  € ÷. Ùð=ØˆÜˆEÜ˜e¤T×*Ò*°%·)±)¸F×2CÒ2CÙØ˜&•MˆEà˜	Ô!Ø Ÿ9™9 VÓ,�Ü §	¡	¨(Ó 3Ó4×TÐT¼¸U¿Y¹YÀ{Ó=SÓ8T�Ü˜h¬×-Ò-Ø$ŸL™L¨Ó0×6Ð6°B×=Ñ=×?Ò?ÏÙ Ü-¨hÔ8HÓI�GØÓ.Ü $ U£˜Ø(/˜f™ùß!Úñ "à˜(Ô"Ø Ÿ9™9 VÓ,�Ü! (¬D×1Ò1¸(¿,¹,ÀvÓ:N×:TÐ:TÐRT×9[Ñ9[×9]Ò9]ÚÜ)¨(´OÓD�ØÓ*Ü  ›K�EØ$+˜&‘MùØ˜)Ô#Ø Ÿ9™9 ZÓ0×6Ð6°B�ßÚñ
 'ó	(ñ '˜ô " "¤d×+Ò+°·±°v³ÐBZÔ0Zô $ BÔ(8Ô9àòñ 'ð	 ð (÷
 “3ÑI¬c°+Ô.HÓI—3—3’3ÑI¬c°+Ô.HÓI×IÒIÜ  ›K�EØ(3˜*Ñ%ùØÐEÔEØ—y‘y ×,Ò,Úð -à˜'Ô!Ø—y‘y ×(Ò(ÚØ Ÿ9™9Ð%6Ó7�Ü˜h¬×-Ò-·#³#Ñ5bÑYaÓ5b·#·#²#Ñ5bÑYaÓ5b×2bÒ2bÙJRÓSÉ(ÀB¤:¨b´$×#7Ò#7™R¸RÒ?É(�EÐSß¨¨b¯	¬	ØŸ	™	žÜ  ›K�EßØ38Ð/Ò0àŸ	™	Ð"3°TÔ:Ø�J‰J�u×ñk ÷l ÙØ�;”JÐÐùò7(ùò  Tøô ô âðús§   Œ4O ÁAO ÂAO ÃO Ã%O Ã-/O ÄA
O Å(O Å?AO Ç
O ÇO ÇAOÈ 'O É
#O É..O Ê!O Ê?4O Ë4O ÌO Ì#O Ì'#OÍ
	O ÍA(O Î?O Ï
O ÏO!Ï O!ra   )5Ú__doc__Ú
__future__r   rr   Útypingr   r   r   r   r   r
  rü   rv   rÖ   r×   rÙ   rE   r   rz   Úcompiler  r  r  r   r   r	  r  r   r    r7   rL   rQ   rY   r[   rZ   rb   ri   rx   r}   rƒ   r‹   r–   r¡   r¦   rµ   r»   r¿   rá   rï   r  rû   r+  rA  r   r   r   Ú<module>rF     s„  ðñõ8 #ã 	ß 3Õ 3ð €
ØÐ Ø€à€Ø€Ø€àˆS�#ˆX�€ð 
�ŠÐ7Ó	8€Ø�ZŠZÐ<Ó=€
Ø�JŠJÐ0Ó1€	Ø�jŠjÐ3Ó4€Ø�ZŠZÐ.Ó/€
Ø�JŠJÐ+Ó,€	Ø—
’
ÐOÓP€õCõ
ð —*’*˜\Ó*€Ø�:Š:ÐPÓQ€ð —’Ø8ó€ð �:Š:Ð4Ó5€Ø�ZŠZÐZÓ[€
Ø�ZŠZ˜Ó%€
õ@8õP
2õ
\õõeõeõ
Aõ7õ*IõõRõIõõB ÷._õD õP÷Vr   