Underground-Digital/Workflow-Engine
0
1from flask_restful import Resource, marshal_with, reqparse2from flask_restful.inputs import int_range3 4from controllers.console import api5from controllers.console.app.wraps import get_app_model6from controllers.console.wraps import account_initialization_required, setup_required7from fields.workflow_run_fields import (8 advanced_chat_workflow_run_pagination_fields,9 workflow_run_detail_fields,10 workflow_run_node_execution_list_fields,11 workflow_run_pagination_fields,12)13from libs.helper import uuid_value14from libs.login import login_required15from models import App16from models.model import AppMode17from services.workflow_run_service import WorkflowRunService18 19 20class AdvancedChatAppWorkflowRunListApi(Resource):21 @setup_required22 @login_required23 @account_initialization_required24 @get_app_model(mode=[AppMode.ADVANCED_CHAT])25 @marshal_with(advanced_chat_workflow_run_pagination_fields)26 def get(self, app_model: App):27 """28 Get advanced chat app workflow run list29 """30 parser = reqparse.RequestParser()31 parser.add_argument("last_id", type=uuid_value, location="args")32 parser.add_argument("limit", type=int_range(1, 100), required=False, default=20, location="args")33 args = parser.parse_args()34 35 workflow_run_service = WorkflowRunService()36 result = workflow_run_service.get_paginate_advanced_chat_workflow_runs(app_model=app_model, args=args)37 38 return result39 40 41class WorkflowRunListApi(Resource):42 @setup_required43 @login_required44 @account_initialization_required45 @get_app_model(mode=[AppMode.ADVANCED_CHAT, AppMode.WORKFLOW])46 @marshal_with(workflow_run_pagination_fields)47 def get(self, app_model: App):48 """49 Get workflow run list50 """51 parser = reqparse.RequestParser()52 parser.add_argument("last_id", type=uuid_value, location="args")53 parser.add_argument("limit", type=int_range(1, 100), required=False, default=20, location="args")54 args = parser.parse_args()55 56 workflow_run_service = WorkflowRunService()57 result = workflow_run_service.get_paginate_workflow_runs(app_model=app_model, args=args)58 59 return result60 61 62class WorkflowRunDetailApi(Resource):63 @setup_required64 @login_required65 @account_initialization_required66 @get_app_model(mode=[AppMode.ADVANCED_CHAT, AppMode.WORKFLOW])67 @marshal_with(workflow_run_detail_fields)68 def get(self, app_model: App, run_id):69 """70 Get workflow run detail71 """72 run_id = str(run_id)73 74 workflow_run_service = WorkflowRunService()75 workflow_run = workflow_run_service.get_workflow_run(app_model=app_model, run_id=run_id)76 77 return workflow_run78 79 80class WorkflowRunNodeExecutionListApi(Resource):81 @setup_required82 @login_required83 @account_initialization_required84 @get_app_model(mode=[AppMode.ADVANCED_CHAT, AppMode.WORKFLOW])85 @marshal_with(workflow_run_node_execution_list_fields)86 def get(self, app_model: App, run_id):87 """88 Get workflow run node execution list89 """90 run_id = str(run_id)91 92 workflow_run_service = WorkflowRunService()93 node_executions = workflow_run_service.get_workflow_run_node_executions(app_model=app_model, run_id=run_id)94 95 return {"data": node_executions}96 97 98api.add_resource(AdvancedChatAppWorkflowRunListApi, "/apps/<uuid:app_id>/advanced-chat/workflow-runs")99api.add_resource(WorkflowRunListApi, "/apps/<uuid:app_id>/workflow-runs")100api.add_resource(WorkflowRunDetailApi, "/apps/<uuid:app_id>/workflow-runs/<uuid:run_id>")101api.add_resource(WorkflowRunNodeExecutionListApi, "/apps/<uuid:app_id>/workflow-runs/<uuid:run_id>/node-executions")102 