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: open video attachments in the browser panel (#13007)
Michael Han9cadba11a8a9
diff --git a/studio/frontend/src/components/assistant-ui/attachment-browser-open.tsx b/studio/frontend/src/components/assistant-ui/attachment-browser-open.tsxindex a5f30914295..a7471d30ed4 100644--- a/studio/frontend/src/components/assistant-ui/attachment-browser-open.tsx+++ b/studio/frontend/src/components/assistant-ui/attachment-browser-open.tsx@@ -25,14 +25,25 @@ import { FileContextMenu } from "./link-context-menu";type Opened = { blob: Blob; plainText?: boolean };-// Documents and text open as tabs; media keeps the lightbox.-const OPENS_IN_BROWSER: ReadonlySet<AttachmentSource["kind"]> = new Set(["document", "text"]);+// Documents, text and videos open as tabs; images and audio keep the lightbox.+const OPENS_IN_BROWSER: ReadonlySet<AttachmentSource["kind"]> = new Set(["document", "text", "video"]);function localLoader(source: AttachmentSource): (() => Promise<Opened>) | null {const { file, text } = source;// Copied: the tab can outlive the composer's File.if (file) return () => file.arrayBuffer().then((data) => ({ blob: new Blob([data], { type: file.type }) }));switch (source.kind) {+ case "video": {+ // A sent clip is only its base64 part until someone opens it.+ const { video, src } = source;+ const url = video ? (video.data.startsWith("data:") ? video.data : `data:${video.mimeType};base64,${video.data}`) : src;+ if (!url) return null;+ return () =>+ fetch(url).then(async (response) => {+ if (!response.ok) throw new Error(`HTTP ${response.status}`);+ return { blob: await response.blob() };+ });+ }case "document":return !source.hasOriginal && text !== undefined? () => Promise.resolve({ blob: new Blob([attachmentBodyText(text)], { type: "text/plain" }), plainText: true })diff --git a/studio/frontend/src/features/browser/browser-panel.tsx b/studio/frontend/src/features/browser/browser-panel.tsxindex 8cdd5c48fa1..2c475f62706 100644--- a/studio/frontend/src/features/browser/browser-panel.tsx+++ b/studio/frontend/src/features/browser/browser-panel.tsx@@ -35,6 +35,7 @@ import {ATTACHMENT_KIND_ICON_CLASS,attachmentFileKind,} from "@/features/chat";+import { formatBytes } from "@/features/hub";import { startLibraryChat } from "@/features/library";import {useSettingsDialogStore,@@ -109,7 +110,8 @@ import { SiteFavicon } from "./site-favicon";import { AnnotateLayer, WebAnnotateLayer } from "./annotate-layer";import { BookmarkStar, BookmarksBar } from "./bookmarks";import { useBookmarkFor } from "./bookmarks-store";-import { browserTabType, textFileKind } from "./file-kind";+import { browserTabType, mediaKind, textFileKind } from "./file-kind";+import { canCopyVideoFrame, copyVideoFrame, tabVideo } from "./video-registry";import { CONTEXT_MENU } from "./link-context-menu";import { CONTEXT_TAB_MENU, TabMenuItems, focusRenameField, renameTabTo, setTabMuted } from "./tab-menu";import {@@ -1463,7 +1465,11 @@ function WebToolbar({ tab }: { tab: BrowserTab | undefined }) {/** HTML and code use the browser chrome; other files keep the floating controls. */function usesBrowserChrome(entry: Extract<BrowserEntry, { kind: "file" }>): boolean {const kind = textFileKind(entry.name, entry.contentType, entry.plainText);- return kind === "html" || kind === "code";+ return kind === "html" || kind === "code" || isVideoEntry(entry);+}++function isVideoEntry(entry: Extract<BrowserEntry, { kind: "file" }>): boolean {+ return !entry.plainText && mediaKind(entry.name, entry.contentType) === "video";}function BrowserFileToolbar({@@ -2056,6 +2062,176 @@ function FloatingFileToolbar({);}+const SPLIT_PILL = cn(PILL, "flex h-9 shrink-0 items-center rounded-full");+const SPLIT_PART =+ "flex h-full cursor-pointer items-center rounded-full text-ui-13p5 text-foreground outline-none transition-colors hover:bg-[color-mix(in_oklab,var(--foreground)_6%,transparent)] focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 data-[state=open]:bg-[color-mix(in_oklab,var(--foreground)_8%,transparent)]";++function SplitChevron() {+ return (+ <HugeiconsIcon+ icon={ChevronDownStandardIcon}+ strokeWidth={1.75}+ className="size-4 shrink-0 text-muted-foreground"+ />+ );+}++/** Video file bar: the name, then Copy and Open, each with its options. */+function VideoFileToolbar({+ tab,+ entry,+}: { tab: BrowserTab; entry: Extract<BrowserEntry, { kind: "file" }> }) {+ const t = useT();+ const navigate = useNavigate();+ const download = tabDownload(tab);+ const blob = download?.blob;+ const { goBack, goForward } = useBrowserStore.getState();+ // A blob URL can't be handed to another app from the desktop app.+ const tabType = isTauri ? null : browserTabType(entry.name, entry.contentType || blob?.type || "");+ const canOpenTab = tabType !== null;+ const frameCopies = canCopyVideoFrame();+ const openInBrowser = () => {+ if (!blob || !tabType) return;+ const url = URL.createObjectURL(new Blob([blob], { type: tabType }));+ window.open(url, "_blank", "noopener,noreferrer");+ window.setTimeout(() => URL.revokeObjectURL(url), 60_000);+ };+ const openInNewChat = () => {+ if (!blob) return;+ startLibraryChat(navigate, {+ files: [new File([blob], entry.name, { type: entry.contentType || blob.type })],+ });+ };+ const save = () => download && void saveBrowserDownload(download);+ const copyFrame = () => {+ const video = tabVideo(tab.id);+ if (!video) return;+ void copyVideoFrame(video).then((ok) =>+ ok ? toast.success(t("browser.video.frameCopied")) : toast.error(t("browser.video.copyFrameFailed")),+ );+ };+ const copyName = () =>+ void copyToClipboard(entry.name).then((ok) => ok && toast.success(t("browser.video.nameCopied")));+ const extension = /\.([a-z0-9]+)$/i.exec(entry.name)?.[1]?.toUpperCase();+ const meta = [extension, blob ? formatBytes(blob.size) : null].filter(Boolean).join(" · ");+ return (+ <>+ {/* As the panel narrows, back/forward and then Copy hide before the name does. */}+ <div className="hidden shrink-0 items-center gap-0.5 @[34rem]:flex">+ <IconButton+ label={t("browser.back")}+ disabled={tab.index === 0}+ onClick={() => goBack(tab.id)}+ className={NAV_BUTTON}+ >+ <ArrowLeft strokeWidth={NAV_STROKE} className={NAV_ICON} />+ </IconButton>+ <IconButton+ label={t("browser.forward")}+ disabled={tab.index >= tab.history.length - 1}+ onClick={() => goForward(tab.id)}+ className={NAV_BUTTON}+ >+ <ArrowRight strokeWidth={NAV_STROKE} className={NAV_ICON} />+ </IconButton>+ </div>+ <div+ title={entry.name}+ className={cn(PILL_SURFACE, "flex h-9 min-w-24 flex-1 items-center gap-2 rounded-full px-3.5")}+ >+ <KindIcon name={entry.name} contentType={entry.contentType} className="size-4.5" />+ <span className="min-w-0 truncate text-ui-13p5 text-foreground">{entry.name}</span>+ {meta ? (+ <span className="hidden shrink-0 text-ui-12 text-muted-foreground @[30rem]:inline">{meta}</span>+ ) : null}+ </div>+ {/* Without Copy frame (desktop app) the name is all there is to copy. */}+ <div className={cn(SPLIT_PILL, "hidden @[26rem]:flex")}>+ <Tooltip>+ <TooltipTrigger asChild={true}>+ <button+ type="button"+ aria-label={frameCopies ? t("browser.video.copyFrame") : t("browser.video.copyName")}+ onClick={frameCopies ? copyFrame : copyName}+ className={cn(SPLIT_PART, frameCopies ? "pl-2.5 pr-1" : "px-2.5")}+ >+ <HugeiconsIcon icon={Copy01Icon} strokeWidth={1.75} className="size-4.5" />+ </button>+ </TooltipTrigger>+ <TooltipContent side="bottom" className="tooltip-compact">+ {frameCopies ? t("browser.video.copyFrame") : t("browser.video.copyName")}+ </TooltipContent>+ </Tooltip>+ {frameCopies ? (+ <DropdownMenu>+ <DropdownMenuTrigger asChild={true}>+ <button type="button" aria-label={t("browser.video.copyOptions")} className={cn(SPLIT_PART, "pr-2 pl-1")}>+ <SplitChevron />+ </button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end" sideOffset={6} className="browser-menu min-w-52 rounded-[20px] p-1.5">+ <DropdownMenuItem onSelect={copyFrame}>+ <HugeiconsIcon icon={Copy01Icon} strokeWidth={1.75} className="size-4" />+ {t("browser.video.copyFrame")}+ </DropdownMenuItem>+ <DropdownMenuItem onSelect={copyName}>+ <HugeiconsIcon icon={TextWrapIcon} strokeWidth={1.75} className="size-4" />+ {t("browser.video.copyName")}+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ ) : null}+ </div>+ <div className={SPLIT_PILL}>+ <button+ type="button"+ disabled={!blob}+ onClick={canOpenTab ? openInBrowser : save}+ title={canOpenTab ? t("browser.file.newBrowserTab") : t("browser.video.saveAs")}+ className={cn(SPLIT_PART, "gap-1.5 pr-1.5 pl-3")}+ >+ <HugeiconsIcon+ icon={canOpenTab ? ArrowUpRight01Icon : Download01Icon}+ strokeWidth={1.75}+ className="size-4.5"+ />+ {canOpenTab ? t("browser.video.open") : t("browser.video.saveAs")}+ </button>+ <DropdownMenu>+ <DropdownMenuTrigger asChild={true}>+ <button+ type="button"+ disabled={!blob}+ aria-label={t("browser.video.openOptions")}+ className={cn(SPLIT_PART, "pr-2.5 pl-1")}+ >+ <SplitChevron />+ </button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end" sideOffset={6} className="browser-menu min-w-56 rounded-[20px] p-1.5">+ {canOpenTab ? (+ <DropdownMenuItem onSelect={openInBrowser}>+ <HugeiconsIcon icon={InternetIcon} strokeWidth={1.75} className="size-4.5" />+ {t("browser.file.newBrowserTab")}+ </DropdownMenuItem>+ ) : null}+ <DropdownMenuItem onSelect={openInNewChat}>+ <HugeiconsIcon icon={BubbleChatAddIcon} strokeWidth={1.75} className="size-4.5" />+ {t("browser.file.newChat")}+ </DropdownMenuItem>+ <DropdownMenuSeparator />+ <DropdownMenuItem onSelect={save}>+ <HugeiconsIcon icon={Download01Icon} strokeWidth={1.75} className="size-4.5" />+ {t("browser.video.saveAs")}+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ </div>+ <PanelMenu tab={tab} />+ </>+ );+}+const DEVICE_WIDTHS: Record<Exclude<DeviceMode, "off">, number> = {mobile: 390,tablet: 820,@@ -2212,6 +2388,8 @@ export const BrowserPanel = memo(function BrowserPanel({ active = true }: { acti{activeTab && activeEntry?.kind === "file" ? (floatingFileControls ? (<FloatingFileToolbar tab={activeTab} entry={activeEntry} />+ ) : isVideoEntry(activeEntry) ? (+ <VideoFileToolbar tab={activeTab} entry={activeEntry} />) : (<BrowserFileToolbar tab={activeTab} entry={activeEntry} />)@@ -2219,7 +2397,9 @@ export const BrowserPanel = memo(function BrowserPanel({ active = true }: { acti<WebToolbar tab={activeTab} />)}</div>- {floatingFileControls ? null : <BookmarksBar tab={activeTab} />}+ {floatingFileControls || (activeEntry?.kind === "file" && isVideoEntry(activeEntry)) ? null : (+ <BookmarksBar tab={activeTab} />+ )}{deviceWidth ? <DeviceBar /> : null}<divref={setPageElement}diff --git a/studio/frontend/src/features/browser/file-kind.ts b/studio/frontend/src/features/browser/file-kind.tsindex 440177ea0b7..a84e1de019b 100644--- a/studio/frontend/src/features/browser/file-kind.ts+++ b/studio/frontend/src/features/browser/file-kind.ts@@ -3,6 +3,7 @@import { documentKind, isMarkdown } from "@/components/file-viewer";import { attachmentTextLanguage } from "@/features/chat";+import { mediaKind } from "./media-kind";export const HTML_NAME = /\.(html?|xhtml)$/i;const HTML_TYPE = /^(text\/html|application\/xhtml\+xml)\b/i;@@ -10,14 +11,7 @@ export const TEXT_TYPE = /^(text\/|application\/(json|xml|javascript|x-yaml|yamlexport const TEXT_NAME =/\.(txt|log|md|markdown|mdx|json|jsonl|ya?ml|toml|ini|cfg|conf|csv|tsv|xml|svg|py|ipynb|js|mjs|cjs|ts|tsx|jsx|css|scss|sh|bash|zsh|rs|go|java|kt|c|cc|cpp|h|hpp|cs|rb|php|swift|sql|r|lua|pl|tex)$/i;-export type Media = "image" | "video" | "audio";--export function mediaKind(name: string, contentType: string): Media | null {- if (/^image\//i.test(contentType) || /\.(png|jpe?g|gif|webp|avif|bmp|ico)$/i.test(name)) return "image";- if (/^video\//i.test(contentType) || /\.(mp4|webm|mov|m4v|ogv)$/i.test(name)) return "video";- if (/^audio\//i.test(contentType) || /\.(mp3|wav|ogg|oga|flac|m4a|aac|opus)$/i.test(name)) return "audio";- return null;-}+export { type Media, mediaKind } from "./media-kind";export type TextFileKind = "html" | "markdown" | "code" | "text";diff --git a/studio/frontend/src/features/browser/file-view.tsx b/studio/frontend/src/features/browser/file-view.tsxindex e3e93eeafb9..a5dd0104814 100644--- a/studio/frontend/src/features/browser/file-view.tsx+++ b/studio/frontend/src/features/browser/file-view.tsx@@ -17,6 +17,7 @@ import { useCallback, useEffect, useMemo, useState } from "react";import { canShowFile, mediaKind, textFileKind } from "./file-kind";import { stageEditsPrompt } from "./stage-edits";import { DEFAULT_FILE_VIEW, useBrowserStore } from "./store";+import { VideoFile } from "./video-file";// The preview shows at most 200,000 chars (4 bytes each at most): a 50 MB body is never decoded whole.const MAX_TEXT_BYTES = 1024 * 1024;@@ -202,9 +203,7 @@ export function FileView({);}if (media === "video") {- return (- <video src={src} controls onError={() => setFailed(true)} className="size-full bg-black object-contain" />- );+ return <VideoFile src={src} name={name} tabId={tabId} onError={() => setFailed(true)} />;}return (<div className="m-auto w-full max-w-lg px-6">diff --git a/studio/frontend/src/features/browser/media-kind.ts b/studio/frontend/src/features/browser/media-kind.tsnew file mode 100644index 00000000000..b272017c329--- /dev/null+++ b/studio/frontend/src/features/browser/media-kind.ts@@ -0,0 +1,13 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// Apart from file-kind.ts, which pulls in the chat feature, so zoom.ts can use it.++export type Media = "image" | "video" | "audio";++export function mediaKind(name: string, contentType: string): Media | null {+ if (/^image\//i.test(contentType) || /\.(png|jpe?g|gif|webp|avif|bmp|ico)$/i.test(name)) return "image";+ if (/^video\//i.test(contentType) || /\.(mp4|webm|mov|m4v|ogv)$/i.test(name)) return "video";+ if (/^audio\//i.test(contentType) || /\.(mp3|wav|ogg|oga|flac|m4a|aac|opus)$/i.test(name)) return "audio";+ return null;+}diff --git a/studio/frontend/src/features/browser/video-file.tsx b/studio/frontend/src/features/browser/video-file.tsxnew file mode 100644index 00000000000..5b9c824ccda--- /dev/null+++ b/studio/frontend/src/features/browser/video-file.tsx@@ -0,0 +1,295 @@+// 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 {+ DropdownMenu,+ DropdownMenuCheckboxItem,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuLabel,+ DropdownMenuRadioGroup,+ DropdownMenuRadioItem,+ DropdownMenuSeparator,+ DropdownMenuTrigger,+} from "@/components/ui/dropdown-menu";+import { useT } from "@/i18n";+import { toast } from "@/lib/toast";+import { cn } from "@/lib/utils";+import {+ Maximize2Icon,+ MoreHorizontalIcon,+ PauseIcon,+ PlayIcon,+ Volume2Icon,+ VolumeXIcon,+} from "lucide-react";+import { type KeyboardEvent, useEffect, useRef, useState } from "react";+import { canCopyVideoFrame, copyVideoFrame, registerTabVideo } from "./video-registry";++const RATES = [0.5, 0.75, 1, 1.25, 1.5, 2] as const;+const SEEK_SECONDS = 5;++function clock(seconds: number): string {+ if (!Number.isFinite(seconds) || seconds < 0) return "0:00";+ const whole = Math.floor(seconds);+ const h = Math.floor(whole / 3600);+ const m = Math.floor((whole % 3600) / 60);+ const s = String(whole % 60).padStart(2, "0");+ return h > 0 ? `${h}:${String(m).padStart(2, "0")}:${s}` : `${m}:${s}`;+}++const CONTROL =+ "flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-full text-foreground transition-colors hover:bg-[color-mix(in_oklab,var(--foreground)_7%,transparent)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-40";++/** A video tab: the clip on a soft band, with its own controls along the bottom. */+export function VideoFile({+ src,+ name,+ tabId,+ onError,+}: {+ src: string;+ name: string;+ tabId: string | undefined;+ onError: () => void;+}) {+ const t = useT();+ const rootRef = useRef<HTMLDivElement>(null);+ const videoRef = useRef<HTMLVideoElement>(null);+ const [playing, setPlaying] = useState(false);+ const [time, setTime] = useState(0);+ const [duration, setDuration] = useState(0);+ const [muted, setMuted] = useState(false);+ const [volume, setVolume] = useState(1);+ const [rate, setRate] = useState(1);+ const [loop, setLoop] = useState(false);++ useEffect(() => {+ const video = videoRef.current;+ if (!video || !tabId) return;+ return registerTabVideo(tabId, video);+ }, [tabId]);++ const video = () => videoRef.current;+ const togglePlay = () => {+ const el = video();+ if (!el) return;+ if (el.paused || el.ended) void el.play().catch(() => undefined);+ else el.pause();+ };+ const seekBy = (delta: number) => {+ const el = video();+ if (!el) return;+ const end = Number.isFinite(el.duration) ? el.duration : el.currentTime + delta;+ el.currentTime = Math.min(end, Math.max(0, el.currentTime + delta));+ };+ const toggleMute = () => {+ const el = video();+ if (!el) return;+ el.muted = !el.muted;+ if (!el.muted && el.volume === 0) el.volume = 1;+ };+ // The whole player, so its controls stay on screen.+ const fullscreen = () => {+ const root = rootRef.current;+ if (!root) return;+ const request = document.fullscreenElement === root ? document.exitFullscreen() : root.requestFullscreen?.();+ void request?.catch(() => undefined);+ };+ const pictureInPicture = () => {+ const el = video();+ if (!el) return;+ const request =+ document.pictureInPictureElement === el ? document.exitPictureInPicture() : el.requestPictureInPicture();+ void request.catch(() => undefined);+ };+ const copyFrame = () => {+ const el = video();+ if (!el) return;+ void copyVideoFrame(el).then((ok) =>+ ok ? toast.success(t("browser.video.frameCopied")) : toast.error(t("browser.video.copyFrameFailed")),+ );+ };++ const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {+ const target = event.target as HTMLElement;+ // Keys from the portaled menu bubble here too; inputs and a focused button's Space are theirs.+ if (!event.currentTarget.contains(target) || target instanceof HTMLInputElement) return;+ if (event.metaKey || event.ctrlKey || event.altKey) return;+ if (event.key === " " && target !== event.currentTarget && target.closest("button")) return;+ const handlers: Record<string, () => void> = {+ " ": togglePlay,+ k: togglePlay,+ ArrowLeft: () => seekBy(-SEEK_SECONDS),+ ArrowRight: () => seekBy(SEEK_SECONDS),+ m: toggleMute,+ f: fullscreen,+ };+ const handler = handlers[event.key];+ if (!handler) return;+ event.preventDefault();+ handler();+ };++ const progress = duration > 0 ? Math.min(100, (time / duration) * 100) : 0;+ const level = muted ? 0 : volume;+ const pipSupported = typeof document !== "undefined" && document.pictureInPictureEnabled;++ return (+ // biome-ignore lint/a11y/noNoninteractiveTabindex: the player takes its keyboard shortcuts while focused+ <div+ ref={rootRef}+ tabIndex={0}+ role="group"+ aria-label={name}+ onKeyDown={onKeyDown}+ className="browser-video flex size-full min-h-0 flex-col bg-background outline-none"+ >+ <div className="flex min-h-0 flex-1 items-center" style={{ containerType: "size" }}>+ {/* Brand-tinted band, so any clip reads as framed rather than a black box. */}+ <div className="browser-video-band flex w-full items-center justify-center px-[7%] py-[clamp(1.5rem,6cqh,3.5rem)]">+ {/* biome-ignore lint/a11y/useMediaCaption: user video has no captions */}+ <video+ ref={videoRef}+ src={src}+ playsInline={true}+ loop={loop}+ onClick={togglePlay}+ onDoubleClick={fullscreen}+ onPlay={() => setPlaying(true)}+ onPause={() => setPlaying(false)}+ onEnded={() => setPlaying(false)}+ onTimeUpdate={(event) => setTime(event.currentTarget.currentTime)}+ onDurationChange={(event) => {+ const value = event.currentTarget.duration;+ if (Number.isFinite(value)) setDuration(value);+ }}+ onLoadedMetadata={(event) => {+ const el = event.currentTarget;+ if (Number.isFinite(el.duration)) return;+ // Recorded WebM leaves the duration out until the end has been read: seek there once.+ const settle = () => {+ el.removeEventListener("timeupdate", settle);+ el.currentTime = 0;+ };+ el.addEventListener("timeupdate", settle);+ el.currentTime = Number.MAX_SAFE_INTEGER;+ }}+ onVolumeChange={(event) => {+ setMuted(event.currentTarget.muted);+ setVolume(event.currentTarget.volume);+ }}+ onRateChange={(event) => setRate(event.currentTarget.playbackRate)}+ onError={onError}+ className="block max-h-[calc(100cqh-clamp(3rem,12cqh,7rem))] max-w-full cursor-pointer rounded-md bg-black shadow-[0_18px_50px_-12px_rgb(0_0_0/0.35)]"+ />+ </div>+ </div>+ <div className="browser-video-controls flex h-13 shrink-0 items-center gap-2 border-t border-border/60 px-3">+ <button+ type="button"+ aria-label={playing ? t("browser.video.pause") : t("browser.video.play")}+ onClick={togglePlay}+ className={CONTROL}+ >+ {playing ? (+ <PauseIcon className="size-4.5" strokeWidth={1.75} />+ ) : (+ <PlayIcon className="size-4.5" strokeWidth={1.75} />+ )}+ </button>+ <input+ type="range"+ aria-label={t("browser.video.seek")}+ min={0}+ max={duration || 0}+ step="any"+ value={Math.min(time, duration || 0)}+ disabled={duration === 0}+ onChange={(event) => {+ const el = video();+ if (el) el.currentTime = Number(event.currentTarget.value);+ }}+ className="browser-video-range mx-1 min-w-0 flex-1"+ style={{ ["--range-fill" as string]: `${progress}%` }}+ />+ <span className="shrink-0 px-1 text-ui-13 text-muted-foreground tabular-nums">+ {clock(time)} / {clock(duration)}+ </span>+ <div className="group/volume flex shrink-0 items-center">+ <input+ type="range"+ aria-label={t("browser.video.volume")}+ min={0}+ max={1}+ step={0.05}+ value={level}+ onChange={(event) => {+ const el = video();+ if (!el) return;+ el.volume = Number(event.currentTarget.value);+ el.muted = el.volume === 0;+ }}+ className="browser-video-range w-0 opacity-0 transition-[width,opacity] duration-150 group-focus-within/volume:mr-1 group-focus-within/volume:w-16 group-focus-within/volume:opacity-100 group-hover/volume:mr-1 group-hover/volume:w-16 group-hover/volume:opacity-100"+ style={{ ["--range-fill" as string]: `${level * 100}%` }}+ />+ <button+ type="button"+ aria-label={muted || volume === 0 ? t("browser.video.unmute") : t("browser.video.mute")}+ onClick={toggleMute}+ className={CONTROL}+ >+ {muted || volume === 0 ? (+ <VolumeXIcon className="size-4.5" strokeWidth={1.75} />+ ) : (+ <Volume2Icon className="size-4.5" strokeWidth={1.75} />+ )}+ </button>+ </div>+ <DropdownMenu>+ <DropdownMenuTrigger asChild={true}>+ <button type="button" aria-label={t("browser.video.more")} className={cn(CONTROL, "aria-expanded:bg-[color-mix(in_oklab,var(--foreground)_8%,transparent)]")}>+ <MoreHorizontalIcon className="size-4.5" strokeWidth={1.75} />+ </button>+ </DropdownMenuTrigger>+ <DropdownMenuContent+ side="top"+ align="end"+ sideOffset={8}+ className="browser-menu min-w-52 rounded-[20px] p-1.5"+ >+ <DropdownMenuLabel className="text-ui-12 text-muted-foreground">+ {t("browser.video.speed")}+ </DropdownMenuLabel>+ <DropdownMenuRadioGroup+ value={String(rate)}+ onValueChange={(value) => {+ const el = video();+ if (el) el.playbackRate = Number(value);+ }}+ >+ {RATES.map((value) => (+ <DropdownMenuRadioItem key={value} value={String(value)} onSelect={(event) => event.preventDefault()}>+ {value === 1 ? t("browser.video.normalSpeed") : `${value}×`}+ </DropdownMenuRadioItem>+ ))}+ </DropdownMenuRadioGroup>+ <DropdownMenuSeparator />+ <DropdownMenuCheckboxItem checked={loop} onCheckedChange={setLoop}>+ {t("browser.video.loop")}+ </DropdownMenuCheckboxItem>+ {pipSupported ? (+ <DropdownMenuItem onSelect={pictureInPicture}>{t("browser.video.pictureInPicture")}</DropdownMenuItem>+ ) : null}+ {canCopyVideoFrame() ? (+ <DropdownMenuItem onSelect={copyFrame}>{t("browser.video.copyFrame")}</DropdownMenuItem>+ ) : null}+ </DropdownMenuContent>+ </DropdownMenu>+ <button type="button" aria-label={t("browser.video.fullscreen")} onClick={fullscreen} className={CONTROL}>+ <Maximize2Icon className="size-4" strokeWidth={1.75} />+ </button>+ </div>+ </div>+ );+}diff --git a/studio/frontend/src/features/browser/video-registry.ts b/studio/frontend/src/features/browser/video-registry.tsnew file mode 100644index 00000000000..003ec088ec1--- /dev/null+++ b/studio/frontend/src/features/browser/video-registry.ts@@ -0,0 +1,41 @@+// 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 { isTauri } from "@/lib/api-base";++// The player of each video tab, so the toolbar can act on the frame on screen.+const videos = new Map<string, HTMLVideoElement>();++export function registerTabVideo(tabId: string, video: HTMLVideoElement): () => void {+ videos.set(tabId, video);+ return () => {+ if (videos.get(tabId) === video) videos.delete(tabId);+ };+}++export function tabVideo(tabId: string): HTMLVideoElement | null {+ return videos.get(tabId) ?? null;+}++/** The desktop app can't write images to the clipboard. */+export const canCopyVideoFrame = (): boolean =>+ !isTauri && typeof ClipboardItem !== "undefined" && typeof navigator.clipboard?.write === "function";++/** Copies the frame on screen as a PNG; false where the clipboard takes no images. */+export async function copyVideoFrame(video: HTMLVideoElement): Promise<boolean> {+ if (!canCopyVideoFrame()) return false;+ if (!video.videoWidth || !video.videoHeight) return false;+ const canvas = document.createElement("canvas");+ canvas.width = video.videoWidth;+ canvas.height = video.videoHeight;+ canvas.getContext("2d")?.drawImage(video, 0, 0);+ const png = new Promise<Blob>((resolve, reject) =>+ canvas.toBlob((blob) => (blob ? resolve(blob) : reject(new Error("no frame"))), "image/png"),+ );+ try {+ await navigator.clipboard.write([new ClipboardItem({ "image/png": png })]);+ return true;+ } catch {+ return false;+ }+}diff --git a/studio/frontend/src/features/browser/zoom.ts b/studio/frontend/src/features/browser/zoom.tsindex 86eac3ea431..1d715976129 100644--- a/studio/frontend/src/features/browser/zoom.ts+++ b/studio/frontend/src/features/browser/zoom.ts@@ -1,12 +1,17 @@// 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 { mediaKind } from "./media-kind";import { defaultZoom } from "./prefs-store";import { type BrowserTab, currentEntry, pageDownload, useBrowserStore } from "./store";export function canZoom(tab: BrowserTab | undefined): tab is BrowserTab {- const kind = tab ? currentEntry(tab).kind : null;- return kind === "web" || kind === "file";+ const entry = tab ? currentEntry(tab) : null;+ if (entry?.kind === "web") return true;+ if (entry?.kind !== "file") return false;+ // Video and audio players don't scale with the page zoom.+ const media = entry.plainText ? null : mediaKind(entry.name, entry.contentType);+ return media !== "video" && media !== "audio";}export const ZOOM_STEPS = [0.25, 0.33, 0.5, 0.67, 0.75, 0.8, 0.9, 1, 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3, 4, 5];diff --git a/studio/frontend/src/i18n/locales/en.ts b/studio/frontend/src/i18n/locales/en.tsindex 1f1fc12ab7d..fb626441072 100644--- a/studio/frontend/src/i18n/locales/en.ts+++ b/studio/frontend/src/i18n/locales/en.ts@@ -278,6 +278,29 @@ export const en = {copyFailed: "Couldn't copy the file.",wrap: "Wrap lines",},+ video: {+ play: "Play",+ pause: "Pause",+ seek: "Seek",+ volume: "Volume",+ mute: "Mute",+ unmute: "Unmute",+ more: "More playback options",+ speed: "Playback speed",+ normalSpeed: "Normal",+ loop: "Loop",+ pictureInPicture: "Picture in picture",+ fullscreen: "Full screen",+ copyFrame: "Copy frame",+ frameCopied: "Frame copied",+ copyFrameFailed: "Couldn't copy the frame.",+ copyName: "Copy file name",+ nameCopied: "File name copied",+ copyOptions: "Copy options",+ open: "Open",+ openOptions: "Open options",+ saveAs: "Save as…",+ },pages: {searchDownloads: "Search download history",clearAll: "Clear all",diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.cssindex d458b0b10a9..b00d53b51cd 100644--- a/studio/frontend/src/index.css+++ b/studio/frontend/src/index.css@@ -5047,6 +5047,68 @@ html.force-reduced-motion .sidebar-section-drop-line {display: none;}+/* Video tabs: the clip sits on a soft brand-tinted band. */+.browser-video-band {+ background:+ radial-gradient(55% 90% at 18% 30%, color-mix(in oklab, var(--primary) 30%, transparent), transparent 70%),+ radial-gradient(50% 80% at 85% 75%, color-mix(in oklab, var(--primary) 24%, transparent), transparent 70%),+ color-mix(in oklab, var(--primary) 9%, var(--background));+}++/* Thin track filled up to --range-fill, with a round thumb. */+.browser-video-range {+ appearance: none;+ height: 1.25rem;+ background: transparent;+ cursor: pointer;+}++.browser-video-range:disabled {+ cursor: default;+}++.browser-video-range::-webkit-slider-runnable-track {+ height: 4px;+ border-radius: 9999px;+ background: linear-gradient(+ to right,+ var(--foreground) var(--range-fill, 0%),+ color-mix(in oklab, var(--foreground) 16%, transparent) var(--range-fill, 0%)+ );+}++.browser-video-range::-moz-range-track {+ height: 4px;+ border-radius: 9999px;+ background: color-mix(in oklab, var(--foreground) 16%, transparent);+}++.browser-video-range::-moz-range-progress {+ height: 4px;+ border-radius: 9999px;+ background: var(--foreground);+}++.browser-video-range::-webkit-slider-thumb {+ appearance: none;+ width: 14px;+ height: 14px;+ margin-top: -5px;+ border-radius: 9999px;+ background: var(--background);+ border: 1px solid color-mix(in oklab, var(--foreground) 22%, transparent);+ box-shadow: 0 1px 4px rgb(0 0 0 / 0.25);+}++.browser-video-range::-moz-range-thumb {+ width: 14px;+ height: 14px;+ border-radius: 9999px;+ background: var(--background);+ border: 1px solid color-mix(in oklab, var(--foreground) 22%, transparent);+ box-shadow: 0 1px 4px rgb(0 0 0 / 0.25);+}+/* The browser's tabs scroll sideways once they're at their narrowest, with no bar. */.browser-tablist {scrollbar-width: none;diff --git a/studio/frontend/tests/browser-settings.test.ts b/studio/frontend/tests/browser-settings.test.tsindex a0d635c82ed..6bab4c83655 100644--- a/studio/frontend/tests/browser-settings.test.ts+++ b/studio/frontend/tests/browser-settings.test.ts@@ -544,3 +544,17 @@ test("a blocked site's blob: page can't download past the block", async () => {useDownloadSitesStore.getState().setSite("https://a.example", null);prefs.setAskBeforeDownloading(true);});++test("video and audio tabs don't zoom; pages, images and documents do", async () => {+ const { canZoom } = await import("../src/features/browser/zoom.ts");+ const tab = (entry: object) =>+ ({ id: "t", index: 0, history: [{ kind: "file", contentType: "", ...entry }], zoom: 1 }) as never;+ assert.equal(canZoom(tab({ name: "clip.mp4" })), false);+ assert.equal(canZoom(tab({ name: "clip", contentType: "video/webm" })), false);+ assert.equal(canZoom(tab({ name: "song.mp3" })), false);+ assert.equal(canZoom(tab({ name: "photo.png" })), true);+ assert.equal(canZoom(tab({ name: "paper.pdf" })), true);+ // A clip shown as its text is a text file.+ assert.equal(canZoom(tab({ name: "clip.mp4", plainText: true })), true);+ assert.equal(canZoom({ id: "t", index: 0, history: [{ kind: "web", url: "https://a.b/" }], zoom: 1 } as never), true);+});