Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(web3): add wallet and module tools to web3 service

Steven Enamakel8623653ca0e4
diff --git a/crates/openhuman-core/src/modules/web3_service.rs b/crates/openhuman-core/src/modules/web3_service.rs
index 52ff8c922c..452496055f 100644
--- a/crates/openhuman-core/src/modules/web3_service.rs
+++ b/crates/openhuman-core/src/modules/web3_service.rs
@@ -95,13 +95,16 @@ async fn ensure_service(
Ok(())
}
-fn owner() -> Option<QuoteOwner> {
- crate::security::approval::APPROVAL_CHAT_CONTEXT
- .try_with(|context| QuoteOwner {
- thread_id: context.thread_id.clone(),
- client_id: context.client_id.clone(),
- })
- .ok()
+/// The quote owner of a turn whose chat routing is `chat`: quotes are bound to
+/// the thread and client that prepared them, so another chat cannot execute
+/// them. `None` outside a chat turn.
+pub(crate) fn owner_of(
+ chat: Option<&crate::security::approval::ApprovalChatContext>,
+) -> Option<QuoteOwner> {
+ chat.map(|context| QuoteOwner {
+ thread_id: context.thread_id.clone(),
+ client_id: context.client_id.clone(),
+ })
}
/// Close the active module service on sign-out. The mutex joins any in-flight
@@ -172,6 +175,7 @@ pub(crate) struct ExecuteParams {
/// Prepare one implementation-owned Web3 quote.
pub(crate) async fn quote(
config: &Config,
+ owner: Option<QuoteOwner>,
member: &'static str,
params: serde_json::Value,
) -> Result<Web3QuoteResponse, wallet::WalletCallError> {
@@ -188,7 +192,7 @@ pub(crate) async fn quote(
member,
Web3QuoteRequest {
service: service_handle,
- owner: owner(),
+ owner,
params,
},
)
@@ -211,6 +215,7 @@ pub(crate) async fn routes(config: &Config) -> Result<serde_json::Value, wallet:
/// Execute one explicitly confirmed quote using its module-declared signer chain.
pub(crate) async fn execute(
config: &Config,
+ owner: Option<QuoteOwner>,
quote_id: String,
confirmed: bool,
) -> Result<serde_json::Value, wallet::WalletCallError> {
@@ -250,7 +255,7 @@ pub(crate) async fn execute(
.value;
let mut request = Web3ExecuteRequest {
service: service_handle,
- owner: owner(),
+ owner,
quote_id: quote_id.clone(),
confirmed,
secret: tinywallet_bus::wire::SecretMaterial {
diff --git a/crates/openhuman-core/src/tools/ops.rs b/crates/openhuman-core/src/tools/ops.rs
index 97a19bfe3a..e401d02a00 100644
--- a/crates/openhuman-core/src/tools/ops.rs
+++ b/crates/openhuman-core/src/tools/ops.rs
@@ -14,7 +14,7 @@ use tinytools_std::filesystem::{
ApplyPatchTool, CsvExportTool, EditFileTool, FileReadTool, FileWriteTool, GitOperationsTool,
GlobTool, GrepTool, ImageInfoTool, ListFilesTool, ReadDiffTool, RunLinterTool, RunTestsTool,
};
-use tinytools_std::network::{CurlTool, PushoverTool};
+use tinytools_std::network::PushoverTool;
/// Create the default tool registry
pub fn default_tools(security: Arc<SecurityPolicy>) -> Vec<Box<dyn Tool>> {
diff --git a/crates/openhuman-core/src/web3/module_tools.rs b/crates/openhuman-core/src/web3/module_tools.rs
index 65010c8f71..d810d63b74 100644
--- a/crates/openhuman-core/src/web3/module_tools.rs
+++ b/crates/openhuman-core/src/web3/module_tools.rs
@@ -35,6 +35,36 @@ impl Tool for Web3ModuleTool {
}
async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {
+ self.run(args, None).await
+ }
+
+ async fn execute_with_context(
+ &self,
+ args: Value,
+ _options: tinytools::ToolCallOptions,
+ context: Option<&dyn tinytools::ToolRunContext>,
+ ) -> anyhow::Result<ToolResult> {
+ let approval = crate::agent::tinyagents::host::run_context::approval_for_tool(context);
+ self.run(args, approval.chat.as_ref()).await
+ }
+
+ async fn execute_with_options(
+ &self,
+ args: Value,
+ _options: ToolCallOptions,
+ ) -> anyhow::Result<ToolResult> {
+ self.execute(args).await
+ }
+}
+
+impl Web3ModuleTool {
+ /// Runs the tool for a turn whose approval context is `chat`.
+ pub(crate) async fn run(
+ &self,
+ args: Value,
+ chat: Option<&crate::security::approval::ApprovalChatContext>,
+ ) -> anyhow::Result<ToolResult> {
+ let owner = crate::modules::web3_service::owner_of(chat);
let config = match crate::config::rpc::load_config_with_timeout().await {
Ok(config) => config,
Err(error) => return Ok(ToolResult::error(error)),
@@ -42,6 +72,7 @@ impl Tool for Web3ModuleTool {
let result: anyhow::Result<Value> = match self.name() {
"web3_swap_quote" => crate::modules::web3_service::quote(
&config,
+ owner.clone(),
tinywallet_bus::names::methods::WEB3_SWAP_QUOTE,
args,
)
@@ -50,6 +81,7 @@ impl Tool for Web3ModuleTool {
.and_then(|value| serde_json::to_value(value).map_err(Into::into)),
"web3_bridge_quote" => crate::modules::web3_service::quote(
&config,
+ owner.clone(),
tinywallet_bus::names::methods::WEB3_BRIDGE_QUOTE,
args,
)
@@ -58,6 +90,7 @@ impl Tool for Web3ModuleTool {
.and_then(|value| serde_json::to_value(value).map_err(Into::into)),
"web3_dapp_call" => crate::modules::web3_service::quote(
&config,
+ owner.clone(),
tinywallet_bus::names::methods::WEB3_DAPP_QUOTE,
args,
)
@@ -71,6 +104,7 @@ impl Tool for Web3ModuleTool {
match serde_json::from_value::<crate::modules::web3_service::ExecuteParams>(args) {
Ok(params) => crate::modules::web3_service::execute(
&config,
+ owner,
params.quote_id,
params.confirmed,
)
@@ -89,12 +123,4 @@ impl Tool for Web3ModuleTool {
Err(error) => Ok(ToolResult::error(error.to_string())),
}
}
-
- async fn execute_with_options(
- &self,
- args: Value,
- _options: ToolCallOptions,
- ) -> anyhow::Result<ToolResult> {
- self.execute(args).await
- }
}
diff --git a/crates/openhuman-core/src/web3/wallet/tools.rs b/crates/openhuman-core/src/web3/wallet/tools.rs
index 4f8b4b5d26..163af396f4 100644
--- a/crates/openhuman-core/src/web3/wallet/tools.rs
+++ b/crates/openhuman-core/src/web3/wallet/tools.rs
@@ -56,6 +56,27 @@ impl Tool for WalletModuleTool {
}
async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {
+ self.run(args, None).await
+ }
+
+ async fn execute_with_context(
+ &self,
+ args: Value,
+ _options: tinytools::ToolCallOptions,
+ context: Option<&dyn tinytools::ToolRunContext>,
+ ) -> anyhow::Result<ToolResult> {
+ let approval = crate::agent::tinyagents::host::run_context::approval_for_tool(context);
+ self.run(args, approval.chat.as_ref()).await
+ }
+}
+
+impl WalletModuleTool {
+ /// Runs the tool for a turn whose approval context is `chat`.
+ pub(crate) async fn run(
+ &self,
+ args: Value,
+ chat: Option<&crate::security::approval::ApprovalChatContext>,
+ ) -> anyhow::Result<ToolResult> {
let result = match self.name() {
"wallet_status" => outcome_value(crate::web3::wallet::status().await),
"wallet_chain_status" => outcome_value(crate::web3::wallet::chain_status().await),