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