+
    lHàjÅ  ã                   ó‚   € R t ^ RIt^ RIt^ RIHt ^ RIHtHt ^ RIH	t	 ^ RI
Ht R R ltR R	 ltR
 R ltRR R lltR# )aX  Open a URL, dev server, or file in the Hermes desktop GUI's preview pane.

Registration lives in the `desktop_preview` tool (``tools.preview_tool``); this module keeps
the normalizer + open action. Emits ``preview.open`` via ``desktop_ui``: the renderer opens
the pane for the window that asked and never steals focus for a background session.
N)ÚPath)ÚunquoteÚurlparse)Ú
desktop_ui)Ú
tool_errorc                ó0   € V ^8„  d   QhR\         R\         /# )é   ÚrawÚreturn©Ústr)Úformats   "Ú</home/ubuntu/.hermes/hermes-agent/tools/open_preview_tool.pyÚ__annotate__r      s   € ÷ ñ œ3ð ¤3ñ ó    c                ó„  € V P                  4       P                  R4      P                  4       pV'       d   RV9   g   VP                  R4      '       d   V# \        P                  ! RV\        P                  4      '       d
   RV,           # \        P                  ! RV\        P                  4      '       d
   RV,           # V# )zý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.
Ú`ú://z8^(localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\])(:\d+)?(/|$)zhttp://z!^[\w.-]+\.[a-z]{2,}(:\d+)?(/.*)?$zhttps://)Ú/z./z../Ú~zfile:)ÚstripÚ
startswithÚreÚmatchÚ
IGNORECASE)r	   Úvs   & r   Ú_normalize_targetr      sŒ   € ð 	�	‰	‹×Ñ˜#Ó×$Ñ$Ó&€Aß�˜”
˜aŸl™lÐ+K×LÒLØˆÜ	‡x‚xÐKÈQÔPR×P]ÑP]×^Ò^Ø˜1�}ÐÜ	‡x‚xÐ4°a¼¿¹×GÒGØ˜A�~ÐØ€Hr   c                ó>   € V ^8„  d   QhR\         R\        R,          /# )r   Útargetr
   N)r   r   )r   s   "r   r   r   "   s   € ÷ "ñ "œ3ð "¤4¨$¥;ñ "r   c                óH  € T ;'       g    RP                  4       pV'       g   R# RV9   dà   \        V4      pVP                  P                  4       R8w  d   R# \	        VP
                  ;'       g    R4      pVP                  '       d$   VP                  R
9  d   RVP                   V 2pMJ\        P                  R8X  d6   \        V4      ^8¼  d&   V^ ,          R8X  d   V^,          R8X  d
   VR	,          pV'       d   \        V4      # R# \        V4      P                  4       # )zBReturn a filesystem path for local targets; None for http(s) URLs.Ú Nr   Úfilez//Úntr   Ú::é   NN>   r    Ú	localhost)r   r   ÚschemeÚlowerr   ÚpathÚnetlocÚosÚnameÚlenr   Ú
expanduser)r   r	   Úparsedr(   s   &   r   Ú_local_fs_pathr/   "   sÜ   € à�<ˆ<�R×
Ñ
Ó
 €CßÙØ�„|Ü˜#“ˆØ�=‰=×ÑÓ  FÔ*ÙÜ�v—{‘{×(Ð( bÓ)ˆØ�=�=ˆ=˜VŸ]™]Ð2CÔCØ˜Ÿ™� t fÐ-‰Dä�G‰G�tŒOÜ�D“	˜Q”Ø�Q•˜3”Ø�Q•˜3”à˜•8ˆDß!Œt�D‹zÐ+ tÐ+Ü�‹9×ÑÓ!Ð!r   c                ó0   € V ^8„  d   QhR\         R\        /# )r   r   r
   )r   Úbool)r   s   "r   r   r   9   s   € ÷ 
ñ 
¤3ð 
¬4ñ 
r   c                 ój   € \        V 4      pVf   R#  VP                  4       #   \         d     R# i ; i)NF)r/   Úis_dirÚOSError)r   r(   s   & r   Ú_is_existing_directoryr5   9   s9   € Ü˜&Ó!€DØ‚|ÙðØ�{‰{‹}ÐøÜô ò ð	ús   “# £2±2c                ó<   € V ^8„  d   QhR\         R\         R\         /# )r   ÚurlÚlabelr
   r   )r   s   "r   r   r   F   s!   € ÷ :ñ :œ3ð :¤sð :´Cñ :r   c                ó  € \        T ;'       g    R4      pV'       g   \        R4      # \        V4      '       d   \        RV R24      # T;'       g    RP                  4       p\        P
                  ! RRVRV/RR	R
RRVRV/4      # )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.u?   directories are not previewable â€” pass a file path or a URL. z is a directory.zpreview.openr7   r8   z!Failed to open the preview pane: z=The preview pane is only available in the Hermes desktop app.ÚsuccessT)r   r   r5   r   r   Úemit_or_error)r7   r8   r   s   && r   Úopen_preview_toolr<   F   sŸ   € ä˜sŸy˜y bÓ)€FßÜð5ó6ð 	6ô ˜f×%Ò%ÜØMØˆhÐ&ð(ó
ð 	
ð
 �[ˆ[�b×ÑÓ!€EÜ×#Ò#ØØ	�˜ Ð'Ø+ØGØ	�D˜% ¨°%Ð8ó:ð :r   )r    )Ú__doc__r*   r   Úpathlibr   Úurllib.parser   r   Útoolsr   Útools.registryr   r   r/   r5   r<   © r   r   Ú<module>rC      s7   ðñó 
Û 	Ý ß *å Ý %õõ "õ.
÷:ñ :r   