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    pub jq: Option<String>,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
14#[schemars(rename = "cli.command.functions.list.Path")]
15pub enum Path {
16    #[serde(rename = "functions/list")]
17    FunctionsList,
18}
19
20#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema, clap::ValueEnum)]
21#[clap(rename_all = "lowercase")]
22#[schemars(rename = "cli.command.functions.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!["functions".to_string(), "list".to_string(), "--source".to_string(), self.source.as_str().to_string()];
46        if let Some(jq) = &self.jq {
47            argv.push("--jq".to_string());
48            argv.push(jq.clone());
49        }
50        argv
51    }
52}
53
54#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
55#[schemars(rename = "cli.command.functions.list.ResponseFavorite")]
56pub struct ResponseFavorite {
57    pub name: String,
58    #[serde(flatten)]
59    pub path: crate::RemotePathCommitOptional,
60    pub note: String,
61}
62
63#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
64#[schemars(rename = "cli.command.functions.list.Response")]
65pub struct Response {
66    pub items: Vec<ResponseItem>,
67}
68
69#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
70#[serde(untagged)]
71#[schemars(rename = "cli.command.functions.list.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    /// Source to list from.
82    #[arg(long, value_enum)]
83    pub source: RequestSource,
84    /// jq filter applied to the JSON output.
85    #[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    /// Emit the JSON Schema for this leaf's `Request` type and exit.
101    RequestSchema(request_schema::Args),
102    /// Emit the JSON Schema for this leaf's `Response` type and exit.
103    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::FunctionsList,
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 Response {
141    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
142        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
143    }
144}
145
146#[cfg(feature = "mcp")]
147impl crate::cli::command::CommandResponse for ResponseItem {
148    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
149        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
150    }
151}
152
153pub mod request_schema;
154
155
156pub mod response_schema;