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: make links in the collapsed update notes clickable (#16829)
Nilay2a3eae75857d
diff --git a/studio/frontend/src/components/update/release-notes-panel.tsx b/studio/frontend/src/components/update/release-notes-panel.tsxindex ecce5c3ec2a..43cbfe46e4b 100644--- a/studio/frontend/src/components/update/release-notes-panel.tsx+++ b/studio/frontend/src/components/update/release-notes-panel.tsx@@ -14,7 +14,10 @@ import {import { useReleaseNotes } from "@/hooks/use-release-notes";import { useT } from "@/i18n";import { resolveReleaseBodyLinks } from "@/lib/release-body-links";-import { releaseNotesPreview } from "@/lib/release-notes-preview";+import {+ type ReleaseNotesLink,+ releaseNotesPreview,+} from "@/lib/release-notes-preview";import {type ReactElement,type ReactNode,@@ -234,6 +237,35 @@ export function ReleaseNotesPanel({);}+function linked(+ text: string,+ links: ReleaseNotesLink[],+ part: ReleaseNotesLink["part"],+): ReactNode[] {+ const nodes: ReactNode[] = [];+ let from = 0;+ for (const link of links) {+ if (link.part !== part) {+ continue;+ }+ nodes.push(+ text.slice(from, link.start),+ <a+ key={link.start}+ href={link.href}+ target="_blank"+ rel="noopener noreferrer"+ className="underline decoration-foreground/40 underline-offset-2 transition-colors hover:decoration-foreground"+ >+ {text.slice(link.start, link.end)}+ </a>,+ );+ from = link.end;+ }+ nodes.push(text.slice(from));+ return nodes;+}+function ReleaseNotesSummary({preview,}: {@@ -265,8 +297,12 @@ function ReleaseNotesSummary({•</span><span className="line-clamp-2 min-w-0">- <span className={UPDATE_NOTES_LEAD_CLASS}>{item.lead}</span>- {item.rest ? <span> {item.rest}</span> : null}+ <span className={UPDATE_NOTES_LEAD_CLASS}>+ {linked(item.lead, item.links, "lead")}+ </span>+ {item.rest ? (+ <span> {linked(item.rest, item.links, "rest")}</span>+ ) : null}</span></li>))}diff --git a/studio/frontend/src/lib/release-notes-preview.ts b/studio/frontend/src/lib/release-notes-preview.tsindex ffa345eab5d..007580309fd 100644--- a/studio/frontend/src/lib/release-notes-preview.ts+++ b/studio/frontend/src/lib/release-notes-preview.ts@@ -35,10 +35,19 @@ const IMAGE = new RegExp(`!\\[${LABEL}\\]${DESTINATION}`, "g");const LINK = new RegExp(`\\[${LABEL}\\]${DESTINATION}`, "g");const IMAGE_REFERENCE = new RegExp(`!\\[${LABEL}\\](?:\\[([^\\]]*)\\])?`, "g");const LINK_REFERENCE = new RegExp(`\\[${LABEL}\\](?:\\[([^\\]]*)\\])?`, "g");+// A parked escape or code span in the destination keeps the link plain.+const WEB_DESTINATION = /^\((https?:\/\/[^\s()<>\uE000-\uE003]+)\)$/i;const DEFINITION = /^ {0,3}\[((?:[^\[\]\\]|\\.)+)\]:/;const ESCAPE = /\\([!-/:-@[-`{-~])/g;-// Private-use sentinels park code spans, so document text cannot contain them.-const SENTINELS = /[\uE000\uE001]/g;+// Private-use sentinels park code spans and mark links, so document text cannot contain them.+const SENTINELS = /[\uE000-\uE003]/g;+// Browsers read `\` as `/` where the expanded view sends `%5C`, so those links stay plain.+const UNSAFE_HREF = /[\s<>\\]/;+const LINK_OPEN = "\uE002";+const LINK_CLOSE = "\uE003";+// Each mark carries its href index, so a pair removed by tag stripping cannot shift the rest.+const MARKS = /(\uE002\d+\uE002|\uE003\d+\uE003)/;+const EDGE_SPACE = /^(\s*)([\s\S]*?)(\s*)$/;const LINE_ENDINGS = /\r\n?/g;const TABS = /\t/g;// A name character must follow "<", so "Python <3.15 and >3.9" keeps its operators.@@ -128,9 +137,24 @@ function stripHtmlTags(text: string): string {return out;}+/** `start`/`end` index into the item's `lead` or `rest`. */+export interface ReleaseNotesLink {+ part: "lead" | "rest";+ start: number;+ end: number;+ href: string;+}++interface Span {+ start: number;+ end: number;+ href: string;+}+export interface ReleaseNotesPreviewItem {lead: string;rest: string;+ links: ReleaseNotesLink[];}export interface ReleaseNotesPreview {@@ -141,6 +165,7 @@ export interface ReleaseNotesPreview {interface Bullet {text: string;indent: number;+ links: Span[];}function definedLabel(@@ -172,7 +197,11 @@ function decodeEntity(match: string, body: string): string {return NAMED_ENTITIES[body.toLowerCase()] ?? match;}-function toPlainText(markdown: string, labels?: Set<string>): string {+function toPlainText(+ markdown: string,+ labels?: Set<string>,+ hrefs?: string[],+): string {const codes: string[] = [];const park = (text: string): string => {codes.push(text);@@ -186,7 +215,19 @@ function toPlainText(markdown: string, labels?: Set<string>): string {parked.replace(AUTOLINK, "$1").replace(IMAGE, "")- .replace(LINK, "$1")+ .replace(LINK, (match, label: string) => {+ const href = hrefs+ ? WEB_DESTINATION.exec(match.slice(label.length + 2))?.[1]+ : undefined;+ const decoded = href?.replace(ENTITY, decodeEntity);+ if (!decoded || UNSAFE_HREF.test(decoded)) {+ return label;+ }+ const id = hrefs?.push(decoded) ?? 0;+ // Edge spaces stay outside the marks, so emphasis around the link strips as before.+ const [, before, inner, after] = EDGE_SPACE.exec(label) ?? [];+ return `${before}${LINK_OPEN}${id}${LINK_OPEN}${inner}${LINK_CLOSE}${id}${LINK_CLOSE}${after}`;+ }).replace(IMAGE_REFERENCE, (match, text, ref) =>definedLabel(labels, ref, text) ? "" : match,)@@ -205,6 +246,44 @@ function toPlainText(markdown: string, labels?: Set<string>): string {.trim();}+/** Spans index the returned text; any doubt drops them rather than link the wrong words. */+function plainWithLinks(+ markdown: string,+ labels: Set<string>,+): { text: string; links: Span[] } {+ const hrefs: string[] = [];+ const marked = toPlainText(markdown, labels, hrefs);+ if (hrefs.length === 0) {+ return { text: marked, links: [] };+ }+ const links: Span[] = [];+ let text = "";+ let label = "";+ let open = 0;+ for (const [index, piece] of marked.split(MARKS).entries()) {+ if (index % 2 === 0) {+ text = `${text}${piece}`.replace(WHITESPACE, " ").trimStart();+ label += piece;+ continue;+ }+ const id = Number(piece.slice(1, -1));+ if (piece.startsWith(LINK_OPEN)) {+ open = id;+ label = "";+ continue;+ }+ const shown = label.replace(WHITESPACE, " ").trim();+ const end = text.trimEnd().length;+ const href = hrefs[id - 1];+ if (open === id && shown && href) {+ links.push({ start: end - shown.length, end, href });+ }+ open = 0;+ }+ const plain = toPlainText(markdown, labels);+ return { text: plain, links: text.trimEnd() === plain ? links : [] };+}+function truncate(text: string): string {if (text.length <= PREVIEW_ITEM_MAX_CHARS) {return text;@@ -652,7 +731,11 @@ function contentLines(markdown: string): ContentLine[] {}/** Conservative: the next sentence must start like one, so "unsloth.ai in the docs" is not split. */-function splitLeadSentence(text: string): ReleaseNotesPreviewItem {+function splitLeadSentence(text: string): {+ lead: string;+ rest: string;+ restStart: number;+} {SENTENCE_BREAK.lastIndex = 0;let match = SENTENCE_BREAK.exec(text);while (match) {@@ -661,33 +744,81 @@ function splitLeadSentence(text: string): ReleaseNotesPreviewItem {TRAILING_WORD.exec(text.slice(0, cut))?.[1]?.toLowerCase() ?? "";const isAbbreviation = ABBREVIATIONS.has(word) || INITIAL.test(word);if (!isAbbreviation && cut >= MIN_LEAD_CHARS) {- return { lead: text.slice(0, cut).trim(), rest: text.slice(cut).trim() };+ const tail = text.slice(cut);+ return {+ lead: text.slice(0, cut).trim(),+ rest: tail.trim(),+ restStart: cut + tail.length - tail.trimStart().length,+ };}match = SENTENCE_BREAK.exec(text);}- return { lead: text, rest: "" };+ return { lead: text, rest: "", restStart: text.length };+}++/** A link the lead split cuts through becomes one anchor on each side. */+function previewItem({ text, links }: Bullet): ReleaseNotesPreviewItem {+ const { lead, rest, restStart } = splitLeadSentence(text);+ const parts: ReleaseNotesLink[] = [];+ for (const { start, end, href } of links) {+ if (start < lead.length) {+ parts.push({+ part: "lead",+ start,+ end: Math.min(end, lead.length),+ href,+ });+ }+ if (end > restStart) {+ const from = Math.max(start, restStart) - restStart;+ parts.push({ part: "rest", start: from, end: end - restStart, href });+ }+ }+ return { lead, rest, links: parts };}interface Collector {bullets: Bullet[];- prose: string[];+ prose: Bullet[];current: Bullet | null;- paragraph: string;+ paragraph: Bullet;// A quote owns its paragraph: a marker outside the quote opens a list rather than continuing it.quotedParagraph: boolean;}+const EMPTY: Bullet = { text: "", indent: 0, links: [] };++/** Truncates, dropping links the cut reaches. */+function clip({ text, indent, links }: Bullet): Bullet {+ const shown = truncate(text);+ const kept = shown === text ? shown.length : shown.length - "...".length;+ return { text: shown, indent, links: links.filter((l) => l.end <= kept) };+}++function append(block: Bullet, text: string, links: Span[]): Bullet {+ const offset = block.text.length + 1;+ return {+ text: `${block.text} ${text}`,+ indent: block.indent,+ links: [+ ...block.links,+ ...links.map((l) => ({+ ...l,+ start: l.start + offset,+ end: l.end + offset,+ })),+ ],+ };+}+function flush(collector: Collector): void {if (collector.current?.text) {- collector.bullets.push({- text: truncate(collector.current.text),- indent: collector.current.indent,- });+ collector.bullets.push(clip(collector.current));}collector.current = null;- if (collector.paragraph) {- collector.prose.push(truncate(collector.paragraph));- collector.paragraph = "";+ if (collector.paragraph.text) {+ collector.prose.push(clip(collector.paragraph));+ collector.paragraph = EMPTY;}collector.quotedParagraph = false;}@@ -699,12 +830,12 @@ function takeBullet(labels: Set<string>,): void {flush(collector);- const item = toPlainText(text, labels);+ const { text: item, links } = plainWithLinks(text, labels);// A quoted list is example output, never a headline bullet.if (!line.quoted) {- collector.current = { text: item, indent: line.indent };+ collector.current = { text: item, indent: line.indent, links };} else if (item) {- collector.prose.push(truncate(item));+ collector.prose.push(clip({ text: item, indent: 0, links }));}}@@ -714,32 +845,29 @@ function takeText(labels: Set<string>,quoted: boolean,): void {- const plain = toPlainText(text, labels);+ const { text: plain, links } = plainWithLinks(text, labels);if (!plain) {return;}if (collector.current === null) {- collector.paragraph = collector.paragraph- ? `${collector.paragraph} ${plain}`- : plain;+ collector.paragraph = collector.paragraph.text+ ? append(collector.paragraph, plain, links)+ : { text: plain, indent: 0, links };collector.quotedParagraph = quoted;return;}- collector.current = {- text: `${collector.current.text} ${plain}`,- indent: collector.current.indent,- };+ collector.current = append(collector.current, plain, links);}function collectBullets(markdown: string): {bullets: Bullet[];- prose: string[];+ prose: Bullet[];} {const collector: Collector = {bullets: [],prose: [],current: null,- paragraph: "",+ paragraph: EMPTY,quotedParagraph: false,};@@ -809,7 +937,7 @@ function collectBullets(markdown: string): {continue;}const insideBlock =- collector.current !== null || collector.paragraph !== "";+ collector.current !== null || collector.paragraph.text !== "";if (!insideBlock && line.indent - line.column >= INDENTED_CODE_INDENT) {continue;}@@ -817,7 +945,7 @@ function collectBullets(markdown: string): {// Only an ordered list starting at 1 may interrupt a paragraph.const interrupts =collector.current === null &&- collector.paragraph !== "" &&+ collector.paragraph.text !== "" &&!collector.quotedParagraph;if (bullet &&@@ -849,13 +977,13 @@ export function releaseNotesPreview((min, bullet) => Math.min(min, bullet.indent),Number.POSITIVE_INFINITY,);- const topLevel = bullets- .filter((bullet) => bullet.indent <= baseIndent + NESTED_INDENT_TOLERANCE)- .map((bullet) => bullet.text);+ const topLevel = bullets.filter(+ (bullet) => bullet.indent <= baseIndent + NESTED_INDENT_TOLERANCE,+ );const source = topLevel.length > 0 ? topLevel : prose;return {- items: source.slice(0, limit).map(splitLeadSentence),+ items: source.slice(0, limit).map(previewItem),remaining: Math.max(source.length - limit, 0),};}diff --git a/studio/frontend/tests/release-notes-preview-links.test.ts b/studio/frontend/tests/release-notes-preview-links.test.tsnew file mode 100644index 00000000000..d0fa8ac5898--- /dev/null+++ b/studio/frontend/tests/release-notes-preview-links.test.ts@@ -0,0 +1,165 @@+// 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";++import { registerBundlerResolver } from "./helpers/kit.ts";++registerBundlerResolver();++const { releaseNotesPreview } = await import(+ "../src/lib/release-notes-preview.ts"+);++function linkedText(markdown: string, limit?: number) {+ return releaseNotesPreview(markdown, limit).items.map((item) => ({+ lead: item.lead,+ rest: item.rest,+ links: item.links.map((link) => ({+ part: link.part,+ text: item[link.part].slice(link.start, link.end),+ href: link.href,+ })),+ }));+}++test("a web link in a bullet keeps its destination for the collapsed card", () => {+ const items = linkedText(+ "- **Qwen3.8-Flash-Next** Dynamic V3.1 - 10-15% extra accuracy [Guide](https://unsloth.ai/docs/models/qwen3.8-next)\n- Glass theme improvements",+ );+ assert.deepEqual(items[0], {+ lead: "Qwen3.8-Flash-Next Dynamic V3.1 - 10-15% extra accuracy Guide",+ rest: "",+ links: [+ {+ part: "lead",+ text: "Guide",+ href: "https://unsloth.ai/docs/models/qwen3.8-next",+ },+ ],+ });+ assert.deepEqual(items[1]?.links, []);+});++test("links across a bullet's lines stay in order", () => {+ const [item] = linkedText(+ "- Faster loads. See [**the docs**](http://unsloth.ai/docs)\n and [#123](https://github.com/unslothai/unsloth/pull/123)",+ );+ assert.equal(item?.rest, "See the docs and #123");+ assert.deepEqual(item?.links, [+ { part: "rest", text: "the docs", href: "http://unsloth.ai/docs" },+ {+ part: "rest",+ text: "#123",+ href: "https://github.com/unslothai/unsloth/pull/123",+ },+ ]);+});++test("the link is the linked words, not an earlier match of its text", () => {+ const spans = releaseNotesPreview(+ [+ "- Studio now runs everywhere. Read more [here](https://unsloth.ai/a)",+ "- Guide mode is faster: read the [guide](https://unsloth.ai/b)",+ "- [Docs](https://unsloth.ai/c) and more [Docs](https://unsloth.ai/d)",+ ].join("\n"),+ ).items.map((item) =>+ item.links.map(({ part, start, end }) => [part, start, end]),+ );+ assert.deepEqual(spans, [+ [["rest", 10, 14]],+ [["lead", 31, 36]],+ [+ ["lead", 0, 4],+ ["lead", 14, 18],+ ],+ ]);+});++test("links keep the summary text and drop when clipped", () => {+ const long = `- ${"word ".repeat(22)}and the [docs](https://unsloth.ai/d)`;+ const [item] = linkedText(long);+ assert.ok(item?.lead.endsWith("..."));+ assert.deepEqual(item?.links, []);++ const [emphasis] = linkedText(+ "- **[Bold link](https://unsloth.ai/x)** and _[ spaced ](https://unsloth.ai/y)_ here",+ );+ assert.equal(emphasis?.lead, "Bold link and _ spaced _ here");+ assert.deepEqual(+ emphasis?.links.map((l) => l.text),+ ["Bold link", "spaced"],+ );+});++test("destinations decode character references and keep their own link", () => {+ const [entity, hidden] = linkedText(+ [+ "- [Guide](https://example.com/?a=1&b=2&c=3) now",+ '- <span title="[hidden](https://a.test)">Model</span> [Guide](https://b.test)',+ ].join("\n"),+ );+ assert.deepEqual(entity?.links, [+ { part: "lead", text: "Guide", href: "https://example.com/?a=1&b=2&c=3" },+ ]);+ assert.equal(hidden?.lead, "Model Guide");+ assert.deepEqual(hidden?.links, [+ { part: "lead", text: "Guide", href: "https://b.test" },+ ]);+});++test("a link the lead split cuts through stays clickable on both sides", () => {+ const [item] = linkedText(+ "- [Faster inference. Read the guide](https://example.com/guide) today",+ );+ assert.equal(item?.lead, "Faster inference.");+ assert.deepEqual(item?.links, [+ {+ part: "lead",+ text: "Faster inference.",+ href: "https://example.com/guide",+ },+ { part: "rest", text: "Read the guide", href: "https://example.com/guide" },+ ]);+});++test("prose fallback keeps its links", () => {+ const [intro, links] = linkedText(+ "Muse Glimmer is out.\n\n[Run Muse Glimmer](https://unsloth.ai/docs/run)\n[Fine-tune it](https://unsloth.ai/docs/train)",+ );+ assert.deepEqual(intro?.links, []);+ assert.deepEqual(links?.links, [+ {+ part: "lead",+ text: "Run Muse Glimmer",+ href: "https://unsloth.ai/docs/run",+ },+ {+ part: "lead",+ text: "Fine-tune it",+ href: "https://unsloth.ai/docs/train",+ },+ ]);+});++test("only plain http and https links become clickable", () => {+ const items = linkedText(+ [+ "- Run [this](javascript:alert(1)) now",+ "- Mail [us](mailto:[email protected]) today",+ "- Read [notes](/docs/notes) here",+ '- Open [page](https://unsloth.ai "Title") later',+ "- Code `[x](https://unsloth.ai)` stays code",+ "- Escaped \\[y](https://unsloth.ai) stays text",+ "- Image  hidden",+ "- Escaped [dest](https://unsloth.ai/a\\_b) stays text",+ "- Backslash [path](https://unsloth.ai/docs\\alpha.md) stays text",+ "- Encoded [path](https://unsloth.ai/docs\alpha.md) stays text",+ ].join("\n"),+ 10,+ );+ for (const item of items) {+ assert.deepEqual(item.links, [], item.lead);+ }+});