use serde::{Deserialize, Serialize};
use crate::state::State;
use crate::workflow_state::WorkflowState;
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct CheckpointId(pub uuid::Uuid);
impl std::fmt::Display for CheckpointId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct NodeId(pub String);
impl std::fmt::Display for NodeId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Checkpoint<S = State> {
pub checkpoint_id: CheckpointId,
pub current_node: NodeId,
pub state: S,
pub graph_hash: u64,
pub created_at: std::time::SystemTime,
}
impl<S: WorkflowState> Checkpoint<S> {
pub fn new(current_node: impl Into<String>, state: S, graph_hash: u64) -> Self {
Self {
checkpoint_id: CheckpointId(uuid::Uuid::new_v4()),
current_node: NodeId(current_node.into()),
state,
graph_hash,
created_at: std::time::SystemTime::now(),
}
}
}
#[derive(Debug, Clone)]
pub struct CheckpointBlob {
pub id: CheckpointId,
pub data: Vec<u8>,
pub graph_hash: u64,
pub created_at: std::time::SystemTime,
}
impl CheckpointBlob {
pub fn new(
id: CheckpointId,
data: Vec<u8>,
graph_hash: u64,
created_at: std::time::SystemTime,
) -> Self {
Self {
id,
data,
graph_hash,
created_at,
}
}
}
#[derive(Debug, thiserror::Error)]
pub enum CheckpointStoreError {
#[error("storage error: {0}")]
Storage(String),
#[error("checkpoint not found: {0}")]
NotFound(CheckpointId),
#[error("corrupted checkpoint: {0}")]
Corrupted(String),
#[error("serialization error: {0}")]
Serialization(String),
#[error("graph mismatch: expected hash {expected:#018x}, got {actual:#018x}")]
GraphMismatch { expected: u64, actual: u64 },
}
pub use crate::ids::TraceId;
#[allow(deprecated)]
#[doc(inline)]
pub use crate::checkpoint_policy::CheckpointPolicy;