__init__.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # coding=utf-8
  2. """
  3. @project: MaxKB
  4. @Author:虎虎
  5. @file: __init__.py.py
  6. @date:2026/3/27 18:45
  7. @desc:
  8. """
  9. from .base_tool_task import ToolTask as BaseToolTask
  10. from .workflow_tool_task import ToolTask as WorkflowToolTask
  11. from django.db.models import QuerySet
  12. from common.utils.logger import maxkb_logger
  13. from tools.models import Tool
  14. from trigger.handler.base_task import BaseTriggerTask
  15. TOOL_TASKS = [BaseToolTask(), WorkflowToolTask()]
  16. def execute(tool, trigger_task, **kwargs):
  17. for TOOL_TASK in TOOL_TASKS:
  18. if TOOL_TASK.support(tool, trigger_task, **kwargs):
  19. TOOL_TASK.execute(tool, trigger_task, **kwargs)
  20. class ToolTask(BaseTriggerTask):
  21. def support(self, trigger_task, **kwargs):
  22. return trigger_task.get('source_type') == 'TOOL'
  23. def execute(self, trigger_task, **kwargs):
  24. tool_id = trigger_task.get('source_id')
  25. tool = QuerySet(Tool).filter(id=tool_id, is_active=True).first()
  26. if not tool:
  27. maxkb_logger.info(f"Tool with id {tool_id} not found or inactive.")
  28. return
  29. execute(tool, trigger_task, **kwargs)