Files
zesdex/apps/infrastructure/src/persistence/cms/conversation_repo.rs
T
asepharyana da2ed6da25 feat(tui): add usage overlay and sidebar for displaying usage statistics and tasks
feat(tui): implement status bar with connection and turn state indicators
feat(tui): create workflow panel for agent status and progress visualization
feat(web): introduce web frontend interface with static file serving
feat(ws): add WebSocket interface for real-time communication and session management
2026-07-20 09:04:57 +07:00

35 lines
1.1 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! JSON filebacked `ConversationRepository`.
//! Stores `Conversation` at `<session_dir>/conversation.json`.
use std::path::Path;
use zesdex_domain::cms::{Conversation, ConversationRepository, RepositoryError};
use crate::utils::write_json_atomic;
/// File-based `ConversationRepository` that reads/writes `conversation.json`.
#[derive(Debug, Clone, Default)]
pub struct JsonConversationRepository;
impl JsonConversationRepository {
pub fn new() -> Self {
Self
}
}
impl ConversationRepository for JsonConversationRepository {
fn load(&self, session_dir: &Path) -> Result<Conversation, RepositoryError> {
let path = session_dir.join("conversation.json");
let data = std::fs::read_to_string(&path)?;
let conv: Conversation = serde_json::from_str(&data)?;
Ok(conv)
}
fn save(&self, session_dir: &Path, conversation: &Conversation) -> Result<(), RepositoryError> {
std::fs::create_dir_all(session_dir)?;
let path = session_dir.join("conversation.json");
write_json_atomic(&path, conversation, None)?;
Ok(())
}
}