Ë
    âß²jå  ã                   ó¨   — d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZ ded	z  d
efd„Z G d„ de«      Z edddd¬«      Z e	e«       y	)u†   Custom / Ollama (local) provider profile: any endpoint registered as
provider="custom" (Ollama, vLLM, llama.cpp, GLM-5.2 on ARK, â€¦).é    )ÚAny)Úurlparse)ÚOPENAI_COMPAT_WIRE_EFFORTSÚclamp_effort)Úregister_provider)ÚProviderProfile)Úbase_url_host_matchesÚbase_urlNÚreturnc                 óh  — | xs dj                  «       }|syt        d|v r|nd|› �«      }	 |j                  dk(  ry	 |j                  xs dj                  «       j                  d«      }t        |«      xr- |dk(  xs& |j                  d	«      xs d
|j                  d«      v S # t        $ r Y yw xY w)zÛTrue only for explicit Ollama signatures (port 11434 or an ``ollama`` host label).
    ``think`` is Ollama-native; strict hosts (Mistral, Groq) 422 on it, and
    arbitrary localhost may be llama.cpp / vLLM / LM Studio.Ú Fz://z//iª,  Tú.z
ollama.comz.ollama.comÚollama)
Ústripr   ÚportÚ
ValueErrorÚhostnameÚlowerÚrstripÚboolÚendswithÚsplit)r
   ÚrawÚparsedÚhosts       úL/home/ubuntu/.hermes/hermes-agent/plugins/model-providers/custom/__init__.pyÚ_looks_like_ollama_endpointr      s¿   € ð Š>�r×
 Ñ
 Ó
"€CÙØÜ˜U c™\‘c°°C°5¨zÓ:€FðØ�;‰;˜%ÒØð  ð �O‰OÒ!˜r×(Ñ(Ó*×1Ñ1°#Ó6€DÜ�‹:Òo˜4 <Ñ/Òn°4·=±=ÀÓ3OÒnÐS[Ð_c×_iÑ_iÐjmÓ_nÐSnÐoøô ò Ùðús   ­B% Â%	B1Â0B1c                   óÞ   ‡ — e Zd ZdZdedz  deedf   fd„Zddedz  dedz  fd„Zdddœd	edz  d
e	dz  de
deeee
f   eee
f   f   fd„Zddddœdedz  dedz  dedee   dz  fˆ fd„Zˆ xZS )ÚCustomProfileuA   Custom/Ollama local provider â€” think=false and num_ctx support.ÚmodelNr   .c                 ó   — t         S )u…  The OpenAI-compat wire set, mirroring this profile's own chat-completions clamp.

        Without this declaration the Responses transport clamps onto the OpenAI
        per-model ladder (``codex_supported_efforts``), where ``max`` is gpt-5.6-only â€”
        so a custom relay's model had a configured ``max`` silently demoted to
        ``xhigh`` while the same provider over chat-completions forwarded ``max``
        unchanged (#114249). A custom endpoint's vocabulary is undiscoverable, so
        the widest OpenAI-compat set is the honest ceiling; ``ultra`` still clamps
        to ``max`` via the shared ``clamp_effort`` policy.
        )r   ©Úselfr    s     r   Úsupported_reasoning_effortsz)CustomProfile.supported_reasoning_efforts!   s
   € ô *Ð)ó    c                 ó   — dddœS )uÞ  Unset ``agent.reasoning_effort`` â†’ ``medium``, as on the Nous / OpenRouter profiles.

        Leaving the field off lets the endpoint's own default apply, and for a hosted reasoning
        model that default can be its ceiling: kimi-k3 behind an OpenAI-compatible relay defaults
        to ``max`` â€” 3x the reasoning tokens and ~3x the latency of medium. The agent skips this
        default for models the catalog marks non-reasoning (``agent.reasoning_params``).
        TÚmedium)ÚenabledÚeffort© r"   s     r   Údefault_reasoning_configz&CustomProfile.default_reasoning_config.   s   € ð  ¨8Ñ4Ð4r%   )Úreasoning_configÚollama_num_ctxr,   r-   Úctxc                ó¼  — i }i }|rd|i|d<   |rÊt        |t        «      rº|j                  d«      xs dj                  «       j	                  «       }|dk(  s|j                  dd«      du r(d|d	<   t        |j                  d
«      «      rd|d<   ||fS |r1t        t        |j                  d
«      xs d«      d«      r	d|d	<   ||fS |rt        |t        «      |d	<   ||fS )NÚnum_ctxÚoptionsr)   r   Únoner(   TFÚreasoning_effortr
   Úthinkzapi.groq.comÚdefault)
Ú
isinstanceÚdictÚgetr   r   r   r	   Ústrr   r   )r#   r,   r-   r.   Ú
extra_bodyÚ	top_levelr)   s          r   Úbuild_api_kwargs_extrasz%CustomProfile.build_api_kwargs_extras8   s  € ð &(ˆ
Ø$&ˆ	ÙØ%.°Ð$?ˆJ�yÑ!ñ ¤
Ð+;¼TÔ BØ&×*Ñ*¨8Ó4Ò:¸×AÑAÓC×IÑIÓKˆFØ˜ÒÐ#3×#7Ñ#7¸	À4Ó#HÈEÑ#Qà06�	Ð,Ñ-Ü.¨s¯w©w°zÓ/BÔCØ*/�J˜wÑ'ð ˜9Ð$Ð$ñ Ô1´#°c·g±g¸jÓ6IÒ6OÈRÓ2PÐR`Ôað 1:�	Ð,Ñ-ð ˜9Ð$Ð$ñ Ü0<¸VÔE_Ó0`�	Ð,Ñ-Ø˜9Ð$Ð$r%   g       @©Úapi_keyr
   Útimeoutr>   r
   r?   c                óF   •— |s| j                   syt        ‰| �	  |||¬«      S )z/base_url is user-configured; fetch only if set.Nr=   )r
   ÚsuperÚfetch_models)r#   r>   r
   r?   Ú	__class__s       €r   rB   zCustomProfile.fetch_modelsV   s)   ø€ ñ ˜DŸMšMØÜ‰wÑ#¨G¸hÐPWÐ#ÓXÐXr%   )N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r9   Útupler$   r7   r+   Úintr   r<   ÚfloatÚlistrB   Ú__classcell__)rC   s   @r   r   r      sÚ   ø„ ÙKð*°°t±ð *ÀÀcÈ3ÀhÁó *ñ5¨c°D©jð 5ÀDÈ4ÁKó 5ð 26ÐTXò%Ø#'¨$¡;ð%ØGJÈTÁzð%Øadð%à	ˆt�C˜�H‰~˜t C¨ H™~Ð-Ñ	.ó%ð> (,ÀDÐ[^òYØ ™*ðYØ7:¸T±zðYØSXðYà	ˆc‰�TÑ	÷Yñ Yr%   r   Úcustom)r   ÚlocalÚvllmÚllamacppz	llama.cppz	llama-cppr*   r   )ÚnameÚaliasesÚenv_varsr
   )rG   Útypingr   Úurllib.parser   Úagent.reasoning_effortr   r   Ú	providersr   Úproviders.baser   Úutilsr	   r9   r   r   r   rM   r*   r%   r   ú<module>rZ      sj   ðñEõ Ý !ç KÝ 'Ý *Ý 'ðp¨#°©*ð p¸ó pô">Y�Oô >YñB 
Ø	Ð\ØØô
€ñ �&Õ r%   