+
    lHàj  ã                  ót  € R t ^ RIHt ^ RIt^ RIt^ RIHt ^ RIHtH	t	H
t
HtHtHt ^ RIHt ^ RIHt ^ RIHtHt RtR	tR
tRtRtRtRtRt]	]]]3,          .]],          3,          t] ! R R4      4       t RR/R R llt!R R lt"R R lt#RRRR/R R llt$RR/R R llt%RR/R R  llt&R! R" lt'R# R$ lt(R# )%a3  The one lifecycle every ``manage_connections`` operation follows, whatever the target kind.

``run_operation`` mints the op, registers it in ``live``, lets the kind prepare its targets (a
managed mint, an MCP catalog check), emits the card through the session callback, then loops:
sleep on ``op.wake`` for at most one tick, run the kind's ``observe`` hook, settle when every
target is resolved or the deadline passes. ``connection.respond`` reaches the loop by transitioning
the op through ``live`` and setting ``wake``; ``/stop`` sets the thread interrupt flag.)ÚannotationsN)Ú	dataclass)ÚAnyÚCallableÚDictÚListÚOptionalÚSequence)Úlive)ÚSettleReason)ÚConnectionOperationÚTargetÚunknown_targetÚmixed_kindsÚlink_still_validÚsettledÚnot_allowedÚrefusedg      @g      Ð?c                  óH   € ] tR t^"t$ RtR]R&   R]R&   R]R&   RtR]R	&   R
tR# )ÚKindz´Per-kind hooks. ``prepare`` runs once before the card; ``observe`` runs every tick and may
transition targets; ``note`` is the model-facing guidance appended to the settled result.z%Callable[[ConnectionOperation], None]ÚprepareÚobserveÚstrÚnoteNz9Optional[Callable[[ConnectionOperation], dict[str, Any]]]Úresult© )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__r   Ú__static_attributes__r   ó    Ú9/home/ubuntu/.hermes/hermes-agent/tools/connectors/run.pyr   r   "   s&   ‡ ñað 3Ó2Ø2Ó2Ø
ƒIàHL€FÐE×Lr#   r   Ú	initiatorc               ó(   € V ^8„  d   QhRRRRRRRR/# )é   Ú	operationr   ÚnameszSequence[str]r%   úOptional[str]Úreturnr   )Úformats   "r$   Ú__annotate__r-   .   s+   € ÷ 8ñ 8Ð*ð 8°=ð 8ÐP]ð 8Ðivñ 8r#   c               ó,  aa€ ^ RI HpHoHo V Uu. uF  q@P	                  V4      NK  	  pp\
        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d   \        # \        V Uu0 uF  qfP                  kK  	  up4      ^8w  d   \        # V Uu. uF7  qfP                  SP                  SP                  39   g   K+  VP                  NK9  	  pp\        V4      \        V4      8w  d   \        # V P                  '       d   \         # \
        ;QJ d     VV3R lV 4       F  '       g   K   RM	  RM! VV3R lV 4       4      '       d   \"        # V^ ,          P                  R8X  dB   ^ RIHpHp	Hp
 T	! RT;'       g    TV P,                  R7      pV
! W°VRVP.                  R	7       R
# ^ RIHp ^ RIHp VP9                  V P:                  4      '       d   VP6                  MTpV! W4      '       d   \<        # R
# u upi u upi u upi )é    )ÚActorÚTargetStateÚallowedc              3  ó(   "  € T F  qR J x € K
  	  R # 5i©Nr   )Ú.0Útargets   & r$   Ú	<genexpr>Úreissue.<locals>.<genexpr>2   s   é € Ð
0©˜f�T�>«ùs   ‚TFc              3  óx   <"  € T F/  pS! VP                   VP                  SP                  4      R J x € K1  	  R # 5ir4   )ÚkindÚstateÚ	initiated)r5   r6   r1   r2   s   & €€r$   r7   r8   ;   s0   øé € Ð
cÑ[bÐQW‰7�6—;‘; §¡¨k×.CÑ.CÓDÈÕLÓ[bùs   ƒ7:Ú	connector)Ú
CARD_RETRYÚmanaged_clientÚmint)Úcreates_guestr%   Úcall)Ú
reinitiateÚactorN)Úcatalog)Úretry)Útools.connectors.contractr0   r1   r2   r6   ÚanyÚUNKNOWN_TARGETÚlenr:   ÚMIXED_KINDSr;   ÚfailedÚexpiredÚnameÚLINK_STILL_VALIDr   ÚSETTLEDÚNOT_ALLOWEDÚtools.connectors.managedr>   r?   r@   rB   ÚuserÚtools.connectorsrE   Útools.connectors.mcprF   ÚownsÚop_idÚREFUSED)r(   r)   r%   r0   rN   Útargetsr6   Ústaler>   r?   r@   ÚclientrE   rF   Úrerunr1   r2   s   &&$            @@r$   Úreissuer]   .   sƒ  ù€ ßEÑEá27Ó8±%¨$×Ñ Ö%±%€GÐ8ß
ƒsÑ
0©Ó
0‡s‡s‚sÑ
0©Ó
0×0Ò0ÜÐÜ
¡gÓ.¡g˜F�KŒK¡gÑ.Ó/°1Ô4ÜÐÙ'.Ól¡w˜V·,±,À;×CUÑCUÐWb×WjÑWjÐBkÑ2kŒ[ˆV�[Œ[¡w€EÐlÜ
ˆ5ƒz”S˜“\Ô!ÜÐØ××ÐÜˆß
ƒsÕ
cÑ[bÓ
c‡s‡s‚sÕ
cÑ[bÓ
c×cÒcÜÐØˆq…z‡�˜+Ô%ßMÑMá¨d¸i×>UÐ>UÈ:Ð\e×\jÑ\jÔkˆÙˆV °$¸e¿j¹jÕIÙÝ(Ý*à$Ÿ\™\¨)¯/©/×:Ò:ˆG�MŠMÀ€EÙ˜I×-Ò-Œ7Ð7°4Ð7ùò- 9ùò /ùâls   ‘HÁ5HÂ(HÃHc               ó$   € V ^8„  d   QhRRRRRR/# )r'   r(   r   Úrawr   r+   ÚNoner   )r,   s   "r$   r-   r-   J   s'   € ÷ bñ bÐ/ð b°cð b¸dñ br#   c                óô   € ^ RI HpHpHp \	        WP
                  4      '       d   VP                  W4       R# VP                  V P                  4      '       d   VP                  MVP                  ! W4       R# )z³Hand the card's answer to the module running this operation (a catalog install or an MCP
one); a managed operation's card only skips and continues, which the MCP fold also covers.)rE   ÚdisplayÚmcpN)	rT   rE   rb   rc   Ú
isinstanceÚDisplayOperationÚapply_answerrV   rW   )r(   r_   rE   rb   rc   s   &&   r$   rf   rf   J   sX   € ÷ 7Ñ6ä�)×5Ñ5×6Ò6Ø×Ñ˜YÔ,ÙØ$Ÿ\™\¨)¯/©/×:Ò:€W×ÒÀ×@PÑ@PÐPÐR[Öar#   c               ó$   € V ^8„  d   QhRRRRRR/# )r'   r(   r   r_   r   r+   Úboolr   )r,   s   "r$   r-   r-   U   s"   € ÷ ñ Ð*ð °ð ¸ñ r#   c                ó  € \        W4       V P                  '       g2   V P                  '       d    V P                  \        P                  4       V P                  '       d   \
        P                  ! V 4       V P                  # )z»The card's answer: apply it, settle once every target is resolved, close a settled operation. Returns whether it settled; raises ``IllegalTransition`` for an answer the operation refuses.)rf   r   Úall_resolvedÚsettler   r
   Úclose)r(   r_   s   &&r$   Úrespondrm   U   sY   € ä�Ô Ø××Ð ×!7×!7Ð!7Ø×Ñœ×2Ñ2Ô3Ø××ÐÜ�
Š
�9ÔØ×ÑÐr#   Útick_secondsrB   c               ó<   € V ^8„  d   QhRRRRRRRRR	R
RRRRRRRR/	# )r'   rY   zlist[Target]r:   r   Úsession_keyr   Útool_call_idr*   Úconnection_callbackúOptional[Callback]rn   úOptional[float]Úwith_urls_in_resultrh   rB   zOptional[Any]r+   r   )r,   s   "r$   r-   r-   _   sb   € ÷ ñ Øðà
ðð ð	ð
  ðð ,ðð "ðð ðð ðð 	ñr#   c          	     ó8   € \        \        WW7R7      VVVVR7      # )zQBlock the tool thread until the operation settles; return the tool's JSON string.)rp   rq   rB   ©rr   rn   ru   )Úopen_and_driver   )rY   r:   rp   rq   rr   rn   ru   rB   s   &&$$$$$$r$   Úrun_operationry   _   s'   € ô Ü˜GÈ<ÔcØØ/Ø!Ø/ôð r#   c               ó0   € V ^8„  d   QhRRRRRRRRR	R
RR/# ©r'   r(   r   r:   r   rr   rs   rn   rt   ru   rh   r+   r   r   )r,   s   "r$   r-   r-   t   sD   € ÷ ñ Ø"ðà
ðð ,ð	ð
 "ðð ðð 	ñr#   c               óà   €  \         P                  ! V 4       \        T TTTTR7      #   \         P                   d1   p^ RIHp T! RTP
                  P                   R24      u Rp?# Rp?ii ; i)zTRegister ``operation`` as the session's open one and drive it; one open per session.)Ú
tool_errorz8a connection operation is already open in this session (zj); it settles when the user finishes with the card, on Continue, or at its deadline. Do not start another.Nrw   )r
   ÚopenÚOperationAlreadyOpenÚtools.registryr}   ÚexistingrW   Údrive_operation)r(   r:   rr   rn   ru   Úexcr}   s   &&$$$  r$   rx   rx   t   sx   € ð
Ü�	Š	�)Ôô ØØØ/Ø!Ø/ôð øô ×$Ñ$ô 
Ý-áØFÀsÇ|Á|×GYÑGYÐFZð [kð kó
õ 	
ûð
ús   ‚( ¨A-½%A(Á"A-Á(A-c               ó0   € V ^8„  d   QhRRRRRRRRR	R
RR/# r{   r   )r,   s   "r$   r-   r-   �   sD   € ÷ 3ñ 3Ø"ð3à
ð3ð ,ð	3ð
 "ð3ð ð3ð 	ñ3r#   c               óþ  €  VP                  V 4       V P                  4        Ve)   V P                  '       g   V! V P                  4       4       \	        WV4       \
        P                  ! V 4       VP                  e(   \        P                  ! VP                  V 4      RR7      # V P                  VR7      pRVR&   VP                  VR&   \        P                  ! VRR7      #   \
        P                  ! T 4       i ; i)NF)Úensure_ascii)Ú	with_urlsr   Ústatusr   )r   Úsettle_if_all_resolvedr   Úrequest_payloadÚ_watchr
   rl   r   ÚjsonÚdumpsr   )r(   r:   rr   rn   ru   Úpayloads   &&$$$ r$   r‚   r‚   �   sÇ   € ðØ�‰�YÔØ×(Ñ(Ô*ØÒ*°9×3D×3DÐ3DÙ 	× 9Ñ 9Ó ;Ô<Üˆy Ô-ä�
Š
�9ÔØ‡{�{ÒÜ�zŠz˜$Ÿ+™+ iÓ0¸uÔEÐEØ×ÑÐ)<ÐÓ=€GØ!€GˆHÑØ—i‘i€GˆF�OÜ�:Š:�g¨EÔ2Ð2øô 	�
Š
�9Õús   ‚6C$ ¹"C$ Ã$C<c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r'   r(   r   r:   r   rn   rt   r+   r`   r   )r,   s   "r$   r-   r-   §   s*   € ÷ +ñ +Ð)ð +°ð +À_ð +ÐY]ñ +r#   c                óÄ  € ^ RI Hp Vf   \        MTpV P                  '       g¼   V! 4       '       d"   V P	                  \
        P                  4       R# \        P                  ! 4       V P                  8¼  d"   V P	                  \
        P                  4       R# VP                  V 4       V P                  '       g   V P                  4       '       d   R# \        W4       KÍ  R# )r/   ©Úis_interruptedN)Útools.interruptr’   ÚWATCH_INTERVAL_SECONDSr   rk   r   Ú	interruptÚtimeÚdeadline_atÚdeadliner   r‰   Ú_sleep_until_wake)r(   r:   rn   r’   Úticks   &&&  r$   r‹   r‹   §   sŸ   € Ý.à%1Ò%9Õ!¸|€DØ××ÐÙ×ÒØ×Ñœ\×3Ñ3Ô4ÙÜ�9Š9‹;˜)×/Ñ/Ô/Ø×Ñœ\×2Ñ2Ô3ÙØ�‰�YÔà××Ð 	× @Ñ @× BÒ BÙÜ˜)Ö*ñ  r#   c               ó$   € V ^8„  d   QhRRRRRR/# )r'   r(   r   rš   Úfloatr+   r`   r   )r,   s   "r$   r-   r-   ¹   s"   € ÷ ñ Ð!4ð ¸Eð Àdñ r#   c                ó�  € ^ RI Hp \        \        P                  ! 4       V,           V P                  4      pV P
                  '       gd   V! 4       '       gW   V\        P                  ! 4       ,
          pV^ 8:  d   M2V P                  P                  \        \        V4      4      '       g   Kt   V P                  P                  4        R# )zUSleep up to one tick, leaving early on ``wake``, the deadline, or the interrupt flag.r‘   N)
r“   r’   Úminr–   r—   r   ÚwakeÚwaitÚ_WAKE_SLICE_SECONDSÚclear)r(   rš   r’   ÚuntilÚ	remainings   &&   r$   r™   r™   ¹   s€   € å.ä”—	’	“˜dÕ" I×$9Ñ$9Ó:€EØ××Ð©×(8Ò(8ØœDŸIšI›KÕ'ˆ	Ø˜Œ>ØØ�>‰>×ÑœsÔ#6¸	ÓB×CÔCØØ‡N�N×ÑÖr#   ))r    Ú
__future__r   rŒ   r–   Údataclassesr   Útypingr   r   r   r   r   r	   rT   r
   rG   r   Útools.connectors.operationr   r   rI   rK   rO   rP   rQ   rX   r”   r¡   Údictr   ÚCallbackr   r]   rf   rm   ry   rx   r‚   r‹   r™   r   r#   r$   Ú<module>r«      sæ   ðñ[õ #ã Û Ý !ß @× @å !Ý 2ß Bà!€Ø€Ø%Ð Ø
€Ø€Ø
€àÐ àÐ à�T˜#˜s˜(•^Ð$ h¨s¥mÐ3Õ4€ð ÷Mð Mó ðMð8Ð`d÷ 8õ8bõðð %)ðð ÷ð*ð
 %)÷ð63ð
 %)÷3õ0+÷$r#   