+
    lHàjß   ã                  óR  a € 0 t $ R t^ RIHt ^ RIt^ RIt^ RIHt ^ RIH	t	 ^RI
HtHtHt ]P                  ! ]4      t]! RR7       ! R R	4      4       t]! RR7       ! R
 R4      4       t]! RR7       ! R R4      4       t/ tR]R&   / tR]R&   / tR]R&   / tR]R&   R R ltRR/R R lltRR/R R lltRR/R R lltR4RR/R R  lllt]! ]P>                  PA                  R!4      4      t! ! R" R#]"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)R0 R1 lt*R2 R3 lt+R# )5uª  The contract catalog: every method, serverâ†’client request and event the gateway speaks.

Three tables, filled by the ``contracts.*`` topic modules at import time and read by
``tui_gateway/server.py`` (runtime validation) and ``scripts/gen_gateway_contracts.py``
(TypeScript + OpenRPC rendering). A handler registered with ``@method`` for a name that has
no contract here fails at import: the wire has no undeclared surface.
)ÚannotationsN)Ú	dataclass)ÚValidationError)ÚParamsÚPayloadÚResultT)Úfrozenc                  óD   € ] tR t^t$ R]R&   R]R&   R]R&   RtR]R&   R	tR
# )ÚMethodContractÚstrÚnameútype[Params]Úparamsútype[Result]ÚresultÚ Údoc© N©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__annotations__r   Ú__static_attributes__r   ó    ÚC/home/ubuntu/.hermes/hermes-agent/tui_gateway/contracts/registry.pyr
   r
      s   ‡ à
ƒIØÓØÓØ€Cˆ‡Mr   r
   c                  óH   € ] tR t^t$ RtR]R&   R]R&   R]R&   RtR]R	&   R
tR# )ÚServerRequestContractzBA question the backend asks the client (``server_requests.send``).r   r   r   r   r   r   r   r   r   N)r   r   r   r   Ú__doc__r   r   r   r   r   r   r   r      s   ‡ áLà
ƒIØÓØÓØ€Cˆ‡Mr   r   c                  ó:   € ] tR t^(t$ R]R&   R]R&   RtR]R&   RtR# )	ÚEventContractr   r   útype[Payload] | NoneÚpayloadr   r   r   Nr   r   r   r   r!   r!   (   s   ‡ à
ƒIØ!Ó!Ø€Cˆ‡Mr   r!   zdict[str, MethodContract]ÚMETHODSÚCANONICAL_METHODSz dict[str, ServerRequestContract]ÚSERVER_REQUESTSzdict[str, EventContract]ÚEVENTSc               ó    € V ^8„  d   QhRRRR/# )é   ÚtableÚdictÚreturnÚNoner   )Úformats   "r   Ú__annotate__r/   7   s   € ÷ ñ �Dð  Dñ r   c                ót   € VP                   V 9   d   \        R VP                    24      hWVP                   &   R# )zcontract declared twice: N)r   ÚRuntimeError)r*   Úentrys   &&r   Ú_declarer3   7   s3   € ð ‡z�z�UÔÜÐ6°u·z±z°lÐCÓDÐDØˆ%�*‰*Ór   r   r   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,   r
   r   )r.   s   "r   r/   r/   ?   s0   € ÷ ñ �ð  ð °|ð È#ð ÐWeñ r   c               ó>   € \        WW#4      p\        \        V4       V# ©N)r
   r3   r$   ©r   r   r   r   r2   s   &$$$ r   Úmethodr9   ?   s   € Ü˜4¨Ó5€EÜŒW�eÔØ€Lr   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR	/# r5   r   )r.   s   "r   r/   r/   E   s1   € ÷ ñ ˜3ð ¨<ð Àð ÐTWð Ðaoñ r   c               ó>   € \        WW#4      p\        \        V4       V# r7   )r
   r3   r%   r8   s   &$$$ r   Úcanonical_methodr<   E   s   € Ü˜4¨Ó5€EÜÔ Ô&Ø€Lr   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,   r   r   )r.   s   "r   r/   r/   K   s1   € ÷ ñ ˜ð ¨ð ¸|ð ÐRUð Ð_tñ r   c               ó>   € \        WW#4      p\        \        V4       V# r7   )r   r3   r&   r8   s   &$$$ r   Úserver_requestr?   K   s   € Ü! $°Ó<€EÜŒ_˜eÔ$Ø€Lr   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r)   r   r   r#   r"   r   r,   r!   r   )r.   s   "r   r/   r/   Q   s*   € ÷ ñ �ð Ð2ð À3ð ÐP]ñ r   c               ó>   € \        WV4      p\        \        V4       V# r7   )r!   r3   r'   )r   r#   r   r2   s   &&$ r   ÚeventrB   Q   s   € Ü˜$¨Ó-€EÜŒV�UÔØ€Lr   ÚHERMES_TEST_ISOLATIONc                  ó   € ] tR t^_tRtRtR# )ÚContractViolationzNA result or payload the gateway produced does not match its declared contract.r   N)r   r   r   r   r   r   r   r   r   rE   rE   _   s   † ÝXr   rE   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r)   Úkindr   r   Úexcr   r,   r-   r   )r.   s   "r   r/   r/   c   s.   € ÷ Jñ J�#ð J˜Sð J ð J¸4ñ Jr   c                óv   € \         '       d   \        V  R V: RV 24      Vh\        P                  RWV4       R# )Ú z violates its contract: z$%s %r violates its wire contract: %sN)ÚSTRICTrE   ÚloggerÚerror)rG   r   rH   s   &&&r   Ú_reportrN   c   s8   € ßƒvÜ 4 &¨¨$©Ð1IÈ#ÈÐ OÓPÐVYÐYÜ
‡L�LÐ7¸ÀSÖIr   c               ó$   € V ^8„  d   QhRRRRRR/# )r)   Úcontractú&MethodContract | ServerRequestContractr   r+   r,   ztuple[dict | None, str | None]r   )r.   s   "r   r/   r/   i   s#   € ÷ ñ ÐDð Èdð ÐWuñ r   c                ó’  €  V P                   P                  V4       VR3#   \         d›   pTP                  4        Fy  pTP	                  R4      R8X  g   K  RP                  R TP	                  RR4       4       4      ;'       g    RpRRT P                   R	T R	TP	                  R
4       R23u u Rp?# 	   Rp?TR3# Rp?ii ; i)uÃ  Reject UNKNOWN keys (``4000`` with the key path) â€” the one check no handler performs, and the
one that catches a renamed or misspelled field on either side. Required / type errors are left to
the handler, which owns its documented domain codes (``4006`` missing session_id, ``4015`` bad
url, â€¦) and which clients already branch on; ``check_params_accepted`` closes the loop by
flagging a handler that SUCCEEDS on params the contract calls invalid.ÚtypeÚextra_forbiddenÚ.c              3  ó8   "  € T F  p\        V4      x € K  	  R # 5ir7   ©r   ©Ú.0Úps   & r   Ú	<genexpr>Ú"validate_params.<locals>.<genexpr>t   s   é € ÐBÑ/A¨!œs 1Ÿv˜vÓ/Aùó   ‚Úlocr   Nzinvalid params for z: Úmsguq    â€” the client and the Hermes backend are out of sync (different versions); run `hermes update` and restart bothr   )r   Úmodel_validater   ÚerrorsÚgetÚjoinr   )rP   r   rH   Úerrr^   s   &&   r   Úvalidate_paramsre   i   sÄ   € ð2Ø�‰×&Ñ& vÔ.ð �4ˆ<Ðøô ô 2Ø—:‘:–<ˆCØ�w‰w�v‹Ð"3Ö3Ø—h‘hÑB¨s¯w©w°u¸bÔ/AÓBÓB×NÐNÀh�ØÐ 3°H·M±M°?À"ÀSÀEÈÈCÏGÉGÐTYËNÐK[ð \1ð 1ð 2÷ 2õ  ð �4ˆ<Ðûð2ús,   ‚! ¡C¬&CÁ.CÂ+CÂ1CÂ7CÃCc               ó$   € V ^8„  d   QhRRRRRR/# )r)   rP   r
   r   r+   r,   z	list[str]r   )r.   s   "r   r/   r/   {   s!   € ÷ ñ  ~ð ¸tð È	ñ r   c                ó¦  €  V P                   P                  V4       . #   \         d§   pTP                  4        Uu. uF{  pT P                  \
        9   d   TP                  R4      R8w  g   K0  MTP                  R4      R9   g   KI  RP                  R TP                  RR	4       4       4      ;'       g    RNK}  	  Mu upi upu Rp?# Rp?ii ; i)
u  Key paths the canonical dispatcher refuses (``4001 invalid_params``): unknown and missing
keys â€” the closed set its handlers enforced by hand. Value/type checks stay in the handlers,
which own their domain reasons (``stale_generation``, ``not_found``, â€¦).rS   ÚmissingrU   c              3  ó8   "  € T F  p\        V4      x € K  	  R # 5ir7   rW   rX   s   & r   r[   Ú+canonical_param_problems.<locals>.<genexpr>„   s   é € Ð<Ñ); Aœ˜QŸ˜Ó);ùr]   r^   r   N)rT   rh   r   )r   r`   r   ra   r   r$   rb   rc   )rP   r   rH   rd   s   &&  r   Úcanonical_param_problemsrk   {   sÂ   € ðMØ�‰×&Ñ& vÔ.ð €Iøô ô Mð UX×T^ÑT^ÔT`ó MÑT`ÈSØ4<·M±MÄWÔ4L�C—G‘G˜F“O yÑ0ô IØ0ØŸ™ ›Ð,JÑJô I�—‘Ñ<¨¯©°¸Ô);Ó<Ó<×HÐHÀÒHÒT`ùô Mõ 	MûðMús7   ‚ ŸCªC¼-B>Á.B>Â.B>Â6B>Â=CÃCÃCc               ó$   € V ^8„  d   QhRRRRRR/# )r)   rP   rQ   r   r+   r,   r-   r   )r.   s   "r   r/   r/   Š   s$   € ÷ :ñ :Ð$Jð :ÐTXð :Ð]añ :r   c                óž   €  V P                   P                  V4       R#   \         d#   p\        RT P                  T4        Rp?R# Rp?ii ; i)zþThe handler answered with a result: the params it accepted must be valid under the
contract, else the contract is narrower than the wire (a required field that is optional in
practice, a type the handler coerces). Same strict/error-log policy as results.zparams accepted byN)r   r`   r   rN   r   )rP   r   rH   s   && r   Úcheck_params_acceptedrn   Š   s=   € ð:Ø�‰×&Ñ& vÖ.øÜô :ÜÐ$ h§m¡m°S×9Ò9ûð:úó   ‚ ŸAªAÁAc               ó$   € V ^8„  d   QhRRRRRR/# )r)   rP   rQ   r   r+   r,   r-   r   )r.   s   "r   r/   r/   ”   s#   € ÷ 1ñ 1ÐAð 1È4ð 1ÐTXñ 1r   c                óž   €  V P                   P                  V4       R#   \         d#   p\        R T P                  T4        Rp?R# Rp?ii ; i)z	result ofN)r   r`   r   rN   r   )rP   r   rH   s   && r   Úcheck_resultrr   ”   s<   € ð1Ø�‰×&Ñ& vÖ.øÜô 1Ü�˜XŸ]™]¨C×0Ò0ûð1úro   c               ó$   € V ^8„  d   QhRRRRRR/# )r)   r   r   r#   zdict | Noner,   r-   r   )r.   s   "r   r/   r/   ›   s!   € ÷ )ñ )˜ð ) kð )°dñ )r   c                ó.  € \         P                  V 4      pVf   R # VP                  f!   V'       d   \        RV \	        V4      4       R #  VP                  P                  T;'       g    / 4       R #   \         d   p\        RY4        R p?R # R p?ii ; i)Nz
payload of)r'   rb   r#   rN   Ú_no_payload_errorr`   r   )r   r#   rP   rH   s   &&  r   Úcheck_payloadrv   ›   s{   € Ü�z‰z˜$Ó€HØÒñ 	Ø×ÑÒßÜ�L $Ô(9¸'Ó(BÔCÙð)Ø×Ñ×'Ñ'¨¯¨°2Ö6øÜô )Ü�˜d×(Ò(ûð)ús   ÁA2 Á)A2 Á2BÁ=BÂBc               ó(   € V ^8„  d   QhRRRRRRRR/# )r)   Úmethodszdict[str, object]Úemitted_eventszset[str]Úserver_requestsr,   r-   r   )r.   s   "r   r/   r/   «   s1   € ÷ dñ dÐ.ð dÀð dÐ[cð dÐhlñ dr   c                óD  € . p\        \        V 4      \        \        4      ,
          4      ;p'       d   VP                  RV 24       \        \        \        4      \        V 4      ,
          4      ;p'       d   VP                  RV 24       \        V\        \        4      ,
          4      ;p'       d   VP                  RV 24       \        \        \        4      V,
          4      ;p'       d   VP                  RV 24       \        V\        \
        4      ,
          4      ;p'       d   VP                  RV 24       \        \        \
        4      V,
          4      ;p'       d   VP                  RV 24       V'       d"   \        RRP                  V4      ,           4      hR	# )
z‹Every registered method / emitted event name / sent server request has a contract, and no
contract is orphaned. Raises with the full lists.zmethods without a contract: z"method contracts with no handler: zevents without a contract: zevent contracts nothing emits: z$server requests without a contract: z(server request contracts nothing sends: z'tui_gateway/contracts is incomplete:
  z
  N)ÚsortedÚsetr$   Úappendr'   r&   rE   rc   )rx   ry   rz   Úproblemsrh   Úorphans   &&&   r   Úassert_completer�   «   sD  € ð €HÜœ˜W›¬¬G«Õ4Ó5Ð5€wÖ5Ø�‰Ð6°w°iÐ@ÔAÜœœG›¤s¨7£|Õ3Ó4Ð4€vÖ4Ø�‰Ð<¸V¸HÐEÔFÜ˜¬#¬f«+Õ5Ó6Ð6€wÖ6Ø�‰Ð5°g°YÐ?Ô@ÜœœF› nÕ4Ó5Ð5€vÖ5Ø�‰Ð9¸&¸ÐBÔCÜ˜¬3¬Ó+?Õ?Ó@Ð@€wÖ@Ø�‰Ð>¸w¸iÐHÔIÜœœOÓ,¨Õ>Ó?Ð?€vÖ?Ø�‰ÐBÀ6À(ÐKÔLßÜÐ JÈVÏ[É[ÐYaÓMbÕ bÓcÐcñ r   c               ó    € V ^8„  d   QhRRRR/# )r)   r#   r+   r,   r   r   )r.   s   "r   r/   r/   ¿   s   € ÷ (ñ (˜tð (¨ñ (r   c                óŽ   €  ! R  R\         4      p VP                  V 4       \        R4      h  \         d   pTu Rp?# Rp?ii ; i)c                  ó   € ] tR t^ÀtRtR# )Ú!_no_payload_error.<locals>._Emptyr   N)r   r   r   r   r   r   r   r   Ú_Emptyr…   À   s   † Ûr   r†   NÚunreachable)r   r`   r   ÚAssertionError)r#   r†   rH   s   &  r   ru   ru   ¿   sE   € ô”ô ðØ×Ñ˜gÔ&ô ˜Ó
'Ð'øô ô Ø�
ûðús   ‘- ­A¸?¹A¿Ar7   ),Ú__conditional_annotations__r   Ú
__future__r   ÚloggingÚosÚdataclassesr   Úpydanticr   Úbaser   r   r   Ú	getLoggerr   rL   r
   r   r!   r$   r   r%   r&   r'   r3   r9   r<   r?   rB   ÚboolÚenvironrb   rK   rˆ   rE   rN   re   rk   rn   rr   rv   r�   ru   )r‰   s   @r   Ú<module>r“      sL  øðôõ #ã Û 	Ý !å $ç )Ñ )à	×	Ò	˜8Ó	$€ñ �$Ô÷ð ó ðñ �$Ô÷ð ó ðñ �$Ô÷ð ó ðð &(€Ð	"Ó 'ð 02Ð Ð,Ó 1Ø46€Ð1Ó 6Ø#%€Ð Ó %õðÐPR÷ ðÐZ\÷ ðÐXZ÷ ñÈ÷ ð ñ 
ˆb�j‰j�n‰nÐ4Ó5Ó	6€ôY˜ô YõJõõ$õ:õ1õ)õ d÷((r   