Skip to content

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

Move the pinned message into a header menu

luishron123a5f4514ef82c
diff --git a/src/components/ChatPinnedBanner.tsx b/src/components/ChatPinnedBanner.tsx
deleted file mode 100644
index 49d14c757b..0000000000
--- a/src/components/ChatPinnedBanner.tsx
+++ /dev/null
@@ -1,51 +0,0 @@
-import { Pin, X } from "lucide-react";
-import type { Bot, Message } from "@/state/store";
-import { t } from "@/lib/i18n";
-import { peerLine } from "@/lib/peer-message";
-import { citationPreviewText } from "@/lib/citations";
-
-/** The chat's pinned message above the transcript: who said it, a one-line preview that jumps to it, and Unpin. */
-export function PinnedBanner({
- bot,
- pinnedId,
- messages,
- onJump,
- onUnpin,
-}: {
- bot: Bot;
- pinnedId?: string;
- messages: Message[];
- onJump: (messageId: string) => void;
- onUnpin?: () => void;
-}) {
- const pinned = messages.find((m) => m.id === pinnedId);
- if (!pinned || pinned.kind !== "text") return null;
- const pinnedPeer = peerLine(pinned);
- const sender =
- pinned.role === "user" ? (pinnedPeer?.name ?? t("chat.you")) : (pinned.from?.name ?? bot.name);
- const text = citationPreviewText(pinnedPeer?.body ?? pinned.text ?? "").replace(/\s+/g, " ").trim();
- if (!text) return null;
- return (
- <div className="w-full px-5">
- <div className="mb-2 flex items-center gap-2 rounded-lg border border-accent/25 bg-accent/[0.07] px-3 py-1.5">
- <Pin size={12} className="shrink-0 text-accent" />
- <button
- onClick={() => onJump(pinned.id)}
- className="flex min-w-0 flex-1 items-baseline gap-2 text-left"
- title={t("chat.pinnedJump")}
- >
- <span className="shrink-0 text-[12px] font-medium text-accent">{sender}</span>
- <span dir="auto" className="truncate text-[13px] text-ink-secondary">{text}</span>
- </button>
- {onUnpin && <button
- onClick={onUnpin}
- aria-label={t("chat.unpinMessage")}
- title={t("chat.unpin")}
- className="shrink-0 rounded p-0.5 text-ink-secondary hover:bg-raised hover:text-ink"
- >
- <X size={13} />
- </button>}
- </div>
- </div>
- );
-}
diff --git a/src/components/ChatView.tsx b/src/components/ChatView.tsx
index d44ca61fbd..722d42b0a3 100644
--- a/src/components/ChatView.tsx
+++ b/src/components/ChatView.tsx
@@ -126,7 +126,7 @@ import { appendComposerDraft, appendDraftAttachments, useReplyDraft } from "@/li
import { botLineText, localDay, transcriptLookups, type TranscriptLookups } from "@/lib/transcript-derivations"; import { DaySeparator } from "./DaySeparator";
import { splitTranscriptCitations, type CitationAttachment } from "@/lib/citations";
import { EmptyChat } from "./ChatEmptyState";
-import { PinnedBanner } from "./ChatPinnedBanner";
+import { PinnedMessagesMenu, pinnedPreview } from "./PinnedMessagesMenu";
import { highlightCitationSource } from "@/lib/citations-dom";
import { useCanWriteIn, useReactor } from "@/lib/cloud-guest";
import { formattedReplyWidth, isFormattedReply, splitReplyBlocks } from "@/lib/formatted-reply";
@@ -1090,6 +1090,12 @@ export const ChatView = memo(function ChatView({ bot: profile, inForkPanel = fal
{/* The model and the bot's computer stay in view in both modes; Simple mode moves only ⋯ into the bot panel. */}
{!phone && <ModelPicker key={bot.threadId} bot={bot} threadId={bot.threadId} />}
<LiveCallChip currentBotId={bot.id} onOpen={(botId, threadId) => openThread(dispatch, { botId, threadId }, store.state(), showThreads)} />{!phoneMenu && <WatchScreenButton botId={bot.id} messages={messages} liveTools={liveTools} place={place} />}
+ <PinnedMessagesMenu
+ pins={pinnedPreview(messages, bot.pinnedMessageId, bot.name)}
+ triggerClassName={cn(ELEVATED_FLOAT, ELEVATED_HOVER)}
+ onJump={(messageId) => dispatch({ type: "focusMessage", threadId: bot.threadId, messageId })}
+ onUnpin={remoteClient ? undefined : () => dispatch({ type: "updateTask", botId: bot.id, threadId: bot.threadId, patch: { pinnedMessageId: "" } })}
+ />
{!phoneMenu && <button
data-tour="computer"
onClick={(event) => { if (!state.computerOpen) rememberComputerPanelOpen({ botId: bot.id, opener: event.currentTarget, tabs: event.detail === 0 }); dispatch({ type: "toggleComputer" }); }}
@@ -1118,18 +1124,6 @@ export const ChatView = memo(function ChatView({ bot: profile, inForkPanel = fal
<ChatErrorBanner message={state.error} onDismiss={() => dispatch({ type: "error", message: null })} />
<ChatNotice notice={state.notice} />
- <PinnedBanner
- bot={bot}
- pinnedId={bot.pinnedMessageId}
- messages={messages}
- onJump={(messageId) =>
- dispatch({ type: "focusMessage", threadId: bot.threadId, messageId })
- }
- onUnpin={remoteClient ? undefined : () =>
- dispatch({ type: "updateTask", botId: bot.id, threadId: bot.threadId, patch: { pinnedMessageId: "" } })
- }
- />
-
</GlassBar>
<div
diff --git a/src/components/GroupView.tsx b/src/components/GroupView.tsx
index ce69faed8b..95465d225e 100644
--- a/src/components/GroupView.tsx
+++ b/src/components/GroupView.tsx
@@ -4,7 +4,7 @@ import { activeLocale, intlLocale, t } from "@/lib/i18n";
import { useShowThreads } from "@/lib/thread-preferences";
import { useReactor } from "@/lib/cloud-guest";
import { otherSpeaker } from "@/lib/own-profile";
-import { Check, ChevronDown, FolderOpen, Loader2, Pin, Square, X } from "lucide-react";
+import { Check, ChevronDown, FolderOpen, Loader2, Square } from "lucide-react";
import {
api,
useStore,
@@ -86,7 +86,7 @@ import { useUnreadDivider } from "@/hooks/use-unread-divider";
import { unreadMessageIds } from "@/lib/unread-divider";
import { NewMessagesDivider } from "./NewMessagesDivider";
import { appendDraftAttachments, useReplyDraft } from "@/lib/drafts";
-import { citationPreviewText, splitTranscriptCitations, type CitationAttachment } from "@/lib/citations";
+import { splitTranscriptCitations, type CitationAttachment } from "@/lib/citations";
import { highlightCitationSource } from "@/lib/citations-dom";
import { latestFailure, latestReply, type TranscriptSnapshot } from "@/lib/transcript-announcer";
import { pendingApprovals } from "./PendingApproval";
@@ -1047,35 +1047,6 @@ export function GroupView({ group, inForkPanel = false }: { group: Group; inFork
</div>
)}
- {(() => {
- const pinned = group.messages.find((m) => m.id === group.pinnedMessageId && m.kind === "text");
- const text = pinned ? citationPreviewText(pinned.text ?? "").replace(/\s+/g, " ").trim() : "";
- if (!pinned || !text) return null;
- const sender = pinned.role === "user" ? t("chat.you") : (pinned.from?.name ?? t("room.aBot"));
- return (
- <div className="w-full px-5">
- <div className="mb-2 flex items-center gap-2 rounded-lg border border-accent/25 bg-accent/[0.07] px-3 py-1.5">
- <Pin size={12} className="shrink-0 text-accent" />
- <button
- onClick={() => dispatch({ type: "focusMessage", threadId: group.threadId, messageId: pinned.id })}
- className="flex min-w-0 flex-1 items-baseline gap-2 text-left"
- title={t("chat.pinnedJump")}
- >
- <span className="shrink-0 text-[12px] font-medium text-accent">{sender}</span>
- <span dir="auto" className="truncate text-[13px] text-ink-secondary">{text}</span>
- </button>
- <button
- onClick={() => dispatch({ type: "patchGroup", groupId: group.id, patch: { pinnedMessageId: "" } })}
- aria-label={t("chat.unpinMessage")}
- title={t("chat.unpin")}
- className={cn("shrink-0 rounded p-0.5 text-ink-secondary hover:bg-raised hover:text-ink", remoteClient && "hidden")}
- >
- <X size={13} />
- </button>
- </div>
- </div>
- );
- })()}
</GlassBar>
<div
diff --git a/src/components/PinnedMessagesMenu.dom.test.ts b/src/components/PinnedMessagesMenu.dom.test.ts
new file mode 100644
index 0000000000..1a76e0dc50
--- /dev/null
+++ b/src/components/PinnedMessagesMenu.dom.test.ts
@@ -0,0 +1,72 @@
+// @vitest-environment happy-dom
+import { act, createElement } from "react";
+import { createRoot } from "react-dom/client";
+import { afterEach, expect, it, vi } from "vitest";
+import type { Message } from "@/state/store";
+import { PinnedMessagesMenu, pinnedPreview } from "./PinnedMessagesMenu";
+
+(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+afterEach(() => { document.body.innerHTML = ""; });
+
+const message = (patch: Partial<Message>): Message => ({ id: "m1", role: "bot", kind: "text", text: "Ship on Friday", createdAt: 1, ...patch }) as Message;
+const PINS = [{ id: "m1", sender: "Pepper", text: "Ship on Friday" }];
+
+async function mount(props: Partial<Parameters<typeof PinnedMessagesMenu>[0]> = {}) {
+ const onJump = vi.fn(), onUnpin = vi.fn();
+ const root = createRoot(document.body.appendChild(document.createElement("div")));
+ await act(async () => root.render(createElement(PinnedMessagesMenu, { pins: PINS, onJump, onUnpin, ...props })));
+ return { root, onJump, onUnpin };
+}
+const trigger = () => document.querySelector<HTMLButtonElement>("[data-pinned-menu] > button");
+const items = () => [...document.querySelectorAll<HTMLButtonElement>("[role=menu] [role=menuitem]")];
+const key = (name: string) => act(async () => { document.activeElement!.dispatchEvent(new KeyboardEvent("keydown", { key: name, bubbles: true, cancelable: true })); });
+
+it("shows no button while nothing is pinned", async () => {
+ const { root } = await mount({ pins: [] });
+ expect(trigger()).toBeNull();
+ act(() => root.unmount());
+});
+
+it("lists who said the pinned message and what, and jumps to it", async () => {
+ const { root, onJump } = await mount();
+ expect(document.querySelector("[role=menu]")).toBeNull();
+ await act(async () => trigger()!.click());
+ expect(trigger()!.getAttribute("aria-expanded")).toBe("true");
+ expect(items()[0]!.textContent).toBe("PepperShip on Friday");
+ expect(document.activeElement).toBe(items()[0]);
+ await act(async () => items()[0]!.click());
+ expect(onJump).toHaveBeenCalledWith("m1");
+ expect(trigger()!.getAttribute("aria-expanded")).toBe("false");
+ act(() => root.unmount());
+});
+
+it("reaches Unpin with the arrows, and Escape closes the menu back onto its button", async () => {
+ const { root, onUnpin } = await mount();
+ await act(async () => trigger()!.click());
+ await key("ArrowDown");
+ expect(document.activeElement).toBe(items()[1]);
+ await key("Home");
+ expect(document.activeElement).toBe(items()[0]);
+ await key("End");
+ await act(async () => (document.activeElement as HTMLButtonElement).click());
+ expect(onUnpin).toHaveBeenCalledWith("m1");
+ await key("Escape");
+ expect(trigger()!.getAttribute("aria-expanded")).toBe("false");
+ expect(document.activeElement).toBe(trigger());
+ act(() => root.unmount());
+});
+
+it("offers no Unpin to someone who cannot change the conversation", async () => {
+ const { root } = await mount({ onUnpin: undefined });
+ await act(async () => trigger()!.click());
+ expect(items()).toHaveLength(1);
+ act(() => root.unmount());
+});
+
+it("previews only a text message that still exists", () => {
+ expect(pinnedPreview([message({})], "m1", "Pepper")).toEqual(PINS);
+ expect(pinnedPreview([message({ role: "user" })], "m1", "Pepper")[0]!.sender).toBe("You");
+ expect(pinnedPreview([message({})], "gone", "Pepper")).toEqual([]);
+ expect(pinnedPreview([message({})], undefined, "Pepper")).toEqual([]);
+ expect(pinnedPreview([message({ text: " " })], "m1", "Pepper")).toEqual([]);
+});
diff --git a/src/components/PinnedMessagesMenu.test.ts b/src/components/PinnedMessagesMenu.test.ts
new file mode 100644
index 0000000000..3037254f14
--- /dev/null
+++ b/src/components/PinnedMessagesMenu.test.ts
@@ -0,0 +1,11 @@
+import { readFileSync } from "node:fs";
+import { expect, it } from "vitest";
+
+it("keeps the pinned message out of the strip above both transcripts", () => {
+ for (const file of ["ChatView.tsx", "GroupView.tsx"]) {
+ const text = readFileSync(new URL(`./${file}`, import.meta.url), "utf8");
+ expect(text, file).not.toContain("chat.pinnedJump");
+ }
+ expect(readFileSync(new URL("./RoomHeader.tsx", import.meta.url), "utf8")).toContain("<PinnedMessagesMenu");
+ expect(readFileSync(new URL("./ChatView.tsx", import.meta.url), "utf8")).toMatch(/<PinnedMessagesMenu[\s\S]{0,600}data-tour="computer"/);
+});
diff --git a/src/components/PinnedMessagesMenu.tsx b/src/components/PinnedMessagesMenu.tsx
new file mode 100644
index 0000000000..752e0b4546
--- /dev/null
+++ b/src/components/PinnedMessagesMenu.tsx
@@ -0,0 +1,109 @@
+import { useEffect, useRef, useState, type KeyboardEvent } from "react";
+import { Pin, PinOff } from "lucide-react";
+import type { Message } from "@/state/store";
+import { cn } from "@/lib/cn";
+import { t } from "@/lib/i18n";
+import { peerLine } from "@/lib/peer-message";
+import { citationPreviewText } from "@/lib/citations";
+import { usePopoverDismiss } from "@/hooks/use-popover-dismiss";
+import { useMenuMotion } from "./MenuMotion";
+import { MENU_LABEL, MENU_SHEET, SIMPLE_MENU_META, SIMPLE_MENU_ROW } from "./menu-recipe";
+
+export type PinnedPreview = { id: string; sender: string; text: string };
+
+export function pinnedPreview(messages: readonly Message[], pinnedId: string | undefined, botName: string, peers = true): PinnedPreview[] {
+ const pinned = pinnedId ? messages.find((message) => message.id === pinnedId) : undefined;
+ if (!pinned || pinned.kind !== "text") return [];
+ const peer = peers ? peerLine(pinned) : null;
+ const sender = pinned.role === "user" ? (peer?.name ?? t("chat.you")) : (pinned.from?.name ?? botName);
+ const text = citationPreviewText(peer?.body ?? pinned.text ?? "").replace(/\s+/g, " ").trim();
+ return text ? [{ id: pinned.id, sender, text }] : [];
+}
+
+/** The conversation's pinned messages behind one header button: each row jumps to its message, and Unpin sits beside it. */
+export function PinnedMessagesMenu({ pins, onJump, onUnpin, triggerClassName }: {
+ pins: readonly PinnedPreview[];
+ onJump: (messageId: string) => void;
+ onUnpin?: (messageId: string) => void;
+ triggerClassName?: string;
+}) {
+ const [open, setOpen] = useState(false);
+ const motion = useMenuMotion(open);
+ const root = useRef<HTMLDivElement>(null);
+ const trigger = useRef<HTMLButtonElement>(null);
+ const menu = useRef<HTMLDivElement>(null);
+ usePopoverDismiss(open, root, () => { setOpen(false); trigger.current?.focus(); });
+ useEffect(() => {
+ if (open) menu.current?.querySelector<HTMLElement>("[role=menuitem]")?.focus();
+ }, [open]);
+ if (!pins.length) return null;
+
+ const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
+ const items = Array.from(menu.current?.querySelectorAll<HTMLElement>("[role=menuitem]") ?? []);
+ const at = items.indexOf(document.activeElement as HTMLElement);
+ const next = event.key === "ArrowDown" ? items[(at + 1) % items.length]
+ : event.key === "ArrowUp" ? items[(at - 1 + items.length) % items.length]
+ : event.key === "Home" ? items[0]
+ : event.key === "End" ? items[items.length - 1]
+ : undefined;
+ if (!next) return;
+ event.preventDefault();
+ next.focus();
+ };
+
+ return (
+ <div ref={root} data-pinned-menu className="relative">
+ <button
+ ref={trigger}
+ type="button"
+ onClick={() => setOpen((shown) => !shown)}
+ aria-label={t("chat.pinnedMessages")}
+ title={t("chat.pinnedMessages")}
+ aria-haspopup="menu"
+ aria-expanded={open}
+ className={cn("flex size-8 items-center justify-center rounded-full text-ink-secondary hover:text-ink aria-expanded:text-accent", triggerClassName)}
+ >
+ <Pin size={16} />
+ </button>
+ {motion.shown && (
+ <div
+ ref={menu}
+ role="menu"
+ aria-label={t("chat.pinnedMessages")}
+ onKeyDown={onKeyDown}
+ className={cn("absolute end-0 top-full z-40 mt-1.5 w-80 max-w-[calc(100vw-1rem)]", MENU_SHEET, motion.className)}
+ {...motion.exitProps}
+ >
+ <div className={MENU_LABEL}>{t("chat.pinnedMessages")}</div>
+ {pins.map((pin) => (
+ <div key={pin.id} className="flex items-start gap-1">
+ <button
+ type="button"
+ role="menuitem"
+ data-pinned-jump={pin.id}
+ title={t("chat.pinnedJump")}
+ onClick={() => { setOpen(false); onJump(pin.id); }}
+ className={cn(SIMPLE_MENU_ROW, "flex-1 flex-col items-start gap-0 py-1.5")}
+ >
+ <span className={SIMPLE_MENU_META}>{pin.sender}</span>
+ <span dir="auto" className="line-clamp-2 w-full [overflow-wrap:anywhere]">{pin.text}</span>
+ </button>
+ {onUnpin && (
+ <button
+ type="button"
+ role="menuitem"
+ aria-label={t("chat.unpinMessage")}
+ title={t("chat.unpin")}
+ onClick={() => onUnpin(pin.id)}
+ className="flex size-[30px] shrink-0 items-center justify-center rounded-md text-ink-secondary hover:bg-ink/[0.06] hover:text-ink focus:bg-ink/[0.06] focus:text-ink touch:size-10"
+ >
+ <PinOff size={16} />
+ </button>
+ )}
+ </div>
+ ))}
+ </div>
+ )}
+ </div>
+ );
+}
diff --git a/src/components/RoomHeader.tsx b/src/components/RoomHeader.tsx
index 3ebef2316e..9892069d96 100644
--- a/src/components/RoomHeader.tsx
+++ b/src/components/RoomHeader.tsx
@@ -18,6 +18,7 @@ import { useCaptionChrome } from "./DesktopCapabilities";
import { ExportTranscriptMenu } from "./ExportTranscriptMenu";
import { RoomHeaderCallButton } from "./GroupCallView";
import { GroupUsageChip } from "./GroupUsageChip";
+import { PinnedMessagesMenu, pinnedPreview } from "./PinnedMessagesMenu";
import { PlaceIcon } from "./PlaceIcon";
import { roomMemberQueueTitle } from "./RoomQueueList";
import { RoomWorkingFolderChip } from "./RoomWorkingFolder";
@@ -147,7 +148,16 @@ export function RoomHeader({
membersTriggerRef: RefObject<HTMLButtonElement | null>;
}) {
const { dragProps: headerDragProps, noDragStyle: headerNoDragStyle } = useCaptionChrome();
+ const { dispatch } = useStore();
const faces = memberMauses(group, members);
+ const pinned = (
+ <PinnedMessagesMenu
+ pins={pinnedPreview(group.messages, group.pinnedMessageId, t("room.aBot"), false)}
+ triggerClassName="transition-colors hover:bg-ink/[0.06]"
+ onJump={(messageId) => dispatch({ type: "focusMessage", threadId: group.threadId, messageId })}
+ onUnpin={remoteClient ? undefined : () => dispatch({ type: "patchGroup", groupId: group.id, patch: { pinnedMessageId: "" } })}
+ />
+ );
const membersLabel = members.length === 1
? t("room.members.ariaOne")
: t("room.members.ariaMany", { count: members.length });
@@ -174,6 +184,7 @@ export function RoomHeader({
</div>
<div data-roomhead-controls className="flex shrink-0 items-center gap-1.5">
<ThreadPresenceFaces threadId={group.threadId} />
+ {pinned}
<button
ref={membersTriggerRef}
type="button"
@@ -222,6 +233,7 @@ export function RoomHeader({
className="flex items-center gap-1.5 @max-3xl/roomhead:ml-auto @max-3xl/roomhead:flex-wrap @max-3xl/roomhead:justify-end"
>
<ThreadPresenceFaces threadId={group.threadId} />
+ {pinned}
<button
type="button"
onClick={onToggleFind}
diff --git a/src/components/chat-dir-auto.test.ts b/src/components/chat-dir-auto.test.ts
index f23d7b7916..d04eaa0f38 100644
--- a/src/components/chat-dir-auto.test.ts
+++ b/src/components/chat-dir-auto.test.ts
@@ -27,7 +27,6 @@ describe("chat text follows the writer's direction", () => {
const quotes = source("CitationUI.tsx").match(/<pre dir="auto"[^>]*>\{citation\.quote\}/g) ?? [];
expect(quotes).toHaveLength(2);
- const pins = [source("ChatPinnedBanner.tsx"), source("GroupView.tsx")].map((text) => text.includes('dir="auto" className="truncate text-[13px] text-ink-secondary"'));
- expect(pins).toEqual([true, true]);
+ expectDirAuto("PinnedMessagesMenu.tsx", "{pin.text}");
});
});
diff --git a/src/locales/en.json b/src/locales/en.json
index acee464452..532786ad84 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -2674,6 +2674,7 @@
"chat.unpinHint": "Unpin this message",
"chat.unpin": "Unpin",
"chat.pinnedJump": "Jump to the pinned message",
+ "chat.pinnedMessages": "Pinned messages",
"chat.you": "You",
"chat.peer.asked": "asked via ask_bot",
"chat.peer.handedTask": "handed on a task",