- coord routers: removed JWT auth requirement (internal-only endpoints) - error_handler: SQLAlchemy OperationalError/DisconnectionError → 503 with Retry-After: 30 header instead of 500 - /health: live DB probe (SELECT 1) instead of static response - CLAUDE.md: "Live State Tracking" section with full agent protocol for all projects — session start, lock claim/release, component state updates, softfail + local queue catch-up - COORDINATION_PROTOCOL.md: softfail/catch-up section + server-side 503 behavior documented Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
78 lines
2.7 KiB
Python
78 lines
2.7 KiB
Python
"""Coordination workflows router."""
|
|
|
|
from uuid import UUID
|
|
|
|
from fastapi import APIRouter, Depends, Query, status
|
|
from sqlalchemy.orm import Session
|
|
|
|
from api.database import get_db
|
|
from api.schemas.coord_workflow import CoordWorkflowCreate, CoordWorkflowResponse, CoordWorkflowUpdate
|
|
from api.schemas.coord_work_item import CoordWorkItemResponse
|
|
from api.services import coord_workflow_service, coord_work_item_service
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("", response_model=dict, status_code=status.HTTP_200_OK)
|
|
def list_workflows(
|
|
project_key: str | None = Query(default=None),
|
|
status_filter: str | None = Query(default=None),
|
|
skip: int = Query(default=0, ge=0),
|
|
limit: int = Query(default=100, ge=1, le=1000),
|
|
db: Session = Depends(get_db),
|
|
):
|
|
"""List workflows with optional filters."""
|
|
workflows, total = coord_workflow_service.get_workflows(
|
|
db, project_key=project_key, status_filter=status_filter, skip=skip, limit=limit
|
|
)
|
|
return {
|
|
"total": total,
|
|
"skip": skip,
|
|
"limit": limit,
|
|
"workflows": [CoordWorkflowResponse.model_validate(w) for w in workflows],
|
|
}
|
|
|
|
|
|
@router.post("", response_model=CoordWorkflowResponse, status_code=status.HTTP_201_CREATED)
|
|
def create_workflow(
|
|
data: CoordWorkflowCreate,
|
|
db: Session = Depends(get_db),
|
|
):
|
|
"""Create a new coordination workflow."""
|
|
workflow = coord_workflow_service.create_workflow(db, data)
|
|
return CoordWorkflowResponse.model_validate(workflow)
|
|
|
|
|
|
@router.get("/{workflow_id}", response_model=dict, status_code=status.HTTP_200_OK)
|
|
def get_workflow(
|
|
workflow_id: UUID,
|
|
db: Session = Depends(get_db),
|
|
):
|
|
"""Get a workflow by ID including its work items."""
|
|
workflow = coord_workflow_service.get_workflow_by_id(db, workflow_id)
|
|
items, _ = coord_work_item_service.get_work_items(db, workflow_id=str(workflow_id))
|
|
return {
|
|
"workflow": CoordWorkflowResponse.model_validate(workflow),
|
|
"work_items": [CoordWorkItemResponse.model_validate(i) for i in items],
|
|
}
|
|
|
|
|
|
@router.put("/{workflow_id}", response_model=CoordWorkflowResponse, status_code=status.HTTP_200_OK)
|
|
def update_workflow(
|
|
workflow_id: UUID,
|
|
data: CoordWorkflowUpdate,
|
|
db: Session = Depends(get_db),
|
|
):
|
|
"""Update a workflow."""
|
|
workflow = coord_workflow_service.update_workflow(db, workflow_id, data)
|
|
return CoordWorkflowResponse.model_validate(workflow)
|
|
|
|
|
|
@router.delete("/{workflow_id}", response_model=dict, status_code=status.HTTP_200_OK)
|
|
def delete_workflow(
|
|
workflow_id: UUID,
|
|
db: Session = Depends(get_db),
|
|
):
|
|
"""Delete a workflow and its work items (cascade)."""
|
|
return coord_workflow_service.delete_workflow(db, workflow_id)
|