§
    øžyjs  ã                   óÈ   — d Z ddlZddlmZ ddlmZ ddlmZmZ ddl	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S )u·  Let the agent react to a message with an emoji in the Hermes desktop app.

The conversational counterpart to the user's tapback: the same reaction store,
the same one-per-author semantics, just written with ``author="agent"``.

Lives in the ``desktop_ui`` toolset (like the other GUI affordances) so it costs
nothing on every other surface â€” the platform adapters already expose reactions
through ``send_message(action="react")``, and this is the desktop's equivalent.

Defaults to the message that triggered this turn (the photon precedent: the
model shouldn't have to thread row ids through tool calls), and emits
``message.reaction`` so the renderer paints it without waiting for a resume.
é    N)Úget_session_env)Ú
desktop_ui)ÚregistryÚ
tool_error)Úenv_var_enabledc                  óF   — 	 ddl m}   | ¦   «         S # t          $ r Y dS w xY w)zAOpen the SessionDB for the profile owning this turn, or ``None``.r   ©Ú	SessionDBN)Úhermes_stater
   Ú	Exceptionr	   s    úA/home/ragecks/.hermes/hermes-agent/tools/react_to_message_tool.pyÚ_open_session_dbr      sG   € ðØ*Ð*Ð*Ð*Ð*Ð*àˆy‰{Œ{ÐøÝð ð ð Øˆtˆtðøøøs   ‚ ’
 Ÿ ÚemojiÚreturnc                 óX  — | pd                      ¦   «         } t          dd¦  «        pt          dd¦  «        }|st          d¦  «        S t          ¦   «         }|€t          d¦  «        S |}d}|€Qt	          dt          |pd¦  «        ¦  «        }|                     |d|¬	¦  «        }|€t          |rd
|› d�nd¦  «        S n'|                     |t          |¦  «        ¦  «        }|pd}	 |                     |t          |¦  «        | pdd¬¦  «        }	n)# t          $ r}
t          d|
› �¦  «        cY d}
~
S d}
~
ww xY w|	€t          d|› d�¦  «        S 	 t          j        dt          |¦  «        |	|dœ¦  «         n# t          $ r Y nw xY wt          j        dt          |¦  «        |	dœd¬¦  «        S )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.Ú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Úget_message_roleÚset_message_reactionr   r   ÚemitÚjsonÚdumps)r   Úmessage_row_idÚmessages_backÚsession_keyÚdbr   Útarget_roleÚbackÚrowr   Úexcs              r   Úreact_to_message_toolr/   "   sD  € àˆ[�b×ÒÑ!Ô!€EÝ!Ð"6¸Ñ;Ô;ð ½Ø˜Rñ@ô @€Kð ð \ÝÐZÑ[Ô[Ð[å	Ñ	Ô	€BØ	€zÝÐ;Ñ<Ô<Ð<à€FØ€KØ€~õ
 �1•c˜-Ð,¨1Ñ-Ô-Ñ.Ô.ˆØ×)Ò)¨+¸FÈ4Ð)ÑPÔPˆØˆ>ÝØ9=ÐeÐ5¨Ð5Ð5Ð5Ð5ÐCeñô ð ð ð
 ×!Ò! +­s°6©{¬{Ñ;Ô;ˆØ�m˜Vˆð@Ø×+Ò+Ø�˜V™œ e m¨t¸Gð ,ñ 
ô 
ˆ	ˆ	øõ ð @ð @ð @ÝÐ>¸Ð>Ð>Ñ?Ô?Ð?Ð?Ð?Ð?Ð?Ð?øøøøð@øøøð ÐÝÐO VÐOÐOÐOÑPÔPÐPðÝŒØÝ˜6‘{”{°ÀKÐPÐPñ	
ô 	
ð 	
ð 	
øõ ð ð ð Øˆðøøøõ Œ:Ø¥C¨¡K¤K¸iÐHÐHÐW\ðñ ô ð s0   Ã&(D Ä
D5ÄD0Ä*D5Ä0D5Å&E5 Å5
FÆFc                  óÞ   — 	 ddl m}   | ¦   «                              d¦  «        }n# t          $ r Y dS w xY wt	          |t
          ¦  «        o"t          |                     dd¦  «        ¦  «        S )uƒ  Opt-in feature flag â€” surface eligibility is the toolset's job.

    ``desktop_ui`` already restricts this to GUI sessions. What's left is the
    user's own toggle (Settings â†’ Appearance), which the desktop mirrors into
    ``display.message_reactions`` on the CONNECTED gateway's config â€” so this
    reads the right config whether that gateway is local, SSH, URL, or cloud.
    r   )Úload_config_readonlyÚdisplayFÚmessage_reactions)Úhermes_cli.configr1   Úgetr   Ú
isinstanceÚdictÚbool)r1   r2   s     r   Úcheck_react_requirementsr9   \   s…   € ðØ:Ð:Ð:Ð:Ð:Ð:à&Ð&Ñ(Ô(×,Ò,¨YÑ7Ô7ˆˆøÝð ð ð Øˆuˆuðøøøå�g�tÑ$Ô$ÐV­¨g¯kªkÐ:MÈuÑ.UÔ.UÑ)VÔ)VÐVs   ‚#& ¦
4³4Ú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                 óš   — t          |                      dd¦  «        |                      d¦  «        |                      d¦  «        ¬¦  «        S )Nr   r   r'   r(   r@   )r/   r5   )ÚargsÚkws     r   ú<lambda>rH   Ÿ   sF   € Õ4Ø�hŠh�w Ñ#Ô#Ø—x’xÐ 0Ñ1Ô1Ø—h’h˜Ñ/Ô/ð ñ  ô  € ó    u   ðŸ’›)rC   ÚtoolsetÚschemaÚhandlerÚcheck_fnr   )NN)Ú__doc__r%   Úgateway.session_contextr   Útoolsr   Útools.registryr   r   Úutilsr   r   Ústrr/   r8   r9   ÚREACT_TO_MESSAGE_SCHEMAÚregister© rI   r   ú<module>rW      sy  ððð ð €€€à 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø Ð Ð Ð Ð Ð Ø /Ð /Ð /Ð /Ð /Ð /Ð /Ð /Ø !Ð !Ð !Ð !Ð !Ð !ðð ð ð7ð 7 ð 7ÐRUð 7ð 7ð 7ð 7ðtW $ð Wð Wð Wð Wð$ ð
	ð ð !ð6ðð ð "ðSðð ð "ðFðð ð
ð 
ð0 �Ið5ð ð+ð +Ð ð\ €Ô Ø	ØØ"ðð ð
 &Ø
ðñ ô ð ð ð rI   