use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::kernel::identity::{RunId, Seq};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum Event {
StateUpdated {
step_id: Option<String>,
payload: Value,
},
ActionRequested {
action_id: String,
payload: Value,
},
ActionSucceeded { action_id: String, output: Value },
ActionFailed { action_id: String, error: String },
Interrupted { value: Value },
Resumed { value: Value },
Completed,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SequencedEvent {
pub seq: Seq,
pub event: Event,
}
pub trait EventStore: Send + Sync {
fn append(&self, run_id: &RunId, events: &[Event]) -> Result<Seq, KernelError>;
fn scan(&self, run_id: &RunId, from: Seq) -> Result<Vec<SequencedEvent>, KernelError>;
fn head(&self, run_id: &RunId) -> Result<Seq, KernelError>;
}
#[derive(Debug, thiserror::Error)]
pub enum KernelError {
#[error("EventStore error: {0}")]
EventStore(String),
#[error("SnapshotStore error: {0}")]
SnapshotStore(String),
#[error("Reducer error: {0}")]
Reducer(String),
#[error("Policy error: {0}")]
Policy(String),
#[error("Driver error: {0}")]
Driver(String),
#[error("Executor: {0}")]
Executor(crate::kernel::action::ActionError),
}