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