systemprompt_models/execution/step/
enums.rs1use serde::{Deserialize, Serialize};
7
8use crate::errors::ParseEnumError;
9
10#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
11pub struct StepId(pub String);
12
13impl StepId {
14 #[must_use]
15 pub fn new() -> Self {
16 Self(uuid::Uuid::new_v4().to_string())
17 }
18
19 #[must_use]
20 pub fn as_str(&self) -> &str {
21 &self.0
22 }
23}
24
25impl Default for StepId {
26 fn default() -> Self {
27 Self::new()
28 }
29}
30
31impl From<String> for StepId {
32 fn from(s: String) -> Self {
33 Self(s)
34 }
35}
36
37impl std::fmt::Display for StepId {
38 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39 write!(f, "{}", self.0)
40 }
41}
42
43#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
44#[serde(rename_all = "snake_case")]
45pub enum StepStatus {
46 #[default]
47 Pending,
48 InProgress,
49 Completed,
50 Failed,
51}
52
53impl std::fmt::Display for StepStatus {
54 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55 match self {
56 Self::Pending => write!(f, "pending"),
57 Self::InProgress => write!(f, "in_progress"),
58 Self::Completed => write!(f, "completed"),
59 Self::Failed => write!(f, "failed"),
60 }
61 }
62}
63
64impl std::str::FromStr for StepStatus {
65 type Err = ParseEnumError;
66
67 fn from_str(s: &str) -> Result<Self, Self::Err> {
68 match s.to_lowercase().as_str() {
69 "pending" => Ok(Self::Pending),
70 "in_progress" | "running" | "active" => Ok(Self::InProgress),
71 "completed" | "done" | "success" => Ok(Self::Completed),
72 "failed" | "error" => Ok(Self::Failed),
73 _ => Err(ParseEnumError::new("step status", s)),
74 }
75 }
76}
77
78#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
79#[serde(rename_all = "snake_case")]
80pub enum StepType {
81 #[default]
82 Understanding,
83 Planning,
84 SkillUsage,
85 ToolExecution,
86 Completion,
87}
88
89impl std::fmt::Display for StepType {
90 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
91 match self {
92 Self::Understanding => write!(f, "understanding"),
93 Self::Planning => write!(f, "planning"),
94 Self::SkillUsage => write!(f, "skill_usage"),
95 Self::ToolExecution => write!(f, "tool_execution"),
96 Self::Completion => write!(f, "completion"),
97 }
98 }
99}
100
101impl std::str::FromStr for StepType {
102 type Err = ParseEnumError;
103
104 fn from_str(s: &str) -> Result<Self, Self::Err> {
105 match s.to_lowercase().as_str() {
106 "understanding" => Ok(Self::Understanding),
107 "planning" => Ok(Self::Planning),
108 "skill_usage" => Ok(Self::SkillUsage),
109 "tool_execution" | "toolexecution" => Ok(Self::ToolExecution),
110 "completion" => Ok(Self::Completion),
111 _ => Err(ParseEnumError::new("step type", s)),
112 }
113 }
114}