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}
42
43impl ApiConfig {
44 pub fn is_empty(&self) -> bool {
45 self.address.is_none()
46 && self.objectiveai_authorization.is_none()
47 && self.openrouter_authorization.is_none()
48 && self.github_authorization.is_none()
49 && self.mcp_authorization.as_ref().is_none_or(|m| m.is_empty())
50 && self.user_agent.is_none()
51 && self.http_referer.is_none()
52 && self.x_title.is_none()
53 && self.commit_author_name.is_none()
54 && self.commit_author_email.is_none()
55 }
56
57 pub fn is_none(this: &Option<Self>) -> bool {
58 this.as_ref().is_none_or(|cfg| cfg.is_empty())
59 }
60
61 pub fn get_address(&self) -> Option<&str> {
62 self.address.as_deref()
63 }
64 pub fn set_address(&mut self, value: impl Into<String>) {
65 self.address = Some(value.into());
66 }
67
68
69
70
71 pub fn get_objectiveai_authorization(&self) -> Option<&str> {
72 self.objectiveai_authorization.as_deref()
73 }
74 pub fn set_objectiveai_authorization(&mut self, value: impl Into<String>) {
75 self.objectiveai_authorization = Some(value.into());
76 }
77
78 pub fn get_openrouter_authorization(&self) -> Option<&str> {
79 self.openrouter_authorization.as_deref()
80 }
81 pub fn set_openrouter_authorization(&mut self, value: impl Into<String>) {
82 self.openrouter_authorization = Some(value.into());
83 }
84
85 pub fn get_github_authorization(&self) -> Option<&str> {
86 self.github_authorization.as_deref()
87 }
88 pub fn set_github_authorization(&mut self, value: impl Into<String>) {
89 self.github_authorization = Some(value.into());
90 }
91
92 pub fn get_mcp_authorization(
93 &self,
94 ) -> Option<&indexmap::IndexMap<String, String>> {
95 self.mcp_authorization.as_ref()
96 }
97 pub fn add_mcp_authorization(
98 &mut self,
99 key: impl Into<String>,
100 value: impl Into<String>,
101 ) {
102 self.mcp_authorization
103 .get_or_insert_with(indexmap::IndexMap::new)
104 .insert(key.into(), value.into());
105 }
106 pub fn del_mcp_authorization(&mut self, key: &str) {
107 if let Some(mcp) = &mut self.mcp_authorization {
108 mcp.shift_remove(key);
109 }
110 }
111
112 pub fn get_user_agent(&self) -> Option<&str> {
113 self.user_agent.as_deref()
114 }
115 pub fn set_user_agent(&mut self, value: impl Into<String>) {
116 self.user_agent = Some(value.into());
117 }
118
119 pub fn get_http_referer(&self) -> Option<&str> {
120 self.http_referer.as_deref()
121 }
122 pub fn set_http_referer(&mut self, value: impl Into<String>) {
123 self.http_referer = Some(value.into());
124 }
125
126 pub fn get_x_title(&self) -> Option<&str> {
127 self.x_title.as_deref()
128 }
129 pub fn set_x_title(&mut self, value: impl Into<String>) {
130 self.x_title = Some(value.into());
131 }
132
133 pub fn get_commit_author_name(&self) -> Option<&str> {
134 self.commit_author_name.as_deref()
135 }
136 pub fn set_commit_author_name(&mut self, value: impl Into<String>) {
137 self.commit_author_name = Some(value.into());
138 }
139
140 pub fn get_commit_author_email(&self) -> Option<&str> {
141 self.commit_author_email.as_deref()
142 }
143 pub fn set_commit_author_email(&mut self, value: impl Into<String>) {
144 self.commit_author_email = Some(value.into());
145 }
146
147 pub fn jq(
148 &self,
149 filter: &str,
150 ) -> Result<Vec<serde_json::Value>, super::super::Error> {
151 super::super::run_jq(self, filter)
152 }
153}