
    .cj$                         d Z ddlZddlZddlmZ ddlmZmZ ddlm	Z	 de
de
fdZdd
e
de
de
fdZdefdZddddddddddd
gddZ ej        dded ed           dS )ar  Open a URL, dev server, or file in the Hermes desktop GUI's preview pane.

Gated on ``HERMES_DESKTOP`` (like ``read_terminal`` / ``close_terminal``) so it
never appears outside the GUI. Emits ``preview.open`` through the shared
``desktop_ui`` bridge; the renderer opens the pane beside the chat for the
window that asked and never steals focus for a background session.
    N)
desktop_ui)registry
tool_errorenv_var_enabledrawreturnc                 F   |                                                       d                                           }|rd|v s|                    d          r|S t          j        d|t          j                  rd|z   S t          j        d|t          j                  rd|z   S |S )u  Coax a bare host/domain into a fetchable URL; leave paths + schemes alone.

    ``www.cnn.com`` → ``https://www.cnn.com``; ``localhost:3000`` →
    ``http://localhost:3000``. File paths and explicit schemes pass through for
    the renderer's preview normalizer to classify.
    `z://)/z./z../~zfile:z8^(localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\])(:\d+)?(/|$)zhttp://z!^[\w.-]+\.[a-z]{2,}(:\d+)?(/.*)?$zhttps://)strip
startswithrematchI)r   vs     9/home/ice/.hermes/hermes-agent/tools/open_preview_tool.py_normalize_targetr      s     			#$$&&A 

all+KLL
	xKQPRPTUU 1}	x4a>> A~H     urllabelc                 N   t          | pd          }|st          d          S |pd                                }	 t          j        d||d          }n)# t
          $ r}t          d|           cY d}~S d}~ww xY w|st          d          S t          j        d||d	d
          S )zHAsk the desktop GUI to show ``url`` in the preview pane beside the chat.r   up   url is required — a web URL (https://…), a localhost dev server, or a file path to show in the preview pane.zpreview.openr   r   z!Failed to open the preview pane: Nz=The preview pane is only available in the Hermes desktop app.T)successr   r   F)ensure_ascii)r   r   r   r   emit	Exceptionjsondumps)r   r   targetokexcs        r   open_preview_toolr%   #   s    syb))F 
5
 
 	

 [b!!EE_^Ve-L-LMM E E ECcCCDDDDDDDDE [YZZZ:$vFFUZ[[[[s   A 
A9A4.A94A9c                       t          d          S )uI   Desktop GUI only — HERMES_DESKTOP is set on the gateway the app spawns.HERMES_DESKTOPr    r   r   check_open_preview_requirementsr)   7   s    +,,,r   open_previewu  Open something in the preview pane beside the chat in the Hermes desktop app. Use this when the user asks to see a page, dev server, or file in the preview pane — e.g. "open cnn.com in the preview pane" or "preview localhost:3000". Accepts a web URL (a bare domain like www.cnn.com is fine), a localhost dev-server URL, or a file path (HTML renders live; other files show their contents). The pane opens for the current window only.objectstringul   What to preview: a web URL (https://… or a bare domain), a localhost URL (localhost:3000), or a file path.)typedescriptionz2Optional tab label; defaults to the target's name.r   )r-   
propertiesrequired)namer.   
parametersterminalc                 t    t          |                     dd          |                     dd                    S )Nr   r   r   r   )r%   get)argskws     r   <lambda>r8   ^   s5    0TXXeR5H5HPTPXPXY`bdPePefff r   u   🖼️)r1   toolsetschemahandlercheck_fnemoji)r   )__doc__r    r   toolsr   tools.registryr   r   utilsr   strr   r%   boolr)   OPEN_PREVIEW_SCHEMAregisterr(   r   r   <module>rF      sn     				       / / / / / / / / ! ! ! ! ! !3 3    "\ \3 \s \C \ \ \ \(- - - - - 	L  !F  !S 
 
 G   <  	ff,
     r   