Skip to content

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

Sidebar: peek a bot's open conversations on hover in Simple mode

luishron12376d303f36b35
diff --git a/src/components/Sidebar.simple-mode.test.ts b/src/components/Sidebar.simple-mode.test.ts
index d7830ccc9c..446084ef30 100644
--- a/src/components/Sidebar.simple-mode.test.ts
+++ b/src/components/Sidebar.simple-mode.test.ts
@@ -157,7 +157,7 @@ describe("bot-first sidebar", () => {
const line = markup.slice(markup.indexOf(">Done.<"));
expect(line).toMatch(/^>Done\.<\/span><\/span><span data-testid="model-badge" role="img" aria-label="Model: [^"]+ \(Claude\)" class="[^"]*\bms-auto\b[^"]*"><span data-provider-mark="brand" class="[^"]*\bopacity-60\b/);
expect(line).toMatch(/^>Done\.<\/span><\/span><span data-testid="model-badge"[^>]*><span data-provider-mark="brand"[^>]*><svg[\s\S]*?<\/svg><\/span><\/span><\/div><span class="sr-only">Unread<\/span>/);
- const name = markup.slice(markup.indexOf('class="flex items-baseline justify-between gap-2 pr-7"'), markup.indexOf(">Done.<"));
+ const name = markup.slice(markup.indexOf('class="flex items-baseline justify-between gap-2 pr-7 group-hover:pr-[3.25rem] group-focus-within:pr-[3.25rem] touch:pr-[3.25rem] max-md:touch:pr-7"'), markup.indexOf(">Done.<"));
expect(name).toMatch(/<span aria-hidden="true" data-row-dot="" class="pointer-events-none absolute right-\[3px\] top-1\.5 flex size-6 items-center justify-center transition-opacity group-hover:opacity-0 group-focus-within:opacity-0 touch:opacity-0 max-md:hidden"><span data-testid="unread-dot" title="Unread" class="size-2 shrink-0 rounded-full bg-accent"><\/span><\/span>/);
expect(name).toContain('<span aria-hidden="true" title="Unread" class="size-2 shrink-0 rounded-full bg-accent hidden self-center max-md:block touch:block"></span>');
expect(markup.match(/data-provider-mark=/g)).toHaveLength(1);
@@ -245,7 +245,7 @@ describe("bot-first sidebar", () => {
const simple = renderToStaticMarkup(createElement(BotListItem, rowProps("comfortable", candidate)));
expect(simple).toContain("[--row:var(--color-raised)]");
expect(simple).toMatch(/data-bot-actions="atlas"[^>]*class="[^"]*\bpointer-events-none opacity-0 group-hover:pointer-events-auto/);
- expect(simple).toContain('class="flex items-baseline justify-between gap-2 pr-7"');
+ expect(simple).toContain('class="flex items-baseline justify-between gap-2 pr-7 group-hover:pr-[3.25rem] group-focus-within:pr-[3.25rem] touch:pr-[3.25rem] max-md:touch:pr-7"');
fixture.advanced = true;
expect(renderToStaticMarkup(createElement(BotListItem, rowProps("comfortable", candidate)))).toMatch(/data-bot-actions="atlas"[^>]*class="[^"]*\bpointer-events-auto opacity-100/);
});
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx
index 0136d8d057..8efbf53c1e 100644
--- a/src/components/Sidebar.tsx
+++ b/src/components/Sidebar.tsx
@@ -23,7 +23,7 @@ import { copyText } from "@/lib/copy-text";
import type { LocaleKey } from "@/locales";
import { ConfirmDialog } from "./ConfirmDialog";
import { BulkSelectFilters, ThreadListFooter, deleteThreadsInBulk, useBulkSelect } from "./BulkSelectBar";
-
+import { SidebarBotThreadsPeek } from "./SidebarBotThreadsPeek";
import { RoomMark, StackedMauses } from "./StackedMauses";
import { LocalComputerAutoWarning } from "./LocalComputerAutoWarning";
import { nextRename } from "@/lib/rename";
@@ -776,7 +776,7 @@ export const BotListItem = memo(function BotListItem(props: BotRowProps) {
)}
</span>
<div className={cn("min-w-0 flex-1", iconOnly && "hidden")}>
- <div className={cn("flex items-baseline justify-between gap-2", simpleRow && "pr-7")}>
+ <div className={cn("flex items-baseline justify-between gap-2", simpleRow && "pr-7 group-hover:pr-[3.25rem] group-focus-within:pr-[3.25rem] touch:pr-[3.25rem] max-md:touch:pr-7")}>
<span className={cn("flex min-w-0 grow items-center gap-1.5 truncate text-ink", simpleRow ? "text-[14px] font-medium leading-5" : "text-[15px] font-semibold leading-5")}>
{!simpleList && bot.pinned && <Pin size={12} className="shrink-0 text-ink-secondary" />}
<RenameTitle
@@ -905,7 +905,7 @@ export const BotListItem = memo(function BotListItem(props: BotRowProps) {
<button type="button" data-bot-actions={bot.id} aria-label={t("sidebar.bot.actions", { name: bot.name })} title={t("sidebar.bot.actions", { name: bot.name })} aria-haspopup="menu" onClick={(event) => { const rect = event.currentTarget.getBoundingClientRect(); onMenu({ botId: bot.id, x: rect.left, y: rect.bottom }); }}
className={cn("absolute right-1 top-1/2 flex size-7 -translate-y-1/2 items-center justify-center rounded text-ink-secondary hover:bg-raised hover:text-ink", simpleRow && "right-[3px] top-1.5 size-6 translate-y-0 rounded-lg",
selected && !simpleRow ? "pointer-events-auto opacity-100" : "pointer-events-none opacity-0 group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100 max-md:pointer-events-auto max-md:opacity-70 touch:pointer-events-auto touch:opacity-70")}><MoreHorizontal size={15} /></button>
- </>}
+ </>}{!renaming && !deleting && simpleRow && <SidebarBotThreadsPeek bot={bot} dispatch={dispatch} />}
{deleting && iconOnly && (
<span className="pointer-events-none absolute bottom-1 right-1 rounded-full bg-card p-1 text-ink-secondary">
<Loader2 size={12} className="animate-spin" />
diff --git a/src/components/SidebarBotThreadsPeek.test.ts b/src/components/SidebarBotThreadsPeek.test.ts
new file mode 100644
index 0000000000..00b0da7e7a
--- /dev/null
+++ b/src/components/SidebarBotThreadsPeek.test.ts
@@ -0,0 +1,76 @@
+import { createElement } from "react";
+import { renderToStaticMarkup } from "react-dom/server";
+import { describe, expect, it } from "vitest";
+import type { Task } from "@/state/store";
+import { PEEK_LIMIT, peekPlace, peekThreads, SidebarBotThreadsPeek } from "./SidebarBotThreadsPeek";
+
+const task = (threadId: string, extra: Partial<Task> = {}): Task => ({ threadId, title: threadId, createdAt: 1, ...extra });
+const bot = (tasks: Task[], threadId = "main") => ({ threadId, mainThreadId: "main", tasks: [task("main"), ...tasks] });
+
+describe("peekThreads", () => {
+ it("is empty for a bot with only the conversation its row opens", () => {
+ expect(peekThreads(bot([]))).toEqual([]);
+ });
+
+ it("lists the newest open conversations, capped, without the main one", () => {
+ const listed = peekThreads(bot([task("a", { updatedAt: 10 }), task("b", { updatedAt: 40 }), task("c", { updatedAt: 30 }), task("d", { updatedAt: 20 })]));
+ expect(listed.map((entry) => entry.threadId)).toEqual(["b", "c", "d"]);
+ expect(listed).toHaveLength(PEEK_LIMIT);
+ });
+
+ it("keeps the conversation on screen when it is not the main one", () => {
+ expect(peekThreads(bot([task("a")], "a")).map((entry) => entry.threadId)).toEqual(["a"]);
+ });
+
+ it("leaves out routine runs, burst helpers and closed, archived or snoozed conversations", () => {
+ const closed = [
+ task("run", { routineRunId: "r1" }),
+ task("burst", { openedBy: { botId: "x", name: "X", at: 1, burstId: "b1" } }),
+ task("closed", { closedBy: { botId: "x", name: "X", at: 1 } }),
+ task("archived", { archivedAt: 5 }),
+ task("snoozed", { snoozedUntil: Date.now() + 60_000 }),
+ ];
+ expect(peekThreads(bot([...closed, task("open")])).map((entry) => entry.threadId)).toEqual(["open"]);
+ });
+
+ it("excludes the conversation in view for a bot without a main one", () => {
+ expect(peekThreads({ threadId: "a", tasks: [task("a"), task("b")] }).map((entry) => entry.threadId)).toEqual(["b"]);
+ });
+});
+
+describe("peekPlace", () => {
+ const viewport = { width: 1440, height: 900 };
+
+ it("sits beside the row, level with its top", () => {
+ expect(peekPlace({ left: 8, right: 300, top: 200 }, 4, viewport, false)).toEqual({ left: 300, top: 200 });
+ });
+
+ it("stays inside the window near its bottom and right edges", () => {
+ expect(peekPlace({ left: 8, right: 1400, top: 880 }, 4, viewport, false)).toEqual({ left: 1192, top: 748 });
+ });
+
+ it("opens on the other side in a right-to-left layout", () => {
+ expect(peekPlace({ left: 1140, right: 1432, top: 200 }, 4, viewport, true)).toEqual({ left: 900, top: 200 });
+ });
+});
+
+describe("SidebarBotThreadsPeek", () => {
+ const render = (tasks: Task[]) => renderToStaticMarkup(createElement(SidebarBotThreadsPeek, { bot: { id: "atlas", name: "Atlas", ...bot(tasks) }, dispatch: () => {} }));
+
+ it("offers only a new conversation for a bot with nothing else open", () => {
+ const markup = render([]);
+ expect(markup).toContain('data-bot-new-thread="atlas" aria-label="New thread"');
+ expect(markup).not.toContain("aria-expanded");
+ });
+
+ it("discloses the other open conversations, closed until hovered or pressed", () => {
+ const markup = render([task("a")]);
+ expect(markup).toContain('data-bot-threads-peek="atlas" aria-haspopup="menu" aria-expanded="false" aria-label="Expand Atlas threads"');
+ expect(markup).not.toContain('role="menu"');
+ expect(markup).not.toContain("data-bot-new-thread");
+ });
+
+ it("hides its control on phones and shows it without hover on other touch screens", () => {
+ expect(render([])).toMatch(/class="[^"]*\bmax-md:hidden touch:pointer-events-auto touch:opacity-70\b/);
+ });
+});
diff --git a/src/components/SidebarBotThreadsPeek.tsx b/src/components/SidebarBotThreadsPeek.tsx
new file mode 100644
index 0000000000..8accc4dc00
--- /dev/null
+++ b/src/components/SidebarBotThreadsPeek.tsx
@@ -0,0 +1,150 @@
+import { ChevronRight, Plus } from "lucide-react";
+import { useEffect, useMemo, useRef, useState, type Dispatch, type KeyboardEvent as ReactKeyboardEvent } from "react";
+import { createPortal } from "react-dom";
+import { cn } from "@/lib/cn";
+import { t } from "@/lib/i18n";
+import { localizedTaskTitle } from "@/lib/task-title";
+import { usePopoverDismiss } from "@/hooks/use-popover-dismiss";
+import type { Action, Bot, Task } from "@/state/store";
+import { botOpensTo } from "@/state/thread-navigation";
+import { MENU_GUTTER, MENU_ICON, MENU_META, MENU_ROW, MENU_SEPARATOR, MENU_SHEET } from "./menu-recipe";
+import { useHeldMenuMotion } from "./MenuMotion";
+import { isArchived, isSnoozed, threadRecency, threadUpdatedLabel } from "./SidebarThreadRow";
+
+export const PEEK_LIMIT = 3;
+/** Long enough that sweeping the pointer down the list opens nothing. */
+export const PEEK_OPEN_MS = 350;
+/** Long enough to cross from the row onto the sheet. */
+export const PEEK_CLOSE_MS = 200;
+const SHEET_WIDTH = 240;
+const EDGE = 8;
+
+type PeekBot = Pick<Bot, "id" | "name" | "threadId" | "mainThreadId" | "tasks">;
+
+/** The bot's open conversations other than the one its row opens, newest first. */
+export function peekThreads(bot: Pick<PeekBot, "threadId" | "mainThreadId" | "tasks">): Task[] {
+ const rowThread = botOpensTo(bot, false);
+ return (bot.tasks ?? [])
+ .filter((task) => task.threadId !== rowThread && !task.routineRunId && !task.openedBy?.burstId && !task.closedBy && !isArchived(task) && !isSnoozed(task))
+ .sort((a, b) => threadRecency(b) - threadRecency(a))
+ .slice(0, PEEK_LIMIT);
+}
+
+type Place = { left: number; top: number };
+
+export function peekPlace(row: Pick<DOMRect, "left" | "right" | "top">, rows: number, viewport: { width: number; height: number }, rtl: boolean): Place {
+ const height = rows * 30 + 24;
+ const left = rtl ? row.left - SHEET_WIDTH : row.right;
+ return {
+ left: Math.max(EDGE, Math.min(left, viewport.width - SHEET_WIDTH - EDGE)),
+ top: Math.max(EDGE, Math.min(row.top, viewport.height - height - EDGE)),
+ };
+}
+
+const SLOT = "pointer-events-none absolute right-[30px] top-1.5 flex size-6 items-center justify-center rounded-lg text-ink-secondary opacity-0 transition-opacity hover:bg-raised hover:text-ink group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100 max-md:hidden touch:pointer-events-auto touch:opacity-70 motion-reduce:transition-none";
+
+/** Beside a Simple row's "…": a "+" for a bot with one conversation, else the disclosure of a sheet listing its other open ones, which hovering the row also opens. */
+export function SidebarBotThreadsPeek({ bot, dispatch }: { bot: PeekBot; dispatch: Dispatch<Action> }) {
+ const threads = useMemo(() => peekThreads(bot), [bot.tasks, bot.mainThreadId, bot.threadId]);
+ const [place, setPlace] = useState<Place | null>(null);
+ const motion = useHeldMenuMotion(place);
+ const anchor = useRef<HTMLButtonElement>(null);
+ const sheet = useRef<HTMLDivElement>(null);
+ const timer = useRef<number | undefined>(undefined);
+ const focusSheet = useRef(false);
+ const has = threads.length > 0;
+ const open = place !== null;
+
+ const cancel = () => window.clearTimeout(timer.current);
+ const close = () => { cancel(); setPlace(null); };
+ const show = () => {
+ cancel();
+ const row = anchor.current?.parentElement;
+ if (!row) return;
+ setPlace(peekPlace(row.getBoundingClientRect(), threads.length + 1, { width: window.innerWidth, height: window.innerHeight }, getComputedStyle(row).direction === "rtl"));
+ };
+ const later = (run: () => void, ms: number) => { cancel(); timer.current = window.setTimeout(run, ms); };
+
+ useEffect(() => cancel, []);
+ useEffect(() => { if (!has) close(); }, [has]);
+ useEffect(() => {
+ const row = anchor.current?.parentElement;
+ if (!row || !has) return;
+ // offsetParent is null while the disclosure is hidden, which it is on a phone-width window.
+ const enter = (event: PointerEvent) => { if (event.pointerType === "mouse" && event.buttons === 0 && anchor.current?.offsetParent) later(show, PEEK_OPEN_MS); };
+ const leave = (event: PointerEvent) => { if (event.pointerType === "mouse") later(() => setPlace(null), PEEK_CLOSE_MS); };
+ row.addEventListener("pointerenter", enter);
+ row.addEventListener("pointerleave", leave);
+ return () => { row.removeEventListener("pointerenter", enter); row.removeEventListener("pointerleave", leave); };
+ }, [has, threads.length]);
+ useEffect(() => {
+ if (!open) return;
+ if (focusSheet.current) { focusSheet.current = false; sheet.current?.querySelector<HTMLElement>("[role=menuitem]")?.focus(); }
+ const away = (event: Event) => { if (!(event.target instanceof Node) || !sheet.current?.contains(event.target)) close(); };
+ window.addEventListener("resize", close);
+ window.addEventListener("scroll", away, true);
+ return () => { window.removeEventListener("resize", close); window.removeEventListener("scroll", away, true); };
+ }, [open]);
+ const root = useRef({ contains: (target: unknown) => target instanceof Node && Boolean(sheet.current?.contains(target) || anchor.current?.contains(target)) });
+ usePopoverDismiss(open, root, () => {
+ if (sheet.current?.contains(document.activeElement)) anchor.current?.focus();
+ close();
+ });
+
+ const slot = cn(SLOT, open && "pointer-events-auto opacity-100");
+ if (!has) {
+ return <button ref={anchor} type="button" data-bot-new-thread={bot.id} aria-label={t("task.newShort")} title={t("task.newShort")}
+ onClick={() => dispatch({ type: "newTask", botId: bot.id })} className={slot}><Plus size={14} /></button>;
+ }
+
+ const pick = (action: Action) => { close(); dispatch(action); };
+ const onKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>) => {
+ const items = Array.from(sheet.current?.querySelectorAll<HTMLElement>("[role=menuitem]") ?? []);
+ const at = items.indexOf(document.activeElement as HTMLElement);
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
+ event.preventDefault();
+ items[(at + (event.key === "ArrowDown" ? 1 : items.length - 1)) % items.length]?.focus();
+ } else if (event.key === "Home" || event.key === "End") {
+ event.preventDefault();
+ items[event.key === "Home" ? 0 : items.length - 1]?.focus();
+ } else if (event.key === "Tab") {
+ anchor.current?.focus();
+ close();
+ }
+ };
+ const now = Date.now();
+ const shown = motion.value;
+ return (
+ <>
+ <button ref={anchor} type="button" data-bot-threads-peek={bot.id} aria-haspopup="menu" aria-expanded={open}
+ aria-label={t("task.expandNamed", { name: bot.name })} title={t("task.expandNamed", { name: bot.name })}
+ onClick={(event) => { if (open) { close(); return; } focusSheet.current = event.detail === 0; show(); }} className={slot}>
+ <ChevronRight size={14} className="rtl:-scale-x-100" />
+ </button>
+ {motion.shown && shown && createPortal(
+ <div ref={sheet} role="menu" aria-label={bot.name} data-bot-threads-sheet={bot.id} style={{ left: shown.left, top: shown.top, width: SHEET_WIDTH }}
+ onPointerEnter={cancel} onPointerLeave={(event) => { if (event.pointerType === "mouse") later(() => setPlace(null), PEEK_CLOSE_MS); }} onKeyDown={onKeyDown}
+ className={cn(MENU_SHEET, "fixed z-[60] gap-0", motion.className)} {...motion.exitProps}>
+ <button type="button" role="menuitem" className={MENU_ROW} onClick={() => pick({ type: "newTask", botId: bot.id })}>
+ <span className={MENU_GUTTER}><Plus size={14} className={MENU_ICON} /></span>
+ <span className="min-w-0 flex-1 truncate">{t("task.newShort")}</span>
+ </button>
+ <div role="separator" className={MENU_SEPARATOR} />
+ {threads.map((task) => {
+ const waiting = task.activity === "waiting-on-you";
+ const mark = waiting ? t("sidebar.preview.waiting") : task.unread ? t("task.unread") : undefined;
+ return (
+ <button key={task.threadId} type="button" role="menuitem" data-peek-thread={task.threadId} aria-current={task.threadId === bot.threadId ? "page" : undefined}
+ className={MENU_ROW} onClick={() => pick({ type: "switchTask", botId: bot.id, threadId: task.threadId })}>
+ <span className={MENU_GUTTER}>{mark && <span role="img" aria-label={mark} title={mark} className={cn("size-1.5 rounded-full", waiting ? "bg-warning" : "bg-accent")} />}</span>
+ <span className="min-w-0 flex-1 truncate">{localizedTaskTitle(task.title) || t("task.untitledConversation")}</span>
+ <span className={cn(MENU_META, "tabular-nums")}>{threadUpdatedLabel(threadRecency(task), now)}</span>
+ </button>
+ );
+ })}
+ </div>,
+ document.body,
+ )}
+ </>
+ );
+}