-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresult.py
More file actions
56 lines (41 loc) · 1.7 KB
/
result.py
File metadata and controls
56 lines (41 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Result of an execution with status and optional error information."""
from enum import Enum
from typing import Any
from pydantic import BaseModel, Field
from uipath.runtime.errors import UiPathErrorContract
from uipath.runtime.events import UiPathRuntimeEvent, UiPathRuntimeEventType
from uipath.runtime.resumable.trigger import UiPathResumeTrigger
class UiPathRuntimeStatus(str, Enum):
"""Standard status values for runtime execution."""
SUCCESSFUL = "successful"
FAULTED = "faulted"
SUSPENDED = "suspended"
class UiPathRuntimeResult(UiPathRuntimeEvent):
"""Result of an execution with status and optional error information."""
output: dict[str, Any] | BaseModel | str | None = None
status: UiPathRuntimeStatus = UiPathRuntimeStatus.SUCCESSFUL
trigger: UiPathResumeTrigger | None = None
error: UiPathErrorContract | None = None
event_type: UiPathRuntimeEventType = Field(
default=UiPathRuntimeEventType.RUNTIME_RESULT, frozen=True
)
def to_dict(self) -> dict[str, Any]:
"""Convert to dictionary format for output."""
output_data: dict[str, Any] | str
if self.output is None:
output_data = {}
elif isinstance(self.output, BaseModel):
output_data = self.output.model_dump()
elif isinstance(self.output, str):
output_data = {"output": self.output}
else:
output_data = self.output
result = {
"output": output_data,
"status": self.status,
}
if self.trigger:
result["resume"] = self.trigger.model_dump(by_alias=True)
if self.error:
result["error"] = self.error.model_dump()
return result