Skip to main content

stakpak_tui/app/
events.rs

1use ratatui::style::Color;
2use stakpak_api::models::ListRuleBook;
3use stakpak_shared::models::{
4    integrations::openai::{AgentModel, ToolCall, ToolCallResult, ToolCallResultProgress},
5    llm::{LLMModel, LLMTokenUsage},
6};
7use uuid::Uuid;
8
9use crate::app::{LoadingOperation, SessionInfo};
10use crate::services::board_tasks::FetchTasksResult;
11
12#[derive(Debug)]
13pub enum InputEvent {
14    AssistantMessage(String),
15    AddUserMessage(String),
16    StreamAssistantMessage(Uuid, String),
17    RunToolCall(ToolCall),
18    ToolResult(ToolCallResult),
19    StreamToolResult(ToolCallResultProgress),
20    StartLoadingOperation(LoadingOperation),
21    EndLoadingOperation(LoadingOperation),
22    InputChanged(char),
23    ShellMode,
24    RunShellCommand(String),
25    /// Spawn the user's shell and then execute a command in it (for interactive stall recovery)
26    RunShellWithCommand(String),
27    GetStatus(String),
28    BillingInfoLoaded(stakpak_shared::models::billing::BillingResponse),
29    Error(String),
30    SetSessions(Vec<SessionInfo>),
31    InputBackspace,
32    InputChangedNewline,
33    InputSubmitted,
34    InputSubmittedWith(String),
35    InputSubmittedWithColor(String, Color),
36    MessageToolCalls(Vec<ToolCall>),
37    ScrollUp,
38    ScrollDown,
39    PageUp,
40    PageDown,
41    DropdownUp,
42    DropdownDown,
43    Up,
44    Down,
45    Quit,
46    HandleEsc,
47    HandleReject(Option<String>, bool, Option<Color>),
48    CursorLeft,
49    CursorRight,
50    ToggleCursorVisible,
51    Resized(u16, u16),
52    ShowConfirmationDialog(ToolCall),
53    HasUserMessage,
54    Tab,
55    ToggleApprovalStatus,
56    ShellOutput(String),
57    ShellError(String),
58    ShellWaitingForInput,
59    ShellCompleted(i32),
60    ShellClear,
61    ShellKill,
62    HandlePaste(String),
63    /// Ctrl+V clipboard image paste (non-text, via system clipboard).
64    HandleClipboardImagePaste,
65    InputDelete,
66    InputDeleteWord,
67    InputCursorStart,
68    InputCursorEnd,
69    InputCursorPrevWord,
70    InputCursorNextWord,
71    ToggleAutoApprove,
72    AutoApproveCurrentTool,
73    ToggleDialogFocus,
74    RetryLastToolCall,
75    /// Interactive stall detected - automatically switch to shell mode and fire the command
76    InteractiveStallDetected(String),
77    AttemptQuit,
78    ToggleCollapsedMessages,
79    ShowFileChangesPopup,
80    FileChangesRevertFile,
81    FileChangesRevertAll,
82    FileChangesOpenEditor,
83    EmergencyClearTerminal,
84    ToggleMouseCapture,
85    OpenFileInEditor,
86    // Approval popup events
87    ApprovalPopupNextTab,
88    ApprovalPopupPrevTab,
89    ApprovalPopupToggleApproval,
90    ApprovalPopupSubmit,
91    ApprovalPopupEscape,
92    // Approval bar events (inline approval)
93    ApprovalBarApproveAll,
94    ApprovalBarRejectAll,
95    ApprovalBarSelectAction(usize),
96    ApprovalBarApproveSelected,
97    ApprovalBarRejectSelected,
98    ApprovalBarNextAction,
99    ApprovalBarPrevAction,
100    ApprovalBarCollapse,
101    // Profile switcher events
102    ShowProfileSwitcher,
103    ProfilesLoaded(Vec<String>, String),
104    ProfileSwitchRequested(String),
105    ProfileSwitchProgress(String),
106    ProfileSwitchComplete(String),
107    ProfileSwitchFailed(String),
108    // Command palette events
109    ShowCommandPalette,
110    CommandPaletteSearchInputChanged(char),
111    CommandPaletteSearchBackspace,
112    ProfileSwitcherSelect,
113    ProfileSwitcherCancel,
114    // Shortcuts popup events
115    ShowShortcuts,
116    ShortcutsCancel,
117
118    // Rulebook switcher events
119    ShowRulebookSwitcher,
120    RulebooksLoaded(Vec<ListRuleBook>),
121    CurrentRulebooksLoaded(Vec<String>),
122    RulebookSwitcherSelect,
123    RulebookSwitcherToggle,
124    RulebookSwitcherCancel,
125    RulebookSwitcherConfirm,
126    RulebookSwitcherSelectAll,
127    RulebookSwitcherDeselectAll,
128    RulebookSearchInputChanged(char),
129    RulebookSearchBackspace,
130    HandleCtrlS,
131    ToggleMoreShortcuts,
132    // Usage tracking events
133    StreamUsage(LLMTokenUsage),
134    RequestTotalUsage,
135    TotalUsage(LLMTokenUsage),
136
137    // Model events
138    StreamModel(LLMModel),
139
140    // Side panel events
141    ToggleSidePanel,
142    SidePanelNextSection,
143    SidePanelToggleSection,
144    MouseClick(u16, u16),
145
146    // Board tasks events
147    RefreshBoardTasks,
148    BoardTasksLoaded(FetchTasksResult),
149    BoardTasksError(String),
150}
151
152#[derive(Debug)]
153pub enum OutputEvent {
154    UserMessage(
155        String,
156        Option<Vec<ToolCallResult>>,
157        Vec<stakpak_shared::models::integrations::openai::ContentPart>,
158    ),
159    AcceptTool(ToolCall),
160    RejectTool(ToolCall, bool),
161    ListSessions,
162    SwitchToSession(String),
163    NewSession,
164    Memorize,
165    SendToolResult(ToolCallResult, bool, Vec<ToolCall>),
166    ResumeSession,
167    RequestProfileSwitch(String),
168    RequestRulebookUpdate(Vec<String>),
169    RequestCurrentRulebooks,
170    RequestTotalUsage,
171    SwitchModel(AgentModel),
172}