fix(workflow and tool): Output processing modification of tool nodes and error modification for tool tests
This commit is contained in:
@@ -3,6 +3,8 @@ from typing import Optional
|
|||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from app.core.error_codes import BizCode
|
||||||
from app.schemas.tool_schema import (
|
from app.schemas.tool_schema import (
|
||||||
ToolCreateRequest, ToolUpdateRequest, ToolExecuteRequest, ParseSchemaRequest,
|
ToolCreateRequest, ToolUpdateRequest, ToolExecuteRequest, ParseSchemaRequest,
|
||||||
CustomToolTestRequest, ToolActiveUpdate
|
CustomToolTestRequest, ToolActiveUpdate
|
||||||
@@ -250,8 +252,10 @@ async def sync_mcp_tools(
|
|||||||
try:
|
try:
|
||||||
result = await service.sync_mcp_tools(tool_id, current_user.tenant_id)
|
result = await service.sync_mcp_tools(tool_id, current_user.tenant_id)
|
||||||
if not result.get("success", False):
|
if not result.get("success", False):
|
||||||
raise HTTPException(status_code=400, detail=result.get("message", "同步失败"))
|
raise BusinessException(result.get("message", "工具列表同步失败"), BizCode.BAD_REQUEST)
|
||||||
return success(data=result, msg="MCP工具列表同步完成")
|
return success(data=result, msg="MCP工具列表同步完成")
|
||||||
|
except BusinessException:
|
||||||
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
@@ -274,8 +278,10 @@ async def test_tool_connection(
|
|||||||
# 普通连接测试
|
# 普通连接测试
|
||||||
result = await service.test_connection(tool_id, current_user.tenant_id)
|
result = await service.test_connection(tool_id, current_user.tenant_id)
|
||||||
if result["success"] is False:
|
if result["success"] is False:
|
||||||
raise HTTPException(status_code=400, detail=result["message"])
|
raise BusinessException(result["message"], BizCode.SERVICE_UNAVAILABLE)
|
||||||
return success(data=result, msg="连接测试完成")
|
return success(data=result, msg="连接测试完成")
|
||||||
|
except BusinessException:
|
||||||
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
|
|||||||
@@ -195,6 +195,6 @@ class MCPToolManager:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {
|
return {
|
||||||
"success": False,
|
"success": False,
|
||||||
"error": str(e),
|
"error": "连接失败",
|
||||||
"message": "连接失败"
|
"message": str(e)
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,6 @@ class ToolNode(BaseNode):
|
|||||||
def _output_types(self) -> dict[str, VariableType]:
|
def _output_types(self) -> dict[str, VariableType]:
|
||||||
return {
|
return {
|
||||||
"data": VariableType.STRING,
|
"data": VariableType.STRING,
|
||||||
"error_code": VariableType.STRING,
|
|
||||||
"execution_time": VariableType.NUMBER
|
"execution_time": VariableType.NUMBER
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,10 +47,7 @@ class ToolNode(BaseNode):
|
|||||||
|
|
||||||
if not tenant_id:
|
if not tenant_id:
|
||||||
logger.error(f"节点 {self.node_id} 缺少租户ID")
|
logger.error(f"节点 {self.node_id} 缺少租户ID")
|
||||||
return {
|
raise ValueError("缺少租户ID")
|
||||||
"success": False,
|
|
||||||
"data": "缺少租户ID"
|
|
||||||
}
|
|
||||||
|
|
||||||
# 渲染工具参数
|
# 渲染工具参数
|
||||||
rendered_parameters = {}
|
rendered_parameters = {}
|
||||||
@@ -83,13 +79,8 @@ class ToolNode(BaseNode):
|
|||||||
logger.info(f"节点 {self.node_id} 工具执行成功")
|
logger.info(f"节点 {self.node_id} 工具执行成功")
|
||||||
return {
|
return {
|
||||||
"data": result.data if isinstance(result.data, str) else json.dumps(result.data, ensure_ascii=False),
|
"data": result.data if isinstance(result.data, str) else json.dumps(result.data, ensure_ascii=False),
|
||||||
"error_code": "",
|
|
||||||
"execution_time": result.execution_time
|
"execution_time": result.execution_time
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
logger.error(f"节点 {self.node_id} 工具执行失败: {result.error}")
|
logger.error(f"节点 {self.node_id} 工具执行失败: {result.error}")
|
||||||
return {
|
raise ValueError(f"工具执行失败: {result.error if isinstance(result.error, str) else json.dumps(result.error, ensure_ascii=False)}")
|
||||||
"data": result.error if isinstance(result.error, str) else json.dumps(result.error, ensure_ascii=False),
|
|
||||||
"error_code": result.error_code,
|
|
||||||
"execution_time": result.execution_time
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -374,7 +374,7 @@ class AgentRunService:
|
|||||||
files: Optional[List[FileInput]]
|
files: Optional[List[FileInput]]
|
||||||
) -> None:
|
) -> None:
|
||||||
"""校验上传文件是否符合 file_upload 配置"""
|
"""校验上传文件是否符合 file_upload 配置"""
|
||||||
if not files:
|
if not files or not features_config:
|
||||||
return
|
return
|
||||||
fu = features_config.get("file_upload", {})
|
fu = features_config.get("file_upload", {})
|
||||||
if not (isinstance(fu, dict) and fu.get("enabled")):
|
if not (isinstance(fu, dict) and fu.get("enabled")):
|
||||||
|
|||||||
Reference in New Issue
Block a user