
    Fd                     d    d dl Z d dlZd dlmZmZ d dlmZ d dlmZ d dl	m
Z
  G d d          ZdS )    N)AnyCallable)AUTO_GPT_COMMAND_IDENTIFIER)logger)Commandc                       e Zd ZU dZeeef         ed<   d Zdede	fdZ
de	de	fdZd	edd
fdZdefdZddZdedede	f         fdZdede	fdZdefdZdedd
fdZd
S )CommandRegistrya   
    The CommandRegistry class is a manager for a collection of Command objects.
    It allows the registration, modification, and retrieval of Command objects,
    as well as the scanning and loading of command plugins from a specified
    directory.
    commandsc                     i | _         d S Nr
   )selfs    SC:\Users\Administrator\Downloads\Auto-GPT-master\autogpt\models\command_registry.py__init__zCommandRegistry.__init__   s        module_namereturnc                 *    t          j        |          S r   )	importlibimport_module)r   r   s     r   _import_modulezCommandRegistry._import_module   s    &{333r   modulec                 *    t          j        |          S r   )r   reload)r   r   s     r   _reload_modulezCommandRegistry._reload_module   s    '''r   cmdNc                 z    |j         | j        v rt          j        d|j          d           || j        |j         <   d S )N	Command 'z-' already registered and will be overwritten!)namer
   r   warn)r   r   s     r   registerzCommandRegistry.register   sK    8t}$$KSCHSSS   #&chr   command_namec                 N    || j         v r
| j         |= d S t          d| d          )Nr   ' not found in registry.r
   KeyError)r   r"   s     r   
unregisterzCommandRegistry.unregister$   s9    4=((l+++M|MMMNNNr   c                     | j         D ]c}| j         |         }|                     |j                  }|                     |          }t	          |d          r|                    |            ddS )z#Reloads all loaded command plugins.r!   N)r
   r   
__module__r   hasattrr!   )r   cmd_namer   r   reloaded_modules        r   reload_commandszCommandRegistry.reload_commands*   sx     	/ 	/H-)C((88F"11&99O
33 /((...	/ 	/r   r   .c                     | j         |         S r   r   )r   r   s     r   get_commandzCommandRegistry.get_command3   s    }T""r   c                 d    || j         vrt          d| d          | j         |         } |di |S )Nr   r$    r%   )r   r"   kwargscommands       r   callzCommandRegistry.call6   sK    t},,M|MMMNNN--w     r   c                     d t          | j                                                  D             }d                    |          S )zi
        Returns a string representation of all registered `Command` objects for use in a prompt
        c                 B    g | ]\  }}|d z    dt          |           S )   z. )str).0idxr   s      r   
<listcomp>z2CommandRegistry.command_prompt.<locals>.<listcomp>@   sA     
 
 
)1csQw$$#c(($$
 
 
r   
)	enumerater
   valuesjoin)r   commands_lists     r   command_promptzCommandRegistry.command_prompt<   sJ    
 
5>t}?S?S?U?U5V5V
 
 
 yy'''r   c                    t          j        |          }t          |          D ]}t          ||          }t	          |t
                    r0t          |t
                    r|                     |j                   Wt          j	        |          r?t          |t                    r*|t          k    r |            }|                     |           dS )a  
        Imports the specified Python module containing command plugins.

        This method imports the associated module and registers any functions or
        classes that are decorated with the `AUTO_GPT_COMMAND_IDENTIFIER` attribute
        as `Command` objects. The registered `Command` objects are then added to the
        `commands` dictionary of the `CommandRegistry` object.

        Args:
            module_name (str): The name of the module to import for command plugins.
        N)r   r   dirgetattrr*   r   r!   r3   inspectisclass
issubclassr   )r   r   r   	attr_nameattrcmd_instances         r   import_commandszCommandRegistry.import_commandsE   s     (55V 	, 	,I69--Dt899 	,g1? ? 	, dl++++ %%,*4T7*C*C,HLPW#tvvl+++	, 	,r   )r   N)__name__r)   __qualname____doc__dictr8   r   __annotations__r   r   r   r   r!   r'   r-   r   r/   r4   rA   rK   r1   r   r   r	   r	   
   sj          3<      4# 4# 4 4 4 4(S (S ( ( ( (&G & & & & &Os O O O O/ / / /# #c(: # # # #! !3 ! ! ! !( ( ( ( (,3 ,4 , , , , , ,r   r	   )r   rE   typingr   r   autogpt.command_decoratorr   autogpt.logsr   autogpt.models.commandr   r	   r1   r   r   <module>rU      s                         A A A A A A       * * * * * *V, V, V, V, V, V, V, V, V, V,r   