codex_convert_proxy/proxy/
core.rs1use std::collections::HashMap;
4use std::sync::Arc;
5
6use crate::config::BackendRouter;
7use crate::providers::Provider;
8use crate::proxy::context_store::{ConversationSnapshot, ConversationStore};
9
10pub struct CodexProxy {
12 pub router: Arc<BackendRouter>,
14 pub providers: HashMap<String, Arc<dyn Provider>>,
16 pub log_body: bool,
18 pub log_dir: std::path::PathBuf,
20 pub conversation_store: Arc<ConversationStore>,
22}
23
24impl CodexProxy {
25 pub fn new(
27 router: Arc<BackendRouter>,
28 providers: HashMap<String, Arc<dyn Provider>>,
29 log_body: bool,
30 log_dir: std::path::PathBuf,
31 ) -> Self {
32 Self {
33 router,
34 providers,
35 log_body,
36 log_dir,
37 conversation_store: Arc::new(ConversationStore::new()),
38 }
39 }
40
41 pub fn get_provider(&self, name: &str) -> Option<Arc<dyn Provider>> {
43 self.providers.get(name).map(Arc::clone)
44 }
45
46 pub fn get_conversation(&self, response_id: &str) -> Option<ConversationSnapshot> {
48 self.conversation_store.get(response_id)
49 }
50
51 pub fn store_conversation(&self, response_id: String, snapshot: ConversationSnapshot) {
53 self.conversation_store.insert(response_id, snapshot);
54 }
55}