workflow.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from datetime import datetime
  2. from typing import TYPE_CHECKING
  3. from pydantic import BaseModel
  4. from core_shared import JSONValue
  5. if TYPE_CHECKING:
  6. from app.db.models import WorkflowDefinitionModel, WorkflowVersion
  7. class WorkflowCreateRequest(BaseModel):
  8. tenant_id: str
  9. app_id: str
  10. code: str
  11. name: str
  12. workflow_type: str = "main"
  13. class WorkflowDefinitionResponse(BaseModel):
  14. id: str
  15. tenant_id: str
  16. app_id: str
  17. code: str
  18. name: str
  19. workflow_type: str
  20. latest_version_no: int
  21. created_time: datetime
  22. @classmethod
  23. def from_entity(cls, entity: "WorkflowDefinitionModel") -> "WorkflowDefinitionResponse":
  24. return cls.model_validate(entity, from_attributes=True)
  25. class WorkflowVersionCreateRequest(BaseModel):
  26. tenant_id: str
  27. workflow_id: str
  28. dsl_json: dict[str, JSONValue] | None = None
  29. compiled_plan_json: dict[str, JSONValue] | None = None
  30. schema_version: str | None = None
  31. checksum: str | None = None
  32. status: str = "draft"
  33. class WorkflowVersionResponse(BaseModel):
  34. id: str
  35. tenant_id: str
  36. workflow_id: str
  37. version_no: int
  38. dsl_json: dict[str, JSONValue] | None = None
  39. compiled_plan_json: dict[str, JSONValue] | None = None
  40. schema_version: str | None = None
  41. checksum: str | None = None
  42. status: str
  43. created_time: datetime
  44. @classmethod
  45. def from_entity(cls, entity: "WorkflowVersion") -> "WorkflowVersionResponse":
  46. return cls.model_validate(entity, from_attributes=True)