+
    lHàj¿  ã                  ó"  € R t ^ RIHt ^ RIt^ RIHt ^ RIHtHtH	t	 ]P                  ! ]4      t. ROt^
t]! 0 Rm4      t]! RR7       ! R R4      4       tR	 R
 ltR R ltR R ltRR R lltR R ltRtR R ltR R ltR R ltR R ltR# )zŸConfiguration and availability gate for connector tools.

Availability fails closed; the gateway remains authoritative for entitlement and route availability.
)ÚannotationsN)Ú	dataclass)ÚAnyÚCallableÚOptionalÚConnectorConfigT)Úfrozenc                  ó<   € ] tR t^t$ RtR]R&   ]R R l4       tRtR# )r   TÚboolÚenabledc               ó    € V ^8„  d   QhRRRR/# )é   Úrawr   Úreturnr   © )Úformats   "ÚD/home/ubuntu/.hermes/hermes-agent/tools/connectors/gateway/config.pyÚ__annotate__ÚConnectorConfig.__annotate__#   s   € ÷ ñ ˜3ð  ?ñ ó    c                ó¾   € \        V\        4      '       d
   V ! VR7      # \        V\        4      '       d#   V ! \        VP	                  R4      R4      R7      # V ! 4       # )z:Malformed configuration falls back to the enabled default.)r   r   T)Ú
isinstancer
   ÚdictÚ_coerce_boolÚget)Úclsr   s   &&r   Úfrom_rawÚConnectorConfig.from_raw"   sK   € ô �cœ4× Ò Ù˜sÔ#Ð#Ü�cœ4× Ò Ùœ|¨C¯G©G°IÓ,>ÀÓEÔFÐFÙ‹uˆr   r   N)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   Ú__annotations__Úclassmethodr   Ú__static_attributes__r   r   r   r   r      s    ‡ ð €GˆTÓàôó ôr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úvaluer   Úfallbackr
   r   r   )r   s   "r   r   r   ,   s!   € ÷ 	ñ 	˜ð 	 tð 	°ñ 	r   c                ó  € \        V \        4      '       d   V # V f   V# \        V \        \        34      '       d   \        V 4      # \        V \        4      '       d&   V P                  4       P                  4       \        9  # V# )N)r   r
   ÚintÚfloatÚstrÚstripÚlowerÚ_FALSE_STRINGS)r&   r'   s   &&r   r   r   ,   se   € Ü�%œ×ÒØˆØ‚}ØˆÜ�%œ#œu˜×&Ò&Ü�E‹{ÐÜ�%œ×ÒØ�{‰{‹}×"Ñ"Ó$¬NÑ:Ð:Ø€Or   c               ó   € V ^8„  d   QhRR/# )r   r   r   r   )r   s   "r   r   r   8   s   € ÷ .ñ .�_ñ .r   c                 ó   €  ^ RI Hp  V ! 4       ;'       g    / p\        VP                  R4      \        4      '       d   VP                  R4      M/ p\        V\        4      '       g   / p\
        P                  VP                  R4      4      #   \         d6   p\        P                  RT4       \
        P                  R4      u Rp?# Rp?ii ; i)é    )Úload_config_readonlyÚtoolsÚ
connectorsz#Failed to load connector config: %sN)
Úhermes_cli.configr2   r   r   r   r   r   Ú	ExceptionÚloggerÚdebug)Ú_loadÚcfgÚ	tools_cfgÚes       r   Úload_configr=   8   s™   € ð
.ÝCá‹g�mˆm˜ˆÜ(2°3·7±7¸7Ó3CÄT×(JÒ(J�C—G‘G˜GÔ$ÐPRˆ	Ü˜)¤T×*Ò*ØˆIÜ×'Ñ'¨	¯©°lÓ(CÓDÐDøÜô .Ü�‰Ð:¸AÔ>Ü×'Ñ'¨Ó-Õ-ûð.ús#   ‚B –A6B ÂCÂ*CÃCÃCc               ó   € V ^8„  d   QhRR/# ©r   r   r
   r   )r   s   "r   r   r   F   s   € ÷ Rñ R $ñ Rr   c                 ón   € ^ RI Hp  V ! 4       p\        VP                  4      ;'       d    VP                  # )aÛ  The portal has enabled connectors for this account.

The gateway answers 404 to every ``/v1/connectors`` route for an account the portal has not
enabled, and 404 is indistinguishable from "dark" by design. Paid access or a free tool pool
says nothing about that, so entitlement is the wrong predicate here: the portal mints its
answer onto the token as ``managed_tools`` and this reads only that. A token minted before
the claim existed carries none and reads as not enabled.)Úget_nous_portal_account_info)Úhermes_cli.nous_accountrA   r
   Ú	logged_inÚmanaged_tools_rolled_out)rA   Úaccount_infos     r   rD   rD   F   s/   € õ Eá/Ó1€LÜ�×&Ñ&Ó'×QÐQ¨L×,QÑ,QÐQr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úconfig_loaderz'Optional[Callable[[], ConnectorConfig]]Úentitlement_checkzOptional[Callable[[], bool]]r   r
   r   )r   s   "r   r   r   T   s&   € ÷ ñ Ø:ðà3ðð 
ñr   c                óJ  €  T ;'       g    \         pV! 4       P                  '       g   R# Vf8   ^ RIHp ^ RIHp V! V! 4       4      '       g   \        4       '       d   R# \        p\        V! 4       4      #   \         d"   p\        P                  RT4        Rp?R# Rp?ii ; i)a©  Fail closed so availability failures do not become model-visible errors.

The one gate for the connectors surface, and the tool's ``check_fn``: outside it the tool is
not in the schema at all, so the model never narrates a gateway 404 to a user the portal has
not enabled. Free-tier identities are always in, and so is a user with no identity who may get
one; accounts are in only when the portal says so via the token claim.FN)Úis_guest_state)Ú_read_nous_provider_stateTz'Connector availability check failed: %s)r=   r   Úhermes_cli.anon_authrJ   Útools.managed_tool_gatewayrK   Úguest_identity_pendingrD   r
   r6   r7   r8   )rG   rH   Úresolved_loaderrJ   rK   r<   s   &&    r   Úconnectors_availablerP   T   s†   € ðØ'×6Ð6¬;ˆÙÓ ×(×(Ð(ÙØÒ$Ý;ÝLñ Ñ7Ó9×:Ò:Ô>T×>VÒ>VÙä 8ÐÜÑ%Ó'Ó(Ð(øÜô Ü�‰Ð>ÀÔBÝûðús-   ‚A6 ‹A6 «"A6 ÁA6 Á A6 Á6B"ÂBÂB"c               ó   € V ^8„  d   QhRR/# r?   r   )r   s   "r   r   r   q   s   € ÷ 	5ñ 	5 ñ 	5r   c                 ó¼   € ^ RI Hp Hp ^ RIHpHp V ! 4       '       d   V! 4       f   V! 4       '       d   R# V! 4       pV'       * ;'       g    \        VR,          4      # )z¯No Nous identity or bearer yet, and a guest one may be created (``nous.guest`` is not false
and no earlier mint was refused for good). No network: this feeds the ``check_fn``.)Úguest_allowedÚlast_mint_failure)rK   Úpeek_nous_access_tokenFÚ	retryable)rL   rS   rT   rM   rK   rU   r
   )rS   rT   rK   rU   Úfailures        r   rN   rN   q   sI   € ÷ Fß\á�?Š?Ñ7Ó9ÒEÑI_×IaÒIaÙÙÓ!€GØŒ;×4Ð4œ$˜w {Õ3Ó4Ð4r   z'Hosted connectors could not be set up. c               ó   € V ^8„  d   QhRR/# ©r   r   úOptional[str]r   )r   s   "r   r   r   €   s   € ÷ hñ h˜]ñ hr   c                 óz   € ^ RI Hp Hp V! 4       ;p'       g   R# \        V ! VR,          VR,          R7      ,           # )zZThe last failed guest creation for this profile, worded with the wait still left, or None.)Úanon_failure_copyrT   NÚ
error_codeÚretry_after)r^   )rL   r\   rT   Ú_SETUP_FAILED)r\   rT   rW   s      r   Úguest_setup_failurer`   €   s5   € çIá(Ó*Ð*ˆGÖ*ÙÜÑ,¨W°\Õ-BÐPWÐXeÕPfÔgÕgÐgr   c               ó   € V ^8„  d   QhRR/# rY   r   )r   s   "r   r   r   ‰   s   € ÷ Iñ I˜}ñ Ir   c                 óî   € \        4       '       g   R# ^ RIHp  ^ RIHp  V ! RR7      e   R#  \        4       ;'       g    \
        R,           #   T d!   p\
        \        T4      ,           u Rp?# Rp?ii ; i)a  Create the guest identity on the first hosted connector action, synchronously.

Returns None when an identity exists or was just created, else the failure copy for the model:
a refusal, a rate limit or an unreachable portal, with the wait when there is one.N)Úensure_portal_identity)Ú	AuthErrorT)ÚexplicitzTry again shortly.)rN   rL   rc   Úhermes_cli.auth_constantsrd   r_   r+   r`   )rc   rd   Úexcs      r   Úensure_guest_identityrh   ‰   sh   € ô
 "×#Ò#ÙÝ;Ý3ð(Ù!¨4Ô0Ò<Ùð =ô Ó ×HÐH¤MÐ4HÕ$HÐHøð ô (Üœs 3›xÕ'Õ'ûð(ús    A ÁA4ÁA/Á)A4Á/A4c               ó    € V ^8„  d   QhRRRR/# )r   Ú
session_idrZ   r   r+   r   )r   s   "r   r   r   ›   s   € ÷ Nñ N mð N¸ñ Nr   c                óZ   € ^ RI Hp V! RR4      ;'       g    \        T ;'       g    R4      # )aR  The key an operation is registered under: the gateway session key the RPCs look up by
(``HERMES_SESSION_KEY``), falling back to the agent's session id where no gateway bound one.
The agent id alone is wrong on the desktop: compaction rotates it mid-turn while the gateway
key stays, and a card keyed by the old id can no longer be driven.©Úget_session_envÚHERMES_SESSION_KEYÚ )Úgateway.session_contextrm   r+   )rj   rm   s   & r   Úoperation_session_keyrq   ›   s*   € õ
 8áÐ/°Ó4×MÐM¼¸J×<LÐ<LÈ"Ó8MÐMr   c               ó   € V ^8„  d   QhRR/# )r   r   r+   r   )r   s   "r   r   r   ¥   s   € ÷ /ñ /˜#ñ /r   c                 ó¤   € ^ RI Hp  V ! RR4      ;'       g
    V ! RR4      p\        T;'       g    R4      P                  4       P	                  4       # )r1   rl   ÚHERMES_SESSION_PLATFORMro   ÚHERMES_SESSION_SOURCE)rp   rm   r+   r,   r-   )rm   Úplatforms     r   Úsession_platformrw   ¥   sF   € Ý7áÐ8¸"Ó=×mÐmÁÐQhÐjlÓAm€HÜˆx�~ˆ~˜2Ó×$Ñ$Ó&×,Ñ,Ó.Ð.r   )ÚMAX_CALLS_PER_DISPATCHr   rP   rh   rN   r=   >   ro   Ú0ÚnoÚoffÚfalse)NN)Ú__doc__Ú
__future__r   ÚloggingÚdataclassesr   Útypingr   r   r   Ú	getLoggerr   r7   Ú__all__rx   Ú	frozensetr.   r   r   r=   rD   rP   rN   r_   r`   rh   rq   rw   r   r   r   Ú<module>r…      s›   ðñõ
 #ã Ý !ß *Ñ *à	×	Ò	˜8Ó	$€ò€ð Ð áÒ:Ó;€ñ �$Ô÷ð ó ðõ	õ.õR÷õ:	5ð :€õhõIõ$N÷/r   