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.

Spaces: fix Teams sharing UI gaps from the 31 Oct app sweep (CUA-3040/3041/3042) (#6287)

Francesco Bonacci3a636170bb78
diff --git a/apps/cua-spaces-web/src/bridge/thread.ts b/apps/cua-spaces-web/src/bridge/thread.ts
index 22be4789bc..5da01ef715 100644
--- a/apps/cua-spaces-web/src/bridge/thread.ts
+++ b/apps/cua-spaces-web/src/bridge/thread.ts
@@ -214,6 +214,8 @@ const liveShape = (agents: readonly LiveAgent[]) => agents.map((a) => `${a.agent
const FIRST_PAGE = 100;
const MEMBERS_POLL_MS = 5_000;
+/** The share list is read every this many member polls (15 s). */
+const SHARES_EVERY = 3;
const MAX_BACKOFF_MS = 30_000;
const message = (e: unknown) => (e instanceof Error ? e.message : String(e));
@@ -373,11 +375,18 @@ export function useSpaceThread(spaceId: string | null): SpaceThread {
);
membersDue.current = read;
read();
- const t = setInterval(read, MEMBERS_POLL_MS);
- void data.call("sharing.list", { spaceId }).then(
- (s) => alive && setShares(s),
- () => {},
- );
+ // Who it is shared with changes while the page is open (a teammate is added or removed): read it with the members.
+ const readShares = () =>
+ void data.call("sharing.list", { spaceId }).then(
+ (s) => alive && setShares((was) => (JSON.stringify(was) === JSON.stringify(s) ? was : s)),
+ () => {},
+ );
+ readShares();
+ let tick = 0;
+ const t = setInterval(() => {
+ read();
+ if (++tick % SHARES_EVERY === 0) readShares();
+ }, MEMBERS_POLL_MS);
return () => {
alive = false;
membersDue.current = () => {};
diff --git a/apps/cua-spaces-web/src/components/space-detail/stream-surface.tsx b/apps/cua-spaces-web/src/components/space-detail/stream-surface.tsx
index fb3c18bdd3..b5f8f29bf9 100644
--- a/apps/cua-spaces-web/src/components/space-detail/stream-surface.tsx
+++ b/apps/cua-spaces-web/src/components/space-detail/stream-surface.tsx
@@ -66,6 +66,8 @@ export interface StreamSurfaceProps {
windowName?: string | null;
/** Pointer and keys go to the Space (default). False only shows it (Watch). */
interactive?: boolean;
+ /** The person may only watch this Space (shared as Can view): it says so instead of offering control. */
+ viewOnly?: boolean;
}
/** How long the desktop may take to send its first picture. After that the
@@ -102,7 +104,7 @@ function useTimedOut(waiting: boolean, ms: number, key: string): boolean {
const SURFACE_RADIUS = 8;
const SURFACE_BORDER = 0;
-export function StreamSurface({ spaceId, os, aspectRatio = 16 / 10, canStream, previewText, access, onAccessAction, children, className, windowId, windowName, interactive = true }: StreamSurfaceProps) {
+export function StreamSurface({ spaceId, os, aspectRatio = 16 / 10, canStream, previewText, access, onAccessAction, children, className, windowId, windowName, interactive = true, viewOnly = false }: StreamSurfaceProps) {
const ref = useRef<HTMLDivElement | null>(null);
const settings = useSettings();
const autoConnect = settings.data?.values.autoConnect ?? true;
@@ -123,7 +125,7 @@ export function StreamSurface({ spaceId, os, aspectRatio = 16 / 10, canStream, p
attempt,
spaceId,
tier: "full",
- interactive,
+ interactive: interactive && !viewOnly,
radius: SURFACE_RADIUS,
inset: SURFACE_BORDER,
os,
@@ -206,7 +208,15 @@ export function StreamSurface({ spaceId, os, aspectRatio = 16 / 10, canStream, p
)}
</div>
)}
- {slot?.phase === "live" && slot.focused ? (
+ {slot?.phase === "live" && viewOnly ? (
+ <p
+ data-view-only=""
+ data-video-hole=""
+ className="glass absolute bottom-2 left-1/2 max-w-[calc(100%-1rem)] -translate-x-1/2 truncate rounded-lg px-3 py-1 text-xs text-muted-foreground shadow-float"
+ >
+ View only. You can watch, but not control this Space.
+ </p>
+ ) : slot?.phase === "live" && slot.focused ? (
// While the desktop has the keyboard: how to give it back, over the
// video's bottom edge. The host cuts the video out under it
// (`data-video-hole`), so no strip under the stream is needed.
diff --git a/apps/cua-spaces-web/src/components/space-thread/roster-owner.test.ts b/apps/cua-spaces-web/src/components/space-thread/roster-owner.test.ts
new file mode 100644
index 0000000000..e0b91fb857
--- /dev/null
+++ b/apps/cua-spaces-web/src/components/space-thread/roster-owner.test.ts
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: FSL-1.1-MIT
+// Copyright (c) 2026 Cua AI, Inc.
+
+import { describe, expect, it } from "vitest";
+
+import { buildRoster } from "./roster";
+
+const base = { members: [], entries: [], me: null, identity: "[email protected]", harnessName: () => "" };
+
+describe("who is in a shared Space (CUA-3040)", () => {
+ it("a guest sees the owner next to themselves, though only the owner can list the shares", () => {
+ const roster = buildRoster({ ...base, shares: [], owner: { name: "Ada", email: "[email protected]" } });
+ expect(roster.people.map((p) => [p.label, p.me])).toEqual([
+ ["Guest", true],
+ ["Ada", false],
+ ]);
+ });
+
+ it("the owner is listed once when the share list names them too", () => {
+ const roster = buildRoster({ ...base, shares: [{ who: "[email protected]", role: "editor" }], owner: { name: "Ada", email: "[email protected]" } });
+ expect(roster.people.filter((p) => p.label === "Ada")).toHaveLength(1);
+ });
+
+ it("the owner sees whoever the Space is shared with", () => {
+ const roster = buildRoster({ ...base, identity: "[email protected]", shares: [{ who: "[email protected]", role: "viewer" }] });
+ expect(roster.people.map((p) => p.label)).toEqual(["Ada", "Bob"]);
+ });
+});
diff --git a/apps/cua-spaces-web/src/components/space-thread/roster.ts b/apps/cua-spaces-web/src/components/space-thread/roster.ts
index 9519b71a6e..366dbe9ddf 100644
--- a/apps/cua-spaces-web/src/components/space-thread/roster.ts
+++ b/apps/cua-spaces-web/src/components/space-thread/roster.ts
@@ -130,6 +130,8 @@ export function buildRoster(input: {
harnessName: (harness: string) => string;
/** Your role in the Space (null: a daemon that doesn't say, the owner's). */
role?: ThreadRole | null;
+ /** Whose Space it is, when it was shared with you: only the owner sees the share list, so a guest learns the owner from here. */
+ owner?: { name: string; email?: string | null } | null;
}): Roster {
const agents: RosterAgent[] = input.members.map((m) => ({
kind: "agent",
@@ -168,6 +170,12 @@ export function buildRoster(input: {
const mine = input.me ? posted.get(input.me) : undefined;
const myLabel = mine?.name || (input.identity ? personLabel(input.identity) : "You");
add({ kind: "person", id: input.me ?? "me", label: myLabel, me: true }, input.me ?? "me", myLabel.toLowerCase());
+ if (input.owner) {
+ const label = input.owner.name || personLabel(input.owner.email ?? "");
+ const key = `share:${input.owner.email ?? label}`;
+ const author = [...posted.values()].find((a) => a.name.toLowerCase() === label.toLowerCase());
+ add({ kind: "person", id: author?.id ?? key, label, me: false }, author?.id ?? key, label.toLowerCase());
+ }
for (const s of input.shares) {
const label = personLabel(s.who);
const author = [...posted.values()].find((a) => a.name.toLowerCase() === label.toLowerCase());
diff --git a/apps/cua-spaces-web/src/components/space-thread/space-call.tsx b/apps/cua-spaces-web/src/components/space-thread/space-call.tsx
index c890ad6a41..37a11cae27 100644
--- a/apps/cua-spaces-web/src/components/space-thread/space-call.tsx
+++ b/apps/cua-spaces-web/src/components/space-thread/space-call.tsx
@@ -60,6 +60,7 @@ export function SpaceCall({
view,
onStream,
presence,
+ owner,
onShare,
layout = "call",
onLayout,
@@ -102,6 +103,8 @@ export function SpaceCall({
/** Opens a row in its own window. */
onStream: (row: StreamRow) => void;
presence?: MemberPresence;
+ /** Whose Space this is, when it was shared with you (the owner is in the room too). */
+ owner?: { name: string; email?: string | null } | null;
/** Opens Share for this Space (Add an agent offers it; absent: sharing isn't offered here). */
onShare?: () => void;
/** The Space is still being made: the composer queues, nothing joins yet (`thread` is `creatingThread`). */
@@ -112,8 +115,8 @@ export function SpaceCall({
const [moreOpen, setMoreOpen] = useState(false);
const [addOpen, setAddOpen] = useState(false);
const roster = useMemo(
- () => buildRoster({ members: thread.members, shares: thread.shares, entries: thread.entries, me: thread.me, identity, role: thread.role, harnessName: (h) => harnessName(core, h) }),
- [thread.members, thread.shares, thread.entries, thread.me, thread.role, identity, core],
+ () => buildRoster({ members: thread.members, shares: thread.shares, entries: thread.entries, me: thread.me, identity, role: thread.role, owner, harnessName: (h) => harnessName(core, h) }),
+ [thread.members, thread.shares, thread.entries, thread.me, thread.role, identity, owner, core],
);
// Anyone who can post can add an agent; a guest only reads.
const canAdd = !creating && thread.status === "ready" && thread.role !== "guest";
diff --git a/apps/cua-spaces-web/src/lib/stream-surface.test.tsx b/apps/cua-spaces-web/src/lib/stream-surface.test.tsx
index 447c0f4da2..f903a958aa 100644
--- a/apps/cua-spaces-web/src/lib/stream-surface.test.tsx
+++ b/apps/cua-spaces-web/src/lib/stream-surface.test.tsx
@@ -455,10 +455,10 @@ describe("<StreamSurface> native video", () => {
posted = [];
});
- const mount = (props: { canStream?: boolean; children?: React.ReactNode } = {}) =>
+ const mount = (props: { canStream?: boolean; viewOnly?: boolean; children?: React.ReactNode } = {}) =>
render(
<BridgeProvider adapter={createDemoAdapter({ latencyMs: 1 })} core={noCore}>
- <StreamSurface spaceId="sp-1" os="macos" canStream={props.canStream ?? true} previewText="Not reachable">
+ <StreamSurface spaceId="sp-1" os="macos" canStream={props.canStream ?? true} previewText="Not reachable" viewOnly={props.viewOnly}>
{props.children}
</StreamSurface>
</BridgeProvider>,
@@ -508,6 +508,21 @@ describe("<StreamSurface> native video", () => {
expect(posted.at(-1)).toEqual({ type: "surfaces", update: [], remove: [first.surfaceId] });
});
+ // CUA-3041: a teammate with Can view is told it is view only; the host is never asked to give the keys.
+ it("says view only for a viewer and never offers control", async () => {
+ hostDrawsVideo();
+ const { container, queryByText } = mount({ viewOnly: true });
+ await waitFor(() => expect(updates()).not.toHaveLength(0));
+ const first = updates()[0];
+ if (!first) throw new Error("no surface update");
+ expect(first).toMatchObject({ interactive: false });
+ act(() => hostEvent("video.surface", { surfaceId: first.surfaceId, state: "live" }));
+ expect(container.querySelector("[data-view-only]")?.textContent).toContain("View only");
+ act(() => hostEvent("video.focus", { surfaceId: first.surfaceId }));
+ expect(queryByText("Stop controlling")).toBeNull();
+ expect(container.querySelector("[data-video-focus]")).toBeNull();
+ });
+
// Regression: closing picture in picture showed "Could not connect to the
// desktop" before the inline desktop came back. The slot that comes back
// must start at connecting: no failure or timeout left from the slot (or
diff --git a/apps/cua-spaces-web/src/routes/spaces/$spaceId.tsx b/apps/cua-spaces-web/src/routes/spaces/$spaceId.tsx
index 1461d6c2eb..15ab541853 100644
--- a/apps/cua-spaces-web/src/routes/spaces/$spaceId.tsx
+++ b/apps/cua-spaces-web/src/routes/spaces/$spaceId.tsx
@@ -13,6 +13,7 @@ import { AgentsSection } from "@/components/space-detail/agents-section";
import { DropWell } from "@/components/space-detail/drop-well";
import { FactList } from "@/components/space-detail/facts";
import { SpaceResourcesPanel } from "@/components/resources/space-resources-panel";
+import { ownerLabel } from "@/lib/space-access";
import { systemName } from "@/lib/resources";
import { StreamSection } from "@/components/space-detail/stream-section";
import { StreamSurface } from "@/components/space-detail/stream-surface";
@@ -115,8 +116,14 @@ function SpaceDetailPage() {
// already gone (Back after Remove from list) says so, and never jumps into
// another Space.
const [showed, setShowed] = useState<string | null>(null);
+ // Who shared it, when it was shared with you: if the row goes while this page is open,
+ // the owner most likely stopped sharing it, and the page says so.
+ const [sharedBy, setSharedBy] = useState<{ spaceId: string; owner: string | null } | null>(null);
useEffect(() => {
- if (space) setShowed(spaceId);
+ if (!space) return;
+ setShowed(spaceId);
+ const a = space.access;
+ setSharedBy(a && a.kind !== "mine" ? { spaceId, owner: ownerLabel(a) } : null);
}, [space, spaceId]);
const created = !space && showed === spaceId ? createdId(spaceId) : undefined;
useEffect(() => {
@@ -124,20 +131,25 @@ function SpaceDetailPage() {
}, [created, navigate]);
if (created) return null;
+ const removedAccess = !space && !error && sharedBy?.spaceId === spaceId ? sharedBy : null;
if (error || (!isLoading && !space)) {
return (
<Page>
<BackLink />
<EmptyState
icon={<MonitorIcon />}
- title={error ? "Couldn't load this Space" : "This Space isn't here"}
+ title={error ? "Couldn't load this Space" : removedAccess ? "You no longer have access" : "This Space isn't here"}
action={
<Button variant="outline" render={<Link to="/spaces" />}>
Back to Spaces
</Button>
}
>
- {error ? error.message : "It may have been deleted, or it runs on a machine this app can't see."}
+ {error
+ ? error.message
+ : removedAccess
+ ? `${removedAccess.owner ?? "The owner"} stopped sharing this Space with you.`
+ : "It may have been deleted, or it runs on a machine this app can't see."}
</EmptyState>
</Page>
);
@@ -160,7 +172,11 @@ function SpaceDetailPage() {
// device may connect.
const action = (id: string) => detail.actions.find((a) => a.id === id);
const teleportAction = action("teleport");
- const shareAction = action("share");
+ // A teammate who may only watch is not offered Share or control (the host refuses both anyway).
+ const viewOnly = space.access?.role === "viewer";
+ const sharedOwner = space.access && space.access.kind === "withMe" ? { name: ownerLabel(space.access) ?? "", email: space.access.ownerEmail } : null;
+ const mayShare = space.access?.canShare !== false && !viewOnly;
+ const shareAction = mayShare ? action("share") : undefined;
// Signed in, not enrolled: the access line's action opens Settings,
// Devices with the enroll sheet.
const enroll = () => {
@@ -304,9 +320,10 @@ function SpaceDetailPage() {
<OsIcon os={space.os} className="size-4.5 text-muted-foreground" />
</div>
);
- const surface = (className: string, windowId?: string | null, windowName?: string | null, interactive = true) => (
+ const surface = (className: string, windowId?: string | null, windowName?: string | null, interactive = !viewOnly) => (
<StreamSurface
interactive={interactive}
+ viewOnly={viewOnly}
spaceId={space.id}
windowId={windowId}
windowName={windowName}
@@ -500,6 +517,7 @@ function SpaceDetailPage() {
view={shownView}
onStream={(row) => void onPip(row)}
onShare={shareAction?.enabled ? share : undefined}
+ owner={sharedOwner}
/>
{dialogs}
</>
diff --git a/libs/cua/crates/cua-spaces/src/share.rs b/libs/cua/crates/cua-spaces/src/share.rs
index c53fa8f2ab..fde9e48445 100644
--- a/libs/cua/crates/cua-spaces/src/share.rs
+++ b/libs/cua/crates/cua-spaces/src/share.rs
@@ -678,9 +678,10 @@ impl Spaces {
"nothing here can ask you to confirm; share from the Cua app or run `cua spaces share` in a terminal",
)
})?;
+ let label = self.space_label(&canonical);
let reason = match role {
- ShareRole::Viewer => format!("Let {who} watch {canonical}"),
- ShareRole::Editor => format!("Let {who} use {canonical} (see and control it)"),
+ ShareRole::Viewer => format!("let {who} watch \"{label}\""),
+ ShareRole::Editor => format!("let {who} use \"{label}\" (see and control it)"),
};
tokio::task::spawn_blocking(move || consent.confirm(&reason))
.await
@@ -763,6 +764,17 @@ impl Spaces {
self.shares_of(&canonical, &machine).await
}
+ /// The name people gave a Space, for prompts; the id only when it has
+ /// no name.
+ fn space_label(&self, canonical: &str) -> String {
+ self.list()
+ .ok()
+ .and_then(|l| l.into_iter().find(|i| i.id == canonical))
+ .map(|i| i.shown_name().to_string())
+ .filter(|n| !n.is_empty())
+ .unwrap_or_else(|| canonical.to_string())
+ }
+
/// The consent prompt, run off the async runtime.
async fn confirm_share(&self, reason: String) -> Result<()> {
let consent = self
@@ -854,12 +866,16 @@ impl Spaces {
.filter(|o| !o.is_empty())
.unwrap_or_default();
let label = listed.map(|i| i.name).unwrap_or_default();
+ let space_label = self.space_label(&canonical);
self.confirm_share(match role {
ShareRole::Viewer => {
- format!("Let every member of team {} watch {canonical}", org.label())
+ format!(
+ "let every member of team {} watch \"{space_label}\"",
+ org.label()
+ )
}
ShareRole::Editor => format!(
- "Let every member of team {} use {canonical} (see and control it)",
+ "let every member of team {} use \"{space_label}\" (see and control it)",
org.label()
),
})
diff --git a/libs/cua/crates/cua-spaces/tests/share.rs b/libs/cua/crates/cua-spaces/tests/share.rs
index c8eef1563e..57aca5a6be 100644
--- a/libs/cua/crates/cua-spaces/tests/share.rs
+++ b/libs/cua/crates/cua-spaces/tests/share.rs
@@ -403,7 +403,7 @@ async fn sharing_needs_the_users_confirmation() {
assert_eq!(e.tag(), "permission_denied", "{e}");
assert_eq!(
no.asked.lock().unwrap().as_slice(),
- [format!("Let [email protected] use {id} (see and control it)")]
+ ["let [email protected] use \"studio\" (see and control it)".to_string()]
);
assert!(relay.machine(&reg.machine.id).unwrap().allow.is_empty());
assert!(spaces.share_audit(None, 10).unwrap().is_empty());