o
    Zhz                     @   s   d dl Z d dlZd dlZd dlmZmZmZmZmZ d dl	m
Z
 d dlmZ d dlmZmZmZ e eZG dd deZdefd	d
ZdefddZG dd deZdS )    N)AnyListOptionalTypeUnion)CallbackManagerForToolRun)BaseTool)	BaseModelFieldmodel_validatorc                   @   sT   e Zd ZU dZedddZeeee f e	d< 	 e
ddeded	efd
dZdS )
ShellInputz!Commands for the Bash Shell tool..z<List of shell commands to run. Deserialized using json.loads)descriptioncommandsbefore)modevaluesreturnc                 C   s,   | d}t|ts|g|d< td |S )zValidate commands.r   zBThe shell tool has no safeguards by default. Use at your own risk.)get
isinstancelistwarningswarn)clsr   r    r   [/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/tools/shell/tool.py_validate_commands   s   


zShellInput._validate_commandsN)__name__
__module____qualname____doc__r
   r   r   strr   __annotations__r   classmethoddictr   r   r   r   r   r   r      s   
 r   r   c                  C   s2   zddl m}  W n ty   tdw | ddS )zGet default bash process.r   BashProcesszBashProcess has been moved to langchain experimental.To use this tool, install langchain-experimental with `pip install langchain-experimental`.T)Zreturn_err_output)Z$langchain_experimental.llm_bash.bashr%   ImportErrorr$   r   r   r   _get_default_bash_process'   s   
r'   c                  C   s   t  } | dkr
dS | S )zGet platform.DarwinMacOS)platformsystem)r+   r   r   r   _get_platform4   s   r,   c                   @   s   e Zd ZU dZeedZeed< 	 dZ	e
ed< 	 de  dZe
ed< 	 eZee ed	< 	 d
Zeed< 	 	ddee
ee
 f dee de
fddZdS )	ShellToolzTool to run shell commands.)default_factoryprocessZterminalnamezRun shell commands on this z	 machine.r   args_schemaFask_human_inputNr   run_managerr   c              
   C   s   t d|  z#| jr$td }|dkr| j|W S td W dS | j|W S  tyE } zt	d|  W Y d}~dS d}~ww )z%Run commands and return final output.zExecuting command:
 z'Proceed with command execution? (y/n): yz.Invalid input. User aborted command execution.Nz Error during command execution: )
printr2   inputlowerr/   runloggerinfo	Exceptionerror)selfr   r3   Z
user_inputer   r   r   _runQ   s   
zShellTool._run)N)r   r   r   r   r
   r'   r/   r   r!   r0   r    r,   r   r   r1   r   r	   r2   boolr   r   r   r   r?   r   r   r   r   r-   <   s(   
 r-   )loggingr*   r   typingr   r   r   r   r   Zlangchain_core.callbacksr   Zlangchain_core.toolsr   Zpydanticr	   r
   r   	getLoggerr   r9   r   r'   r    r,   r-   r   r   r   r   <module>   s    
