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: removing a composer attachment no longer reloads the others (#13677)
Michael Han4e63ad8d38fc
diff --git a/studio/frontend/src/components/assistant-ui/attachment.tsx b/studio/frontend/src/components/assistant-ui/attachment.tsxindex 26a2a113dbb..965b57eb194 100644--- a/studio/frontend/src/components/assistant-ui/attachment.tsx+++ b/studio/frontend/src/components/assistant-ui/attachment.tsx@@ -43,6 +43,7 @@ import {} from "@/features/chat";import { formatBytes } from "@/features/hub";import { useAppearanceCustomStore } from "@/features/settings";+import { ComposerAttachmentByIdProvider } from "@/components/assistant-ui/stale-safe-scopes";import { cn } from "@/lib/utils";import { useShallow } from "zustand/shallow";import {@@ -686,8 +687,6 @@ const SENT_FILE_COMPONENTS = {Document: SentFileItem,File: SentFileItem,};-const CARD_COMPONENTS = { Attachment: ComposerAttachmentCard };-export const UserMessageAttachments: FC = () => {const setting = useAppearanceCustomStore((s) => s.customization.sentAttachments,@@ -782,11 +781,26 @@ export const ComposerAttachments: FC<{className,)}>- <ComposerPrimitive.Attachments components={CARD_COMPONENTS} />+ <ComposerAttachmentCardList /></div>);};+// Not ComposerPrimitive.Attachments: its index keys remount every card after a removed one,+// and each remount blanks its preview and decodes the image again.+const ComposerAttachmentCardList: FC = () => {+ const ids = useAuiState(+ useShallow(({ composer }) =>+ composer.attachments.map((attachment) => attachment.id),+ ),+ );+ return ids.map((id) => (+ <ComposerAttachmentByIdProvider key={id} id={id}>+ <ComposerAttachmentCard />+ </ComposerAttachmentByIdProvider>+ ));+};+export const ComposerAddAttachment: FC = () => {return (<ComposerPrimitive.AddAttachment asChild={true}>diff --git a/studio/frontend/src/components/assistant-ui/stale-safe-scopes.tsx b/studio/frontend/src/components/assistant-ui/stale-safe-scopes.tsxindex 27776671dbe..4fc316579c4 100644--- a/studio/frontend/src/components/assistant-ui/stale-safe-scopes.tsx+++ b/studio/frontend/src/components/assistant-ui/stale-safe-scopes.tsx@@ -39,6 +39,20 @@ export const MessageByIndexProvider: FC<return <AuiProvider value={aui}>{children}</AuiProvider>;};+/** Composer attachment scope by id: an index scope reads a moved card's old index past the end and throws. */+export const ComposerAttachmentByIdProvider: FC<+ PropsWithChildren<{ id: string }>+> = ({ id, children }) => {+ const aui = useAui({+ attachment: Derived({+ source: "composer",+ query: { type: "id", id },+ get: (aui) => aui.composer().attachment({ id }),+ }),+ });+ return <AuiProvider value={aui}>{children}</AuiProvider>;+};+/** `useMessagePartText` that reads an empty text part instead of throwing on a mismatched part. */export const useMessagePartTextSafe = (): TextPartState =>useAuiState((s) => textPartOrEmpty(s.part));diff --git a/studio/frontend/tests/chat-attachment-display.test.ts b/studio/frontend/tests/chat-attachment-display.test.tsindex c6070089ffe..821a38888a7 100644--- a/studio/frontend/tests/chat-attachment-display.test.ts+++ b/studio/frontend/tests/chat-attachment-display.test.ts@@ -181,7 +181,7 @@ test("the composer always shows attachments as cards", () => {assert.equal("composerAttachments" in saved, false);assert.match(ATTACHMENT,- /<ComposerPrimitive\.Attachments components=\{CARD_COMPONENTS\} \/>/,+ /<ComposerAttachmentByIdProvider key=\{id\} id=\{id\}>\s*<ComposerAttachmentCard \/>/,);assert.doesNotMatch(ATTACHMENT,@@ -190,6 +190,26 @@ test("the composer always shows attachments as cards", () => {assert.doesNotMatch(ATTACHMENT, /customization\.composerAttachments/);});+// assistant-ui keys composer attachments by index, so removing the first remounted every card after+// it (each card is keyed by its attachment id), and each remount blanked its preview and decoded the+// image again. The list is keyed and scoped by id instead; an index scope would also throw for a+// moved card, whose new index applies a step after the list re-renders.+test("composer attachment cards are keyed and scoped by attachment id", async () => {+ const list = ATTACHMENT.slice(+ ATTACHMENT.indexOf("const ComposerAttachmentCardList: FC"),+ );+ assert.match(+ list,+ /composer\.attachments\.map\(\(attachment\) => attachment\.id\)/,+ );+ assert.doesNotMatch(ATTACHMENT, /<ComposerPrimitive\.Attachments\b/);+ const scopes = await readSrcAsync(+ "components/assistant-ui/stale-safe-scopes.tsx",+ );+ assert.match(scopes, /query: \{ type: "id", id \}/);+ assert.match(scopes, /aui\.composer\(\)\.attachment\(\{ id \}\)/);+});+test("audio or video attached before a model loaded is checked when sent", () => {const listener = { hasAudioInput: true, hasVideoInput: false };const textOnly = { hasAudioInput: false, hasVideoInput: false };