use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SubagentTerminalStatus {
Success,
Failure,
Cancellation,
Timeout,
}
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct AgentRunRef {
pub session_id: String,
pub run_id: String,
}
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct DelegatedRunLineage {
pub parent: AgentRunRef,
pub child: AgentRunRef,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct FsWatchEvent {
pub kind: String,
pub paths: Vec<String>,
pub relative_paths: Vec<String>,
pub raw_kind: String,
pub error: Option<String>,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub enum WorkerEvent {
WorkerSpawned,
WorkerProgressed,
WorkerWaitingForInput,
WorkerSuspended,
WorkerResumed,
WorkerCompleted,
WorkerFailed,
WorkerStopped,
WorkerCancelled,
}
impl WorkerEvent {
pub const ALL: [Self; 9] = [
Self::WorkerSpawned,
Self::WorkerProgressed,
Self::WorkerWaitingForInput,
Self::WorkerSuspended,
Self::WorkerResumed,
Self::WorkerCompleted,
Self::WorkerFailed,
Self::WorkerStopped,
Self::WorkerCancelled,
];
pub fn as_status(self) -> &'static str {
match self {
Self::WorkerSpawned => "running",
Self::WorkerProgressed => "progressed",
Self::WorkerWaitingForInput => "awaiting_input",
Self::WorkerSuspended => "suspended",
Self::WorkerResumed => "running",
Self::WorkerCompleted => "completed",
Self::WorkerFailed => "failed",
Self::WorkerStopped => "stopped",
Self::WorkerCancelled => "cancelled",
}
}
pub fn as_str(self) -> &'static str {
match self {
Self::WorkerSpawned => "WorkerSpawned",
Self::WorkerProgressed => "WorkerProgressed",
Self::WorkerWaitingForInput => "WorkerWaitingForInput",
Self::WorkerSuspended => "WorkerSuspended",
Self::WorkerResumed => "WorkerResumed",
Self::WorkerCompleted => "WorkerCompleted",
Self::WorkerFailed => "WorkerFailed",
Self::WorkerStopped => "WorkerStopped",
Self::WorkerCancelled => "WorkerCancelled",
}
}
pub fn is_terminal(self) -> bool {
matches!(
self,
Self::WorkerCompleted
| Self::WorkerFailed
| Self::WorkerStopped
| Self::WorkerCancelled
)
}
pub fn from_status(status: &str) -> Option<Self> {
match status {
"running" => Some(Self::WorkerSpawned),
"progressed" => Some(Self::WorkerProgressed),
"awaiting_input" => Some(Self::WorkerWaitingForInput),
"suspended" => Some(Self::WorkerSuspended),
"completed" => Some(Self::WorkerCompleted),
"failed" => Some(Self::WorkerFailed),
"stopped" => Some(Self::WorkerStopped),
"cancelled" | "canceled" => Some(Self::WorkerCancelled),
_ => None,
}
}
pub fn status_is_terminal(status: &str) -> bool {
Self::from_status(status).is_some_and(Self::is_terminal)
}
}