Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30862,6 +30862,13 @@ components:
- browser
- windows
description: 'The computer it works on: browser, the Bot''s own browser computer, which every Bot has unless told otherwise; or windows, the Windows computer of the person it works for: in a conversation, theirs; in a routine, its owner''s. One at a time. Experimental.'
computerAccess:
type: string
x-extensible-enum:
- allowed
- refused
readOnly: true
description: 'Whether the caller may see and use this Bot''s browser computer: its screen, its terminal, who has control and its activity. allowed for an admin, on a public Bot, and for its owner. refused for anybody else, such as a teammate a private Bot is shared with, who still chats with it; every computer call and the live screen and terminal answer them 404 BOT_NOT_FOUND. A client that reads refused opens none of them and says so. Absent from a server older than this field, where a client learns it from that 404. A value this client doesn''t know reads as allowed. Never accepted when a Bot is created or changed.'
instructions:
type: string
description: What the starter Bot is told, kept apart from its role description. Only the starter Bot has instructions.
Expand Down
15 changes: 15 additions & 0 deletions api/openapi/bots.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,21 @@ components:
which every Bot has unless told otherwise; or windows, the Windows
computer of the person it works for: in a conversation, theirs; in a
routine, its owner's. One at a time. Experimental.
computerAccess:
type: string
x-extensible-enum: [allowed, refused]
readOnly: true
description: >-
Whether the caller may see and use this Bot's browser computer:
its screen, its terminal, who has control and its activity.
allowed for an admin, on a public Bot, and for its owner. refused
for anybody else, such as a teammate a private Bot is shared
with, who still chats with it; every computer call and the live
screen and terminal answer them 404 BOT_NOT_FOUND. A client that
reads refused opens none of them and says so. Absent from a
server older than this field, where a client learns it from that
404. A value this client doesn't know reads as allowed. Never
accepted when a Bot is created or changed.
instructions:
type: string
description: >-
Expand Down
33 changes: 32 additions & 1 deletion app/src/components/computer/computer-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import { useEffect, useState, useSyncExternalStore } from "react";
import {
IconDeviceDesktop,
IconDeviceDesktopOff,
IconLock,
IconTerminal2,
} from "@/components/icons";
import { PageEmpty } from "@/components/layout/page-parts";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { WindowsComputerView } from "@/components/windows-computer/windows-computer-page";
import { agentQueryOptions } from "@/lib/agents/queries";
import {
COMPUTER_REFUSED_SAID,
COMPUTER_REFUSED_TITLE,
computerRefusedFor,
} from "@/lib/computers/access";
import {
followedView,
onComputerViewRequest,
Expand Down Expand Up @@ -71,9 +77,28 @@ export function ComputerViewPanel({
</PageEmpty>
</section>
);
/*
* A BOT WHOSE COMPUTER THIS PERSON MAY NOT SEE SAYS SO, AND OPENS NOTHING. A teammate on a private Bot shared with
* them: the server answers every call about its computer 404 (lib/computers/access.ts). The panel used to read
* those as a computer still starting, a wheel still being checked and a terminal reconnecting, for ever. Nothing
* of the live panel is drawn here, so no screenshot, status, wheel or activity is read and no socket is opened.
*/
if (computerRefusedFor(bot.data)) return <RefusedComputerPanel />;
return <LiveComputerPanel agentId={agentId} name={name} />;
}

/** The panel where this person may not see the Bot's computer. */
function RefusedComputerPanel() {
return (
// The empty state brings its own 16px above it, which is the panel's top padding.
<section aria-label="Computer sidebar" className="px-4 pb-4">
<PageEmpty icon={IconLock} title={COMPUTER_REFUSED_TITLE}>
{COMPUTER_REFUSED_SAID}
</PageEmpty>
</section>
);
}

/**
* The panel for a Bot that works on a Windows computer: the person's own, whichever of their Bots it is (a person
* has one in each organization). Its live screen, who is using it, and its recording; nothing of the browser computer
Expand Down Expand Up @@ -147,10 +172,16 @@ function LiveComputerPanel({
"screen";

// One wheel for the whole computer: whoever holds it holds the screen and the terminal both.
const { control, someoneElse } = useComputerControl(agentId);
const { control, someoneElse, refused } = useComputerControl(agentId);
const youHaveIt =
control?.holder === "human" && !control.transitioning && !someoneElse;

/*
* A server older than `Bot.computerAccess` says it only by refusing: the wheel's first read answers 404, and the
* panel then says what it says above, closing the screen and the terminal with their reads and sockets.
*/
if (refused) return <RefusedComputerPanel />;

return (
<section aria-label="Computer sidebar" className="p-4">
<Tabs
Expand Down
150 changes: 88 additions & 62 deletions app/src/components/computer/computer-terminal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { lazy, Suspense, useRef, useState } from "react";
import { COMPUTER_REFUSED_LINE } from "@/lib/computers/access";
import { useComputerControl } from "@/lib/computers/use-control";
import { ComputerControlButton } from "./computer-controls";
import type { LiveTerminalHandle } from "./live-terminal";
Expand All @@ -23,80 +24,105 @@ const LiveTerminal = lazy(() =>
* it is handed back. The terminal inside is always a dark terminal, in either of the app's themes.
*/
export function ComputerTerminal({ computerId }: { computerId: string }) {
const { control, someoneElse } = useComputerControl(computerId);
const {
control,
someoneElse,
refused: controlRefused,
} = useComputerControl(computerId);
/** The signed-in person holds the wheel. Someone else holding it on a shared Bot is not them typing. */
const driving =
control?.holder === "human" && !control.transitioning && !someoneElse;
const terminal = useRef<LiveTerminalHandle>(null);
const [problem, setProblem] = useState<string | null>(null);
const [reconnecting, setReconnecting] = useState(false);
const [retryKey, setRetryKey] = useState(0);
/** The terminal's socket was refused: the server answered it 404 (lib/computers/access.ts). */
const [socketRefused, setSocketRefused] = useState(false);

/*
* NOT THIS PERSON'S TO SEE. The socket, or the wheel, was refused, and asking again gets the same answer: one
* sentence where the shell would be, and no socket, no Retry and no "Checking who has control…" under it. It used to
* say "Reconnecting…" for as long as the tab was open.
*/
const refused = socketRefused || controlRefused;

return (
<figure className="overflow-hidden rounded-2xl border dark:border-white/15">
<div
className="relative h-[clamp(16rem,55vh,30rem)] p-2.5"
style={{ background: TERMINAL_BACKGROUND }}
>
<Suspense fallback={null}>
<LiveTerminal
computerId={computerId}
driving={driving}
onProblem={setProblem}
onReconnecting={setReconnecting}
ref={terminal}
retryKey={retryKey}
/>
</Suspense>
{reconnecting && !problem ? (
<span
className="absolute top-2 right-2 rounded-full bg-black/60 px-2.5 py-1 font-medium text-white text-xs backdrop-blur-sm"
role="status"
{refused ? (
<div
className="flex h-[clamp(16rem,55vh,30rem)] items-center justify-center bg-muted p-4 text-center text-muted-foreground text-sm"
role="status"
>
{COMPUTER_REFUSED_LINE}
</div>
) : (
<>
<div
className="relative h-[clamp(16rem,55vh,30rem)] p-2.5"
style={{ background: TERMINAL_BACKGROUND }}
>
<Suspense fallback={null}>
<LiveTerminal
computerId={computerId}
driving={driving}
onProblem={setProblem}
onReconnecting={setReconnecting}
onRefused={() => setSocketRefused(true)}
ref={terminal}
retryKey={retryKey}
/>
</Suspense>
{reconnecting && !problem ? (
<span
className="absolute top-2 right-2 rounded-full bg-black/60 px-2.5 py-1 font-medium text-white text-xs backdrop-blur-sm"
role="status"
>
Reconnecting…
</span>
) : null}
{problem ? (
<div className="absolute inset-0 flex flex-col items-center justify-center gap-3 bg-background/90 p-4 text-center text-muted-foreground text-sm">
<span>{problem}</span>
<button
className="underline"
onClick={() => {
setProblem(null);
setRetryKey((value) => value + 1);
}}
type="button"
>
Retry
</button>
</div>
) : null}
</div>
<div
className={`flex flex-wrap items-center justify-between gap-2 border-t px-3 py-2 ${driving ? "bg-warning/10" : ""}`}
>
Reconnecting…
</span>
) : null}
{problem ? (
<div className="absolute inset-0 flex flex-col items-center justify-center gap-3 bg-background/90 p-4 text-center text-muted-foreground text-sm">
<span>{problem}</span>
<button
className="underline"
onClick={() => {
setProblem(null);
setRetryKey((value) => value + 1);
}}
type="button"
>
Retry
</button>
{driving ? (
<span className="text-sm">
<strong className="font-medium">You have control</strong> of the
terminal and the screen. Click the terminal and type. The Bot
waits until you hand it back.
</span>
) : (
<span className="text-muted-foreground text-xs">
{!control
? "Checking who has control…"
: control.transitioning
? "Finishing the current action…"
: someoneElse
? "Someone else has control."
: "The Bot has control."}
</span>
)}
<ComputerControlButton
computerId={computerId}
onTakeControl={() => terminal.current?.focus()}
/>
</div>
) : null}
</div>
<div
className={`flex flex-wrap items-center justify-between gap-2 border-t px-3 py-2 ${driving ? "bg-warning/10" : ""}`}
>
{driving ? (
<span className="text-sm">
<strong className="font-medium">You have control</strong> of the
terminal and the screen. Click the terminal and type. The Bot waits
until you hand it back.
</span>
) : (
<span className="text-muted-foreground text-xs">
{!control
? "Checking who has control…"
: control.transitioning
? "Finishing the current action…"
: someoneElse
? "Someone else has control."
: "The Bot has control."}
</span>
)}
<ComputerControlButton
computerId={computerId}
onTakeControl={() => terminal.current?.focus()}
/>
</div>
</>
)}
</figure>
);
}
Loading
Loading