
    [jV              
           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           dS )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                 P   	 t          |           }|j        }n# t          $ r Y dS w xY w|j                                        dk    o`|j        pd                                dk    oA|dv o=|j        du o4|j        du o+|j        	                    d          dv o|j
         o|j         S )	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      N/home/ice/.hermes/hermes-agent/plugins/model-providers/kimi-coding/__init__.py_is_confirmed_kimi_coding_urlr      s    (##{   uu 	( 	 _"))++~=	 K	  Ot#	  Ot#		 
 Ks##'@@	  	  	s    
''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                2   |p| j         pd                    d          }t          |          }|r0t          |          j                            d          dk    r|dz  }t                                          ||pd|          }||r|S d |D             S )z>Use Kimi Code's OpenAI-compatible surface for model discovery.r   r   r   z/v1Nr    c                 f    g | ].}|                                                                 d k    ,|/S )k3)stripr   ).0models     r   
<listcomp>z,KimiProfile.fetch_models.<locals>.<listcomp>:   s6    KKK%U[[]]-@-@-B-Bd-J-J-J-J-J    )r   r   r   r   r   superfetch_models)selfr!   r   r"   effective_baseconfirmed_coding_endpointmodels	__class__s          r   r,   zKimiProfile.fetch_models'   s     #9dm9rAA#FF$A.$Q$Q!$ 	$.)A)A)F)M)Mc)R)RV_)_)_e#N%%#+t & 
 

 >6>MKK6KKKKr*   )reasoning_configr2   c                8   i }i }|rt          |t                    sddi|d<   ||fS |                    dd          }|du rddi|d<   ||fS |                    d          pd                                                                }|d	v r||d
<   n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-   r2   context
extra_body	top_levelr5   r8   s          r   build_api_kwargs_extrasz#KimiProfile.build_api_kwargs_extras<   s     
	 	)z2BD'I'I 	) '-i%8Jz"y(("&&y$77e&,j%9Jz"y(( #&&x006B==??EEGG...,2I())&,i%8Jz"9$$r*   )__name__
__module____qualname____doc__strfloatlistr,   r>   tupler   rC   __classcell__)r1   s   @r   r   r   $   s        OO
 ##L L L tL *	L
 L 
cT	L L L L L 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)rG   typingr   urllib.parser   	providersr   providers.baser   r   rH   boolr   r   rM   kimi_cn r*   r   <module>r`      sB          ! ! ! ! ! ! ' ' ' ' ' ' < < < < < < < <C D    &;% ;% ;% ;% ;%/ ;% ;% ;%| {	34)&!#56-	 	 	 +	&!)&!#56-	 	 	  $     '     r*   