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: one scrolling attachment row once a chat has messages; even the gap above the composer input (#13678)

Michael Han5d1aa4217de4
diff --git a/studio/frontend/src/components/assistant-ui/attachment.tsx b/studio/frontend/src/components/assistant-ui/attachment.tsx
index 15190175443..26a2a113dbb 100644
--- a/studio/frontend/src/components/assistant-ui/attachment.tsx
+++ b/studio/frontend/src/components/assistant-ui/attachment.tsx
@@ -26,6 +26,7 @@ import {
PASTED_TEXT_PREVIEW_MAX_CHARS,
attachmentFileKind,
attachmentKindLabel,
+ COMPOSER_ATTACHMENT_MAX_ROWS,
composerAttachmentsOverflow,
sentAttachmentLayout,
type AttachmentFileKind,
@@ -718,8 +719,14 @@ export const UserMessageAttachments: FC = () => {
};
// The layout decision is a DOM data attribute, never state, so a resize or new card re-renders no card.
-export const ComposerAttachments: FC<{ className?: string }> = ({ className }) => {
+export const ComposerAttachments: FC<{
+ className?: string;
+ /** One scrolling row once the thread has messages, so the strip does not push the reply up. */
+ oneRowInChat?: boolean;
+}> = ({ className, oneRowInChat = false }) => {
const count = useAuiState(({ composer }) => composer.attachments.length);
+ const inChat = useAuiState(({ thread }) => !thread.isEmpty);
+ const maxRows = oneRowInChat && inChat ? 1 : COMPOSER_ATTACHMENT_MAX_ROWS;
const ref = useRef<HTMLDivElement | null>(null);
const previousCount = useRef(count);
@@ -738,6 +745,7 @@ export const ComposerAttachments: FC<{ className?: string }> = ({ className }) =
width,
card?.getBoundingClientRect().width ?? 0,
Number.parseFloat(style.columnGap) || 0,
+ maxRows,
);
const next = strip ? "strip" : "wrap";
if (el.dataset.layout !== next) el.dataset.layout = next;
@@ -763,14 +771,14 @@ export const ComposerAttachments: FC<{ className?: string }> = ({ className }) =
observer.disconnect();
el.removeEventListener("wheel", onWheel);
};
- }, [count]);
+ }, [count, maxRows]);
return (
<div
ref={ref}
data-reload-snapshot-sensitive
className={cn(
- "aui-composer-attachments aui-composer-attachment-cards mb-4 flex w-full flex-row flex-wrap gap-2 px-1.5 pt-0.5 pb-1 empty:hidden data-[layout=strip]:flex-nowrap data-[layout=strip]:overflow-x-auto data-[layout=strip]:overscroll-x-contain",
+ "aui-composer-attachments aui-composer-attachment-cards mb-[calc(0.5rem*var(--ui-space-scale,1))] flex w-full flex-row flex-wrap gap-2 px-1.5 pt-0.5 pb-1 empty:hidden data-[layout=strip]:flex-nowrap data-[layout=strip]:overflow-x-auto data-[layout=strip]:overscroll-x-contain",
className,
)}
>
diff --git a/studio/frontend/src/components/assistant-ui/thread.tsx b/studio/frontend/src/components/assistant-ui/thread.tsx
index 74c282f8070..47e4668b7bb 100644
--- a/studio/frontend/src/components/assistant-ui/thread.tsx
+++ b/studio/frontend/src/components/assistant-ui/thread.tsx
@@ -5656,7 +5656,7 @@ const Composer: FC<{
<>
{!isDictating ? (
<>
- <ComposerAttachments />
+ <ComposerAttachments oneRowInChat={true} />
<PendingAudioChip />
</>
) : null}
diff --git a/studio/frontend/src/features/chat/lib/attachment-layout.ts b/studio/frontend/src/features/chat/lib/attachment-layout.ts
index 69807acf10f..04023f15388 100644
--- a/studio/frontend/src/features/chat/lib/attachment-layout.ts
+++ b/studio/frontend/src/features/chat/lib/attachment-layout.ts
@@ -24,9 +24,10 @@ export function composerAttachmentsOverflow(
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) > COMPOSER_ATTACHMENT_MAX_ROWS;
+ return Math.ceil(count / perRow) > maxRows;
}
diff --git a/studio/frontend/tests/chat-attachment-display.test.ts b/studio/frontend/tests/chat-attachment-display.test.ts
index 29297a6311f..c6070089ffe 100644
--- a/studio/frontend/tests/chat-attachment-display.test.ts
+++ b/studio/frontend/tests/chat-attachment-display.test.ts
@@ -1,7 +1,6 @@
// 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 assert from "node:assert/strict";
import test from "node:test";
@@ -57,7 +56,11 @@ test("each file kind is read off the name, with a decisive MIME type first", ()
["notes", "text/plain", "text"],
];
for (const [name, mime, kind] of cases) {
- assert.equal(attachmentFileKind(name, mime), kind, `${name} (${mime || "no type"})`);
+ assert.equal(
+ attachmentFileKind(name, mime),
+ kind,
+ `${name} (${mime || "no type"})`,
+ );
}
assert.equal(attachmentFileKind("recording.txt", "audio/wav"), "audio");
assert.equal(attachmentFileKind("x.constructor", ""), "file");
@@ -98,19 +101,32 @@ test("composer cards wrap for two rows, then become one scrolling strip", () =>
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);
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\)\)\]";/,
);
- assert.match(ATTACHMENT, /const CARD_SIZE = "h-\[calc\(7rem\*var\(--ui-space-scale,1\)\)\] w-full";/);
- assert.match(ATTACHMENT, /className=\{cn\("aui-attachment-root aui-attachment-card group\/attachment-card relative", CARD_SLOT\)\}/);
- assert.match(ATTACHMENT, /variant === "card" && cn\("group\/attachment-card", CARD_SLOT\)/);
+ assert.match(
+ ATTACHMENT,
+ /const CARD_SIZE = "h-\[calc\(7rem\*var\(--ui-space-scale,1\)\)\] w-full";/,
+ );
+ assert.match(
+ ATTACHMENT,
+ /className=\{cn\("aui-attachment-root aui-attachment-card group\/attachment-card relative", CARD_SLOT\)\}/,
+ );
+ assert.match(
+ ATTACHMENT,
+ /variant === "card" && cn\("group\/attachment-card", CARD_SLOT\)/,
+ );
assert.match(ATTACHMENT, /aui-composer-attachment-cards [^"]*\bgap-2\b/);
});
test("cards keep their hairline edge in dark mode", () => {
const edge = /const CARD_EDGE =\n\s*"([^"]*)";/.exec(ATTACHMENT)?.[1] ?? "";
- const surface = /const CARD_SURFACE =\n\s*"([^"]*)";/.exec(ATTACHMENT)?.[1] ?? "";
+ const surface =
+ /const CARD_SURFACE =\n\s*"([^"]*)";/.exec(ATTACHMENT)?.[1] ?? "";
assert.match(edge, /^border border-\[/);
assert.doesNotMatch(edge + surface, /dark:/);
});
@@ -122,7 +138,8 @@ test("the strip is laid out through the DOM, never through React state", () => {
);
assert.match(strip, /el\.dataset\.layout = next/);
assert.doesNotMatch(strip, /useState/);
- assert.match(strip, /\}, \[count\]\);/);
+ // maxRows flips once, when the first message lands; resizes still go through the observer.
+ assert.match(strip, /\}, \[count, maxRows\]\);/);
assert.match(strip, /new ResizeObserver\(layout\)/);
});
@@ -141,8 +158,14 @@ test("sent attachments split images from files by type, with stable component ma
test("the sent attachments setting defaults to auto and rejects anything else", () => {
assert.equal(DEFAULT_CUSTOMIZATION.sentAttachments, "auto");
- assert.equal(sanitizeCustomization({ sentAttachments: "chips" }).sentAttachments, "chips");
- assert.equal(sanitizeCustomization({ sentAttachments: 7 }).sentAttachments, "auto");
+ assert.equal(
+ sanitizeCustomization({ sentAttachments: "chips" }).sentAttachments,
+ "chips",
+ );
+ assert.equal(
+ sanitizeCustomization({ sentAttachments: 7 }).sentAttachments,
+ "auto",
+ );
});
test("the sent attachments options read as Standard and Compact", () => {
@@ -160,7 +183,10 @@ test("the composer always shows attachments as cards", () => {
ATTACHMENT,
/<ComposerPrimitive\.Attachments components=\{CARD_COMPONENTS\} \/>/,
);
- assert.doesNotMatch(ATTACHMENT, /COMPACT_COMPONENTS|const AttachmentUI\b|aui-pasted-text-chip/);
+ assert.doesNotMatch(
+ ATTACHMENT,
+ /COMPACT_COMPONENTS|const AttachmentUI\b|aui-pasted-text-chip/,
+ );
assert.doesNotMatch(ATTACHMENT, /customization\.composerAttachments/);
});
@@ -169,22 +195,47 @@ test("audio or video attached before a model loaded is checked when sent", () =>
const textOnly = { hasAudioInput: false, hasVideoInput: false };
const base = { checkpoint: "unsloth/model", modelLabel: "Model" };
assert.equal(
- attachedMediaUnavailableReason({ ...base, activeModel: listener, audio: true, video: false }),
+ attachedMediaUnavailableReason({
+ ...base,
+ activeModel: listener,
+ audio: true,
+ video: false,
+ }),
null,
);
assert.match(
- attachedMediaUnavailableReason({ ...base, activeModel: textOnly, audio: true, video: false }) ?? "",
+ attachedMediaUnavailableReason({
+ ...base,
+ activeModel: textOnly,
+ audio: true,
+ video: false,
+ }) ?? "",
/^Model cannot accept audio\./,
);
assert.match(
- attachedMediaUnavailableReason({ ...base, activeModel: listener, audio: false, video: true }) ?? "",
+ attachedMediaUnavailableReason({
+ ...base,
+ activeModel: listener,
+ audio: false,
+ video: true,
+ }) ?? "",
/^Model cannot accept video\./,
);
assert.ok(
- attachedMediaUnavailableReason({ ...base, activeModel: undefined, audio: true, video: false }),
+ attachedMediaUnavailableReason({
+ ...base,
+ activeModel: undefined,
+ audio: true,
+ video: false,
+ }),
);
assert.equal(
- attachedMediaUnavailableReason({ ...base, activeModel: textOnly, audio: false, video: false }),
+ attachedMediaUnavailableReason({
+ ...base,
+ activeModel: textOnly,
+ audio: false,
+ video: false,
+ }),
null,
);
assert.equal(
@@ -204,15 +255,33 @@ test("several clips are sent to GGUF and transformers, but refused on MLX", () =
const gguf = { hasAudioInput: true, isMlx: false };
const mlx = { hasAudioInput: true, isMlx: true };
assert.equal(
- attachedMediaUnavailableReason({ ...base, activeModel: gguf, audio: true, audioCount: 3, video: false }),
+ attachedMediaUnavailableReason({
+ ...base,
+ activeModel: gguf,
+ audio: true,
+ audioCount: 3,
+ video: false,
+ }),
null,
);
assert.equal(
- attachedMediaUnavailableReason({ ...base, activeModel: mlx, audio: true, audioCount: 1, video: false }),
+ attachedMediaUnavailableReason({
+ ...base,
+ activeModel: mlx,
+ audio: true,
+ audioCount: 1,
+ video: false,
+ }),
null,
);
assert.match(
- attachedMediaUnavailableReason({ ...base, activeModel: mlx, audio: true, audioCount: 2, video: false }) ?? "",
+ attachedMediaUnavailableReason({
+ ...base,
+ activeModel: mlx,
+ audio: true,
+ audioCount: 2,
+ video: false,
+ }) ?? "",
/^Gemma takes one audio file per message\./,
);
});
@@ -247,8 +316,12 @@ test("attaching no longer needs a loaded model, only a capable one when one is l
});
test("every attachment opens in the Library's viewer, from the composer and from a message", async () => {
- const preview = await readSrcAsync("components/assistant-ui/attachment-preview.tsx");
- const viewer = await readSrcAsync("components/assistant-ui/attachment-document-dialog.tsx");
+ const preview = await readSrcAsync(
+ "components/assistant-ui/attachment-preview.tsx",
+ );
+ const viewer = await readSrcAsync(
+ "components/assistant-ui/attachment-document-dialog.tsx",
+ );
for (const dialog of [
"ImageGalleryDialog",
"AttachmentTextDialog",
@@ -271,7 +344,10 @@ test("files handed to a new chat wait until it is on screen", async () => {
const fn = start.slice(start.indexOf("export function startLibraryChat("));
const navigate = fn.indexOf('navigate({ to: "/chat"');
const offer = fn.indexOf(".offer(");
- assert.ok(navigate !== -1 && offer > navigate, "the files are offered before the new chat opens");
+ assert.ok(
+ navigate !== -1 && offer > navigate,
+ "the files are offered before the new chat opens",
+ );
assert.match(fn, /\.then\(\(\) => \{\n\s*requestAnimationFrame\(/);
});
@@ -282,23 +358,41 @@ test("an image card in the composer shares the file card border but has no fill"
);
assert.match(card, /const src = useAttachmentImageSrc\(\);/);
assert.match(card, /CARD_EDGE,\n\s*!src && CARD_SURFACE,/);
- assert.match(card, /<CardImageOrBody name=\{name\} kind=\{kind\} src=\{src\} \/>/);
+ assert.match(
+ card,
+ /<CardImageOrBody name=\{name\} kind=\{kind\} src=\{src\} \/>/,
+ );
});
test("an attachment's viewer mounts on first open, not with every tile", async () => {
- const viewer = await readSrcAsync("components/assistant-ui/attachment-document-dialog.tsx");
- assert.match(viewer, /const \[mounted, setMounted\] = useState\(open\);\n\s*if \(open && !mounted\) setMounted\(true\);/);
+ const viewer = await readSrcAsync(
+ "components/assistant-ui/attachment-document-dialog.tsx",
+ );
+ assert.match(
+ viewer,
+ /const \[mounted, setMounted\] = useState\(open\);\n\s*if \(open && !mounted\) setMounted\(true\);/,
+ );
assert.match(viewer, /\{mounted && \(\n\s*<MediaViewer/);
});
test("the viewer's chat and download report a file they could not read", async () => {
- const viewer = await readSrcAsync("components/assistant-ui/attachment-document-dialog.tsx");
- assert.match(viewer, /\.catch\(\(\) => toast\.error\(`Could not read \$\{name\}`\)\)/);
- assert.match(viewer, /\.catch\(\(\) => toast\.error\(t\("library\.toast\.downloadFailed", \{ name \}\)\)\)/);
+ const viewer = await readSrcAsync(
+ "components/assistant-ui/attachment-document-dialog.tsx",
+ );
+ assert.match(
+ viewer,
+ /\.catch\(\(\) => toast\.error\(`Could not read \$\{name\}`\)\)/,
+ );
+ assert.match(
+ viewer,
+ /\.catch\(\(\) => toast\.error\(t\("library\.toast\.downloadFailed", \{ name \}\)\)\)/,
+ );
});
test("a sent text file downloads whole, not the capped preview", async () => {
- const preview = await readSrcAsync("components/assistant-ui/attachment-preview.tsx");
+ const preview = await readSrcAsync(
+ "components/assistant-ui/attachment-preview.tsx",
+ );
assert.match(preview, /new Blob\(\[attachmentBodyText\(sentText\)\]/);
assert.doesNotMatch(preview, /new Blob\(\[ready\.text\]/);
});
@@ -310,16 +404,50 @@ test("a composer clip reads as a video, not by its .mp4 name as audio", () => {
});
test("a sent document shown from its stored text downloads and chats as a .txt", async () => {
- const dialog = await readSrcAsync("components/assistant-ui/attachment-document-dialog.tsx");
+ const dialog = await readSrcAsync(
+ "components/assistant-ui/attachment-document-dialog.tsx",
+ );
assert.match(
dialog,
/saveAs=\{\n\s*loaded\?\.plain !== undefined\n\s*\? \{ name: `\$\{source\.name\.replace\(\/\\\.\[\^\.\]\+\$\/, ""\)\}\.txt`, contentType: "text\/plain" \}/,
);
- assert.match(dialog, /const name = saveAs\?\.name \?\? \(source\.name \|\| "attachment"\);/);
- assert.match(dialog, /downloadFile\(blob, name, contentType \|\| undefined\)/);
+ assert.match(
+ dialog,
+ /const name = saveAs\?\.name \?\? \(source\.name \|\| "attachment"\);/,
+ );
+ assert.match(
+ dialog,
+ /downloadFile\(blob, name, contentType \|\| undefined\)/,
+ );
});
test("a card preview follows the text adapter before a binary document viewer", async () => {
- const preview = await readSrcAsync("components/assistant-ui/attachment-card-preview.tsx");
- assert.match(preview, /if \(binary && isTextAttachment\(file\.name, file\.type\)\) return \{ kind: "text" \};\n\s*if \(document\)/);
+ const preview = await readSrcAsync(
+ "components/assistant-ui/attachment-card-preview.tsx",
+ );
+ assert.match(
+ preview,
+ /if \(binary && isTextAttachment\(file\.name, file\.type\)\) return \{ kind: "text" \};\n\s*if \(document\)/,
+ );
+});
+
+test("the main composer keeps attachments to one scrolling row once the chat has messages", async () => {
+ const attachment = await readSrcAsync(
+ "components/assistant-ui/attachment.tsx",
+ );
+ assert.match(
+ attachment,
+ /const maxRows = oneRowInChat && inChat \? 1 : COMPOSER_ATTACHMENT_MAX_ROWS;/,
+ );
+ assert.match(
+ attachment,
+ /useAuiState\(\(\{ thread \}\) => !thread\.isEmpty\)/,
+ );
+ const thread = await readSrcAsync("components/assistant-ui/thread.tsx");
+ assert.match(thread, /<ComposerAttachments oneRowInChat=\{true\} \/>/);
+ // The gap under the strip matches the one between the input and the controls.
+ assert.match(
+ attachment,
+ /aui-composer-attachment-cards mb-\[calc\(0\.5rem\*var\(--ui-space-scale,1\)\)\]/,
+ );
});