
    sj                        d Z ddlZddlmZmZ ddlmZmZ dZdddddZ		 	 	 	 	 d"d
e
dee
         dee
         dee
         dee         de
fdZdddd ee          ddddddddddddg ddZ ej        dded d !           dS )#u  Leave a mark on the page in the Hermes desktop GUI's in-app browser.

``drive_preview`` already draws every move it makes — the field it can reach,
a box round its target, the cursor going there — but those are transients:
each one stands for a single action and retires itself. That is right for
narrating a click and no use at all for holding a finding on screen.

This is the deliberate one. An annotation outlines an element — or, with
``hold``, the entire visible field at once — and stays until the agent takes it
down, so it can show the user what it found, flag the fields
it is about to fill, or keep its place while it works elsewhere on the page.
Named for TouchDesigner's Annotate — the labelled box you drop around part of a
network to call it out.

Annotations are bound to elements, not coordinates: they ride scrolls and
reflows, and they go when their element does, so a navigation clears them
without the agent having to.

Rides the same ``preview.act`` bridge as ``drive_preview`` rather than opening
a second channel — the renderer already resolves ``@e`` refs and owns the
overlay, so this is one more verb on a wire that exists.

Lives in the ``desktop_ui`` toolset, which the GUI gateway enables only for
desktop-sourced sessions.
    N)CallableOptional)registry
tool_error)addholdremoveclearpinr   unpinr   actionrefselectorlabelcallbackreturnc                    |t          d          S | pd                                                                }|t          vr+t          dd                    t                     d          S |dv r|s|st          | d          S d	 d
t
          |         fd|dv rdn|fd|dv rdn|fd|ffD             }	  ||          }n)# t          $ r}t          d|           cY d}~S d}~ww xY w|st          d          S 	 t          j        t          j	        |          d          S # t          t          f$ r( t          j        dt          |          id          cY S w xY w)z8Put one annotation up, take one down, or clear them all.Nz=annotate_preview is only available in the Hermes desktop app.r   zaction must be one of: z, .)r   r	   zY needs a ref from drive_preview action='elements' (e.g. 'btn-sign-in') or a CSS selector.c                     i | ]
\  }}|||S )N ).0namevals      ?/home/agent/.hermes/hermes-agent/tools/annotate_preview_tool.py
<dictcomp>z)annotate_preview_tool.<locals>.<dictcomp>=   s/     	 	 	D# ? 	c ??    r   r   )r
   r   r   textz'Failed to annotate the in-app browser: zYThe annotation timed out, or no GUI window answered. Open a page with open_preview first.F)ensure_ascii)r   striplowerACTIONSjoinWIRE	Exceptionjsondumpsloads	TypeError
ValueErrorstr)	r   r   r   r   r   verbpayloadrawexcs	            r   annotate_preview_toolr/   (   s    YZZZOe""$$**,,D7IDIIg4F4FIIIJJJ   #   6 6 6
 
 	

	 	 tDz"D$555DD3?):!:!:IUO	
	 	 	GKhw K K KICIIJJJJJJJJK  
3
 
 	

Bz$*S//>>>>z" B B Bz63s88,5AAAAAABs0   8C 
C*C%C*%C*?'D' '6E E annotate_previewu  Draw a lasting mark on the page open in the in-app browser / preview pane of the Hermes desktop GUI. Everything drive_preview draws as it works fades on its own; an annotation STAYS until you remove it, so this is how you point at something. Use it to show the user what you found ('here are the three cheapest'), flag what you are about to change before you change it, or keep your place while you work elsewhere on the page. Address elements by the same refs drive_preview action='elements' hands back. action='add' outlines an element and gives it an optional short label; 'hold' freezes the WHOLE visible field at once — every element the page offers, outlined and named — which is the picture drive_preview flashes as it works, made to stay; 'remove' takes one down; 'clear' takes them all down. Annotations follow their element as the page scrolls and disappear if it does, so a navigation clears them for you. Keep labels to a word or two — they are drawn on the page, not read aloud.objectstringz'add' marks one element, 'hold' freezes the whole visible field, 'remove' takes one down, 'clear' takes them all down. Defaults to 'add'.)typeenumdescriptionzLElement reference from drive_preview action='elements' (e.g. 'btn-sign-in').)r3   r5   z9CSS selector, as a fallback when no ref fits. Prefer ref.z;Short caption drawn on the mark, e.g. 'cheapest'. Optional.)r   r   r   r   )r3   
propertiesrequired)r   r5   
parameters
desktop_uic           	          t          |                     dd          |                     d          |                     d          |                     d          |                    d                    S )Nr   r   r   r   r   r   )r   r   r   r   r   )r/   get)argskws     r   <lambda>r>      sa    4xx%((HHUOO*%%hhw
##      r   u   🔖)r   toolsetschemahandleremoji)r   NNNN)__doc__r%   typingr   r   tools.registryr   r   r!   r#   r*   r/   listANNOTATE_PREVIEW_SCHEMAregisterr   r   r   <module>rI      s   4  % % % % % % % % / / / / / / / /
, f'JJ "#'.B .B.B	#.B sm.B C=	.B
 x .B 	.B .B .B .Bd 	 $  !W/	  !m 
 !Z 
 !\ %
 
. 3 )/ / d  	"       r   