
    sj                     
   d Z ddlm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de dd          Z eddddedddde d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)__version__)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      P/home/agent/.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_configr3   c                |   i }i }|rt          |t                    sddi|d<   ||fS |                    dd          }|du rddi|d<   ||fS ddlm}m}m} |                    d	          pd
                                                                }	|	r|	dk    r ||	||          }
n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disabledr   )KIMI_K3_EFFORTSKIMI_K3_OVERRIDESclamp_efforteffortr   noneNreasoning_effort)	
isinstancedictgetagent.reasoning_effortr9   r:   r;   r'   r   )r.   r3   context
extra_body	top_levelr6   r9   r:   r;   r<   	k3_efforts              r   build_api_kwargs_extrasz#KimiProfile.build_api_kwargs_extras=   sB    
	 	)z2BD'I'I 	) '-i%8Jz"y(("&&y$77e&,j%9Jz"y((	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 #&&x006B==??EEGG 	f&&$V_>OPPIII'',5I())&,i%8Jz"9$$r+   )__name__
__module____qualname____doc__strfloatlistr-   r@   tupler   rG   __classcell__)r2   s   @r   r    r    %   s        OO
 ##L L L tL *	L
 L 
cT	L L L L L L, 261% 1% 1%#'$;1%	tCH~tCH~-	.1% 1% 1% 1% 1% 1% 1% 1%r+   r    zkimi-coding)kimimoonshotzkimi-for-coding)KIMI_API_KEYKIMI_CODING_API_KEYzhttps://api.moonshot.ai/v1i }  z%https://hermes-agent.nousresearch.comzHermes AgentzHermesAgent/)zHTTP-RefererzX-Titlez
User-Agentz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)rK   typingr   urllib.parser   
hermes_clir   _HERMES_VERSION	providersr   providers.baser   r   rL   boolr   r    rQ   kimi_cn r+   r   <module>rf      s          ! ! ! ! ! ! 5 5 5 5 5 5 ' ' ' ' ' ' < < < < < < < <C D    &I% I% I% I% I%/ I% I% I%X {	34)&?!6_66 
 .   +	&!)&?!6_66 
 .    $     '     r+   