+
    lHàjË  ã                   ó  € R t ^ RIt^ RIHt ^RIHt ]! 4       t]P                  tR R lt^t	]! R4      ]3R R ll4       t
]! R	4      ]3R
 R ll4       t
]! R4      ]3R R ll4       t
]! R4      ]3R R ll4       t
R R ltR# )u‡  Bot-relay JSON-RPC handlers â€” the gateway side of cross-connection A2A. Connections ARE the
peer set: the Desktop owns every gateway socket and relays between them via four doors on EACH
gateway: ``roster.sync`` (push OTHER connections' agents so ``message_agent`` resolves them),
``outbox.drain`` (collect envelopes queued here for other connections), ``deliver`` (one-turn Bot
Chat delivery on the TARGET gateway, returns the reply), ``reply`` (write the reply/error back on
the SENDER gateway for its waiter). Plumbing: ``tools/bot_relay.py``; handlers are rebound onto
server.py's globals (method_ctx.py) and reference ``_ok``/``_err`` bare.N©ÚPath)ÚHandlerRegistryc                ó$   € V ^8„  d   QhR\         /# ©é   Úreturnr   )Úformats   "ÚB/home/ubuntu/.hermes/hermes-agent/tui_gateway/methods_bot_relay.pyÚ__annotate__r      s   € ÷ /ñ /”Tñ /ó    c                 ó>   € ^ RI Hp Hp V! \        V ! 4       4      4      # )zþInstall root shared by every profile (relay state is install-wide). Same formula as the
writers (``tools/bot_relay``, ``tools/bot_mode_dm``): both ends of the mailbox must agree for
every HERMES_HOME, including non-``profiles/`` subdirs of ``~/.hermes``.©Ú_default_homeÚ_hermes_root)Útools.bot_mode_prober   r   r   r   s     r
   Ú_relay_rootr      s   € ÷ AÙœ™]›_Ó-Ó.Ð.r   zbot_relay.roster.syncc                ó0   € V ^8„  d   QhR\         R\         /# ©r   Úparamsr   ©Údict)r	   s   "r
   r   r       s   € ÷ 'ñ '”4ð '¬tñ 'r   c                óZ  aa	€  ^ RI Ho	Hp R VV	3R llpV! 4       pV! S! 4       VP                  R4      4      pV! 4       pWu8w  d+   \        P
                  ! \        4      P                  RWW4       \        V RV/4      #   \         d!   p\        T R\        T4      4      u Rp?# Rp?ii ; i)	u¹  Replace this gateway's view of agents on OTHER connections â†’ ``{count}`` accepted rows
(``agents`` rows ``{profile, handle, connection_id, ...}``; invalid rows are dropped).
A roster that changes is logged with its rows: a peer connection listed with this machine's
own profiles, or two publishers alternating, shows up as a flapping line (the pushing window
is in the Desktop's desktop.log ``[bot-relay win=â€¦]`` lines at the same time).)Úread_remote_rosterÚwrite_remote_rosterc                ó$   € V ^8„  d   QhR\         /# r   )Ústr)r	   s   "r
   r   Ú_.<locals>.__annotate__)   s   € ÷ 	gñ 	g”sñ 	gr   c                  ó„   <€ S! S! 4       4      p R \        V 4       R2RP                  R V  4       4      ,           R,           # )zn=z [Ú c              3   ó�   "  € T F<  qP                  R 4       RVP                  R4       RVP                  R4      : 2x € K>  	  R# 5i)Úconnection_idÚ/ÚprofileÚ=ÚtitleN©Úget)Ú.0Úrs   & r
   Ú	<genexpr>Ú#_.<locals>.trace.<locals>.<genexpr>+   sB   é € ð 1aÙ[_ÐVW—5‘5˜Ó)Ð*¨!¨A¯E©E°)Ó,<Ð+=¸Q¸q¿u¹uÀW»~Ñ>PÕQÓ[_ùs   ‚AAÚ])ÚlenÚjoin)ÚrowsÚ_rootr   s    €€r
   ÚtraceÚ_.<locals>.trace)   sO   ø€ Ù%¡e£gÓ.ˆDØœ˜D›	�{ "Ð%¨¯©ñ 1aÙ[_ó1aó )aõ aØcfõgð gr   Úagentsz"bot_relay roster changed: %s -> %sÚcountiâ  N)Útools.bot_relayr   r   r'   ÚloggingÚ	getLoggerÚ__name__ÚinfoÚ_okÚ	ExceptionÚ_errr   )
Úridr   r0   r   r1   Úbeforer4   ÚafterÚer   s
   &&f      @r
   Ú_rA      s•   ù€ ð'ßK÷	gñ 	gñ
 “ˆÙ#¡E£G¨V¯Z©Z¸Ó-AÓBˆÙ“ˆØŒ?Ü×ÒœhÓ'×,Ñ,Ð-QÐSYÔaÜ�3˜ %Ð(Ó)Ð)øÜô 'Ü�C˜œs 1›vÓ&Õ&ûð'ús$   „AA? Á7A? Á?B*Â
B%ÂB*Â%B*zbot_relay.outbox.drainc                ó0   € V ^8„  d   QhR\         R\         /# r   r   )r	   s   "r
   r   r   9   s   € ÷ 'ñ '”4ð '¬tñ 'r   c                óž   €  ^ RI Hp \        V RV! V! 4       4      /4      #   \         d!   p\	        T R\        T4      4      u Rp?# Rp?ii ; i)u«   Claim every pending cross-connection envelope queued here â†’ ``{envelopes}``; claimed
envelopes move to ``claimed/`` atomically so concurrent drains can't double-deliver.)Úclaim_pending_envelopesÚ	envelopesiã  N)r5   rD   r:   r;   r<   r   )r=   r   r0   rD   r@   s   &&&  r
   rA   rA   8   sG   € ð'Ý;Ü�3˜Ñ&=¹e»gÓ&FÐGÓHÐHøÜô 'Ü�C˜œs 1›vÓ&Õ&ûð'ús   ‚! ¡A¬AÁAÁAzbot_relay.deliverc                ó0   € V ^8„  d   QhR\         R\         /# r   r   )r	   s   "r
   r   r   D   s   € ÷ 5Qñ 5Q”4ð 5Q¬tñ 5Qr   c           	     óÞ  a€ ^ RI HpHp ^ RIHp  V! SP                  R4      4       SP                  R4      p\        V\        4      '       d   VP                  V4      '       g   \        R4      h ^ R
IHpHp ^ RIHp	Hp
 R!p\!        \#        4       RR4      pT	! T4      '       d   T! T
! T4      4      pMT! T3R lT 4       !  pSP%                  4        UUu/ uF  w  rïYë9  g   K  YïbK  	  pppT'       d   TTR&   TP'                  4       R8X  d   RMTpT! 4       p^ RIHp \-        T! T4      4      P                  T4      pTf   \        T RRT R2RR/R	7      # \        TP                  R4      \        4      '       dO   ^ RIHp ^ RIHpHp T! TR,          SP                  R4      SP                  R4      T! T4      T! T4      4      TR&    \5        Y! T/ TCRT/C4      4      #   \         d    \        T RRRR/R	7      u # i ; iu uppi   \6         dQ   p\8        P:                  ! \<        4      P?                  RTRR7       \        T R\        T4      RR /R	7      u Rp?# Rp?ii ; i)"zILegacy transport bridge only: canonical admission or an explicit refusal.)Ú_delivery_idÚauthority_delivery)Ú
_HANDLE_REÚidr#   zinvalid profileiú  Úinvalid_paramsÚreason)Údata)Údelivery_turn_authorÚrelaying_principal_author)Ú_is_authenticated_identityÚ_principal_digestÚfrom_handleÚfrom_connectionÚauth_identityNc              3   óF   <"  € T F  pSP                  V4      x € K  	  R # 5i)Nr&   )r(   Úkeyr   s   & €r
   r*   Ú_.<locals>.<genexpr>_   s   øé € Ð'QÁ=¸C¨¯
©
°3¯¨Ã=ùs   ƒ!ÚauthorÚhermesÚdefault)Ú_rosteriü  zno profile 'z' on this gatewayÚunknown_profileÚmessage)Úlocal_taken_forms)Úqualify_sender_stampr   zbot_relay.deliver to %s refusedT)Úexc_infoiæ  Úruntime_unavailable)Úfrom_profilerS   rT   ) Útools.bot_live_deliveryrH   rI   r5   rJ   r'   Ú
isinstancer   Ú	fullmatchÚ
ValueErrorr<   rO   rP   Ú#tui_gateway.methods_browser_controlrQ   rR   ÚgetattrÚcurrent_transportÚitemsÚlowerr   r\   r   r_   r`   r   r:   r;   r6   r7   r8   Údebug)r=   r   r0   rH   rI   rJ   r#   rO   rP   rQ   rR   Úsender_fieldsÚidentityrY   rW   ÚvalueÚ	forwardedÚresolvedÚrootr\   Úhomer_   r`   r   Úexcs   &f&                      r
   rA   rA   C   sG  ø€ ÷ IÝ*ðTÙ�V—Z‘Z Ó%Ô&Ø—*‘*˜YÓ'ˆÜ˜'¤3×'Ò'¨z×/CÑ/CÀG×/LÒ/LÜÐ.Ó/Ð/ð 0M÷ PßaØF€MÜÔ(Ó*¨O¸TÓB€HÙ! (×+Ò+ñ +Ñ+<¸XÓ+FÓG‰á%Ô'QÁ=Ó'QÑRˆØ.4¯l©l¬nÔY©n¡
 ÀÑ@X”�’©n€IÑYßØ$ˆ	�(ÑØ#ŸM™M›O¨xÔ7‰y¸W€HÙ‹7€Dõ -Ü‘˜“Ó×"Ñ" 8Ó,€DØ‚|Ü�C˜ ¨g¨YÐ6GÐHÐPXÐZkÐOlÔmÐmÜ�)—-‘- 	Ó*¬C×0Ò0õ 	;ßLÙ3Ø�iÕ  &§*¡*¨]Ó";¸V¿Z¹ZÐHYÓ=ZÙ˜tÓ$Ñ&7¸Ó&=ó ?ˆ	�)ÑðQÜ�3Ð*¨4Ð1S°IÐ1S¸yÈ(Ñ1SÓTÓUÐUøôO ô TÜ�C˜Ð/°xÐAQÐ6RÔSÒSðTüó& Zøô* ô Qô 	×Òœ(Ó#×)Ñ)Ð*KÈXÐ`dÐ)ÔeÜ�C˜œs 3›x¨xÐ9NÐ.OÔPÕPûð	QúsH   ‘=G) ÁG) Á&G) Ã
HÃ(HÇH Ç)HÈHÈI,ÈAI'É!I,É'I,zbot_relay.replyc                ó0   € V ^8„  d   QhR\         R\         /# r   r   )r	   s   "r
   r   r   }   s   € ÷ 'ñ '”4ð '¬tñ 'r   c                óX  € \        VP                  R4      ;'       g    R4      P                  4       pV'       g   \        V RR4      #  ^ RIHp T! V! 4       T\        VP                  R4      ;'       g    R4      \        VP                  R4      ;'       g    R4      \        VP                  R4      ;'       g    R4      R	7       \        V R
R/4      #   \         d!   p\        T R\        T4      4      u Rp?# Rp?i\         d!   p\        T R\        T4      4      u Rp?# Rp?ii ; i)z¦Write a relayed ``reply`` and/or ``error`` (+ optional typed ``reason``, see
``tools.bot_failure_reasons``) for envelope ``id`` so the sender-side waiter picks it up.rK   Ú iý  zid required)Úwrite_replyÚreplyÚerrorrM   )rz   r{   rM   ÚokTiþ  Niç  )	r   r'   Ústripr<   r5   ry   r:   rg   r;   )r=   r   r0   Úenvelope_idry   r@   s   &&&   r
   rA   rA   |   sì   € ô �f—j‘j Ó&×,Ð,¨"Ó-×3Ñ3Ó5€KßÜ�C˜˜}Ó-Ð-ð'Ý/Ù‘E“G˜[´°F·J±J¸wÓ4G×4MÐ4MÈ2Ó0NÜ˜fŸj™j¨Ó1×7Ð7°RÓ8ÄÀVÇZÁZÐPXÓEY×E_ÐE_Ð]_ÓA`õ	bä�3˜˜t˜Ó%Ð%øÜô 'Ü�C˜œs 1›vÓ&Õ&ûÜô 'Ü�C˜œs 1›vÓ&Õ&ûð'úsH   Á	+C Á5"C Â"C Â;C ÃD)Ã C;Ã5D)Ã;D)ÄD)Ä	D$ÄD)Ä$D)c                ó   € V ^8„  d   QhRR/# )r   r   N© )r	   s   "r
   r   r   Ž   s   € ÷ 	$ñ 	$˜ñ 	$r   c           	      ó   € \         P                  V 4       ^RIHp V P                  VP
                  ,          V n        R F  p\        W\        W4      4       K  	  VP                  V 4       VP                  V 4       R# )é   )Úmethods_groupsN)Úget_hosted_room_serviceÚ_WORKER_UNAVAILABLEÚ_profile_nameÚ_requested_profileÚ_api_server_keyÚ_room_link_run_storage_durable)
Ú	_registryÚinstallrx   rƒ   Ú_LONG_HANDLERSÚLONG_HANDLERSÚsetattrri   Úbind_serverÚregister)Úserverrƒ   Únames   &  r
   r�   r�   Ž   sg   € Ü×Ñ�fÔÝ Ø"×1Ñ1°N×4PÑ4PÕP€FÔó=ˆô 	�œg nÓ;Ö<ñ=ð ×Ñ˜vÔ&Ø×Ñ˜FÖ#r   )Ú__doc__r6   Úpathlibr   Ú
method_ctxr   rŠ   Úmethodr   ÚTURN_MAX_ATTEMPTSrA   r�   r€   r   r
   Ú<module>r˜      s²   ðñLó Ý å 'áÓ€	Ø	×	Ñ	€õ/ð Ð ñ ÐÓ Ø*ö 'ó !ð'ñ0 Ð Ó!Ø*ö 'ó "ð'ñ ÐÓØ*ö 5Qó ð5Qñp ÐÓØ*ö 'ó ð'÷"	$r   