mermaid_cli/tui/state/
conversation.rs1use crate::models::ChatMessage;
6use crate::session::{ConversationHistory, ConversationManager};
7
8pub struct ConversationState {
10 pub messages: Vec<ChatMessage>,
12 pub conversation_manager: Option<ConversationManager>,
14 pub current_conversation: Option<ConversationHistory>,
16 pub cumulative_tokens: usize,
18 pub conversation_title: Option<String>,
20}
21
22impl ConversationState {
23 pub fn new() -> Self {
25 Self {
26 messages: Vec::new(),
27 conversation_manager: None,
28 current_conversation: None,
29 cumulative_tokens: 0,
30 conversation_title: None,
31 }
32 }
33
34 pub fn with_conversation(
36 conversation_manager: Option<ConversationManager>,
37 current_conversation: Option<ConversationHistory>,
38 ) -> Self {
39 Self {
40 messages: Vec::new(),
41 conversation_manager,
42 current_conversation,
43 cumulative_tokens: 0,
44 conversation_title: None,
45 }
46 }
47
48 pub fn add_tokens(&mut self, count: usize) {
50 self.cumulative_tokens += count;
51 }
52
53 pub fn message_count(&self) -> usize {
55 self.messages.len()
56 }
57
58 pub fn is_empty(&self) -> bool {
60 self.messages.is_empty()
61 }
62}
63
64impl Default for ConversationState {
65 fn default() -> Self {
66 Self::new()
67 }
68}