#[cfg(test)]
use super::mob_orchestrator_authority::MobOrchestratorSnapshot;
use super::*;
use crate::run::MobRun;
#[cfg(target_arch = "wasm32")]
use crate::tokio;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum MobState {
Creating = 0,
Running = 1,
Stopped = 2,
Completed = 3,
Destroyed = 4,
}
impl MobState {
pub(super) fn from_u8(v: u8) -> Self {
match v {
0 => Self::Creating,
1 => Self::Running,
2 => Self::Stopped,
3 => Self::Completed,
4 => Self::Destroyed,
_ => {
debug_assert!(false, "invalid mob lifecycle state byte: {v}");
tracing::error!(state_byte = v, "invalid mob lifecycle state byte");
Self::Destroyed
}
}
}
pub fn as_str(self) -> &'static str {
match self {
Self::Creating => "Creating",
Self::Running => "Running",
Self::Stopped => "Stopped",
Self::Completed => "Completed",
Self::Destroyed => "Destroyed",
}
}
}
impl std::fmt::Display for MobState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
pub(super) enum MobCommand {
Spawn {
spec: Box<super::handle::SpawnMemberSpec>,
owner_session_id: Option<SessionId>,
ops_registry: Option<Arc<dyn meerkat_core::ops_lifecycle::OpsLifecycleRegistry>>,
reply_tx: oneshot::Sender<Result<super::handle::MemberSpawnReceipt, MobError>>,
},
SpawnProvisioned {
spawn_ticket: u64,
result: Result<super::handle::MemberSpawnReceipt, MobError>,
},
Retire {
meerkat_id: MeerkatId,
reply_tx: oneshot::Sender<Result<(), MobError>>,
},
Respawn {
meerkat_id: MeerkatId,
initial_message: Option<ContentInput>,
reply_tx: oneshot::Sender<
Result<super::handle::MemberRespawnReceipt, super::handle::MobRespawnError>,
>,
},
RetireAll {
reply_tx: oneshot::Sender<Result<(), MobError>>,
},
Wire {
local: MeerkatId,
target: super::handle::PeerTarget,
reply_tx: oneshot::Sender<Result<(), MobError>>,
},
Unwire {
local: MeerkatId,
target: super::handle::PeerTarget,
reply_tx: oneshot::Sender<Result<(), MobError>>,
},
ExternalTurn {
meerkat_id: MeerkatId,
content: ContentInput,
handling_mode: meerkat_core::types::HandlingMode,
render_metadata: Option<meerkat_core::types::RenderMetadata>,
reply_tx: oneshot::Sender<Result<SessionId, MobError>>,
},
InternalTurn {
meerkat_id: MeerkatId,
content: ContentInput,
reply_tx: oneshot::Sender<Result<SessionId, MobError>>,
},
KickoffBarrierSnapshot {
meerkat_ids: Vec<MeerkatId>,
reply_tx: oneshot::Sender<Vec<(MeerkatId, tokio::sync::watch::Receiver<bool>)>>,
},
KickoffOutcomeResolved {
meerkat_id: MeerkatId,
outcome: meerkat_runtime::completion::CompletionOutcome,
ack_tx: oneshot::Sender<()>,
},
RunFlow {
flow_id: FlowId,
activation_params: serde_json::Value,
scoped_event_tx: Option<tokio::sync::mpsc::Sender<meerkat_core::ScopedAgentEvent>>,
reply_tx: oneshot::Sender<Result<RunId, MobError>>,
},
CancelFlow {
run_id: RunId,
reply_tx: oneshot::Sender<Result<(), MobError>>,
},
FlowStatus {
run_id: RunId,
reply_tx: oneshot::Sender<Result<Option<MobRun>, MobError>>,
},
FlowFinished {
run_id: RunId,
},
FlowCanceledCleanup {
run_id: RunId,
},
#[cfg(test)]
FlowTrackerCounts {
reply_tx: oneshot::Sender<(usize, usize)>,
},
#[cfg(test)]
OrchestratorSnapshot {
reply_tx: oneshot::Sender<MobOrchestratorSnapshot>,
},
Stop {
reply_tx: oneshot::Sender<Result<(), MobError>>,
},
ResumeLifecycle {
reply_tx: oneshot::Sender<Result<(), MobError>>,
},
Complete {
reply_tx: oneshot::Sender<Result<(), MobError>>,
},
Destroy {
reply_tx: oneshot::Sender<Result<(), MobError>>,
},
Reset {
reply_tx: oneshot::Sender<Result<(), MobError>>,
},
TaskCreate {
subject: String,
description: String,
blocked_by: Vec<TaskId>,
reply_tx: oneshot::Sender<Result<TaskId, MobError>>,
},
TaskUpdate {
task_id: TaskId,
status: TaskStatus,
owner: Option<MeerkatId>,
reply_tx: oneshot::Sender<Result<(), MobError>>,
},
ForceCancel {
meerkat_id: MeerkatId,
reply_tx: oneshot::Sender<Result<(), MobError>>,
},
SetSpawnPolicy {
policy: Option<Arc<dyn super::spawn_policy::SpawnPolicy>>,
reply_tx: oneshot::Sender<()>,
},
Shutdown {
reply_tx: oneshot::Sender<Result<(), MobError>>,
},
}