objectiveai_sdk/cli/command/agents/instances/list/
mod.rs1use crate::cli::command::CommandRequest;
6
7pub use super::super::logs::read::all::Target;
11
12#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
13#[schemars(rename = "cli.command.agents.instances.list.Request")]
14pub struct Request {
15 pub path_type: Path,
16 pub targets: Vec<Target>,
17 pub jq: Option<String>,
18}
19
20#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
21#[schemars(rename = "cli.command.agents.instances.list.Path")]
22pub enum Path {
23 #[serde(rename = "agents/instances/list")]
24 AgentsInstancesList,
25}
26
27impl CommandRequest for Request {
28 fn into_command(&self) -> Vec<String> {
29 let mut argv = vec![
30 "agents".to_string(),
31 "instances".to_string(),
32 "list".to_string(),
33 ];
34 for target in &self.targets {
35 argv.push("--target".to_string());
36 argv.push(target.into_arg_string());
37 }
38 if let Some(jq) = &self.jq {
39 argv.push("--jq".to_string());
40 argv.push(jq.clone());
41 }
42 argv
43 }
44}
45
46#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
49#[schemars(rename = "cli.command.agents.instances.list.ResponseItem")]
50pub struct ResponseItem {
51 pub agent_instance_hierarchy: String,
53 pub tags: Vec<String>,
55 pub queued: u64,
58 #[serde(default, skip_serializing_if = "Option::is_none")]
61 #[schemars(extend("omitempty" = true))]
62 pub timestamp_spawned: Option<i64>,
63 #[serde(default, skip_serializing_if = "Option::is_none")]
66 #[schemars(extend("omitempty" = true))]
67 pub timestamp_active: Option<i64>,
68 pub logged: u64,
70}
71
72#[derive(clap::Args)]
73pub struct Args {
74 #[arg(long = "target", required = true)]
78 pub targets: Vec<String>,
79 #[arg(long)]
81 pub jq: Option<String>,
82}
83
84#[derive(clap::Args)]
85#[command(args_conflicts_with_subcommands = true)]
86pub struct Command {
87 #[command(flatten)]
88 pub args: Args,
89 #[command(subcommand)]
90 pub schema: Option<Schema>,
91}
92
93#[derive(clap::Subcommand)]
94pub enum Schema {
95 RequestSchema(request_schema::Args),
97 ResponseSchema(response_schema::Args),
99}
100
101impl TryFrom<Args> for Request {
102 type Error = crate::cli::command::FromArgsError;
103 fn try_from(args: Args) -> Result<Self, Self::Error> {
104 let targets = args
105 .targets
106 .iter()
107 .map(|s| {
108 s.parse::<Target>().map_err(|msg| {
109 crate::cli::command::FromArgsError::path_parse("target", msg)
110 })
111 })
112 .collect::<Result<Vec<_>, _>>()?;
113 Ok(Self {
114 path_type: Path::AgentsInstancesList,
115 targets,
116 jq: args.jq,
117 })
118 }
119}
120
121#[cfg(feature = "cli-executor")]
122pub async fn execute<E: crate::cli::command::CommandExecutor>(
123 executor: &E,
124 mut request: Request,
125
126 agent_arguments: Option<&crate::cli::command::AgentArguments>,
127 ) -> Result<E::Stream<ResponseItem>, E::Error> {
128 request.jq = None;
129 executor.execute(request, agent_arguments).await
130}
131
132#[cfg(feature = "cli-executor")]
133pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
134 executor: &E,
135 mut request: Request,
136 jq: String,
137
138 agent_arguments: Option<&crate::cli::command::AgentArguments>,
139 ) -> Result<E::Stream<serde_json::Value>, E::Error> {
140 request.jq = Some(jq);
141 executor.execute(request, agent_arguments).await
142}
143
144#[cfg(feature = "mcp")]
145impl crate::cli::command::CommandResponse for ResponseItem {
146 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
147 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
148 }
149}
150
151pub mod request_schema;
152
153
154pub mod response_schema;