Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Allow resizing the top pinned circle area from its bottom edge
guylfe41efb8663b35
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsxindex 2476992cb3..7ef8a3e668 100644--- a/src/components/Sidebar.tsx+++ b/src/components/Sidebar.tsx@@ -82,6 +82,7 @@ import { MENU_ITEM, MENU_ITEM_SEPARATOR, MENU_SHEET } from "./menu-recipe";import { ELEVATED_CONTROL } from "./elevated";export { TeamMenuItems };import { SidebarResizeHandle, useSidebarWidth } from "./SidebarResizeHandle";+import { SidebarPinnedArea } from "./SidebarPinnedArea";import { PHONE_TOP_BUTTON, SIMPLE_CORNER_BUTTON, SIMPLE_ROW_FOCUS, SIMPLE_TOP_BUTTON, SidebarSearchPill, SidebarSearchToggle } from "./SidebarSimpleTop";import { isSidebarToggle } from "@/lib/keyboard-shortcuts";import { SidebarRailSeparator, SimpleRailFooter } from "./SidebarSimpleRail";@@ -1303,11 +1304,7 @@ export const Sidebar = memo(function Sidebar({ open, onClose, collapseToIcons =</div>}{!q && <TeamSideSwitch compact={density === "icons"} listOnly={phone} />}{!q && <SidebarInboxRow icons={density === "icons"} large={!advanced} running={showAttention ? attentionHasRunningWork(attention) : hasCrossBotRunningWork(state.bots, state.pendingQueued, state.groups)} onOpened={phone ? onClose : undefined} />}{universalPins && pinnedBots.length > 0 && !simpleDesk && (- <div- data-sidebar-universal-pins=""- // vh, not %: a percentage has no height to resolve against inside the glass head.- className="max-h-[min(40vh,280px)] shrink-0 overflow-y-auto border-b border-hairline/40 px-2 pb-2"- >+ <SidebarPinnedArea resizable={pinnedCircles && density !== "icons" && !phone}>{density !== "icons" && !pinnedCircles && (<div className="px-2 pb-1 pt-1 text-[12px] font-medium leading-4 text-ink-secondary">{t("sidebar.section.pinned")}@@ -1320,7 +1317,7 @@ export const Sidebar = memo(function Sidebar({ open, onClose, collapseToIcons =row={botRow}listItem={BotListItem}/>- </div>+ </SidebarPinnedArea>)}{attentionPinned && density !== "icons" && (diff --git a/src/components/SidebarPinnedArea.dom.test.ts b/src/components/SidebarPinnedArea.dom.test.tsnew file mode 100644index 0000000000..bdaf040922--- /dev/null+++ b/src/components/SidebarPinnedArea.dom.test.ts@@ -0,0 +1,68 @@+// @vitest-environment happy-dom+import { act, createElement } from "react";+import { createRoot, type Root } from "react-dom/client";+import { afterEach, beforeEach, expect, it, vi } from "vitest";+import { SidebarPinnedArea } from "./SidebarPinnedArea";++(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;+let host: HTMLDivElement;+let root: Root;+let frameHeight: number;+let measure: () => void;+const pane = () => host.querySelector<HTMLElement>("[data-sidebar-universal-pins]")!;+const handle = () => host.querySelector<HTMLElement>('[role="separator"]')!;+function render(resizable = true) {+ act(() => root.render(createElement("div", { "data-glass-frame": "" },+ createElement("div", { "data-glass-bar": "top" },+ createElement(SidebarPinnedArea, { resizable, children: "Pinned threads" })),+ createElement("div", { "data-glass-bar": "bottom" }))));+}+function pointer(type: string, y: number) {+ act(() => { handle().dispatchEvent(new PointerEvent(type, { pointerId: 1, button: 0, clientY: y, bubbles: true })); });+}+beforeEach(() => {+ host = document.createElement("div");+ document.body.append(host);+ root = createRoot(host);+ localStorage.clear();+ frameHeight = 800;+ vi.stubGlobal("ResizeObserver", class {+ constructor(cb: () => void) { measure = cb; }+ observe() {} disconnect() {}+ });+ vi.spyOn(HTMLElement.prototype, "clientHeight", "get").mockImplementation(() => frameHeight);+ vi.spyOn(HTMLElement.prototype, "offsetHeight", "get").mockImplementation(function (this: HTMLElement) {+ if (this.dataset.glassBar === "top") return 100 + pane().offsetHeight;+ if (this.dataset.glassBar === "bottom") return 80;+ return Math.min(Number.parseFloat(this.style.height) || 180, Number.parseFloat(this.style.maxHeight) || Infinity);+ });+});+afterEach(() => { act(() => root.unmount()); host.remove(); localStorage.clear(); vi.restoreAllMocks(); vi.unstubAllGlobals(); });++it("drags the divider from the visible height and remembers it when reopened", () => {+ render();+ expect(pane().style.height).toBe("");+ pointer("pointerdown", 240);+ pointer("pointermove", 400);+ pointer("lostpointercapture", 400);+ expect(pane().style.height).toBe("340px");+ render(false);+ expect(handle()).toBeNull();+ render();+ expect(pane().style.height).toBe("340px");+ act(() => { handle().dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowUp", bubbles: true })); });+ expect(pane().style.height).toBe("324px");+});++it("reserves room for the rest of the sidebar and adjusts when the window shrinks", () => {+ render();+ pointer("pointerdown", 220);+ pointer("pointermove", 1500);+ expect(pane().style.height).toBe("524px");+ frameHeight = 550;+ act(() => measure());+ expect(pane().style.maxHeight).toBe("274px");+ expect(handle().getAttribute("aria-valuemax")).toBe("274");+ pointer("pointermove", -400);+ expect(pane().style.height).toBe("64px");+});diff --git a/src/components/SidebarPinnedArea.tsx b/src/components/SidebarPinnedArea.tsxnew file mode 100644index 0000000000..77a837db48--- /dev/null+++ b/src/components/SidebarPinnedArea.tsx@@ -0,0 +1,83 @@+import { useId, useLayoutEffect, useRef, useState, type ReactNode } from "react";+import { t } from "@/lib/i18n";++const HEIGHT_KEY = "openmausbot.sidebarPinnedHeight";+const MIN_HEIGHT = 64;+const LIST_SPACE = 96;+const scrollArea = "shrink-0 overflow-y-auto px-2 pb-2";++function readHeight() {+ try {+ const value = Number(localStorage.getItem(HEIGHT_KEY));+ return Number.isFinite(value) && value > 0 ? value : null;+ } catch { return null; }+}++function rememberHeight(height: number) {+ try { localStorage.setItem(HEIGHT_KEY, String(height)); } catch { /* Storage may be unavailable. */ }+}++export function SidebarPinnedArea({ resizable, children }: { resizable: boolean; children: ReactNode }) {+ if (!resizable) return <div data-sidebar-universal-pins="" className={`${scrollArea} max-h-[min(40vh,280px)] border-b border-hairline/40`}>{children}</div>;+ return <ResizablePinnedArea>{children}</ResizablePinnedArea>;+}++function ResizablePinnedArea({ children }: { children: ReactNode }) {+ const id = useId();+ const pane = useRef<HTMLDivElement>(null);+ const drag = useRef<{ pointer: number; y: number; height: number; latest?: number } | null>(null);+ const [height, setHeight] = useState(readHeight);+ const [bounds, setBounds] = useState({ max: 280, actual: 0 });+ useLayoutEffect(() => {+ const el = pane.current!;+ const header = el.closest<HTMLElement>("[data-glass-bar]");+ const frame = header?.parentElement;+ if (!header || !frame) return;+ const footer = frame.querySelector<HTMLElement>(':scope > [data-glass-bar="bottom"]');+ const measure = () => {+ const actual = el.offsetHeight;+ const max = Math.max(0, frame.clientHeight - (header.offsetHeight - actual) - (footer?.offsetHeight ?? 0) - LIST_SPACE);+ setBounds(prev => prev.max === max && prev.actual === actual ? prev : { max, actual });+ };+ measure();+ const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(measure);+ for (const node of [frame, header, footer, el]) if (node) observer?.observe(node);+ return () => observer?.disconnect();+ }, []);+ const minimum = Math.min(MIN_HEIGHT, bounds.max);+ const resize = (wanted: number) => {+ const next = Math.max(minimum, Math.min(bounds.max, Math.round(wanted)));+ setHeight(next);+ return next;+ };+ return <>+ <div ref={pane} id={id} data-sidebar-universal-pins="" className={scrollArea}+ style={{ height: height ?? undefined, maxHeight: height === null ? `min(40vh, 280px, ${bounds.max}px)` : bounds.max }}>{children}</div>+ <div role="separator" aria-label={t("sidebar.section.pinned")} title={t("computer.resizeAria")} aria-orientation="horizontal"+ aria-controls={id} aria-valuemin={Math.min(minimum, bounds.actual)} aria-valuemax={bounds.max} aria-valuenow={bounds.actual} tabIndex={0}+ className="group flex h-2 w-full shrink-0 cursor-row-resize touch-none select-none items-center justify-center border-b border-hairline/40 hover:bg-raised focus-visible:bg-raised focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent"+ onPointerDown={event => {+ if (event.button !== 0 || drag.current) return;+ event.preventDefault();+ event.currentTarget.setPointerCapture(event.pointerId);+ drag.current = { pointer: event.pointerId, y: event.clientY, height: pane.current!.offsetHeight };+ }}+ onPointerMove={event => {+ const start = drag.current;+ if (start?.pointer === event.pointerId) start.latest = resize(start.height + event.clientY - start.y);+ }}+ onLostPointerCapture={event => {+ const start = drag.current;+ if (start?.pointer !== event.pointerId) return;+ if (start.latest !== undefined) rememberHeight(start.latest);+ drag.current = null;+ }}+ onKeyDown={event => {+ if (event.key !== "ArrowUp" && event.key !== "ArrowDown") return;+ event.preventDefault();+ rememberHeight(resize(pane.current!.offsetHeight + (event.key === "ArrowDown" ? 16 : -16)));+ }}>+ <span aria-hidden="true" className="h-0.5 w-6 rounded-full bg-hairline group-hover:bg-ink-secondary group-focus-visible:bg-ink-secondary" />+ </div>+ </>;+}