Skip to main content

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

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