Ë
    ãß²j  ã                  óü   — U d Z ddlmZ ddlZddlmZmZmZ ddlm	Z	 ddl
m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dlZddiZd „ Zy)$aX  Agent-facing tool: respond to a native JS dialog captured by the CDP supervisor.

Response-only: the agent reads ``pending_dialogs`` from ``browser_snapshot``,
then calls ``browser_dialog(action=...)``. Gated on ``_browser_cdp_check`` so it
appears together with ``browser_cdp``. Design: ``website/docs/developer-guide/browser-supervisor.md``.
é    )Ú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_SCHEMAc                óT  — t        j                  |xs d«      }|€t        j                  dddœ«      S |j	                  | ||¬«      }|j                  d«      r)t        j                  d| |j                  di «      d	œ«      S t        j                  d|j                  d
d«      dœ«      S )z@Respond to a pending dialog on the active task's CDP supervisor.ÚdefaultFzÔ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   Útask_idÚ
supervisorÚresults         ú>/home/ubuntu/.hermes/hermes-agent/tools/browser_dialog_tool.pyr	   r	   F   s¦   € ô %×(Ñ(¨Ò)=°IÓ>€JØÐÜ�z‰zØðCñ
ó ð 	ð ×)Ñ)°À[Ð\eÐ)Óf€FØ‡z�z�$ÔÜ�z‰z d°fÈÏ
É
ÐS[Ð]_ÓH`ÑaÓbÐbÜ�:‰: %°&·*±*¸WÀoÓ2VÑWÓXÐXó    c                 ó   — ddl m}   | «       S )zIGate: same as ``browser_cdp`` so the two tools appear/disappear together.r   ©Ú_browser_cdp_check)Útools.browser_cdp_toolr+   r*   s    r'   Ú_browser_dialog_checkr-   ^   s   € å9áÓÐr(   zbrowser-cdpc                óš   — t        | j                  dd«      | j                  d«      | j                  d«      |j                  d«      ¬«      S )Nr   Ú r   r   r$   )r   r   r   r$   )r	   r    )ÚargsÚkws     r'   ú<lambda>r2   i   sC   € œ~°T·X±X¸hÈÓ5KÐY]×YaÑYaÐboÓYpØ8<¿¹ÀÓ8MÐWY×W]ÑW]Ð^gÓWhô j€ r(   u   ðŸ’¬)r   ÚtoolsetÚschemaÚhandlerÚcheck_fnÚemojiÚlogger)ztools.approvalr8   c                óÌ   — t         j                  | «      }|€t        dt        ›d| ›�«      ‚dd l}ddlm}  |t        | g|¢­Ž  t        |j                  |d   «      |d   «      S )Nzmodule z has no attribute r   )Ú	warn_onceé   )	Ú_PLUGIN_COMPAT_LAZYr    ÚAttributeErrorÚ__name__Ú	importlibÚhermes_cli.plugin_compatr:   ÚgetattrÚimport_module)r   Útargetr?   r:   s       r'   Ú__getattr__rD   |   se   € Ü ×$Ñ$ TÓ*€FØ€~Ü˜w¤x lÐ2DÀTÀHÐMÓNÐNÛÝ2ÙŒh˜Ð&˜vÓ&Ü�9×*Ñ*¨6°!©9Ó5°v¸a±yÓAÐAr(   )NNN)
r   Ústrr   úOptional[str]r   rF   r$   rF   ÚreturnrE   )rG   Úbool)Ú__doc__Ú
__future__r   r!   Útypingr   r   r   Útools.browser_supervisorr   Útools.registryr   r   Ú__annotations__r	   r-   ÚregisterÚloggingr<   rD   © r(   r'   ú<module>rR      s  ðòõ #ã ß &Ñ &å 8Ý #ð ð	.ð$ ð !Ø! 9Ð-ð<ñ		ð !ðDñð !ð=ññ%
ð6 �Jñ;ñ)3)Ð �~ó 3ðp "&Ø#Ø!ð	YØðYàðYð ðYð ð	Yð
 	óYó0 ð €× Ñ Ø	ØØ ñjà"Ø
õó ð Ð*ðÐ ó
Br(   