Skip to main content

opencode_voice/
state.rs

1//! Core state and event types for the voice application.
2
3/// The recording state machine.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum RecordingState {
6    Idle,
7    Recording,
8    Transcribing,
9    Injecting,
10    ApprovalPending,
11    Error,
12}
13
14/// Input events from keyboard or global hotkey.
15#[derive(Debug, Clone)]
16pub enum InputEvent {
17    Toggle,
18    KeyDown,
19    KeyUp,
20    Quit,
21}
22
23/// Application-wide events flowing through the main event loop channel.
24#[derive(Debug)]
25pub enum AppEvent {
26    Input(InputEvent),
27    SseConnected,
28    SseDisconnected(Option<String>),
29    PermissionAsked(crate::approval::types::PermissionRequest),
30    PermissionReplied {
31        session_id: String,
32        request_id: String,
33        reply: String,
34    },
35    QuestionAsked(crate::approval::types::QuestionRequest),
36    QuestionReplied {
37        session_id: String,
38        request_id: String,
39        answers: Vec<Vec<String>>,
40    },
41    QuestionRejected {
42        session_id: String,
43        request_id: String,
44    },
45    /// Session status changed (busy/idle).
46    ///
47    /// Used to detect when the AI resumes work — implying any pending
48    /// approvals have been answered (possibly manually by the user).
49    SessionStatus {
50        session_id: String,
51        busy: bool,
52    },
53    AudioChunk {
54        rms_energy: f32,
55    },
56    /// Sent after a 3-second delay to transition back to Idle from Error state.
57    RecoverFromError,
58    /// Periodic UI tick (~10 Hz) for animations (recording timer, spinner).
59    Tick,
60    Shutdown,
61}