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 cowork() -> Self {
54        Self("sp_cowork".to_string())
55    }
56
57    pub fn system(service_name: &str) -> Self {
58        Self(format!("sys_{service_name}"))
59    }
60}
61
62#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
63#[serde(rename_all = "lowercase")]
64pub enum ClientType {
65    Cimd,
66    FirstParty,
67    ThirdParty,
68    System,
69    Unknown,
70}
71
72impl ClientType {
73    pub const fn as_str(self) -> &'static str {
74        match self {
75            Self::Cimd => "cimd",
76            Self::FirstParty => "firstparty",
77            Self::ThirdParty => "thirdparty",
78            Self::System => "system",
79            Self::Unknown => "unknown",
80        }
81    }
82}
83
84impl std::fmt::Display for ClientType {
85    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
86        write!(f, "{}", self.as_str())
87    }
88}