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