|
| 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 | + |
| 13 | +from common.utils.logger import maxkb_logger |
| 14 | +from tools.models import Tool |
| 15 | +from trigger.handler.base_task import BaseTriggerTask |
| 16 | + |
| 17 | +TOOL_TASKS = [BaseToolTask(), WorkflowToolTask()] |
| 18 | + |
| 19 | + |
| 20 | +def execute(tool, trigger_task, **kwargs): |
| 21 | + for TOOL_TASK in TOOL_TASKS: |
| 22 | + if TOOL_TASK.support(tool, trigger_task, **kwargs): |
| 23 | + TOOL_TASK.execute(tool, trigger_task, **kwargs) |
| 24 | + |
| 25 | + |
| 26 | +class ToolTask(BaseTriggerTask): |
| 27 | + def support(self, trigger_task, **kwargs): |
| 28 | + return trigger_task.get('source_type') == 'TOOL' |
| 29 | + |
| 30 | + def execute(self, trigger_task, **kwargs): |
| 31 | + tool_id = trigger_task.get('source_id') |
| 32 | + tool = QuerySet(Tool).filter(id=tool_id, is_active=True).first() |
| 33 | + if not tool: |
| 34 | + maxkb_logger.info(f"Tool with id {tool_id} not found or inactive.") |
| 35 | + return |
| 36 | + execute(tool, trigger_task, **kwargs) |
0 commit comments