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: use the inline markdown table style in the Hub, file previews and the composer draft (#14087)
Michael Han72d0d2dbf33f
diff --git a/studio/frontend/src/components/assistant-ui/composer-draft-preview.tsx b/studio/frontend/src/components/assistant-ui/composer-draft-preview.tsxindex 67fd4387e20..0d59330a21b 100644--- a/studio/frontend/src/components/assistant-ui/composer-draft-preview.tsx+++ b/studio/frontend/src/components/assistant-ui/composer-draft-preview.tsx@@ -3,6 +3,7 @@import { useDeferredValue, type ComponentProps } from "react";import { Streamdown } from "streamdown";+import { StaticMarkdownTable } from "./markdown-table";import { useChatPreferencesStore } from "@/features/chat";import { useT } from "@/i18n";import { withLiteralUnknownTags } from "@/lib/markdown-data-images";@@ -18,6 +19,7 @@ const components: NonNullable<ComponentProps<typeof Streamdown>["components"]> =img: ({ alt }) => (<span className="text-muted-foreground">[{alt || "image"}]</span>),+ table: StaticMarkdownTable,};export function ComposerDraftPreview({ text }: { text: string }) {@@ -41,7 +43,7 @@ export function ComposerDraftPreview({ text }: { text: string }) {controls={false}components={components}rehypePlugins={REHYPE_PLUGINS}- className="min-w-0 space-y-2 [overflow-wrap:anywhere] [&_pre]:whitespace-pre-wrap [&_table]:block [&_table]:overflow-x-auto"+ className="min-w-0 space-y-2 [overflow-wrap:anywhere] [&_pre]:whitespace-pre-wrap">{draft}</Streamdown>diff --git a/studio/frontend/src/components/assistant-ui/markdown-table.tsx b/studio/frontend/src/components/assistant-ui/markdown-table.tsxindex 7c48ca6fbfc..9939e62cd18 100644--- a/studio/frontend/src/components/assistant-ui/markdown-table.tsx+++ b/studio/frontend/src/components/assistant-ui/markdown-table.tsx@@ -8,7 +8,12 @@ import {DialogTitle,} from "@/components/ui/dialog";import { useT } from "@/i18n";-import { Cancel01Icon, ExpandIcon } from "@hugeicons/core-free-icons";+import {+ Cancel01Icon,+ Copy01Icon,+ Download01Icon,+ ExpandIcon,+} from "@hugeicons/core-free-icons";import { HugeiconsIcon } from "@hugeicons/react";import {type ComponentProps,@@ -21,11 +26,31 @@ import {import {type ExtraProps,StreamdownContext,+ type StreamdownProps,TableCopyDropdown,TableDownloadDropdown,defaultTranslations,} from "streamdown";+// Streamdown ships its own glyphs for the table controls; swap in ours so copy,+// download and expand match the icons used everywhere else.+// `strokeWidth` is dropped, not forwarded: SVG types it `string | number`, HugeiconsIcon wants a number.+function streamdownIcon(icon: typeof Copy01Icon) {+ return function StreamdownIcon({+ size,+ strokeWidth: _strokeWidth,+ ...props+ }: ComponentProps<"svg"> & { size?: number }) {+ return <HugeiconsIcon icon={icon} size={size} {...props} />;+ };+}+export const MARKDOWN_TABLE_ICONS = {+ CopyIcon: streamdownIcon(Copy01Icon),+ DownloadIcon: streamdownIcon(Download01Icon),+ // Streamdown's key for the table's enlarge control.+ Maximize2Icon: streamdownIcon(ExpandIcon),+} satisfies NonNullable<StreamdownProps["icons"]>;+// Streamdown's copy and download find the table through this attribute, so the wrapper keeps it.const TABLE_WRAPPER = "table-wrapper";@@ -76,6 +101,37 @@ function TableScroll({);}+// rgb()/rgba() and the modern `/ alpha` syntax; anything else is taken as opaque.+const SLASH_ALPHA = /\/\s*([\d.]+%?)\s*\)$/;+const RGBA_ALPHA = /^rgba\([^,]+,[^,]+,[^,]+,\s*([\d.]+)\s*\)$/;+function isOpaque(color: string): boolean {+ const alpha = SLASH_ALPHA.exec(color)?.[1] ?? RGBA_ALPHA.exec(color)?.[1];+ if (alpha === undefined) {+ return true;+ }+ return alpha.endsWith("%")+ ? Number.parseFloat(alpha) >= 100+ : Number(alpha) >= 1;+}++// The controls sit over the header, so they paint whatever is behind the table: every background+// up to the first opaque one, stacked. Chat, the Hub, the browser panel and dialogs all differ.+function paintSurface(wrapper: HTMLElement): void {+ const layers: string[] = [];+ for (let el = wrapper.parentElement; el; el = el.parentElement) {+ const color = getComputedStyle(el).backgroundColor;+ if (color === "transparent" || color === "rgba(0, 0, 0, 0)") {+ continue;+ }+ layers.push(`linear-gradient(${color}, ${color})`);+ if (isOpaque(color)) {+ break;+ }+ }+ layers.push("linear-gradient(var(--background), var(--background))");+ wrapper.style.setProperty("--md-table-surface", layers.join(", "));+}+export function MarkdownTable({children,className,@@ -86,8 +142,23 @@ export function MarkdownTable({const { isAnimating } = useContext(StreamdownContext);const [expanded, setExpanded] = useState(false);const label = defaultTranslations.viewFullscreen;+ const wrapper = useRef<HTMLDivElement>(null);+ useLayoutEffect(() => {+ if (wrapper.current) {+ paintSurface(wrapper.current);+ }+ }, []);+ // Repainted on each approach, so a theme switch since mount is picked up.+ const repaint = (event: { currentTarget: HTMLDivElement }) =>+ paintSurface(event.currentTarget);return (- <div className="aui-md-table" data-streamdown={TABLE_WRAPPER}>+ <div+ ref={wrapper}+ className="aui-md-table"+ data-streamdown={TABLE_WRAPPER}+ onPointerEnter={repaint}+ onFocus={repaint}+ ><TableScroll className={className} props={props}>{children}</TableScroll>@@ -142,3 +213,19 @@ export function MarkdownTable({</div>);}++// For markdown shown inside another control: the same table, without controls.+export function StaticMarkdownTable({+ children,+ className,+ node: _node,+ ...props+}: ComponentProps<"table"> & ExtraProps) {+ return (+ <div className="aui-md-table">+ <TableScroll className={className} props={props}>+ {children}+ </TableScroll>+ </div>+ );+}diff --git a/studio/frontend/src/components/assistant-ui/markdown-text.tsx b/studio/frontend/src/components/assistant-ui/markdown-text.tsxindex 16795979e0e..c7e10945f68 100644--- a/studio/frontend/src/components/assistant-ui/markdown-text.tsx+++ b/studio/frontend/src/components/assistant-ui/markdown-text.tsx@@ -48,11 +48,7 @@ import {useAui,useAuiState,} from "@assistant-ui/react";-import {- Copy01Icon,- Download01Icon,- ExpandIcon,-} from "@hugeicons/core-free-icons";+import { Copy01Icon, Download01Icon } from "@hugeicons/core-free-icons";import { HugeiconsIcon } from "@hugeicons/react";import { createMathPlugin } from "@streamdown/math";import { mermaid } from "@streamdown/mermaid";@@ -119,7 +115,7 @@ import {sandboxSessionIdFor,sandboxSessionInSrc,} from "./sandbox-files";-import { MarkdownTable } from "./markdown-table";+import { MARKDOWN_TABLE_ICONS, MarkdownTable } from "./markdown-table";import { SearchImageElement, SearchImagesContext } from "./search-image";import { useSandboxImage } from "./use-sandbox-image";import { rehypeSandboxImages } from "./rehype-sandbox-images";@@ -169,24 +165,6 @@ const STREAMDOWN_SHIKI_THEME = [unslothLightTheme,unslothDarkTheme,] satisfies NonNullable<StreamdownProps["shikiTheme"]>;-// Streamdown ships its own glyphs for the table controls; swap in ours so copy,-// download and expand match the icons used everywhere else.-// `strokeWidth` is dropped, not forwarded: SVG types it `string | number`, HugeiconsIcon wants a number.-function streamdownIcon(icon: typeof Copy01Icon) {- return function StreamdownIcon({- size,- strokeWidth: _strokeWidth,- ...props- }: ComponentProps<"svg"> & { size?: number }) {- return <HugeiconsIcon icon={icon} size={size} {...props} />;- };-}-const STREAMDOWN_ICONS = {- CopyIcon: streamdownIcon(Copy01Icon),- DownloadIcon: streamdownIcon(Download01Icon),- // Streamdown's key for the table's enlarge control.- Maximize2Icon: streamdownIcon(ExpandIcon),-} satisfies NonNullable<StreamdownProps["icons"]>;const { withSmoothContextProvider } = INTERNAL;const STREAMING_RENDER_DUTY = 3;@@ -1585,7 +1563,7 @@ function MarkdownTextRenderer({rehypePlugins={rehypePlugins}urlTransform={safeMarkdownUrl}controls={STREAMDOWN_CONTROLS}- icons={STREAMDOWN_ICONS}+ icons={MARKDOWN_TABLE_ICONS}shikiTheme={STREAMDOWN_SHIKI_THEME}BlockComponent={StreamdownBlock}>diff --git a/studio/frontend/src/components/markdown/markdown-preview.tsx b/studio/frontend/src/components/markdown/markdown-preview.tsxindex 8145238d2b8..1a7fdcf5ed7 100644--- a/studio/frontend/src/components/markdown/markdown-preview.tsx+++ b/studio/frontend/src/components/markdown/markdown-preview.tsx@@ -7,6 +7,11 @@ import { openLink } from "@/lib/open-link";import { safeMarkdownUrl } from "@/lib/safe-markdown-url";import { scheduleIdleTask } from "@/lib/schedule-idle-task";import { cn } from "@/lib/utils";+import {+ MARKDOWN_TABLE_ICONS,+ MarkdownTable,+ StaticMarkdownTable,+} from "@/components/assistant-ui/markdown-table";import { codePlugin } from "@/components/assistant-ui/shared-code-plugin";import { math } from "@streamdown/math";import { mermaid } from "@streamdown/mermaid";@@ -42,6 +47,11 @@ const MARKDOWN_COMPONENTS = {{children}</a>),+ table: MarkdownTable,+};+const INERT_COMPONENTS = {+ ...INERT_MARKDOWN_COMPONENTS,+ table: StaticMarkdownTable,};type MarkdownPreviewProps = {@@ -103,7 +113,8 @@ function MarkdownPreviewImpl({mode="static"plugins={plugins}rehypePlugins={REHYPE_PLUGINS}- components={inert ? INERT_MARKDOWN_COMPONENTS : MARKDOWN_COMPONENTS}+ components={inert || plain ? INERT_COMPONENTS : MARKDOWN_COMPONENTS}+ icons={MARKDOWN_TABLE_ICONS}urlTransform={safeMarkdownUrl}controls={false}className={markdownClassName}diff --git a/studio/frontend/src/features/hub/catalog/model-readme.tsx b/studio/frontend/src/features/hub/catalog/model-readme.tsxindex a3555df7976..383095e9189 100644--- a/studio/frontend/src/features/hub/catalog/model-readme.tsx+++ b/studio/frontend/src/features/hub/catalog/model-readme.tsx@@ -16,6 +16,10 @@ import { scheduleIdleTask } from "@/lib/schedule-idle-task";import { cn } from "@/lib/utils";import { confirmExternalLink } from "../stores/external-link-confirm";import { useHfTokenStore } from "@/features/hub/stores/hf-token-store";+import {+ MARKDOWN_TABLE_ICONS,+ MarkdownTable,+} from "@/components/assistant-ui/markdown-table";import { codePlugin } from "@/components/assistant-ui/shared-code-plugin";import { math as streamdownMath } from "@streamdown/math";import { mermaid as streamdownMermaid } from "@streamdown/mermaid";@@ -142,9 +146,7 @@ const PROSE = cn("[&_pre]:rounded-[12px] [&_pre]:border [&_pre]:border-border/60 [&_pre]:bg-muted/40 [&_pre]:p-3 [&_pre]:text-ui-12 [&_pre]:overflow-x-auto","[&_pre_code]:bg-transparent [&_pre_code]:p-0","[&_blockquote]:border-l-2 [&_blockquote]:border-border/60 [&_blockquote]:pl-3 [&_blockquote]:text-muted-foreground",- "[&_table]:my-3 [&_table]:text-ui-12p5",- "[&_th]:px-2 [&_th]:py-1.5 [&_th]:text-left [&_th]:font-semibold [&_th]:border-b [&_th]:border-border/60",- "[&_td]:px-2 [&_td]:py-1.5 [&_td]:border-b [&_td]:border-border/40",+ "[&_table]:text-ui-12p5","[&_img]:rounded-[10px] [&_img]:my-2 [&_img]:max-w-full","[&_audio]:my-1 [&_audio]:max-w-full [&_audio]:h-9 [&_audio]:align-middle","[&_video]:my-2 [&_video]:max-w-full [&_video]:rounded-[10px]",@@ -220,6 +222,7 @@ function ReadmeImage({const README_COMPONENTS: Components = {a: ReadmeLink,img: ReadmeImage,+ table: MarkdownTable,};function readmeLoadingMessage(subject: ReadmeSubject): string {@@ -537,6 +540,7 @@ export function ModelReadme({plugins={current.plugins}controls={false}components={README_COMPONENTS}+ icons={MARKDOWN_TABLE_ICONS}allowedTags={README_ALLOWED_TAGS}rehypePlugins={README_REHYPE_PLUGINS}urlTransform={urlTransform}diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.cssindex e43eed19b50..f4b85a479fe 100644--- a/studio/frontend/src/index.css+++ b/studio/frontend/src/index.css@@ -4428,6 +4428,11 @@ html[data-chat-font] .aui-root {margin-block: calc(1rem * var(--ui-space-scale, 1));}+ /* The cell floor's 15cqi. Not the dialog panel, which sizes to the table. */+ .aui-md-table:not(.aui-md-table-dialog) {+ container-type: inline-size;+ }+/* The second mask layer keeps the scrollbar opaque under the fade. */.aui-md-table-scroll {--md-table-fade-start: 0px;@@ -4484,8 +4489,10 @@ html[data-chat-font] .aui-root {line-height: 1.5;vertical-align: top;white-space: normal;- /* A floor, so many columns scroll instead of breaking every word. */- min-width: 8rem;+ /* Words wrap whole; `anywhere` (markdown previews set it) would shrink columns to a letter. */+ overflow-wrap: break-word;+ /* A floor, so many columns scroll instead of breaking every word; narrow panels lower it. */+ min-width: min(8rem, 15cqi);}.aui-md-table :is(th, td):first-child {@@ -4508,12 +4515,22 @@ html[data-chat-font] .aui-root {align-items: center;gap: 0.125rem;padding-left: 1rem;- background: linear-gradient(to right, transparent, var(--background) 1rem);+ isolation: isolate;opacity: 0;pointer-events: none;transition: opacity 120ms ease;}+ /* On a pseudo-element, so the fade's mask leaves the copy and download menus alone. */+ .aui-md-table-actions::before {+ content: "";+ position: absolute;+ inset: 0;+ z-index: -1;+ background: var(--md-table-surface, var(--background));+ mask-image: linear-gradient(to right, transparent, #000 1rem);+ }+.aui-md-table:hover > .aui-md-table-actions,.aui-md-table-actions:focus-within,.aui-md-table-actions:has(> .relative > div) {@@ -5943,7 +5960,7 @@ html.force-reduced-motion .sidebar-section-drop-line {/* An odd-sized glyph in these 32px buttons sits on a half pixel, which paints it 0.5px right ofits circle; an even size centers it. After the block above, which it must outrank. */-.aui-root.aui-thread-root :is(.aui-chat-icon-btn, .aui-md-table-actions button) svg {+:is(.aui-root.aui-thread-root, .aui-md-table.aui-md-table) :is(.aui-chat-icon-btn, .aui-md-table-actions button) svg {width: round(var(--icon-size), 2px);height: round(var(--icon-size), 2px);}diff --git a/studio/frontend/tests/markdown-preview-literal-tags.test.ts b/studio/frontend/tests/markdown-preview-literal-tags.test.tsindex 62977211ddf..31e51cb8905 100644--- a/studio/frontend/tests/markdown-preview-literal-tags.test.ts+++ b/studio/frontend/tests/markdown-preview-literal-tags.test.ts@@ -24,6 +24,18 @@ import { readSrc } from "./helpers/kit.ts";import { loadWithStubs } from "./helpers/module-stubs.ts";import { openingTag } from "./helpers/tsx-ast.ts";+// The real tables pull in the app's dialog; these surfaces only need the <table> through.+const plainTable = ({+ children,+ node: _node,+ ...props+}: { children?: React.ReactNode; node?: unknown }) =>+ React.createElement("table", props, children);+const markdownTable = {+ MARKDOWN_TABLE_ICONS: {},+ MarkdownTable: plainTable,+ StaticMarkdownTable: plainTable,+};const shared = {react: React,"react/jsx-runtime": jsxRuntime,@@ -45,6 +57,7 @@ const { MarkdownPreview } = loadWithStubs<typeof MarkdownPreviewModule>("@/lib/schedule-idle-task": scheduleIdleTask,"@/lib/utils": utils,"./inert-components": inertComponents,+ "@/components/assistant-ui/markdown-table": markdownTable,"katex/dist/katex.min.css": {},},);@@ -62,6 +75,7 @@ const { ComposerDraftPreview } = loadWithStubs<select({ plainTextComposer: false }),},"@/i18n": { useT: () => (key: string) => key },+ "./markdown-table": markdownTable,},);