use serde::{Deserialize, Serialize};
use crate::graph::command::Interrupt;
use crate::harness::ids::{CheckpointId, NodeId, RunId};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum GraphEvent {
RunStarted {
run_id: RunId,
},
RunCompleted {
run_id: RunId,
steps: usize,
},
RunFailed {
run_id: RunId,
error: String,
},
StepStarted {
step: usize,
active: Vec<NodeId>,
},
StepCompleted {
step: usize,
},
TaskScheduled {
node: NodeId,
step: usize,
},
NodeStarted {
node: NodeId,
step: usize,
},
NodeCompleted {
node: NodeId,
step: usize,
},
NodeFailed {
node: NodeId,
step: usize,
error: String,
},
StateUpdated {
node: NodeId,
step: usize,
},
RouteSelected {
node: NodeId,
target: NodeId,
},
CheckpointSaved {
checkpoint_id: CheckpointId,
},
InterruptEmitted {
interrupt: Interrupt,
},
SubgraphStarted {
node: NodeId,
namespace: Vec<String>,
},
SubgraphCompleted {
node: NodeId,
namespace: Vec<String>,
},
ContextForked {
node: NodeId,
fork: usize,
step: usize,
},
RecursionDepthChanged {
depth: usize,
},
Custom {
name: String,
data: serde_json::Value,
},
}
impl GraphEvent {
pub fn kind(&self) -> &'static str {
match self {
GraphEvent::RunStarted { .. } => "run.started",
GraphEvent::RunCompleted { .. } => "run.completed",
GraphEvent::RunFailed { .. } => "run.failed",
GraphEvent::StepStarted { .. } => "step.started",
GraphEvent::StepCompleted { .. } => "step.completed",
GraphEvent::TaskScheduled { .. } => "task.scheduled",
GraphEvent::NodeStarted { .. } => "node.started",
GraphEvent::NodeCompleted { .. } => "node.completed",
GraphEvent::NodeFailed { .. } => "node.failed",
GraphEvent::StateUpdated { .. } => "state.updated",
GraphEvent::RouteSelected { .. } => "route.selected",
GraphEvent::CheckpointSaved { .. } => "checkpoint.saved",
GraphEvent::InterruptEmitted { .. } => "interrupt.emitted",
GraphEvent::SubgraphStarted { .. } => "subgraph.started",
GraphEvent::SubgraphCompleted { .. } => "subgraph.completed",
GraphEvent::ContextForked { .. } => "context.forked",
GraphEvent::RecursionDepthChanged { .. } => "recursion.depth_changed",
GraphEvent::Custom { .. } => "custom",
}
}
pub fn step(&self) -> Option<usize> {
match self {
GraphEvent::StepStarted { step, .. }
| GraphEvent::StepCompleted { step }
| GraphEvent::TaskScheduled { step, .. }
| GraphEvent::NodeStarted { step, .. }
| GraphEvent::NodeCompleted { step, .. }
| GraphEvent::NodeFailed { step, .. }
| GraphEvent::StateUpdated { step, .. }
| GraphEvent::ContextForked { step, .. } => Some(*step),
GraphEvent::RunCompleted { steps, .. } => Some(*steps),
_ => None,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum StreamMode {
Values,
Updates,
Messages,
Debug,
Interrupts,
Custom,
}