Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
feat(handoff): wire the card and pill to the pane, desktop view and sign-in import
milind-sonif1b5ba44c269
diff --git a/server/host/handoff-requests.test.ts b/server/host/handoff-requests.test.tsindex 08f70ac846..1035997058 100644--- a/server/host/handoff-requests.test.ts+++ b/server/host/handoff-requests.test.ts@@ -107,10 +107,19 @@ describe("a bot hands one step to the person", () => {expect(card).toMatchObject({ done: true, note: "Used the work account", resumed: true });expect(w.answered).toEqual([{ messageId: "m1", text: handoffResumePrompt({ instruction: ask.instruction, note: "Used the work account" }, "done") }]);expect(w.answered[0]!.text).toContain("outcome done");+ expect(w.answered[0]!.text).toContain("That is their claim and is unverified.");expect(w.answered[0]!.text).toContain("Re-read the page");expect(w.handedBack).toEqual(["work"]);});+ it("tells done, skipped and expired apart, and only done is a claim to check", () => {+ const texts = (["done", "cancelled", "expired"] as const).map((outcome) => handoffResumePrompt({ instruction: ask.instruction }, outcome));+ expect(new Set(texts).size).toBe(3);+ expect(texts.map((text) => /outcome (done|skipped|expired)/.exec(text)?.[1])).toEqual(["done", "skipped", "expired"]);+ expect(texts.map((text) => text.includes("unverified"))).toEqual([true, false, false]);+ expect(texts.every((text) => text.includes("Re-read the page first"))).toBe(true);+ });+it("Skip resumes the bot with skipped", async () => {const w = world();await w.requests.request(BOT, "work", ask);diff --git a/src/components/BrowserPanel.tsx b/src/components/BrowserPanel.tsxindex 44387ece03..bc5f357f0b 100644--- a/src/components/BrowserPanel.tsx+++ b/src/components/BrowserPanel.tsx@@ -10,7 +10,7 @@ import { ExtensionsMenu, extensionsOf, type BrowserExtension } from "./browser/Eimport { MoreMenu } from "./browser/MoreMenu";import { PasskeyNotice } from "./browser/PasskeyNotice";import { StreamSurface, type StreamSurfaceHandle, type SurfaceConnect } from "./browser/StreamSurface";-import { BrowserViewerPill } from "./viewer-pill-host";+import { BrowserViewerPill, usePaneHold } from "./viewer-pill-host";import { createBrowserControl, startsInteraction, streamTransport, type BrowserControl, type BrowserTakeStatus } from "@/lib/browser-control";import { resolveAddressBarInput } from "@/lib/browser-address";import { closeBrowserPictureInPicture, openBrowserPictureInPicture, supportsBrowserPictureInPicture, useBrowserPictureInPicture } from "@/lib/browser-pip";@@ -219,8 +219,9 @@ export function LiveBrowser({ bot, signIn, page }: { bot: Bot; signIn?: BrowserS}, []);useEffect(() => { browserControl.current?.keep(kept || signInOpen); }, [kept, signInOpen]);- const takeControl = () => { setKept(true); browserControl.current?.keep(true); browserControl.current?.takeControl(); };- const handBack = () => { setKept(false); browserControl.current?.handBack(); };+ const paneHold = usePaneHold(bot.id, scopedThread ?? null, paneMode);+ const takeControl = () => { setKept(true); browserControl.current?.keep(true); browserControl.current?.takeControl(); paneHold.set(true); };+ const handBack = () => { setKept(false); browserControl.current?.handBack(); paneHold.set(false); };const openSignInPage = () => {const url = signInPage.current;if (!url || pageNow.current === null) return;@@ -455,7 +456,7 @@ export function LiveBrowser({ bot, signIn, page }: { bot: Bot; signIn?: BrowserS</div>) : null}</div>- {maximized && <BrowserViewerPill bot={bot} you={you} pending={takeStatus === "pending" || takeStatus === "slow"} onTake={takeControl} onStop={handBack} onCollapse={() => setMaximized(false)} />}+ {maximized && <BrowserViewerPill bot={bot} you={paneMode ? paneHold.held : you} pending={takeStatus === "pending" || takeStatus === "slow"} onTake={takeControl} onStop={handBack} onDone={() => paneHold.set(false)} onCollapse={() => setMaximized(false)} />}<dialog ref={profilesDialog} onClose={() => setShowProfiles(false)} onClick={(e) => { if (e.target === e.currentTarget) setShowProfiles(false); }} className="m-auto w-[min(420px,calc(100%-32px))] max-h-[80vh] overflow-auto rounded-2xl border border-hairline/50 bg-card p-5 text-ink shadow-2xl backdrop:bg-black/40"><div className="mb-4 flex items-center justify-between"><h2 className="text-[15px] font-medium">{t("browser.panel.profiles")}</h2><button className={button} aria-label={t("browser.panel.closeProfiles")} onClick={() => setShowProfiles(false)}><X size={16} /></button></div>{(heldElsewhere || (you && takeStatus !== "")) && <p className="mb-3 text-[12px] text-ink-secondary">{t(heldElsewhere ? "browser.profiles.heldElsewhere" : "browser.profiles.busy")}</p>}diff --git a/src/components/HandoffCard.dom.test.ts b/src/components/HandoffCard.dom.test.tsindex 6b764f5ba3..bb8048ec6c 100644--- a/src/components/HandoffCard.dom.test.ts+++ b/src/components/HandoffCard.dom.test.ts@@ -30,10 +30,10 @@ const handoff = (fields: Partial<SignInRequestCardData> = {}): SignInRequestCard});const row = (id: string, signIn: SignInRequestCardData): Message => ({ id, at: 1, role: "bot", kind: "signin", text: signIn.instruction ?? "", signIn } as Message);-async function show(messages: Message[], index = messages.length - 1) {+async function show(messages: Message[], index = messages.length - 1, config?: unknown) {const dispatch = vi.fn();const bot = { id: "scout", name: "Scout", color: "teal", threadId: "t1", messages, tasks: [] } as unknown as Bot;- const state: AppState = { ...initialState, bots: [bot], selectedId: bot.id, connected: true };+ const state = { ...initialState, bots: [bot], selectedId: bot.id, connected: true, ...(config ? { config } : {}) } as AppState;const value = { state, dispatch, flushBotPatches: async () => null, refreshInstances: async () => {}, refreshModels: async () => {} };await act(async () => root.render(createElement(StoreContext.Provider, { value },createElement(SignInRequestCard, { botId: "scout", botName: "Scout", threadId: "t1", message: messages[index]! }))));@@ -105,6 +105,27 @@ describe("a step the bot handed to the person", () => {expect(container.querySelector("[data-handoff-suggestion]")).toBeNull();});+ it("offers the person's own sign-in from their browser when the app can import one for the site, and answers done once it did", async () => {+ const offer = vi.fn(async () => ({ offered: true }));+ const importIt = vi.fn(async () => ({ ok: true, site: "github.com", imported: 4, sessionOnly: 0, skipped: {} }));+ (window as unknown as { ogb: unknown }).ogb = { browserCookies: { offer, sources: async () => [{ id: "chrome", name: "Chrome", engine: "chromium", profiles: [{ id: "Default", name: "Person 1" }] }], import: importIt } };+ try {+ await show([row("m1", handoff({ need: "sign_in", site: "github.com", url: "https://github.com/" }))], 0, { browserEngine: { cookieImport: true } });+ expect(offer).toHaveBeenCalledWith({ botId: "scout", threadId: null, site: "github.com" });+ await act(async () => button("Use my sign-in from my own browser")!.click());+ await act(async () => { await new Promise((done) => setTimeout(done, 0)); });+ await act(async () => { container.querySelector<HTMLFormElement>('dialog form')!.requestSubmit(); await new Promise((done) => setTimeout(done, 0)); });+ expect(importIt).toHaveBeenCalledWith({ botId: "scout", threadId: null, site: "github.com", source: "chrome", profile: "Default" });+ expect(calls.find((call) => call.url.endsWith("/sign-in-cards/m1/done"))?.body).toEqual({ threadId: "t1", note: "imported the person's sign-in for github.com from their own Chrome" });+ offer.mockClear();+ await show([row("m2", handoff({ need: "captcha", site: "github.com", url: "https://github.com/" }))], 0, { browserEngine: { cookieImport: true } });+ expect(offer).not.toHaveBeenCalled();+ expect(button("Use my sign-in from my own browser")).toBeUndefined();+ } finally {+ delete (window as unknown as { ogb?: unknown }).ogb;+ }+ });+it("leaves a site sign-in without an instruction on its own card", async () => {await show([row("m1", { url: "https://notion.so", site: "notion.so", place: "browser" })]);expect(container.querySelector('[data-shell="kicker"]')).toBeNull();diff --git a/src/components/HandoffCard.tsx b/src/components/HandoffCard.tsxindex e868795280..e50f99f9cc 100644--- a/src/components/HandoffCard.tsx+++ b/src/components/HandoffCard.tsx@@ -1,5 +1,5 @@import { useState, type ReactNode } from "react";-import { Check, Globe, Hand, Loader2, LockKeyhole, Monitor, RefreshCw } from "lucide-react";+import { Check, Globe, Hand, KeyRound, Loader2, LockKeyhole, Monitor, RefreshCw } from "lucide-react";import { HANDOFF_NOTE_MAX } from "../../shared/sign-in-request";import type { Surface } from "../../shared/wire";@@ -11,8 +11,9 @@ import type { Bot, Message } from "@/state/store";import { useStoreDispatch, useStoreSelector } from "@/state/store-select";import { ASK_DARK_PRIMARY, ASK_QUIET_BUTTON, ASK_SECONDARY_BUTTON, AskCard, AskError, returnFocusToComposer } from "./AskCard";import { ELEVATED_CARD } from "./elevated";+import { CookieImportDialog } from "./browser/CookieImportDialog";import { HandoffPreview } from "./HandoffPreview";-import { HandoffSuggestion, useSuggestedApp } from "./HandoffSuggestion";+import { HandoffSuggestion, useSignInImport, useSuggestedApp } from "./HandoffSuggestion";export const placeIcon = (place: Surface) => place === "browser" ? <Globe /> : <Monitor />;@@ -58,6 +59,8 @@ export function HandoffCard({ botId, botName, color: _color, threadId, message,const [note, setNote] = useState("");const [explained, setExplained] = useState(false);const [localError, setLocalError] = useState<string | null>(null);+ const [importing, setImporting] = useState(false);+ const importFor = useSignInImport(botId, threadId, !end && card.place === "browser" && card.need === "sign_in" ? card.site : "");const ref = { botId, threadId, messageId: message.id, place: card.place };const instruction = card.instruction ?? "";const placeLabel = handoffPlaceLabel(card.place);@@ -144,8 +147,19 @@ export function HandoffCard({ botId, botName, color: _color, threadId, message,<LockKeyhole size={11} aria-hidden="true" /> {t("handoff.private")}</p>)}+ {importFor && (+ <button type="button" onClick={() => setImporting(true)} disabled={pending !== null} data-handoff-import=""+ className={cn(ASK_QUIET_BUTTON, "-ms-2 mt-2")}>+ <KeyRound size={14} aria-hidden="true" />{t("handoff.importSignIn")}+ </button>+ )}{localError && <AskError>{localError}</AskError>}</AskCard>+ {importFor && (+ <CookieImportDialog open={importing} botId={botId} botName={botName} threadId={importFor.threadId} site={importFor.site}+ onClose={() => setImporting(false)}+ onImported={(imported) => void answerSignIn(ref, "done", `imported the person's sign-in for ${imported.site} from their own ${imported.browser}`).catch(() => undefined)} />+ )}{suggested && (<HandoffSuggestion app={suggested.card} status={suggested.status} request={ref} botName={botName} />)}diff --git a/src/components/HandoffPreview.dom.test.ts b/src/components/HandoffPreview.dom.test.tsnew file mode 100644index 0000000000..0fdd87c21a--- /dev/null+++ b/src/components/HandoffPreview.dom.test.ts@@ -0,0 +1,45 @@+// @vitest-environment happy-dom+import { act, createElement } from "react";+import { createRoot, type Root } from "react-dom/client";+import { afterEach, beforeEach, expect, it, vi } from "vitest";++const streams = vi.hoisted(() => ({ started: 0, stopped: 0 }));+vi.mock("@/lib/browser-stream-client", async (original) => ({+ ...await original<typeof import("@/lib/browser-stream-client")>(),+ createPreviewStreamClient: () => { streams.started += 1; return { send: () => true, stop: () => { streams.stopped += 1; } }; },+ createPreviewFramePainter: () => ({ paint: () => undefined, stop: () => undefined }),+}));++import { initialState, StoreContext, type AppState, type Bot } from "@/state/store";+import { HandoffPreview } from "./HandoffPreview";++let container: HTMLDivElement, root: Root;+beforeEach(() => {+ vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);+ streams.started = 0; streams.stopped = 0;+ container = document.createElement("div"); document.body.append(container); root = createRoot(container);+});+afterEach(async () => { await act(async () => root.unmount()); container.remove(); vi.unstubAllGlobals(); });++const bot = { id: "scout", name: "Scout", threadId: "t1", messages: [], tasks: [] } as unknown as Bot;+async function show(state: Partial<AppState>) {+ const value = { state: { ...initialState, bots: [bot], config: { browserEngine: { engine: "chrome" } }, ...state } as AppState, dispatch: vi.fn(), flushBotPatches: async () => null, refreshInstances: async () => {}, refreshModels: async () => {} };+ await act(async () => root.render(createElement(StoreContext.Provider, { value },+ createElement(HandoffPreview, { botId: "scout", threadId: "t1", place: "browser", label: "Take over", onOpen: () => undefined }))));+}++it("watches the bot's browser at card width, with one stream of its own", async () => {+ await show({});+ expect(streams.started).toBe(1);+ expect(container.querySelector("canvas")).not.toBeNull();+});++it("opens no second stream while the Browser panel shows this bot, and stops its own when the panel opens", async () => {+ await show({ computerOpen: true, selectedId: "scout" });+ expect(streams.started).toBe(0);+ await show({});+ expect(streams.started).toBe(1);+ await show({ computerOpen: true, selectedId: "scout" });+ expect(streams.stopped).toBe(1);+ expect(container.querySelector("canvas")).not.toBeNull();+});diff --git a/src/components/HandoffPreview.tsx b/src/components/HandoffPreview.tsxindex 6108fea95c..2fd5d81ff3 100644--- a/src/components/HandoffPreview.tsx+++ b/src/components/HandoffPreview.tsx@@ -35,17 +35,20 @@ export function HandoffPreview({ botId, threadId, place, label, onOpen, disabledconst canvas = useRef<HTMLCanvasElement>(null);const [phase, setPhase] = useState<PreviewPhase>(still ? "frame" : "connecting");const [frame, setFrame] = useState<string | null>(still ?? null);- const live = still === undefined && place === "browser" && streams && visible;+ const live = still === undefined && place === "browser" && streams;+ // The Browser panel open on this bot has its own stream: the card keeps its last picture rather than open a second.+ const panelOpen = useStoreSelector((state) => state.computerOpen && state.selectedId === botId);+ const streaming = live && visible && !panelOpen;useEffect(() => {- if (!live || !canvas.current) return;+ if (!streaming || !canvas.current) return;const painter = createPreviewFramePainter(canvas.current, () => setPhase("live"));const client = createPreviewStreamClient({ access: browserStreamAccess(botId, window.location, browserScope(team, threadId)), maxWidth: 1120, maxHeight: 700, interactive: false },{ onFrame: (jpeg) => painter.paint(jpeg), onViewport: () => undefined, onConnectedChange: () => undefined, onUnauthorized: () => setPhase((now) => (now === "live" ? now : "none")) },);return () => { client.stop(); painter.stop(); };- }, [live, botId, threadId, team]);+ }, [streaming, botId, threadId, team]);const seen = useStoreSelector((state) => {const row = state.bots.find((bot) => bot.id === botId)?.messages.findLast((one) => one.kind === "screen" && one.png);diff --git a/src/components/HandoffSuggestion.tsx b/src/components/HandoffSuggestion.tsxindex af0c78dc89..53acb90328 100644--- a/src/components/HandoffSuggestion.tsx+++ b/src/components/HandoffSuggestion.tsx@@ -14,6 +14,8 @@ import { t } from "@/lib/i18n";import { mcpSignInLink } from "@/lib/mcp-sign-in";import { answerSignIn } from "@/lib/sign-in";import { useOwnerOrAdmin } from "@/lib/use-owner-or-admin";+import { browserScope } from "@/lib/team-browser";+import { cookieImportAvailable } from "./browser/CookieImportDialog";import { api } from "@/state/store";import { useStoreDispatch, useStoreSelector } from "@/state/store-select";import { ASK_DARK_PRIMARY, ASK_QUIET_BUTTON } from "./AskCard";@@ -54,6 +56,23 @@ export function useSuggestedApp(site: string, botId: string): { card: ToolkitCarreturn found.status?.connected && botAppScope(bot, found.card.slug) !== null ? null : found;}+/** Whether the desktop app offers to bring the person's own sign-in for this site into the bot's browser (never for+ * Google, never into a temporary browser); the scope the import names. */+export function useSignInImport(botId: string, threadId: string, site: string): { site: string; threadId: string | null } | null {+ const ready = useStoreSelector((state) => cookieImportAvailable(state.config) && state.bots.find((bot) => bot.id === botId)?.browserProfile !== "guest");+ const scope = useStoreSelector((state) => browserScope(state.config?.team, threadId).threadId ?? null);+ const [offered, setOffered] = useState<string | null>(null);+ useEffect(() => {+ setOffered(null);+ const bridge = window.ogb?.browserCookies;+ if (!ready || !site || !bridge) return;+ let live = true;+ void bridge.offer({ botId, threadId: scope, site }).then((answer) => { if (live && answer.offered) setOffered(site); }, () => undefined);+ return () => { live = false; };+ }, [ready, site, botId, scope]);+ return offered && offered === site ? { site, threadId: scope } : null;+}+/*** Under a sign-in the bot asked for, when the site is an app it could use directly: Connect starts that app's own* connection, gives it to the bot, and answers the request as done so the bot goes on through the app.diff --git a/src/components/browser/CookieImportDialog.tsx b/src/components/browser/CookieImportDialog.tsxindex fdffb5dc0a..f04256ab4f 100644--- a/src/components/browser/CookieImportDialog.tsx+++ b/src/components/browser/CookieImportDialog.tsx@@ -52,13 +52,15 @@ export function cookieImportAvailable(config: { browserEngine?: { cookieImport?:* A site's sign-in from one of the person's own browsers into a bot's: they pick the browser, its profile and the* site, and confirm a sentence naming all three and the bot. Security: only counts and a reason come back.*/-export function CookieImportDialog({ open, botId, botName, threadId, site: initialSite, onClose }: {+export function CookieImportDialog({ open, botId, botName, threadId, site: initialSite, onClose, onImported }: {open: boolean;botId: string;botName: string;threadId: string | null;site: string;onClose: () => void;+ /** The import went through: the site it took and the browser it came from. */+ onImported?: (imported: { site: string; browser: string }) => void;}) {const dialog = useRef<HTMLDialogElement>(null);const opening = useRef(initialSite);@@ -102,6 +104,7 @@ export function CookieImportDialog({ open, botId, botName, threadId, site: inititry {const done = await bridge.import({ botId, threadId, site: site.trim(), source: source.id, profile: profile.id });const unread = done.ok ? (done.skipped.protected ?? 0) + (done.skipped.failed ?? 0) : 0;+ if (done.ok && done.imported > 0) onImported?.({ site: done.site, browser: source.name });setResult(done.ok? { tone: "ok", text: t(done.imported === 1 ? "browser.cookieImport.doneOne" : "browser.cookieImport.done", { count: done.imported, site: done.site })+ (unread ? ` ${t("browser.cookieImport.partial", { count: unread, browser: source.name })}` : "") }diff --git a/src/components/viewer-pill-host.dom.test.ts b/src/components/viewer-pill-host.dom.test.tsnew file mode 100644index 0000000000..221c6e45ef--- /dev/null+++ b/src/components/viewer-pill-host.dom.test.ts@@ -0,0 +1,63 @@+// @vitest-environment happy-dom+import { act, createElement } from "react";+import { createRoot, type Root } from "react-dom/client";+import { afterEach, beforeEach, expect, it, vi } from "vitest";++import { initialState, StoreContext, type AppState } from "@/state/store";+import { BrowserViewerPill, usePaneHold } from "./viewer-pill-host";++let container: HTMLDivElement, root: Root;+let hold: ReturnType<typeof vi.fn>;+beforeEach(() => {+ vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);+ hold = vi.fn(async (input: { held: boolean }) => ({ held: input.held }));+ (window as unknown as { ogb: unknown }).ogb = { browserPane: { show: vi.fn(), hold } };+ container = document.createElement("div"); document.body.append(container); root = createRoot(container);+});+afterEach(async () => { await act(async () => root.unmount()); container.remove(); delete (window as unknown as { ogb?: unknown }).ogb; vi.unstubAllGlobals(); });++const settle = () => act(async () => { await new Promise((done) => setTimeout(done, 0)); });+const button = (name: string) => [...container.querySelectorAll("button")].find((one) => one.textContent?.trim() === name || one.getAttribute("aria-label") === name);++function PaneViewer({ onCollapse }: { onCollapse: () => void }) {+ const pane = usePaneHold("scout", null, true);+ return createElement(BrowserViewerPill, { bot: { id: "scout" }, you: pane.held, pending: false, onTake: () => pane.set(true), onStop: () => pane.set(false), onDone: () => pane.set(false), onCollapse });+}++async function show(state: Partial<AppState>, onCollapse = vi.fn()) {+ const value = { state: { ...initialState, ...state }, dispatch: vi.fn(), flushBotPatches: async () => null, refreshInstances: async () => {}, refreshModels: async () => {} };+ await act(async () => root.render(createElement(StoreContext.Provider, { value }, createElement(PaneViewer, { onCollapse }))));+ return onCollapse;+}++it("takes and hands back the desktop app's pane through its hold, and lets a hold it took go when it goes", async () => {+ await show({});+ expect(container.querySelector('[role="status"]')?.textContent).toBe("Watching");+ await act(async () => button("Take control")!.click()); await settle();+ expect(hold).toHaveBeenLastCalledWith({ botId: "scout", threadId: null, held: true });+ expect(container.querySelector('[role="status"]')?.textContent).toBe("You're in control");+ await act(async () => button("Stop")!.click()); await settle();+ expect(hold).toHaveBeenLastCalledWith({ botId: "scout", threadId: null, held: false });+ await act(async () => button("Take control")!.click()); await settle();+ await act(async () => root.unmount());+ expect(hold).toHaveBeenLastCalledWith({ botId: "scout", threadId: null, held: false });+ root = createRoot(container);+});++it("during a request, I'm done answers it, lets the pane go and folds the viewer", async () => {+ const fetch = vi.fn(async (_input: RequestInfo | URL, _init?: RequestInit) => new Response("{}", { status: 200, headers: { "content-type": "application/json" } }));+ vi.stubGlobal("fetch", fetch);+ const help = { botId: "scout", threadId: "t1", messageId: "m1", site: "", place: "browser" as const, instruction: "Sign in." };+ const onCollapse = await show({ computerControl: { scout: { held: false, helpReason: null, help } } } as unknown as Partial<AppState>);+ await act(async () => button("Take control")!.click()); await settle();+ await act(async () => button("I'm done")!.click()); await settle();+ expect(String(fetch.mock.calls[0]?.[0])).toContain("/api/bots/scout/sign-in-cards/m1/done");+ expect(hold).toHaveBeenLastCalledWith({ botId: "scout", threadId: null, held: false });+ expect(onCollapse).toHaveBeenCalledOnce();+});++it("folds back into the chat from its own control", async () => {+ const onCollapse = await show({});+ await act(async () => button("Back to the chat")!.click());+ expect(onCollapse).toHaveBeenCalledOnce();+});diff --git a/src/components/viewer-pill-host.tsx b/src/components/viewer-pill-host.tsxindex 5a78736065..0e19b00447 100644--- a/src/components/viewer-pill-host.tsx+++ b/src/components/viewer-pill-host.tsx@@ -1,8 +1,10 @@-import { useState } from "react";+import { useCallback, useEffect, useRef, useState } from "react";+import { Minimize2 } from "lucide-react";import { signInWaits } from "../../shared/sign-in-request";import type { ComputerHelpRef } from "../../shared/wire";import { viewerPillState } from "@/lib/handoff";+import { t } from "@/lib/i18n";import { answerSignIn } from "@/lib/sign-in";import type { Bot } from "@/state/store";import { useStoreSelector } from "@/state/store-select";@@ -33,7 +35,28 @@ function useDone(help: ComputerHelpRef | null, onCollapse: () => void) {return { busy, done };}-export function BrowserViewerPill({ bot, you, pending, onTake, onStop, onCollapse }: {+/**+ * The person's hold on the tab the desktop app's native pane shows: while held, the bot may only read it. Taken and+ * handed back through the app, which names the tab; a hold this view took goes back when the view goes.+ */+export function usePaneHold(botId: string, threadId: string | null, enabled: boolean) {+ const [held, setHeld] = useState(false);+ const mine = useRef(false);+ const set = useCallback((want: boolean) => {+ const bridge = window.ogb?.browserPane;+ if (!enabled || !bridge?.hold) return;+ void bridge.hold({ botId, threadId, held: want }).then((answer) => { mine.current = answer.held; setHeld(answer.held); }, () => { mine.current = false; setHeld(false); });+ }, [botId, threadId, enabled]);+ useEffect(() => () => {+ if (mine.current) void window.ogb?.browserPane?.hold?.({ botId, threadId, held: false }).catch(() => undefined);+ mine.current = false;+ }, [botId, threadId]);+ return { held: enabled && held, set };+}++/** Under a full-size browser: the one pill, centred, and the control that folds it back into the chat. It sits below the+ * page rather than over it, since the desktop app's native pane draws above anything laid over the page. */+export function BrowserViewerPill({ bot, you, pending, onTake, onStop, onCollapse, onDone }: {bot: Pick<Bot, "id">;/** This person drives the browser now. */you: boolean;@@ -42,12 +65,18 @@ export function BrowserViewerPill({ bot, you, pending, onTake, onStop, onCollapsonTake: () => void;onStop: () => void;onCollapse: () => void;+ /** After I'm done answered the request, before the viewer folds. */+ onDone?: () => void;}) {const help = useWaitingHelp(bot.id, true);- const { busy, done } = useDone(help, onCollapse);+ const { busy, done } = useDone(help, () => { onDone?.(); onCollapse(); });return (- <div className="pointer-events-none absolute inset-x-0 bottom-4 z-20 flex justify-center px-4">+ <div data-viewer-pill-row="" className="relative flex shrink-0 items-center justify-center border-t border-hairline/30 px-4 py-2.5"><ViewerPill state={viewerPillState({ inControl: you, requestPending: help !== null })} busy={busy || pending} onTake={onTake} onStop={onStop} onDone={done} />+ <button type="button" onClick={onCollapse} aria-label={t("viewer.collapse")} title={t("viewer.collapse")}+ className="absolute end-4 flex size-8 items-center justify-center rounded-full text-ink-secondary hover:bg-ink/[0.07] hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus">+ <Minimize2 size={15} aria-hidden="true" />+ </button></div>);}diff --git a/src/locales/en.json b/src/locales/en.jsonindex 998b45897d..0ee639a284 100644--- a/src/locales/en.json+++ b/src/locales/en.json@@ -11476,5 +11476,6 @@"viewer.watching": "Watching","viewer.stop": "Stop","viewer.collapse": "Back to the chat",- "sidebar.preview.waitingFor": "Waiting for you: {what}"+ "sidebar.preview.waitingFor": "Waiting for you: {what}",+ "handoff.importSignIn": "Use my sign-in from my own browser"}diff --git a/src/locales/pt-br.json b/src/locales/pt-br.jsonindex 7fb8264975..08efe4d43e 100644--- a/src/locales/pt-br.json+++ b/src/locales/pt-br.json@@ -11476,5 +11476,6 @@"viewer.watching": "Assistindo","viewer.stop": "Parar","viewer.collapse": "Voltar ao chat",- "sidebar.preview.waitingFor": "Esperando você: {what}"+ "sidebar.preview.waitingFor": "Esperando você: {what}",+ "handoff.importSignIn": "Usar meu login do meu próprio navegador"}