Skip to main content

ScriptHost

Trait ScriptHost 

Source
pub trait ScriptHost: Send + Sync {
    // Required methods
    fn http_get(
        &self,
        url: &str,
        headers: BTreeMap<String, String>,
    ) -> Result<String, String>;
    fn http_post(
        &self,
        url: &str,
        body: &str,
        headers: BTreeMap<String, String>,
    ) -> Result<String, String>;
    fn shell(&self, command: &str) -> Result<String, String>;
    fn read_file(&self, path: &str) -> Result<String, String>;
    fn write_file(&self, path: &str, content: &str) -> Result<String, String>;
    fn env_var(&self, name: &str) -> Result<String, String>;
}
Expand description

The side-effecting host functions a script tool can call. Implemented by the daemon (with permission enforcement + real I/O) and by tests (with canned responses). Every method returns Result<String, String>; an Err(msg) is turned into a Rhai exception by the tool engine, which surfaces to the agent as an [error] … result.

Required Methods§

Source

fn http_get( &self, url: &str, headers: BTreeMap<String, String>, ) -> Result<String, String>

HTTP GET url with the given request headers, returning the response body.

Source

fn http_post( &self, url: &str, body: &str, headers: BTreeMap<String, String>, ) -> Result<String, String>

HTTP POST body to url with the given headers, returning the response body.

Source

fn shell(&self, command: &str) -> Result<String, String>

Run a shell command, returning its combined output.

Source

fn read_file(&self, path: &str) -> Result<String, String>

Read a file (confined to the agent workdir by the implementor).

Source

fn write_file(&self, path: &str, content: &str) -> Result<String, String>

Write content to a file (confined to the agent workdir by the implementor), returning a short confirmation.

Source

fn env_var(&self, name: &str) -> Result<String, String>

Read an environment variable.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§