objectiveai_sdk/cli/command/config/viewer/
mod.rs1pub mod address;
2pub mod get;
3pub mod port;
4pub mod secret;
5pub mod signature;
6
7#[derive(clap::Subcommand)]
8pub enum Command {
9 Get(get::Command),
10 Address {
11 #[command(subcommand)]
12 command: address::Command,
13 },
14 Port {
15 #[command(subcommand)]
16 command: port::Command,
17 },
18 Secret {
19 #[command(subcommand)]
20 command: secret::Command,
21 },
22 Signature {
23 #[command(subcommand)]
24 command: signature::Command,
25 },
26}
27
28#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
29#[serde(untagged)]
30#[schemars(rename = "cli.command.config.viewer.Request")]
31pub enum Request {
32 #[schemars(title = "Get")]
33 Get(get::Request),
34 #[schemars(title = "GetRequestSchema")]
35 GetRequestSchema(get::request_schema::Request),
36 #[schemars(title = "GetResponseSchema")]
37 GetResponseSchema(get::response_schema::Request),
38 #[schemars(title = "Address")]
39 Address(address::Request),
40 #[schemars(title = "Port")]
41 Port(port::Request),
42 #[schemars(title = "Secret")]
43 Secret(secret::Request),
44 #[schemars(title = "Signature")]
45 Signature(signature::Request),
46}
47
48#[objectiveai_sdk_macros::json_schema_ignore]
51#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
52#[schemars(rename = "cli.command.config.viewer.Response")]
53#[serde(untagged)]
54pub enum 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 #[schemars(title = "Address")]
62 Address(address::Response),
63 #[schemars(title = "Port")]
64 Port(port::Response),
65 #[schemars(title = "Secret")]
66 Secret(secret::Response),
67 #[schemars(title = "Signature")]
68 Signature(signature::Response),
69}
70
71#[cfg(feature = "mcp")]
72impl crate::cli::command::CommandResponse for Response {
73 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
74 match self {
75 Response::Get(v) => v.into_mcp(),
76 Response::GetRequestSchema(v) => v.into_mcp(),
77 Response::GetResponseSchema(v) => v.into_mcp(),
78 Response::Address(v) => v.into_mcp(),
79 Response::Port(v) => v.into_mcp(),
80 Response::Secret(v) => v.into_mcp(),
81 Response::Signature(v) => v.into_mcp(),
82 }
83 }
84}
85
86impl TryFrom<Command> for Request {
87 type Error = crate::cli::command::FromArgsError;
88 fn try_from(command: Command) -> Result<Self, Self::Error> {
89 match command {
90 Command::Get(cmd) => match cmd.schema {
91 None => Ok(Request::Get(get::Request::try_from(cmd.args)?)),
92 Some(get::Schema::RequestSchema(args)) =>
93 Ok(Request::GetRequestSchema(get::request_schema::Request::try_from(args)?)),
94 Some(get::Schema::ResponseSchema(args)) =>
95 Ok(Request::GetResponseSchema(get::response_schema::Request::try_from(args)?)),
96 },
97 Command::Address { command } =>
98 Ok(Request::Address(address::Request::try_from(command)?)),
99 Command::Port { command } =>
100 Ok(Request::Port(port::Request::try_from(command)?)),
101 Command::Secret { command } =>
102 Ok(Request::Secret(secret::Request::try_from(command)?)),
103 Command::Signature { command } =>
104 Ok(Request::Signature(signature::Request::try_from(command)?)),
105 }
106 }
107}
108
109impl crate::cli::command::CommandRequest for Request {
110 fn into_command(&self) -> Vec<String> {
111 match self {
112 Request::Get(inner) => inner.into_command(),
113 Request::GetRequestSchema(inner) => inner.into_command(),
114 Request::GetResponseSchema(inner) => inner.into_command(),
115 Request::Address(inner) => inner.into_command(),
116 Request::Port(inner) => inner.into_command(),
117 Request::Secret(inner) => inner.into_command(),
118 Request::Signature(inner) => inner.into_command(),
119 }
120 }
121}
122
123#[cfg(feature = "cli-executor")]
124pub async fn execute<E: crate::cli::command::CommandExecutor>(
125 executor: &E,
126 request: Request,
127
128 agent_arguments: Option<&crate::cli::command::AgentArguments>,
129 ) -> Result<
130 std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>>,
131 E::Error,
132> {
133 use futures::StreamExt;
134 let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>> =
135 match request {
136 Request::Get(req) => {
137 let value = get::execute(executor, req, agent_arguments).await?;
138 Box::pin(crate::cli::command::StreamOnce::new(Ok(
139 Response::Get(value),
140 )))
141 }
142 Request::GetRequestSchema(req) => {
143 let value = get::request_schema::execute(executor, req, agent_arguments).await?;
144 Box::pin(crate::cli::command::StreamOnce::new(Ok(
145 Response::GetRequestSchema(value),
146 )))
147 }
148 Request::GetResponseSchema(req) => {
149 let value = get::response_schema::execute(executor, req, agent_arguments).await?;
150 Box::pin(crate::cli::command::StreamOnce::new(Ok(
151 Response::GetResponseSchema(value),
152 )))
153 }
154 Request::Address(req) => {
155 let inner = address::execute(executor, req, agent_arguments).await?;
156 Box::pin(inner.map(|r| r.map(Response::Address)))
157 }
158 Request::Port(req) => {
159 let inner = port::execute(executor, req, agent_arguments).await?;
160 Box::pin(inner.map(|r| r.map(Response::Port)))
161 }
162 Request::Secret(req) => {
163 let inner = secret::execute(executor, req, agent_arguments).await?;
164 Box::pin(inner.map(|r| r.map(Response::Secret)))
165 }
166 Request::Signature(req) => {
167 let inner = signature::execute(executor, req, agent_arguments).await?;
168 Box::pin(inner.map(|r| r.map(Response::Signature)))
169 }
170 };
171 Ok(stream)
172}
173
174#[cfg(feature = "cli-executor")]
175pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
176 executor: &E,
177 request: Request,
178 jq: String,
179
180 agent_arguments: Option<&crate::cli::command::AgentArguments>,
181 ) -> Result<
182 std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>>,
183 E::Error,
184> {
185 let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>> =
186 match request {
187 Request::Get(req) => {
188 let value = get::execute_jq(executor, req, jq, agent_arguments).await?;
189 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
190 }
191 Request::GetRequestSchema(req) => {
192 let value = get::request_schema::execute_jq(executor, req, jq, agent_arguments).await?;
193 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
194 }
195 Request::GetResponseSchema(req) => {
196 let value = get::response_schema::execute_jq(executor, req, jq, agent_arguments).await?;
197 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
198 }
199 Request::Address(req) => {
200 let inner = address::execute_jq(executor, req, jq, agent_arguments).await?;
201 Box::pin(inner)
202 }
203 Request::Port(req) => {
204 let inner = port::execute_jq(executor, req, jq, agent_arguments).await?;
205 Box::pin(inner)
206 }
207 Request::Secret(req) => {
208 let inner = secret::execute_jq(executor, req, jq, agent_arguments).await?;
209 Box::pin(inner)
210 }
211 Request::Signature(req) => {
212 let inner = signature::execute_jq(executor, req, jq, agent_arguments).await?;
213 Box::pin(inner)
214 }
215 };
216 Ok(stream)
217}