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: keep the loaded models card in the corner it is supposed to be in (#8301)
Daniel Hanb9c733a6cb40
diff --git a/studio/frontend/src/app/provider.tsx b/studio/frontend/src/app/provider.tsxindex c8c5ddfea88..037f67bcdca 100644--- a/studio/frontend/src/app/provider.tsx+++ b/studio/frontend/src/app/provider.tsx@@ -397,6 +397,7 @@ function TauriUpdateLayer({) : (// Capped like the browser stack: the download panel shares it, so both must fit.<div+ ref={stack.ref}className="pointer-events-none fixed right-4 z-[9998] flex flex-col items-end gap-2"style={{ bottom: stack.bottom, maxHeight: stack.maxHeight }}>@@ -679,6 +680,7 @@ function TauriWrapper({ children }: { children: ReactNode }) {{/* Capped to the viewport, or a long download list plus expanded notespushes the top of the stack off screen. */}<div+ ref={stack.ref}className="pointer-events-none fixed right-4 z-[9998] flex flex-col items-end gap-2"style={{ bottom: stack.bottom, maxHeight: stack.maxHeight }}>diff --git a/studio/frontend/src/features/settings/stores/monitor-frame-store.ts b/studio/frontend/src/features/settings/stores/monitor-frame-store.tsindex 0024bda08cc..efa8c8901ca 100644--- a/studio/frontend/src/features/settings/stores/monitor-frame-store.ts+++ b/studio/frontend/src/features/settings/stores/monitor-frame-store.ts@@ -6,7 +6,7 @@// same corner; the chat composer docks to the bottom of the same column once a// thread has turns. Each publishes its box here while it is mounted.-import { useEffect, useMemo, useState } from "react";+import { useCallback, useEffect, useMemo, useState } from "react";import { create } from "zustand";export type MonitorFrame = {@@ -71,6 +71,10 @@ const STACK_GAP = 8;const STACK_WIDTH = 448;// Never lift so far that the stack itself is pushed off the top.const MIN_STACK_ROOM = 120;+// Room the stack asks for before it has been measured. Deliberately small: guessing+// high is what parked the loaded models card mid-window with the corner underneath it+// empty. The real height arrives from the stack's ResizeObserver on the next frame.+const ASSUMED_STACK_HEIGHT = 56;// The monitor's own controls, measured from its top edge: 12px of panel// padding, a 24px control row (the drag handle and the size-6 Close button),// an 8px rule and an 8px margin come to 54. Rounded up so a font or a border@@ -104,10 +108,11 @@ function inStackColumn(frame: MonitorFrame, viewportWidth: number): boolean {* lifting over it there is what put the banners in the middle of the page with* the corner underneath them empty.*- * Derived from the cap rather than guessed, so the two cannot disagree: the- * space below the box is what stackMaxHeight allows. Read as a bare "is it near- * the bottom" instead, boxes ending just above the cutoff were left in the- * capped branch with a cap that did not fit under them.+ * Measured against what the stack actually is, not a fixed guess. In a short+ * window the welcome composer left 83px under it and the 80px card fits, but the+ * old constant said 120, so the stack lifted over the composer and left the very+ * corner it was dodging empty. `neededRoom` comes from the stack's own+ * ResizeObserver (see useStackGeometry), so a taller stack still gets dodged.** Asked against the inset in force, never a fixed one: lifting over one box* moves the stack up into the next, and a box that had room at the corner may@@ -117,8 +122,11 @@ function reachesStack(frame: MonitorFrame,viewportHeight: number,bottomInset: number,+ neededRoom: number,): boolean {- return roomBelow(frame, viewportHeight, bottomInset) < MIN_STACK_ROOM;+ // At least a pixel: a needed room of 0 lets the capped branch hand back a+ // max-height of 0, which browsers honour, leaving the stack invisible.+ return roomBelow(frame, viewportHeight, bottomInset) < Math.max(1, neededRoom);}/** The inset that clears this box's top edge, whether or not it fits there. */@@ -169,6 +177,7 @@ export function stackBottomInset(frame: MonitorFrame | null,viewportWidth: number,viewportHeight: number,+ neededRoom: number = ASSUMED_STACK_HEIGHT,): number {if (!frame) return STACK_INSET;// Only dodge a box that is in the stack's column and crowds its corner; one@@ -176,7 +185,7 @@ export function stackBottomInset(// corner free.const inTheWay =inStackColumn(frame, viewportWidth) &&- reachesStack(frame, viewportHeight, STACK_INSET);+ reachesStack(frame, viewportHeight, STACK_INSET, neededRoom);return inTheWay ? dodgeInset(frame, viewportHeight) : STACK_INSET;}@@ -200,10 +209,11 @@ export function stackMaxHeight(viewportWidth: number,viewportHeight: number,bottomInset: number,+ neededRoom: number = ASSUMED_STACK_HEIGHT,): number {const ownMargin = viewportHeight - bottomInset - STACK_INSET;if (!frame || !inStackColumn(frame, viewportWidth)) return ownMargin;- if (reachesStack(frame, viewportHeight, bottomInset)) {+ if (reachesStack(frame, viewportHeight, bottomInset, neededRoom)) {// Lifted over: bottomInset already cleared it.if (liftFits(frame, viewportHeight)) return ownMargin;// Seated inside it instead. Stop below its header, or the Close button goes@@ -234,13 +244,25 @@ export function stackGeometry(frames: MonitorFrame | null | readonly MonitorFrame[],viewportWidth: number,viewportHeight: number,+ neededRoom: number = ASSUMED_STACK_HEIGHT,): StackGeometry {const list = frames === null ? [] : Array.isArray(frames) ? frames : [frames];if (list.length === 0) {- const bottom = stackBottomInset(null, viewportWidth, viewportHeight);+ const bottom = stackBottomInset(+ null,+ viewportWidth,+ viewportHeight,+ neededRoom,+ );return {bottom,- maxHeight: stackMaxHeight(null, viewportWidth, viewportHeight, bottom),+ maxHeight: stackMaxHeight(+ null,+ viewportWidth,+ viewportHeight,+ bottom,+ neededRoom,+ ),};}// Settled, not summed. Lifting over one box moves the stack up into the next,@@ -251,7 +273,7 @@ export function stackGeometry(for (let pass = 0; pass <= column.length; pass += 1) {let next = bottom;for (const frame of column) {- if (reachesStack(frame, viewportHeight, bottom)) {+ if (reachesStack(frame, viewportHeight, bottom, neededRoom)) {next = Math.max(next, dodgeInset(frame, viewportHeight));}}@@ -262,14 +284,29 @@ export function stackGeometry(bottom,maxHeight: Math.min(...list.map((f) =>- stackMaxHeight(f, viewportWidth, viewportHeight, bottom),+ stackMaxHeight(f, viewportWidth, viewportHeight, bottom, neededRoom),),),};}-/** `stackGeometry` in px, recomputed as the monitor moves or resizes. */-export function useStackGeometry(): StackGeometry {+export type StackPlacement = StackGeometry & {+ /** Attach to the stack container so its height feeds back into the placement. */+ ref: (node: HTMLElement | null) => void;+};++/**+ * `stackGeometry` in px, recomputed as the monitor moves or resizes, and as the+ * stack's own content grows.+ *+ * The measurement has to be taken with this hook's own `maxHeight` off. The+ * overlays are `min-h-0` flex items with inner scrollers, so under the cap they+ * shrink to it and `scrollHeight` reports the cap, not the content: 83px of+ * content reads back as 40 under a 40px cap. Fed back in that is the placement+ * reading its own output, so a stack taller than the gap under an obstacle would+ * measure as exactly the gap, never ask to be lifted, and sit there clipped.+ */+export function useStackGeometry(): StackPlacement {const frames = useMonitorFrameStore((state) => state.frames);// Every published box, not their union: see stackGeometry.const published = useMemo(() => [...frames.values()], [frames]);@@ -277,6 +314,7 @@ export function useStackGeometry(): StackGeometry {width: typeof window === "undefined" ? 0 : window.innerWidth,height: typeof window === "undefined" ? 0 : window.innerHeight,}));+ const [neededRoom, setNeededRoom] = useState(ASSUMED_STACK_HEIGHT);useEffect(() => {const onResize = () =>setViewport({ width: window.innerWidth, height: window.innerHeight });@@ -284,5 +322,36 @@ export function useStackGeometry(): StackGeometry {window.addEventListener("resize", onResize);return () => window.removeEventListener("resize", onResize);}, []);- return stackGeometry(published, viewport.width, viewport.height);+ const ref = useCallback((node: HTMLElement | null) => {+ if (node === null || typeof ResizeObserver === "undefined") return;+ const measure = () => {+ // An empty stack asks for nothing, so nothing is dodged for it.+ if (node.childElementCount === 0) {+ setNeededRoom((current) => (current === 0 ? current : 0));+ return;+ }+ // Drop the cap and put it back in one synchronous block, so scrollHeight+ // sees the unconstrained layout but nothing else ever sees the uncapped+ // box. Through style, not state: React rewrites the same value next render.+ const capped = node.style.maxHeight;+ node.style.maxHeight = "none";+ const natural = node.scrollHeight;+ node.style.maxHeight = capped;+ setNeededRoom((current) => (current === natural ? current : natural));+ };+ measure();+ const observer = new ResizeObserver(measure);+ observer.observe(node);+ // A 0-height stack stays 0 as children come and go, so watch the child list too.+ const mutations = new MutationObserver(measure);+ mutations.observe(node, { childList: true, subtree: true });+ return () => {+ observer.disconnect();+ mutations.disconnect();+ };+ }, []);+ return {+ ...stackGeometry(published, viewport.width, viewport.height, neededRoom),+ ref,+ };}diff --git a/studio/frontend/tests/monitor-stack-inset.test.ts b/studio/frontend/tests/monitor-stack-inset.test.tsindex 344907cf244..120f54e9926 100644--- a/studio/frontend/tests/monitor-stack-inset.test.ts+++ b/studio/frontend/tests/monitor-stack-inset.test.ts@@ -2,6 +2,7 @@// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0import assert from "node:assert/strict";+import { readFile } from "node:fs/promises";import test from "node:test";import {@@ -271,6 +272,87 @@ test("the welcome composer is left alone, and the stack stays in the corner", ()assert.equal(stackBottomInset(welcome, CHAT_W, CHAT_H), 16);});+// The reported case: a 921x534 window, where the welcome composer leaves 83px+// under it and the 80px card fits in the corner it was being lifted out of.+// Asking for a fixed 120 parked it in the middle of the screen instead.+const SHORT_W = 921;+const SHORT_H = 534;+const SHORT_WELCOME = { left: 316, top: 308, right: 877, bottom: 427 };++test("a card that fits under the welcome composer keeps the corner", () => {+ const geometry = stackGeometry(SHORT_WELCOME, SHORT_W, SHORT_H, 80);+ assert.equal(geometry.bottom, 16, "the card belongs in the corner");+ const stackTop = SHORT_H - geometry.bottom - geometry.maxHeight;+ assert.ok(stackTop >= SHORT_WELCOME.bottom, "and still clears the composer");+ assert.ok(geometry.maxHeight >= 80, "with room for the card it measured");+});++test("a stack too tall for that gap is still lifted over", () => {+ const inset = stackBottomInset(SHORT_WELCOME, SHORT_W, SHORT_H, 200);+ assert.ok(inset > 16, "200px cannot fit in 83px, so it has to move");+ assert.ok(SHORT_H - inset <= SHORT_WELCOME.top, "and clears it fully");+});++test("a docked composer is dodged whatever the stack measures", () => {+ const docked = { left: 412, top: 664, right: 1148, bottom: 814 };+ for (const height of [40, 80, 120, 260]) {+ assert.ok(+ stackBottomInset(docked, CHAT_W, CHAT_H, height) > 16,+ `a ${height}px stack must still clear Send`,+ );+ }+});++// The measurement feeds the cap, and the cap is on the element measured. The+// overlays are min-h-0 flex items, so under the cap they shrink to it and+// scrollHeight reports the cap: a stack taller than the gap would measure as+// the gap, never ask for a lift, and sit clipped. So read with the cap off.+test("the height is measured with the hook's own cap lifted", async () => {+ const source = await readFile(+ new URL(+ "../src/features/settings/stores/monitor-frame-store.ts",+ import.meta.url,+ ),+ "utf8",+ );+ const measure = source.slice(+ source.indexOf("const measure = () => {"),+ source.indexOf("observer.observe(node)"),+ );+ assert.ok(measure, "the measure callback moved");+ assert.match(+ measure,+ /node\.style\.maxHeight = "none";[\s\S]*node\.scrollHeight/,+ "scrollHeight is read while the cap still applies",+ );+ assert.match(+ measure,+ /node\.scrollHeight;[\s\S]*node\.style\.maxHeight = capped;/,+ "the cap is not restored after the read",+ );+});++// The sweep above, re-run at the heights the stack actually takes.+test("no measured height leaves the stack overlapping a box", () => {+ const composer = { left: 412, top: 664, right: 1148, bottom: 814 };+ for (const needed of [0, 40, 80, 120, 200, 320]) {+ for (let bottom = 60; bottom <= CHAT_H - 16; bottom += 4) {+ const box = { left: 996, top: Math.max(0, bottom - 180), right: 1264, bottom };+ for (const boxes of [[box], [box, composer]]) {+ const geometry = stackGeometry(boxes, CHAT_W, CHAT_H, needed);+ const label = `needed=${needed} bottom=${bottom} n=${boxes.length}`;+ assert.ok(geometry.maxHeight > 0, `non-positive cap for ${label}`);+ const stackTop = CHAT_H - geometry.bottom - geometry.maxHeight;+ for (const each of boxes) {+ const clearsAbove = CHAT_H - geometry.bottom <= each.top;+ const clearsBelow = stackTop >= each.bottom;+ assert.ok(clearsAbove || clearsBelow, `overlap for ${label}`);+ }+ }+ }+ }+});+// Same rule, applied to the other publisher: a monitor dragged up the screen// leaves the corner free, so the stack belongs in it.test("a monitor away from the corner no longer lifts the stack", () => {