§
    øžyjž  ã                  óú   — U d Z ddlmZ ddlZddlZddlmZmZmZ ddl	m
Z
 ddlmZ  ej        e¦  «        Zddd	d
ddgddœd
ddœd
ddœdœdgdœdœZded<   	 	 	 d%d&d„Zd'd „Z ej        dd!ed"„ ed#¬$¦  «         dS )(uB  Agent-facing tool: respond to a native JS dialog captured by the CDP supervisor.

This tool is response-only â€” the agent first reads ``pending_dialogs`` from
``browser_snapshot`` output, then calls ``browser_dialog(action=...)`` to
accept or dismiss.

Gated on the same ``_browser_cdp_check`` as ``browser_cdp`` so it only
appears when a CDP endpoint is reachable (Browserbase with a
``connectUrl``, local Chromium-family browser via ``/browser connect``, or
``browser.cdp_url`` set in config).

See ``website/docs/developer-guide/browser-supervisor.md`` for the full
design.
é    )ÚannotationsN)ÚAnyÚDictÚOptional)ÚSUPERVISOR_REGISTRY)ÚregistryÚbrowser_dialogu¦  Respond to a native JavaScript dialog (alert / confirm / prompt / beforeunload) that is currently blocking the page.

**Workflow:** call ``browser_snapshot`` first â€” if a dialog is open, it appears in the ``pending_dialogs`` field with ``id``, ``type``, and ``message``. Then call this tool with ``action='accept'`` or ``action='dismiss'``.

**Prompt dialogs:** pass ``prompt_text`` to supply the response string. Ignored for alert/confirm/beforeunload.

**Multiple dialogs:** if more than one dialog is queued (rare â€” happens when a second dialog fires while the first is still open), pass ``dialog_id`` from the snapshot to disambiguate.

**Availability:** only present when a CDP-capable backend is attached â€” Browserbase sessions, local Chromium-family browser via ``/browser connect``, or ``browser.cdp_url`` in config.yaml. Not available on Camofox (REST-only) or the default Playwright local browser (CDP port is hidden).ÚobjectÚstringÚacceptÚdismissz»'accept' clicks OK / returns the prompt text. 'dismiss' clicks Cancel / returns null from prompt(). For ``beforeunload`` dialogs: 'accept' allows the navigation, 'dismiss' keeps the page.)ÚtypeÚenumÚdescriptionzdResponse string for a ``prompt()`` dialog. Ignored for other dialog types. Defaults to empty string.)r   r   z~Specific dialog to respond to, from ``browser_snapshot.pending_dialogs[].id``. Required only when multiple dialogs are queued.©ÚactionÚprompt_textÚ	dialog_idr   )r   Ú
propertiesÚrequired)Únamer   Ú
parameterszDict[str, Any]ÚBROWSER_DIALOG_SCHEMAÚstrr   úOptional[str]r   Útask_idÚreturnc                ól  — |pd}t          j        |¦  «        }|€t          j        dddœ¦  «        S |                     | ||¬¦  «        }|                     d¦  «        r,t          j        d| |                     d	i ¦  «        d
œ¦  «        S t          j        d|                     dd¦  «        dœ¦  «        S )z@Respond to a pending dialog on the active task's CDP supervisor.ÚdefaultNFzÔNo CDP supervisor is attached to this task. Either the browser backend doesn't expose CDP (Camofox, default Playwright) or no browser session has been started yet. Call browser_navigate or /browser connect first.)ÚsuccessÚerrorr   ÚokTÚdialog)r    r   r#   r!   zunknown error)r   ÚgetÚjsonÚdumpsÚrespond_to_dialog)r   r   r   r   Úeffective_task_idÚ
supervisorÚresults          ú?/home/ragecks/.hermes/hermes-agent/tools/browser_dialog_tool.pyr	   r	   R   så   € ð  Ð, 9ÐÝ$Ô(Ð):Ñ;Ô;€JØÐÝŒzà ðGðð ñ

ô 

ð 
	
ð ×)Ò)ØØØð *ñ ô €Fð
 ‡z‚z�$ÑÔð 
ÝŒzàØ Ø Ÿ*š* X¨rÑ2Ô2ðð ñ
ô 
ð 	
õ Œ: %°&·*²*¸WÀoÑ2VÔ2VÐWÐWÑXÔXÐXó    Úboolc                 óŒ   — 	 ddl m}  n3# t          $ r&}t                               d|¦  «         Y d}~dS d}~ww xY w | ¦   «         S )uQ  Gate: same as ``browser_cdp`` â€” only offered when CDP is reachable.

    Kept identical so the two tools appear and disappear together. The
    supervisor itself is started lazily by ``browser_navigate`` /
    ``/browser connect`` / Browserbase session creation, so a reachable
    CDP URL is enough to commit to showing the tool.
    r   )Ú_browser_cdp_checkz8browser_dialog check: browser_cdp_tool import failed: %sNF)Útools.browser_cdp_toolr/   Ú	ExceptionÚloggerÚdebug)r/   Úexcs     r+   Ú_browser_dialog_checkr5   x   so   € ðØ=Ð=Ð=Ð=Ð=Ð=Ð=øÝð ð ð Ý�ŠÐOÐQTÑUÔUÐUØˆuˆuˆuˆuˆuøøøøðøøøð ÐÑÔÐs   ‚	 ‰
9“4´9zbrowser-cdpc                óÂ   — t          |                      dd¦  «        |                      d¦  «        |                      d¦  «        |                     d¦  «        ¬¦  «        S )Nr   Ú r   r   r   )r   r   r   r   )r	   r$   )ÚargsÚkws     r+   ú<lambda>r:   Œ   sS   € �~Ø�xŠx˜ "Ñ%Ô%Ø—H’H˜]Ñ+Ô+Ø—(’(˜;Ñ'Ô'Ø—’�yÑ!Ô!ð	 ñ  ô  € r,   u   ðŸ’¬)r   ÚtoolsetÚschemaÚhandlerÚcheck_fnÚemoji)NNN)
r   r   r   r   r   r   r   r   r   r   )r   r-   )Ú__doc__Ú
__future__r   r%   ÚloggingÚtypingr   r   r   Útools.browser_supervisorr   Útools.registryr   Ú	getLoggerÚ__name__r2   r   Ú__annotations__r	   r5   Úregister© r,   r+   ú<module>rK      s   ððð ð ð #Ð "Ð "Ð "Ð "Ð "à €€€Ø €€€Ø &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &à 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø #Ð #Ð #Ð #Ð #Ð #à	ˆÔ	˜8Ñ	$Ô	$€ð ð	.ð$ ð !Ø! 9Ð-ð<ð		ð 	ð !ðDðð ð !ð=ðð ð%
ð 
ð6 �Jð;ð ð)3)ð 3)Ð ð 3ð 3ð 3ñ 3ðp "&Ø#Ø!ð	#Yð #Yð #Yð #Yð #YðL ð  ð  ð  ð  €Ô Ø	ØØ ðð ð #Ø
ðñ ô ð ð ð r,   