Refactor: Restructure collab main function to prepare for new subcommand: serve llm (#15824)

This is just a refactor that we're landing ahead of any functional
changes to make sure we haven't broken anything.

Release Notes:

- N/A

Co-authored-by: Marshall <marshall@zed.dev>
Co-authored-by: Jason <jason@zed.dev>
This commit is contained in:
Max Brunsfeld 2024-08-05 12:07:38 -07:00 committed by GitHub
parent 705f7e7a03
commit 27779e33fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 142 additions and 85 deletions

View file

@ -3,6 +3,7 @@ pub mod auth;
pub mod db;
pub mod env;
pub mod executor;
pub mod llm;
mod rate_limiter;
pub mod rpc;
pub mod seed;
@ -124,7 +125,7 @@ impl std::fmt::Display for Error {
impl std::error::Error for Error {}
#[derive(Deserialize)]
#[derive(Clone, Deserialize)]
pub struct Config {
pub http_port: u16,
pub database_url: String,
@ -176,6 +177,29 @@ impl Config {
}
}
/// The service mode that collab should run in.
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum ServiceMode {
Api,
Collab,
Llm,
All,
}
impl ServiceMode {
pub fn is_collab(&self) -> bool {
matches!(self, Self::Collab | Self::All)
}
pub fn is_api(&self) -> bool {
matches!(self, Self::Api | Self::All)
}
pub fn is_llm(&self) -> bool {
matches!(self, Self::Llm | Self::All)
}
}
pub struct AppState {
pub db: Arc<Database>,
pub live_kit_client: Option<Arc<dyn live_kit_server::api::Client>>,