use std::collections::HashMap;
use std::sync::Arc;
use crate::config::BackendRouter;
use crate::providers::Provider;
use crate::proxy::context_store::{ConversationSnapshot, ConversationStore};
pub struct CodexProxy {
pub router: Arc<BackendRouter>,
pub providers: HashMap<String, Arc<dyn Provider>>,
pub log_body: bool,
pub log_dir: std::path::PathBuf,
pub conversation_store: Arc<ConversationStore>,
}
impl CodexProxy {
pub fn new(
router: Arc<BackendRouter>,
providers: HashMap<String, Arc<dyn Provider>>,
log_body: bool,
log_dir: std::path::PathBuf,
) -> Self {
Self {
router,
providers,
log_body,
log_dir,
conversation_store: Arc::new(ConversationStore::new()),
}
}
pub fn get_provider(&self, name: &str) -> Option<Arc<dyn Provider>> {
self.providers.get(name).map(Arc::clone)
}
pub fn get_conversation(&self, response_id: &str) -> Option<ConversationSnapshot> {
self.conversation_store.get(response_id)
}
pub fn store_conversation(&self, response_id: String, snapshot: ConversationSnapshot) {
self.conversation_store.insert(response_id, snapshot);
}
}