mirror of
https://github.com/outbackdingo/optimclaw.git
synced 2026-08-29 08:59:31 +00:00
Add ToolExecutor for standalone tool dispatch used by both the
orchestrator HTTP RPC endpoint and the WASM tool_invoke host function.
Includes Python SDK for container scripts, WASM test fixture, and
comprehensive E2E test coverage across all PTC paths.
Implementation:
- ToolExecutor with timeout, nesting depth limit, safety sanitization
- Orchestrator POST /worker/{job_id}/tools/call endpoint with SSE events
- WASM tool_invoke host function with alias resolution
- Python SDK (stdlib-only) with call_tool + convenience wrappers
Tests (16 new):
- 6 orchestrator HTTP RPC tests (auth, echo, not-found, timeout, SSE, no-executor)
- 3 executor integration tests (sanitization, invalid params, sequential)
- 4 Python SDK tests (env vars, request format, HTTP error, wrappers)
- 3 WASM E2E tests (echo via alias, alias not granted, no capability)
Refs #407
Co-Authored-By: Claude Opus 4.6 <[email protected]>
53 lines
1.5 KiB
Rust
53 lines
1.5 KiB
Rust
wit_bindgen::generate!({
|
|
world: "sandboxed-tool",
|
|
path: "../../wit/tool.wit",
|
|
});
|
|
|
|
struct TestPtcTool;
|
|
|
|
impl exports::near::agent::tool::Guest for TestPtcTool {
|
|
fn execute(req: exports::near::agent::tool::Request) -> exports::near::agent::tool::Response {
|
|
match execute_inner(&req.params) {
|
|
Ok(result) => exports::near::agent::tool::Response {
|
|
output: Some(result),
|
|
error: None,
|
|
},
|
|
Err(e) => exports::near::agent::tool::Response {
|
|
output: None,
|
|
error: Some(e),
|
|
},
|
|
}
|
|
}
|
|
|
|
fn schema() -> String {
|
|
r#"{"type":"object","properties":{"message":{"type":"string"}},"required":["message"]}"#.to_string()
|
|
}
|
|
|
|
fn description() -> String {
|
|
"Test tool for PTC: calls echo via tool_invoke".to_string()
|
|
}
|
|
}
|
|
|
|
fn execute_inner(params: &str) -> Result<String, String> {
|
|
let parsed: serde_json::Value = serde_json::from_str(params)
|
|
.map_err(|e| format!("Invalid params: {}", e))?;
|
|
|
|
let message = parsed.get("message")
|
|
.and_then(|v| v.as_str())
|
|
.ok_or("Missing 'message' parameter")?;
|
|
|
|
// Build the parameters for the echo tool
|
|
let echo_params = serde_json::json!({"message": message});
|
|
|
|
// Call tool_invoke with alias "echo_alias" which should resolve to "echo"
|
|
let result = near::agent::host::tool_invoke(
|
|
"echo_alias",
|
|
&echo_params.to_string(),
|
|
)?;
|
|
|
|
// Prefix to prove it went through WASM
|
|
Ok(format!("via_wasm:{}", result))
|
|
}
|
|
|
|
export!(TestPtcTool);
|