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