objectiveai_sdk/cli/command/laboratories/attach/
mod.rs1use crate::cli::command::CommandRequest;
7use crate::cli::command::agents::selector::{AgentSelector, AgentSelectorArgs};
8
9#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
10#[schemars(rename = "cli.command.laboratories.attach.Request")]
11pub struct Request {
12 pub path_type: Path,
13 pub selector: AgentSelector,
14 pub laboratory_id: String,
15 #[serde(default, skip_serializing_if = "Option::is_none")]
19 #[schemars(extend("omitempty" = true))]
20 pub machine: Option<String>,
21 #[serde(default, skip_serializing_if = "Option::is_none")]
24 #[schemars(extend("omitempty" = true))]
25 pub machine_state: Option<String>,
26 #[serde(flatten)]
27 pub base: crate::cli::command::RequestBase,
28}
29
30#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
31#[schemars(rename = "cli.command.laboratories.attach.Path")]
32pub enum Path {
33 #[serde(rename = "laboratories/attach")]
34 LaboratoriesAttach,
35}
36
37impl CommandRequest for Request {
38 fn request_base(&self) -> &crate::cli::command::RequestBase {
39 &self.base
40 }
41
42 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
43 Some(&mut self.base)
44 }
45}
46
47#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
50#[schemars(rename = "cli.command.laboratories.attach.Response")]
51pub struct Response {
52 pub laboratory_id: String,
54 #[serde(default, skip_serializing_if = "Option::is_none")]
57 #[schemars(extend("omitempty" = true))]
58 pub machine: Option<String>,
59 #[serde(default, skip_serializing_if = "Option::is_none")]
61 #[schemars(extend("omitempty" = true))]
62 pub machine_state: Option<String>,
63}
64
65#[derive(clap::Args)]
66#[command(group(clap::ArgGroup::new("laboratory_id_required").required(true).args(["laboratory_id"])))]
67pub struct Args {
68 #[command(flatten)]
69 pub selector: AgentSelectorArgs,
70 #[arg(long)]
72 pub laboratory_id: Option<String>,
73 #[arg(long, requires = "machine_state")]
77 pub machine: Option<String>,
78 #[arg(long, requires = "machine")]
81 pub machine_state: Option<String>,
82 #[command(flatten)]
83 pub base: crate::cli::command::RequestBaseArgs,
84}
85
86#[derive(clap::Args)]
87#[command(args_conflicts_with_subcommands = true)]
88pub struct Command {
89 #[command(flatten)]
90 pub args: Args,
91 #[command(subcommand)]
92 pub schema: Option<Schema>,
93}
94
95#[derive(clap::Subcommand)]
96pub enum Schema {
97 RequestSchema(request_schema::Args),
99 ResponseSchema(response_schema::Args),
101}
102
103impl TryFrom<Args> for Request {
104 type Error = crate::cli::command::FromArgsError;
105 fn try_from(args: Args) -> Result<Self, Self::Error> {
106 let selector = AgentSelector::try_from(args.selector)?;
107 let laboratory_id = args.laboratory_id.ok_or_else(|| {
108 crate::cli::command::FromArgsError::path_parse(
109 "laboratory_id",
110 "--laboratory-id is required".to_string(),
111 )
112 })?;
113 if args.machine.is_some() != args.machine_state.is_some() {
116 return Err(crate::cli::command::FromArgsError::path_parse(
117 "machine",
118 "--machine and --machine-state must be provided together".to_string(),
119 ));
120 }
121 Ok(Self {
122 path_type: Path::LaboratoriesAttach,
123 selector,
124 laboratory_id,
125 machine: args.machine,
126 machine_state: args.machine_state,
127 base: args.base.into(),
128 })
129 }
130}
131
132#[cfg(feature = "cli-executor")]
133pub async fn execute<E: crate::cli::command::CommandExecutor>(
134 executor: &E,
135 mut request: Request,
136 agent_arguments: Option<&crate::cli::command::AgentArguments>,
137) -> Result<Response, E::Error> {
138 request.base.clear_transform();
139 executor.execute_one(request, agent_arguments).await
140}
141
142#[cfg(feature = "cli-executor")]
143pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
144 executor: &E,
145 mut request: Request,
146 transform: crate::cli::command::Transform,
147 agent_arguments: Option<&crate::cli::command::AgentArguments>,
148) -> Result<serde_json::Value, E::Error> {
149 request.base.set_transform(transform);
150 executor.execute_one(request, agent_arguments).await
151}
152
153#[cfg(feature = "mcp")]
154impl crate::cli::command::CommandResponse for Response {
155 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
156 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
157 }
158}
159
160pub mod request_schema;
161
162pub mod response_schema;
163
164#[cfg(feature = "cli-listener")]
169pub struct ListenerExecution {
170 pub request: Request,
171 pub agent_arguments: crate::cli::command::AgentArguments,
172 pub response: crate::cli::broadcast_listener::UnaryResponse<Response>,
173}