Ë
    ãß²j~B  ã                  óè  — 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m	Z	 ddl
mZmZmZmZmZ ddlmZmZ  ej&                  e«      Zddd	d
ddœdddœd
 ee«      dedœd
 ee«      dedœdœdgdœdœZded<   d:d„Zd;d„Zd;d„Zd„ Zd<d„Zd„ Zd=d„Zddddd d d d d!œZ d>d"„Z!d?d#„Z"d@d$„Z#dAd%„Z$d&d'd
d(dœfd)d*d+d,dœfd-d.dd/dœfd0d1d+d2dœffZ%d3Z&dBd4„Z'dCd5„Z(dDd6„Z) ejT                  dd7ee$eg d d8e)¬9«	       y)EuÔ  ``video_generate``: one tool dispatching to a plugin-registered :class:`VideoGenProvider`
(``agent/video_gen_provider.py`` ABC, ``agent/video_gen_registry.py``, ``plugins/video_gen/<name>/``).

Ships **no in-tree provider**: enable a plugin and select it in ``hermes tools`` â†’ Video
Generation. The tool layer only does lightweight validation; each provider clamps/ignores
unsupported params inside ``generate``. Video edit/extend are deliberately not exposed here.
é    )ÚannotationsN)ÚAnyÚDictÚListÚOptional)ÚCOMMON_ASPECT_RATIOSÚCOMMON_RESOLUTIONSÚDEFAULT_ASPECT_RATIOÚDEFAULT_RESOLUTIONÚerror_response)ÚregistryÚ
tool_errorÚvideo_generateuG   (rebuilt at get_definitions() time â€” see _build_dynamic_video_schema)ÚobjectÚstringz\Text instruction describing the desired video, motion, subject, style, camera movement, etc.©ÚtypeÚdescriptionÚintegerzkDesired video duration in seconds. Providers clamp to their supported range. Omit for the provider default.zOutput aspect ratio.)r   Úenumr   ÚdefaultzOutput resolution.)ÚpromptÚdurationÚaspect_ratioÚ
resolutionr   ©r   Ú
propertiesÚrequired)Únamer   Ú
parametersúDict[str, Any]ÚVIDEO_GENERATE_SCHEMAc                óî   — 	 ddl m}m}  | |«       d| «      }t        |t        «      r |j                  «       r|j                  «       S dS # t        $ r }t        j                  d|«       Y d}~yd}~ww xY w)zIReturn the stripped ``video_gen.<key>`` string from config.yaml, or None.r   )Úcfg_getÚload_configÚ	video_genz#Could not read video_gen config: %sN)	Úhermes_cli.configr$   r%   Ú	ExceptionÚloggerÚdebugÚ
isinstanceÚstrÚstrip)Úkeyr$   r%   ÚvalueÚexcs        ú@/home/ubuntu/.hermes/hermes-agent/tools/video_generation_tool.pyÚ_read_video_gen_keyr2   H   sb   € ðß:Ù™› {°CÓ8ˆô ' u¬cÔ2°u·{±{´}ˆ5�;‰;‹=ÐNÈ$ÐNøô ò Ü�‰Ð:¸CÔ@Üûðús   ‚A Á	A4ÁA/Á/A4c                 ó   — t        d«      S )NÚprovider©r2   © ó    r1   Ú_read_configured_video_providerr8   S   s   € Ü˜zÓ*Ð*r7   c                 ó   — t        d«      S )NÚmodelr5   r6   r7   r1   Ú_read_configured_video_modelr;   W   s   € Ü˜wÓ'Ð'r7   c                 ó0   — ddl m}  ddlm}  |«        | |fS )zgImport the provider registry after (idempotent) plugin discovery so user-installed plugins are visible.r   )Úvideo_gen_registry)Ú_ensure_plugins_discovered)Úagentr=   Úhermes_cli.pluginsr>   )r=   r>   s     r1   Ú_discovered_registryrA   [   s   € å(Ý=ÙÔ ØÐ9Ð9Ð9r7   c                 ó\   — t        «       \  } }t        d„ | j                  «       D «       «      S )z=True when at least one registered provider reports available.c              3  ó6   K  — | ]  }t        |d d«      –— Œ y­w)Úis_availableFN)Ú_provider_call)Ú.0Úps     r1   ú	<genexpr>z6check_video_generation_requirements.<locals>.<genexpr>f   s   è ø€ Ò_¸AŒ~˜a °×7Ñ_ùs   ‚)rA   ÚanyÚlist_providers)Úregistry_modÚ_s     r1   Ú#check_video_generation_requirementsrM   c   s(   € ä*Ó,�O€L�!ÜÑ_À×A\ÑA\ÓA^Ô_Ó_Ð_r7   c                 óÐ   — 	 t        «       \  } }| j                  «       }|€ |d¬«       | j                  «       }|S # t        $ r }t        j	                  d|«       Y d}~yd}~ww xY w)zdActive provider or None; a miss forces a discovery refresh (sessions older than the plugin install).NT)Úforcez(video_gen provider resolution failed: %s)rA   Úget_active_providerr(   r)   r*   )rK   Úensure_discoveredr4   r0   s       r1   Ú_resolve_active_providerrR   i   sf   € ð	Ü*>Ó*@Ñ'ˆÐ'Ø×3Ñ3Ó5ˆØÐÙ DÕ)Ø#×7Ñ7Ó9ˆHØˆøÜò Ü�‰Ð?ÀÔEÜûðús   ‚9< ¼	A%ÁA Á A%c                ó�   — | r%t        j                  t        d| › d�d| ¬«      «      S t        j                  t        dd¬«      «      S )Nzvideo_gen.provider='uŸ   ' is set but no plugin registered that name. Run `hermes plugins list` to see installed video gen backends, or `hermes tools` â†’ Video Generation to pick one.Úprovider_not_registered)ÚerrorÚ
error_typer4   u†   No video generation backend is configured. Run `hermes tools` â†’ Video Generation to enable one (xAI, FAL, OpenRouter, or DeepInfra).Úno_provider_configured)rU   rV   )ÚjsonÚdumpsr   )Ú
configureds    r1   Ú_missing_provider_errorr[   w   s]   € ÙÜ�z‰zœ.Ø)¨*¨ð 6Fð Gð 1¸:ô	Gó Hð 	Hô
 �:‰:”nðVà+ô-ó .ð .r7   TF)ÚtrueÚ1ÚyesÚonÚfalseÚ0ÚnoÚoffc                óV   — 	 | �| dk(  rd S t        | «      S # t        t        f$ r Y y w xY w)NÚ )ÚintÚ	TypeErrorÚ
ValueError©r/   s    r1   Ú_coerce_intrj   ˆ   s7   € ðØ�}¨°ªˆtÐC¼¸U»ÐCøÜ”zÐ"ò Ùðús   ‚ ‹
 –(§(c                ó¬   — t        | t        «      r| S t        | t        «      r1t        j	                  | j                  «       j                  «       «      S d S ©N)r+   Úboolr,   Ú_BOOL_WORDSÚgetr-   Úlowerri   s    r1   Ú_coerce_boolrq   �   s>   € Ü�%œÔØˆÜ5?ÀÄsÔ5KŒ;�?‰?˜5Ÿ;™;›=×.Ñ.Ó0Ó1ÐUÐQUÐUr7   c                óè   — t        | t        «      r| g} t        | t        t        f«      sy | D �cg c]4  }t        |t        «      sŒ|j	                  «       sŒ%|j	                  «       ‘Œ6 c}xs d S c c}w rl   )r+   r,   ÚlistÚtupler-   )r/   Úitems     r1   Ú_normalize_reference_imagesrv   •   sU   € Ü�%œÔØ�ˆÜ�eœd¤E˜]Ô+ØØ%*ÖU˜T¬j¸¼sÕ.CÈÏ
É
ÍˆD�J‰J�LÒUÒ]ÐY]Ð]ùÒUs   ¯A/ÁA/ÁA/c                ó¨  ‡‡‡— | j                  d«      xs dj                  «       Š| j                  d«      xs dj                  «       xs d }t        | j                  d«      «      }|j                  d«      }ddlm}  ||||«      \  }}}|�|S t        | j                  d«      «      | j                  d	«      xs t        j                  «       xs t        | j                  d
«      xs t        j                  «       xs t        | j                  d«      xs dj                  «       xs d t        | j                  d«      «      t        | j                  d«      «      t        | j                  d«      «      dœ}‰st        d«      S d| v sd| v rt        d«      S t        «       }t        «       Š‰€t        |«      S t        «       xs ‰j                  «       Š‰||dœ|¥}	|	j                  «       D �
�ci c]  \  }
}|€Œ	|
|“Œ }	}
}t!        ‰dd«      }d ˆˆˆfd„}	  ‰j"                  d!d‰i|	¤Ž}t-        |t.        «      s	 |dd«      S t1        j2                  |«      S c c}}
w # t$        $ r.}t&        j)                  d||«        |d|› d�d«      cY d }~S d }~wt*        $ r0}t&        j)                  d||«        |d|› d|› �d«      cY d }~S d }~ww xY w)"Nr   re   Ú	image_urlÚreference_image_urlsÚtask_idr   )Ú_confine_source_imagesr   r   r   Únegative_promptÚaudioÚseedÚupscale)r   r   r   r|   r}   r~   r   z'prompt is required for video generationÚ	operationÚ	video_urlz†video_generate only supports text-to-video, image-to-video, and reference-to-video; use a provider-specific tool for video edit/extend)r:   rx   ry   r   ú?c                óh   •— t        j                  t        | |t        ‰dd«      ‰xs d‰¬«      «      S )Nr   re   )rU   rV   r4   r:   r   )rX   rY   r   Úgetattr)rU   rV   r:   r   r4   s     €€€r1   Ú_errz$_handle_video_generate.<locals>._errÇ   s7   ø€ Ü�z‰zœ.Ø JÜ˜X v¨rÓ2¸%º+À2ÈfôVó Wð 	Wr7   zBvideo_gen provider '%s' rejected kwargs (signature too narrow): %sz
Provider 'z\' signature is out of date with the video_generate schema. Report this to the plugin author.Úprovider_contractz"video_gen provider '%s' raised: %sz	' error: Úprovider_exceptionz#Provider returned a non-dict result)rU   r,   rV   r,   Úreturnr,   r6   )ro   r-   rv   Útools.image_generation_toolr{   rj   r
   r   rq   r   r8   rR   r[   r;   Údefault_modelÚitemsr„   Úgeneraterg   r)   Úwarningr(   r+   ÚdictrX   rY   )ÚargsÚ_kwrx   ry   rz   r{   Úconfine_errorÚoptionalrZ   ÚkwargsÚkÚvÚpnamer…   Úresultr0   r:   r   r4   s                   @@@r1   Ú_handle_video_generater˜   �   sÑ  ú€ Ø�h‰h�xÓ Ò& B×-Ñ-Ó/€FØ—‘˜+Ó&Ò,¨"×3Ñ3Ó5Ò=¸€IÜ6°t·x±xÐ@VÓ7WÓXÐØ�g‰g�iÓ €Gõ CÙ5KØÐ'¨ó62Ñ2€IÐ# ]àÐ ØÐô   §¡¨Ó 4Ó5ØŸ™ .Ó1ÒIÔ5I×PÑPÓRÒjÔVjØ—x‘x Ó-ÒCÔ1C×JÑJÓLÒbÔPbØ ŸH™HÐ%6Ó7Ò=¸2×DÑDÓFÒNÈ$Ü˜dŸh™h wÓ/Ó0Ü˜DŸH™H VÓ,Ó-Ü §¡¨Ó 3Ó4ñ6€Hñ ÜÐCÓDÐDØ�dÑ˜k¨TÑ1ÜðUóVð 	Vô 1Ó2€JÜ'Ó)€HØÐÜ& zÓ2Ð2ô )Ó*ÒF¨h×.DÑ.DÓ.F€Eà YÐH\ñjØ`hðj€Fð  &Ÿ|™|›~×?‘t�q˜!°±ˆa�‰dÐ?€FÑ?Ü�H˜f cÓ*€E÷WðNØ"�×"Ñ"Ñ;¨&Ð;°FÑ;ˆô �fœdÔ#ÙÐ9Ð;NÓOÐOÜ�:‰:�fÓÐùó+ @øô ò !ä�‰Ð[Ð]bÐdgÔhÙØ˜˜ð  0ð 1àó!õ 	!ûô ò NÜ�‰Ð;¸UÀCÔHÙ�j   y°°Ð6Ð8LÓMÕMûðNús<   Ç2
IÇ=IÈI# É#	KÉ,#JÊKÊKÊ!%KËKËKÚsupports_negative_promptr|   zContent to avoid in the output.Úsupports_audior}   Úbooleanz6Enable native audio generation (affects pricing tier).Úsupports_seedr~   zSeed for reproducible outputs.Úsupports_upscaler   zlHigh-resolution pass via the backend's video upscaler (~2x, extra cost/latency). Omit for native resolution.u[  Generate a video from a text prompt (text-to-video), animate a still image (image-to-video), or guide generation with reference images. Pass `image_url` to animate an image or `reference_image_urls` for reference-to-video. Video edit/extend workflows are not part of this unified surface; use a dedicated provider-specific tool when one is available. The backend and model family are user-configured via `hermes tools` â†’ Video Generation; the agent does not pick them. Long-running generations may take 30 seconds to several minutes â€” the call blocks until the video is ready. Returns the result in the `video` field â€” either an HTTP URL or an absolute file path. To show it to the user, reference that path/URL in your response using the file-delivery convention for the current platform (your platform guidance describes how files are delivered here).c                ó   — | d|dgdœdœS )Nr   r   r   )r   r    r6   )r   r   s     r1   Ú_schemarŸ     s   € à"Ø'°zÐPXÈzÑZñ\ð \r7   c                óP   — 	  t        | |«      «       xs |S # t        $ r |cY S w xY w)zO``provider.<method>()`` or ``default`` when it raises or returns a falsy value.)r„   r(   )r4   Úmethodr   s      r1   rE   rE     s2   € ðØ(Œw�x Ó(Ó*Ò5¨gÐ5øÜò ØŠðús   ‚ —%¤%c                 ól  ‡— t         d   d   } t        g}t        «       }t        «       }|€1|j	                  d«       t        dj                  |«      d| d   i«      S t        |di «      }t        |dg «      }|xs |j                  «       Št        ˆfd„|D «       i «      }t        |j                  d	«      xs g «      }|j                  d
«      }|r|j                  |«       d|v rd|vr|j	                  d«       nd|v rd|vr|j	                  d«       |xs t        |j                  d	«      xs g «      }	d|	v }
d|	v }|
r|s|j	                  d«       n|
s|j	                  d«       |j                  dk(  r6|j	                  d«       	 ddlm}  |d«      }|r|j	                  d|› �«       d| d   i}|
r;dddœ|d<   t#        |j                  d«      xs d«      }|dkD  rdddi|d|› d �d!œ|d"<   |j                  d#|j                  d#«      «      }|j                  d$|j                  d$«      «      }t%        | d%   «      }|r*|r(t#        |«      |d&<   t#        |«      |d'<   d(|› d)|› d*�|d+<   ||d%<   d,D ]:  \  }}t%        | |   «      }|j                  |«      rt'        ||   «      |d-<   |||<   Œ< t(        D ]  \  }}}|j                  |«      sŒ|||<   Œ |j                  d.«      r"|j                  d/«      s|j	                  d0«       t        dj                  |«      |«      S # t         $ r d}Y �Œœw xY w)1z¸Description AND params from capabilities() + the model's catalog entry; enums and duration
    bounds tighten to the active model. Unadvertised args are still accepted (replay compat).r    r   u|   
No video backend is available. Calls will return an error until the user picks one via `hermes tools` â†’ Video Generation.Ú
r   ÚcapabilitiesÚlist_modelsc              3  ón   •K  — | ],  }t        |t        «      sŒ|j                  d «      ‰k(  sŒ)|–— Œ. y­w)ÚidN)r+   rŽ   ro   )rF   ÚmÚactive_models     €r1   rH   z._build_dynamic_video_schema.<locals>.<genexpr>$  s*   øè ø€ Ò`˜Q¬J°q¼$Õ,?ÀAÇEÁEÈ$ÃKÐS_ÓD_”qÑ`ùs   ƒ5™5®5Ú
modalitiesÚmodalityÚimageÚtextu_   - this model is image-to-video only â€” image_url is REQUIRED; text-only calls will be rejecteduA   - this model is text-to-video only â€” image_url is not supportedz,- image-to-video only: image_url is REQUIREDz%- text-to-video only (no image input)ÚxaizÇ- chaining: for edit/extend pass the public HTTPS MP4 in `video` or `public_url` from the prior Imagine result (files-cdn). For image-to-video / reference-to-video pass public image URLs the same wayr   )Úxai_storage_notice_textr&   re   z- storage: r   zVPublic HTTPS URL of a still image to animate (image-to-video). Omit for text-to-video.r   rx   Úmax_reference_imagesÚarrayr   zUp to z= public HTTPS reference image URLs (style or character refs).)r   r‹   ÚmaxItemsr   ry   Úmin_durationÚmax_durationr   ÚminimumÚmaximumzVideo duration in seconds (Ú-z!). Omit for the provider default.r   ))r   Úaspect_ratios)r   Úresolutionsr   Úaudio_always_onrš   u~   - audio: native stereo audio is generated with every video (always on; no toggle) â€” describe the desired sound in the prompt)r"   Ú_GENERIC_DESCRIPTIONr;   rR   ÚappendrŸ   ÚjoinrE   rŠ   ÚnextÚsetro   Úaddr   Útools.xai_httpr¯   r(   rf   rŽ   rs   Ú_CAPABILITY_PARAMS)Ústatic_propsÚpartsÚconfigured_modelr4   ÚcapsÚmodelsÚ
model_metaÚmodel_modalitiesr«   Úeffective_modalitiesÚcan_i2vÚt2vr¯   Únoticer   Úmax_refsr³   r´   Úduration_paramr.   Úcaps_keyÚparamÚflagr©   s                          @r1   Ú_build_dynamic_video_schemarÓ     sž  ø€ ô )¨Ñ6°|ÑD€LÜ,Ð-€EÜ3Ó5ÐÜ'Ó)€HØÐØ�‰ðPô	Qô �t—y‘y Ó'¨(°LÀÑ4JÐ)KÓLÐLÜ˜( N°BÓ7€DÜ˜H m°RÓ8€FØ#Ò? x×'=Ñ'=Ó'?€LÜÓ` &Ô`ÐbdÓe€Jô ˜:Ÿ>™>¨,Ó7Ò=¸2Ó>ÐØ�~‰~˜jÓ)€HÙØ×Ñ˜XÔ&ØÐ"Ñ" vÐ5EÑ'EØ�‰ð/õ	0ð 
Ð#Ñ	#¨Ð7GÑ(GØ�‰ÐXÔYØ+ÒP¬s°4·8±8¸LÓ3IÒ3OÈRÓ/PÐØÐ-Ð-€GØ
Ð(Ð
(€CÙ‘sØ�‰ÐCÕDÙØ�‰Ð<Ô=Ø‡}�}˜ÒØ�‰ðô	ð
	Ý>Ù,¨[Ó9ˆFñ Ø�L‰L˜; v hÐ/Ô0Ø"*¨L¸Ñ,BÐ!C€JÙàð<ñ#>ˆ
�;Ñô
 �t—x‘xÐ 6Ó7Ò<¸1Ó=ˆØ�aŠ<àØ  (Ð+Ø$à˜X˜Jð '1ð 1ñ23ˆJÐ-Ñ.ð —>‘> .°$·(±(¸>Ó2JÓK€LØ—>‘> .°$·(±(¸>Ó2JÓK€LÜ˜, zÑ2Ó3€NÙ™Ü$'¨Ó$5ˆ�yÑ!Ü$'¨Ó$5ˆ�yÑ!à)¨,¨°q¸¸ð G-ð -ð 	�}Ñ%ð ,€JˆzÑð \ò  ‰ˆˆXÜ�\ #Ñ&Ó'ˆØ�8‰8�HÔÜ   h¡Ó0ˆE�&‰MØˆ
�3Šð	 ô
 /ò $Ñˆˆc�5Ø�8‰8�D�>Ø#ˆJ�sŠOð$ð ‡x�xÐ!Ô"¨4¯8©8Ð4DÔ+EØ�‰ðô	ô �4—9‘9˜UÓ# ZÓ0Ð0øô[ ò 	Ø‹Fð	ús   ÆL$ Ì$L3Ì2L3r&   u   ðŸŽ¬)	r   ÚtoolsetÚschemaÚhandlerÚcheck_fnÚrequires_envÚis_asyncÚemojiÚdynamic_schema_overrides)r.   r,   rˆ   úOptional[str])rˆ   rÜ   )rˆ   rm   )rZ   rÜ   rˆ   r,   )r/   r   rˆ   zOptional[int])r/   r   rˆ   zOptional[bool])r/   r   rˆ   zOptional[List[str]])r�   r!   r�   r   rˆ   r,   )r   r,   r   r!   rˆ   r!   )r4   r   r¡   r,   r   r   rˆ   r   )rˆ   r!   )+Ú__doc__Ú
__future__r   rX   ÚloggingÚtypingr   r   r   r   Úagent.video_gen_providerr   r	   r
   r   r   Útools.registryr   r   Ú	getLoggerÚ__name__r)   rs   r"   Ú__annotations__r2   r8   r;   rA   rM   rR   r[   rn   rj   rq   rv   r˜   rÂ   r»   rŸ   rE   rÓ   Úregisterr6   r7   r1   ú<module>rç      sÇ  ðòõ #ã Û ß ,Ó ,÷õ ÷ 0à	ˆ×	Ñ	˜8Ó	$€ð ð ]àð !ð<ñð "ðLñð !ÙÐ1Ó2Ø5Ø/ñ	ð !ÙÐ/Ó0Ø3Ø-ñ	ñ+
ð@ �JñE#ñ*)Ð �~ó *óZOó+ó(ò:ó`òó
.ð  $¨t¸4Ø E°¸uñF€óóVó^ó<ðH  Ð!2ØØ8ñ5ð ð �wØØOñ!ð ð �fØØ7ñð ð ˜ØðEñ%ð ðÐ ð.8ð ó"\óóZ1ðz €× Ñ Ø	ØØ Ø"Ø0ØØØ
Ø8ö	:r7   