Skip to main content

objectiveai_cli/command/agents/laboratories/
attach.rs

1//! `agents laboratories attach` — acquire the target's lock(s), insert
2//! the `(target, laboratory_id)` row, release. Errors if the laboratory
3//! is already attached to the target.
4
5use objectiveai_sdk::cli::command::agents::laboratories::attach::{Request, Response};
6
7use crate::context::Context;
8use crate::error::Error;
9
10pub async fn execute(ctx: &Context, request: Request) -> Result<Response, Error> {
11    let (target, claims) = super::lock_target(ctx, &request.selector).await?;
12    let pool = ctx.db_client().await?.clone();
13    let result =
14        crate::db::laboratory_attachments::attach(&pool, &target, &request.laboratory_id).await;
15    super::release_all(claims);
16    let inserted = result?;
17    if !inserted {
18        return Err(Error::LaboratoryAlreadyAttached {
19            laboratory_id: request.laboratory_id,
20        });
21    }
22    Ok(Response {
23        laboratory_id: request.laboratory_id,
24    })
25}
26
27pub mod request_schema {
28    use objectiveai_sdk::cli::command::agents::laboratories::attach as sdk;
29    use objectiveai_sdk::cli::command::agents::laboratories::attach::request_schema::{
30        Request, Response,
31    };
32
33    use crate::context::Context;
34    use crate::error::Error;
35
36    pub async fn execute(_ctx: &Context, _request: Request) -> Result<Response, Error> {
37        Ok(objectiveai_sdk::cli::command::ResponseSchema(
38            schemars::schema_for!(sdk::Request),
39        ))
40    }
41}
42
43pub mod response_schema {
44    use objectiveai_sdk::cli::command::agents::laboratories::attach as sdk;
45    use objectiveai_sdk::cli::command::agents::laboratories::attach::response_schema::{
46        Request, Response,
47    };
48
49    use crate::context::Context;
50    use crate::error::Error;
51
52    pub async fn execute(_ctx: &Context, _request: Request) -> Result<Response, Error> {
53        Ok(objectiveai_sdk::cli::command::ResponseSchema(
54            schemars::schema_for!(sdk::Response),
55        ))
56    }
57}