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