use std::path::Path;
use oxide_agent::wasm::{wasm_tool_definition, WasmTool};
fn main() -> anyhow::Result<()> {
let definition = wasm_tool_definition(
"sanitize_input",
"Strip dangerous characters from user-provided text",
serde_json::json!({
"type": "object",
"properties": {
"text": {
"type": "string",
"description": "Raw user input to sanitize"
}
},
"required": ["text"]
}),
);
let wasm_path = Path::new("tools/sanitize.wasm");
#[cfg(feature = "wasm-tools")]
{
let tool = WasmTool::from_file(wasm_path, definition)?;
let args = serde_json::json!({ "text": "hello <script>alert(1)</script>" });
let result = tool.call(args)?;
println!("Sanitized: {result}");
println!("Tool definition: {}", tool.definition().function.name);
}
#[cfg(not(feature = "wasm-tools"))]
{
let err = WasmTool::from_file(wasm_path, definition).unwrap_err();
println!("Expected error: {err}");
println!("Enable with: oxide-agent = {{ features = [\"wasm-tools\"] }}");
}
Ok(())
}