objectiveai_sdk/cli/command/agents/list/
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.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.Path")]
15pub enum Path {
16 #[serde(rename = "agents/list")]
17 AgentsList,
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.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 "--source".to_string(),
49 self.source.as_str().to_string(),
50 ];
51 if let Some(jq) = &self.jq {
52 argv.push("--jq".to_string());
53 argv.push(jq.clone());
54 }
55 argv
56 }
57}
58
59#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
60#[schemars(rename = "cli.command.agents.list.ResponseFavorite")]
61pub struct ResponseFavorite {
62 pub name: String,
63 #[serde(flatten)]
64 pub path: crate::RemotePathCommitOptional,
65 pub note: String,
66}
67
68#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
69#[serde(untagged)]
70#[schemars(rename = "cli.command.agents.list.ResponseItem")]
71pub enum ResponseItem {
72 #[schemars(title = "Favorite")]
73 Favorite(ResponseFavorite),
74 #[schemars(title = "Item")]
75 Item(crate::RemotePath),
76}
77
78#[derive(clap::Args)]
79pub struct Args {
80 #[arg(long, value_enum)]
82 pub source: RequestSource,
83 #[arg(long)]
85 pub jq: Option<String>,
86}
87
88#[derive(clap::Args)]
89#[command(args_conflicts_with_subcommands = true)]
90pub struct Command {
91 #[command(flatten)]
92 pub args: Args,
93 #[command(subcommand)]
94 pub schema: Option<Schema>,
95}
96
97#[derive(clap::Subcommand)]
98pub enum Schema {
99 RequestSchema(request_schema::Args),
101 ResponseSchema(response_schema::Args),
103}
104
105impl TryFrom<Args> for Request {
106 type Error = crate::cli::command::FromArgsError;
107 fn try_from(args: Args) -> Result<Self, Self::Error> {
108 Ok(Self { path_type: Path::AgentsList,
109 source: args.source,
110 jq: args.jq,
111 })
112 }
113}
114
115#[cfg(feature = "cli-executor")]
116pub async fn execute<E: crate::cli::command::CommandExecutor>(
117 executor: &E,
118 mut request: Request,
119
120 agent_arguments: Option<&crate::cli::command::AgentArguments>,
121 ) -> Result<E::Stream<ResponseItem>, E::Error> {
122 request.jq = None;
123 executor.execute(request, agent_arguments).await
124}
125
126#[cfg(feature = "cli-executor")]
127pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
128 executor: &E,
129 mut request: Request,
130 jq: String,
131
132 agent_arguments: Option<&crate::cli::command::AgentArguments>,
133 ) -> Result<E::Stream<serde_json::Value>, E::Error> {
134 request.jq = Some(jq);
135 executor.execute(request, agent_arguments).await
136}
137
138#[cfg(feature = "mcp")]
139impl crate::cli::command::CommandResponse for ResponseItem {
140 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
141 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
142 }
143}
144
145pub mod request_schema;
146
147
148pub mod response_schema;