liminal_server/agents/
self_station.rs1use super::AgentRegistry;
7use super::storage::{Land, check_bytes, check_population, validate_act};
8use crate::agents::error::AgentError;
9use crate::agents::records::{AgentEvent, AgentHarness, AgentSpec, AgentTransition};
10
11pub const SELF_PLACED_PURPOSE: &str = "Its own station, placed by the seat itself.";
13
14impl AgentRegistry {
15 pub fn place_own(&self, name: &str, owner: &str, at_ms: u64) -> Result<bool, AgentError> {
23 let mut index = self.lock()?;
24 if index.records.contains_key(name) {
25 return Ok(false);
26 }
27 let transition = AgentTransition {
28 holder: name.to_owned(),
29 at_ms,
30 change: AgentEvent::Create(AgentSpec {
31 harness: AgentHarness::Seat,
32 purpose: SELF_PLACED_PURPOSE.to_owned(),
33 service: None,
34 }),
35 };
36 validate_act(&self.bounds, name, &transition)?;
37 check_population(&index, &self.bounds, owner)?;
38 let land = Land {
39 version: 1,
40 name: name.to_owned(),
41 owner: owner.to_owned(),
42 transition,
43 receipt: None,
44 };
45 let bytes = serde_json::to_vec(&land).map_err(|_| AgentError::Invalid("event encoding"))?;
46 check_bytes(&self.bounds, bytes.len())?;
47 if self.placer.is_some() {
48 self.place(name, &format!("self:{name}"))?;
49 }
50 self.land(&mut index, land)?;
51 drop(index);
52 tracing::info!(agent = name, "AGENT_STATION_SELF_PLACED");
53 Ok(true)
54 }
55}