use std::pin::Pin;
use async_trait::async_trait;
use futures::Stream;
use serde_json::Value;
use crate::error::Result;
use crate::types::{
CompletionRequest, CompletionResponse, CoreEntry, IncomingMessage, MemoryEntry, MemoryQuery,
OutgoingMessage, Platform, ScoredMemory, SkillCapability, StreamChunk, ToolFormat, ToolOutput,
};
#[async_trait]
pub trait LlmProvider: Send + Sync {
async fn complete(&self, request: CompletionRequest) -> Result<CompletionResponse>;
async fn stream(
&self,
request: CompletionRequest,
) -> Result<Pin<Box<dyn Stream<Item = Result<StreamChunk>> + Send>>>;
fn model_id(&self) -> &str;
fn max_tokens(&self) -> usize;
fn provider_name(&self) -> &str;
fn supports_strict_tools(&self) -> bool;
fn supports_streaming_tool_deltas(&self) -> bool;
fn native_tool_format(&self) -> ToolFormat;
}
#[async_trait]
pub trait BatchProvider: Send + Sync {
async fn batch(&self, requests: Vec<CompletionRequest>) -> Result<Vec<CompletionResponse>>;
fn max_batch_size(&self) -> usize;
}
#[async_trait]
pub trait EmbeddingProvider: Send + Sync {
async fn embed(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>>;
fn dimensions(&self) -> usize;
fn model_id(&self) -> &str;
}
#[async_trait]
pub trait Tool: Send + Sync {
fn name(&self) -> &str;
fn description(&self) -> &str;
fn schema(&self) -> Value;
fn capabilities_required(&self) -> Vec<SkillCapability>;
async fn execute(&self, input: Value, ctx: &ToolContext) -> Result<ToolOutput>;
}
#[derive(Debug, Clone)]
pub struct ToolContext {
pub session_id: String,
pub user_id: String,
pub workspace_path: Option<String>,
}
#[async_trait]
pub trait MemoryStore: Send + Sync {
async fn store(&self, entry: MemoryEntry) -> Result<()>;
async fn search(&self, query: &MemoryQuery) -> Result<Vec<ScoredMemory>>;
async fn get(&self, id: &str) -> Result<Option<MemoryEntry>>;
async fn delete(&self, id: &str) -> Result<()>;
async fn dedupe_check(&self, content_hash: &str) -> Result<Option<String>>;
async fn expire_stale(&self) -> Result<u64>;
}
#[async_trait]
pub trait CoreMemoryStore: Send + Sync {
async fn get_all(&self, user_id: &str) -> Result<Vec<CoreEntry>>;
async fn set(&self, user_id: &str, entry: CoreEntry) -> Result<()>;
async fn remove(&self, user_id: &str, key: &str) -> Result<()>;
async fn render(&self, user_id: &str) -> Result<String>;
async fn total_tokens(&self, user_id: &str) -> Result<usize>;
}
#[async_trait]
pub trait Channel: Send + Sync {
fn platform(&self) -> Platform;
async fn send(&self, msg: OutgoingMessage) -> Result<()>;
async fn receive(&self) -> Result<IncomingMessage>;
async fn connect(&mut self) -> Result<()>;
async fn disconnect(&mut self) -> Result<()>;
}