use agent_client_protocol::schema::v2 as acp;
use schemars::JsonSchema;
use serde::Serialize;
use thiserror::Error;
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum TurnPhase {
#[default]
Idle,
Submitting,
Running,
CompletedBeforeAcceptance,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TurnFinished {
pub stop_reason: Option<acp::StopReason>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
#[error("the session is already in a turn")]
pub struct TurnInProgress;
impl TurnPhase {
pub fn is_idle(self) -> bool {
self == Self::Idle
}
pub fn waiting_for_response(self) -> bool {
matches!(self, Self::Submitting | Self::Running)
}
pub(super) fn accepted(self) -> Self {
match self {
Self::Submitting => Self::Running,
Self::CompletedBeforeAcceptance => Self::Idle,
Self::Idle | Self::Running => self,
}
}
pub(super) fn finished(self) -> Self {
match self {
Self::Submitting => Self::CompletedBeforeAcceptance,
Self::Running => Self::Idle,
Self::Idle | Self::CompletedBeforeAcceptance => self,
}
}
}