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