coreason-runtime 0.1.0

Kinetic Plane execution engine for the CoReason Tripartite Cybernetic Manifold
Documentation
// Copyright (c) 2026 CoReason, Inc.
// All rights reserved.

use extism::Plugin;
use std::path::Path;

pub struct WasmDispatcher;

impl WasmDispatcher {
    pub fn execute_plugin(
        plugin_path: &str,
        function_name: &str,
        input_data: &str,
    ) -> Result<String, String> {
        let wasm_file_path = Path::new(plugin_path);
        if !wasm_file_path.exists() {
            return Err(format!("Plugin file not found at path: {}", plugin_path));
        }

        let wasm_bytes = std::fs::read(wasm_file_path)
            .map_err(|e| format!("Failed to read WASM bytes from file: {}", e))?;

        // Initialize Extism Plugin in a sandboxed WASI environment
        let mut plugin = Plugin::new(&wasm_bytes, [], true)
            .map_err(|e| format!("Failed to initialize Extism plugin: {}", e))?;

        // Call the target function in the guest module
        let output = plugin
            .call::<&str, &str>(function_name, input_data)
            .map_err(|e| format!("Extism guest execution failed: {}", e))?;

        Ok(output.to_string())
    }
}