Ë
    áß²j[  ã                   óÂ   — U d Z ddlZddlmZmZ ddlmZ ddedee   defd„Zdded	ee   defd
„Z	de
dee   fd„ZdZeeedœZeeee   f   ed<   dee   dee   fd„Zy)z>Endpoint identity for auxiliary custom-provider health checks.é    N)ÚAnyÚOptional)Únormalize_route_base_urlÚproviderÚbase_urlÚreturnc                 óx   — ddl m} ddlm}  || «      }t	        t        | |«      «      } |«       }|r|d|fS ||fS )u  Provider-wide key, or endpoint-specific key for an explicit custom endpoint â€” prefixed with the
    active profile home: a 402 on profile A's account must not hide the provider from profile B's
    (differently funded) account in the same multiplexed process.r   ©Ú_normalize_chain_label)Úhermes_home_keyzcustom-endpoint)Úagent.auxiliary_clientr   Úhermes_constantsr   r   Ú_custom_health_base_url)r   r   r   r   ÚlabelÚendpointÚhome_keys          ú;/home/ubuntu/.hermes/hermes-agent/agent/auxiliary_health.pyÚ_unhealthy_cache_keyr      sI   € õ >Ý0Ù" 8Ó,€EÜ'Ô(?ÀÈ(Ó(SÓT€HÙÓ €HÙØÐ*¨HÐ4Ð4Ø�Uˆ?Ðó    Úexplicit_base_urlc                 óÜ  — ddl m} t        |xs d«      j                  «       }ddl m}  || «      }|dk(  r|xs  |«       S |j                  d«      r|r|S t        j                  t        «      5  ddl	m
}m}  ||«      r|xs  |«       cddd«       S  || «      }|r9|xs, t        |j                  d	«      xs d«      j                  «       cddd«       S 	 ddd«       y# 1 sw Y   yxY w)
zQReturn the concrete custom endpoint used to scope health and failed-route checks.r   )Ú_current_custom_base_urlÚ r
   zlocal/customzcustom:)Ú_get_named_custom_providerÚ_resolves_to_customNr   )r   r   ÚstrÚstripr   Ú
startswithÚ
contextlibÚsuppressÚImportErrorÚhermes_cli.runtime_providerr   r   Úget)	r   r   r   Úexplicitr   r   r   r   Úentrys	            r   r   r      sé   € å?ÜÐ$Ò*¨Ó+×1Ñ1Ó3€HÝ=Ù" 8Ó,€EØ�ÒØÒ5Ñ3Ó5Ð5Ø×Ñ˜	Ô"¡xØˆÜ	×	Ñ	œ[Ó	)ñ Hß_Ù˜uÔ%ØÒ9Ñ7Ó9÷Hñ Hñ +¨8Ó4ˆÙØÒGœs 5§9¡9¨ZÓ#8Ò#>¸BÓ?×EÑEÓG÷Hñ Hð
 ÷Hð ÷Hð ús   Á0C"Â9C"Ã"C+Úexcc                 ó:   ‡ — ddl m} t        ˆ fd„|D «       d«      S )a+  Why a fallback candidate cannot serve this walk (``_FALLBACK_REASONS`` label), or None.

    The same capacity classes that admitted the primary failure into the chain (payment/quota,
    rate limit, connection, route-incompatible model, malformed response) mean "this lane is out
    for now, try the next configured one"; anything else (a 400 request-shape error, a ValueError)
    is the caller's bug and must still propagate. Auth errors are excluded on purpose: they have
    their own refresh-then-quarantine path in the candidate helpers (#106367).r   )Ú_FALLBACK_REASONSc              3   óF   •K  — | ]  \  }}|d k7  sŒ |‰«      sŒ|–— Œ y­w)z
auth errorN© )Ú.0Ú	predicater   r&   s      €r   ú	<genexpr>z8fallback_candidate_unavailable_reason.<locals>.<genexpr>5   s&   øè ø€ ÒeÑ#�9˜e¸EÀ\Ó<QÑV_Ð`cÕVdŒÑeùs   ƒ!‘!š!N)r   r(   Únext)r&   r(   s   ` r   Ú%fallback_candidate_unavailable_reasonr/   +   s!   ø€ õ 9ÜÛeÐ'8ÔeØóð r   g      N@)z
rate limitzconnection errorzinvalid provider responseÚ_CANDIDATE_QUARANTINE_TTLÚreasonc                 ó4   — t         j                  | xs d«      S )z™Seconds to hide a fallback candidate for ``reason`` (a ``_FALLBACK_REASONS`` label, or None
    for a stale credential); None means the long default TTL.r   )r0   r#   )r1   s    r   Ú!fallback_candidate_quarantine_ttlr3   F   s   € ô %×(Ñ(¨ª°2Ó6Ð6r   )N)Ú__doc__r   Útypingr   r   Úhermes_cli.route_identityr   r   r   r   Ú	Exceptionr/   Ú'_TRANSIENT_CANDIDATE_QUARANTINE_SECONDSr0   ÚdictÚfloatÚ__annotations__r3   r*   r   r   ú<module>r<      s®   ðÚ DÛ ß  å >ñ 3ð °(¸3±-ð È3ó ñ cð ¸hÀs¹mð ÐWZó ð,¨yð ¸XÀc¹]ó ð& +/Ð 'à9Ø?Ø!Hñ9Ð ˜4  X¨e¡_Ð 4Ñ5ó ð7¨h°s©mð 7ÀÈÁô 7r   