use std::collections::VecDeque;
use ratatui::text::Line;
use rustc_hash::FxHashMap;
use crate::context::Context;
use crate::models::ChatMessage;
use crate::session::{ConversationHistory, ConversationManager};
pub struct ConversationState {
pub messages: Vec<ChatMessage>,
pub conversation_manager: Option<ConversationManager>,
pub current_conversation: Option<ConversationHistory>,
pub input_history: VecDeque<String>,
pub history_index: Option<usize>,
pub history_buffer: String,
pub context: Option<Context>,
pub cumulative_tokens: usize,
pub conversation_title: Option<String>,
pub markdown_cache: FxHashMap<(usize, usize), Vec<Line<'static>>>,
}
impl ConversationState {
pub fn new() -> Self {
Self {
messages: Vec::new(),
conversation_manager: None,
current_conversation: None,
input_history: VecDeque::new(),
history_index: None,
history_buffer: String::new(),
context: None,
cumulative_tokens: 0,
conversation_title: None,
markdown_cache: FxHashMap::default(),
}
}
pub fn with_conversation(
conversation_manager: Option<ConversationManager>,
current_conversation: Option<ConversationHistory>,
input_history: VecDeque<String>,
) -> Self {
Self {
messages: Vec::new(),
conversation_manager,
current_conversation,
input_history,
history_index: None,
history_buffer: String::new(),
context: None,
cumulative_tokens: 0,
conversation_title: None,
markdown_cache: FxHashMap::default(),
}
}
pub fn add_tokens(&mut self, count: usize) {
self.cumulative_tokens += count;
}
pub fn message_count(&self) -> usize {
self.messages.len()
}
pub fn is_empty(&self) -> bool {
self.messages.is_empty()
}
}
impl Default for ConversationState {
fn default() -> Self {
Self::new()
}
}