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