noether_engine/executor/
composite.rs1use super::inline::{InlineExecutor, InlineRegistry};
9use super::nix::NixExecutor;
10use super::runtime::RuntimeExecutor;
11use super::{ExecutionError, StageExecutor};
12use noether_core::stage::StageId;
13use noether_store::StageStore;
14use serde_json::Value;
15
16pub struct CompositeExecutor {
18 inline: InlineExecutor,
19 nix: Option<NixExecutor>,
20 runtime: RuntimeExecutor,
21}
22
23impl CompositeExecutor {
24 pub fn from_store(store: &dyn StageStore) -> Self {
27 Self::from_store_with_registry(store, InlineRegistry::new())
28 }
29
30 pub fn from_store_with_registry(store: &dyn StageStore, registry: InlineRegistry) -> Self {
36 let inline = InlineExecutor::from_store_with_registry(store, registry);
37 let nix = NixExecutor::from_store(store);
38 let runtime = RuntimeExecutor::from_store(store);
39
40 if nix.is_some() {
41 eprintln!("Nix executor: active (synthesized stages will run via nix)");
42 }
43
44 Self {
45 inline,
46 nix,
47 runtime,
48 }
49 }
50
51 pub fn with_llm(
54 mut self,
55 llm: Box<dyn crate::llm::LlmProvider>,
56 config: crate::llm::LlmConfig,
57 ) -> Self {
58 self.runtime.set_llm(llm, config);
59 self
60 }
61
62 pub fn with_embedding(
65 mut self,
66 provider: Box<dyn crate::index::embedding::EmbeddingProvider>,
67 ) -> Self {
68 self.runtime = self.runtime.with_embedding(provider);
69 self
70 }
71
72 pub fn register_synthesized(&mut self, stage_id: &StageId, code: &str, language: &str) {
75 if let Some(nix) = &mut self.nix {
76 nix.register(stage_id, code, language);
77 }
78 }
79
80 pub fn nix_available(&self) -> bool {
82 self.nix.is_some()
83 }
84}
85
86impl StageExecutor for CompositeExecutor {
87 fn execute(&self, stage_id: &StageId, input: &Value) -> Result<Value, ExecutionError> {
88 if let Some(nix) = &self.nix {
90 if nix.has_implementation(stage_id) {
91 return nix.execute(stage_id, input);
92 }
93 }
94 if self.runtime.has_implementation(stage_id) {
96 return self.runtime.execute(stage_id, input);
97 }
98 self.inline.execute(stage_id, input)
100 }
101}