Ë
    ãß²j=  ã                  óT  — U 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	 ddl
mZmZmZ ddlmZmZ d%d„Zd%d	„Zd&d
„Zd'd„ZdddœZd(d„Z eddddi «      Zded<    eddddddddœi«      Zded<   d)d„Zd*d„Zd*d „ZdeefdeeffD ]   \  ZZZ ej@                  ed!eeeg d"d#¬$«       Œ" y)+z1xAI-specific Imagine video edit and extend tools.é    )ÚannotationsN)ÚAnyÚDictÚOptional)Úload_config)Úhas_xai_video_credentialsÚrun_xai_video_editÚrun_xai_video_extend)ÚregistryÚ
tool_errorc                 ó    — 	 t        «       j                  d«      } t        | t        «      xr | j                  d«      dk(  S # t        $ r Y yw xY w)NÚ	video_genFÚproviderÚxai)r   ÚgetÚ	ExceptionÚ
isinstanceÚdict)Úsections    ú:/home/ubuntu/.hermes/hermes-agent/tools/xai_video_tools.pyÚ_configured_for_xai_videor      sO   € ðÜ“-×#Ñ# KÓ0ˆô �gœtÓ$ÒI¨¯©°ZÓ)@ÀEÑ)IÐIøô ò Ùðús   ‚A Á	AÁAc                 ó.   — t        «       xr
 t        «       S ©N)r   r   © ó    r   Ú_check_xai_video_requirementsr      s   € Ü$Ó&ÒFÔ+DÓ+FÐFr   c                óf   — t        | t        «      r | j                  «       r| j                  «       S d S r   )r   ÚstrÚstrip©Úvalues    r   Ú_clean_stringr"      s$   € Ü& u¬cÔ2°u·{±{´}ˆ5�;‰;‹=ÐNÈ$ÐNr   c                ój   — | �t        | t        «      ry 	 t        | «      S # t        t        f$ r Y y w xY wr   )r   ÚboolÚintÚ	TypeErrorÚ
ValueErrorr    s    r   Ú_coerce_intr(      s9   € à€}œ
 5¬$Ô/ØðÜ�5‹zÐøÜ”zÐ"ò Ùðús   •
   2±2Ústringui   Public HTTPS MP4 URL of the source video â€” the `video` or `public_url` from a prior xAI Imagine result.©ÚtypeÚdescriptionúDict[str, Any]c                óF   — | |› d|› d�ddd|› d�dœt         dœ|¥d	d
gdœdœS )NzZ an existing video with xAI Imagine. This is separate from `video_generate` because video z‡ is provider-specific. `video_url` must be the public HTTPS MP4 URL from a prior Imagine result (`video` or `public_url` on files-cdn).Úobjectr)   zInstruction for how xAI should z the source video.r*   ©ÚpromptÚ	video_urlr1   r2   )r+   Ú
propertiesÚrequired)Únamer,   Ú
parameters)Ú_VIDEO_URL_PARAM)r5   ÚverbÚnounÚprompt_verbÚextras        r   Ú_xai_video_schemar<   1   sg   € ààˆfð .Ø.2¨Vð 4=ð=ð ð %Ø%DÀ[ÀMÐQcÐ#dñô .ñð ðð " ;Ð/ñ
ñð r   Úxai_video_editÚEditÚeditingÚmodifyÚXAI_VIDEO_EDIT_SCHEMAÚxai_video_extendÚExtendÚ	extensionÚcontinueÚdurationÚintegerzNDesired extension duration in seconds. xAI clamps this to its supported range.ÚXAI_VIDEO_EXTEND_SCHEMAc                óf  — t        | j                  d«      «      t        | j                  d«      «      }}|st        d|› �«      S |r|j                  «       j	                  d«      st        d«      S t        «       st        j                  dddd	d
œ«      S t        j                   |d||dœ|¤Ž«      S )Nr1   r2   z!prompt is required for xAI video )zhttp://zhttps://z_video_url must be a public HTTPS MP4 URL (the `video`/`public_url` from a prior Imagine result)FzzxAI video edit/extend tools require `video_gen.provider` to be configured as `xai` via `hermes tools` -> Video Generation.Úprovider_not_configuredr   )ÚsuccessÚerrorÚ
error_typer   r0   r   )r"   r   r   ÚlowerÚ
startswithr   ÚjsonÚdumps)ÚargsÚopÚrunr;   r1   r2   s         r   Ú_run_xai_video_toolrU   X   s·   € Ü% d§h¡h¨xÓ&8Ó9¼=ÈÏÉÐR]ÓI^Ó;_ˆI€FÙÜÐ=¸b¸TÐBÓCÐCÙ˜)Ÿ/™/Ó+×6Ñ6Ð7NÔOÜð+ó
ð 	
ô %Ô&Ü�z‰zØðNð 4Øñ
ó ð 	ô �:‰:‘cÐF °9ÑFÀÑFÓGÐGr   c                ó$   — t        | dt        «      S )NÚedit)rU   r	   ©rR   Ú_kws     r   Ú_handle_xai_video_editrZ   n   s   € Ü˜t VÔ-?Ó@Ð@r   c           
     óX   — t        | dt        t        | j                  d«      «      ¬«      S )NÚextendrF   )rF   )rU   r
   r(   r   rX   s     r   Ú_handle_xai_video_extendr]   r   s&   € Ü˜t XÔ/CÌkÐZ^×ZbÑZbÐcmÓZnÓNoÔpÐpr   r   FÚvideo)r5   ÚtoolsetÚschemaÚhandlerÚcheck_fnÚrequires_envÚis_asyncÚemoji)Úreturnr$   )r!   r   rf   zOptional[str])r!   r   rf   zOptional[int])r5   r   r8   r   r9   r   r:   r   r;   r-   rf   r-   )rR   r-   rS   r   r;   r   rf   r   )rR   r-   rY   r   rf   r   )!Ú__doc__Ú
__future__r   rP   Útypingr   r   r   Úhermes_cli.configr   Úplugins.video_gen.xair   r	   r
   Útools.registryr   r   r   r   r"   r(   r7   r<   rA   Ú__annotations__rH   rU   rZ   r]   Ú_nameÚ_schemaÚ_handlerÚregisterr   r   r   ú<module>rr      s  ðâ 7å "ã ß &Ñ &å )ß eÑ eß /óJóGóOóð ð	8ñÐ óñ0 ):Ð:JÈFÐT]Ð_gÐikÓ(lÐ �~Ó lá*;Ø˜ +¨zØØð*ñ
ð<ó
+Ð ˜ó 
óHó,Aóqð
 Ð,Ð.DÐEØÐ0Ð2JÐKð!ò Ñ€Eˆ7�Hð €H×ÑØ˜K°ÀØ.¸RÈ%ÐW^öñ	r   