Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(cua-driver): report actual browser delivery mode in public results (#5222)

injaneity6e48c3347a2d
diff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/action_record.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/action_record.rs
index 83da49a9fb..4097d0857e 100644
--- a/libs/cua-driver/rust/crates/cua-driver-core/src/action_record.rs
+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/action_record.rs
@@ -969,7 +969,13 @@ fn actual_delivery_from_legacy(
tool_name,
"browser_click" | "browser_pointer" | "browser_type"
) {
- return Some(ActualDelivery::Background);
+ return match structured
+ .get("delivery_mode")
+ .and_then(serde_json::Value::as_str)
+ {
+ Some("foreground") => Some(ActualDelivery::Foreground),
+ _ => Some(ActualDelivery::Background),
+ };
}
if transport == ActionTransport::AgentCursorOverlay
|| args.get("scope").and_then(serde_json::Value::as_str) == Some("desktop")
@@ -1821,6 +1827,7 @@ mod tests {
"ref": "secret-ref",
"destination_ref": "secret-destination",
"input_route": input_route,
+ "delivery_mode": "foreground",
});
let structured = serde_json::json!({
"status": "ok",
diff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/browser/pointer.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/browser/pointer.rs
index fc4615a8af..bc741d9ba2 100644
--- a/libs/cua-driver/rust/crates/cua-driver-core/src/browser/pointer.rs
+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/browser/pointer.rs
@@ -549,6 +549,7 @@ impl BrowserPointerTool {
"status": "ok",
"action": request.action.as_str(),
"route": request.route.as_str(),
+ "delivery_mode": if request.foreground && request.route == InputRoute::Trusted { "foreground" } else { "background" },
"target_id": validated.record.target_id,
"tab_id": validated.tab.tab_id,
"ref": external_ref,
diff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/browser/v2_tests.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/browser/v2_tests.rs
index e21df42d35..f0dab72300 100644
--- a/libs/cua-driver/rust/crates/cua-driver-core/src/browser/v2_tests.rs
+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/browser/v2_tests.rs
@@ -2678,11 +2678,12 @@ async fn foreground_delivery_mode_accepts_window_activation_for_trusted_click()
"foreground"
);
+ let foreground_args = json!({
+ "target_id": target, "tab_id": tab, "ref": main_ref,
+ "delivery_mode": "foreground", "session": SESSION
+ });
let foreground = BrowserClickTool::new(f.engine.clone())
- .invoke(json!({
- "target_id": target, "tab_id": tab, "ref": main_ref,
- "delivery_mode": "foreground", "session": SESSION
- }))
+ .invoke(foreground_args.clone())
.await;
let s = structured(&foreground);
assert_eq!(s["status"], "ok", "{s}");
@@ -2690,6 +2691,29 @@ async fn foreground_delivery_mode_accepts_window_activation_for_trusted_click()
assert_eq!(s["delivery_mode"], "foreground");
let mouse = recorded_calls(&f, "Input.dispatchMouseEvent");
assert_eq!(mouse.len(), 2, "press and release: {mouse:?}");
+ let public = ActionExecutionRecord::from_legacy("browser_click", &foreground_args, s)
+ .expect("browser click action record")
+ .public_result()
+ .expect("public browser click result");
+ let public = serde_json::to_value(public).expect("serialize public result");
+ assert_eq!(public["delivery"]["mode"], "foreground", "{public}");
+
+ let pointer_args = json!({
+ "target_id": target, "tab_id": tab, "action": "hover", "x": 10, "y": 10,
+ "delivery_mode": "foreground", "session": SESSION
+ });
+ let pointer = BrowserPointerTool::new(f.engine.clone())
+ .invoke(pointer_args.clone())
+ .await;
+ let p = structured(&pointer);
+ assert_eq!(p["status"], "ok", "{p}");
+ assert_eq!(p["delivery_mode"], "foreground", "{p}");
+ let public = ActionExecutionRecord::from_legacy("browser_pointer", &pointer_args, p)
+ .expect("browser pointer action record")
+ .public_result()
+ .expect("public browser pointer result");
+ let public = serde_json::to_value(public).expect("serialize public result");
+ assert_eq!(public["delivery"]["mode"], "foreground", "{public}");
}
#[tokio::test]