pub struct ConsistencyEngine { /* private fields */ }Expand description
Consistency engine for coordinating state across all protocols
The engine maintains unified state per workspace and broadcasts state changes to all registered protocol adapters. This ensures that all protocols reflect the same persona, scenario, reality level, and entity state.
Implementations§
Source§impl ConsistencyEngine
impl ConsistencyEngine
Sourcepub async fn register_adapter(
&self,
adapter: Arc<dyn ProtocolAdapter + Send + Sync>,
)
pub async fn register_adapter( &self, adapter: Arc<dyn ProtocolAdapter + Send + Sync>, )
Register a protocol adapter
Adapters are notified of all state changes for their protocol.
Sourcepub async fn get_or_create_state(&self, workspace_id: &str) -> UnifiedState
pub async fn get_or_create_state(&self, workspace_id: &str) -> UnifiedState
Get or create unified state for a workspace
Sourcepub async fn get_state(&self, workspace_id: &str) -> Option<UnifiedState>
pub async fn get_state(&self, workspace_id: &str) -> Option<UnifiedState>
Get unified state for a workspace (returns None if not found)
Sourcepub async fn set_active_persona(
&self,
workspace_id: &str,
persona: PersonaProfile,
) -> Result<()>
pub async fn set_active_persona( &self, workspace_id: &str, persona: PersonaProfile, ) -> Result<()>
Set active persona for a workspace
This updates the unified state and broadcasts the change to all protocol adapters, ensuring all protocols use the new persona.
Sourcepub async fn set_active_scenario(
&self,
workspace_id: &str,
scenario_id: String,
) -> Result<()>
pub async fn set_active_scenario( &self, workspace_id: &str, scenario_id: String, ) -> Result<()>
Set active scenario for a workspace
Sourcepub async fn set_reality_level(
&self,
workspace_id: &str,
level: RealityLevel,
) -> Result<()>
pub async fn set_reality_level( &self, workspace_id: &str, level: RealityLevel, ) -> Result<()>
Set reality level for a workspace
Sourcepub async fn set_reality_ratio(
&self,
workspace_id: &str,
ratio: f64,
) -> Result<()>
pub async fn set_reality_ratio( &self, workspace_id: &str, ratio: f64, ) -> Result<()>
Set reality continuum ratio for a workspace
Sourcepub async fn register_entity(
&self,
workspace_id: &str,
entity: EntityState,
) -> Result<()>
pub async fn register_entity( &self, workspace_id: &str, entity: EntityState, ) -> Result<()>
Register or update an entity
Entities are tracked across all protocols. When an entity is created via HTTP, it becomes immediately available in GraphQL, gRPC, etc. Also automatically adds the entity to the persona graph if a persona_id is present.
Sourcepub async fn get_entity(
&self,
workspace_id: &str,
entity_type: &str,
entity_id: &str,
) -> Option<EntityState>
pub async fn get_entity( &self, workspace_id: &str, entity_type: &str, entity_id: &str, ) -> Option<EntityState>
Get entity by type and ID
Find related entities using the persona graph
Given a persona ID and entity type, finds all related entities of the target type by traversing the persona graph.
§Arguments
workspace_id- Workspace identifierpersona_id- Starting persona IDtarget_entity_type- Entity type to find (e.g., “order”, “payment”)relationship_type- Optional relationship type filter (e.g., “has_orders”)
§Returns
Vector of entity states matching the criteria
Sourcepub async fn activate_chaos_rule(
&self,
workspace_id: &str,
rule: Value,
) -> Result<()>
pub async fn activate_chaos_rule( &self, workspace_id: &str, rule: Value, ) -> Result<()>
Activate a chaos rule
Sourcepub async fn deactivate_chaos_rule(
&self,
workspace_id: &str,
rule_name: &str,
) -> Result<()>
pub async fn deactivate_chaos_rule( &self, workspace_id: &str, rule_name: &str, ) -> Result<()>
Deactivate a chaos rule
Sourcepub async fn update_protocol_state(
&self,
workspace_id: &str,
protocol: Protocol,
protocol_state: ProtocolState,
) -> Result<()>
pub async fn update_protocol_state( &self, workspace_id: &str, protocol: Protocol, protocol_state: ProtocolState, ) -> Result<()>
Update protocol state
Sourcepub async fn get_protocol_state(
&self,
workspace_id: &str,
protocol: Protocol,
) -> Option<ProtocolState>
pub async fn get_protocol_state( &self, workspace_id: &str, protocol: Protocol, ) -> Option<ProtocolState>
Get protocol state
Sourcepub fn subscribe_to_events(
&self,
_workspace_id: Option<&str>,
) -> Receiver<StateChangeEvent>
pub fn subscribe_to_events( &self, _workspace_id: Option<&str>, ) -> Receiver<StateChangeEvent>
Subscribe to state change events
Returns a receiver that will receive all state change events for the specified workspace (or all workspaces if None).
Sourcepub async fn restore_state(&self, state: UnifiedState) -> Result<()>
pub async fn restore_state(&self, state: UnifiedState) -> Result<()>
Restore unified state from a snapshot
This replaces the current state for a workspace with the provided state. All protocol adapters will be notified of the state changes.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ConsistencyEngine
impl !RefUnwindSafe for ConsistencyEngine
impl Send for ConsistencyEngine
impl Sync for ConsistencyEngine
impl Unpin for ConsistencyEngine
impl !UnwindSafe for ConsistencyEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more