The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(network): add host tool for network host operations
Steven Enamakel0043626af88d
diff --git a/crates/openhuman-core/src/tools/impl/network/host.rs b/crates/openhuman-core/src/tools/impl/network/host.rsindex 21c5bb3b59..668c5f9dd8 100644--- a/crates/openhuman-core/src/tools/impl/network/host.rs+++ b/crates/openhuman-core/src/tools/impl/network/host.rs@@ -13,7 +13,11 @@ use tinytools_std::network::{AsyncHtmlExtractor, HttpLimits, HttpRequestTool, NetGate, WebFetchTool,};+use super::gate::RoutedGate;use crate::config::HttpRequestConfig;+use crate::security::approval::ApprovalChatContext;+use crate::security::SecurityPolicy;+use crate::tools::per_call::PerCallTool;use {tinyjuice_bus::tools::summary_focus_property, tinyjuice_bus::tools::SUMMARY_FOCUS_ARG};/// The fallbacks for a `0` limit, from the `[http_request]` schema defaults, so@@ -50,11 +54,32 @@ impl AsyncHtmlExtractor for TinyJuiceHtml {}/// `http_request`, with the x402 402-retry wired in when `web3` is compiled.+///+/// For a caller that is not in a chat turn (a flow node, a direct dispatch): its+/// disclosures and x402 quotes carry no chat routing. A chat turn registers+/// [`routed_http_request_tool`] instead.pub fn http_request_tool(gate: Arc<dyn NetGate>,allowed_domains: Vec<String>,max_response_size: usize,timeout_secs: u64,+) -> HttpRequestTool {+ http_request_tool_for(+ gate,+ None,+ allowed_domains,+ max_response_size,+ timeout_secs,+ )+}++/// [`http_request_tool`] whose x402 quotes are owned by `chat`.+fn http_request_tool_for(+ gate: Arc<dyn NetGate>,+ chat: Option<&ApprovalChatContext>,+ allowed_domains: Vec<String>,+ max_response_size: usize,+ timeout_secs: u64,) -> HttpRequestTool {let tool = HttpRequestTool::new(gate,@@ -64,23 +89,54 @@ pub fn http_request_tool(http_limits(),);#[cfg(feature = "web3")]- let tool = tool.with_payment_hook(Arc::new(x402::X402PaymentHook));+ let tool = tool.with_payment_hook(Arc::new(x402::X402PaymentHook::new(chat)));+ #[cfg(not(feature = "web3"))]+ let _ = chat;tool}+/// `http_request` for chat turns: built for each call around that call's chat,+/// so its egress disclosures and x402 quotes reach (and belong to) that chat.+pub fn routed_http_request_tool(+ policy: Arc<SecurityPolicy>,+ allowed_domains: Vec<String>,+ max_response_size: usize,+ timeout_secs: u64,+) -> PerCallTool<HttpRequestTool> {+ PerCallTool::new(move |chat| {+ http_request_tool_for(+ Arc::new(RoutedGate::new(Arc::clone(&policy), chat)),+ chat,+ allowed_domains.clone(),+ max_response_size,+ timeout_secs,+ )+ })+}+/// Dedicated x402 agent entry point backed by the same host HTTP policy and-/// the module payment hook used by `http_request`.+/// the module payment hook used by `http_request`, built for each call around+/// that call's chat.#[cfg(feature = "web3")]-pub fn x402_request_tool(- gate: Arc<dyn NetGate>,+pub(crate) fn x402_request_tool(+ policy: Arc<SecurityPolicy>,allowed_domains: Vec<String>,max_response_size: usize,timeout_secs: u64,-) -> impl Tool {- X402RequestTool {- gate: Arc::clone(&gate),- inner: http_request_tool(gate, allowed_domains, max_response_size, timeout_secs),- }+) -> PerCallTool<impl Tool> {+ PerCallTool::new(move |chat| {+ let gate: Arc<dyn NetGate> = Arc::new(RoutedGate::new(Arc::clone(&policy), chat));+ X402RequestTool {+ gate: Arc::clone(&gate),+ inner: http_request_tool_for(+ gate,+ chat,+ allowed_domains.clone(),+ max_response_size,+ timeout_secs,+ ),+ }+ })}#[cfg(feature = "web3")]@@ -120,6 +176,24 @@ impl Tool for X402RequestTool {}}+/// `web_fetch` for chat turns: built for each call around that call's chat, so+/// its egress disclosure reaches that chat.+pub fn routed_web_fetch_tool(+ policy: Arc<SecurityPolicy>,+ allowed_domains: Vec<String>,+ max_bytes: Option<usize>,+ timeout_secs: Option<u64>,+) -> PerCallTool<WebFetchTool> {+ PerCallTool::new(move |chat| {+ web_fetch_tool(+ Arc::new(RoutedGate::new(Arc::clone(&policy), chat)),+ allowed_domains.clone(),+ max_bytes,+ timeout_secs,+ )+ })+}+/// `web_fetch`, converting HTML through TinyJuice and opting into TinyJuice's/// optional `summary_focus` argument.pub fn web_fetch_tool(@@ -147,6 +221,7 @@ mod x402 {use async_trait::async_trait;use tinytools_std::network::{PaymentAttempt, PaymentHook};+ use super::ApprovalChatContext;use crate::modules::x402_service;/// `Err("COMPONENT_DISABLED:wallet")` when `[components] wallet` is off:@@ -163,8 +238,21 @@ mod x402 {))}+ /// The 402 handler for one `http_request` call. It owns the call's chat+ /// routing: `PaymentHook::pay` takes no run context, so the quote owner is+ /// held here and the hook is built per call.#[derive(Debug)]- pub(super) struct X402PaymentHook;+ pub(super) struct X402PaymentHook {+ chat: Option<ApprovalChatContext>,+ }++ impl X402PaymentHook {+ pub(super) fn new(chat: Option<&ApprovalChatContext>) -> Self {+ Self {+ chat: chat.cloned(),+ }+ }+ }#[async_trait]impl PaymentHook for X402PaymentHook {@@ -184,12 +272,13 @@ mod x402 {.await.map_err(|error| format!("x402 payment failed: {error}"))?;declined_when_wallet_off(&config)?;- let owner = crate::security::approval::APPROVAL_CHAT_CONTEXT- .try_with(|context| tinywallet_bus::wire::QuoteOwner {+ let owner = self+ .chat+ .as_ref()+ .map(|context| tinywallet_bus::wire::QuoteOwner {thread_id: context.thread_id.clone(),client_id: context.client_id.clone(),- })- .ok();+ });let (service, payment) =x402_service::prepare_payment(&config, url.to_owned(), challenge.to_owned(), owner).awaitdiff --git a/crates/openhuman-core/src/tools/impl/network/mod.rs b/crates/openhuman-core/src/tools/impl/network/mod.rsindex 45f84ef78e..d9a52507d1 100644--- a/crates/openhuman-core/src/tools/impl/network/mod.rs+++ b/crates/openhuman-core/src/tools/impl/network/mod.rs@@ -23,7 +23,7 @@ pub use gitbooks::{GitbooksGetPageTool, GitbooksSearchTool};pub use gmail_unsubscribe::GmailUnsubscribeTool;#[cfg(feature = "web3")]pub(crate) use host::x402_request_tool;-pub use host::{http_request_tool, web_fetch_tool};+pub use host::{http_request_tool, routed_http_request_tool, routed_web_fetch_tool, web_fetch_tool};#[cfg(feature = "mcp")]pub use mcp::{mcp_call_tool, McpListServersTool, McpListToolsTool};#[cfg(feature = "mcp")]diff --git a/crates/openhuman-core/src/tools/ops.rs b/crates/openhuman-core/src/tools/ops.rsindex c1aaa36751..9998e42101 100644--- a/crates/openhuman-core/src/tools/ops.rs+++ b/crates/openhuman-core/src/tools/ops.rs@@ -304,7 +304,7 @@ pub fn all_tools_with_runtime(// + `security` still gate which hosts are reachable; there is no// enable flag because every session needs basic HTTP as a baseline// capability.- tools.push(Box::new(http_request_tool(+ tools.push(Box::new(routed_http_request_tool(security.clone(),http_config.allowed_domains.clone(),http_config.max_response_size,@@ -327,7 +327,7 @@ pub fn all_tools_with_runtime(// GET-and-read primitive that reuses the same allowed-domains gate// as `http_request`. Use this for docs/READMEs; reach for// `http_request` only when you need richer HTTP semantics.- tools.push(Box::new(web_fetch_tool(+ tools.push(Box::new(routed_web_fetch_tool(security.clone(),http_config.allowed_domains.clone(),Some(http_config.max_response_size),@@ -337,14 +337,25 @@ pub fn all_tools_with_runtime(// curl — always registered. Shares `http_request.allowed_domains`,// adds streaming-to-disk with a hard byte ceiling. Writes land// under `<workspace>/<curl.dest_subdir>`.- tools.push(Box::new(CurlTool::new(- security.clone(),- http_config.allowed_domains.clone(),- action_dir.to_path_buf(),- root_config.curl.dest_subdir.clone(),- root_config.curl.max_download_bytes,- root_config.curl.timeout_secs,- )));+ tools.push(Box::new(PerCallTool::new({+ let security = security.clone();+ let allowed_domains = http_config.allowed_domains.clone();+ let action_dir = action_dir.to_path_buf();+ let dest_subdir = root_config.curl.dest_subdir.clone();+ let max_download_bytes = root_config.curl.max_download_bytes;+ let timeout_secs = root_config.curl.timeout_secs;+ // Built per call so the disclosure reaches that call's chat.+ move |chat| {+ CurlTool::new(+ Arc::new(RoutedGate::new(security.clone(), chat)),+ allowed_domains.clone(),+ action_dir.clone(),+ dest_subdir.clone(),+ max_download_bytes,+ timeout_secs,+ )+ }+ })));// gitbooks — answers questions about OpenHuman by calling the// GitBook MCP server. Two tools mirroring the upstream MCP tools.