use crate::types::{AgentId, AgentMeta, KillReason, KillTrigger, RuntimeState};
use async_trait::async_trait;
use futures_core::stream::BoxStream;
use thiserror::Error;
#[derive(Clone, Debug)]
#[non_exhaustive]
pub enum Status {
Idle,
Busy,
Drained,
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub enum SupervisorEvent {
Registered(AgentId),
Heartbeat(AgentId),
StallDetected {
agent: AgentId,
missed: u32,
},
KillSwitchTripped {
reason: String,
},
StateChanged(RuntimeState),
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum SupervisorError {
#[error("storage unavailable: {0}")]
Storage(String),
#[error("unknown agent: {0}")]
UnknownAgent(AgentId),
#[error("internal: {0}")]
Internal(String),
}
#[async_trait]
pub trait Supervisor: Send + Sync {
async fn register(&self, agent: AgentId, meta: AgentMeta) -> Result<(), SupervisorError>;
async fn heartbeat(&self, agent: AgentId) -> Result<(), SupervisorError>;
async fn report(&self, agent: AgentId, status: Status) -> Result<(), SupervisorError>;
async fn watch(&self) -> BoxStream<'static, SupervisorEvent>;
async fn trip_kill_switch(
&self,
reason: KillReason,
trigger: KillTrigger,
) -> Result<(), SupervisorError>;
async fn runtime_state(&self) -> RuntimeState;
}