Skip to main content

objectiveai_sdk/cli/command/viewer/
mod.rs

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