Skip to content

Commit d839bd0

Browse files
authored
Say OpenBot runs on this computer in the account menu, and offer Connect to an OpenBot (#2820)
On OpenBot Desktop with OpenBot on this computer, the account menu showed "dev@openbot.local" under the person's name. That is the server's stand-in for the one person, not an account anybody signed in with, but it read as one: a person added to an organization on OpenBot Cloud looked for Sign out to sign in with another email, found none, and nothing said OpenBot ran on her computer. With local evaluation the account row now says "OpenBot runs on this computer" in place of the email, and never names the person by the stand-in. Inside a desktop app that can connect elsewhere, Connect to an OpenBot sits where Sign out would be and opens Settings > Computer at Connection, where Move to OpenBot Cloud and Connect to an OpenBot each say what they do. The web app and Desktop connected to an OpenBot elsewhere are unchanged. Tests: app-navigation.test.tsx holds the menu in each mode, and self-contained-account-menu.test.tsx runs the whole app in Chromium and WebKit, light and dark, from the menu to the connection choices.
1 parent da5fecd commit d839bd0

8 files changed

Lines changed: 634 additions & 13 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,9 @@ jobs:
593593
# is reached" row, through the app OpenBot is part of (named by its token endpoint's host) and
594594
# through Microsoft Entra, with no token to paste.
595595
# And Report a bug, Your bug reports and Admin's Bug reports, wide and on a phone, light and dark,
596-
# held against Add credential and the Vault: a file taken, one refused, the report saved. In the image, as above:
596+
# held against Add credential and the Vault: a file taken, one refused, the report saved.
597+
# And the account menu with OpenBot on this computer saying so in place of the stand-in email,
598+
# and its Connect to an OpenBot opening Settings → Computer at Connection. In the image, as above:
597599
# WebKit's system packages are about 94 MB, which took nine minutes from the mirror on a slow day.
598600
#
599601
# The files run side by side, like the Chromium list's, but eight at a time rather than a worker
@@ -734,6 +736,7 @@ jobs:
734736
app/tests/run-ended-unheard-layout.test.tsx
735737
app/tests/section-strip-routines.test.tsx
736738
app/tests/select-scrolls-layout.test.tsx
739+
app/tests/self-contained-account-menu.test.tsx
737740
app/tests/service-terms.test.tsx
738741
app/tests/settings-tool-cards-admin-layout.test.tsx
739742
app/tests/settings-tool-cards-core.test.tsx

‎app/src/components/app-sidebar/account-label.tsx‎

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,41 @@ import { OpenBotVersion } from "../layout/openbot-version";
2020
/** The version's type under the strip's avatar: tiny and quiet. */
2121
const versionClassName = "text-[10px] leading-3 text-muted-foreground";
2222

23+
/** What the account row says under the name where OpenBot runs on this computer. */
24+
const ON_THIS_COMPUTER_LINE = "OpenBot runs on this computer";
25+
26+
/**
27+
* Whether OpenBot runs on this computer for one person, with nobody signed in (`localEvaluation`):
28+
* OpenBot Desktop on this computer, or `OPENBOT_SINGLE_USER`. There the person's email is a stand-in
29+
* the server makes up (`dev@openbot.local`), not an account anybody signed in with, so it is never
30+
* shown as one.
31+
*/
32+
function useOnThisComputer(): boolean {
33+
return (
34+
useQuery(deploymentCapabilitiesQueryOptions()).data?.localEvaluation ===
35+
true
36+
);
37+
}
38+
39+
/** The first letters of a name's first two words. */
40+
function initialsOf(name: string): string {
41+
return name
42+
.trim()
43+
.split(/\s+/)
44+
.slice(0, 2)
45+
.map((part) => part[0]?.toUpperCase())
46+
.join("");
47+
}
48+
2349
function UserAvatar() {
2450
const { data: currentUser } = useQuery(currentUserQueryOptions());
25-
const initials =
26-
currentUser?.name
27-
?.trim()
28-
.split(/\s+/)
29-
.slice(0, 2)
30-
.map((part) => part[0]?.toUpperCase())
31-
.join("") ?? currentUser?.email.slice(0, 2).toUpperCase();
51+
const { person } = useAccountNames();
52+
// On this computer the email is the stand-in, so its letters are never drawn either.
53+
const initials = useOnThisComputer()
54+
? person && initialsOf(person)
55+
: currentUser?.name != null
56+
? initialsOf(currentUser.name)
57+
: currentUser?.email.slice(0, 2).toUpperCase();
3258

3359
return (
3460
<div
@@ -43,10 +69,25 @@ function UserAvatar() {
4369
/** The person's name, and the organization they are working in where OpenBot lists them. */
4470
function useAccountNames() {
4571
const { data: currentUser } = useQuery(currentUserQueryOptions());
72+
const onThisComputer = useOnThisComputer();
4673
const choices = useOrganizationChoices();
4774
const organization = choices?.organizations.find(
4875
(one) => one.id === choices.currentId,
4976
);
77+
if (onThisComputer) {
78+
// Until they give a name, the server's stand-in for it is the stand-in email.
79+
const named =
80+
currentUser?.name &&
81+
!currentUser.needsName &&
82+
currentUser.name !== currentUser.email
83+
? currentUser.name
84+
: undefined;
85+
return {
86+
person: currentUser ? (named ?? "You") : undefined,
87+
email: undefined,
88+
organization: organization ? organizationLabel(organization) : undefined,
89+
};
90+
}
5091
return {
5192
person: currentUser?.name || currentUser?.email,
5293
// Their name already says who it is; the email says which account, when there is a name.
@@ -59,9 +100,14 @@ function useAccountNames() {
59100
* The account row at the top of the account menu: avatar, the person's name and, under it, their
60101
* email. Not a menu item: it says whose menu this is. The organization they work in is the row
61102
* right under it, which is where they change it, and the release the server runs is under Help.
103+
*
104+
* Where OpenBot runs on this computer nobody signed in, so the line under the name says that in
105+
* place of an email (`useOnThisComputer`).
62106
*/
63107
export function AccountRow() {
64108
const { person, email } = useAccountNames();
109+
const onThisComputer = useOnThisComputer();
110+
const under = onThisComputer ? ON_THIS_COMPUTER_LINE : email;
65111
return (
66112
<div
67113
className="flex min-w-0 items-center gap-2 px-2 py-1.5"
@@ -70,9 +116,9 @@ export function AccountRow() {
70116
<UserAvatar />
71117
<span className="grid min-w-0 flex-1 text-left *:leading-4">
72118
<span className="truncate text-sm tracking-tight">{person}</span>
73-
{email ? (
119+
{under ? (
74120
<span className="truncate text-muted-foreground text-xs">
75-
{email}
121+
{under}
76122
</span>
77123
) : null}
78124
</span>

‎app/src/components/app-sidebar/section-strip.tsx‎

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { type Icon, IconLogout, IconMessages } from "@/components/icons";
1+
import {
2+
type Icon,
3+
IconArrowsExchange,
4+
IconLogout,
5+
IconMessages,
6+
} from "@/components/icons";
7+
import { useQuery } from "@tanstack/react-query";
28
import { Link, useRouterState } from "@tanstack/react-router";
39
import type { ReactNode } from "react";
410
import AgentOrb from "@/components/agents/orb/agent-orb";
@@ -14,6 +20,8 @@ import {
1420
} from "@/components/ui/dropdown-menu";
1521
import { useSidebar } from "@/components/ui/sidebar";
1622
import { useSignOutOffered } from "@/lib/auth/sign-out-offered";
23+
import { desktopConnectionQueryOptions } from "@/lib/desktop/queries";
24+
import { desktopShell } from "@/lib/desktop/shell";
1725
import { appConfig } from "@/lib/generated/application-config";
1826
import {
1927
isNavigationLink,
@@ -30,6 +38,7 @@ import {
3038
sectionHasPanel,
3139
useOpenSection,
3240
} from "@/lib/sections";
41+
import { COMPUTER_SECTION } from "@/lib/settings/computer-sections";
3342
import { BotsNavBadge } from "../bot-profile/attention";
3443
import { RecordingDot, useLiveRecording } from "../browser/browser-nav-item";
3544
import { navigationRender } from "../edition/team-features-dialog";
@@ -135,11 +144,40 @@ function PageItem({ item }: { item: NavigationLink }) {
135144
);
136145
}
137146

147+
/**
148+
* OpenBot Desktop with OpenBot on this computer, in a desktop app that can connect elsewhere: the
149+
* way to an OpenBot that runs somewhere else, OpenBot Cloud or a company's own, where Sign out sits
150+
* when there is a sign-in. Nobody signed in here, so there is no Sign out to look for. It opens
151+
* Settings → Computer at Connection, whose rows say what each choice does before anything happens.
152+
*/
153+
function ConnectInsteadItem() {
154+
const connection = useQuery({
155+
...desktopConnectionQueryOptions(),
156+
enabled: desktopShell() !== null,
157+
}).data;
158+
if (connection?.mode !== "local" || !connection.canConnect) return null;
159+
return (
160+
<>
161+
<DropdownMenuSeparator />
162+
<DropdownMenuItem
163+
className={accountMenuItemClassName}
164+
render={
165+
<Link hash={COMPUTER_SECTION.connection} to="/settings/computer" />
166+
}
167+
>
168+
<IconArrowsExchange />
169+
Connect to an OpenBot
170+
</DropdownMenuItem>
171+
</>
172+
);
173+
}
174+
138175
/**
139176
* The account at the strip's foot, and the menu it opens. Whose account it is (name and email),
140177
* then a short list: the organization being worked in, which opens the switcher; the account's
141178
* pages (Admin for an admin, Settings); Help, which holds Get the desktop app, Get troubleshooting
142-
* logs and the version; and Sign out.
179+
* logs and the version; and Sign out. With OpenBot on this computer, there is no sign-in to end:
180+
* the row says where OpenBot runs, and Connect to an OpenBot takes Sign out's place.
143181
*
144182
* OpenBot for Business is offered only outside a shared organization: somebody working in one
145183
* already has what it describes.
@@ -204,6 +242,7 @@ function StripAccount() {
204242
</DropdownMenuItem>
205243
))}
206244
<HelpMenu itemClassName={accountMenuItemClassName} />
245+
{signOutOffered ? null : <ConnectInsteadItem />}
207246
{signOutOffered ? (
208247
<>
209248
<DropdownMenuSeparator />

‎app/src/components/settings/connection-sections.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ export function ConnectInsteadSection({
182182
const change = useMutation(changeConnectionMutationOptions());
183183
const leaving = change.isPending || change.isSuccess;
184184
return (
185-
<PageSection title="Connection">
185+
// The account menu's Connect to an OpenBot opens the page here.
186+
<PageSection id={COMPUTER_SECTION.connection} title="Connection">
186187
<PageRows>
187188
{moveToCloud ? (
188189
<>

‎app/src/lib/settings/computer-sections.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { useEffect } from "react";
1010
export const COMPUTER_SECTION = {
1111
thisComputer: "this-computer",
1212
browsers: "browsers",
13+
/** Where to connect to an OpenBot that runs somewhere else, opened from the account menu. */
14+
connection: "connection",
1315
} as const;
1416

1517
/** What the person does to move the page themselves, after which it is theirs to scroll. */

‎app/tests/app-navigation.test.tsx‎

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ function renderSidebar(
9393
me?: Record<string, unknown>,
9494
/** OpenBot Cloud: people sign in with their OpenBot by CopilotKit account (`hostedSignIn`). */
9595
hostedSignIn = false,
96+
/** Who the person is, in place of Maya Chen. */
97+
who?: { name: string; email: string; needsName?: boolean },
9698
) {
9799
const queryClient = new QueryClient({
98100
defaultOptions: { queries: { retry: false, staleTime: Infinity } },
@@ -111,6 +113,7 @@ function renderSidebar(
111113
email: "maya@example.com",
112114
role,
113115
onboarding: null,
116+
...who,
114117
};
115118
if (me) {
116119
globalThis.fetch = Object.assign(
@@ -569,6 +572,115 @@ test("a single-person install has no Sign out, because nobody signed in", async
569572
expect(within(menu).getAllByRole("menuitem").length).toBeGreaterThan(0);
570573
});
571574

575+
/*
576+
* Reported from OpenBot Desktop with OpenBot on this computer: the account menu said
577+
* "dev@openbot.local" under the person's name, read as the account she was signed in with, and she
578+
* looked for Sign out to sign in with another. Nobody signs in there: the email is the server's
579+
* stand-in for the one person. The row says where OpenBot runs instead, and where Sign out would be,
580+
* Connect to an OpenBot opens Settings → Computer at its connection choices.
581+
*/
582+
const STAND_IN = "dev@openbot.local";
583+
584+
/** OpenBot Desktop as the page meets it, with OpenBot on this computer and a build that can connect. */
585+
function insideDesktop(connection: Record<string, unknown>) {
586+
const shell = window as { __TAURI_INTERNALS__?: unknown };
587+
shell.__TAURI_INTERNALS__ = {
588+
invoke: async (command: string) => {
589+
if (command === "plugin:openbot-desktop|connection") return connection;
590+
throw `Command ${command} not found`;
591+
},
592+
transformCallback: () => 0,
593+
};
594+
return () => {
595+
delete shell.__TAURI_INTERNALS__;
596+
};
597+
}
598+
599+
test("with OpenBot on this computer, the account menu says so in place of the stand-in email, and offers Connect to an OpenBot", async () => {
600+
const leave = insideDesktop({ mode: "local", address: null });
601+
try {
602+
const { view, user } = renderSidebar(
603+
"admin",
604+
"personal",
605+
undefined,
606+
false,
607+
{
608+
name: "Sofía",
609+
email: STAND_IN,
610+
},
611+
);
612+
await user.click(await view.findByRole("button", { name: /Sofía/ }));
613+
const menu = await view.findByRole("menu");
614+
const row = menu.querySelector('[data-slot="account-row"]');
615+
expect(row?.textContent).toContain("Sofía");
616+
expect(row?.textContent).toContain("OpenBot runs on this computer");
617+
expect(menu.textContent).not.toContain(STAND_IN);
618+
const connect = await within(menu).findByRole("menuitem", {
619+
name: "Connect to an OpenBot",
620+
});
621+
expect(connect.getAttribute("href")).toBe("/settings/computer#connection");
622+
// Last, where Sign out is when there is a sign-in, and there is none here.
623+
const items = within(menu).getAllByRole("menuitem");
624+
expect(items.at(-1)).toBe(connect);
625+
expect(
626+
within(menu).queryByRole("menuitem", { name: "Sign out" }),
627+
).toBeNull();
628+
} finally {
629+
leave();
630+
}
631+
});
632+
633+
test("with OpenBot on this computer and no name given yet, the menu never names the person by the stand-in email", async () => {
634+
// Until a name is given, the server's name for the person is the stand-in email too.
635+
const { view, user } = renderSidebar("admin", "personal", undefined, false, {
636+
name: STAND_IN,
637+
email: STAND_IN,
638+
needsName: true,
639+
});
640+
const account = await view.findByRole("button", { name: /You/ });
641+
expect(account.textContent).not.toContain(STAND_IN);
642+
expect(account.textContent).not.toContain("DE");
643+
await user.click(account);
644+
const menu = await view.findByRole("menu");
645+
const row = menu.querySelector('[data-slot="account-row"]');
646+
expect(row?.textContent).toContain("You");
647+
expect(row?.textContent).toContain("OpenBot runs on this computer");
648+
expect(menu.textContent).not.toContain(STAND_IN);
649+
});
650+
651+
test("OpenBot on this computer in a plain browser, or a desktop app that can't connect, offers no Connect to an OpenBot", async () => {
652+
const { view, user } = renderSidebar("admin", "personal");
653+
await user.click(await view.findByRole("button", { name: /Maya Chen/ }));
654+
const menu = await view.findByRole("menu");
655+
expect(menu.textContent).toContain("OpenBot runs on this computer");
656+
expect(
657+
within(menu).queryByRole("menuitem", { name: "Connect to an OpenBot" }),
658+
).toBeNull();
659+
});
660+
661+
test("OpenBot Desktop connected to an OpenBot elsewhere keeps the email and Sign out, with no Connect to an OpenBot", async () => {
662+
const leave = insideDesktop({
663+
mode: "connected",
664+
address: "https://openbot.example.com",
665+
});
666+
try {
667+
const { view, user } = renderSidebar("user", "team", undefined, true);
668+
await user.click(await view.findByRole("button", { name: /Maya Chen/ }));
669+
const menu = await view.findByRole("menu");
670+
const row = menu.querySelector('[data-slot="account-row"]');
671+
expect(row?.textContent).toContain("maya@example.com");
672+
expect(row?.textContent).not.toContain("OpenBot runs on this computer");
673+
expect(
674+
within(menu).getByRole("menuitem", { name: "Sign out" }),
675+
).toBeTruthy();
676+
expect(
677+
within(menu).queryByRole("menuitem", { name: "Connect to an OpenBot" }),
678+
).toBeNull();
679+
} finally {
680+
leave();
681+
}
682+
});
683+
572684
test("the sidebar has no command palette row: Cmd/Ctrl+K opens it", async () => {
573685
const { view } = renderSidebar("user");
574686
await view.findByRole("link", { name: "Routines" });

0 commit comments

Comments
 (0)