objectiveai_cli/command/agents/laboratories/
list.rs1use std::pin::Pin;
7
8use futures::Stream;
9use objectiveai_sdk::cli::command::agents::laboratories::list::{Request, ResponseItem};
10use objectiveai_sdk::cli::command::agents::selector::AgentSelector;
11
12use crate::context::Context;
13use crate::db::laboratory_attachments::Target;
14use crate::error::Error;
15
16type ItemStream = Pin<Box<dyn Stream<Item = Result<ResponseItem, Error>> + Send>>;
17
18pub async fn execute(ctx: &Context, request: Request) -> Result<ItemStream, Error> {
19 let target = match &request.selector {
20 AgentSelector::Ref { .. } => return Err(Error::LaboratoryRefTarget),
21 AgentSelector::Tag { agent_tag } => Target::Tag(agent_tag.clone()),
22 AgentSelector::Instance {
23 parent_agent_instance_hierarchy,
24 agent_instance,
25 } => {
26 let parent = parent_agent_instance_hierarchy
27 .as_deref()
28 .unwrap_or(&ctx.config.agent_instance_hierarchy);
29 Target::Aih(format!("{parent}/{agent_instance}"))
30 }
31 };
32 let pool = ctx.db_client().await?.clone();
33 let stream = async_stream::stream! {
34 match crate::db::laboratory_attachments::list(&pool, &target).await {
35 Ok(ids) => {
36 for id in ids {
37 yield Ok(ResponseItem { id });
38 }
39 }
40 Err(e) => yield Err(Error::from(e)),
41 }
42 };
43 Ok(Box::pin(stream))
44}
45
46pub mod request_schema {
47 use objectiveai_sdk::cli::command::agents::laboratories::list as sdk;
48 use objectiveai_sdk::cli::command::agents::laboratories::list::request_schema::{
49 Request, Response,
50 };
51
52 use crate::context::Context;
53 use crate::error::Error;
54
55 pub async fn execute(_ctx: &Context, _request: Request) -> Result<Response, Error> {
56 Ok(objectiveai_sdk::cli::command::ResponseSchema(
57 schemars::schema_for!(sdk::Request),
58 ))
59 }
60}
61
62pub mod response_schema {
63 use objectiveai_sdk::cli::command::agents::laboratories::list as sdk;
64 use objectiveai_sdk::cli::command::agents::laboratories::list::response_schema::{
65 Request, Response,
66 };
67
68 use crate::context::Context;
69 use crate::error::Error;
70
71 pub async fn execute(_ctx: &Context, _request: Request) -> Result<Response, Error> {
72 Ok(objectiveai_sdk::cli::command::ResponseSchema(
73 schemars::schema_for!(sdk::ResponseItem),
74 ))
75 }
76}