mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 08:58:09 +08:00
feat(api): Implement HITL for Workflow, add is_resumption for start event
This commit is contained in:
@ -527,6 +527,11 @@ class WorkflowDraftRunLoopNodeApi(Resource):
|
||||
raise InternalServerError()
|
||||
|
||||
|
||||
class HumanInputSubmitPayload(BaseModel):
|
||||
inputs: dict[str, Any]
|
||||
action: str
|
||||
|
||||
|
||||
@console_ns.route("/apps/<uuid:app_id>/advanced-chat/workflows/draft/human-input/nodes/<string:node_id>/form")
|
||||
class AdvancedChatDraftHumanInputFormApi(Resource):
|
||||
@console_ns.doc("get_advanced_chat_draft_human_input_form")
|
||||
@ -580,19 +585,14 @@ class AdvancedChatDraftHumanInputFormApi(Resource):
|
||||
Submit human input form preview
|
||||
"""
|
||||
current_user, _ = current_account_with_tenant()
|
||||
parser = (
|
||||
reqparse.RequestParser()
|
||||
.add_argument("inputs", type=dict, required=True, location="json")
|
||||
.add_argument("action", type=str, required=True, location="json")
|
||||
)
|
||||
args = parser.parse_args()
|
||||
args = HumanInputSubmitPayload.model_validate(console_ns.payload or {})
|
||||
workflow_service = WorkflowService()
|
||||
result = workflow_service.submit_human_input_form_preview(
|
||||
app_model=app_model,
|
||||
account=current_user,
|
||||
node_id=node_id,
|
||||
form_inputs=args["inputs"],
|
||||
action=args["action"],
|
||||
form_inputs=args.inputs,
|
||||
action=args.action,
|
||||
)
|
||||
return jsonable_encoder(result)
|
||||
|
||||
@ -650,19 +650,14 @@ class WorkflowDraftHumanInputFormApi(Resource):
|
||||
Submit human input form preview
|
||||
"""
|
||||
current_user, _ = current_account_with_tenant()
|
||||
parser = (
|
||||
reqparse.RequestParser()
|
||||
.add_argument("inputs", type=dict, required=True, location="json")
|
||||
.add_argument("action", type=str, required=True, location="json")
|
||||
)
|
||||
args = parser.parse_args()
|
||||
workflow_service = WorkflowService()
|
||||
args = HumanInputSubmitPayload.model_validate(console_ns.payload or {})
|
||||
result = workflow_service.submit_human_input_form_preview(
|
||||
app_model=app_model,
|
||||
account=current_user,
|
||||
node_id=node_id,
|
||||
form_inputs=args["inputs"],
|
||||
action=args["action"],
|
||||
form_inputs=args.inputs,
|
||||
action=args.action,
|
||||
)
|
||||
return jsonable_encoder(result)
|
||||
|
||||
|
||||
@ -411,11 +411,8 @@ class ConsoleWorkflowPauseDetailsApi(Resource):
|
||||
is_paused = workflow_run.status == WorkflowExecutionStatus.PAUSED
|
||||
if not is_paused:
|
||||
return {
|
||||
"is_suspended": False,
|
||||
"paused_at": None,
|
||||
"paused_nodes": [],
|
||||
"pending_human_inputs": [],
|
||||
"pause_reasons": [],
|
||||
}, 200
|
||||
|
||||
pause_entity = workflow_run_repo.get_workflow_pause(workflow_run_id)
|
||||
@ -430,11 +427,8 @@ class ConsoleWorkflowPauseDetailsApi(Resource):
|
||||
|
||||
# Build response
|
||||
response = {
|
||||
"is_suspended": True,
|
||||
"paused_at": workflow_run.created_at.isoformat() + "Z" if workflow_run.created_at else None,
|
||||
"paused_nodes": [],
|
||||
"pending_human_inputs": [],
|
||||
"pause_reasons": pause_reasons,
|
||||
}
|
||||
|
||||
# Add pending human input forms
|
||||
|
||||
@ -157,6 +157,7 @@ class ConsoleWorkflowEventsApi(Resource):
|
||||
app = _retrieve_app_for_workflow_run(session, workflow_run)
|
||||
|
||||
if workflow_run.finished_at is not None:
|
||||
# TODO(QuantumGhost): should we modify the handling for finished workflow run here?
|
||||
response = WorkflowResponseConverter.workflow_run_result_to_finish_response(
|
||||
task_id=workflow_run.id,
|
||||
workflow_run=workflow_run,
|
||||
|
||||
Reference in New Issue
Block a user