
    `gjL                        U d Z ddlmZ ddlZddlZddlmZmZmZ ddl	m
Z
  ej                  e      Z eh d      Zi Zded<    ej$                         Zdd	Zdd
ZddZddZy)u  
TTS Provider Registry
=====================

Central map of registered TTS providers. Populated by plugins at
import-time via :meth:`PluginContext.register_tts_provider`; consumed
by :mod:`tools.tts_tool` to dispatch ``text_to_speech`` tool calls to
the active plugin backend **when** the configured ``tts.provider``
name is neither a built-in nor a command-type provider.

Built-ins-always-win
--------------------
Plugin names that collide with a built-in TTS provider (``edge``,
``openai``, ``elevenlabs``, ``minimax``, ``gemini``, ``mistral``,
``xai``, ``piper``, ``kittentts``, ``neutts``) are rejected at
registration with a warning. This invariant is also re-checked at
dispatch time in :func:`tools.tts_tool._dispatch_to_plugin_provider`.

Command-providers-win-over-plugins
----------------------------------
This registry doesn't enforce the command-vs-plugin precedence — that
lives in the dispatcher, which checks for a same-name
``tts.providers.<name>: type: command`` entry before consulting the
registry. The rationale is locality: a name declared in the user's
``config.yaml`` is more specific to their setup than a plugin that
happens to be installed.
    )annotationsN)DictListOptional)TTSProvider>   xaiedgepipergeminineuttsopenaiminimaxmistral	deepinfra	kittentts
elevenlabszDict[str, TTSProvider]
_providersc           	        t        | t              s!t        dt        |       j                         | j
                  }t        |t              r|j                         st        d      |j                         j                         }|t        v r4t        j                  d|dj                  t        t                           yt        5  t         j#                  |      }| t         |<   ddd       +t        j%                  d|t        |      j                         yt        j%                  d|t        |       j                         y# 1 sw Y   axY w)u  Register a TTS provider.

    Rejects:

    - Non-:class:`TTSProvider` instances (raises :class:`TypeError`).
    - Empty/whitespace ``.name`` (raises :class:`ValueError`).
    - Names colliding with a built-in (logs a warning, silently
      ignores — built-ins-always-win invariant).

    Re-registration (same ``name``) overwrites the previous entry and
    logs a debug message — makes hot-reload scenarios (tests, dev
    loops) behave predictably.
    z8register_provider() expects a TTSProvider instance, got z-TTS provider .name must be a non-empty stringu   TTS provider '%s' shadows a built-in name; registration ignored. Built-in TTS providers (%s) always win — pick a different name.z, Nz(TTS provider '%s' re-registered (was %r)z!Registered TTS provider '%s' (%s))
isinstancer   	TypeErrortype__name__namestrstrip
ValueErrorlower_BUILTIN_NAMESloggerwarningjoinsorted_lockr   getdebug)providerr   keyexistings       E/root/.hermes/venv/lib/python3.12/site-packages/agent/tts_registry.pyregister_providerr*   C   s    h,>**+-
 	
 ==DdC 

HII
**,


C
nP6.12	

 		 #>>#&"
3# 6h((	

 	/h((	
# #s   	EEc                     t         5  t        t        j                               } ddd       t	         d       S # 1 sw Y   xY w)z0Return all registered providers, sorted by name.Nc                    | j                   S )Nr   )ps    r)   <lambda>z list_providers.<locals>.<lambda>t   s
    qvv     )r'   )r#   listr   valuesr"   )itemss    r)   list_providersr4   p   s;    	 *Z&&()*%-..* *s	   ;Ac                    t        | t              syt        j                  | j	                         j                               S )u   Return the provider registered under *name*, or None.

    Name matching is case-insensitive and whitespace-tolerant — mirrors
    how ``tools.tts_tool._get_provider`` normalizes the configured
    ``tts.provider`` value.
    N)r   r   r   r$   r   r   r-   s    r)   get_providerr6   w   s/     dC >>$**,,,.//r0   c                 b    t         5  t        j                          ddd       y# 1 sw Y   yxY w)z"Clear the registry. **Test-only.**N)r#   r   clear r0   r)   _reset_for_testsr:      s&    	   s   %.)r&   r   returnNone)r;   zList[TTSProvider])r   r   r;   zOptional[TTSProvider])r;   r<   )__doc__
__future__r   logging	threadingtypingr   r   r   agent.tts_providerr   	getLoggerr   r   	frozensetr   r   __annotations__Lockr#   r*   r4   r6   r:   r9   r0   r)   <module>rG      sq   8 #   ' ' *			8	$    &(
" '	*
Z/	0r0   