Skip to main content

agent_storage/conversation/
conversation_id.rs

1//! Stable identifier assigned to a logical conversation.
2
3use serde::{Deserialize, Serialize};
4use std::str::FromStr;
5use uuid::Uuid;
6
7/// Stable identifier assigned to a logical conversation.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
9pub struct ConversationId(Uuid);
10
11impl ConversationId {
12    pub fn new() -> Self {
13        Self(Uuid::new_v4())
14    }
15}
16
17impl Default for ConversationId {
18    fn default() -> Self {
19        Self::new()
20    }
21}
22
23impl std::fmt::Display for ConversationId {
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        self.0.fmt(f)
26    }
27}
28
29impl FromStr for ConversationId {
30    type Err = uuid::Error;
31
32    fn from_str(value: &str) -> Result<Self, Self::Err> {
33        Uuid::parse_str(value).map(Self)
34    }
35}