Skip to main content

wisp/app/
foreground.rs

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