+
    jHàjï&  ã                  ó0  a € 0 t $ R t^ RIHt ^ RIt^ RIt^ RIt^ RIHt ^xt	Rt
 ! R R4      t]P                  ! 4       t/ tR]R&   R	 R
 ltR R ltR R ltRR /R R lltRR R]	/R R lltRR R]	RR/R ltR R ltR R ltRR /R  ltRR/R! ltR# )"uD  The session owner's serverâ†’client requests to a local viewer, and who may settle them.

The owner sends a request frame (``tui_gateway/contracts/server_requests.py``: ``sudo``, ``secret``,
``clarify``, the Desktop UI requests) to the viewers attached to a session's event stream and blocks the
agent thread until one answers, the turn is interrupted, or it times out: the canonical side of main's
sidecar ``tui_gateway/server_requests.py``. A viewer answers with a JSON-RPC response frame
(:func:`resolve`) or, for a batch clarify, per question with ``clarify.lock`` (:func:`lock_answer`); both go
through :func:`may_settle`, and a batch's terminal result comes from ``tools.clarify_batch.settle_batch``,
the rule the sidecar uses too. Values are never published, journaled or logged: they travel only in the
viewer's response frame.
)ÚannotationsN)Úsettle_batchg      Ð?c                  ó$   € ] tR t^tRtRR ltRtR# )Ú_PendingNc                	ó¼   € \         P                  ! 4       V n        Wn        W@n        W0n        R V n        RV n        V'       d   \        V4      MRV n	        / V n
        R# )Ú N)Ú	threadingÚEventÚeventÚ
session_idÚmethodÚeventsÚvalueÚresultÚtupleÚqidsÚlocked)Úselfr   r   r   r   s   &&&&&ÚD/home/ubuntu/.hermes/hermes-agent/gateway/session_server_requests.pyÚ__init__Ú_Pending.__init__   sE   € Ü—_’_Ó&ˆŒ
Ø$ŒØŒð ŒØˆŒ
ØˆŒç#'”E˜$”K¨TˆŒ	ØˆŽó    )r
   r   r   r   r   r   r   r   )NNN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú	__slots__r   Ú__static_attributes__© r   r   r   r      s   † Ø`€I÷ð r   r   zdict[str, _Pending]Ú_openc               ó   € V ^8„  d   QhRR/# ©é   ÚreturnÚboolr   )Úformats   "r   Ú__annotate__r&   -   s   € ÷ Sñ S¨tñ Sr   c                ó„   € V P                   P                  V4      pVRJ;'       d    VRJ;'       d    VP                  VJ # )zSTrue when *authority*'s live *session_id* is the very stream a request was sent on.N)ÚsessionsÚgetÚevent_stream)Ú	authorityr   r   Úlives   &&& r   Úowned_byr-   -   sC   € à×Ñ×!Ñ! *Ó-€DØ�tÐ×RÐR ¨dÐ 2×RÐR°t×7HÑ7HÈFÐ7RÐRr   c               ó   € V ^8„  d   QhRR/# r!   r   )r%   s   "r   r&   r&   3   s   € ÷ Cñ C¸ñ Cr   c                ó,  € ^ RI Hp ^ RIHp \	        WV4      '       g   R#  V P                  W! V P                  V4      R4       T P                  P                  T4      pTRJ;'       d    YP                  P                  4       9   #   T d     R# i ; i)as  The one rule for who may settle an owner request (a response frame or ``clarify.lock``): the
request went out on *authority*'s own live stream for that session (session ids repeat across
profiles and ``_open`` is process-wide), *actor* holds ``session:respond`` there, and *actor* is
attached to that session, the same set of connections the request frame was written to.)Ú
SessionRef)ÚRuntimeStoreErrorFzsession:respondN)Úgateway.session_contractr0   Úhermes_state_runtimer1   r-   Ú	authorizeÚ
profile_idr(   r)   ÚsubscribersÚvalues)r+   Úactorr   r   r0   r1   r,   s   &&&&   r   Ú
may_settler9   3   s�   € õ
 4Ý6Ü�I¨6×2Ò2ÙðØ×Ñ˜E :¨i×.BÑ.BÀJÓ#OÐQbÔcð ×Ñ×!Ñ! *Ó-€DØ�tÐ×BÐB ×)9Ñ)9×)@Ñ)@Ó)BÑ BÐBøð ô Úðús   ¢#B ÂBÂBc               ó   € V ^8„  d   QhRR/# r!   r   )r%   s   "r   r&   r&   D   s   € ÷ \ñ \ ñ \r   c                óþ   € \        V \        4      ;'       dg    RV 9  ;'       dZ    \        V P                  R4      \        4      ;'       d3    V R,          P	                  R4      ;'       d    RV 9   ;'       g    RV 9   # )zbA viewer's answer to one of the owner's requests: a string ``srq-`` id, a result/error, no method.r   Úidúsrq-r   Úerror)Ú
isinstanceÚdictr)   ÚstrÚ
startswith)Úframes   &r   Úis_response_framerD   D   s„   € ä�uœdÓ#÷ [ð [¨¸Ñ(=÷ [ð [Ä*ÈUÏYÉYÐW[Ë_Ô^aÓBb÷ [ð [Ø�d•×&Ñ& vÓ.÷[ð [Ø4<ÀÑ4E×4YÐ4YÈÐTYÑIYð\r   Ú
session_okc                ó   € R # )Tr   ©r   r   s   &&r   Ú<lambda>rH   J   s   € ¹Dr   c               ó   € V ^8„  d   QhRR/# r!   r   )r%   s   "r   r&   r&   J   s   € ÷ ñ ÀTñ r   c               óÎ  € \         ;_uu_ 4        \        P                  V R,          4      pVe$   V! VP                  VP                  4      '       g    RRR4       R# \        P                  V R,          R4       VP                  e   \        VP                  4      MRpRRR4       RV 9  d   V P                  R4      MRpXe   \        W44      p\        V\        4      '       d   VP                  R4      MRp\        V\        4      '       d   TMRXn        \        V\        4      '       d   TMRVn        VP                  P                  4        R#   + '       g   i     L¼; i)	af  Settle the open request *frame* answers; False when nothing (here) waits for that id.
``session_ok(session_id, events)`` lets the caller refuse an answer from a connection not entitled
to that session: the caller's own authority must own ``events``, the stream the request was sent on
(session ids are only unique per profile, and ``_open`` is process-wide).r<   NFr>   r   r   r   T)Ú_lockr   r)   r   r   Úpopr   r@   r   r   r?   rA   r   r   r
   Úset)rC   rE   Úpendingr   r   r   s   &$    r   ÚresolverO   J   sü   € ÷
 
ŽÜ—)‘)˜E $�KÓ(ˆØŠ?¡*¨W×-?Ñ-?ÀÇÁ×"PÒ"PØ÷ 
‰ô 	�	‰	�%˜•+˜tÔ$Ø)0¯©Ò)A”�g—n‘nÔ%Àtˆ÷ 
ð %,°5Ô$8ˆU�Y‰Y�xÔ ¸d€FØÒä˜fÓ-ˆÜ#-¨f´d×#;Ò#;ˆF�J‰J�wÔÀ€EÜ'¨¬s×3Ò3‘E¸€G„MÜ)¨&´$×7Ò7‘V¸T€G„NØ‡M�M×ÑÔÙ÷ 
�ús   �AEÁEÁAEÅE$	Ú	cancelledc                 ó   € R # ©Fr   r   r   r   rH   rH   `   s   € Ér   Útimeoutc               ó   € V ^8„  d   QhRR/# )r"   r#   rA   r   )r%   s   "r   r&   r&   `   s   € ÷ 8ñ 8Ðmpñ 8r   c          	     óB   € \        WW#WER7      pVe   VP                  # R# )u¾   Send one one-string serverâ†’client request (``sudo``, ``secret``: ``ValueResult``) to the
session's attached viewers and wait for its ``value``; "" on skip, interrupt, timeout or no viewer.)rP   rS   r   )Ú_askr   )r   r   r   ÚparamsrP   rS   rN   s   &&&&$$ r   Ú
ask_viewerrX   `   s&   € ô �6 vÀÔ\€GØ#Ò/ˆ7�=‰=Ð7°RÐ7r   c                 ó   € R # rR   r   r   r   r   rH   rH   g   s   € Éur   r   c          
     óD   € \        WW#WEVR7      pVe   VP                  # R# )a^  The same round trip for a structured answer (``clarify``: ``ClarifyResult``): the viewer's
``result`` dict, or None on interrupt, timeout, an error response or no attached viewer.
``qids`` makes it a batch, which always ends with ``{answers: <locked so far>, outcome}`` once
asked: ``lock_answer`` (the ``clarify.lock`` verb) answers it per question.)rP   rS   r   N)rV   r   )r   r   r   rW   rP   rS   r   rN   s   &&&&$$$ r   Úask_viewer_resultr[   g   s)   € ô �6 vÀÐbfÔg€GØ$Ò0ˆ7�>‰>Ð:°dÐ:r   c               ó   € V ^8„  d   QhRR/# r!   r   )r%   s   "r   r&   r&   q   s   € ÷ uñ u¨4ñ ur   c                ó&  a aa€ \         ;_uu_ 4        \        ;QJ d3    V VV3R l\        P                  4        4       F  '       g   K   RM(	  RM$! V VV3R l\        P                  4        4       4      uuRRR4       #   + '       g   i     R# ; i)zXWhether a *method* request is open on this live session's stream (the card still waits).c              3  óš   <"  € T F@  qP                   S8H  ;'       d&    VP                  SJ ;'       d    VP                  S8H  x € KB  	  R # 5i)N)r   r   r   )Ú.0Úpr   r   r   s   & €€€r   Ú	<genexpr>Úwaiting.<locals>.<genexpr>t   sA   øé € ÐtÑesÐ`a—<‘< :Ñ-×[Ð[°!·(±(¸fÐ2D×[Ð[ÈÏÉÐU[ÑI[Ô[Óesùs   ƒA�A³ATFN)rK   Úanyr   r7   )r   r   r   s   fffr   Úwaitingrd   q   sF   ú€ ç	Žß‹sÖtÔej×eqÑeqÔesÓt�s�sŠsÖtÔej×eqÑeqÔesÓtÓt÷ 
��‹ús   ’4A?Á	+A?Á?B	c               ó   € V ^8„  d   QhRR/# )r"   r#   Úintr   )r%   s   "r   r&   r&   w   s   € ÷ 	ñ 	¨Cñ 	r   c           	     ó´  € \         ;_uu_ 4        \        \        P                  4       4       UUu. uFR  w  r4VP                  V8X  g   K  VP
                  V J g   K*  VP                  V8X  g   K=  \        P                  V4      NKT  	  pppRRR4       X F  pVP                  P                  4        K  	  \        V4      # u uppi   + '       g   i     LD; i)zÈSettle every open *method* request on this live session's stream with no answer, the way a
viewer that answered would: the asker reads None and every renderer gets ``request.cancel
reason: resolved``.N)rK   Úlistr   Úitemsr   r   r   rL   r
   rM   Úlen)r   r   r   Úridr`   ÚsettledrN   s   &&&    r   Úwithdrawrm   w   s§   € ÷ 
ŽÜ04´U·[±[³]Ô0Cô `Ñ0C¡f cØ—l‘l jÑ0ô "Ø56·X±XÀÐ5Gô "ØLMÏHÉHÐX^ÑL^ô "”5—9‘9˜S–>Ñ0Cˆñ `÷ 
ó ˆØ�‰×ÑÖñ äˆw‹<Ðùó	`÷ 
�ús.   �!C°C
Á
C
ÁC
Á/C
ÂCÃCÃC	c                ó   € R # rR   r   rG   s   &&r   rH   rH   ƒ   s   € ÑZ_r   c               ór  € \         ;_uu_ 4        \        P                  V 4      pVe2   VP                  e$   V! VP                  VP
                  4      '       g    RRR4       R# WP                  9  d   \        V4      hW$P                  V&   VP                   Uu. uF  qUVP                  9  g   K  VNK  	  ppV'       g3   \        P                  V R4       \        VP                  RR7      Vn
        RRR4       X'       g   XP                  P                  4        V# u upi   + '       g   i     L9; i)a´  Lock one answer of an open batch request (``clarify.lock``; editable until the last lock;
``None`` = skipped). Returns the question ids still unanswered; the lock that empties it settles
the request with ``{answers, outcome: submitted}``. ``None`` when no open batch has that id or the
caller may not answer its session (expired, or another profile's / session's request: see
:func:`resolve`); ``ValueError`` for an unknown question id.NÚ	submitted©Úended)rK   r   r)   r   r   r   Ú
ValueErrorr   rL   r   r   r
   rM   )Ú
request_idÚquestion_idÚanswerrE   rN   ÚqidÚ	remainings   &&&$   r   Úlock_answerry   ƒ   sß   € ÷ 
ŽÜ—)‘)˜JÓ'ˆØŠ?˜gŸl™lÒ2¹*ÀW×EWÑEWÐY`×YgÑYg×:hÒ:hØ÷ 
‰ð Ÿl™lÔ*Ü˜[Ó)Ð)Ø&,�‰�{Ñ#Ø$+§L¢LÓN¡L˜S¸w¿~¹~Ñ4M—S�S¡Lˆ	ÐNßÜ�I‰I�j $Ô'Ü)¨'¯.©.ÀÔLˆGŒN÷ 
÷ Ø�‰×ÑÔØÐùò O÷ 
�ús0   �A
D&ÁD&Á%7D&ÂD!Â3D!Â9<D&Ä!D&Ä&D6	c               ó¤  € V P                   P                  4       '       g   R # R\        P                  ! 4       P                  R,           2p\        WW4      p\        ;_uu_ 4        V\        V&   R R R 4       V P                   P                  RRRVRVRRV/VC/4       R	p	R
p
VP                  P                  \        4      '       g-   V	\        ,          p	V! 4       '       d   Rp
MVf   KH  W•8¼  g   KP   \        ;_uu_ 4        \        P                  VR 4      VJ pV'       d4   VP                  e&   \        VP                  V
R8X  d   RMRR7      Vn        R R R 4       X'       dX   \"        P$                  ! \&        4      ;_uu_ 4        V P)                  VRVRVRV
/RR7       R R R 4       VP                  e   V# R # \"        P$                  ! \&        4      ;_uu_ 4        V P)                  VRVRVRR/RR7       R R R 4       V#   + '       g   i     EL�; i  + '       g   i     LÊ; i  + '       g   i     L�; i  + '       g   i     T# ; i)Nr=   :Né   NÚjsonrpcz2.0r<   r   rW   r   g        rS   ÚinterruptedrP   Ú	timed_outrq   Úreasonzrequest.cancel)Ú
event_typeÚresolved)ÚfanoutÚ
transportsÚuuidÚuuid4Úhexr   rK   r   Úwriter
   ÚwaitÚ_POLL_SrL   r   r   r   r   Ú
contextlibÚsuppressÚ	ExceptionÚpublish)r   r   r   rW   rP   rS   r   rt   rN   Úwaitedr   Ú
still_opens   &&&&$$$     r   rV   rV   ™   sç  € Ø�=‰=×#Ñ#×%Ò%ÙØœŸ
š
›×(Ñ(¨Õ-Ð.Ð/€JÜ�z¨Ó8€Gß	ŽØ#ŒˆjÑ÷ 
à
‡M�M×Ñ˜ E¨4°¸XÀvØ! L°*Ð#GÀÐ#GðIô Jà€FØ€FØ�m‰m× Ñ ¤×)Ò)Ø”'ÕˆÙ�;Š;Ø"ˆFØØÔ 6Ö#4Øß	ŽÜ—Y‘Y˜z¨4Ó0°GÐ;ˆ
ß˜'Ÿ,™,Ò2ô *¨'¯.©.Ø?EÈÔ?V±Ð\gôiˆGŒN÷ 
÷ ô × Ò ¤×+Õ+Ø�N‰N˜:¨¨j¸(ÀFÈHÐV\Ð']Ø&6ð ô 8÷ ,ð "Ÿ,™,Ò2ˆwÐ<¸Ð<ô
 
×	Ò	œY×	'Õ	'Ø�‰�z D¨*°hÀÈÐR\Ð#]Ø"2ð 	ô 	4÷ 
(ð €N÷E 
�ˆú÷ 
�ú÷ ,×+ú÷ 
(Ö	'ð €Nús1   Á&
HÄAHÆH+ÇH>ÈH	ÈH(	È+H;	È>I	)Ú__conditional_annotations__Ú__doc__Ú
__future__r   rŠ   r   r„   Útools.clarify_batchr   ÚREQUEST_TIMEOUT_Sr‰   r   ÚLockrK   r   Ú__annotations__r-   r9   rD   rO   rX   r[   rd   rm   ry   rV   )r�   s   @r   Ú<module>r—      s½   øðô
õ #ã Û Û å ,àÐ Ø
€÷ñ ð" 	�ŠÓ€Ø€ÐÓ õSõCõ"\ðÑ!@÷ ð,8Áð 8ÐWh÷ 8ð;Á}ð ;Ð^oð ;Øô;õuõ	ðÑ?_ô ð,'Èö 'r   