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#[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 into_command(&self) -> Vec<String> {
207 match self {
208 Request::Get(inner) => inner.into_command(),
209 Request::GetRequestSchema(inner) => inner.into_command(),
210 Request::GetResponseSchema(inner) => inner.into_command(),
211 Request::Address(inner) => inner.into_command(),
212 Request::ObjectiveaiAuthorization(inner) => inner.into_command(),
213 Request::OpenrouterAuthorization(inner) => inner.into_command(),
214 Request::GithubAuthorization(inner) => inner.into_command(),
215 Request::McpAuthorization(inner) => inner.into_command(),
216 Request::McpTimeoutMs(inner) => inner.into_command(),
217 Request::BackoffMaxElapsedTimeMs(inner) => inner.into_command(),
218 Request::UserAgent(inner) => inner.into_command(),
219 Request::HttpReferer(inner) => inner.into_command(),
220 Request::XTitle(inner) => inner.into_command(),
221 Request::CommitAuthorName(inner) => inner.into_command(),
222 Request::CommitAuthorEmail(inner) => inner.into_command(),
223 }
224 }
225
226 fn request_base(&self) -> &crate::cli::command::RequestBase {
227 match self {
228 Request::Get(inner) => inner.request_base(),
229 Request::GetRequestSchema(inner) => inner.request_base(),
230 Request::GetResponseSchema(inner) => inner.request_base(),
231 Request::Address(inner) => inner.request_base(),
232 Request::ObjectiveaiAuthorization(inner) => inner.request_base(),
233 Request::OpenrouterAuthorization(inner) => inner.request_base(),
234 Request::GithubAuthorization(inner) => inner.request_base(),
235 Request::McpAuthorization(inner) => inner.request_base(),
236 Request::McpTimeoutMs(inner) => inner.request_base(),
237 Request::BackoffMaxElapsedTimeMs(inner) => inner.request_base(),
238 Request::UserAgent(inner) => inner.request_base(),
239 Request::HttpReferer(inner) => inner.request_base(),
240 Request::XTitle(inner) => inner.request_base(),
241 Request::CommitAuthorName(inner) => inner.request_base(),
242 Request::CommitAuthorEmail(inner) => inner.request_base(),
243 }
244 }
245
246 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
247 match self {
248 Request::Get(inner) => inner.request_base_mut(),
249 Request::GetRequestSchema(inner) => inner.request_base_mut(),
250 Request::GetResponseSchema(inner) => inner.request_base_mut(),
251 Request::Address(inner) => inner.request_base_mut(),
252 Request::ObjectiveaiAuthorization(inner) => inner.request_base_mut(),
253 Request::OpenrouterAuthorization(inner) => inner.request_base_mut(),
254 Request::GithubAuthorization(inner) => inner.request_base_mut(),
255 Request::McpAuthorization(inner) => inner.request_base_mut(),
256 Request::McpTimeoutMs(inner) => inner.request_base_mut(),
257 Request::BackoffMaxElapsedTimeMs(inner) => inner.request_base_mut(),
258 Request::UserAgent(inner) => inner.request_base_mut(),
259 Request::HttpReferer(inner) => inner.request_base_mut(),
260 Request::XTitle(inner) => inner.request_base_mut(),
261 Request::CommitAuthorName(inner) => inner.request_base_mut(),
262 Request::CommitAuthorEmail(inner) => inner.request_base_mut(),
263 }
264 }
265}
266
267#[cfg(feature = "cli-executor")]
268pub async fn execute<E: crate::cli::command::CommandExecutor>(
269 executor: &E,
270 request: Request,
271
272 agent_arguments: Option<&crate::cli::command::AgentArguments>,
273 ) -> Result<
274 std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>>,
275 E::Error,
276> {
277 use futures::StreamExt;
278 let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>> =
279 match request {
280 Request::Get(req) => {
281 let value = get::execute(executor, req, agent_arguments).await?;
282 Box::pin(crate::cli::command::StreamOnce::new(Ok(
283 Response::Get(value),
284 )))
285 }
286 Request::GetRequestSchema(req) => {
287 let value = get::request_schema::execute(executor, req, agent_arguments).await?;
288 Box::pin(crate::cli::command::StreamOnce::new(Ok(
289 Response::GetRequestSchema(value),
290 )))
291 }
292 Request::GetResponseSchema(req) => {
293 let value = get::response_schema::execute(executor, req, agent_arguments).await?;
294 Box::pin(crate::cli::command::StreamOnce::new(Ok(
295 Response::GetResponseSchema(value),
296 )))
297 }
298 Request::Address(req) => {
299 let inner = address::execute(executor, req, agent_arguments).await?;
300 Box::pin(inner.map(|r| r.map(Response::Address)))
301 }
302 Request::ObjectiveaiAuthorization(req) => {
303 let inner = objectiveai_authorization::execute(executor, req, agent_arguments).await?;
304 Box::pin(inner.map(|r| r.map(Response::ObjectiveaiAuthorization)))
305 }
306 Request::OpenrouterAuthorization(req) => {
307 let inner = openrouter_authorization::execute(executor, req, agent_arguments).await?;
308 Box::pin(inner.map(|r| r.map(Response::OpenrouterAuthorization)))
309 }
310 Request::GithubAuthorization(req) => {
311 let inner = github_authorization::execute(executor, req, agent_arguments).await?;
312 Box::pin(inner.map(|r| r.map(Response::GithubAuthorization)))
313 }
314 Request::McpAuthorization(req) => {
315 let inner = mcp_authorization::execute(executor, req, agent_arguments).await?;
316 Box::pin(inner.map(|r| r.map(Response::McpAuthorization)))
317 }
318 Request::McpTimeoutMs(req) => {
319 let inner = mcp_timeout_ms::execute(executor, req, agent_arguments).await?;
320 Box::pin(inner.map(|r| r.map(Response::McpTimeoutMs)))
321 }
322 Request::BackoffMaxElapsedTimeMs(req) => {
323 let inner = backoff_max_elapsed_time_ms::execute(executor, req, agent_arguments).await?;
324 Box::pin(inner.map(|r| r.map(Response::BackoffMaxElapsedTimeMs)))
325 }
326 Request::UserAgent(req) => {
327 let inner = user_agent::execute(executor, req, agent_arguments).await?;
328 Box::pin(inner.map(|r| r.map(Response::UserAgent)))
329 }
330 Request::HttpReferer(req) => {
331 let inner = http_referer::execute(executor, req, agent_arguments).await?;
332 Box::pin(inner.map(|r| r.map(Response::HttpReferer)))
333 }
334 Request::XTitle(req) => {
335 let inner = x_title::execute(executor, req, agent_arguments).await?;
336 Box::pin(inner.map(|r| r.map(Response::XTitle)))
337 }
338 Request::CommitAuthorName(req) => {
339 let inner = commit_author_name::execute(executor, req, agent_arguments).await?;
340 Box::pin(inner.map(|r| r.map(Response::CommitAuthorName)))
341 }
342 Request::CommitAuthorEmail(req) => {
343 let inner = commit_author_email::execute(executor, req, agent_arguments).await?;
344 Box::pin(inner.map(|r| r.map(Response::CommitAuthorEmail)))
345 }
346 };
347 Ok(stream)
348}
349
350#[cfg(feature = "cli-executor")]
351pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
352 executor: &E,
353 request: Request,
354 transform: crate::cli::command::Transform,
355
356 agent_arguments: Option<&crate::cli::command::AgentArguments>,
357 ) -> Result<
358 std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>>,
359 E::Error,
360> {
361 let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>> =
362 match request {
363 Request::Get(req) => {
364 let value = get::execute_transform(executor, req, transform, agent_arguments).await?;
365 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
366 }
367 Request::GetRequestSchema(req) => {
368 let value = get::request_schema::execute_transform(executor, req, transform, agent_arguments).await?;
369 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
370 }
371 Request::GetResponseSchema(req) => {
372 let value = get::response_schema::execute_transform(executor, req, transform, agent_arguments).await?;
373 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
374 }
375 Request::Address(req) => {
376 let inner = address::execute_transform(executor, req, transform, agent_arguments).await?;
377 Box::pin(inner)
378 }
379 Request::ObjectiveaiAuthorization(req) => {
380 let inner = objectiveai_authorization::execute_transform(executor, req, transform, agent_arguments).await?;
381 Box::pin(inner)
382 }
383 Request::OpenrouterAuthorization(req) => {
384 let inner = openrouter_authorization::execute_transform(executor, req, transform, agent_arguments).await?;
385 Box::pin(inner)
386 }
387 Request::GithubAuthorization(req) => {
388 let inner = github_authorization::execute_transform(executor, req, transform, agent_arguments).await?;
389 Box::pin(inner)
390 }
391 Request::McpAuthorization(req) => {
392 let inner = mcp_authorization::execute_transform(executor, req, transform, agent_arguments).await?;
393 Box::pin(inner)
394 }
395 Request::McpTimeoutMs(req) => {
396 let inner = mcp_timeout_ms::execute_transform(executor, req, transform, agent_arguments).await?;
397 Box::pin(inner)
398 }
399 Request::BackoffMaxElapsedTimeMs(req) => {
400 let inner = backoff_max_elapsed_time_ms::execute_transform(executor, req, transform, agent_arguments).await?;
401 Box::pin(inner)
402 }
403 Request::UserAgent(req) => {
404 let inner = user_agent::execute_transform(executor, req, transform, agent_arguments).await?;
405 Box::pin(inner)
406 }
407 Request::HttpReferer(req) => {
408 let inner = http_referer::execute_transform(executor, req, transform, agent_arguments).await?;
409 Box::pin(inner)
410 }
411 Request::XTitle(req) => {
412 let inner = x_title::execute_transform(executor, req, transform, agent_arguments).await?;
413 Box::pin(inner)
414 }
415 Request::CommitAuthorName(req) => {
416 let inner = commit_author_name::execute_transform(executor, req, transform, agent_arguments).await?;
417 Box::pin(inner)
418 }
419 Request::CommitAuthorEmail(req) => {
420 let inner = commit_author_email::execute_transform(executor, req, transform, agent_arguments).await?;
421 Box::pin(inner)
422 }
423 };
424 Ok(stream)
425}