Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Commit bd240e2

Browse files
committed
feat: add support for loading built-in plugins and update command provider handling
1 parent 5f3a7c5 commit bd240e2

5 files changed

Lines changed: 92 additions & 24 deletions

File tree

docs/EMBEDDED_PLUGINS.md

Whitespace-only changes.

rohas-cli/src/main.rs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ enum Commands {
2222
Run {
2323
file: PathBuf,
2424

25-
#[arg(long, default_value = "openai")]
26-
provider: String,
25+
#[arg(long)]
26+
provider: Option<String>,
2727

2828
#[arg(long)]
2929
api_key: Option<String>,
@@ -75,37 +75,43 @@ fn main() -> anyhow::Result<()> {
7575

7676
let mut optimizer = TokenSaver::new();
7777
optimizer.optimize(&mut program);
78+
let mut executor: Executor;
79+
if let Some(provider) = provider {
80+
let provider_enum = match provider.to_string().as_str() {
81+
"openai" => LLMProvider::OpenAI,
82+
"anthropic" => LLMProvider::Anthropic,
83+
"local" => LLMProvider::Local,
84+
"ollama" => LLMProvider::Ollama,
85+
_ => return Err(anyhow::anyhow!("Unknown provider: {}", provider)),
86+
};
87+
let llm_config = ProviderConfig {
88+
provider: provider_enum,
89+
api_key,
90+
base_url,
91+
default_model: model,
92+
};
93+
executor = Executor::new(Some(llm_config))?;
94+
} else {
95+
executor = Executor::new(None)?;
96+
}
7897

79-
let provider_enum = match provider.as_str() {
80-
"openai" => LLMProvider::OpenAI,
81-
"anthropic" => LLMProvider::Anthropic,
82-
"local" => LLMProvider::Local,
83-
"ollama" => LLMProvider::Ollama,
84-
_ => return Err(anyhow::anyhow!("Unknown provider: {}", provider)),
85-
};
86-
87-
let llm_config = ProviderConfig {
88-
provider: provider_enum,
89-
api_key,
90-
base_url,
91-
default_model: model,
92-
};
93-
94-
let mut executor = Executor::new(Some(llm_config))?;
98+
if let Err(e) = executor.load_builtin_plugins() {
99+
eprintln!("Warning: Failed to load builtin plugins: {}", e);
100+
}
95101

96102
if let Err(e) = executor.scan_plugin_directory("plugins") {
97103
eprintln!("Warning: Failed to scan plugins directory: {}", e);
98104
}
99105

100106
if let Err(e) = executor.load_plugins_from_default_manifest() {
101107
eprintln!("Warning: Failed to load plugins from manifest: {}", e);
102-
}
108+
}
103109

104110
let loaded_plugins = executor.list_plugins();
105111
if !loaded_plugins.is_empty() {
106112
eprintln!("Loaded plugins: {}", loaded_plugins.join(", "));
107113
}
108-
114+
109115
let flow_engine = FlowEngine::new(executor);
110116

111117
let mut executor_guard = flow_engine.executor.lock().unwrap();

rohas-plugins/src/builtin/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ impl BuiltinFactory {
5959
version: String,
6060
) -> Result<Box<dyn Plugin>> {
6161
let handler = match builtin_key {
62-
"csv_loader" => csv::load_csv,
63-
"excel_loader" | "xls_loader" => excel::load_excel,
64-
"postgres_query" => postgres::query_postgres,
62+
"csvLoader" => csv::load_csv,
63+
"excelLoader" | "xlsLoader" => excel::load_excel,
64+
"postgresQuery" => postgres::query_postgres,
6565
_ => {
6666
return Err(anyhow!(
67-
"Unknown builtin plugin '{}'. Supported builtins: csv_loader, excel_loader, postgres_query",
67+
"Unknown builtin plugin '{}'. Supported builtins: csvLoader, excelLoader, postgresQuery",
6868
builtin_key
6969
))
7070
}

rohas-runtime/src/executor.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ impl Executor {
114114
))
115115
}
116116

117+
pub fn load_builtin_plugins(&mut self) -> Result<()> {
118+
self.plugins.load_builtin_plugins()
119+
}
120+
117121
pub fn load_plugins_from_manifest(&mut self, manifest_path: &std::path::Path) -> Result<()> {
118122
self.plugins.load_from_manifest(manifest_path)
119123
}

rohas-runtime/src/plugin/registry.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,64 @@ impl PluginRegistry {
7979
Ok(())
8080
}
8181

82+
pub fn load_builtin_plugins(&mut self) -> Result<()> {
83+
// Load CSV loader plugin
84+
self.load_plugin_from_entry("csvLoader", &PluginManifestEntry {
85+
plugin_type: "builtin".to_string(),
86+
description: "Load data from CSV files".to_string(),
87+
version: "1.0.0".to_string(),
88+
endpoint: None,
89+
timeout: 5,
90+
path: None,
91+
args: vec![],
92+
interpreter: None,
93+
script: None,
94+
language: None,
95+
builtin: Some("csvLoader".to_string()),
96+
library: None,
97+
symbol: None,
98+
wasm_path: None,
99+
}, None)?;
100+
101+
// Load Excel loader plugin
102+
self.load_plugin_from_entry("excelLoader", &PluginManifestEntry {
103+
plugin_type: "builtin".to_string(),
104+
description: "Load data from Excel files".to_string(),
105+
version: "1.0.0".to_string(),
106+
endpoint: None,
107+
timeout: 5,
108+
path: None,
109+
args: vec![],
110+
interpreter: None,
111+
script: None,
112+
language: None,
113+
builtin: Some("excelLoader".to_string()),
114+
library: None,
115+
symbol: None,
116+
wasm_path: None,
117+
}, None)?;
118+
119+
// Load PostgreSQL query plugin
120+
self.load_plugin_from_entry("postgresQuery", &PluginManifestEntry {
121+
plugin_type: "builtin".to_string(),
122+
description: "Query PostgreSQL databases".to_string(),
123+
version: "1.0.0".to_string(),
124+
endpoint: None,
125+
timeout: 5,
126+
path: None,
127+
args: vec![],
128+
interpreter: None,
129+
script: None,
130+
language: None,
131+
builtin: Some("postgresQuery".to_string()),
132+
library: None,
133+
symbol: None,
134+
wasm_path: None,
135+
}, None)?;
136+
137+
Ok(())
138+
}
139+
82140
fn load_plugin_from_entry(
83141
&mut self,
84142
name: &str,

0 commit comments

Comments
 (0)