Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Bot-coloured main buttons: Send, Allow and the answers a bot waits for (#3767)

Milind Soni976554a4bde2
diff --git a/docs/pr-screenshots/bot-colour-buttons/approval-dark-purple-after.png b/docs/pr-screenshots/bot-colour-buttons/approval-dark-purple-after.png
new file mode 100644
index 0000000000..33c7275a8a
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/approval-dark-purple-after.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/approval-dark-purple-before.png b/docs/pr-screenshots/bot-colour-buttons/approval-dark-purple-before.png
new file mode 100644
index 0000000000..6375cf14e8
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/approval-dark-purple-before.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/approval-dark-teal-after.png b/docs/pr-screenshots/bot-colour-buttons/approval-dark-teal-after.png
new file mode 100644
index 0000000000..d751081e0c
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/approval-dark-teal-after.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/approval-dark-teal-before.png b/docs/pr-screenshots/bot-colour-buttons/approval-dark-teal-before.png
new file mode 100644
index 0000000000..ff46b8a97a
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/approval-dark-teal-before.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/approval-dark-yellow-after.png b/docs/pr-screenshots/bot-colour-buttons/approval-dark-yellow-after.png
new file mode 100644
index 0000000000..04cc2e30d9
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/approval-dark-yellow-after.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/approval-dark-yellow-before.png b/docs/pr-screenshots/bot-colour-buttons/approval-dark-yellow-before.png
new file mode 100644
index 0000000000..58d215874e
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/approval-dark-yellow-before.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/approval-dark-yellow-focus.png b/docs/pr-screenshots/bot-colour-buttons/approval-dark-yellow-focus.png
new file mode 100644
index 0000000000..4f31149104
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/approval-dark-yellow-focus.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/approval-light-purple-after.png b/docs/pr-screenshots/bot-colour-buttons/approval-light-purple-after.png
new file mode 100644
index 0000000000..54a587f46c
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/approval-light-purple-after.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/approval-light-purple-before.png b/docs/pr-screenshots/bot-colour-buttons/approval-light-purple-before.png
new file mode 100644
index 0000000000..e25d32073a
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/approval-light-purple-before.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/approval-light-teal-after.png b/docs/pr-screenshots/bot-colour-buttons/approval-light-teal-after.png
new file mode 100644
index 0000000000..4bfddc97d1
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/approval-light-teal-after.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/approval-light-teal-before.png b/docs/pr-screenshots/bot-colour-buttons/approval-light-teal-before.png
new file mode 100644
index 0000000000..99f5534ff3
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/approval-light-teal-before.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/approval-light-yellow-after.png b/docs/pr-screenshots/bot-colour-buttons/approval-light-yellow-after.png
new file mode 100644
index 0000000000..c70d399d3c
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/approval-light-yellow-after.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/approval-light-yellow-before.png b/docs/pr-screenshots/bot-colour-buttons/approval-light-yellow-before.png
new file mode 100644
index 0000000000..9fce605530
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/approval-light-yellow-before.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/approval-light-yellow-focus.png b/docs/pr-screenshots/bot-colour-buttons/approval-light-yellow-focus.png
new file mode 100644
index 0000000000..3c255861a4
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/approval-light-yellow-focus.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/composer-dark-purple-after.png b/docs/pr-screenshots/bot-colour-buttons/composer-dark-purple-after.png
new file mode 100644
index 0000000000..d3b3fe9d59
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/composer-dark-purple-after.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/composer-dark-purple-before.png b/docs/pr-screenshots/bot-colour-buttons/composer-dark-purple-before.png
new file mode 100644
index 0000000000..f1bf67660c
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/composer-dark-purple-before.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/composer-dark-teal-after.png b/docs/pr-screenshots/bot-colour-buttons/composer-dark-teal-after.png
new file mode 100644
index 0000000000..a8244fbc3f
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/composer-dark-teal-after.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/composer-dark-teal-before.png b/docs/pr-screenshots/bot-colour-buttons/composer-dark-teal-before.png
new file mode 100644
index 0000000000..f1bf67660c
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/composer-dark-teal-before.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/composer-dark-yellow-after.png b/docs/pr-screenshots/bot-colour-buttons/composer-dark-yellow-after.png
new file mode 100644
index 0000000000..7bf3f0ac9c
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/composer-dark-yellow-after.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/composer-dark-yellow-before.png b/docs/pr-screenshots/bot-colour-buttons/composer-dark-yellow-before.png
new file mode 100644
index 0000000000..f1bf67660c
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/composer-dark-yellow-before.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/composer-light-purple-after.png b/docs/pr-screenshots/bot-colour-buttons/composer-light-purple-after.png
new file mode 100644
index 0000000000..8dda7fc661
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/composer-light-purple-after.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/composer-light-purple-before.png b/docs/pr-screenshots/bot-colour-buttons/composer-light-purple-before.png
new file mode 100644
index 0000000000..c38e5a0e39
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/composer-light-purple-before.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/composer-light-teal-after.png b/docs/pr-screenshots/bot-colour-buttons/composer-light-teal-after.png
new file mode 100644
index 0000000000..f5730ae2d3
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/composer-light-teal-after.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/composer-light-teal-before.png b/docs/pr-screenshots/bot-colour-buttons/composer-light-teal-before.png
new file mode 100644
index 0000000000..c38e5a0e39
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/composer-light-teal-before.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/composer-light-yellow-after.png b/docs/pr-screenshots/bot-colour-buttons/composer-light-yellow-after.png
new file mode 100644
index 0000000000..82b2bca2d4
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/composer-light-yellow-after.png differ
diff --git a/docs/pr-screenshots/bot-colour-buttons/composer-light-yellow-before.png b/docs/pr-screenshots/bot-colour-buttons/composer-light-yellow-before.png
new file mode 100644
index 0000000000..c38e5a0e39
Binary files /dev/null and b/docs/pr-screenshots/bot-colour-buttons/composer-light-yellow-before.png differ
diff --git a/src/components/AskCard.tsx b/src/components/AskCard.tsx
index b481d4fb6c..f36b693bdb 100644
--- a/src/components/AskCard.tsx
+++ b/src/components/AskCard.tsx
@@ -1,6 +1,8 @@
import type { KeyboardEvent, ReactNode } from "react";
+import { botButton, type BotButton } from "@/lib/bot-button";
import { cn } from "@/lib/cn";
import { useAdvancedMode } from "@/lib/interface-mode";
+import type { MausColor } from "@/lib/mascot";
import { Check, Pencil, X } from "lucide-react";
export function AskCard({
@@ -115,11 +117,18 @@ export function AskSettledLine({
* A fixed height with a centered line box keeps Arabic and Latin labels on one baseline band; vertical padding lets
* each script's font metrics push text off center.
*/
-const ASK_CONTROL =
- "inline-flex h-7 shrink-0 items-center justify-center gap-1.5 whitespace-nowrap rounded-full px-3 text-[13px] font-medium leading-5 transition-colors [&>svg]:shrink-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus disabled:cursor-not-allowed disabled:opacity-40";
+const ASK_SHAPE =
+ "inline-flex h-7 shrink-0 items-center justify-center gap-1.5 whitespace-nowrap rounded-full px-3 text-[13px] font-medium leading-5 transition-colors [&>svg]:shrink-0 disabled:cursor-not-allowed";
+const ASK_LOOK = "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus disabled:opacity-40";
+const ASK_CONTROL = `${ASK_SHAPE} ${ASK_LOOK}`;
+const ASK_PRIMARY_LOOK = `${ASK_LOOK} ui-button-primary bg-accent text-accent-ink hover:brightness-110`;
-export const ASK_PRIMARY_BUTTON =
- `${ASK_CONTROL} ui-button-primary bg-accent text-accent-ink hover:brightness-110`;
+export const ASK_PRIMARY_BUTTON = `${ASK_SHAPE} ${ASK_PRIMARY_LOOK}`;
+
+/** The answer a card waits for, in the asking bot's own button; the plain primary when no single bot asked. */
+export function askPrimary(color: MausColor | undefined): BotButton {
+ return botButton(color, ASK_SHAPE, ASK_PRIMARY_LOOK);
+}
export const ASK_CHIP = `${ASK_CONTROL} max-w-full border`;
export const ASK_CHIP_IDLE = "border-transparent bg-ink/[0.07] text-ink hover:bg-ink/[0.12]";
diff --git a/src/components/ChatView.tsx b/src/components/ChatView.tsx
index 2b66469628..bd5d23f8a7 100644
--- a/src/components/ChatView.tsx
+++ b/src/components/ChatView.tsx
@@ -138,7 +138,7 @@ const USER_COLLAPSE_CHARS = 600;
const USER_COLLAPSE_LINES = 8;
interface ChatRows {
- botId: string; threadId: string; botName: string; voiceId?: string;
+ botId: string; threadId: string; botName: string; botColor: Bot["color"]; voiceId?: string;
tts: ConfigStatus["tts"]; localVoice: boolean; busy: boolean; liveTools: ReadonlySet<string>;
hasMore: boolean; bots: readonly Bot[];
mentionPeers: readonly MentionPeer[]; mentionPerson: { profileName?: string };
@@ -691,7 +691,7 @@ const MessagesList = memo(function MessagesList({
onRegenerate: () => void;
onReply: (message: Message) => void;
}) {
- const { botId, threadId, botName, busy, hasMore, focus, showToolCalls, locale, simple = false } = useChatRows();
+ const { botId, threadId, botName, botColor, bots, busy, hasMore, focus, showToolCalls, locale, simple = false } = useChatRows();
// A finished turn keeps the bot's progress lines and folds only its tool steps under "Worked for", in both modes.
const items = useMemo(() => groupTranscript(messages), [messages, locale]);
const newestMessageId = messages.at(-1)?.id;
@@ -743,13 +743,13 @@ const MessagesList = memo(function MessagesList({
}
switch (richRowKind(m)) {
case "secret":
- return m.secret ? <SecretRequestCard botId={botId} threadId={threadId} message={m} /> : null;
+ return m.secret ? <SecretRequestCard botId={botId} color={botColor} threadId={threadId} message={m} /> : null;
case "signin":
- return m.signIn ? <SignInRequestCard botId={botId} botName={botName} threadId={threadId} message={m} /> : null;
+ return m.signIn ? <SignInRequestCard botId={botId} botName={botName} color={botColor} threadId={threadId} message={m} /> : null;
case "connector":
- return m.connector ? <ConnectorCard botId={botId} threadId={threadId} message={m} /> : null;
+ return m.connector ? <ConnectorCard botId={botId} color={botColor} threadId={threadId} message={m} /> : null;
case "options":
- return optionsCardRow({ message: m, transcript, botId, botName, threadId });
+ return optionsCardRow({ message: m, transcript, botId, botName, botColor: bots.find((one) => one.id === m.inbox?.from.botId)?.color ?? botColor, threadId });
case "widget":
case "app":
return <RichMessageRow botId={botId} botName={botName} threadId={threadId} message={m} />;
@@ -920,8 +920,8 @@ export function ChatView({ bot: profile }: { bot: Bot }) {
const reactor = useReactor();
const speakerViewer = state.config?.team && reactor !== "user" ? reactor : null;
const rows = useMemo<ChatRows>(
- () => ({ botId: bot.id, threadId: bot.threadId, botName: bot.name, voiceId: bot.voice, tts, localVoice, busy, liveTools, hasMore, bots, mentionPeers, mentionPerson: { profileName: state.config?.profile?.name }, focus, showToolCalls, locale, dispatch, onBranch, bubbleStyle, conversational: isConversational(bot.replyStyle), simple: !advanced, canReact: canWrite !== false, openedAt, speakerViewer }),
- [bot.id, bot.threadId, bot.name, bot.voice, tts, localVoice, busy, liveTools, hasMore, bots, mentionPeers, state.config?.profile?.name, focus, showToolCalls, locale, dispatch, onBranch, bubbleStyle, bot.replyStyle, advanced, canWrite, openedAt, speakerViewer],
+ () => ({ botId: bot.id, threadId: bot.threadId, botName: bot.name, botColor: bot.color, voiceId: bot.voice, tts, localVoice, busy, liveTools, hasMore, bots, mentionPeers, mentionPerson: { profileName: state.config?.profile?.name }, focus, showToolCalls, locale, dispatch, onBranch, bubbleStyle, conversational: isConversational(bot.replyStyle), simple: !advanced, canReact: canWrite !== false, openedAt, speakerViewer }),
+ [bot.id, bot.threadId, bot.name, bot.color, bot.voice, tts, localVoice, busy, liveTools, hasMore, bots, mentionPeers, state.config?.profile?.name, focus, showToolCalls, locale, dispatch, onBranch, bubbleStyle, bot.replyStyle, advanced, canWrite, openedAt, speakerViewer],
);
const currentTask = bot.tasks?.find((task) => task.threadId === bot.threadId), place = effectivePlace(bot, currentTask), team = state.config?.team, privateChat = Boolean(team) && currentTask?.private === true, sharedChat = Boolean(team) && !privateChat;
diff --git a/src/components/Composer.simple.test.ts b/src/components/Composer.simple.test.ts
index b561d75402..3890f5f088 100644
--- a/src/components/Composer.simple.test.ts
+++ b/src/components/Composer.simple.test.ts
@@ -10,6 +10,7 @@ import type { Bot, Group } from "@/state/store";
import { restoreComposerDraft } from "@/lib/drafts";
import { setCallMode } from "@/lib/call-mode";
import { userBubbleTone } from "@/lib/user-bubble-tone";
+import { BOT_BUTTON, botButtonTone } from "@/lib/bot-button";
const fixture = vi.hoisted(() => ({
advanced: false,
@@ -67,6 +68,17 @@ const click = (element: Element | null) => {
if (!element) throw new Error("nothing to click");
flushSync(() => (element as HTMLElement).click());
};
+/** The bot's own button: its bubble's fill and ink, with the darker hover and press steps. */
+function expectBotButton(button: HTMLElement | null, color: Bot["color"]) {
+ const tone = botButtonTone(color);
+ expect(button?.className.split(" ")).toContain(BOT_BUTTON);
+ expect(button?.style.getPropertyValue("--bot-button")).toBe(tone.fill);
+ expect(button?.style.getPropertyValue("--bot-button-ink")).toBe(tone.ink);
+ expect(button?.style.getPropertyValue("--bot-button-hover")).toBe(tone.hover);
+ expect(button?.style.getPropertyValue("--bot-button-pressed")).toBe(tone.pressed);
+}
+const sendButton = () => container.querySelector<HTMLButtonElement>('button[aria-label="Send message"]');
+
function openPlus() {
click(plus());
expect(menu()).not.toBeNull();
@@ -173,10 +185,13 @@ describe("the Simple composer in a bot chat", () => {
it("turns its round button into Send while there is text, in the bot's colour", () => {
restoreComposerDraft(`bot:${bot.id}:${bot.threadId}`, { text: "hello", attachments: [] });
render({ bot });
- const send = container.querySelector<HTMLButtonElement>('button[aria-label="Send message"]')!;
+ const send = sendButton()!;
expect(send.className.split(" ")).toContain("size-7");
- expect(send.style.backgroundColor).not.toBe("");
+ expectBotButton(send, "purple");
+ expect(send.className).not.toMatch(/\bbg-accent\b|brightness/);
expect(fixture.call).toBeNull();
+ render({ bot: { ...bot, color: "yellow" } });
+ expectBotButton(sendButton(), "yellow");
});
it("turns its round button into Stop while the bot works, and keeps a quiet Stop beside Send while you type", () => {
@@ -184,7 +199,7 @@ describe("the Simple composer in a bot chat", () => {
render({ bot: busy });
const slot = container.querySelector<HTMLButtonElement>('[data-composer-stop="slot"]')!;
expect(slot.getAttribute("aria-label")).toBe("Stop this turn");
- expect(slot.style.backgroundColor).not.toBe("");
+ expectBotButton(slot, "purple");
expect(fixture.call).toBeNull();
click(slot);
expect(fixture.dispatch).toHaveBeenCalledWith({ type: "interrupt", botId: "atlas", threadId: "atlas-thread" });
@@ -244,6 +259,14 @@ describe("the Simple composer in a group chat", () => {
expect(container.querySelector("[data-goal-chip]")).toBeNull();
expect(container.querySelector("textarea")!.getAttribute("placeholder")).toBe("Message Launch planning");
expect(fixture.groupCall).toMatchObject({ group: { id: "room" }, placement: "composer", fill: "var(--color-accent)", ink: "var(--color-accent-ink)" });
+ restoreComposerDraft(`group:${room.id}:${room.threadId}`, { text: "hello room", attachments: [] });
+ render({ group: room, members: [bot, peer] });
+ const send = sendButton()!;
+ expect(send.className.split(" ")).not.toContain(BOT_BUTTON);
+ expect(send.style.backgroundColor).toBe("var(--color-accent)");
+ expect(send.style.color).toBe("var(--color-accent-ink)");
+ restoreComposerDraft(`group:${room.id}:${room.threadId}`, { text: "", attachments: [] });
+ render({ group: room, members: [bot, peer] });
openPlus();
expect([...menu()!.querySelectorAll("[data-menu-key]")].map((row) => row.getAttribute("data-menu-key"))).toEqual(["attach", "goal", "teach"]);
click(item("goal"));
@@ -275,6 +298,20 @@ describe("the Advanced composer", () => {
expect(container.querySelector("[data-composer-backdrop]")!.className.split(" ")).toContain("top-1/2");
});
+ it("sends with the bot's own button too, and keeps the accent in a room", () => {
+ fixture.advanced = true;
+ restoreComposerDraft(`bot:${bot.id}:${bot.threadId}`, { text: "hello", attachments: [] });
+ render({ bot: { ...bot, color: "teal" } });
+ const send = sendButton()!;
+ expect(send.className.split(" ")).toContain("size-8");
+ expectBotButton(send, "teal");
+ expect(send.className).not.toMatch(/\bbg-accent\b|text-white/);
+ restoreComposerDraft(`group:${room.id}:${room.threadId}`, { text: "hello room", attachments: [] });
+ render({ group: room, members: [bot, peer] });
+ expect(sendButton()!.className.split(" ")).not.toContain(BOT_BUTTON);
+ expect(sendButton()!.style.backgroundColor).toBe("var(--color-accent)");
+ });
+
it("keeps the room's Goal chip and its header call button", () => {
fixture.advanced = true;
render({ group: room, members: [bot, peer] });
diff --git a/src/components/Composer.tsx b/src/components/Composer.tsx
index 478d98ed4a..716c780563 100644
--- a/src/components/Composer.tsx
+++ b/src/components/Composer.tsx
@@ -963,10 +963,10 @@ export function Composer({
className={cn(
"flex shrink-0 items-center justify-center rounded-full",
!simpleDock ? "size-8 text-ink-secondary hover:bg-raised hover:text-ink"
- : stopInSlot ? "size-7 hover:brightness-110"
+ : stopInSlot ? cn("size-7", slot.button.className)
: SIMPLE_CONTROL,
)}
- style={stopInSlot ? { backgroundColor: slot.fill, color: slot.ink } : undefined}
+ style={stopInSlot ? slot.button.style : undefined}
title={t("chat.stop")}
>
<Square size={simpleDock ? 10 : 14} className="fill-current" />
@@ -996,13 +996,11 @@ export function Composer({
disabled={attachmentPending}
aria-label={sendNames.label}
title={sendNames.title}
- style={simpleDock && !(busy && !canSteer) ? { backgroundColor: slot.fill, color: slot.ink } : undefined}
+ style={busy && !canSteer ? undefined : slot.button.style}
className={cn(
- "flex shrink-0 items-center justify-center rounded-full",
- simpleDock ? "size-7 animate-[slot-fade-in_120ms_ease-out] disabled:cursor-default disabled:opacity-40" : "size-8 text-white",
- busy && !canSteer
- ? "bg-raised text-ink-secondary hover:bg-raised-hover"
- : simpleDock ? "hover:brightness-110" : "bg-accent hover:brightness-110",
+ "flex shrink-0 items-center justify-center rounded-full disabled:cursor-default",
+ simpleDock ? "size-7 animate-[slot-fade-in_120ms_ease-out]" : "size-8",
+ busy && !canSteer ? "bg-raised text-ink-secondary hover:bg-raised-hover" : slot.button.className,
)}
>
{busy && !canSteer ? <Clock size={simpleDock ? 14 : 15} /> : <ArrowUp size={16} strokeWidth={1.75} absoluteStrokeWidth />}
diff --git a/src/components/ConnectorCard.tsx b/src/components/ConnectorCard.tsx
index 2075ad12e8..d93d6a26ef 100644
--- a/src/components/ConnectorCard.tsx
+++ b/src/components/ConnectorCard.tsx
@@ -1,21 +1,21 @@
import { useCallback, useEffect, useRef, useState } from "react";
import { Loader2, PlugZap, RefreshCw, X } from "lucide-react";
-import { api, type Message } from "@/state/store";
+import { api, type Bot, type Message } from "@/state/store";
import { t } from "@/lib/i18n";
import type { LocaleKey } from "@/locales";
import { AUTHORIZATION_LINK_MS, reserveConnectionPage, reusableConnectionUrl, type PendingAuthorization } from "@/lib/connector-oauth";
import { accountAliasTaken, requiresAccountAlias } from "@/lib/connector-status";
import { mcpSignInLink } from "@/lib/mcp-sign-in";
import { cn } from "@/lib/cn";
-import { ASK_PRIMARY_BUTTON, ASK_QUIET_BUTTON, AskCard, AskSettledLine } from "./AskCard";
+import { askPrimary, ASK_QUIET_BUTTON, AskCard, AskSettledLine } from "./AskCard";
import { CardHint } from "./CardHint";
const STATUS_CHECK_MS = 4_000;
/** Composio marks an unfinished account EXPIRED shortly after its link lapses; the card keeps asking until it can say so. */
const STATUS_WATCH_MS = AUTHORIZATION_LINK_MS + 2 * 60 * 1_000;
-export function ConnectorCard({ botId, threadId, message }: { botId: string; threadId: string; message: Message }) {
+export function ConnectorCard({ botId, color, threadId, message }: { botId: string; color?: Bot["color"]; threadId: string; message: Message }) {
const connector = message.connector!;
const [busy, setBusy] = useState(false);
const [localError, setLocalError] = useState<string | { key: LocaleKey } | null>(null);
@@ -184,7 +184,7 @@ export function ConnectorCard({ botId, threadId, message }: { botId: string; thr
type="button"
onClick={() => void connect(labelNeeded ? label.trim() : undefined)}
disabled={busy || (labelNeeded && !label.trim())}
- className={ASK_PRIMARY_BUTTON}
+ {...askPrimary(color)}
>
{busy ? <Loader2 size={14} className="animate-spin" /> : authorizing ? <RefreshCw size={14} /> : <PlugZap size={14} />}
{authorizing
diff --git a/src/components/GroupView.tsx b/src/components/GroupView.tsx
index e2c569b03d..dca5c8ccd7 100644
--- a/src/components/GroupView.tsx
+++ b/src/components/GroupView.tsx
@@ -421,11 +421,11 @@ export const Transcript = memo(function Transcript({
<CancelledTurnRow onRetry={canRetryRoom ? retryRoom : undefined} />
) :
m.kind === "secret" && m.secret && m.from?.botId ? (
- <SecretRequestCard botId={m.from.botId} threadId={group.threadId} message={m} />
+ <SecretRequestCard botId={m.from.botId} color={m.from.color} threadId={group.threadId} message={m} />
) : m.kind === "signin" && m.signIn && m.from?.botId ? (
- <SignInRequestCard botId={m.from.botId} botName={m.from.name} threadId={group.threadId} message={m} />
+ <SignInRequestCard botId={m.from.botId} botName={m.from.name} color={m.from.color} threadId={group.threadId} message={m} />
) : m.kind === "connector" && m.connector && m.from?.botId ? (
- <ConnectorCard botId={m.from.botId} threadId={group.threadId} message={m} />
+ <ConnectorCard botId={m.from.botId} color={m.from.color} threadId={group.threadId} message={m} />
) : m.kind === "options" && m.card?.requestId && m.card.questionRequest ? (
<div className="flex justify-start">
<MessageBoundary fallbackText={m.card.subtitle || m.card.title || ""}>
diff --git a/src/components/OptionsCardRow.tsx b/src/components/OptionsCardRow.tsx
index aa9989e93d..0ee162b0d6 100644
--- a/src/components/OptionsCardRow.tsx
+++ b/src/components/OptionsCardRow.tsx
@@ -1,5 +1,5 @@
import type { ReactNode } from "react";
-import type { Message } from "@/state/store";
+import type { Bot, Message } from "@/state/store";
import { ApprovalCard } from "./ApprovalCard";
import { HelperIntro } from "./HelperIntro";
import { MessageBoundary } from "./MessageBoundary";
@@ -16,11 +16,12 @@ function typedPast(card: Message, transcript: Message[]): boolean {
return index >= 0 && transcript.slice(index + 1).some((later) => later.role === "user" && later.kind === "text");
}
-export function optionsCardRow({ message: m, transcript, botId, botName, threadId }: {
+export function optionsCardRow({ message: m, transcript, botId, botName, botColor, threadId }: {
message: Message;
transcript: Message[];
botId: string;
botName: string;
+ botColor?: Bot["color"];
threadId: string;
}): ReactNode {
// MausBot's follow-up is drawn under its intro (HelperIntro), never as a row of its own.
@@ -29,7 +30,7 @@ export function optionsCardRow({ message: m, transcript, botId, botName, threadI
<HelperIntro botId={botId} threadId={threadId} message={m} answered={shouldHideOnboardingCard(m, transcript)}
followup={transcript.find((entry) => entry.helperFollowup)} />
) : m.card?.requestId && m.card.questionRequest ? (
- <QuestionCard threadId={threadId} bot={{ name: botName }} message={m} typedPast={typedPast(m, transcript)} />
+ <QuestionCard threadId={threadId} bot={{ name: botName, color: botColor }} message={m} typedPast={typedPast(m, transcript)} />
) : m.card?.requestId && m.card.tool ? (
<ApprovalCard bot={{ name: botName }} message={m} threadId={threadId} />
) : shouldHideOnboardingCard(m, transcript) ? null : (
diff --git a/src/components/PendingApproval.tsx b/src/components/PendingApproval.tsx
index b574cbd4a0..e8e2588c40 100644
--- a/src/components/PendingApproval.tsx
+++ b/src/components/PendingApproval.tsx
@@ -8,6 +8,7 @@ import { SkillRequestPreview } from "@/components/SkillRequestPreview";
import { APPROVAL_CODE_CHIP, toolLabel } from "./ApprovalCard";
import { outboundSummary } from "@/lib/approval-summary";
import { reviewedSkillSha256 } from "../../shared/skill-request";
+import { botButton } from "@/lib/bot-button";
import { useOwnerOrAdmin } from "@/lib/use-owner-or-admin";
import { yourComputerAsk } from "@/lib/your-computer";
@@ -103,8 +104,10 @@ function label(pending: Pending): string {
return key ? t(key) : t("approval.label.requested");
}
-export const APPROVAL_CONTROL =
- "inline-flex h-7 shrink-0 items-center justify-center gap-1.5 whitespace-nowrap rounded-full px-3 text-[13px] font-medium leading-5 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus";
+const APPROVAL_SHAPE =
+ "inline-flex h-7 shrink-0 items-center justify-center gap-1.5 whitespace-nowrap rounded-full px-3 text-[13px] font-medium leading-5 transition-colors";
+const RING = "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus";
+export const APPROVAL_CONTROL = `${APPROVAL_SHAPE} ${RING}`;
const COMMAND_TOOLS = new Set(["Bash", "shell"]);
@@ -275,6 +278,7 @@ export function PendingApprovalActions({
rememberCommand: rememberCommand || undefined,
});
+ const allow = botButton(bot?.color, cn(APPROVAL_SHAPE, "disabled:cursor-not-allowed"), cn(RING, "bg-accent text-white hover:bg-accent/90 disabled:opacity-40"));
const showPrimary = part !== "more";
const showMore = part !== "primary";
const always = durableRequest ? null
@@ -317,7 +321,8 @@ export function PendingApprovalActions({
type="button"
onClick={() => decide("allow")}
disabled={isSkillRequest && !reviewedSha256}
- className={cn(APPROVAL_CONTROL, "bg-accent text-white hover:bg-accent/90 disabled:cursor-not-allowed disabled:opacity-40")}
+ className={allow.className}
+ style={allow.style}
>
{isTeamSetup ? pending.message.card?.options[0] : isSkillRequest
? pending.message.card?.skillRequest?.action === "update"
diff --git a/src/components/QuestionCard.tsx b/src/components/QuestionCard.tsx
index 1913f9d5cd..37aafd5622 100644
--- a/src/components/QuestionCard.tsx
+++ b/src/components/QuestionCard.tsx
@@ -18,7 +18,7 @@ import {
ASK_CHOICE_ROW,
ASK_SOMETHING_ELSE_FIELD,
AskSomethingElse,
- ASK_PRIMARY_BUTTON,
+ askPrimary,
ASK_QUIET_BUTTON,
ASK_SMALL_PILL,
AskCard,
@@ -101,7 +101,7 @@ export function QuestionCard({
typedPast = false,
}: {
threadId: string;
- bot?: Pick<Bot, "name">;
+ bot?: Pick<Bot, "name"> & Partial<Pick<Bot, "color">>;
message: Message;
/** The person has written in the chat since: Simple mode quiets the choices, which still answer. */
typedPast?: boolean;
@@ -222,7 +222,7 @@ export function QuestionCard({
footer={oneTap && !draft.custom.trim() ? undefined : (
<>
<span className="me-auto text-[12px] text-ink-tertiary">{t("question.status.waiting")}</span>
- <button type="button" onClick={submit} disabled={!complete} className={ASK_PRIMARY_BUTTON}>
+ <button type="button" onClick={submit} disabled={!complete} {...askPrimary(bot?.color)}>
{simple && multi && questions.length === 1 ? t("question.done") : questions.length > 1 ? t("question.submitAll") : t("question.submit")}
</button>
</>
diff --git a/src/components/SecretRequestCard.tsx b/src/components/SecretRequestCard.tsx
index 5e756f9d64..06c4b79445 100644
--- a/src/components/SecretRequestCard.tsx
+++ b/src/components/SecretRequestCard.tsx
@@ -5,17 +5,19 @@ import { credentialResumeOutcome, credentialSaveRequest, isConfigCredentialTarge
import { credentialProvider } from "@/lib/analytics-allowlist";
import { cn } from "@/lib/cn";
import { keySaved, keySaveFailure, savedKeyResult } from "@/lib/product-events";
-import { api, useStore, type ConfigStatus, type Message } from "@/state/store";
-import { ASK_FIELD, ASK_PRIMARY_BUTTON, ASK_QUIET_BUTTON, AskCard, AskSettledLine, returnFocusToComposer } from "./AskCard";
+import { api, useStore, type Bot, type ConfigStatus, type Message } from "@/state/store";
+import { ASK_FIELD, askPrimary, ASK_QUIET_BUTTON, AskCard, AskSettledLine, returnFocusToComposer } from "./AskCard";
// Security: the value goes straight to the host's settings, never into the chat.
export function SecretRequestCard({
botId,
+ color,
threadId,
message,
}: {
botId: string;
+ color?: Bot["color"];
threadId: string;
message: Message;
}) {
@@ -192,7 +194,7 @@ export function SecretRequestCard({
aria-label={secret.label}
className={cn(ASK_FIELD, "min-w-[10rem] flex-1")}
/>
- <button type="submit" disabled={saving || (!value.trim() && !savedLocally)} className={ASK_PRIMARY_BUTTON}>
+ <button type="submit" disabled={saving || (!value.trim() && !savedLocally)} {...askPrimary(color)}>
{saving ? <Loader2 size={14} className="animate-spin" /> : <LockKeyhole size={14} />}
{savedLocally ? "Continue task" : "Save securely"}
</button>
diff --git a/src/components/SignInRequestCard.tsx b/src/components/SignInRequestCard.tsx
index 5aae944665..60a72bf4a6 100644
--- a/src/components/SignInRequestCard.tsx
+++ b/src/components/SignInRequestCard.tsx
@@ -7,8 +7,8 @@ import { cn } from "@/lib/cn";
import { t } from "@/lib/i18n";
import { cardSaveTarget, saveLoginFromCard } from "@/lib/logins";
import { answerSignIn, signInHostIsHere } from "@/lib/sign-in";
-import { useStore, type Message } from "@/state/store";
-import { ASK_CHIP, ASK_CHIP_IDLE, ASK_PRIMARY_BUTTON, ASK_QUIET_BUTTON, AskCard, AskSettledLine, returnFocusToComposer } from "./AskCard";
+import { useStore, type Bot, type Message } from "@/state/store";
+import { ASK_CHIP, ASK_CHIP_IDLE, askPrimary, ASK_QUIET_BUTTON, AskCard, AskSettledLine, returnFocusToComposer } from "./AskCard";
import { LoginForm } from "./LoginForm";
// Security: a saved login is encrypted on the server and filled by fill_login; neither the bot nor any screen ever gets
@@ -25,11 +25,13 @@ const WHERE = {
export function SignInRequestCard({
botId,
botName,
+ color,
threadId,
message,
}: {
botId: string;
botName: string;
+ color?: Bot["color"];
threadId: string;
message: Message;
}) {
@@ -140,7 +142,7 @@ export function SignInRequestCard({
{t("signIn.saveLogin")}
</button>
)}
- <button type="button" onClick={() => void answer("done")} disabled={pending !== null} className={ASK_PRIMARY_BUTTON}>
+ <button type="button" onClick={() => void answer("done")} disabled={pending !== null} {...askPrimary(color)}>
{pending === "done" ? <Loader2 size={14} className="animate-spin" /> : <Check size={14} />}
{t("signIn.done")}
</button>
diff --git a/src/components/bot-buttons.test.ts b/src/components/bot-buttons.test.ts
new file mode 100644
index 0000000000..bdefbdc58b
--- /dev/null
+++ b/src/components/bot-buttons.test.ts
@@ -0,0 +1,111 @@
+// The answer a bot's card waits for is that bot's own button; Deny, Cancel and the quiet actions keep their looks, and a
+// card no single bot owns keeps the plain primary.
+import { createElement } from "react";
+import { renderToStaticMarkup } from "react-dom/server";
+import { afterAll, describe, expect, it, vi } from "vitest";
+import type { Bot, Message } from "@/state/store";
+
+const fixture = vi.hoisted(() => {
+ vi.stubGlobal("window", {});
+ vi.stubGlobal("localStorage", { getItem: () => null, setItem: () => {} });
+ return { dispatch: vi.fn() };
+});
+vi.mock("@/lib/interface-mode", () => ({ useAdvancedMode: () => false }));
+vi.mock("@/lib/use-owner-or-admin", () => ({ useOwnerOrAdmin: () => true }));
+vi.mock("@/state/store", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("@/state/store")>()),
+ useStore: () => ({ state: {}, dispatch: fixture.dispatch }),
+}));
+
+const { BOT_BUTTON, botButtonTone } = await import("@/lib/bot-button");
+const { t } = await import("@/lib/i18n");
+const { pendingApprovals, PendingApprovalActions } = await import("./PendingApproval");
+const { QuestionCard } = await import("./QuestionCard");
+const { SecretRequestCard } = await import("./SecretRequestCard");
+const { SignInRequestCard } = await import("./SignInRequestCard");
+const { ConnectorCard } = await import("./ConnectorCard");
+
+afterAll(() => vi.unstubAllGlobals());
+
+function button(html: string, label: string): string {
+ const found = (html.match(/<button[^>]*>[\s\S]*?<\/button>/g) ?? []).find((one) => one.replace(/<[^>]+>/g, "").trim() === label);
+ expect(found, label).toBeDefined();
+ return found!;
+}
+const classes = (tag: string) => (/class="([^"]*)"/.exec(tag)?.[1] ?? "").split(" ");
+
+function expectOwn(tag: string, color: Bot["color"]) {
+ const tone = botButtonTone(color);
+ expect(classes(tag)).toContain(BOT_BUTTON);
+ expect(classes(tag)).not.toContain("ui-button-primary");
+ expect(tag).toContain(`--bot-button:${tone.fill};--bot-button-ink:${tone.ink};--bot-button-hover:${tone.hover};--bot-button-pressed:${tone.pressed}`);
+}
+function expectPlain(tag: string) {
+ expect(classes(tag)).not.toContain(BOT_BUTTON);
+ expect(tag).not.toContain("--bot-button");
+}
+
+const approval = (bot?: Bot) => {
+ const message: Message = {
+ id: "approval-1", at: 1, role: "bot", kind: "options",
+ card: { title: "Approval needed", subtitle: "rm -rf ./build", options: ["Allow", "Deny"], tool: "Bash", requestId: "request-1", allowSession: true },
+ };
+ return renderToStaticMarkup(PendingApprovalActions({ pending: pendingApprovals([message])[0]!, bot, threadId: "thread-1", onCancelTurn: vi.fn() }));
+};
+
+const question: Message = {
+ id: "question-1", role: "bot", kind: "options", at: 1,
+ card: {
+ title: "Your bot has a question", subtitle: "", options: [], requestId: "request-2",
+ questionRequest: { version: 1, questions: [
+ { question: "Which page?", header: "Page", options: [{ label: "Home" }, { label: "Pricing" }] },
+ { question: "Which tone?", header: "Tone", options: [{ label: "Calm" }, { label: "Bold" }] },
+ ] },
+ },
+};
+
+describe("a bot's cards answer in its own colour", () => {
+ it("paints Allow once in the asking bot's colour, while Deny stays the danger word and Always allow stays quiet", () => {
+ const html = approval({ id: "scout", name: "Scout", color: "pink" } as Bot);
+ expectOwn(button(html, t("approval.action.allowOnce")), "pink");
+ const deny = button(html, t("approval.action.deny"));
+ expectPlain(deny);
+ expect(classes(deny)).toContain("text-danger");
+ expectPlain(button(html, t("approval.action.alwaysAllow")));
+ expect(classes(button(approval(), t("approval.action.allowOnce")))).toContain("bg-accent");
+ expectPlain(button(approval(), t("approval.action.allowOnce")));
+ });
+
+ it("sends a question's answers in the asking bot's colour, a light one included", () => {
+ const own = renderToStaticMarkup(createElement(QuestionCard, { threadId: "thread-1", bot: { name: "Scout", color: "yellow" }, message: question }));
+ const submit = button(own, t("question.submitAll"));
+ expectOwn(submit, "yellow");
+ expect(submit).toContain("disabled");
+ expectPlain(button(renderToStaticMarkup(createElement(QuestionCard, { threadId: "thread-1", bot: { name: "Scout" }, message: question })), t("question.submitAll")));
+ });
+
+ it("saves a key, finishes a sign-in and connects an app in the asking bot's colour", () => {
+ const secret: Message = {
+ id: "secret-1", role: "bot", kind: "secret", at: 1, text: "",
+ secret: { target: "openaiImageApiKey", label: "OpenAI API key", description: "", placeholder: "sk-…", requestKey: "key-1" } as Message["secret"],
+ };
+ expectOwn(button(renderToStaticMarkup(createElement(SecretRequestCard, { botId: "scout", color: "blue", threadId: "t", message: secret })), "Save securely"), "blue");
+
+ const signIn: Message = {
+ id: "signin-1", role: "bot", kind: "signin", at: 1, text: "",
+ signIn: { url: "https://example.com/login", site: "example.com", place: "browser" } as Message["signIn"],
+ };
+ const signInHtml = renderToStaticMarkup(createElement(SignInRequestCard, { botId: "scout", botName: "Scout", color: "green", threadId: "t", message: signIn }));
+ expectOwn(button(signInHtml, t("signIn.done")), "green");
+ expectPlain(button(signInHtml, t("signIn.cancel")));
+
+ const connector: Message = {
+ id: "connector-1", role: "bot", kind: "connector", at: 1,
+ connector: { slug: "github", label: "GitHub", description: "", status: "required", resumeKey: "resume-1" },
+ };
+ expectOwn(button(renderToStaticMarkup(createElement(ConnectorCard, { botId: "scout", color: "silver", threadId: "t", message: connector })), t("connectors.card.connectSecurely")), "silver");
+ const plain = button(renderToStaticMarkup(createElement(ConnectorCard, { botId: "scout", threadId: "t", message: connector })), t("connectors.card.connectSecurely"));
+ expectPlain(plain);
+ expect(classes(plain)).toContain("ui-button-primary");
+ });
+});
diff --git a/src/components/composer-simple.ts b/src/components/composer-simple.ts
index f8fd57e56b..ec21c176bb 100644
--- a/src/components/composer-simple.ts
+++ b/src/components/composer-simple.ts
@@ -1,16 +1,21 @@
import type { Bot, Group } from "@/state/store";
import { effectiveDefaultResponder, groupComposerHint } from "@/lib/group-routing";
import { t } from "@/lib/i18n";
-import { userBubbleTone } from "@/lib/user-bubble-tone";
+import { BOT_BUTTON, botButtonStyle, botButtonTone, type BotButton } from "@/lib/bot-button";
/** Simple mode's small round controls in the composer: the +, the mic and Stop beside the round button. */
export const SIMPLE_CONTROL = "size-7 rounded-full bg-ink/[0.05] ring-[0.5px] ring-inset ring-ink/[0.07] text-ink-tertiary hover:bg-ink/[0.09] hover:text-ink";
-/** The round call, Send and Stop button: the bot's flat tone with its own ink, or the accent in a room. */
-export function slotColors(color: Bot["color"] | undefined, room: boolean): { fill: string; ink: string } {
- if (room) return { fill: "var(--color-accent)", ink: "var(--color-accent-ink)" };
- const tone = userBubbleTone(color ?? "green");
- return { fill: tone.background, ink: tone.ink };
+const ROOM_FILL = { fill: "var(--color-accent)", ink: "var(--color-accent-ink)" };
+
+/** The round call, Send and Stop button: the bot's own button, or the accent in a room. */
+export function slotColors(color: Bot["color"] | undefined, room: boolean): { fill: string; ink: string; button: BotButton } {
+ if (room) {
+ return { ...ROOM_FILL, button: { className: "hover:brightness-110 disabled:opacity-40", style: { backgroundColor: ROOM_FILL.fill, color: ROOM_FILL.ink } } };
+ }
+ const own = color ?? "green";
+ const tone = botButtonTone(own);
+ return { fill: tone.fill, ink: tone.ink, button: { className: BOT_BUTTON, style: botButtonStyle(own) } };
}
export function composerPlaceholder({ simple, locked, approval, attaching, listening, replying, busy, canSteer, queued, busyName, sendLabel, group, members, jevOn, goal, botName, setupHint }: {
diff --git a/src/components/inbox/InboxCard.tsx b/src/components/inbox/InboxCard.tsx
index 67c64c68a3..d1af1e9e84 100644
--- a/src/components/inbox/InboxCard.tsx
+++ b/src/components/inbox/InboxCard.tsx
@@ -6,7 +6,7 @@ import { Check, CornerUpLeft, Inbox, X } from "lucide-react";
import type { InboxRow, InboxView } from "../../../shared/inbox";
import { t } from "@/lib/i18n";
import { openInbox, readInboxRow, useInboxView } from "@/state/inbox";
-import { INBOX_PRIMARY, INBOX_SECONDARY } from "./InboxReading";
+import { inboxPrimary, INBOX_SECONDARY } from "./InboxReading";
import { InboxRowItem } from "./InboxRow";
import { askOf, CARD_ROWS, choiceResponse, choicesOf, rowsIn, tabCounts } from "./inbox-view";
import { useInboxActions } from "./use-inbox-actions";
@@ -22,14 +22,14 @@ export function InboxCardSlot({ threadId, messageId }: { threadId: string; messa
}
function Answers({ row, view }: { row: InboxRow; view: InboxView }) {
- const { answer } = useInboxActions(view);
+ const { answer, colorOf } = useInboxActions(view);
const ask = askOf(row);
const choices = choicesOf(row);
const reading = () => { readInboxRow(row); openInbox({ reading: row.id }); };
if (ask === "approval") {
return (
<>
- <button type="button" data-inbox-action="allow" onClick={() => answer(row, { behavior: "allow" })} className={INBOX_PRIMARY}><Check size={14} aria-hidden="true" />{t("approval.action.allowOnce")}</button>
+ <button type="button" data-inbox-action="allow" onClick={() => answer(row, { behavior: "allow" })} {...inboxPrimary(colorOf(row))}><Check size={14} aria-hidden="true" />{t("approval.action.allowOnce")}</button>
<button type="button" data-inbox-action="deny" onClick={() => answer(row, { behavior: "deny" })} className={INBOX_SECONDARY}><X size={14} aria-hidden="true" />{t("approval.action.deny")}</button>
</>
);
diff --git a/src/components/inbox/InboxPanel.dom.test.ts b/src/components/inbox/InboxPanel.dom.test.ts
index 2ab4fcd718..92e0e8a001 100644
--- a/src/components/inbox/InboxPanel.dom.test.ts
+++ b/src/components/inbox/InboxPanel.dom.test.ts
@@ -13,7 +13,8 @@ vi.mock("../../state/api", () => ({
}),
}));
-import { initialState, StoreContext, type AppState } from "@/state/store";
+import { initialState, StoreContext, type AppState, type Bot } from "@/state/store";
+import { BOT_BUTTON, botButtonTone } from "@/lib/bot-button";
import { closeInbox, currentInboxPanel, inboxVersion, openInbox, setInboxView, useInboxLoader } from "@/state/inbox";
import { approvalRow, inboxView, messageRow, questionRow, reportRow, settledRow } from "@/testing/inbox-fixture";
import type { InboxView } from "../../../shared/inbox";
@@ -24,9 +25,9 @@ import { InboxPanel } from "./InboxPanel";
let root: Root;
const dispatch = vi.fn();
-const mount = (child: ReactElement) => act(async () => {
+const mount = (child: ReactElement, bots: Bot[] = []) => act(async () => {
root.render(createElement(StoreContext.Provider,
- { value: { state: { ...initialState } as AppState, dispatch, flushBotPatches: vi.fn(), refreshInstances: vi.fn(), refreshModels: vi.fn() } as never }, child));
+ { value: { state: { ...initialState, bots } as AppState, dispatch, flushBotPatches: vi.fn(), refreshInstances: vi.fn(), refreshModels: vi.fn() } as never }, child));
});
const settle = () => act(async () => { await new Promise((resolve) => setTimeout(resolve, 0)); });
const click = (selector: string) => act(async () => { document.querySelector<HTMLElement>(selector)!.click(); });
@@ -121,6 +122,37 @@ describe("the inbox's card in the chat", () => {
});
});
+describe("answer buttons in the asking bot's colour", () => {
+ const reporter = { id: "reporter", name: "Reporter", color: "orange" } as Bot;
+ /** The answer under a line, not the quick action on the row itself. */
+ const answer = (selector: string) => [...document.querySelectorAll<HTMLElement>(selector)].find((button) => !button.closest("[data-inbox-row]"))!;
+ const own = (selector: string) => {
+ const button = answer(selector);
+ expect(button.className.split(" ")).toContain(BOT_BUTTON);
+ expect(button.style.getPropertyValue("--bot-button")).toBe(botButtonTone("orange").fill);
+ expect(button.style.getPropertyValue("--bot-button-ink")).toBe(botButtonTone("orange").ink);
+ };
+
+ it("paints Allow on the chat's card and in the panel in the colour of the bot the line is from", async () => {
+ await mount(createElement(InboxCardSlot, { threadId: "inbox", messageId: approvalRow.id }), [reporter]);
+ own('[data-inbox-card] [data-inbox-action="allow"]');
+ expect(answer('[data-inbox-card] [data-inbox-action="deny"]').className.split(" ")).not.toContain(BOT_BUTTON);
+ openInbox({ reading: approvalRow.id });
+ await mount(createElement(InboxPanel), [reporter]);
+ own('[data-inbox-reading] [data-inbox-action="allow"]');
+ });
+
+ it("keeps the plain primary for a teammate's line and for a bot this app does not know", async () => {
+ openInbox({ reading: messageRow.id });
+ await mount(createElement(InboxPanel), [reporter]);
+ const send = document.querySelector<HTMLElement>('[data-inbox-reading] button[type="submit"]')!;
+ expect(send.className.split(" ")).not.toContain(BOT_BUTTON);
+ expect(send.className.split(" ")).toContain("bg-accent");
+ await mount(createElement(InboxCardSlot, { threadId: "inbox", messageId: approvalRow.id }));
+ expect(answer('[data-inbox-card] [data-inbox-action="allow"]').className.split(" ")).not.toContain(BOT_BUTTON);
+ });
+});
+
describe("keeping the list live", () => {
function Loader({ version }: { version: string | null }) {
useInboxLoader(version);
diff --git a/src/components/inbox/InboxReading.tsx b/src/components/inbox/InboxReading.tsx
index f0143338db..c9033dbfce 100644
--- a/src/components/inbox/InboxReading.tsx
+++ b/src/components/inbox/InboxReading.tsx
@@ -3,7 +3,8 @@
import { useState } from "react";
import { ArrowLeft, Check, ExternalLink, Send, X } from "lucide-react";
import type { InboxRow, InboxView } from "../../../shared/inbox";
-import { cn } from "@/lib/cn";
+import { botButton } from "@/lib/bot-button";
+import type { MausColor } from "@/lib/mascot";
import { t } from "@/lib/i18n";
import type { Message } from "@/state/store";
import { readInboxLine, replyToInboxRow } from "@/state/inbox";
@@ -14,7 +15,8 @@ import { askOf, choiceResponse, choicesOf, closeResponse, subjectOf } from "./in
import { useInboxActions } from "./use-inbox-actions";
export const INBOX_BUTTON = "inline-flex h-7 items-center gap-1.5 rounded-full px-3 text-[13px] font-medium transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent";
-export const INBOX_PRIMARY = `${INBOX_BUTTON} bg-accent text-accent-ink hover:bg-accent/90`;
+/** Allow, in the colour of the bot the line is from. */
+export const inboxPrimary = (color: MausColor | undefined) => botButton(color, INBOX_BUTTON, "bg-accent text-accent-ink hover:bg-accent/90");
export const INBOX_SECONDARY = `${INBOX_BUTTON} bg-raised text-ink hover:bg-inset`;
/** The line as the chat shows it, so a question answers here with the very card it asks with in the chat. */
@@ -29,7 +31,8 @@ function settledLabel(row: InboxRow): string {
}
export function InboxReading({ view, row, now }: { view: InboxView; row: InboxRow; now: number }) {
- const { answer, openInChat, run } = useInboxActions(view);
+ const { answer, openInChat, run, colorOf } = useInboxActions(view);
+ const primary = inboxPrimary(colorOf(row));
const [reply, setReply] = useState("");
const [sending, setSending] = useState(false);
const ask = askOf(row);
@@ -77,7 +80,7 @@ export function InboxReading({ view, row, now }: { view: InboxView; row: InboxRo
</p>
))}
{row.tab === "done" && <p className="flex items-center gap-1.5 text-[13px] text-ink-secondary"><Check size={14} aria-hidden="true" />{settledLabel(row)}</p>}
- {ask === "question" && row.card?.questionRequest && view.threadId && <QuestionCard threadId={view.threadId} bot={{ name: row.from.name }} message={asMessage(row)} />}
+ {ask === "question" && row.card?.questionRequest && view.threadId && <QuestionCard threadId={view.threadId} bot={{ name: row.from.name, color: colorOf(row) }} message={asMessage(row)} />}
{ask === "review" && <p className="text-[13px] text-ink-secondary">{t("inbox.reviewInChat")}</p>}
</div>
<footer className="space-y-2 border-t border-hairline/40 px-3 py-2.5">
@@ -85,7 +88,7 @@ export function InboxReading({ view, row, now }: { view: InboxView; row: InboxRo
<div className="flex flex-wrap items-center gap-1.5">
{ask === "approval" ? (
<>
- <button type="button" data-inbox-action="allow" onClick={() => answer(row, { behavior: "allow" })} className={INBOX_PRIMARY}><Check size={14} aria-hidden="true" />{t("approval.action.allowOnce")}</button>
+ <button type="button" data-inbox-action="allow" onClick={() => answer(row, { behavior: "allow" })} {...primary}><Check size={14} aria-hidden="true" />{t("approval.action.allowOnce")}</button>
<button type="button" data-inbox-action="deny" onClick={() => answer(row, { behavior: "deny" })} className={INBOX_SECONDARY}><X size={14} aria-hidden="true" />{t("approval.action.deny")}</button>
</>
) : !row.card?.questionRequest && choices.map((choice) => (
@@ -99,7 +102,7 @@ export function InboxReading({ view, row, now }: { view: InboxView; row: InboxRo
onKeyDown={(event) => { if (event.key === "Enter" && !event.shiftKey) { event.preventDefault(); void send(reply); } }}
className="min-h-[2.5rem] flex-1 resize-none rounded-xl border border-hairline/50 bg-panel px-3 py-2 text-[13px] text-ink placeholder:text-ink-tertiary focus:border-accent/60 focus:outline-none" />
<button type="submit" disabled={!reply.trim() || sending} aria-label={t("chat.send")} title={t("chat.send")}
- className={cn("flex size-9 shrink-0 items-center justify-center rounded-full bg-accent text-accent-ink", (!reply.trim() || sending) && "opacity-50")}>
+ {...botButton(colorOf(row), "flex size-9 shrink-0 items-center justify-center rounded-full", "bg-accent text-accent-ink disabled:opacity-50")}>
<Send size={15} aria-hidden="true" />
</button>
</form>
diff --git a/src/components/inbox/use-inbox-actions.ts b/src/components/inbox/use-inbox-actions.ts
index bb4e00b1b8..d26425c321 100644
--- a/src/components/inbox/use-inbox-actions.ts
+++ b/src/components/inbox/use-inbox-actions.ts
@@ -36,5 +36,8 @@ export function useInboxActions(view: InboxView | null) {
else { readInboxRow(row); openInbox({ reading: row.id }); }
}, [answer, openInChat]);
- return { run, answer, openInChat };
+ /** The bot a line is from, whose colour its answer buttons wear; none for a teammate's line. */
+ const colorOf = (row: InboxRow) => (row.from.botId ? state.bots.find((bot) => bot.id === row.from.botId)?.color : undefined);
+
+ return { run, answer, openInChat, colorOf };
}
diff --git a/src/lib/bot-button.test.ts b/src/lib/bot-button.test.ts
new file mode 100644
index 0000000000..6738d0d487
--- /dev/null
+++ b/src/lib/bot-button.test.ts
@@ -0,0 +1,100 @@
+import { readFileSync } from "node:fs";
+import { dirname, join } from "node:path";
+import { fileURLToPath } from "node:url";
+import { describe, expect, it } from "vitest";
+import { BOT_BUTTON, botButton, botButtonStyle, botButtonTone } from "./bot-button";
+import { contrastRatio, mixSrgb } from "./color-contrast";
+import { MAUS_COLOR_NAMES } from "./mascot";
+import { SKIN_IDS, THEME_SKINS } from "./skins";
+import { userBubbleTone } from "./user-bubble-tone";
+
+const css = readFileSync(join(dirname(fileURLToPath(import.meta.url)), "../styles.css"), "utf8");
+
+function declarations(body: string): Record<string, string> {
+ return Object.fromEntries([...body.matchAll(/(--[\w-]+)\s*:\s*([^;]+);/g)].map(([, name, value]) => [name, value.trim()]));
+}
+
+const theme = declarations(css.match(/@theme\s*\{([^}]*)\}/)?.[1] ?? "");
+const skin = (id: string) => ({
+ ...theme,
+ ...declarations(css.match(new RegExp(`\\[data-skin="${id}"\\]\\s*\\{([^}]*)\\}`))?.[1] ?? ""),
+});
+
+/** A token with alpha, as the eye sees it over `background`. */
+function over(color: string, background: string): string {
+ const alpha = /^#[0-9a-f]{8}$/i.test(color) ? parseInt(color.slice(7), 16) / 255 : 1;
+ return mixSrgb(color.slice(0, 7), background, alpha);
+}
+
+/** The label and icon are 13px or 14px: normal text, so 4.5:1. */
+const LABEL_MIN = 4.5;
+/** A focus ring against what it sits on: WCAG 1.4.11. */
+const RING_MIN = 3;
+
+function rule(selector: string): string {
+ const at = css.indexOf(`\n${selector} {`) + 1;
+ expect(at, selector).toBeGreaterThan(0);
+ const before = css.slice(0, at).replace(/\/\*[\s\S]*?\*\//g, "");
+ expect(before.split("{").length - before.split("}").length, `${selector} sits outside any @layer`).toBe(0);
+ return css.slice(at, css.indexOf("}", at));
+}
+
+describe("a bot's own button", () => {
+ it.each(MAUS_COLOR_NAMES)("paints %s with the very fill and ink of its Simple bubble", (color) => {
+ const bubble = userBubbleTone(color);
+ const tone = botButtonTone(color);
+ expect(tone.fill).toBe(bubble.background);
+ expect(tone.ink).toBe(bubble.ink);
+ expect(new Set([tone.fill, tone.hover, tone.pressed]).size).toBe(3);
+ });
+
+ it("covers a light bot colour that needs dark ink", () => {
+ expect(botButtonTone("yellow").ink).toBe("#101410");
+ expect(MAUS_COLOR_NAMES.filter((color) => botButtonTone(color).ink !== "#ffffff")).toEqual(["yellow"]);
+ });
+
+ it("is a light and a dark theme by default, and every skin is checked below", () => {
+ expect(SKIN_IDS).toEqual(expect.arrayContaining([THEME_SKINS.light, THEME_SKINS.dark]));
+ });
+
+ it.each(SKIN_IDS.flatMap((id) => MAUS_COLOR_NAMES.map((color) => [id, color] as const)))(
+ "reads at AA for %s × %s, resting, hovered, pressed, focused and disabled",
+ (id, color) => {
+ const tokens = skin(id);
+ const tone = botButtonTone(color);
+ for (const [state, fill] of [["resting", tone.fill], ["hover", tone.hover], ["pressed", tone.pressed]] as const) {
+ expect(contrastRatio(tone.ink, fill), `${state} label`).toBeGreaterThanOrEqual(LABEL_MIN);
+ }
+ expect(contrastRatio(tone.ink, tone.hover)).toBeGreaterThan(contrastRatio(tone.ink, tone.fill));
+ expect(contrastRatio(tone.ink, tone.pressed)).toBeGreaterThan(contrastRatio(tone.ink, tone.hover));
+ for (const surface of ["--color-app", "--color-card", "--color-composer", "--color-panel"]) {
+ expect(tokens[surface], `${id} ${surface}`).toMatch(/^#[0-9a-f]{6}$/i);
+ expect(contrastRatio(tokens["--color-focus"]!, tokens[surface]!), `focus ring on ${surface}`).toBeGreaterThanOrEqual(RING_MIN);
+ }
+ const disabled = tokens["--color-raised-hover"]!;
+ expect(contrastRatio(over(tokens["--color-ink-secondary"]!, disabled), disabled), "disabled label").toBeGreaterThanOrEqual(RING_MIN);
+ expect(disabled).not.toBe(tokens["--color-composer"]);
+ },
+ );
+
+ it("is painted by an unlayered rule from the four properties botButtonStyle sets", () => {
+ expect(rule(".bot-button")).toMatch(/background-color:\s*var\(--bot-button\);[\s\S]*color:\s*var\(--bot-button-ink\);/);
+ expect(rule(".bot-button:enabled:hover")).toContain("background-color: var(--bot-button-hover);");
+ expect(rule(".bot-button:enabled:active")).toContain("background-color: var(--bot-button-pressed);");
+ expect(rule(":focus-visible")).toMatch(/outline:\s*2px solid var\(--color-focus\);[\s\S]*outline-offset:\s*2px;/);
+ expect(css).not.toMatch(/\.bot-button[^{]*:focus-visible/);
+ expect(rule(".bot-button:disabled")).toMatch(/background-color:\s*var\(--color-raised-hover\);[\s\S]*color:\s*var\(--color-ink-secondary\);/);
+ const tone = botButtonTone("blue");
+ expect(botButtonStyle("blue")).toEqual({
+ "--bot-button": tone.fill, "--bot-button-ink": tone.ink, "--bot-button-hover": tone.hover, "--bot-button-pressed": tone.pressed,
+ });
+ });
+
+ it("keeps the plain look when no single bot owns the button", () => {
+ expect(botButton(undefined, "h-7 rounded-full", "bg-accent text-accent-ink")).toEqual({ className: "h-7 rounded-full bg-accent text-accent-ink" });
+ const own = botButton("purple", "h-7 rounded-full", "bg-accent text-accent-ink");
+ expect(own.className).toBe(`h-7 rounded-full ${BOT_BUTTON}`);
+ expect(own.className).not.toContain("ui-button-primary");
+ expect(own.style).toEqual(botButtonStyle("purple"));
+ });
+});
diff --git a/src/lib/bot-button.ts b/src/lib/bot-button.ts
new file mode 100644
index 0000000000..dbea06e85d
--- /dev/null
+++ b/src/lib/bot-button.ts
@@ -0,0 +1,43 @@
+import type { CSSProperties } from "react";
+import { mixSrgb } from "./color-contrast";
+import type { MausColor } from "./mascot";
+import { userBubbleTone } from "./user-bubble-tone";
+
+/** Hover and press step the fill away from its ink, so the label only gains contrast. */
+const HOVER_MIX = 0.12;
+const PRESSED_MIX = 0.22;
+
+export const BOT_BUTTON = "bot-button";
+
+export type BotButtonTone = { fill: string; ink: string; hover: string; pressed: string };
+
+/** A bot's own primary button: the flat fill and ink of its Simple bubble. */
+export function botButtonTone(color: MausColor): BotButtonTone {
+ const { background, ink } = userBubbleTone(color);
+ const away = ink === "#ffffff" ? "#000000" : "#ffffff";
+ return {
+ fill: background,
+ ink,
+ hover: mixSrgb(away, background, HOVER_MIX),
+ pressed: mixSrgb(away, background, PRESSED_MIX),
+ };
+}
+
+export function botButtonStyle(color: MausColor): CSSProperties {
+ const tone = botButtonTone(color);
+ return {
+ "--bot-button": tone.fill,
+ "--bot-button-ink": tone.ink,
+ "--bot-button-hover": tone.hover,
+ "--bot-button-pressed": tone.pressed,
+ } as CSSProperties;
+}
+
+export type BotButton = { className: string; style?: CSSProperties };
+
+/** A primary action that belongs to one bot. `shape` sizes it either way; `plain` is its look when no single bot owns
+ * it, as in a room or for a teammate's line. */
+export function botButton(color: MausColor | undefined, shape: string, plain: string): BotButton {
+ const classes = (look: string) => [shape, look].filter(Boolean).join(" ");
+ return color ? { className: classes(BOT_BUTTON), style: botButtonStyle(color) } : { className: classes(plain) };
+}
diff --git a/src/styles.css b/src/styles.css
index 366839c555..fd8d8b105d 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -978,6 +978,26 @@
background: color-mix(in srgb, var(--color-ink) 15%, transparent);
}
+/* A primary action that belongs to one bot wears that bot's flat bubble tone in every skin. Unlayered, like the
+ neutral pill above, so no utility repaints it. Its focus ring is the global one, 2px off the fill, so it reads on
+ any bot colour; a disabled one takes the same quiet colours as a disabled accent button. */
+.bot-button {
+ border-color: transparent;
+ background-color: var(--bot-button);
+ color: var(--bot-button-ink);
+}
+.bot-button:enabled:hover {
+ background-color: var(--bot-button-hover);
+}
+.bot-button:enabled:active {
+ background-color: var(--bot-button-pressed);
+}
+.bot-button:disabled {
+ background-color: var(--color-raised-hover);
+ color: var(--color-ink-secondary);
+ opacity: 1;
+}
+
/* Shiki emits both palettes so cached blocks follow the nearest skin without
re-tokenizing. Scope the scheme to code; native controls keep their styling. */
.chat-md .shiki {