systemprompt_identifiers/
ai.rs1use crate::{DbValue, ToDbValue};
4use schemars::JsonSchema;
5use serde::{Deserialize, Serialize};
6use std::fmt;
7
8#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
9#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
10#[cfg_attr(feature = "sqlx", sqlx(transparent))]
11#[serde(transparent)]
12pub struct AiRequestId(String);
13
14impl AiRequestId {
15 pub fn new(id: impl Into<String>) -> Self {
16 Self(id.into())
17 }
18
19 pub fn generate() -> Self {
20 Self(uuid::Uuid::new_v4().to_string())
21 }
22
23 pub fn as_str(&self) -> &str {
24 &self.0
25 }
26}
27
28impl fmt::Display for AiRequestId {
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 write!(f, "{}", self.0)
31 }
32}
33
34impl From<String> for AiRequestId {
35 fn from(s: String) -> Self {
36 Self(s)
37 }
38}
39
40impl From<&str> for AiRequestId {
41 fn from(s: &str) -> Self {
42 Self(s.to_string())
43 }
44}
45
46impl AsRef<str> for AiRequestId {
47 fn as_ref(&self) -> &str {
48 &self.0
49 }
50}
51
52impl ToDbValue for AiRequestId {
53 fn to_db_value(&self) -> DbValue {
54 DbValue::String(self.0.clone())
55 }
56}
57
58impl ToDbValue for &AiRequestId {
59 fn to_db_value(&self) -> DbValue {
60 DbValue::String(self.0.clone())
61 }
62}
63
64#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
65#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
66#[cfg_attr(feature = "sqlx", sqlx(transparent))]
67#[serde(transparent)]
68pub struct MessageId(String);
69
70impl MessageId {
71 pub fn new(id: impl Into<String>) -> Self {
72 Self(id.into())
73 }
74
75 pub fn generate() -> Self {
76 Self(uuid::Uuid::new_v4().to_string())
77 }
78
79 pub fn as_str(&self) -> &str {
80 &self.0
81 }
82}
83
84impl fmt::Display for MessageId {
85 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
86 write!(f, "{}", self.0)
87 }
88}
89
90impl From<String> for MessageId {
91 fn from(s: String) -> Self {
92 Self(s)
93 }
94}
95
96impl From<&str> for MessageId {
97 fn from(s: &str) -> Self {
98 Self(s.to_string())
99 }
100}
101
102impl AsRef<str> for MessageId {
103 fn as_ref(&self) -> &str {
104 &self.0
105 }
106}
107
108impl ToDbValue for MessageId {
109 fn to_db_value(&self) -> DbValue {
110 DbValue::String(self.0.clone())
111 }
112}
113
114impl ToDbValue for &MessageId {
115 fn to_db_value(&self) -> DbValue {
116 DbValue::String(self.0.clone())
117 }
118}
119
120impl From<MessageId> for String {
121 fn from(id: MessageId) -> Self {
122 id.0
123 }
124}
125
126impl From<&MessageId> for String {
127 fn from(id: &MessageId) -> Self {
128 id.0.clone()
129 }
130}
131
132impl PartialEq<&str> for MessageId {
133 fn eq(&self, other: &&str) -> bool {
134 self.0 == *other
135 }
136}
137
138impl std::borrow::Borrow<str> for MessageId {
139 fn borrow(&self) -> &str {
140 &self.0
141 }
142}
143
144#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
145#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
146#[cfg_attr(feature = "sqlx", sqlx(transparent))]
147#[serde(transparent)]
148pub struct ConfigId(String);
149
150impl ConfigId {
151 pub fn new(id: impl Into<String>) -> Self {
152 Self(id.into())
153 }
154
155 pub fn generate() -> Self {
156 Self(uuid::Uuid::new_v4().to_string())
157 }
158
159 pub fn as_str(&self) -> &str {
160 &self.0
161 }
162}
163
164impl fmt::Display for ConfigId {
165 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
166 write!(f, "{}", self.0)
167 }
168}
169
170impl From<String> for ConfigId {
171 fn from(s: String) -> Self {
172 Self(s)
173 }
174}
175
176impl From<&str> for ConfigId {
177 fn from(s: &str) -> Self {
178 Self(s.to_string())
179 }
180}
181
182impl AsRef<str> for ConfigId {
183 fn as_ref(&self) -> &str {
184 &self.0
185 }
186}
187
188impl ToDbValue for ConfigId {
189 fn to_db_value(&self) -> DbValue {
190 DbValue::String(self.0.clone())
191 }
192}
193
194impl ToDbValue for &ConfigId {
195 fn to_db_value(&self) -> DbValue {
196 DbValue::String(self.0.clone())
197 }
198}