Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
fix(spaces): Upgrade falls back to the account app's billing page (CUA-1515) (#5128)
ddupont4b37441420ca
diff --git a/apps/cua-spaces-desktop/src/bridge/settings.ts b/apps/cua-spaces-desktop/src/bridge/settings.tsindex 49378aeac2..f78b4175af 100644--- a/apps/cua-spaces-desktop/src/bridge/settings.ts+++ b/apps/cua-spaces-desktop/src/bridge/settings.ts@@ -81,13 +81,16 @@ export function experimentsPage(model: AppModel) {}/** `settings.get`'s answer: General, Experiments, the update channel (null:- * no updater) and the global shortcut (null: none here). */+ * no updater), the global shortcut (null: none here) and the account app. */export function settingsState(model: AppModel, parts: HostParts) {return {page: encode(settingsPage(model, parts)),experiments: encode(experimentsPage(model)),updateChannel: parts.updates.updater === null ? null : parts.updates.channelWord,globalShortcut: parts.system?.globalShortcut?.() ?? null,+ // The account app (CUA_ENV, CUA_ACCOUNT_APP_URL): the page's core has no+ // environment, so Upgrade's billing fallback names this one.+ accountUrl: model.native.appAccountAppUrl(),};}diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIBridge.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIBridge.swiftindex 1ccc2a7718..e77c7b907a 100644--- a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIBridge.swift+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIBridge.swift@@ -462,6 +462,9 @@ final class WebUIBridge: NSObject, WKScriptMessageHandlerWithReply {"updateChannel": model.updates.updater == nil ? NSNull() : (model.updates.channel == .beta ? "beta" : "stable"),// ⌘⇧Space, and whether the system gave it (tried again on each read)."globalShortcut": GlobalShortcut.installed?.bridgeValue ?? NSNull(),+ // The account app (CUA_ENV, CUA_ACCOUNT_APP_URL): the page's core+ // has no environment, so Upgrade's billing fallback names this one.+ "accountUrl": appAccountAppUrl(),]}diff --git a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/WebUIHostTests.swift b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/WebUIHostTests.swiftindex 4198883ed0..1237e7e0f5 100644--- a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/WebUIHostTests.swift+++ b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/WebUIHostTests.swift@@ -310,6 +310,14 @@ struct WebUIHostTests {#expect(model.updates.channel == .beta)}+ /// The page's core has no environment: the host names the account app+ /// Upgrade's billing fallback opens (CUA_ENV, CUA_ACCOUNT_APP_URL).+ @Test func settingsNameTheAccountApp() async throws {+ let (bridge, _) = bridge()+ let s = try await bridge.handle("settings.get", [:]) as? [String: Any]+ #expect(s?["accountUrl"] as? String == appAccountAppUrl())+ }+@Test func theGlobalShortcutSaysWhetherTheSystemGaveIt() async throws {let (bridge, _) = bridge()defer { GlobalShortcut.installed = nil }diff --git a/apps/cua-spaces-web/src/bridge/README.md b/apps/cua-spaces-web/src/bridge/README.mdindex 20bd5ad512..3380f5a2a2 100644--- a/apps/cua-spaces-web/src/bridge/README.md+++ b/apps/cua-spaces-web/src/bridge/README.md@@ -203,6 +203,10 @@ speaks it as is:change calls `window.setBackgroundColor`. The host registers ⌘⇧Spaceitself; `settings.get` carries `globalShortcut: {label, registered}`, andeach read tries the registration again when the system refused it.+- `settings.get` also carries `accountUrl`, the host's account app+ (`app_account_app_url`: `CUA_ENV`, `CUA_ACCOUNT_APP_URL`). The page's wasm+ core has no environment, so the relay notice's Upgrade falls back to that+ app's billing page (`relayUsage.view {usage, accountApp}`).- Touch ID and the unlock prompt stay native.- Launch at login is the core's `launch-at-login` row. The adapter reads itfrom the page and sets it with `settings.choose {row: "launch-at-login"}`,diff --git a/apps/cua-spaces-web/src/bridge/adapters/webkit.ts b/apps/cua-spaces-web/src/bridge/adapters/webkit.tsindex 67270c38c2..d2c0c37b89 100644--- a/apps/cua-spaces-web/src/bridge/adapters/webkit.ts+++ b/apps/cua-spaces-web/src/bridge/adapters/webkit.ts@@ -292,6 +292,7 @@ export function toSettingsSnapshot(s: WkSettings, page: Pick<SettingsValues, "thkeyvaultProtection: protection.length ? protection : null,},globalShortcut: s.globalShortcut ? { label: s.globalShortcut.label, registered: s.globalShortcut.registered } : null,+ accountUrl: s.accountUrl ?? null,};}diff --git a/apps/cua-spaces-web/src/bridge/contracts/bridge-shapes.json b/apps/cua-spaces-web/src/bridge/contracts/bridge-shapes.jsonindex 303b7ffd33..678741e06d 100644--- a/apps/cua-spaces-web/src/bridge/contracts/bridge-shapes.json+++ b/apps/cua-spaces-web/src/bridge/contracts/bridge-shapes.json@@ -2284,6 +2284,12 @@"label","registered"]+ },+ "accountUrl": {+ "type": [+ "string",+ "null"+ ]}},"required": [@@ -3703,6 +3709,12 @@"label","registered"]+ },+ "accountUrl": {+ "type": [+ "string",+ "null"+ ]}},"required": [diff --git a/apps/cua-spaces-web/src/bridge/contracts/shapes.ts b/apps/cua-spaces-web/src/bridge/contracts/shapes.tsindex e6efdcc8ea..fbfc7ec076 100644--- a/apps/cua-spaces-web/src/bridge/contracts/shapes.ts+++ b/apps/cua-spaces-web/src/bridge/contracts/shapes.ts@@ -233,6 +233,7 @@ const SettingsShape = ref(}),),globalShortcut: optNull(obj<GlobalShortcut>()({ label: str, registered: bool })),+ accountUrl: optNull(str),}),);@@ -974,6 +975,7 @@ const WkSettingsShape = ref(}),updateChannel: optNull(oneOf("stable", "beta")),globalShortcut: optNull(object({ label: str, registered: bool })),+ accountUrl: optNull(str),}),);diff --git a/apps/cua-spaces-web/src/bridge/derive.ts b/apps/cua-spaces-web/src/bridge/derive.tsindex a57a9bf1ee..1f9941b3d2 100644--- a/apps/cua-spaces-web/src/bridge/derive.ts+++ b/apps/cua-spaces-web/src/bridge/derive.ts@@ -753,8 +753,9 @@ export function orderRuns<T extends SpaceAgentRun>(core: CoreClient, runs: T[]):/* ---- Relay usage ---------------------------------------------------------- *//** Settings' Relay usage row and the notice past the allowance (the core's- * `relayUsage.view`). No stand-in: without the core the page shows+ * `relayUsage.view`; Upgrade falls back to `accountApp`'s billing page, the+ * host's account app, as the page's core has no environment). No stand-in: without the core the page shows* neither, rather than words of its own. */-export function relayUsageView(core: CoreClient, usage: RelayUsage): RelayUsageView | null {- return core.tryCall<RelayUsageView | null>("relayUsage.view", { usage }) ?? null;+export function relayUsageView(core: CoreClient, usage: RelayUsage, accountApp: string | null = null): RelayUsageView | null {+ return core.tryCall<RelayUsageView | null>("relayUsage.view", accountApp ? { usage, accountApp } : { usage }) ?? null;}diff --git a/apps/cua-spaces-web/src/bridge/protocol.ts b/apps/cua-spaces-web/src/bridge/protocol.tsindex 7f77b354aa..836cbe6e7a 100644--- a/apps/cua-spaces-web/src/bridge/protocol.ts+++ b/apps/cua-spaces-web/src/bridge/protocol.ts@@ -102,6 +102,9 @@ export interface SettingsSnapshot {/** The global shortcut that brings the app to the front, as the host* registered it with the system. Absent or null: this host has none. */globalShortcut?: GlobalShortcut | null;+ /** The host's account app (`https://app.cua.ai`, or staging's), which the+ * page's core cannot resolve itself. Absent or null: the production one. */+ accountUrl?: string | null;}/** A system-wide shortcut the host registered (macOS: ⌘⇧Space). */diff --git a/apps/cua-spaces-web/src/bridge/relay-usage.ts b/apps/cua-spaces-web/src/bridge/relay-usage.tsindex b44adbe08a..43d8de0053 100644--- a/apps/cua-spaces-web/src/bridge/relay-usage.ts+++ b/apps/cua-spaces-web/src/bridge/relay-usage.ts@@ -13,6 +13,7 @@ import { useContext, useMemo, useSyncExternalStore } from "react";import { isUnsupported, type DataAdapter } from "./adapter";import { BridgeContext } from "./BridgeProvider";import { relayUsageView } from "./derive";+import { useSettings } from "./hooks";import type { RelayUsage, RelayUsageView } from "./ops/relay-usage";export type { RelayAllowanceNotice, RelayUsage, RelayUsageView } from "./ops/relay-usage";@@ -131,5 +132,6 @@ export function useRelayUsage(): RelayUsage | null {export function useRelayUsageView(): RelayUsageView | null {const usage = useRelayUsage();const core = useContext(BridgeContext)?.core;- return useMemo(() => (usage && core ? relayUsageView(core, usage) : null), [usage, core]);+ const accountApp = useSettings().data?.accountUrl ?? null;+ return useMemo(() => (usage && core ? relayUsageView(core, usage, accountApp) : null), [usage, core, accountApp]);}diff --git a/apps/cua-spaces-web/src/bridge/webkit-protocol.ts b/apps/cua-spaces-web/src/bridge/webkit-protocol.tsindex 1af35f9001..ccd28a32b8 100644--- a/apps/cua-spaces-web/src/bridge/webkit-protocol.ts+++ b/apps/cua-spaces-web/src/bridge/webkit-protocol.ts@@ -312,6 +312,8 @@ export interface WkSettings {updateChannel?: string | null;/** The global shortcut the host registered; absent or null: none. */globalShortcut?: { label: string; registered: boolean } | null;+ /** The host's account app (`app_account_app_url`); absent or null: none named. */+ accountUrl?: string | null;}/** `keyvault.*`: the core's page views, plus the overview (camelCase records). */diff --git a/apps/cua-spaces-web/src/components/shell/relay-allowance-notice.test.tsx b/apps/cua-spaces-web/src/components/shell/relay-allowance-notice.test.tsxindex 48d38dca09..2f9a891eb9 100644--- a/apps/cua-spaces-web/src/components/shell/relay-allowance-notice.test.tsx+++ b/apps/cua-spaces-web/src/components/shell/relay-allowance-notice.test.tsx@@ -24,7 +24,7 @@ beforeAll(async () => {const reached: RelayUsage = { ...demoRelayUsage(), hoursUsed: 20.2, softLimitReached: true, reasons: ["hours"] };/** The demo host answering `usage`, recording the links it opens. */-function host(usage: RelayUsage | null) {+function host(usage: RelayUsage | null, accountUrl?: string) {const demo = createDemoAdapter({ latencyMs: 0 });demo.state.relayUsage = usage;const opened: string[] = [];@@ -32,6 +32,8 @@ function host(usage: RelayUsage | null) {...demo,call: (op, args) => {if (op === "session.openExternal") opened.push((args as { url: string }).url);+ // The host names its account app (the page's core has no environment).+ if (op === "settings.get" && accountUrl) return demo.call(op, args).then((s) => ({ ...(s as object), accountUrl }) as typeof s);return demo.call(op, args);},};@@ -62,6 +64,21 @@ describe.skipIf(!wasmBuilt)("<RelayAllowanceNotice>", () => {await waitFor(() => expect(opened).toEqual(["https://cua.ai/pricing"]));});+ it("with no page from the relay, Upgrade opens the host's account app billing page", async () => {+ const staging = host({ ...reached, upgradeUrl: null }, "https://app.staging.cua.ai");+ staging.view();+ await waitFor(() => {+ fireEvent.click(screen.getByRole("button", { name: "Upgrade" }));+ expect(staging.opened).toContain("https://app.staging.cua.ai/billing");+ });+ cleanup();+ // A host that names none: the production account app.+ const prod = host({ ...reached, upgradeUrl: null });+ prod.view();+ fireEvent.click(await screen.findByRole("button", { name: "Upgrade" }));+ await waitFor(() => expect(prod.opened).toEqual(["https://app.cua.ai/billing"]));+ });+it("dismissed, it stays hidden for that month and reason, and shows again for another", async () => {const first = host(reached);first.view();diff --git a/libs/cua/crates/cua-spaces-app-core/src/dispatch.rs b/libs/cua/crates/cua-spaces-app-core/src/dispatch.rsindex 7698fa4893..16d315546c 100644--- a/libs/cua/crates/cua-spaces-app-core/src/dispatch.rs+++ b/libs/cua/crates/cua-spaces-app-core/src/dispatch.rs@@ -465,7 +465,15 @@ pub fn call_value(method: &str, args: Value) -> Result<Value, CoreError> {a.get::<Option<SpaceOs>>("hostOs")?.unwrap_or(SpaceOs::Macos),)),- "relayUsage.view" => out(relay_usage::view(&a.get("usage")?)),+ // The page's core has no environment: the host names its account app+ // (`settings.get`'s `accountUrl`), the Upgrade fallback's billing page.+ "relayUsage.view" => {+ let usage = a.get("usage")?;+ out(match a.get::<Option<String>>("accountApp")? {+ Some(app) if app.starts_with("https://") => relay_usage::view_for(&usage, &app),+ _ => relay_usage::view(&usage),+ })+ }"wizard.pickerImages" => out(wizard::picker_images()),"wizard.pickerGroups" => out(wizard::picker_groups()),"wizard.findImage" => out(wizard::find_image(&a.get::<String>("ref")?)),@@ -1105,6 +1113,31 @@ mod tests {));}+ /// The page's core has no environment: Upgrade's billing fallback is the+ /// account app the host names, else production's; only https is taken.+ #[test]+ fn relay_upgrade_falls_back_to_the_hosts_account_app() {+ let usage = json!({+ "metered": true, "plan": "free", "hoursUsed": 20.2, "hoursLimit": 20.0,+ "softLimitReached": true, "reasons": ["hours"], "upgradeUrl": null,+ });+ let upgrade = |args: Value| {+ call_value("relayUsage.view", args).unwrap()["notice"]["upgradeUrl"].clone()+ };+ assert_eq!(+ upgrade(json!({"usage": usage, "accountApp": "https://app.staging.cua.ai"})),+ json!("https://app.staging.cua.ai/billing")+ );+ assert_eq!(+ upgrade(json!({"usage": usage, "accountApp": "javascript:alert(1)"})),+ json!(format!("{}/billing", cua_home::env::account_app_url()))+ );+ assert_eq!(+ upgrade(json!({"usage": usage})),+ json!(format!("{}/billing", cua_home::env::account_app_url()))+ );+ }+/// The web asks the core whether a machine shares its desktop before it/// reads the machine's agent runs, usage or windows (calls that a/// machine that does not share its desktop refuses).diff --git a/libs/cua/crates/cua-spaces-app-core/src/relay_usage.rs b/libs/cua/crates/cua-spaces-app-core/src/relay_usage.rsindex bcb9458ebc..dacc20e7a0 100644--- a/libs/cua/crates/cua-spaces-app-core/src/relay_usage.rs+++ b/libs/cua/crates/cua-spaces-app-core/src/relay_usage.rs@@ -159,8 +159,14 @@ pub fn notice_text(u: &RelayUsage) -> String {}/// The row and the notice; none when the relay meters nothing (the apps-/// show nothing about it).+/// show nothing about it). Upgrade opens the relay's page, else the account+/// app's billing page.pub fn view(u: &RelayUsage) -> Option<RelayUsageView> {+ view_for(u, &cua_home::env::account_app_url())+}++/// [`view`] with Upgrade falling back to `account_app`'s billing page.+pub fn view_for(u: &RelayUsage, account_app: &str) -> Option<RelayUsageView> {if !u.metered {return None;}@@ -182,7 +188,9 @@ pub fn view(u: &RelayUsage) -> Option<RelayUsageView> {notice: u.soft_limit_reached.then(|| RelayAllowanceNotice {text: notice_text(u),upgrade: UPGRADE.into(),- upgrade_url: checked(u.clone()).upgrade_url,+ upgrade_url: checked(u.clone())+ .upgrade_url+ .or_else(|| Some(format!("{}/billing", account_app.trim_end_matches('/')))),dismiss: DISMISS.into(),dismiss_key: dismiss_key(u),}),@@ -283,6 +291,29 @@ mod tests {);}+ #[test]+ fn upgrade_falls_back_to_the_account_app_billing_page() {+ let mut u = free();+ u.soft_limit_reached = true;+ u.reasons = vec!["hours".into()];+ // The relay's page wins.+ let n = view_for(&u, "https://app.staging.cua.ai")+ .unwrap()+ .notice+ .unwrap();+ assert_eq!(n.upgrade_url.as_deref(), Some("https://cua.ai/pricing"));+ // None from the relay: the account app's billing page.+ u.upgrade_url = None;+ let n = view_for(&u, "https://app.staging.cua.ai/")+ .unwrap()+ .notice+ .unwrap();+ assert_eq!(+ n.upgrade_url.as_deref(),+ Some("https://app.staging.cua.ai/billing")+ );+ }+#[test]fn only_https_upgrade_links_are_kept() {for bad in ["http://cua.ai/pricing", "javascript:alert(1)", ""] {@@ -292,7 +323,17 @@ mod tests {..free()};assert_eq!(checked(u.clone()).upgrade_url, None, "{bad}");- assert_eq!(view(&u).unwrap().notice.unwrap().upgrade_url, None);+ // A link that is not https is dropped; Upgrade opens the+ // account app's billing page instead.+ assert_eq!(+ view_for(&u, "https://app.cua.ai")+ .unwrap()+ .notice+ .unwrap()+ .upgrade_url+ .as_deref(),+ Some("https://app.cua.ai/billing")+ );}}