o
    PL
j#                     @   s   U d Z ddlZddlmZ ddlmZ ddlmZ ee	Z
daee dB ed< G dd deZed	d
dddddddd	Zee dS )zOpenRouter provider profile.    N)Any)register_provider)ProviderProfile_CACHEc                       s   e Zd ZdZddddedB dedee dB f fdd	Zdd
dedB dede	eef fddZ
dddddde	dB dededB dedB dedee	eef e	eef f fddZ  ZS )OpenRouterProfileuM   OpenRouter aggregator — provider preferences, reasoning config passthrough.Ng       @api_keytimeoutr   r	   returnc             
      sb   t durt S zt jd|d}|dur|a |W S  ty0 } ztd| W Y d}~dS d}~ww )u|  Fetch from public OpenRouter catalog — no auth required.

        Note: Tool-call capability filtering is applied by hermes_cli/models.py
        via fetch_openrouter_models() → _openrouter_model_supports_tools(), not
        here. The picker early-returns via the dedicated openrouter path before
        reaching this method, so filtering here would be unreachable.
        Nr   zfetch_models(openrouter): %s)r   superfetch_models	Exceptionloggerdebug)selfr   r	   resultexc	__class__ O/home/kuhnn/.hermes/hermes-agent/plugins/model-providers/openrouter/__init__.pyr      s   zOpenRouterProfile.fetch_models)
session_idr   contextc             	   K   s   i }| d}|r||d< | dpd}|dkrR| d}|d urR|dkrRzt|}W n ttfy8   d }Y nw |d urRd|  krGdkrRn |S d	|d
g|d< |S )Nprovider_preferencesprovidermodel zopenrouter/pareto-codeopenrouter_min_coding_scoreg        g      ?zpareto-router)idmin_coding_scoreplugins)getfloat	TypeError
ValueError)r   r   r   bodyprefsr   scorescore_fr   r   r   build_extra_body*   s$   

z"OpenRouterProfile.build_extra_bodyF)reasoning_configsupports_reasoningr   r   r*   r+   r   c                K   s`   i }|r|durt ||d< nddd|d< i }|r%|r%|dr%||d< ||r-d|ifS i fS )	a  OpenRouter passes the full reasoning_config dict as extra_body.reasoning.

        For xAI Grok models routed through OpenRouter, attach the
        ``x-grok-conv-id`` header so that xAI's prompt cache stays pinned to
        the same backend server across turns.
        N	reasoningTmedium)enabledeffort)z
x-ai/grok-z	xai/grok-zx-grok-conv-idextra_headers)dict
startswith)r   r*   r+   r   r   r   
extra_bodyr0   r   r   r   build_api_kwargs_extrasD   s   z)OpenRouterProfile.build_api_kwargs_extras)__name__
__module____qualname____doc__strr"   listr   r   r1   r)   booltupler4   __classcell__r   r   r   r   r      sH    


r   
openrouter)or)OPENROUTER_API_KEY
OpenRouteru*   OpenRouter — unified API for 200+ modelszhttps://openrouter.ai/keyszhttps://openrouter.ai/api/v1z#https://openrouter.ai/api/v1/models)zanthropic/claude-sonnet-4.6zopenai/gpt-5.4zdeepseek/deepseek-chatzgoogle/gemini-3-flash-previewzqwen/qwen3-plus)	namealiasesenv_varsdisplay_namedescription
signup_urlbase_url
models_urlfallback_models)r8   loggingtypingr   	providersr   providers.baser   	getLoggerr5   r   r   r:   r9   __annotations__r   r>   r   r   r   r   <module>   s(    
S