+
    „WÝjF”  ã                  óÎ  a € 0 t $ R t^ RIHt ^ RIt^ RIt^ RIHtHtH	t	H
t
Ht ^ RIHtHt ^ RIHtHtHt ^ RIHt ^ RIHt ]P.                  ! R4      tRctR	 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 R R lt!R R lt"R R lt#R R lt$R R lt%R R!/R" R# llt&R$ R% lt'R&RR R!/R' R( llt(R) R* lt)R+ R, lt*R- R. lt+R/ R0 lt,R1 R2 lt-R3 R4 lt.R5 R6 lt/R7 R8 lt0R9 R: lt1R; R< lt2R=RR>RR?R/R@ RA llt3RB RC lt4RdRD RE llt5RF RG lt6RH RI lt7ReRJ RK llt8RL RM lt9RN RO lt:RP RQ lt;RR RS lt<RTRU/t=RV]>RW&   RX RY lt?RZ R[ lt@R\ R] ltAR^RR_RR`RR&R/Ra Rb lltBR# )fuÙ  Custom-provider resolution: ``providers:`` / ``custom_providers:`` lookup, identity recovery,
custom credential pools, and the named-custom runtime builder. Extracted from
:mod:`hermes_cli.runtime_provider`; origin-internal collaborators
(``load_config``, ``_get_model_config``, ``load_pool``, ``has_usable_secret``, â€¦) are looked up on
the origin module AT CALL TIME via :func:`_rp` so ``monkeypatch.setattr(runtime_provider, name, â€¦)``
keeps working for moved bodies.)ÚannotationsN)ÚAnyÚCallableÚDictÚOptionalÚTuple)Úcustom_provider_aliasesÚcustom_provider_slug)Úcustom_entry_for_endpointÚentry_declares_credentialÚentry_scoped_pool)Úget_secret_str)Úbase_url_hostnamezhermes_cli.runtime_providerc                 ó   € ^ RI Hp  V # )zUOrigin module, late-bound so test patches on ``hermes_cli.runtime_provider.*`` apply.N)Úhermes_cli.runtime_providerÚruntime_provider)Úorigins    ÚVC:\Users\johnn\AppData\Local\hermes\hermes-agent\hermes_cli\runtime_provider_custom.pyÚ_rpr      s
   € å0Ø€Mó    c               ó    € V ^8„  d   QhRRRR/# )é   ÚvalueÚstrÚreturn© )Úformats   "r   Ú__annotate__r      s   € ÷ 3ñ 3¨3ð 3°3ñ 3r   c                ó^   € V P                  4       P                  4       P                  R R4      # )Ú Ú-)ÚstripÚlowerÚreplace©r   s   &r   Ú_normalize_custom_provider_namer%      s$   € Ø�;‰;‹=×ÑÓ ×(Ñ(¨¨cÓ2Ð2r   c               ó   € V ^8„  d   QhRR/# )r   r   r   r   )r   s   "r   r   r   "   s   € ÷ 8ñ 8¨Cñ 8r   c                ó‚   € \        T ;'       g    R 4      P                  4       P                  R4      P                  4       # )Ú Ú/)r   r!   Úrstripr"   r$   s   &r   Ú_normalize_base_url_for_matchr+   "   s0   € Üˆu�{ˆ{˜Ó×!Ñ!Ó#×*Ñ*¨3Ó/×5Ñ5Ó7Ð7r   c               ó    € V ^8„  d   QhRRRR/# )r   r   r   r   r   r   )r   s   "r   r   r   &   s   € ÷ $ñ $�#ð $˜#ñ $r   c                óH   € \        T ;'       g    R 4      P                  4       # )r(   ©r   r!   r$   s   &r   Ú_cleanr/   &   s   € Üˆu�{ˆ{˜Ó×!Ñ!Ó#Ð#r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úentryúdict[str, Any]Úlabelr   r   r   )r   s   "r   r   r   *   s!   € ÷ ñ ˜>ð °#ð ¸#ñ r   c                óð   € \        V P                  R4      ;'       g    V P                  R4      4      pV'       g   R# \        VR4      P                  4       pV'       g   \        P                  RW4       V# )u  The credential named by ``key_env`` / ``api_key_env`` on a config block, or "".

A declared variable that resolves to nothing is logged: every custom rung substitutes
``no-key-required`` for an empty key (keyless local servers), so a misnamed or unexported
variable otherwise surfaces only as the provider's 401/403 (#67453). A block with no key_env at
all stays silent â€” that IS the keyless-server configuration. A ``providers:`` entry with a
declared credential never falls back to an implicit env key, so the placeholder is what it gets.
Úkey_envÚapi_key_envr(   u½   %s: key_env %s is set but the variable is empty/unset â€” unless another credential is configured for it, the request carries the placeholder no-key-required and the endpoint will reject it)r/   Úgetr   r!   ÚloggerÚwarning)r1   r3   r5   r   s   &&  r   Ú_key_env_secretr:   *   sb   € ô �U—Y‘Y˜yÓ)×EÐE¨U¯Y©Y°}Ó-EÓF€GßÙÜ˜7 BÓ'×-Ñ-Ó/€EßÜ�‰ð 1à27ô	Bð €Lr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Ú	model_cfgr2   Úbase_urlr   r   r   )r   s   "r   r   r   >   s!   € ÷ /ñ / nð /Àð /Èñ /r   c                ó¾   € \        V P                  R4      4      P                  R4      pV'       d    V\        V4      P                  R4      8w  d   R# \        V R4      # )uâ   ``model.key_env`` for a bare ``provider: custom`` runtime, only when ``base_url`` IS the
configured ``model.base_url`` â€” the key was declared for that endpoint, never for a direct alias
or CUSTOM_BASE_URL pointing elsewhere.r=   r)   r(   Úmodel)r/   r7   r*   r:   )r<   r=   Úcfg_base_urls   && r   Ú_model_cfg_key_env_forrA   >   sL   € ô ˜)Ÿ-™-¨
Ó3Ó4×;Ñ;¸CÓ@€Lß˜<¬6°(Ó+;×+BÑ+BÀ3Ó+GÔGÙÜ˜9 gÓ.Ð.r   c               ó    € V ^8„  d   QhRRRR/# )r   r1   r2   r   r   r   )r   s   "r   r   r   H   s   € ÷ Oñ O�nð O¨ñ Or   c                óœ   € V P                  R 4      ;'       g5    V P                  R4      ;'       g    V P                  R4      ;'       g    R# )ÚapiÚurlr=   r(   )r7   )r1   s   &r   Ú
_entry_urlrF   H   s;   € Ø�9‰9�UÓ×NÐN˜uŸy™y¨Ó/×NÐN°5·9±9¸ZÓ3H×NÐNÈBÐNr   c               ó    € V ^8„  d   QhRRRR/# )r   r   r   r   zdict[str, bool]r   )r   s   "r   r   r   O   s   € ÷ Zñ Z ð Z¨ñ Zr   c                óæ   € \        V \        4      '       g   / # V P                  4        UUu/ uF7  w  r\        V\        4      '       g   K  \        V\        4      '       g   K5  WbK9  	  upp# u uppi )zAReturn the string-keyed boolean capabilities accepted at runtime.)Ú
isinstanceÚdictÚitemsr   Úbool)r   ÚkÚvs   &  r   Ú_filter_capabilitiesrO   O   sN   € ä�eœT×"Ò"Øˆ	Ø"Ÿ[™[œ]ÔY™]‘T�Q¬j¸¼C×.@ŒDÄZÐPQÔSW×EXŒDˆAŠD™]ÒYÐYùÓYs   ¬A-ÁA-Á#A-c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r1   r2   r?   úOptional[str]Úresultr   ÚNoner   )r   s   "r   r   r   V   s*   € ÷ .ñ . Nð .¸=ð .ÐR`ð .Ðeiñ .r   c                ó:  € \        V P                  R4      4      pV P                  R4      p\        V\        4      '       d   V'       d   VP                  V4      MRp\        V\        4      '       d   VP	                  \        V4      4       V'       d   W2R&   R# R# )z>Copy explicit boolean per-model capabilities into the runtime.ÚcapabilitiesÚmodelsN)rO   r7   rI   rJ   Úupdate)r1   r?   rR   rU   rV   Úmodel_configs   &&&   r   Ú_lift_model_capabilitiesrY   V   ss   € ä'¨¯	©	°.Ó(AÓB€LØ�Y‰Y�xÓ €FÜ(2°6¼4×(@Ò(@ÇU�6—:‘:˜eÔ$ÐPT€LÜ�,¤×%Ò%Ø×ÑÔ0°Ó>Ô?ßØ!-ˆ~Óñ r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r1   r2   rR   r   rS   r   )r   s   "r   r   r   b   s!   € ÷ 0ñ 0˜~ð 0°~ð 0È$ñ 0r   c                ór   € \        4       P                  V P                  R4      4      pV'       d   W!R&   R# R# )uZ   Copy a validated ``extra_headers`` dict. SECURITY: values carry credentials â€” never log.Úextra_headersN)r   Únormalize_extra_headersr7   )r1   rR   r\   s   && r   Ú_lift_extra_headersr^   b   s-   € ä“E×1Ñ1°%·)±)¸OÓ2LÓM€MßØ"/ˆÓñ r   c               ó0   € V ^8„  d   QhRRRRRRRRRRR	R
/# )r   r1   r2   rR   Úprovider_keyr   r5   Úapi_moderQ   r   rS   r   )r   s   "r   r   r   i   s:   € ÷ 2ñ 2 nð 2¸nð 2Ð_bð 2Ðmpð 2Ø)6ð2Ø;?ñ2r   c               óè   € V'       d   W1R&   V'       d   W!R&   V P                  R4      p\        V\        4      '       d   \        V4      VR&   \        W4       V'       d   WAR&   \	        V RV4       R# )z[Copy the optional fields shared by ``providers:`` and legacy ``custom_providers:`` entries.r5   r`   Ú
extra_bodyra   N)r7   rI   rJ   r^   rY   )r1   rR   r`   r5   ra   rc   s   &&$$$ r   Ú_lift_common_custom_fieldsrd   i   sc   € ÷ Ø#ˆyÑßØ!-ˆ~ÑØ—‘˜<Ó(€JÜ�*œd×#Ò#Ü# JÓ/ˆˆ|ÑÜ˜Ô&ßØ%ˆzÑä˜U D¨&Ö1r   c               ó    € V ^8„  d   QhRRRR/# )r   Úrequested_normr   r   rL   r   )r   s   "r   r   r   }   s   € ÷ ?ñ ?¨ð ?°ñ ?r   c                ó  € V R8X  g   V P                  R4      '       d   R# \        4       p VP                  P                  V 4      pT;'       g    RP                  4       P                  4       T 8H  #   TP                   d     R# i ; i)uë  Raw names map to custom providers only when they are not canonical built-ins. Explicit
``custom:<name>`` keys always target the saved entry, and bare ``custom`` is exempt: a user may
literally name a ``providers:`` entry "custom" (returning None before the config scan made such
cron jobs fail with ``auth_unavailable``). Defer to the built-in only when the raw name IS the
canonical provider (``nous``); an entry matching merely an alias (``kimi`` â†’ ``kimi-coding``)
is the user's target.Úcustomzcustom:Fr(   )Ú
startswithr   Úauth_modÚresolve_providerÚ	AuthErrorr!   r"   )rf   ÚrpÚ	canonicals   &  r   Ú_shadowed_by_builtinro   }   s|   € ð ˜Ô! ^×%>Ñ%>¸y×%IÒ%IÙÜ	‹€BðØ—K‘K×0Ñ0°Ó@ˆ	ð �OˆO˜×"Ñ"Ó$×*Ñ*Ó,°Ñ>Ð>øð �<‰<ô Úðús   ¬A2 Á2BÂBÚresolve_credentialsTc               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   rf   r   Ú	providersr2   rp   rL   r   z$Optional[tuple[dict[str, Any], Any]]r   )r   s   "r   r   r   Ž   s,   € ÷  ñ  Øð Ø$2ð ØLPð à)ñ r   c               ó´  € ^ RI Hp \        4       pVP                  4        EF²  w  rV\	        V\
        4      '       d   V! V4      '       g   K,  T \        \        VP                  RR4      ;'       g    T4      \        V4      4      9  d   Kk  \        V4      pV'       g   K€  \        VP                  R4      ;'       g    VP                  R4      4      pV'       d#   V'       d   \        VR4      P                  4       MRp	RVP                  RV4      RVP                  4       RT	;'       g    \        VP                  RR4      4      RVP                  R	R4      /p
\        VP                  R
R4      4      pV'       d   WºR
&   \        Yj\        V4      TTP                  VP                  R4      ;'       g    VP                  R4      4      R7       W¥3u # 	  R# )zWScan ``providers:`` (new-style, keyed) for ``requested_norm``; ``(entry, config key)``.)Úis_provider_enabledÚnamer(   r5   r6   r=   Úapi_keyr?   Údefault_modelÚkey_cmdra   Ú	transport©r`   r5   ra   N)Úhermes_cli.configrt   r   rK   rI   rJ   r   r   r7   rF   r/   r   r!   rd   Ú_parse_api_mode)rf   rr   rp   rt   rm   Úep_namer1   r=   r5   rv   rR   rx   s   &&$         r   Ú_match_new_style_providerr~   Ž   s‘  € õ 6Ü	‹€BØ#Ÿ/™/×+‰ˆä˜%¤×&Ò&Ñ.AÀ%×.HÒ.HÙØÔ!8¼¸U¿Y¹YÀvÈrÓ=R×=]Ð=]ÐV]Ó9^Ô`cÐdkÓ`lÓ!mÔmÙÜ˜eÓ$ˆßÙô ˜Ÿ™ 9Ó-×IÐI°·±¸=Ó1IÓJˆß9@×EX”. ¨"Ó-×3Ñ3Ô5Ð^`ˆØ"(¨%¯)©)°F¸GÓ*DÀjÐRZ×R`ÑR`ÓRbØ"+¨W×-XÐ-X¼¸u¿y¹yÈÐTVÓ?WÓ8XÐZaÐch×clÑclÐm|ð  Aó  dBð"Cˆô ˜Ÿ™ 9¨bÓ1Ó2ˆßØ '�9Ñô 	#Ø¬¨w«ÀØ×'Ñ'¨¯	©	°*Ó(=×(WÐ(WÀÇÁÈ;ÓAWÓXõ	
ð ˆÒñ3 ,ñ4 r   c               ó    € V ^8„  d   QhRRRR/# )r   rf   r   r   z%Optional[tuple[dict[str, Any], dict]]r   )r   s   "r   r   r   ±   s   € ÷ ñ °#ð ÐLqñ r   c                ó²  € V EFO  p\        V\        4      '       d#   VP                  R4      VP                  R4      3MRw  r4\        V\        4      '       d   \        V\        4      '       g   Kn  \	        VP                  RR4      4      pV \        W54      9  d   K›  RVP                  4       RVP                  4       R\	        VP                  RR4      4      /p\	        VP                  RR4      4      pV'       d   WvR&   \        W&V\	        VP                  RR4      4      \        4       P                  VP                  R	4      4      R
7       Wb3u # 	  R# )z_Scan the legacy ``custom_providers:`` list for ``requested_norm``; ``(result, matched entry)``.ru   r=   Nr`   r(   rv   r?   r5   ra   rz   ©NN)
rI   rJ   r7   r   r/   r   r!   rd   r   r|   )rf   Úcustom_providersr1   ru   r=   r`   rR   Ú
model_names   &&      r   Ú_match_legacy_custom_providerr„   ±   s  € ä!ˆÜGQÐRWÔY]×G^ÒG^˜%Ÿ)™) FÓ+¨U¯Y©Y°zÓ-BÑCÐdp‰ˆÜ˜$¤×$Ò$¬J°xÄ×,EÒ,EÙÜ˜eŸi™i¨¸Ó;Ó<ˆØÔ!8¸Ó!LÔLÙØ˜$Ÿ*™*›,¨
°H·N±NÓ4DÀiÔQWÐX]×XaÑXaÐbkÐmoÓXpÓQqÐrˆÜ˜EŸI™I g¨rÓ2Ó3ˆ
ßØ(�7‰OÜ" 5¸|ÔU[Ð\a×\eÑ\eÐfoÐqsÓ\tÓUuÜ,/«E×,AÑ,AÀ%Ç)Á)ÈJÓBWÓ,Xõ	Zàˆ}Òñ "ñ r   Úconfigc               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Úrequested_providerr   r…   úOptional[dict[str, Any]]rp   rL   r   r   )r   s   "r   r   r   Ä   s.   € ÷ 'ñ 'Øð'Ø(@ð'àð'ð ñ'r   c               óB   € \        WVR7      pV'       d
   V^ ,          # R# )z³Resolve a named endpoint. Creation-time config copying supplies its own config snapshot
and skips credential reads; ordinary runtime callers keep their existing scoped resolution.©r…   rp   N©Ú_select_named_custom_provider)r‡   r…   rp   Úfounds   &$$ r   Ú_get_named_custom_providerrŽ   Ä   s#   € ô *Ð*<ÐatÔu€Eßˆ5��8Ð& $Ð&r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r‡   r   r…   r2   r   úOptional[tuple]r   )r   s   "r   r   r   Î   s"   € ÷ 'ñ '¸#ð 'À~ð 'ÐZiñ 'r   c                óB   € \        WRR7      pV'       d
   V^,          # R# )z¬The config path (``("providers", key)`` / ``("custom_providers", index)``) of the ONE entry
the runtime routes *requested_provider* through, else None. Reads no credential.FrŠ   Nr‹   )r‡   r…   r�   s   && r   Ú!named_custom_provider_config_pathr’   Î   s#   € ô *Ð*<ÐafÔg€Eßˆ5��8Ð& $Ð&r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r=   r   r…   r2   r   r�   r   )r   s   "r   r   r   Õ   s"   € ÷ 
ñ 
°#ð 
¸~ð 
ÐRañ 
r   c                óò  € \        T ;'       g    R4      P                  4       P                  R4      pV'       d&   \        VP	                  R4      \
        4      '       d   R# \        4       P                  V4      ;'       g    R Fn  p\        V\
        4      '       g   K  \        VP	                  R4      ;'       g    R4      P                  4       P                  R4      V8X  g   Kc  \        W4      u # 	  R# )a  The config path of the entry a bare ``custom`` route at *base_url* takes its key from: the
first compatible ``custom_providers`` / ``providers`` entry with that URL (trailing slash
ignored), the same owner the credential pool seeds from. Reads no credential.r(   r)   r‚   Nr=   r   )	r   r!   r*   rI   r7   rJ   r   Úget_compatible_custom_providersÚ_compatible_entry_path)r=   r…   rE   r1   s   &&  r   Ú#custom_provider_config_path_for_urlr—   Õ   s·   € ô ˆh�nˆn˜"Ó
×
#Ñ
#Ó
%×
,Ñ
,¨SÓ
1€Cß”*˜VŸZ™ZÐ(:Ó;¼T×BÒBÙÜ“×6Ñ6°vÓ>×DÐDÀ"ÒDˆÜ�eœT×"Ô"¤s¨5¯9©9°ZÓ+@×+FÐ+FÀBÓ'G×'MÑ'MÓ'O×'VÑ'VÐWZÓ'[Ð_bÖ'bÜ)¨&Ó8Ò8ñ Eñ r   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   r‡   r   r…   rˆ   rp   rL   r   z0Optional[tuple[dict[str, Any], Optional[tuple]]]r   )r   s   "r   r   r   â   s2   € ÷ Sñ SØðSØ(@ðSØW[ðSà5ñSr   c               ó^  € \        T ;'       g    R4      pV'       d   VR8X  g   \        V4      '       d   R# \        4       pVf   VP                  4       pVP	                  R4      p\        V\        4      '       d   \        W5VR7      MRpV'       d   V^ ,          RV^,          33# \        VP	                  R4      \        4      '       d   \        P                  R4       R# VP                  V4      pV'       d   \        W74      MRpV'       d   V^ ,          \        W^,          4      3# R# )zr``(resolved entry, its config path)`` for the first usable match: ``providers:`` first,
then the legacy list view.r(   ÚautoNrr   )rp   r‚   z…custom_providers in config.yaml is a dict, not a list. Each entry must be prefixed with '-' in YAML. Run 'hermes doctor' for details.)r%   ro   r   Úload_configr7   rI   rJ   r~   r8   r9   r•   r„   r–   )r‡   r…   rp   rf   rm   rr   r�   r‚   s   &$$     r   rŒ   rŒ   â   s  € ô
 5Ð5G×5MÐ5MÈ2ÓN€Nß˜^¨vÔ5Ô9MÈn×9]Ò9]ÙÜ	‹€BØ‚~Ø—‘Ó!ˆØ—
‘
˜;Ó'€Iô �i¤×&Ò&ô 	" .ÐQdÕeØ,0ð 
÷ Ø�Q�x˜+ u¨Q¥xÐ0Ð0Ð0Ü�&—*‘*Ð/Ó0´$×7Ò7Ü�‰ð :ô 	;ñ Ø×9Ñ9¸&ÓAÐßO_Ô)¨.ÔKÐei€EßCHˆE�!�HÔ,¨V¸1µXÓ>Ð?ÐRÈdÐRr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r…   r2   r1   r   r�   r   )r   s   "r   r   r   þ   s&   € ÷ 
Kñ 
K >ð 
K¸.ð 
KÈ_ñ 
Kr   c           	     óR  aaa€ ^ RI Ho V P                  R4      pSP                  R4      oS'       d-   \        V\        4      '       d   \        V3R lV 4       R4      # V P                  R4      p\        VV3R l\        \        V\        4      '       d   TMR4       4       R4      # )	z²Where a ``get_compatible_custom_providers`` entry lives in *config*. The view keeps the first
of identical legacy entries, so the first raw entry normalizing to it is its source.)Ú _normalize_custom_provider_entryrr   r`   c              3  ól   <"  € T F)  p\        V4      P                  4       S8X  g   K#  R V3x € K+  	  R# 5i)rr   Nr.   )Ú.0rM   Úkeys   & €r   Ú	<genexpr>Ú)_compatible_entry_path.<locals>.<genexpr>  s*   øé € ÐR©y¨!¼CÀ»F¿L¹L»NÈcÑ<QÔ%�k 1Õ%«yùs   ƒ 4¨4Nr‚   c              3  óN   <"  € T F  w  rS! V4      S8X  g   K  R V3x € K  	  R# 5i)r‚   Nr   )r    ÚiÚrawrž   r1   s   &  €€r   r¢   r£     s0   øé € ð DÑ7l©V¨QÙ4°SÓ9¸UÑBô )Ð$ aÕ(Ó7lùs   ƒ%™%r   )Úhermes_cli.config_providersrž   r7   rI   rJ   ÚnextÚ	enumerateÚlist)r…   r1   rr   Úlegacyrž   r¡   s   &f  @@r   r–   r–   þ   s�   ú€ õ MØ—
‘
˜;Ó'€IØ
�)‰)�NÓ
#€Cß
Œz˜)¤T×*Ò*ÜÔR©yÓRÐTXÓYÐYØ�Z‰ZÐ*Ó+€FÜõ D´yÌ:ÐV\Ô^b×KcÒKcÁÐikÔ7ló DØEIóKð Kr   c               ó    € V ^8„  d   QhRRRR/# )r   r‡   r   r   rL   r   )r   s   "r   r   r     s   € ÷ ñ °#ð ¸$ñ r   c                ó^   €  \        4       P                  V 4      RJ#   \         d     R# i ; i)z¬True when config defines a ``providers:`` / ``custom_providers:`` entry matching the request
(public wrapper so e.g. the cronjob tool need not reach into a private helper).NF)r   rŽ   Ú	Exception)r‡   s   &r   Úhas_named_custom_providerr¯     s2   € ðÜ‹u×/Ñ/Ð0BÓCÈ4ÐOÐOøÜô Úðús   ‚ �,«,c               ó    € V ^8„  d   QhRRRR/# )r   r‡   r   r   rQ   r   )r   s   "r   r   r     s   € ÷ }ñ }°ð }¸ñ }r   c                óˆ  € \        T ;'       g    R4      R9   d   R#  \        4       P                  V 4      pT'       g   R# \	        \        TP                  R4      ;'       g    R4      \        TP                  R4      ;'       g    R4      4      P                  R^4      ^,          ;'       g    R#   \         d     R# i ; i)uz  Codex ``[model_providers.<id>]`` key for a configured named custom provider â€” its ``custom:``
identity without the prefix (the ``providers:`` config key; legacy ``custom_providers:`` entries
use their normalized display name). None for bare ``custom``, aliases that resolve to custom
(ollama, vllm, â€¦) and unknown names: codex has no stable id to look up for those (#75186).r(   Nru   r`   Ú:>   r(   rh   )r%   r   rŽ   r®   r	   r   r7   Úsplit)r‡   r1   s   & r   Úcodex_model_provider_idr´     s©   € ô
 'Ð'9×'?Ð'?¸RÓ@ÀNÔRÙðÜ“×0Ñ0Ð1CÓDˆ÷ ÙÜ¤ E§I¡I¨fÓ$5×$;Ð$;¸Ó <¼cÀ%Ç)Á)ÈNÓB[×BaÐBaÐ_aÓ>bÓc×iÑiÐjmÐopÓqÐrsÕt×|Ð|Ðx|Ð|øô	 ô Úðús   žB2 Â2CÃ Cc               ó    € V ^8„  d   QhRRRR/# )r   Úmatchesz Callable[[dict[str, Any]], bool]r   rQ   r   )r   s   "r   r   r   '  s   € ÷ ñ Ð#Cð Èñ r   c           
     ó  € \        4       p VP                  4       pTP                  R4      p\	        T\
        4      '       d`   TP                  4        FK  w  rE\	        T\
        4      '       g   K  T ! T4      '       g   K-  \        \        T4      \        T4      4      u # 	   TP                  T4      pT;'       g    .  F›  p\	        T\
        4      '       d   TP                  R4      MRp\	        T\        4      '       g   KD  TP                  4       '       g   K\  T ! T4      '       g   Kl  \        T\        TP                  RR4      ;'       g    R4      4      u # 	  R#   \         d     R# i ; i  \         d    Rp LÎi ; i)zˆFirst entry in ``providers:`` then legacy ``custom_providers:`` where ``matches(entry)``
holds, as its canonical ``custom:<name>`` slug.Nrr   ru   r`   r(   )r   r›   r®   r7   rI   rJ   rK   r	   r   r•   r!   )r¶   rm   r…   rr   r}   r1   r‚   ru   s   &       r   Ú_find_custom_identityr¸   '  s3  € ô 
‹€BðØ—‘Ó!ˆð —
‘
˜;Ó'€IÜ�)œT×"Ò"Ø'Ÿo™oÖ/‰NˆGÜ˜%¤×&Ô&©7°5¯>¬>Ü+¬C°«L¼#¸g»,ÓGÒGñ 0ð Ø×=Ñ=¸fÓEÐð "×'Ð' RÒ'ˆÜ$.¨u´d×$;Ò$;ˆu�y‰y˜Ô ÀˆÜ�dœC× Ô  T§Z¡Z§\¤\±g¸e·n´nÜ'¨¬c°%·)±)¸NÈBÓ2O×2UÐ2UÐSUÓ.VÓWÒWñ (ñ øô ô Úðûô ô  ØÒð ús#   ŒE! Â#E3 Å!E0Å/E0Å3FÆFc               ó    € V ^8„  d   QhRRRR/# )r   r=   r   r   rQ   r   )r   s   "r   r   r   ?  s   € ÷ kñ k¨Cð k°Mñ kr   c                óL   a€ \        V 4      oS'       g   R# \        V3R l4      # )u  Map an endpoint URL back to its canonical ``custom:<name>`` menu key. Session persistence
stores the agent's *resolved* provider, which for every named custom endpoint is the literal
string ``"custom"`` â€” the entry name is lost, and the api_key is deliberately never persisted.Nc                ó2   <€ \        \        V 4      4      S8H  # ©N)r+   rF   )r1   Útargets   &€r   Ú<lambda>Ú/find_custom_provider_identity.<locals>.<lambda>F  s   ø€ Ô/LÌZÐX]ÓM^Ó/_ÐciÒ/ir   )r+   r¸   )r=   r½   s   &@r   Úfind_custom_provider_identityrÀ   ?  s!   ø€ ô +¨8Ó4€FßÙÜ Ô!iÓjÐjr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   r½   r   r   rL   r   )r   s   "r   r   r   I  s&   € ÷ Fñ F˜Sð F¨#ð F°$ñ Fr   c                ót   € \        V \        4      ;'       d"    V P                  4       P                  4       V8H  # r¼   )rI   r   r!   r"   )r   r½   s   &&r   Ú_model_id_matchesrÃ   I  s+   € Ü�eœSÓ!×EÐE e§k¡k£m×&9Ñ&9Ó&;¸vÑ&EÐEr   c               ó    € V ^8„  d   QhRRRR/# )r   r?   r   r   rQ   r   )r   s   "r   r   r   M  s   € ÷ 6ñ 6°#ð 6¸-ñ 6r   c                ó¢   a€ \        T ;'       g    R4      P                  4       P                  4       oS'       g   R# R V3R llp\        V4      # )uè   Map a model id back to the ``custom:<name>`` entry that serves it â€” companion to
:func:`find_custom_provider_identity` for persistence paths where no base_url survived the
round-trip (the session row always stores the model name).r(   Nc               ó    € V ^8„  d   QhRRRR/# )r   r1   r2   r   rL   r   )r   s   "r   r   Ú<find_custom_provider_identity_by_model.<locals>.__annotate__U  s   € ÷ 	ñ 	 >ð 	°dñ 	r   c                óô  <a € \         ;QJ d     V V3R  lR 4       F  '       g   K   RM	  RM! V V3R  lR 4       4      '       d   R# S P                  R4      p\        V\        4      '       d;   \         ;QJ d    V3R lV 4       F  '       g   K   R# 	  R# ! V3R lV 4       4      # \        V\        4      '       d;   \         ;QJ d    V3R lV 4       F  '       g   K   R# 	  R# ! V3R lV 4       4      # R# )c              3  óZ   <"  € T F   p\        SP                  V4      S4      x € K"  	  R # 5ir¼   )rÃ   r7   )r    r¡   r1   r½   s   & €€r   r¢   ÚVfind_custom_provider_identity_by_model.<locals>._entry_serves_model.<locals>.<genexpr>V  s&   øé € Ð_ÑD^¸SÔ  §¡¨3£°×8Ð8ÓD^ùs   ƒ(+TFrV   c              3  óx   <"  € T F/  p\        V4      P                  4       P                  4       S8H  x € K1  	  R # 5ir¼   ©r   r!   r"   )r    Úmidr½   s   & €r   r¢   rÊ   Z  s*   øé € ÐLÁV¸c”s˜3“x—~‘~Ó'×-Ñ-Ó/°6Ö9ÃVùs   ƒ7:c              3  ó¼   <"  € T FQ  p\        \        V\        4      '       d+   VP                  R 4      ;'       g    VP                  R4      MTS4      x € KS  	  R# 5i)Úidru   N)rÃ   rI   rJ   r7   )r    Úitemr½   s   & €r   r¢   rÊ   \  sN   øé € ð +Ù#)˜4ô )ÌzÐZ^Ô`d×OeÒOe¨¯©°$«×)KÐ)K¸4¿8¹8ÀFÓ;KøÐkoÐqw×xÐxÛ#)ùs
   ƒ7A»!A)r?   rw   )Úanyr7   rI   rJ   rª   )r1   rV   r½   s   f €r   Ú_entry_serves_modelÚCfind_custom_provider_identity_by_model.<locals>._entry_serves_modelU  s¸   ù€ ß‹3Õ_ÑD^Ó_�3�3Š3Õ_ÑD^Ó_×_Ò_ÙØ—‘˜8Ó$ˆÜ�fœd×#Ò#ß“3ÔLÁVÓL—3”3ÐL’3ÐL�3ÔLÁVÓLÓLÐLÜ�fœd×#Ò#ß“3ô +Ù#)ó+—3”3ð +’3ð +�3ô +Ù#)ó+ó +ð +ár   )r   r!   r"   r¸   )r?   rÒ   r½   s   & @r   Ú&find_custom_provider_identity_by_modelrÔ   M  sE   ø€ ô �—�˜"Ó×#Ñ#Ó%×+Ñ+Ó-€FßÙ÷	ð 	ô !Ð!4Ó5Ð5r   r=   Úconfig_providerr?   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r=   rQ   rÕ   r?   r   r   )r   s   "r   r   r   c  s+   € ÷ -<ñ -<¨=ð -<ÐR_ð -<Ø%2ð-<Ø>Kñ-<r   c                óœ  € \        4       pV '       dM   \        V 4      pV'       d   V# ^ RIHp V! 4       pV'       d#   \	        V 4      \	        VR,          4      8X  d   R# V'       d   \        V4      MRpV'       d   V# \        T;'       g    R4      P                  4       pV'       gB    \        VP                  4       P                  R4      ;'       g    R4      P                  4       pV'       g/   \        P                  P                  RR4      P                  4       p\        V4      pV'       d   VR9   d   R#  VP                  V4      p	T	f   R#  \        \        T	P                  R4      ;'       g    R4      4      pT;'       g    \        T4      #   \         d    Rp L¼i ; i  \         d     R# i ; i  \         d     R# i ; i)	zëRecover the durable menu identity for a bare custom provider. Match a configured
endpoint first, then the ownership-checked managed server, then a configured model or
provider. Every session persistence/restore path shares this lookup.)Ú_state_endpointr=   ÚllamacppNr(   ÚproviderÚHERMES_INFERENCE_PROVIDER>   rš   rh   Ú
openrouter)r   rÀ   Ú!hermes_cli.local_runtime.endpointrØ   r+   rÔ   r   r!   Ú_get_model_configr7   r®   ÚosÚenvironr%   rŽ   r	   )
r=   rÕ   r?   rm   ÚidentityrØ   ÚendpointÚ	candidateÚcandidate_normr1   s
   $$$       r   Úcanonical_custom_identityrå   c  sˆ  € ô
 
‹€BßÜ0°Ó:ˆßØˆOõ 	FÙ"Ó$ˆßÔ5°hÓ?ÔC`ÐaiÐjtÕauÓCvÔvÙß@EÔ5°eÔ<È4€HßØˆÜ�O×)Ð) rÓ*×0Ñ0Ó2€Ißð	Ü˜B×0Ñ0Ó2×6Ñ6°zÓB×HÐHÀbÓI×OÑOÓQˆI÷ Ü—J‘J—N‘NÐ#>ÀÓC×IÑIÓKˆ	Ü4°YÓ?€Nç˜^Ð/OÔOÙð
Ø×-Ñ-¨iÓ8ˆð ‚}ÙðÜ0´°U·Y±Y¸zÓ5J×5PÐ5PÈbÓ1QÓRˆð ×;Ð;Ô+¨NÓ;Ð;øô- ô 	ØŠIð	ûô ô Úðûô ô ÚðúsB   Â**F ÃF Ä=F* Å!F< Å7F< ÆF'Æ&F'Æ*F9Æ8F9Æ<GÇ
Gc               ó    € V ^8„  d   QhRRRR/# )r   rÚ   rQ   r   rL   r   )r   s   "r   r   r   “  s   € ÷ ñ  =ð °Tñ r   c                ól  € \        T ;'       g    R4      P                  4       pV'       d   VP                  4       R8X  d   R# VP                  4       R8X  d   R#  ^ RIHp \        4       pVP                  4       pV! WP                  R4      VP                  V4      4      RJ#   \         d     R# i ; i)	uÏ  Whether a provider name currently resolves to a routable route. Empty/None/``auto`` is
vacuously routable (agent build falls back to the configured default). Bare ``custom`` is the
resolved billing class shared by every named entry â€” not a routable identity; restore paths
must heal it (:func:`canonical_custom_identity`) or fall back. Anything else is routable iff the
full chain (built-in -> ``providers:`` -> ``custom_providers:`` -> models.dev) resolves it.r(   rš   Trh   F)Úresolve_provider_fullrr   N)
r   r!   r"   Úhermes_cli.providersrè   r   r›   r7   r•   r®   )rÚ   ru   rè   rm   r…   s   &    r   Úis_routable_providerrê   “  s–   € ô ˆx�~ˆ~˜2Ó×$Ñ$Ó&€Dß�4—:‘:“< 6Ô)ÙØ‡z�zƒ|�xÔÙðÝ>Ü‹UˆØ—‘Ó!ˆÙ$ T¯:©:°kÓ+BÀB×DfÑDfÐgmÓDnÓoÐw{Ð{Ð{øÜô Úðús   ÁAB$ Â$B3Â2B3c               ó$   € V ^8„  d   QhRRRRRR/# )r   r=   r   Úprovider_namerQ   r   rˆ   r   )r   s   "r   r   r   ª  s"   € ÷ 'ñ ' ð '°Mð 'ÐMeñ 'r   c                ót   € V P                   P                  4       p\        WV4      pV'       d
   V^,          # R# )z¢The ``providers:`` entry that owns a custom endpoint, from the frozen route's config when the
session froze one (a live edit then neither drops nor reassigns it).N)Ú_FROZEN_RUNTIME_CONFIGr7   r
   )rm   r=   rì   ÚfrozenÚmatchs   &&&  r   Ú_owning_entryrñ   ª  s5   € ð ×&Ñ&×*Ñ*Ó,€FÜ% h¸vÓF€Eßˆ5��8Ð& $Ð&r   c               ó    € V ^8„  d   QhRRRR/# )r   r=   r   r   ztuple[bool, Any]r   )r   s   "r   r   r   ²  s   € ÷ Rñ R¨3ð RÐ3Cñ Rr   c           
     ó¦   € \        W4      pVe   \        V4      '       g   R# R\        Y\        VP	                  R4      ;'       g    R4      4      3# )a}  ``(declared, key)`` for a bare ``provider: custom`` route whose URL a ``providers:`` entry owns.
``declared`` is False when no entry owns the URL or it names no credential; the caller then keeps
its implicit env fallbacks. Otherwise ``key`` is the entry's own (key_cmd first, as on the named
path), or "" when it resolves to nothing: no other account's env key may stand in for it.Tru   rh   )Fr(   )rñ   r   Ú_entry_credentialr   r7   )rm   r=   r1   s   && r   Ú_owning_entry_credentialrõ   ²  sM   € ô
 ˜"Ó'€EØ‚}Ô5°e×<Ò<ØÐØÔ" 2¬c°%·)±)¸FÓ2C×2OÐ2OÀxÓ.PÓQÐQÐQr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r1   r2   ru   r   r   r   r   )r   s   "r   r   r   ½  s&   € ÷ 
Hñ 
H ð 
H°sð 
H¸sñ 
Hr   c                óð   a € \        VP                  R4      4      pV'       d   ^ RIHp V! W24      ;pe   V# \        VP                  R4      4      \	        VRV R24      3p\        V 3R lV 4       R4      # )zÿA ``providers:`` entry's own credential, for the named and the URL-matched bare routes alike:
``key_cmd`` (minted per request) first, else the first usable of ``api_key`` / ``key_env``, else "".
A placeholder ``api_key`` never hides a working ``key_env``.rx   )Úbuild_command_token_providerrv   zcustom provider 'Ú'c              3  óZ   <"  € T F   pSP                  V4      '       g   K  Vx € K"  	  R # 5ir¼   ©Úhas_usable_secret©r    Úcrm   s   & €r   r¢   Ú$_entry_credential.<locals>.<genexpr>Ç  s    øé € ÐB™J�q¨"×*>Ñ*>¸q×*A—’›Jùó   ƒ+¡
+r(   )r/   r7   Úagent.command_token_sourcerø   r:   r¨   )rm   r1   ru   rx   rø   Útoken_providerÚ
candidatess   f&&    r   rô   rô   ½  ss   ø€ ô �U—Y‘Y˜yÓ)Ó*€GßÝKÙ:¸7ÓIÐIˆNÒVØ!Ð!Ü˜Ÿ™ 9Ó-Ó.´ÀÐIZÐ[_ÐZ`Ð`aÐGbÓ0cÐd€JÜÔB™JÓBÀBÓGÐGr   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r   r=   r   Úprovider_labelÚapi_mode_overriderQ   rì   r   rˆ   r   )r   s   "r   r   r   Ê  s4   € ÷ %ñ %Øð%Ø#&ð%Ø;Hð%Ø`mð%àñ%r   c           
     ó,  € \        4       p VP                  P                  4       pVf   / MRV/p\        VP                  ! W3/ VB 4      p\        W@V4      p\        \        P                  R R V 4        4       4      4      p	V	 Fâ  p
 \        VP                  V
4      W¨4      ;pf   K%  VP                  4       '       d   VP                  4       MRpVe   VP                  V4      MRpV'       g   Kn  VP                  V4      '       g#   VP                  \!        V 4      4      '       d   RpTP#                  Y;'       g    VP%                  V 4      ;'       g    RWRV
 2VR	7      u # 	  R#   \         d    . Rr‡ EL'i ; i  \         d     EK  i ; i)
zÂRuntime dict from the first credential pool that owns this custom endpoint, else None. A pool
the owning entry shares with a same-named built-in yields only the entry's rows (entry_scoped_pool).Nr…   c              3  ó8   "  € T F  q'       g   K  Vx € K  	  R # 5ir¼   r   )r    rM   s   & r   r¢   Ú0_try_resolve_from_custom_pool.<locals>.<genexpr>Ù  s   é € Ð#iÑ/c¨!Ógh§A¢AÓ/cùs   ‚	�
c              3  ó„   "  € T F6  p\        T;'       g    R 4      P                  4       P                  4       x € K8  	  R# 5i)r(   NrÌ   )r    r¡   s   & r   r¢   r	  Ù  s2   é € Ð/cÑZbÐSV´°C·I°I¸2³×0DÑ0DÓ0F×0LÑ0L×0NÐ0NÓZbùs
   ‚A •+A r(   úno-key-requiredÚchat_completionszpool:)ÚsourceÚcredential_pool)r   rî   r7   rª   Ú#custom_provider_pool_key_candidatesrñ   r®   rJ   Úfromkeysr   Ú	load_poolÚhas_credentialsÚselectÚ_pool_entry_api_keyrü   Ú_loopback_hostnamer   Ú_runtimeÚ_detect_api_mode_for_url)r=   r  r  rì   rm   rï   ÚscopeÚraw_keysÚownerr  Úpool_keyÚpoolr1   Úpool_api_keys   &&&&          r   Ú_try_resolve_from_custom_poolr  Ê  sˆ  € ô
 
‹€Bð#à×*Ñ*×.Ñ.Ó0ˆØ’n‘¨8°VÐ*<ˆÜ˜×>Ò>¸xÑ`ÐZ_Ñ`ÓaˆÜ˜b¨MÓ:ˆô ”d—m‘mÑ#iÑ/cÑZbÔ/cÓ#iÓiÓj€JÛˆð	Ü)¨"¯,©,°xÓ*@À(ÓRÐR�Ò[ÙØ%)×%9Ñ%9×%;Ò%;�D—K‘K”MÀˆEØ<AÒ<M˜2×1Ñ1°%Ô8ÐSUˆLßÙØ×'Ñ'¨×5Ò5¸"×:OÑ:OÔPaÐbjÓPk×:lÒ:lð  1�Ø—;‘;˜~×/Ð/ÀB×D_ÑD_Ð`hÓDi×/Ð/ÐmØ'ÀÀhÀZÐ>PÐbfð ó hò hñ# ñ* øô3 ô #Ø˜d“%ð#ûô. ô 	Ûð	úsH   ŒAE. Â
FÂ+FÃ0FÃ4FÄ5FÅFÅFÅ.F Å?F ÆFÆFc               ó    € V ^8„  d   QhRRRR/# )r   Úcustom_providerr2   r   r   )r   s   "r   r   r   ò  s   € ÷ ,ñ ,¸ð ,È>ñ ,r   c                ó~   € V P                  R 4      p\        V\        4      '       d	   V'       g   / # R \        V4      /# )rc   )r7   rI   rJ   )r   rc   s   & r   Ú"_custom_provider_request_overridesr"  ò  s6   € Ø ×$Ñ$ \Ó2€JÜ�j¤$×'Ò'¯zØˆ	Øœ$˜zÓ*Ð+Ð+r   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r   r2   Útarget_modelrQ   rR   r   rS   r   )r   s   "r   r   r   ù  s1   € ÷ gñ g°>ð gÐQ^ð gÐhvð gÐ{ñ gr   c                ó2  € T;'       g    V P                  R4      pV'       d   W2R&   \        WV4       V P                  R4      '       d   \        V R,          4      VR&   \        V 4      pV'       d%   / VP                  R4      ;'       g    / CVCVR&   R# R# )uN  Copy model / capabilities / extra_headers / request_overrides onto a
resolved custom runtime. An explicit ``target_model`` wins over the provider's configured
default (auxiliary slots / background-review resolve a concrete model and must not fall back to
``default_model``). ``extra_headers`` may carry credentials â€” NEVER log them.r?   r\   Úrequest_overridesN)r7   rY   rJ   r"  )r   r$  rR   rƒ   r&  s   &&&  r   Ú_apply_custom_provider_extrasr'  ù  s�   € ð
 ×=Ð= ×!4Ñ!4°WÓ!=€JßØ$ˆw‰Ü˜_¸&ÔAà×Ñ˜?×+Ò+Ü"& °Õ'GÓ"HˆˆÑÜ:¸?ÓKÐßØ&f¨&¯*©*Ð5HÓ*I×*OÐ*OÈRÐ&fÐTeÐ&fˆÐ"Ó#ñ r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r‡   r   Úexplicit_api_keyrQ   r   r2   r   )r   s   "r   r   r   
  s"   € ÷ ñ °#ð Èð Ð[iñ r   c           	     ó  € \        4       p ^ RIHp V! VP                  4       R7      pV'       dR   TP                  RRVR,          T;'       g    RP                  4       ;'       g    VR,          ;'       g    R	R
V R7      #  \        VP                  4       P                  R4      ;'       g    / P                  R4      4      pV'       d   \        R4      h\        R4      h  \         d    Rp LÈi ; i  \         d    Rp L@i ; i)uW  Managed llama.cpp runtime: the supervised (or detected external) server, or a typed error.
No server => say so and stop; falling through to the generic custom path would surface "local
server is off" as OpenRouter's baffling "401 Invalid API key". The switch's state picks the
message (server off â†’ point at the switch; else the setup pane).)Úresolve_llamacpp_endpoint©r…   Nrh   r  r=   r(   rv   r  zlocal-runtime©r  r‡   Úlocal_runtimeÚenabledFu‹   The local model server isn't running. It may still be starting â€” try again in a moment, or check Settings â†’ Providers â†’ Local models.u}   The local model server is turned off. Turn it back on in Settings â†’ Providers â†’ Local models, or switch to another model.)
r   rÝ   r+  r›   r®   r  r!   rL   r7   Ú
ValueError)r‡   r)  rm   r+  râ   r/  s   &&    r   Ú_resolve_llamacpp_runtimer1  
  s  € ô
 
‹€BðÝOÙ,°B·N±NÓ4DÔEˆ÷ Ø�{‰{˜8Ð%7¸À*Õ9MØ,×2Ð2°×9Ñ9Ó;×gÐg¸xÈ	Õ?R×gÐgÐVgÐpØ.@ð ó Bð 	BðÜ˜Ÿ™Ó(×,Ñ,¨_Ó=×CÐCÀ×HÑHÈÓSÓTˆ÷ Üð 7ó 8ð 	8ô ð ó ð øô ô ØŠðûô ô ØŠðús)   ŒC" Â*C5 Â.C5 Ã"C2Ã1C2Ã5DÄDc          
     ó,   € V ^8„  d   QhRRRRRRRRRR	/# )
r   r=   r   rv   r   ra   rQ   Úextrar   r2   r   )r   s   "r   r   r   &  s1   € ÷ >ñ > #ð >°ð >¸}ð >ÐWZð >Ð_mñ >r   c                óˆ   € V P                   ! RT;'       g    V P                  V4      ;'       g    RTT;'       g    R3/ VB # )zX``custom`` runtime dict with URL-detected api_mode fallback and the no-auth placeholder.rh   r  r  )r  r  )rm   r=   rv   ra   r3  s   &&&&,r   Ú_custom_runtimer5  &  sJ   € à�;Š;�x ×!hÐ!h¨R×-HÑ-HÈÓ-R×!hÐ!hÐVhÐjrØ×3Ð3Ð"3ñ>Ø7<ñ>ð >r   Úopenaizhttps://api.openai.com/v1zdict[str, str]Ú_DIRECT_API_BASE_URLSc               ó$   € V ^8„  d   QhRRRRRR/# )r   rÚ   rQ   Úexisting_baser   z#tuple[Optional[str], Optional[str]]r   )r   s   "r   r   r   2  s'   € ÷ ñ  mð ÀMð ÐVyñ r   c                ól  € V '       g   W3# \         P                  V P                  4       P                  4       4      pVe   \	        4       P                  V 4      e   W3# RT;'       g    RP                  4       ;'       g4    \        RR4      P                  4       P                  R4      ;'       g    T3# )uT  ``provider: openai`` â†’ custom + the user's OpenAI endpoint, api.openai.com/v1 only as the last resort.

The ONE normalization both aux paths (``agent.auxiliary_client`` and ``resolve_runtime_provider``)
apply, so the same ``auxiliary.<task>.provider`` value routes identically everywhere. A
``providers.openai`` entry keeps the provider name so the named-custom branch applies its base_url
and key; otherwise ``OPENAI_BASE_URL`` (a proxy/gateway the OPENAI_API_KEY was issued for) wins over
the public endpoint â€” sending the proxy key to api.openai.com 401s and then quarantines a valid key.
rh   r(   ÚOPENAI_BASE_URLr)   )r7  r7   r!   r"   r   rŽ   r   r*   )rÚ   r9  Útarget_bases   && r   Úexpand_direct_api_aliasr=  2  sœ   € ÷ ØÐ&Ð&Ü'×+Ñ+¨H¯N©NÓ,<×,BÑ,BÓ,DÓE€KØÒœc›e×>Ñ>¸xÓHÒTØÐ&Ð&Ø�m×)Ð) r×0Ñ0Ó2×~Ð~´nÐEVÐXZÓ6[×6aÑ6aÓ6c×6jÑ6jÐknÓ6o×~Ð~Ðs~Ð~Ð~r   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r‡   r   r)  rQ   Úexplicit_base_urlr   r2   r   )r   s   "r   r   r   C  s0   € ÷ vñ v°cð vÈ]ð vØ58ðvØ=Kñvr   c           	     ó  a
€ \        4       o
VP                  4       P                  R4      pT;'       g    RP                  4       pS
P                  V4      '       d   RMS
P	                  VRR4      pV'       d   RVR&   V# \        S
V4      w  rgT;'       g    RP                  4       \        S
P                  4       V4      .V'       d   . MS
P                  VRR7      Op\        V
3R	 lV 4       R4      ;'       g    Tp	\        S
W9RRV R
7      # )zMBare ``custom`` + explicit base_url (e.g. a ``model_aliases:`` direct alias).r)   r(   Nrh   zdirect-aliasr  T©Úollamac              3  óZ   <"  € T F   pSP                  V4      '       g   K  Vx € K"  	  R # 5ir¼   rû   rý   s   & €r   r¢   Ú0_resolve_direct_alias_runtime.<locals>.<genexpr>X  s    øé € ÐE™z˜!¨R×-AÑ-AÀ!×-D—A’A›zùr   r-  )r   r!   r*   rü   r  rõ   rA   rÞ   Ú_host_gated_env_key_candidatesr¨   r5  )r‡   r)  r?  r=   Úexplicit_keyÚpool_resultÚdeclaredÚ	entry_keyr  rv   rm   s   &&&       @r   Ú_resolve_direct_alias_runtimerJ  C  s  ø€ ô 
‹€BØ ×&Ñ&Ó(×/Ñ/°Ó4€Hð %×*Ð*¨×1Ñ1Ó3€LØ×.Ñ.¨|×<Ò<‘$À"×BbÑBbÐckÐmuÐw{ÓB|€KßØ .ˆ�HÑØÐô 3°2°xÓ@Ñ€HØ#×)Ð) r×0Ñ0Ó2Ô4JÈ2×K_ÑK_ÓKaÐckÓ4lð cß"‘B¨×(IÑ(IÈ(Ð[_Ð(IÓ(`ðc€JäÔE™zÓEÀrÓJ×WÐWÈi€GÜ˜2˜x°$¸~ÐbtÔuÐur   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r‡   r   r=   r   rQ   r   )r   s   "r   r   r   \  s!   € ÷ ñ °Cð À3ð È=ñ r   c                óÄ   € ^ RI Hp V! V 4      pVe   V#  \        V4      P                  4       R8X  d   RVP                  4       9   d   R# R#  R#   \         d     R# i ; i)zXOpenCode family by provider name, else by opencode.ai host (``/zen/go`` => opencode-go).)Úopencode_provider_familyNzopencode.aiz/zen/gozopencode-gozopencode-zen)Úhermes_cli.modelsrM  r   r"   r®   )r‡   r=   rM  Úfamilys   &&  r   Ú_opencode_family_for_customrP  \  ss   € õ ;Ù%Ð&8Ó9€FØÒØˆðÜ˜XÓ&×,Ñ,Ó.°-Ô?Ø$-°·±Ó1AÔ$A�=ÐUÀ~ÐUð @ñ øô ô ØÙðús   –4A ÁA ÁAÁAr)  r?  r$  c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r   r‡   r   r)  rQ   r?  r$  r   rˆ   r   )r   s   "r   r   r   n  s:   € ÷ Cñ C¸ð CÐP]ð CØ5BðCà0=ðCàVnñCr   c                ó”  a€ \        4       oT ;'       g    RP                  4       P                  4       pRpV\        9   d-   V'       g%   SP	                  V 4      pV'       g   \        W4      # V'       d!   VR8w  d   SP                  V4      '       d   RpVR8X  d   V'       d   \        WV4      # Vf"   Vf   SP	                  V 4      M\	        WR7      pV'       g   R# T;'       g    RP                  4       ;'       g    VP                  RR4      P                  R4      pV'       g   R# T;'       g    RP                  4       pSP                  V4      '       d   RMKSP                  TRVP                  R4      VP                  R4      ;'       g    VP                  R	4      R
7      p	V	'       d   \        WcV	4       V	# SP                  V4      '       d   TMq\        ST\        VP                  R	V 4      ;'       g    R4      4      ;'       g;    \        V3R l\!        V4      '       d   . MSP#                  VRR7       4       R4      p
\%        SWzVP                  R4      RVP                  R	V 4       2V R7      p\        WcV4       \'        W4      pVe°   VP                  R4      '       g™   ^ RIHpHp \        T;'       gC    VP                  R4      ;'       g*    SP/                  4       P                  R4      ;'       g    R4      P                  4       pV'       d   V! WÏ4      VR&   V! WËR,          VR,          4      VR&   V# )u(  Runtime for a llamacpp alias, a bare-custom direct alias, or a configured custom entry.
Aliases resolving to "custom" (ollama, vllm, llamacpp, â€¦) are treated like bare ``custom``. A
llamacpp alias with no explicit base_url resolves to the managed server first; an explicit
base_url always wins.r(   Nrh   r,  r=   r)   ra   r`   ru   )rì   c              3  óZ   <"  € T F   pSP                  V4      '       g   K  Vx € K"  	  R # 5ir¼   rû   rý   s   & €r   r¢   Ú0_resolve_named_custom_runtime.<locals>.<genexpr>¡  s0   øé € ð yñ \�qØ`b×`tÑ`tÐuv×`w÷ ’ó \ùr   FrA  zcustom_provider:r-  )Únormalize_opencode_base_urlÚopencode_model_api_moder?   Údefault)r   r!   r"   Ú_LLAMACPP_ALIASESrŽ   r1  Ú_resolves_to_customrJ  r7   r*   rü   r  r'  rô   r   r¨   r   rE  r5  rP  rN  rU  rV  rÞ   )r‡   r)  r?  r$  r…   rf   r   r=   rF  rG  rv   rR   rO  rU  rV  Úeffective_modelrm   s   $$$$$           @r   Ú_resolve_named_custom_runtimer[  n  s  ø€ ô 
‹€Bð )×.Ð.¨B×5Ñ5Ó7×=Ñ=Ó?€NØ€OØÔ*Ô*×3DØ×7Ñ7Ð8JÓKˆßÜ,Ð-?ÓRÐRß˜.¨HÔ4¸×9OÑ9OÐP^×9_Ò9_Ø!ˆØ˜Ô!×&7Ü,Ð-?ÐSdÓeÐeØÒØPVÒP^˜2×8Ñ8Ð9KÔLÜ :Ð;MÔ ]ð 	çÙØ"×(Ð( b×/Ñ/Ó1×XÐX°_×5HÑ5HÈÐUWÓ5X×`Ñ`ÐadÓe€HßÙØ$×*Ð*¨×1Ñ1Ó3€Lð ×.Ñ.¨|×<Ò<‘$À"×BbÑBbØ�(˜O×/Ñ/°
Ó;Ø%×)Ñ)¨.Ó9×XÐX¸_×=PÑ=PÐQWÓ=Xð Ccó C€K÷ ä% oÀ[ÔQØÐð
 $&×#7Ñ#7¸×#EÒ#E‘<Ü˜"˜o¬s°?×3FÑ3FÀvÐOaÓ3b×3nÐ3nÐfnÓ/oÓp÷ 	~ð 	~Üô yÔ#<¸_×#MÒ#M™RØ"$×"CÑ"CÀHÐUZÐ"CÓ"[ð\ó yØz|ó~ð ô ˜R °O×4GÑ4GÈ
Ó4SØ&6°×7JÑ7JÈ6ÐSeÓ7fÐ6gÐ$hØ0BôD€Fô " /ÀÔHô )Ð);ÓF€FØÒ /×"5Ñ"5°j×"AÒ"AßZÜ˜l×yÐy¨o×.AÑ.AÀ'Ó.J×yÐyÈb×NbÑNbÓNd×NhÑNhÐirÓNs×yÐyÐwyÓz÷  Añ  Aó  CˆßÙ!8¸Ó!QˆF�:ÑÙ8¸È
ÕASÐU[Ð\fÕUgÓhˆˆzÑØ€Mr   )rÙ   z	llama.cppz	llama-cppr¼   r�   )CÚ__conditional_annotations__Ú__doc__Ú
__future__r   Úloggingrß   Útypingr   r   r   r   r   ré   r   r	   Úagent.custom_entry_poolr
   r   r   Úagent.secret_scoper   Úutilsr   Ú	getLoggerr8   rX  r   r%   r+   r/   r:   rA   rF   rO   rY   r^   rd   ro   r~   r„   rŽ   r’   r—   rŒ   r–   r¯   r´   r¸   rÀ   rÃ   rÔ   rå   rê   rñ   rõ   rô   r  r"  r'  r1  r5  r7  Ú__annotations__r=  rJ  rP  r[  )r\  s   @r   Ú<module>rf     s�  øðô#õ #ã Û 	ß 7Õ 7ç Nß kÑ kÝ -Ý #à	×	Ò	Ð8Ó	9€à:Ð òõ3õ8õ$õõ(/õOõZõ.õ0õ2õ(?ð" ØSW÷ õFð&'ØCGð'à $÷'õ'õ
õSõ8
Kõõ}õ&õ0kõFõ6ð,-<¸4ð -<Ðbfð -<Ø59÷-<õ`÷.'õRõ
H÷%õP,õgõ"õ8>ð *2Ð3NÐ(OÐ �~Ó Oõõ"võ2ð$CÐ`dð CØEIðCà@DðCàMQ÷Cñ Cr   