Skip to main content

liminal_server/auth_lys/
drafts_projection.rs

1//! How a committed agent receipt reaches the runtime's own projections.
2
3use super::DraftError;
4use lys_pass::drafts::ApprovedDraft;
5
6/// Repairs runtime projections from a committed receipt without another mutation.
7pub trait AgentProjection: Send + Sync {
8    /// Applies the native roster and state projection after durable execution.
9    ///
10    /// # Errors
11    /// A failed native projection; the receipt remains available to replay.
12    fn apply(&self, draft: &ApprovedDraft) -> Result<(), DraftError>;
13}
14impl AgentProjection for crate::agents::runtime::Agents {
15    fn apply(&self, draft: &ApprovedDraft) -> Result<(), DraftError> {
16        if draft.target.action == "create_agent" {
17            self.created(&draft.target.id)
18                .map_err(|_| DraftError::Store)?;
19        }
20        Ok(())
21    }
22}
23impl AgentProjection for crate::server::connection::services::LiminalConnectionServices {
24    fn apply(&self, draft: &ApprovedDraft) -> Result<(), DraftError> {
25        self.execute_agent_draft(draft)
26            .map_err(|_| DraftError::Store)?;
27        Ok(())
28    }
29}