lellm_graph/
checkpoint.rs1use serde::{Deserialize, Serialize};
21
22use crate::state::State;
23use crate::workflow_state::WorkflowState;
24
25#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
29pub struct CheckpointId(pub uuid::Uuid);
30
31impl std::fmt::Display for CheckpointId {
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 write!(f, "{}", self.0)
34 }
35}
36
37#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
41pub struct NodeId(pub String);
42
43impl std::fmt::Display for NodeId {
44 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45 write!(f, "{}", self.0)
46 }
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
61pub struct Checkpoint<S = State> {
62 pub checkpoint_id: CheckpointId,
64 pub current_node: NodeId,
66 pub state: S,
68 pub graph_hash: u64,
70 pub created_at: std::time::SystemTime,
72}
73
74impl<S: WorkflowState> Checkpoint<S> {
75 pub fn new(current_node: impl Into<String>, state: S, graph_hash: u64) -> Self {
76 Self {
77 checkpoint_id: CheckpointId(uuid::Uuid::new_v4()),
78 current_node: NodeId(current_node.into()),
79 state,
80 graph_hash,
81 created_at: std::time::SystemTime::now(),
82 }
83 }
84}
85
86#[derive(Debug, Clone)]
96pub struct CheckpointBlob {
97 pub id: CheckpointId,
99 pub data: Vec<u8>,
101 pub graph_hash: u64,
103 pub created_at: std::time::SystemTime,
105}
106
107impl CheckpointBlob {
108 pub fn new(
109 id: CheckpointId,
110 data: Vec<u8>,
111 graph_hash: u64,
112 created_at: std::time::SystemTime,
113 ) -> Self {
114 Self {
115 id,
116 data,
117 graph_hash,
118 created_at,
119 }
120 }
121}
122
123#[derive(Debug, thiserror::Error)]
127pub enum CheckpointStoreError {
128 #[error("storage error: {0}")]
129 Storage(String),
130 #[error("checkpoint not found: {0}")]
131 NotFound(CheckpointId),
132 #[error("corrupted checkpoint: {0}")]
133 Corrupted(String),
134 #[error("serialization error: {0}")]
135 Serialization(String),
136 #[error("graph mismatch: expected hash {expected:#018x}, got {actual:#018x}")]
137 GraphMismatch { expected: u64, actual: u64 },
138}
139
140pub use crate::ids::TraceId;
147
148#[allow(deprecated)]
153#[doc(inline)]
154pub use crate::checkpoint_policy::CheckpointPolicy;