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
fix(network): decline x402 payments when the wallet component is off
Steven Enamakel5b02d6e93609
diff --git a/crates/openhuman-core/src/modules/ops_components_tests.rs b/crates/openhuman-core/src/modules/ops_components_tests.rsindex 7a209f53c8..0e0a359513 100644--- a/crates/openhuman-core/src/modules/ops_components_tests.rs+++ b/crates/openhuman-core/src/modules/ops_components_tests.rs@@ -44,3 +44,14 @@ fn disabled_lib_stems_cover_only_disabled_modules() {assert!(!stems.contains(&mcp.to_string()));assert!(disabled_lib_stems(&Config::default()).is_empty());}++#[tokio::test]+async fn a_disabled_wallet_never_loads_the_tinywallet_module() {+ let config = config_without("wallet");+ let err = ensure_loaded_within(&config, "tinywallet", None)+ .await+ .unwrap_err();+ assert_eq!(err, LoadError::Disabled("wallet"));+ assert_eq!(err.into_message(), "COMPONENT_DISABLED:wallet");+ assert_eq!(state_of("tinywallet"), ModuleState::Available);+}diff --git a/crates/openhuman-core/src/tools/impl/network/host.rs b/crates/openhuman-core/src/tools/impl/network/host.rsindex 9408f0bece..89e58d32eb 100644--- a/crates/openhuman-core/src/tools/impl/network/host.rs+++ b/crates/openhuman-core/src/tools/impl/network/host.rs@@ -149,6 +149,22 @@ mod x402 {use crate::modules::x402_service;+ /// `Err("COMPONENT_DISABLED:wallet")` when `[components] wallet` is off:+ /// the hook declines before any quote, signing or module load. The 402+ /// response then surfaces to the caller unpaid.+ pub(super) fn declined_when_wallet_off(+ config: &crate::config::Config,+ ) -> Result<(), String> {+ if config.components.wallet {+ return Ok(());+ }+ log::debug!("[tool.http_request] x402 payment declined: component 'wallet' disabled");+ Err(format!(+ "{}:wallet",+ crate::core::runtime::COMPONENT_DISABLED+ ))+ }+#[derive(Debug)]pub(super) struct X402PaymentHook;@@ -169,6 +185,9 @@ mod x402 {let config = crate::config::rpc::load_config_with_timeout().await.map_err(|error| format!("x402 payment failed: {error}"))?;+ if let Err(refused) = declined_when_wallet_off(&config) {+ return Err(refused);+ }let owner = crate::security::approval::APPROVAL_CHAT_CONTEXT.try_with(|context| tinywallet_bus::wire::QuoteOwner {thread_id: context.thread_id.clone(),diff --git a/crates/openhuman-core/src/tools/impl/network/host_tests.rs b/crates/openhuman-core/src/tools/impl/network/host_tests.rsindex 6b7f25a3b0..c19fa4b5c3 100644--- a/crates/openhuman-core/src/tools/impl/network/host_tests.rs+++ b/crates/openhuman-core/src/tools/impl/network/host_tests.rs@@ -103,3 +103,18 @@ async fn tinyjuice_detects_and_converts_html() {.unwrap().contains("hi"));}++#[cfg(feature = "web3")]+#[test]+fn x402_hook_declines_payment_when_wallet_component_is_off() {+ let mut config = crate::config::Config::default();+ assert!(x402::declined_when_wallet_off(&config).is_ok());+ assert!(config.components.set("wallet", false));+ assert_eq!(+ x402::declined_when_wallet_off(&config).unwrap_err(),+ "COMPONENT_DISABLED:wallet"+ );+ // Re-enabling needs no restart of the hook: it reads the config per call.+ assert!(config.components.set("wallet", true));+ assert!(x402::declined_when_wallet_off(&config).is_ok());+}