Skip to main content

aura_agent/runtime/effects/
effect_api.rs

1use super::AuraEffectSystem;
2use async_trait::async_trait;
3use aura_core::effects::{PhysicalTimeEffects, RandomCoreEffects};
4use aura_core::DeviceId;
5use aura_protocol::effects::{EffectApiError, EffectApiEventStream};
6
7// Implementation of EffectApiEffects
8#[async_trait]
9impl aura_protocol::effects::EffectApiEffects for AuraEffectSystem {
10    async fn append_event(&self, _event: Vec<u8>) -> Result<(), EffectApiError> {
11        self.ensure_mock_effect_api("append_event")?;
12        Ok(())
13    }
14
15    async fn current_epoch(&self) -> Result<u64, EffectApiError> {
16        self.ensure_mock_effect_api("current_epoch")?;
17        Ok(0)
18    }
19
20    async fn events_since(&self, _epoch: u64) -> Result<Vec<Vec<u8>>, EffectApiError> {
21        self.ensure_mock_effect_api("events_since")?;
22        Ok(vec![])
23    }
24
25    async fn is_device_authorized(
26        &self,
27        _device_id: DeviceId,
28        _operation: &str,
29    ) -> Result<bool, EffectApiError> {
30        self.ensure_mock_effect_api("is_device_authorized")?;
31        Ok(true)
32    }
33
34    async fn update_device_activity(&self, _device_id: DeviceId) -> Result<(), EffectApiError> {
35        self.ensure_mock_effect_api("update_device_activity")?;
36        Ok(())
37    }
38
39    async fn subscribe_to_events(&self) -> Result<EffectApiEventStream, EffectApiError> {
40        self.ensure_mock_effect_api("subscribe_to_events")?;
41        Err(EffectApiError::CryptoOperationFailed {
42            message: "subscribe_to_events not implemented in mock".to_string(),
43        })
44    }
45
46    async fn would_create_cycle(
47        &self,
48        _edges: &[(Vec<u8>, Vec<u8>)],
49        _new_edge: (Vec<u8>, Vec<u8>),
50    ) -> Result<bool, EffectApiError> {
51        self.ensure_mock_effect_api("would_create_cycle")?;
52        Ok(false)
53    }
54
55    async fn find_connected_components(
56        &self,
57        _edges: &[(Vec<u8>, Vec<u8>)],
58    ) -> Result<Vec<Vec<Vec<u8>>>, EffectApiError> {
59        self.ensure_mock_effect_api("find_connected_components")?;
60        Ok(vec![])
61    }
62
63    async fn topological_sort(
64        &self,
65        _edges: &[(Vec<u8>, Vec<u8>)],
66    ) -> Result<Vec<Vec<u8>>, EffectApiError> {
67        self.ensure_mock_effect_api("topological_sort")?;
68        Ok(vec![])
69    }
70
71    async fn shortest_path(
72        &self,
73        _edges: &[(Vec<u8>, Vec<u8>)],
74        _start: Vec<u8>,
75        _end: Vec<u8>,
76    ) -> Result<Option<Vec<Vec<u8>>>, EffectApiError> {
77        self.ensure_mock_effect_api("shortest_path")?;
78        Ok(None)
79    }
80
81    async fn generate_secret(&self, length: usize) -> Result<Vec<u8>, EffectApiError> {
82        Ok(self.random_bytes(length).await)
83    }
84
85    async fn hash_data(&self, data: &[u8]) -> Result<[u8; 32], EffectApiError> {
86        // Mock implementation - simple hash
87        use aura_core::hash::hash;
88        Ok(hash(data))
89    }
90
91    async fn current_timestamp(&self) -> Result<u64, EffectApiError> {
92        // Use PhysicalTimeEffects instead of direct SystemTime
93        let physical_time =
94            self.time_handler
95                .physical_time()
96                .await
97                .map_err(|e| EffectApiError::Backend {
98                    error: format!("time unavailable: {e}"),
99                })?;
100        Ok(physical_time.ts_ms / 1000)
101    }
102
103    async fn effect_api_device_id(&self) -> Result<DeviceId, EffectApiError> {
104        Ok(self.device_id())
105    }
106
107    #[allow(clippy::disallowed_methods)]
108    async fn new_uuid(&self) -> Result<uuid::Uuid, EffectApiError> {
109        // Mock implementation
110        Ok(uuid::Uuid::new_v4())
111    }
112}