feat: enable duplicate workflow feature

This commit is contained in:
Abhishek Kumar 2026-03-21 12:21:40 +05:30
parent c61a3843a5
commit 93c45580e7
8 changed files with 396 additions and 2 deletions

View file

@ -21,6 +21,7 @@ from api.services.configuration.masking import (
)
from api.services.mps_service_key_client import mps_service_key_client
from api.services.workflow.dto import ReactFlowDTO
from api.services.workflow.duplicate import duplicate_workflow
from api.services.workflow.errors import ItemKind, WorkflowError
from api.services.workflow.workflow import WorkflowGraph
@ -606,6 +607,38 @@ async def update_workflow(
raise HTTPException(status_code=500, detail=str(e))
@router.post("/{workflow_id}/duplicate")
async def duplicate_workflow_endpoint(
workflow_id: int,
user: UserModel = Depends(get_user),
) -> WorkflowResponse:
"""Duplicate a workflow including its definition, configuration, recordings, and triggers."""
try:
workflow = await duplicate_workflow(
workflow_id=workflow_id,
organization_id=user.selected_organization_id,
user_id=user.id,
)
return {
"id": workflow.id,
"name": workflow.name,
"status": workflow.status,
"created_at": workflow.created_at,
"workflow_definition": mask_workflow_definition(
workflow.workflow_definition_with_fallback
),
"current_definition_id": workflow.current_definition_id,
"template_context_variables": workflow.template_context_variables,
"call_disposition_codes": workflow.call_disposition_codes,
"workflow_configurations": workflow.workflow_configurations,
}
except ValueError as e:
raise HTTPException(status_code=404, detail=str(e))
except Exception as e:
logger.error(f"Error duplicating workflow {workflow_id}: {e}")
raise HTTPException(status_code=500, detail=str(e))
@router.post("/{workflow_id}/runs")
async def create_workflow_run(
workflow_id: int,