Skip to main content

objectiveai_sdk/cli/command/agents/list/
mod.rs

1//! `agents list available` — async handler stub.
2
3use 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    #[serde(flatten)]
11    pub base: crate::cli::command::RequestBase,
12}
13
14#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
15#[schemars(rename = "cli.command.agents.list.Path")]
16pub enum Path {
17    #[serde(rename = "agents/list")]
18    AgentsList,
19}
20
21#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema, clap::ValueEnum)]
22#[clap(rename_all = "kebab-case")]
23#[schemars(rename = "cli.command.agents.list.RequestSource")]
24pub enum RequestSource {
25    Filesystem,
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::Objectiveai => "objectiveai",
36            RequestSource::Mock => "mock",
37            RequestSource::All => "all",
38        }
39    }
40}
41
42impl CommandRequest for Request {
43    fn into_command(&self) -> Vec<String> {
44        let mut argv = vec![
45            "agents".to_string(),
46            "list".to_string(),
47            "--source".to_string(),
48            self.source.as_str().to_string(),
49        ];
50        self.base.push_flags(&mut argv);
51        argv
52    }
53
54    fn request_base(&self) -> &crate::cli::command::RequestBase {
55        &self.base
56    }
57
58    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
59        Some(&mut self.base)
60    }
61}
62
63/// The list endpoints return remote paths verbatim, so this is a plain
64/// alias of [`crate::RemotePath`] (not a wrapper enum) — its published
65/// schema is therefore the bare `RemotePath` `$ref` with no distinct
66/// named type for the SDK code generators to reconstruct.
67pub type ResponseItem = crate::RemotePath;
68
69#[derive(clap::Args)]
70pub struct Args {
71    /// Which source to list from.
72    #[arg(long, value_enum)]
73    pub source: RequestSource,
74    #[command(flatten)]
75    pub base: crate::cli::command::RequestBaseArgs,
76}
77
78#[derive(clap::Args)]
79#[command(args_conflicts_with_subcommands = true)]
80pub struct Command {
81    #[command(flatten)]
82    pub args: Args,
83    #[command(subcommand)]
84    pub schema: Option<Schema>,
85}
86
87#[derive(clap::Subcommand)]
88pub enum Schema {
89    /// Emit the JSON Schema for this leaf's `Request` type and exit.
90    RequestSchema(request_schema::Args),
91    /// Emit the JSON Schema for this leaf's `Response` type and exit.
92    ResponseSchema(response_schema::Args),
93}
94
95impl TryFrom<Args> for Request {
96    type Error = crate::cli::command::FromArgsError;
97    fn try_from(args: Args) -> Result<Self, Self::Error> {
98        Ok(Self { path_type: Path::AgentsList,
99            source: args.source,
100            base: args.base.into(),
101        })
102    }
103}
104
105#[cfg(feature = "cli-executor")]
106pub async fn execute<E: crate::cli::command::CommandExecutor>(
107    executor: &E,
108    mut request: Request,
109
110        agent_arguments: Option<&crate::cli::command::AgentArguments>,
111    ) -> Result<E::Stream<ResponseItem>, E::Error> {
112    request.base.clear_transform();
113    executor.execute(request, agent_arguments).await
114}
115
116#[cfg(feature = "cli-executor")]
117pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
118    executor: &E,
119    mut request: Request,
120    transform: crate::cli::command::Transform,
121
122        agent_arguments: Option<&crate::cli::command::AgentArguments>,
123    ) -> Result<E::Stream<serde_json::Value>, E::Error> {
124    request.base.set_transform(transform);
125    executor.execute(request, agent_arguments).await
126}
127
128// `ResponseItem` is `crate::RemotePath`; its `CommandResponse` impl lives
129// on `RemotePath` in `crate::remote` (one impl shared by every list leaf
130// that aliases it).
131
132pub mod request_schema;
133
134
135pub mod response_schema;