2025-05-02 17:31:33 +08:00

22 lines
1.1 KiB
Python

# File: backend/app/api/v1/endpoints/workflow.py (No significant changes needed)
# Description: 工作流相关的 API 路由 (uses the refactored service)
# ... (保持不变, 确保调用 refactored WorkflowService) ...
from typing import Optional
from fastapi import APIRouter, Depends, HTTPException, status
from app.models.pydantic_models import WorkflowRunRequest, WorkflowRunResponse
from app.services.workflow_service import WorkflowService # Import the refactored class
from app.db.database import get_db_session # Import if service needs DB
from sqlalchemy.ext.asyncio import AsyncSession
router = APIRouter()
workflow_service = WorkflowService()
@router.post("/run", response_model=WorkflowRunResponse)
async def run_workflow(
request: WorkflowRunRequest,
db: Optional[AsyncSession] = Depends(get_db_session) # Make DB optional or required based on component needs
):
print(f"收到运行工作流请求: {len(request.nodes)} 个节点, {len(request.edges)} 条边")
result = await workflow_service.execute_workflow(request.nodes, request.edges, db)
# No need to raise HTTPException here if service returns success=False
return result