diff --git a/api/controllers/console/human_input_form.py b/api/controllers/console/human_input_form.py index dee1b1cb49..294d1f7bcc 100644 --- a/api/controllers/console/human_input_form.py +++ b/api/controllers/console/human_input_form.py @@ -2,7 +2,6 @@ Console/Studio Human Input Form APIs. """ -import json import logging from collections.abc import Generator diff --git a/api/models/workflow.py b/api/models/workflow.py index ef8d557f72..6788449680 100644 --- a/api/models/workflow.py +++ b/api/models/workflow.py @@ -406,12 +406,12 @@ class Workflow(Base): # bug return helper.generate_text_hash(json.dumps(entity, sort_keys=True)) + @property @deprecated( "This property is not accurate for determining if a workflow is published as a tool." "It only checks if there's a WorkflowToolProvider for the app, " "not if this specific workflow version is the one being used by the tool." ) - @property def tool_published(self) -> bool: """ DEPRECATED: This property is not accurate for determining if a workflow is published as a tool. diff --git a/api/repositories/entities/workflow_pause.py b/api/repositories/entities/workflow_pause.py index b970f39816..e3925af1e7 100644 --- a/api/repositories/entities/workflow_pause.py +++ b/api/repositories/entities/workflow_pause.py @@ -6,9 +6,39 @@ by the core workflow module. These models are independent of the storage mechani and don't contain implementation details like tenant_id, app_id, etc. """ +import enum from abc import ABC, abstractmethod from collections.abc import Sequence from datetime import datetime +from typing import Annotated, Literal, TypeAlias + +from pydantic import BaseModel, Field +from sqlalchemy import Sequence + + +class _PauseTypeEnum(enum.StrEnum): + human_input = enum.auto() + breakpoint = enum.auto() + scheduling = enum.auto() + + +class HumanInputPause(BaseModel): + type: Literal[_PauseTypeEnum.human_input] = _PauseTypeEnum.human_input + form_id: str + + +class SchedulingPause(BaseModel): + type: Literal[_PauseTypeEnum.scheduling] = _PauseTypeEnum.scheduling + + +PauseType: TypeAlias = Annotated[HumanInputPause | SchedulingPause, Field(discriminator="type")] + + +class PauseDetail(BaseModel): + node_id: str + node_title: str + pause_type: PauseType + from core.workflow.entities.pause_reason import PauseReason diff --git a/api/services/workflow_run_service.py b/api/services/workflow_run_service.py index b903d8df5f..d0f34d3a54 100644 --- a/api/services/workflow_run_service.py +++ b/api/services/workflow_run_service.py @@ -5,6 +5,7 @@ from sqlalchemy import Engine from sqlalchemy.orm import sessionmaker import contexts +from core.workflow.entities.workflow_pause import PauseDetail from extensions.ext_database import db from libs.infinite_scroll_pagination import InfiniteScrollPagination from models import ( @@ -159,3 +160,9 @@ class WorkflowRunService: app_id=app_model.id, workflow_run_id=run_id, ) + + def get_pause_details(self, workflow_run_id: str) -> Sequence[PauseDetail]: + pause = self._workflow_run_repo.get_workflow_pause(workflow_run_id) + if pause is None: + return [] + return pause.get_pause_details()