refactor: compose BaseMetaPlugin in remaining meta plugins

Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-09-12 12:21:03 -03:00
parent 8693061338
commit cb1f330231
7 changed files with 161 additions and 492 deletions

View File

@@ -1,6 +1,6 @@
use std::time::Instant;
use crate::meta_plugin::{MetaPlugin, MetaPluginType};
use crate::meta_plugin::{MetaPlugin, MetaPluginType, BaseMetaPlugin};
#[derive(Debug, Clone, Default)]
/// Meta plugin that calculates the read rate (KB/s) of input data.
@@ -14,14 +14,12 @@ use crate::meta_plugin::{MetaPlugin, MetaPluginType};
/// * `start_time` - Start time of reading, if begun.
/// * `bytes_read` - Total bytes accumulated.
/// * `is_finalized` - Whether processing is complete.
/// * `outputs` - Mapping of output names to values.
/// * `options` - Configuration options.
/// * `base` - Base plugin for outputs and options.
pub struct ReadRateMetaPlugin {
start_time: Option<Instant>,
bytes_read: u64,
is_finalized: bool,
outputs: std::collections::HashMap<String, serde_yaml::Value>,
options: std::collections::HashMap<String, serde_yaml::Value>,
base: BaseMetaPlugin,
}
impl ReadRateMetaPlugin {
@@ -49,32 +47,17 @@ impl ReadRateMetaPlugin {
_options: Option<std::collections::HashMap<String, serde_yaml::Value>>,
outputs: Option<std::collections::HashMap<String, serde_yaml::Value>>,
) -> ReadRateMetaPlugin {
// Start with default options
let mut final_options = std::collections::HashMap::new();
if let Some(opts) = _options {
for (key, value) in opts {
final_options.insert(key, value);
}
}
let mut base = BaseMetaPlugin::new();
// Start with default outputs
let mut final_outputs = std::collections::HashMap::new();
let default_outputs = Self::default().default_outputs();
for output_name in default_outputs {
final_outputs.insert(output_name.clone(), serde_yaml::Value::String(output_name));
}
if let Some(outs) = outputs {
for (key, value) in outs {
final_outputs.insert(key, value);
}
}
// Set default outputs
let default_outputs = &["read_rate"];
base.initialize_plugin(default_outputs, _options, outputs);
ReadRateMetaPlugin {
start_time: None,
bytes_read: 0,
is_finalized: false,
outputs: final_outputs,
options: final_options,
base,
}
}
@@ -136,7 +119,7 @@ impl MetaPlugin for ReadRateMetaPlugin {
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
"read_rate",
serde_yaml::Value::String(rate),
&self.outputs
self.base.outputs()
) {
metadata.push(meta_data);
}
@@ -197,7 +180,7 @@ impl MetaPlugin for ReadRateMetaPlugin {
///
/// Immutable reference to the outputs HashMap.
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.outputs
self.base.outputs()
}
/// Returns a mutable reference to the outputs mapping.
@@ -208,10 +191,17 @@ impl MetaPlugin for ReadRateMetaPlugin {
///
/// Mutable reference to the outputs HashMap.
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.outputs
self.base.outputs_mut()
}
/// Returns the default output names for this plugin.
///
/// # Returns
///
/// Vector containing "read_rate".
fn default_outputs(&self) -> Vec<String> {
vec!["read_rate".to_string()]
}
/// Returns a reference to the options mapping.
///
@@ -219,7 +209,7 @@ impl MetaPlugin for ReadRateMetaPlugin {
///
/// Immutable reference to the options HashMap.
fn options(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.options
self.base.options()
}
/// Returns a mutable reference to the options mapping.
@@ -230,7 +220,7 @@ impl MetaPlugin for ReadRateMetaPlugin {
///
/// Mutable reference to the options HashMap.
fn options_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.options
self.base.options_mut()
}
}
use crate::meta_plugin::register_meta_plugin;