+
    lHàj  ã                  ó,  € R t ^ RIHt ^ RIHtHtHt ^ RIHtH	t	H
t
 . R"Ot ! R R]4      t ! R	 R]4      t ! R
 R]4      t ! R R]4      t ! R R]4      tR#R R lltRtRtRtRtRtR]
]]]/R]
]]]]	]//tRRRRRRRRR]	RR/R R lltR  R! ltR# )$z¯Gateway HTTP errors and envelope parsing.

Per-tool execute failures are result entries, not exceptions; connection links are intentionally unredacted for the model to relay.
)Úannotations)ÚAnyÚMappingÚOptional)ÚCARDÚLINKÚSIDEÚGatewayAuthErrorÚGatewayUnavailableÚIdempotencyConflictÚToolGatewayErrorc                  óF   a € ] tR t^tRtRRRRRRRR/R	 V 3R
 llltRtV ;t# )r   zLHTTP-level gateway failure; ``retryable`` is decided by the envelope parser.ÚcodeÚGATEWAY_ERRORÚstatusNÚ
request_idÚ	retryableFc               ó0   € V ^8„  d   QhRRRRRRRRRR	R
R/# )é   ÚmessageÚstrr   r   zOptional[int]r   úOptional[str]r   ÚboolÚreturnÚNone© )Úformats   "ÚD/home/ubuntu/.hermes/hermes-agent/tools/connectors/gateway/errors.pyÚ__annotate__ÚToolGatewayError.__annotate__   sF   € ÷ #ñ #àð#ð ð	#ð
 ð#ð "ð#ð ð#ð 
ñ#ó    c               	óV   <€ \         SV `  V4       W n        W0n        W@n        WPn        R # ©N)ÚsuperÚ__init__r   r   r   r   )Úselfr   r   r   r   r   Ú	__class__s   &&$$$$€r   r$   ÚToolGatewayError.__init__   s&   ø€ ô 	‰Ñ˜Ô!ØŒ	ØŒØ$ŒØ"Žr    )r   r   r   r   ©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r$   Ú__static_attributes__Ú__classcell__©r&   s   @r   r   r      s=   ø† ÙVð#ð $ð	#ð
 !%ð#ð %)ð#ð  ÷#÷ #ð #r    c                  ó   € ] tR t^*tRtRtR# )r	   z&Authentication or entitlement failure.r   N©r)   r*   r+   r,   r-   r.   r   r    r   r	   r	   *   s   † Ý0r    c                  ó   € ] tR t^.tRtRtR# )r
   z?404 signals callers to degrade silently to local-only behavior.r   Nr2   r   r    r   r
   r
   .   s   † ÝIr    c                  ó   € ] tR t^2tRtRtR# )r   z;Never retry a reused idempotency key with a different body.r   Nr2   r   r    r   r   r   2   s   † ÝEr    c                  ó2   a € ] tR t^6tRtR V 3R lltRtV ;t# )ÚRateLimitedzQ429 with the gateway's retry hint in seconds; the caller decides whether to wait.c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   r   r   Úretry_afterÚfloatÚkwargsr   r   r   r   )r   s   "r   r   ÚRateLimited.__annotate__9   s(   € ÷ 'ñ ' ð '°Uð 'Àcð 'Èdñ 'r    c               	ó6   <€ \         SV `  ! V3/ VB  W n        R # r"   )r#   r$   r8   )r%   r   r8   r:   r&   s   &&$,€r   r$   ÚRateLimited.__init__9   s   ø€ Ü‰Ò˜Ñ+ FÒ+Ø&Ör    )r8   r(   r0   s   @r   r6   r6   6   s   ø† Ù[÷'ö 'r    r6   Nc               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   r   ÚintÚbodyr   ÚheaderszOptional[Mapping[str, Any]]r   r   r   )r   s   "r   r   r   >   s0   € ÷ ,Hñ ,H ð ,H¨3ð ,HÐ9Tð ,HÐ`pñ ,Hr    c                ón  € RV  2pRpRpRp\        V\        4      '       Ed=   VP                  R4      p\        V\        4      '       dJ   \        VP                  R4      ;'       g    T4      p\        VP                  R4      ;'       g    R4      pMn\        V\        4      '       d   V'       d   TpMMVP                  R4      '       d7   \        VR,          4      p\        VP                  R4      ;'       g    R4      pVP                  R4      pVe   \        V4      p\        VP                  R4      \        \
        34      '       d   \        VR,          4      pMV'       d   \        V4      R	,          pV'       g   R
V  2pRVRV RV/p	V R9   d   \        V3/ V	B # V R8X  d   \        V3/ V	B # V R8X  d   \        V3/ V	B # V R8X  dY   V'       d   T;'       g    / P                  R4      MRp
V
R9  d   \        V
4      MT;'       g    RR,          p\        V3RV/V	B # \        V3RV R8¬  /V	B # )a  Parse every gateway error envelope without raising on a malformed body.

Three envelope shapes exist: ``{error: {code, message}}`` on most routes, ``{error: "<code>"}``
on the account routes, and a flat ``{code, message, requestId, retryAfterMs}`` on a 429.ÚHTTP_Ú NÚerrorr   r   Ú	requestIdÚretryAfterMs:Niô  Nz(tool gateway request failed with status r   r   i”  i™  i­  zRetry-Afterg     @�@r8   r   iô  )i‘  i“  )NrD   )Ú
isinstancer   Úgetr   r?   r9   r	   r
   r   r6   r   )r   r@   rA   r   r   r   Úretry_after_msÚenvelopeÚraw_request_idr:   Úheaderr8   s   &&&         r   Úparse_gateway_errorrN   >   s   € ð
 �6�(Ð€DØ€GØ€JØ&*€NÜ�$œ× Ó Ø—8‘8˜GÓ$ˆÜ�h¤×(Ò(Ü�x—|‘| FÓ+×3Ð3¨tÓ4ˆDÜ˜(Ÿ,™, yÓ1×7Ð7°RÓ8‰GÜ˜¤#×&Ò&¯8Ø‰DØ�X‰X�f×ÒÜ�t˜F•|Ó$ˆDÜ˜$Ÿ(™( 9Ó-×3Ð3°Ó4ˆGØŸ™ +Ó.ˆØÒ%Ü˜^Ó,ˆJÜ�d—h‘h˜~Ó.´´e°×=Ò=Ü" 4¨Õ#7Ó8ˆNøß	Ü�d“)˜D•/ˆßØ<¸V¸HÐEˆð 	�Ø�&Ø�jð€Fð
 �ÔÜ Ñ2¨6Ñ2Ð2Ø�„}Ü! 'Ñ4¨VÑ4Ð4Ø�„}Ü" 7Ñ5¨fÑ5Ð5Ø�„}ß7>�'—-�-˜R×$Ñ$ ]Ô3ÀDˆØ'-°ZÔ'?”e˜F”mÀn×F^ÐF^ÐX^ÐbhÕEhˆÜ˜7ÑF°ÐF¸vÑFÐFÜ˜GÑG¨v¸©}ÐGÀÑGÐGr    zxThis app is not connected. Only the main agent can connect it, so report that back instead of trying to connect it here.zwThis app is not connected. Call manage_connections to open a connection card for it; there is no link to show the user.z€This app's connection expired. Only the main agent can reconnect it, so report that back instead of trying to reconnect it here.z“This app's connection expired. Call manage_connections with action 'reconnect' to open a connection card for it; there is no link to show the user.zXThe connection expired. Show the user the connect_url to reconnect, then retry the call.ÚCONNECTION_REQUIREDÚCONNECTION_EXPIREDÚ	connectorr   Úconnect_urlÚhintÚsurfacer   c               ó4   € V ^8„  d   QhRRRRRRRRRRRRR	R
/# )r   rQ   r   r   rR   rS   rT   r   r   r   zdict[str, Any]r   )r   s   "r   r   r   Š   sP   € ÷  ñ  àð ð ð ð ð	 ð
 ð ð ð ð ð ð ñ r    c                ó~  € \         P                  V\         R,          4      pRTRT;'       g    \        WP4      /pV '       d   WR&   V\        8X  d   V\        ,          VR&   V# V\        8X  d   RVR&   V\        ,          VR&   V# V'       d$   W'R&   T;'       g    VP                  \
        4      pV'       d   W7R&   V# )	zØThe model-facing shape for an app the call cannot use until the user connects it.

``code`` is CONNECTION_REQUIRED or CONNECTION_EXPIRED; both keep the card and link behaviour,
the expired one with reconnect wording.rO   r   r   rQ   rS   TÚconnect_card_availablerR   )Ú_HINTSrI   Ú_default_messager   r   r   )rQ   r   rR   rS   rT   r   ÚhintsÚpayloads   $$$$$$  r   Úrender_connection_requiredr\   Š   s²   € ô �J‰J�tœVÐ$9Õ:Ó;€Eà�Ø�7×?Ð?Ô.¨tÓ?ð€G÷ Ø(�ÑØ”$„Ø¤�+ˆ�‰ØˆØ”$„Ø,0ˆÐ(Ñ)Ø¤�+ˆ�‰ØˆßØ!,�ÑØ×&Ð&�u—y‘y¤“ˆßØ�‰Ø€Nr    c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   rQ   r   r   r   )r   s   "r   r   r   ­   s!   € ÷ 7ñ 7˜3ð 7¨=ð 7¸Sñ 7r    c                óD   € V'       d   R V R2MRpV R8X  d   V R2# V R2# )zThe z
 connectorzThis connectorrP   zA connection for this account has expired and must be reconnected.z# is not connected for this account.r   )r   rQ   Úapps   && r   rY   rY   ­   s:   € ß*3ˆD��˜:Ñ
&Ð9I€CØÐ#Ô#Ø�ÐWÐXÐXØˆUÐ5Ð6Ð6r    )ÚSIDE_AGENT_HINTr	   r
   r   r   rN   r\   r"   )r-   Ú
__future__r   Útypingr   r   r   Útools.connectors.turnr   r   r   Ú__all__ÚRuntimeErrorr   r	   r
   r   r6   rN   r`   Ú	CARD_HINTÚEXPIRED_SIDE_AGENT_HINTÚEXPIRED_CARD_HINTÚEXPIRED_LINK_HINTrX   r\   rY   r   r    r   Ú<module>rj      s  ðñõ
 #ç )Ñ )ç 2Ñ 2ò€ô#�|ô #ô&1Ð'ô 1ôJÐ)ô JôFÐ*ô Fô'Ð"ô '÷,Hð`,ð ð)ð 
ð.ð ðAð ð
 oÐ ð ˜D /°4¸ÐCØ˜4Ð!8¸$Ð@QÐSWÐYjÐkð
€ð à#ð ð "ð ð "&ð	 ð
 ð ð ð ð &÷ ÷F7r    