liminal-server 0.25.4

Standalone server for the liminal messaging bus
Documentation
//! The native agent owner opened over the approval journal.

use super::DraftJournal;
use crate::auth_lys::live::drafts::{DraftError, JournalLimits};
use liminal::durability::DurableStore;
use std::sync::Arc;

/// Server-selected dependencies for the existing native agent owner.
pub struct AgentBindings {
    pub bounds: crate::agents::config::AgentsConfig,
    pub network: String,
    pub supervisor: liminal::channel::ChannelSupervisor,
    pub device: String,
    pub placer: Option<Arc<dyn crate::services::lifecycle::Placer>>,
    pub seats: Option<Arc<dyn crate::agents::registry::AgentSeats>>,
}
/// The pair can only be constructed by opening the registry over this journal.
#[derive(Debug)]
pub struct ApprovalAgents {
    journal: Arc<DraftJournal>,
    agents: Arc<crate::agents::runtime::Agents>,
}
impl ApprovalAgents {
    /// Opens after migration, before listeners or approved-draft admission.
    ///
    /// # Errors
    /// Migration, native replay, configured bounds or retained restoration.
    pub fn open(
        store: Arc<dyn DurableStore>,
        limits: JournalLimits,
        bindings: AgentBindings,
    ) -> Result<Arc<Self>, DraftError> {
        let journal = DraftJournal::open(store, limits)?;
        let wrapped: Arc<dyn DurableStore> = journal.clone();
        let agents = crate::agents::runtime::Agents::open(
            wrapped,
            bindings.bounds,
            bindings.network,
            bindings.supervisor,
            &bindings.device,
            bindings.placer,
            bindings.seats,
        )
        .map_err(|_| DraftError::Store)?;
        for (name, mut waiting) in journal.read(|snapshot| snapshot.waiting.clone())? {
            waiting.gone = agents
                .presence()
                .connection(&name)
                .map_err(|_| DraftError::Store)?
                .is_none();
            agents
                .retained()
                .publish(&[(
                    format!("agents.{name}.state"),
                    waiting.snapshot().map_err(|_| DraftError::Store)?,
                )])
                .map_err(|_| DraftError::Store)?;
        }
        Ok(Arc::new(Self { journal, agents }))
    }
    /// The shared target owner; opening another registry would split authority.
    #[must_use]
    pub const fn agents(&self) -> &Arc<crate::agents::runtime::Agents> {
        &self.agents
    }
    /// The prepared and execution evidence on the same durable target route.
    #[must_use]
    pub const fn journal(&self) -> &Arc<DraftJournal> {
        &self.journal
    }
}