+
    lHàjÞ  ã                  ó|   € R t ^ RIHt ^ RIt^RIHt ]! 4       tRsRR/R R llt	RR	 R
 llt
RR R lltR R ltR# )aó  Ink TUI / desktop host for ``PluginContext.inject_message``.

Separate from ``PluginManager.set_gateway_message_injector``. A messaging gateway
and this process can both be live; they must not share one slot (last writer
would win). Routing uses the reported ``session_key``, not the ephemeral UI
session id, and lands on that session's prompt queue.

Bodies are rebound onto ``server.py`` globals at install time
(``method_ctx.bind_module``), so ``_sessions`` and the queue helpers are bare names.
)ÚannotationsN)Úbind_moduleFÚ	plugin_idÚ c               ó(   € V ^8„  d   QhRRRRRRRR/# )é   Úsession_keyÚstrÚcontentr   ÚreturnÚbool© )Úformats   "Ú>/home/ubuntu/.hermes/hermes-agent/tui_gateway/plugin_inject.pyÚ__annotate__r      s)   € ÷ *ñ *¨sð *¸Sð *ÈSð *ÐZ^ñ *ó    c           	     ól  a € ?\        S \        4      '       d	   S '       g   R# \        V\        4      '       d   VP                  4       '       g   R# \        ;_uu_ 4        \	        V 3R l\        \        P                  4       4       4       R4      pRRR4       Xf   R# Vw  rEVP                  R4      '       g/   VP                  R4      '       g   VP                  R4      '       d   R# VP                  R4      f   R# VR,          ;_uu_ 4        VP                  R4      ;'       g    / p\        V\        4      '       d   VP                  R	4      MRp\        VP                  R
4      4      p\        WQV4       \        P                  4       VR&   V'       d    RRR4       R#  RRR4       R\        P                  4       P                  R,           2p	\         P#                  \$        W”V3RRVR,           2R7      P'                  4        R#   + '       g   i     EL‡; i  + '       g   i     L…; i)a_  Queue *content* on the live session whose ``session_key`` matches.

Returns False when this process has no such session, so the caller can fall
through to the messaging-gateway slot. Never reroutes to a different session.
A busy session only queues (a notice must not cancel in-flight work). An idle
session drains so the queued prompt starts a turn.
Fc              3  óŽ   <"  € T F:  w  r\        V\        4      '       g   K  VP                  R 4      S8X  g   K5  W3x € K<  	  R# 5i)r   N)Ú
isinstanceÚdictÚget)Ú.0ÚsidÚsessionr   s   &  €r   Ú	<genexpr>Ú-inject_tui_session_message.<locals>.<genexpr>'   s>   øé € ð á$;‘L�CÜ˜g¤t×,ô à18·±¸]Ó1KÈ{Ñ1Zô �•Û$;ùs   ƒA¢AºANÚlazyÚ_closingÚ
_finalizedÚhistory_lockÚqueued_promptÚ	transportÚrunningÚlast_activeTzinject-:Né   Nztui-inject-)ÚtargetÚargsÚdaemonÚname)r   r	   ÚstripÚ_sessions_lockÚnextÚlistÚ	_sessionsÚitemsr   r   r   Ú_enqueue_promptÚtimeÚuuidÚuuid4ÚhexÚ	threadingÚThreadÚ_drain_queued_promptÚstart)
r   r
   r   Úmatchr   r   ÚqueuedÚkeep_transportr"   Úrids
   d$$       r   Úinject_tui_session_messager<      s¦  ø€ ð 	Ü�k¤3×'Ò'¯{ÙÜ�gœs×#Ò#¨7¯=©=¯?ª?Ùß	ŽÜôä$(¬¯©Ó):Ô$;óð
 ó
ˆ÷ 
ð ‚}ÙØ�L€CØ‡{�{�6×Ò˜gŸk™k¨*×5Ò5¸¿¹À\×9RÒ9RÙØ‡{�{�>Ó"Ò*ÙØ	�×	 ×	 Ø—‘˜_Ó-×3Ð3°ˆÜ4>¸vÄt×4LÒ4L˜Ÿ™ KÔ0ÐRVˆÜ�w—{‘{ 9Ó-Ó.ˆÜ˜¨.Ô9Ü!%§¡£ˆ�ÑßØ÷ 
!Ñ	 ð ÷ 
!ð ”D—J‘J“L×$Ñ$ RÕ(Ð)Ð
*€CÜ×ÑÜ#¨3°WÐ*=Ø˜K¨¨B­ yÐ1ð ó ÷ �e„gÙ÷; 
�ˆú÷  
!×	 ús   Á2HÄBH#ÈH 	È#H3	c               ó   € V ^8„  d   QhRR/# ©r   r   ÚNoner   )r   s   "r   r   r   E   s   € ÷ Tñ T°$ñ Tr   c                óÒ   € ^ RI HpHp V fA   V! \        \        4       V! 4       p \
        '       g   \        P                  ! \        4       RsV P                  \        \        4       R# )aI  Publish this process's TUI host on *manager*, or the active profile's manager.

Passing a manager (tests) does not publish process-wide. The no-arg form is
the Ink TUI / desktop startup path: every profile manager in this process
gets the host, and managers created later pick it up, without touching the
messaging-gateway slot.
)Úget_plugin_managerÚpublish_tui_message_hostNT)
Úhermes_cli.pluginsrA   rB   Ú_TUI_INJECT_OWNERr<   Ú_atexit_registeredÚatexitÚregisterÚclear_tui_message_injectorÚset_tui_message_injector)ÚmanagerrA   rB   s   &  r   Úinstall_tui_message_injectorrK   E   sN   € ÷ Pð ‚Ù Ô!2Ô4NÔOÙ$Ó&ˆß!Ó!Ü�OŠOÔ6Ô7Ø!%ÐØ×$Ñ$Ô%6Ô8RÖSr   c               ó   € V ^8„  d   QhRR/# r>   r   )r   s   "r   r   r   Y   s   € ÷ :ñ :°ñ :r   c                ón   € ^ RI HpHp V f   V! \        4       V! 4       p V P	                  \        4       R# )z=Drop this process's host. A different owner is left in place.)Ú clear_published_tui_message_hostrA   N)rC   rN   rA   rD   rH   )rJ   rN   rA   s   &  r   rH   rH   Y   s*   € çWà‚Ù(Ô):Ô;Ù$Ó&ˆØ×&Ñ&Ô'8Ö9r   c               ó   € V ^8„  d   QhRR/# r>   r   )r   s   "r   r   r   c   s   € ÷ 0ñ 0˜ñ 0r   c                ó2   € \        \        4       V RR7       R# )zFPublish this module's helpers onto ``server``, rebound to its globals.)ÚskipN)Ú_)r   Úglobals)Úservers   &r   rG   rG   c   s   € ä”“	˜6¨×/r   )N)Ú__doc__Ú
__future__r   rF   Ú
method_ctxr   ÚobjectrD   rE   r<   rK   rH   rG   r   r   r   Ú<module>rY      sC   ðñ	õ #ã å #ñ “HÐ ØÐ ð*ÐSU÷ *÷ZT÷(:÷0r   