1use ratatui::style::Color;
2use stakai::Model;
3use stakpak_api::models::ListRuleBook;
4use stakpak_shared::models::{
5 integrations::openai::{ToolCall, ToolCallResult, ToolCallResultProgress, ToolCallStreamInfo},
6 llm::LLMTokenUsage,
7};
8use uuid::Uuid;
9
10use crate::app::{ExistingPlanPrompt, LoadingOperation, SessionInfo};
11use crate::services::banner::BannerStyle;
12use crate::services::board_tasks::FetchTasksResult;
13
14#[derive(Debug)]
15pub enum InputEvent {
16 AssistantMessage(String),
17 AddUserMessage(String),
18 StreamAssistantMessage(Uuid, String),
19 RunToolCall(ToolCall),
20 ToolResult(ToolCallResult),
21 StreamToolResult(ToolCallResultProgress),
22 StreamToolCallProgress(Vec<ToolCallStreamInfo>),
24 StartLoadingOperation(LoadingOperation),
25 EndLoadingOperation(LoadingOperation),
26 InputChanged(char),
27 ShellMode,
28 RunShellCommand(String),
29 RunShellWithCommand(String),
31 GetStatus(String),
32 BillingInfoLoaded(stakpak_shared::models::billing::BillingResponse),
33 Error(String),
34 SetSessions(Vec<SessionInfo>),
35 SetBannerMessage(String, BannerStyle),
36 InputBackspace,
37 InputChangedNewline,
38 InputSubmitted,
39 InputSubmittedWith(String),
40 InputSubmittedWithColor(String, Color),
41 MessageToolCalls(Vec<ToolCall>),
42 ScrollUp,
43 ScrollDown,
44 PageUp,
45 PageDown,
46 DropdownUp,
47 DropdownDown,
48 Up,
49 Down,
50 Quit,
51 HandleEsc,
52 HandleReject(Option<String>, bool, Option<Color>),
53 CursorLeft,
54 CursorRight,
55 ToggleCursorVisible,
56 Resized(u16, u16),
57 ShowConfirmationDialog(ToolCall),
58 HasUserMessage,
59 Tab,
60 ToggleApprovalStatus,
61 ShellOutput(String),
62 ShellError(String),
63 ShellWaitingForInput,
64 ShellCompleted(i32),
65 ShellClear,
66 ShellKill,
67 HandlePaste(String),
68 HandleClipboardImagePaste,
70 InputDelete,
71 InputDeleteWord,
72 InputCursorStart,
73 InputCursorEnd,
74 InputCursorPrevWord,
75 InputCursorNextWord,
76 ToggleAutoApprove,
77 AutoApproveCurrentTool,
78 ToggleDialogFocus,
79 RetryLastToolCall,
80 InteractiveStallDetected(String),
82 AttemptQuit,
83 ToggleCollapsedMessages,
84 ShowFileChangesPopup,
85 ShowAutoApprovePopup,
87 FileChangesRevertFile,
88 FileChangesRevertAll,
89 FileChangesOpenEditor,
90 EmergencyClearTerminal,
91 ToggleMouseCapture,
92 OpenFileInEditor,
93 ApprovalPopupNextTab,
95 ApprovalPopupPrevTab,
96 ApprovalPopupToggleApproval,
97 ApprovalPopupSubmit,
98 ApprovalPopupEscape,
99 ApprovalBarApproveAll,
101 ApprovalBarRejectAll,
102 ApprovalBarSelectAction(usize),
103 ApprovalBarApproveSelected,
104 ApprovalBarRejectSelected,
105 ApprovalBarNextAction,
106 ApprovalBarPrevAction,
107 ApprovalBarCollapse,
108 ShowProfileSwitcher,
110 ProfilesLoaded(Vec<String>, String),
111 ProfileSwitchRequested(String),
112 ProfileSwitchProgress(String),
113 ProfileSwitchComplete(String),
114 ProfileSwitchFailed(String),
115 ShowCommandPalette,
117 CommandPaletteSearchInputChanged(char),
118 CommandPaletteSearchBackspace,
119 ProfileSwitcherSelect,
120 ProfileSwitcherCancel,
121 ShowShortcuts,
123 ShortcutsCancel,
124
125 ShowRulebookSwitcher,
127 RulebooksLoaded(Vec<ListRuleBook>),
128 CurrentRulebooksLoaded(Vec<String>),
129 RulebookSwitcherSelect,
130 RulebookSwitcherToggle,
131 RulebookSwitcherCancel,
132 RulebookSwitcherConfirm,
133 RulebookSwitcherSelectAll,
134 RulebookSwitcherDeselectAll,
135 RulebookSearchInputChanged(char),
136 RulebookSearchBackspace,
137 HandleCtrlS,
138 ToggleMoreShortcuts,
139 StreamUsage(LLMTokenUsage),
141 RequestTotalUsage,
142 TotalUsage(LLMTokenUsage),
143
144 StreamModel(Model),
146
147 ShowModelSwitcher,
149 AvailableModelsLoaded(Vec<Model>),
150 ModelSwitcherSelect,
151 ModelSwitcherCancel,
152 ModelSwitcherSearchInputChanged(char),
153 ModelSwitcherSearchBackspace,
154 RecentModelsUpdated(Vec<String>),
156
157 ToggleSidePanel,
159 SidePanelNextSection,
160 SidePanelToggleSection,
161
162 MouseClick(u16, u16),
164 MouseDragStart(u16, u16),
165 MouseDrag(u16, u16),
166 MouseDragEnd(u16, u16),
167 MouseMove(u16, u16),
168
169 RefreshBoardTasks,
171 BoardTasksLoaded(FetchTasksResult),
172 BoardTasksError(String),
173
174 PlanModeChanged(bool),
177 ExistingPlanFound(ExistingPlanPrompt),
179 TogglePlanReview,
181 PlanReviewClose,
183 PlanReviewCursorUp,
185 PlanReviewCursorDown,
187 PlanReviewComment,
189 PlanReviewApprove,
191 PlanReviewFeedback,
193 PlanReviewNextComment,
195 PlanReviewPrevComment,
197 PlanReviewResolve,
199 PlanReviewPageUp,
201 PlanReviewPageDown,
203
204 ShowAskUserPopup(
206 ToolCall,
207 Vec<stakpak_shared::models::integrations::openai::AskUserQuestion>,
208 ),
209 AskUserNextTab,
210 AskUserPrevTab,
211 AskUserNextOption,
212 AskUserPrevOption,
213 AskUserSelectOption,
214 AskUserConfirmQuestion,
215 AskUserCustomInputChanged(char),
216 AskUserCustomInputBackspace,
217 AskUserCustomInputDelete,
218 AskUserSubmit,
219 AskUserCancel,
220
221 CopySessionId,
223
224 SetSessionId(String),
226
227 RunningBackgroundTasksCount(usize),
229 ShowApprovalSettingsPersistenceModal,
231 ApprovalSettingsPersistenceNavigate(i32),
232 ApprovalSettingsPersistenceConfirm,
233 ApprovalSettingsPersistenceCancel,
234}
235
236impl InputEvent {
237 pub fn is_backend_event(&self) -> bool {
245 matches!(
246 self,
247 InputEvent::StreamAssistantMessage(_, _)
248 | InputEvent::AssistantMessage(_)
249 | InputEvent::StartLoadingOperation(_)
250 | InputEvent::EndLoadingOperation(_)
251 | InputEvent::StreamUsage(_)
252 | InputEvent::StreamModel(_)
253 | InputEvent::StreamToolCallProgress(_)
254 | InputEvent::StreamToolResult(_)
255 | InputEvent::HasUserMessage
256 | InputEvent::Error(_)
257 | InputEvent::RunToolCall(_)
258 | InputEvent::ToolResult(_)
259 | InputEvent::MessageToolCalls(_)
260 | InputEvent::ShowConfirmationDialog(_)
261 | InputEvent::AddUserMessage(_)
262 | InputEvent::PlanModeChanged(_)
263 | InputEvent::BoardTasksLoaded(_)
264 | InputEvent::BoardTasksError(_)
265 | InputEvent::ShowAskUserPopup(_, _)
266 | InputEvent::ExistingPlanFound(_)
267 | InputEvent::SetSessions(_)
268 | InputEvent::SetBannerMessage(_, _)
269 | InputEvent::GetStatus(_)
270 | InputEvent::BillingInfoLoaded(_)
271 | InputEvent::TotalUsage(_)
272 | InputEvent::ProfileSwitchProgress(_)
273 | InputEvent::ProfileSwitchComplete(_)
274 | InputEvent::ProfileSwitchFailed(_)
275 | InputEvent::ProfilesLoaded(_, _)
276 | InputEvent::AvailableModelsLoaded(_)
277 | InputEvent::RecentModelsUpdated(_)
278 | InputEvent::RulebooksLoaded(_)
279 | InputEvent::CurrentRulebooksLoaded(_)
280 | InputEvent::RunningBackgroundTasksCount(_)
281 )
282 }
283}
284
285#[derive(Debug)]
286pub enum OutputEvent {
287 UserMessage(
290 String,
291 Option<Vec<ToolCallResult>>,
292 Vec<stakpak_shared::models::integrations::openai::ContentPart>,
293 Option<usize>, ),
295 AcceptTool(ToolCall),
296 RejectTool(ToolCall, bool),
297 ListSessions,
298 SwitchToSession(String),
299 NewSession,
300 SendToolResult(ToolCallResult, bool, Vec<ToolCall>),
301 ResumeSession,
302 RequestProfileSwitch(String),
303 RequestRulebookUpdate(Vec<String>),
304 RequestCurrentRulebooks,
305 RequestTotalUsage,
306 RequestAvailableModels,
307 SwitchToModel(Model),
308 SaveRecentModels(Vec<String>),
310 PlanModeActivated(Option<String>),
312 PlanFeedback(String),
314 PlanApproved,
316 CommandCalled(String),
318 AskUserResponse(ToolCallResult),
320 SaveAutoApproveToProfile(Vec<String>),
322}