|
19 | 19 | from application.flow.step_node.tool_workflow_lib_node.i_tool_workflow_lib_node import IToolWorkflowLibNode |
20 | 20 | from application.models import ChatRecord |
21 | 21 | from application.serializers.common import ToolExecute |
| 22 | +from common.database_model_manage.database_model_manage import DatabaseModelManage |
22 | 23 | from common.exception.app_exception import ChatException |
23 | 24 | from common.handle.impl.response.loop_to_response import LoopToResponse |
24 | | -from tools.models import ToolWorkflowVersion |
| 25 | +from tools.models import ToolWorkflowVersion, Tool |
25 | 26 |
|
26 | 27 |
|
27 | 28 | def _write_context(node_variable: Dict, workflow_variable: Dict, node: INode, workflow, answer: str, |
@@ -131,6 +132,18 @@ def _is_interrupt_exec(node, node_variable: Dict, workflow_variable: Dict): |
131 | 132 | return node.context.get('is_interrupt_exec', False) |
132 | 133 |
|
133 | 134 |
|
| 135 | +def valid_function(tool_lib, workspace_id): |
| 136 | + if tool_lib is None: |
| 137 | + raise Exception(_('Tool does not exist')) |
| 138 | + get_authorized_tool = DatabaseModelManage.get_model("get_authorized_tool") |
| 139 | + if tool_lib and tool_lib.workspace_id != workspace_id and get_authorized_tool is not None: |
| 140 | + tool_lib = get_authorized_tool(QuerySet(Tool).filter(id=tool_lib.id), workspace_id).first() |
| 141 | + if tool_lib is None: |
| 142 | + raise Exception(_("Tool does not exist")) |
| 143 | + if not tool_lib.is_active: |
| 144 | + raise Exception(_("Tool is not active")) |
| 145 | + |
| 146 | + |
134 | 147 | class BaseToolWorkflowLibNodeNode(IToolWorkflowLibNode): |
135 | 148 | def get_parameters(self, input_field_list): |
136 | 149 | result = {} |
@@ -176,6 +189,8 @@ def execute(self, tool_lib_id, input_field_list, **kwargs) -> NodeResult: |
176 | 189 | '-create_time')[0:1].first() |
177 | 190 | if tool_workflow_version is None: |
178 | 191 | raise ChatException(500, _("The tool has not been published. Please use it after publishing.")) |
| 192 | + tool_lib = QuerySet(Tool).filter(id=tool_lib_id).first() |
| 193 | + valid_function(tool_lib, workspace_id) |
179 | 194 | parameters = self.get_parameters(input_field_list) |
180 | 195 | tool_record_id = (self.node_params.get('child_node') or {}).get('chat_record_id') or str(uuid.uuid7()) |
181 | 196 | took_execute = ToolExecute(tool_lib_id, tool_record_id, |
|
0 commit comments