2025-09-18 04:49:10 +00:00
|
|
|
from pydantic import Field
|
|
|
|
|
|
2026-03-02 10:42:30 +00:00
|
|
|
from dify_graph.entities.pause_reason import PauseReason
|
|
|
|
|
from dify_graph.entities.workflow_start_reason import WorkflowStartReason
|
|
|
|
|
from dify_graph.graph_events import BaseGraphEvent
|
2025-09-18 04:49:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class GraphRunStartedEvent(BaseGraphEvent):
|
2026-02-09 06:57:23 +00:00
|
|
|
# Reason is emitted for workflow start events and is always set.
|
|
|
|
|
reason: WorkflowStartReason = Field(
|
|
|
|
|
default=WorkflowStartReason.INITIAL,
|
|
|
|
|
description="reason for workflow start",
|
|
|
|
|
)
|
2025-09-18 04:49:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class GraphRunSucceededEvent(BaseGraphEvent):
|
2025-10-19 13:33:41 +00:00
|
|
|
"""Event emitted when a run completes successfully with final outputs."""
|
|
|
|
|
|
|
|
|
|
outputs: dict[str, object] = Field(
|
|
|
|
|
default_factory=dict,
|
|
|
|
|
description="Final workflow outputs keyed by output selector.",
|
|
|
|
|
)
|
2025-09-18 04:49:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class GraphRunFailedEvent(BaseGraphEvent):
|
|
|
|
|
error: str = Field(..., description="failed reason")
|
|
|
|
|
exceptions_count: int = Field(description="exception count", default=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GraphRunPartialSucceededEvent(BaseGraphEvent):
|
2025-10-19 13:33:41 +00:00
|
|
|
"""Event emitted when a run finishes with partial success and failures."""
|
|
|
|
|
|
2025-09-18 04:49:10 +00:00
|
|
|
exceptions_count: int = Field(..., description="exception count")
|
2025-10-19 13:33:41 +00:00
|
|
|
outputs: dict[str, object] = Field(
|
|
|
|
|
default_factory=dict,
|
|
|
|
|
description="Outputs that were materialised before failures occurred.",
|
|
|
|
|
)
|
2025-09-18 04:49:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class GraphRunAbortedEvent(BaseGraphEvent):
|
|
|
|
|
"""Event emitted when a graph run is aborted by user command."""
|
|
|
|
|
|
|
|
|
|
reason: str | None = Field(default=None, description="reason for abort")
|
2025-10-19 13:33:41 +00:00
|
|
|
outputs: dict[str, object] = Field(
|
|
|
|
|
default_factory=dict,
|
|
|
|
|
description="Outputs produced before the abort was requested.",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GraphRunPausedEvent(BaseGraphEvent):
|
|
|
|
|
"""Event emitted when a graph run is paused by user command."""
|
|
|
|
|
|
2025-11-26 11:59:34 +00:00
|
|
|
reasons: list[PauseReason] = Field(description="reason for pause", default_factory=list)
|
2025-10-19 13:33:41 +00:00
|
|
|
outputs: dict[str, object] = Field(
|
|
|
|
|
default_factory=dict,
|
|
|
|
|
description="Outputs available to the client while the run is paused.",
|
|
|
|
|
)
|