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(browser): add computer-use actions to browser tool
Steven Enamakel783688b98a93
diff --git a/crates/openhuman-core/src/tools/impl/browser/browser.rs b/crates/openhuman-core/src/tools/impl/browser/browser.rsindex 2f6ec71c46..13575fcfc2 100644--- a/crates/openhuman-core/src/tools/impl/browser/browser.rs+++ b/crates/openhuman-core/src/tools/impl/browser/browser.rs@@ -13,7 +13,6 @@ use crate::agent::turn_origin::AgentTurnOrigin;use crate::modules::browser::BrowserClient;use crate::security::approval::{ApprovalGate, GateOutcome};use crate::security::SecurityPolicy;-use crate::tools::schema_cache::static_schema;use async_trait::async_trait;use pending::{approval_target, needs_host_confirmation, Pending};use serde_json::{json, Value};@@ -31,7 +30,7 @@ use std::{time::Instant,};use task_actions::{- approve_task_action, host_hint, parse_action, required, task_inputs, task_outcome,+ approve_task_action, direct_action, host_hint, required, task_inputs, task_outcome,};use tinycomputer_bus::agent::{ContinueTaskRequest, TaskId, TaskStatus, TaskView};use tinycomputer_bus::browser::{@@ -489,7 +488,7 @@ impl BrowserTool {Ok(serde_json::to_value(d)?)}_ => {- let action = parse_action(args)?;+ let action = direct_action(args)?;approve_browser_action(&self.client, &id, &action, false, origin).await?;Ok(serde_json::to_value(self.client.perform(&id, action).await?,@@ -532,7 +531,7 @@ impl Tool for BrowserTool {)}fn parameters_schema(&self) -> Value {- static_schema!(include_str!("parameters/browser.json"))+ tinycomputer_bus::browser::tool::parameters_schema()}/// Direct consequential actions park on the approval gate *inside*/// `execute` (`intercept_forced`), which waits up to the gate's TTL. The@@ -588,9 +587,6 @@ impl Tool for BrowserTool {#[path = "browser_computer_tests.rs"]mod tests;-#[cfg(test)]-#[path = "browser_schema_tests.rs"]-mod schema_tests;#[cfg(test)]#[path = "browser_task_outcome_tests.rs"]diff --git a/crates/openhuman-core/src/tools/impl/browser/browser_computer_tests.rs b/crates/openhuman-core/src/tools/impl/browser/browser_computer_tests.rsindex 21f74813d0..a2ad6aac3f 100644--- a/crates/openhuman-core/src/tools/impl/browser/browser_computer_tests.rs+++ b/crates/openhuman-core/src/tools/impl/browser/browser_computer_tests.rs@@ -87,46 +87,29 @@ fn approval_describes_selector_and_locator_targets() {}#[test]-fn direct_actions_use_typed_targets_and_reject_unbounded_inputs() {+fn direct_actions_decode_through_the_bus_tool_args() {assert!(- matches!(parse_action(&json!({"action":"click","selector":"@e1"})).unwrap(), Action::Click { target: Target::Ref { value }, .. } if value == "e1")+ matches!(direct_action(&json!({"action":"click","selector":"@e1"})).unwrap(), Action::Click { target: Target::Ref { value }, .. } if value == "e1"));- assert!(parse_action(&json!({"action":"click"})).is_err());- assert!(parse_action(&json!({"action":"scroll","direction":"diagonal"})).is_err());- assert!(parse_action(&json!({"action":"arbitrary_script"})).is_err());+ assert!(direct_action(&json!({"action":"click"})).is_err());+ assert!(direct_action(&json!({"action":"scroll","direction":"diagonal"})).is_err());+ assert!(direct_action(&json!({"action":"arbitrary_script"})).is_err());+ assert!(direct_action(&json!({"action":"find","by":"text","value":"Save","find_action":"text"})).is_ok());}#[test]-fn browser_action_parser_covers_supported_direct_and_find_actions() {- for args in [- json!({"action":"fill","selector":"#email","value":"x"}),- json!({"action":"type","text":"hello"}),- json!({"action":"get_text","selector":"#title"}),- json!({"action":"is_visible","selector":"#title"}),- json!({"action":"hover","selector":"#title"}),- json!({"action":"press","key":"Enter"}),- json!({"action":"scroll","direction":"left","pixels":32}),- json!({"action":"wait","text":"Ready","ms":5,"timeout_ms":25}),- ] {- assert!(parse_action(&args).is_ok(), "{args}");- }-- for find_action in ["click", "fill", "text", "hover"] {- let mut args = json!({- "action":"find", "by":"role", "value":"button", "find_action":find_action- });- if find_action == "fill" {- args["fill_value"] = json!("hello");- }- assert!(parse_action(&args).is_ok(), "{find_action}");- }-- assert!(parse_action(&json!({"action":"scroll","direction":"up","pixels":u64::MAX})).is_ok());- assert!(parse_action(- &json!({"action":"find","by":"text","value":"Save","find_action":"text"})- )- .is_ok());- assert!(parse_action(&json!({"action":"wait","selector":"#ready"})).is_ok());+fn model_visible_browser_schema_is_the_bus_schema() {+ let tool = BrowserTool::new(+ std::sync::Arc::new(crate::security::SecurityPolicy::default()),+ std::sync::Arc::new(BrowserClient::new(std::sync::Arc::new(+ crate::config::Config::default(),+ ))),+ 3,+ );+ let schema = tinytools::Tool::parameters_schema(&tool);+ assert_eq!(schema, tinycomputer_bus::browser::tool::parameters_schema());+ assert_eq!(schema["required"], json!(["action"]));+ assert_eq!(schema["properties"]["action"]["enum"].as_array().unwrap().len(), 22);}#[test]diff --git a/crates/openhuman-core/src/tools/impl/browser/browser_schema_tests.rs b/crates/openhuman-core/src/tools/impl/browser/browser_schema_tests.rsdeleted file mode 100644index a8807ddceb..0000000000--- a/crates/openhuman-core/src/tools/impl/browser/browser_schema_tests.rs+++ /dev/null@@ -1,24 +0,0 @@-use super::*;-use serde_json::json;--fn expected_browser() -> serde_json::Value {- json!({"type":"object","properties":{- "action":{"type":"string","enum":["open","snapshot","read_page","click","fill","type","get_text","get_title","get_url","wait","press","hover","scroll","is_visible","find","task","task_continue","task_cancel","confirm_pending","list_downloads","wait_download","close"]},- "url":{"type":"string","description":"Starting HTTPS URL for open or an optional starting URL for task"},"selector":{"type":"string"},"value":{"type":"string"},"text":{"type":"string"},"key":{"type":"string"},"direction":{"type":"string"},"pixels":{"type":"integer"},"ms":{"type":"integer"},"timeout_ms":{"type":"integer"},"interactive_only":{"type":"boolean"},"compact":{"type":"boolean"},"depth":{"type":"integer"},"by":{"type":"string"},"find_action":{"type":"string"},"fill_value":{"type":"string"},"goal":{"type":"string"},"inputs":{"type":"object","additionalProperties":{"type":"string"}},"task_id":{"type":"string","description":"Task id returned by task, for task_continue and task_cancel"},"flow":{"type":"object","description":"Optional TinyComputer flow ({app, vars, steps}) to run instead of planning one from goal, e.g. a plan saved from an earlier successful run"},"answer":{"type":"string","description":"Free-text answer for a paused task; done after a needs_human pause"},"token":{"type":"string","description":"Token returned with the exact pending action"}- },"required":["action"]})-}--#[test]-fn browser_static_schema_matches_json_literal() {- let tool = BrowserTool::new(- std::sync::Arc::new(crate::security::SecurityPolicy::default()),- std::sync::Arc::new(BrowserClient::new(std::sync::Arc::new(- crate::config::Config::default(),- ))),- 3,- );- assert_eq!(- tinytools::Tool::parameters_schema(&tool),- expected_browser()- );-}diff --git a/crates/openhuman-core/src/tools/impl/browser/browser_task_actions.rs b/crates/openhuman-core/src/tools/impl/browser/browser_task_actions.rsindex 6ce3992b5c..fd848a1256 100644--- a/crates/openhuman-core/src/tools/impl/browser/browser_task_actions.rs+++ b/crates/openhuman-core/src/tools/impl/browser/browser_task_actions.rs@@ -6,7 +6,8 @@ use serde_json::{json, Value};use sha2::{Digest, Sha256};use std::collections::BTreeMap;use tinycomputer_bus::agent::{TaskStatus, TaskView};-use tinycomputer_bus::browser::{Action, LocateBy, Locator, ScrollDirection, Target, WaitState};+use tinycomputer_bus::browser::tool::ToolArgs;+use tinycomputer_bus::browser::Action;/// What the host adds to a task report the agent cannot act on alone: a/// task that failed because Chrome was not found, or would not start from@@ -128,70 +129,11 @@ pub(super) fn required<'a>(args: &'a Value, key: &str) -> anyhow::Result<&'a str.ok_or_else(|| anyhow::anyhow!("Missing '{key}' parameter"))}-pub(super) fn parse_action(args: &Value) -> anyhow::Result<Action> {- let target = || required(args, "selector").map(Target::parse);- Ok(match required(args, "action")? {- "click" => Action::Click {- target: target()?,- new_tab: false,- },- "fill" => Action::Fill {- target: target()?,- value: required(args, "value")?.into(),- },- "type" => Action::Type {- target: args["selector"].as_str().map(Target::parse),- text: required(args, "text")?.into(),- delay_ms: None,- },- "get_text" => Action::GetText { target: target()? },- "is_visible" => Action::IsVisible { target: target()? },- "hover" => Action::Hover { target: target()? },- "press" => Action::Press {- key: required(args, "key")?.into(),- },- "scroll" => Action::Scroll {- direction: match required(args, "direction")? {- "up" => ScrollDirection::Up,- "down" => ScrollDirection::Down,- "left" => ScrollDirection::Left,- "right" => ScrollDirection::Right,- x => anyhow::bail!("Invalid direction: {x}"),- },- pixels: args["pixels"].as_u64().and_then(|v| u32::try_from(v).ok()),- target: None,- },- "wait" => Action::WaitFor {- target: args["selector"].as_str().map(Target::parse),- text: args["text"].as_str().map(str::to_owned),- state: WaitState::Visible,- ms: args["ms"].as_u64(),- timeout_ms: args["timeout_ms"].as_u64(),- },- "find" => {- let by = match required(args, "by")? {- "role" => LocateBy::Role,- "text" => LocateBy::Text,- "label" => LocateBy::Label,- "placeholder" => LocateBy::Placeholder,- "testid" => LocateBy::TestId,- x => anyhow::bail!("Invalid locator: {x}"),- };- let target = Target::locator(Locator::new(by, required(args, "value")?));- match required(args, "find_action")? {- "click" => Action::Click {- target,- new_tab: false,- },- "fill" => Action::Fill {- target,- value: required(args, "fill_value")?.into(),- },- "text" => Action::GetText { target },- "hover" => Action::Hover { target },- x => anyhow::bail!("Invalid find action: {x}"),- }- }- x => anyhow::bail!("Unsupported browser action: {x}"),- })+/// Decodes the model's arguments into the contract's [`ToolArgs`] and maps+/// them to the module's page [`Action`]; the schema and mapping live in+/// `tinycomputer_bus::browser::tool`.+pub(super) fn direct_action(args: &Value) -> anyhow::Result<Action> {+ let parsed: ToolArgs = serde_json::from_value(args.clone())+ .map_err(|e| anyhow::anyhow!("Invalid browser arguments: {e}"))?;+ Ok(parsed.to_action()?)}diff --git a/crates/openhuman-core/src/tools/impl/browser/parameters/browser.json b/crates/openhuman-core/src/tools/impl/browser/parameters/browser.jsondeleted file mode 100644index e95b31edc9..0000000000--- a/crates/openhuman-core/src/tools/impl/browser/parameters/browser.json+++ /dev/null@@ -1,106 +0,0 @@-{- "type": "object",- "properties": {- "action": {- "type": "string",- "enum": [- "open",- "snapshot",- "read_page",- "click",- "fill",- "type",- "get_text",- "get_title",- "get_url",- "wait",- "press",- "hover",- "scroll",- "is_visible",- "find",- "task",- "task_continue",- "task_cancel",- "confirm_pending",- "list_downloads",- "wait_download",- "close"- ]- },- "url": {- "type": "string",- "description": "Starting HTTPS URL for open or an optional starting URL for task"- },- "selector": {- "type": "string"- },- "value": {- "type": "string"- },- "text": {- "type": "string"- },- "key": {- "type": "string"- },- "direction": {- "type": "string"- },- "pixels": {- "type": "integer"- },- "ms": {- "type": "integer"- },- "timeout_ms": {- "type": "integer"- },- "interactive_only": {- "type": "boolean"- },- "compact": {- "type": "boolean"- },- "depth": {- "type": "integer"- },- "by": {- "type": "string"- },- "find_action": {- "type": "string"- },- "fill_value": {- "type": "string"- },- "goal": {- "type": "string"- },- "inputs": {- "type": "object",- "additionalProperties": {- "type": "string"- }- },- "task_id": {- "type": "string",- "description": "Task id returned by task, for task_continue and task_cancel"- },- "flow": {- "type": "object",- "description": "Optional TinyComputer flow ({app, vars, steps}) to run instead of planning one from goal, e.g. a plan saved from an earlier successful run"- },- "answer": {- "type": "string",- "description": "Free-text answer for a paused task; done after a needs_human pause"- },- "token": {- "type": "string",- "description": "Token returned with the exact pending action"- }- },- "required": [- "action"- ]-}