Skip to main content

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

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