use crate::types::{BusMessage, LlmRequest, LlmResponse, ToolCall, ToolDef, ToolResult};
use anyhow::Result;
use serde_json::Value;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct MemoryHit {
pub key: String,
pub value: Value,
pub score: f32,
}
#[async_trait::async_trait]
pub trait LlmProvider: Send + Sync {
async fn generate(&self, req: LlmRequest) -> Result<LlmResponse>;
fn name(&self) -> &str;
fn supports_model(&self, model: &str) -> bool;
}
#[async_trait::async_trait]
pub trait Bus: Send + Sync {
async fn publish(&self, msg: BusMessage) -> Result<()>;
async fn subscribe(
&self,
topic: &str,
handler: Box<dyn Fn(BusMessage) -> std::pin::Pin<Box<dyn std::future::Future<Output = ()> + Send>> + Send + Sync>,
) -> Result<()>;
async fn start(&self) -> Result<()>;
async fn stop(&self) -> Result<()>;
}
#[async_trait::async_trait]
pub trait MemoryStore: Send + Sync {
async fn store(&self, namespace: &str, key: &str, value: Value) -> Result<()>;
async fn retrieve(&self, namespace: &str, key: &str) -> Result<Option<Value>>;
async fn search(&self, namespace: &str, query: &str, top_k: usize) -> Result<Vec<MemoryHit>>;
async fn delete(&self, namespace: &str, key: &str) -> Result<()>;
}
#[async_trait::async_trait]
pub trait ToolExecutor: Send + Sync {
async fn execute(&self, call: ToolCall) -> Result<ToolResult>;
fn list_tools(&self) -> Vec<ToolDef>;
}