set an agent's initial agents.md at create
This commit is contained in:
parent
a6147dc875
commit
456cf9a7cb
19 changed files with 708 additions and 19 deletions
|
|
@ -41,6 +41,9 @@ struct CreateAgentRequest<'a> {
|
|||
/// 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`.
|
||||
|
|
@ -50,19 +53,30 @@ struct CreateAgentRequest<'a> {
|
|||
/// built here keeps that cost inside the one arm that incurs it, the same
|
||||
/// way `PathArgs::resolve` is called only in the arms that need the
|
||||
/// deployment's env vars.
|
||||
pub(crate) fn create(target: &Target, name: &str, hive: &str) -> Result<()> {
|
||||
pub(crate) fn create(
|
||||
target: &Target,
|
||||
name: &str,
|
||||
hive: &str,
|
||||
agents_md: Option<&Path>,
|
||||
) -> Result<()> {
|
||||
// Client-side before the round trip, so a typo is an immediate local
|
||||
// error rather than a 400 the operator has to wait for. The controller
|
||||
// validates both again — that is the gate that matters, this is the
|
||||
// one that is fast.
|
||||
let name = parse_ident(name, "agent name")?;
|
||||
let hive = parse_ident(hive, "hive")?;
|
||||
let agents_md = agents_md
|
||||
.map(|path| {
|
||||
std::fs::read_to_string(path)
|
||||
.with_context(|| format!("reading --agents-md {}", path.display()))
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
let rt = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.context("starting a tokio runtime for the controller request")?;
|
||||
let resp = rt.block_on(post_create(target, &name, &hive))?;
|
||||
let resp = rt.block_on(post_create(target, &name, &hive, agents_md.as_deref()))?;
|
||||
|
||||
println!("queued: job node {}", resp.node_id);
|
||||
println!(
|
||||
|
|
@ -114,11 +128,20 @@ pub(crate) fn mint_forge_token(target: &Target, name: &str) -> Result<()> {
|
|||
}
|
||||
|
||||
/// One `POST /api/agents` round trip at the controller.
|
||||
async fn post_create(target: &Target, name: &str, hive: &str) -> Result<CreateAgentResponse> {
|
||||
async fn post_create(
|
||||
target: &Target,
|
||||
name: &str,
|
||||
hive: &str,
|
||||
agents_md: Option<&str>,
|
||||
) -> Result<CreateAgentResponse> {
|
||||
post(
|
||||
target,
|
||||
"/api/agents",
|
||||
&CreateAgentRequest { name, hive },
|
||||
&CreateAgentRequest {
|
||||
name,
|
||||
hive,
|
||||
agents_md,
|
||||
},
|
||||
"create-agent",
|
||||
)
|
||||
.await
|
||||
|
|
|
|||
Loading…
Reference in a new issue