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