Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Sidebar: archive or delete a conversation from the hover list
luishron1236b44cc1fc3e3
diff --git a/src/components/SidebarBotThreadsPeek.dom.test.ts b/src/components/SidebarBotThreadsPeek.dom.test.tsindex 6b5864bf61..8a8d2f358e 100644--- a/src/components/SidebarBotThreadsPeek.dom.test.ts+++ b/src/components/SidebarBotThreadsPeek.dom.test.ts@@ -36,6 +36,7 @@ const cross = async (from: Element, to: Element) => {await act(async () => { for (const [type, target, related] of [["pointerout", from, to], ["pointerleave", from, to], ["pointerover", to, from], ["pointerenter", to, from]] as const) pointer(type, target, related); });};const wait = async (ms: number) => { await act(async () => { vi.advanceTimersByTime(ms); }); };+const action = (threadId: string, kind: string) => sheet()!.querySelector(`[data-peek-thread="${threadId}"]`)!.parentElement!.querySelector<HTMLButtonElement>(`[data-peek-action="${kind}"]`)!;beforeEach(() => { vi.useFakeTimers(); dispatch.mockClear(); });afterEach(async () => {@@ -90,4 +91,51 @@ describe("the hover sheet of a bot's other conversations", () => {await act(async () => { scroller.dispatchEvent(new Event("scroll")); });expect(chevron().getAttribute("aria-expanded")).toBe("false");});++ it("archives a conversation from its row without opening it or closing the sheet", async () => {+ await mount([task("a"), task("b")]);+ await open();+ const archive = action("a", "archive");+ expect(archive.getAttribute("aria-labelledby")!.split(" ").map((id) => document.getElementById(id)?.textContent || document.getElementById(id)?.getAttribute("aria-label"))).toEqual(["Archive", "a"]);+ await act(async () => { archive.click(); });+ expect(dispatch.mock.calls).toEqual([[{ type: "updateTask", botId: "atlas", threadId: "a", patch: { archivedAt: expect.any(Number) } }]]);+ expect(chevron().getAttribute("aria-expanded")).toBe("true");+ });++ it("deletes a conversation only after the same confirmation its thread row asks", async () => {+ await mount([task("a")]);+ await open();+ await act(async () => { action("a", "delete").click(); });+ expect(dispatch).not.toHaveBeenCalled();+ const dialog = document.querySelector<HTMLElement>("[role=alertdialog], [role=dialog]")!;+ expect(dialog.textContent).toContain("Delete thread?");+ expect(dialog.textContent).toContain("“a” and its conversation will be deleted.");+ await act(async () => { [...dialog.querySelectorAll("button")].find((button) => button.textContent === "Delete thread")!.click(); });+ expect(dispatch.mock.calls).toEqual([[{ type: "deleteTask", botId: "atlas", threadId: "a" }]]);+ });++ it("offers neither action for a conversation that is working", async () => {+ await mount([task("a", { busy: true })]);+ await open();+ expect(action("a", "archive").disabled).toBe(true);+ expect(action("a", "delete").disabled).toBe(true);+ });++ it("reaches a row's actions with the arrow keys and moves on to the next row", async () => {+ await mount([task("a"), task("b")]);+ await open();+ const key = async (name: string) => { await act(async () => { document.activeElement!.dispatchEvent(new KeyboardEvent("keydown", { key: name, bubbles: true })); }); };+ const thread = (id: string) => sheet()!.querySelector<HTMLElement>(`[data-peek-thread="${id}"]`)!;+ thread("a").focus();+ await key("ArrowRight");+ expect(document.activeElement).toBe(action("a", "archive"));+ await key("ArrowRight");+ expect(document.activeElement).toBe(action("a", "delete"));+ await key("ArrowRight");+ expect(document.activeElement).toBe(thread("a"));+ await key("ArrowLeft");+ expect(document.activeElement).toBe(action("a", "delete"));+ await key("ArrowDown");+ expect(document.activeElement).toBe(thread("b"));+ });});diff --git a/src/components/SidebarBotThreadsPeek.tsx b/src/components/SidebarBotThreadsPeek.tsxindex 6ed92ee764..b633f1386e 100644--- a/src/components/SidebarBotThreadsPeek.tsx+++ b/src/components/SidebarBotThreadsPeek.tsx@@ -1,5 +1,5 @@-import { ChevronRight, Plus } from "lucide-react";-import { useEffect, useMemo, useRef, useState, type Dispatch, type KeyboardEvent as ReactKeyboardEvent } from "react";+import { Archive, ChevronRight, Plus, Trash2 } from "lucide-react";+import { useEffect, useId, useMemo, useRef, useState, type Dispatch, type KeyboardEvent as ReactKeyboardEvent, type MouseEvent as ReactMouseEvent } from "react";import { createPortal } from "react-dom";import { cn } from "@/lib/cn";import { t } from "@/lib/i18n";@@ -7,9 +7,10 @@ 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 { ConfirmDialog } from "./ConfirmDialog";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";+import { isArchived, isSnoozed, isWorking, threadRecency, threadRowActions, threadUpdatedLabel } from "./SidebarThreadRow";export const PEEK_LIMIT = 3;/** Long enough that sweeping the pointer down the list opens nothing. */@@ -43,6 +44,10 @@ export function peekPlace(row: Pick<DOMRect, "left" | "right" | "top">, rows: nuconst 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";+const ROW_ACTIONS = "pointer-events-none absolute end-2 top-1/2 flex -translate-y-1/2 items-center gap-1 opacity-0 transition-opacity group-hover/peek:pointer-events-auto group-hover/peek:opacity-100 group-focus-within/peek:pointer-events-auto group-focus-within/peek:opacity-100 touch:pointer-events-auto touch:opacity-100 motion-reduce:transition-none";+const ROW_ACTION = "flex size-6 items-center justify-center rounded-md text-ink-secondary hover:bg-ink/[0.06] hover:text-ink focus-visible:bg-ink/[0.06] focus-visible:text-ink active:bg-ink/[0.08] disabled:cursor-default disabled:opacity-50 disabled:hover:bg-transparent disabled:hover:text-ink-secondary touch:size-10";+const ROW_TIME = "min-w-13 text-end tabular-nums transition-opacity group-hover/peek:opacity-0 group-focus-within/peek:opacity-0 touch:min-w-21 touch:opacity-0 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]);@@ -52,6 +57,9 @@ export function SidebarBotThreadsPeek({ bot, dispatch }: { bot: PeekBot; dispatcconst sheet = useRef<HTMLDivElement>(null);const timer = useRef<number | undefined>(undefined);const focusSheet = useRef(false);+ const focusAnchor = useRef(false);+ const [deleting, setDeleting] = useState<Task | null>(null);+ const labels = useId();const has = threads.length > 0;const open = place !== null;@@ -66,7 +74,12 @@ export function SidebarBotThreadsPeek({ bot, dispatch }: { bot: PeekBot; dispatcconst later = (run: () => void, ms: number) => { cancel(); timer.current = window.setTimeout(run, ms); };useEffect(() => cancel, []);- useEffect(() => { if (!has) close(); }, [has]);+ useEffect(() => {+ if (has) return;+ close();+ if (focusAnchor.current) anchor.current?.focus();+ focusAnchor.current = false;+ }, [has]);// React reports entering the sheet while the pointer is still leaving the row, so each side checks where the pointer went.const within = (target: EventTarget | null) => target instanceof Node && Boolean(sheet.current?.contains(target) || anchor.current?.parentElement?.contains(target));const leave = (event: Pick<PointerEvent, "pointerType" | "relatedTarget">) => { if (event.pointerType === "mouse" && !within(event.relatedTarget)) later(() => setPlace(null), PEEK_CLOSE_MS); };@@ -93,17 +106,34 @@ export function SidebarBotThreadsPeek({ bot, dispatch }: { bot: PeekBot; dispatcclose();});+ const actions = threadRowActions(bot.id, dispatch, false);+ const confirm = <ConfirmDialog open={deleting !== null} title={t("task.deleteConfirm")} body={t("task.deleteBody", { title: deleting?.title ?? "" })} confirmLabel={t("task.deleteAria")}+ onCancel={() => setDeleting(null)} onConfirm={() => { if (deleting && !isWorking(deleting)) actions.onDelete(deleting); setDeleting(null); }} returnFocusRef={anchor} />;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>;+ 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>{confirm}</>;}const pick = (action: Action) => { close(); dispatch(action); };+ const archive = (task: Task, event: ReactMouseEvent) => {+ if (event.detail === 0) {+ if (threads.length === 1) focusAnchor.current = true;+ else sheet.current?.querySelector<HTMLElement>("[role=menuitem]")?.focus();+ }+ actions.onArchive(task, Date.now());+ };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") {+ const items = Array.from(sheet.current?.querySelectorAll<HTMLElement>("[role=menuitem]:not([data-peek-action])") ?? []);+ const focused = document.activeElement as HTMLElement | null;+ const row = focused?.closest("[data-peek-row]");+ const at = items.indexOf(row?.querySelector<HTMLElement>("[data-peek-thread]") ?? focused!);+ if (row && (event.key === "ArrowRight" || event.key === "ArrowLeft")) {+ event.preventDefault();+ const across = Array.from(row.querySelectorAll<HTMLElement>("[role=menuitem]:not(:disabled)"));+ const forward = (event.key === "ArrowRight") !== (getComputedStyle(row).direction === "rtl");+ across[(across.indexOf(focused!) + (forward ? 1 : across.length - 1)) % across.length]?.focus();+ } else 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") {@@ -135,18 +165,29 @@ export function SidebarBotThreadsPeek({ bot, dispatch }: { bot: PeekBot; dispatc{threads.map((task) => {const waiting = task.activity === "waiting-on-you";const mark = waiting ? t("sidebar.preview.waiting") : task.unread ? t("task.unread") : undefined;+ const working = isWorking(task);+ const titleId = `${labels}${task.threadId}`;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 key={task.threadId} role="none" data-peek-row="" className="group/peek relative shrink-0 rounded-md hover:bg-ink/[0.06] focus-within:bg-ink/[0.06]">+ <button type="button" role="menuitem" data-peek-thread={task.threadId} aria-current={task.threadId === bot.threadId ? "page" : undefined}+ className={cn(MENU_ROW, "hover:bg-transparent focus:bg-transparent")} 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 id={titleId} className="min-w-0 flex-1 truncate">{localizedTaskTitle(task.title) || t("task.untitledConversation")}</span>+ <span className={cn(MENU_META, ROW_TIME)}>{threadUpdatedLabel(threadRecency(task), now)}</span>+ </button>+ <span className={ROW_ACTIONS}>+ <button type="button" role="menuitem" data-peek-action="archive" id={`${titleId}a`} aria-label={t("task.archive")} aria-labelledby={`${titleId}a ${titleId}`} title={t("task.archive")}+ disabled={working} className={ROW_ACTION} onClick={(event) => archive(task, event)}><Archive size={14} aria-hidden="true" /></button>+ <button type="button" role="menuitem" data-peek-action="delete" id={`${titleId}d`} aria-label={t("task.deleteAria")} aria-labelledby={`${titleId}d ${titleId}`} title={t("task.deleteAria")}+ disabled={working} className={cn(ROW_ACTION, "hover:text-danger focus-visible:text-danger")} onClick={() => { close(); setDeleting(task); }}><Trash2 size={14} aria-hidden="true" /></button>+ </span>+ </div>);})}</div>,document.body,)}+ {confirm}</>);}diff --git a/src/components/SidebarThreadRow.tsx b/src/components/SidebarThreadRow.tsxindex be7a43bcbe..cd40237ab9 100644--- a/src/components/SidebarThreadRow.tsx+++ b/src/components/SidebarThreadRow.tsx@@ -90,7 +90,7 @@ const tomorrowNineAm = () => {return when.getTime();};-const isWorking = (task: Pick<Task, "activity" | "busy">): boolean => task.activity === "working" || Boolean(task.busy);+export const isWorking = (task: Pick<Task, "activity" | "busy">): boolean => task.activity === "working" || Boolean(task.busy);const isWaitingOnTeammate = (task: Pick<Task, "waitingForTeammates">): boolean =>task.waitingForTeammates === true;