1mod api;
14mod assets;
15mod collab;
16pub mod mcp_http;
17mod pty;
18mod server;
19pub mod state_sync;
20pub mod voice;
21mod websocket;
22
23pub use server::start_server;
24pub use state_sync::{McpActivityState, UserHintsQueue};
25pub use mcp_http::{SharedMcpContext, create_mcp_context, mcp_router};
26
27use crate::collaboration::{create_hub, SharedCollabHub};
28use crate::in_memory_logger::InMemoryLogStore;
29use serde::{Deserialize, Serialize};
30use std::collections::HashMap;
31use std::path::PathBuf;
32use std::sync::atomic::AtomicUsize;
33use std::sync::Arc;
34use tokio::sync::{oneshot, RwLock};
35
36#[derive(Debug)]
37pub struct PromptManager {
38 pub next_id: AtomicUsize,
39 pub pending: Arc<RwLock<HashMap<String, oneshot::Sender<String>>>>,
40 pub active_prompts: Arc<RwLock<HashMap<String, String>>>, }
42
43impl PromptManager {
44 pub fn new() -> Self {
45 Self {
46 next_id: AtomicUsize::new(1),
47 pending: Arc::new(RwLock::new(HashMap::new())),
48 active_prompts: Arc::new(RwLock::new(HashMap::new())),
49 }
50 }
51}
52
53pub type SharedMcpActivity = Arc<RwLock<McpActivityState>>;
55
56pub type SharedUserHints = Arc<RwLock<UserHintsQueue>>;
58
59#[derive(Debug)]
61pub struct DashboardState {
62 pub cwd: PathBuf,
64 pub pty_sessions: HashMap<String, pty::PtyHandle>,
66 pub connections: usize,
68 pub log_store: InMemoryLogStore,
70 pub mcp_activity: SharedMcpActivity,
72 pub user_hints: SharedUserHints,
74 pub collab_hub: SharedCollabHub,
76 pub prompt_manager: PromptManager,
78}
79
80impl DashboardState {
81 pub fn new(cwd: PathBuf, log_store: InMemoryLogStore) -> Self {
82 Self {
83 cwd,
84 pty_sessions: HashMap::new(),
85 connections: 0,
86 log_store,
87 mcp_activity: Arc::new(RwLock::new(McpActivityState::default())),
88 user_hints: Arc::new(RwLock::new(UserHintsQueue::default())),
89 collab_hub: create_hub(),
90 prompt_manager: PromptManager::new(),
91 }
92 }
93
94 pub fn mcp_activity_handle(&self) -> SharedMcpActivity {
96 Arc::clone(&self.mcp_activity)
97 }
98
99 pub fn user_hints_handle(&self) -> SharedUserHints {
101 Arc::clone(&self.user_hints)
102 }
103}
104
105#[derive(Debug, Serialize, Deserialize)]
107#[serde(tag = "type", rename_all = "snake_case")]
108pub enum TerminalMessage {
109 Input { data: String },
111 Resize { cols: u16, rows: u16 },
113 Output { data: String },
115 System { message: String },
117 Exit { code: i32 },
119 Error { message: String },
121 Ping,
123 Pong,
125}
126
127#[derive(Debug, Serialize, Deserialize)]
129pub struct FileTreeNode {
130 pub name: String,
131 pub path: String,
132 pub is_dir: bool,
133 pub size: u64,
134 pub modified: i64,
135 pub file_type: String,
136}
137
138pub type SharedState = Arc<RwLock<DashboardState>>;