objectiveai_cli/command/plugins/install/
mod.rs1use std::pin::Pin;
7
8use futures::Stream;
9use objectiveai_sdk::cli::command::plugins::install::{Request, Response};
10
11use crate::context::Context;
12use crate::error::Error;
13
14pub mod filesystem;
15pub mod github;
16
17type ItemStream = Pin<Box<dyn Stream<Item = Result<Response, Error>> + Send>>;
18
19fn once<T: Send + 'static>(
20 item: Result<T, Error>,
21) -> Pin<Box<dyn Stream<Item = Result<T, Error>> + Send>> {
22 Box::pin(futures::stream::once(async move { item }))
23}
24
25pub async fn execute(ctx: &Context, request: Request) -> Result<ItemStream, Error> {
26 let stream: ItemStream = match request {
27 Request::Filesystem(req) => {
28 let value = filesystem::execute(ctx, req).await?;
29 once(Ok(Response::Filesystem(value)))
30 }
31 Request::FilesystemRequestSchema(req) => {
32 let value = filesystem::request_schema::execute(ctx, req).await?;
33 once(Ok(Response::FilesystemRequestSchema(value)))
34 }
35 Request::FilesystemResponseSchema(req) => {
36 let value = filesystem::response_schema::execute(ctx, req).await?;
37 once(Ok(Response::FilesystemResponseSchema(value)))
38 }
39 Request::Github(req) => {
40 let value = github::execute(ctx, req).await?;
41 once(Ok(Response::Github(value)))
42 }
43 Request::GithubRequestSchema(req) => {
44 let value = github::request_schema::execute(ctx, req).await?;
45 once(Ok(Response::GithubRequestSchema(value)))
46 }
47 Request::GithubResponseSchema(req) => {
48 let value = github::response_schema::execute(ctx, req).await?;
49 once(Ok(Response::GithubResponseSchema(value)))
50 }
51 };
52 Ok(stream)
53}