aether-core 0.1.5

Core library for AI-powered code injection framework
Documentation
//! # Aether Runtime
//!
//! Executive environment for dynamic AI code execution.
//! This module uses the Rhai script engine to execute code generated by AI at runtime.

use crate::{Result, AetherError};
use rhai::{Engine, Dynamic, Scope};
use std::collections::HashMap;

/// A runtime environment capable of executing AI-generated scripts in isolation.
pub struct AetherRuntime {
    engine: Engine,
}

impl AetherRuntime {
    /// Create a new Aether runtime.
    pub fn new() -> Self {
        let mut engine = Engine::new();
        // Disable potentially dangerous operations for security
        engine.set_max_operations(1000); 
        
        Self { engine }
    }

    /// Execute AI-generated code as a Rhai script.
    /// 
    /// # Arguments
    /// 
    /// * `script` - The raw script generated by AI.
    /// * `inputs` - A map of input variables to pass to the script.
    pub fn execute(&self, script: &str, inputs: HashMap<String, Dynamic>) -> Result<Dynamic> {
        let mut scope = Scope::new();
        
        // Push inputs into scope
        for (name, val) in inputs {
            scope.push(name, val);
        }

        // Execute script
        self.engine.eval_with_scope(&mut scope, script)
            .map_err(|e| AetherError::ConfigError(format!("Runtime execution failed: {}", e)))
    }
}

impl Default for AetherRuntime {
    fn default() -> Self {
        Self::new()
    }
}