feat: add convenience methods to filter service and improve filter chain processing
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -31,7 +31,10 @@ impl FilterChain {
|
||||
pub fn process(&mut self, data: &[u8]) -> Result<Vec<u8>> {
|
||||
let mut current_data = data.to_vec();
|
||||
for plugin in &mut self.plugins {
|
||||
current_data = plugin.process(¤t_data)?;
|
||||
// Process the current data through the plugin
|
||||
let processed = plugin.process(¤t_data)?;
|
||||
current_data = processed;
|
||||
|
||||
// Early exit if no data remains
|
||||
if current_data.is_empty() {
|
||||
break;
|
||||
@@ -42,20 +45,15 @@ impl FilterChain {
|
||||
|
||||
pub fn finish(&mut self) -> Result<Vec<u8>> {
|
||||
let mut result = Vec::new();
|
||||
let mut all_data = Vec::new();
|
||||
|
||||
|
||||
// Process each plugin's finish method and collect results
|
||||
for plugin in &mut self.plugins {
|
||||
let processed = plugin.finish()?;
|
||||
if !processed.is_empty() {
|
||||
all_data.extend(processed);
|
||||
let finished_data = plugin.finish()?;
|
||||
if !finished_data.is_empty() {
|
||||
result.extend(finished_data);
|
||||
}
|
||||
}
|
||||
|
||||
// If we have any data from finish, use it
|
||||
if !all_data.is_empty() {
|
||||
result = all_data;
|
||||
}
|
||||
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user