Skip to main content

codex/cli/
session.rs

1use crate::CliOverridesPatch;
2
3/// Request for `codex resume [OPTIONS] [SESSION_ID] [PROMPT]`.
4#[derive(Clone, Debug, Eq, PartialEq)]
5pub struct ResumeSessionRequest {
6    pub session_id: Option<String>,
7    pub prompt: Option<String>,
8    pub all: bool,
9    pub last: bool,
10    /// Per-call CLI overrides layered on top of the builder.
11    pub overrides: CliOverridesPatch,
12}
13
14impl ResumeSessionRequest {
15    pub fn new() -> Self {
16        Self {
17            session_id: None,
18            prompt: None,
19            all: false,
20            last: false,
21            overrides: CliOverridesPatch::default(),
22        }
23    }
24
25    pub fn session_id(mut self, session_id: impl Into<String>) -> Self {
26        let session_id = session_id.into();
27        self.session_id = (!session_id.trim().is_empty()).then_some(session_id);
28        self
29    }
30
31    pub fn prompt(mut self, prompt: impl Into<String>) -> Self {
32        let prompt = prompt.into();
33        self.prompt = (!prompt.trim().is_empty()).then_some(prompt);
34        self
35    }
36
37    pub fn all(mut self, enable: bool) -> Self {
38        self.all = enable;
39        self
40    }
41
42    pub fn last(mut self, enable: bool) -> Self {
43        self.last = enable;
44        self
45    }
46
47    pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
48        self.overrides = overrides;
49        self
50    }
51}
52
53impl Default for ResumeSessionRequest {
54    fn default() -> Self {
55        Self::new()
56    }
57}
58
59/// Request for `codex fork [OPTIONS] [SESSION_ID] [PROMPT]`.
60#[derive(Clone, Debug, Eq, PartialEq)]
61pub struct ForkSessionRequest {
62    pub session_id: Option<String>,
63    pub prompt: Option<String>,
64    pub all: bool,
65    pub last: bool,
66    /// Per-call CLI overrides layered on top of the builder.
67    pub overrides: CliOverridesPatch,
68}
69
70impl ForkSessionRequest {
71    pub fn new() -> Self {
72        Self {
73            session_id: None,
74            prompt: None,
75            all: false,
76            last: false,
77            overrides: CliOverridesPatch::default(),
78        }
79    }
80
81    pub fn session_id(mut self, session_id: impl Into<String>) -> Self {
82        let session_id = session_id.into();
83        self.session_id = (!session_id.trim().is_empty()).then_some(session_id);
84        self
85    }
86
87    pub fn prompt(mut self, prompt: impl Into<String>) -> Self {
88        let prompt = prompt.into();
89        self.prompt = (!prompt.trim().is_empty()).then_some(prompt);
90        self
91    }
92
93    pub fn all(mut self, enable: bool) -> Self {
94        self.all = enable;
95        self
96    }
97
98    pub fn last(mut self, enable: bool) -> Self {
99        self.last = enable;
100        self
101    }
102
103    pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
104        self.overrides = overrides;
105        self
106    }
107}
108
109impl Default for ForkSessionRequest {
110    fn default() -> Self {
111        Self::new()
112    }
113}