Ë
    ãß²j7  ã                  óô   — U d Z ddlmZ ddlZddlmZmZmZ ddlm	Z	m
Z
 ddlmZ  G d„ de«      Zi Zd	ed
<    ej"                  «       Zdd„Zdd„Zdd„Zddœdd„Zddœdd„Zddœdd„Zddœdd„Zdd„Zdd„Zy)a²  Live operations, one open per (profile, session), found by ``op_id``. The RPC layer reads and
drives operations through here; the tool thread that minted one closes it on settle.

The profile is part of the key: two multiplexed profiles can carry the same timestamp-based
session key, and each side (the tool thread under the turn's profile override, the RPC under the
session's profile scope) resolves it through ``hermes_home_key``.é    )ÚannotationsN)ÚDictÚOptionalÚTuple)Úget_process_hermes_homeÚhermes_home_key)ÚConnectionOperationc                  ó    ‡ — e Zd Zdˆ fd„Zˆ xZS )ÚOperationAlreadyOpenc                óh   •— t         ‰| �  d|j                  ›d|j                  › d�«       || _        y )Nzsession z already has operation z open)ÚsuperÚ__init__Úsession_keyÚop_idÚexisting)Úselfr   Ú	__class__s     €ú:/home/ubuntu/.hermes/hermes-agent/tools/connectors/live.pyr   zOperationAlreadyOpen.__init__   s7   ø€ Ü‰Ñ˜8 H×$8Ñ$8Ð#;Ð;RÐS[×SaÑSaÐRbÐbgÐhÔiØ ˆ�ó    )r   r	   )Ú__name__Ú
__module__Ú__qualname__r   Ú__classcell__)r   s   @r   r   r      s   ø„ ÷!ñ !r   r   z*Dict[Tuple[str, str], ConnectionOperation]Ú_openc                ó0   — t        | xs
 t        «       «      S )z»A session record names its profile home only for a non-default profile; the tool thread sees
    the same home through its turn override, and the default profile through the process home.)r   r   ©Úprofile_homes    r   Ú_profile_keyr      s   € ô ˜<ÒDÔ+BÓ+DÓEÐEr   c                ó   — t        |«      | fS ©N)r   )r   r   s     r   Ú_keyr!   !   s   € Ü˜Ó% {Ð2Ð2r   c                óö   — t        «       | _        | j                  | j                  f}t        5  t        j                  |«      }|�|j                  st        |«      ‚| t        |<   d d d «       y # 1 sw Y   y xY wr    )r   Úprofile_keyr   Ú_lockr   ÚgetÚsettledr   )Ú	operationÚkeyr   s      r   Úopenr)   %   sj   € Ü+Ó-€IÔØ× Ñ  )×"7Ñ"7Ð
8€CÜ	ñ Ü—9‘9˜S“>ˆØÐ¨×(8Ò(8Ü& xÓ0Ð0ØŒˆc‰
÷	÷ ñ ús   ®8A/Á/A8r   c               óš   — t         5  t        j                  t        | |«      «      }d d d «       �|j                  s|S d S # 1 sw Y   ŒxY wr    )r$   r   r%   r!   r&   )r   r   r'   s      r   Úcurrentr+   /   sG   € Ü	ñ ?Ü—I‘Iœd ;°Ó=Ó>ˆ	÷?à!Ð-°i×6GÒ6Gˆ9ÐQÈTÐQ÷?ð ?ús   ‡ AÁA
c               ó    — t         5  t        j                  t        | |«      «      }d d d «       �|j                  |k(  r|S d S # 1 sw Y   ŒxY wr    )r$   r   r%   r!   r   )r   r   r   r'   s       r   r%   r%   5   sK   € Ü	ñ ?Ü—I‘Iœd ;°Ó=Ó>ˆ	÷?à!Ð-°)·/±/ÀUÒ2Jˆ9ÐTÐPTÐT÷?ð ?ús   ‡ AÁAc               ó¤   ‡ ‡— t        |«      Št        5  t        ˆ ˆfd„t        j	                  «       D «       d «      cd d d «       S # 1 sw Y   y xY w)Nc              3  ón   •K  — | ],  \  \  }}}|‰k(  r|j                   ‰k(  r|j                  s|–— Œ. y ­wr    )r   r&   )Ú.0r(   Ú_r'   r   r#   s       €€r   ú	<genexpr>zget_by_op_id.<locals>.<genexpr>>   s?   øè ø€ ò cÑ#6¡8 C¨¨YØ˜{Ò*¨y¯©À%Ò/GÐPY×PaÒPaô ñ cùs   ƒ25©r   r$   Únextr   Úitems)r   r   r#   s   ` @r   Úget_by_op_idr5   ;   sI   ù€ Ü˜|Ó,€KÜ	ñ jÜô c¼%¿+¹+»-ô cØdhój÷j÷ jò jús   ”(AÁAc               ó¨   ‡ ‡‡— t        |«      Št        5  t        ˆ ˆˆfd„t        j	                  «       D «       d «      cd d d «       S # 1 sw Y   y xY w)Nc              3  ó”   •K  — | ]?  \  \  }}}|‰k(  r2|j                   s&|j                  ‰«      xŠ�‰j                  dk(  r|–— ŒA y ­w)NÚ	connector)r&   ÚtargetÚkind)r/   r(   r0   r'   Únamer#   r9   s       €€€r   r1   zfind_target.<locals>.<genexpr>E   sU   øè ø€ ò hÑ#6¡8 C¨¨YØ˜{Ò*°9×3DÒ3DØ$-×$4Ñ$4°TÓ$:Ð:˜&ÐGÈFÏKÉKÐ[fÒLfô ñ hùs   ƒAAr2   )r;   r   r#   r9   s   ` @@r   Úfind_targetr<   B   sI   ú€ Ü˜|Ó,€KÜ	ñ oÜõ h¼%¿+¹+»-ô hàimóo÷o÷ oò oús   •)AÁAc                ó¦   — | j                   | j                  f}t        5  t        j	                  |«      | u rt        |= d d d «       y # 1 sw Y   y xY wr    )r#   r   r$   r   r%   )r'   r(   s     r   Úcloser>   J   sG   € Ø× Ñ  )×"7Ñ"7Ð
8€CÜ	ñ Ü�9‰9�S‹>˜YÑ&Ü�c�
÷÷ ñ ús   ŸAÁAc                 ób   — t         5  t        j                  «        d d d «       y # 1 sw Y   y xY wr    )r$   r   Úclear© r   r   Úreset_for_testsrB   Q   s#   € Ü	ñ Ü�‰Œ÷÷ ñ ús   ‡%¥.)r   úOptional[str]ÚreturnÚstr)r   rE   r   rC   rD   zTuple[str, str])r'   r	   rD   ÚNone)r   rE   r   rC   rD   úOptional[ConnectionOperation])r   rE   r   rE   r   rC   rD   rG   )r   rE   r   rC   rD   rG   )r;   rE   r   rC   rD   rG   )rD   rF   )Ú__doc__Ú
__future__r   Ú	threadingÚtypingr   r   r   Úhermes_constantsr   r   Útools.connectors.operationr	   ÚRuntimeErrorr   r   Ú__annotations__ÚLockr$   r   r!   r)   r+   r%   r5   r<   r>   rB   rA   r   r   ú<module>rQ      s’   ðòEõ #ã ß (Ñ (ç EÝ :ô!˜<ô !ð 57€Ð1Ó 6Øˆ	�‰Ó€óFó3óð @Dõ Rð HLõ Uð ?Cõ jð =Aõ oóôr   