Skip to main content

wisp/app/
foreground.rs

1use agent_client_protocol::schema::v2::SessionId;
2use std::path::PathBuf;
3
4/// The operation the UI itself is in the middle of. A prompt's own lifecycle
5/// lives in the conversation's turn.
6#[derive(Default)]
7pub enum ForegroundOperation {
8    #[default]
9    Idle,
10    PreparingPrompt(String),
11    CreatingSession { previous_selections: Vec<(String, String)> },
12    ResumingSession { session_id: SessionId, cwd: PathBuf },
13    ListingWorkspaces,
14    PickingWorkspace,
15    MovingWorkspace,
16    LoadingWorkspaceSession { session_id: SessionId, cwd: PathBuf },
17}
18
19impl ForegroundOperation {
20    pub(super) fn is_idle(&self) -> bool {
21        matches!(self, Self::Idle)
22    }
23
24    /// Abandons a prompt still being prepared, whose conversation or submission is gone.
25    pub(super) fn drop_prepared_prompt(&mut self) {
26        if matches!(self, Self::PreparingPrompt(_)) {
27            *self = Self::Idle;
28        }
29    }
30
31    pub(super) fn take_prepared_prompt(&mut self) -> Option<String> {
32        if !matches!(self, Self::PreparingPrompt(_)) {
33            return None;
34        }
35        let Self::PreparingPrompt(text) = std::mem::take(self) else { unreachable!() };
36        Some(text)
37    }
38}