Skip to main content

objectiveai_cli/filesystem/config/
api.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(
4    Debug, Clone, Default, Serialize, Deserialize, schemars::JsonSchema,
5)]
6#[schemars(rename = "filesystem.config.ApiConfig")]
7pub struct ApiConfig {
8    #[serde(default, skip_serializing_if = "Option::is_none")]
9    #[schemars(extend("omitempty" = true))]
10    pub address: Option<String>,
11    #[serde(default, skip_serializing_if = "Option::is_none")]
12    #[schemars(extend("omitempty" = true))]
13    pub objectiveai_authorization: Option<String>,
14    #[serde(default, skip_serializing_if = "Option::is_none")]
15    #[schemars(extend("omitempty" = true))]
16    pub openrouter_authorization: Option<String>,
17    #[serde(default, skip_serializing_if = "Option::is_none")]
18    #[schemars(extend("omitempty" = true))]
19    pub github_authorization: Option<String>,
20    #[serde(default, skip_serializing_if = "Option::is_none")]
21    #[schemars(extend("omitempty" = true))]
22    pub mcp_authorization: Option<indexmap::IndexMap<String, String>>,
23    #[serde(default, skip_serializing_if = "Option::is_none")]
24    #[schemars(extend("omitempty" = true))]
25    pub user_agent: Option<String>,
26    #[serde(default, skip_serializing_if = "Option::is_none")]
27    #[schemars(extend("omitempty" = true))]
28    pub http_referer: Option<String>,
29    /// `X-Title` HTTP header — keeps the `x_` prefix because that's the
30    /// literal header name (every other field had its `x_` dropped on
31    /// the flatten).
32    #[serde(default, skip_serializing_if = "Option::is_none")]
33    #[schemars(extend("omitempty" = true))]
34    pub x_title: Option<String>,
35    #[serde(default, skip_serializing_if = "Option::is_none")]
36    #[schemars(extend("omitempty" = true))]
37    pub commit_author_name: Option<String>,
38    #[serde(default, skip_serializing_if = "Option::is_none")]
39    #[schemars(extend("omitempty" = true))]
40    pub commit_author_email: Option<String>,
41    /// MCP timeout override, in milliseconds. One value, fanned out to
42    /// the connect timeout, the per-call timeout, AND the backoff
43    /// max-elapsed-time of every MCP client this CLI drives (its
44    /// streaming conduit) and projected onto the spawned API's `MCP_*`
45    /// env (which in turn drives the proxy it spawns). `None` ⇒ the
46    /// canonical default (60000ms). The other exponential-backoff knobs
47    /// (intervals / randomization / multiplier) keep their built-in
48    /// defaults.
49    #[serde(default, skip_serializing_if = "Option::is_none")]
50    #[schemars(extend("omitempty" = true))]
51    pub mcp_timeout_ms: Option<u64>,
52}
53
54impl ApiConfig {
55    pub fn is_empty(&self) -> bool {
56        self.address.is_none()
57            && self.objectiveai_authorization.is_none()
58            && self.openrouter_authorization.is_none()
59            && self.github_authorization.is_none()
60            && self.mcp_authorization.as_ref().is_none_or(|m| m.is_empty())
61            && self.user_agent.is_none()
62            && self.http_referer.is_none()
63            && self.x_title.is_none()
64            && self.commit_author_name.is_none()
65            && self.commit_author_email.is_none()
66            && self.mcp_timeout_ms.is_none()
67    }
68
69    pub fn is_none(this: &Option<Self>) -> bool {
70        this.as_ref().is_none_or(|cfg| cfg.is_empty())
71    }
72
73    pub fn get_address(&self) -> Option<&str> {
74        self.address.as_deref()
75    }
76    pub fn set_address(&mut self, value: impl Into<String>) {
77        self.address = Some(value.into());
78    }
79
80
81
82
83    pub fn get_objectiveai_authorization(&self) -> Option<&str> {
84        self.objectiveai_authorization.as_deref()
85    }
86    pub fn set_objectiveai_authorization(&mut self, value: impl Into<String>) {
87        self.objectiveai_authorization = Some(value.into());
88    }
89
90    pub fn get_openrouter_authorization(&self) -> Option<&str> {
91        self.openrouter_authorization.as_deref()
92    }
93    pub fn set_openrouter_authorization(&mut self, value: impl Into<String>) {
94        self.openrouter_authorization = Some(value.into());
95    }
96
97    pub fn get_github_authorization(&self) -> Option<&str> {
98        self.github_authorization.as_deref()
99    }
100    pub fn set_github_authorization(&mut self, value: impl Into<String>) {
101        self.github_authorization = Some(value.into());
102    }
103
104    pub fn get_mcp_authorization(
105        &self,
106    ) -> Option<&indexmap::IndexMap<String, String>> {
107        self.mcp_authorization.as_ref()
108    }
109    pub fn add_mcp_authorization(
110        &mut self,
111        key: impl Into<String>,
112        value: impl Into<String>,
113    ) {
114        self.mcp_authorization
115            .get_or_insert_with(indexmap::IndexMap::new)
116            .insert(key.into(), value.into());
117    }
118    pub fn del_mcp_authorization(&mut self, key: &str) {
119        if let Some(mcp) = &mut self.mcp_authorization {
120            mcp.shift_remove(key);
121        }
122    }
123
124    pub fn get_user_agent(&self) -> Option<&str> {
125        self.user_agent.as_deref()
126    }
127    pub fn set_user_agent(&mut self, value: impl Into<String>) {
128        self.user_agent = Some(value.into());
129    }
130
131    pub fn get_http_referer(&self) -> Option<&str> {
132        self.http_referer.as_deref()
133    }
134    pub fn set_http_referer(&mut self, value: impl Into<String>) {
135        self.http_referer = Some(value.into());
136    }
137
138    pub fn get_x_title(&self) -> Option<&str> {
139        self.x_title.as_deref()
140    }
141    pub fn set_x_title(&mut self, value: impl Into<String>) {
142        self.x_title = Some(value.into());
143    }
144
145    pub fn get_commit_author_name(&self) -> Option<&str> {
146        self.commit_author_name.as_deref()
147    }
148    pub fn set_commit_author_name(&mut self, value: impl Into<String>) {
149        self.commit_author_name = Some(value.into());
150    }
151
152    pub fn get_commit_author_email(&self) -> Option<&str> {
153        self.commit_author_email.as_deref()
154    }
155    pub fn set_commit_author_email(&mut self, value: impl Into<String>) {
156        self.commit_author_email = Some(value.into());
157    }
158
159    pub fn get_mcp_timeout_ms(&self) -> Option<u64> {
160        self.mcp_timeout_ms
161    }
162    pub fn set_mcp_timeout_ms(&mut self, value: u64) {
163        self.mcp_timeout_ms = Some(value);
164    }
165
166    pub fn jq(
167        &self,
168        filter: &str,
169    ) -> Result<Vec<serde_json::Value>, super::super::Error> {
170        super::super::run_jq(self, filter)
171    }
172}