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