Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Pin to sidebar: base pin edits on the stored list, wrap the toolbar, show the panel limit
Bugfixer 2ac361cd55d7c
diff --git a/src/components/app/PageTools.test.ts b/src/components/app/PageTools.test.tsindex d5eabd570b..63bd316c29 100644--- a/src/components/app/PageTools.test.ts+++ b/src/components/app/PageTools.test.ts@@ -211,6 +211,22 @@ describe("a bot's page in the chat", () => {act(() => setWebPanels(Array.from({ length: MAX_WEB_PANELS }, (_, i) => ({ id: `p${i}`, name: `P${i}`, url: `https://p${i}.example/` }))));expect(button("Pin to sidebar", card()).disabled).toBe(true);+ expect(card().querySelector("[data-page-pin-full]")?.textContent).toContain(`maximum of ${MAX_WEB_PANELS} pages`);+ act(() => { setWebPanels([]); setAdvancedMode(false); });+ });++ it("keeps a page another window pinned a moment ago when this one pins", async () => {+ setWebPanels([]);+ setAdvancedMode(true);+ await render(row(payload()));+ // Another window's write whose storage event hasn't arrived yet.+ localStorage.setItem("omb-web-panels", JSON.stringify([{ id: "panel-9", name: "Other", url: "https://other.example/" }]));+ await click("Pin to sidebar", card());+ expect(JSON.parse(localStorage.getItem("omb-web-panels")!).map((panel: { name: string }) => panel.name)).toEqual(["Other", "Pricing"]);+ // The other window unpins everything; Unpin here must not pin the page again.+ localStorage.setItem("omb-web-panels", "[]");+ await click("Unpin", card());+ expect(localStorage.getItem("omb-web-panels")).toBe("[]");act(() => { setWebPanels([]); setAdvancedMode(false); });});diff --git a/src/components/app/PageTools.tsx b/src/components/app/PageTools.tsxindex 9a02746d5d..dcf7eec271 100644--- a/src/components/app/PageTools.tsx+++ b/src/components/app/PageTools.tsx@@ -9,7 +9,7 @@ import { useCopyFeedback } from "@/lib/copy-text";import { t } from "@/lib/i18n";import { useAdvancedMode } from "@/lib/interface-mode";import { addPointedChip } from "@/lib/pointed-chips";-import { setWebPanels, useWebPanels } from "@/lib/web-panel-preferences";+import { latestWebPanels, setWebPanels, useWebPanels } from "@/lib/web-panel-preferences";import { findPinnedPage, MAX_WEB_PANELS, togglePinnedPage, type PinnedChatPage } from "@/lib/web-panels";import type { AppDocument, AppPayload } from "../../../shared/app";import { pointMessage, readPointEvent } from "../../../shared/app-frame/point";@@ -125,7 +125,11 @@ export function usePagePin(page: PinnedChatPage, title: string) {const advanced = useAdvancedMode();const panels = useWebPanels();const pinned = Boolean(findPinnedPage(panels, page));- return { show: advanced, pinned, full: !pinned && panels.length >= MAX_WEB_PANELS, toggle: () => setWebPanels(togglePinnedPage(panels, page, title)) };+ return { show: advanced, pinned, full: !pinned && panels.length >= MAX_WEB_PANELS, toggle: () => {+ // Base the edit on the stored list, not this render's: another window may have pinned or unpinned since.+ const latest = latestWebPanels();+ if (Boolean(findPinnedPage(latest, page)) === pinned) setWebPanels(togglePinnedPage(latest, page, title));+ } };}export interface PageToolsProps {@@ -155,7 +159,7 @@ export function PageToolbar({ version, point, share, ready, fullScreen, room, pi{!version.latest && <button type="button" className="ms-1 rounded px-1 text-accent-text hover:underline" onClick={() => version.show(null)}>{t("chat.preview.latest")}</button>}{version.flash && <span role="status" data-page-updated className="ms-1 rounded-full bg-accent/15 px-2 py-px font-medium text-accent-text">{t("chat.preview.updated")}</span>}</div>- <div className="ms-auto flex items-center gap-1">+ <div className="ms-auto flex flex-wrap items-center gap-1">{!room && <><button type="button" aria-pressed={point.pointing} onClick={point.toggle} disabled={!ready} title={t("chat.preview.pointHint")}className={cn(ASK_CHIP, point.pointing ? ASK_CHIP_PICKED : ASK_CHIP_IDLE)}>@@ -181,6 +185,7 @@ export function PageToolbar({ version, point, share, ready, fullScreen, room, pi{fullScreen.open ? <X size={16} /> : <Maximize2 size={14} />}</button></div>+ {!room && pin?.show && pin.full && <p data-page-pin-full className="basis-full text-end text-xs text-ink-secondary">{t("chat.preview.pinFull", { max: MAX_WEB_PANELS })}</p>}</div>);}diff --git a/src/lib/web-panel-preferences.ts b/src/lib/web-panel-preferences.tsindex b4b10467b0..e97f68ec8e 100644--- a/src/lib/web-panel-preferences.ts+++ b/src/lib/web-panel-preferences.ts@@ -9,6 +9,7 @@ export const WEB_PANELS_KEY = "omb-web-panels";let sessionPanels: WebPanel[] | undefined;let cachedRaw: string | null | undefined;let cachedPanels: WebPanel[] = [];+let writeFailed = false;const listeners = new Set<() => void>();const NONE: WebPanel[] = [];@@ -61,12 +62,27 @@ export function setWebPanels(panels: readonly WebPanel[]): void {sessionPanels = parseWebPanels(raw);try {storage()?.setItem(WEB_PANELS_KEY, raw);+ writeFailed = false;} catch {// Kept for this session when storage is full or blocked.+ writeFailed = true;}notify();}+/** The stored list as it is now, including another window's edit whose storage event hasn't arrived yet: base an edit on this, not on a rendered snapshot. */+export function latestWebPanels(): readonly WebPanel[] {+ if (!writeFailed) {+ try {+ const store = storage();+ if (store) return parseWebPanels(store.getItem(WEB_PANELS_KEY));+ } catch {+ // Blocked storage: fall back to this session's list.+ }+ }+ return readPanels();+}+export function useWebPanels(): WebPanel[] {return useSyncExternalStore(subscribe, readPanels, () => NONE);}