1use serde::{Deserialize, Serialize};
2use std::fmt;
3use uuid::Uuid;
4
5macro_rules! id_newtype {
6 ($name:ident, $prefix:literal) => {
7 #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
8 #[serde(transparent)]
9 pub struct $name(String);
10
11 impl $name {
12 pub fn new() -> Self {
13 Self(format!("{}-{}", $prefix, Uuid::new_v4()))
14 }
15
16 #[allow(clippy::should_implement_trait)]
17 pub fn from_str(s: impl Into<String>) -> Self {
18 Self(s.into())
19 }
20
21 pub fn as_str(&self) -> &str {
22 &self.0
23 }
24 }
25
26 impl Default for $name {
27 fn default() -> Self {
28 Self::new()
29 }
30 }
31
32 impl fmt::Display for $name {
33 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34 f.write_str(&self.0)
35 }
36 }
37
38 impl From<String> for $name {
39 fn from(s: String) -> Self {
40 Self(s)
41 }
42 }
43
44 impl From<&str> for $name {
45 fn from(s: &str) -> Self {
46 Self(s.to_owned())
47 }
48 }
49 };
50}
51
52id_newtype!(AgentId, "agent");
53id_newtype!(TeamId, "team");
54id_newtype!(DepartmentId, "dept");
55id_newtype!(OrgId, "org");
56id_newtype!(WorkflowId, "wf");
57id_newtype!(HarnessId, "harness");
58id_newtype!(ToolId, "tool");
59id_newtype!(ToolSetId, "toolset");
60id_newtype!(SkillId, "skill");
61id_newtype!(PersonaId, "persona");
62id_newtype!(RunId, "run");