Skip to main content

agentic_reality/engine/query/
reality.rs

1//! Reality query operations.
2
3use crate::engine::query::QueryEngine;
4use crate::types::error::{RealityError, RealityResult};
5use crate::types::ids::AnchorId;
6use crate::types::reality::*;
7
8impl<'a> QueryEngine<'a> {
9    pub fn get_reality_layers(&self) -> RealityResult<&RealityLayers> {
10        self.engine
11            .reality_store
12            .layers
13            .as_ref()
14            .ok_or_else(|| RealityError::NotInitialized("reality layers".into()))
15    }
16
17    pub fn get_current_layer(&self) -> RealityResult<&RealityLayer> {
18        Ok(&self.get_reality_layers()?.current_layer)
19    }
20
21    pub fn get_freshness(&self) -> RealityResult<&FreshnessPerception> {
22        self.engine
23            .reality_store
24            .freshness
25            .as_ref()
26            .ok_or_else(|| RealityError::NotInitialized("freshness perception".into()))
27    }
28
29    pub fn is_fresh(&self, source: &str) -> bool {
30        self.engine
31            .reality_store
32            .freshness
33            .as_ref()
34            .and_then(|f| f.by_source.get(source))
35            .map(|s| {
36                matches!(
37                    s.level,
38                    FreshnessLevel::Live { .. } | FreshnessLevel::Fresh { .. }
39                )
40            })
41            .unwrap_or(false)
42    }
43
44    pub fn get_anchors(&self) -> &[RealityAnchor] {
45        &self.engine.reality_store.anchors
46    }
47
48    pub fn get_anchor(&self, id: &AnchorId) -> RealityResult<&RealityAnchor> {
49        self.engine
50            .reality_store
51            .anchors
52            .iter()
53            .find(|a| a.id == *id)
54            .ok_or_else(|| RealityError::NotFound(format!("anchor {}", id)))
55    }
56
57    pub fn get_anchor_drift(&self) -> &[AnchorDrift] {
58        &self.engine.reality_store.anchor_drifts
59    }
60
61    pub fn get_hallucination_state(&self) -> RealityResult<&HallucinationState> {
62        self.engine
63            .reality_store
64            .hallucination_state
65            .as_ref()
66            .ok_or_else(|| RealityError::NotInitialized("hallucination state".into()))
67    }
68
69    pub fn get_hallucination_risk(&self) -> Option<&HallucinationRisk> {
70        self.engine
71            .reality_store
72            .hallucination_state
73            .as_ref()
74            .map(|s| &s.risk_level)
75    }
76
77    pub fn get_grounding_status(&self) -> Option<&GroundingStatus> {
78        self.engine
79            .reality_store
80            .hallucination_state
81            .as_ref()
82            .map(|s| &s.grounding)
83    }
84}