do_memory_storage_turso/trait_impls/
mod.rs1use async_trait::async_trait;
7use do_memory_core::memory::attribution::{
8 RecommendationFeedback, RecommendationSession, RecommendationStats,
9};
10use do_memory_core::{Error, Result, StorageBackend};
11
12#[derive(Debug, Clone)]
14pub struct StorageStatistics {
15 pub episode_count: usize,
16 pub pattern_count: usize,
17 pub heuristic_count: usize,
18}
19
20#[async_trait]
22impl StorageBackend for super::TursoStorage {
23 async fn store_episode(&self, episode: &do_memory_core::Episode) -> Result<()> {
24 super::TursoStorage::store_episode(self, episode).await
25 }
26
27 async fn get_episode(&self, id: uuid::Uuid) -> Result<Option<do_memory_core::Episode>> {
28 super::TursoStorage::get_episode(self, id).await
29 }
30
31 async fn delete_episode(&self, id: uuid::Uuid) -> Result<()> {
32 super::TursoStorage::delete_episode(self, id).await
33 }
34
35 async fn store_pattern(&self, pattern: &do_memory_core::Pattern) -> Result<()> {
36 super::TursoStorage::store_pattern(self, pattern).await
37 }
38
39 async fn get_pattern(
40 &self,
41 id: do_memory_core::episode::PatternId,
42 ) -> Result<Option<do_memory_core::Pattern>> {
43 super::TursoStorage::get_pattern(self, id).await
44 }
45
46 async fn store_heuristic(&self, heuristic: &do_memory_core::Heuristic) -> Result<()> {
47 super::TursoStorage::store_heuristic(self, heuristic).await
48 }
49
50 async fn get_heuristic(&self, id: uuid::Uuid) -> Result<Option<do_memory_core::Heuristic>> {
51 super::TursoStorage::get_heuristic(self, id).await
52 }
53
54 async fn query_episodes_since(
55 &self,
56 since: chrono::DateTime<chrono::Utc>,
57 limit: Option<usize>,
58 ) -> Result<Vec<do_memory_core::Episode>> {
59 super::TursoStorage::query_episodes_since(self, since, limit).await
60 }
61
62 async fn query_episodes_by_metadata(
63 &self,
64 key: &str,
65 value: &str,
66 limit: Option<usize>,
67 ) -> Result<Vec<do_memory_core::Episode>> {
68 super::TursoStorage::query_episodes_by_metadata(self, key, value, limit).await
69 }
70
71 async fn store_embedding(&self, id: &str, embedding: Vec<f32>) -> Result<()> {
72 super::TursoStorage::store_embedding_backend(self, id, embedding).await
73 }
74
75 async fn get_embedding(&self, id: &str) -> Result<Option<Vec<f32>>> {
76 super::TursoStorage::get_embedding_backend(self, id).await
77 }
78
79 async fn delete_embedding(&self, id: &str) -> Result<bool> {
80 super::TursoStorage::delete_embedding_backend(self, id).await
81 }
82
83 async fn store_embeddings_batch(&self, embeddings: Vec<(String, Vec<f32>)>) -> Result<()> {
84 super::TursoStorage::store_embeddings_batch_backend(self, embeddings).await
85 }
86
87 async fn get_embeddings_batch(&self, ids: &[String]) -> Result<Vec<Option<Vec<f32>>>> {
88 super::TursoStorage::get_embeddings_batch_backend(self, ids).await
89 }
90
91 async fn store_relationship(
94 &self,
95 relationship: &do_memory_core::episode::EpisodeRelationship,
96 ) -> Result<()> {
97 super::TursoStorage::store_relationship(self, relationship).await
98 }
99
100 async fn remove_relationship(&self, relationship_id: uuid::Uuid) -> Result<()> {
101 super::TursoStorage::remove_relationship(self, relationship_id).await
102 }
103
104 async fn get_relationships(
105 &self,
106 episode_id: uuid::Uuid,
107 direction: do_memory_core::episode::Direction,
108 ) -> Result<Vec<do_memory_core::episode::EpisodeRelationship>> {
109 super::TursoStorage::get_relationships(self, episode_id, direction).await
110 }
111
112 async fn relationship_exists(
113 &self,
114 from_episode_id: uuid::Uuid,
115 to_episode_id: uuid::Uuid,
116 relationship_type: do_memory_core::episode::RelationshipType,
117 ) -> Result<bool> {
118 super::TursoStorage::relationship_exists(
119 self,
120 from_episode_id,
121 to_episode_id,
122 relationship_type,
123 )
124 .await
125 }
126
127 async fn store_recommendation_session(&self, session: &RecommendationSession) -> Result<()> {
128 super::TursoStorage::store_recommendation_session(self, session).await
129 }
130
131 async fn get_recommendation_session(
132 &self,
133 session_id: uuid::Uuid,
134 ) -> Result<Option<RecommendationSession>> {
135 super::TursoStorage::get_recommendation_session(self, session_id).await
136 }
137
138 async fn get_recommendation_session_for_episode(
139 &self,
140 episode_id: uuid::Uuid,
141 ) -> Result<Option<RecommendationSession>> {
142 super::TursoStorage::get_recommendation_session_for_episode(self, episode_id).await
143 }
144
145 async fn store_recommendation_feedback(&self, feedback: &RecommendationFeedback) -> Result<()> {
146 super::TursoStorage::store_recommendation_feedback(self, feedback).await
147 }
148
149 async fn get_recommendation_feedback(
150 &self,
151 session_id: uuid::Uuid,
152 ) -> Result<Option<RecommendationFeedback>> {
153 super::TursoStorage::get_recommendation_feedback(self, session_id).await
154 }
155
156 async fn get_recommendation_stats(&self) -> Result<RecommendationStats> {
157 super::TursoStorage::get_recommendation_stats(self).await
158 }
159}
160
161#[async_trait]
163impl do_memory_core::monitoring::storage::MonitoringStorageBackend for super::TursoStorage {
164 async fn store_execution_record(
165 &self,
166 record: &do_memory_core::monitoring::types::ExecutionRecord,
167 ) -> Result<()> {
168 super::TursoStorage::store_execution_record(self, record)
169 .await
170 .map_err(|e| Error::Storage(format!("Storage error: {}", e)))
171 }
172
173 async fn store_agent_metrics(
174 &self,
175 metrics: &do_memory_core::monitoring::types::AgentMetrics,
176 ) -> Result<()> {
177 super::TursoStorage::store_agent_metrics(self, metrics)
178 .await
179 .map_err(|e| Error::Storage(format!("Storage error: {}", e)))
180 }
181
182 async fn store_task_metrics(
183 &self,
184 metrics: &do_memory_core::monitoring::types::TaskMetrics,
185 ) -> Result<()> {
186 super::TursoStorage::store_task_metrics(self, metrics)
187 .await
188 .map_err(|e| Error::Storage(format!("Storage error: {}", e)))
189 }
190
191 async fn load_agent_metrics(
192 &self,
193 agent_name: &str,
194 ) -> Result<Option<do_memory_core::monitoring::types::AgentMetrics>> {
195 super::TursoStorage::load_agent_metrics(self, agent_name)
196 .await
197 .map_err(|e| Error::Storage(format!("Storage error: {}", e)))
198 }
199
200 async fn load_execution_records(
201 &self,
202 agent_name: Option<&str>,
203 limit: usize,
204 ) -> Result<Vec<do_memory_core::monitoring::types::ExecutionRecord>> {
205 super::TursoStorage::load_execution_records(self, agent_name, limit)
206 .await
207 .map_err(|e| Error::Storage(format!("Storage error: {}", e)))
208 }
209
210 async fn load_task_metrics(
211 &self,
212 task_type: &str,
213 ) -> Result<Option<do_memory_core::monitoring::types::TaskMetrics>> {
214 super::TursoStorage::load_task_metrics(self, task_type)
215 .await
216 .map_err(|e| Error::Storage(format!("Storage error: {}", e)))
217 }
218}