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: follow-ups for the media gallery, hub link and rail divider (#11765)
Michael Han168961def8cc
diff --git a/studio/backend/core/inference/gallery_projects.py b/studio/backend/core/inference/gallery_projects.pyindex a409613b751..39a24061ebc 100644--- a/studio/backend/core/inference/gallery_projects.py+++ b/studio/backend/core/inference/gallery_projects.py@@ -77,9 +77,10 @@ def _copy_with_dir_fd(source: Path, sandbox: str, folder: str) -> bool:finally:os.close(sandbox_fd)try:+ # Keyed by gallery id and written atomically, so a file here is this item, maybe since edited.try:st = os.stat(name, dir_fd = folder_fd, follow_symlinks = False)- if stat.S_ISREG(st.st_mode) and st.st_size == source.stat().st_size:+ if stat.S_ISREG(st.st_mode):return Trueexcept FileNotFoundError:pass@@ -112,17 +113,16 @@ def _copy_by_path(source: Path, sandbox: str, folder: str) -> bool:raise PermissionError(f"{target} resolves outside the project sandbox")dest = Path(real) / source.nametry:- if (- not dest.is_symlink()- and dest.is_file()- and dest.stat().st_size == source.stat().st_size- ):+ if not dest.is_symlink() and dest.is_file():return Trueexcept OSError:passtmp = Path(real) / _tmp_name(source.name)try:shutil.copyfile(source, tmp)+ # Without dir_fd the folder can be swapped after the check; check again before the rename.+ if os.path.realpath(tmp.parent) != real:+ raise PermissionError(f"{target} moved outside the project sandbox")os.replace(tmp, dest)except BaseException:with contextlib.suppress(OSError):diff --git a/studio/backend/core/inference/image_gallery.py b/studio/backend/core/inference/image_gallery.pyindex b0434749430..0e5a56e5f7f 100644--- a/studio/backend/core/inference/image_gallery.py+++ b/studio/backend/core/inference/image_gallery.py@@ -100,8 +100,10 @@ def _record("id": image_id,"url": f"/api/inference/images/gallery/{image_id}/file",**gallery_flags.flags_for(flags, image_id),- # Lets the client keep a dragged item in place when it re-sorts.- "order_at": gallery_flags.order_at(flags, image_id),+ # The server's own sort key, so a client re-sort agrees with it (created_at can differ).+ "order_at": gallery_flags.order_rank(+ flags, image_id, _mtime(gallery_dir() / f"{image_id}.png")+ ),}diff --git a/studio/backend/core/inference/video_gallery.py b/studio/backend/core/inference/video_gallery.pyindex 346b80c1836..1deee09c208 100644--- a/studio/backend/core/inference/video_gallery.py+++ b/studio/backend/core/inference/video_gallery.py@@ -174,8 +174,10 @@ def _record("id": video_id,"url": f"/api/inference/video/gallery/{video_id}/file",**gallery_flags.flags_for(flags, video_id),- # Lets the client keep a dragged item in place when it re-sorts.- "order_at": gallery_flags.order_at(flags, video_id),+ # The server's own sort key, so a client re-sort agrees with it (created_at can differ).+ "order_at": gallery_flags.order_rank(+ flags, video_id, _mtime(path) if (path := video_path(video_id)) else 0.0+ ),}diff --git a/studio/backend/models/inference.py b/studio/backend/models/inference.pyindex 79a337f8ca6..25d66f47c58 100644--- a/studio/backend/models/inference.py+++ b/studio/backend/models/inference.py@@ -4295,7 +4295,7 @@ class GalleryImage(BaseModel):archived: bool = Field(False, description = "Moved to the archived shelf, hidden from the strip")order_at: Optional[float] = Field(None,- description = "Manual sort key (epoch-second scale) once dragged; unset sorts by creation",+ description = "Unpinned sort key (epoch-second scale): the manual key once dragged, else the file mtime",)@@ -5154,7 +5154,7 @@ class GalleryVideo(BaseModel):archived: bool = Field(False, description = "Moved to the archived shelf, hidden from the strip")order_at: Optional[float] = Field(None,- description = "Manual sort key (epoch-second scale) once dragged; unset sorts by creation",+ description = "Unpinned sort key (epoch-second scale): the manual key once dragged, else the file mtime",)diff --git a/studio/backend/tests/test_gallery_projects.py b/studio/backend/tests/test_gallery_projects.pyindex e7f60fef050..34746f4dba8 100644--- a/studio/backend/tests/test_gallery_projects.py+++ b/studio/backend/tests/test_gallery_projects.py@@ -45,6 +45,14 @@ def test_adding_the_same_item_twice_reports_it_is_already_there(project, media):assert sorted(p.name for p in (project / "sandbox" / "images").iterdir()) == ["abc123.png"]+def test_an_edited_project_copy_is_kept(project, media, copy_mode):+ gp.copy_into_project(media, "p1", "images")+ dest = project / "sandbox" / "images" / "abc123.png"+ dest.write_bytes(b"edited in the project, a different size")+ assert gp.copy_into_project(media, "p1", "images")["already"] is True+ assert dest.read_bytes() == b"edited in the project, a different size"++def test_an_unknown_project_is_refused(project, media):with pytest.raises(gp.ProjectNotFound):gp.copy_into_project(media, "gone", "images")@@ -106,3 +114,22 @@ def test_concurrent_adds_of_one_item_all_succeed(project, media, copy_mode):def test_temp_names_are_unique_per_call():assert gp._tmp_name("a.png") != gp._tmp_name("a.png")+++def test_a_folder_swapped_mid_copy_is_refused_without_dir_fd(project, media, tmp_path, monkeypatch):+ monkeypatch.setattr(gp, "_USE_DIR_FD", False)+ folder = project / "sandbox" / "images"+ folder.mkdir()+ outside = tmp_path / "outside"+ outside.mkdir()+ real_copyfile = gp.shutil.copyfile++ def swap_then_copy(src, dst):+ folder.rename(project / "sandbox" / "images-old")+ folder.symlink_to(outside, target_is_directory = True)+ return real_copyfile(src, dst)++ monkeypatch.setattr(gp.shutil, "copyfile", swap_then_copy)+ with pytest.raises(PermissionError):+ gp.copy_into_project(media, "p1", "images")+ assert list(outside.iterdir()) == []diff --git a/studio/backend/tests/test_image_gallery.py b/studio/backend/tests/test_image_gallery.pyindex 17ccbe4b6ae..7cb4d157262 100644--- a/studio/backend/tests/test_image_gallery.py+++ b/studio/backend/tests/test_image_gallery.py@@ -249,6 +249,18 @@ def test_records_carry_default_flags():assert record["pinned"] is False and record["archived"] is False+def test_records_carry_the_listing_sort_key():+ # A batch shares one created_at; the listing sorts by mtime, so records must say so.+ a = gallery.save(_img(), _meta(created_at = 100.0))+ b = gallery.save(_img(), _meta(created_at = 100.0))+ os.utime(gallery.gallery_dir() / f"{a['id']}.png", (150.0, 150.0))+ os.utime(gallery.gallery_dir() / f"{b['id']}.png", (120.0, 120.0))+ assert [(r["id"], r["order_at"]) for r in gallery.list_images()] == [+ (a["id"], 150.0),+ (b["id"], 120.0),+ ]++def test_pinned_images_sort_ahead_of_newer_ones():old = _save_with_mtime("old", 100.0)_save_with_mtime("new", 200.0)diff --git a/studio/frontend/src/components/media-rail-resize-handle.tsx b/studio/frontend/src/components/media-rail-resize-handle.tsxindex 30327dde09b..0fb3ab3b7ec 100644--- a/studio/frontend/src/components/media-rail-resize-handle.tsx+++ b/studio/frontend/src/components/media-rail-resize-handle.tsx@@ -1,7 +1,7 @@// SPDX-License-Identifier: AGPL-3.0-only// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0-import { useRef } from "react";+import { useLayoutEffect, useRef, useState } from "react";import { PanelResizeHandle } from "@/components/ui/panel-resize-handle";import {@@ -40,23 +40,48 @@ export function MediaRailResizeHandle({const anchorRef = useRef<HTMLSpanElement>(null);const root = () =>anchorRef.current?.closest<HTMLElement>(`[${MEDIA_RAIL_ROOT_ATTR}]`) ?? null;+ // The `100% - 13rem` cap in layout px, so drags and keys start from the width actually shown.+ const [cap, setCap] = useState<number | null>(null);+ useLayoutEffect(() => {+ const anchor = anchorRef.current;+ // What the rail's 100% resolves against: the page root's padding box, or the rail's parent.+ const block = placement === "page" ? anchor?.parentElement : anchor?.parentElement?.parentElement;+ if (!block) return;+ const update = () => {+ const style = getComputedStyle(block);+ const inner =+ placement === "page"+ ? block.clientWidth+ : block.clientWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight);+ const rem = parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;+ setCap((inner - 13 * rem) / rail.scale);+ };+ update();+ const observer = new ResizeObserver(update);+ observer.observe(block);+ return () => observer.disconnect();+ }, [placement, rail.scale]);+ // The cap can fall below the stored minimum (high interface scale near the breakpoint).+ const max = cap === null ? rail.max : Math.max(0, Math.min(rail.max, cap));+ const width = Math.min(rail.width, max);const handle = (<PanelResizeHandleedge="right"open={true}- width={rail.width}+ width={width}stored={rail.stored}- min={MEDIA_RAIL_WIDTH_MIN}- max={rail.max}+ min={Math.min(MEDIA_RAIL_WIDTH_MIN, max)}+ max={max}scale={rail.scale}- clamp={rail.clamp}- setWidth={rail.setWidth}+ clamp={(px) => Math.min(rail.clamp(px), max)}+ // Commits what is shown; a capped pull past the edge keeps the stored preference.+ setWidth={(px) => rail.setWidth(Math.min(px, max))}resetWidth={rail.resetWidth}// The rail does not collapse; click does nothing, drag and arrow keys resize.onToggle={() => {}}target={root}cssVar="--media-rail-width"- measure={() => rail.width}+ measure={() => width}label="Resize settings panel"toggleLabel="Resize settings panel"hideTooltip={true}diff --git a/studio/frontend/src/features/hub/hub-page.tsx b/studio/frontend/src/features/hub/hub-page.tsxindex 83c951bbbda..c0cebbac3c8 100644--- a/studio/frontend/src/features/hub/hub-page.tsx+++ b/studio/frontend/src/features/hub/hub-page.tsx@@ -1382,14 +1382,15 @@ export function ModelsPage() {]);useEffect(() => {- if (!isModelDiscover || !sectionChannelId) return;+ // A capability link clears the section itself; applying the preset would reset its filter.+ if (!isModelDiscover || !sectionChannelId || urlCapability) return;const preset = findChannel(sectionChannelId);if (!preset) return;setDiscoverFormat(preset.format);setSortBy(preset.sort);setDirection("desc");setCapabilityFilter("all");- }, [isModelDiscover, sectionChannelId]);+ }, [isModelDiscover, sectionChannelId, urlCapability]);const handleManageLocalFolders = useCallback(() => setFoldersDialogOpen(true),[],diff --git a/studio/frontend/src/features/images/api.ts b/studio/frontend/src/features/images/api.tsindex 7aee460d804..2224e8cf7bc 100644--- a/studio/frontend/src/features/images/api.ts+++ b/studio/frontend/src/features/images/api.ts@@ -253,7 +253,7 @@ export interface GalleryImage {// Library state, not recipe: stored beside the PNG, absent on records written before this existed.pinned?: boolean;archived?: boolean;- /** Manual sort key once dragged; unset sorts by created_at. */+ /** The server's unpinned sort key: the drag key, else the file mtime. */order_at?: number | null;}diff --git a/studio/frontend/src/features/images/images-page.tsx b/studio/frontend/src/features/images/images-page.tsxindex d78a03f42c0..bc824b5f1d1 100644--- a/studio/frontend/src/features/images/images-page.tsx+++ b/studio/frontend/src/features/images/images-page.tsx@@ -2025,12 +2025,17 @@ export function ImagesPage({const next = moveGalleryItem(galleryCache.images, id, afterId);if (next === galleryCache.images) return;const guessedPinned = Boolean(next.find((i) => i.id === id)?.pinned);+ // Takes a pin token too: a pin clicked after this drop must not be undone by its response.+ const attempt = (pinSeq.current += 1);+ pinAttempt.current.set(id, attempt);stripEpoch.current += 1;galleryCache.images = next;setImages(next);try {// Shares the pin queue, since both rewrite the order.const record = await serializeById("image-pin", () => moveGalleryImage(id, afterId));+ if (pinAttempt.current.get(id) !== attempt) return;+ pinAttempt.current.delete(id);setImages((prev) => {const patched = prev.map((i) =>i.id === id ? { ...i, pinned: record.pinned, order_at: record.order_at } : i,diff --git a/studio/frontend/src/features/images/train/diffusion-train-panel.tsx b/studio/frontend/src/features/images/train/diffusion-train-panel.tsxindex 214c7a6b736..898fa1e269a 100644--- a/studio/frontend/src/features/images/train/diffusion-train-panel.tsx+++ b/studio/frontend/src/features/images/train/diffusion-train-panel.tsx@@ -1520,8 +1520,9 @@ export function DiffusionTrainPanel({// row pan the page sideways on a phone.return (<div className="flex min-h-0 w-full min-w-0 flex-1 flex-col overflow-y-auto overflow-x-hidden pr-5 sm:pr-8 @[50rem]:flex-row @[50rem]:overflow-hidden">- {/* Left: configure. The rail width and container breakpoint match Create and the shared header. */}- <div className="flex w-full min-w-0 shrink-0 flex-col border-b border-border/60 pl-10 max-sm:pl-5 @[50rem]:w-[min(var(--media-rail-width,calc(408px*var(--ui-space-scale,1))),calc(100%-13rem))] @[50rem]:overflow-hidden @[50rem]:border-r @[50rem]:border-b-0">+ {/* Left: configure. The rail width and container breakpoint match Create and the shared header.+ The cap adds back the parent's pr-8 so it matches Create's, where the page divider sits. */}+ <div className="flex w-full min-w-0 shrink-0 flex-col border-b border-border/60 pl-10 max-sm:pl-5 @[50rem]:w-[min(var(--media-rail-width,calc(408px*var(--ui-space-scale,1))),calc(100%-13rem+--spacing(8)))] @[50rem]:overflow-hidden @[50rem]:border-r @[50rem]:border-b-0">{/* Keep the former row-level top inset inside the pane so the divider reaches the header. */}<divref={attachSettingsScroll}diff --git a/studio/frontend/src/features/video/api.ts b/studio/frontend/src/features/video/api.tsindex 014ae8e46b1..ac13cb4efa7 100644--- a/studio/frontend/src/features/video/api.ts+++ b/studio/frontend/src/features/video/api.ts@@ -224,7 +224,7 @@ export interface GalleryVideo {// Library state, not recipe: stored beside the clip, absent on sidecars written before this existed.pinned?: boolean;archived?: boolean;- /** Manual sort key once dragged; unset sorts by created_at. */+ /** The server's unpinned sort key: the drag key, else the file mtime. */order_at?: number | null;}diff --git a/studio/frontend/src/features/video/video-page.tsx b/studio/frontend/src/features/video/video-page.tsxindex 55363777c0b..2e0ed0ba7bc 100644--- a/studio/frontend/src/features/video/video-page.tsx+++ b/studio/frontend/src/features/video/video-page.tsx@@ -1980,12 +1980,17 @@ function VideoGenerator({const next = moveGalleryItem(galleryCache.videos, id, afterId);if (next === galleryCache.videos) return;const guessedPinned = Boolean(next.find((i) => i.id === id)?.pinned);+ // Takes a pin token too: a pin clicked after this drop must not be undone by its response.+ const attempt = (pinSeq.current += 1);+ pinAttempt.current.set(id, attempt);stripEpoch.current += 1;galleryCache.videos = next;setVideos(next);try {// Shares the pin queue, since both rewrite the order.const record = await serializeById("video-pin", () => moveGalleryVideo(id, afterId));+ if (pinAttempt.current.get(id) !== attempt) return;+ pinAttempt.current.delete(id);setVideos((prev) => {const patched = prev.map((i) =>i.id === id ? { ...i, pinned: record.pinned, order_at: record.order_at } : i,diff --git a/studio/frontend/src/lib/gallery-flags.ts b/studio/frontend/src/lib/gallery-flags.tsindex a901b4ce9ad..b5ecf065178 100644--- a/studio/frontend/src/lib/gallery-flags.ts+++ b/studio/frontend/src/lib/gallery-flags.ts@@ -41,7 +41,7 @@ export interface FlaggableItem {id: string;pinned?: boolean;archived?: boolean;- /** Manual sort key in epoch seconds, set once dragged; replaces created_at in the sort. */+ /** The server's unpinned sort key in epoch seconds (drag key, else file mtime). */order_at?: number | null;created_at: number | string;}