Skip to main content

objectiveai_sdk/cli/command/agents/instances/get/
mod.rs

1//! `agents instances get` — fetch per-agent aggregates (tags, queued
2//! count, spawn/active timestamps, total logged messages) for one or
3//! more targets. Same response shape as `agents instances list`, but
4//! each target resolves to the EXACT agent rather than its children;
5//! an explicitly-named target always yields an item (zero-filled when
6//! it has no activity).
7
8use crate::cli::command::CommandRequest;
9
10/// Reuse the shared `--target` enum and the `list` response item — a
11/// `get` row is identical in shape to a `list` row.
12pub use super::list::{ResponseItem, Target};
13
14#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
15#[schemars(rename = "cli.command.agents.instances.get.Request")]
16pub struct Request {
17    pub path_type: Path,
18    pub targets: Vec<Target>,
19    pub jq: Option<String>,
20}
21
22#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
23#[schemars(rename = "cli.command.agents.instances.get.Path")]
24pub enum Path {
25    #[serde(rename = "agents/instances/get")]
26    AgentsInstancesGet,
27}
28
29impl CommandRequest for Request {
30    fn into_command(&self) -> Vec<String> {
31        let mut argv = vec![
32            "agents".to_string(),
33            "instances".to_string(),
34            "get".to_string(),
35        ];
36        for target in &self.targets {
37            argv.push("--target".to_string());
38            argv.push(target.into_arg_string());
39        }
40        if let Some(jq) = &self.jq {
41            argv.push("--jq".to_string());
42            argv.push(jq.clone());
43        }
44        argv
45    }
46}
47
48#[derive(clap::Args)]
49pub struct Args {
50    /// One or more `--target instance=L[,parent=P]` entries. Also
51    /// accepts `--target tag=T` and `--target me`. Fetches each
52    /// resolved agent exactly (not its children).
53    #[arg(long = "target", required = true)]
54    pub targets: Vec<String>,
55    /// jq filter applied to the JSON output.
56    #[arg(long)]
57    pub jq: Option<String>,
58}
59
60#[derive(clap::Args)]
61#[command(args_conflicts_with_subcommands = true)]
62pub struct Command {
63    #[command(flatten)]
64    pub args: Args,
65    #[command(subcommand)]
66    pub schema: Option<Schema>,
67}
68
69#[derive(clap::Subcommand)]
70pub enum Schema {
71    /// Emit the JSON Schema for this leaf's `Request` type and exit.
72    RequestSchema(request_schema::Args),
73    /// Emit the JSON Schema for this leaf's `Response` type and exit.
74    ResponseSchema(response_schema::Args),
75}
76
77impl TryFrom<Args> for Request {
78    type Error = crate::cli::command::FromArgsError;
79    fn try_from(args: Args) -> Result<Self, Self::Error> {
80        let targets = args
81            .targets
82            .iter()
83            .map(|s| {
84                s.parse::<Target>().map_err(|msg| {
85                    crate::cli::command::FromArgsError::path_parse("target", msg)
86                })
87            })
88            .collect::<Result<Vec<_>, _>>()?;
89        Ok(Self {
90            path_type: Path::AgentsInstancesGet,
91            targets,
92            jq: args.jq,
93        })
94    }
95}
96
97#[cfg(feature = "cli-executor")]
98pub async fn execute<E: crate::cli::command::CommandExecutor>(
99    executor: &E,
100    mut request: Request,
101
102        agent_arguments: Option<&crate::cli::command::AgentArguments>,
103    ) -> Result<E::Stream<ResponseItem>, E::Error> {
104    request.jq = None;
105    executor.execute(request, agent_arguments).await
106}
107
108#[cfg(feature = "cli-executor")]
109pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
110    executor: &E,
111    mut request: Request,
112    jq: String,
113
114        agent_arguments: Option<&crate::cli::command::AgentArguments>,
115    ) -> Result<E::Stream<serde_json::Value>, E::Error> {
116    request.jq = Some(jq);
117    executor.execute(request, agent_arguments).await
118}
119
120pub mod request_schema;
121
122
123pub mod response_schema;