Skip to main content

systemprompt_identifiers/
client.rs

1crate::define_id!(ClientId);
2
3impl ClientId {
4    pub fn client_type(&self) -> ClientType {
5        if self.0.starts_with("https://") {
6            ClientType::Cimd
7        } else if self.0.starts_with("sp_") {
8            ClientType::FirstParty
9        } else if self.0.starts_with("client_") {
10            ClientType::ThirdParty
11        } else if self.0.starts_with("sys_") {
12            ClientType::System
13        } else {
14            ClientType::Unknown
15        }
16    }
17
18    pub fn is_dcr(&self) -> bool {
19        matches!(
20            self.client_type(),
21            ClientType::FirstParty | ClientType::ThirdParty
22        )
23    }
24
25    pub fn is_cimd(&self) -> bool {
26        self.0.starts_with("https://")
27    }
28
29    pub fn is_system(&self) -> bool {
30        self.0.starts_with("sys_")
31    }
32
33    pub fn web() -> Self {
34        Self("sp_web".to_string())
35    }
36
37    pub fn cli() -> Self {
38        Self("sp_cli".to_string())
39    }
40
41    pub fn mobile_ios() -> Self {
42        Self("sp_mobile_ios".to_string())
43    }
44
45    pub fn mobile_android() -> Self {
46        Self("sp_mobile_android".to_string())
47    }
48
49    pub fn desktop() -> Self {
50        Self("sp_desktop".to_string())
51    }
52
53    pub fn system(service_name: &str) -> Self {
54        Self(format!("sys_{service_name}"))
55    }
56}
57
58#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
59#[serde(rename_all = "lowercase")]
60pub enum ClientType {
61    Cimd,
62    FirstParty,
63    ThirdParty,
64    System,
65    Unknown,
66}
67
68impl ClientType {
69    pub const fn as_str(self) -> &'static str {
70        match self {
71            Self::Cimd => "cimd",
72            Self::FirstParty => "firstparty",
73            Self::ThirdParty => "thirdparty",
74            Self::System => "system",
75            Self::Unknown => "unknown",
76        }
77    }
78}
79
80impl std::fmt::Display for ClientType {
81    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
82        write!(f, "{}", self.as_str())
83    }
84}