
    PL
j!                    D    d Z ddlmZ ddlZddlmZ dddZdd	ZddZdS )z0Shared helpers for direct xAI HTTP integrations.    )annotationsN)Dictnamestrc                    	 ddl m}  ||           }||S n# t          $ r Y nw xY wt          j                            | |          S )zRead ``name`` from ``~/.hermes/.env`` first, then ``os.environ``.

    Wraps :func:`hermes_cli.config.get_env_value` so tests can patch
    ``tools.xai_http.get_env_value`` to inject dotenv-only secrets into the
    xAI credential resolver.
    r   )get_env_value)hermes_cli.configr   	Exceptionosenvironget)r   default_hermes_get_env_valuevalues       2/home/kuhnn/.hermes/hermes-agent/tools/xai_http.pyr   r      so    LLLLLL%%d++L    :>>$(((s    
%%returnc                 @    	 ddl m}  n# t          $ r d} Y nw xY wd|  S )z>Return a stable Hermes-specific User-Agent for xAI HTTP calls.r   __version__unknownzHermes-Agent/)
hermes_clir   r
   r   s    r   hermes_xai_user_agentr      sN     *******       (;(((s   	 Dict[str, str]c                    	 ddl m}   | d          }t          |                    d          pd                                          }t          |                    d          pd                                                              d          }|rd||pd	d
S n# t          $ r Y nw xY w	 ddlm}  |            }t          |                    d          pd                                          }t          |                    d          pd                                                              d          }|rd||pd	d
S n# t          $ r Y nw xY wt          t          d          pd                                          }t          t          d          pd	                                                              d          }d||d
S )u  Resolve bearer credentials for direct xAI HTTP endpoints.

    Prefers Hermes-managed xAI OAuth credentials when available, then falls back
    to ``XAI_API_KEY`` resolved via ``hermes_cli.config.get_env_value`` so keys
    stored in ``~/.hermes/.env`` (the standard Hermes location) are honored —
    not just ones already exported into ``os.environ``. This keeps direct xAI
    endpoints (images, TTS, STT, etc.) aligned with the main runtime auth model
    and preserves the regression contract from PR #17140 / #17163.
    r   )resolve_runtime_providerz	xai-oauth)	requestedapi_key base_url/zhttps://api.x.ai/v1)providerr   r   )%resolve_xai_oauth_runtime_credentialsXAI_API_KEYXAI_BASE_URLxai)
hermes_cli.runtime_providerr   r   r   striprstripr
   hermes_cli.authr"   r   )r   runtimeaccess_tokenr   r"   credsr   s          r   resolve_xai_http_credentialsr-   #   s%   HHHHHH**[AAA7;;y117R88>>@@w{{:..4"55;;==DDSII 	''$=(=  	    IIIIII5577599Y//5266<<>>uyy,,23399;;BB3GG 	''$=(=  	     -..4"55;;==G=00I4IJJPPRRYYZ]^^H  s%   BB 
B+*B+/BE	 	
EE)N)r   r   )r   r   )r   r   )	__doc__
__future__r   r   typingr   r   r   r-        r   <module>r3      s    6 6 " " " " " " 				      ) ) ) ) )$) ) ) ). . . . . .r2   