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