
    `gjV              
           d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	 de
defdZ G d	 d
e	      Z eddddedddid      Z eddddedddid      Z ee        ee       y)u   Kimi / Moonshot provider profiles.

Kimi has dual endpoints:
  - sk-kimi-* keys → api.kimi.com/coding (Anthropic Messages API)
  - legacy keys → api.moonshot.ai/v1 (OpenAI chat completions)

This module covers the chat_completions path (/v1 endpoint).
    )Any)urlparse)register_provider)OMIT_TEMPERATUREProviderProfilebase_urlreturnc                    	 t        |       }|j                  }|j                  j	                         dk(  xr |j
                  xs dj	                         dk(  xra |dv xr[ |j                  du xrK |j                  du xr; |j                  j                  d      dv xr |j                   xr |j                   S # t        $ r Y yw xY w)	z>Return True only for Kimi Code's canonical HTTPS API surfaces.Fhttps zapi.kimi.com)Ni  N/>   
/coding/v1/coding)r   port
ValueErrorschemelowerhostnameusernamepasswordpathrstripqueryfragment)r   parsedr   s      _/root/.hermes/venv/lib/python3.12/site-packages/plugins/model-providers/kimi-coding/__init__.py_is_confirmed_kimi_coding_urlr      s    (#{{ 	( 	 __"))+~=	 K	  OOt#	  OOt#		 
 KKs#'@@	  	  	  s   B< <	CCc            
            e Zd Z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dd
dedz  de	eee
f   eee
f   f   fdZ xZS )KimiProfileuE   Kimi/Moonshot — temperature omitted, thinking xor reasoning_effort.Ng       @api_keyr   timeoutr!   r   r"   r	   c                b   |xs | j                   xs dj                  d      }t        |      }|r,t        |      j                  j                  d      dk(  r|dz  }t
        |   ||xs d|      }||r|S |D cg c]&  }|j                         j                         dk7  s%|( c}S c c}w )z>Use Kimi Code's OpenAI-compatible surface for model discovery.r   r   r   z/v1Nr    k3)	r   r   r   r   r   superfetch_modelsstripr   )	selfr!   r   r"   effective_baseconfirmed_coding_endpointmodelsmodel	__class__s	           r   r&   zKimiProfile.fetch_models'   s     #9dmm9rAA#F$A.$Q!$.)A)F)F)M)Mc)RV_)_e#N%#+t & 

 >6M#)K%U[[]-@-@-Bd-JKKKs   >&B,%B,)reasoning_configr.   c                   i }i }|rt        |t              sddi|d<   ||fS |j                  dd      }|du rddi|d<   ||fS |j                  d      xs dj                         j	                         }|d	v r	||d
<   ||fS ddi|d<   ||fS )u  Kimi reasoning controls.

        Moonshot's wire shape treats ``extra_body.thinking`` (a binary toggle)
        and a top-level ``reasoning_effort`` as mutually exclusive — sending
        both is at best redundant and risks "cannot specify both 'thinking' and
        'reasoning_effort'" (HTTP 400). This mirrors the kimi-k2 handling on the
        opencode-go relay: send effort when one is requested, otherwise fall
        back to ``extra_body.thinking`` — never both.
        typeenabledthinkingTFdisabledeffortr   >   lowhighmediumreasoning_effort)
isinstancedictgetr'   r   )r(   r.   context
extra_body	top_levelr1   r4   s          r   build_api_kwargs_extrasz#KimiProfile.build_api_kwargs_extras<   s     
	z2BD'I '-i%8Jz"y(("&&y$7e&,j%9Jz"y(( #&&x06B==?EEG..,2I() 9$$ '-i%8Jz"9$$    )__name__
__module____qualname____doc__strfloatlistr&   r:   tupler   r?   __classcell__)r-   s   @r   r   r   $   s    O
 ##L tL *	L
 L 
cT	L, 26#%#'$;#%	tCH~tCH~-	.#%r@   r   zkimi-coding)kimimoonshotzkimi-for-coding)KIMI_API_KEYKIMI_CODING_API_KEYzhttps://api.moonshot.ai/v1i }  z
User-Agentzhermes-agent/1.0zkimi-k2-turbo-preview)namealiasesenv_varsr   fixed_temperaturedefault_max_tokensdefault_headersdefault_aux_modelzkimi-coding-cn)zkimi-cnzmoonshot-cn)KIMI_CN_API_KEYzhttps://api.moonshot.cn/v1N)rD   typingr   urllib.parser   	providersr   providers.baser   r   rE   boolr   r   rJ   kimi_cn r@   r   <module>r]      s     ! ' <C D &;%/ ;%| 	34)&!#56-	 	&!)&!#56-	 $  ' r@   