Skip to main content

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

1//! `tools 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.tools.list.Request")]
7pub struct Request {
8    pub path_type: Path,
9    pub offset: Option<usize>,
10    pub limit: Option<usize>,
11    pub jq: Option<String>,
12}
13
14#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
15#[schemars(rename = "cli.command.tools.list.Path")]
16pub enum Path {
17    #[serde(rename = "tools/list")]
18    ToolsList,
19}
20
21impl CommandRequest for Request {
22    fn into_command(&self) -> Vec<String> {
23        let mut argv = vec!["tools".to_string(), "list".to_string()];
24        if let Some(offset) = self.offset {
25            argv.push("--offset".to_string());
26            argv.push(offset.to_string());
27        }
28        if let Some(limit) = self.limit {
29            argv.push("--limit".to_string());
30            argv.push(limit.to_string());
31        }
32        if let Some(jq) = &self.jq {
33            argv.push("--jq".to_string());
34            argv.push(jq.clone());
35        }
36        argv
37    }
38}
39
40// Each list item carries the same shape as `tools get`'s response —
41// `ResponseManifest` is the canonical definition. Re-export here so
42// list items deserialize as the same Rust type.
43pub use super::get::ResponseManifest as ResponseItem;
44
45#[derive(clap::Args)]
46pub struct Args {
47    /// Skip the first N matching entries.
48    #[arg(long)]
49    pub offset: Option<usize>,
50    /// Return at most N matching entries.
51    #[arg(long)]
52    pub limit: Option<usize>,
53    /// jq filter applied to the JSON output.
54    #[arg(long)]
55    pub jq: Option<String>,
56}
57
58#[derive(clap::Args)]
59#[command(args_conflicts_with_subcommands = true)]
60pub struct Command {
61    #[command(flatten)]
62    pub args: Args,
63    #[command(subcommand)]
64    pub schema: Option<Schema>,
65}
66
67#[derive(clap::Subcommand)]
68pub enum Schema {
69    /// Emit the JSON Schema for this leaf's `Request` type and exit.
70    RequestSchema(request_schema::Args),
71    /// Emit the JSON Schema for this leaf's `Response` type and exit.
72    ResponseSchema(response_schema::Args),
73}
74
75impl TryFrom<Args> for Request {
76    type Error = crate::cli::command::FromArgsError;
77    fn try_from(args: Args) -> Result<Self, Self::Error> {
78        Ok(Self { path_type: Path::ToolsList,
79            offset: args.offset,
80            limit: args.limit,
81            jq: args.jq,
82        })
83    }
84}
85
86#[cfg(feature = "cli-executor")]
87pub async fn execute<E: crate::cli::command::CommandExecutor>(
88    executor: &E,
89    mut request: Request,
90
91        agent_arguments: Option<&crate::cli::command::AgentArguments>,
92    ) -> Result<E::Stream<ResponseItem>, E::Error> {
93    request.jq = None;
94    executor.execute(request, agent_arguments).await
95}
96
97#[cfg(feature = "cli-executor")]
98pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
99    executor: &E,
100    mut request: Request,
101    jq: String,
102
103        agent_arguments: Option<&crate::cli::command::AgentArguments>,
104    ) -> Result<E::Stream<serde_json::Value>, E::Error> {
105    request.jq = Some(jq);
106    executor.execute(request, agent_arguments).await
107}
108
109pub mod request_schema;
110
111
112pub mod response_schema;