1pub mod execute;
2pub mod get;
3pub mod list;
4pub mod profiles;
5pub mod publish;
6
7#[derive(clap::Subcommand)]
8pub enum Command {
9 Execute {
10 #[command(subcommand)]
11 command: execute::Command,
12 },
13 Get(get::Command),
14 List(list::Command),
15 Profiles {
16 #[command(subcommand)]
17 command: profiles::Command,
18 },
19 Publish(publish::Command),
20}
21
22#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
23#[serde(untagged)]
24#[schemars(rename = "cli.command.functions.Request")]
25pub enum Request {
26 #[schemars(title = "Execute")]
27 Execute(execute::Request),
28 #[schemars(title = "Get")]
29 Get(get::Request),
30 #[schemars(title = "GetRequestSchema")]
31 GetRequestSchema(get::request_schema::Request),
32 #[schemars(title = "GetResponseSchema")]
33 GetResponseSchema(get::response_schema::Request),
34 #[schemars(title = "List")]
35 List(list::Request),
36 #[schemars(title = "ListRequestSchema")]
37 ListRequestSchema(list::request_schema::Request),
38 #[schemars(title = "ListResponseSchema")]
39 ListResponseSchema(list::response_schema::Request),
40 #[schemars(title = "Profiles")]
41 Profiles(profiles::Request),
42 #[schemars(title = "Publish")]
43 Publish(publish::Request),
44 #[schemars(title = "PublishRequestSchema")]
45 PublishRequestSchema(publish::request_schema::Request),
46 #[schemars(title = "PublishResponseSchema")]
47 PublishResponseSchema(publish::response_schema::Request),
48}
49
50#[objectiveai_sdk_macros::json_schema_ignore]
53#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
54#[schemars(rename = "cli.command.functions.ResponseItem")]
55#[serde(untagged)]
56pub enum ResponseItem {
57 #[schemars(title = "Execute")]
58 Execute(execute::ResponseItem),
59 #[schemars(title = "Get")]
60 Get(get::Response),
61 #[schemars(title = "GetRequestSchema")]
62 GetRequestSchema(get::request_schema::Response),
63 #[schemars(title = "GetResponseSchema")]
64 GetResponseSchema(get::response_schema::Response),
65 #[schemars(title = "List")]
66 List(list::ResponseItem),
67 #[schemars(title = "ListRequestSchema")]
68 ListRequestSchema(list::request_schema::Response),
69 #[schemars(title = "ListResponseSchema")]
70 ListResponseSchema(list::response_schema::Response),
71 #[schemars(title = "Profiles")]
72 Profiles(profiles::ResponseItem),
73 #[schemars(title = "Publish")]
74 Publish(publish::Response),
75 #[schemars(title = "PublishRequestSchema")]
76 PublishRequestSchema(publish::request_schema::Response),
77 #[schemars(title = "PublishResponseSchema")]
78 PublishResponseSchema(publish::response_schema::Response),
79}
80
81#[cfg(feature = "mcp")]
82impl crate::cli::command::CommandResponse for ResponseItem {
83 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
84 match self {
85 ResponseItem::Execute(v) => v.into_mcp(),
86 ResponseItem::Get(v) => v.into_mcp(),
87 ResponseItem::GetRequestSchema(v) => v.into_mcp(),
88 ResponseItem::GetResponseSchema(v) => v.into_mcp(),
89 ResponseItem::List(v) => v.into_mcp(),
90 ResponseItem::ListRequestSchema(v) => v.into_mcp(),
91 ResponseItem::ListResponseSchema(v) => v.into_mcp(),
92 ResponseItem::Profiles(v) => v.into_mcp(),
93 ResponseItem::Publish(v) => v.into_mcp(),
94 ResponseItem::PublishRequestSchema(v) => v.into_mcp(),
95 ResponseItem::PublishResponseSchema(v) => v.into_mcp(),
96 }
97 }
98}
99
100impl TryFrom<Command> for Request {
101 type Error = crate::cli::command::FromArgsError;
102 fn try_from(command: Command) -> Result<Self, Self::Error> {
103 match command {
104 Command::Execute { command } =>
105 Ok(Request::Execute(execute::Request::try_from(command)?)),
106 Command::Get(cmd) => match cmd.schema {
107 None => Ok(Request::Get(get::Request::try_from(cmd.args)?)),
108 Some(get::Schema::RequestSchema(args)) =>
109 Ok(Request::GetRequestSchema(get::request_schema::Request::try_from(args)?)),
110 Some(get::Schema::ResponseSchema(args)) =>
111 Ok(Request::GetResponseSchema(get::response_schema::Request::try_from(args)?)),
112 },
113 Command::List(cmd) => match cmd.schema {
114 None => Ok(Request::List(list::Request::try_from(cmd.args)?)),
115 Some(list::Schema::RequestSchema(args)) =>
116 Ok(Request::ListRequestSchema(list::request_schema::Request::try_from(args)?)),
117 Some(list::Schema::ResponseSchema(args)) =>
118 Ok(Request::ListResponseSchema(list::response_schema::Request::try_from(args)?)),
119 },
120 Command::Profiles { command } =>
121 Ok(Request::Profiles(profiles::Request::try_from(command)?)),
122 Command::Publish(cmd) => match cmd.schema {
123 None => Ok(Request::Publish(publish::Request::try_from(cmd.args)?)),
124 Some(publish::Schema::RequestSchema(args)) =>
125 Ok(Request::PublishRequestSchema(publish::request_schema::Request::try_from(args)?)),
126 Some(publish::Schema::ResponseSchema(args)) =>
127 Ok(Request::PublishResponseSchema(publish::response_schema::Request::try_from(args)?)),
128 },
129 }
130 }
131}
132
133impl crate::cli::command::CommandRequest for Request {
134 fn request_base(&self) -> &crate::cli::command::RequestBase {
135 match self {
136 Request::Execute(inner) => inner.request_base(),
137 Request::Get(inner) => inner.request_base(),
138 Request::GetRequestSchema(inner) => inner.request_base(),
139 Request::GetResponseSchema(inner) => inner.request_base(),
140 Request::List(inner) => inner.request_base(),
141 Request::ListRequestSchema(inner) => inner.request_base(),
142 Request::ListResponseSchema(inner) => inner.request_base(),
143 Request::Profiles(inner) => inner.request_base(),
144 Request::Publish(inner) => inner.request_base(),
145 Request::PublishRequestSchema(inner) => inner.request_base(),
146 Request::PublishResponseSchema(inner) => inner.request_base(),
147 }
148 }
149
150 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
151 match self {
152 Request::Execute(inner) => inner.request_base_mut(),
153 Request::Get(inner) => inner.request_base_mut(),
154 Request::GetRequestSchema(inner) => inner.request_base_mut(),
155 Request::GetResponseSchema(inner) => inner.request_base_mut(),
156 Request::List(inner) => inner.request_base_mut(),
157 Request::ListRequestSchema(inner) => inner.request_base_mut(),
158 Request::ListResponseSchema(inner) => inner.request_base_mut(),
159 Request::Profiles(inner) => inner.request_base_mut(),
160 Request::Publish(inner) => inner.request_base_mut(),
161 Request::PublishRequestSchema(inner) => inner.request_base_mut(),
162 Request::PublishResponseSchema(inner) => inner.request_base_mut(),
163 }
164 }
165}
166
167#[cfg(feature = "cli-executor")]
168pub async fn execute<E: crate::cli::command::CommandExecutor>(
169 executor: &E,
170 request: Request,
171
172 agent_arguments: Option<&crate::cli::command::AgentArguments>,
173 ) -> Result<
174 std::pin::Pin<Box<dyn futures::Stream<Item = Result<ResponseItem, E::Error>> + Send>>,
175 E::Error,
176> {
177 use futures::StreamExt;
178 let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<ResponseItem, E::Error>> + Send>> =
179 match request {
180 Request::Execute(req) => {
181 let inner = execute::execute(executor, req, agent_arguments).await?;
182 Box::pin(inner.map(|r| r.map(ResponseItem::Execute)))
183 }
184 Request::Get(req) => {
185 let value = get::execute(executor, req, agent_arguments).await?;
186 Box::pin(crate::cli::command::StreamOnce::new(Ok(
187 ResponseItem::Get(value),
188 )))
189 }
190 Request::GetRequestSchema(req) => {
191 let value = get::request_schema::execute(executor, req, agent_arguments).await?;
192 Box::pin(crate::cli::command::StreamOnce::new(Ok(
193 ResponseItem::GetRequestSchema(value),
194 )))
195 }
196 Request::GetResponseSchema(req) => {
197 let value = get::response_schema::execute(executor, req, agent_arguments).await?;
198 Box::pin(crate::cli::command::StreamOnce::new(Ok(
199 ResponseItem::GetResponseSchema(value),
200 )))
201 }
202 Request::List(req) => {
203 let inner = list::execute(executor, req, agent_arguments).await?;
204 Box::pin(inner.map(|r| r.map(ResponseItem::List)))
205 }
206 Request::ListRequestSchema(req) => {
207 let value = list::request_schema::execute(executor, req, agent_arguments).await?;
208 Box::pin(crate::cli::command::StreamOnce::new(Ok(
209 ResponseItem::ListRequestSchema(value),
210 )))
211 }
212 Request::ListResponseSchema(req) => {
213 let value = list::response_schema::execute(executor, req, agent_arguments).await?;
214 Box::pin(crate::cli::command::StreamOnce::new(Ok(
215 ResponseItem::ListResponseSchema(value),
216 )))
217 }
218 Request::Profiles(req) => {
219 let inner = profiles::execute(executor, req, agent_arguments).await?;
220 Box::pin(inner.map(|r| r.map(ResponseItem::Profiles)))
221 }
222 Request::Publish(req) => {
223 let value = publish::execute(executor, req, agent_arguments).await?;
224 Box::pin(crate::cli::command::StreamOnce::new(Ok(
225 ResponseItem::Publish(value),
226 )))
227 }
228 Request::PublishRequestSchema(req) => {
229 let value = publish::request_schema::execute(executor, req, agent_arguments).await?;
230 Box::pin(crate::cli::command::StreamOnce::new(Ok(
231 ResponseItem::PublishRequestSchema(value),
232 )))
233 }
234 Request::PublishResponseSchema(req) => {
235 let value = publish::response_schema::execute(executor, req, agent_arguments).await?;
236 Box::pin(crate::cli::command::StreamOnce::new(Ok(
237 ResponseItem::PublishResponseSchema(value),
238 )))
239 }
240 };
241 Ok(stream)
242}
243
244#[cfg(feature = "cli-executor")]
245pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
246 executor: &E,
247 request: Request,
248 transform: crate::cli::command::Transform,
249
250 agent_arguments: Option<&crate::cli::command::AgentArguments>,
251 ) -> Result<
252 std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>>,
253 E::Error,
254> {
255 let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>> =
256 match request {
257 Request::Execute(req) => {
258 let inner = execute::execute_transform(executor, req, transform, agent_arguments).await?;
259 Box::pin(inner)
260 }
261 Request::Get(req) => {
262 let value = get::execute_transform(executor, req, transform, agent_arguments).await?;
263 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
264 }
265 Request::GetRequestSchema(req) => {
266 let value = get::request_schema::execute_transform(executor, req, transform, agent_arguments).await?;
267 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
268 }
269 Request::GetResponseSchema(req) => {
270 let value = get::response_schema::execute_transform(executor, req, transform, agent_arguments).await?;
271 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
272 }
273 Request::List(req) => {
274 let inner = list::execute_transform(executor, req, transform, agent_arguments).await?;
275 Box::pin(inner)
276 }
277 Request::ListRequestSchema(req) => {
278 let value = list::request_schema::execute_transform(executor, req, transform, agent_arguments).await?;
279 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
280 }
281 Request::ListResponseSchema(req) => {
282 let value = list::response_schema::execute_transform(executor, req, transform, agent_arguments).await?;
283 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
284 }
285 Request::Profiles(req) => {
286 let inner = profiles::execute_transform(executor, req, transform, agent_arguments).await?;
287 Box::pin(inner)
288 }
289 Request::Publish(req) => {
290 let value = publish::execute_transform(executor, req, transform, agent_arguments).await?;
291 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
292 }
293 Request::PublishRequestSchema(req) => {
294 let value = publish::request_schema::execute_transform(executor, req, transform, agent_arguments).await?;
295 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
296 }
297 Request::PublishResponseSchema(req) => {
298 let value = publish::response_schema::execute_transform(executor, req, transform, agent_arguments).await?;
299 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
300 }
301 };
302 Ok(stream)
303}