
    `gj              
         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Zd.dZdddddddddddddddgddZded<   dddddddddd d!ddddd"ddgddZded#<   d/d$Zd/d%Z ej8                  dd&eeeg d'd()        ej8                  dd&eeeg d'd()       y)0z1xAI-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               } t        | t              r| j	                  d      nd }t        |t              xr |j	                  d      dk(  S # t        $ r Y yw xY w)NF	video_genproviderxai)r   	Exception
isinstancedictget)cfgsections     H/root/.hermes/venv/lib/python3.12/site-packages/tools/xai_video_tools.py_configured_for_xai_videor      s]    m '1d&;cggk"Ggt$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                d    t        | t              r | j                         r| j                         S y r   )r   strstripvalues    r   _clean_stringr#      s#    %%++-{{}r   c                l    | y 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)   %   s=    }%5zz" s   
! 33c                 6    t        j                  ddddd      S )NFzzxAI 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   )jsondumpsr   r   r   _provider_not_configured_errorr1   0   s)    ::J 0  r   	video_urlc                b    t        |       }|sy|j                         j                  d      r|S y)z9Require a public HTTPS MP4 URL (``http``/``https`` only).N)zhttp://zhttps://)r#   lower
startswith)r2   cleaneds     r   _normalize_public_video_urlr7   <   s/    I&G}}!!"9:r   xai_video_editzEdit an existing video with xAI Imagine. This is separate from `video_generate` because video editing is provider-specific. `video_url` must be the public HTTPS MP4 URL from a prior Imagine result (`video` or `public_url` on files-cdn).objectstringz7Instruction for how xAI should modify the source video.)typedescriptionui   Public HTTPS MP4 URL of the source video — the `video` or `public_url` from a prior xAI Imagine result.z$Optional xAI Imagine model override.promptr2   modelr>   )r;   
propertiesrequired)namer<   
parametersDict[str, Any]XAI_VIDEO_EDIT_SCHEMAxai_video_extendzExtend an existing video with xAI Imagine. This is separate from `video_generate` because video extension is provider-specific. `video_url` must be the public HTTPS MP4 URL from a prior Imagine result (`video` or `public_url` on files-cdn).z9Instruction for how xAI should continue the source video.integerzNDesired extension duration in seconds. xAI clamps this to its supported range.r>   r2   durationr?   XAI_VIDEO_EXTEND_SCHEMAc                @   t        | j                  d            }t        | j                  d            }t        | j                  d            }|st        d      S |st        d      S t	               s
t               S t        |||      }t        j                  |      S )Nr>   r2   r?   z%prompt is required for xAI video edit_video_url must be a public HTTPS MP4 URL (the `video`/`public_url` from a prior Imagine result)r=   )	r#   r   r7   r   r   r1   r	   r/   r0   )args_kwr>   r2   r?   results         r   _handle_xai_video_editrP      s    488H-.F+DHH[,ABI$((7+,EABB+
 	
 %&-//F
 ::fr   c                v   t        | j                  d            }t        | j                  d            }t        | j                  d            }t        | j                  d            }|st	        d      S |st	        d      S t               s
t               S t        ||||      }t        j                  |      S )Nr>   r2   r?   rI   z'prompt is required for xAI video extendrL   rH   )
r#   r   r7   r)   r   r   r1   r
   r/   r0   )rM   rN   r>   r2   r?   rI   rO   s          r   _handle_xai_video_extendrR      s    488H-.F+DHH[,ABI$((7+,E488J/0HCDD+
 	
 %&-//!	F ::fr   r   Fvideo)rB   toolsetschemahandlercheck_fnrequires_envis_asyncemoji)returnr%   )r"   r   r[   Optional[str])r"   r   r[   zOptional[int])r[   r   )r2   r   r[   r\   )rM   rD   rN   r   r[   r   )__doc__
__future__r   r/   typingr   r   r   hermes_cli.configr   plugins.video_gen.xair   r	   r
   tools.registryr   r   r   r   r#   r)   r1   r7   rE   __annotations__rJ   rP   rR   registerr   r   r   <module>re      sm   7 "  & & ) 
 0JG	 	9  !X
 !D !E
" {+') ~ B 	9  !Z
 !D ". !E'
0 {+5$+  $N.2   	 "*
	   	"$*
	r   