use serde::{Deserialize, Serialize};
pub trait InferenceBackend {
fn summarize(&self, content: &str) -> Result<String, InferenceError>;
fn tag(&self, content: &str) -> Result<Vec<String>, InferenceError>;
fn embed(&self, content: &str) -> Result<Vec<f32>, InferenceError>;
fn suggest_pins(&self, events: &[Event]) -> Result<Vec<String>, InferenceError>;
}
#[derive(Debug, thiserror::Error)]
pub enum InferenceError {
#[error("HTTP request failed: {0}")]
HttpError(#[from] reqwest::Error),
#[error("Serialization error: {0}")]
SerializationError(#[from] serde_json::Error),
#[error("Invalid response from inference backend")]
InvalidResponse,
#[error("Inference backend not configured")]
NotConfigured,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Event {
pub id: String,
pub content: String,
pub timestamp: i64,
pub source: String,
pub meta: Option<String>,
}
impl Event {
pub fn new(id: String, content: String, timestamp: i64, source: String) -> Self {
Self {
id,
content,
timestamp,
source,
meta: None,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InferenceConfig {
pub enabled: bool,
pub api_url: Option<String>,
pub api_key: Option<String>,
pub model: String,
pub embedding_dim: usize,
pub timeout: u64,
}
impl Default for InferenceConfig {
fn default() -> Self {
Self {
enabled: false,
api_url: Some("http://localhost:1234/v1".to_string()),
api_key: None,
model: "mirror-log-model".to_string(),
embedding_dim: 1536,
timeout: 30,
}
}
}
pub trait WasmInferenceBackend: InferenceBackend {
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_event_creation() {
let event = Event::new(
"test-id".to_string(),
"test content".to_string(),
1234567890,
"test-source".to_string(),
);
assert_eq!(event.id, "test-id");
assert_eq!(event.content, "test content");
}
#[test]
fn test_inference_config_default() {
let config = InferenceConfig::default();
assert!(!config.enabled);
assert_eq!(config.embedding_dim, 1536);
}
}