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    #[serde(flatten)]
20    pub base: crate::cli::command::RequestBase,
21}
22
23#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
24#[schemars(rename = "cli.command.agents.instances.get.Path")]
25pub enum Path {
26    #[serde(rename = "agents/instances/get")]
27    AgentsInstancesGet,
28}
29
30impl CommandRequest for Request {
31    fn into_command(&self) -> Vec<String> {
32        let mut argv = vec![
33            "agents".to_string(),
34            "instances".to_string(),
35            "get".to_string(),
36        ];
37        for target in &self.targets {
38            argv.push("--target".to_string());
39            argv.push(target.into_arg_string());
40        }
41        self.base.push_flags(&mut argv);
42        argv
43    }
44
45    fn request_base(&self) -> &crate::cli::command::RequestBase {
46        &self.base
47    }
48
49    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
50        Some(&mut self.base)
51    }
52}
53
54#[derive(clap::Args)]
55pub struct Args {
56    /// One or more `--target instance=L[,parent=P]` entries. Also
57    /// accepts `--target tag=T` and `--target me`. Fetches each
58    /// resolved agent exactly (not its children).
59    #[arg(long = "target", required = true)]
60    pub targets: Vec<String>,
61    #[command(flatten)]
62    pub base: crate::cli::command::RequestBaseArgs,
63}
64
65#[derive(clap::Args)]
66#[command(args_conflicts_with_subcommands = true)]
67pub struct Command {
68    #[command(flatten)]
69    pub args: Args,
70    #[command(subcommand)]
71    pub schema: Option<Schema>,
72}
73
74#[derive(clap::Subcommand)]
75pub enum Schema {
76    /// Emit the JSON Schema for this leaf's `Request` type and exit.
77    RequestSchema(request_schema::Args),
78    /// Emit the JSON Schema for this leaf's `Response` type and exit.
79    ResponseSchema(response_schema::Args),
80}
81
82impl TryFrom<Args> for Request {
83    type Error = crate::cli::command::FromArgsError;
84    fn try_from(args: Args) -> Result<Self, Self::Error> {
85        let targets = args
86            .targets
87            .iter()
88            .map(|s| {
89                s.parse::<Target>().map_err(|msg| {
90                    crate::cli::command::FromArgsError::path_parse("target", msg)
91                })
92            })
93            .collect::<Result<Vec<_>, _>>()?;
94        Ok(Self {
95            path_type: Path::AgentsInstancesGet,
96            targets,
97            base: args.base.into(),
98        })
99    }
100}
101
102#[cfg(feature = "cli-executor")]
103pub async fn execute<E: crate::cli::command::CommandExecutor>(
104    executor: &E,
105    mut request: Request,
106
107        agent_arguments: Option<&crate::cli::command::AgentArguments>,
108    ) -> Result<E::Stream<ResponseItem>, E::Error> {
109    request.base.clear_transform();
110    executor.execute(request, agent_arguments).await
111}
112
113#[cfg(feature = "cli-executor")]
114pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
115    executor: &E,
116    mut request: Request,
117    transform: crate::cli::command::Transform,
118
119        agent_arguments: Option<&crate::cli::command::AgentArguments>,
120    ) -> Result<E::Stream<serde_json::Value>, E::Error> {
121    request.base.set_transform(transform);
122    executor.execute(request, agent_arguments).await
123}
124
125pub mod request_schema;
126
127
128pub mod response_schema;