2026-07-16 12:32:17 +07:00
|
|
|
//! Service trait definitions — use-case boundaries for CMS operations.
|
|
|
|
|
//!
|
2026-07-19 17:05:27 +07:00
|
|
|
//! 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.
|
2026-07-16 12:32:17 +07:00
|
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
|
|
|
|
|
use super::conversation::{ChatMessage, Conversation};
|
|
|
|
|
use super::memory::Memory;
|
|
|
|
|
use super::settings::Settings;
|
|
|
|
|
|
2026-07-19 17:05:27 +07:00
|
|
|
/// Use-cases for application settings.
|
2026-07-16 12:32:17 +07:00
|
|
|
pub trait SettingsService {
|
2026-07-19 17:05:27 +07:00
|
|
|
/// Load the current `Settings` from the default store location.
|
2026-07-16 12:32:17 +07:00
|
|
|
fn load_settings(&self) -> Result<Settings>;
|
|
|
|
|
|
2026-07-19 17:05:27 +07:00
|
|
|
/// Persist updated `Settings` to the default store location.
|
2026-07-16 12:32:17 +07:00
|
|
|
fn save_settings(&self, settings: &Settings) -> Result<()>;
|
|
|
|
|
|
2026-07-19 17:05:27 +07:00
|
|
|
/// Update (or insert) a provider configuration entry.
|
|
|
|
|
///
|
|
|
|
|
/// Flow: load current AppConfig → mutate provider map → save.
|
2026-07-17 06:44:31 +07:00
|
|
|
fn update_provider(&self, name: &str, config: &super::app_config::ProviderConfig)
|
|
|
|
|
-> Result<()>;
|
2026-07-16 12:32:17 +07:00
|
|
|
}
|
|
|
|
|
|
2026-07-19 17:05:27 +07:00
|
|
|
/// Use-cases for conversation (session message) management.
|
2026-07-16 12:32:17 +07:00
|
|
|
pub trait ConversationService {
|
2026-07-19 17:05:27 +07:00
|
|
|
/// Load a `Conversation` for the given session ID.
|
2026-07-16 12:32:17 +07:00
|
|
|
fn load_conversation(&self, session_id: &str) -> Result<Conversation>;
|
|
|
|
|
|
2026-07-19 17:05:27 +07:00
|
|
|
/// Persist a `Conversation` to its session storage.
|
2026-07-16 12:32:17 +07:00
|
|
|
fn save_conversation(&self, conv: &Conversation) -> Result<()>;
|
|
|
|
|
|
2026-07-19 17:05:27 +07:00
|
|
|
/// Append a single `ChatMessage` to the conversation and persist.
|
|
|
|
|
///
|
|
|
|
|
/// Flow: push message to in-memory conv → persist full conversation.
|
2026-07-16 12:32:17 +07:00
|
|
|
fn add_message(&self, conv: &mut Conversation, msg: ChatMessage) -> Result<()>;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-19 17:05:27 +07:00
|
|
|
/// Use-cases for long-term memory management.
|
2026-07-16 12:32:17 +07:00
|
|
|
pub trait MemoryService {
|
2026-07-19 17:05:27 +07:00
|
|
|
/// List all memory slugs (filenames without extension).
|
2026-07-16 12:32:17 +07:00
|
|
|
fn list_memories(&self) -> Result<Vec<String>>;
|
|
|
|
|
|
2026-07-19 17:05:27 +07:00
|
|
|
/// Save (create or overwrite) a `Memory`.
|
2026-07-16 12:32:17 +07:00
|
|
|
fn save_memory(&self, memory: &Memory) -> Result<()>;
|
|
|
|
|
|
2026-07-19 17:05:27 +07:00
|
|
|
/// Delete a `Memory` by its slug/name.
|
2026-07-16 12:32:17 +07:00
|
|
|
fn delete_memory(&self, name: &str) -> Result<()>;
|
|
|
|
|
}
|