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-desktop): record space_open_viewer when a viewer opens (#5545)
Francesco Bonacciac3ae5ddb931
diff --git a/apps/cua-spaces-desktop/src/bridge/stream.ts b/apps/cua-spaces-desktop/src/bridge/stream.tsindex 224681867e..a03bf4392e 100644--- a/apps/cua-spaces-desktop/src/bridge/stream.ts+++ b/apps/cua-spaces-desktop/src/bridge/stream.ts@@ -11,7 +11,7 @@ import { createStreamOpener, StreamUnavailableError, type Fetch } from "../mediaimport type { BridgeContext } from "./context";import { Failure, type Handlers } from "./host";-export function streamMethods({ supervisor, env }: BridgeContext): Handlers {+export function streamMethods({ supervisor, env, model }: BridgeContext): Handlers {const open = createStreamOpener({cuaHome: cuaHome(env),fetch: globalThis.fetch as unknown as Fetch,@@ -30,7 +30,17 @@ export function streamMethods({ supervisor, env }: BridgeContext): Handlers {if (windowId !== undefined && (typeof windowId !== "string" || windowId === "")) throw Failure.badArgs("windowId: string");if (epoch !== undefined && (typeof epoch !== "number" || !Number.isInteger(epoch) || epoch < 0)) throw Failure.badArgs("epoch: number");try {- return await open({ spaceId, tier, windowId, epoch, activate: activate === true });+ const ticket = await open({ spaceId, tier, windowId, epoch, activate: activate === true });+ // A viewer opening is the `space_open_viewer` usage event the SwiftUI and Tauri apps record; this host+ // recorded none, so the daily report's viewer count fell to zero from 0.9.0. The grid's tiles are not viewers.+ if (tier === "full" && !epoch) {+ try {+ model.recordFeature("space_open_viewer");+ } catch {+ // Telemetry never fails a stream.+ }+ }+ return ticket;} catch (error) {if (error instanceof StreamUnavailableError) throw Failure.unsupported(error.message);throw error;diff --git a/apps/cua-spaces-desktop/test/stream-telemetry.test.ts b/apps/cua-spaces-desktop/test/stream-telemetry.test.tsnew file mode 100644index 0000000000..33927721e3--- /dev/null+++ b/apps/cua-spaces-desktop/test/stream-telemetry.test.ts@@ -0,0 +1,36 @@+// SPDX-License-Identifier: FSL-1.1-MIT+// Copyright (c) 2026 Cua AI, Inc.++import { describe, expect, it } from "vitest";+import { streamMethods } from "../src/bridge/stream";+import type { BridgeContext } from "../src/bridge/context";++function methods(recorded: string[], recordFeature = (name: string) => void recorded.push(name)) {+ const ctx = {+ supervisor: null,+ env: { CUA_SPACES_TEST_STREAM_URL: "ws://127.0.0.1:1/{id}/{tier}" },+ model: { recordFeature },+ } as unknown as BridgeContext;+ const handler = streamMethods(ctx)["spaces.openStream"]!;+ return (args: Record<string, unknown>) => Promise.resolve(handler(args, {} as never));+}++describe("spaces.openStream usage events", () => {+ it("records space_open_viewer when a full viewer opens, not for grid tiles or reconnects", async () => {+ const recorded: string[] = [];+ const open = methods(recorded);+ await open({ spaceId: "local:a", tier: "tile" });+ expect(recorded).toEqual([]);+ await open({ spaceId: "local:a", tier: "full" });+ expect(recorded).toEqual(["space_open_viewer"]);+ await open({ spaceId: "local:a", tier: "full", epoch: 2 });+ expect(recorded).toEqual(["space_open_viewer"]);+ });++ it("never fails a stream because telemetry threw", async () => {+ const open = methods([], () => {+ throw new Error("telemetry down");+ });+ await expect(open({ spaceId: "local:a", tier: "full" })).resolves.toMatchObject({ wsUrl: "ws://127.0.0.1:1/local%3Aa/full" });+ });+});