Skip to main content

agent_sdk_eval/
identity.rs

1//! Stable identifiers for evaluation framework records.
2
3use serde::{Deserialize, Deserializer, Serialize, de::Error as DeError};
4
5use agent_sdk_core::domain::{EntityId, IdValidationError};
6
7#[derive(Clone, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
8#[serde(transparent)]
9/// Stable identifier for an evaluation request or report.
10pub struct EvaluationId(EntityId);
11
12impl EvaluationId {
13    /// Creates a new evaluation id.
14    ///
15    /// # Panics
16    ///
17    /// Panics when the identifier is invalid. Use `try_new` for untrusted input.
18    pub fn new(value: impl Into<String>) -> Self {
19        Self::try_new(value).expect("EvaluationId must be valid")
20    }
21
22    /// Creates a new evaluation id and returns validation errors.
23    pub fn try_new(value: impl Into<String>) -> Result<Self, IdValidationError> {
24        EntityId::try_new(value).map(Self)
25    }
26
27    /// Returns the id as a string slice.
28    pub fn as_str(&self) -> &str {
29        self.0.as_str()
30    }
31}
32
33impl From<&str> for EvaluationId {
34    fn from(value: &str) -> Self {
35        Self::new(value)
36    }
37}
38
39impl<'de> Deserialize<'de> for EvaluationId {
40    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
41    where
42        D: Deserializer<'de>,
43    {
44        let value = String::deserialize(deserializer)?;
45        Self::try_new(value).map_err(D::Error::custom)
46    }
47}
48
49impl core::fmt::Debug for EvaluationId {
50    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
51        formatter.write_str("EvaluationId(redacted)")
52    }
53}