Skip to main content

codex_app_server_client/
builders.rs

1use crate::protocol::{
2    ClientInfo, ConfigReadParams, InitializeCapabilities, InitializeParams, ThreadStartParams,
3    TurnStartParams, UserInput,
4};
5
6impl ClientInfo {
7    pub fn new(name: impl Into<String>, version: impl Into<String>) -> Self {
8        Self {
9            name: name.into(),
10            title: None,
11            version: version.into(),
12        }
13    }
14
15    pub fn with_title(mut self, title: impl Into<String>) -> Self {
16        self.title = Some(title.into());
17        self
18    }
19}
20
21impl InitializeParams {
22    pub fn for_client(name: impl Into<String>, version: impl Into<String>) -> Self {
23        Self {
24            capabilities: None,
25            client_info: ClientInfo::new(name, version),
26        }
27    }
28
29    pub fn with_capabilities(mut self, capabilities: InitializeCapabilities) -> Self {
30        self.capabilities = Some(capabilities);
31        self
32    }
33}
34
35impl ThreadStartParams {
36    pub fn new() -> Self {
37        Self::default()
38    }
39
40    pub fn model(mut self, model: impl Into<String>) -> Self {
41        self.model = Some(model.into());
42        self
43    }
44
45    pub fn cwd(mut self, cwd: impl Into<String>) -> Self {
46        self.cwd = Some(cwd.into());
47        self
48    }
49
50    pub fn ephemeral(mut self, ephemeral: bool) -> Self {
51        self.ephemeral = Some(ephemeral);
52        self
53    }
54
55    pub fn developer_instructions(mut self, instructions: impl Into<String>) -> Self {
56        self.developer_instructions = Some(instructions.into());
57        self
58    }
59}
60
61impl UserInput {
62    pub fn text(text: impl Into<String>) -> Self {
63        Self::Text {
64            text: text.into(),
65            text_elements: Vec::new(),
66        }
67    }
68}
69
70impl TurnStartParams {
71    pub fn text(thread_id: impl Into<String>, text: impl Into<String>) -> Self {
72        Self {
73            additional_context: None,
74            approval_policy: None,
75            approvals_reviewer: None,
76            client_user_message_id: None,
77            collaboration_mode: None,
78            cwd: None,
79            effort: None,
80            environments: None,
81            input: vec![UserInput::text(text)],
82            model: None,
83            multi_agent_mode: None,
84            output_schema: None,
85            permissions: None,
86            personality: None,
87            responsesapi_client_metadata: None,
88            runtime_workspace_roots: None,
89            sandbox_policy: None,
90            service_tier: None,
91            summary: None,
92            thread_id: thread_id.into(),
93        }
94    }
95
96    pub fn model(mut self, model: impl Into<String>) -> Self {
97        self.model = Some(model.into());
98        self
99    }
100
101    pub fn cwd(mut self, cwd: impl Into<String>) -> Self {
102        self.cwd = Some(cwd.into());
103        self
104    }
105}
106
107impl ConfigReadParams {
108    pub fn for_cwd(cwd: impl Into<String>) -> Self {
109        Self {
110            cwd: Some(cwd.into()),
111            include_layers: None,
112        }
113    }
114
115    pub fn include_layers(mut self, include_layers: bool) -> Self {
116        self.include_layers = Some(include_layers);
117        self
118    }
119}