use std::sync::Arc;
use crate::storage::MemoryStore;
use crate::temporal::Validity;
use crate::{AgentId, Result, now_unix};
#[derive(Debug, Clone, PartialEq)]
pub struct Reached {
pub id: String,
pub kind: String,
pub label: String,
pub depth: u32,
}
pub struct Graph {
engine: Arc<dyn MemoryStore>,
agent: AgentId,
}
impl Graph {
#[must_use]
pub fn new(engine: Arc<dyn MemoryStore>, agent: AgentId) -> Self {
Self { engine, agent }
}
#[must_use]
pub fn agent(&self) -> &AgentId {
&self.agent
}
pub async fn add_entity(&self, id: &str, kind: &str, label: &str) -> Result<()> {
self.add_entity_with(id, kind, label, Validity::since(now_unix())).await
}
pub async fn add_entity_with(&self, id: &str, kind: &str, label: &str, validity: Validity) -> Result<()> {
self.engine
.graph_upsert_entity(&self.agent, id, kind, label, validity)
.await
}
pub async fn add_edge(&self, src: &str, relation: &str, dst: &str, weight: f64) -> Result<()> {
let now = now_unix();
self.engine
.graph_upsert_edge(&self.agent, src, relation, dst, weight, now)
.await
}
pub async fn traverse(&self, start: &str, max_depth: u32) -> Result<Vec<Reached>> {
let now = now_unix();
self.engine.graph_traverse(&self.agent, start, max_depth, now).await
}
}