Skip to content
Merged
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
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ jobs:
# sign-in through Composio held on OpenBot's own step for its countdown before it
# leaves, in this tab and in the new one a Bot's card opens, a picture over 8MB fetched
# only when it is opened, counted on the wire, and the AI connection changed in Settings, a
# key the provider refuses saying why and changing nothing. The
# key the provider refuses saying why and changing nothing, and on OpenBot Cloud a person
# held at Connect your AI until they connect their own. The
# onboarding frame reads the generated app config, which `bun test` alone doesn't write (the
# test script's pretest does).
- run: bun run generate:app-config
Expand All @@ -378,7 +379,7 @@ jobs:
--volume "$(command -v bun):/usr/local/bin/bun:ro" \
--env OPENBOT_APP_BROWSER=1 \
"$PLAYWRIGHT_IMAGE" \
bun test --parallel app/tests/tool-line-reduced-motion.test.tsx app/tests/onboarding-window-buttons.test.tsx app/tests/onboarding-orb-room.test.tsx app/tests/transcript-rail-clearance.test.tsx app/tests/a2ui-frame.test.tsx app/tests/update-banner-layout.test.tsx app/tests/composer-dictation-notice-layout.test.tsx app/tests/conversation-intro-halo.test.tsx app/tests/transcript-room.test.tsx app/tests/skins-window-buttons.test.tsx app/tests/opendots-rail-badge.test.tsx app/tests/account-version-layout.test.tsx app/tests/organization-menu-names.test.tsx app/tests/bot-orb-one-color.test.tsx app/tests/compact-avatar-layout.test.tsx app/tests/theme-follows-system.test.tsx app/tests/desktop-window-theme.test.tsx app/tests/bot-screen-record-layout.test.tsx app/tests/teams-screens-layout.test.tsx app/tests/team-grants-screens-layout.test.tsx app/tests/needs-you-board-layout.test.tsx app/tests/checkbox-contrast.test.tsx app/tests/maths-rendering.test.tsx app/tests/task-report-chip.test.tsx app/tests/consent-handoff.test.tsx app/tests/large-picture-tile.test.tsx app/tests/audit-computer-limit-layout.test.tsx app/tests/ai-connection-dialog.test.tsx
bun test --parallel app/tests/tool-line-reduced-motion.test.tsx app/tests/onboarding-window-buttons.test.tsx app/tests/onboarding-orb-room.test.tsx app/tests/transcript-rail-clearance.test.tsx app/tests/a2ui-frame.test.tsx app/tests/update-banner-layout.test.tsx app/tests/composer-dictation-notice-layout.test.tsx app/tests/conversation-intro-halo.test.tsx app/tests/transcript-room.test.tsx app/tests/skins-window-buttons.test.tsx app/tests/opendots-rail-badge.test.tsx app/tests/account-version-layout.test.tsx app/tests/organization-menu-names.test.tsx app/tests/bot-orb-one-color.test.tsx app/tests/compact-avatar-layout.test.tsx app/tests/theme-follows-system.test.tsx app/tests/desktop-window-theme.test.tsx app/tests/bot-screen-record-layout.test.tsx app/tests/teams-screens-layout.test.tsx app/tests/team-grants-screens-layout.test.tsx app/tests/needs-you-board-layout.test.tsx app/tests/checkbox-contrast.test.tsx app/tests/maths-rendering.test.tsx app/tests/task-report-chip.test.tsx app/tests/consent-handoff.test.tsx app/tests/large-picture-tile.test.tsx app/tests/audit-computer-limit-layout.test.tsx app/tests/ai-connection-dialog.test.tsx app/tests/connect-your-ai.test.tsx

# Dictation in the Desktop window on a Mac whose recognizer has no English (United Kingdom) on
# the device, in Chromium and in WebKit, the engine the Mac window draws with: it listens in the
Expand Down
23 changes: 23 additions & 0 deletions app/src/components/channels/add-model-key-link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,42 @@ import { queryClient } from "@/query-client";
export const NO_AI_CONNECTION =
"This organization doesn't have an AI connection yet. An admin can add a model key in Admin, under Vault.";

/**
* What the server says on OpenBot Cloud when a run has no AI, word for word: the person has none of
* their own and their organization has none for everyone. Anybody can fix it, by connecting theirs.
*/
export const NO_PERSONAL_AI_CONNECTION =
"Connect your AI to use Bots. An admin can also set one up for everyone in your organization.";

/** Where a person connects their own AI: onboarding's Connect your AI step. */
export const CONNECT_YOUR_AI_PATH = "/onboarding?step=ai";

/** Where an admin adds the key: a new credential in Admin, under Vault. */
export const ADD_MODEL_KEY_PATH = "/admin/credentials/new";

/**
* Add a model key, beside the sentence that says there is none: where the admin already is when
* they find out. Only for an admin of the organization; a member reads the sentence, which tells
* them who to ask. Named query client, as everything drawn inside a conversation.
*
* On OpenBot Cloud the sentence is the person's own to fix, so everybody gets Connect your AI,
* which opens the step onboarding has for it. A whole page load, so the step reads the person's AI
* connection afresh.
*/
export function AddModelKeyLink({ reason }: { reason: string }) {
const me = useQuery(
{ ...currentUserQueryOptions(), enabled: reason === NO_AI_CONNECTION },
queryClient,
).data;
if (reason === NO_PERSONAL_AI_CONNECTION)
return (
<a
className={cn(buttonVariants({ size: "sm", variant: "outline" }))}
href={CONNECT_YOUR_AI_PATH}
>
Connect your AI
</a>
);
if (reason !== NO_AI_CONNECTION || !isOrganizationAdmin(me?.role))
return null;
return (
Expand Down
211 changes: 211 additions & 0 deletions app/src/components/onboarding/ai-step.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
import { IconBuilding, IconChevronRight } from "@tabler/icons-react";
import { useQuery } from "@tanstack/react-query";
import { useId, useState } from "react";
import { useSignOut } from "@/components/app-sidebar/use-sign-out";
import { useSwitchOrganization } from "@/components/organizations/use-switch-organization";
import {
Item,
ItemActions,
ItemContent,
ItemMedia,
ItemTitle,
} from "@/components/ui/item";
import { currentUserQueryOptions } from "@/lib/auth/queries";
import { useOrganizationChoices } from "@/lib/organizations/queries";
import {
ChooseConnection,
ChooserCard,
ConnectedRow,
} from "@/components/settings/ai-connection-chooser";
import { Button } from "@/components/ui/button";
import {
type PersonalAiConnection,
personalAiConnectionQueryOptions,
} from "@/lib/ai-connection/queries";
import { StepIntro } from "./onboarding-frame";
import type { OnboardingStep } from "./onboarding-wizard";

/**
* Onboarding's Connect your AI step, on an OpenBot that provides no AI of its own (OpenBot Cloud):
* the person connects their own before they use OpenBot, with a key or an address, or by signing in
* to a provider the server can sign them in to. Theirs alone: it follows them into every
* organization they are in and is never shared with any of them.
*
* ONLY WHERE IT IS NEEDED, AND NO WAY PAST IT. The route puts the step in the list only when the
* server says one is required and this person's runs have none (`needsAiConnection`); somebody whose
* organization already has an AI never sees it, and adds their own later in Settings. Until the
* server says a connection is in use, the step's button is disabled and there is no Not now.
*
* THE CHOOSER IS SETTINGS' OWN, ON THE PAGE. The same provider list, ways in and checks as
* Settings' AI connection dialog (ai-connection-chooser.tsx), in its personal mode, drawn in a card
* where the other steps draw their picture: beside the words on a desktop, under them on a phone.
*/
export function useAiStep(): OnboardingStep {
const personal = useQuery(personalAiConnectionQueryOptions());
const connected = personal.data ? personal.data.uses !== "none" : false;
return {
id: "ai",
title: "Connect your AI",
/*
* The way out sits with the words on a desktop, beside the chooser, and under the chooser on a
* phone, where the column reads top to bottom and connecting is what the step is for. Drawn in
* one place or the other, never both: the hidden one is `display: none`, out of reach.
*/
intro: () => (
<StepIntro
after={
<div className="max-lg:hidden">
<WayOut />
</div>
}
>
<p>
Bots need an AI model to work. Connect your own by signing in or with
an API key. It's personal to you and never shared with your
organization.
</p>
<p>You can change it anytime in Settings.</p>
</StepIntro>
),
demo: () =>
personal.data ? (
<div className="flex flex-col gap-8">
<AiChooserPane personal={personal.data} />
{/*
* Room below it for the fade above the phone's pinned buttons (`before:h-8` in the frame's
* footer) and the frame's 16px gutter past it, so scrolled to the end, Sign out reads
* clear of it.
*/}
<div className="pb-12 lg:hidden">
<WayOut />
</div>
</div>
) : null,
primaryDisabled: !connected,
};
}

/**
* THE WAY OUT THAT ISN'T A SKIP. Somebody in more than one organization may be here because the
* one they are working in has no AI, while another of theirs has one for everyone: they can work
* there instead, by the same switch as the account menu's. And anybody can sign out. Both sit with
* the words, under the sentence, as Welcome's one setting does.
*/
function WayOut() {
const headingId = useId();
const choices = useOrganizationChoices();
const switching = useSwitchOrganization();
const signOut = useSignOut();
const email = useQuery(currentUserQueryOptions()).data?.email;
const others =
choices?.organizations.filter((one) => one.id !== choices.currentId) ?? [];
return (
<section
aria-label="Other ways on"
className="flex flex-col gap-3 text-left"
>
{others.length > 0 ? (
<>
<div className="flex flex-col gap-1">
<h2 className="text-lg font-semibold text-pretty" id={headingId}>
Or work in another organization
</h2>
<p className="text-pretty text-muted-foreground">
If one of them has an AI for everyone, Bots can use it there.
</p>
</div>
<fieldset
aria-labelledby={headingId}
className="m-0 flex min-w-0 flex-col gap-2 border-0 p-0"
>
{others.map((organization) => (
<Item
className="text-left"
key={organization.id}
render={
<button
disabled={switching.pending}
onClick={() => switching.run(organization.id)}
type="button"
/>
}
size="sm"
variant="outline"
>
<ItemMedia variant="icon">
<IconBuilding />
</ItemMedia>
<ItemContent>
<ItemTitle className="[overflow-wrap:anywhere]">
{organization.name}
</ItemTitle>
</ItemContent>
<ItemActions>
<IconChevronRight className="size-4 text-muted-foreground" />
</ItemActions>
</Item>
))}
</fieldset>
</>
) : null}
<div className="flex min-w-0 items-center justify-between gap-3 text-sm text-muted-foreground">
<span className="min-w-0 truncate">
{email ? `Signed in as ${email}` : null}
</span>
<Button
className="-me-2.5 shrink-0"
disabled={signOut.pending}
onClick={signOut.run}
size="sm"
type="button"
variant="ghost"
>
{signOut.pending ? "Signing out…" : "Sign out"}
</Button>
</div>
</section>
);
}

/** The chooser, or once connected, what is connected and a way to change it. */
function AiChooserPane({ personal }: { personal: PersonalAiConnection }) {
const [changing, setChanging] = useState(false);
const connected = personal.uses !== "none";
return (
<div className="mx-auto w-full max-w-lg">
<ChooserCard>
{connected && !changing ? (
<div className="flex flex-col gap-4">
{personal.uses === "personal" ? (
<ConnectedRow connection={personal.connection} />
) : (
<p className="text-sm">
Bots use the AI your organization set up.
</p>
)}
<p className="text-sm text-muted-foreground">
Bots use it when they work for you.
</p>
<div className="flex justify-end">
<Button
onClick={() => setChanging(true)}
size="sm"
type="button"
variant="ghost"
>
Change
</Button>
</div>
</div>
) : (
<ChooseConnection
connection={personal.connection}
mode={{ kind: "personal", signIns: personal.signIns }}
onBack={connected ? () => setChanging(false) : undefined}
onConnected={() => setChanging(false)}
/>
)}
</ChooserCard>
</div>
);
}
22 changes: 20 additions & 2 deletions app/src/components/organizations/organization-boundary.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { useNavigate } from "@tanstack/react-router";
import { useNavigate, useRouter } from "@tanstack/react-router";
import { Fragment, type ReactNode, useEffect } from "react";
import { useCurrentOrganizationId } from "@/lib/organizations/current";
import {
onOrganizationChange,
useCurrentOrganizationId,
} from "@/lib/organizations/current";
import { onSwitchedElsewhere } from "@/lib/organizations/queries";

/**
Expand All @@ -11,9 +14,16 @@ import { onSwitchedElsewhere } from "@/lib/organizations/queries";
* conversation, a draft, a list it had drawn) is carried from one organization into another.
*
* It also says how a switch made in another window is followed here: from home.
*
* AND THE GATES DECIDE AGAIN, IN THE NEW ONE. A switch takes the person home while the app still
* works in the organization they are leaving, so the signed-in gate (`_authed`) and onboarding's
* decided on that one's answers. Once the app has changed over (and dropped what it held for the
* old one, query-client.ts), the routes on screen load again, and their gates ask the new one:
* somebody who has to connect their own AI there is sent to do it at once, not on their next click.
*/
export function OrganizationBoundary({ children }: { children: ReactNode }) {
const navigate = useNavigate();
const router = useRouter();
// A switch made in another window is followed from home, as a switch made here is.
useEffect(
() =>
Expand All @@ -22,5 +32,13 @@ export function OrganizationBoundary({ children }: { children: ReactNode }) {
}),
[navigate],
);
useEffect(
() =>
onOrganizationChange((next, previous) => {
if (next === undefined || previous === undefined) return;
void router.invalidate();
}),
[router],
);
return <Fragment key={useCurrentOrganizationId()}>{children}</Fragment>;
}
Loading
Loading