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
feat(spaces-web): drop files on a Space's tile to send them there (#5100)
ddupont5fa12e448a08
diff --git a/apps/cua-spaces-web/src/__tests__/tile-drop.test.tsx b/apps/cua-spaces-web/src/__tests__/tile-drop.test.tsxnew file mode 100644index 0000000000..3514935435--- /dev/null+++ b/apps/cua-spaces-web/src/__tests__/tile-drop.test.tsx@@ -0,0 +1,122 @@+// SPDX-License-Identifier: FSL-1.1-MIT+// Copyright (c) 2026 Cua AI, Inc.++// Files dropped from Finder on a Space's tile on the Spaces page go into+// that Space, as a drop on its page's well does (real routes, wasm core,+// the demo host): the tile says where they go while they are over it, what+// the drop did shows in a toast, a stopped Space's tile refuses them, and an+// app dropped on a tile opens Teleport at that app.++import { cleanup, fireEvent, waitFor } from "@testing-library/react";+import { afterEach, describe, expect, it } from "vitest";+import { wasmBuilt } from "@/bridge/__tests__/testCore";+import { mountApp, stubBrowserApis, type TestHost } from "./app-harness";++afterEach(cleanup);+stubBrowserApis();++const RUNNING = "relay:mac-mini/qa-windows";++function host(calls: [string, unknown][], answers: Record<string, (args: unknown) => unknown> = {}): TestHost {+ return {+ failsCreates: false,+ listsGhost: false,+ intercept: (op, args) => {+ calls.push([op, args]);+ return answers[op]?.(args);+ },+ };+}++const transfer = (names: string[]) => ({ types: ["Files"], files: names.map((n) => new File(["x"], n)), dropEffect: "none" });++const tileOf = (id: string) =>+ waitFor(() => {+ const link = document.querySelector<HTMLElement>(`[data-space-id="${id}"]`);+ if (!link) throw new Error(`no tile ${id}`);+ return link.parentElement!;+ });++describe.skipIf(!wasmBuilt)("dropping files on a Space's tile", () => {+ it("says where the files go while over the tile, sends the dropped files into that Space, and reports it", async () => {+ const calls: [string, unknown][] = [];+ await mountApp(+ "/spaces",+ host(calls, {+ "spaces.droppedFiles": () => ["/Users/ada/notes.txt", "/Users/ada/plan.pdf"],+ "spaces.sendFiles": () => [+ { name: "notes.txt", bytes: 10, remotePath: "/home/cua/Desktop/notes.txt" },+ { name: "plan.pdf", bytes: 20, remotePath: "/home/cua/Desktop/plan.pdf" },+ ],+ }),+ );+ const tile = await tileOf(RUNNING);+ await waitFor(() => expect(tile.querySelector('[data-space-id]')?.getAttribute("data-state")).toBe("running"));+ const dt = transfer(["notes.txt", "plan.pdf"]);++ fireEvent.dragEnter(tile, { dataTransfer: dt });+ fireEvent.dragOver(tile, { dataTransfer: dt });+ expect(tile.getAttribute("data-tile-drop")).toBe("accept");+ expect(tile.textContent).toContain("Send to qa-windows");+ expect(dt.dropEffect).toBe("copy");++ fireEvent.drop(tile, { dataTransfer: dt });+ expect(tile.getAttribute("data-tile-drop")).toBeNull();+ await waitFor(() => expect(calls).toContainEqual(["spaces.sendFiles", { spaceId: RUNNING, paths: ["/Users/ada/notes.txt", "/Users/ada/plan.pdf"] }]));+ expect(calls).toContainEqual(["spaces.droppedFiles", { names: ["notes.txt", "plan.pdf"] }]);+ await waitFor(() => expect(tile.getAttribute("data-drop-status")).toBe("done"));+ await waitFor(() => expect(document.body.textContent).toContain("Sent to qa-windows"));+ });++ it("says why when the send fails", async () => {+ const calls: [string, unknown][] = [];+ await mountApp(+ "/spaces",+ host(calls, {+ "spaces.droppedFiles": () => ["/Users/ada/notes.txt"],+ "spaces.sendFiles": () => {+ throw new Error("the Space did not answer");+ },+ }),+ );+ const tile = await tileOf(RUNNING);+ await waitFor(() => expect(tile.querySelector('[data-space-id]')?.getAttribute("data-state")).toBe("running"));+ const dt = transfer(["notes.txt"]);+ fireEvent.dragOver(tile, { dataTransfer: dt });+ fireEvent.drop(tile, { dataTransfer: dt });+ await waitFor(() => expect(tile.getAttribute("data-drop-status")).toBe("failed"));+ await waitFor(() => expect(document.body.textContent).toContain("Couldn't send to qa-windows"));+ expect(document.body.textContent).toContain("the Space did not answer");+ });++ it("refuses files on a Space that isn't running", async () => {+ const calls: [string, unknown][] = [];+ await mountApp("/spaces", host(calls));+ const link = await waitFor(() => {+ const el = document.querySelector<HTMLElement>('[data-space-id][data-state="stopped"]');+ if (!el) throw new Error("no stopped tile");+ return el;+ });+ const tile = link.parentElement!;+ const dt = transfer(["notes.txt"]);+ fireEvent.dragOver(tile, { dataTransfer: dt });+ expect(tile.getAttribute("data-tile-drop")).toBe("refuse");+ expect(dt.dropEffect).toBe("none");+ expect(tile.textContent).toContain("isn't running");+ fireEvent.drop(tile, { dataTransfer: dt });+ await new Promise((r) => setTimeout(r, 50));+ expect(calls.some(([op]) => op === "spaces.droppedFiles" || op === "spaces.sendFiles")).toBe(false);+ });++ it("opens Teleport at an app dropped on a tile", async () => {+ const calls: [string, unknown][] = [];+ await mountApp("/spaces", host(calls, { "spaces.droppedFiles": () => ["/Applications/Google Chrome.app"] }));+ const tile = await tileOf(RUNNING);+ await waitFor(() => expect(tile.querySelector('[data-space-id]')?.getAttribute("data-state")).toBe("running"));+ const dt = transfer(["Google Chrome.app"]);+ fireEvent.dragOver(tile, { dataTransfer: dt });+ fireEvent.drop(tile, { dataTransfer: dt });+ await waitFor(() => expect(calls.some(([op]) => op === "teleport.entryForPath")).toBe(true));+ expect(calls.some(([op]) => op === "spaces.sendFiles")).toBe(false);+ });+});diff --git a/apps/cua-spaces-web/src/routes/spaces/index.tsx b/apps/cua-spaces-web/src/routes/spaces/index.tsxindex 367c6b5cae..92bca785b3 100644--- a/apps/cua-spaces-web/src/routes/spaces/index.tsx+++ b/apps/cua-spaces-web/src/routes/spaces/index.tsx@@ -2,10 +2,10 @@// Copyright (c) 2026 Cua AI, Inc.import { createFileRoute, Link } from "@tanstack/react-router";-import { KeyRoundIcon, LoaderCircleIcon, MonitorIcon, PlusIcon, PowerIcon } from "lucide-react";-import { useRef, useState } from "react";+import { ArrowDownCircleIcon, KeyRoundIcon, LoaderCircleIcon, MonitorIcon, PlusIcon, PowerIcon } from "lucide-react";+import { useEffect, useRef, useState, type DragEvent } from "react";-import { emptyHome, useBridge, useFirstSpaceOffers, useMachines, useNewSpaceWizard, useSpaceAccess, useSpaces, useSpaceThumbnail, type Space } from "@/bridge";+import { emptyHome, useBridge, useFirstSpaceOffers, useMachines, useNewSpaceWizard, useSpaceAccess, useSpaceFiles, useSpaces, useSpaceThumbnail, type Space } from "@/bridge";import { EmptyHome } from "@/components/empty-home";import { GettingStarted } from "@/components/getting-started";import { OsIcon } from "@/components/os-icon";@@ -16,7 +16,7 @@ import { useTileVideo } from "@/components/video/tile-video";import { useNewSpace } from "@/hooks/use-new-space";import { Button } from "@/components/ui/button";import { Segmented } from "@/components/ui/segmented";-import { toastError } from "@/components/ui/toast";+import { toast, toastError } from "@/components/ui/toast";import { creatingLine, thisComputerText } from "@/lib/host-labels";import { plural } from "@/lib/plural";import { cn } from "@/lib/utils";@@ -101,9 +101,18 @@ function SpacesPage() {}function SpaceTile({ space, machine, accessKey }: { space: Space; machine: string; accessKey?: string | null }) {+ const drop = useTileDrop(space);return (- <div className="group/tile relative">+ <div className="group/tile relative" data-tile-drop={drop.over ?? undefined} data-drop-status={drop.status?.kind} {...drop.handlers}><SpaceLink space={space} machine={machine} />+ {drop.over ? <DropOverlay space={space} accepts={drop.over === "accept"} /> : null}+ {/* A drop on the tile still going in: the core's "Sending …" line. */}+ {drop.status?.kind === "working" && !drop.over ? (+ <div className="pointer-events-none absolute top-3 left-3 flex max-w-[60%] items-center gap-1.5 rounded-full border bg-card/90 px-2 py-0.5 text-2xs font-medium text-muted-foreground shadow-xs backdrop-blur-sm">+ <LoaderCircleIcon className="size-3 shrink-0 animate-spin" aria-hidden />+ <span className="truncate">{drop.status.text}</span>+ </div>+ ) : null}{/* Over the thumbnail, as the SwiftUI sidebar row ends: "Signed in", then power. */}<div className="absolute top-3 right-3 flex items-center gap-1.5">{/* A live Keyvault sign-in is in this Space: the badge opens Access with its row brought forward. */}@@ -124,6 +133,65 @@ function SpaceTile({ space, machine, accessKey }: { space: Space; machine: strin);}+/**+ * Files dropped from Finder on a running Space's tile go into that Space,+ * as a drop on its page's well does (`useSpaceFiles`: the host reads the+ * paths from the drop itself; an app bundle opens Teleport at that app).+ * While files are over the tile it says where they go; what the drop did+ * shows on the tile and in a toast.+ */+function useTileDrop(space: Space) {+ const files = useSpaceFiles(space);+ const [over, setOver] = useState<"accept" | "refuse" | null>(null);+ const accepts = spaceState(space) === "running";+ const status = files.status;+ useEffect(() => {+ if (!status) return;+ const group = `tile-drop:${space.id}`;+ if (status.kind === "working") toast(status.text, { group });+ else if (status.kind === "done") toast(`Sent to ${space.name}`, { description: status.text, type: "success", group });+ else toast(`Couldn't send to ${space.name}`, { description: status.text, type: "error", group });+ }, [status, space.id, space.name]);+ const carriesFiles = (e: DragEvent) => Array.from(e.dataTransfer?.types ?? []).includes("Files");+ const onDragOver = (e: DragEvent) => {+ if (!carriesFiles(e)) return;+ // Always handled here, so a drop on a tile never reaches the window.+ e.preventDefault();+ e.dataTransfer.dropEffect = accepts ? "copy" : "none";+ setOver(accepts ? "accept" : "refuse");+ };+ const onDragLeave = (e: DragEvent) => {+ // Leaving for one of the tile's own children is still over the tile.+ if (e.currentTarget.contains(e.relatedTarget as Node | null)) return;+ setOver(null);+ };+ const onDrop = (e: DragEvent) => {+ if (!carriesFiles(e)) return;+ e.preventDefault();+ setOver(null);+ if (!accepts) return;+ const names = Array.from(e.dataTransfer.files).map((f) => f.name);+ if (names.length) void files.drop(names);+ };+ return { over, status, handlers: { onDragEnter: onDragOver, onDragOver, onDragLeave, onDrop } };+}++/** Over a tile while files are dragged on it: where they go, or why they can't. */+function DropOverlay({ space, accepts }: { space: Space; accepts: boolean }) {+ return (+ <div+ aria-hidden+ className={cn(+ "pointer-events-none absolute inset-0 flex flex-col items-center justify-center gap-1.5 rounded-xl border-2 text-center text-[13px] backdrop-blur-[2px]",+ accepts ? "border-brand bg-brand/15 text-foreground" : "border-dashed border-border bg-card/80 text-muted-foreground",+ )}+ >+ {accepts ? <ArrowDownCircleIcon className="size-6 text-brand" strokeWidth={1.5} /> : null}+ <span className="max-w-[85%] truncate font-medium">{accepts ? `Send to ${space.name}` : `${space.name} isn't running`}</span>+ </div>+ );+}+/*** The core's power button, while the pointer is on the tile or focus is in* it, and always while it runs (the SwiftUI sidebar row's, which shows on