Skip to main content

objectiveai_sdk/cli/command/agents/read/all/
mod.rs

1//! `agents read all` — 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.read.all.Request")]
7pub struct Request {
8    pub path_type: Path,
9    pub agent_instance_hierarchies: Vec<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.read.all.Path")]
15pub enum Path {
16    #[serde(rename = "agents/read/all")]
17    AgentsReadAll,
18}
19
20impl CommandRequest for Request {
21    fn into_command(&self) -> Vec<String> {
22        let mut argv = vec![
23            "agents".to_string(),
24            "read".to_string(),
25            "all".to_string(),
26        ];
27        argv.extend(self.agent_instance_hierarchies.iter().cloned());
28        if let Some(jq) = &self.jq {
29            argv.push("--jq".to_string());
30            argv.push(jq.clone());
31        }
32        argv
33    }
34}
35
36#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
37#[serde(untagged)]
38#[schemars(rename = "cli.command.agents.read.all.ResponseContent")]
39pub enum ResponseContent {
40    #[schemars(title = "One")]
41    One(i64),
42    #[schemars(title = "Many")]
43    Many(Vec<i64>),
44}
45
46#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
47#[serde(tag = "type", rename_all = "snake_case")]
48#[schemars(rename = "cli.command.agents.read.all.ResponseQueueMessage")]
49pub enum ResponseQueueMessage {
50    #[schemars(title = "Developer")]
51    Developer {
52        content: ResponseContent,
53        #[serde(skip_serializing_if = "Option::is_none")]
54        #[schemars(extend("omitempty" = true))]
55        name: Option<String>,
56    },
57    #[schemars(title = "System")]
58    System {
59        content: ResponseContent,
60        #[serde(skip_serializing_if = "Option::is_none")]
61        #[schemars(extend("omitempty" = true))]
62        name: Option<String>,
63    },
64    #[schemars(title = "User")]
65    User {
66        content: ResponseContent,
67        #[serde(skip_serializing_if = "Option::is_none")]
68        #[schemars(extend("omitempty" = true))]
69        name: Option<String>,
70    },
71    #[schemars(title = "Assistant")]
72    Assistant {
73        #[serde(skip_serializing_if = "Option::is_none")]
74        #[schemars(extend("omitempty" = true))]
75        content: Option<ResponseContent>,
76        #[serde(skip_serializing_if = "Option::is_none")]
77        #[schemars(extend("omitempty" = true))]
78        name: Option<String>,
79        #[serde(skip_serializing_if = "Option::is_none")]
80        #[schemars(extend("omitempty" = true))]
81        reasoning: Option<i64>,
82        #[serde(skip_serializing_if = "Option::is_none")]
83        #[schemars(extend("omitempty" = true))]
84        tool_calls: Option<Vec<i64>>,
85        #[serde(skip_serializing_if = "Option::is_none")]
86        #[schemars(extend("omitempty" = true))]
87        refusal: Option<i64>,
88    },
89    #[schemars(title = "Tool")]
90    Tool {
91        content: ResponseContent,
92        tool_call_id: String,
93    },
94}
95
96#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
97#[serde(tag = "type", rename_all = "snake_case")]
98#[schemars(rename = "cli.command.agents.read.all.ResponseQueueItem")]
99pub enum ResponseQueueItem {
100    #[schemars(title = "AssistantResponse")]
101    AssistantResponse {
102        #[serde(skip_serializing_if = "Option::is_none")]
103        #[schemars(extend("omitempty" = true))]
104        reasoning: Option<i64>,
105        #[serde(skip_serializing_if = "Option::is_none")]
106        #[schemars(extend("omitempty" = true))]
107        tool_calls: Option<Vec<i64>>,
108        #[serde(skip_serializing_if = "Option::is_none")]
109        #[schemars(extend("omitempty" = true))]
110        content: Option<ResponseContent>,
111        #[serde(skip_serializing_if = "Option::is_none")]
112        #[schemars(extend("omitempty" = true))]
113        refusal: Option<i64>,
114    },
115    #[schemars(title = "ToolResponse")]
116    ToolResponse {
117        tool_call_id: String,
118        content: ResponseContent,
119    },
120    #[schemars(title = "Notification")]
121    Notification {
122        content: ResponseContent,
123    },
124    #[schemars(title = "AgentCompletionRequest")]
125    AgentCompletionRequest {
126        messages: Vec<ResponseQueueMessage>,
127    },
128    #[schemars(title = "FunctionExecutionRequest")]
129    FunctionExecutionRequest {
130        id: i64,
131    },
132    #[schemars(title = "FunctionInventionRecursiveRequest")]
133    FunctionInventionRecursiveRequest {
134        id: i64,
135    },
136}
137
138#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
139#[schemars(rename = "cli.command.agents.read.all.ResponseItem")]
140pub struct ResponseItem {
141    pub agent_id: String,
142    pub items: Vec<ResponseQueueItem>,
143}
144
145#[derive(clap::Args)]
146pub struct Args {
147    /// One or more agent_instance_hierarchy values.
148    #[arg(required = true)]
149    pub agent_instance_hierarchies: Vec<String>,
150    /// jq filter applied to the JSON output.
151    #[arg(long)]
152    pub jq: Option<String>,
153}
154
155#[derive(clap::Args)]
156#[command(args_conflicts_with_subcommands = true)]
157pub struct Command {
158    #[command(flatten)]
159    pub args: Args,
160    #[command(subcommand)]
161    pub schema: Option<Schema>,
162}
163
164#[derive(clap::Subcommand)]
165pub enum Schema {
166    /// Emit the JSON Schema for this leaf's `Request` type and exit.
167    RequestSchema(request_schema::Args),
168    /// Emit the JSON Schema for this leaf's `Response` type and exit.
169    ResponseSchema(response_schema::Args),
170}
171
172impl TryFrom<Args> for Request {
173    type Error = crate::cli::command::FromArgsError;
174    fn try_from(args: Args) -> Result<Self, Self::Error> {
175        Ok(Self { path_type: Path::AgentsReadAll,
176            agent_instance_hierarchies: args.agent_instance_hierarchies,
177            jq: args.jq,
178        })
179    }
180}
181
182#[cfg(feature = "cli-executor")]
183pub async fn execute<E: crate::cli::command::CommandExecutor>(
184    executor: &E,
185    mut request: Request,
186
187        agent_arguments: Option<&crate::cli::command::AgentArguments>,
188    ) -> Result<E::Stream<ResponseItem>, E::Error> {
189    request.jq = None;
190    executor.execute(request, agent_arguments).await
191}
192
193#[cfg(feature = "cli-executor")]
194pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
195    executor: &E,
196    mut request: Request,
197    jq: String,
198
199        agent_arguments: Option<&crate::cli::command::AgentArguments>,
200    ) -> Result<E::Stream<serde_json::Value>, E::Error> {
201    request.jq = Some(jq);
202    executor.execute(request, agent_arguments).await
203}
204
205#[cfg(feature = "mcp")]
206impl crate::cli::command::CommandResponse for ResponseItem {
207    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
208        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
209    }
210}
211
212pub mod request_schema;
213
214
215pub mod response_schema;