upload
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
from app.api.pipelines.router import router
|
||||
|
||||
__all__ = ["router"]
|
||||
@@ -0,0 +1,114 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.database.session import get_session
|
||||
from app.models import User
|
||||
from app.schemas.pipeline_chat_sch import PipelineGenerateRequest, PipelineGenerateResponse
|
||||
from app.services.pipeline_dialog_service import DialogAccessError, PipelineDialogService
|
||||
from app.services.pipeline_service import PipelineService
|
||||
from app.utils.business_logger import log_business_event
|
||||
from app.utils.token_manager import get_current_user
|
||||
|
||||
|
||||
router = APIRouter(tags=["Pipelines"])
|
||||
|
||||
|
||||
@router.post("/generate", response_model=PipelineGenerateResponse)
|
||||
async def generate_pipeline(
|
||||
payload: PipelineGenerateRequest,
|
||||
request: Request,
|
||||
session: AsyncSession = Depends(get_session),
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
trace_id = getattr(request.state, "traceId", None)
|
||||
log_business_event(
|
||||
"pipeline_prompt_received",
|
||||
trace_id=trace_id,
|
||||
user_id=str(current_user.id),
|
||||
dialog_id=str(payload.dialog_id),
|
||||
message_len=len(payload.message),
|
||||
capability_ids_count=len(payload.capability_ids or []),
|
||||
)
|
||||
|
||||
service = PipelineService(session)
|
||||
dialog_service = PipelineDialogService(session)
|
||||
try:
|
||||
await dialog_service.append_user_message(
|
||||
dialog_id=payload.dialog_id,
|
||||
user_id=current_user.id,
|
||||
content=payload.message,
|
||||
)
|
||||
dialog = await dialog_service.get_dialog(
|
||||
dialog_id=payload.dialog_id,
|
||||
user_id=current_user.id,
|
||||
)
|
||||
except DialogAccessError as exc:
|
||||
detail = str(exc)
|
||||
log_business_event(
|
||||
"pipeline_prompt_rejected",
|
||||
trace_id=trace_id,
|
||||
user_id=str(current_user.id),
|
||||
dialog_id=str(payload.dialog_id),
|
||||
reason=detail,
|
||||
)
|
||||
if "denied" in detail:
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=detail) from exc
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=detail) from exc
|
||||
|
||||
try:
|
||||
result = await service.generate(
|
||||
dialog_id=payload.dialog_id,
|
||||
message=payload.message,
|
||||
user_id=current_user.id,
|
||||
capability_ids=payload.capability_ids,
|
||||
previous_pipeline_id=dialog.last_pipeline_id,
|
||||
)
|
||||
except Exception as exc:
|
||||
if "ollama" in str(exc).lower():
|
||||
message_ru = "Не удалось обратиться к локальной модели Ollama. Проверьте OLLAMA_HOST/OLLAMA_MODEL и повторите запрос."
|
||||
result = {
|
||||
"status": "cannot_build",
|
||||
"message_ru": message_ru,
|
||||
"chat_reply_ru": message_ru,
|
||||
"pipeline_id": None,
|
||||
"nodes": [],
|
||||
"edges": [],
|
||||
"missing_requirements": ["ollama_unavailable"],
|
||||
"context_summary": None,
|
||||
}
|
||||
else:
|
||||
raise
|
||||
|
||||
response_payload = PipelineGenerateResponse(**result)
|
||||
try:
|
||||
await dialog_service.append_assistant_message(
|
||||
dialog_id=payload.dialog_id,
|
||||
user_id=current_user.id,
|
||||
content=response_payload.chat_reply_ru or response_payload.message_ru,
|
||||
assistant_payload=response_payload.model_dump(mode="json", exclude_none=True),
|
||||
)
|
||||
except DialogAccessError as exc:
|
||||
detail = str(exc)
|
||||
log_business_event(
|
||||
"pipeline_prompt_rejected",
|
||||
trace_id=trace_id,
|
||||
user_id=str(current_user.id),
|
||||
dialog_id=str(payload.dialog_id),
|
||||
reason=detail,
|
||||
)
|
||||
if "denied" in detail:
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=detail) from exc
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=detail) from exc
|
||||
|
||||
log_business_event(
|
||||
"pipeline_prompt_processed",
|
||||
trace_id=trace_id,
|
||||
user_id=str(current_user.id),
|
||||
dialog_id=str(payload.dialog_id),
|
||||
result_status=response_payload.status,
|
||||
pipeline_id=str(response_payload.pipeline_id) if response_payload.pipeline_id else None,
|
||||
)
|
||||
|
||||
return response_payload
|
||||
@@ -0,0 +1,78 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Request, status
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.database.session import get_session
|
||||
from app.models import User
|
||||
from app.schemas.pipeline_chat_sch import (
|
||||
PipelineDialogHistoryResponse,
|
||||
PipelineDialogMessageResponse,
|
||||
)
|
||||
from app.services.pipeline_dialog_service import DialogAccessError, PipelineDialogService
|
||||
from app.utils.business_logger import log_business_event
|
||||
from app.utils.token_manager import get_current_user
|
||||
|
||||
|
||||
router = APIRouter(tags=["Pipelines"])
|
||||
|
||||
|
||||
@router.get("/dialogs/{dialog_id}/history", response_model=PipelineDialogHistoryResponse)
|
||||
async def get_pipeline_dialog_history(
|
||||
dialog_id: UUID,
|
||||
request: Request,
|
||||
limit: int = Query(default=30, ge=1, le=200),
|
||||
offset: int = Query(default=0, ge=0),
|
||||
session: AsyncSession = Depends(get_session),
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
trace_id = getattr(request.state, "traceId", None)
|
||||
dialog_service = PipelineDialogService(session)
|
||||
try:
|
||||
dialog, messages = await dialog_service.get_history(
|
||||
dialog_id=dialog_id,
|
||||
user_id=current_user.id,
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
)
|
||||
except DialogAccessError as exc:
|
||||
detail = str(exc)
|
||||
log_business_event(
|
||||
"pipeline_dialog_history_rejected",
|
||||
trace_id=trace_id,
|
||||
user_id=str(current_user.id),
|
||||
dialog_id=str(dialog_id),
|
||||
reason=detail,
|
||||
)
|
||||
if "denied" in detail:
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=detail) from exc
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=detail) from exc
|
||||
|
||||
response = PipelineDialogHistoryResponse(
|
||||
dialog_id=dialog.id,
|
||||
title=dialog.title,
|
||||
messages=[
|
||||
PipelineDialogMessageResponse(
|
||||
id=message.id,
|
||||
role=message.role.value,
|
||||
content=message.content,
|
||||
assistant_payload=message.assistant_payload,
|
||||
created_at=message.created_at,
|
||||
)
|
||||
for message in messages
|
||||
],
|
||||
)
|
||||
|
||||
log_business_event(
|
||||
"pipeline_dialog_history_viewed",
|
||||
trace_id=trace_id,
|
||||
user_id=str(current_user.id),
|
||||
dialog_id=str(dialog.id),
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
message_count=len(response.messages),
|
||||
)
|
||||
|
||||
return response
|
||||
@@ -0,0 +1,52 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, Depends, Query, Request
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.database.session import get_session
|
||||
from app.models import User
|
||||
from app.schemas.pipeline_chat_sch import PipelineDialogListItemResponse
|
||||
from app.services.pipeline_dialog_service import PipelineDialogService
|
||||
from app.utils.business_logger import log_business_event
|
||||
from app.utils.token_manager import get_current_user
|
||||
|
||||
|
||||
router = APIRouter(tags=["Pipelines"])
|
||||
|
||||
|
||||
@router.get("/dialogs", response_model=list[PipelineDialogListItemResponse])
|
||||
async def list_pipeline_dialogs(
|
||||
request: Request,
|
||||
limit: int = Query(default=20, ge=1, le=200),
|
||||
offset: int = Query(default=0, ge=0),
|
||||
session: AsyncSession = Depends(get_session),
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
trace_id = getattr(request.state, "traceId", None)
|
||||
dialog_service = PipelineDialogService(session)
|
||||
dialogs = await dialog_service.list_dialogs(
|
||||
user_id=current_user.id,
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
)
|
||||
response = [
|
||||
PipelineDialogListItemResponse(
|
||||
dialog_id=dialog.id,
|
||||
title=dialog.title,
|
||||
last_status=dialog.last_status,
|
||||
last_pipeline_id=dialog.last_pipeline_id,
|
||||
last_message_preview=dialog.last_message_preview,
|
||||
created_at=dialog.created_at,
|
||||
updated_at=dialog.updated_at,
|
||||
)
|
||||
for dialog in dialogs
|
||||
]
|
||||
log_business_event(
|
||||
"pipeline_dialogs_listed",
|
||||
trace_id=trace_id,
|
||||
user_id=str(current_user.id),
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
result_count=len(response),
|
||||
)
|
||||
return response
|
||||
@@ -0,0 +1,54 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.database.session import get_session
|
||||
from app.models import User
|
||||
from app.schemas.pipeline_chat_sch import DialogResetRequest, DialogResetResponse
|
||||
from app.services.pipeline_dialog_service import DialogAccessError, PipelineDialogService
|
||||
from app.services.pipeline_service import PipelineService
|
||||
from app.utils.business_logger import log_business_event
|
||||
from app.utils.token_manager import get_current_user
|
||||
|
||||
|
||||
router = APIRouter(tags=["Pipelines"])
|
||||
|
||||
|
||||
@router.post("/dialog/reset", response_model=DialogResetResponse)
|
||||
async def reset_pipeline_dialog(
|
||||
payload: DialogResetRequest,
|
||||
request: Request,
|
||||
session: AsyncSession = Depends(get_session),
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
trace_id = getattr(request.state, "traceId", None)
|
||||
dialog_service = PipelineDialogService(session)
|
||||
try:
|
||||
await dialog_service.get_dialog(
|
||||
dialog_id=payload.dialog_id,
|
||||
user_id=current_user.id,
|
||||
)
|
||||
except DialogAccessError as exc:
|
||||
detail = str(exc)
|
||||
log_business_event(
|
||||
"pipeline_dialog_reset_rejected",
|
||||
trace_id=trace_id,
|
||||
user_id=str(current_user.id),
|
||||
dialog_id=str(payload.dialog_id),
|
||||
reason=detail,
|
||||
)
|
||||
if "denied" in detail:
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=detail) from exc
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=detail) from exc
|
||||
|
||||
service = PipelineService(session)
|
||||
result = await service.reset_dialog(payload.dialog_id)
|
||||
log_business_event(
|
||||
"pipeline_dialog_reset",
|
||||
trace_id=trace_id,
|
||||
user_id=str(current_user.id),
|
||||
dialog_id=str(payload.dialog_id),
|
||||
result_status=result.get("status") if isinstance(result, dict) else None,
|
||||
)
|
||||
return DialogResetResponse(**result)
|
||||
@@ -0,0 +1,17 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from app.api.pipelines.generate import router as generate_router
|
||||
from app.api.pipelines.get_dialog_history import router as get_dialog_history_router
|
||||
from app.api.pipelines.list_dialogs import router as list_dialogs_router
|
||||
from app.api.pipelines.reset_dialog import router as reset_dialog_router
|
||||
from app.api.pipelines.run import router as run_router
|
||||
from app.api.pipelines.update_graph import router as update_graph_router
|
||||
|
||||
|
||||
router = APIRouter(prefix="/v1/pipelines", tags=["Pipelines"])
|
||||
router.include_router(generate_router)
|
||||
router.include_router(list_dialogs_router)
|
||||
router.include_router(get_dialog_history_router)
|
||||
router.include_router(reset_dialog_router)
|
||||
router.include_router(run_router)
|
||||
router.include_router(update_graph_router)
|
||||
@@ -0,0 +1,83 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.database.session import get_session
|
||||
from app.models import Pipeline, User, UserRole
|
||||
from app.schemas.execution_sch import RunPipelineRequest, RunPipelineResponse
|
||||
from app.services.execution_service import ExecutionService, ExecutionServiceError
|
||||
from app.utils.business_logger import log_business_event
|
||||
from app.utils.token_manager import get_current_user
|
||||
|
||||
|
||||
router = APIRouter(tags=["Pipelines"])
|
||||
|
||||
|
||||
@router.post("/{pipeline_id}/run", response_model=RunPipelineResponse, status_code=status.HTTP_202_ACCEPTED)
|
||||
async def run_pipeline(
|
||||
pipeline_id: UUID,
|
||||
payload: RunPipelineRequest,
|
||||
request: Request,
|
||||
session: AsyncSession = Depends(get_session),
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
trace_id = getattr(request.state, "traceId", None)
|
||||
pipeline = await session.get(Pipeline, pipeline_id)
|
||||
if pipeline is None:
|
||||
log_business_event(
|
||||
"pipeline_run_rejected",
|
||||
trace_id=trace_id,
|
||||
user_id=str(current_user.id),
|
||||
pipeline_id=str(pipeline_id),
|
||||
reason="pipeline_not_found",
|
||||
)
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Pipeline not found")
|
||||
|
||||
if current_user.role != UserRole.ADMIN and pipeline.created_by != current_user.id:
|
||||
log_business_event(
|
||||
"pipeline_run_rejected",
|
||||
trace_id=trace_id,
|
||||
user_id=str(current_user.id),
|
||||
pipeline_id=str(pipeline_id),
|
||||
reason="pipeline_not_owned",
|
||||
)
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Pipeline not found")
|
||||
|
||||
service = ExecutionService(session)
|
||||
try:
|
||||
run = await service.create_run(
|
||||
pipeline_id=pipeline_id,
|
||||
inputs=payload.inputs,
|
||||
initiated_by=current_user.id,
|
||||
)
|
||||
except ExecutionServiceError as exc:
|
||||
message = str(exc)
|
||||
log_business_event(
|
||||
"pipeline_run_rejected",
|
||||
trace_id=trace_id,
|
||||
user_id=str(current_user.id),
|
||||
pipeline_id=str(pipeline_id),
|
||||
reason=message,
|
||||
)
|
||||
if "not found" in message.lower():
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=message) from exc
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=message) from exc
|
||||
|
||||
ExecutionService.start_background_execution(run.id)
|
||||
log_business_event(
|
||||
"pipeline_run_started",
|
||||
trace_id=trace_id,
|
||||
user_id=str(current_user.id),
|
||||
pipeline_id=str(run.pipeline_id),
|
||||
run_id=str(run.id),
|
||||
inputs_count=len(payload.inputs or {}),
|
||||
)
|
||||
|
||||
return RunPipelineResponse(
|
||||
run_id=run.id,
|
||||
pipeline_id=run.pipeline_id,
|
||||
status=run.status.value,
|
||||
)
|
||||
@@ -0,0 +1,205 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections import defaultdict
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.database.session import get_session
|
||||
from app.models import Pipeline, User, UserRole
|
||||
from app.schemas.pipeline_chat_sch import (
|
||||
PipelineGraphUpdateRequest,
|
||||
PipelineGraphUpdateResponse,
|
||||
)
|
||||
from app.utils.business_logger import log_business_event
|
||||
from app.utils.token_manager import get_current_user
|
||||
|
||||
|
||||
router = APIRouter(tags=["Pipelines"])
|
||||
|
||||
|
||||
def _graph_has_cycle(steps: set[int], edges: list[dict[str, int | str]]) -> bool:
|
||||
adjacency: dict[int, set[int]] = {step: set() for step in steps}
|
||||
for edge in edges:
|
||||
src = edge["from_step"]
|
||||
dst = edge["to_step"]
|
||||
if isinstance(src, int) and isinstance(dst, int):
|
||||
adjacency.setdefault(src, set()).add(dst)
|
||||
|
||||
visiting: set[int] = set()
|
||||
visited: set[int] = set()
|
||||
|
||||
def dfs(step: int) -> bool:
|
||||
if step in visiting:
|
||||
return True
|
||||
if step in visited:
|
||||
return False
|
||||
visiting.add(step)
|
||||
for neighbor in adjacency.get(step, set()):
|
||||
if dfs(neighbor):
|
||||
return True
|
||||
visiting.remove(step)
|
||||
visited.add(step)
|
||||
return False
|
||||
|
||||
return any(dfs(step) for step in adjacency)
|
||||
|
||||
|
||||
def _sync_node_connections(
|
||||
nodes: list[dict[str, object]],
|
||||
edges: list[dict[str, int | str]],
|
||||
) -> None:
|
||||
incoming_by_step: dict[int, set[int]] = defaultdict(set)
|
||||
outgoing_by_step: dict[int, set[int]] = defaultdict(set)
|
||||
incoming_types_by_step: dict[int, set[tuple[int, str]]] = defaultdict(set)
|
||||
|
||||
for edge in edges:
|
||||
src = edge.get("from_step")
|
||||
dst = edge.get("to_step")
|
||||
edge_type = edge.get("type")
|
||||
if not isinstance(src, int) or not isinstance(dst, int) or not isinstance(edge_type, str):
|
||||
continue
|
||||
|
||||
outgoing_by_step[src].add(dst)
|
||||
incoming_by_step[dst].add(src)
|
||||
incoming_types_by_step[dst].add((src, edge_type))
|
||||
|
||||
for node in nodes:
|
||||
step = node.get("step")
|
||||
if not isinstance(step, int):
|
||||
node["input_connected_from"] = []
|
||||
node["output_connected_to"] = []
|
||||
node["input_data_type_from_previous"] = []
|
||||
continue
|
||||
|
||||
node["input_connected_from"] = sorted(incoming_by_step.get(step, set()))
|
||||
node["output_connected_to"] = sorted(outgoing_by_step.get(step, set()))
|
||||
node["input_data_type_from_previous"] = [
|
||||
{"from_step": src, "type": edge_type}
|
||||
for src, edge_type in sorted(incoming_types_by_step.get(step, set()))
|
||||
]
|
||||
|
||||
|
||||
@router.patch("/{pipeline_id}/graph", response_model=PipelineGraphUpdateResponse)
|
||||
async def update_pipeline_graph(
|
||||
pipeline_id: UUID,
|
||||
payload: PipelineGraphUpdateRequest,
|
||||
request: Request,
|
||||
session: AsyncSession = Depends(get_session),
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
trace_id = getattr(request.state, "traceId", None)
|
||||
|
||||
pipeline = await session.get(Pipeline, pipeline_id)
|
||||
if pipeline is None:
|
||||
log_business_event(
|
||||
"pipeline_graph_update_rejected",
|
||||
trace_id=trace_id,
|
||||
user_id=str(current_user.id),
|
||||
pipeline_id=str(pipeline_id),
|
||||
reason="pipeline_not_found",
|
||||
)
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Pipeline not found")
|
||||
|
||||
if current_user.role != UserRole.ADMIN and pipeline.created_by != current_user.id:
|
||||
log_business_event(
|
||||
"pipeline_graph_update_rejected",
|
||||
trace_id=trace_id,
|
||||
user_id=str(current_user.id),
|
||||
pipeline_id=str(pipeline_id),
|
||||
reason="pipeline_not_owned",
|
||||
)
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Pipeline not found")
|
||||
|
||||
nodes = [node.model_dump(mode="json") for node in payload.nodes]
|
||||
edges = [edge.model_dump(mode="json") for edge in payload.edges]
|
||||
|
||||
validation_errors: list[str] = []
|
||||
steps: set[int] = set()
|
||||
for node in nodes:
|
||||
step = node.get("step")
|
||||
if not isinstance(step, int):
|
||||
validation_errors.append("graph: invalid_step")
|
||||
continue
|
||||
if step in steps:
|
||||
validation_errors.append(f"graph: duplicate_node_step:{step}")
|
||||
continue
|
||||
steps.add(step)
|
||||
|
||||
normalized_edges: list[dict[str, int | str]] = []
|
||||
seen_edges: set[tuple[int, int, str]] = set()
|
||||
|
||||
for edge in edges:
|
||||
src = edge.get("from_step")
|
||||
dst = edge.get("to_step")
|
||||
edge_type = str(edge.get("type") or "").strip()
|
||||
|
||||
if not isinstance(src, int) or not isinstance(dst, int):
|
||||
validation_errors.append("graph: invalid_edge_reference")
|
||||
continue
|
||||
|
||||
if src not in steps or dst not in steps:
|
||||
validation_errors.append(f"graph: edge_to_missing_node:{src}->{dst}")
|
||||
continue
|
||||
|
||||
if src == dst:
|
||||
validation_errors.append(f"graph: self_loop:{src}")
|
||||
continue
|
||||
|
||||
if not edge_type:
|
||||
validation_errors.append("graph: invalid_edge_type")
|
||||
continue
|
||||
|
||||
edge_key = (src, dst, edge_type)
|
||||
if edge_key in seen_edges:
|
||||
validation_errors.append(
|
||||
f"graph: duplicate_edge:{src}->{dst}:{edge_type}"
|
||||
)
|
||||
continue
|
||||
|
||||
seen_edges.add(edge_key)
|
||||
normalized_edges.append({"from_step": src, "to_step": dst, "type": edge_type})
|
||||
|
||||
if normalized_edges and _graph_has_cycle(steps, normalized_edges):
|
||||
validation_errors.append("graph: cycle")
|
||||
|
||||
if validation_errors:
|
||||
log_business_event(
|
||||
"pipeline_graph_update_rejected",
|
||||
trace_id=trace_id,
|
||||
user_id=str(current_user.id),
|
||||
pipeline_id=str(pipeline_id),
|
||||
reason="invalid_graph",
|
||||
errors=sorted(set(validation_errors)),
|
||||
)
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail={
|
||||
"message": "Invalid pipeline graph",
|
||||
"errors": sorted(set(validation_errors)),
|
||||
},
|
||||
)
|
||||
|
||||
_sync_node_connections(nodes, normalized_edges)
|
||||
|
||||
pipeline.nodes = nodes
|
||||
pipeline.edges = normalized_edges
|
||||
await session.commit()
|
||||
await session.refresh(pipeline)
|
||||
|
||||
log_business_event(
|
||||
"pipeline_graph_updated",
|
||||
trace_id=trace_id,
|
||||
user_id=str(current_user.id),
|
||||
pipeline_id=str(pipeline.id),
|
||||
nodes_count=len(nodes),
|
||||
edges_count=len(normalized_edges),
|
||||
)
|
||||
|
||||
return PipelineGraphUpdateResponse(
|
||||
pipeline_id=pipeline.id,
|
||||
nodes=pipeline.nodes,
|
||||
edges=pipeline.edges,
|
||||
updated_at=pipeline.updated_at,
|
||||
)
|
||||
Reference in New Issue
Block a user