ratatui_toolkit/widgets/ai_chat/mod.rs
1//! AI Chat Widget for interactive chat interfaces.
2//!
3//! Provides a chat interface with:
4//! - Multi-line text input (Ctrl+J for newline)
5//! - File attachments via @ prefix with fuzzy search
6//! - Commands via / prefix (e.g., /clear)
7//! - Message history display
8//! - Loading spinner for AI responses
9
10mod constructors;
11pub mod methods;
12pub mod state;
13pub mod traits;
14
15use ratatui::style::Style;
16
17pub use state::{InputState, Message, MessageRole, MessageStore};
18
19/// Result of handling a key event.
20#[derive(Debug, Clone, PartialEq)]
21pub enum AIChatEvent {
22 /// No event
23 None,
24 /// Message submitted
25 MessageSubmitted(String),
26 /// File attached
27 FileAttached(String),
28 /// Command executed
29 Command(String),
30}
31
32/// AI Chat widget for interactive chat interfaces.
33pub struct AIChat<'a> {
34 /// Store for chat messages
35 messages: &'a mut MessageStore,
36 /// Input state for text entry
37 input: &'a mut InputState,
38 /// Currently attached files
39 attached_files: Vec<String>,
40 /// Whether AI is generating a response
41 is_loading: bool,
42 /// Style for user messages
43 user_message_style: Style,
44 /// Style for AI messages
45 ai_message_style: Style,
46 /// Style for input area
47 input_style: Style,
48 /// Prompt text for input
49 input_prompt: String,
50 /// Available commands
51 commands: Vec<String>,
52 /// Selected command index in command mode
53 selected_command_index: usize,
54}