use std::fmt;
use uuid::Uuid;
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct MemoryId(Uuid);
impl MemoryId {
pub fn new() -> Self {
Self(Uuid::new_v4())
}
pub fn as_uuid(&self) -> &Uuid {
&self.0
}
}
impl Default for MemoryId {
fn default() -> Self {
Self::new()
}
}
impl fmt::Display for MemoryId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl From<Uuid> for MemoryId {
fn from(u: Uuid) -> Self {
Self(u)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct AgentId(Uuid);
impl AgentId {
pub fn new() -> Self {
Self(Uuid::new_v4())
}
}
impl Default for AgentId {
fn default() -> Self {
Self::new()
}
}
impl fmt::Display for AgentId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct SessionId(Uuid);
impl SessionId {
pub fn new() -> Self {
Self(Uuid::new_v4())
}
}
impl Default for SessionId {
fn default() -> Self {
Self::new()
}
}
impl fmt::Display for SessionId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct NamespaceId(String);
impl NamespaceId {
pub fn new(s: impl Into<String>) -> Self {
Self(s.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl fmt::Display for NamespaceId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct EntityId(String);
impl EntityId {
pub fn new(s: impl Into<String>) -> Self {
Self(s.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl fmt::Display for EntityId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct Tag(String);
impl Tag {
pub fn new(s: impl Into<String>) -> Self {
Self(s.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl fmt::Display for Tag {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_memory_id_new_is_unique() {
let a = MemoryId::new();
let b = MemoryId::new();
assert_ne!(a, b);
}
#[test]
fn test_memory_id_display_contains_uuid() {
let id = MemoryId::new();
let s = id.to_string();
assert_eq!(s.len(), 36);
}
#[test]
fn test_memory_id_display_is_stable() {
let id = MemoryId::new();
assert_eq!(id.to_string(), id.to_string());
}
#[test]
fn test_agent_id_display_is_stable() {
let id = AgentId::new();
assert_eq!(id.to_string(), id.to_string());
}
#[test]
fn test_session_id_display_is_stable() {
let id = SessionId::new();
assert_eq!(id.to_string(), id.to_string());
}
#[test]
fn test_namespace_id_display_returns_inner() {
let ns = NamespaceId::new("test-ns");
assert_eq!(ns.to_string(), "test-ns");
}
#[test]
fn test_entity_id_display_returns_inner() {
let e = EntityId::new("user:99");
assert_eq!(e.to_string(), "user:99");
}
#[test]
fn test_tag_display_returns_inner() {
let t = Tag::new("critical");
assert_eq!(t.to_string(), "critical");
}
#[test]
fn test_memory_id_clone_equals_original() {
let a = MemoryId::new();
let b = a.clone();
assert_eq!(a, b);
}
#[test]
fn test_memory_id_from_uuid_roundtrip() {
let u = Uuid::new_v4();
let id = MemoryId::from(u);
assert_eq!(id.as_uuid(), &u);
}
#[test]
fn test_tag_as_str() {
let t = Tag::new("foo");
assert_eq!(t.as_str(), "foo");
}
#[test]
fn test_entity_id_as_str() {
let e = EntityId::new("bar");
assert_eq!(e.as_str(), "bar");
}
}