swarmctl shares the create-agent, inference and permissions shapes with the controller
This commit is contained in:
parent
249aab6642
commit
0831b85b73
26 changed files with 675 additions and 434 deletions
|
|
@ -13,11 +13,8 @@
|
|||
//! over the socket rather than pulling in a full client stack for one
|
||||
//! POST.
|
||||
//!
|
||||
//! The responses come from `swarm-controller-api`. The request body below
|
||||
//! **mirrors** the controller's own private `CreateAgentRequest`, whose
|
||||
//! fields include types from `swarm-queue-client` and `hive-sh4re`, and
|
||||
//! `swarm-controller-api` depends on neither. The seam is narrow and both
|
||||
//! ends validate, so drift surfaces as a 400 naming the field.
|
||||
//! The request and response bodies come from `swarm-controller-api`, which
|
||||
//! the controller imports too.
|
||||
//!
|
||||
//! Long-form rationale for all three: `swarmctl/README.md`.
|
||||
|
||||
|
|
@ -27,25 +24,13 @@ use anyhow::{Context as _, Result, bail};
|
|||
use http_body_util::{BodyExt as _, Full};
|
||||
use hyper_util::rt::TokioIo;
|
||||
use serde::Serialize;
|
||||
use swarm_controller_api::agents::{CreateAgentResponse, MintAgentForgeTokenResponse};
|
||||
use swarm_controller_api::agents::{
|
||||
CreateAgentRequest, CreateAgentResponse, MintAgentForgeTokenResponse,
|
||||
};
|
||||
use tokio::net::UnixStream;
|
||||
|
||||
use crate::remote::Target;
|
||||
|
||||
/// Body of `POST /api/agents`. Mirrors the controller's own
|
||||
/// `CreateAgentRequest` — see this module's doc comment.
|
||||
#[derive(Serialize)]
|
||||
struct CreateAgentRequest<'a> {
|
||||
name: &'a str,
|
||||
/// Where the agent's deploy message is addressed. Required by the
|
||||
/// endpoint and not defaulted anywhere, because it is only knowable
|
||||
/// from the operator making the choice.
|
||||
hive: &'a str,
|
||||
/// The text the agent's `AGENTS.md` starts with; left out when not given.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
agents_md: Option<&'a str>,
|
||||
}
|
||||
|
||||
/// Run `swarmctl agent create`.
|
||||
///
|
||||
/// Synchronous on purpose: every other verb in this crate is, and this is
|
||||
|
|
@ -138,9 +123,13 @@ async fn post_create(
|
|||
target,
|
||||
"/api/agents",
|
||||
&CreateAgentRequest {
|
||||
name,
|
||||
hive,
|
||||
agents_md,
|
||||
name: name.to_owned(),
|
||||
hive: hive.to_owned(),
|
||||
limits: None,
|
||||
inference: None,
|
||||
permissions: None,
|
||||
archetype: None,
|
||||
agents_md: agents_md.map(str::to_owned),
|
||||
},
|
||||
"create-agent",
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue