Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: show the browser in Project chats (#15089)
Sourav Rajvieb21b704fcc1
diff --git a/studio/frontend/src/features/browser/agent/executor.ts b/studio/frontend/src/features/browser/agent/executor.tsindex b8b38ee4d9d..af6a28242fb 100644--- a/studio/frontend/src/features/browser/agent/executor.ts+++ b/studio/frontend/src/features/browser/agent/executor.ts@@ -566,8 +566,9 @@ async function askInPanel(question: Question, context: Run, remember = true): Prconst tabId = agentChat(context.session.chat).tabId;const store = useBrowserStore.getState();if (tabId) store.revealIn(context.session.chat, tabId);- else if (chatOnScreen(context) && !store.open) store.openPanel();- if (!chatOnScreen(context)) notifyOffScreenQuestion(context.session.chat);+ // Even when already open: a project's overlay or Research can be hiding it, and only a new open shows it.+ if (chatOnScreen(context)) store.openPanel();+ else notifyOffScreenQuestion(context.session.chat);const answer = await askUser(context.session.chat, question, context.signal, keep);if (answer === "always" && keep) granted.add(key);return answer;diff --git a/studio/frontend/src/features/browser/browser-toggle.tsx b/studio/frontend/src/features/browser/browser-toggle.tsxindex 628230d09b2..fe8a2e457bc 100644--- a/studio/frontend/src/features/browser/browser-toggle.tsx+++ b/studio/frontend/src/features/browser/browser-toggle.tsx@@ -26,8 +26,15 @@ function openNewTab(fullView = false) {if (fullView) state.setFullView(true);}-/** The chat header's new tab button: a click opens a tab beside the chat, hovering offers full view. Hidden while the panel is open; its shortcuts still work. */-export function BrowserToggleButton({ active = true }: { active?: boolean }) {+/** The chat header's new tab button: a click opens a tab beside the chat, hovering offers full view.+ * Hidden while the panel is open, unless `hideWhenOpen` is false: a project's overlay may not be showing it. */+export function BrowserToggleButton({+ active = true,+ hideWhenOpen = true,+}: {+ active?: boolean;+ hideWhenOpen?: boolean;+}) {const t = useT();const open = useBrowserStore((state) => state.open);const newTabShortcut = useShortcutLabel("newBrowserTab");@@ -58,7 +65,7 @@ export function BrowserToggleButton({ active = true }: { active?: boolean }) {event.preventDefault();openTab(true);},- { enabled: active && !open },+ { enabled: active && !(hideWhenOpen && open) },);const clearTimer = () => {if (timer.current !== null) window.clearTimeout(timer.current);@@ -85,7 +92,7 @@ export function BrowserToggleButton({ active = true }: { active?: boolean }) {timer.current = null;setMenuOpen(false);}, [open]);- if (open) return null;+ if (hideWhenOpen && open) return null;const label = t("browser.newTab");const onMouse = (handler: () => void) => (event: { pointerType: string }) => {if (event.pointerType === "mouse") handler();diff --git a/studio/frontend/src/features/chat/chat-page.tsx b/studio/frontend/src/features/chat/chat-page.tsxindex ce484201259..89b36e1d402 100644--- a/studio/frontend/src/features/chat/chat-page.tsx+++ b/studio/frontend/src/features/chat/chat-page.tsx@@ -375,6 +375,47 @@ function useStagedFixPrompt(pendingFixPrompt: string | null, active: boolean): v}, [pendingFixPrompt, aui, active]);}+/** Hosts the browser for this chat. Project landing never mounts SingleContent, so it calls this itself (#15046).+ * `overlay`: the browser covers the chat as a modal, so handing work to the composer closes it first. */+function useBrowserChatHost(active: boolean, overlay = false): void {+ const isMobile = useIsMobile();+ const aui = useAui();+ useEffect(() => {+ if (!active || isMobile) return;+ setBrowserPanelAvailable(true);+ setInAppLinkHandler(openUrlInBrowser);+ const focusComposer = () => document.querySelector<HTMLTextAreaElement>(COMPOSER_INPUT_SELECTOR)?.focus();+ useBrowserStore.setState({+ requestEdits: (prompt) => {+ useChatArtifactsStore.getState().stageFixPrompt(prompt);+ if (overlay) useBrowserStore.getState().closePanel();+ },+ // Marks are sent with a reply the overlay would hide, so it stages a prompt like compare does.+ sendAnnotations: overlay ? null : (annotations, files) => sendDocumentAnnotations(aui, annotations, files),+ attachToChat: (file) =>+ aui+ .composer()+ .addAttachment(file)+ .then(() => {+ if (overlay) {+ useBrowserStore.getState().closePanel();+ // After the closing overlay hands focus back to its opener.+ window.setTimeout(focusComposer, 0);+ } else {+ focusComposer();+ }+ return true;+ })+ .catch(() => false),+ });+ return () => {+ setBrowserPanelAvailable(false);+ setInAppLinkHandler(null);+ useBrowserStore.setState({ requestEdits: null, sendAnnotations: null, attachToChat: null });+ };+ }, [active, overlay, isMobile, aui]);+}+// Compare keeps the base view mounted but hidden; the overlay owns the browser then, so it runs once.const BrowserOverlaidContext = createContext(false);@@ -581,7 +622,6 @@ const SingleContent = memo(function SingleContent({const activeThreadId = useChatRuntimeStore((state) => state.activeThreadId);const isMobile = useIsMobile();const chatActive = useChatActive();- const aui = useAui();// Compare keeps this view mounted but hidden, so the backgrounded copy leaves the prompt to SharedComposer.const pendingFixPrompt = useChatArtifactsStore((state) => state.pendingFixPrompt,@@ -589,29 +629,7 @@ const SingleContent = memo(function SingleContent({const browserOpen = useBrowserStore((state) => state.open);const browserOpenSequence = useBrowserStore((state) => state.openSequence);const closeBrowser = useBrowserStore((state) => state.closePanel);- useEffect(() => {- if (!chatActive || isMobile) return;- setBrowserPanelAvailable(true);- setInAppLinkHandler(openUrlInBrowser);- useBrowserStore.setState({- requestEdits: (prompt) => useChatArtifactsStore.getState().stageFixPrompt(prompt),- sendAnnotations: (annotations, files) => sendDocumentAnnotations(aui, annotations, files),- attachToChat: (file) =>- aui- .composer()- .addAttachment(file)- .then(() => {- document.querySelector<HTMLTextAreaElement>(COMPOSER_INPUT_SELECTOR)?.focus();- return true;- })- .catch(() => false),- });- return () => {- setBrowserPanelAvailable(false);- setInAppLinkHandler(null);- useBrowserStore.setState({ requestEdits: null, sendAnnotations: null, attachToChat: null });- };- }, [chatActive, isMobile, aui]);+ useBrowserChatHost(chatActive);useStagedFixPrompt(pendingFixPrompt, chatActive);const openResearchRunId = useResearchRunStore((state) => state.openRunId);const closeResearchPanel = useResearchRunStore((state) => state.closePanel);@@ -1868,6 +1886,7 @@ function ProjectLanding({// Gates body-portaled surfaces so they cannot linger or act while the landing is off-route.const active = useChatActive();// The browser shows over a project, so its Request edits lands in this composer.+ useBrowserChatHost(active, true);useStagedFixPrompt(useChatArtifactsStore((state) => state.pendingFixPrompt),active,@@ -4923,7 +4942,12 @@ export function ChatPage({{view.mode === "single" && (<ChatHeaderMenu temporary={incognito} onToggleTemporary={toggleIncognito} />)}- {view.mode === "single" && !isMobile ? <BrowserToggleButton active={active} /> : null}+ {(view.mode === "single" || view.mode === "project") && !isMobile ? (+ <BrowserToggleButton+ active={active}+ hideWhenOpen={view.mode === "single" || showBrowserOverlay}+ />+ ) : null}{view.mode === "single" &&latestResearchRunId &&latestResearchRunStatus ? (diff --git a/studio/frontend/tests/artifact-panel-reopen.test.ts b/studio/frontend/tests/artifact-panel-reopen.test.tsindex 6671c16b11e..54eaef467c4 100644--- a/studio/frontend/tests/artifact-panel-reopen.test.ts+++ b/studio/frontend/tests/artifact-panel-reopen.test.ts@@ -87,6 +87,37 @@ test("a project has no side pane, so a browser opened from it shows over it, notassert.match(page, /\(view\.mode === "project" &&\s*projectBrowserBaseline !== null &&\s*browserOpenSequence > projectBrowserBaseline\)/);});+test("a project hosts the browser like a chat, so Browser use and the header toggle work (#15046)", () => {+ const page = read("../src/features/chat/chat-page.tsx");+ const landing = page.slice(page.indexOf("function ProjectLanding"));+ assert.match(page, /function useBrowserChatHost\(active: boolean, overlay = false\): void \{/);+ assert.match(page, /Project landing never mounts SingleContent/);+ assert.match(landing, /useBrowserChatHost\(active, true\);/);+ assert.match(page, /useBrowserChatHost\(chatActive\);/);+ assert.match(+ page,+ /\(view\.mode === "single" \|\| view\.mode === "project"\) && !isMobile \? \(\s*<BrowserToggleButton\s*active=\{active\}\s*hideWhenOpen=\{view\.mode === "single" \|\| showBrowserOverlay\}/,+ );+ const toggle = read("../src/features/browser/browser-toggle.tsx");+ assert.match(toggle, /hideWhenOpen = true,/);+ assert.match(toggle, /if \(hideWhenOpen && open\) return null;/);+ assert.match(toggle, /\{ enabled: active && !\(hideWhenOpen && open\) \}/);+});++test("a project's modal overlay closes before Request edits or Attach hand off to its composer", () => {+ const page = read("../src/features/chat/chat-page.tsx");+ const host = page.slice(page.indexOf("function useBrowserChatHost"), page.indexOf("// Compare keeps the base view"));+ assert.match(host, /stageFixPrompt\(prompt\);\s*if \(overlay\) useBrowserStore\.getState\(\)\.closePanel\(\);/);+ assert.match(host, /sendAnnotations: overlay \? null : /);+ assert.match(host, /if \(overlay\) \{\s*useBrowserStore\.getState\(\)\.closePanel\(\);[^}]*window\.setTimeout\(focusComposer, 0\);/);+ assert.match(host, /\[active, overlay, isMobile, aui\]/);+});++test("a browser-use question re-opens the panel even when it is already open, so a project overlay shows it", () => {+ const executor = read("../src/features/browser/agent/executor.ts");+ assert.match(executor, /if \(tabId\) store\.revealIn\(context\.session\.chat, tabId\);\s*(\/\/[^\n]*\n\s*)?if \(chatOnScreen\(context\)\) store\.openPanel\(\);/);+});+test("opening the browser closes Research, which would otherwise hide it in the side pane", () => {const page = read("../src/features/chat/chat-page.tsx");assert.match(page, /if \(handledBrowserOpenRef\.current === browserOpenSequence\) return;/);@@ -105,6 +136,7 @@ test("Request edits stays in overlays, staging the prompt for the visible compostest("a project's browser overlay stages Request edits in the project composer", () => {const page = read("../src/features/chat/chat-page.tsx");const landing = page.slice(page.indexOf("function ProjectLanding"));+ assert.match(landing, /useBrowserChatHost\(active, true\);/);assert.match(landing, /useStagedFixPrompt\(\s*useChatArtifactsStore\(\(state\) => state\.pendingFixPrompt\),\s*active,\s*\);/);assert.match(page, /useStagedFixPrompt\(pendingFixPrompt, chatActive\);/);});