traits.rs (1835B)
1 use crate::messages::DaveApiResponse; 2 use crate::tools::Tool; 3 use claude_agent_sdk_rs::PermissionMode; 4 use std::collections::HashMap; 5 use std::path::PathBuf; 6 use std::sync::mpsc; 7 use std::sync::Arc; 8 9 /// Backend type selection 10 #[derive(Debug, Clone, Copy, PartialEq, Eq)] 11 pub enum BackendType { 12 OpenAI, 13 Claude, 14 } 15 16 /// Trait for AI backend implementations 17 pub trait AiBackend: Send + Sync { 18 /// Stream a request to the AI backend 19 /// 20 /// Returns a receiver that will receive tokens and tool calls as they arrive, 21 /// plus an optional JoinHandle to the spawned task for cleanup on session deletion. 22 /// 23 /// If `resume_session_id` is Some, the backend should resume the specified Claude 24 /// session instead of starting a new conversation. 25 #[allow(clippy::too_many_arguments)] 26 fn stream_request( 27 &self, 28 messages: Vec<crate::Message>, 29 tools: Arc<HashMap<String, Tool>>, 30 model: String, 31 user_id: String, 32 session_id: String, 33 cwd: Option<PathBuf>, 34 resume_session_id: Option<String>, 35 ctx: egui::Context, 36 ) -> ( 37 mpsc::Receiver<DaveApiResponse>, 38 Option<tokio::task::JoinHandle<()>>, 39 ); 40 41 /// Clean up resources associated with a session. 42 /// Called when a session is deleted to allow backends to shut down any persistent connections. 43 fn cleanup_session(&self, session_id: String); 44 45 /// Interrupt the current query for a session. 46 /// This stops any in-progress work but preserves the session history. 47 fn interrupt_session(&self, session_id: String, ctx: egui::Context); 48 49 /// Set the permission mode for a session. 50 /// Plan mode makes Claude plan actions without executing them. 51 fn set_permission_mode(&self, session_id: String, mode: PermissionMode, ctx: egui::Context); 52 }