Ë
    ãß²jà  ã                  ó”   — d Z ddlmZ ddlZddlmZmZmZ ddlm	Z	m
Z
mZmZ  ej                  d«      Zddd	œdd
„Zdd„Zdd„Zdd„Zy)aa  Plugin-registered TTS providers for ``tools.tts_tool``: routes ``tts.provider: <name>`` values
that are neither built-in nor ``type: command`` to a plugin :class:`agent.tts_provider.TTSProvider`.
Discovery goes through ``hermes_cli.plugins._ensure_plugins_discovered`` (imported lazily so the
tool module stays importable without the plugin machinery).
é    )ÚannotationsN)ÚAnyÚDictÚOptional)ÚBUILTIN_TTS_PROVIDERSÚ!DEFAULT_COMMAND_TTS_OUTPUT_FORMATÚ_get_named_provider_configÚ_is_command_provider_configztools.tts_toolTF)ÚdiscoverÚretryc               ój   — ddl m} |rddlm}  |«         || «      }|€|r d¬«        || «      }|S )u  The registered ``TTSProvider`` named *key*, or None. ``discover`` runs plugin discovery first;
    ``retry`` re-discovers with ``force=True`` on a miss (a long-lived session may predate the
    plugin's install). Raises on registry/discovery failure â€” callers decide if fatal.r   )Úget_provider)Ú_ensure_plugins_discoveredT)Úforce)Úagent.tts_registryr   Úhermes_cli.pluginsr   )Úkeyr   r   r   r   Úplugin_providers         ú;/home/ubuntu/.hermes/hermes-agent/tools/tts_tool_plugins.pyÚ_lookup_plugin_providerr      s=   € õ 0ÙÝAÙ"Ô$Ù" 3Ó'€OØÐ¡5Ù"¨Õ.Ù& sÓ+ˆØÐó    c                ó
  — |xs dj                  «       j                  «       }|r|t        v ryt        t	        ||«      «      ry	 t        |d¬«      }|€yt        |t        «      r|ni }|j                  d«      |j                  d«      |j                  d«      }
}	}|j                  d	t        «      }t        j                  d
|«       |j                  | |t        |t        «      r|r|ndt        |	t        «      r|	r|	ndt        |
t         t"        f«      rt#        |
«      nd|rt        |«      j                  «       nd¬«      }t        |t        «      r|r|S |S # t        $ r }t        j                  d|«       Y d}~yd}~ww xY w)a  Route to a plugin-registered TTS provider; None means "fall through".

    Invariants re-checked here so a caller refactor can't break them: built-in names never reach
    the registry; a same-named ``type: command`` provider wins; only an exact registered name
    dispatches. Plugin exceptions propagate to ``text_to_speech_tool``'s error envelope.

    Resolution invariants enforced here (matches issue #30398):
    1. The caller is responsible for the elif chain that handles ``edge``/``openai``/etc.; this function
    explicitly rejects those names defensively. 2. 3. Plugin dispatch fires only when ``provider`` matches a
    registered :class:`TTSProvider` whose ``name`` equals the configured value. Unknown names return None
    (caller falls through to Edge default). See #17843.
    Ú NT)r   z2tts plugin dispatch skipped (discovery failed): %sÚvoiceÚmodelÚspeedÚoutput_formatz2Generating speech with plugin TTS provider '%s'...Úmp3)r   r   r   Úformat)ÚlowerÚstripr   r
   r	   r   Ú	ExceptionÚloggerÚdebugÚ
isinstanceÚdictÚgetr   ÚinfoÚ
synthesizeÚstrÚintÚfloat)ÚtextÚoutput_pathÚproviderÚ
tts_configr   r   ÚexcÚcfgr   r   r   ÚfmtÚwrittens                r   Ú_dispatch_to_plugin_providerr5   "   sR  € ð Š>�r×
 Ñ
 Ó
"×
(Ñ
(Ó
*€CÙ�#Ô.Ñ.ØÜ"Ô#=¸jÈ#Ó#NÔOØðÜ1°#¸TÔBˆð ÐØä" :¬tÔ4‰*¸"€CØŸ'™' 'Ó*¨C¯G©G°GÓ,<¸c¿g¹gÀgÓ>N�%ˆ5€EØ
�'‰'�/Ô#DÓ
E€CÜ
‡K�KÐDÀcÔJØ×(Ñ(Øˆk¬*°U¼CÔ*@ÁU¡ÐPTÜ! %¬Ô-±%‰e¸TÜ(¨´´e°Ô=Œe�EŒlÀ4Ù#&Œs�3‹x�~‰~Ô¨Eð	 )ó 3€Gô
 ! ¬#Ô.±7ˆ7ÐKÀÐKøô ò Ü�‰ÐIÈ3ÔOÜûðús   ÁE Å	FÅ"E=Å=Fc                ó  — | xs dj                  «       j                  «       }|r|t        v ry	 t        |d¬«      }|duxr t	        |j
                  «      S # t        $ r!}t        j                  d||«       Y d}~yd}~ww xY w)z`True when the registered plugin provider opts into voice-bubble delivery (any failure -> False).r   F)r   Nz5tts plugin voice_compatible check failed for '%s': %s)	r    r!   r   r   ÚboolÚvoice_compatibler"   r#   r$   )r/   r   r   r1   s       r   Ú$_plugin_provider_is_voice_compatibler9   H   s|   € àŠ>�r×
 Ñ
 Ó
"×
(Ñ
(Ó
*€CÙ�#Ô.Ñ.ØðÜ1°#ÀÔFˆØ dÐ*ÒU¬t°O×4TÑ4TÓ/UÐUøÜò Ü�‰ÐLÈcÐSVÔWÜûðús   ¯'A Á	BÁ A<Á<Bc                ór   — 	 t        | «      }t        |xr |j                  «       «      S # t        $ r Y yw xY w)zh``check_fn`` leg for plugin names: discovered provider reports ``is_available()``; any failure is False.F)r   r7   Úis_availabler"   )r/   Úplugins     r   Ú_plugin_provider_is_availabler=   U   s<   € ðÜ(¨Ó2ˆÜ�FÒ4˜v×2Ñ2Ó4Ó5Ð5øÜò Ùðús   ‚'* ª	6µ6)r   r*   r   r7   r   r7   )
r-   r*   r.   r*   r/   r*   r0   zDict[str, Any]ÚreturnzOptional[str])r/   r*   r>   r7   )Ú__doc__Ú
__future__r   ÚloggingÚtypingr   r   r   Útools.tts_command_providerr   r   r	   r
   Ú	getLoggerr#   r   r5   r9   r=   © r   r   ú<module>rF      sT   ðñõ #ã ß &Ñ &÷!ó !ð 
ˆ×	Ñ	Ð+Ó	,€ð ;?Èeõ ó#LóL
ôr   