mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 14:25:02 +00:00
Each plugin now follows the standardized structure:
- category/plugin_name/plugin_name.{ext} - Implementation
- category/plugin_name/package.json - Plugin metadata
- category/package.json - Category manifest with "plugins" array
Languages restructured:
- Go: 31 plugins across 7 categories (math, string, logic, list, dict, var, convert)
- Rust: 55 plugins as individual crates in Cargo workspace
- C++: 34 header-only plugins with complete coverage
- Mojo: 11 plugins across 3 categories (math, string, list)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
78 lines
2.0 KiB
Rust
78 lines
2.0 KiB
Rust
//! MetaBuilder Workflow Plugin Base Types
|
|
//!
|
|
//! Shared types for all Rust workflow plugins.
|
|
|
|
use serde_json::Value;
|
|
use std::collections::HashMap;
|
|
|
|
/// Runtime context for plugin execution.
|
|
pub struct Runtime {
|
|
/// Workflow state storage
|
|
pub store: HashMap<String, Value>,
|
|
/// Shared context (clients, config)
|
|
pub context: HashMap<String, Value>,
|
|
}
|
|
|
|
impl Runtime {
|
|
pub fn new() -> Self {
|
|
Runtime {
|
|
store: HashMap::new(),
|
|
context: HashMap::new(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for Runtime {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|
|
|
|
/// Result type for plugin operations
|
|
pub type PluginResult = Result<HashMap<String, Value>, PluginError>;
|
|
|
|
/// Error type for plugin operations
|
|
#[derive(Debug)]
|
|
pub enum PluginError {
|
|
MissingInput(String),
|
|
InvalidType(String),
|
|
OperationFailed(String),
|
|
}
|
|
|
|
impl std::fmt::Display for PluginError {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
PluginError::MissingInput(s) => write!(f, "Missing required input: {}", s),
|
|
PluginError::InvalidType(s) => write!(f, "Invalid input type: {}", s),
|
|
PluginError::OperationFailed(s) => write!(f, "Operation failed: {}", s),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::error::Error for PluginError {}
|
|
|
|
/// Trait for workflow plugins
|
|
pub trait Plugin {
|
|
fn run(&self, runtime: &mut Runtime, inputs: &HashMap<String, Value>) -> PluginResult;
|
|
}
|
|
|
|
/// Helper to get a value from inputs with type conversion
|
|
pub fn get_input<T: serde::de::DeserializeOwned>(
|
|
inputs: &HashMap<String, Value>,
|
|
key: &str,
|
|
) -> Option<T> {
|
|
inputs.get(key).and_then(|v| serde_json::from_value(v.clone()).ok())
|
|
}
|
|
|
|
/// Helper macro to create output map
|
|
#[macro_export]
|
|
macro_rules! output {
|
|
($($key:expr => $value:expr),* $(,)?) => {{
|
|
let mut map = std::collections::HashMap::new();
|
|
$(
|
|
map.insert($key.to_string(), serde_json::json!($value));
|
|
)*
|
|
map
|
|
}};
|
|
}
|