
    `gj$                        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y)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Zded<   ddZy)	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]
attributesNOptional[str]element_tokenc                D    | j                   \  }}}}||dz  z   ||dz  z   fS )N   )r   )selfxywhs        M/root/.hermes/venv/lib/python3.12/site-packages/tools/computer_use/backend.pycenterzUIElement.center#   s.    [[
1a16z1qAv:%%    )returnzTuple[int, int])__name__
__module____qualname____doc____annotations__r   r   r   r   r   r   dictr   r   r'    r(   r&   r   r      s_    9J
IE3O(4F%4CMCLIs!&t!<J< $(M='&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Zded<   y)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heightNr   png_b64r   zList[UIElement]elementsr   r   window_titler   png_bytes_lenimage_mime_type)r*   r+   r,   r-   r.   r6   r   listr7   r   r8   r9   r:   r0   r(   r&   r2   r2   (   sZ     IJK!G]! %d ;Ho;CML#M3 &*O])r(   r2   c                      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Z
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<   dZded<   y)ActionResultu=  Result of any action (click / type / scroll / drag / key / wait).

    Beyond the transport-level ``ok`` flag, this carries cua-driver's
    structured action verdict so the model can follow the documented
    verify → escalate ladder (NousResearch/hermes-agent#67052). ``ok`` stays
    tool/transport success only — it is NOT the semantic verdict. Read
    ``effect`` / ``escalation`` to decide the next rung. All structured
    fields are optional and additive: an older driver that omits
    ``structuredContent`` leaves them ``None`` and behavior is unchanged.
    boolokr   actionr   messageNzOptional[CaptureResult]capturer   r   metazOptional[bool]verifiedr   effectzOptional[Dict[str, Any]]
escalationpathdegradeddelivery_modecode)r*   r+   r,   r-   r.   rA   rB   r   r/   rC   rD   rE   rF   rG   rH   rI   rJ   r0   r(   r&   r=   r=   F   s    	 	HKGS (,G$+ 6D.6  $Hn# FM  ,0J(/D-#Hn##'M=' D-r(   r=   c            
         e Zd ZdZedd       Zedd       Zedd       Ze	 	 	 	 d	 	 	 	 	 	 	 	 	 dd       Zedddddddd	d
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z	edddddddd	d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z
eddddddd	d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Zedd	d	 	 	 d d       Zedd	d	 	 	 d!d       Zed"d       Zd"dZed#d$d       Zed%d&d       Zd'dZy)(ComputerUseBackendz<Lifecycle: `start()` before first use, `stop()` at shutdown.c                     y Nr0   r!   s    r&   startzComputerUseBackend.startr   s     r(   c                     y rN   r0   rO   s    r&   stopzComputerUseBackend.stopu   s    r(   c                     y)zReturn True if the backend can be used on this host right now.

        Used by check_fn gating and by the post-setup wizard.
        Nr0   rO   s    r&   is_availablezComputerUseBackend.is_availablex       r(   Nc                     y rN   r0   )r!   r3   r   r   r   s        r&   rB   zComputerUseBackend.capture   s     r(   left   F)elementr"   r#   buttonclick_count	modifiersrI   bring_to_frontc                    y rN   r0   )	r!   rY   r"   r#   rZ   r[   r\   rI   r]   s	            r&   clickzComputerUseBackend.click        r(   )from_element
to_elementfrom_xyto_xyrZ   r\   rI   r]   c                    y rN   r0   )	r!   ra   rb   rc   rd   rZ   r\   rI   r]   s	            r&   dragzComputerUseBackend.drag   r`   r(      )amountrY   r"   r#   r\   rI   r]   c                    y rN   r0   )	r!   	directionrh   rY   r"   r#   r\   rI   r]   s	            r&   scrollzComputerUseBackend.scroll   r`   r(   )rI   r]   c                    y rN   r0   )r!   textrI   r]   s       r&   	type_textzComputerUseBackend.type_text   s    ADr(   c                    y)z7Send a key combo, e.g. 'cmd+s', 'ctrl+alt+t', 'return'.Nr0   )r!   keysrI   r]   s       r&   keyzComputerUseBackend.key   rU   r(   c                     y)z9Return running apps with bundle IDs, PIDs, window counts.Nr0   rO   s    r&   	list_appszComputerUseBackend.list_apps   rU   r(   c                    g S )zReturn visible native windows with PID and window identifiers.

        Optional compatibility hook: backends that predate window discovery
        remain instantiable and simply report no windows.
        r0   rO   s    r&   list_windowszComputerUseBackend.list_windows   s	     	r(   c                     y)zJRoute input to `app` (by name or bundle ID). Default: focus without raise.Nr0   )r!   r   raise_windows      r&   	focus_appzComputerUseBackend.focus_app   rU   r(   c                     y)zSet a native value on an element (e.g. AXPopUpButton selection).

        `element` is the 1-based SOM index returned by a prior capture call.
        Nr0   )r!   valuerY   s      r&   	set_valuezComputerUseBackend.set_value   rU   r(   c           	     z    ddl }|j                  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@   rA   )timesleepmaxminr=   )r!   secondsr   s      r&   r}   zComputerUseBackend.wait   s:    

3sC./0tFggc]RS<TUUr(   )r)   None)r)   r>   )somNNN)
r3   r   r   r   r   Optional[int]r   r   r)   r2   )rY   r   r"   r   r#   r   rZ   r   r[   r   r\   Optional[List[str]]rI   r   r]   r>   r)   r=   )ra   r   rb   r   rc   Optional[Tuple[int, int]]rd   r   rZ   r   r\   r   rI   r   r]   r>   r)   r=   )rj   r   rh   r   rY   r   r"   r   r#   r   r\   r   rI   r   r]   r>   r)   r=   )rm   r   rI   r   r]   r>   r)   r=   )rp   r   rI   r   r]   r>   r)   r=   )r)   zList[Dict[str, Any]])F)r   r   rw   r>   r)   r=   rN   )rz   r   rY   r   r)   r=   )r   floatr)   r=   )r*   r+   r,   r-   r   rP   rR   rT   rB   r_   rf   rk   rn   rq   rs   ru   rx   r{   r}   r0   r(   r&   rL   rL   o   s   F       !!#'  	
 ! 
   "&)-'+$  	
    ' %  
   '+$(-1+/)-'+$ $ "	
 + )  ' %  
  
 !%)-'+$  	
    ' %  
  EI).E"&E3?E E ?C#(F F-9F F
 H H Y Y  Vr(   rL   N)r-   
__future__r   abcr   r   dataclassesr   r   typingr   r	   r
   r   r   r   r2   r=   rL   r0   r(   r&   <module>r      sw    # # ( 3 3 & & &0 * * *: % % %PmV mVr(   