Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(pair): show 'On your phone? Open in the app' only on phones and tablets
Bugfixer 20836cc7e999e
diff --git a/src/pair/PairPage.test.ts b/src/pair/PairPage.test.tsindex 2103214746..c04f8de0d4 100644--- a/src/pair/PairPage.test.ts+++ b/src/pair/PairPage.test.ts@@ -6,11 +6,13 @@ const f = vi.hoisted(() => ({ effects: [] as EffectCallback[], pair: vi.fn() }))vi.mock("react", async original => ({ ...await original<typeof import("react")>(), useEffect: (effect: EffectCallback) => { f.effects.push(effect); } }));vi.mock("../lib/session", async original => ({ ...await original<typeof import("../lib/session")>(), pairWithCode: f.pair, readSessionState: vi.fn().mockResolvedValue({ kind: "unauthenticated", error: "" }) }));vi.mock("../components/DesktopWorkspaceSwitcher", () => ({ DesktopWorkspaceSwitcher: () => null }));-import { codeProblem, codeReady, openInAppLink, PairPage, pairIntro, pairsAutomatically, pairTitle, TeamLeftPage, teamPage, unencryptedPublic } from "./PairPage";+import { codeProblem, codeReady, openInAppLink, PairPage, pairIntro, pairsAutomatically, pairTitle, phoneBrowser, TeamLeftPage, teamPage, unencryptedPublic } from "./PairPage";import en from "../locales/en.json";import type { EnvironmentDescriptor } from "../lib/session";const code = "ABCD-EFGH-JK23";+const androidChrome = "Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36";+const windowsChrome = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";const render = (initialCode: string | null) => { f.effects = []; return renderToStaticMarkup(createElement(PairPage, { initialCode })); };const flush = async () => { for (let i = 0; i < 10; i++) await Promise.resolve(); };let replaced: string[];@@ -92,6 +94,7 @@ it("warns only on plain http across the open internet", () => {it("asks for the code first, with email sign-in as a link below, and says how to get a code", async () => {vi.stubGlobal("window", {});+ vi.stubGlobal("navigator", { userAgent: androidChrome, maxTouchPoints: 5 });vi.stubGlobal("location", { replace: () => {}, protocol: "http:", hostname: "203.0.113.9", origin: "http://203.0.113.9:8799" });vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok: true, json: async () => ({ environmentId: "e", label: "hetzner-1", platform: "linux", version: "1", capabilities: { emailSignIn: true } }) }));const html = render(code);@@ -116,3 +119,24 @@ it("a team's page whose person is no longer in the team says so in one sentence,expect(html).toContain("You're no longer in Acme.");expect(html).not.toMatch(/<(input|button|a) /);});++it("offers the phone app only to a phone or tablet, never to a desktop browser", () => {+ expect(phoneBrowser(androidChrome, 5)).toBe(true);+ expect(phoneBrowser("Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Mobile/15E148 Safari/604.1", 5)).toBe(true);+ expect(phoneBrowser("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15", 5)).toBe(true);+ expect(phoneBrowser("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15", 0)).toBe(false);+ expect(phoneBrowser(windowsChrome, 0)).toBe(false);+ expect(phoneBrowser("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", 0)).toBe(false);+ expect(phoneBrowser("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", 10)).toBe(true);+ expect(phoneBrowser(windowsChrome, 10)).toBe(false);+});++it("Chrome on Windows sees the pairing form without the phone app's line", () => {+ vi.stubGlobal("window", {});+ vi.stubGlobal("navigator", { userAgent: windowsChrome, maxTouchPoints: 0 });+ vi.stubGlobal("location", { replace: () => {}, protocol: "http:", hostname: "127.0.0.1", origin: "http://127.0.0.1:8799" });+ const html = render(null);+ expect(html).toContain(">Connect</button>");+ expect(html).not.toContain(en["pair.onPhone"]);+ expect(html).not.toContain("openmausbot://pair");+});diff --git a/src/pair/PairPage.tsx b/src/pair/PairPage.tsxindex a2a1829b15..c570dc6fc4 100644--- a/src/pair/PairPage.tsx+++ b/src/pair/PairPage.tsx@@ -54,6 +54,12 @@ export function openInAppLink(origin: string, code: string): string {return `openmausbot://pair?address=${encodeURIComponent(origin)}${filled}`;}+/** The link opens the phone app, so only a phone or tablet is offered it. A tablet asking for desktop sites says+ * Macintosh (iPad) or Linux (Android) and is told apart by its touch screen. */+export function phoneBrowser(userAgent = typeof navigator === "undefined" ? "" : navigator.userAgent, touchPoints = typeof navigator === "undefined" ? 0 : navigator.maxTouchPoints ?? 0): boolean {+ return /iPhone|iPad|iPod|Android/.test(userAgent) || (/Macintosh|Linux/.test(userAgent) && touchPoints > 0);+}+/** Plain http to the open internet: the session cookie and every chat would cross it readable. */export function unencryptedPublic(where: { protocol: string; hostname: string }): boolean {return where.protocol === "http:" && !isPrivateHost(where.hostname);@@ -272,7 +278,7 @@ export function PairPage({ initialCode, initialEmail = null, reason }: { initial<button type="submit" disabled={busy || !codeReady(code)} className={button}>{t(busy ? "pair.connecting" : "pair.connect")}</button>- {where?.origin ? (+ {where?.origin && phoneBrowser() ? (<p className="mt-3 text-[13px] text-ink-secondary">{t("pair.onPhone")}{" "}<a href={openInAppLink(where.origin, code)} className="text-accent underline">{t("pair.openInApp", { app: productName() })}</a>