Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
feat(chat): pin a bot's page to the sidebar (#4951)
Bugfixer 228ba8de84d34
diff --git a/src/components/PinnedPanelsSettings.tsx b/src/components/PinnedPanelsSettings.tsxindex 4ed9c2ed47..bb23aa901b 100644--- a/src/components/PinnedPanelsSettings.tsx+++ b/src/components/PinnedPanelsSettings.tsx@@ -37,7 +37,7 @@ export function PinnedPanelsSettings() {<li key={panel.id} className="flex items-center gap-3 px-3 py-2"><div className="min-w-0 flex-1"><p className="truncate text-[14px] font-medium text-ink">{panel.name}</p>- <p className="truncate text-[12px] text-ink-secondary" title={panel.url}>{panel.url}</p>+ <p className="truncate text-[12px] text-ink-secondary" title={panel.url}>{panel.url ?? t("webPanels.settings.chatPage")}</p></div><buttontype="button"diff --git a/src/components/SidebarFooterNav.tsx b/src/components/SidebarFooterNav.tsxindex 6f8cb6a3c6..d57f6e20b6 100644--- a/src/components/SidebarFooterNav.tsx+++ b/src/components/SidebarFooterNav.tsx@@ -1,4 +1,4 @@-import { FolderOpen, Globe, Puzzle, UsersRound, Zap } from "lucide-react";+import { AppWindow, FolderOpen, Globe, Puzzle, UsersRound, Zap } from "lucide-react";import { useMemo, type ReactNode } from "react";import { useAppTriggers } from "@/lib/app-triggers";@@ -180,7 +180,7 @@ export function SidebarFooterNav({label={panel.name}iconsOnly={iconsOnly || toolbar}active={state.activeView === "web-panel" && state.webPanelId === panel.id}- icon={(active) => <Globe size={iconSize} className={tone(active)} />}+ icon={(active) => (panel.page ? <AppWindow size={iconSize} className={tone(active)} /> : <Globe size={iconSize} className={tone(active)} />)}onClick={() => dispatch({ type: "showWebPanel", id: panel.id })}/>))}diff --git a/src/components/WebPanelPage.test.ts b/src/components/WebPanelPage.test.tsindex e696c6d63c..0a936e80a4 100644--- a/src/components/WebPanelPage.test.ts+++ b/src/components/WebPanelPage.test.ts@@ -6,12 +6,25 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;const fixture = vi.hoisted(() => ({- panels: [] as Array<{ id: string; name: string; url: string }>,+ panels: [] as Array<{ id: string; name: string; url?: string; page?: { botId: string; threadId: string; messageId: string } }>,+ setWebPanels: vi.fn(),+ fetchAppDocument: vi.fn(async (_threadId: string, _messageId: string, _signal?: AbortSignal): Promise<unknown> => ({ srcdoc: "<p>hi</p>", can: {} })),state: { webPanelId: "panel-1" } as { webPanelId?: string },dispatch: vi.fn(),api: vi.fn(async (_path: string, _init?: unknown): Promise<unknown> => ({ framing: "allowed" })),}));-vi.mock("@/lib/web-panel-preferences", () => ({ useWebPanels: () => fixture.panels }));+vi.mock("@/lib/web-panel-preferences", () => ({ useWebPanels: () => fixture.panels, setWebPanels: fixture.setWebPanels }));+vi.mock("./app/app-api", () => ({+ AppDocumentError: class AppDocumentError extends Error {+ failure: unknown;+ constructor(failure: { offline: boolean; error?: string }) { super(failure.error ?? "offline"); this.failure = failure; }+ },+ fetchAppDocument: fixture.fetchAppDocument,+}));+vi.mock("./app/AppFrame", async () => {+ const { createElement: h } = await import("react");+ return { AppFrame: (props: { botId: string; threadId: string; fill?: boolean }) => h("div", { "data-frame": `${props.botId}/${props.threadId}`, "data-fill": String(Boolean(props.fill)) }) };+});vi.mock("@/state/store", () => ({ useStore: () => ({ state: fixture.state, dispatch: fixture.dispatch }) }));vi.mock("@/state/api", () => ({ api: fixture.api }));@@ -86,4 +99,29 @@ describe("a pinned web panel's page", () => {act(() => root.render(createElement(WebPanelPage)));expect(fixture.dispatch).toHaveBeenCalledWith({ type: "showChat" });});++ it("shows a pinned chat page from the server, framed like the chat frames it", async () => {+ fixture.panels = [{ id: "panel-1", name: "Sales", page: { botId: "b1", threadId: "t1", messageId: "m1" } }];+ fixture.api.mockClear();+ await act(async () => root.render(createElement(WebPanelPage)));+ expect(fixture.fetchAppDocument).toHaveBeenCalledWith("t1", "m1", expect.any(AbortSignal));+ expect(fixture.api).not.toHaveBeenCalled();+ expect(host.querySelector("[data-frame]")?.getAttribute("data-frame")).toBe("b1/t1");+ expect(host.querySelector("[data-frame]")?.getAttribute("data-fill")).toBe("true");+ expect(host.querySelector("h1")?.textContent).toBe("Sales");+ });++ it("says when a pinned chat page is gone, and unpins it", async () => {+ const { AppDocumentError } = await import("./app/app-api");+ fixture.panels = [+ { id: "panel-1", name: "Sales", page: { botId: "b1", threadId: "t1", messageId: "m1" } },+ { id: "panel-2", name: "CI", url: "https://ci.example/" },+ ];+ fixture.fetchAppDocument.mockRejectedValueOnce(new AppDocumentError({ offline: false, status: 404, error: "No such page." }));+ await act(async () => root.render(createElement(WebPanelPage)));+ expect(host.querySelector("[data-frame]")).toBeNull();+ expect(host.querySelector("[role=alert]")?.textContent).toContain("No such page.");+ act(() => [...host.querySelectorAll("button")].find((button) => button.textContent === "Unpin")!.click());+ expect(fixture.setWebPanels).toHaveBeenCalledWith([{ id: "panel-2", name: "CI", url: "https://ci.example/" }]);+ });});diff --git a/src/components/WebPanelPage.tsx b/src/components/WebPanelPage.tsxindex bb63fee5cd..bd248749d6 100644--- a/src/components/WebPanelPage.tsx+++ b/src/components/WebPanelPage.tsx@@ -1,15 +1,20 @@// A pinned web page shown in place of the chat, like Team map. The page is// framed with a sandbox and no referrer; a page that refuses framing (or// never loads) falls back to a button that opens it in the browser.-import { ExternalLink, Globe, RotateCw } from "lucide-react";-import { useEffect, useState } from "react";+// A pinned chat page (a bot's show_html page) is fetched from the server and+// framed exactly as the chat frames it.+import { AppWindow, ExternalLink, Globe, PinOff, RotateCw } from "lucide-react";+import { useEffect, useRef, useState } from "react";import { openExternalLink } from "@/lib/app-links";import { t } from "@/lib/i18n";-import { useWebPanels } from "@/lib/web-panel-preferences";-import { isAppOrigin } from "@/lib/web-panels";+import { setWebPanels, useWebPanels } from "@/lib/web-panel-preferences";+import { isAppOrigin, type PinnedChatPage, type WebPanel } from "@/lib/web-panels";import { api } from "@/state/api";import { useStore } from "@/state/store";+import type { AppDocument } from "../../shared/app";+import { AppDocumentError, fetchAppDocument } from "./app/app-api";+import { AppFrame, type AppFrameHandle } from "./app/AppFrame";const LOAD_TIMEOUT_MS = 10_000;@@ -43,6 +48,7 @@ export function WebPanelPage() {}, [panel?.url, reloads]);if (!panel) return null;+ if (panel.page) return <PinnedChatPageView key={panel.id} panel={panel} page={panel.page} panels={panels} />;const refused = refusedUrl === panel.url;const openInBrowser = () => void openExternalLink(panel.url).catch(() => undefined);@@ -88,3 +94,71 @@ export function WebPanelPage() {</main>);}++type PageLoad = { doc: AppDocument } | { failure: string };++function PinnedChatPageView({ panel, page, panels }: { panel: WebPanel; page: PinnedChatPage; panels: readonly WebPanel[] }) {+ const { dispatch } = useStore();+ const [reloads, setReloads] = useState(0);+ const [load, setLoad] = useState<PageLoad | null>(null);+ const handle = useRef<AppFrameHandle | null>(null);++ useEffect(() => {+ const controller = new AbortController();+ setLoad(null);+ fetchAppDocument(page.threadId, page.messageId, controller.signal).then(+ (doc) => { if (!controller.signal.aborted) setLoad({ doc }); },+ (error: unknown) => {+ if (controller.signal.aborted) return;+ setLoad({ failure: error instanceof AppDocumentError && !error.failure.offline ? error.failure.error : t("app.strip.offline") });+ },+ );+ return () => controller.abort();+ }, [page.threadId, page.messageId, reloads]);++ const unpin = () => setWebPanels(panels.filter((entry) => entry.id !== panel.id));++ return (+ <main className="flex min-w-0 flex-1 flex-col bg-app" aria-label={panel.name} data-pinned-page={page.messageId}>+ <header className="flex items-center gap-2 border-b border-hairline/40 px-4 py-2.5">+ <AppWindow size={16} className="shrink-0 text-ink-secondary" />+ <h1 className="min-w-0 flex-1 truncate text-[14px] font-semibold text-ink">{panel.name}</h1>+ <button+ type="button"+ className="ui-icon-button shrink-0"+ aria-label={t("webPanels.page.reload")}+ title={t("webPanels.page.reload")}+ onClick={() => setReloads((n) => n + 1)}+ >+ <RotateCw size={16} />+ </button>+ <button type="button" className="ui-button" onClick={unpin}>+ <PinOff size={14} />+ {t("chat.preview.unpin")}+ </button>+ </header>+ {load && "doc" in load ? (+ <div className="relative min-h-0 flex-1">+ <AppFrame+ key={reloads}+ doc={load.doc}+ botId={page.botId}+ threadId={page.threadId}+ title={panel.name}+ height={600}+ handle={handle}+ onHeight={() => {}}+ onProblem={() => {}}+ onTeardownRequested={() => dispatch({ type: "showChat" })}+ fill+ />+ </div>+ ) : load ? (+ <div role="alert" className="flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center">+ <p className="text-[14px] font-medium text-ink">{t("webPanels.page.pageGone")}</p>+ <p className="max-w-sm text-[13px] text-ink-secondary">{load.failure}</p>+ </div>+ ) : null}+ </main>+ );+}diff --git a/src/components/app/AppMessage.tsx b/src/components/app/AppMessage.tsxindex ff98d60056..2dbf5828eb 100644--- a/src/components/app/AppMessage.tsx+++ b/src/components/app/AppMessage.tsx@@ -9,7 +9,7 @@ import { AppDocumentError, fetchAppDocument, type AppFetchFailure } from "./app-import { APP_POOL_LIMITS, useAppPoolSlot, type AppPool } from "./app-pool";import { AppDone, AppHeader, AppInfo, AppOpenButton, AppPlaceholder, AppStrip, APP_SURFACE } from "./AppChrome";import { AppFrame, type AppFrameHandle, type AppFrameProblem } from "./AppFrame";-import { PAGE_HEIGHT, PageFullScreen, PageNotes, PageToolbar, usePagePoint, usePageShare, usePageVersion } from "./PageTools";+import { PAGE_HEIGHT, PageFullScreen, PageNotes, PageToolbar, usePagePin, usePagePoint, usePageShare, usePageVersion } from "./PageTools";const WIDTH = "max-w-[760px]";const DOC_REUSE_MS = 60_000;@@ -154,7 +154,8 @@ function AppRow({ botId, botName, threadId, message, payload, pool, room }: {threadId, appId: message.id, rev, title: payload.title, picked: () => setFullScreen(false),});const share = usePageShare(threadId, message.id, message.publishedPage);- const tools = { version, point, share, room, ready: Boolean(current), fullScreen: { open: fullScreen, toggle: () => { point.stop(); setFullScreen((open) => !open); } } };+ const pin = usePagePin({ botId, threadId, messageId: message.id }, payload.title);+ const tools = { version, point, share, room, pin, ready: Boolean(current), fullScreen: { open: fullScreen, toggle: () => { point.stop(); setFullScreen((open) => !open); } } };const reloadNow = () => {setProblem(null);diff --git a/src/components/app/PageTools.test.ts b/src/components/app/PageTools.test.tsindex 31f1062404..d5eabd570b 100644--- a/src/components/app/PageTools.test.ts+++ b/src/components/app/PageTools.test.ts@@ -6,7 +6,10 @@ import { createRoot, type Root } from "react-dom/client";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import { BotEditorStore, type Message, type useStore } from "@/state/store";+import { setAdvancedMode } from "@/lib/interface-mode";import { addPointedChip, forgetPointedChips, takePointedChips, usePointedChips } from "@/lib/pointed-chips";+import { setWebPanels } from "@/lib/web-panel-preferences";+import { MAX_WEB_PANELS } from "@/lib/web-panels";import type { AppPayload } from "../../../shared/app";import type { PublishedPageCard } from "../../../shared/published-page";import { botHtmlDocument } from "../../../shared/app-frame/document";@@ -191,6 +194,26 @@ describe("a bot's page in the chat", () => {expect(overlay()).toBeNull();});+ it("pins the page to the sidebar and unpins it, only in Advanced mode, where pinned panels show", async () => {+ setWebPanels([]);+ setAdvancedMode(false);+ await render(row(payload()));+ expect(card().querySelector("[data-page-pin]")).toBeNull();++ act(() => setAdvancedMode(true));+ await click("Pin to sidebar", card());+ expect(JSON.parse(localStorage.getItem("omb-web-panels")!)).toEqual([+ { id: "panel-1", name: "Pricing", page: { botId: "pepper", threadId: "t1", messageId: "a1" } },+ ]);+ expect(button("Unpin", card()).getAttribute("aria-pressed")).toBe("true");+ await click("Unpin", card());+ expect(JSON.parse(localStorage.getItem("omb-web-panels")!)).toEqual([]);++ 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);+ act(() => { setWebPanels([]); setAdvancedMode(false); });+ });+it("gives an MCP app none of a page's tools", async () => {await render(row(payload({ source: "mcp", mcp: { server: "excalidraw", tool: "create_view", resourceUri: "ui://excalidraw/app.html" } })));expect(card().querySelector("[data-page-tools]")).toBeNull();diff --git a/src/components/app/PageTools.tsx b/src/components/app/PageTools.tsxindex 3e91d2d82d..4e4497cef1 100644--- a/src/components/app/PageTools.tsx+++ b/src/components/app/PageTools.tsx@@ -1,13 +1,16 @@// A bot's page in the chat, artifact-style: its version stepper, Point, Share, Open in new tab and Full screen.import { useCallback, useEffect, useRef, useState, type MutableRefObject, type ReactNode } from "react";import { createPortal } from "react-dom";-import { ArrowUpRight, Check, ChevronLeft, ChevronRight, Copy, Crosshair, Globe, Loader2, Maximize2, Share2, Trash2, X } from "lucide-react";+import { ArrowUpRight, Check, ChevronLeft, ChevronRight, Copy, Crosshair, Globe, Loader2, Maximize2, Pin, PinOff, Share2, Trash2, X } from "lucide-react";import { useStore } from "@/state/store";import { openExternalLink } from "@/lib/app-links";import { cn } from "@/lib/cn";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 { 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";import type { PublishedPageCard } from "../../../shared/published-page";@@ -117,6 +120,14 @@ export function usePagePoint(args: { frame(): HTMLIFrameElement | null | undefinreturn { pointing, toggle: () => set(!on.current), stop: () => { if (on.current) set(false); } };}+/** Pin to sidebar: the page joins the sidebar's pinned panels, which show in Advanced mode, so the button does too. */+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)) };+}+export interface PageToolsProps {version: ReturnType<typeof usePageVersion>;point: ReturnType<typeof usePagePoint>;@@ -125,10 +136,11 @@ export interface PageToolsProps {fullScreen: { open: boolean; toggle(): void };/** Shown in a room: view-only, so no Point and no Share. */room?: boolean;+ pin?: ReturnType<typeof usePagePin>;}/** The card's toolbar: ‹ v2 › and Updated on the left; Point, Share, Open in new tab and Full screen on the right. */-export function PageToolbar({ version, point, share, ready, fullScreen, room, className }: PageToolsProps & { className?: string }) {+export function PageToolbar({ version, point, share, ready, fullScreen, room, pin, className }: PageToolsProps & { className?: string }) {const label = version.latest ? t("chat.preview.version", { n: version.rev + 1 }) : t("chat.preview.versionOf", { n: version.rev + 1, count: version.last + 1 });const busy = share.share.kind === "busy";return (@@ -151,6 +163,13 @@ export function PageToolbar({ version, point, share, ready, fullScreen, room, cl<button type="button" onClick={() => void share.run(version.rev)} disabled={busy} className={cn(ASK_CHIP, ASK_CHIP_IDLE)}>{busy ? <Loader2 size={14} className="animate-spin" /> : <Share2 size={14} />}{t("chat.preview.share")}</button>+ {pin?.show && (+ <button type="button" data-page-pin aria-pressed={pin.pinned} onClick={pin.toggle} disabled={pin.full}+ title={pin.full ? t("chat.preview.pinFull", { max: MAX_WEB_PANELS }) : t(pin.pinned ? "chat.preview.unpinHint" : "chat.preview.pinHint")}+ className={cn(ASK_CHIP, pin.pinned ? ASK_CHIP_PICKED : ASK_CHIP_IDLE)}>+ {pin.pinned ? <PinOff size={14} /> : <Pin size={14} />}{t(pin.pinned ? "chat.preview.unpin" : "chat.preview.pin")}+ </button>+ )}</>}<button type="button" className={TOOL} disabled={!share.url} onClick={() => share.url && void openExternalLink(share.url)}aria-label={t("chat.preview.openTab")} title={share.url ? t("chat.preview.openTab") : t("chat.preview.openTabNeedsLink")}>diff --git a/src/lib/web-panels.test.ts b/src/lib/web-panels.test.tsindex dfa1018afb..a8541f4a62 100644--- a/src/lib/web-panels.test.ts+++ b/src/lib/web-panels.test.ts@@ -1,6 +1,6 @@import { describe, expect, it } from "vitest";-import { isAppOrigin, MAX_WEB_PANELS, newWebPanelId, parseWebPanels, validateWebPanel } from "./web-panels";+import { findPinnedPage, isAppOrigin, MAX_WEB_PANELS, newWebPanelId, parseWebPanels, pinnedPageName, togglePinnedPage, validateWebPanel } from "./web-panels";describe("pinned web panels", () => {it("accepts absolute http and https pages and trims the name", () => {@@ -52,3 +52,40 @@ describe("pinned web panels", () => {.toBe("panel-3");});});++describe("a bot's chat page pinned to the sidebar", () => {+ const page = { botId: "b1", threadId: "t1", messageId: "m1" };++ it("pins a chat page under its title and unpins it again", () => {+ const pinned = togglePinnedPage([], page, " Company dashboard ");+ expect(pinned).toEqual([{ id: "panel-1", name: "Company dashboard", page }]);+ expect(findPinnedPage(pinned, page)).toBe(pinned[0]);+ expect(togglePinnedPage(pinned, page, "Company dashboard")).toEqual([]);+ });++ it("keeps web panels beside it and never pins onto a full list", () => {+ const web = [{ id: "panel-1", name: "CI", url: "https://ci.example/" }];+ expect(togglePinnedPage(web, page, "Sales")).toEqual([...web, { id: "panel-2", name: "Sales", page }]);+ const full = Array.from({ length: MAX_WEB_PANELS }, (_, i) => ({ id: `p${i}`, name: `P${i}`, url: `https://p${i}.example/` }));+ expect(togglePinnedPage(full, page, "Sales")).toBe(full);+ });++ it("names a page after its title, cut to 40 characters, or Page when it has none", () => {+ expect(pinnedPageName("a".repeat(60))).toHaveLength(40);+ expect(togglePinnedPage([], page, " ")[0]?.name).toBe("Page");+ });++ it("reads a pinned chat page back from storage, and drops a broken one", () => {+ const stored = [+ { id: "a", name: "Sales", page },+ { id: "b", name: "No ref", page: { botId: "b1", threadId: "", messageId: "m1" } },+ { id: "c", name: "Bad ref", page: "t1/m1" },+ { id: "d", name: "", page },+ { id: "e", name: "Web", url: "https://e.example/" },+ ];+ expect(parseWebPanels(JSON.stringify(stored))).toEqual([+ { id: "a", name: "Sales", page },+ { id: "e", name: "Web", url: "https://e.example/" },+ ]);+ });+});diff --git a/src/lib/web-panels.ts b/src/lib/web-panels.tsindex 59d77b1f7f..f09b617a64 100644--- a/src/lib/web-panels.ts+++ b/src/lib/web-panels.ts@@ -2,13 +2,20 @@// keeps one click away in the sidebar. Renderer-only data — no bot sees it,// no server stores it. Only plain http(s) pages without credentials are// accepted, because the URL is framed in the app and handed to the browser.+// A panel can instead point at a page a bot made in a chat (show_html): it is+// shown the way the chat shows it, from the server, never from a URL.-export interface WebPanel {- id: string;- name: string;- url: string;+/** Where a bot's page in a chat lives. */+export interface PinnedChatPage {+ botId: string;+ threadId: string;+ messageId: string;}+export type WebPanel =+ | { id: string; name: string; url: string; page?: undefined }+ | { id: string; name: string; page: PinnedChatPage; url?: undefined };+export const MAX_WEB_PANELS = 6;export const MAX_WEB_PANEL_NAME = 40;@@ -60,8 +67,17 @@ export function parseWebPanels(raw: string | null | undefined): WebPanel[] {for (const entry of value) {if (panels.length >= MAX_WEB_PANELS) break;if (!entry || typeof entry !== "object") continue;- const { id, name, url } = entry as Record<string, unknown>;- if (typeof id !== "string" || !id || seen.has(id) || typeof name !== "string" || typeof url !== "string") continue;+ const { id, name, url, page } = entry as Record<string, unknown>;+ if (typeof id !== "string" || !id || seen.has(id) || typeof name !== "string") continue;+ if (page !== undefined) {+ const ref = chatPageRef(page);+ const title = pinnedPageName(name);+ if (!ref || !title) continue;+ seen.add(id);+ panels.push({ id, name: title, page: ref });+ continue;+ }+ if (typeof url !== "string") continue;const check = validateWebPanel({ name, url });if (!check.ok) continue;seen.add(id);@@ -70,6 +86,34 @@ export function parseWebPanels(raw: string | null | undefined): WebPanel[] {return panels;}+const MAX_REF_ID = 200;++function chatPageRef(value: unknown): PinnedChatPage | undefined {+ if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;+ const { botId, threadId, messageId } = value as Record<string, unknown>;+ const ok = (part: unknown): part is string => typeof part === "string" && part.length > 0 && part.length <= MAX_REF_ID;+ return ok(botId) && ok(threadId) && ok(messageId) ? { botId, threadId, messageId } : undefined;+}++/** A page's title as a panel name: one line, at most 40 characters. */+export function pinnedPageName(title: string): string {+ return title.replace(/\s+/g, " ").trim().slice(0, MAX_WEB_PANEL_NAME).trim();+}++/** The panel that pins this chat page, if any. */+export function findPinnedPage(panels: readonly WebPanel[], page: PinnedChatPage): WebPanel | undefined {+ return panels.find((panel) => panel.page?.threadId === page.threadId && panel.page.messageId === page.messageId);+}++/** The list with this chat page pinned (named after its title) or, when it already is, unpinned. Pinning onto a full+ * list changes nothing. */+export function togglePinnedPage(panels: readonly WebPanel[], page: PinnedChatPage, title: string): readonly WebPanel[] {+ const pinned = findPinnedPage(panels, page);+ if (pinned) return panels.filter((panel) => panel !== pinned);+ if (panels.length >= MAX_WEB_PANELS) return panels;+ return [...panels, { id: newWebPanelId(panels), name: pinnedPageName(title) || "Page", page }];+}+export function newWebPanelId(existing: readonly WebPanel[]): string {let n = existing.length + 1;const taken = new Set(existing.map((panel) => panel.id));diff --git a/src/locales/en.json b/src/locales/en.jsonindex ad8c14b8a3..762ff9c13f 100644--- a/src/locales/en.json+++ b/src/locales/en.json@@ -6676,12 +6676,14 @@"webPanels.settings.nameInvalid": "Give the panel a name of up to {max} characters.","webPanels.settings.urlInvalid": "Use a full http:// or https:// address without a user name or password.","webPanels.settings.urlSelf": "That's this app's own address. Pin a different page.",+ "webPanels.settings.chatPage": "A page from a chat","webPanels.settings.help": "Pages open inside the app. Bots can't see them.","webPanels.settings.full": "You've pinned the maximum of {max} pages. Remove one to add another.","webPanels.page.reload": "Reload","webPanels.page.openInBrowser": "Open in browser","webPanels.page.cantEmbed": "This page can't be shown inside the app","webPanels.page.cantEmbedBody": "Some sites refuse to be embedded. Open it in your browser instead.",+ "webPanels.page.pageGone": "This page can't be shown right now","webPanels.page.refusedBody": "{site} doesn't allow other apps to show it. Open it in your browser instead.","botAccess.tools.budget": "Its last turn listed {listed} of the {limit} tools its AI takes at once.","botAccess.tools.budgetSearched": "Found through tool search instead: {names}",@@ -7431,6 +7433,11 @@"chat.preview.point": "Point","chat.preview.pointHint": "Click the part of the page you want changed. Press Esc to stop.","chat.preview.share": "Share",+ "chat.preview.pin": "Pin to sidebar",+ "chat.preview.unpin": "Unpin",+ "chat.preview.pinHint": "Keep this page one click away in the sidebar",+ "chat.preview.unpinHint": "Remove this page from the sidebar",+ "chat.preview.pinFull": "You've pinned the maximum of {max} pages. Remove one in Settings to pin this one.","chat.preview.republish": "Update link","chat.preview.published": "Published","chat.preview.updatedLink": "Updated at the same link",diff --git a/src/locales/pt-br.json b/src/locales/pt-br.jsonindex e668f43975..3cd1d4f482 100644--- a/src/locales/pt-br.json+++ b/src/locales/pt-br.json@@ -6393,12 +6393,14 @@"webPanels.settings.nameInvalid": "Dê ao painel um nome com até {max} caracteres.","webPanels.settings.urlInvalid": "Use um endereço http:// ou https:// completo, sem nome de usuário nem senha.","webPanels.settings.urlSelf": "Esse é o endereço deste app. Fixe outra página.",+ "webPanels.settings.chatPage": "Uma página de um chat","webPanels.settings.help": "As páginas abrem dentro do app. Os bots não conseguem vê-las.","webPanels.settings.full": "Você atingiu o limite de {max} páginas fixadas. Remova uma para adicionar outra.","webPanels.page.reload": "Recarregar","webPanels.page.openInBrowser": "Abrir no navegador","webPanels.page.cantEmbed": "Não é possível mostrar esta página dentro do app","webPanels.page.cantEmbedBody": "Alguns sites não permitem isso. Abra no navegador.",+ "webPanels.page.pageGone": "Esta página não pode ser mostrada agora","webPanels.page.refusedBody": "O site {site} não permite que outros apps mostrem seu conteúdo. Abra-o no navegador.","botAccess.tools.budget": "Ferramentas listadas na última sessão: {listed} de {limit}, o limite que a IA dele aceita de uma vez.","botAccess.tools.budgetSearched": "Disponíveis pela busca de ferramentas: {names}",@@ -7260,6 +7262,11 @@"chat.preview.point": "Apontar","chat.preview.pointHint": "Clique na parte da página que você quer mudar. Aperte Esc para parar.","chat.preview.share": "Compartilhar",+ "chat.preview.pin": "Fixar na barra lateral",+ "chat.preview.unpin": "Desafixar",+ "chat.preview.pinHint": "Mantenha esta página a um clique na barra lateral",+ "chat.preview.unpinHint": "Remover esta página da barra lateral",+ "chat.preview.pinFull": "Você fixou o máximo de {max} páginas. Remova uma em Configurações para fixar esta.","chat.preview.republish": "Atualizar link","chat.preview.published": "Publicada","chat.preview.updatedLink": "Atualizada no mesmo link",diff --git a/src/locales/source-hashes.json b/src/locales/source-hashes.jsonindex 019cb00b63..2a1305ad67 100644--- a/src/locales/source-hashes.json+++ b/src/locales/source-hashes.json@@ -33567,7 +33567,14 @@"mascot.body.jalebi": "2e200e92c49eb6d51ca76db4516d1fe7a39430862e5b8ebb5fa30071dc5ccc63","mascot.body.katli": "28670af54fcc50cd51c5983623672ed0d63c3355b5be96ef666812b0da6b6bf5","mascot.body.karanji": "dc2ff0fdc7d7ce51f05cd1dd8d6f0f8ff444c82da36304373561c9cf246c32a4",- "skins.tagline.diwali": "92af77174824ccd4267be3745deb99c28cd2ddd21e761e2afcd438bded98405c"+ "skins.tagline.diwali": "92af77174824ccd4267be3745deb99c28cd2ddd21e761e2afcd438bded98405c",+ "chat.preview.pin": "d5112330c62b1d4f09810792611f10db67c27fcafdf8c81274ecd8a8656d2748",+ "chat.preview.unpin": "ee3c716130546a45492c899f7486b67f880e5631a2b8b8065bb16be9956d0b43",+ "chat.preview.pinHint": "f5f31cfdaf2c8d4a02bf609b4d9006246fd561a7c8e1b8d81985feea435682a8",+ "chat.preview.unpinHint": "3df27bb21925a0a6ad3458a902df50be9e666b88a233d1a7c81b14f216c71e01",+ "chat.preview.pinFull": "f3cb86a1f0b52a900f5f7a62701255b5f1fdc8189864d129ffa8e6d836778679",+ "webPanels.settings.chatPage": "5f91a43d9ab7b59e888918479fcbfe51b365743302ac0d9042dd35dfe3fadba5",+ "webPanels.page.pageGone": "98a0b4b8583492387bbd9fbb96b8044b9fdc979baa40210d6d8e5489d9fb668a"},"zh": {"pro.fromPrice": "a48a04a457d60b08b54fc83e7a6c4584ffedb1e23621859084900c8521a3af7b",