
    Ng                    &   d Z ddlmZ ddlmZmZmZmZmZm	Z	 ddl
mZmZ ddlmZmZ ddlmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlm Z  erddl!m"Z# ddl$m"Z% n	 ddl!m"Z# ddl$m"Z% n# e&$ r Y nw xY w G d de          Z'dS )zPlaywright web browser toolkit.    )annotations)TYPE_CHECKINGAnyListOptionalTypecast)BaseToolBaseToolkit)
ConfigDictmodel_validator)BaseBrowserToollazy_import_playwright_browsers)	ClickTool)CurrentWebPageTool)ExtractHyperlinksTool)ExtractTextTool)GetElementsTool)NavigateTool)NavigateBackTool)Browserc                      e Zd ZU dZdZded<   dZded<    edd	          Z e	d
          e
dd                        ZddZe
	 	 ddd            ZdS )PlayWrightBrowserToolkita<  Toolkit for PlayWright browser tools.

    **Security Note**: This toolkit provides code to control a web-browser.

        Careful if exposing this toolkit to end-users. The tools in the toolkit
        are capable of navigating to arbitrary webpages, clicking on arbitrary
        elements, and extracting arbitrary text and hyperlinks from webpages.

        Specifically, by default this toolkit allows navigating to:

        - Any URL (including any internal network URLs)
        - And local files

        If exposing to end-users, consider limiting network access to the
        server that hosts the agent; in addition, consider it is advised
        to create a custom NavigationTool wht an args_schema that limits the URLs
        that can be navigated to (e.g., only allow navigating to URLs that
        start with a particular prefix).

        Remember to scope permissions to the minimal permissions necessary for
        the application. If the default tool selection is not appropriate for
        the application, consider creating a custom toolkit with the appropriate
        tools.

        See https://python.langchain.com/docs/security for more information.

    Parameters:
        sync_browser: Optional. The sync browser. Default is None.
        async_browser: Optional. The async browser. Default is None.
    NzOptional['SyncBrowser']sync_browserzOptional['AsyncBrowser']async_browserTforbid)arbitrary_types_allowedextrabefore)modevaluesdictreturnr   c                    t                       |                    d          $|                    d          t          d          |S )z#Check that the arguments are valid.r   Nr   z7Either async_browser or sync_browser must be specified.)r   get
ValueError)clsr!   s     q/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/agent_toolkits/playwright/toolkit.py%validate_imports_and_browser_providedz>PlayWrightBrowserToolkit.validate_imports_and_browser_providedL   sG     	()))::o&&.6::n3M3M3UVWWW    List[BaseTool]c                     t           t          t          t          t          t
          t          g} fd|D             }t          t          t                   |          S )zGet the tools in the toolkit.c                R    g | ]#}|                     j        j                   $S )r   r   )from_browserr   r   ).0tool_clsselfs     r(   
<listcomp>z6PlayWrightBrowserToolkit.get_tools.<locals>.<listcomp>a   sK     
 
 
  !!!.d>P "  
 
 
r*   )
r   r   r   r   r   r   r   r	   r   r
   )r2   tool_classestoolss   `  r(   	get_toolsz"PlayWrightBrowserToolkit.get_toolsU   sa     !5

 
 
 
 )	
 
 
 DNE***r*   Optional[SyncBrowser]Optional[AsyncBrowser]c                8    t                        | ||          S )zInstantiate the toolkit.

        Args:
            sync_browser: Optional. The sync browser. Default is None.
            async_browser: Optional. The async browser. Default is None.

        Returns:
            The toolkit.
        r.   )r   )r'   r   r   s      r(   r/   z%PlayWrightBrowserToolkit.from_browseri   s%      	()))sMJJJJr*   )r!   r"   r#   r   )r#   r+   )NN)r   r7   r   r8   r#   r   )__name__
__module____qualname____doc__r   __annotations__r   r   model_configr   classmethodr)   r6   r/    r*   r(   r   r   $   s          > -1L0000.2M2222: $  L
 _(###   [ $#+ + + +(  /304K K K K [K K Kr*   r   N)(r=   
__future__r   typingr   r   r   r   r   r	   langchain_core.toolsr
   r   pydanticr   r   )langchain_community.tools.playwright.baser   r   *langchain_community.tools.playwright.clickr   1langchain_community.tools.playwright.current_pager   7langchain_community.tools.playwright.extract_hyperlinksr   1langchain_community.tools.playwright.extract_textr   1langchain_community.tools.playwright.get_elementsr   -langchain_community.tools.playwright.navigater   2langchain_community.tools.playwright.navigate_backr   playwright.async_apir   AsyncBrowserplaywright.sync_apiSyncBrowserImportErrorr   rA   r*   r(   <module>rS      s   % % " " " " " " A A A A A A A A A A A A A A A A 6 6 6 6 6 6 6 6 0 0 0 0 0 0 0 0        A @ @ @ @ @ P P P P P P      N M M M M M M M M M M M F F F F F F O O O O O O 	<<<<<<:::::::@@@@@@>>>>>>>   VK VK VK VK VK{ VK VK VK VK VKs   +A8 8B ?B 