Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Simple's sidebar: move the bots, group chats and bot threads like any section (#3910)
Omkar Satpute10af83e74dd7
diff --git a/src/components/Sidebar.simple-layout.test.ts b/src/components/Sidebar.simple-layout.test.tsindex 1017c25b53..48bcb23c65 100644--- a/src/components/Sidebar.simple-layout.test.ts+++ b/src/components/Sidebar.simple-layout.test.ts@@ -44,7 +44,7 @@ vi.mock("@/state/store", async (importOriginal) => {import { initialState } from "@/state/store";import { BOTS_SECTION_ID, CHANNELS_SECTION_ID, PINNED_SECTION_ID, userSectionId } from "@/lib/sidebar-layout";-import { SIDEBAR_COLLAPSED_SECTIONS_KEY, SIDEBAR_DENSITY_KEY, SIDEBAR_SECTION_ORDER_KEY, SIDEBAR_WIDTH_KEY, SIMPLE_SIDEBAR_WIDTH_KEY, setSidebarDensity } from "@/lib/sidebar-preferences";+import { SIDEBAR_COLLAPSED_SECTIONS_KEY, SIDEBAR_DENSITY_KEY, SIDEBAR_SECTION_ORDER_KEY, SIDEBAR_WIDTH_KEY, SIMPLE_SIDEBAR_SECTION_ORDER_KEY, SIMPLE_SIDEBAR_WIDTH_KEY, setSidebarDensity } from "@/lib/sidebar-preferences";import { Sidebar, TeamMenuItems } from "./Sidebar";import { PinnedBotRoster } from "./PinnedCircleThreads";import { SidebarFooter } from "./SidebarFooter";@@ -207,7 +207,7 @@ describe("Simple-mode sidebar layout", () => {for (const action of ["onAddBots", "onRename", "onShare", "onDelete"] as const) expect(items[action]).toBeTypeOf("function");});- it("keeps a saved order for the departments and writes a Simple move back without moving the fixed lists", () => {+ it("starts from the shared order for the departments, and a Simple move is saved for Simple only", () => {fixture.state = { ...fixture.state, sections: ["Work", "Home"] };const saved = [userSectionId("Home"), CHANNELS_SECTION_ID, BOTS_SECTION_ID, userSectionId("Work")];fixture.storage.set(SIDEBAR_SECTION_ORDER_KEY, JSON.stringify(saved));@@ -215,11 +215,21 @@ describe("Simple-mode sidebar layout", () => {const work = () => headers(render().tree).find((header) => header.props.name === "Work")!;expect(work().props.reorderable).toBe(true);work().props.onMove!(-1);- const moved = [userSectionId("Work"), CHANNELS_SECTION_ID, BOTS_SECTION_ID, userSectionId("Home")];- expect(JSON.parse(fixture.storage.get(SIDEBAR_SECTION_ORDER_KEY)!)).toEqual(moved);- expect(sectionOrder(render().tree)).toEqual([BOTS_SECTION_ID, CHANNELS_SECTION_ID, userSectionId("Work"), userSectionId("Home")]);- work().props.onMove!(-1);- expect(JSON.parse(fixture.storage.get(SIDEBAR_SECTION_ORDER_KEY)!)).toEqual(moved);+ const moved = [BOTS_SECTION_ID, CHANNELS_SECTION_ID, userSectionId("Work"), userSectionId("Home")];+ expect(JSON.parse(fixture.storage.get(SIMPLE_SIDEBAR_SECTION_ORDER_KEY)!)).toEqual(moved);+ expect(JSON.parse(fixture.storage.get(SIDEBAR_SECTION_ORDER_KEY)!)).toEqual(saved);+ expect(sectionOrder(render().tree)).toEqual(moved);+ });++ it("moves group chats above the bots, which then get their own heading, and leaves Advanced's order alone", () => {+ const chats = () => headers(render().tree).find((header) => header.props.name === "Group chats")!;+ expect(chats().props.reorderable).toBe(true);+ chats().props.onMove!(-1);+ const { tree } = render();+ expect(sectionOrder(tree)).toEqual([CHANNELS_SECTION_ID, BOTS_SECTION_ID, userSectionId("Work")]);+ expect(headers(tree).map((header) => header.props.name)).toEqual(["Group chats", "Bots", "Work"]);+ expect(listedBots(tree)).toEqual(["atlas", "bea", "dodo"]);+ expect(fixture.storage.get(SIDEBAR_SECTION_ORDER_KEY)).toBeUndefined();});it("never hides the heading-less bots behind a collapse saved in Advanced", () => {diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsxindex 9c1413d9d0..a48c82bd8a 100644--- a/src/components/Sidebar.tsx+++ b/src/components/Sidebar.tsx@@ -1495,7 +1495,7 @@ export function Sidebar({ open, onClose, collapseToIcons = false }: {: sectionName? sectionedBots.filter((bot) => bot.section === sectionName): [];- const headless = simpleDesk ? id === PINNED_SECTION_ID || id === BOTS_SECTION_ID : simple && id === BOTS_SECTION_ID && index === 0;+ const headless = simple && id === BOTS_SECTION_ID && index === 0;const collapsed = !headless && sectionCollapsed(id);const queued = collapsed ? [...sectionChiefItems, ...sectionBotItems].flatMap((bot) =>sidebarBotActivityTasks(bot, state.pendingQueued).filter((task) => task.queued).map((task) => `${bot.name}: ${task.title}`)) : [];diff --git a/src/components/SidebarSections.tsx b/src/components/SidebarSections.tsxindex 83dce2b7bc..3e644ecd2c 100644--- a/src/components/SidebarSections.tsx+++ b/src/components/SidebarSections.tsx@@ -2,8 +2,6 @@ import { useRef, useState, type DragEvent, type RefObject } from "react";import { FOLDER_DRAG_TYPE } from "@/lib/folder-order";import { t } from "@/lib/i18n";import {- SIMPLE_FIXED_SECTION_IDS,- keepFixedSectionSlots,mergeSectionOrder,moveSection,orderedSidebarSections,@@ -11,16 +9,25 @@ import {sameSectionOrder,sidebarLayoutInteractive,sidebarSectionCollapsed,- simpleSidebarSections,+ simpleOrderedSections,userSectionId,type SectionDropPlace,} from "@/lib/sidebar-layout";-import { loadCollapsedSections, loadSectionOrder, saveCollapsedSections, saveSectionOrder, toggleCollapsedSection, type SidebarDensity } from "@/lib/sidebar-preferences";+import {+ loadCollapsedSections,+ loadSectionOrder,+ loadSimpleSectionOrder,+ saveCollapsedSections,+ saveSectionOrder,+ saveSimpleSectionOrder,+ toggleCollapsedSection,+ type SidebarDensity,+} from "@/lib/sidebar-preferences";const SECTION_DRAG_TYPE = "application/x-openmausbot-sidebar-section";/** The sidebar's sections on this device: which are collapsed, their saved order, and dragging or Alt+Up/Down a- * heading to reorder them. Simple keeps its fixed lists first and orders only the departments after them. */+ * heading to reorder them. Simple and Advanced each keep their own order, so a move in one leaves the other as it was. */export function useSidebarSections({ simple, rail, density, query, label, sidebarRef }: {simple: boolean;rail: boolean;@@ -31,6 +38,7 @@ export function useSidebarSections({ simple, rail, density, query, label, sideba}) {const [collapsedIds, setCollapsedIds] = useState<string[]>(() => loadCollapsedSections());const [savedOrder, setSavedOrder] = useState<string[]>(() => loadSectionOrder());+ const [simpleOrder, setSimpleOrder] = useState<string[]>(() => loadSimpleSectionOrder());const [draggingId, setDraggingId] = useState<string | null>(null);const [dropTarget, setDropTarget] = useState<{ id: string; place: SectionDropPlace } | null>(null);const [announcement, setAnnouncement] = useState("");@@ -64,19 +72,20 @@ export function useSidebarSections({ simple, rail, density, query, label, sidebaconst replace = (ids: string[]) => [...new Set(ids.map((id) => (id === userSectionId(from) ? userSectionId(to) : id)))];setCollapsedIds((current) => { const next = replace(current); saveCollapsedSections(next); return next; });setSavedOrder((current) => { const next = replace(current); saveSectionOrder(next); return next; });+ setSimpleOrder((current) => { const next = replace(current); saveSimpleSectionOrder(next); return next; });focusHeader(to);},arrange(natural: string[]) {const orderedIds = orderedSidebarSections(natural, savedOrder);- const sectionIds = simple || rail ? simpleSidebarSections(orderedIds) : orderedIds;- const reorderableIds = simple ? sectionIds.filter((id) => !SIMPLE_FIXED_SECTION_IDS.includes(id)) : sectionIds;- const reorder = (id: string, moved: string[]) => {- const next = simple ? simpleSidebarSections(moved) : moved;+ const ownOrder = simple || rail;+ const sectionIds = ownOrder ? simpleOrderedSections(orderedIds, simpleOrder) : orderedIds;+ const reorder = (id: string, next: string[]) => {if (sameSectionOrder(next, sectionIds)) return;- const merged = mergeSectionOrder(savedOrder, simple ? keepFixedSectionSlots(orderedIds, next) : next);- if (interactive && !sameSectionOrder(merged, savedOrder)) {- setSavedOrder(merged);- saveSectionOrder(merged);+ const saved = ownOrder ? simpleOrder : savedOrder;+ const merged = mergeSectionOrder(saved, next);+ if (interactive && !sameSectionOrder(merged, saved)) {+ (ownOrder ? setSimpleOrder : setSavedOrder)(merged);+ (ownOrder ? saveSimpleSectionOrder : saveSectionOrder)(merged);}const position = next.indexOf(id);if (position >= 0) setAnnouncement(t("sidebar.section.moved", { name: label(id), position: position + 1, count: next.length }));@@ -84,7 +93,7 @@ export function useSidebarSections({ simple, rail, density, query, label, sidebareturn {sectionIds,header: (id: string) => ({- reorderable: interactive && reorderableIds.length > 1 && reorderableIds.includes(id),+ reorderable: interactive && sectionIds.length > 1,dragging: draggingId === id,onDragStart: (event: DragEvent<HTMLElement>) => {event.dataTransfer.effectAllowed = "move";diff --git a/src/lib/sidebar-layout.test.ts b/src/lib/sidebar-layout.test.tsindex 27d4ca4e9c..0b71040560 100644--- a/src/lib/sidebar-layout.test.ts+++ b/src/lib/sidebar-layout.test.ts@@ -5,7 +5,6 @@ import {BOTS_SECTION_ID,CHANNELS_SECTION_ID,PINNED_SECTION_ID,- keepFixedSectionSlots,mergeSectionOrder,moveSection,orderedSidebarSections,@@ -18,6 +17,7 @@ import {sidebarGoalRunPreview,sidebarSectionCollapsed,sidebarSectionLabel,+ simpleOrderedSections,simpleSidebarSections,userSectionId,userSectionName,@@ -264,18 +264,22 @@ describe("Simple-mode section order", () => {expect(simpleSidebarSections(saved)).toEqual([BOTS_SECTION_ID, CHANNELS_SECTION_ID, home, work]);});- it("writes a Simple reorder of departments back without moving the fixed lists in the saved order", () => {- const full = [PINNED_SECTION_ID, CHANNELS_SECTION_ID, BOTS_SECTION_ID, work, home];- const shown = simpleSidebarSections(full);- const moved = simpleSidebarSections(placeSection(shown, home, work, "before"));- expect(moved).toEqual([PINNED_SECTION_ID, BOTS_SECTION_ID, CHANNELS_SECTION_ID, home, work]);- expect(keepFixedSectionSlots(full, moved)).toEqual([PINNED_SECTION_ID, CHANNELS_SECTION_ID, BOTS_SECTION_ID, home, work]);- expect(keepFixedSectionSlots(full, shown)).toEqual(full);+ it("keeps that default until a section is moved in Simple, then follows Simple's own saved order", () => {+ const ordered = [PINNED_SECTION_ID, CHANNELS_SECTION_ID, BOTS_SECTION_ID, work, home];+ expect(simpleOrderedSections(ordered, [])).toEqual([PINNED_SECTION_ID, BOTS_SECTION_ID, CHANNELS_SECTION_ID, work, home]);+ const moved = [CHANNELS_SECTION_ID, home, PINNED_SECTION_ID, BOTS_SECTION_ID, work];+ expect(simpleOrderedSections(ordered, moved)).toEqual(moved);});- it("cannot move a department above the fixed lists", () => {- const shown = [BOTS_SECTION_ID, CHANNELS_SECTION_ID, work];- expect(simpleSidebarSections(moveSection(shown, work, -1))).toEqual(shown);+ it("can move any section, the bots and group chats included, above the others", () => {+ const shown = simpleOrderedSections([CHANNELS_SECTION_ID, BOTS_SECTION_ID, work], []);+ expect(moveSection(shown, work, -1)).toEqual([BOTS_SECTION_ID, work, CHANNELS_SECTION_ID]);+ expect(placeSection(shown, CHANNELS_SECTION_ID, BOTS_SECTION_ID, "before")).toEqual([CHANNELS_SECTION_ID, BOTS_SECTION_ID, work]);+ });++ it("slots a department added after a Simple move in beside its neighbours from the default", () => {+ const saved = [work, CHANNELS_SECTION_ID, BOTS_SECTION_ID];+ expect(simpleOrderedSections([CHANNELS_SECTION_ID, BOTS_SECTION_ID, work, home], saved)).toEqual([work, home, CHANNELS_SECTION_ID, BOTS_SECTION_ID]);});});diff --git a/src/lib/sidebar-layout.ts b/src/lib/sidebar-layout.tsindex 74bd4c337f..1b43b5cdd9 100644--- a/src/lib/sidebar-layout.ts+++ b/src/lib/sidebar-layout.ts@@ -174,19 +174,17 @@ export function orderedSidebarSections(return result;}-export const SIMPLE_FIXED_SECTION_IDS: readonly SidebarSectionId[] = [PINNED_SECTION_ID, BOTS_SECTION_ID, CHANNELS_SECTION_ID, BOT_CHATS_SECTION_ID];+export const SIMPLE_FIRST_SECTION_IDS: readonly SidebarSectionId[] = [PINNED_SECTION_ID, BOTS_SECTION_ID, CHANNELS_SECTION_ID, BOT_CHATS_SECTION_ID];export function simpleSidebarSections(ids: SidebarSectionId[]): SidebarSectionId[] {return [- ...SIMPLE_FIXED_SECTION_IDS.filter((id) => ids.includes(id)),- ...ids.filter((id) => !SIMPLE_FIXED_SECTION_IDS.includes(id)),+ ...SIMPLE_FIRST_SECTION_IDS.filter((id) => ids.includes(id)),+ ...ids.filter((id) => !SIMPLE_FIRST_SECTION_IDS.includes(id)),];}-export function keepFixedSectionSlots(fullOrder: SidebarSectionId[], simpleOrder: SidebarSectionId[]): SidebarSectionId[] {- const moved = simpleOrder.filter((id) => !SIMPLE_FIXED_SECTION_IDS.includes(id));- let next = 0;- return fullOrder.map((id) => (SIMPLE_FIXED_SECTION_IDS.includes(id) ? id : moved[next++] ?? id));+export function simpleOrderedSections(ordered: SidebarSectionId[], simpleSaved: SidebarSectionId[]): SidebarSectionId[] {+ return orderedSidebarSections(simpleSidebarSections(ordered), simpleSaved);}export function moveSection(diff --git a/src/lib/sidebar-preferences.ts b/src/lib/sidebar-preferences.tsindex 257d25a3cc..b51359a4d7 100644--- a/src/lib/sidebar-preferences.ts+++ b/src/lib/sidebar-preferences.ts@@ -14,6 +14,7 @@ export const SIMPLE_SIDEBAR_WIDTH_KEY = "openmausbot.sidebarWidth.simple";export const SIDEBAR_ATTENTION_PINNED_KEY = "openmausbot.sidebarAttentionPinned.v1";export const SIDEBAR_COLLAPSED_SECTIONS_KEY = "openmausbot.sidebarCollapsedSections.v1";export const SIDEBAR_SECTION_ORDER_KEY = "openmausbot.sidebarSectionOrder.v1";+export const SIMPLE_SIDEBAR_SECTION_ORDER_KEY = "openmausbot.sidebarSectionOrder.simple.v1";export const PINNED_CIRCLES_KEY = "openmausbot.pinnedCircles";export const UNIVERSAL_PINS_KEY = "openmausbot.universalPins";export const PINNED_CIRCLE_ORDER_KEY = "openmausbot.pinnedCircleOrder.v1";@@ -445,3 +446,14 @@ export function saveSectionOrder(): void {saveStringList(SIDEBAR_SECTION_ORDER_KEY, ids, storage);}++export function loadSimpleSectionOrder(storage?: Pick<Storage, "getItem"> | null): string[] {+ return loadStringList(SIMPLE_SIDEBAR_SECTION_ORDER_KEY, storage);+}++export function saveSimpleSectionOrder(+ ids: string[],+ storage?: Pick<Storage, "setItem"> | null,+): void {+ saveStringList(SIMPLE_SIDEBAR_SECTION_ORDER_KEY, ids, storage);+}