mermaid_cli/tui/state/
conversation.rs1use std::collections::VecDeque;
6
7use crate::context::Context;
8use crate::models::ChatMessage;
9use crate::session::{ConversationHistory, ConversationManager};
10
11pub struct ConversationState {
13 pub messages: Vec<ChatMessage>,
15 pub conversation_manager: Option<ConversationManager>,
17 pub current_conversation: Option<ConversationHistory>,
19 pub input_history: VecDeque<String>,
21 pub history_index: Option<usize>,
23 pub history_buffer: String,
25 pub context: Option<Context>,
27 pub cumulative_tokens: usize,
29 pub conversation_title: Option<String>,
31}
32
33impl ConversationState {
34 pub fn new() -> Self {
36 Self {
37 messages: Vec::new(),
38 conversation_manager: None,
39 current_conversation: None,
40 input_history: VecDeque::new(),
41 history_index: None,
42 history_buffer: String::new(),
43 context: None,
44 cumulative_tokens: 0,
45 conversation_title: None,
46 }
47 }
48
49 pub fn with_conversation(
51 conversation_manager: Option<ConversationManager>,
52 current_conversation: Option<ConversationHistory>,
53 input_history: VecDeque<String>,
54 ) -> Self {
55 Self {
56 messages: Vec::new(),
57 conversation_manager,
58 current_conversation,
59 input_history,
60 history_index: None,
61 history_buffer: String::new(),
62 context: None,
63 cumulative_tokens: 0,
64 conversation_title: None,
65 }
66 }
67
68 pub fn add_tokens(&mut self, count: usize) {
70 self.cumulative_tokens += count;
71 }
72
73 pub fn message_count(&self) -> usize {
75 self.messages.len()
76 }
77
78 pub fn is_empty(&self) -> bool {
80 self.messages.is_empty()
81 }
82}
83
84impl Default for ConversationState {
85 fn default() -> Self {
86 Self::new()
87 }
88}