objectiveai_sdk/cli/command/agents/list/available/
mod.rs1use crate::cli::command::CommandRequest;
4
5#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
6#[schemars(rename = "cli.command.agents.list.available.Request")]
7pub struct Request {
8 pub path_type: Path,
9 pub source: RequestSource,
10 pub jq: Option<String>,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
14#[schemars(rename = "cli.command.agents.list.available.Path")]
15pub enum Path {
16 #[serde(rename = "agents/list/available")]
17 AgentsListAvailable,
18}
19
20#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema, clap::ValueEnum)]
21#[clap(rename_all = "kebab-case")]
22#[schemars(rename = "cli.command.agents.list.available.RequestSource")]
23pub enum RequestSource {
24 Filesystem,
25 Favorites,
26 Objectiveai,
27 Mock,
28 All,
29}
30
31impl RequestSource {
32 fn as_str(&self) -> &'static str {
33 match self {
34 RequestSource::Filesystem => "filesystem",
35 RequestSource::Favorites => "favorites",
36 RequestSource::Objectiveai => "objectiveai",
37 RequestSource::Mock => "mock",
38 RequestSource::All => "all",
39 }
40 }
41}
42
43impl CommandRequest for Request {
44 fn into_command(&self) -> Vec<String> {
45 let mut argv = vec![
46 "agents".to_string(),
47 "list".to_string(),
48 "available".to_string(),
49 "--source".to_string(),
50 self.source.as_str().to_string(),
51 ];
52 if let Some(jq) = &self.jq {
53 argv.push("--jq".to_string());
54 argv.push(jq.clone());
55 }
56 argv
57 }
58}
59
60#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
61#[schemars(rename = "cli.command.agents.list.available.ResponseFavorite")]
62pub struct ResponseFavorite {
63 pub name: String,
64 #[serde(flatten)]
65 pub path: crate::RemotePathCommitOptional,
66 pub note: String,
67}
68
69#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
70#[serde(untagged)]
71#[schemars(rename = "cli.command.agents.list.available.ResponseItem")]
72pub enum ResponseItem {
73 #[schemars(title = "Favorite")]
74 Favorite(ResponseFavorite),
75 #[schemars(title = "Item")]
76 Item(crate::RemotePath),
77}
78
79#[derive(clap::Args)]
80pub struct Args {
81 #[arg(long, value_enum)]
83 pub source: RequestSource,
84 #[arg(long)]
86 pub jq: Option<String>,
87}
88
89#[derive(clap::Args)]
90#[command(args_conflicts_with_subcommands = true)]
91pub struct Command {
92 #[command(flatten)]
93 pub args: Args,
94 #[command(subcommand)]
95 pub schema: Option<Schema>,
96}
97
98#[derive(clap::Subcommand)]
99pub enum Schema {
100 RequestSchema(request_schema::Args),
102 ResponseSchema(response_schema::Args),
104}
105
106impl TryFrom<Args> for Request {
107 type Error = crate::cli::command::FromArgsError;
108 fn try_from(args: Args) -> Result<Self, Self::Error> {
109 Ok(Self { path_type: Path::AgentsListAvailable,
110 source: args.source,
111 jq: args.jq,
112 })
113 }
114}
115
116#[cfg(feature = "cli-executor")]
117pub async fn execute<E: crate::cli::command::CommandExecutor>(
118 executor: &E,
119 mut request: Request,
120
121 agent_arguments: Option<&crate::cli::command::AgentArguments>,
122 ) -> Result<E::Stream<ResponseItem>, E::Error> {
123 request.jq = None;
124 executor.execute(request, agent_arguments).await
125}
126
127#[cfg(feature = "cli-executor")]
128pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
129 executor: &E,
130 mut request: Request,
131 jq: String,
132
133 agent_arguments: Option<&crate::cli::command::AgentArguments>,
134 ) -> Result<E::Stream<serde_json::Value>, E::Error> {
135 request.jq = Some(jq);
136 executor.execute(request, agent_arguments).await
137}
138
139#[cfg(feature = "mcp")]
140impl crate::cli::command::CommandResponse for ResponseItem {
141 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
142 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
143 }
144}
145
146pub mod request_schema;
147
148
149pub mod response_schema;