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.

Keep syntax colour on settled thinking fences in tilde, four-backtick, indented and stopped forms (#13415)

Daniel Hand6cfacfbfbfd
diff --git a/studio/frontend/src/components/assistant-ui/markdown-text.tsx b/studio/frontend/src/components/assistant-ui/markdown-text.tsx
index 16ac84fbd86..ca9c312f9b3 100644
--- a/studio/frontend/src/components/assistant-ui/markdown-text.tsx
+++ b/studio/frontend/src/components/assistant-ui/markdown-text.tsx
@@ -910,8 +910,9 @@ function StreamdownBlockContent(props: BlockProps) {
source={settledFence.text}
/>
) : (
- <PlainFenceBlock
+ <LiveThinkingFence
language={settledFence.language}
+ settled
source={settledFence.text}
/>
);
@@ -1161,14 +1162,16 @@ function PlainFenceBlock({
function LiveThinkingFence({
language,
+ settled = false,
source,
}: {
language: string | null;
+ settled?: boolean;
source: string;
}) {
const languageToken = language?.trim().split(/\s+/)[0] || null;
const host = useRef<HTMLDivElement | null>(null);
- const colour = useThinkingCodeColour(host, source, languageToken, false);
+ const colour = useThinkingCodeColour(host, source, languageToken, settled);
const result = useMemo(
() =>
colour === null
@@ -1182,7 +1185,7 @@ function LiveThinkingFence({
<PlainFenceShell language={languageToken} source={source} />
) : (
<FenceBody
- isIncomplete
+ isIncomplete={!settled}
language={languageToken}
result={result}
source={source}
diff --git a/studio/frontend/tests/code-fence-body.test.ts b/studio/frontend/tests/code-fence-body.test.ts
index e70c39f824b..ef55e96b6a3 100644
--- a/studio/frontend/tests/code-fence-body.test.ts
+++ b/studio/frontend/tests/code-fence-body.test.ts
@@ -105,10 +105,11 @@ test("a streaming open fence is highlighted rather than shown plain", () => {
test("a fence in the thinking box is coloured off the main thread, while it grows only on screen", () => {
assert.match(readSrc("components/assistant-ui/code-highlight-context.ts"), /export const CodeHighlightModeContext = createContext<CodeHighlightMode>\("all"\);/);
assert.match(MARKDOWN_TEXT, /\{highlightCode \|\| highlightMode === "settled" \? \(\s*<FenceBlock[\s\S]{0,300}isIncomplete=\{highlightCode \? props\.isIncomplete : false\}/, "a closed fence in a trace takes the deferred, worker-routed block, never the growing fence's tokenizer");
- assert.equal((MARKDOWN_TEXT.match(/\) : \(\s*<PlainFenceBlock/g) ?? []).length, 2, "the closed fence routes keep a plain twin");
+ assert.equal((MARKDOWN_TEXT.match(/\) : \(\s*<PlainFenceBlock/g) ?? []).length, 1, "only the ``` closed fence route keeps a plain twin");
assert.match(MARKDOWN_TEXT, /<StreamingFenceBlock\s*language=\{openFence\.language\}\s*source=\{openFence\.text\}\s*\/>\s*\) : \(\s*<LiveThinkingFence/, "a growing thinking fence takes the viewport-gated worker route");
const live = MARKDOWN_TEXT.slice(MARKDOWN_TEXT.indexOf("function LiveThinkingFence("), MARKDOWN_TEXT.indexOf("function FenceBlock("));
- assert.match(live, /useThinkingCodeColour\(host, source, languageToken, false\)/);
+ assert.match(live, /useThinkingCodeColour\(host, source, languageToken, settled\)/);
+ assert.match(live, /<FenceBody\s*isIncomplete=\{!settled\}/);
assert.equal(/useFenceTokens|code\.highlight|noteStreamingFence/.test(live), false, "no main-thread tokenizer for a growing thinking fence");
assert.match(live, /result === null \? \(\s*<PlainFenceShell language=\{languageToken\} source=\{source\} \/>/, "plain until the worker answers");
assert.match(MARKDOWN_TEXT, /const STREAMDOWN_PLAIN_CODE_PLUGINS = \{ math, mermaid \}/);
@@ -139,7 +140,13 @@ test("a completed fence on a non-``` form keeps the bounded renderer", () => {
),
"and it must render the per-line body rather than Block, or the spans remount",
);
- // Not `FenceBlock`: that branch also owns the reach latch, the action bar and the mode switch.
+ // In a thinking box the same forms, and a fence left open by Stop, keep their colour once settled.
+ assert.match(
+ branch,
+ /\) : \(\s*<LiveThinkingFence\s*language=\{settledFence\.language\}\s*settled\s*source=\{settledFence\.text\}/,
+ "a settled tilde, four-backtick, indented or stopped fence in a trace must not drop to the plain block",
+ );
+ // Not `FenceBlock`: that branch also owns the reach latch, the action bar and the mode switch.
assert.ok(
!/<FenceBlock[\s\S]{0,200}settledFence/.test(MARKDOWN_TEXT),
"widening FenceBlock would add controls and artifact paths to blocks that do not have them",