处理agent答非所问的问题
This commit is contained in:
@@ -10,6 +10,7 @@ from app.core.database import get_db
|
||||
from app.models.execution_log import ExecutionLog
|
||||
from app.models.execution import Execution
|
||||
from app.models.workflow import Workflow
|
||||
from app.models.agent import Agent
|
||||
from app.api.auth import get_current_user
|
||||
from app.models.user import User
|
||||
from app.core.exceptions import NotFoundError
|
||||
@@ -38,21 +39,34 @@ async def get_execution_logs(
|
||||
execution_id: str,
|
||||
level: Optional[str] = Query(None, description="日志级别筛选: INFO/WARN/ERROR/DEBUG"),
|
||||
node_id: Optional[str] = Query(None, description="节点ID筛选"),
|
||||
skip: int = Query(0, ge=0),
|
||||
skip: int =Query(0, ge=0),
|
||||
limit: int = Query(100, ge=1, le=1000),
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""获取执行日志列表"""
|
||||
# 验证执行记录是否存在且属于当前用户
|
||||
execution = db.query(Execution).join(Workflow, Execution.workflow_id == Workflow.id).filter(
|
||||
Execution.id == execution_id,
|
||||
Workflow.user_id == current_user.id
|
||||
).first()
|
||||
from app.models.agent import Agent
|
||||
|
||||
# 验证执行记录是否存在
|
||||
execution = db.query(Execution).filter(Execution.id == execution_id).first()
|
||||
|
||||
if not execution:
|
||||
raise NotFoundError("执行记录", execution_id)
|
||||
|
||||
# 验证权限:检查workflow或agent的所有权
|
||||
has_permission = False
|
||||
if execution.workflow_id:
|
||||
workflow = db.query(Workflow).filter(Workflow.id == execution.workflow_id).first()
|
||||
if workflow and workflow.user_id == current_user.id:
|
||||
has_permission = True
|
||||
elif execution.agent_id:
|
||||
agent = db.query(Agent).filter(Agent.id == execution.agent_id).first()
|
||||
if agent and (agent.user_id == current_user.id or agent.status in ["published", "running"]):
|
||||
has_permission = True
|
||||
|
||||
if not has_permission:
|
||||
raise NotFoundError("执行记录", execution_id)
|
||||
|
||||
# 构建查询
|
||||
query = db.query(ExecutionLog).filter(
|
||||
ExecutionLog.execution_id == execution_id
|
||||
@@ -79,15 +93,26 @@ async def get_execution_log_summary(
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""获取执行日志摘要(统计信息)"""
|
||||
# 验证执行记录是否存在且属于当前用户
|
||||
execution = db.query(Execution).join(Workflow, Execution.workflow_id == Workflow.id).filter(
|
||||
Execution.id == execution_id,
|
||||
Workflow.user_id == current_user.id
|
||||
).first()
|
||||
# 验证执行记录是否存在
|
||||
execution = db.query(Execution).filter(Execution.id == execution_id).first()
|
||||
|
||||
if not execution:
|
||||
raise NotFoundError("执行记录", execution_id)
|
||||
|
||||
# 验证权限:检查workflow或agent的所有权
|
||||
has_permission = False
|
||||
if execution.workflow_id:
|
||||
workflow = db.query(Workflow).filter(Workflow.id == execution.workflow_id).first()
|
||||
if workflow and workflow.user_id == current_user.id:
|
||||
has_permission = True
|
||||
elif execution.agent_id:
|
||||
agent = db.query(Agent).filter(Agent.id == execution.agent_id).first()
|
||||
if agent and (agent.user_id == current_user.id or agent.status in ["published", "running"]):
|
||||
has_permission = True
|
||||
|
||||
if not has_permission:
|
||||
raise NotFoundError("执行记录", execution_id)
|
||||
|
||||
# 统计各级别日志数量
|
||||
from sqlalchemy import func
|
||||
level_stats = db.query(
|
||||
@@ -148,15 +173,26 @@ async def get_execution_performance(
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""获取执行性能分析数据"""
|
||||
# 验证执行记录是否存在且属于当前用户
|
||||
execution = db.query(Execution).join(Workflow, Execution.workflow_id == Workflow.id).filter(
|
||||
Execution.id == execution_id,
|
||||
Workflow.user_id == current_user.id
|
||||
).first()
|
||||
# 验证执行记录是否存在
|
||||
execution = db.query(Execution).filter(Execution.id == execution_id).first()
|
||||
|
||||
if not execution:
|
||||
raise NotFoundError("执行记录", execution_id)
|
||||
|
||||
# 验证权限:检查workflow或agent的所有权
|
||||
has_permission = False
|
||||
if execution.workflow_id:
|
||||
workflow = db.query(Workflow).filter(Workflow.id == execution.workflow_id).first()
|
||||
if workflow and workflow.user_id == current_user.id:
|
||||
has_permission = True
|
||||
elif execution.agent_id:
|
||||
agent = db.query(Agent).filter(Agent.id == execution.agent_id).first()
|
||||
if agent and (agent.user_id == current_user.id or agent.status in ["published", "running"]):
|
||||
has_permission = True
|
||||
|
||||
if not has_permission:
|
||||
raise NotFoundError("执行记录", execution_id)
|
||||
|
||||
from sqlalchemy import func
|
||||
|
||||
# 获取总执行时间
|
||||
|
||||
Reference in New Issue
Block a user