
    ihz                         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 j"                  e      Z G d de      Zdefd	Zdefd
Z G d de      Zy)    N)AnyListOptionalTypeUnion)CallbackManagerForToolRun)BaseTool)	BaseModelFieldmodel_validatorc                   t    e Zd ZU dZ edd      Zeeee   f   e	d<   	  e
d      eded	efd
              Zy)
ShellInputz!Commands for the Bash Shell tool..z<List of shell commands to run. Deserialized using json.loads)descriptioncommandsbefore)modevaluesreturnc                 ~    |j                  d      }t        |t              s|g|d<   t        j                  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   s      b/var/www/html/dev/engine/venv/lib/python3.12/site-packages/langchain_community/tools/shell/tool.py_validate_commandszShellInput._validate_commands   s>    
 ::j)(D)"*F:P	
     N)__name__
__module____qualname____doc__r   r   r   strr   __annotations__r   classmethoddictr   r    r   r   r   r      s[    +&+R'HeCcN#  )(#
 
 
  $
r   r   r   c                  R    	 ddl m}   | d      S # t        $ r t        d      w xY w)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)return_err_output)$langchain_experimental.llm_bash.bashr*   ImportErrorr)   s    r   _get_default_bash_processr.   '   s:    
D ..  
9
 	

s    &c                  :    t        j                         } | dk(  ry| S )zGet platform.DarwinMacOS)platformsystem)r3   s    r   _get_platformr4   4   s    __FMr   c                       e Zd ZU dZ ee      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Zy)	ShellToolzTool to run shell commands.)default_factoryprocessterminalnamezRun shell commands on this z	 machine.r   args_schemaFask_human_inputNr   run_managerr   c                 h   t        d|        	 | j                  rOt        d      j                         }|dk(  r| j                  j                  |      S t        j                  d       y| j                  j                  |      S # t        $ r"}t        j                  d|        Y d}~yd}~ww xY 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: )
printr<   inputlowerr8   runloggerinfo	Exceptionerror)selfr   r=   
user_inputes        r   _runzShellTool._runQ   s     	%hZ01	##"#LMSSU
$<<++H55KK PQ||''11 	LL;A3?@	s$   AB B +B 	B1B,,B1)N)r   r    r!   r"   r   r.   r8   r   r$   r:   r#   r4   r   r   r;   r   r
   r<   boolr   r   r   r   rK   r'   r   r   r6   r6   <   s    %)BCGSC'D#4]_4EYOKO#-Ki-%!OT! <@T#Y' 78 
	r   r6   )loggingr2   r   typingr   r   r   r   r   langchain_core.callbacksr   langchain_core.toolsr	   pydanticr
   r   r   	getLoggerr   rD   r   r.   r#   r4   r6   r'   r   r   <module>rS      sf       3 3 * 6 6			8	$ 0
/3 
/s + +r   