coreason-engine 0.1.0

Coreason execution engine for deterministic computation
Documentation
// Copyright (c) 2026 CoReason, Inc
//
// This software is proprietary and dual-licensed
// Licensed under the Prosperity Public License 3.0 (the "License")
// A copy of the license is available at <https://prosperitylicense.com/versions/3.0.0>
// For details, see the LICENSE file
// Commercial use beyond a 30-day trial requires a separate license
//
// Source Code: <https://github.com/CoReason-AI/coreason-runtime>

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())
    }
}