refactor: update meta plugins to use new trait interface
Co-authored-by: aider (openai/andrew/openrouter/mistralai/mistral-medium-3.1) <aider@aider.chat>
This commit is contained in:
@@ -95,9 +95,9 @@ impl MetaPlugin for MetaPluginProgram {
|
||||
false
|
||||
}
|
||||
|
||||
fn initialize(&mut self, _conn: &rusqlite::Connection, item_id: i64) -> Result<()> {
|
||||
fn initialize(&mut self, item_id: i64) -> Result<PluginResponse> {
|
||||
debug!("META: Initializing program plugin: {:?}", self);
|
||||
|
||||
|
||||
// Store item ID for later use
|
||||
self.item_id = Some(item_id);
|
||||
|
||||
@@ -122,18 +122,20 @@ impl MetaPlugin for MetaPluginProgram {
|
||||
self.writer = Some(Box::new(stdin));
|
||||
self.process = Some(process);
|
||||
|
||||
Ok(())
|
||||
Ok(PluginResponse::default())
|
||||
}
|
||||
|
||||
fn finalize(&mut self, conn: &Connection) -> Result<()> {
|
||||
fn finalize(&mut self) -> Result<PluginResponse> {
|
||||
debug!("META: Finalizing program plugin");
|
||||
let mut metadata = Vec::new();
|
||||
|
||||
if let Some(process) = self.process.take() {
|
||||
// Close stdin to signal end of input
|
||||
drop(self.writer.take());
|
||||
|
||||
|
||||
// Wait for the process to complete
|
||||
let output = process.wait_with_output()?;
|
||||
|
||||
|
||||
if output.status.success() {
|
||||
// Process the output
|
||||
let output_str = String::from_utf8_lossy(&output.stdout);
|
||||
@@ -142,14 +144,16 @@ impl MetaPlugin for MetaPluginProgram {
|
||||
} else {
|
||||
output_str.trim().to_string()
|
||||
};
|
||||
|
||||
|
||||
if !result.is_empty() {
|
||||
debug!("META: Program output: {}", result);
|
||||
self.result = Some(result);
|
||||
|
||||
// Save the result to database if we have item_id
|
||||
|
||||
// Create metadata to be stored
|
||||
if let Some(item_id) = self.item_id {
|
||||
let _ = self.save_meta(conn, item_id, &self.meta_name.clone(), self.result.clone().unwrap());
|
||||
if let Some(meta) = self.create_meta(item_id, &self.meta_name, result) {
|
||||
metadata.push(meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -160,15 +164,20 @@ impl MetaPlugin for MetaPluginProgram {
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Ok(PluginResponse {
|
||||
metadata: if metadata.is_empty() { None } else { Some(metadata) },
|
||||
is_finalized: true,
|
||||
})
|
||||
}
|
||||
|
||||
fn update(&mut self, data: &[u8], _conn: &Connection) {
|
||||
fn update(&mut self, data: &[u8]) -> Result<PluginResponse> {
|
||||
if let Some(ref mut writer) = self.writer {
|
||||
if let Err(e) = writer.write_all(data) {
|
||||
debug!("META: Failed to write to process stdin: {}", e);
|
||||
}
|
||||
}
|
||||
Ok(PluginResponse::default())
|
||||
}
|
||||
|
||||
fn meta_name(&self) -> String {
|
||||
|
||||
Reference in New Issue
Block a user