+
    lHàjb"  ã                  óì   a € 0 t $ R t^ RIHt ^ RIt^ RIt^ RIHt ^ RIH	t	 ]P                  ! RRR7      tR]R&   Rt]! 0 Rm4      t]! 0 Rm4      tR	 R
 ltR R ltR R ltR R ltR R ltR R ltR# )uÃ  Legacy-handler fallback for authority-backed WebSocket connections.

Session verbs live on the session authority; methods it answers ``-32601`` for may still have a
legacy sidecar handler (pet, wake word, connectors, config). That fallback must not widen what
the connection's ticket grants (R2-M3):

* only connections holding the authority's full interactive grant reach legacy dispatch â€” a
  worker-adoption ticket (``{'worker:adopt'}``) or a capability-less connection keeps the
  authority's ``-32601``;
* a ticket bound to a secondary profile keeps that profile's scope: sessionless
  ``@_profile_scoped`` handlers read :func:`connection_profile_home` instead of defaulting to the
  launch profile.
)ÚannotationsN)ÚPath)ÚAnyÚ!hermes_ws_connection_profile_home)Údefaultz"contextvars.ContextVar[str | None]Ú_connection_profile_homec               ó$   € V ^8„  d   QhRRRRRR/# )é   Úactorr   ÚmethodÚstrÚreturnÚbool© )Úformats   "ÚC/home/ubuntu/.hermes/hermes-agent/tui_gateway/ws_legacy_fallback.pyÚ__annotate__r   5   s&   € ÷ 	gñ 	g 3ð 	g°ð 	g¸ñ 	gó    c                óÌ   € ^ RI Hp V\        9   d   R# VP                  \        4      '       d   V\
        9  d   R# VR,          \        \        V RR4      ;'       g    R4      8*  # )zçTrue when the connection's grant covers the interactive purpose (the authority's own
capability map; never a second list that could drift) and *method* is neither a session verb
the authority owns nor a process-global sidecar verb.)Ú_PURPOSE_CAPABILITIESFÚinteractiveÚcapabilitiesr   )Úgateway.runtime_bootstrapr   Ú_PROCESS_GLOBALÚ
startswithÚ_SESSION_NAMESPACESÚ_SESSION_FALLBACK_ALLOWEDÚ	frozensetÚgetattr)r
   r   r   s   && r   Úlegacy_fallback_allowedr   5   sX   € õ @Ø”Ô ÙØ×ÑÔ,×-Ò-°&Ô@YÔ2YÙØ  Õ/´9¼WÀUÈNÐ\^Ó=_×=eÐ=eÐceÓ3fÑfÐfr   c               ó   € V ^8„  d   QhRR/# )r	   r   ú
str | Noner   )r   s   "r   r   r   A   s   € ÷ *ñ * ñ *r   c                 ó*   € \         P                  4       # )zUThe non-launch profile home the current legacy fallback request's ticket is bound to.)r   Úgetr   r   r   Úconnection_profile_homer$   A   s   € ä#×'Ñ'Ó)Ð)r   c               ó$   € V ^8„  d   QhRRRRRR/# )r	   Úserverr   Ú
profile_idr   r!   r   )r   s   "r   r   r   F   s!   € ÷ 
ñ 
 #ð 
°3ð 
¸:ñ 
r   c                óP  € \        \        T;'       g    R4      4      pVP                  4       '       g   R# VP                  4       '       g   \	        \        V4      4      hVP                  4       \        V P                  4       4      P                  4       8X  d   R# \        V4      # )z´The ticket's non-launch home, or None for the launch profile. Raises when the ticket names a
home that stopped being a directory: that is a refusal, never the launch profile (N86).Ú N)r   r   Úis_absoluteÚis_dirÚFileNotFoundErrorÚresolveÚ_launch_home)r&   r'   Úhomes   && r   Ú_foreign_profile_homer0   F   sy   € ô ”�J×$Ð$ "Ó%Ó&€DØ×Ñ×ÒÙØ�;‰;�=Š=Ü¤ D£	Ó*Ð*Ø‡|�|ƒ~œ˜f×1Ñ1Ó3Ó4×<Ñ<Ó>Ô>ÙÜˆt‹9Ðr   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r	   r&   r   ÚreqÚdictr/   r   r   ztuple[dict, str | None]r   )r   s   "r   r   r   S   s)   € ÷ ?ñ ? Cð ?¨dð ?¸#ð ?ÐBYñ ?r   c           	     ó^  € ^ RI Hp ^ RIHp \	        VP                  R4      \        4      '       d   VP                  R4      M/ pRRRVP                  R4      RRR	R
R//p\        VP                  R4      ;'       g    R4      P                  4       ;p'       d*    V P                  V4      pY'       d   \        T4      3# R3# VP                  VP                  R4      4      p	V	e   RV	P                  P                  9  d   W3# V! V4      p
 V
'       d   V P                  V
4      MRpVe6   \        V4      P                  4       \        V4      P                  4       8w  d   VR3# \        V/ VCRV
/CR7      V3#   \        \        3 d    TR3u # i ; i  \        \        3 d    Rp L‚i ; i)a  Bind a non-launch ticket's profile into a legacy verb (N86). The verb runs in the ticket's
home, or in the one an explicit ``profile`` names (Desktop's host-scoped routing), so handlers
that ignore ``profile`` (billing, usage) resolve through that runtime scope instead of the
launch home. A method whose contract declares ``profile`` and got none is handed the ticket's
own profile name (refused when that name does not resolve to the ticket's home). Returns the
request plus the home to scope ("" = launch), or an error frame and None.©Úprofile_name_for_home)ÚMETHODSÚparamsÚjsonrpcú2.0ÚidÚerrorÚcodeéà  Úmessageúprofile unavailableÚprofiler)   Nr   ©r8   )Úhermes_constantsr6   Útui_gateway.contracts.registryr7   Ú
isinstancer#   r3   r   ÚstripÚ_profile_homeÚOSErrorÚ
ValueErrorr8   Úmodel_fieldsr   r-   )r&   r2   r/   r6   r7   r8   ÚrefusedÚexplicitÚnamedÚcontractÚnameÚresolveds   &&&         r   Ú_ticket_profile_requestrQ   S   s’  € õ 7Ý6Ü",¨S¯W©W°XÓ->Ä×"EÒ"EˆS�W‰W�XÔÈ2€FØ˜%  s§w¡w¨t£}°gÀÈÈiÐYnÐ?oÐp€GÜ�v—z‘z )Ó,×2Ð2°Ó3×9Ñ9Ó;Ð;€xÖ;ð	!Ø×(Ñ(¨Ó2ˆEð ¦%”C˜“JÐ/Ð/¨RÐ/Ð/Ø�{‰{˜3Ÿ7™7 8Ó,Ó-€HØÒ˜9¨H¯O©O×,HÑ,HÔHØˆyÐÙ  Ó&€Dðß15�6×'Ñ'¨Ô-¸4ˆð Òœ4 ›>×1Ñ1Ó3´t¸D³z×7IÑ7IÓ7KÔKØ˜ˆ}ÐÜ�Ð7˜vÐ7 y°$Ñ7Ô8¸$Ð>Ð>øô œÐ$ô 	!Ø˜D�=Ò ð	!ûô ”ZÐ ô ØŠðús*   ÂE; ÄF ÄF Å;FÆFÆF,Æ+F,c               ó(   € V ^8„  d   QhRRRRRRRR/# )r	   r&   r   r2   r3   r/   r   r   r   )r   s   "r   r   r   q   s.   € ÷ Qñ Q˜cð Q¨ð Q°Cð Q¸Dñ Qr   c           	     óŒ  € ^ RI Hp \        VP                  R4      \        4      '       d   VP                  R4      M/ pVP                  R4      ;'       g	    V! V4      p V'       d   V P                  V4      MRpVe6   \        V4      P                  4       \        V4      P                  4       8w  d   RRRVP                  R4      RR	R
RR//# VP                  R4      R8w  d   \	        V/ VCRV/CR7      # V P                  ;_uu_ 4        \        V P                  P                  4       4      pRRR4       \        VP                  R4      ;'       g    R4      pX U	U
u. uFŽ  w  ršV
P                  R4      '       d   K  \        V
P                  R4      ;'       g    V P                  4       4      P                  4       \        V4      P                  4       8X  g   K|  V P!                  WšV4      NK�  	  pp	p
RRRVP                  R4      RRV//#   \        \        3 d    Rp EL¬i ; i  + '       g   i     EL; iu up
p	i )a  A store-wide session read for a ticket bound to the non-launch *home*. Those handlers default
to the LAUNCH profile's store and ``session.active_list`` lists every profile's live sessions, so
the ticket's own profile is named (or the read refused), never the launch profile's served.r5   r8   rA   Nr9   r:   r;   r<   r=   r>   r?   r@   r   úsession.active_listrB   Úcurrent_session_idr)   Ú
_finalizedÚprofile_homeÚresultÚsessions)rC   r6   rE   r#   r3   rG   rH   rI   r   r-   Ú_sessions_lockÚlistÚ	_sessionsÚitemsr   r.   Ú_session_live_item)r&   r2   r/   r6   r8   rO   rP   ÚliveÚcurrentÚsidÚsessionÚrowss   &&&         r   Ú_own_profile_readrd   q   sî  € õ 7Ü",¨S¯W©W°XÓ->Ä×"EÒ"EˆS�W‰W�XÔÈ2€FØ�:‰:�iÓ ×?Ð?Ñ$9¸$Ó$?€Dðß15�6×'Ñ'¨Ô-¸4ˆð Òœ4 ›>×1Ñ1Ó3´t¸D³z×7IÑ7IÓ7KÔKØ˜5 $¨¯©°«°wÀÈÈyÐZoÐ@pÐqÐqØ
‡w�wˆxÓÐ1Ô1Ü�CÐ ; 6Ð ;¨9°dÑ ;Ô<Ð<Ø	×	×	Ó	Ü�F×$Ñ$×*Ñ*Ó,Ó-ˆ÷ 
ä�&—*‘*Ð1Ó2×8Ð8°bÓ9€GÙQUô %ÑQUÁÀØ—;‘;˜|×,ô =Ü15°g·k±kÀ.Ó6Q×6jÐ6jÐU[×UhÑUhÓUjÓ1k×1sÑ1sÓ1uÜ�D‹z×!Ñ!Ó#ñ2$ô =ˆF×%Ñ% c°GÖ<ÑQU€Dñ %ð �u˜d C§G¡G¨D£M°8¸jÈ$Ð=OÐPÐPøô ”ZÐ ô Ø‹ðú÷ 
×	Ð	üó%s<   Á!H Á)H Ä$H,Å"I ÆI Æ<I Ç I ÈH)È(H)È,H=	c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r	   r&   r   r2   r3   Ú	transportr
   r   zdict | Noner   )r   s   "r   r   r   ‰   s/   € ÷ .ñ .˜Cð . dð .°sð .À3ð .È;ñ .r   c           
     óÀ  €  \        V \        VRR4      4      p\        P
                  ! 4       pTe:   TP                  R4      \        9   d    \        YT4      pRT9   g   RT9   d   T# TpM3Te0   \        YT4      w  rTf   T# T'       d   T P                  RT/4      p\        P                  T4      p T;_uu_ 4        T P                  Y4      uuRRR4       \        P                  T4       #   \         d    RRRTP                  R4      RRRR	R
//u # i ; i  + '       g   i     M; i \        P                  T4       R#   \        P                  T4       i ; i)z™Run ``server.dispatch`` with the ticket's profile home bound (call from a worker thread;
the pool path copies this context, so long handlers see it too).r'   Nr9   r:   r;   r<   r=   r>   r?   r@   r   rX   rW   )r0   r   rH   r#   Ú
contextlibÚnullcontextr   rd   rQ   Ú_session_profile_runtime_scoper   ÚsetÚdispatchÚreset)	r&   r2   rf   r
   r/   ÚscopeÚscopedÚtargetÚtokens	   &&&&     r   Údispatch_legacyrr   ‰   s>  € ðrÜ$ V¬W°U¸LÈ$Ó-OÓPˆô ×"Ò"Ó$€EØÒ˜CŸG™G HÓ-Ô1JÔJÜ" 6°Ó5ˆØ�vÔ ¨FÔ!2ØˆMØ‰Ø	Ò	Ü-¨f¸4Ó@‰ˆØŠ>ØˆJßØ×9Ñ9¸>È6Ð:RÓSˆEÜ$×(Ñ(¨Ó.€Eð.ßŠUØ—?‘? 3Ó2÷ ‰Uô 	!×&Ñ& uÕ-øô' ô rØ˜5 $¨¯©°«°wÀÈÈyÐZoÐ@pÐqÒqðrú÷  �UúˆUô 	!×&Ñ& uÖ-øÔ ×&Ñ& uÕ-ús5   ‚C/ Â4
E Â>DÃ
E Ã/&DÄDÄD+	Ä&E ÅE)zsession.zprompt.zmessage.>   rT   úsession.most_recentúsession.events.statsúsession.foreign.listúsession.foreign.importúsession.foreign.preview>   ú
reload.envú
reload.mcpúagents.listúprocess.stopúdelegation.pause)Ú__conditional_annotations__Ú__doc__Ú
__future__r   rh   ÚcontextvarsÚpathlibr   Útypingr   Ú
ContextVarr   Ú__annotations__r   r   r   r   r   r$   r0   rQ   rd   rr   )r}   s   @r   Ú<module>r…      s€   øðôõ #ã Û Ý Ý à?J×?UÒ?UØ'°ô@7Ð Ð<ó 7ð :Ð Ù%ò 'ó Ð ñ ÒkÓl€õ	gõ*õ

õ?õ<Q÷0.r   