objectiveai_cli/filesystem/config/
api.rs1use 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 #[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 #[serde(default, skip_serializing_if = "Option::is_none")]
48 #[schemars(extend("omitempty" = true))]
49 pub mcp_timeout_ms: Option<u64>,
50 #[serde(default, skip_serializing_if = "Option::is_none")]
59 #[schemars(extend("omitempty" = true))]
60 pub backoff_max_elapsed_time_ms: Option<u64>,
61}
62
63impl ApiConfig {
64 pub fn is_empty(&self) -> bool {
65 self.address.is_none()
66 && self.objectiveai_authorization.is_none()
67 && self.openrouter_authorization.is_none()
68 && self.github_authorization.is_none()
69 && self.mcp_authorization.as_ref().is_none_or(|m| m.is_empty())
70 && self.user_agent.is_none()
71 && self.http_referer.is_none()
72 && self.x_title.is_none()
73 && self.commit_author_name.is_none()
74 && self.commit_author_email.is_none()
75 && self.mcp_timeout_ms.is_none()
76 && self.backoff_max_elapsed_time_ms.is_none()
77 }
78
79 pub fn is_none(this: &Option<Self>) -> bool {
80 this.as_ref().is_none_or(|cfg| cfg.is_empty())
81 }
82
83 pub fn get_address(&self) -> Option<&str> {
84 self.address.as_deref()
85 }
86 pub fn set_address(&mut self, value: impl Into<String>) {
87 self.address = Some(value.into());
88 }
89
90
91
92
93 pub fn get_objectiveai_authorization(&self) -> Option<&str> {
94 self.objectiveai_authorization.as_deref()
95 }
96 pub fn set_objectiveai_authorization(&mut self, value: impl Into<String>) {
97 self.objectiveai_authorization = Some(value.into());
98 }
99
100 pub fn get_openrouter_authorization(&self) -> Option<&str> {
101 self.openrouter_authorization.as_deref()
102 }
103 pub fn set_openrouter_authorization(&mut self, value: impl Into<String>) {
104 self.openrouter_authorization = Some(value.into());
105 }
106
107 pub fn get_github_authorization(&self) -> Option<&str> {
108 self.github_authorization.as_deref()
109 }
110 pub fn set_github_authorization(&mut self, value: impl Into<String>) {
111 self.github_authorization = Some(value.into());
112 }
113
114 pub fn get_mcp_authorization(
115 &self,
116 ) -> Option<&indexmap::IndexMap<String, String>> {
117 self.mcp_authorization.as_ref()
118 }
119 pub fn add_mcp_authorization(
120 &mut self,
121 key: impl Into<String>,
122 value: impl Into<String>,
123 ) {
124 self.mcp_authorization
125 .get_or_insert_with(indexmap::IndexMap::new)
126 .insert(key.into(), value.into());
127 }
128 pub fn del_mcp_authorization(&mut self, key: &str) {
129 if let Some(mcp) = &mut self.mcp_authorization {
130 mcp.shift_remove(key);
131 }
132 }
133
134 pub fn get_user_agent(&self) -> Option<&str> {
135 self.user_agent.as_deref()
136 }
137 pub fn set_user_agent(&mut self, value: impl Into<String>) {
138 self.user_agent = Some(value.into());
139 }
140
141 pub fn get_http_referer(&self) -> Option<&str> {
142 self.http_referer.as_deref()
143 }
144 pub fn set_http_referer(&mut self, value: impl Into<String>) {
145 self.http_referer = Some(value.into());
146 }
147
148 pub fn get_x_title(&self) -> Option<&str> {
149 self.x_title.as_deref()
150 }
151 pub fn set_x_title(&mut self, value: impl Into<String>) {
152 self.x_title = Some(value.into());
153 }
154
155 pub fn get_commit_author_name(&self) -> Option<&str> {
156 self.commit_author_name.as_deref()
157 }
158 pub fn set_commit_author_name(&mut self, value: impl Into<String>) {
159 self.commit_author_name = Some(value.into());
160 }
161
162 pub fn get_commit_author_email(&self) -> Option<&str> {
163 self.commit_author_email.as_deref()
164 }
165 pub fn set_commit_author_email(&mut self, value: impl Into<String>) {
166 self.commit_author_email = Some(value.into());
167 }
168
169 pub fn get_mcp_timeout_ms(&self) -> Option<u64> {
170 self.mcp_timeout_ms
171 }
172 pub fn set_mcp_timeout_ms(&mut self, value: u64) {
173 self.mcp_timeout_ms = Some(value);
174 }
175
176 pub fn get_backoff_max_elapsed_time_ms(&self) -> Option<u64> {
177 self.backoff_max_elapsed_time_ms
178 }
179 pub fn set_backoff_max_elapsed_time_ms(&mut self, value: u64) {
180 self.backoff_max_elapsed_time_ms = Some(value);
181 }
182
183 pub fn jq(
184 &self,
185 filter: &str,
186 ) -> Result<Vec<serde_json::Value>, super::super::Error> {
187 super::super::run_jq(self, filter)
188 }
189}