Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
Browser pane: typed text stays with its own tab; Enter shows the full address (29f) (#826)
Oleksandr Ivanchenkode1918aa0cbc
diff --git a/frontend/src/components/VirtualMachinePane.tsx b/frontend/src/components/VirtualMachinePane.tsxindex 06e1671e..e2929c99 100644--- a/frontend/src/components/VirtualMachinePane.tsx+++ b/frontend/src/components/VirtualMachinePane.tsx@@ -191,8 +191,19 @@ export const VirtualMachinePane: React.FC<VirtualMachinePaneProps> = ({const [activeTab, setActiveTab] = useState<PaneTab>(() => chosenPaneTab(teamId));useEffect(() => rememberPaneTab(teamId, activeTab), [teamId, activeTab]);// 28r: what was last written into the address field, and for which tab (see `fieldKey` below)- // 28x: `typed` marks the person's own text, which only a real change of address may replace- const [written, setWritten] = useState<{ key: string; url: string; typed?: boolean } | null>(null);+ const [written, setWritten] = useState<{ key: string; url: string } | null>(null);+ // 29f: what the person typed, per tab (same keys), apart from what a stream wrote, so another tab's stream+ // never reaches it (Rigel's Q4). Only a new url (or page) from that tab's own stream replaces it (28x/28y).+ const [typed, setTyped] = useState<Record<string, string>>({});+ const dropTyped = useCallback((key: string) => setTyped((t) => {+ if (!(key in t)) return t;+ const rest = { ...t };+ delete rest[key];+ return rest;+ }), []);+ // 29f: the url each tab's own stream last reported since the pane opened. A tab you come back to reports+ // its address again on a new socket; the same url is not a change, so what you typed there stays.+ const heard = useRef(new Map<string, string>());// No event fires when the browser catches a login, so a new screenshot or page loads the list again.const passwords = useSavedPasswords(teamId, `${activeUrl}|${screenshotBase64?.length ?? 0}|${screenshotBase64?.slice(-32) ?? ''}`);const savedCount = passwords.logins.length;@@ -319,20 +330,49 @@ export const VirtualMachinePane: React.FC<VirtualMachinePaneProps> = ({const [fieldSeen, setFieldSeen] = useState(fieldKey);if (fieldSeen !== fieldKey) {setFieldSeen(fieldKey);- if (written && !written.typed && written.key === fieldSeen) setWritten(null);+ if (written && written.key === fieldSeen) setWritten(null);}- const inputUrl = written?.key === fieldKey+ const inputUrl = typed[fieldKey] ?? (written?.key === fieldKey? written.url- : chosenPage ? (isBlankPage(pageInfo?.url) ? '' : pageInfo?.url ?? '') : pagesKnown ? activeUrl : '';- const setInputUrl = (url: string) => setWritten({ key: fieldKey, url, typed: true });+ : chosenPage ? (isBlankPage(pageInfo?.url) ? '' : pageInfo?.url ?? '') : pagesKnown ? activeUrl : '');+ const setInputUrl = (url: string) => setTyped((t) => ({ ...t, [fieldKey]: url }));// Then the stream takes over, but only the chosen page's own: a late message from the page just left// never writes its address. A blank tab's own about:blank keeps the field empty (28u), as its chip says// "nothing open"; pageUrl keeps the raw value for the blank check and the picture. 28y: only a new url or page// writes it; a title that changes on its own ("(3) Inbox") never reaches the field or what the person typed.useEffect(() => {- if (stream.location?.url && stream.location.page === chosenPage) setWritten({ key: fieldKey, url: isBlankPage(stream.location.url) ? '' : stream.location.url });+ const url = stream.location?.url;+ if (!url || stream.location?.page !== chosenPage) return;+ setWritten({ key: fieldKey, url: isBlankPage(url) ? '' : url });+ if (heard.current.get(fieldKey) !== url) dropTyped(fieldKey);+ heard.current.set(fieldKey, url);// eslint-disable-next-line react-hooks/exhaustive-deps}, [stream.location?.url, stream.location?.page]);+ // 29f: a closed pane starts over (a reopened stream writes the address, as 28x/28y decided); a closed page's+ // typed text goes with it, and another team's pane remembers nothing of this one.+ useEffect(() => {+ if (!isOpen) heard.current.clear();+ }, [isOpen]);+ useEffect(() => {+ if (!pageKeys) return;+ const open = new Set(pageKeys.map((p) => `page:${p}`));+ for (const key of [...heard.current.keys()]) if (key.startsWith('page:') && !open.has(key)) heard.current.delete(key);+ setTyped((t) => {+ const gone = Object.keys(t).filter((key) => key.startsWith('page:') && !open.has(key));+ if (!gone.length) return t;+ const rest = { ...t };+ for (const key of gone) delete rest[key];+ return rest;+ });+ }, [pageKeys]);+ const typedTeam = useRef(teamId);+ useEffect(() => {+ if (typedTeam.current === teamId) return;+ typedTeam.current = teamId;+ heard.current.clear();+ setTyped({});+ setWritten(null);+ }, [teamId]);// The pane's own stream knows each page's title too, so the trail can name pages the bot openeduseEffect(() => {noteTitle(stream.location?.url, stream.location?.title);@@ -341,7 +381,10 @@ export const VirtualMachinePane: React.FC<VirtualMachinePaneProps> = ({// The app's last known address is any bot's, not the selected tab's: it writes the field only when no// page is chosen (an older server with no pages route)useEffect(() => {- if (!chosenPage && pagesKnown) setWritten({ key: fieldKey, url: activeUrl });+ if (!chosenPage && pagesKnown) {+ setWritten({ key: fieldKey, url: activeUrl });+ dropTyped(fieldKey);+ }// eslint-disable-next-line react-hooks/exhaustive-deps}, [activeUrl]);@@ -791,6 +834,10 @@ export const VirtualMachinePane: React.FC<VirtualMachinePaneProps> = ({}if (isControlMode) stream.send({ action: 'navigate', url: target }, true);else onNavigate(target, chosenPage);+ // 29f (Rigel's Q2): the field goes back to the page and shows the full address it was sent to,+ // even when the page was already there and no new url comes+ setWritten({ key: fieldKey, url: target });+ dropTyped(fieldKey);}}}placeholder="https://..."diff --git a/frontend/tests/typedAddressStays.test.mjs b/frontend/tests/typedAddressStays.test.mjsindex 91b96f14..215494de 100644--- a/frontend/tests/typedAddressStays.test.mjs+++ b/frontend/tests/typedAddressStays.test.mjs@@ -5,6 +5,8 @@// stream-written address until its own stream spoke again.// 28y title-change-keeps-typing (Mira, typed-address-stays/design-check.md:19; Rigel's Q1): a page whose title// changes on its own no longer wipes what the person types; only a new url or page writes the field.+// 29f typed-text-own-tab (Rigel's Q4 and R6; his Q2): typed text belongs to its tab, so another tab's stream never+// wipes it; Enter hands the field back to the page and shows the full address it was sent to.import assert from 'node:assert/strict';import test from 'node:test';import { JSDOM } from 'jsdom';@@ -216,3 +218,96 @@ test('text the person typed is kept when they leave the tab and come back', asynassert.equal(field(m.host).value, 'booktun.ing', 'the typed text is still there on return');} finally { m.done(); }});++test("29f Q4: typed on Ben, Ann's own stream reports, back on Ben: the typed text is still there", async () => {+ const k = threeTabs('x6');+ answer = k.LIST;+ const m = mount({ teamId: 'x6', browsingBot: 'Ben', botNames: NAMES, activeUrl: OTHER, onNavigate: () => {} });+ try {+ await settle();+ assert.equal(currentTab(m.host), 'x6#ben#c1');+ await tick(sockets.at(-1), 'https://shop.example.com/trail/cart', 'Cart');+ setVal(field(m.host), 'booktun.ing');+ click(m.host, 'x6#ann#c2');+ await settle();+ await tick(sockets.at(-1), 'https://news.example.com/today', 'News today');+ assert.equal(field(m.host).value, 'https://news.example.com/today', "Ann's own address under her tab");+ click(m.host, 'x6#ben#c1');+ assert.equal(field(m.host).value, 'booktun.ing', 'the tap render shows what was typed on Ben');+ await settle();+ // Ben's new socket reports where Ben still is: the same url is no change, the typed text stays+ await tick(sockets.at(-1), 'https://shop.example.com/trail/cart', 'Cart');+ assert.equal(field(m.host).value, 'booktun.ing', "Ben's own same-url report keeps it");+ await tick(sockets.at(-1), 'https://shop.example.com/trail/cart', 'Cart');+ assert.equal(field(m.host).value, 'booktun.ing', 'and so does the 2 s tick');+ // A new url from Ben's own stream still replaces it+ await tick(sockets.at(-1), 'https://shop.example.com/trail/checkout', 'Checkout');+ assert.equal(field(m.host).value, 'https://shop.example.com/trail/checkout');+ } finally { m.done(); }+});++test("29f: Ben's page moved while the person was on Ann: back on Ben, his new url replaces the typed text", async () => {+ const k = threeTabs('x7');+ answer = k.LIST;+ const m = mount({ teamId: 'x7', browsingBot: 'Ben', botNames: NAMES, activeUrl: OTHER, onNavigate: () => {} });+ try {+ await settle();+ await tick(sockets.at(-1), 'https://shop.example.com/trail/cart', 'Cart');+ setVal(field(m.host), 'booktun.ing');+ click(m.host, 'x7#ann#c2');+ await settle();+ await tick(sockets.at(-1), 'https://news.example.com/', 'News');+ click(m.host, 'x7#ben#c1');+ await settle();+ await tick(sockets.at(-1), 'https://shop.example.com/trail/paid', 'Paid');+ assert.equal(field(m.host).value, 'https://shop.example.com/trail/paid', 'a new url from his own stream wins');+ } finally { m.done(); }+});++test("29f: a closed page forgets what was typed on it", async () => {+ const k = threeTabs('x8');+ answer = k.LIST;+ const m = mount({ teamId: 'x8', browsingBot: 'Ben', botNames: NAMES, activeUrl: OTHER, onNavigate: () => {} });+ try {+ await settle();+ click(m.host, 'x8#ann#c2');+ await settle();+ setVal(field(m.host), 'booktun.ing');+ click(m.host, 'x8#ben#c1');+ await settle();+ // Ann's page closes, then a page with the same key opens again: it starts from its own address+ answer = { ...k.LIST, pages: [k.SHARED, k.BEN] };+ pane.notifyBrowserPages('x8');+ await settle(400);+ answer = k.LIST;+ pane.notifyBrowserPages('x8');+ await settle(400);+ click(m.host, 'x8#ann#c2');+ assert.equal(field(m.host).value, 'https://news.example.com/', 'no typed text left from the closed page');+ } finally { m.done(); }+});++test("29f Q2: Enter on the page's own address without https shows the full address, and the tick keeps it", async () => {+ const k = threeTabs('x9');+ answer = k.LIST;+ const went = [];+ const m = mount({ teamId: 'x9', browsingBot: 'Ben', botNames: NAMES, activeUrl: OTHER, onNavigate: (url, page) => went.push([url, page]) });+ try {+ await settle();+ const ben = sockets.at(-1);+ await tick(ben, 'https://shop.example.com/trail/ridgeline-2p', 'Ridgeline 2P Tent');+ setVal(field(m.host), 'shop.example.com/trail/ridgeline-2p');+ pane.flushSync(() => field(m.host).dispatchEvent(new window.KeyboardEvent('keydown', { key: 'Enter', bubbles: true })));+ assert.deepEqual(went, [['https://shop.example.com/trail/ridgeline-2p', 'x9#ben#c1']]);+ assert.equal(field(m.host).value, 'https://shop.example.com/trail/ridgeline-2p', 'the full address right after Enter');+ // The page was already there: the 2 s tick brings the same url, and the field stays in step+ await tick(ben, 'https://shop.example.com/trail/ridgeline-2p', 'Ridgeline 2P Tent');+ assert.equal(field(m.host).value, 'https://shop.example.com/trail/ridgeline-2p');+ // Enter to a new place: the page's own report of where it landed shows+ setVal(field(m.host), 'shop.example.com/trail');+ pane.flushSync(() => field(m.host).dispatchEvent(new window.KeyboardEvent('keydown', { key: 'Enter', bubbles: true })));+ assert.equal(field(m.host).value, 'https://shop.example.com/trail');+ await tick(ben, 'https://shop.example.com/trail/', 'Trail');+ assert.equal(field(m.host).value, 'https://shop.example.com/trail/');+ } finally { m.done(); }+});