Skip to main content

systemprompt_identifiers/
agent.rs

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