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(spaces-app): host setup follows CUA_ENV for the relay (CUA-1610) (#5241)

Francesco Bonacci601963fc0958
diff --git a/libs/cua/crates/cua-spaces-app-core/parity/golden/main-window.json b/libs/cua/crates/cua-spaces-app-core/parity/golden/main-window.json
index 9625f4d70f..e9f48406a3 100644
--- a/libs/cua/crates/cua-spaces-app-core/parity/golden/main-window.json
+++ b/libs/cua/crates/cua-spaces-app-core/parity/golden/main-window.json
@@ -325,7 +325,7 @@
"allow: Share with (optional) [Teammates’ emails] = "
],
"lede": "You and the people you share with can see and use this computer’s screen from other devices. Cua connects them for you, with no network setup. Signed in as [email protected].",
- "request": "mode=relay relay=https://relay.cua.ai direct=- name=- allow=-",
+ "request": "mode=relay relay=- direct=- name=- allow=-",
"title": "Set up this computer"
},
"hostForm": "initial"
@@ -343,7 +343,7 @@
"allow: Share with (optional) [Teammates’ emails] = "
],
"lede": "You and the people you share with can see and use this computer’s screen from other devices. Cua connects them for you, with no network setup. Signed in as [email protected].",
- "request": "mode=relay relay=https://relay.cua.ai direct=- name=Studio allow=-",
+ "request": "mode=relay relay=- direct=- name=Studio allow=-",
"title": "Set up this computer"
},
"hostForm": "set-name"
@@ -361,7 +361,7 @@
"allow: Share with (optional) [Teammates’ emails] = [email protected], [email protected]"
],
"lede": "You and the people you share with can see and use this computer’s screen from other devices. Cua connects them for you, with no network setup. Signed in as [email protected].",
- "request": "mode=relay relay=https://relay.cua.ai direct=- name=Studio [email protected],[email protected]",
+ "request": "mode=relay relay=- direct=- name=Studio [email protected],[email protected]",
"title": "Set up this computer"
},
"hostForm": "set-allow"
@@ -371,17 +371,17 @@
"advanced": "Advanced (open)",
"busy": false,
"buttons": "Back / Turn on remote access",
- "canSubmit": true,
+ "canSubmit": false,
"error": null,
"fields": [
"name: Name [How it shows on your other devices] = Studio ",
"profile: Use it to [-] = desktop",
"allow: Share with (optional) [Teammates’ emails] = [email protected], [email protected]",
"direct: Direct connection = off (advanced)",
- "relay: Relay server [https://relay.example.com] = https://relay.cua.ai (advanced)"
+ "relay: Relay server [https://relay.example.com] = (advanced)"
],
"lede": "For self-hosting teams: joins your own relay at the address below.",
- "request": "mode=relay relay=https://relay.cua.ai direct=- name=Studio [email protected],[email protected]",
+ "request": null,
"title": "Set up this computer"
},
"hostForm": "toggle-advanced"
diff --git a/libs/cua/crates/cua-spaces-app-core/src/host.rs b/libs/cua/crates/cua-spaces-app-core/src/host.rs
index 57a750ffc5..50555271be 100644
--- a/libs/cua/crates/cua-spaces-app-core/src/host.rs
+++ b/libs/cua/crates/cua-spaces-app-core/src/host.rs
@@ -318,7 +318,8 @@ pub const DEFAULT_RELAY_URL: &str = "https://relay.cua.ai";
/// The relay host setup joins unless the form names another:
/// `CUA_RELAY_URL`, else the relay of `CUA_ENV` ([`DEFAULT_RELAY_URL`] in
-/// production).
+/// production). For native callers: the form does not prefill it, because
+/// this core also runs in the page (wasm), which has no environment.
pub fn default_relay_url() -> String {
cua_home::env::relay_url()
}
@@ -1496,7 +1497,11 @@ impl Default for HostFormState {
advanced: false,
direct: false,
listen: DEFAULT_LISTEN.into(),
- relay_url: default_relay_url(),
+ // Empty: the form leaves the relay to the host, which resolves it
+ // from its own `CUA_RELAY_URL` / `CUA_ENV`. This core also runs
+ // in the page (wasm), which has no environment and would name
+ // the production relay under `CUA_ENV=staging` (CUA-1610).
+ relay_url: String::new(),
busy: false,
error: None,
spare: false,
@@ -1644,7 +1649,9 @@ fn form_request(s: &HostFormState) -> Result<HostSetupRequest, String> {
provide_spaces: None,
})
.and_then(|r| {
- if r.mode == "relay" && r.relay_url.is_none() {
+ // Only self-hosting (Advanced) must name its relay; otherwise an
+ // empty relay means "the host decides".
+ if r.mode == "relay" && s.advanced && r.relay_url.is_none() {
Err("relay URL needed".into())
} else {
Ok(r)
@@ -2270,6 +2277,33 @@ mod tests {
assert_eq!(connected_now(&other), 0);
}
+ #[test]
+ fn the_form_leaves_the_relay_to_the_host_unless_named() {
+ // CUA-1610: the page's core has no `CUA_ENV`; a prefilled prod relay
+ // was sent with the staging token. Empty means "the host decides".
+ let s = form_initial();
+ assert_eq!(s.relay_url, "");
+ let r = form_view(&s, None).request.expect("valid");
+ assert_eq!(r.mode, "relay");
+ assert_eq!(r.relay_url, None);
+ // Self-hosting (Advanced) must name its relay; naming one sends it.
+ let own = form_reduce(
+ &s,
+ &HostFormAction::SetProfile {
+ profile: SELF_HOSTED_PROFILE.into(),
+ },
+ );
+ assert!(form_view(&own, None).request.is_none());
+ let named = form_reduce(
+ &own,
+ &HostFormAction::SetRelayUrl {
+ url: " https://relay.example/ ".into(),
+ },
+ );
+ let r = form_view(&named, None).request.expect("valid");
+ assert_eq!(r.relay_url.as_deref(), Some("https://relay.example"));
+ }
+
#[test]
fn self_hosting_opens_only_from_its_profile() {
// Setup and first run: Cua's relay, nothing about self-hosting.