Skip to main content

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

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