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