| 1 | use crate::config::CommandCompactionConfig; |
| 2 | use crate::outcome::CommandResult; |
| 3 | use crate::types::CommandProviderId; |
| 4 | pub use codewhale_protocol::setup::SetupStep; |
| 5 | |
| 6 | pub enum ModelSelection<'a> { |
| 7 | Auto, |
| 8 | Named(&'a str), |
| 9 | } |
| 10 | |
| 11 | pub struct ModelSelectionReceipt { |
| 12 | pub message: String, |
| 13 | pub compaction: CommandCompactionConfig, |
| 14 | } |
| 15 | |
| 16 | pub struct ProviderSelection { |
| 17 | pub id: CommandProviderId, |
| 18 | pub model: Option<String>, |
| 19 | pub already_active: bool, |
| 20 | } |
| 21 | |
| 22 | pub struct ProviderFallback { |
| 23 | pub current: String, |
| 24 | pub entries: Vec<(usize, CommandProviderId, bool)>, |
| 25 | pub last_reason: Option<String>, |
| 26 | } |
| 27 | |
| 28 | pub trait CommandProviderRoutesContext { |
| 29 | fn resolve_switch( |
| 30 | &self, |
| 31 | selector: &str, |
| 32 | model: Option<&str>, |
| 33 | ) -> Result<ProviderSelection, String>; |
| 34 | fn fallback(&self) -> ProviderFallback; |
| 35 | } |
| 36 | |
| 37 | pub trait CommandModelSelectionContext { |
| 38 | fn select_session_model( |
| 39 | &mut self, |
| 40 | selection: ModelSelection<'_>, |
| 41 | ) -> Result<ModelSelectionReceipt, String>; |
| 42 | fn save_session_route_default(&mut self) -> String; |
| 43 | } |
| 44 | |
| 45 | pub enum ModelAction<'a> { |
| 46 | OpenPicker, |
| 47 | RefreshCatalog, |
| 48 | Router(&'a str), |
| 49 | UpdateCompaction(CommandCompactionConfig), |
| 50 | } |
| 51 | |
| 52 | pub enum ProviderAction<'a> { |
| 53 | OpenPicker, |
| 54 | Setup(Option<&'a str>), |
| 55 | Switch { |
| 56 | provider: CommandProviderId, |
| 57 | model: Option<String>, |
| 58 | }, |
| 59 | } |
| 60 | |
| 61 | pub enum SetupAction<'a> { |
| 62 | OpenWizard(Option<SetupStep>), |
| 63 | Provider(&'a str), |
| 64 | } |
| 65 | |
| 66 | pub fn resolve_action<T, A: TryFrom<T>>(intent: T, message: Option<String>) -> CommandResult<A> |
| 67 | where |
| 68 | A::Error: std::fmt::Display, |
| 69 | { |
| 70 | match A::try_from(intent) { |
| 71 | Ok(action) => CommandResult { |
| 72 | message, |
| 73 | action: Some(action), |
| 74 | is_error: false, |
| 75 | }, |
| 76 | Err(reason) => CommandResult::error(reason.to_string()), |
| 77 | } |
| 78 | } |
| 79 |