Skip to main content

objectiveai_sdk/cli/command/config/api/
mod.rs

1pub mod address;
2pub mod claude_agent_sdk;
3pub mod codex_sdk;
4pub mod commit_author_email;
5pub mod commit_author_name;
6pub mod get;
7pub mod github_authorization;
8pub mod http_referer;
9pub mod mcp_authorization;
10pub mod objectiveai_authorization;
11pub mod openrouter_authorization;
12pub mod port;
13pub mod user_agent;
14pub mod x_title;
15
16#[derive(clap::Subcommand)]
17pub enum Command {
18    Get(get::Command),
19    Address {
20        #[command(subcommand)]
21        command: address::Command,
22    },
23    Port {
24        #[command(subcommand)]
25        command: port::Command,
26    },
27    ClaudeAgentSdk {
28        #[command(subcommand)]
29        command: claude_agent_sdk::Command,
30    },
31    CodexSdk {
32        #[command(subcommand)]
33        command: codex_sdk::Command,
34    },
35    ObjectiveaiAuthorization {
36        #[command(subcommand)]
37        command: objectiveai_authorization::Command,
38    },
39    OpenrouterAuthorization {
40        #[command(subcommand)]
41        command: openrouter_authorization::Command,
42    },
43    GithubAuthorization {
44        #[command(subcommand)]
45        command: github_authorization::Command,
46    },
47    McpAuthorization {
48        #[command(subcommand)]
49        command: mcp_authorization::Command,
50    },
51    UserAgent {
52        #[command(subcommand)]
53        command: user_agent::Command,
54    },
55    HttpReferer {
56        #[command(subcommand)]
57        command: http_referer::Command,
58    },
59    XTitle {
60        #[command(subcommand)]
61        command: x_title::Command,
62    },
63    CommitAuthorName {
64        #[command(subcommand)]
65        command: commit_author_name::Command,
66    },
67    CommitAuthorEmail {
68        #[command(subcommand)]
69        command: commit_author_email::Command,
70    },
71}
72
73#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
74#[serde(untagged)]
75#[schemars(rename = "cli.command.config.api.Request")]
76pub enum Request {
77    #[schemars(title = "Get")]
78    Get(get::Request),
79    #[schemars(title = "GetRequestSchema")]
80    GetRequestSchema(get::request_schema::Request),
81    #[schemars(title = "GetResponseSchema")]
82    GetResponseSchema(get::response_schema::Request),
83    #[schemars(title = "Address")]
84    Address(address::Request),
85    #[schemars(title = "Port")]
86    Port(port::Request),
87    #[schemars(title = "ClaudeAgentSdk")]
88    ClaudeAgentSdk(claude_agent_sdk::Request),
89    #[schemars(title = "CodexSdk")]
90    CodexSdk(codex_sdk::Request),
91    #[schemars(title = "ObjectiveaiAuthorization")]
92    ObjectiveaiAuthorization(objectiveai_authorization::Request),
93    #[schemars(title = "OpenrouterAuthorization")]
94    OpenrouterAuthorization(openrouter_authorization::Request),
95    #[schemars(title = "GithubAuthorization")]
96    GithubAuthorization(github_authorization::Request),
97    #[schemars(title = "McpAuthorization")]
98    McpAuthorization(mcp_authorization::Request),
99    #[schemars(title = "UserAgent")]
100    UserAgent(user_agent::Request),
101    #[schemars(title = "HttpReferer")]
102    HttpReferer(http_referer::Request),
103    #[schemars(title = "XTitle")]
104    XTitle(x_title::Request),
105    #[schemars(title = "CommitAuthorName")]
106    CommitAuthorName(commit_author_name::Request),
107    #[schemars(title = "CommitAuthorEmail")]
108    CommitAuthorEmail(commit_author_email::Request),
109}
110
111// Exempt from json-schema coverage: tier aggregate (see the root
112// `ResponseItem` in command.rs - TS7056).
113#[objectiveai_sdk_macros::json_schema_ignore]
114#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
115#[schemars(rename = "cli.command.config.api.Response")]
116#[serde(untagged)]
117pub enum Response {
118    #[schemars(title = "Get")]
119    Get(get::Response),
120    #[schemars(title = "GetRequestSchema")]
121    GetRequestSchema(get::request_schema::Response),
122    #[schemars(title = "GetResponseSchema")]
123    GetResponseSchema(get::response_schema::Response),
124    #[schemars(title = "Address")]
125    Address(address::Response),
126    #[schemars(title = "Port")]
127    Port(port::Response),
128    #[schemars(title = "ClaudeAgentSdk")]
129    ClaudeAgentSdk(claude_agent_sdk::Response),
130    #[schemars(title = "CodexSdk")]
131    CodexSdk(codex_sdk::Response),
132    #[schemars(title = "ObjectiveaiAuthorization")]
133    ObjectiveaiAuthorization(objectiveai_authorization::Response),
134    #[schemars(title = "OpenrouterAuthorization")]
135    OpenrouterAuthorization(openrouter_authorization::Response),
136    #[schemars(title = "GithubAuthorization")]
137    GithubAuthorization(github_authorization::Response),
138    #[schemars(title = "McpAuthorization")]
139    McpAuthorization(mcp_authorization::Response),
140    #[schemars(title = "UserAgent")]
141    UserAgent(user_agent::Response),
142    #[schemars(title = "HttpReferer")]
143    HttpReferer(http_referer::Response),
144    #[schemars(title = "XTitle")]
145    XTitle(x_title::Response),
146    #[schemars(title = "CommitAuthorName")]
147    CommitAuthorName(commit_author_name::Response),
148    #[schemars(title = "CommitAuthorEmail")]
149    CommitAuthorEmail(commit_author_email::Response),
150}
151
152#[cfg(feature = "mcp")]
153impl crate::cli::command::CommandResponse for Response {
154    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
155        match self {
156            Response::Get(v) => v.into_mcp(),
157            Response::GetRequestSchema(v) => v.into_mcp(),
158            Response::GetResponseSchema(v) => v.into_mcp(),
159            Response::Address(v) => v.into_mcp(),
160            Response::Port(v) => v.into_mcp(),
161            Response::ClaudeAgentSdk(v) => v.into_mcp(),
162            Response::CodexSdk(v) => v.into_mcp(),
163            Response::ObjectiveaiAuthorization(v) => v.into_mcp(),
164            Response::OpenrouterAuthorization(v) => v.into_mcp(),
165            Response::GithubAuthorization(v) => v.into_mcp(),
166            Response::McpAuthorization(v) => v.into_mcp(),
167            Response::UserAgent(v) => v.into_mcp(),
168            Response::HttpReferer(v) => v.into_mcp(),
169            Response::XTitle(v) => v.into_mcp(),
170            Response::CommitAuthorName(v) => v.into_mcp(),
171            Response::CommitAuthorEmail(v) => v.into_mcp(),
172        }
173    }
174}
175
176impl TryFrom<Command> for Request {
177    type Error = crate::cli::command::FromArgsError;
178    fn try_from(command: Command) -> Result<Self, Self::Error> {
179        match command {
180            Command::Get(cmd) => match cmd.schema {
181                None => Ok(Request::Get(get::Request::try_from(cmd.args)?)),
182                Some(get::Schema::RequestSchema(args)) =>
183                    Ok(Request::GetRequestSchema(get::request_schema::Request::try_from(args)?)),
184                Some(get::Schema::ResponseSchema(args)) =>
185                    Ok(Request::GetResponseSchema(get::response_schema::Request::try_from(args)?)),
186            },
187            Command::Address { command } =>
188                Ok(Request::Address(address::Request::try_from(command)?)),
189            Command::Port { command } =>
190                Ok(Request::Port(port::Request::try_from(command)?)),
191            Command::ClaudeAgentSdk { command } =>
192                Ok(Request::ClaudeAgentSdk(claude_agent_sdk::Request::try_from(command)?)),
193            Command::CodexSdk { command } =>
194                Ok(Request::CodexSdk(codex_sdk::Request::try_from(command)?)),
195            Command::ObjectiveaiAuthorization { command } =>
196                Ok(Request::ObjectiveaiAuthorization(objectiveai_authorization::Request::try_from(command)?)),
197            Command::OpenrouterAuthorization { command } =>
198                Ok(Request::OpenrouterAuthorization(openrouter_authorization::Request::try_from(command)?)),
199            Command::GithubAuthorization { command } =>
200                Ok(Request::GithubAuthorization(github_authorization::Request::try_from(command)?)),
201            Command::McpAuthorization { command } =>
202                Ok(Request::McpAuthorization(mcp_authorization::Request::try_from(command)?)),
203            Command::UserAgent { command } =>
204                Ok(Request::UserAgent(user_agent::Request::try_from(command)?)),
205            Command::HttpReferer { command } =>
206                Ok(Request::HttpReferer(http_referer::Request::try_from(command)?)),
207            Command::XTitle { command } =>
208                Ok(Request::XTitle(x_title::Request::try_from(command)?)),
209            Command::CommitAuthorName { command } =>
210                Ok(Request::CommitAuthorName(commit_author_name::Request::try_from(command)?)),
211            Command::CommitAuthorEmail { command } =>
212                Ok(Request::CommitAuthorEmail(commit_author_email::Request::try_from(command)?)),
213        }
214    }
215}
216
217impl crate::cli::command::CommandRequest for Request {
218    fn into_command(&self) -> Vec<String> {
219        match self {
220            Request::Get(inner) => inner.into_command(),
221            Request::GetRequestSchema(inner) => inner.into_command(),
222            Request::GetResponseSchema(inner) => inner.into_command(),
223            Request::Address(inner) => inner.into_command(),
224            Request::Port(inner) => inner.into_command(),
225            Request::ClaudeAgentSdk(inner) => inner.into_command(),
226            Request::CodexSdk(inner) => inner.into_command(),
227            Request::ObjectiveaiAuthorization(inner) => inner.into_command(),
228            Request::OpenrouterAuthorization(inner) => inner.into_command(),
229            Request::GithubAuthorization(inner) => inner.into_command(),
230            Request::McpAuthorization(inner) => inner.into_command(),
231            Request::UserAgent(inner) => inner.into_command(),
232            Request::HttpReferer(inner) => inner.into_command(),
233            Request::XTitle(inner) => inner.into_command(),
234            Request::CommitAuthorName(inner) => inner.into_command(),
235            Request::CommitAuthorEmail(inner) => inner.into_command(),
236        }
237    }
238}
239
240#[cfg(feature = "cli-executor")]
241pub async fn execute<E: crate::cli::command::CommandExecutor>(
242    executor: &E,
243    request: Request,
244
245        agent_arguments: Option<&crate::cli::command::AgentArguments>,
246    ) -> Result<
247    std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>>,
248    E::Error,
249> {
250    use futures::StreamExt;
251    let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>> =
252        match request {
253            Request::Get(req) => {
254                let value = get::execute(executor, req, agent_arguments).await?;
255                Box::pin(crate::cli::command::StreamOnce::new(Ok(
256                    Response::Get(value),
257                )))
258            }
259            Request::GetRequestSchema(req) => {
260                let value = get::request_schema::execute(executor, req, agent_arguments).await?;
261                Box::pin(crate::cli::command::StreamOnce::new(Ok(
262                    Response::GetRequestSchema(value),
263                )))
264            }
265            Request::GetResponseSchema(req) => {
266                let value = get::response_schema::execute(executor, req, agent_arguments).await?;
267                Box::pin(crate::cli::command::StreamOnce::new(Ok(
268                    Response::GetResponseSchema(value),
269                )))
270            }
271            Request::Address(req) => {
272                let inner = address::execute(executor, req, agent_arguments).await?;
273                Box::pin(inner.map(|r| r.map(Response::Address)))
274            }
275            Request::Port(req) => {
276                let inner = port::execute(executor, req, agent_arguments).await?;
277                Box::pin(inner.map(|r| r.map(Response::Port)))
278            }
279            Request::ClaudeAgentSdk(req) => {
280                let inner = claude_agent_sdk::execute(executor, req, agent_arguments).await?;
281                Box::pin(inner.map(|r| r.map(Response::ClaudeAgentSdk)))
282            }
283            Request::CodexSdk(req) => {
284                let inner = codex_sdk::execute(executor, req, agent_arguments).await?;
285                Box::pin(inner.map(|r| r.map(Response::CodexSdk)))
286            }
287            Request::ObjectiveaiAuthorization(req) => {
288                let inner = objectiveai_authorization::execute(executor, req, agent_arguments).await?;
289                Box::pin(inner.map(|r| r.map(Response::ObjectiveaiAuthorization)))
290            }
291            Request::OpenrouterAuthorization(req) => {
292                let inner = openrouter_authorization::execute(executor, req, agent_arguments).await?;
293                Box::pin(inner.map(|r| r.map(Response::OpenrouterAuthorization)))
294            }
295            Request::GithubAuthorization(req) => {
296                let inner = github_authorization::execute(executor, req, agent_arguments).await?;
297                Box::pin(inner.map(|r| r.map(Response::GithubAuthorization)))
298            }
299            Request::McpAuthorization(req) => {
300                let inner = mcp_authorization::execute(executor, req, agent_arguments).await?;
301                Box::pin(inner.map(|r| r.map(Response::McpAuthorization)))
302            }
303            Request::UserAgent(req) => {
304                let inner = user_agent::execute(executor, req, agent_arguments).await?;
305                Box::pin(inner.map(|r| r.map(Response::UserAgent)))
306            }
307            Request::HttpReferer(req) => {
308                let inner = http_referer::execute(executor, req, agent_arguments).await?;
309                Box::pin(inner.map(|r| r.map(Response::HttpReferer)))
310            }
311            Request::XTitle(req) => {
312                let inner = x_title::execute(executor, req, agent_arguments).await?;
313                Box::pin(inner.map(|r| r.map(Response::XTitle)))
314            }
315            Request::CommitAuthorName(req) => {
316                let inner = commit_author_name::execute(executor, req, agent_arguments).await?;
317                Box::pin(inner.map(|r| r.map(Response::CommitAuthorName)))
318            }
319            Request::CommitAuthorEmail(req) => {
320                let inner = commit_author_email::execute(executor, req, agent_arguments).await?;
321                Box::pin(inner.map(|r| r.map(Response::CommitAuthorEmail)))
322            }
323        };
324    Ok(stream)
325}
326
327#[cfg(feature = "cli-executor")]
328pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
329    executor: &E,
330    request: Request,
331    jq: String,
332
333        agent_arguments: Option<&crate::cli::command::AgentArguments>,
334    ) -> Result<
335    std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>>,
336    E::Error,
337> {
338    let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>> =
339        match request {
340            Request::Get(req) => {
341                let value = get::execute_jq(executor, req, jq, agent_arguments).await?;
342                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
343            }
344            Request::GetRequestSchema(req) => {
345                let value = get::request_schema::execute_jq(executor, req, jq, agent_arguments).await?;
346                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
347            }
348            Request::GetResponseSchema(req) => {
349                let value = get::response_schema::execute_jq(executor, req, jq, agent_arguments).await?;
350                Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
351            }
352            Request::Address(req) => {
353                let inner = address::execute_jq(executor, req, jq, agent_arguments).await?;
354                Box::pin(inner)
355            }
356            Request::Port(req) => {
357                let inner = port::execute_jq(executor, req, jq, agent_arguments).await?;
358                Box::pin(inner)
359            }
360            Request::ClaudeAgentSdk(req) => {
361                let inner = claude_agent_sdk::execute_jq(executor, req, jq, agent_arguments).await?;
362                Box::pin(inner)
363            }
364            Request::CodexSdk(req) => {
365                let inner = codex_sdk::execute_jq(executor, req, jq, agent_arguments).await?;
366                Box::pin(inner)
367            }
368            Request::ObjectiveaiAuthorization(req) => {
369                let inner = objectiveai_authorization::execute_jq(executor, req, jq, agent_arguments).await?;
370                Box::pin(inner)
371            }
372            Request::OpenrouterAuthorization(req) => {
373                let inner = openrouter_authorization::execute_jq(executor, req, jq, agent_arguments).await?;
374                Box::pin(inner)
375            }
376            Request::GithubAuthorization(req) => {
377                let inner = github_authorization::execute_jq(executor, req, jq, agent_arguments).await?;
378                Box::pin(inner)
379            }
380            Request::McpAuthorization(req) => {
381                let inner = mcp_authorization::execute_jq(executor, req, jq, agent_arguments).await?;
382                Box::pin(inner)
383            }
384            Request::UserAgent(req) => {
385                let inner = user_agent::execute_jq(executor, req, jq, agent_arguments).await?;
386                Box::pin(inner)
387            }
388            Request::HttpReferer(req) => {
389                let inner = http_referer::execute_jq(executor, req, jq, agent_arguments).await?;
390                Box::pin(inner)
391            }
392            Request::XTitle(req) => {
393                let inner = x_title::execute_jq(executor, req, jq, agent_arguments).await?;
394                Box::pin(inner)
395            }
396            Request::CommitAuthorName(req) => {
397                let inner = commit_author_name::execute_jq(executor, req, jq, agent_arguments).await?;
398                Box::pin(inner)
399            }
400            Request::CommitAuthorEmail(req) => {
401                let inner = commit_author_email::execute_jq(executor, req, jq, agent_arguments).await?;
402                Box::pin(inner)
403            }
404        };
405    Ok(stream)
406}