workflow_run.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. from flask_restful import Resource, marshal_with, reqparse # type: ignore
  2. from flask_restful.inputs import int_range # type: ignore
  3. from controllers.console import api
  4. from controllers.console.app.wraps import get_app_model
  5. from controllers.console.wraps import account_initialization_required, setup_required
  6. from fields.workflow_run_fields import (
  7. advanced_chat_workflow_run_pagination_fields,
  8. workflow_run_detail_fields,
  9. workflow_run_node_execution_list_fields,
  10. workflow_run_pagination_fields,
  11. )
  12. from libs.helper import uuid_value
  13. from libs.login import login_required
  14. from models import App
  15. from models.model import AppMode
  16. from services.workflow_run_service import WorkflowRunService
  17. class AdvancedChatAppWorkflowRunListApi(Resource):
  18. @setup_required
  19. @login_required
  20. @account_initialization_required
  21. @get_app_model(mode=[AppMode.ADVANCED_CHAT])
  22. @marshal_with(advanced_chat_workflow_run_pagination_fields)
  23. def get(self, app_model: App):
  24. """
  25. Get advanced chat app workflow run list
  26. """
  27. parser = reqparse.RequestParser()
  28. parser.add_argument("last_id", type=uuid_value, location="args")
  29. parser.add_argument("limit", type=int_range(1, 100), required=False, default=20, location="args")
  30. args = parser.parse_args()
  31. workflow_run_service = WorkflowRunService()
  32. result = workflow_run_service.get_paginate_advanced_chat_workflow_runs(app_model=app_model, args=args)
  33. return result
  34. class WorkflowRunListApi(Resource):
  35. @setup_required
  36. @login_required
  37. @account_initialization_required
  38. @get_app_model(mode=[AppMode.ADVANCED_CHAT, AppMode.WORKFLOW])
  39. @marshal_with(workflow_run_pagination_fields)
  40. def get(self, app_model: App):
  41. """
  42. Get workflow run list
  43. """
  44. parser = reqparse.RequestParser()
  45. parser.add_argument("last_id", type=uuid_value, location="args")
  46. parser.add_argument("limit", type=int_range(1, 100), required=False, default=20, location="args")
  47. args = parser.parse_args()
  48. workflow_run_service = WorkflowRunService()
  49. result = workflow_run_service.get_paginate_workflow_runs(app_model=app_model, args=args)
  50. return result
  51. class WorkflowRunDetailApi(Resource):
  52. @setup_required
  53. @login_required
  54. @account_initialization_required
  55. @get_app_model(mode=[AppMode.ADVANCED_CHAT, AppMode.WORKFLOW])
  56. @marshal_with(workflow_run_detail_fields)
  57. def get(self, app_model: App, run_id):
  58. """
  59. Get workflow run detail
  60. """
  61. run_id = str(run_id)
  62. workflow_run_service = WorkflowRunService()
  63. workflow_run = workflow_run_service.get_workflow_run(app_model=app_model, run_id=run_id)
  64. return workflow_run
  65. class WorkflowRunNodeExecutionListApi(Resource):
  66. @setup_required
  67. @login_required
  68. @account_initialization_required
  69. @get_app_model(mode=[AppMode.ADVANCED_CHAT, AppMode.WORKFLOW])
  70. @marshal_with(workflow_run_node_execution_list_fields)
  71. def get(self, app_model: App, run_id):
  72. """
  73. Get workflow run node execution list
  74. """
  75. run_id = str(run_id)
  76. workflow_run_service = WorkflowRunService()
  77. node_executions = workflow_run_service.get_workflow_run_node_executions(app_model=app_model, run_id=run_id)
  78. return {"data": node_executions}
  79. api.add_resource(AdvancedChatAppWorkflowRunListApi, "/apps/<uuid:app_id>/advanced-chat/workflow-runs")
  80. api.add_resource(WorkflowRunListApi, "/apps/<uuid:app_id>/workflow-runs")
  81. api.add_resource(WorkflowRunDetailApi, "/apps/<uuid:app_id>/workflow-runs/<uuid:run_id>")
  82. api.add_resource(WorkflowRunNodeExecutionListApi, "/apps/<uuid:app_id>/workflow-runs/<uuid:run_id>/node-executions")