feat(studio): 新增 Studio 工作流编辑/运行页,优化顶部三栏对齐
- 后端:项目/运行 API、上下文服务与数据模型 - 前端:Studio 列表、编辑页(R1/R2 布局)、运行页与节点图 - 编辑页顶部:CSS Grid 统一标签行与控件行对齐,项目按钮独立第三行 - Docker 开发配置与文档脚本 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from fastapi import APIRouter
|
||||
from .routes import presetsRoute, chatsRoute, worldbooksRoute, apiConfigRoute, charactersRoute, chatWsRoute, tokenUsageRoute, imageGalleryRoute, regexRoute, chatSummaryRoute
|
||||
from .routes import presetsRoute, chatsRoute, worldbooksRoute, apiConfigRoute, charactersRoute, chatWsRoute, tokenUsageRoute, imageGalleryRoute, regexRoute, chatSummaryRoute, studioRoute
|
||||
from utils.file_utils import get_all_roles_and_chats
|
||||
from core.config import settings
|
||||
from pathlib import Path
|
||||
@@ -18,6 +18,7 @@ router.include_router(tokenUsageRoute.router)
|
||||
router.include_router(imageGalleryRoute.router)
|
||||
router.include_router(regexRoute.router)
|
||||
router.include_router(chatSummaryRoute.router)
|
||||
router.include_router(studioRoute.router)
|
||||
|
||||
# ✅ 注册 WebSocket 路由(必须在 HTTP 路由之后,避免路径冲突)
|
||||
router.include_router(chatWsRoute.router)
|
||||
|
||||
217
backend/api/routes/studioRoute.py
Normal file
217
backend/api/routes/studioRoute.py
Normal file
@@ -0,0 +1,217 @@
|
||||
import logging
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from models.studio_models import (
|
||||
AdvanceRunRequest,
|
||||
CreateStudioProjectRequest,
|
||||
PipelineDefinition,
|
||||
RenameRunRequest,
|
||||
StudioProject,
|
||||
StudioProjectSummary,
|
||||
StudioRun,
|
||||
StudioRunSummary,
|
||||
UpdateStudioProjectRequest,
|
||||
WorkflowTemplateSummary,
|
||||
WorkflowVariablesResponse,
|
||||
)
|
||||
from services.studio_project_service import studio_project_service
|
||||
from services.studio_run_service import studio_run_service
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
router = APIRouter(prefix="/studio", tags=["studio"])
|
||||
|
||||
|
||||
@router.get("/projects", response_model=List[StudioProjectSummary])
|
||||
async def list_studio_projects():
|
||||
try:
|
||||
return studio_project_service.list_projects()
|
||||
except Exception as e:
|
||||
logger.error("Failed to list studio projects: %s", e)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/projects/{project_id}", response_model=StudioProject)
|
||||
async def get_studio_project(project_id: str):
|
||||
try:
|
||||
return studio_project_service.get_project(project_id)
|
||||
except FileNotFoundError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
except Exception as e:
|
||||
logger.error("Failed to get studio project %s: %s", project_id, e)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.patch("/projects/{project_id}", response_model=StudioProject)
|
||||
async def update_studio_project(project_id: str, req: UpdateStudioProjectRequest):
|
||||
try:
|
||||
return studio_project_service.update_project_meta(
|
||||
project_id,
|
||||
name=req.name,
|
||||
description=req.description,
|
||||
)
|
||||
except FileNotFoundError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
except Exception as e:
|
||||
logger.error("Failed to update studio project %s: %s", project_id, e)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.put("/projects/{project_id}/pipeline", response_model=StudioProject)
|
||||
async def save_studio_pipeline(project_id: str, pipeline: PipelineDefinition):
|
||||
try:
|
||||
return studio_project_service.save_pipeline(project_id, pipeline)
|
||||
except FileNotFoundError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
except Exception as e:
|
||||
logger.error("Failed to save pipeline for %s: %s", project_id, e)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/templates", response_model=List[WorkflowTemplateSummary])
|
||||
async def list_workflow_templates():
|
||||
try:
|
||||
return studio_project_service.list_workflow_templates()
|
||||
except Exception as e:
|
||||
logger.error("Failed to list workflow templates: %s", e)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/variables", response_model=WorkflowVariablesResponse)
|
||||
async def get_workflow_variables(projectId: str | None = None):
|
||||
try:
|
||||
return studio_project_service.get_workflow_variables(projectId)
|
||||
except Exception as e:
|
||||
logger.error("Failed to load workflow variables: %s", e)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/skill-templates")
|
||||
async def get_skill_templates() -> Dict[str, Any]:
|
||||
try:
|
||||
return studio_project_service.get_skill_templates()
|
||||
except FileNotFoundError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
except Exception as e:
|
||||
logger.error("Failed to load skill templates: %s", e)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/niches")
|
||||
async def get_niches() -> Dict[str, Any]:
|
||||
try:
|
||||
return studio_project_service.get_niches()
|
||||
except Exception as e:
|
||||
logger.error("Failed to load niches: %s", e)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.delete("/projects/{project_id}")
|
||||
async def delete_studio_project(project_id: str):
|
||||
try:
|
||||
studio_project_service.delete_project(project_id)
|
||||
return {"ok": True, "id": project_id}
|
||||
except FileNotFoundError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
except Exception as e:
|
||||
logger.error("Failed to delete studio project %s: %s", project_id, e)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.post("/projects", response_model=StudioProject)
|
||||
async def create_studio_project(req: CreateStudioProjectRequest):
|
||||
try:
|
||||
return studio_project_service.create_project(req)
|
||||
except FileNotFoundError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
except Exception as e:
|
||||
logger.error("Failed to create studio project: %s", e)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.post("/projects/{project_id}/runs", response_model=StudioRun)
|
||||
async def create_studio_run(project_id: str):
|
||||
try:
|
||||
return studio_run_service.create_run(project_id)
|
||||
except FileNotFoundError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
except Exception as e:
|
||||
logger.error("Failed to create studio run for %s: %s", project_id, e)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/projects/{project_id}/runs", response_model=List[StudioRunSummary])
|
||||
async def list_studio_runs(project_id: str):
|
||||
try:
|
||||
studio_project_service.get_project(project_id)
|
||||
return studio_run_service.list_runs(project_id)
|
||||
except FileNotFoundError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
except Exception as e:
|
||||
logger.error("Failed to list studio runs for %s: %s", project_id, e)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/projects/{project_id}/runs/{run_id}", response_model=StudioRun)
|
||||
async def get_studio_run(project_id: str, run_id: str):
|
||||
try:
|
||||
return studio_run_service.get_run(project_id, run_id)
|
||||
except FileNotFoundError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
except Exception as e:
|
||||
logger.error("Failed to get studio run %s/%s: %s", project_id, run_id, e)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.post("/projects/{project_id}/runs/{run_id}/advance", response_model=StudioRun)
|
||||
async def advance_studio_run(
|
||||
project_id: str, run_id: str, req: AdvanceRunRequest
|
||||
):
|
||||
try:
|
||||
return studio_run_service.advance_run(
|
||||
project_id, run_id, display_params=req.displayParams
|
||||
)
|
||||
except FileNotFoundError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
except NotImplementedError as e:
|
||||
raise HTTPException(status_code=501, detail=str(e))
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
"Failed to advance studio run %s/%s: %s", project_id, run_id, e
|
||||
)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.delete("/projects/{project_id}/runs/{run_id}")
|
||||
async def delete_studio_run(project_id: str, run_id: str):
|
||||
try:
|
||||
studio_run_service.delete_run(project_id, run_id)
|
||||
return {"ok": True, "id": run_id}
|
||||
except FileNotFoundError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
"Failed to delete studio run %s/%s: %s", project_id, run_id, e
|
||||
)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.patch("/projects/{project_id}/runs/{run_id}", response_model=StudioRun)
|
||||
async def rename_studio_run(
|
||||
project_id: str, run_id: str, req: RenameRunRequest
|
||||
):
|
||||
try:
|
||||
return studio_run_service.rename_run(project_id, run_id, req.title)
|
||||
except FileNotFoundError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
"Failed to rename studio run %s/%s: %s", project_id, run_id, e
|
||||
)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
Reference in New Issue
Block a user