Exemple #1
0
    def __process_command(self, message: State) -> Action:
        if not message.is_already_processed():
            message.previous_execution = self.server_status_datasource.get_last_message(message.user_name)
            actions = self.__process_command_ai(message)
            message.mark_as_processed()
            logger.info(f"after setting info: {message.is_already_processed()}")
            self.server_status_datasource.store_info(message)
            action = self.server_pending_actions_datasource.store_pending_actions(
                message.command_id,
                actions,
                message.user_name)
        else:
            logger.info(f"we have pending action")
            action = self.server_pending_actions_datasource.get_next_action(message.command_id, message.user_name)

        if action is None:
            action = Action(
                suggested_command=message.command,
                origin_command=message.command,
                execute=False
            )

        action.origin_command = message.command
        if message.is_post_process():
            message.action_post_suggested = action
        else:
            message.action_suggested = action
        self.server_status_datasource.store_info(message)
        action.execute = action.execute or self.server_status_datasource.is_power()

        return action
    def execute(self, state: State) -> Action:
        plugin_to_select = state.command.replace(f'{self.SELECT_DIRECTIVE}',
                                                 '').strip()
        plugin_to_select = extract_quoted_agent_name(plugin_to_select)

        agent_descriptor = self.agent_datasource.get_agent_descriptor(
            plugin_to_select)

        plugins_config = self.config_storage.read_config(None)

        if not agent_descriptor:
            return create_error_select(plugin_to_select)

        if agent_descriptor and not agent_descriptor.installed:
            logger.info(
                f'installing dependencies of plugin {agent_descriptor.name}')

            command = f'$CLAI_PATH/fileExist.sh {agent_descriptor.pkg_name} $CLAI_PATH' \
                    f'{" --user" if plugins_config.user_install else ""}'
            action_selected_to_return = Action(suggested_command=command,
                                               execute=True)
        else:
            self.select_plugin(plugin_to_select, state)
            action_selected_to_return = Action(suggested_command=":",
                                               execute=True)

        action_selected_to_return.origin_command = state.command
        return action_selected_to_return
Exemple #3
0
 def process_post_command(self, message: State) -> Action:
     message = self.complete_history(message)
     command_runner = self.command_runner_factory \
         .provide_post_command_runner(message.command, self.agent_runner)
     action = command_runner.execute_post(message)
     if not action:
         action = Action()
     action.origin_command = message.command
     return action
Exemple #4
0
 def execute_post(self, state: State) -> Action:
     action = self.agent_runner.process_post(state, self.ignore_threshold)
     if not action:
         action = Action()
     action.origin_command = state.command
     return action