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