Ë
    ãß²jy  ã                   óz  — d Z ddlmZmZ ddlmZ ddlmZmZ dZ	dZ
dZ	 	 	 	 d/d	ed
ee   dee   dee   dee   dee   de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 d!dœdd"dœd#d$dœd ee
«      d%dœd#d&dœd d'dœd(œ
d	gd)œd*œZ ej$                  dd+ed,„ d-¬.«       ddlZy)0a3  Interact with the in-app browser / preview pane in the Hermes desktop GUI (click, type, scroll).

Elements are addressed by legible refs from ``action="elements"`` (``btn-sign-in``); a ref survives
re-renders and only a navigation retires it, so the renderer answers with a *delta* instead of
re-sending the inventory. Round-trips through the gateway's blocking-prompt bridge
(``preview.act.request`` / ``preview.act.respond``); this module is schema + a thin dispatcher over
the platform-injected callback. ``desktop_ui`` toolset: desktop-sourced sessions only.
é    )ÚCallableÚOptional)Úpassthrough_json)ÚregistryÚ
tool_error)
ÚelementsÚclickÚhoverÚtypeÚscrollÚpressÚstrobeÚbackÚforwardÚreload)ÚtopÚbottom)r	   r
   r   r   NÚactionÚrefÚselectorÚtextÚkeyÚsubmitÚamountÚtoÚlimitÚfullÚcallbackÚreturnc                 ó  — |
€t        d«      S | xs dj                  «       j                  «       }|t        vr"t        ddj	                  t        «      › d�«      S |t
        v r|s|st        |› d�«      S |dk(  r|€t        d	«      S |d
k(  r|st        d«      S |�*|t        vr"t        ddj	                  t        «      › d�«      S 	 d|fd|fd|fd|fd|fd|fd|	fd|fd|€dn
t        |«      fd|€dn
t        |«      ff
}	  |
|D ��ci c]  \  }}|€Œ	||“Œ c}}«      }|st        d«      S t        |«      S # t        t        f$ r t        d«      cY S w xY wc c}}w # t        $ r}t        d|› �«      cY d}~S d}~ww xY w)zHDispatch one interaction to the desktop renderer and return its outcome.Nz:drive_preview is only available in the Hermes desktop app.Ú zaction must be one of: z, ú.zK needs a ref from action='elements' (e.g. 'btn-sign-in') or a CSS selector.r   ztype needs the text to enter.r   z,press needs a key, e.g. 'Enter' or 'Escape'.zto must be one of: r   r   r   r   r   r   r   r   r   Úmaxz amount and max must be integers.z%Failed to act on the in-app browser: zUThe action timed out, or no GUI window answered. Open a page with open_preview first.)r   ÚstripÚlowerÚACTIONSÚjoinÚNEEDS_TARGETÚ	SCROLL_TOÚintÚ	TypeErrorÚ
ValueErrorÚ	Exceptionr   )r   r   r   r   r   r   r   r   r   r   r   ÚverbÚfieldsÚnameÚvalÚrawÚexcs                    ú=/home/ubuntu/.hermes/hermes-agent/tools/drive_preview_tool.pyÚdrive_preview_toolr5      sÉ  € ð ÐÜÐVÓWÐWØŠL�b×ÑÓ!×'Ñ'Ó)€DØ”7ÑÜÐ3°D·I±I¼gÓ4FÐ3GÀqÐIÓJÐJØŒ|Ñ¡S©HÜ˜T˜FÐ"mÐnÓoÐoØˆv‚~˜$˜,ÜÐ9Ó:Ð:Øˆw‚™sÜÐHÓIÐIØ	€~˜"¤IÑ-ÜÐ/°·	±	¼)Ó0DÐ/EÀQÐGÓHÐHð>à�tÐ˜u c˜l¨Z¸Ð,BÀVÈTÀNÐUZÐ\_ÐT`Ø�vÐ ¨ °°r°
Ø˜v˜~‘t´3°v³;Ð?À%ÐQVÐQ^ÉÔdgÐhmÓdnÐAoð
ˆðIÙ°6×M¡i d¨C¸S¹_˜˜c™	ÓMÓNˆñ ÜÐqÓrÐrÜ˜CÓ Ð øô ”zÐ"ò >ÜÐ<Ó=Ò=ð>üó NøÜò IÜÐAÀ#ÀÐGÓHÕHûðIúsH   Ã:D7 Ä E Ä
E
ÄE
ÄE Ä7EÅEÅE Å	E>Å&E9Å3E>Å9E>Údrive_previewut  Use the web page open in the desktop preview pane (the one `desktop_preview` opens): log in, fill forms, click through flows. ALWAYS start with action='elements' â€” it inventories clickable/typable things as refs ('btn-sign-in') with role/label/value; act by ref, not guessed selectors. Refs survive re-renders and only die on navigation (you'll be told they're stale â€” call elements again). After the first full inventory, actions answer with a DELTA: 'added' in full, 'changed' as ref + moved fields, 'removed'/'rebound' as ref lists ('rebound' needs nothing from you â€” the ref already follows the rebuilt element). Anything unmentioned is unchanged; do not re-read to check. Input is real (pointer travels, hover menus open). Actions: elements, click, hover (park the pointer â€” opens dropdowns before clicking in), type (submit=true also presses Enter), scroll, press, strobe (visual flourish only â€” one call runs a multi-second burst; never loop it), back/forward/reload. Moves draw live and fade; annotate_preview leaves a lasting mark. Page text only: desktop_preview action=read. Separate automated browser: browser_* tools.ÚobjectÚstringzStart with 'elements'.)r   ÚenumÚdescriptionz*Element ref from an earlier elements call.)r   r:   z"CSS selector fallback. Prefer ref.ztype: the text.Úbooleanz*type: press Enter + submit the form after.z1press: key name ('Enter', 'Escape', 'ArrowDown').Úintegerz4scroll: pixels (negative = up; default ~one screen).z#scroll: jump to top/bottom instead.zelements: cap the inventory.z9elements: full re-read instead of a delta. Rarely needed.)
r   r   r   r   r   r   r   r   r#   r   )r   Ú
propertiesÚrequired)r0   r:   Ú
parametersÚ
desktop_uic                 óÂ   — t        d| j                  dd«      | j                  d«      |j                  d«      dœdD �ci c]  }|| j                  |«      “Œ c}¤ŽS c c}w )Nr   r!   r#   r   )r   r   r   )r   r   r   r   r   r   r   r   © )r5   Úget)ÚargsÚkwÚks      r4   ú<lambda>rG   Š   sV   € Ô1ð  Ø�x‰x˜ "Ó%¨T¯X©X°e«_ÀrÇvÁvÈjÓGYñ à#gÖ
h˜aˆ1ˆd�h‰h�q‹k‰>Ò
hñ € ùâ
hs   ¾Au   ðŸ–±ï¸�)r0   ÚtoolsetÚschemaÚhandlerÚemoji)r!   NNNNNNNNNN)Ú__doc__Útypingr   r   Útools.desktop_uir   Útools.registryr   r   r&   r)   r(   ÚstrÚboolr*   r5   ÚlistÚACT_PREVIEW_SCHEMAÚregisterÚjsonrB   ó    r4   ú<module>rW      s¶  ðñ÷ &å -ß /à
j€Ø€	ð 3€ð hlØVZØRVØ#'ñ	!!Øð!!Ø# C™=ð!!Ø;CÀC¹=ð!!ØW_Ð`cÑWdð!!à	�#‰ð!!à'/°¡~ð!!àFNÈsÁmð!!ð 	�‰ð!!ð &.¨c¡]ð!!ð BJÈ$Áð!!ð �xÑ ð	!!ð -0ó	!!ðJ ð	$ð( ð !Ù˜W›Ø7ñð !ØKñð
 !ØCñð &Ð6GÑHà!ØKñð
 !ØRñð
 "ØUñð
 !Ù˜Y›ØDñð "Ø=ñð
 "ØZññI(
ðR �JñW,ñ5GÐ ðT €× Ñ Ø	ØØñð õô rV   