Skip to content

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

App settings: a bot sets Advanced layout prefs in Simple without a mode switch

milind-soni04eeb54b6b78
diff --git a/server/app-settings/host.test.ts b/server/app-settings/host.test.ts
index a787b0188c..404ea759fd 100644
--- a/server/app-settings/host.test.ts
+++ b/server/app-settings/host.test.ts
@@ -493,26 +493,40 @@ describe("Simple mode: a bot changes settings in the background and never switch
expect(fx.windowValues.get("appearance.advanced")).toBe(true);
});
+ it("lists threads in Simple when asked, with no word of Advanced, and Undo puts Simple back as it was", async () => {
+ const fx = simple();
+ fx.windowValues.set("appearance.showThreads", false);
+ const applied = await fx.set("appearance.showThreads", "true");
+ expect(applied).toMatchObject({ status: 200, body: { text: expect.stringMatching(/^Done: List each bot's threads in the sidebar\. /) } });
+ expect(fx.windowValues.get("appearance.showThreads")).toBe(true);
+ expect(fx.windowValues.get("appearance.advanced")).toBe(false);
+ expect(fx.cards().at(-1)!.card.subtitle).toBe("List each bot's threads in the sidebar");
+ expect(await fx.undo()).toEqual({ claimed: true, state: "undone" });
+ expect(fx.windowValues.get("appearance.showThreads")).toBe(false);
+ });
+
it.each([
- ["appearance.showThreads", "true"], ["appearance.toolsLayout", "toolbar"], ["appearance.pinnedCircles", "true"],
- ["appearance.pinnedPages", JSON.stringify([{ name: "Docs", url: "https://example.com" }])],
- ])("refuses %s, which Simple does not show, rather than claim a change nobody sees", async (id, value) => {
+ ["appearance.toolsLayout", "toolbar", "toolbar", "Show the sidebar's tools as a toolbar of icons"],
+ ["appearance.pinnedCircles", "true", true, "Show pinned bots as circles"],
+ ["appearance.pinnedPages", JSON.stringify([{ name: "Docs", url: "https://example.com" }]), [{ name: "Docs", url: "https://example.com" }], "Pin these pages beside the chat: Docs (https://example.com)"],
+ ])("saves %s in Simple, which keeps its own layout for it, and the card says it shows in Advanced mode", async (id, value, saved, line) => {
const fx = simple();
- const refused = await fx.set(id, value);
- expect(refused.status).toBe(409);
- expect(refused.body.error).toMatch(/shows only in Advanced mode and this app is on Simple, so nothing changed\. Don't switch modes for it.*the switch at the bottom of Settings, then ask again\.$/);
- expect(fx.windowValues.has(id)).toBe(false);
+ const applied = await fx.set(id, value);
+ expect(applied.status).toBe(200);
+ expect(applied.body.text).toContain(`Done: ${line} (shows in Advanced mode).`);
+ expect(fx.windowValues.get(id)).toEqual(saved);
expect(fx.windowValues.get("appearance.advanced")).toBe(false);
- expect(fx.cards()).toEqual([]);
+ expect(fx.cards().map((card) => card.card.subtitle)).toEqual([`${line} (shows in Advanced mode)`]);
fx.windowValues.set("appearance.advanced", true);
- expect((await fx.set(id, value)).status).toBe(200);
+ expect((await fx.set(id, value)).body.text).toContain(`Done: ${line}.`);
});
- it("pins pages in Simple while the window frame's bar shows them", async () => {
+ it("pins pages in Simple with no word of Advanced while the window frame's bar shows them", async () => {
const fx = simple();
fx.windowValues.set("appearance.windowFrame", true);
expect((await fx.set("appearance.pinnedPages", JSON.stringify([{ name: "Docs", url: "https://example.com" }]))).status).toBe(200);
expect(fx.windowValues.get("appearance.advanced")).toBe(false);
+ expect(fx.cards().at(-1)!.card.subtitle).toBe("Pin these pages beside the chat: Docs (https://example.com)");
});
});
diff --git a/server/app-settings/registry-window.ts b/server/app-settings/registry-window.ts
index 57c5e2d59d..91b6202f3f 100644
--- a/server/app-settings/registry-window.ts
+++ b/server/app-settings/registry-window.ts
@@ -7,13 +7,11 @@ const turn = (on: boolean, yes: string, no: string) => (on ? yes : no);
/** `read` is the window's last report of its preferences. */
export function windowEntries(windowPref: WindowPref, read: (id: WindowPrefId) => unknown): SettingEntry[] {
- /** Simple mode draws this one as if unset (unless `shown`), so a change while the window is on Simple would show nothing:
- * it is refused, and the bot never switches modes for it. */
- const advancedOnly = (label: string, shown = () => false) => () => (read("appearance.advanced") === false && !shown()
- ? `${label} shows only in Advanced mode and this app is on Simple, so nothing changed. Don't switch modes for it: tell the person in one line that it shows in Advanced mode, which they turn on with the switch at the bottom of Settings, then ask again.`
- : null);
- const flag = (id: Parameters<WindowPref>[0], label: string, help: string, where: Parameters<WindowPref>[3], synonyms: string[], yes: string, no: string, refusal?: () => string | null) =>
- windowPref(id, label, help, where, synonyms, "true or false", { says: (on: boolean) => turn(on, yes, no), ...(refusal ? { refusal } : {}) });
+ /** Simple mode keeps its own layout for this one (unless `shown`): the change is saved all the same, and its card says
+ * where it shows. */
+ const inAdvanced = (shown = () => false) => (line: string) => (read("appearance.advanced") === false && !shown() ? `${line} (shows in Advanced mode)` : line);
+ const flag = (id: Parameters<WindowPref>[0], label: string, help: string, where: Parameters<WindowPref>[3], synonyms: string[], yes: string, no: string, shows = (line: string) => line) =>
+ windowPref(id, label, help, where, synonyms, "true or false", { says: (on: boolean) => shows(turn(on, yes, no)) });
/** A way in to this computer: a bot may turn it on, but turning it off can cut off the device the person is using now. */
const wayIn = (id: Parameters<WindowPref>[0], label: string, help: string, where: Parameters<WindowPref>[3], synonyms: string[], yes: string) =>
windowPref(id, label, help, where, synonyms, "true (turning it off is done by the person, in Settings)",
@@ -21,18 +19,18 @@ export function windowEntries(windowPref: WindowPref, read: (id: WindowPrefId) =
return [
flag("appearance.userBubbles", "Coloured messages", "Your own messages take the bot's colour.", "bubbles", ["bubbles", "message color", "my messages"],
"Colour your messages with each bot's colour", "Show your messages in plain grey"),
- flag("appearance.showThreads", "Threads in the sidebar", "List each bot's conversations under it in the sidebar.", "layout", ["threads", "conversations", "sidebar"],
- "List each bot's threads in the sidebar", "Hide threads from the sidebar", advancedOnly("Threads in the sidebar")),
- windowPref("appearance.toolsLayout", "Sidebar tools layout", "How the sidebar shows its tools: rows, or a toolbar of icons.", "layout", ["tools layout", "toolbar", "rows"], "rows or toolbar",
- { says: (layout: "rows" | "toolbar") => (layout === "rows" ? "Show the sidebar's tools as rows" : "Show the sidebar's tools as a toolbar of icons"), refusal: advancedOnly("Sidebar tools layout") }),
- flag("appearance.pinnedCircles", "Pinned bots as circles", "Pinned bots show as a row of circles at the top of the sidebar.", "layout", ["pinned", "circles", "pins"],
- "Show pinned bots as circles", "Show pinned bots as rows", advancedOnly("Pinned bots as circles")),
+ flag("appearance.showThreads", "Threads in the sidebar", "List each bot's conversations under it in the sidebar; Simple mode lists them under each bot row, not under the tiles at the top.", "layout", ["threads", "conversations", "sidebar"],
+ "List each bot's threads in the sidebar", "Hide threads from the sidebar"),
+ windowPref("appearance.toolsLayout", "Sidebar tools layout", "How the sidebar shows its tools: rows, or a toolbar of icons. Simple mode's sidebar has no tools list, so it shows in Advanced mode.", "layout", ["tools layout", "toolbar", "rows"], "rows or toolbar",
+ { says: (layout: "rows" | "toolbar") => inAdvanced()(layout === "rows" ? "Show the sidebar's tools as rows" : "Show the sidebar's tools as a toolbar of icons") }),
+ flag("appearance.pinnedCircles", "Pinned bots as circles", "Pinned bots show as a row of circles at the top of the sidebar. Simple mode keeps pinned bots as tiles in a wide window, so it shows in Advanced mode there.", "layout", ["pinned", "circles", "pins"],
+ "Show pinned bots as circles", "Show pinned bots as rows", inAdvanced()),
flag("appearance.universalPins", "Universal pins", "Pinned bots stay pinned in every place on the rail.", "layout", ["universal pins", "pins everywhere"],
"Keep pinned bots pinned in every place", "Pin bots in each place on its own"),
- windowPref("appearance.pinnedPages", "Pinned pages", "Web pages pinned beside the chat. Send the full list; chat pages pinned from a conversation stay.", "layout",
+ windowPref("appearance.pinnedPages", "Pinned pages", "Web pages pinned beside the chat. Send the full list; chat pages pinned from a conversation stay. Simple mode shows them in the window frame's bar while the window frame is on, otherwise in Advanced mode.", "layout",
["pinned panels", "pinned pages", "web panel", "side page"], 'a list of up to 6 {"name","url"} with http(s) addresses; an empty list unpins every web page',
- { says: (pages: Array<{ name: string; url: string }>) => (pages.length ? `Pin these pages beside the chat: ${pages.map((page) => `${page.name} (${page.url})`).join(", ")}` : "Unpin every web page beside the chat"),
- refusal: advancedOnly("Pinned pages", () => read("appearance.windowFrame") === true) }),
+ { says: (pages: Array<{ name: string; url: string }>) => inAdvanced(() => read("appearance.windowFrame") === true)(pages.length
+ ? `Pin these pages beside the chat: ${pages.map((page) => `${page.name} (${page.url})`).join(", ")}` : "Unpin every web page beside the chat") }),
flag("appearance.showComputers", "Show your computers", "The rail of places down the side of the window (desktop app).", "layout", ["rail", "show your computers", "places"],
"Show the rail of your computers and Clouds", "Hide the rail of your computers and Clouds"),
flag("appearance.windowFrame", "Window frame", "Draw the system's own title bar around the window (desktop app; on Windows after a restart).", "layout", ["window frame", "title bar"],
diff --git a/src/components/BotModelBadge.test.ts b/src/components/BotModelBadge.test.ts
index 9a05c0c7e5..2d3643d4d5 100644
--- a/src/components/BotModelBadge.test.ts
+++ b/src/components/BotModelBadge.test.ts
@@ -5,7 +5,7 @@ import { initialState, type AppState, type Bot, type InstanceInfo } from "@/stat
import type { SidebarDensity } from "@/lib/sidebar-preferences";
const fixture = vi.hoisted(() => ({ state: {} as Partial<AppState>, advanced: true }));
-vi.mock("@/lib/thread-preferences", () => ({ useShowThreads: () => false }));
+vi.mock("@/lib/thread-preferences", () => ({ useShowThreads: () => false, useThreadsChosenOn: () => false }));
vi.mock("@/lib/interface-mode", async (importOriginal) => ({
...await importOriginal<typeof import("@/lib/interface-mode")>(),
useAdvancedMode: () => fixture.advanced,
diff --git a/src/components/Sidebar.simple-mode.test.ts b/src/components/Sidebar.simple-mode.test.ts
index 59de0cb14d..16cfff57cc 100644
--- a/src/components/Sidebar.simple-mode.test.ts
+++ b/src/components/Sidebar.simple-mode.test.ts
@@ -9,7 +9,7 @@ vi.mock("@/lib/interface-mode", async (original) => ({
...await original<typeof import("@/lib/interface-mode")>(),
useAdvancedMode: () => fixture.advanced,
}));
-vi.mock("@/lib/thread-preferences", () => ({ useShowThreads: () => fixture.showThreads }));
+vi.mock("@/lib/thread-preferences", () => ({ useShowThreads: () => fixture.showThreads, useThreadsChosenOn: () => false }));
vi.mock("@/lib/use-owner-or-admin", () => ({ useOwnerOrAdmin: () => fixture.admin }));
vi.mock("./DesktopCapabilities", () => ({ useDesktopCapabilities: () => ({}) }));
vi.mock("react-dom", () => ({ createPortal: (node: ReactNode) => node }));
diff --git a/src/components/SidebarBotListItem.expansion.test.ts b/src/components/SidebarBotListItem.expansion.test.ts
index 976714fdba..663890d944 100644
--- a/src/components/SidebarBotListItem.expansion.test.ts
+++ b/src/components/SidebarBotListItem.expansion.test.ts
@@ -30,7 +30,7 @@ vi.mock("./DesktopCapabilities", () => ({ useDesktopCapabilities: () => ({}) }))
// Thread trees are an Advanced surface: Simple mode lists bots only.
vi.mock("@/lib/interface-mode", async (original) => ({ ...await original<typeof import("@/lib/interface-mode")>(), useAdvancedMode: () => true }));
vi.mock("@/lib/thread-preferences", async (original) => ({ ...await original<typeof import("@/lib/thread-preferences")>(),
- useShowThreads: () => true,
+ useShowThreads: () => true, useThreadsChosenOn: () => false,
}));
vi.mock("@/lib/live-call-media", async (original) => {
const actual = await original<typeof import("@/lib/live-call-media")>();
diff --git a/src/components/SidebarThreadLabels.dom.test.ts b/src/components/SidebarThreadLabels.dom.test.ts
index 104d251ac3..1fecf4a6ba 100644
--- a/src/components/SidebarThreadLabels.dom.test.ts
+++ b/src/components/SidebarThreadLabels.dom.test.ts
@@ -5,7 +5,8 @@ import { createRoot, type Root } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { Bot, Task } from "@/state/store";
import { setThreadsUnfolded } from "@/lib/thread-fold-preferences";
-import { SidebarThreadLabels } from "./SidebarThreadLabels";
+import { setShowThreads } from "@/lib/thread-preferences";
+import { SidebarThreadLabels, ThreadFoldChevron } from "./SidebarThreadLabels";
const now = Date.now();
const task = (threadId: string, title: string, hoursAgo: number, extra: Partial<Task> = {}): Task =>
@@ -47,3 +48,26 @@ describe("a bot's threads unfolded under its row in Simple mode", () => {
expect(marked()).toEqual([]);
});
});
+
+describe("threads in the sidebar, turned on while the app is on Simple", () => {
+ const labels = () => [...host.querySelectorAll("[data-thread-label]")].map((row) => row.getAttribute("data-thread-label"));
+ const chevron = (bot: Bot) => flushSync(() => root.render(createElement(ThreadFoldChevron, { bot, dispatch: vi.fn() })));
+
+ it("lists every bot's threads under its row, with New thread where the fold was, and folds back only when turned off", () => {
+ setThreadsUnfolded("research", false);
+ render(research());
+ expect(labels()).toEqual([]);
+ chevron(research());
+ expect(host.querySelector("[data-bot-threads-fold]")).not.toBeNull();
+
+ flushSync(() => setShowThreads(true));
+ render(research());
+ expect(labels()).toEqual(["pricing", "home", "deck"]);
+ chevron(research());
+ expect([host.querySelector("[data-bot-threads-fold]"), host.querySelector("[data-bot-new-thread]")?.getAttribute("data-bot-new-thread")]).toEqual([null, "research"]);
+
+ flushSync(() => setShowThreads(false));
+ render(research());
+ expect(labels()).toEqual([]);
+ });
+});
diff --git a/src/components/SidebarThreadLabels.tsx b/src/components/SidebarThreadLabels.tsx
index a827f8c20d..a420ef0144 100644
--- a/src/components/SidebarThreadLabels.tsx
+++ b/src/components/SidebarThreadLabels.tsx
@@ -5,6 +5,7 @@ import { t } from "@/lib/i18n";
import { nextRename } from "@/lib/rename";
import { localizedTaskTitle } from "@/lib/task-title";
import { setThreadsUnfolded, useThreadsUnfolded } from "@/lib/thread-fold-preferences";
+import { useThreadsChosenOn } from "@/lib/thread-preferences";
import type { Action, AppState, Bot } from "@/state/store";
import { botOpensTo } from "@/state/thread-navigation";
import { canUnfold, openThreadPinned, threadLabels, type LabelRow } from "./sidebar-thread-labels";
@@ -30,10 +31,12 @@ type FillBot = FoldBot & Pick<Bot, "threadId" | "switchingTo">;
export const threadLabelsId = (botId: string) => `thread-labels-${botId}`;
-/** Simple mode's chevron on a bot row: unfolds the bot's threads under it. A bot with one thread gets New thread here. */
+/** Simple mode's chevron on a bot row: unfolds the bot's threads under it. A bot with one thread, or every bot row while
+ * threads in the sidebar are on, gets New thread here. */
export function ThreadFoldChevron({ bot, dispatch }: { bot: FoldBot; dispatch: Dispatch<Action> }) {
const unfolded = useThreadsUnfolded(bot.id);
- if (!canUnfold(bot)) {
+ const listed = useThreadsChosenOn();
+ if (listed || !canUnfold(bot)) {
return <button 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>;
}
@@ -68,7 +71,9 @@ function StatusMark({ row }: { row: LabelRow }) {
export function SidebarThreadLabels({ bot, selected, drafting = false, rowThreadId, pendingQueued, dispatch }: {
bot: Bot; selected: boolean; drafting?: boolean; rowThreadId: string; pendingQueued: AppState["pendingQueued"]; dispatch: Dispatch<Action>;
}) {
+ const listed = useThreadsChosenOn();
const unfolded = useThreadsUnfolded(bot.id) && canUnfold(bot);
+ const foldable = unfolded && !listed;
const current = selected && !drafting ? bot.switchingTo ?? bot.threadId : undefined;
const { rows, more, runningMore } = threadLabels(bot, pendingQueued, { unfolded, current, rowThreadId, now: Date.now() });
const [renaming, setRenaming] = useState<string | null>(null);
@@ -132,7 +137,7 @@ export function SidebarThreadLabels({ bot, selected, drafting = false, rowThread
: event.key === "Home" ? 0 : event.key === "End" ? list.length - 1 : null;
if (to !== null) { event.preventDefault(); focusItem(to); return; }
if (event.key === "Enter" || event.key === " ") { event.preventDefault(); list[at]?.click(); return; }
- if (event.key === "ArrowLeft" && unfolded) {
+ if (event.key === "ArrowLeft" && foldable) {
event.preventDefault();
setThreadsUnfolded(bot.id, false);
document.querySelector<HTMLElement>(`[data-bot-threads-fold="${CSS.escape(bot.id)}"]`)?.focus();
diff --git a/src/lib/thread-fold-preferences.ts b/src/lib/thread-fold-preferences.ts
index 7aa46b15c3..e3facdcc20 100644
--- a/src/lib/thread-fold-preferences.ts
+++ b/src/lib/thread-fold-preferences.ts
@@ -1,5 +1,7 @@
import { useEffect, useState } from "react";
+import { useThreadsChosenOn } from "./thread-preferences";
+
/** The bots whose threads the person unfolded under their sidebar row, on this device. Folded is the default. */
export const UNFOLDED_THREADS_KEY = "omb-unfolded-threads";
const LIMIT = 200;
@@ -53,12 +55,14 @@ function subscribe(listener: () => void): () => void {
return () => listeners.delete(listener);
}
+/** Every bot row's threads are unfolded while the person has threads in the sidebar turned on. */
export function useThreadsUnfolded(botId: string): boolean {
+ const listed = useThreadsChosenOn();
const [unfolded, setUnfolded] = useState(() => unfoldedThreadBots().has(botId));
useEffect(() => {
const read = () => setUnfolded(unfoldedThreadBots().has(botId));
read();
return subscribe(read);
}, [botId]);
- return unfolded;
+ return listed || unfolded;
}
diff --git a/src/lib/thread-preferences.ts b/src/lib/thread-preferences.ts
index 868aa64fe9..526e9f80aa 100644
--- a/src/lib/thread-preferences.ts
+++ b/src/lib/thread-preferences.ts
@@ -24,6 +24,16 @@ export function showThreads(): boolean {
}
}
+/** Only a "1" the person saved: unset reads as on in Advanced, but Simple lists threads only once they are asked for. */
+export function threadsChosenOn(): boolean {
+ if (sessionChoice !== undefined) return sessionChoice;
+ try {
+ return storage()?.getItem(SHOW_THREADS_KEY) === "1";
+ } catch {
+ return false;
+ }
+}
+
function notify() {
for (const listener of listeners) listener();
}
@@ -61,6 +71,10 @@ export function useShowThreadsChoice(): boolean {
return useSyncExternalStore(subscribe, showThreads, () => true);
}
+export function useThreadsChosenOn(): boolean {
+ return useSyncExternalStore(subscribe, threadsChosenOn, () => false);
+}
+
export function useShowThreads(): boolean {
const chosen = useShowThreadsChoice();
return useAdvancedMode() && chosen;
diff --git a/src/lib/window-prefs.test.ts b/src/lib/window-prefs.test.ts
index bd8643e858..1b94da11ab 100644
--- a/src/lib/window-prefs.test.ts
+++ b/src/lib/window-prefs.test.ts
@@ -24,6 +24,17 @@ describe("window preferences", () => {
expect(await windowPrefValues()).toMatchObject({ "general.sendKey": "mod-enter", "general.notificationSounds": false, "appearance.pinnedCircles": true });
});
+ it("reports threads as Simple shows them: off until the person turns them on, though Advanced's unset default is on", async () => {
+ values.set("omb-advanced-mode", "1");
+ expect((await windowPrefValues())["appearance.showThreads"]).toBe(true);
+ values.set("omb-advanced-mode", "0");
+ expect((await windowPrefValues())["appearance.showThreads"]).toBe(false);
+ applyWindowPref({ kind: "window-pref", id: "appearance.showThreads", value: true });
+ expect([values.get("omb-show-threads"), (await windowPrefValues())["appearance.showThreads"]]).toEqual(["1", true]);
+ applyWindowPref({ kind: "window-pref", id: "appearance.showThreads", value: false });
+ expect([values.get("omb-show-threads"), (await windowPrefValues())["appearance.showThreads"]]).toEqual(["0", false]);
+ });
+
it("reports the window's values once after a burst of setters", async () => {
vi.useFakeTimers();
const fetched = vi.fn(async () => new Response("{}"));
diff --git a/src/lib/window-prefs.ts b/src/lib/window-prefs.ts
index 7e5eb59508..aa84b38a26 100644
--- a/src/lib/window-prefs.ts
+++ b/src/lib/window-prefs.ts
@@ -15,7 +15,7 @@ import { choosePlaceColor } from "./place-look";
import { readSendKey, setSendKey } from "./send-key";
import { loadPinnedCircles, loadSidebarToolsLayout, loadUniversalPins, setPinnedCircles, setSidebarToolsLayout, setUniversalPins } from "./sidebar-preferences";
import { applySkinChoice, readSkinChoice } from "./skins";
-import { setShowThreads, showThreads } from "./thread-preferences";
+import { setShowThreads, showThreads, threadsChosenOn } from "./thread-preferences";
import { readColorUserBubbles, setColorUserBubbles } from "./user-bubble-preference";
import { latestWebPanels, setWebPanels } from "./web-panel-preferences";
import { newWebPanelId, validateWebPanel, type WebPanel } from "./web-panels";
@@ -44,7 +44,7 @@ const PREFS: { [I in WindowPrefId]: Pref<I> } = {
"general.sendKey": { read: () => readSendKey(), write: (key) => setSendKey(key) },
"general.notificationSounds": { read: () => notificationSoundsEnabled(), write: (on) => setNotificationSounds(on) },
"appearance.userBubbles": { read: () => readColorUserBubbles(), write: (on) => setColorUserBubbles(on) },
- "appearance.showThreads": { read: () => showThreads(), write: (on) => setShowThreads(on) },
+ "appearance.showThreads": { read: () => (readAdvancedMode() ? showThreads() : threadsChosenOn()), write: (on) => setShowThreads(on) },
"appearance.toolsLayout": { read: () => loadSidebarToolsLayout(), write: (layout) => setSidebarToolsLayout(layout) },
"appearance.pinnedCircles": { read: () => loadPinnedCircles(), write: (on) => setPinnedCircles(on) },
"appearance.universalPins": { read: () => loadUniversalPins(), write: (on) => setUniversalPins(on) },