
    PL
jK                        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i Zded<    ej                    ZddZddZddZddZddZdS )a  
Video Generation Provider Registry
==================================

Central map of registered providers. Populated by plugins at import-time via
``PluginContext.register_video_gen_provider()``; consumed by the
``video_generate`` tool to dispatch each call to the active backend.

Active selection
----------------
The active provider is chosen by ``video_gen.provider`` in ``config.yaml``.
If unset, :func:`get_active_provider` applies fallback logic:

1. If exactly one provider is registered, use it.
2. Otherwise return ``None`` (the tool surfaces a helpful error pointing
   the user at ``hermes tools``).

Mirrors ``agent/image_gen_registry.py`` so the two surfaces behave the
same.
    )annotationsN)DictListOptional)VideoGenProviderzDict[str, VideoGenProvider]
_providersproviderr   returnNonec                <   t          | t                    s$t          dt          |           j                   | j        }t          |t                    r|                                st          d          t          5  t                              |          }| t          |<   ddd           n# 1 swxY w Y   |0t                              d|t          |          j                   dS t                              d|t          |           j                   dS )u   Register a video generation provider.

    Re-registration (same ``name``) overwrites the previous entry and logs
    a debug message — this makes hot-reload scenarios (tests, dev loops)
    behave predictably.
    z=register_provider() expects a VideoGenProvider instance, got z3Video gen provider .name must be a non-empty stringNz.Video gen provider '%s' re-registered (was %r)z'Registered video gen provider '%s' (%s))
isinstancer   	TypeErrortype__name__namestrstrip
ValueError_lockr   getloggerdebug)r	   r   existings      </home/kuhnn/.hermes/hermes-agent/agent/video_gen_registry.pyregister_providerr   %   sJ    h 011 
->>*- -
 
 	
 =DdC   P

 PNOOO	 $ $>>$''#
4$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ EtTRZ^^Mdeeeee>d8nnF]^^^^^s    %B11B58B5List[VideoGenProvider]c                     t           5  t          t                                                    } ddd           n# 1 swxY w Y   t	          | d           S )z0Return all registered providers, sorted by name.Nc                    | j         S )Nr   )ps    r   <lambda>z list_providers.<locals>.<lambda>A   s    qv     )key)r   listr   valuessorted)itemss    r   list_providersr(   =   s    	 * *Z&&(())* * * * * * * * * * * * * * *%--....s   ';??r   r   Optional[VideoGenProvider]c                    t          | t                    sdS t          5  t                              |                                           cddd           S # 1 swxY w Y   dS )z5Return the provider registered under *name*, or None.N)r   r   r   r   r   r   r   s    r   get_providerr+   D   s    dC   t	 , ,~~djjll++, , , , , , , , , , , , , , , , , ,s   ,AAAc                    d} 	 ddl m}  |            }t          |t                    r|                    d          nd}t          |t                    rR|                    d          }t          |t
                    r(|                                r|                                } n2# t          $ r%}t          	                    d|           Y d}~nd}~ww xY wt          5  t          t                    }ddd           n# 1 swxY w Y   | r4|                    |           }||S t          	                    d|            t          |          dk    r.t          t          |                                                    S dS )	zResolve the currently-active provider.

    Reads ``video_gen.provider`` from config.yaml; falls back per the
    module docstring.
    Nr   )load_config	video_genr	   z1Could not read video_gen.provider from config: %szCvideo_gen.provider='%s' configured but not registered; falling back   )hermes_cli.configr-   r   dictr   r   r   	Exceptionr   r   r   r   lennextiterr%   )
configuredr-   cfgsectionrawexcsnapshotr	   s           r   get_active_providerr<   L   s    !%J
O111111kmm*4S$*?*?I#''+&&&Tgt$$ 	)++j))C#s## )		 ) YY[[
 O O OH#NNNNNNNNO 
 $ $
##$ $ $ $ $ $ $ $ $ $ $ $ $ $ $  
<<
++OQ	
 	
 	
 8}}D**++,,,4s*   B#B( (
C2CC!DD	Dc                 x    t           5  t                                           ddd           dS # 1 swxY w Y   dS )z"Clear the registry. **Test-only.**N)r   r   clear r"   r   _reset_for_testsr@   r   s~    	                   s   /33)r	   r   r
   r   )r
   r   )r   r   r
   r)   )r
   r)   )r
   r   )__doc__
__future__r   logging	threadingtypingr   r   r   agent.video_gen_providerr   	getLoggerr   r   r   __annotations__Lockr   r   r(   r+   r<   r@   r?   r"   r   <module>rJ      s    * # " " " " "      ' ' ' ' ' ' ' ' ' ' 5 5 5 5 5 5		8	$	$ +-
 , , , ,	_ _ _ _0/ / / /, , , ,# # # #L     r"   