feat: add unified status service implementation
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -33,22 +33,11 @@ pub async fn handle_status(
|
|||||||
// Get database path
|
// Get database path
|
||||||
let db_path = state.db.lock().await.path().unwrap_or("unknown").to_string();
|
let db_path = state.db.lock().await.path().unwrap_or("unknown").to_string();
|
||||||
|
|
||||||
// Get all meta plugin types that are supported
|
// Use the status service to generate status info showing all supported plugins
|
||||||
let supported_meta_plugins: Vec<MetaPluginType> = MetaPluginType::iter()
|
let status_service = crate::services::status_service::StatusService::new();
|
||||||
.filter(|mpt| {
|
let status_info = status_service.generate_supported_status(
|
||||||
let plugin = crate::meta_plugin::get_meta_plugin((*mpt).clone(), None, None);
|
|
||||||
plugin.is_supported()
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
// Default to LZ4 compression for the API status endpoint
|
|
||||||
let enabled_compression_type = Some(CompressionType::LZ4);
|
|
||||||
|
|
||||||
let status_info = generate_status_info(
|
|
||||||
state.data_dir.clone(),
|
state.data_dir.clone(),
|
||||||
db_path.into(),
|
db_path.into(),
|
||||||
&supported_meta_plugins,
|
|
||||||
enabled_compression_type,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let response = ApiResponse {
|
let response = ApiResponse {
|
||||||
|
|||||||
@@ -340,34 +340,18 @@ fn build_meta_plugin_table(meta_plugin_info: &Vec<MetaPluginInfo>) -> Table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn mode_status(
|
pub fn mode_status(
|
||||||
_cmd: &mut Command,
|
cmd: &mut Command,
|
||||||
settings: &config::Settings,
|
settings: &config::Settings,
|
||||||
data_path: PathBuf,
|
data_path: PathBuf,
|
||||||
db_path: PathBuf,
|
db_path: PathBuf,
|
||||||
) -> Result<(), anyhow::Error> {
|
) -> Result<(), anyhow::Error> {
|
||||||
debug!("STATUS: Starting mode_status function");
|
debug!("STATUS: Starting mode_status function");
|
||||||
|
|
||||||
// Determine which meta plugins would be enabled for a save operation
|
let status_service = crate::services::status_service::StatusService::new();
|
||||||
debug!("STATUS: Getting meta plugin types from settings");
|
|
||||||
let mut meta_plugin_types: Vec<MetaPluginType> = crate::modes::common::settings_meta_plugin_types(_cmd, settings);
|
|
||||||
debug!("STATUS: Got {} meta plugin types", meta_plugin_types.len());
|
|
||||||
|
|
||||||
// Always add the Digest plugin if not present
|
|
||||||
if !meta_plugin_types.contains(&MetaPluginType::Digest) {
|
|
||||||
meta_plugin_types.push(MetaPluginType::Digest);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine which compression type would be enabled for a save operation
|
|
||||||
let enabled_compression_type = if let Some(compression_name) = &settings.compression() {
|
|
||||||
CompressionType::from_str(compression_name).ok()
|
|
||||||
} else {
|
|
||||||
Some(crate::compression_engine::default_compression_type())
|
|
||||||
};
|
|
||||||
|
|
||||||
let output_format = crate::modes::common::settings_output_format(settings);
|
let output_format = crate::modes::common::settings_output_format(settings);
|
||||||
debug!("STATUS: About to call generate_status_info");
|
debug!("STATUS: About to generate status info");
|
||||||
let status_info = generate_status_info(data_path, db_path, &meta_plugin_types, enabled_compression_type);
|
let status_info = status_service.generate_status(cmd, settings, data_path, db_path);
|
||||||
debug!("STATUS: generate_status_info completed successfully");
|
debug!("STATUS: Status info generated successfully");
|
||||||
|
|
||||||
match output_format {
|
match output_format {
|
||||||
OutputFormat::Table => {
|
OutputFormat::Table => {
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
use crate::common::status::{generate_status_info, StatusInfo};
|
||||||
|
use crate::config::Settings;
|
||||||
|
use crate::meta_plugin::MetaPluginType;
|
||||||
|
use crate::compression_engine::CompressionType;
|
||||||
|
use clap::Command;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
pub struct StatusService;
|
||||||
|
|
||||||
|
impl StatusService {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn generate_status(
|
||||||
|
&self,
|
||||||
|
cmd: &mut Command,
|
||||||
|
settings: &Settings,
|
||||||
|
data_path: PathBuf,
|
||||||
|
db_path: PathBuf,
|
||||||
|
) -> StatusInfo {
|
||||||
|
// Determine which meta plugins would be enabled for a save operation
|
||||||
|
let mut meta_plugin_types: Vec<MetaPluginType> = crate::modes::common::settings_meta_plugin_types(cmd, settings);
|
||||||
|
|
||||||
|
// Always add the Digest plugin if not present
|
||||||
|
if !meta_plugin_types.contains(&MetaPluginType::Digest) {
|
||||||
|
meta_plugin_types.push(MetaPluginType::Digest);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine which compression type would be enabled for a save operation
|
||||||
|
let enabled_compression_type = if let Some(compression_name) = &settings.compression() {
|
||||||
|
CompressionType::from_str(compression_name).ok()
|
||||||
|
} else {
|
||||||
|
Some(crate::compression_engine::default_compression_type())
|
||||||
|
};
|
||||||
|
|
||||||
|
generate_status_info(data_path, db_path, &meta_plugin_types, enabled_compression_type)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn generate_supported_status(
|
||||||
|
&self,
|
||||||
|
data_path: PathBuf,
|
||||||
|
db_path: PathBuf,
|
||||||
|
) -> StatusInfo {
|
||||||
|
// Get all meta plugin types that are supported
|
||||||
|
let supported_meta_plugins: Vec<MetaPluginType> = MetaPluginType::iter()
|
||||||
|
.filter(|mpt| {
|
||||||
|
let plugin = crate::meta_plugin::get_meta_plugin((*mpt).clone(), None, None);
|
||||||
|
plugin.is_supported()
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
// Default to LZ4 compression for the API status endpoint
|
||||||
|
let enabled_compression_type = Some(CompressionType::LZ4);
|
||||||
|
|
||||||
|
generate_status_info(data_path, db_path, &supported_meta_plugins, enabled_compression_type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for StatusService {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user