Ë
    ãß²jÀ  ã                   óÔ   — d Z ddlZddlZddlmZ ddlmZ ddlmZm	Z	 d„ Z
ddedefd	„Zdefd
„ZddddddœdddœdddœdœdgdœdœZ ej                   dded„ ed¬«       ddiZd„ Zy)a`  Agent emoji reaction in the Hermes desktop app: the counterpart to the user's tapback
(same store, one-per-author, ``author="agent"``). Lives in the ``desktop_ui`` toolset so it
costs nothing elsewhere (adapters expose reactions via ``send_message(action="react")``);
defaults to the triggering message and emits ``message.reaction`` for live painting.é    N)Úget_session_env)Ú
desktop_ui)ÚregistryÚ
tool_errorc                  ó<   — 	 ddl m}   | «       S # t        $ r Y yw xY w)zAOpen the SessionDB for the profile owning this turn, or ``None``.r   ©ÚacquireN)Úhermes_state_registryr	   Ú	Exceptionr   s    ú@/home/ubuntu/.hermes/hermes-agent/tools/react_to_message_tool.pyÚ_open_session_dbr      s$   € ðÝ1Ù‹yÐøÜò Ùðús   ‚ �	šÚemojiÚreturnc                 ór  — | xs dj                  «       } t        dd«      xs t        dd«      }|st        d«      S t        «       }|€t        d«      S 	 |d}}|€rt	        dt        |xs d«      «      }|j                  |d|¬	«      }|€bt        |rd
|› d�nd«      t        j                  t        «      5  ddl
m}  ||«       ddd«       S |j                  |t        |«      «      xs d}	 |j                  |t        |«      | xs dd¬«      }	|	€?t        d|› d�«      t        j                  t        «      5  ddl
m}  ||«       ddd«       S t        j                  t        «      5  t        j                  dt        |«      |	|dœ«       ddd«       t!        j"                  dt        |«      |	dœd¬«      t        j                  t        «      5  ddl
m}  ||«       ddd«       S # 1 sw Y   S xY w# t        $ rT}
t        d|
› �«      cY d}
~
t        j                  t        «      5  ddl
m}  ||«       ddd«       S # 1 sw Y   S xY wd}
~
ww xY w# 1 sw Y   S xY w# 1 sw Y   ŒÕxY w# 1 sw Y   S xY w# t        j                  t        «      5  ddl
m}  ||«       ddd«       w # 1 sw Y   w xY wxY w)zAAttach (or with an empty ``emoji`` retract) the agent's reaction.Ú ÚHERMES_SESSION_KEYÚHERMES_SESSION_IDu>   No active session â€” reactions need a persisted conversation.NzSession storage is unavailable.Úuserr   )ÚroleÚoffsetzNo user message found z back.z No user message to react to yet.)Úrelease_or_closeÚagent)ÚauthorzFailed to set the reaction: zMessage z" is not part of this conversation.zmessage.reaction)Úrow_idÚ	reactionsr   T)Úsuccessr   r   F)Úensure_ascii)Ústripr   r   r   ÚmaxÚintÚlatest_message_row_idÚ
contextlibÚsuppressr   r
   r   Úget_message_roleÚset_message_reactionr   ÚemitÚjsonÚdumps)r   Úmessage_row_idÚmessages_backÚsession_keyÚdbr   Útarget_roleÚbackr   r   Úexcs              r   Úreact_to_message_toolr0      s�  € àŠ[�b×ÑÓ!€EÜ!Ð"6¸Ó;Òg¼ÐObÐdfÓ?g€KÙÜÐZÓ[Ð[Ü	Ó	€BØ	€zÜÐ;Ó<Ð<ð!Ø,¨f�ˆØˆ>ô �qœ#˜mÒ0¨qÓ1Ó2ˆDØ×-Ñ-¨kÀÈtÐ-ÓTˆFØˆ~Ü!É4Ð$:¸4¸&ÀÑ"GÐUwÓxô × Ñ ¤Ó+ñ 	!Ý>Ù˜RÔ ÷	!ð 	!ð ×-Ñ-¨k¼3¸v»;ÓGÒQÈ6ˆKð	DØ×/Ñ/°¼SÀ»[È%Ê-ÐSWÐ`gÐ/ÓhˆIð ÐÜ ¨¨Ð0RÐSÓTô × Ñ ¤Ó+ñ 	!Ý>Ù˜RÔ ÷	!ð 	!ô	 × Ñ ¤Ó+ñ 	vÜ�O‰OÐ.¼3¸v»;ÐU^ÐhsÑ0tÔu÷	vä�z‰z d´c¸&³kÐPYÑZÐinÔoä× Ñ ¤Ó+ñ 	!Ý>Ù˜RÔ ÷	!÷ 	!ñ 	!ûô ò 	DÜÐ <¸S¸EÐBÓCÔCô × Ñ ¤Ó+ñ 	!Ý>Ù˜RÔ ÷	!÷ 	!ñ 	!þð	Dú÷	!ð 	!ú÷		vð 	vú÷	!ð 	!ûŒZ× Ñ ¤Ó+ñ 	!Ý>Ù˜RÔ ÷	!÷ 	!ñ 	!ýs©   ÁAI8 Â4G(ÃI8 Ã,"G4 ÄI8 Ä7IÅI8 Å($I Æ+I8 ÇI,Ç(G1	Ç4	IÇ=IÈ
IÈI8 È(I É I		ÉIÉI8 ÉI	É I)É%I8 É,I5	É8J6ÊJ*Ê!	J6Ê*J3Ê/J6c                  ó0   — t        j                  dd¬«      S )uX   Opt-in flag (Settings â†’ Appearance); ``desktop_ui`` already restricts to GUI sessions.Úmessage_reactionsF)Údefault)r   Úuser_enabled© ó    r   Úcheck_react_requirementsr7   =   s   € ä×"Ñ"Ð#6ÀÔFÐFr6   Úreact_to_messageu  React to a message with a single emoji, the way you'd tapback in iMessage. Reach for it when a reaction is what a person would do: something funny gets a ðŸ˜‚, warmth gets a â�¤ï¸�, a plan you're on board with gets a ðŸ‘� â€” then just carry on with whatever the message actually needs. If a reaction says it all, it can BE the reply (skip the redundant 'sounds good!' turn). Use it like a person would: occasionally, when felt â€” not on every message, and never as a status signal. NEVER narrate or explain a reaction ('I reacted with...', 'Reacting now') â€” the emoji appearing on the bubble is the whole point, and commentary kills it. Defaults to the user's most recent message. One reaction per message: a different emoji replaces yours, an empty string retracts it.ÚobjectÚstringuf   The emoji to react with (e.g. 'â�¤ï¸�', 'ðŸ˜‚', 'ðŸ‘�'). Pass an empty string to remove your reaction.)ÚtypeÚdescriptionÚintegerz}Optional. The specific message to react to. Omit to react to the user's latest message, which is almost always what you want.u®   Optional. React to an EARLIER user message: 1 = the one before the latest, 2 = two before, and so on. For when something lands late â€” the joke you only got after answering.©r   r)   r*   )r;   Ú
propertiesÚrequired)Únamer<   Ú
parametersr   c                 óz   — t        | j                  dd«      | j                  d«      | j                  d«      ¬«      S )Nr   r   r)   r*   r>   )r0   Úget)ÚargsÚkws     r   ú<lambda>rG   r   s2   € Ô4Ø�h‰h�w Ó#°D·H±HÐ=MÓ4NØ—h‘h˜Ó/ô 1€ r6   u   ðŸ’›)rA   ÚtoolsetÚschemaÚhandlerÚcheck_fnr   Úenv_var_enabled)ÚutilsrL   c                 óÌ   — t         j                  | «      }|€t        dt        ›d| ›�«      ‚dd l}ddlm}  |t        | g|¢­Ž  t        |j                  |d   «      |d   «      S )Nzmodule z has no attribute r   )Ú	warn_onceé   )	Ú_PLUGIN_COMPAT_LAZYrD   ÚAttributeErrorÚ__name__Ú	importlibÚhermes_cli.plugin_compatrO   ÚgetattrÚimport_module)rA   ÚtargetrT   rO   s       r   Ú__getattr__rY   „   se   € Ü ×$Ñ$ TÓ*€FØ€~Ü˜w¤x lÐ2DÀTÀHÐMÓNÐNÛÝ2ÙŒh˜Ð&˜vÓ&Ü�9×*Ñ*¨6°!©9Ó5°v¸a±yÓAÐAr6   )NN)Ú__doc__r"   r'   Úgateway.session_contextr   Útoolsr   Útools.registryr   r   r   Ústrr0   Úboolr7   ÚREACT_TO_MESSAGE_SCHEMAÚregisterrQ   rY   r5   r6   r   ú<module>rb      sØ   ðñXó
 Û å 3Ý ß /òñ"! ð "!ÐRUó "!ðJG $ó Gð ð
	ð ð !ð6ñð "ðSñð "ðFññ
ð0 �Iñ5ñ+Ð ð\ €× Ñ Ø	 \Ð:Qñ1ð &¨Võð  Ð3ðÐ ó
Br6   