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: let the floating browser go anywhere, and float per chat (#16859)
Michael Han2193ee82735a
diff --git a/studio/frontend/src/features/browser/browser-toggle.tsx b/studio/frontend/src/features/browser/browser-toggle.tsxindex 6d8222bfaae..30999e0d3d6 100644--- a/studio/frontend/src/features/browser/browser-toggle.tsx+++ b/studio/frontend/src/features/browser/browser-toggle.tsx@@ -44,7 +44,9 @@ export function BrowserToggleButton({floatable?: boolean;}) {const t = useT();- const open = useBrowserStore((state) => state.open);+ const panelOpen = useBrowserStore((state) => state.open);+ // The floating window leaves the header free, so the button stays there.+ const open = useBrowserStore((state) => state.open && !state.floating);const newTabShortcut = useShortcutLabel("newBrowserTab");const fullViewShortcut = useShortcutLabel("toggleBrowserFullView");const [menuOpen, setMenuOpen] = useState(false);@@ -72,7 +74,8 @@ export function BrowserToggleButton({event.preventDefault();openTab("fullView");},- { enabled: active && !(hideWhenOpen && open) },+ // The floating window's own bar takes this shortcut while it is up.+ { enabled: active && !(hideWhenOpen && panelOpen) },);const clearTimer = () => {if (timer.current !== null) window.clearTimeout(timer.current);diff --git a/studio/frontend/src/features/browser/floating-preview.ts b/studio/frontend/src/features/browser/floating-preview.tsindex 113fe7ecedd..83ff6c0c45c 100644--- a/studio/frontend/src/features/browser/floating-preview.ts+++ b/studio/frontend/src/features/browser/floating-preview.ts@@ -45,7 +45,7 @@ type Geometry = {height: number;};type Box = { left: number; top: number; width: number; height: number };-type Room = Box & { composer: Box | null };+type Room = Box & { headerGap: number };let geometry: Geometry | null = null;// The page's side-pane layout width, shown scaled down.@@ -97,37 +97,8 @@ function writeGeometry(next: Geometry): void {const clamp = (value: number, min: number, max: number) =>Math.min(max, Math.max(min, value));-const toBox = (rect: DOMRect): Box => ({- left: rect.left,- top: rect.top,- width: rect.width,- height: rect.height,-});--function overlaps(a: Box, b: Box): boolean {- return (- a.left < b.left + b.width &&- b.left < a.left + a.width &&- a.top < b.top + b.height &&- b.top < a.top + a.height- );-}--function composerIn(split: HTMLElement): Box | null {- for (const form of split.querySelectorAll?.<HTMLElement>(- "form.aui-composer-root",- ) ?? []) {- if (- form.offsetParent === null ||- form.closest('[aria-hidden="true"], [inert]')- )- continue;- const box = form.getBoundingClientRect();- if (box.width > 0 && box.height > 0) return toBox(box);- }- return null;-}-+/** The whole chat, header included: the window goes wherever it is dragged. `headerGap`: where+ * it opens, below the chat header's controls. */function roomFor(surface: HTMLElement): Room | null {const split = surface.closest<HTMLElement>(".chat-artifact-split");if (!split) return null;@@ -138,41 +109,29 @@ function roomFor(surface: HTMLElement): Room | null {?.querySelector<HTMLElement>(":scope > [data-side-panel-inset]:not(.chat-header-fade)",);- const top =- Math.max(box.top, header?.getBoundingClientRect().bottom ?? box.top) +- EDGE_GAP;+ const top = box.top + EDGE_GAP;const width = box.width - 2 * EDGE_GAP;const height = box.bottom - EDGE_GAP - top;+ const headerBottom = header?.getBoundingClientRect().bottom ?? box.top;return width > 0 && height > 0? {left: box.left + EDGE_GAP,top,width,height,- composer: composerIn(split),+ headerGap: Math.max(0, headerBottom - box.top),}: null;}-function clearOfComposer(box: Box, room: Room): Box {- const composer = room.composer;- if (!composer || !overlaps(box, composer)) return box;- const tops = [- composer.top - EDGE_GAP - box.height,- composer.top + composer.height + EDGE_GAP,- ].filter(- (top) => top >= room.top && top + box.height <= room.top + room.height,- );- if (tops.length === 0) return box;- const top = tops.reduce((best, next) =>- Math.abs(next - box.top) < Math.abs(best - box.top) ? next : best,- );- return { ...box, top };-}--function defaultGeometry(room: Box): Geometry {+function defaultGeometry(room: Room): Geometry {const width = Math.round(clamp(room.width * 0.38, 320, 480));- return { left: null, top: 0, width, height: Math.round(width * 0.68) };+ return {+ left: null,+ top: room.headerGap,+ width,+ height: Math.round(width * 0.68),+ };}function boxIn(room: Room, intent: Geometry): Box {@@ -186,15 +145,12 @@ function boxIn(room: Room, intent: Geometry): Box {Math.min(MIN_HEIGHT, room.height),room.height,);- return clearOfComposer(- {- left: room.left + placeAxis(intent.left, room.width - width),- top: room.top + clamp(intent.top, 0, room.height - height),- width,- height,- },- room,- );+ return {+ left: room.left + placeAxis(intent.left, room.width - width),+ top: room.top + clamp(intent.top, 0, room.height - height),+ width,+ height,+ };}function intentOf(room: Box, box: Box): Geometry {@@ -268,13 +224,6 @@ export function floatSurface(surface: HTMLElement): () => void {place();const observer = new ResizeObserver(place);if (split) observer.observe(split);- const observeComposer = () => {- const composer = split?.querySelector?.<HTMLElement>(- "form.aui-composer-root",- );- if (composer) observer.observe(composer);- };- observeComposer();window.addEventListener("resize", place);return () => {observer.disconnect();@@ -316,35 +265,6 @@ function resized(return { left, top, width: right - left, height: bottom - top };}-function settled(- start: Box,- previous: Box,- next: Box,- edge: FloatingEdge,- room: Room,-): Box {- if (edge === "move") return clearOfComposer(next, room);- const composer = room.composer;- if (!composer || !overlaps(next, composer) || overlaps(start, composer))- return next;- let { top, height } = next;- const bottom = top + height;- if (edge.includes("s") && start.top + start.height <= composer.top) {- height = composer.top - EDGE_GAP - top;- } else if (- edge.includes("n") &&- start.top >= composer.top + composer.height- ) {- top = composer.top + composer.height + EDGE_GAP;- height = bottom - top;- }- const stopped = { ...next, top, height };- return height >= Math.min(MIN_HEIGHT, room.height) &&- !overlaps(stopped, composer)- ? stopped- : previous;-}-const CURSORS: Record<FloatingEdge, string> = {move: "grabbing",n: "ns-resize",@@ -427,13 +347,7 @@ export function startFloatingGesture(if (Math.hypot(dx, dy) < DRAG_SLOP_PX) return;begin();}- latest = settled(- start,- latest,- resized(start, edge, dx, dy, room),- edge,- room,- );+ latest = resized(start, edge, dx, dy, room);if (!frame) frame = requestAnimationFrame(draw);};const finish = () => {@@ -466,13 +380,7 @@ export function nudgeFloating(event: ReactKeyboardEvent<HTMLElement>): void {const step = 2;const edge = event.shiftKey ? "se" : "move";const start = currentBox(room);- const next = settled(- start,- start,- resized(start, edge, delta.dx * step, delta.dy * step, room),- edge,- room,- );+ const next = resized(start, edge, delta.dx * step, delta.dy * step, room);paint(surface, next);writeGeometry(intentOf(room, next));announceMove();diff --git a/studio/frontend/src/features/browser/store.ts b/studio/frontend/src/features/browser/store.tsindex 893717a73f3..2adfb3808e0 100644--- a/studio/frontend/src/features/browser/store.ts+++ b/studio/frontend/src/features/browser/store.ts@@ -100,7 +100,7 @@ export type BrowserTab = {chat: string;};-type ChatBrowser = { open: boolean; activeTabId: string | null; fullView: boolean };+type ChatBrowser = { open: boolean; activeTabId: string | null; fullView: boolean; floating: boolean };/** The chat on screen before the chat page names it (chat-page.tsx `shownChatKey`). */export const NEW_CHAT = "new";@@ -334,7 +334,7 @@ type BrowserState = {bookmarkSequence: number;device: DeviceMode;fullView: boolean;- /** The floating window layout, for every chat and kept across closes. */+ /** The floating window layout of the chat on screen, kept across closes (others keep theirs in `chats`). */floating: boolean;/** Floated by a close mid-run (close-browser.ts): its own close restores the chosen layout. */floatedForAgent: boolean;@@ -505,7 +505,7 @@ export const useBrowserStore = create<BrowserState>((set, get) => {// Another chat's: it shows there next time, without moving this chat's panel.const saved = state.chats[chat];const activeTabId = background && saved?.activeTabId ? saved.activeTabId : owned.id;- return { tabs, chats: { ...state.chats, [chat]: { open: true, fullView: saved?.fullView ?? false, activeTabId } } };+ return { tabs, chats: { ...state.chats, [chat]: { open: true, fullView: saved?.fullView ?? false, floating: saved?.floating ?? false, activeTabId } } };}return {open: true,@@ -534,7 +534,12 @@ export const useBrowserStore = create<BrowserState>((set, get) => {if (chat === state.chat) return;const chats = { ...state.chats };if (state.tabs.some((tab) => tab.chat === state.chat)) {- chats[state.chat] = { open: state.open, activeTabId: state.activeTabId, fullView: state.fullView };+ chats[state.chat] = {+ open: state.open,+ activeTabId: state.activeTabId,+ fullView: state.fullView,+ floating: state.floating && !state.floatedForAgent,+ };} else {delete chats[state.chat];}@@ -553,6 +558,9 @@ export const useBrowserStore = create<BrowserState>((set, get) => {activeTabId: fresh?.id ?? activeTabId,open,fullView: open && (saved ? saved.fullView : state.fullView),+ // Each chat floats only once it was floated there; a chat new to the browser opens beside it.+ floating: saved?.floating ?? false,+ floatedForAgent: false,annotateTabId: null,renamingTabId: null,});@@ -576,7 +584,15 @@ export const useBrowserStore = create<BrowserState>((set, get) => {return;}set((state) => ({- chats: { ...state.chats, [chat]: { open: true, fullView: state.chats[chat]?.fullView ?? false, activeTabId: tabId } },+ chats: {+ ...state.chats,+ [chat]: {+ open: true,+ fullView: state.chats[chat]?.fullView ?? false,+ floating: state.chats[chat]?.floating ?? false,+ activeTabId: tabId,+ },+ },}));},openTabIn: (chat, url, options) => {diff --git a/studio/frontend/src/features/chat/chat-page.tsx b/studio/frontend/src/features/chat/chat-page.tsxindex 3b6be0ab124..cf940a82845 100644--- a/studio/frontend/src/features/chat/chat-page.tsx+++ b/studio/frontend/src/features/chat/chat-page.tsx@@ -620,7 +620,14 @@ function useStoredChatTitle(threadId: string | null): string | undefined {}const ARTIFACT_PANEL_DEFAULT_SIZE = "38%";-const BROWSER_PANEL_DEFAULT_SIZE = "50%";+// t3code's default docked width, never more than half the chat or under the panel's 30% minimum.+const BROWSER_PANEL_DEFAULT_PX = 540;++function browserPanelDefaultSize(split: HTMLElement | null | undefined): string {+ const width = split?.getBoundingClientRect().width ?? 0;+ if (width <= 0) return "50%";+ return `${Math.min(50, Math.max(30, (BROWSER_PANEL_DEFAULT_PX / width) * 100))}%`;+}const ARTIFACT_PANEL_TRANSITION_MS = 260;const ARTIFACT_SURFACE_POP_DELAY_MS = 150;@@ -703,7 +710,7 @@ const SingleContent = memo(function SingleContent({const defaultPanelSizeRef = useRef(ARTIFACT_PANEL_DEFAULT_SIZE);useEffect(() => {defaultPanelSizeRef.current = showBrowserPanel- ? BROWSER_PANEL_DEFAULT_SIZE+ ? browserPanelDefaultSize(contextSurfaceRef.current?.closest<HTMLElement>(".chat-artifact-split")): ARTIFACT_PANEL_DEFAULT_SIZE;});const showContextPanel = showResearchPanel || browserDocked;@@ -913,13 +920,16 @@ const SingleContent = memo(function SingleContent({id="chat-thread"defaultSize="100%"// Distinct per layout: re-registering re-sorts panels so resizing follows the chat.+ // The browser can take most of the row (it opens small); research keeps the chat wider.minSize={browserFullView? "0%": chatOnRight- ? "34%"+ ? "28%": artifactLayoutActive- ? "42%"+ ? showResearchPanel+ ? "42%"+ : "30%": "100%"}className="h-full min-h-0 min-w-0 overflow-hidden"@@ -992,11 +1002,11 @@ const SingleContent = memo(function SingleContent({}maxSize={chatOnRight- ? "66%"+ ? "72%": showResearchPanel? "58%": artifactLayoutActive- ? "58%"+ ? "70%": "0%"}collapsible={showBrowserPanel}diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.cssindex f4439691831..c7bc02f5171 100644--- a/studio/frontend/src/index.css+++ b/studio/frontend/src/index.css@@ -5684,7 +5684,8 @@ html[data-find-bar-open] [data-sonner-toaster][data-y-position="top"] {/* Placed by floating-preview.ts. No transition: a drag's transform must drop without easing back. */.chat-artifact-pop-surface.chat-browser-floating {- z-index: 35;+ /* In front of everything in the chat, its header (z-40) included. */+ z-index: 45;opacity: 1;pointer-events: auto;will-change: auto;diff --git a/studio/frontend/tests/artifact-panel-reopen.test.ts b/studio/frontend/tests/artifact-panel-reopen.test.tsindex c6674b1bbbd..eb837d78ad4 100644--- a/studio/frontend/tests/artifact-panel-reopen.test.ts+++ b/studio/frontend/tests/artifact-panel-reopen.test.ts@@ -101,7 +101,7 @@ test("a project hosts the browser like a chat, so Browser use and the header togconst 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\) \}/);+ assert.match(toggle, /\{ enabled: active && !\(hideWhenOpen && panelOpen\) \}/);});test("a project's modal overlay closes before Request edits or Attach hand off to its composer", () => {diff --git a/studio/frontend/tests/browser-floating-layout.test.ts b/studio/frontend/tests/browser-floating-layout.test.tsindex 5e4872d9b3c..31bdb5c95b2 100644--- a/studio/frontend/tests/browser-floating-layout.test.ts+++ b/studio/frontend/tests/browser-floating-layout.test.ts@@ -58,3 +58,15 @@ test("only a page shown natively skips the floating window's scale; files and neassert.match(panel, /const nativeShown = native && activeEntry\?\.kind === "web" && !activeTab\?\.nativeError;/);assert.match(panel, /floating && !nativeShown\s*\?\s*FLOATING_PAGE_STYLE/);});++test("floating is the chat's own: another chat opens its browser beside it, and the first floats again on return", () => {+ const store = () => useBrowserStore.getState();+ store().showChat("single:float-a");+ store().openUrl("https://example.com/a");+ store().setFloating(true);+ store().showChat("single:float-b");+ store().openUrl("https://example.com/b");+ assert.equal(store().floating, false);+ store().showChat("single:float-a");+ assert.deepEqual([store().open, store().floating], [true, true]);+});diff --git a/studio/frontend/tests/browser-floating-preview.test.ts b/studio/frontend/tests/browser-floating-preview.test.tsindex 76559bff53c..3aae723dc97 100644--- a/studio/frontend/tests/browser-floating-preview.test.ts+++ b/studio/frontend/tests/browser-floating-preview.test.ts@@ -157,21 +157,19 @@ test("a resize from a corner keeps the opposite corner put and never goes underrelease();});-test("the preview steps over the composer rather than covering it, and a resize stops at it", () => {+test("the window goes wherever it is dragged: over the composer and up over the chat header", () => {composer = rect(500, 760, 600, 120);dockedWidth = 0;const release = floatSurface(surface as never);- const [left, , width, height] = placed();- drag("move", [left + 10, placed()[1] + 10], [800, 780]);- assert.equal(placed()[1] + height, 760 - 12);- assert.equal(placed()[2], width);- const above = placed();- drag("s", [above[0] + 10, above[1] + above[3]], [above[0] + 10, above[1] + above[3] + 200]);- assert.deepEqual(placed(), above);- drag("sw", [above[0], above[1] + above[3]], [above[0] - 100, above[1] + above[3] + 200]);- const grown = placed();- assert.equal(grown[0], above[0] - 100);- assert.equal(grown[1] + grown[3], 760 - 12);+ const [left, top, width, height] = placed();+ drag("move", [left + 10, top + 10], [800, 790]);+ // Dropped onto the composer, it stays there, down at the chat's bottom edge.+ assert.equal(placed()[1] + placed()[3], 900 - 12);+ drag("move", [800, placed()[1]], [800, -500]);+ // Up to the chat's own edge, over its 48px header.+ assert.equal(placed()[1], 12);+ drag("s", [placed()[0] + 10, 12 + height], [placed()[0] + 10, 2000]);+ assert.deepEqual([placed()[1], placed()[1] + placed()[3], placed()[2]], [12, 900 - 12, width]);release();composer = null;});