Skip to content

Commit 4f1cca1

Browse files
committed
fix: After disabling the shared workflow tool, the intelligent agent that applies it can still call it
1 parent 4445a75 commit 4f1cca1

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

apps/application/flow/step_node/tool_workflow_lib_node/impl/base_tool_workflow_lib_node.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
from application.flow.step_node.tool_workflow_lib_node.i_tool_workflow_lib_node import IToolWorkflowLibNode
2020
from application.models import ChatRecord
2121
from application.serializers.common import ToolExecute
22+
from common.database_model_manage.database_model_manage import DatabaseModelManage
2223
from common.exception.app_exception import ChatException
2324
from common.handle.impl.response.loop_to_response import LoopToResponse
24-
from tools.models import ToolWorkflowVersion
25+
from tools.models import ToolWorkflowVersion, Tool
2526

2627

2728
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):
131132
return node.context.get('is_interrupt_exec', False)
132133

133134

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+
134147
class BaseToolWorkflowLibNodeNode(IToolWorkflowLibNode):
135148
def get_parameters(self, input_field_list):
136149
result = {}
@@ -176,6 +189,8 @@ def execute(self, tool_lib_id, input_field_list, **kwargs) -> NodeResult:
176189
'-create_time')[0:1].first()
177190
if tool_workflow_version is None:
178191
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)
179194
parameters = self.get_parameters(input_field_list)
180195
tool_record_id = (self.node_params.get('child_node') or {}).get('chat_record_id') or str(uuid.uuid7())
181196
took_execute = ToolExecute(tool_lib_id, tool_record_id,

apps/application/flow/tools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,8 @@ def inner(**kwargs):
10631063

10641064

10651065
def get_tools(source_type, source_id, tool_workflow_ids, workspace_id):
1066-
tools = QuerySet(Tool).filter(id__in=tool_workflow_ids, tool_type=ToolType.WORKFLOW, workspace_id=workspace_id)
1066+
tools = QuerySet(Tool).filter(id__in=tool_workflow_ids, is_active=True, tool_type=ToolType.WORKFLOW,
1067+
workspace_id=workspace_id)
10671068
latest_subquery = ToolWorkflowVersion.objects.filter(
10681069
tool_id=OuterRef('tool_id')
10691070
).order_by('-create_time')

0 commit comments

Comments
 (0)