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_call_timeout_ms;
10pub mod mcp_connect_timeout_ms;
11pub mod objectiveai_authorization;
12pub mod openrouter_authorization;
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 ObjectiveaiAuthorization {
24 #[command(subcommand)]
25 command: objectiveai_authorization::Command,
26 },
27 OpenrouterAuthorization {
28 #[command(subcommand)]
29 command: openrouter_authorization::Command,
30 },
31 GithubAuthorization {
32 #[command(subcommand)]
33 command: github_authorization::Command,
34 },
35 McpAuthorization {
36 #[command(subcommand)]
37 command: mcp_authorization::Command,
38 },
39 McpCallTimeoutMs {
40 #[command(subcommand)]
41 command: mcp_call_timeout_ms::Command,
42 },
43 McpConnectTimeoutMs {
44 #[command(subcommand)]
45 command: mcp_connect_timeout_ms::Command,
46 },
47 BackoffMaxElapsedTimeMs {
48 #[command(subcommand)]
49 command: backoff_max_elapsed_time_ms::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.api.config.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 = "ObjectiveaiAuthorization")]
86 ObjectiveaiAuthorization(objectiveai_authorization::Request),
87 #[schemars(title = "OpenrouterAuthorization")]
88 OpenrouterAuthorization(openrouter_authorization::Request),
89 #[schemars(title = "GithubAuthorization")]
90 GithubAuthorization(github_authorization::Request),
91 #[schemars(title = "McpAuthorization")]
92 McpAuthorization(mcp_authorization::Request),
93 #[schemars(title = "McpCallTimeoutMs")]
94 McpCallTimeoutMs(mcp_call_timeout_ms::Request),
95 #[schemars(title = "McpConnectTimeoutMs")]
96 McpConnectTimeoutMs(mcp_connect_timeout_ms::Request),
97 #[schemars(title = "BackoffMaxElapsedTimeMs")]
98 BackoffMaxElapsedTimeMs(backoff_max_elapsed_time_ms::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#[objectiveai_sdk_macros::json_schema_ignore]
114#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
115#[schemars(rename = "cli.command.api.config.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 = "ObjectiveaiAuthorization")]
127 ObjectiveaiAuthorization(objectiveai_authorization::Response),
128 #[schemars(title = "OpenrouterAuthorization")]
129 OpenrouterAuthorization(openrouter_authorization::Response),
130 #[schemars(title = "GithubAuthorization")]
131 GithubAuthorization(github_authorization::Response),
132 #[schemars(title = "McpAuthorization")]
133 McpAuthorization(mcp_authorization::Response),
134 #[schemars(title = "McpCallTimeoutMs")]
135 McpCallTimeoutMs(mcp_call_timeout_ms::Response),
136 #[schemars(title = "McpConnectTimeoutMs")]
137 McpConnectTimeoutMs(mcp_connect_timeout_ms::Response),
138 #[schemars(title = "BackoffMaxElapsedTimeMs")]
139 BackoffMaxElapsedTimeMs(backoff_max_elapsed_time_ms::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::ObjectiveaiAuthorization(v) => v.into_mcp(),
161 Response::OpenrouterAuthorization(v) => v.into_mcp(),
162 Response::GithubAuthorization(v) => v.into_mcp(),
163 Response::McpAuthorization(v) => v.into_mcp(),
164 Response::McpCallTimeoutMs(v) => v.into_mcp(),
165 Response::McpConnectTimeoutMs(v) => v.into_mcp(),
166 Response::BackoffMaxElapsedTimeMs(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::ObjectiveaiAuthorization { command } =>
190 Ok(Request::ObjectiveaiAuthorization(objectiveai_authorization::Request::try_from(command)?)),
191 Command::OpenrouterAuthorization { command } =>
192 Ok(Request::OpenrouterAuthorization(openrouter_authorization::Request::try_from(command)?)),
193 Command::GithubAuthorization { command } =>
194 Ok(Request::GithubAuthorization(github_authorization::Request::try_from(command)?)),
195 Command::McpAuthorization { command } =>
196 Ok(Request::McpAuthorization(mcp_authorization::Request::try_from(command)?)),
197 Command::McpCallTimeoutMs { command } =>
198 Ok(Request::McpCallTimeoutMs(mcp_call_timeout_ms::Request::try_from(command)?)),
199 Command::McpConnectTimeoutMs { command } =>
200 Ok(Request::McpConnectTimeoutMs(mcp_connect_timeout_ms::Request::try_from(command)?)),
201 Command::BackoffMaxElapsedTimeMs { command } =>
202 Ok(Request::BackoffMaxElapsedTimeMs(backoff_max_elapsed_time_ms::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 request_base(&self) -> &crate::cli::command::RequestBase {
219 match self {
220 Request::Get(inner) => inner.request_base(),
221 Request::GetRequestSchema(inner) => inner.request_base(),
222 Request::GetResponseSchema(inner) => inner.request_base(),
223 Request::Address(inner) => inner.request_base(),
224 Request::ObjectiveaiAuthorization(inner) => inner.request_base(),
225 Request::OpenrouterAuthorization(inner) => inner.request_base(),
226 Request::GithubAuthorization(inner) => inner.request_base(),
227 Request::McpAuthorization(inner) => inner.request_base(),
228 Request::McpCallTimeoutMs(inner) => inner.request_base(),
229 Request::McpConnectTimeoutMs(inner) => inner.request_base(),
230 Request::BackoffMaxElapsedTimeMs(inner) => inner.request_base(),
231 Request::UserAgent(inner) => inner.request_base(),
232 Request::HttpReferer(inner) => inner.request_base(),
233 Request::XTitle(inner) => inner.request_base(),
234 Request::CommitAuthorName(inner) => inner.request_base(),
235 Request::CommitAuthorEmail(inner) => inner.request_base(),
236 }
237 }
238
239 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
240 match self {
241 Request::Get(inner) => inner.request_base_mut(),
242 Request::GetRequestSchema(inner) => inner.request_base_mut(),
243 Request::GetResponseSchema(inner) => inner.request_base_mut(),
244 Request::Address(inner) => inner.request_base_mut(),
245 Request::ObjectiveaiAuthorization(inner) => inner.request_base_mut(),
246 Request::OpenrouterAuthorization(inner) => inner.request_base_mut(),
247 Request::GithubAuthorization(inner) => inner.request_base_mut(),
248 Request::McpAuthorization(inner) => inner.request_base_mut(),
249 Request::McpCallTimeoutMs(inner) => inner.request_base_mut(),
250 Request::McpConnectTimeoutMs(inner) => inner.request_base_mut(),
251 Request::BackoffMaxElapsedTimeMs(inner) => inner.request_base_mut(),
252 Request::UserAgent(inner) => inner.request_base_mut(),
253 Request::HttpReferer(inner) => inner.request_base_mut(),
254 Request::XTitle(inner) => inner.request_base_mut(),
255 Request::CommitAuthorName(inner) => inner.request_base_mut(),
256 Request::CommitAuthorEmail(inner) => inner.request_base_mut(),
257 }
258 }
259}
260
261#[cfg(feature = "cli-executor")]
262pub async fn execute<E: crate::cli::command::CommandExecutor>(
263 executor: &E,
264 request: Request,
265
266 agent_arguments: Option<&crate::cli::command::AgentArguments>,
267 ) -> Result<
268 std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>>,
269 E::Error,
270> {
271 use futures::StreamExt;
272 let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>> =
273 match request {
274 Request::Get(req) => {
275 let value = get::execute(executor, req, agent_arguments).await?;
276 Box::pin(crate::cli::command::StreamOnce::new(Ok(
277 Response::Get(value),
278 )))
279 }
280 Request::GetRequestSchema(req) => {
281 let value = get::request_schema::execute(executor, req, agent_arguments).await?;
282 Box::pin(crate::cli::command::StreamOnce::new(Ok(
283 Response::GetRequestSchema(value),
284 )))
285 }
286 Request::GetResponseSchema(req) => {
287 let value = get::response_schema::execute(executor, req, agent_arguments).await?;
288 Box::pin(crate::cli::command::StreamOnce::new(Ok(
289 Response::GetResponseSchema(value),
290 )))
291 }
292 Request::Address(req) => {
293 let inner = address::execute(executor, req, agent_arguments).await?;
294 Box::pin(inner.map(|r| r.map(Response::Address)))
295 }
296 Request::ObjectiveaiAuthorization(req) => {
297 let inner = objectiveai_authorization::execute(executor, req, agent_arguments).await?;
298 Box::pin(inner.map(|r| r.map(Response::ObjectiveaiAuthorization)))
299 }
300 Request::OpenrouterAuthorization(req) => {
301 let inner = openrouter_authorization::execute(executor, req, agent_arguments).await?;
302 Box::pin(inner.map(|r| r.map(Response::OpenrouterAuthorization)))
303 }
304 Request::GithubAuthorization(req) => {
305 let inner = github_authorization::execute(executor, req, agent_arguments).await?;
306 Box::pin(inner.map(|r| r.map(Response::GithubAuthorization)))
307 }
308 Request::McpAuthorization(req) => {
309 let inner = mcp_authorization::execute(executor, req, agent_arguments).await?;
310 Box::pin(inner.map(|r| r.map(Response::McpAuthorization)))
311 }
312 Request::McpCallTimeoutMs(req) => {
313 let inner = mcp_call_timeout_ms::execute(executor, req, agent_arguments).await?;
314 Box::pin(inner.map(|r| r.map(Response::McpCallTimeoutMs)))
315 }
316 Request::McpConnectTimeoutMs(req) => {
317 let inner = mcp_connect_timeout_ms::execute(executor, req, agent_arguments).await?;
318 Box::pin(inner.map(|r| r.map(Response::McpConnectTimeoutMs)))
319 }
320 Request::BackoffMaxElapsedTimeMs(req) => {
321 let inner = backoff_max_elapsed_time_ms::execute(executor, req, agent_arguments).await?;
322 Box::pin(inner.map(|r| r.map(Response::BackoffMaxElapsedTimeMs)))
323 }
324 Request::UserAgent(req) => {
325 let inner = user_agent::execute(executor, req, agent_arguments).await?;
326 Box::pin(inner.map(|r| r.map(Response::UserAgent)))
327 }
328 Request::HttpReferer(req) => {
329 let inner = http_referer::execute(executor, req, agent_arguments).await?;
330 Box::pin(inner.map(|r| r.map(Response::HttpReferer)))
331 }
332 Request::XTitle(req) => {
333 let inner = x_title::execute(executor, req, agent_arguments).await?;
334 Box::pin(inner.map(|r| r.map(Response::XTitle)))
335 }
336 Request::CommitAuthorName(req) => {
337 let inner = commit_author_name::execute(executor, req, agent_arguments).await?;
338 Box::pin(inner.map(|r| r.map(Response::CommitAuthorName)))
339 }
340 Request::CommitAuthorEmail(req) => {
341 let inner = commit_author_email::execute(executor, req, agent_arguments).await?;
342 Box::pin(inner.map(|r| r.map(Response::CommitAuthorEmail)))
343 }
344 };
345 Ok(stream)
346}
347
348#[cfg(feature = "cli-executor")]
349pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
350 executor: &E,
351 request: Request,
352 transform: crate::cli::command::Transform,
353
354 agent_arguments: Option<&crate::cli::command::AgentArguments>,
355 ) -> Result<
356 std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>>,
357 E::Error,
358> {
359 let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>> =
360 match request {
361 Request::Get(req) => {
362 let value = get::execute_transform(executor, req, transform, agent_arguments).await?;
363 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
364 }
365 Request::GetRequestSchema(req) => {
366 let value = get::request_schema::execute_transform(executor, req, transform, agent_arguments).await?;
367 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
368 }
369 Request::GetResponseSchema(req) => {
370 let value = get::response_schema::execute_transform(executor, req, transform, agent_arguments).await?;
371 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
372 }
373 Request::Address(req) => {
374 let inner = address::execute_transform(executor, req, transform, agent_arguments).await?;
375 Box::pin(inner)
376 }
377 Request::ObjectiveaiAuthorization(req) => {
378 let inner = objectiveai_authorization::execute_transform(executor, req, transform, agent_arguments).await?;
379 Box::pin(inner)
380 }
381 Request::OpenrouterAuthorization(req) => {
382 let inner = openrouter_authorization::execute_transform(executor, req, transform, agent_arguments).await?;
383 Box::pin(inner)
384 }
385 Request::GithubAuthorization(req) => {
386 let inner = github_authorization::execute_transform(executor, req, transform, agent_arguments).await?;
387 Box::pin(inner)
388 }
389 Request::McpAuthorization(req) => {
390 let inner = mcp_authorization::execute_transform(executor, req, transform, agent_arguments).await?;
391 Box::pin(inner)
392 }
393 Request::McpCallTimeoutMs(req) => {
394 let inner = mcp_call_timeout_ms::execute_transform(executor, req, transform, agent_arguments).await?;
395 Box::pin(inner)
396 }
397 Request::McpConnectTimeoutMs(req) => {
398 let inner = mcp_connect_timeout_ms::execute_transform(executor, req, transform, agent_arguments).await?;
399 Box::pin(inner)
400 }
401 Request::BackoffMaxElapsedTimeMs(req) => {
402 let inner = backoff_max_elapsed_time_ms::execute_transform(executor, req, transform, agent_arguments).await?;
403 Box::pin(inner)
404 }
405 Request::UserAgent(req) => {
406 let inner = user_agent::execute_transform(executor, req, transform, agent_arguments).await?;
407 Box::pin(inner)
408 }
409 Request::HttpReferer(req) => {
410 let inner = http_referer::execute_transform(executor, req, transform, agent_arguments).await?;
411 Box::pin(inner)
412 }
413 Request::XTitle(req) => {
414 let inner = x_title::execute_transform(executor, req, transform, agent_arguments).await?;
415 Box::pin(inner)
416 }
417 Request::CommitAuthorName(req) => {
418 let inner = commit_author_name::execute_transform(executor, req, transform, agent_arguments).await?;
419 Box::pin(inner)
420 }
421 Request::CommitAuthorEmail(req) => {
422 let inner = commit_author_email::execute_transform(executor, req, transform, agent_arguments).await?;
423 Box::pin(inner)
424 }
425 };
426 Ok(stream)
427}
428
429#[cfg(feature = "cli-listener")]
432pub enum ListenerExecution {
433 Get(get::ListenerExecution),
434 GetRequestSchema(get::request_schema::ListenerExecution),
435 GetResponseSchema(get::response_schema::ListenerExecution),
436 Address(address::ListenerExecution),
437 ObjectiveaiAuthorization(objectiveai_authorization::ListenerExecution),
438 OpenrouterAuthorization(openrouter_authorization::ListenerExecution),
439 GithubAuthorization(github_authorization::ListenerExecution),
440 McpAuthorization(mcp_authorization::ListenerExecution),
441 McpCallTimeoutMs(mcp_call_timeout_ms::ListenerExecution),
442 McpConnectTimeoutMs(mcp_connect_timeout_ms::ListenerExecution),
443 BackoffMaxElapsedTimeMs(backoff_max_elapsed_time_ms::ListenerExecution),
444 UserAgent(user_agent::ListenerExecution),
445 HttpReferer(http_referer::ListenerExecution),
446 XTitle(x_title::ListenerExecution),
447 CommitAuthorName(commit_author_name::ListenerExecution),
448 CommitAuthorEmail(commit_author_email::ListenerExecution),
449}