
    (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 d3d
Zd3dZd4dZd5dZd6dZd7d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*<   d8d-Zd8d.Z ej        dd/eeeg d0d12            ej        d$d/eeeg d0d12           dS )9z1xAI-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_errorreturnboolc                     	 t                      } n# t          $ r Y dS w xY wt          | t                    r|                     d          nd }t          |t                    o|                    d          dk    S )NF	video_genproviderxai)r   	Exception
isinstancedictget)cfgsections     ;/home/rurouni/.hermes/hermes-agent/tools/xai_video_tools.py_configured_for_xai_videor      s    mm   uu&0d&;&;Ecggk"""Ggt$$IZ)@)@E)IIs    
c                 :    t                      ot                      S N)r   r        r   _check_xai_video_requirementsr      s    $&&F+D+F+FFr   valuer   Optional[str]c                    t          | t                    r(|                                 r|                                 S d S r   )r   strstripr    s    r   _clean_stringr&      s6    % %++-- {{}}4r   Optional[int]c                    | d S t          | t                    rd S 	 t          |           S # t          t          f$ r Y d S w xY wr   )r   r   int	TypeError
ValueErrorr%   s    r   _coerce_intr,   %   s[    }t% t5zzz"   tts   , A Ar#   c                 4    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_errorr4   0   s1    :J 0    r   	video_urlc                ~    t          |           }|sdS |                                                    d          r|S dS )z9Require a public HTTPS MP4 URL (``http``/``https`` only).N)zhttp://zhttps://)r&   lower
startswith)r5   cleaneds     r   _normalize_public_video_urlr:   <   sE    I&&G t}}!!"9:: 4r   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.promptr5   modelrA   )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.rA   r5   durationrB   XAI_VIDEO_EXTEND_SCHEMAargs_kwc                   t          |                     d                    }t          |                     d                    }t          |                     d                    }|st          d          S |st          d          S t	                      st                      S t          |||          }t          j        |          S )NrA   r5   rB   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   r:   r   r   r4   r	   r2   r3   )rN   rO   rA   r5   rB   results         r   _handle_xai_video_editrS      s    488H--..F+DHH[,A,ABBI$((7++,,E CABBB 
+
 
 	
 %&& 0-///  F
 :fr   c                   t          |                     d                    }t          |                     d                    }t          |                     d                    }t          |                     d                    }|st	          d          S |st	          d          S t                      st                      S t          ||||          }t          j	        |          S )NrA   r5   rB   rL   z'prompt is required for xAI video extendrQ   rK   )
r&   r   r:   r,   r   r   r4   r
   r2   r3   )rN   rO   rA   r5   rB   rL   rR   s          r   _handle_xai_video_extendrU      s    488H--..F+DHH[,A,ABBI$((7++,,E488J//00H ECDDD 
+
 
 	
 %&& 0-///!	  F :fr   r   Fvideo)rE   toolsetschemahandlercheck_fnrequires_envis_asyncemoji)r   r   )r    r   r   r!   )r    r   r   r'   )r   r#   )r5   r   r   r!   )rN   rG   rO   r   r   r#   )__doc__
__future__r   r2   typingr   r   r   hermes_cli.configr   plugins.video_gen.xair   r	   r
   tools.registryr   r   r   r   r&   r,   r4   r:   rH   __annotations__rM   rS   rU   registerr   r   r   <module>rf      s   7 7 7 " " " " " "  & & & & & & & & & & ) ) ) ) ) )         
 0 / / / / / / /J J J JG G G G      	 	 	 	    	9  !X 
 !D  !E 
 
" {+' ) )     B 	9  !Z 
 !D  ".  !E '
 
0 {+5 $+ $+  $ $ $ $N   .   2  	 "*
	 	 	 	  	"$*
	 	 	 	 	 	r   