
    `gj?                        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)a  
Transcription Provider Registry
================================

Central map of registered STT providers. Populated by plugins at
import-time via :meth:`PluginContext.register_transcription_provider`;
consumed by :mod:`tools.transcription_tools` to dispatch
:func:`transcribe_audio` calls to the active plugin backend **when**
the configured ``stt.provider`` name is not a built-in.

Built-ins-always-win
--------------------
Plugin names that collide with a built-in STT provider (``local``,
``local_command``, ``groq``, ``openai``, ``mistral``, ``xai``) are
rejected at registration with a warning. This invariant is also
re-checked at dispatch time in
:func:`tools.transcription_tools._dispatch_to_plugin_provider`.
    )annotationsN)DictListOptional)TranscriptionProvider>   xaigroqlocalopenaimistral	deepinfra
elevenlabslocal_commandz Dict[str, TranscriptionProvider]
_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 transcription provider.

    Rejects:

    - Non-:class:`TranscriptionProvider` 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.
    zBregister_provider() expects a TranscriptionProvider instance, got z7Transcription provider .name must be a non-empty stringu   Transcription provider '%s' shadows a built-in name; registration ignored. Built-in STT providers (%s) always win — pick a different name.z, Nz2Transcription provider '%s' re-registered (was %r)z+Registered transcription provider '%s' (%s))
isinstancer   	TypeErrortype__name__namestrstrip
ValueErrorlower_BUILTIN_NAMESloggerwarningjoinsorted_lockr   getdebug)providerr   keyexistings       O/root/.hermes/venv/lib/python3.12/site-packages/agent/transcription_registry.pyregister_providerr'   8   s    h 56>**+-
 	
 ==DdC 

RSS
**,


C
n 6.12		
 		 #>>#&"
3# @h((	

 	9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>j   s
    qvv     )r$   )r    listr   valuesr   )itemss    r&   list_providersr1   f   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.transcription_tools._get_provider`` normalizes the
    configured ``stt.provider`` value.
    N)r   r   r   r!   r   r   r*   s    r&   get_providerr3   m   s/     dC >>$**,,,.//r-   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 r-   r&   _reset_for_testsr7   y   s&    	   s   %.)r#   r   returnNone)r8   zList[TranscriptionProvider])r   r   r8   zOptional[TranscriptionProvider])r8   r9   )__doc__
__future__r   logging	threadingtypingr   r   r   agent.transcription_providerr   	getLoggerr   r   	frozensetr   r   __annotations__Lockr    r'   r1   r3   r7   r6   r-   r&   <module>rD      sq   & #   ' ' >			8	$  	 	 02
, 1	+
\/	0r-   