systemprompt_identifiers/
agent.rs1crate::define_id!(AgentId, generate, schema);
7crate::define_id!(ExternalAgentId, non_empty);
8
9use crate::error::IdValidationError;
10
11#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, schemars::JsonSchema)]
12#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
13#[cfg_attr(feature = "sqlx", sqlx(transparent))]
14#[serde(transparent)]
15pub struct AgentName(String);
16
17impl AgentName {
18 pub fn try_new(name: impl Into<String>) -> Result<Self, IdValidationError> {
19 let name = name.into();
20 if name.is_empty() {
21 return Err(IdValidationError::empty("AgentName"));
22 }
23 if name.eq_ignore_ascii_case("unknown") {
24 return Err(IdValidationError::invalid(
25 "AgentName",
26 "'unknown' is reserved for error detection",
27 ));
28 }
29 Ok(Self(name))
30 }
31
32 #[allow(clippy::expect_used)]
33 pub fn new(name: impl Into<String>) -> Self {
34 Self::try_new(name).expect("AgentName validation failed")
35 }
36
37 pub fn as_str(&self) -> &str {
38 &self.0
39 }
40
41 pub fn system() -> Self {
42 Self("system".to_string())
43 }
44}
45
46crate::__define_id_validated_conversions!(AgentName);
47crate::__define_id_common!(AgentName);