Skip to main content

perspt_tui/
app_event.rs

1//! App Event - Message bus for TUI events
2//!
3//! Provides a decoupled event system inspired by Codex CLI's architecture.
4//! All events flow through this enum, enabling async handling via tokio::select!
5
6use crate::task_tree::TaskStatus;
7use crossterm::event::Event as CrosstermEvent;
8
9/// Application events for the TUI message bus
10#[derive(Debug)]
11pub enum AppEvent {
12    /// Terminal input event (key press, mouse, resize)
13    Terminal(CrosstermEvent),
14
15    /// Streaming chunk from LLM
16    StreamChunk(String),
17
18    /// Stream completed (EOT received)
19    StreamComplete,
20
21    /// Agent state update (for Agent mode - legacy)
22    AgentUpdate(AgentStateUpdate),
23
24    /// Core agent event from SRBNOrchestrator (new event system)
25    CoreEvent(perspt_core::AgentEvent),
26
27    /// Periodic tick for animations (throbber, cursor blink)
28    Tick,
29
30    /// Request to quit the application
31    Quit,
32
33    /// Error event
34    Error(String),
35}
36
37/// Agent state updates for the Agent mode TUI
38#[derive(Debug, Clone)]
39pub enum AgentStateUpdate {
40    /// Task status changed
41    Status { node_id: String, status: TaskStatus },
42    /// Energy value updated
43    Energy { node_id: String, energy: f32 },
44    /// Log message
45    Log(String),
46    /// Node completed
47    NodeCompleted(String),
48    /// Orchestration finished
49    Complete,
50}
51
52/// Sender type for AppEvents
53pub type AppEventSender = tokio::sync::mpsc::UnboundedSender<AppEvent>;
54
55/// Receiver type for AppEvents
56pub type AppEventReceiver = tokio::sync::mpsc::UnboundedReceiver<AppEvent>;
57
58/// Create a new AppEvent channel
59pub fn create_app_event_channel() -> (AppEventSender, AppEventReceiver) {
60    tokio::sync::mpsc::unbounded_channel()
61}