Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Offer web conversation links beside app links
Purv Kabaria64dc243c79cb
diff --git a/src/components/SidebarThreadRow.tsx b/src/components/SidebarThreadRow.tsxindex b80c2194ec..c552b20147 100644--- a/src/components/SidebarThreadRow.tsx+++ b/src/components/SidebarThreadRow.tsx@@ -2,6 +2,7 @@ import { memo, useEffect, useRef, useState, type Dispatch, type ReactNode } fromimport { createPortal } from "react-dom";import { Archive, ArchiveRestore, BellOff, Check, ChevronRight, Clock, Clock3, FolderInput, Link2, Link2Off, Loader2, MoreHorizontal, Pencil, Pin, PinOff, RefreshCw, Trash2 } from "lucide-react";import type { Action, AppState, BotProject, Task } from "@/state/store";+import { api } from "@/state/store";import type { RoutineRun } from "@/lib/routines";import { cn } from "@/lib/cn";import { MENU_SHEET } from "./menu-recipe";@@ -10,7 +11,7 @@ import { intlLocale, t } from "@/lib/i18n";import { nextRename } from "@/lib/rename";import { imeComposing } from "@/lib/send-key";import { isTickable, opensRowMenuFromKey } from "@/lib/bulk-select";-import { threadRefUrl } from "@/lib/thread-refs";+import { threadRefUrl, threadWebRefUrl } from "@/lib/thread-refs";import { copyText } from "@/lib/copy-text";import { ConfirmDialog } from "./ConfirmDialog";import { threadLinkLabel } from "../../shared/thread-link";@@ -262,6 +263,16 @@ const sameThreadRow = ({ task: previousTask, ...previous }: ThreadRowProps, { taexport const SidebarThreadRow = memo(function SidebarThreadRow({ task, ownerId, current, folders, onSelect, onRename, onRegenerateTitle, onDelete, onMove, onArchive, onPin, onSnooze, onLink, onRefreshPermissions, activityLabel: liveActivity, now, selectMode = false, checked = false, onToggleSelect, panel = false, preview }: ThreadRowProps) {const activityLabel = useHeldText(liveActivity);const [menu, setMenu] = useState<{ left: number; top: number } | null>(null);+ const [webLink, setWebLink] = useState<string | null>(null);+ useEffect(() => {+ setWebLink(null);+ if (!menu) return;+ let active = true;+ void api<{ publicUrl?: string | null }>("/api/settings/custom-domain", { background: true }).then((domain) => {+ if (active) setWebLink(domain.publicUrl ? threadWebRefUrl({ botId: ownerId, threadId: task.threadId }, domain.publicUrl) : null);+ }).catch(() => { if (active) setWebLink(null); });+ return () => { active = false; };+ }, [menu, ownerId, task.threadId]);const menuMotion = useHeldMenuMotion(menu);const [renaming, setRenaming] = useState(false);const [draft, setDraft] = useState(task.title);@@ -374,6 +385,7 @@ export const SidebarThreadRow = memo(function SidebarThreadRow({ task, ownerId,className={cn("fixed z-50 max-h-[calc(100vh-16px)] w-[220px] overflow-y-auto", MENU_SHEET, menuMotion.className)} {...menuMotion.exitProps}onKeyDown={(event) => { if (event.key === "Escape") { event.preventDefault(); event.stopPropagation(); setMenu(null); actionRef.current?.focus(); } }}><button type="button" onClick={copyLink} className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-[14px] leading-[18px] text-ink hover:bg-menu-hover"><Link2 size={16} />{t("task.copyLink")}</button>+ {webLink && <button type="button" onClick={() => { setMenu(null); void copyText(webLink); }} className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-[14px] leading-[18px] text-ink hover:bg-menu-hover"><Link2 size={16} />{t("task.copyLink")} (HTTP{webLink.startsWith("https:") ? "S" : ""})</button>}{!task.sharedChat && <button type="button" onClick={startRename} className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-[14px] leading-[18px] text-ink hover:bg-menu-hover"><Pencil size={16} />{t("task.renameAria")}</button>}<ShareRowItems botId={ownerId} task={task} onPicked={() => setMenu(null)} />{onRegenerateTitle && !task.sharedChat && <button type="button" disabled={regenerating} aria-busy={regenerating} onClick={regenerateTitle} className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-[14px] leading-[18px] text-ink hover:bg-menu-hover disabled:opacity-40">{regenerating ? <Loader2 size={16} className="animate-spin" /> : <RefreshCw size={16} />}{regenerating ? t("task.regeneratingTitle") : t("task.regenerateTitle")}</button>}diff --git a/src/components/bot-panel/Conversations.dom.test.ts b/src/components/bot-panel/Conversations.dom.test.tsindex 3600dbeb22..04f7cac1ac 100644--- a/src/components/bot-panel/Conversations.dom.test.ts+++ b/src/components/bot-panel/Conversations.dom.test.ts@@ -94,6 +94,35 @@ afterEach(() => {});describe("a bot's conversations in its panel", () => {+ it("offers the public web conversation link alongside the app link and copies its exact address", async () => {+ const writeText = vi.fn(() => Promise.resolve());+ vi.stubGlobal("navigator", { clipboard: { writeText } });+ const previous = fixture.api.getMockImplementation()!;+ fixture.api.mockImplementation((path: string) => path === "/api/settings/custom-domain"+ ? Promise.resolve({ publicUrl: "https://chat.example/" }) : previous(path));+ try {+ render(research());+ click(host.querySelector('[aria-label="Actions for Translate the launch post"]'));+ await vi.waitFor(() => expect(document.querySelector("[data-thread-overlay]")?.textContent).toContain("Copy link (HTTPS)"));+ const buttons = [...document.querySelector("[data-thread-overlay]")!.querySelectorAll("button")];+ expect(buttons.some((button) => button.textContent === "Copy link")).toBe(true);+ click(buttons.find((button) => button.textContent === "Copy link (HTTPS)")!);+ expect(writeText).toHaveBeenCalledWith("https://chat.example/?thread=launch&bot=research");+ } finally { vi.unstubAllGlobals(); }+ });++ it("keeps the app link available when the public-address request fails", async () => {+ const previous = fixture.api.getMockImplementation()!;+ fixture.api.mockImplementation((path: string) => path === "/api/settings/custom-domain"+ ? Promise.reject(new Error("not permitted")) : previous(path));+ render(research());+ click(host.querySelector('[aria-label="Actions for Translate the launch post"]'));+ await Promise.resolve();+ const menu = document.querySelector("[data-thread-overlay]")!;+ expect([...menu.querySelectorAll("button")].some((button) => button.textContent === "Copy link")).toBe(true);+ expect(menu.textContent).not.toContain("Copy link (HTTPS)");+ });+it("lists three, newest first, with the open one marked, and Show N more opens the rest", () => {render(research());expect(CONVERSATIONS_SHOWN).toBe(3);diff --git a/src/lib/thread-refs.test.ts b/src/lib/thread-refs.test.tsindex 4801045b1e..1d8132b7d5 100644--- a/src/lib/thread-refs.test.ts+++ b/src/lib/thread-refs.test.ts@@ -9,11 +9,25 @@ import {splitThreadRefsForDisplay,takeThreadLinkFromLocation,threadRefUrl,+ threadWebRefUrl,threadTokenFromPaste,threadTokenSpacing,type ThreadRefCandidate,} from "./thread-refs";+describe("web conversation links", () => {+ it("uses the public web address and encodes both identifiers without retaining unrelated query values", () => {+ const result = threadWebRefUrl({ botId: "bot & one", threadId: "thread/#?" }, "https://chat.example/team/?old=secret#fragment");+ const url = new URL(result!);+ expect(url.origin + url.pathname).toBe("https://chat.example/team/");+ expect([...url.searchParams]).toEqual([["thread", "thread/#?"], ["bot", "bot & one"]]);+ expect(url.hash).toBe("");+ });+ it.each(["not a URL", "javascript:alert(1)", "file:///tmp/chat", "https://user:[email protected]/"])("refuses a non-web or credential-bearing base: %s", (base) => {+ expect(threadWebRefUrl({ botId: "bot", threadId: "thread" }, base)).toBeNull();+ });+});+const scout = (threadId: string, title: string, activeAt?: number): ThreadRefCandidate =>({ botId: "scout", botName: "Scout", threadId, title, activeAt });const ada = (threadId: string, title: string, activeAt?: number): ThreadRefCandidate =>diff --git a/src/lib/thread-refs.ts b/src/lib/thread-refs.tsindex 40dbdb659a..15787d40ca 100644--- a/src/lib/thread-refs.ts+++ b/src/lib/thread-refs.ts@@ -124,6 +124,20 @@ export function threadRefUrl(ref: { botId: string; threadId: string }): string {return THREAD_URL_PREFIX + encodeURIComponent(ref.threadId) + "?bot=" + encodeURIComponent(ref.botId);}+export function threadWebRefUrl(ref: { botId: string; threadId: string }, base: string): string | null {+ try {+ const url = new URL(base);+ if (!["https:", "http:"].includes(url.protocol) || url.username || url.password) return null;+ url.search = "";+ url.hash = "";+ url.searchParams.set("thread", ref.threadId);+ url.searchParams.set("bot", ref.botId);+ return url.href;+ } catch {+ return null;+ }+}+/** `?thread=<threadId>&bot=<botId>` on the web app's address: a chat link that works outside the app. */export function takeThreadLinkFromLocation(): string | null {const location = window.location;