Skip to content

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.

Studio: proportional image attachments, attachment card and Chat with files polish (#13970)

Michael Hanaafc3dfda1f2
diff --git a/studio/frontend/src/components/assistant-ui/attachment.tsx b/studio/frontend/src/components/assistant-ui/attachment.tsx
index 965b57eb194..ac990c725da 100644
--- a/studio/frontend/src/components/assistant-ui/attachment.tsx
+++ b/studio/frontend/src/components/assistant-ui/attachment.tsx
@@ -77,8 +77,11 @@ import {
import { ScrollPane } from "./scroll-pane";
export const CARD_SLOT =
- "shrink-0 w-[calc((100%_-_var(--spacing)*8)/5)] min-w-[calc(7rem*var(--ui-space-scale,1))]";
+ "shrink-0 w-[calc((100%_-_var(--spacing)*6)/4.15)] min-w-[calc(7.5rem*var(--ui-space-scale,1))]";
export const CARD_SIZE = "h-[calc(7rem*var(--ui-space-scale,1))] w-full";
+// The Library's thumbnail bounds; an image card keeps the row's height, past these it is cropped.
+const MIN_IMAGE_RATIO = 2 / 3;
+const MAX_IMAGE_RATIO = 3 / 2;
const SENT_IMAGE_SIZE = "size-[calc(9rem*var(--ui-space-scale,1))]";
const SENT_IMAGE_SIZE_COMPACT = "size-[calc(5rem*var(--ui-space-scale,1))]";
const SENT_ROW_WIDTH = "w-[calc(18rem*var(--ui-space-scale,1))]";
@@ -137,7 +140,7 @@ const FileCardBody: FC<{
) : (
<CardCenter>{center}</CardCenter>
)}
- <span className={cn("flex min-w-0 items-center gap-1.5 px-2.25 pb-[calc(var(--spacing)*1.75-0.5px)]", preview && "pt-1.25")}>
+ <span className={cn("flex min-w-0 items-center gap-1.5 px-2.25 pb-[calc(var(--spacing)*1.75-1px)]", preview && "pt-[calc(var(--spacing)*1.75-3px)]")}>
{icon ?? <AttachmentKindIcon kind={kind} className="size-3.25" />}
<span className="min-w-0 truncate text-ui-11p5 leading-ui-15 text-foreground">
{name}
@@ -146,18 +149,24 @@ const FileCardBody: FC<{
</span>
);
-const CardImageOrBody: FC<{ name: string; kind: AttachmentFileKind; src: string | undefined }> = ({
- name,
- kind,
- src,
-}) => {
+const CardImageOrBody: FC<{
+ name: string;
+ kind: AttachmentFileKind;
+ src: string | undefined;
+ /** Width over height, once the image has decoded. */
+ onRatio?: (ratio: number) => void;
+}> = ({ name, kind, src, onRatio }) => {
const file = useAuiState(({ attachment }) => (attachment as { file?: File }).file);
if (src) {
return (
<img
src={src}
alt={name || "Attachment preview"}
- className="h-full w-full object-cover"
+ onLoad={(event) => {
+ const { naturalWidth, naturalHeight } = event.currentTarget;
+ if (naturalWidth > 0 && naturalHeight > 0) onRatio?.(naturalWidth / naturalHeight);
+ }}
+ className="h-full w-full object-cover object-top"
/>
);
}
@@ -507,6 +516,7 @@ const ComposerAttachmentCard: FC = () => {
const src = useAttachmentImageSrc();
const attachmentId = useAuiState(({ attachment }) => attachment.id);
const { name, kind } = useAttachmentKind();
+ const [ratio, setRatio] = useState<number | null>(null);
if (annotations) {
return (
@@ -532,7 +542,17 @@ const ComposerAttachmentCard: FC = () => {
return (
<AttachmentPrimitive.Root
key={attachmentId}
- className={cn("aui-attachment-root aui-attachment-card group/attachment-card relative", CARD_SLOT)}
+ className={cn(
+ "aui-attachment-root aui-attachment-card group/attachment-card relative",
+ src ? "shrink-0" : CARD_SLOT,
+ )}
+ style={
+ src
+ ? {
+ width: `calc(7rem * var(--ui-space-scale, 1) * ${Math.min(Math.max(ratio ?? 1, MIN_IMAGE_RATIO), MAX_IMAGE_RATIO)})`,
+ }
+ : undefined
+ }
>
<AttachmentPreviewDialog redactFromReload={true}>
<button
@@ -546,7 +566,7 @@ const ComposerAttachmentCard: FC = () => {
title={name}
aria-label={name ? `${label} attachment: ${name}` : `${label} attachment`}
>
- <CardImageOrBody name={name} kind={kind} src={src} />
+ <CardImageOrBody name={name} kind={kind} src={src} onRatio={setRatio} />
</button>
</AttachmentPreviewDialog>
<AttachmentCardRemove />
@@ -733,16 +753,14 @@ export const ComposerAttachments: FC<{
const el = ref.current;
if (!el) return;
const layout = () => {
- const card = el.firstElementChild as HTMLElement | null;
const style = getComputedStyle(el);
const width =
el.clientWidth -
Number.parseFloat(style.paddingLeft) -
Number.parseFloat(style.paddingRight);
const strip = composerAttachmentsOverflow(
- count,
+ [...el.children].map((card) => card.getBoundingClientRect().width),
width,
- card?.getBoundingClientRect().width ?? 0,
Number.parseFloat(style.columnGap) || 0,
maxRows,
);
@@ -754,8 +772,10 @@ export const ComposerAttachments: FC<{
el.scrollLeft = el.scrollWidth;
}
previousCount.current = count;
+ // An image card widens to its proportions once it decodes, without resizing the row.
const observer = new ResizeObserver(layout);
observer.observe(el);
+ for (const card of el.children) observer.observe(card);
const onWheel = (event: WheelEvent) => {
if (el.dataset.layout !== "strip") return;
if (Math.abs(event.deltaY) <= Math.abs(event.deltaX)) return;
diff --git a/studio/frontend/src/features/browser/browser-toggle.tsx b/studio/frontend/src/features/browser/browser-toggle.tsx
index 323ae02da8b..628230d09b2 100644
--- a/studio/frontend/src/features/browser/browser-toggle.tsx
+++ b/studio/frontend/src/features/browser/browser-toggle.tsx
@@ -126,13 +126,18 @@ export function BrowserToggleButton({ active = true }: { active?: boolean }) {
<DropdownMenuItem onSelect={() => openTab()}>
<HugeiconsIcon icon={Add01Icon} strokeWidth={1.75} className="size-icon" />
{label}
- {newTabShortcut ? <DropdownMenuShortcut>{newTabShortcut}</DropdownMenuShortcut> : null}
+ {newTabShortcut ? <DropdownMenuShortcut className="text-ui-11">{newTabShortcut}</DropdownMenuShortcut> : null}
</DropdownMenuItem>
<DropdownMenuItem onSelect={() => openTab(true)}>
- <HugeiconsIcon icon={EnterFullViewIcon} strokeWidth={1.75} className="size-icon" />
+ {/* Its corner marks sit inside the box, so at the shared size it reads smaller than the plus. */}
+ <HugeiconsIcon
+ icon={EnterFullViewIcon}
+ strokeWidth={1.75}
+ className="size-[calc(var(--icon-size)*1.2)] -mx-[calc(var(--icon-size)*0.1)]"
+ />
{t("browser.newTabFullView")}
{fullViewShortcut ? (
- <DropdownMenuShortcut>{fullViewShortcut}</DropdownMenuShortcut>
+ <DropdownMenuShortcut className="text-ui-11">{fullViewShortcut}</DropdownMenuShortcut>
) : null}
</DropdownMenuItem>
</DropdownMenuContent>
diff --git a/studio/frontend/src/features/chat/lib/attachment-layout.ts b/studio/frontend/src/features/chat/lib/attachment-layout.ts
index 04023f15388..68ec0d87f7e 100644
--- a/studio/frontend/src/features/chat/lib/attachment-layout.ts
+++ b/studio/frontend/src/features/chat/lib/attachment-layout.ts
@@ -20,14 +20,22 @@ export function sentAttachmentLayout(
}
export function composerAttachmentsOverflow(
- count: number,
+ cardWidths: readonly number[],
width: number,
- cardWidth: number,
gap: number,
maxRows: number = COMPOSER_ATTACHMENT_MAX_ROWS,
): boolean {
- if (count === 0 || cardWidth <= 0) return false;
- // Cards sized to a fifth of the row divide it exactly; the slack absorbs subpixel rounding.
- const perRow = Math.max(1, Math.floor((width + gap) / (cardWidth + gap) + 0.01));
- return Math.ceil(count / perRow) > maxRows;
+ // Wraps as flex-wrap does; the slack absorbs subpixel rounding of cards that divide the row exactly.
+ let rows = 1;
+ let used = 0;
+ for (const card of cardWidths) {
+ if (card <= 0) continue;
+ if (used > 0 && used + gap + card > width + 0.5) {
+ rows += 1;
+ used = card;
+ } else {
+ used += (used > 0 ? gap : 0) + card;
+ }
+ }
+ return rows > maxRows;
}
diff --git a/studio/frontend/src/features/rag/components/thread-documents-bar.tsx b/studio/frontend/src/features/rag/components/thread-documents-bar.tsx
index 736d78e540e..c6b65e8767b 100644
--- a/studio/frontend/src/features/rag/components/thread-documents-bar.tsx
+++ b/studio/frontend/src/features/rag/components/thread-documents-bar.tsx
@@ -806,7 +806,8 @@ function ChatFilesPanel({
title={compact ? "Expand files" : "Collapse files"}
>
<HugeiconsIcon
- icon={compact ? ChevronDownStandardIcon : ChevronUpStandardIcon}
+ // The panel opens upward from the composer, so up expands and down collapses.
+ icon={compact ? ChevronUpStandardIcon : ChevronDownStandardIcon}
strokeWidth={1.75}
style={HEADER_ICON}
/>
diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.css
index 979df6b6f68..71bc9e44c2a 100644
--- a/studio/frontend/src/index.css
+++ b/studio/frontend/src/index.css
@@ -6281,7 +6281,7 @@ html[data-find-bar-open] [data-sonner-toaster][data-y-position="top"] {
}
.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;
+ @apply inline-flex h-7 shrink-0 items-center rounded-full border px-3 text-ui-12 text-foreground transition-colors disabled:pointer-events-none disabled:opacity-50;
border-color: color-mix(in oklab, var(--foreground) 14%, transparent);
}
.unsloth-files-panel-action:hover {
diff --git a/studio/frontend/tests/chat-attachment-display.test.ts b/studio/frontend/tests/chat-attachment-display.test.ts
index 821a38888a7..fc1760c8366 100644
--- a/studio/frontend/tests/chat-attachment-display.test.ts
+++ b/studio/frontend/tests/chat-attachment-display.test.ts
@@ -94,19 +94,23 @@ test("Auto lists up to six sent files, then collapses them to chips", () => {
test("composer cards wrap for two rows, then become one scrolling strip", () => {
assert.equal(COMPOSER_ATTACHMENT_MAX_ROWS, 2);
- const fifth = (724 - 4 * 8) / 5;
- assert.equal(composerAttachmentsOverflow(10, 724, fifth, 8), false);
- assert.equal(composerAttachmentsOverflow(11, 724, fifth, 8), true);
- assert.equal(composerAttachmentsOverflow(10, 724, fifth + 0.004, 8), false);
- assert.equal(composerAttachmentsOverflow(7, 300, 105, 8), true);
- assert.equal(composerAttachmentsOverflow(0, 724, fifth, 8), false);
- assert.equal(composerAttachmentsOverflow(20, 724, 0, 8), false);
- // In a chat the strip allows one row: a sixth card at a fifth of the width already scrolls.
- assert.equal(composerAttachmentsOverflow(5, 724, fifth, 8, 1), false);
- assert.equal(composerAttachmentsOverflow(6, 724, fifth, 8, 1), true);
+ const quarter = (724 - 3 * 8) / 4;
+ const cards = (n: number, w = quarter) => Array.from({ length: n }, () => w);
+ assert.equal(composerAttachmentsOverflow(cards(8), 724, 8), false);
+ assert.equal(composerAttachmentsOverflow(cards(9), 724, 8), true);
+ assert.equal(composerAttachmentsOverflow(cards(8, quarter + 0.004), 724, 8), false);
+ assert.equal(composerAttachmentsOverflow(cards(7, 105), 300, 8), true);
+ assert.equal(composerAttachmentsOverflow([], 724, 8), false);
+ assert.equal(composerAttachmentsOverflow(cards(20, 0), 724, 8), false);
+ // In a chat the strip allows one row: a fifth card at a quarter of the width already scrolls.
+ assert.equal(composerAttachmentsOverflow(cards(4), 724, 8, 1), false);
+ assert.equal(composerAttachmentsOverflow(cards(5), 724, 8, 1), true);
+ // Image cards take their own widths.
+ assert.equal(composerAttachmentsOverflow(cards(8, 75), 724, 8, 1), false);
+ assert.equal(composerAttachmentsOverflow([168, 168, 168, 168, 75], 724, 8, 1), true);
assert.match(
ATTACHMENT,
- /const CARD_SLOT =\n\s*"shrink-0 w-\[calc\(\(100%_-_var\(--spacing\)\*8\)\/5\)\] min-w-\[calc\(7rem\*var\(--ui-space-scale,1\)\)\]";/,
+ /const CARD_SLOT =\n\s*"shrink-0 w-\[calc\(\(100%_-_var\(--spacing\)\*6\)\/4\.15\)\] min-w-\[calc\(7\.5rem\*var\(--ui-space-scale,1\)\)\]";/,
);
assert.match(
ATTACHMENT,
@@ -114,7 +118,7 @@ test("composer cards wrap for two rows, then become one scrolling strip", () =>
);
assert.match(
ATTACHMENT,
- /className=\{cn\("aui-attachment-root aui-attachment-card group\/attachment-card relative", CARD_SLOT\)\}/,
+ /"aui-attachment-root aui-attachment-card group\/attachment-card relative",\n\s*src \? "shrink-0" : CARD_SLOT,/,
);
assert.match(
ATTACHMENT,
@@ -380,7 +384,11 @@ test("an image card in the composer shares the file card border but has no fill"
assert.match(card, /CARD_EDGE,\n\s*!src && CARD_SURFACE,/);
assert.match(
card,
- /<CardImageOrBody name=\{name\} kind=\{kind\} src=\{src\} \/>/,
+ /Math\.min\(Math\.max\(ratio \?\? 1, MIN_IMAGE_RATIO\), MAX_IMAGE_RATIO\)/,
+ );
+ assert.match(
+ card,
+ /<CardImageOrBody name=\{name\} kind=\{kind\} src=\{src\} onRatio=\{setRatio\} \/>/,
);
});