Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Sidebar threads peek: place the sheet by its rendered height, and check the conversation again before deleting it
luishron123f29f25549881
diff --git a/src/components/SidebarBotThreadsPeek.dom.test.ts b/src/components/SidebarBotThreadsPeek.dom.test.tsindex 24399e37e8..3483dace93 100644--- a/src/components/SidebarBotThreadsPeek.dom.test.ts+++ b/src/components/SidebarBotThreadsPeek.dom.test.ts@@ -16,15 +16,18 @@ let chat: HTMLElement;let root: Root;const dispatch = vi.fn<(action: Action) => void>();+const show = async (tasks: Task[]) => {+ await act(async () => {+ root.render(createElement("div", { "data-row": "" },+ createElement(SidebarBotThreadsPeek, { bot: { id: "atlas", name: "Atlas", threadId: "main", mainThreadId: "main", tasks: [task("main"), ...tasks] }, dispatch })));+ });+};const mount = async (tasks: Task[]) => {scroller = document.createElement("div");chat = document.createElement("div");document.body.append(scroller, chat);root = createRoot(scroller);- await act(async () => {- root.render(createElement("div", { "data-row": "" },- createElement(SidebarBotThreadsPeek, { bot: { id: "atlas", name: "Atlas", threadId: "main", mainThreadId: "main", tasks: [task("main"), ...tasks] }, dispatch })));- });+ await show(tasks);row = scroller.querySelector<HTMLElement>("[data-row]")!;};const chevron = () => row.querySelector<HTMLButtonElement>("[data-bot-threads-peek]")!;@@ -115,6 +118,25 @@ describe("the hover sheet of a bot's other conversations", () => {expect(dispatch.mock.calls).toEqual([[{ type: "deleteTask", botId: "atlas", threadId: "a" }]]);});+ it("does not delete a conversation that started working while the confirmation was open", async () => {+ await mount([task("a")]);+ await open();+ await act(async () => { action("a", "delete").click(); });+ await show([task("a", { busy: true })]);+ const dialog = document.querySelector<HTMLElement>("[role=alertdialog], [role=dialog]")!;+ await act(async () => { [...dialog.querySelectorAll("button")].find((button) => button.textContent === "Delete thread")!.click(); });+ expect(dispatch).not.toHaveBeenCalled();+ });++ it("stays inside the window when its rows are taller than a mouse's, as on a touch screen", async () => {+ await mount([task("a"), task("b"), task("c")]);+ row.getBoundingClientRect = () => ({ left: 8, right: 300, top: window.innerHeight - 20 }) as DOMRect;+ const height = vi.spyOn(HTMLElement.prototype, "offsetHeight", "get").mockReturnValue(185);+ await open();+ height.mockRestore();+ expect(sheet()!.style.top).toBe(`${window.innerHeight - 185 - 8}px`);+ });+it("offers neither action for a conversation that is working", async () => {await mount([task("a", { busy: true })]);await open();diff --git a/src/components/SidebarBotThreadsPeek.tsx b/src/components/SidebarBotThreadsPeek.tsxindex e8519bdd3d..33beaa2b79 100644--- a/src/components/SidebarBotThreadsPeek.tsx+++ b/src/components/SidebarBotThreadsPeek.tsx@@ -1,5 +1,5 @@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 { useEffect, useId, useLayoutEffect, 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";@@ -57,7 +57,8 @@ export function SidebarBotThreadsPeek({ bot, dispatch }: { bot: PeekBot; dispatcconst focusSheet = useRef(false);const focusAnchor = useRef(false);const typed = useRef<Typeahead | null>(null);- const [deleting, setDeleting] = useState<Task | null>(null);+ const [deletingId, setDeletingId] = useState<string | null>(null);+ const deleting = deletingId ? bot.tasks?.find((task) => task.threadId === deletingId) : undefined;const labels = useId();const has = threads.length > 0;const open = place !== null;@@ -91,6 +92,13 @@ export function SidebarBotThreadsPeek({ bot, dispatch }: { bot: PeekBot; dispatcrow.addEventListener("pointerleave", leave);return () => { row.removeEventListener("pointerenter", enter); row.removeEventListener("pointerleave", leave); };}, [has, threads.length]);+ // Rows are taller on a touch screen, so the sheet's own height decides how far up it has to sit.+ useLayoutEffect(() => {+ const height = sheet.current?.offsetHeight;+ if (!place || !height) return;+ const top = Math.max(EDGE, Math.min(place.top, window.innerHeight - height - EDGE));+ if (top !== place.top) setPlace({ ...place, top });+ }, [place, threads.length]);useEffect(() => {if (!open) return;if (focusSheet.current) { focusSheet.current = false; sheet.current?.querySelector<HTMLElement>("[role=menuitem]")?.focus(); }@@ -106,8 +114,8 @@ export function SidebarBotThreadsPeek({ bot, dispatch }: { bot: PeekBot; dispatc});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 confirm = <ConfirmDialog open={deleting !== undefined} title={t("task.deleteConfirm")} body={t("task.deleteBody", { title: deleting?.title ?? "" })} confirmLabel={t("task.deleteAria")}+ onCancel={() => setDeletingId(null)} onConfirm={() => { if (deleting && !isWorking(deleting)) actions.onDelete(deleting); setDeletingId(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")}@@ -185,7 +193,7 @@ export function SidebarBotThreadsPeek({ bot, dispatch }: { bot: PeekBot; dispatc<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>+ disabled={working} className={cn(ROW_ACTION, "hover:text-danger focus-visible:text-danger")} onClick={() => { close(); setDeletingId(task.threadId); }}><Trash2 size={14} aria-hidden="true" /></button></span></div>);