+
    igJ                    N  a R t0 t R t^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
t
^ RIt^ RIt^ RIt^ RIt^ RIHtHtHtHt ^ RIHt ^ RIHt ^ RIHt  ^ RIHt  ^ RIHt ^ R
I H!t! ^ RI"H#t# ^ RI$H%t% ^ RI&H't' ^ RI(H)t)  ^ RI*H+t, ]P\                  ! ]/4      t0Rt1R R lt2/ t3] ^ k ^t4Rt5Rt6R R lt7R R lt8R R lt9R R lt:R R lt;R ]#R!]%R"]'/t<] ^k Rs=] ^k R#s>R#s?Rs@] ^k R$ R% ltAR& R' ltBR( R) ltCR* R+ ltDR, R- ltER. R/ ltFR0 R1 ltG/ tH] ^k ]I! 4       tJ] ^k R#sK]L! ]P                  P                  R2R34      4      tO/ tP] ^k RsQR#sR]P                  ! 4       tTR4 tU]P                  ! ]U4       R5 tWR6 tXR7 tYR8 tZR9 R: lt[]P                  ! ]Z4       R;R<R=R>R?R@RARBRCR@RDR=RE//RFRC.//R;RGR=RHR?R@RARBRIR@RJR=RKRLR#//RF. //R;RMR=RNR?R@RARBROR@RDR=RP//RFRO.//R;RQR=RRR?R@RARBROR@RDR=RS/RTR@RDR=RU//RFRORT.//R;RVR=RWR?R@RARBRXR@RDRYRZR[.R=R\//RFRX.//R;R]R=R^R?R@RARB/ RF. //R;R_R=R`R?R@RARBRaR@RDR=Rb//RFRa.//R;RcR=RdR?R@RARB/ RF. //R;ReR=RfR?R@RARB/ RF. //R;RgR=RhR?R@RARBRiR@RDR=Rj/RkR@RJRLR#R=Rl//RFRi.//R;RmR=RnR?R@RARBRoR@RJRLR#R=Rp/RqR@RDR=Rr//RF. //.t\Rs Rt lt]Ru Rv lt^RRw Rx llt_Ry Rz lt`R{ R| ltaRR} R~ lltbRR R lltcRR R lltdRR R llteRR R lltfRR R lltgRR R llthRR R lltiRR R lltjRR R lltkRR R lltlRR R lltmRR R lltnRR R lltoR R ltpR R ltqRR R lltrRR R lltsRR lttRR ltuRR R lltvR R ltwR R ltxR R lty]/R8X  d    ]z! R4       ]z! R4       ]A! 4       t{]{f   RMR]{P                  4        R2t}]z! R]} 24       ]y! 4       '       d
   ]z! R4       ML]z! R4        ]`! 4        ]{e9   ]{P                  4       '       g#   ]z! R]{P                  4        R24       ]z! R4       ]z! R4       ]\ F'  t]z! R]R;,           R]R=,          R,           R24       K)  	  ]z! R4       ]z! R4       ]z! R4       ]z! R4       ^ RIHt ]\ U u/ uF  q R;,          V bK  	  up t]P                  ! R<R]R<,          R ]yRR7       ]P                  ! RGR]RG,          R ]yRR7       ]P                  ! RMR]RM,          R ]yRR7       ]P                  ! RQR]RQ,          R ]yRR7       ]P                  ! RVR]RV,          R ]yRR7       ]P                  ! R]R]R],          R ]yRR7       ]P                  ! R_R]R_,          R ]yRR7       ]P                  ! RcR]Rc,          R ]yRR7       ]P                  ! ReR]Re,          R ]yRR7       ]P                  ! RgR]Rg,          R ]yRR7       ]P                  ! RmR]Rm,          R ]yRR7       R#   ] d    R t EL|i ; i  ] d    R	 t ELi ; i  ]- d    R t, ELri ; i  ]~ d    ]z! R4       ]z! R4        EL_i ; iu up i )u  
Browser Tool Module

This module provides browser automation tools using agent-browser CLI.  It
supports two backends — **Browserbase** (cloud) and **local Chromium** — with
identical agent-facing behaviour.  The backend is auto-detected: if
``BROWSERBASE_API_KEY`` is set the cloud service is used; otherwise a local
headless Chromium instance is launched automatically.

The tool uses agent-browser's accessibility tree (ariaSnapshot) for text-based
page representation, making it ideal for LLM agents without vision capabilities.

Features:
- **Local mode** (default): zero-cost headless Chromium via agent-browser.
  Works on Linux servers without a display.  One-time setup:
  ``agent-browser install`` (downloads Chromium) or
  ``agent-browser install --with-deps`` (also installs system libraries for
  Debian/Ubuntu/Docker).
- **Cloud mode**: Browserbase cloud execution with stealth features, proxies,
  and CAPTCHA solving.  Activated when BROWSERBASE_API_KEY is set.
- Session isolation per task ID
- Text-based page snapshots using accessibility tree
- Element interaction via ref selectors (@e1, @e2, etc.)
- Task-aware content extraction using LLM summarization
- Automatic cleanup of browser sessions

Environment Variables:
- BROWSERBASE_API_KEY: API key for Browserbase (enables cloud mode)
- BROWSERBASE_PROJECT_ID: Project ID for Browserbase (required for cloud mode)
- BROWSERBASE_PROXIES: Enable/disable residential proxies (default: "true")
- BROWSERBASE_ADVANCED_STEALTH: Enable advanced stealth mode with custom Chromium,
  requires Scale Plan (default: "false")
- BROWSERBASE_KEEP_ALIVE: Enable keepAlive for session reconnection after disconnects,
  requires paid plan (default: "true")
- BROWSERBASE_SESSION_TIMEOUT: Custom session timeout in milliseconds. Set to extend
  beyond project default. Common values: 600000 (10min), 1800000 (30min) (default: none)

Usage:
    from tools.browser_tool import browser_navigate, browser_snapshot, browser_click
    
    # Navigate to a page
    result = browser_navigate("https://example.com", task_id="task_123")
    
    # Get page snapshot
    snapshot = browser_snapshot(task_id="task_123")
    
    # Click an element
    browser_click("@e5", task_id="task_123")
N)DictAnyOptionalListPath)call_llm)get_hermes_home)check_website_accessc                     R # N urls   &//home/ubuntu/hermes-agent/tools/browser_tool.py<lambda>r   I   s    t    )is_safe_urlc                     R # Fr   r   s   &r   r   r   N       ur   )CloudBrowserProvider)BrowserbaseProvider)BrowserUseProvider)FirecrawlProvider) normalize_browser_cloud_provider)is_camofox_modec                      R # r   r   r   r   r   r   r   [   r   r   za/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binc                :    V ^8  d   QhR\         \        ,          /#    return)liststr)formats   "r   __annotate__r%   g   s      d3i r   c                    . p Rp\         P                  P                  V4      '       g   V #  \         P                  ! V4       F}  pVP	                  R4      '       g   K  VR8w  g   K%  \         P                  P                  WR4      p\         P                  P                  V4      '       g   Kl  V P                  V4       K  	  V #   \         d     T # i ; i)a+  Find Homebrew versioned Node.js bin directories (e.g. node@20, node@24).

When Node is installed via ``brew install node@24`` and NOT linked into
/opt/homebrew/bin, the binary lives only in /opt/homebrew/opt/node@24/bin/.
This function discovers those paths so they can be added to subprocess PATH.
z/opt/homebrew/optnodebin)ospathisdirlistdir
startswithjoinappendOSError)dirshomebrew_optentrybin_dirs       r   _discover_homebrew_node_dirsr5   g   s     D&L77==&&ZZ-E''EVO'',,|EB77==))KK( . K  Ks$   -C C (AC /C CCi,  @  c                $    V ^8  d   QhR\         /# r   )int)r$   s   "r   r%   r%      s     # #c #r   c                     \        4       p V R,          pVP                  4       '       dv   ^ RIp\        V4      ;_uu_ 4       pVP	                  V4      ;'       g    / pRRR4       XP                  R/ 4      P                  R4      pVe   \        \        V4      ^4      # \        #   + '       g   i     LP; i  \         d&   p\        P                  RT4        Rp?\        # Rp?ii ; i)zReturn the configured browser command timeout from config.yaml.

Reads ``config["browser"]["command_timeout"]`` and falls back to
``DEFAULT_COMMAND_TIMEOUT`` (30s) if unset or unreadable.
config.yamlNbrowsercommand_timeoutz.Could not read command_timeout from config: %s)r	   existsyamlopen	safe_loadgetmaxr8   	ExceptionloggerdebugDEFAULT_COMMAND_TIMEOUT)hermes_homeconfig_pathr>   fcfgvales          r   _get_command_timeoutrM      s    J%'!M1k""annQ'--2 #'')R(,,->?C3s8Q'' #" #"
  JEqII""Js1   A B9 B&AB9 &B6	1B9 9C)C$$C)c                :    V ^8  d   QhR\         \        ,          /# r   r   r#   )r$   s   "r   r%   r%      s     C C8C= Cr   c                 `    \         P                  ! RR4      P                  4       ;'       g    R# )u>   Model for browser_vision (screenshot analysis — multimodal).AUXILIARY_VISION_MODEL Nr)   getenvstripr   r   r   _get_vision_modelrV      s%    99-r288:BBdBr   c                :    V ^8  d   QhR\         \        ,          /# r   rO   )r$   s   "r   r%   r%      s     H Hx} Hr   c                 `    \         P                  ! RR4      P                  4       ;'       g    R# )uC   Model for page snapshot text summarization — same as web_extract.AUXILIARY_WEB_EXTRACT_MODELrR   NrS   r   r   r   _get_extraction_modelrZ      s%    992B7==?GG4Gr   c                0    V ^8  d   QhR\         R\         /# )r    cdp_urlr!   r#   )r$   s   "r   r%   r%      s     . .3 .3 .r   c                \   T ;'       g    RP                  4       pV'       g   R# VP                  4       pRV9   d   V# TpVP                  R4      '       g   VP                  R4      '       d   VP                  R4      ^8X  d   VP	                  R4      P                  R^4      R,          P                  4       '       dY   RVP                  R^4      R,          9  d;   VP                  R4      '       d   RMRVP                  R	^4      ^,          ,           pMV# VP                  4       P                  R
4      '       d   TpMVP	                  R4      R
,           p \        P                  ! V^
R7      pVP                  4        VP                  4       p\!        TP                  R4      ;'       g    R4      P                  4       pT'       d   \        P#                  RY4       T# \        P                  RT4       T#   \         d$   p\        P                  RYT4       Tu Rp?# Rp?ii ; i)a  Normalize a user-supplied CDP endpoint into a concrete connectable URL.

Accepts:
- full websocket endpoints: ws://host:port/devtools/browser/...
- HTTP discovery endpoints: http://host:port or http://host:port/json/version
- bare websocket host:port values like ws://host:port

For discovery-style endpoints we fetch /json/version and return the
webSocketDebuggerUrl so downstream tools always receive a concrete browser
websocket instead of an ambiguous host:port URL.
rR   z/devtools/browser/zws://zwss://:/zhttp://zhttps://z://z/json/versiontimeoutz,Failed to resolve CDP endpoint %s via %s: %sNwebSocketDebuggerUrlzResolved CDP endpoint %s -> %szKCDP discovery at %s did not return webSocketDebuggerUrl; using raw endpoint)rU   lowerr-   countrstriprsplitisdigitsplitendswithrequestsrA   raise_for_statusjsonrC   rD   warningr#   info)	r\   rawlowereddiscovery_urlversion_urlresponsepayloadexcws_urls	   &        r   _resolve_cdp_overridery      s    ==b


!CiikGw&
M'""g&8&8&B&B99S>Q3::c?#9#9#q#A"#E#M#M#O#OTW_b_h_hilno_pqs_tTt*1*<*<W*E*EY:Y\YbYbchjkYlmnYooMJ%%o66##**3//A<<R8!!#--/
 34::;AACF4cB
NN`bmnJ  EsY\]
s   8G= =H+H& H+&H+c                $    V ^8  d   QhR\         /# r   r]   )r$   s   "r   r%   r%      s     H H3 Hr   c                 T    \        \        P                  P                  RR4      4      # )a  Return a normalized user-supplied CDP URL override, or empty string.

When ``BROWSER_CDP_URL`` is set (e.g. via ``/browser connect``), we skip
both Browserbase and the local headless launcher and connect directly to
the supplied Chrome DevTools Protocol endpoint.
BROWSER_CDP_URLrR   )ry   r)   environrA   r   r   r   _get_cdp_overrider~      s     !0A2!FGGr   browserbasezbrowser-use	firecrawlFc                :    V ^8  d   QhR\         \        ,          /# r   )r   r   )r$   s   "r   r%   r%      s     '" '"X&:; '"r   c                    \         '       d   \        # Rs  \        4       p V R,          pVP                  4       '       d   ^ RIp\        V4      ;_uu_ 4       pVP                  V4      ;'       g    / pRRR4       XP                  R/ 4      pRp\        V\        4      '       d-   RV9   d&   \        VP                  R4      4      pVR8X  d   RsR# V'       d   V\        9   d   \        V,          ! 4       s\        f#   \        4       pTP!                  4       '       d   Ts\        #   + '       g   i     L; i  \         d!   p\        P                  RT4        Rp?LiRp?ii ; i)aC  Return the configured cloud browser provider, or None for local mode.

Reads ``config["browser"]["cloud_provider"]`` once and caches the result
for the process lifetime. An explicit ``local`` provider disables cloud
fallback. If unset, fall back to Browserbase when direct or managed
Browserbase credentials are available.
Tr:   Nr;   cloud_providerlocalz-Could not read cloud_provider from config: %s)_cloud_provider_resolved_cached_cloud_providerr	   r=   r>   r?   r@   rA   
isinstancedictr   _PROVIDER_REGISTRYrC   rD   rE   r   is_configured)	rG   rH   r>   rI   rJ   browser_cfgprovider_keyrL   fallback_providers	            r   _get_cloud_providerr      s/     %%#I%'!M1k""annQ'--2 #'')R0KL+t,,1A[1P?OO$45   7*-1*0B B);L)I)K& %/1**,,%6"!!+ #"  IDaHHIs=   A D8 D%2AD8 D8 D8 %D5	0D8 8E#EE#c                \    V ^8  d   QhR\         \        \        \        3,          ,          /# r   )r   r   r#   r   )r$   s   "r   r%   r%   "  s      7 7$sCx.)A 7r   c                 2    \        4       P                  4       # )zFReturn Browserbase direct or managed config, or None when unavailable.)r   _get_config_or_noner   r   r   _get_browserbase_config_or_noner   "  s     4466r   c                F    V ^8  d   QhR\         \        \        3,          /# r   )r   r#   r   )r$   s   "r   r%   r%   '  s     / /c3h /r   c                 2    \        4       P                  4       # )zUReturn Browserbase config or raise when neither direct nor managed mode is available.)r   _get_configr   r   r   _get_browserbase_configr   '  s     ,,..r   c                $    V ^8  d   QhR\         /# r   bool)r$   s   "r   r%   r%   ,  s     ) ) )r   c                 >    \        4       '       d   R# \        4       RJ # )zCReturn True when the browser tool will use a local browser backend.FN)r~   r   r   r   r   _is_local_moder   ,  s     D((r   c                $    V ^8  d   QhR\         /# r   r   )r$   s   "r   r%   r%   3  s     
? 
?4 
?r   c                 >    \        4       ;'       g    \        4       RJ # )u  Return True when the browser runs locally (no cloud provider).

SSRF protection is only meaningful for cloud backends (Browserbase,
BrowserUse) where the agent could reach internal resources on a remote
machine.  For local backends — Camofox, or the built-in headless
Chromium without a cloud provider — the user already has full terminal
and network access on the same machine, so the check adds no security
value.
N)_is_camofox_moder   r   r   r   _is_local_backendr   3  s     >>!4!6$!>>r   c                $    V ^8  d   QhR\         /# r   r   )r$   s   "r   r%   r%   @  s     & &T &r   c                    \         '       d   \        # Rs Rs \        4       p V R,          pVP                  4       '       df   ^ RIp\        V4      ;_uu_ 4       pVP                  V4      ;'       g    / pRRR4       \        XP                  R/ 4      P                  R4      4      s\        #   + '       g   i     L@; i  \         d&   p\        P                  RT4        Rp?\        # Rp?ii ; i)zReturn whether the browser is allowed to navigate to private/internal addresses.

Reads ``config["browser"]["allow_private_urls"]`` once and caches the result
for the process lifetime.  Defaults to ``False`` (SSRF protection active).
TFr:   Nr;   allow_private_urlsz1Could not read allow_private_urls from config: %s)_allow_private_urls_resolved_cached_allow_private_urlsr	   r=   r>   r?   r@   r   rA   rC   rD   rE   )rG   rH   r>   rI   rJ   rL   s         r   _allow_private_urlsr   @  s     $#))#' !&	M%'!M1k""annQ'--2 #)-cggi.D.H.HI].^)_& &% #"  MH!LL%%Ms0   A B? B,42B? ,B<	7B? ?C/
C**C/c                $    V ^8  d   QhR\         /# r   r]   )r$   s   "r   r%   r%   Y  s     ! !S !r   c                 Z    \         P                  R8X  d   R# \        P                  ! 4       # )uE  Return a short temp directory path suitable for Unix domain sockets.

macOS sets ``TMPDIR`` to ``/var/folders/xx/.../T/`` (~51 chars).  When we
append ``agent-browser-hermes_…`` the resulting socket path exceeds the
104-byte macOS limit for ``AF_UNIX`` addresses, causing agent-browser to
fail with "Failed to create socket directory" or silent screenshot failures.

Linux ``tempfile.gettempdir()`` already returns ``/tmp``, so this is a
no-op there.  On macOS we bypass ``TMPDIR`` and use ``/tmp`` directly
(symlink to ``/private/tmp``, sticky-bit protected, always available).
darwinz/tmp)sysplatformtempfile
gettempdirr   r   r   _socket_safe_tmpdirr   Y  s"     ||x  r   BROWSER_INACTIVITY_TIMEOUT300c            	        \         '       d   R# Rs \        '       g   R# \        P                  R\	        \        4      4        \        4        \        ;_uu_ 4        \        P                  4        \        P                  4        RRR4       \        P                  4        R#   \         d!   p \        P                  RT 4        Rp ? L{Rp ? ii ; i  + '       g   i     LT; i  \        ;_uu_ 4        \        P                  4        \        P                  4        RRR4       M  + '       g   i     M; i\        P                  4        i ; i)zu
Emergency cleanup of all active browser sessions.
Called on process exit or interrupt to prevent orphaned sessions.
NTz2Emergency cleanup: closing %s active session(s)...zEmergency cleanup error: %s)_cleanup_done_active_sessionsrD   rp   lencleanup_all_browsersrC   error_cleanup_lockclear_session_last_activity_recording_sessions)rL   s    r   _emergency_cleanup_all_sessionsr     s     }M
KKD$%'$ ]""$"((*  	!!#  72A667 ]]]""$"((* ]]] 	!!#sN   
B" )C"C-CC# CC# C 	#E2)D$		E$D4/Ec                    \         P                   ! 4       p . p\        ;_uu_ 4        \        \        P	                  4       4       F)  w  r#W,
          \
        8  g   K  VP                  V4       K+  	  RRR4       V Fs  p \        V \        P                  W 4      ,
          4      p\        P                  RW$4       \        V4       \        ;_uu_ 4        V\        9   d   \        V RRR4       Ku  	  R#   + '       g   i     L; i  + '       g   i     K  ; i  \         d"   p\        P                  RY%4        Rp?K  Rp?ii ; i)a  
Clean up browser sessions that have been inactive for longer than the timeout.

This function is called periodically by the background cleanup thread to
automatically close sessions that haven't been used recently, preventing
orphaned sessions (local or Browserbase) from accumulating.
Nz<Cleaning up inactive session for task: %s (inactive for %ss)z)Error cleaning up inactive session %s: %s)timer   r"   r   items"BROWSER_SESSION_INACTIVITY_TIMEOUTr/   r8   rA   rD   rp   cleanup_browserrC   ro   )current_timesessions_to_cleanuptask_id	last_timeelapsedrL   s         r   "_cleanup_inactive_browser_sessionsr     s     99;L	"&'='C'C'E"FG'*LL#**73 #G 

 '	T,)?)C)CG)ZZ[GKKVX_iG$44.w7  ' 
   	TNNFSS	TsH   1C4C4?ADD&D4D	DDDE&EEc                    \         '       dE    \        4        \        ^4       F(  p\         '       g    K4  \        P                  ! ^4       K*  	  KP  R#   \         d!   p \        P	                  RT 4        Rp ? LaRp ? ii ; i)z
Background thread that periodically cleans up inactive browser sessions.

Runs every 30 seconds and checks for sessions that haven't been used
within the BROWSER_SESSION_INACTIVITY_TIMEOUT period.
zCleanup thread error: %sN)_cleanup_runningr   rC   rD   ro   ranger   sleep)rL   _s     r   _browser_cleanup_thread_workerr     sb     
	:.0
 rA##JJqM    	:NN5q99	:s   
A A>A99A>c                 :   \         ;_uu_ 4        \        e   \        P                  4       '       gN   Rs\        P
                  ! \        RRR7      s\        P                  4        \        P                  R\        4       RRR4       R#   + '       g   i     R# ; i)z;Start the background cleanup thread if not already running.NTzbrowser-cleanup)targetdaemonnamez0Started inactivity cleanup thread (timeout: %ss))r   _cleanup_threadis_aliver   	threadingThreadr   startrD   rp   r   r   r   r   _start_browser_cleanup_threadr     sf     
"/*B*B*D*D#'..5&O
 !!#KKJLno 
s   "B	AB		B	c                 J    Rs \        e   \        P                  ^R7       R# R# )z#Stop the background cleanup thread.FNra   )r   r   r.   r   r   r   _stop_browser_cleanup_threadr     s&     "Q' #r   c                $    V ^8  d   QhR\         /# r    r   r]   )r$   s   "r   r%   r%     s     6 6c 6r   c                    \         ;_uu_ 4        \        P                  ! 4       \        V &   RRR4       R#   + '       g   i     R# ; i)z1Update the last activity timestamp for a session.N)r   r   r   r   s   &r   _update_session_activityr     s$    	*.))+w' 
s	   6A	r   browser_navigatedescriptiona,  Navigate to a URL in the browser. Initializes the session and loads the page. Must be called before other browser tools. For simple information retrieval, prefer web_search or web_extract (faster, cheaper). Use browser tools when you need to interact with a page (click, fill forms, dynamic content).
parameterstypeobject
propertiesr   stringz4The URL to navigate to (e.g., 'https://example.com')requiredbrowser_snapshota]  Get a text-based snapshot of the current page's accessibility tree. Returns interactive elements with ref IDs (like @e1, @e2) for browser_click and browser_type. full=false (default): compact view with interactive elements. full=true: complete page content. Snapshots over 8000 chars are truncated or LLM-summarized. Requires browser_navigate first.fullbooleanzpIf true, returns complete page content. If false (default), returns compact view with interactive elements only.defaultbrowser_clickzClick on an element identified by its ref ID from the snapshot (e.g., '@e5'). The ref IDs are shown in square brackets in the snapshot output. Requires browser_navigate and browser_snapshot to be called first.refz=The element reference from the snapshot (e.g., '@e5', '@e12')browser_typezType text into an input field identified by its ref ID. Clears the field first, then types the new text. Requires browser_navigate and browser_snapshot to be called first.z5The element reference from the snapshot (e.g., '@e3')textzThe text to type into the fieldbrowser_scrollzScroll the page in a direction. Use this to reveal more content that may be below or above the current viewport. Requires browser_navigate to be called first.	directionenumupdownzDirection to scrollbrowser_backzdNavigate back to the previous page in browser history. Requires browser_navigate to be called first.browser_presszPress a keyboard key. Useful for submitting forms (Enter), navigating (Tab), or keyboard shortcuts. Requires browser_navigate to be called first.keyz:Key to press (e.g., 'Enter', 'Tab', 'Escape', 'ArrowDown')browser_closez}Close the browser session and release resources. Call this when done with browser tasks to free up Browserbase session quota.browser_get_imageszGet a list of all images on the current page with their URLs and alt text. Useful for finding images to analyze with the vision tool. Requires browser_navigate to be called first.browser_visiona  Take a screenshot of the current page and analyze it with vision AI. Use this when you need to visually understand what's on the page - especially useful for CAPTCHAs, visual verification challenges, complex layouts, or when the text snapshot doesn't capture important visual information. Returns both the AI analysis and a screenshot_path that you can share with the user by including MEDIA:<screenshot_path> in your response. Requires browser_navigate to be called first.questionzYWhat you want to know about the page visually. Be specific about what you're looking for.annotatezIf true, overlay numbered [N] labels on interactive elements. Each [N] maps to ref @eN for subsequent browser commands. Useful for QA and spatial reasoning about page layout.browser_consoleu  Get browser console output and JavaScript errors from the current page. Returns console.log/warn/error/info messages and uncaught JS exceptions. Use this to detect silent JavaScript errors, failed API calls, and application warnings. Requires browser_navigate to be called first. When 'expression' is provided, evaluates JavaScript in the page context and returns the result — use this for DOM inspection, reading page state, or extracting data programmatically.r   z0If true, clear the message buffers after reading
expressionu   JavaScript expression to evaluate in the page context. Runs in the browser like DevTools console — full access to DOM, window, document. Return values are serialized to JSON. Example: 'document.title' or 'document.querySelectorAll("a").length'c                R    V ^8  d   QhR\         R\        \         \         3,          /# r    r   r!   r#   r   )r$   s   "r   r%   r%     s"     
 
3 
4S> 
r   c           	          ^ RI pRVP                  4       P                  R,           2p\        P	                  RW 4       RVRRRRRR	R
//# )    Nh_N
   Nz,Created local browser session %s for task %ssession_namebb_session_idr\   featuresr   Tuuiduuid4hexrD   rp   )r   r  r  s   &  r   _create_local_sessionr    sY    

((-./L
KK>' 	4WdO	 r   c                ^    V ^8  d   QhR\         R\         R\        \         \         3,          /# )r    r   r\   r!   r   )r$   s   "r   r%   r%     s)       s tCH~ r   c           	         ^ RI pRVP                  4       P                  R,           2p\        P	                  RW1V 4       RVRRRVRR	R
//# )z?Create a session that connects to a user-supplied CDP endpoint.Ncdp_r  u1   Created CDP browser session %s → %s for task %sr  r  r\   r  cdp_overrideTr  )r   r\   r  r  s   &&  r   _create_cdp_sessionr    s\    $**,**3/01L
KKCw0 	7^T*	 r   c                h    V ^8  d   QhR\         \        ,          R\        \        \        3,          /# r   )r   r#   r   )r$   s   "r   r%   r%     s&     0 0x} 0S#X 0r   c                   V f   Rp \        4        \        V 4       \        ;_uu_ 4        V \        9   d   \        V ,          uuRRR4       #  RRR4       \	        4       pV'       d   \        W4      pM+\        4       pVf   \        V 4      pMVP                  V 4      p\        ;_uu_ 4        V \        9   d   \        V ,          uuRRR4       # V\        V &   RRR4       V#   + '       g   i     L; i  + '       g   i     T# ; i)a  
Get or create session info for the given task.

In cloud mode, creates a Browserbase session with proxies enabled.
In local mode, generates a session name for agent-browser --session.
Also starts the inactivity cleanup thread and updates activity tracking.
Thread-safe: multiple subagents can call this concurrently.

Args:
    task_id: Unique identifier for the task
    
Returns:
    Dict with session_name (always), bb_session_id + cdp_url (cloud only)
Nr   )	r   r   r   r   r~   r  r   r  create_session)r   r  session_infoproviders   &   r   _get_session_infor    s      "# W%	&&#G, 
& 
 %&L*7A&(09L#227;L	 &&#G, 
 %1! 
 1 
  
 s   C#-C6	C6#C3	6D	c                $    V ^8  d   QhR\         /# r   r]   )r$   s   "r   r%   r%     s     7 7S 7r   c                    \         P                  ! R4      p V '       d   V # . pR
 F;  p\        P                  P	                  V4      '       g   K*  VP                  V4       K=  	  VP                  \        4       4       \        4       p\        VR,          R,          4      p\        P                  P	                  V4      '       d   VP                  V4       V'       dB   \        P                  P                  V4      p\         P                  ! RVR7      p V '       d   V # \        \        4      P                  P                  pVR,          R,          R,          pVP                  4       '       d   \        V4      # \         P                  ! R4      pV'       g>   V'       d6   \         P                  ! R\        P                  P                  V4      R7      pV'       d   R# \!        R	4      h)a  
Find the agent-browser CLI executable.

Checks in order: current PATH, Homebrew/common bin dirs, Hermes-managed
node, local node_modules/.bin/, npx fallback.

Returns:
    Path to agent-browser executable
    
Raises:
    FileNotFoundError: If agent-browser is not installed
zagent-browserr'   r(   )r*   node_modulesz.binnpxznpx agent-browserzagent-browser CLI not found. Install it with: npm install -g agent-browser
Or run 'npm install' in the repo root to install locally.
Or ensure npx is available in your PATH.)z/opt/homebrew/binz/usr/local/bin)shutilwhichr)   r*   r+   r/   extendr5   r	   r#   pathsepr.   r   __file__parentr=   FileNotFoundError)	which_result
extra_dirsdrG   hermes_node_binextended_path	repo_root	local_binnpx_paths	            r   _find_agent_browserr*    sZ    <<0L J477==a  5 245!#K+.67O	ww}}_%%/*


3||O-H X%%,,IN*V3oEI9~ ||E"H
<<BJJOOJ,GH"
	3 r   c                F    V ^8  d   QhR\         R\        \         ,          /# )r    r   r!   r#   r   )r$   s   "r   r%   r%   2  s      S Xc] r   c                    V '       g   R# . ROpV F]  p\         P                  ! W 4      pV'       g   K#  VP                  R4      P                  4       P                  R4      pV'       g   K[  Vu # 	  R# )zHExtract a screenshot file path from agent-browser human-readable output.Nr*   z'")z6Screenshot saved to ['\"](?P<path>/[^'\"]+?\.png)['\"]z0Screenshot saved to (?P<path>/\S+?\.png)(?:\s|$)z(?P<path>/\S+?\.png)(?:\s|$))researchgrouprU   )r   patternspatternmatchr*   s   &    r   "_extract_screenshot_path_from_textr4  2  s_    H 		'(5;;v&,,.44U;Dt  r   c                    V ^8  d   QhR\         R\         R\        \         ,          R\        \        ,          R\        \         \
        3,          /# )r    r   commandargsrb   r!   )r#   r   r   r8   r   r   )r$   s   "r   r%   r%   G  sQ     I3 I3I3I3 s)I3 c]	I3
 
#s(^I3r   c           	     t   Vf   \        4       pT;'       g    . p \        4       p^ RIHp T! 4       '       d   RRRR/#  \        T 4      pTP                  R
4      '       d   RTR
,          .pMRTR,          .pTP                  4       T,           RT.,           T,           p	 \        P                  P                  \        4       RTR,           24      p
\        P                   ! T
RRR7       \        P#                  RYT
\%        T
4      4       / \        P&                  Cp\)        4       p\        TR,          R,          4      pTP                  RR4      pTP                  R4       Uu. uF  q'       g   K  TNK  	  ppT.\+        4       ,           \,        P                  R4       Uu. uF  q'       g   K  TNK  	  up,           p\/        T4       FE  p\        P                  P1                  T4      '       g   K*  TT9  g   K3  TP3                  ^ T4       KG  	  RP                  T4      TR&   YR&   \        P                  P                  T
RT 24      p\        P                  P                  T
RT 24      p\        P4                  ! T\        P6                  \        P8                  ,          \        P:                  ,          R4      p\        P4                  ! T\        P6                  \        P8                  ,          \        P:                  ,          R4      p \<        P>                  ! T	TT\<        P@                  TR7      p\        PB                  ! T4       \        PB                  ! T4        TPE                  TR7       \5        TR"4      ;_uu_ 4       pTPK                  4       pRRR4       \5        TR"4      ;_uu_ 4       pTPK                  4       pRRR4       TPL                  pTT3 F  p \        PN                  ! T4       K  	  X'       dk   TPS                  4       '       dU   T^ 8w  d   \T        PV                  M\T        PX                  p\        P[                  TR#TTPS                  4       R$,          4       XPS                  4       '       gN   T^ 8X  dG   \        P	                  R%TR&P                  T	R',          4      R(,           T;'       g    RR),          4       TPS                  4       pT'       d    \\        P^                  ! T4      pTR*8X  dn   TP                  R4      '       dW   TP                  R+/ 4      pTP                  R*4      '       g.   TP                  R,4      '       g   \        P	                  R-T4       T# T^ 8w  dC   T'       d   TPS                  4       MR8T 2p$\        P	                  R9TTT$R:,          4       RRRT$/# RRR+/ /#   \         d0   p\        P	                  RT4       RRR\        T4      /u Rp?# Rp?ii ; i  \         d3   p\        P	                  RY4       RRRR	\        T4       2/u Rp?# Rp?ii ; iu upi u upi   \        PB                  ! T4       \        PB                  ! T4       i ; i  \<        PF                   dE    TPI                  4        TPE                  4        \        P	                  RYY
4       RRRR T R!2/u # i ; i  + '       g   i     ELI; i  + '       g   i     EL0; i  \P         d     EK2  i ; i  \\        P`                   d    TR.,          p \        P	                  R/TTT R$,          4       TR08X  d   T;'       g    RPS                  4       p!R1P                  R2 TT!3 4       4      p"\c        T"4      p#T#'       dB   \e        T#4      Pg                  4       '       d#   \        Pi                  R3T#4       RRR+R4T#R5T //u # RRRR6T R7T  2/u # i ; i  \         d2   p\        P	                  R;YRR<7       RRR\        T4      /u Rp?# Rp?ii ; i)=a  
Run an agent-browser CLI command using our pre-created Browserbase session.

Args:
    task_id: Task identifier to get the right session
    command: The command to run (e.g., "open", "click")
    args: Additional arguments for the command
    timeout: Command timeout in seconds.  ``None`` reads
             ``browser.command_timeout`` from config (default 30s).
    
Returns:
    Parsed JSON response from agent-browser
Nzagent-browser CLI not found: %ssuccessFr   )is_interruptedInterruptedz0Failed to create browser session for task=%s: %sz"Failed to create browser session: r\   z--cdpz	--sessionr  z--jsonagent-browser-i  T)modeexist_okz/browser cmd=%s task=%s socket_dir=%s (%d chars)r'   r(   PATHrR   r_   AGENT_BROWSER_SOCKET_DIR_stdout__stderr_i  )stdoutstderrstdinenvra   z9browser '%s' timed out after %ds (task=%s, socket_dir=%s)zCommand timed out after z secondsrzbrowser '%s' stderr: %s:Ni  Nz>browser '%s' returned empty stdout with rc=0. cmd=%s stderr=%s :N   N...:N   Nsnapshotdatarefsz]snapshot returned empty content. Possible stale daemon or CDP connection issue. returncode=%s:Ni  Nz1browser '%s' returned non-JSON output (rc=%s): %s
screenshot
c              3   8   "   T F  q'       g   K  Vx  K  	  R # 5ir   r   ).0parts   & r   	<genexpr>'_run_browser_command.<locals>.<genexpr>  s      .)Ct)Cs   	
z<browser 'screenshot' recovered file from non-JSON output: %sr*   rq   z(Non-JSON output from agent-browser for 'z': zCommand failed with code zbrowser '%s' failed (rc=%s): %s:Ni,  Nzbrowser '%s' exception: %sexc_info)5rM   r*  r!  rD   ro   r#   tools.interruptr:  r  rC   rA   rj   r)   r*   r.   r   makedirsrE   r   r}   r	   r5   
_SANE_PATHreversedr+   insertr?   O_WRONLYO_CREATO_TRUNC
subprocessPopenDEVNULLclosewaitTimeoutExpiredkillread
returncodeunlinkr0   rU   loggingWARNINGDEBUGlogrn   loadsJSONDecodeErrorr4  r   r=   rp   )%r   r6  r7  rb   browser_cmdrL   r:  r  backend_args	cmd_partstask_socket_dirbrowser_envrG   r%  existing_pathp
path_partscandidate_dirsrS  stdout_pathstderr_path	stdout_fd	stderr_fdprocrI   rC  rD  rh  levelstdout_textparsed	snap_datarq   stderr_textcombined_textrecovered_path	error_msgs%   &&&&                                 r   _run_browser_commandr  G  s   & &(::2D3)+
 /5'=99Z(1 	""  i!89 $\.%AB!!#l26  	I
N3 '',,!\.9:;
 	O%$?FO8L	N %n &'kF2U:;#3!.!4!4S!9?!9AQaa!9
?*,-$**3/5/Q1qq/56 	 ^,Dww}}T""t:'=!!!T* - "hhz2F2A./ ggll?hwi4HIggll?hwi4HIGGKrzz)ABJJ)NPUV	GGKrzz)ABJJ)NPUV	
	 ##   ((D HHYHHY	]IIgI& +s##qVVXF $+s##qVVXF $__
 {+A		! , fllnn'1QGOOGMMEJJu7&,,.QUBVW ||~~*/NN ."CHHYr]$;e$C"LLb$/1
 lln&K0j(VZZ	-B-B &

62 6I$==44Y]]6=R=R (78BD @ ?*08QR\Q]6^INN<gzS\]aSbcugy994,,W  38!<5'3q6223  ZI7V5'-OPSTUPVx+XYYZT @ 68 HHYHHY (( 	]IIKIIKNNV"WGug1I'RZ/[\\	] $#####  8 '' !%(R&
CI? l*#)<<R"6"6"8K$(II .*5{)C. %M &H%VN%$~*>*E*E*G*GZ*
 &t" & %s%   uGyPSTWSXY 3L  33W$O5'3q6223s  
W  X !C_; '	Y5Y;*_; %	Y3Y99_; 7_;  D_; )Y >,_; +Z =_; [""_; >[6_; +\
_; _; #A)_; >_; %_; 33\ '(\ \ '\ ?_; 9_; _; X$X=XXY'Y=YY
_; .Z_; A[_; [_; "[3	-	_; 6\		_; 
\_; \_; A_8*A=_8'_; )_85_; 7_88_; ;`7&`2,`72`7c                R    V ^8  d   QhR\         R\        \         ,          R\         /# )r    snapshot_text	user_taskr!   r,  )r$   s   "r   r%   r%     s*     51 5151}51 	51r   c                   V'       d   RV RV  R2pMRV  R2p^ RI Hp V! V4      p RRR	R
RRV/.RRRR/p\        4       pV'       d   WTR&   \        R/ VB pVP                  ^ ,          P
                  P                  ;'       g    RP                  4       ;'       g    \        V 4      pV! V4      #   \         d    \        T 4      u # i ; i)zUse LLM to extract relevant content from a snapshot based on the user's task.

Falls back to simple truncation when no auxiliary text model is configured.
zQYou are a content extractor for a browser automation agent.

The user's task is: a  

Given the following page snapshot (accessibility tree representation), extract and summarize the most relevant information for completing this task. Focus on:
1. Interactive elements (buttons, links, inputs) that might be needed
2. Text content relevant to the task (prices, descriptions, headings, important info)
3. Navigation structure if relevant

Keep ref IDs (like [ref=e5]) for interactive elements so the agent can use them.

Page Snapshot:
zW

Provide a concise summary that preserves actionable information and relevant content.zSummarize this page snapshot, preserving:
1. All interactive elements with their ref IDs (like [ref=e5])
2. Key text content and headings
3. Important information visible on the page

Page Snapshot:
zL

Provide a concise summary focused on interactive elements and key content.redact_sensitive_texttaskweb_extractmessagesroleusercontent
max_tokensi  temperature皙?modelrR   r   )
agent.redactr  rZ   r   choicesmessager  rU   _truncate_snapshotrC   )r  r  extraction_promptr  call_kwargsr  ru   	extracteds   &&      r   _extract_relevant_contentr    s    ##,+ .  -o .d	e 	  -o .Y	Z 	 3-.?@1M&&)5FGH$3	
 &'#( *k*%%a(0088>>BEEGllK]^kKl	$Y// 1!-001s   AB2 B2 B2 2C
Cc                <    V ^8  d   QhR\         R\        R\         /# )r    r  	max_charsr!   )r#   r8   )r$   s   "r   r%   r%   K  s&     I Ic Ic IS Ir   c                >    \        V 4      V8:  d   V # V RV R,           # )z
Simple truncation fallback for snapshots.

Args:
    snapshot_text: The snapshot text to truncate
    max_chars: Maximum characters to keep
    
Returns:
    Truncated text with indicator if truncated
Nz

[... content truncated ...])r   )r  r  s   &&r   r  r  K  s*     =Y&)$'HHHr   c                R    V ^8  d   QhR\         R\        \         ,          R\         /# )r    r   r   r!   r,  )r$   s   "r   r%   r%   `  s*     v v# v v vr   c                F  a ^ RI Hp VP                  V 4      '       d   \        P                  ! RRRR/4      # \        4       '       g<   \        4       '       g,   \        V 4      '       g   \        P                  ! RRRR/4      # \        V 4      pV'       d?   \        P                  ! RRRVR,          RR	VR	,          R
VR
,          RVR,          //4      # \        4       '       d   ^ RI
Hp V! W4      # T;'       g    Rp\        V4      pVP                  RR4      pV'       d   RVR&   \        V4       \        VRV .\!        \#        4       ^<4      R7      pVP                  R4      '       Ed   VP                  R/ 4      p	V	P                  RR4      p
V	P                  RV 4      p\        4       '       gZ   \        4       '       gJ   V'       dB   W8w  d<   \        V4      '       g+   \        VRR.^
R7       \        P                  ! RRRR/4      # RRRVRV
/p. R#OpV
P%                  4       o\&        ;QJ d    V3R lV 4       F  '       g   K   RM	  RM! V3R lV 4       4      '       d
   RV
 R2VR&   V'       d`   RV9   dY   VR,          pVP)                  4        UUu. uF  w  ppV'       g   K  VNK  	  pppVP                  R4      '       g   RVR&   VVR &   \        P                  ! VRR!7      # \        P                  ! RRRVP                  RR"4      /RR!7      # u uppi )$z
Navigate to a URL in the browser.

Args:
    url: The URL to navigate to
    task_id: Task identifier for session isolation
    
Returns:
    JSON string with navigation result (includes stealth features info on first nav)
)
_PREFIX_REr9  Fr   z_Blocked: URL contains what appears to be an API key or token. Secrets must not be sent in URLs.z2Blocked: URL targets a private or internal addressr  blocked_by_policyhostrulesource)camofox_navigater   
_first_navTr?   ra   rM  titlerR   r   zabout:blankz6Blocked: redirect landed on a private/internal addressc              3   ,   <"   T F	  qS9   x  K  	  R # 5ir   r   )rR  r2  title_lowers   & r   rT  #browser_navigate.<locals>.<genexpr>  s     F5E'+%5E   zPage title 'a0  ' suggests bot detection. The site may have blocked this request. Options: 1) Try adding delays between actions, 2) Access different pages first, 3) Enable advanced stealth (BROWSERBASE_ADVANCED_STEALTH=true, requires Scale plan), 4) Some sites have very aggressive bot detection that may be unavoidable.bot_detection_warningr  proxieszRunning WITHOUT residential proxies. Bot detection may be more aggressive. Consider upgrading Browserbase plan for proxy support.stealth_warningstealth_featuresensure_asciizNavigation failed)zaccess deniedz#access to this page has been deniedblockedzbot detectedzverification requiredzplease verifyzare you a robotcaptcha
cloudflarezddos protectionzchecking your browserzjust a momentzattention required)r  r  r/  rn   dumpsr   r   _is_safe_urlr
   r   tools.browser_camofoxr  r  rA   _maybe_start_recordingr  rB   rM   re   anyr   )r   r   r  r  r  effective_task_idr  is_first_navresultrM  r  	final_urlru   blocked_patternsr  kvactive_featuresr  s   &&                @r   r   r   `  s    (zzu 9
  	 ':'<'<\RUEVEVzzuI
  	 #3'GzzuWY'&'&/676?T\^efn^o!p
  	 :--,,9 %%67L##L$7L %*\"01!"3VcUCPdPfhjLklFzz)zz&"%"%HHUC(	 !""+>+@+@YS\Sclx  zC  mD  mD !2F]OUWX::5Q   t9U

 kkm3F5EF333F5EFFFug &\ \ ,- J,6#J/H-5^^-=C-=TQqq-=OC<<	**M *+ ,;H'(zz(77zzuVZZ)<=
  	 Ds   L/Lc                t    V ^8  d   QhR\         R\        \        ,          R\        \        ,          R\        /# )r    r   r   r  r!   r   r   r#   )r$   s   "r   r%   r%     s8     3 3
3c]3 }3 		3r   c           	        \        4       '       d   ^ RIHp V! WV4      # T;'       g    Rp. pV '       g   VP                  R.4       \	        VRV4      pVP                  R4      '       d   VP                  R/ 4      pVP                  RR4      pVP                  R/ 4      p	\        V4      \        8  d   V'       d   \        W4      pM\        V4      \        8  d   \        V4      pRR	RTR
V	'       d   \        V	4      M^ /p
\        P                  ! V
RR7      # \        P                  ! RRRVP                  RR4      /RR7      # )a?  
Get a text-based snapshot of the current page's accessibility tree.

Args:
    full: If True, return complete snapshot. If False, return compact view.
    task_id: Task identifier for session isolation
    user_task: The user's current task (for task-aware extraction)
    
Returns:
    JSON string with page snapshot
)camofox_snapshotr   z-crL  r9  rM  rR   rN  Telement_countFr  r   zFailed to get snapshot)r   r  r  r  r  rA   r   SNAPSHOT_SUMMARIZE_THRESHOLDr  r  rn   r  )r   r   r  r  r  r7  r  rM  r  rN  ru   s   &&&        r   r   r     s)     :y99,,9 DTF!"3ZFFzz)zz&"%R0xx# } <<5mOM">>.}=M t$SYA
 zz(77zzuVZZ)AB
  	r   c                R    V ^8  d   QhR\         R\        \         ,          R\         /# )r    r   r   r!   r,  )r$   s   "r   r%   r%     s%        s  Xc]  c  r   c           
     n   \        4       '       d   ^ RIHp V! W4      # T;'       g    RpV P                  R4      '       g   RV  2p \	        VRV .4      pVP                  R4      '       d   \        P                  ! RRRV /RR	7      # \        P                  ! RRR
VP                  R
RV  24      /RR	7      # )z
Click on an element.

Args:
    ref: Element reference (e.g., "@e5")
    task_id: Task identifier for session isolation
    
Returns:
    JSON string with click result
)camofox_clickr   @clickr9  TclickedFr  r   zFailed to click )r   r  r  r-   r  rA   rn   r  )r   r   r  r  r  s   &&   r   r   r     s     7S**,,9 >>##i!"3WseDFzz)zzts
  	
 zzuVZZ+;C5)AB
  	r   c                ^    V ^8  d   QhR\         R\         R\        \         ,          R\         /# )r    r   r   r   r!   r,  )r$   s   "r   r%   r%   2  s,     # #c # #x} # #r   c           
     t   \        4       '       d   ^ RIHp V! WV4      # T;'       g    RpV P                  R4      '       g   RV  2p \	        VRW.4      pVP                  R4      '       d   \        P                  ! RRRVRV /R	R
7      # \        P                  ! RR	RVP                  RRV  24      /R	R
7      # )z
Type text into an input field.

Args:
    ref: Element reference (e.g., "@e3")
    text: Text to type
    task_id: Task identifier for session isolation
    
Returns:
    JSON string with type result
)camofox_typer   r  fillr9  TtypedelementFr  r   zFailed to type into )r   r  r  r-   r  rA   rn   r  )r   r   r   r  r  r  s   &&&   r   r   r   2  s     6Cw//,,9 >>##i ""3Vc[IFzz)zztTs
 	 	 zzuVZZ+?u)EF
  	r   c                R    V ^8  d   QhR\         R\        \         ,          R\         /# )r    r   r   r!   r,  )r$   s   "r   r%   r%   X  s%     # #c #HSM #S #r   c           
        \        4       '       d   ^ RIHp V! W4      # T;'       g    RpV R9  d!   \        P                  ! RRRRV  R2/RR7      # \        VR	V .4      pVP                  R4      '       d   \        P                  ! RR
RV /RR7      # \        P                  ! RRRVP                  RRV  24      /RR7      # )z
Scroll the page.

Args:
    direction: "up" or "down"
    task_id: Task identifier for session isolation
    
Returns:
    JSON string with scroll result
)camofox_scrollr   r9  Fr   zInvalid direction 'z'. Use 'up' or 'down'.r  scrollTscrolledzFailed to scroll )r   r   )r   r  r  rn   r  r  rA   )r   r   r  r  r  s   &&   r   r   r   X  s     8i11,,9 &zzu*9+5KL
  	
 ""3X	{KFzz)zzt	
  	
 zzuVZZ+<YK)HI
  	r   c                F    V ^8  d   QhR\         \        ,          R\        /# r   rO   )r$   s   "r   r%   r%   ~  s      (3- 3 r   c           	     r   \        4       '       d   ^ RIHp V! V 4      # T ;'       g    Rp\        VR. 4      pVP	                  R4      '       d?   VP	                  R/ 4      p\
        P                  ! RRRVP	                  RR4      /R	R
7      # \
        P                  ! RR	RVP	                  RR4      /R	R
7      # )z
Navigate back in browser history.

Args:
    task_id: Task identifier for session isolation
    
Returns:
    JSON string with navigation result
)camofox_backr   backr9  rM  Tr   rR   Fr  r   zFailed to go back)r   r  r  r  rA   rn   r  )r   r  r  r  rM  s   &    r   r   r   ~  s     6G$$,,9!"3VR@Fzz)zz&"%zzt488E2&
  	
 zzuVZZ)<=
  	r   c                R    V ^8  d   QhR\         R\        \         ,          R\         /# )r    r   r   r!   r,  )r$   s   "r   r%   r%     s%      s Xc] c r   c           
     6   \        4       '       d   ^ RIHp V! W4      # T;'       g    Rp\        VRV .4      pVP	                  R4      '       d   \
        P                  ! RRRV /RR7      # \
        P                  ! RRR	VP	                  R	R
V  24      /RR7      # )z
Press a keyboard key.

Args:
    key: Key to press (e.g., "Enter", "Tab")
    task_id: Task identifier for session isolation
    
Returns:
    JSON string with key press result
)camofox_pressr   pressr9  TpressedFr  r   zFailed to press )r   r  r  r  rA   rn   r  )r   r   r  r  r  s   &&   r   r   r     s     7S**,,9!"3WseDFzz)zzts
  	
 zzuVZZ+;C5)AB
  	r   c                F    V ^8  d   QhR\         \        ,          R\        /# r   rO   )r$   s   "r   r%   r%     s     4 48C= 4C 4r   c                (   \        4       '       d   ^ RIHp V! V 4      # T ;'       g    Rp\        ;_uu_ 4        V\        9   pRRR4       \        V4       RRRR/pX'       g   RVR&   \        P                  ! VR	R
7      #   + '       g   i     LF; i)z
Close the browser session.

Args:
    task_id: Task identifier for session isolation

Returns:
    JSON string with close result
)camofox_closer   Nr9  Tclosedz Session may not have been activero   Fr  )r   r  r  r   r   r   rn   r  )r   r  r  had_sessionru   s   &    r   r   r     s     7W%%,,9	'+;; 
 %& 	4$H @::hU33 
s   
BB	c                t    V ^8  d   QhR\         R\        \        ,          R\        \        ,          R\        /# )r    r   r   r   r!   r  )r$   s   "r   r%   r%     s4     7 74 7Xc] 7T\]`Ta 7mp 7r   c                   Ve   \        W4      # \        4       '       d   ^ RIHp V! W4      # T;'       g    RpV '       d   R.M. pV '       d   R.M. p\	        VRV4      p\	        VRV4      p. p	VP                  R4      '       da   VP                  R/ 4      P                  R. 4       F:  p
V	P                  R	V
P                  R	R
4      RV
P                  RR4      RR/4       K<  	  . pVP                  R4      '       dO   VP                  R/ 4      P                  R. 4       F(  pVP                  RVP                  RR4      RR/4       K*  	  \        P                  ! RRRV	RVR\        V	4      R\        V4      /RR7      # )a-  Get browser console messages and JavaScript errors, or evaluate JS in the page.

When ``expression`` is provided, evaluates JavaScript in the page context
(like the DevTools console) and returns the result.  Otherwise returns
console output (log/warn/error/info) and uncaught exceptions.

Args:
    clear: If True, clear the message/error buffers after reading
    expression: JavaScript expression to evaluate in the page context
    task_id: Task identifier for session isolation
    
Returns:
    JSON string with console messages/errors, or eval result
)camofox_consoler   z--clearconsoleerrorsr9  rM  r  r   rm  r   rR   r  r  	exceptionTconsole_messages	js_errorstotal_messagestotal_errorsFr  )
_browser_evalr   r  r  r  rA   r/   rn   r  r   )r   r   r   r  r  console_args
error_argsconsole_resulterrors_resultr  msgr  errs   &&&          r   r   r     s     Z11 9u..,,9"'I;RL %)2J)*;YUN():HjQMH)$$!%%fb155j"ECOO.+)  F F## $$VR044XrBCMM3779b1+  C ::4HV#h-F  r   c                R    V ^8  d   QhR\         R\        \         ,          R\         /# r    r   r   r!   r,  )r$   s   "r   r%   r%     s%     %( %(c %(HSM %(S %(r   c           
        a \        4       '       d   \        W4      # T;'       g    Rp\        VRV .4      pVP                  R4      '       g   VP                  RR4      o\        ;QJ d    V3R lR 4       F  '       g   K   RM	  RM! V3R lR 4       4      '       d   \
        P                  ! RRRR	S 2/4      # \
        P                  ! RRRS/4      # VP                  R
/ 4      pVP                  R4      pTp\        V\        4      '       d    \
        P                  ! V4      p\
        P                  ! RRRVR\        V4      P                  /R\        R7      #   \
        P                  \        3 d     LSi ; i)zKEvaluate a JavaScript expression in the page context and return the result.r   evalr9  r   zeval failedc              3   H   <"   T F  qSP                  4       9   x  K  	  R # 5ir   )re   )rR  hintr  s   & r   rT   _browser_eval.<locals>.<genexpr>  s     t/stsyy{"/ss   "TFz@JavaScript evaluation is not supported by this browser backend. rM  r  result_typer  r   )zunknown commandznot supportedz	not foundzno such command)r   _camofox_evalr  rA   r  rn   r  r   r#   rn  ro  
ValueErrorr   __name__)r   r   r  r  rM  
raw_resultr  r  s   &&     @r   r  r    sb   Z11,,9!"3Vj\JF::i  jj-03t/st333t/sttt::5[\_[`a   zzuS
  	
 ::fb!D(#J F*c""	ZZ
+F ::4&tF|,, 3	( ( $$j1 		s   E E=<E=c                R    V ^8  d   QhR\         R\        \         ,          R\         /# r  r,  )r$   s   "r   r%   r%   9  s*     B Bc BHSM BS Br   c           
       a ^ RI HpHpHp  T! T;'       g    R4      pV! V4      pV! RV R2RV /R7      p\	        V\
        4      '       d   VP                  R4      MTpTp	\	        V\        4      '       d    \        P                  ! V4      p	\        P                  ! RR	RV	R
\        V	4      P                  /R\        R7      #   \        P                  \        3 d     LSi ; i  \         d   p
\        T
4      o\         ;QJ d    T3R lR 4       F  '       g   K   R	M	  RM! T3R lR 4       4      '       d    \        P                  ! RRRR/4      u Rp
?
# \        P                  ! RRRS/4      u Rp
?
# Rp
?
ii ; i)zFEvaluate JS via Camofox's /tabs/{tab_id}/eval endpoint (if available).)_get_session_ensure_tab_postr   z/tabs/z/evalr   )	json_datar  r9  Tr  Fr  c              3   ,   <"   T F	  qS9   x  K  	  R # 5ir   r   )rR  coder  s   & r   rT   _camofox_eval.<locals>.<genexpr>R  s     C-BTy -Br  r   z|JavaScript evaluation is not supported by this Camofox server. Use browser_snapshot or browser_vision to inspect page state.N)404405501)r  r  r  r  r   r   rA   r#   rn   rn  ro  r  r  r   r  rC   r  )r   r   r  r  r  sessiontab_idrespr  r  rL   r  s   &&         @r   r  r  9  s\   FFBw33)4W%vfXU+j7QR ,6dD+A+ATXXh't
j#&&J/ zztf4<00
 s	, 	, ((*5   	BF	3C-BC333C-BCCC::5 Y  
 zz9eWi@AA	Bs_   
C& A C& 9C 5C& C# C& "C##C& &E?1*E:E:<E:E?E:4E?:E?c                $    V ^8  d   QhR\         /# r   r]   )r$   s   "r   r%   r%   [  s      ;  ;C  ;r   c                x   V \         9   d   R#  \        4       pVR,          pRpVP                  4       '       d^   ^ RIp\	        V4      ;_uu_ 4       pVP                  V4      ;'       g    / pRRR4       XP                  R/ 4      P                  RR4      pV'       g   R# VR,          pVP                  RRR7       \        ^HR	7       ^ RI	pVP                  ! R
4      p	VRV	 RV R,           R2,          p
\        V RR\        V
4      .4      pVP                  R4      '       d.   \         P                  V 4       \        P                  RW
4       R# \        P!                  RVP                  R4      4       R#   + '       g   i     EL; i  \"         d"   p\        P!                  RT4        Rp?R# Rp?ii ; i)z@Start recording if browser.record_sessions is enabled in config.Nr:   Fr;   record_sessionsbrowser_recordingsTparentsr>  max_age_hoursz%Y%m%d_%H%M%Ssession_r   :N   Nz.webmrecordr   r9  z'Auto-recording browser session %s to %sz"Could not start auto-recording: %sr   zAuto-recording setup failed: %s)r   r	   r=   r>   r?   r@   rA   mkdir_cleanup_old_recordingsr   strftimer  r#   addrD   rp   rE   rC   )r   rG   rH   record_enabledr>   rI   rJ   recordings_dirr   	timestamprecording_pathr  rL   s   &            r   r  r  [  sg   %%;%'!M1k""annQ'--2 # WWY3778I5QN$';;TD9b1MM/2	'HYKqe*TT%gx'3~CV9WX::i  ##G,KKA7[LL=vzz'?RS) #""*  ;6::;s=   AF E9-1F !B/F %F 9F
		F F9F44F9c                $    V ^8  d   QhR\         /# r   r]   )r$   s   "r   r%   r%   ~  s     - -3 -r   c                   V \         9  d   R#  \        V RR.4      pVP                  R4      '       d9   VP                  R/ 4      P                  RR4      p\        P	                  RW4       \         P                  T 4       R#   \
         d!   p\        P                  R	Y4        Rp?L=Rp?ii ; i  \         P                  T 4       i ; i)
z1Stop recording if one is active for this session.Nr"  stopr9  rM  r*   rR   z*Saved browser recording for session %s: %sz#Could not stop recording for %s: %s)r   r  rA   rD   rp   rC   rE   discard)r   r  r*   rL   s   &   r   _maybe_stop_recordingr/  ~  s    ))-%gx&B::i  ::fb)--fb9DKKDgT 	##G,  H:GGGH 	##G,s*   AB B.B)$B1 )B..B1 1Cc                F    V ^8  d   QhR\         \        ,          R\        /# r   rO   )r$   s   "r   r%   r%     s     7 7 7 7r   c                h   \        4       '       d   ^ RIHp V! V 4      # T ;'       g    RpRp\        VRV.4      pVP	                  R4      '       d|   VP	                  R/ 4      pVP	                  RR4      p \        V\        4      '       d   \        P                  ! V4      pMTp\        P                  ! RR	R
VR\        V4      /RR7      # \        P                  ! RRRVP	                  RR4      /RR7      #   \        P                   d$    \        P                  ! RR	R
. R^ RR/RR7      u # i ; i)z
Get all images on the current page.

Args:
    task_id: Task identifier for session isolation
    
Returns:
    JSON string with list of images (src and alt)
)camofox_get_imagesr   a  JSON.stringify(
        [...document.images].map(img => ({
            src: img.src,
            alt: img.alt || '',
            width: img.naturalWidth,
            height: img.naturalHeight
        })).filter(img => img.src && !img.src.startsWith('data:'))
    )r  r9  rM  r  z[]Timagesrf   Fr  ro   zCould not parse image datar   zFailed to get images)r   r  r2  r  rA   r   r#   rn   rn  r  r   ro  )r   r2  r  js_coder  rM  r  r3  s   &       r   r   r     s?    <!'**,,9	G ""3VgYGFzz)zz&"%XXh-
	#*c**J/#::4&V "	# # zzuVZZ)?@
  	 ## 	#::4"7	
 "# #	#s   7AC9 95D10D1c                ^    V ^8  d   QhR\         R\        R\        \         ,          R\         /# )r    r   r   r   r!   )r#   r   r   )r$   s   "r   r%   r%     s3     [: [:S [:D [:8C= [:\_ [:r   c                >   \        4       '       d   ^ RIHp V! WV4      # ^ RIp^ RIp^ RIHp T;'       g    Rp^ RIHp V! RR4      p	V	RVP                  4       P                   R	2,          p
 V	P                  R
R
R7       \        V	^R7       . pV'       d   VP                  R4       VP                  R4       VP                  \        V
4      4       \        VRV4      pVP!                  R4      '       gY   VP!                  RR4      p\#        4       pVf   RMRVP%                  4        R2p\&        P(                  ! RRRRV RV 2/RR7      # VP!                  R/ 4      P!                  R4      pV'       d	   V! V4      p
V
P+                  4       '       gH   \#        4       pVf   RMRVP%                  4        R2p\&        P(                  ! RRRRV
 RV R2/RR7      # T
P-                  4       pVP/                  V4      P1                  R4      pR V 2pR!V  R"2p\3        4       p\4        P7                  R#\9        V4      4       R$p ^ R%IHp V! 4       pVP!                  R&/ 4      P!                  R'/ 4      P!                  R(4      pVe   \?        V4      pR)R'R*R+R,R-R.R/R/T/R.R0R0R1T//./.R2R3R4R5R(T/pT'       d   TTR6&   \C        RB/ TB pTPD                  ^ ,          PF                  PH                  ;'       g    R7PK                  4       p^ R8I&H'p T! T4      pRR
R9T;'       g    R:R;\        T
4      /pT'       d;   TP!                  R/ 4      P!                  R<4      '       d   TR,          R<,          TR<&   \&        P(                  ! TRR7      #   \@         d     ELi ; i  \@         dv   p\4        PQ                  R=TR
R>7       RRRR?\        T4       2/p T
P+                  4       '       d   \        T
4      T R;&   R@T RA&   \&        P(                  ! T RR7      u Rp?# Rp?ii ; i)Ca  
Take a screenshot of the current page and analyze it with vision AI.

This tool captures what's visually displayed in the browser and sends it
to Gemini for analysis. Useful for understanding visual content that the
text-based snapshot may not capture (CAPTCHAs, verification challenges,
images, complex layouts, etc.).

The screenshot is saved persistently and its file path is returned alongside
the analysis, so it can be shared with users via MEDIA:<path> in the response.

Args:
    question: What you want to know about the page visually
    annotate: If True, overlay numbered [N] labels on interactive elements
    task_id: Task identifier for session isolation
    
Returns:
    JSON string with vision analysis results and screenshot_path
)camofox_visionNr   r   )get_hermes_dirzcache/screenshotsbrowser_screenshotsbrowser_screenshot_z.pngTr  r  z
--annotatez--fullrO  r9  r   zUnknown errorr   cloud ()FzFailed to take screenshot (z mode): r  rM  r*   z#Screenshot file was not created at z (z mode). This may indicate a socket path issue (macOS /var/folders/), a missing Chromium install ('agent-browser install'), or a stale daemon process.asciizdata:image/png;base64,zCYou are analyzing a screenshot of a web browser.

User's question: a"  

Provide a detailed and helpful answer based on what you see in the screenshot. If there are interactive elements, describe them. If there are verification challenges or CAPTCHAs, describe what type they are and what action might be needed. Focus on answering the user's specific question.z/browser_vision: analysing screenshot (%d bytes)g      ^@)load_config	auxiliaryvisionrb   r  r  r  r  r  r   r   	image_urlr   r  i  r  r  r  rR   r  analysisz$Vision analysis returned no content.screenshot_pathannotationszbrowser_vision failed: %srV  zError during vision analysis: z\Screenshot was captured but vision analysis failed. You can still share it via MEDIA:<path>.noter   ))r   r  r7  base64r  pathlibr   hermes_constantsr8  r	  r
  r#  _cleanup_old_screenshotsr/   r#   r  rA   r   provider_namern   r  r=   
read_bytes	b64encodedecoderV   rD   rE   r   hermes_cli.configr>  floatrC   r   r  r  r  rU   r  r  ro   )!r   r   r   r7  rF  uuid_modr   r  r8  screenshots_dirrC  screenshot_argsr  error_detail_cpr=  actual_screenshot_path
image_dataimage_base64data_urlvision_promptvision_modelvision_timeoutr>  _cfg_vtr  ru   rB  r  response_datarL   
error_infos!   &&&                              r   r   r     sY   ( 8h'::,,9 0$%8:OPO%*=hnn>N>R>R=SSW(XXOx:dT: 	!C ""<0x(s?34%
 zz)$$!::g?L%'C!k79J9J9L8MQ/OD::56tfH\NS "# #
 "(FB!7!;!;F!C!"#9:O %%''%'C!k79J9J9L8MQ/OD::59/9J"TF S1 2 "# # %//1
''
3::7C+L>:  (z *?@ 	 )*F_	& 	5=D((;+//"=AA)LC!&s
 HF?kE8;LM  $3~
 #/K *k*$$Q'//77==2DDF6(2tJJ$Js?3
 

62.22=AA+1&>-+HM-(zz-e<<E  		H  
:
 	2AE3QRUVWRXQY1Z[
!!##,/,@J()!Jvzz*599
:sw   /C!N (N :N AN A&N AN
 $N 8=N 6*N !=N *N 
NN NN P'A*PPPc                8   \        V 4      p\        P                  ! 4       pV\        P                  VR4      ,
          R8  d   R# V\        V&    \        P                  ! 4       VR,          ,
          pV P	                  R4       F5  p VP                  4       P                  V8  d   VP                  4        K5  K7  	  R#   \         d"   p\        P                  RYV4        Rp?Kb  Rp?ii ; i  \         d"   p\        P                  RT4        Rp?R# Rp?ii ; i)zRemove browser screenshots older than max_age_hours to prevent disk bloat.

Throttled to run at most once per hour per directory to avoid repeated
scans on screenshot-heavy workflows.
g          Nzbrowser_screenshot_*.pngz%Failed to clean old screenshot %s: %sz+Screenshot cleanup error (non-critical): %s)r#   r   _last_screenshot_cleanup_by_dirrA   globstatst_mtimeri  rC   rD   rE   )rQ  r  r   nowcutoffrI   rL   s   &&     r   rI  rI  e  s     o
C
))+C
,00c::TA+.#C(	G 45 %%&@AAL668$$v-HHJ . B  LDaKKL GBAFFGsB   7C- /B>6C- >C*	C%C- %C**C- -D8DDc                   ^ RI p \        4       pVR,          pVP                  4       '       g   R# VP                   ! 4       V R,          ,
          pVP                  R4       F5  p VP	                  4       P
                  V8  d   VP                  4        K5  K7  	  R#   \         d"   p\        P                  RYV4        Rp?Kb  Rp?ii ; i  \         d"   p\        P                  RT4        Rp?R# Rp?ii ; i)zIRemove browser recordings older than max_age_hours to prevent disk bloat.Nr  ra  zsession_*.webmz$Failed to clean old recording %s: %sz*Recording cleanup error (non-critical): %s)
r   r	   r=   rc  rd  re  ri  rC   rD   rE   )r  r   rG   r(  rg  rI   rL   s   &      r   r$  r$  }  s    F%'$';;$$&& 45$$%56AK668$$v-HHJ . 7  KCQJJK FA1EEFsF   )C 3C %/BC C'C=C CC C7C22C7c                >    V ^8  d   QhR\         \        ,          RR/# )r    r   r!   NrO   )r$   s   "r   r%   r%     s&     CI CIXc] CId CIr   c                   V f   Rp \         P                  RV 4       \         P                  R\        \        P	                  4       4      4       \
        ;_uu_ 4        \        P                  V 4      pRRR4       X'       Ed   VP                  RR4      p\         P                  RW4       \        V 4        \        V R. ^
R	7       \         P                  R
V 4       \
        ;_uu_ 4        \        P                  V R4       \        P                  V R4       RRR4       V'       d!   \        4       pVe    VP                  V4       VP                  RR4      pV'       Ed   \        P                   P#                  \%        4       RV 24      p\        P                   P'                  V4      '       d   \        P                   P#                  We R24      p\        P                   P)                  V4      '       dm    \+        \-        V4      P/                  4       P1                  4       4      p\        P2                  ! V\4        P6                  4       \         P                  RW4       \@        PB                  ! VRR7       \         P                  RV 4       R# \         P                  RV 4       R#   + '       g   i     ELD; i  \         d"   p\         P                  RY4        Rp?ELRp?ii ; i  + '       g   i     EL; i  \         d"   p\         P                  RT4        Rp?ELRp?ii ; i  \8        \:        \<        \>        3 d    \         P                  RT4        ELi ; i)z
Clean up browser session for a task.

Called automatically when a task completes or when inactivity timeout is reached.
Closes both the agent-browser session and the Browserbase session.

Args:
    task_id: Task identifier to clean up
Nr   z&cleanup_browser called for task_id: %szActive sessions: %sr  unknownz+Found session for task %s: bb_session_id=%src  ra   z1agent-browser close command completed for task %sz*agent-browser close failed for task %s: %sz)Could not close cloud browser session: %sr  rR   r<  z.pidzKilled daemon pid %s for %sz?Could not kill daemon pid for %s (already dead or inaccessible)T)ignore_errorsz$Removed task %s from active sessionsz'No active session found for task_id: %s)"rD   rE   r"   r   keysr   rA   r/  r  rC   ro   popr   r   close_sessionr)   r*   r.   r   r=   isfiler8   r   	read_textrU   rf  signalSIGTERMProcessLookupErrorr  PermissionErrorr0   r  rmtree)	r   r  r  rL   r  r  
socket_dirpid_file
daemon_pids	   &        r   r   r     sv    
LL97C
LL&-=-B-B-D(EF 
'++G4 
 |$(()DBG[ 	g&	U '2rBLLLgV
 ]  $/"&&w5 
 *,H#S**=9
 $'';<&9&;~l^=\]Jww~~j))77<<
nD4IJ77>>(++v%(h)A)A)C)I)I)K%L

FNN;%BJ] j=;WE>Hc 
  	UNNGTT	U ]] ! SNN#NPQRRS /
OWU v%fhtuvs[   J-7%K *-K06L :A+L3 -J>	K-K((K-0L	L0L++L031M('M(c                    V ^8  d   QhRR/# )r    r!   Nr   )r$   s   "r   r%   r%     s     	! 	!d 	!r   c                     \         ;_uu_ 4        \        \        P                  4       4      p RRR4       X  F  p\	        V4       K  	  R#   + '       g   i     L&; i)zH
Clean up all active browser sessions.

Useful for cleanup on shutdown.
N)r   r"   r   rm  r   )task_idsr   s     r   r   r     s<     
(--/0 
   
s   AA	c                h    V ^8  d   QhR\         \        \         \        \        3,          3,          /# r   )r   r#   )r$   s   "r   r%   r%     s%     ' 'T#tCH~*=%> 'r   c                     \         ;_uu_ 4        \        P                  4       uuRRR4       #   + '       g   i     R# ; i)z
Get information about active browser sessions.

Returns:
    Dict mapping task_id to session info (session_name, bb_session_id, cdp_url)
N)r   r   copyr   r   r   get_active_browser_sessionsr    s!     
$$& 
s   .?	c                $    V ^8  d   QhR\         /# r   r   )r$   s   "r   r%   r%     s      D r   c                     \        4       '       d   R#  \        4        \        4       p T e   T P	                  4       '       g   R# R#   \         d     R# i ; i)aQ  
Check if browser tool requirements are met.

In **local mode** (no cloud provider configured): only the
``agent-browser`` CLI must be findable.

In **cloud mode** (Browserbase, Browser Use, or Firecrawl): the CLI
*and* the provider's required credentials must be present.

Returns:
    True if all requirements are met, False otherwise
TF)r   r*  r!  r   r   )r  s    r   check_browser_requirementsr    sS     
 #$HH$:$:$<$<  s   
A AA__main__u   🌐 Browser Tool Moduler   r;  r<  z	   Mode: u   ✅ All requirements metu   ❌ Missing requirements:z    - agent-browser CLI not foundzO     Install: npm install -g agent-browser && agent-browser install --with-depsz   - z credentials not configuredzL   Tip: set browser.cloud_provider to 'local' to use free local mode insteadu   
📋 Available Browser Tools:u     🔹 z: :N<   NrJ  u   
💡 Usage:zC  from tools.browser_tool import browser_navigate, browser_snapshotzE  result = browser_navigate('https://example.com', task_id='my_task')z0  snapshot = browser_snapshot(task_id='my_task'))registryr;   c                 Z    \        V P                  R R4      VP                  R4      R7      # )r   rR   r   )r   r   )r   rA   r7  kws   &,r   r   r   F  s$    /DHHUB4GQSQWQWXaQbcr   u   🌐)r   toolsetschemahandlercheck_fnemojic                 z    \        V P                  R R4      VP                  R4      VP                  R4      R7      # )r   Fr   r  )r   r   r  )r   rA   r  s   &,r   r   r   N  s0    /XXfe$bffY.?266R]K^ `r   u   📸c                 Z    \        V P                  R R4      VP                  R4      R7      # )r   rR   r   )r   r   )r   rA   r  s   &,r   r   r   W       }%1DbffU^N_`r   u   👆c                 |    \        V P                  R R4      V P                  RR4      VP                  R4      R7      # )r   rR   r   r   )r   r   r   )r   rA   r  s   &,r   r   r   _  s2    |0C$((SY[]J^hjhnhnoxhyzr   u   ⌨️c                 Z    \        V P                  R R4      VP                  R4      R7      # )r   r   r   )r   r   )r   rA   r  s   &,r   r   r   g  s#    ~f8U_a_e_efo_pqr   u   📜c                 8    \        VP                  R 4      R7      # r   r   )r   rA   r  s   &,r   r   r   o  s    |BFF94EFr   u   ◀️c                 Z    \        V P                  R R4      VP                  R4      R7      # )r   rR   r   )r   r   )r   rA   r  s   &,r   r   r   w  r  r   c                 8    \        VP                  R 4      R7      # r  )r   rA   r  s   &,r   r   r     s    }RVVI5FGr   u   🚪c                 8    \        VP                  R 4      R7      # r  )r   rA   r  s   &,r   r   r     s    1"&&:KLr   u   🖼️c                 |    \        V P                  R R4      V P                  RR4      VP                  R4      R7      # )r   rR   r   Fr   )r   r   r   )r   rA   r  s   &,r   r   r     sL    ~txx
B7OZ^ZbZbcmotZu  @B  @F  @F  GP  @Q   Rr   u   👁️c                 z    \        V P                  R R4      V P                  R4      VP                  R4      R7      # )r   Fr   r   )r   r   r   )r   rA   r  s   &,r   r   r     sE    TXXgu5MZ^ZbZbcoZpz|  {A  {A  BK  {L   Mr   u   🖥️c                   V ^8  d   Qh/ ^ \         9   d   \        \        \        3,          ;R&   ^\         9   d   \        \        \
        3,          ;R&   ^\         9   d   \        \        ,          ;R&   ^\         9   d   \        \        ,          ;R&   ^\         9   d,   \        \        \        \        \        3,          3,          ;R&   ^\         9   d
   \        ;R&   ^\         9   d   \        \        \        3,          ;R&   # )r    rb  r   r   r   r   r   r   )
__conditional_annotations__r   r#   rO  r   r   r   r   r   set)r$   s   "r   r%   r%      s     0 0x 7 6c5j!1 6y0T DdO U0` > =!56 =a0f 2 1HTN 1g0T 1 0$sDcN*+ 0U0V !  S  W0t . -S%Z( -u0r   r   )NN)r6   )FNN)FN)   )H   z(========================================)r  __doc__atexitrn   rj  r)   r.  rr  r`  r  r   r   r   r   rl   typingr   r   r   r   rG  r   agent.auxiliary_clientr   rH  r	   tools.website_policyr
   rC   tools.url_safetyr   r  tools.browser_providers.baser   #tools.browser_providers.browserbaser   #tools.browser_providers.browser_user   !tools.browser_providers.firecrawlr   tools.tool_backend_helpersr   r  r   r   ImportError	getLoggerr  rD   rZ  r5   rb  rF   DEFAULT_SESSION_TIMEOUTr  rM   rV   rZ   ry   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r8   r}   rA   r   r   r   r   Lockr   r   registerr   r   r   r   r   BROWSER_TOOL_SCHEMASr  r  r  r*  r4  r  r  r  r   r   r   r   r   r   r   r   r   r  r  r  r/  r   r   rI  r$  r   r   r  r  printrT  rJ  r=  r!  r   r  tools.registryr  _BROWSER_SCHEMA_MAPr%   )sr  s   0@r   <module>r     s	  0d    	 	    
     , ,  + ,,9%< > C B ? G
%I 
		8	$
C . 57  6      $ #*C
H
.bH &%"'   :>  =  $ -1  1'"T7
/
)
?&2!& /1  05     &)8TV[)\%] " ,.  -    $B / 0T8,p (6 , - 	"  FHH!#Y 	
 	"  wHI!  $Vu 

  	  kHH!#b 	
 	  EHH!#Z H!#D	 
& 	   xHHT6N!#8 

  	}H"
 	  kHH!#_ 	
 	  WH"
 	$  MH"
 	   sHH!#~ Iu!  $T
 
( 	!  jHIu!#U
 H!  $]
 
S\ F
0h7t*I3X51pI*vr3l F#L#L<<4:7t%(PBD ;F-7t[:|G0F.CIL	!'F z 

$%	(O

Ck71B1B1D0EQ'GD	IdV
 "##())*	e! ?3#4#4#6#6E#++-..IJK`a	
+,&v'r&*?*D)ESIJ ' 
/	
OP	
QR	
<= $-AB-Ay!|-AB    	12c'
 	  	12`'
 	  	/`'
 	  	~.z'
 	  	/0q'
 	  	~.F'
 	  	/`'
 	  	/G'
 	  	34L'
 	  	/0 R'
 	  	01 M'
WB  ,+,
  %$L%  %$%`> ! 	e45cd	e, CsN   W #W" W3 8X X"
WW"
W0/W03
X XXX