
    PL
j                        d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
mZmZmZmZ e G d d                      Ze G d d	                      Ze G d
 d                      Z G d de          ZdS )zAbstract backend interface for computer use.

Any implementation (cua-driver over MCP, pyautogui, noop, future Linux/Windows)
must return the shape described below. All methods synchronous; async is
handled inside the backend implementation if needed.
    )annotations)ABCabstractmethod)	dataclassfield)AnyDictListOptionalTuplec                      e Zd ZU dZded<   ded<   dZded<   dZd	ed
<   dZded<   dZded<   dZ	ded<    e
e          Zded<   ddZdS )	UIElementz/One interactable element on the current screen.intindexstrrole label)r   r   r   r   zTuple[int, int, int, int]boundsappr   pid	window_iddefault_factoryDict[str, Any]
attributesreturnTuple[int, int]c                :    | j         \  }}}}||dz  z   ||dz  z   fS )N   )r   )selfxywhs        >/home/kuhnn/.hermes/hermes-agent/tools/computer_use/backend.pycenterzUIElement.center   s,    [
1a16z1qAv:%%    N)r   r   )__name__
__module____qualname____doc____annotations__r   r   r   r   r   r   dictr   r'    r(   r&   r   r      s         99JJJIIIEOOOO(4F4444CMMMMCLLLLI!&t!<!<!<J<<<<& & & & & &r(   r   c                      e Zd ZU dZded<   ded<   ded<   dZded	<    ee
          Zded<   dZ	ded<   dZ
ded<   dZded<   dS )CaptureResultu  Result of a screen capture call.

    At least one of png_b64 / elements is populated depending on capture mode:
      * mode="vision" → png_b64 only
      * mode="ax"     → elements only
      * mode="som"    → both (default): PNG already has numbered overlays
                         drawn by the backend, and `elements` holds the
                         matching index → element mapping.
    r   moder   widthheightNOptional[str]png_b64r   zList[UIElement]elementsr   r   window_titler   png_bytes_len)r)   r*   r+   r,   r-   r6   r   listr7   r   r8   r9   r/   r(   r&   r1   r1   !   s           IIIJJJKKK!G!!!! %d ; ; ;H;;;;CMMMMLMr(   r1   c                  f    e Zd ZU dZded<   ded<   dZded<   dZd	ed
<    ee          Z	ded<   dS )ActionResultzAResult of any action (click / type / scroll / drag / key / wait).boolokr   actionr   messageNzOptional[CaptureResult]capturer   r   meta)
r)   r*   r+   r,   r-   r@   rA   r   r.   rB   r/   r(   r&   r<   r<   9   sl         KKHHHKKKG (,G++++ 5666D666666r(   r<   c                  T   e Zd ZdZed6d            Zed6d            Zed7d            Zed8d9d            Zed	d	d	ddd	dd:d            Z	ed	d	d	d	dd	dd;d$            Z
ed%d	d	d	d	d&d<d)            Zed=d+            Zed>d-            Zed?d/            Zed@dAd2            ZdBd5Zd	S )CComputerUseBackendz<Lifecycle: `start()` before first use, `stop()` at shutdown.r   Nonec                    d S Nr/   r!   s    r&   startzComputerUseBackend.startJ   s     Sr(   c                    d S rG   r/   rH   s    r&   stopzComputerUseBackend.stopM   s    Cr(   r=   c                    dS )zReturn True if the backend can be used on this host right now.

        Used by check_fn gating and by the post-setup wizard.
        Nr/   rH   s    r&   is_availablezComputerUseBackend.is_availableP         r(   somNr2   r   r   r5   r1   c                    d S rG   r/   )r!   r2   r   s      r&   rA   zComputerUseBackend.captureX   s    VYVYr(   left   )elementr"   r#   buttonclick_count	modifiersrS   Optional[int]r"   r#   rT   rU   r   rV   Optional[List[str]]r<   c                   d S rG   r/   )r!   rS   r"   r#   rT   rU   rV   s          r&   clickzComputerUseBackend.click\   	     sr(   )from_element
to_elementfrom_xyto_xyrT   rV   r\   r]   r^   Optional[Tuple[int, int]]r_   c                   d S rG   r/   )r!   r\   r]   r^   r_   rT   rV   s          r&   dragzComputerUseBackend.dragh   r[   r(      )amountrS   r"   r#   rV   	directionrd   c                   d S rG   r/   )r!   re   rd   rS   r"   r#   rV   s          r&   scrollzComputerUseBackend.scrollt   r[   r(   textc                    d S rG   r/   )r!   rh   s     r&   	type_textzComputerUseBackend.type_text   s    47Cr(   keysc                    dS )z7Send a key combo, e.g. 'cmd+s', 'ctrl+alt+t', 'return'.Nr/   )r!   rk   s     r&   keyzComputerUseBackend.key   rN   r(   List[Dict[str, Any]]c                    dS )z9Return running apps with bundle IDs, PIDs, window counts.Nr/   rH   s    r&   	list_appszComputerUseBackend.list_apps   rN   r(   Fraise_windowc                    dS )zJRoute input to `app` (by name or bundle ID). Default: focus without raise.Nr/   )r!   r   rq   s      r&   	focus_appzComputerUseBackend.focus_app   rN   r(   secondsfloatc           	         ddl }|                    t          dt          |d                               t	          ddd|dd	
          S )z#Default implementation: time.sleep.r   Ng        g      >@Twaitzwaited z.2fs)r>   r?   r@   )timesleepmaxminr<   )r!   rt   ry   s      r&   rw   zComputerUseBackend.wait   sU    

3sC..//000tF<Tg<T<T<T<TUUUUr(   )r   rE   )r   r=   )rO   N)r2   r   r   r5   r   r1   )rS   rW   r"   rW   r#   rW   rT   r   rU   r   rV   rX   r   r<   )r\   rW   r]   rW   r^   r`   r_   r`   rT   r   rV   rX   r   r<   )re   r   rd   r   rS   rW   r"   rW   r#   rW   rV   rX   r   r<   )rh   r   r   r<   )rk   r   r   r<   )r   rn   )F)r   r   rq   r=   r   r<   )rt   ru   r   r<   )r)   r*   r+   r,   r   rI   rK   rM   rA   rZ   rb   rg   rj   rm   rp   rs   rw   r/   r(   r&   rD   rD   G   s       FF    ^  ^   ^ YYYY ^Y  "&)-	 	 	 	 	 ^	  '+$(-1+/)-	 	 	 	 	 ^	 
 !%)-	 	 	 	 	 ^	 777 ^7F F F ^F H H H ^H Y Y Y Y ^YV V V V V Vr(   rD   N)r,   
__future__r   abcr   r   dataclassesr   r   typingr   r	   r
   r   r   r   r1   r<   rD   r/   r(   r&   <module>r      sa    # " " " " " # # # # # # # # ( ( ( ( ( ( ( ( 3 3 3 3 3 3 3 3 3 3 3 3 3 3 & & & & & & & &"        . 
7 
7 
7 
7 
7 
7 
7 
7OV OV OV OV OV OV OV OV OV OVr(   