objectiveai_sdk/cli/command/development/
mod.rs1use crate::cli::command::CommandRequest;
12
13pub mod plugins;
14
15#[derive(clap::Subcommand)]
16pub enum Command {
17 Plugins {
19 #[command(subcommand)]
20 command: plugins::Command,
21 },
22}
23
24#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
25#[serde(untagged)]
26#[schemars(rename = "cli.command.development.Request")]
27pub enum Request {
28 Plugins(plugins::Request),
34}
35
36#[objectiveai_sdk_macros::json_schema_ignore]
39#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
40#[schemars(rename = "cli.command.development.ResponseItem")]
41#[serde(untagged)]
42pub enum ResponseItem {
43 #[schemars(title = "Plugins")]
44 Plugins(plugins::ResponseItem),
45}
46
47#[cfg(feature = "mcp")]
48impl crate::cli::command::CommandResponse for ResponseItem {
49 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
50 match self {
51 ResponseItem::Plugins(v) => v.into_mcp(),
52 }
53 }
54}
55
56impl TryFrom<Command> for Request {
57 type Error = crate::cli::command::FromArgsError;
58 fn try_from(command: Command) -> Result<Self, Self::Error> {
59 match command {
60 Command::Plugins { command } => {
61 Ok(Request::Plugins(plugins::Request::try_from(command)?))
62 }
63 }
64 }
65}
66
67impl CommandRequest for Request {
68 fn request_base(&self) -> &crate::cli::command::RequestBase {
69 match self {
70 Request::Plugins(inner) => inner.request_base(),
71 }
72 }
73
74 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
75 match self {
76 Request::Plugins(inner) => inner.request_base_mut(),
77 }
78 }
79}
80
81#[cfg(feature = "cli-executor")]
82pub async fn execute<E: crate::cli::command::CommandExecutor>(
83 executor: &E,
84 request: Request,
85 identity: Option<&crate::identity::Identity>,
86) -> Result<
87 std::pin::Pin<Box<dyn futures::Stream<Item = Result<ResponseItem, E::Error>> + Send>>,
88 E::Error,
89> {
90 use futures::StreamExt;
91 let stream: std::pin::Pin<
92 Box<dyn futures::Stream<Item = Result<ResponseItem, E::Error>> + Send>,
93 > = match request {
94 Request::Plugins(req) => {
95 let inner = plugins::execute(executor, req, identity).await?;
96 Box::pin(inner.map(|r| r.map(ResponseItem::Plugins)))
97 }
98 };
99 Ok(stream)
100}
101
102#[cfg(feature = "cli-executor")]
103pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
104 executor: &E,
105 request: Request,
106 transform: crate::cli::command::Transform,
107 identity: Option<&crate::identity::Identity>,
108) -> Result<
109 std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>>,
110 E::Error,
111> {
112 let stream: std::pin::Pin<
113 Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>,
114 > = match request {
115 Request::Plugins(req) => {
116 let inner = plugins::execute_transform(executor, req, transform, identity).await?;
117 Box::pin(inner)
118 }
119 };
120 Ok(stream)
121}
122
123#[cfg(all(feature = "cli", feature = "daemon"))]
125pub enum ListenerExecution {
126 Plugins(plugins::ListenerExecution),
127}