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