use std::time::Instant;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GenerationStatus {
Idle,
Sending,
Thinking,
Streaming,
}
impl GenerationStatus {
pub fn display_text(&self) -> &str {
match self {
GenerationStatus::Idle => "Idle",
GenerationStatus::Sending => "Sending",
GenerationStatus::Thinking => "Thinking",
GenerationStatus::Streaming => "Streaming",
}
}
}
#[derive(Debug, Clone)]
pub enum AppState {
Idle,
Generating {
status: GenerationStatus,
start_time: Instant,
tokens_received: usize,
abort_handle: Option<tokio::task::AbortHandle>,
response_buffer: String,
},
}
impl AppState {
pub fn generation_status(&self) -> Option<GenerationStatus> {
match self {
AppState::Generating { status, .. } => Some(*status),
_ => None,
}
}
pub fn is_generating(&self) -> bool {
matches!(self, AppState::Generating { .. })
}
pub fn is_idle(&self) -> bool {
matches!(self, AppState::Idle)
}
pub fn generation_start_time(&self) -> Option<Instant> {
match self {
AppState::Generating { start_time, .. } => Some(*start_time),
_ => None,
}
}
pub fn tokens_received(&self) -> Option<usize> {
match self {
AppState::Generating {
tokens_received, ..
} => Some(*tokens_received),
_ => None,
}
}
pub fn abort_handle(&self) -> Option<&tokio::task::AbortHandle> {
match self {
AppState::Generating { abort_handle, .. } => abort_handle.as_ref(),
_ => None,
}
}
}