Files
zesdex/crates/zesdex-cms/src/domain/service.rs
T

63 lines
2.4 KiB
Rust
Raw Normal View History

//! Service trait definitions — use-case boundaries for CMS operations.
//!
//! These traits define the public API of the application use-cases.
//! They are implemented by concrete types in the `application` layer
//! and consumed by infrastructure adapters (HTTP handlers, CLI commands).
//!
//! ## Traits
//! - `SettingsService` — load/save settings, update provider config
//! - `ConversationService` — load/save conversations, add messages
//! - `MemoryService` — list/save/delete session memories
//!
//! ## Dependency Inversion
//! Application service implementations accept repository traits as generic
//! type parameters. Infrastructure adapters depend only on these service
//! traits, never on concrete implementations.
use anyhow::Result;
use super::conversation::{ChatMessage, Conversation};
use super::memory::Memory;
use super::settings::Settings;
/// Use-cases for application settings.
pub trait SettingsService {
/// Load the current `Settings` from the default store location.
fn load_settings(&self) -> Result<Settings>;
/// Persist updated `Settings` to the default store location.
fn save_settings(&self, settings: &Settings) -> Result<()>;
/// Update (or insert) a provider configuration entry.
///
/// Flow: load current AppConfig → mutate provider map → save.
fn update_provider(&self, name: &str, config: &super::app_config::ProviderConfig)
-> Result<()>;
}
/// Use-cases for conversation (session message) management.
pub trait ConversationService {
/// Load a `Conversation` for the given session ID.
fn load_conversation(&self, session_id: &str) -> Result<Conversation>;
/// Persist a `Conversation` to its session storage.
fn save_conversation(&self, conv: &Conversation) -> Result<()>;
/// Append a single `ChatMessage` to the conversation and persist.
///
/// Flow: push message to in-memory conv → persist full conversation.
fn add_message(&self, conv: &mut Conversation, msg: ChatMessage) -> Result<()>;
}
/// Use-cases for long-term memory management.
pub trait MemoryService {
/// List all memory slugs (filenames without extension).
fn list_memories(&self) -> Result<Vec<String>>;
/// Save (create or overwrite) a `Memory`.
fn save_memory(&self, memory: &Memory) -> Result<()>;
/// Delete a `Memory` by its slug/name.
fn delete_memory(&self, name: &str) -> Result<()>;
}