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: collapse Chat with files to a row of pills, with Show all (#13686)
Michael Han7122742806a2
diff --git a/studio/frontend/src/features/chat/stores/chat-preferences-store.ts b/studio/frontend/src/features/chat/stores/chat-preferences-store.tsindex b3241081af8..6f468d28226 100644--- a/studio/frontend/src/features/chat/stores/chat-preferences-store.ts+++ b/studio/frontend/src/features/chat/stores/chat-preferences-store.ts@@ -28,7 +28,8 @@ import {// pastedTextMinChars: paste length that becomes a .txt attachment; 0 is off.// showInlineEditResponse: on keeps Edit response in each response's action bar instead of its// More menu. notifyWhenReplyFinishes: on sends a system notification when a reply ends while the-// window is hidden or unfocused.+// window is hidden or unfocused. filesPanelCollapsed: on shrinks Chat with files to a header and+// a row of pills.export interface ChatPreferencesState {plainTextComposer: boolean;setPlainTextComposer: (value: boolean) => void;@@ -62,6 +63,8 @@ export interface ChatPreferencesState {setShowScrollToBottomButton: (value: boolean) => void;notifyWhenReplyFinishes: boolean;setNotifyWhenReplyFinishes: (value: boolean) => void;+ filesPanelCollapsed: boolean;+ setFilesPanelCollapsed: (value: boolean) => void;}// A stale stored value would leave the dropdown blank and unfixable.@@ -119,6 +122,9 @@ export const useChatPreferencesStore = create<ChatPreferencesState>()(notifyWhenReplyFinishes: false,setNotifyWhenReplyFinishes: (notifyWhenReplyFinishes) =>set({ notifyWhenReplyFinishes }),+ filesPanelCollapsed: false,+ setFilesPanelCollapsed: (filesPanelCollapsed) =>+ set({ filesPanelCollapsed }),}),{name: "unsloth_chat_preferences",@@ -163,6 +169,7 @@ export const useChatPreferencesStore = create<ChatPreferencesState>()(autoScrollWhileGenerating: saved?.autoScrollWhileGenerating ?? true,showScrollToBottomButton: saved?.showScrollToBottomButton ?? true,notifyWhenReplyFinishes: saved?.notifyWhenReplyFinishes === true,+ filesPanelCollapsed: saved?.filesPanelCollapsed === true,};},},diff --git a/studio/frontend/src/features/rag/components/thread-documents-bar.tsx b/studio/frontend/src/features/rag/components/thread-documents-bar.tsxindex a027e037f6a..736d78e540e 100644--- a/studio/frontend/src/features/rag/components/thread-documents-bar.tsx+++ b/studio/frontend/src/features/rag/components/thread-documents-bar.tsx@@ -2,15 +2,18 @@// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0import {+ createContext,+ type ReactElement,type ReactNode,useCallback,+ useContext,useEffect,useLayoutEffect,useMemo,useRef,useState,} from "react";-import { ChevronLeftIcon, ChevronRightIcon, PlusIcon, XIcon } from "lucide-react";+import { PlusIcon, XIcon } from "lucide-react";import { HugeiconsIcon } from "@hugeicons/react";import {AttachmentIcon,@@ -38,7 +41,11 @@ import {TooltipTrigger,} from "@/components/ui/tooltip";import { Tick02Icon } from "@/lib/tick-icon";-import { ChevronDownStandardIcon } from "@/lib/chevron-icons";+import {+ ChevronDownStandardIcon,+ ChevronUpStandardIcon,+} from "@/lib/chevron-icons";+import { useChatPreferencesStore } from "@/features/chat/stores/chat-preferences-store";import { useAui, useAuiState } from "@assistant-ui/react";import { cn } from "@/lib/utils";import {@@ -264,6 +271,14 @@ function ProjectBadge() {);}+// Inline 16px: the font-scaled size-4 is 15px, an odd inset that sits off centre in the 32px circle.+const HEADER_ICON = { width: 16, height: 16 } as const;++const CompactCardsContext = createContext(false);++const PILL =+ "inline-flex h-8 max-w-[calc(14rem*var(--ui-space-scale,1))] items-center gap-1.5 rounded-full px-3 text-ui-13 transition-colors";+function LinkedFolderCard({name,docs,@@ -271,14 +286,35 @@ function LinkedFolderCard({name: string | undefined;docs: TrackedDocument[];}) {+ const compact = useContext(CompactCardsContext);const indexing = docs.filter(isProcessing).length;const label = name ?? "Linked folder";const count = `${docs.length} ${docs.length === 1 ? "file" : "files"}`;+ const title = `${label}: ${count}, kept in sync and shared with every chat in this project. Manage it in the project's Sources tab.`;+ if (compact) {+ return (+ <div+ title={title}+ className={cn("unsloth-files-item unsloth-files-pill shrink-0 cursor-default", PILL, CARD_EDGE)}+ >+ {indexing > 0 ? (+ <Spinner className="size-3.5 shrink-0" />+ ) : (+ <HugeiconsIcon icon={Folder02Icon} strokeWidth={1.75} className="size-4 shrink-0" />+ )}+ <span className="truncate">{label}</span>+ <span className="shrink-0 text-muted-foreground tabular-nums">+ {indexing > 0 ? `${indexing}/${docs.length}` : docs.length}+ </span>+ <span className="sr-only">linked folder, shared with the project</span>+ </div>+ );+ }return (- <div className={cn("relative", CARD_SLOT)}>+ <div className={cn("unsloth-files-item relative", CARD_SLOT)}><ProjectBadge /><div- title={`${label}: ${count}, kept in sync and shared with every chat in this project. Manage it in the project's Sources tab.`}+ title={title}className={cn("flex overflow-hidden rounded-[15px]", CARD_SIZE, CARD_EDGE)}><FileCardBody@@ -417,6 +453,7 @@ function DocumentCard({onRemove?: () => void;onRetry?: () => void;}) {+ const compact = useContext(CompactCardsContext);const kind = attachmentFileKind(doc.filename, undefined);const processing = isProcessing(doc);const failed = doc.status === "failed";@@ -443,7 +480,7 @@ function DocumentCard({);const ready = doc.status === "completed" && !pending;const [slot, setSlot] = useState<HTMLDivElement | null>(null);- const thumbnail = useDocumentThumbnail(doc, ready, slot);+ const thumbnail = useDocumentThumbnail(doc, ready && !compact, slot);// Every indexed file opens: RagDocumentTrigger picks the browser, the viewer or a new tab.const canOpen = ready;const preview =@@ -464,24 +501,108 @@ function DocumentCard({}/>) : undefined;+ const removable = onRemove && !processing;+ const buttonProps = {+ type: "button",+ disabled: !canOpen,+ title:+ doc.error ??+ (shared+ ? `${doc.filename}: shared with every chat in this project`+ : doc.filename),+ "aria-label": [+ canOpen ? `Preview ${doc.filename}` : doc.filename,+ processing ? `${stageLabel}${percent != null ? ` ${percent}%` : ""}` : null,+ failed ? "couldn't index" : null,+ shared ? "shared with the project" : null,+ ]+ .filter(Boolean)+ .join(", "),+ } as const;+ const removeButton = removable ? (+ <button+ type="button"+ onClick={onRemove}+ aria-label={`Remove ${doc.filename}`}+ className={cn(+ "absolute flex size-5 items-center justify-center rounded-full bg-foreground text-background opacity-0 shadow-sm transition-opacity focus-visible:opacity-100 group-hover/attachment-card:opacity-100 group-focus-within/attachment-card:opacity-100 [@media(pointer:coarse)]:opacity-100",+ compact ? "top-1/2 right-1.5 -translate-y-1/2" : "top-1.5 right-1.5",+ )}+ >+ {/* Inline 12px: the font-scaled svg size rules give 11.25px, an odd inset that sits off centre. */}+ <XIcon className="stroke-[2.5px]" style={{ width: 12, height: 12 }} />+ </button>+ ) : null;+ const wrapDialog = (trigger: ReactElement) =>+ ready ? (+ <RagDocumentTrigger documentId={doc.id} filename={doc.filename}>+ {trigger}+ </RagDocumentTrigger>+ ) : (+ trigger+ );+ if (compact) {+ return (+ <div ref={setSlot} className="unsloth-files-item unsloth-files-pill-item flex shrink-0 items-center gap-1">+ <div className="group/attachment-card relative flex min-w-0">+ {wrapDialog(+ <button+ {...buttonProps}+ className={cn(+ "unsloth-files-pill",+ PILL,+ "text-left disabled:cursor-default",+ CARD_EDGE,+ canOpen && CARD_SURFACE,+ canOpen && "cursor-pointer",+ failed && "border-destructive/40 text-destructive",+ )}+ >+ {processing ? (+ <Spinner className="size-3.5 shrink-0" />+ ) : (+ <AttachmentKindIcon kind={kind} className="size-4 shrink-0" />+ )}+ <span+ className={cn(+ "truncate",+ removable &&+ "group-hover/attachment-card:[mask-image:linear-gradient(to_left,transparent_1.25rem,black_2.5rem)] group-focus-within/attachment-card:[mask-image:linear-gradient(to_left,transparent_1.25rem,black_2.5rem)]",+ )}+ >+ {doc.filename}+ </span>+ {processing && percent != null ? (+ <span className="shrink-0 text-muted-foreground tabular-nums">{percent}%</span>+ ) : null}+ {shared ? (+ <HugeiconsIcon+ icon={Folder02Icon}+ strokeWidth={2}+ className="size-3 shrink-0 text-muted-foreground"+ aria-hidden={true}+ />+ ) : null}+ </button>,+ )}+ {removeButton}+ </div>+ {failed && onRetry ? (+ <button+ type="button"+ onClick={onRetry}+ aria-label={`Retry ${doc.filename}`}+ className="unsloth-files-panel-action h-8 px-3 text-ui-12"+ >+ Retry+ </button>+ ) : null}+ </div>+ );+ }const card = (<button- type="button"- disabled={!canOpen}- title={- doc.error ??- (shared- ? `${doc.filename}: shared with every chat in this project`- : doc.filename)- }- aria-label={[- canOpen ? `Preview ${doc.filename}` : doc.filename,- processing ? `${stageLabel}${percent != null ? ` ${percent}%` : ""}` : null,- failed ? "couldn't index" : null,- shared ? "shared with the project" : null,- ]- .filter(Boolean)- .join(", ")}+ {...buttonProps}className={cn("flex overflow-hidden rounded-[15px] text-left transition-colors disabled:cursor-default",CARD_SIZE,@@ -503,17 +624,11 @@ function DocumentCard({<divref={setSlot}className={cn(- "group/attachment-card relative",+ "unsloth-files-item group/attachment-card relative",CARD_SLOT,)}>- {ready ? (- <RagDocumentTrigger documentId={doc.id} filename={doc.filename}>- {card}- </RagDocumentTrigger>- ) : (- card- )}+ {wrapDialog(card)}{shared ? <ProjectBadge /> : null}{failed && onRetry ? (<button@@ -525,16 +640,7 @@ function DocumentCard({Retry</button>) : null}- {onRemove && !processing ? (- <button- type="button"- onClick={onRemove}- aria-label={`Remove ${doc.filename}`}- className="absolute top-1.5 right-1.5 flex size-5 items-center justify-center rounded-full bg-foreground text-background opacity-0 shadow-sm transition-opacity focus-visible:opacity-100 group-hover/attachment-card:opacity-100 group-focus-within/attachment-card:opacity-100 [@media(pointer:coarse)]:opacity-100"- >- <XIcon className="size-3 stroke-[2.5px]" />- </button>- ) : null}+ {removeButton}</div>);}@@ -546,6 +652,10 @@ function AddFilesCard({disabled: boolean;onClick: () => void;}) {+ const compact = useContext(CompactCardsContext);+ if (compact) {+ return null;+ }return (<div className={CARD_SLOT}><button@@ -595,16 +705,17 @@ function ChatFilesPanel({dropDisabledReason?: string;children?: ReactNode;}) {+ const collapsed = useChatPreferencesStore((s) => s.filesPanelCollapsed);+ const setCollapsed = useChatPreferencesStore((s) => s.setFilesPanelCollapsed);+ // Show all leaves the saved collapse alone, so Show less returns to the cards it started from.+ const [showAll, setShowAll] = useState(false);+ const compact = collapsed || showAll;const stripRef = useRef<HTMLDivElement>(null);- const [scroll, setScroll] = useState({ back: false, forward: false });+ const [overflowing, setOverflowing] = useState(false);const measure = useCallback(() => {const el = stripRef.current;if (!el) return;- const back = el.scrollLeft > 1;- const forward = el.scrollWidth - el.clientWidth - el.scrollLeft > 1;- setScroll((prev) =>- prev.back === back && prev.forward === forward ? prev : { back, forward },- );+ setOverflowing(el.scrollWidth - el.clientWidth > 1);}, []);useLayoutEffect(() => {const el = stripRef.current;@@ -612,20 +723,14 @@ function ChatFilesPanel({measure();const observer = new ResizeObserver(measure);observer.observe(el);- // Adding a card does not resize the strip.+ // Adding a card or swapping cards for pills does not resize the strip.const mutations = new MutationObserver(measure);- mutations.observe(el, { childList: true });+ mutations.observe(el, { childList: true, subtree: true });return () => {observer.disconnect();mutations.disconnect();};}, [measure]);- const page = (direction: 1 | -1) => {- const el = stripRef.current;- if (!el) return;- el.scrollBy({ left: direction * el.clientWidth * 0.8, behavior: "smooth" });- };- const overflowing = scroll.back || scroll.forward;// Drops here are indexed; elsewhere they attach to the message. The page handler skips// prevented drops, and the desktop's window-wide handler skips registered targets.const ignoreDrop = useCallback(() => {}, []);@@ -647,6 +752,7 @@ function ChatFilesPanel({ref={acceptsDrop ? nativeDropTarget : undefined}aria-label={title}className="unsloth-files-panel"+ data-collapsed={children && compact ? "true" : undefined}data-dragging={acceptsDrop && dragging ? "true" : undefined}{...(acceptsDrop ? dropProps : {})}>@@ -686,27 +792,25 @@ function ChatFilesPanel({{note}<div className="ml-auto flex shrink-0 items-center gap-1">{headerControls}- {overflowing ? (- <>- <button- type="button"- className="unsloth-files-panel-icon-btn"- onClick={() => page(-1)}- disabled={!scroll.back}- aria-label="Scroll files back"- >- <ChevronLeftIcon className="size-4" />- </button>- <button- type="button"- className="unsloth-files-panel-icon-btn"- onClick={() => page(1)}- disabled={!scroll.forward}- aria-label="Scroll files forward"- >- <ChevronRightIcon className="size-4" />- </button>- </>+ {children ? (+ <button+ type="button"+ // A narrow glyph: 4px from Add files reads as crowded next to the X.+ className="unsloth-files-panel-icon-btn ml-3"+ onClick={() => {+ setCollapsed(!compact);+ setShowAll(false);+ }}+ aria-expanded={!compact}+ aria-label={compact ? "Expand files" : "Collapse files"}+ title={compact ? "Expand files" : "Collapse files"}+ >+ <HugeiconsIcon+ icon={compact ? ChevronDownStandardIcon : ChevronUpStandardIcon}+ strokeWidth={1.75}+ style={HEADER_ICON}+ />+ </button>) : null}{onClose ? (<button@@ -716,18 +820,42 @@ function ChatFilesPanel({aria-label={closeLabel ?? "Close"}title={closeLabel}>- <XIcon className="size-4" />+ <XIcon style={HEADER_ICON} /></button>) : null}</div></div>{children ? (- <div- ref={stripRef}- onScroll={measure}- className="unsloth-files-panel-strip"- >- {children}+ <div className="unsloth-files-panel-row" data-show-all={showAll ? "true" : undefined}>+ <div+ ref={stripRef}+ className="unsloth-files-panel-strip"+ data-show-all={showAll ? "true" : undefined}+ >+ <CompactCardsContext.Provider value={compact}>+ {children}+ </CompactCardsContext.Provider>+ {showAll ? (+ <button+ type="button"+ className="unsloth-files-panel-action"+ aria-expanded={true}+ onClick={() => setShowAll(false)}+ >+ Show less+ </button>+ ) : null}+ </div>+ {overflowing && !showAll ? (+ <button+ type="button"+ className="unsloth-files-panel-show-all"+ aria-expanded={false}+ onClick={() => setShowAll(true)}+ >+ Show all+ </button>+ ) : null}</div>) : null}</section>diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.cssindex 58d6f8040b7..b6926640a7f 100644--- a/studio/frontend/src/index.css+++ b/studio/frontend/src/index.css@@ -6228,15 +6228,58 @@ html[data-find-bar-open] [data-sonner-toaster][data-y-position="top"] {.aui-composer-root:has(.unsloth-files-panel[data-dragging="true"]) .aui-composer-drop-overlay {opacity: 0 !important;}+.unsloth-files-panel-row {+ @apply relative flex items-center;+}+.unsloth-files-panel-row:has(.unsloth-files-panel-strip:empty) {+ display: none;+}/* Inset at rest; cards scroll under the panel edges. */.unsloth-files-panel-strip {- @apply -mx-4 flex flex-row flex-nowrap gap-2 overflow-x-auto overscroll-x-contain px-4;+ @apply -mx-4 flex min-w-0 flex-1 flex-row flex-nowrap gap-2 overflow-x-auto overscroll-x-contain px-4;scroll-padding-inline: 1rem;scrollbar-width: none;}.unsloth-files-panel-strip::-webkit-scrollbar {display: none;}+.unsloth-files-panel[data-collapsed="true"] {+ @apply gap-2.5 pt-3 pb-3;+}+/* Dropdown-surface look. Hover washes over the solid fill, never replaces it (it would turn see-through). */+.unsloth-files-panel-show-all {+ @apply pointer-events-none absolute top-1/2 right-0 z-10 inline-flex h-8 -translate-y-1/2 items-center rounded-full px-3.5 text-ui-13 text-popover-foreground opacity-0 transition-opacity;+ background-color: var(--popover);+ box-shadow: 0 2px 8px -2px rgba(0, 0, 0, 0.16);+}+.dark .unsloth-files-panel-show-all {+ box-shadow: none;+}+.unsloth-files-panel:not([data-collapsed]) .unsloth-files-panel-show-all {+ top: calc(100% - 0.75rem);+}+.unsloth-files-panel-show-all:hover {+ background-image: linear-gradient(+ rgb(0 0 0 / calc(0.06 * var(--contrast-wash-gain, 1))),+ rgb(0 0 0 / calc(0.06 * var(--contrast-wash-gain, 1)))+ );+}+.unsloth-files-panel-row:has(> .unsloth-files-panel-strip:hover) > .unsloth-files-panel-show-all,+.unsloth-files-panel-show-all:is(:hover, :focus-visible) {+ @apply pointer-events-auto opacity-100;+}+@media (pointer: coarse) {+ .unsloth-files-panel-show-all {+ @apply pointer-events-auto opacity-100;+ }+}+.unsloth-files-panel-strip[data-show-all="true"] {+ @apply max-h-[40dvh] flex-wrap overflow-x-hidden overflow-y-auto;+}+.unsloth-files-panel-strip[data-show-all="true"] .unsloth-files-pill {+ @apply max-w-[calc(14rem*var(--ui-space-scale,1))];+}+.unsloth-files-panel-action {@apply inline-flex h-8 shrink-0 items-center rounded-full border px-3.5 text-ui-13 text-foreground transition-colors disabled:pointer-events-none disabled:opacity-50;border-color: color-mix(in oklab, var(--foreground) 14%, transparent);@@ -6248,16 +6291,24 @@ html[data-find-bar-open] [data-sonner-toaster][data-y-position="top"] {@apply pointer-events-none opacity-50;}/* Dark mode: Add files is a fill, not an outline. */-.dark .unsloth-files-panel-action,.dark .unsloth-files-add-card {border-color: transparent;background-color: color-mix(in oklab, var(--foreground) 8%, transparent);}-.dark .unsloth-files-panel-action:hover,.dark .unsloth-files-add-card:hover {border-color: transparent;background-color: color-mix(in oklab, var(--foreground) 12%, transparent);}+.dark :is(.unsloth-files-panel-action, .unsloth-files-panel-show-all) {+ border-color: transparent;+ background-color: color-mix(in srgb, var(--card), white 10%);+ background-image: none;+}+.dark :is(.unsloth-files-panel-action, .unsloth-files-panel-show-all):hover {+ border-color: transparent;+ background-color: color-mix(in srgb, var(--card), white 15%);+ background-image: none;+}.unsloth-files-panel-icon-btn {@apply inline-flex size-8 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-35;}diff --git a/studio/frontend/tests/project-sources-model-without-tools.test.ts b/studio/frontend/tests/project-sources-model-without-tools.test.tsindex 13b8200a520..bd33d99bdc4 100644--- a/studio/frontend/tests/project-sources-model-without-tools.test.ts+++ b/studio/frontend/tests/project-sources-model-without-tools.test.ts@@ -102,6 +102,11 @@ const { ThreadDocumentsBar } = loadWithStubs<typeof BarModule>(readPendingAttachmentTargetClaim: () => null,useChatRuntimeStore,},+ "@/features/chat/stores/chat-preferences-store": {+ useChatPreferencesStore: (+ select: (s: { filesPanelCollapsed: boolean; setFilesPanelCollapsed: () => void }) => unknown,+ ) => select({ filesPanelCollapsed: false, setFilesPanelCollapsed: () => {} }),+ },"@/features/chat/hooks/use-rag-tool-disabled": gate,"@/features/chat": chatStub,"@/components/file-viewer": fileViewerStub,diff --git a/studio/frontend/tests/rag-thread-initialization.test.ts b/studio/frontend/tests/rag-thread-initialization.test.tsindex 24d80bf7eac..255760f2127 100644--- a/studio/frontend/tests/rag-thread-initialization.test.ts+++ b/studio/frontend/tests/rag-thread-initialization.test.ts@@ -133,6 +133,8 @@ function harness(},];},+ createContext: (value: unknown) => ({ Provider: () => null, value }),+ useContext: (context: { value: unknown }) => context.value,useCallback: (fn: unknown) => fn,useMemo: (fn: () => unknown) => fn(),useEffect(effect: () => void, deps: unknown[]) {@@ -172,6 +174,11 @@ function harness(useChatRuntimeStore: store,readPendingAttachmentTargetClaim: () => null,},+ "@/features/chat/stores/chat-preferences-store": {+ useChatPreferencesStore: (+ select: (s: { filesPanelCollapsed: boolean; setFilesPanelCollapsed: () => void }) => unknown,+ ) => select({ filesPanelCollapsed: false, setFilesPanelCollapsed: () => {} }),+ },"@/features/chat/hooks/use-rag-tool-disabled": {useRagToolDisabled: () => false,},