Skip to main content

objectiveai_sdk/cli/command/laboratories/spawn/
mod.rs

1//! `laboratories spawn` — 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.laboratories.spawn.Request")]
7pub struct Request {
8    pub path_type: Path,
9    #[serde(flatten)]
10    pub base: crate::cli::command::RequestBase,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
14#[schemars(rename = "cli.command.laboratories.spawn.Path")]
15pub enum Path {
16    #[serde(rename = "laboratories/spawn")]
17    LaboratoriesSpawn,
18}
19impl CommandRequest for Request {
20    fn request_base(&self) -> &crate::cli::command::RequestBase {
21        &self.base
22    }
23
24    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
25        Some(&mut self.base)
26    }
27}
28
29#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
30#[schemars(rename = "cli.command.laboratories.spawn.Response")]
31pub struct Response {
32    /// Every daemon address the spawned host was told to connect to
33    /// (the local daemon first when `laboratories config local` is not
34    /// false, then the configured `addresses` entries).
35    pub addresses: Vec<String>,
36}
37
38#[derive(clap::Args)]
39pub struct Args {
40    #[command(flatten)]
41    pub base: crate::cli::command::RequestBaseArgs,
42}
43
44#[derive(clap::Args)]
45#[command(args_conflicts_with_subcommands = true)]
46pub struct Command {
47    #[command(flatten)]
48    pub args: Args,
49    #[command(subcommand)]
50    pub schema: Option<Schema>,
51}
52
53#[derive(clap::Subcommand)]
54pub enum Schema {
55    /// Emit the JSON Schema for this leaf's `Request` type and exit.
56    RequestSchema(request_schema::Args),
57    /// Emit the JSON Schema for this leaf's `Response` type and exit.
58    ResponseSchema(response_schema::Args),
59}
60
61impl TryFrom<Args> for Request {
62    type Error = crate::cli::command::FromArgsError;
63    fn try_from(args: Args) -> Result<Self, Self::Error> {
64        Ok(Self { path_type: Path::LaboratoriesSpawn, base: args.base.into() })
65    }
66}
67
68#[cfg(feature = "cli-executor")]
69pub async fn execute<E: crate::cli::command::CommandExecutor>(
70    executor: &E,
71    mut request: Request,
72
73        agent_arguments: Option<&crate::cli::command::AgentArguments>,
74    ) -> Result<Response, E::Error> {
75    request.base.clear_transform();
76    executor.execute_one(request, agent_arguments).await
77}
78
79#[cfg(feature = "cli-executor")]
80pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
81    executor: &E,
82    mut request: Request,
83    transform: crate::cli::command::Transform,
84
85        agent_arguments: Option<&crate::cli::command::AgentArguments>,
86    ) -> Result<serde_json::Value, E::Error> {
87    request.base.set_transform(transform);
88    executor.execute_one(request, agent_arguments).await
89}
90
91#[cfg(feature = "mcp")]
92impl crate::cli::command::CommandResponse for Response {
93    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
94        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
95    }
96}
97
98pub mod request_schema;
99
100pub mod response_schema;
101
102/// One `/listen` broadcast run of `laboratories spawn`: the actual
103/// [`Request`], the producer's
104/// [`AgentArguments`](crate::cli::command::AgentArguments), and the
105/// unary response future. See [`crate::cli::broadcast_listener`].
106#[cfg(feature = "cli-listener")]
107pub struct ListenerExecution {
108    pub request: Request,
109    pub agent_arguments: crate::cli::command::AgentArguments,
110    pub response: crate::cli::broadcast_listener::UnaryResponse<Response>,
111}