diff --git a/app/src/components/channels/composer/composer.tsx b/app/src/components/channels/composer/composer.tsx
index e19f5b264b..f55bce782b 100644
--- a/app/src/components/channels/composer/composer.tsx
+++ b/app/src/components/channels/composer/composer.tsx
@@ -30,6 +30,7 @@ import {
} from "react";
import { attachmentModality } from "@/components/channels/chat-messages";
import { IconWaveform } from "@/components/icons/waveform";
+import { TrialNote } from "@/components/plan/trial-note";
import { useTouchTyping } from "@/hooks/use-touch-typing";
import {
attachmentAddress,
@@ -2092,6 +2093,8 @@ export function Composer({
+ {/* Under the box once most of the free trial is used: components/plan/trial-note.tsx. */}
+
);
}
@@ -2191,6 +2194,7 @@ export function Composer({
+
{/* The notice's invisible copy, below the box: see above. Hidden from everyone and inert. */}
Plan
-
>
diff --git a/app/src/components/plan/card-needed-dialog.tsx b/app/src/components/plan/card-needed-dialog.tsx
index 01dedfe2da..ffe1ddeba4 100644
--- a/app/src/components/plan/card-needed-dialog.tsx
+++ b/app/src/components/plan/card-needed-dialog.tsx
@@ -1,7 +1,10 @@
import { useQuery } from "@tanstack/react-query";
-import { useEffect, useRef, useSyncExternalStore } from "react";
+import { Fragment, useEffect, useRef, useSyncExternalStore } from "react";
import sentry from "@/assets/sentry.webp";
-import { buttonVariants } from "@/components/ui/button";
+import { AbstractAvatar } from "@/components/agents/abstract-avatar";
+import { IconCheck, IconPlayerPause } from "@/components/icons";
+import { PersonAvatar } from "@/components/organizations/person-avatar";
+import { Button, buttonVariants } from "@/components/ui/button";
import {
Dialog,
DialogBody,
@@ -11,12 +14,31 @@ import {
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
+import {
+ Item,
+ ItemActions,
+ ItemContent,
+ ItemDescription,
+ ItemFooter,
+ ItemGroup,
+ ItemMedia,
+ ItemTitle,
+} from "@/components/ui/item";
import {
Progress,
ProgressLabel,
ProgressValue,
} from "@/components/ui/progress";
+import { Separator } from "@/components/ui/separator";
+import { type AgentProfile, agentListQueryOptions } from "@/lib/agents/queries";
import { currentUserQueryOptions } from "@/lib/auth/queries";
+import { useCurrentOrganizationId } from "@/lib/organizations/current";
+import {
+ type OrganizationMemberSummary,
+ useCurrentOrganizationName,
+ useOrganizationAdmins,
+} from "@/lib/organizations/queries";
+import { roleName } from "@/lib/organizations/words";
import {
cardNeededShown,
hideCardNeeded,
@@ -29,26 +51,34 @@ import {
import {
employeeTrialUsedUp,
needsCard,
+ type PlanStatus,
planKeys,
planQueryOptions,
trialUsedUp,
} from "@/lib/plan/queries";
import {
cardAction,
+ coversEveryone,
+ employeeStoppedWords,
+ PLAN_CARD,
+ PRICE_AMOUNT,
+ PRICE_PER,
SENTRY_ALT,
SENTRY_LINE,
+ type StoppedWords,
stoppedWords,
trialUsed,
} from "@/lib/plan/words";
-import { useCurrentOrganizationId } from "@/lib/organizations/current";
import { cn } from "@/lib/utils";
import { queryClient } from "@/query-client";
/**
* Bots can't run until a card is added: the free trial is used up, or the last payment failed.
- * Says so plainly, with the size of the trial the server sent and what OpenBot costs from here, and
- * gives an admin the one way on (`addCardUrl`, the server's verdict on who may add a card). A member
- * is told who to ask.
+ * Top to bottom: the person's Bots, faded, marked Paused; the title, and a line with the size of
+ * the trial the server sent, how many Bots that paused and that nothing is lost; the trial's bar,
+ * full. An admin then gets a plan card (the price and what adding the card does) and the one way
+ * on (`addCardUrl`, the server's verdict on who may add a card) with Not now beside it. A member gets the owners and admins to ask, as rows
+ * (`useOrganizationAdmins`), and Got it. A failed payment has no bar and no plan card.
*
* One for the whole app, mounted once in the signed-in layout so every skin, and OpenBot Desktop's
* window, which shows the same app, has it. It opens by itself once for a person in an
@@ -115,52 +145,238 @@ export function CardNeededDialog() {
: plan && needsCard(plan)
? plan.addCardUrl
: refusalAddCardUrl();
- const words = stoppedWords(plan, addCardUrl);
+ const stopped = open && !employee;
+ // The person's own Bots, from the list the sidebar reads: what the stop paused. Not the Bots
+ // shared with them, which aren't theirs to call paused.
+ const bots = useQuery({
+ ...agentListQueryOptions(),
+ enabled: stopped && known,
+ }).data?.filter((bot) => bot.mine);
+ const words = stoppedWords(plan, addCardUrl, bots?.length);
+ // A member is told who to ask by name: the organization's owners and admins, read only for them.
+ const admins = useOrganizationAdmins(stopped && words.ask !== null);
+ // Focus starts on the way on, as it did before Not now stood in front of it.
+ const pay = useRef(null);
return (
);
}
+
+/** How many Bots are drawn before the rest are counted ("+2"). */
+const BOTS_SHOWN = 4;
+
+/**
+ * The person's Bots, faded and overlapping, with a Paused pill: what the stop means, shown. Up to
+ * four, and the rest counted.
+ */
+function PausedBots({ bots }: { bots: readonly AgentProfile[] }) {
+ const shown = bots.slice(0, BOTS_SHOWN);
+ const more = bots.length - shown.length;
+ return (
+
+ );
+}
+
+/**
+ * For an admin, what adding a card does: the price and two lines that are true today. No monthly
+ * total: the plan API sends no billed seat count, and the members list includes people who may not
+ * be billed, so a total worked out here could disagree with the bill.
+ */
+function PlanCard() {
+ const name = useCurrentOrganizationName();
+ return (
+
+
+ {PLAN_CARD.title}
+
+
+
+
+ {PRICE_AMOUNT}
+ {" "}
+ {PRICE_PER}
+
+
+ {/* The full width under the title and the price, so each line fits on one. */}
+
+
+
+
+ );
+}
+
+/** How many admins are listed before the rest are counted. */
+const ADMINS_SHOWN = 3;
+
+/**
+ * For a member, who to ask: the organization's owners and admins as rows, with their role. With
+ * nobody to name (still being read, or couldn't be), the sentence stands on its own.
+ */
+function AdminsToAsk({
+ admins,
+ ask,
+}: {
+ admins: readonly OrganizationMemberSummary[];
+ ask: NonNullable;
+}) {
+ if (admins.length === 0)
+ return
+ );
+}
+
+/**
+ * A CopilotKit employee's dialog once their free trial is used up, as it was asked for: the same
+ * news and the full bar, a thank-you in place of the way to pay, and a photo of Sentry, loaded only
+ * here. Only a way to close.
+ */
+function EmployeeContent({ plan }: { plan: PlanStatus | undefined }) {
+ const words = employeeStoppedWords(plan);
+ return (
+
+
+ {words.title}
+ {words.said}
+
+
+ {/* The same bar as the Plan row in Settings, full. */}
+
+ Free trial
+ {() => trialUsed(100)}
+
+
{words.next}
+ {/* Drawn only here, and lazily, so nobody else ever downloads it. */}
+
+
{SENTRY_LINE}
+
+
+ );
+}
diff --git a/app/src/components/plan/trial-note.tsx b/app/src/components/plan/trial-note.tsx
new file mode 100644
index 0000000000..2650b90e2d
--- /dev/null
+++ b/app/src/components/plan/trial-note.tsx
@@ -0,0 +1,42 @@
+import { useQuery } from "@tanstack/react-query";
+import { currentUserQueryOptions } from "@/lib/auth/queries";
+import { isOrganizationAdmin } from "@/lib/auth/roles";
+import { trialRunningLow, usePlan } from "@/lib/plan/queries";
+import { runningLowWords } from "@/lib/plan/words";
+import { queryClient } from "@/query-client";
+
+/**
+ * One quiet line under the message box once most of the free trial is used
+ * (`trialRunningLow`): "82% of your free trial used · Add a card". So the first word about the
+ * limit comes before Bots stop, not as the dialog after.
+ *
+ * The link is the server's verdict on who may add a card (`addCardUrl`). A member is told to ask
+ * an admin. An admin the server sent no link yet is told what happens at 100%. Nothing while the
+ * plan is read, past the trial (the bar over the page and the dialog say it), or for a CopilotKit
+ * employee. Named query client, as everything drawn inside a conversation.
+ */
+export function TrialNote() {
+ const plan = usePlan({ client: queryClient });
+ const role = useQuery(currentUserQueryOptions(), queryClient).data?.role;
+ if (!plan || !trialRunningLow(plan)) return null;
+ const words = runningLowWords(plan, isOrganizationAdmin(role));
+ return (
+
+ );
+}
diff --git a/app/src/lib/plan/queries.ts b/app/src/lib/plan/queries.ts
index 52aa0792a3..a6e5667701 100644
--- a/app/src/lib/plan/queries.ts
+++ b/app/src/lib/plan/queries.ts
@@ -96,6 +96,24 @@ export function trialUsedUp(plan: PlanStatus | undefined): boolean {
);
}
+/** From how much of the free trial used the message box and the Plan row say it is running out. */
+export const RUNNING_LOW_PERCENT = 80;
+
+/**
+ * Whether most of the free trial is used but runs are still left: the message box warns, and the
+ * Plan row offers the card where the server sent the way to add one. Never for a CopilotKit
+ * employee, whose runs never stop.
+ */
+export function trialRunningLow(plan: PlanStatus | undefined): boolean {
+ return (
+ plan?.required === true &&
+ plan.status === "free" &&
+ plan.copilotKitEmployee !== true &&
+ typeof plan.freeRunsUsedPercent === "number" &&
+ plan.freeRunsUsedPercent >= RUNNING_LOW_PERCENT
+ );
+}
+
/**
* Whether a CopilotKit employee who is an owner or an admin can pay for the organization's other
* members: their own plan reads `free`, but the server sends the payment page (`addCardUrl`) when
diff --git a/app/src/lib/plan/words.ts b/app/src/lib/plan/words.ts
index e687c074d4..84b6d4bd3f 100644
--- a/app/src/lib/plan/words.ts
+++ b/app/src/lib/plan/words.ts
@@ -1,4 +1,4 @@
-import { employeeTrialUsedUp, type PlanStatus, trialUsedUp } from "./queries";
+import { type PlanStatus, trialUsedUp } from "./queries";
/** The date in the person's own words: "20 Dec 2026". */
function onDate(at: string): string {
@@ -9,8 +9,38 @@ function onDate(at: string): string {
});
}
-/** What OpenBot costs once the free trial is used up, as every screen says it. */
-export const PRICE = "$5 a month for each member of this organization";
+/** What OpenBot costs a member for a month, in dollars, once the free trial is used up. */
+const PRICE_DOLLARS = 5;
+
+/** What OpenBot costs a member for a month: "$5". */
+export const PRICE_AMOUNT = `$${PRICE_DOLLARS}`;
+
+/** What OpenBot costs once the free trial is used up, as every screen says it in a sentence. */
+export const PRICE = `${PRICE_AMOUNT} a month for each member of this organization`;
+
+/** After the price on the dialog's plan card: "$5 per member a month". */
+export const PRICE_PER = "per member a month";
+
+/** The dialog's plan card, for an admin: its name, and only what adding the card does. */
+export const PLAN_CARD = {
+ title: "Keep your Bots running",
+ runsAgain: "Your Bots run again as soon as the card is added",
+} as const;
+
+/** The plan card's second line: "Covers everyone in Acme". */
+export function coversEveryone(organizationName: string | undefined): string {
+ return `Covers everyone in ${organizationName?.trim() || "this organization"}`;
+}
+
+/** Under the admins a member is told to ask, while the free trial is what stopped them. */
+export const PRICE_FOR_EACH = `It's ${PRICE_AMOUNT} ${PRICE_PER}.`;
+
+/** Said wherever Bots stop for want of a card, so nobody thinks their work is gone. */
+export const NOTHING_LOST = "Your Bots, conversations and memory are all kept.";
+
+/** Under the Plan row's bar while runs are left: what happens at 100%. */
+export const WHEN_USED_UP =
+ "When it's used up, Bots pause until a card is added.";
/**
* Said to a CopilotKit employee once their free trial is used up, in place of the way to pay: their
@@ -23,8 +53,7 @@ export const COPILOTKIT_EMPLOYEE_LINE =
* On the Plan row, for a CopilotKit employee who is an admin of an organization whose other members
* need a card: their own runs are free, everyone else's aren't.
*/
-export const OTHERS_NEED_A_CARD =
- "Everyone else in this organization needs a card added to keep their Bots running. It's $5 a month for each member.";
+export const OTHERS_NEED_A_CARD = `Everyone else in this organization needs a card added to keep their Bots running. It's ${PRICE_AMOUNT} a month for each member.`;
/** Under the photo of Sentry that follows that line, word for word as it was asked for. */
export const SENTRY_LINE = "Sentry loves you too.";
@@ -58,9 +87,14 @@ export function blockedNotice(plan: PlanStatus): string {
: "You've used your free trial. Ask an admin to add a card to keep your Bots running.";
}
+/** "42%", whole and between 0 and 100. */
+function percentOf(percent: number): string {
+ return `${Math.min(100, Math.max(0, Math.round(percent)))}%`;
+}
+
/** "42% used": how much of the free trial is gone, never the count or the cap. */
export function trialUsed(percent: number): string {
- return `${Math.min(100, Math.max(0, Math.round(percent)))}% used`;
+ return `${percentOf(percent)} used`;
}
/** What the Plan row on the organization's settings says about where it stands. */
@@ -85,45 +119,120 @@ export function planSummary(plan: PlanStatus): string {
/** What the dialog that stops an AI action says, for the plan that stopped it. */
export type StoppedWords = {
title: string;
- /** What happened, and what it costs from here. */
+ /** What happened, the Bots it paused, and that nothing is lost. One paragraph under the title. */
said: string;
- /** What the reader does next: add the card, or ask who can. */
- next: string;
+ /** Whether the free trial's bar shows, full: once it is used up, not for a failed payment. */
+ meter: boolean;
+ /** Whether an admin sees the plan card with the price: the free trial, not a failed payment. */
+ plan: boolean;
+ /**
+ * For a member, who can't add the card: the label over the admins to ask, the sentence said alone
+ * when no admin can be named, and a line under the admins. Null for an admin, whose button says
+ * what to do.
+ */
+ ask: { label: string; alone: string; note: string | null } | null;
};
/**
* The dialog's words. Once the free trial is used up it names the allowance the server sent
- * (`freeRunsAllowance`, never sent before then), says what OpenBot costs from here, and tells an
- * admin to add a card and a member who to ask. A failed payment says so instead.
+ * (`freeRunsAllowance`, never sent before then) and how many Bots that paused, and says the
+ * person's work is kept. An admin's button says what to do; a member is told to ask an admin. A
+ * failed payment says so instead, with no bar and no price.
*/
export function stoppedWords(
plan: PlanStatus | undefined,
/** Where the reader adds a card: only an owner or an admin is sent one. */
addCardUrl: string | null | undefined = plan?.addCardUrl,
+ /** How many of the person's Bots are paused, once their list is read. */
+ bots?: number,
): StoppedWords {
const admin = Boolean(addCardUrl);
if (plan?.status === "past_due")
return {
title: "Your last payment didn't go through",
- said: "Bots can't run until this organization's card is updated.",
- next: admin
- ? "Update the card to keep your Bots running."
- : "Ask an admin of this organization to update the card.",
+ said: `Bots can't run until this organization's card is updated. ${NOTHING_LOST}`,
+ meter: false,
+ plan: false,
+ ask: admin
+ ? null
+ : {
+ label: "Ask an admin to update the card",
+ alone: "Ask an admin of this organization to update the card.",
+ note: null,
+ },
};
- const allowance = plan?.freeRunsAllowance;
// The title as the bar and the server's refusal begin, so the three read as one.
return {
title: "You've used your free trial",
- said: `${
- typeof allowance === "number"
- ? `Your free trial was ${allowance.toLocaleString()} Bot runs, and they're all used.`
- : "All the Bot runs in your free trial are used."
- } From now on, OpenBot is ${PRICE}.`,
- // The same words as everyone's, but a CopilotKit employee never pays: no card, nobody to ask.
- next: employeeTrialUsedUp(plan)
- ? COPILOTKIT_EMPLOYEE_LINE
- : admin
- ? "Add a card to keep your Bots running."
- : "Ask an admin of this organization to add a card.",
+ said: `${allUsedPaused(plan, bots)} ${NOTHING_LOST}`,
+ meter: true,
+ plan: admin,
+ ask: admin
+ ? null
+ : {
+ label: "Ask an admin to add a card",
+ alone: "Ask an admin of this organization to add a card.",
+ note: PRICE_FOR_EACH,
+ },
+ };
+}
+
+/**
+ * "All 50 Bot runs in your free trial are used, so your 6 Bots are paused.": the size where it was
+ * sent, and the Bots where they are known.
+ */
+function allUsedPaused(plan: PlanStatus | undefined, bots?: number): string {
+ const allowance = plan?.freeRunsAllowance;
+ const used =
+ typeof allowance === "number"
+ ? `All ${allowance.toLocaleString()} Bot runs in your free trial are used`
+ : "All the Bot runs in your free trial are used";
+ if (!bots) return `${used}.`;
+ return bots === 1
+ ? `${used}, so your Bot is paused.`
+ : `${used}, so your ${bots.toLocaleString()} Bots are paused.`;
+}
+
+/** "Your free trial was 500 Bot runs, and they're all used.", with the size where it was sent. */
+function allUsed(plan: PlanStatus | undefined): string {
+ const allowance = plan?.freeRunsAllowance;
+ return typeof allowance === "number"
+ ? `Your free trial was ${allowance.toLocaleString()} Bot runs, and they're all used.`
+ : "All the Bot runs in your free trial are used.";
+}
+
+/**
+ * The dialog's words for a CopilotKit employee whose free trial is used up: the same news, the
+ * price everyone else pays, and a thank-you in place of the way to pay. Kept as they were asked for.
+ */
+export function employeeStoppedWords(plan: PlanStatus | undefined): {
+ title: string;
+ said: string;
+ next: string;
+} {
+ return {
+ title: "You've used your free trial",
+ said: `${allUsed(plan)} From now on, OpenBot is ${PRICE}.`,
+ next: COPILOTKIT_EMPLOYEE_LINE,
+ };
+}
+
+/**
+ * The quiet note under the message box once most of the free trial is used (`trialRunningLow`):
+ * how much, then what to do. An admin with the way to add a card gets a link (`action`); a member
+ * is told to ask; an admin the server sent no way yet is told what happens at 100%.
+ */
+export function runningLowWords(
+ plan: PlanStatus,
+ admin: boolean,
+): { said: string; next: string | null; action: string | null } {
+ const said = `${percentOf(plan.freeRunsUsedPercent ?? 0)} of your free trial used`;
+ if (plan.addCardUrl) return { said, next: null, action: cardAction(plan) };
+ return {
+ said,
+ next: admin
+ ? "At 100%, Bots pause until a card is added"
+ : "Ask an admin to add a card",
+ action: null,
};
}
diff --git a/app/tests/plan-free-trial.test.tsx b/app/tests/plan-free-trial.test.tsx
index 74a15a3de7..60757b3f05 100644
--- a/app/tests/plan-free-trial.test.tsx
+++ b/app/tests/plan-free-trial.test.tsx
@@ -30,17 +30,17 @@ import { CardNeededDialog } from "@/components/plan/card-needed-dialog";
import { GoalPage } from "@/components/responsibilities/goal-page";
import { RoutinePage } from "@/components/routines/routine-page";
import type { OrganizationPlan } from "@/lib/api/generated/model";
+import { authKeys } from "@/lib/auth/queries";
import { stoppedReason } from "@/lib/copilot/stopped-turn";
import { setCurrentOrganization } from "@/lib/organizations/current";
import { organizationKeys } from "@/lib/organizations/queries";
-import { authKeys } from "@/lib/auth/queries";
import {
forgetCardNeededRefusal,
forgetTrialUsedUpAnnounced,
hideCardNeeded,
rememberTrialUsedUpAnnounced,
} from "@/lib/plan/card-needed";
-import { planKeys } from "@/lib/plan/queries";
+import { planKeys, stopIfNeedsCard } from "@/lib/plan/queries";
import type { ResponsibilityRecord } from "@/lib/responsibilities";
import type { RoutineRecord } from "@/lib/routines/queries";
import { queryClient } from "@/query-client";
@@ -69,6 +69,66 @@ let refuseRuns = false;
/** While set, the plan read waits for it: a server slow to answer. */
let planHeld: Promise | null = null;
const writes: string[] = [];
+/** The organization's members, as the members list answers them. */
+let members: {
+ id: string;
+ name: string | null;
+ email: string;
+ image: string | null;
+ role: string;
+}[] = [];
+/** The person's Bots, as the Bots list answers them. */
+let bots: {
+ id: string;
+ name: string;
+ avatarSeed: string;
+ hidden: boolean;
+ mine: boolean;
+}[] = [];
+
+/** Six of the person's own Bots, for the dialog's row of paused Bots. */
+const sixBots = () =>
+ ["Scout", "Ledger", "Pixel", "Atlas", "Juno", "Otto"].map((name) => ({
+ id: name.toLowerCase(),
+ name,
+ avatarSeed: name,
+ hidden: false,
+ mine: true,
+ }));
+
+/** A Bot somebody else made and shared with the person: not theirs to call paused. */
+const sharedBot = {
+ id: "shared",
+ name: "Team Helper",
+ avatarSeed: "Team Helper",
+ hidden: false,
+ mine: false,
+};
+
+/** Who is in the organization: Ana, a member, and its owner and an admin. */
+const ACME = [
+ {
+ id: "ana",
+ name: "Ana Lopez",
+ email: "ana@example.com",
+ image: null,
+ role: "member",
+ },
+ {
+ id: "priya",
+ name: "Priya Raman",
+ email: "priya@example.com",
+ image: null,
+ role: "admin",
+ },
+ {
+ id: "ines",
+ name: "Ines Duarte",
+ email: "ines@example.com",
+ image: null,
+ role: "owner",
+ },
+];
/** Ana, signed in, as the app has read her before any screen draws. */
function signedIn() {
@@ -102,6 +162,8 @@ beforeEach(() => {
writes.length = 0;
refuseRuns = false;
planHeld = null;
+ members = [];
+ bots = [];
setCurrentOrganization(ORG);
signedIn();
global.fetch = Object.assign(
@@ -132,9 +194,10 @@ beforeEach(() => {
if (planHeld) await planHeld;
return Response.json(plan);
}
- // Every list a screen here reads, empty.
+ // Every list a screen here reads, empty but the members and the Bots.
return Response.json({
- members: [],
+ members,
+ bots,
invitations: [],
runs: [],
triggers: [],
@@ -324,6 +387,8 @@ test("on the free trial the Plan row shows how much is used, and once paid the p
test("once the trial is used up, the dialog says so once, and then opens in place of every AI action", async () => {
plan = usedUp(true);
+ bots = [sharedBot, ...sixBots()];
+ members = ACME;
const sent: string[] = [];
const view = open(
<>
@@ -341,14 +406,48 @@ test("once the trial is used up, the dialog says so once, and then opens in plac
// The first read that says it's used up opens it, saying it plainly.
await opened();
+ await waitFor(() =>
+ expect(dialog()?.textContent).toContain(
+ "All 500 Bot runs in your free trial are used, so your 6 Bots are paused. Your Bots, conversations and memory are all kept.",
+ ),
+ );
+ // Four of the Bots drawn, the rest counted, and marked paused.
+ const paused = dialog()?.querySelector('[data-slot="paused-bots"]');
+ const drawn = [
+ ...(paused?.querySelectorAll('[role="img"][aria-label]') ?? []),
+ ].map((orb) => orb.getAttribute("aria-label"));
+ expect([...new Set(drawn)]).toEqual(["Scout", "Ledger", "Pixel", "Atlas"]);
+ expect(paused?.textContent).toBe("+2Paused");
+ // The bar, full.
+ const bar = dialog()?.querySelector('[role="progressbar"]');
+ expect(bar?.getAttribute("aria-valuenow")).toBe("100");
+ expect(bar?.textContent).toContain("100% used");
+ // The plan card: the price and what the card does. No total: the API sends no billed count.
+ await waitFor(() =>
+ expect(dialog()?.querySelector("[data-plan-card]")).not.toBeNull(),
+ );
+ const card = dialog()?.querySelector("[data-plan-card]")?.textContent ?? "";
+ expect(card).toContain("Keep your Bots running");
+ expect(card).toContain("$5 per member a month");
+ expect(card).toContain("Your Bots run again as soon as the card is added");
+ expect(card).toContain("Covers everyone in this organization");
+ expect(card).not.toMatch(/members|\$15/);
const said = dialog()?.textContent ?? "";
- expect(said).toContain("You've used your free trial");
- expect(said).toContain("Your free trial was 500 Bot runs");
- expect(said).toContain("$5 a month for each member of this organization");
expect(said).not.toContain(EMPLOYEE_LINE);
+ expect(said).not.toContain("Ask an admin");
expect(view.queryByAltText(SENTRY_ALT)).toBeNull();
const pay = view.getByRole("link", { name: "Add a card" });
expect(pay.getAttribute("href")).toBe(ADD_CARD);
+ // Not now closes it, as the × does.
+ await act(async () => {
+ fireEvent.click(view.getByRole("button", { name: "Not now" }));
+ });
+ await settled();
+ expect(dialog()).toBeNull();
+ await act(async () => {
+ fireEvent.click(view.getByLabelText("Send message"));
+ });
+ await settled();
await dismiss();
const tries: [string, () => HTMLElement][] = [
@@ -392,16 +491,93 @@ test("once the trial is used up, the dialog says so once, and then opens in plac
expect(view.container.textContent).toContain("Summarize this week's signups");
});
-test("a member is told to ask an admin, with no button", async () => {
+test("a person whose only Bots are shared with them isn't told any are paused", async () => {
+ plan = usedUp(true);
+ bots = [sharedBot];
+ open(null);
+ await opened();
+ await settled();
+ expect(dialog()?.querySelector('[data-slot="paused-bots"]')).toBeNull();
+ expect(dialog()?.textContent).toContain(
+ "All 500 Bot runs in your free trial are used. Your Bots",
+ );
+ expect(dialog()?.textContent).not.toContain("paused");
+});
+
+test("a member is told which admins to ask, as rows, and Got it closes it", async () => {
plan = usedUp(false);
+ members = ACME;
+ bots = sixBots().slice(0, 1);
const view = open(null);
await opened();
- expect(dialog()?.textContent).toContain(
- "Ask an admin of this organization to add a card.",
+ await waitFor(() =>
+ expect(
+ dialog()?.querySelector('[data-slot="admins-to-ask"]'),
+ ).not.toBeNull(),
);
+ const ask =
+ dialog()?.querySelector('[data-slot="admins-to-ask"]')?.textContent ?? "";
+ expect(ask).toContain("Ask an admin to add a card");
+ // Owners first, each with their address and role.
+ expect(ask).toContain("Ines Duarteines@example.comOwner");
+ expect(ask).toContain("Priya Ramanpriya@example.comAdmin");
+ expect(ask.indexOf("Ines")).toBeLessThan(ask.indexOf("Priya"));
+ expect(ask).not.toContain("Ana Lopez");
+ expect(ask).toContain("It's $5 per member a month.");
+ await waitFor(() =>
+ expect(dialog()?.textContent).toContain("so your Bot is paused."),
+ );
+ expect(dialog()?.querySelector("[data-plan-card]")).toBeNull();
expect(dialog()?.textContent).not.toContain(EMPLOYEE_LINE);
expect(view.queryByAltText(SENTRY_ALT)).toBeNull();
expect(view.queryAllByRole("link")).toHaveLength(0);
+ expect(view.queryByRole("button", { name: "Not now" })).toBeNull();
+ await act(async () => {
+ fireEvent.click(view.getByRole("button", { name: "Got it" }));
+ });
+ await settled();
+ expect(dialog()).toBeNull();
+});
+
+test("with no admin to name, a member is still told to ask one", async () => {
+ plan = usedUp(false);
+ const view = open(null);
+ await opened();
+ expect(dialog()?.textContent).toContain(
+ "Ask an admin of this organization to add a card.",
+ );
+ // No Bots read: no row of them, and the line doesn't count them.
+ expect(dialog()?.querySelector('[data-slot="paused-bots"]')).toBeNull();
+ expect(dialog()?.textContent).toContain(
+ "All 500 Bot runs in your free trial are used. Your Bots",
+ );
+ expect(view.queryAllByRole("link")).toHaveLength(0);
+});
+
+test("a failed payment says so, with no bar and no plan card, and Update card for an admin", async () => {
+ plan = {
+ required: true,
+ status: "past_due",
+ freeRunsUsedPercent: 100,
+ trialEndsAt: null,
+ renewsAt: null,
+ addCardUrl: ADD_CARD,
+ };
+ const view = open(null);
+ await planRead();
+ await act(async () => {
+ stopIfNeedsCard();
+ });
+ await opened();
+ const said = dialog()?.textContent ?? "";
+ expect(said).toContain("Your last payment didn't go through");
+ expect(said).toContain("Your Bots, conversations and memory are all kept.");
+ expect(dialog()?.querySelector('[role="progressbar"]')).toBeNull();
+ expect(dialog()?.querySelector("[data-plan-card]")).toBeNull();
+ expect(
+ view.getByRole("link", { name: "Update card" }).getAttribute("href"),
+ ).toBe(ADD_CARD);
+ expect(view.getByRole("button", { name: "Not now" })).not.toBeNull();
});
test("a run the server refuses for want of a plan opens the dialog, from a REST call or a Bot's run", async () => {
@@ -434,7 +610,9 @@ test("a run the server refuses for want of a plan opens the dialog, from a REST
]);
// Read again as it opened, so it names the trial the server now says was used.
await waitFor(() =>
- expect(dialog()?.textContent).toContain("Your free trial was 500 Bot runs"),
+ expect(dialog()?.textContent).toContain(
+ "All 500 Bot runs in your free trial are used",
+ ),
);
await dismiss();
@@ -517,7 +695,7 @@ test("opened by a refusal before the plan is read again, an admin is told to add
});
await opened();
const said = dialog()?.textContent ?? "";
- expect(said).toContain("Add a card to keep your Bots running.");
+ expect(said).toContain("You've used your free trial");
expect(said).not.toContain("Ask an admin");
expect(
view.getByRole("link", { name: "Add a card" }).getAttribute("href"),
@@ -527,7 +705,9 @@ test("opened by a refusal before the plan is read again, an admin is told to add
answer();
});
await waitFor(() =>
- expect(dialog()?.textContent).toContain("Your free trial was 500 Bot runs"),
+ expect(dialog()?.textContent).toContain(
+ "All 500 Bot runs in your free trial are used",
+ ),
);
expect(dialog()?.textContent).not.toContain("Ask an admin");
});
@@ -750,3 +930,121 @@ test("the Plan row tells a CopilotKit employee past the cap their runs are free"
expect(view.queryByRole("link", { name: "Add a card" })).toBeNull();
expect(dialog()).toBeNull();
});
+
+/** Runs still left on the free trial, `percent` of it used, as an admin or a member reads it. */
+const runningLow = (
+ percent: number,
+ addCardUrl: string | null,
+): OrganizationPlan => ({
+ required: true,
+ status: "free",
+ freeRunsUsedPercent: percent,
+ trialEndsAt: null,
+ renewsAt: null,
+ addCardUrl,
+});
+
+/** The quiet line under the message box. */
+const trialNote = () => document.querySelector('[data-slot="trial-note"]');
+
+/** The person's role in this organization, as the app read it. */
+function signedInAs(role: string) {
+ queryClient.setQueryData(authKeys.currentUser(), {
+ id: "ana",
+ email: "ana@example.com",
+ name: "Ana Lopez",
+ role,
+ });
+}
+
+function composer() {
+ return open(
+ {}}
+ />,
+ );
+}
+
+test("from 80% of the free trial used, a note under the message box says so, with the card for an admin", async () => {
+ plan = runningLow(82, ADD_CARD);
+ composer();
+ await waitFor(() => expect(trialNote()).not.toBeNull());
+ expect(trialNote()?.textContent).toBe(
+ "82% of your free trial used · Add a card",
+ );
+ expect(trialNote()?.querySelector("a")?.getAttribute("href")).toBe(ADD_CARD);
+ // A warning, not a stop.
+ expect(dialog()).toBeNull();
+});
+
+test("a member's note says to ask an admin", async () => {
+ plan = runningLow(90, null);
+ signedInAs("member");
+ composer();
+ await waitFor(() => expect(trialNote()).not.toBeNull());
+ expect(trialNote()?.textContent).toBe(
+ "90% of your free trial used · Ask an admin to add a card",
+ );
+ expect(trialNote()?.querySelector("a")).toBeNull();
+});
+
+test("an admin the server sent no way to add a card yet is told what happens at 100%", async () => {
+ plan = runningLow(85, null);
+ composer();
+ await waitFor(() => expect(trialNote()).not.toBeNull());
+ expect(trialNote()?.textContent).toBe(
+ "85% of your free trial used · At 100%, Bots pause until a card is added",
+ );
+});
+
+test("no note under 80%, past the trial, or for a CopilotKit employee", async () => {
+ for (const [what, next] of [
+ ["79% used", runningLow(79, ADD_CARD)],
+ ["used up", usedUp(true)],
+ ["employee", { ...runningLow(95, null), copilotKitEmployee: true }],
+ ] as const) {
+ plan = next;
+ queryClient.removeQueries({ queryKey: planKeys.all });
+ rememberTrialUsedUpAnnounced("ana", ORG);
+ composer();
+ await settled();
+ expect(trialNote(), what).toBeNull();
+ cleanup();
+ }
+});
+
+test("the Plan row says what happens at 100%, and from 80% offers the card beside the bar", async () => {
+ queryClient.setQueryData(organizationKeys.mine(), {
+ organizations: [
+ {
+ id: ORG,
+ slug: "ana",
+ name: "Ana's organization",
+ role: "owner",
+ active: true,
+ personal: true,
+ },
+ ],
+ canCreate: true,
+ currentId: ORG,
+ });
+ plan = runningLow(42, null);
+ const early = open();
+ await early.findByRole("progressbar");
+ await early.findByText(
+ "When it's used up, Bots pause until a card is added.",
+ );
+ expect(early.queryByRole("link", { name: "Add a card" })).toBeNull();
+ cleanup();
+
+ queryClient.removeQueries({ queryKey: planKeys.all });
+ plan = runningLow(86, ADD_CARD);
+ const late = open();
+ const bar = await late.findByRole("progressbar");
+ expect(bar.getAttribute("aria-valuenow")).toBe("86");
+ const pay = await late.findByRole("link", { name: "Add a card" });
+ expect(pay.getAttribute("href")).toBe(ADD_CARD);
+ expect(dialog()).toBeNull();
+});