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: show long thinking in a capped box that scrolls on its own instead of Expand thinking (#16876)

Michael Han340b48c6f1fe
diff --git a/studio/frontend/src/components/assistant-ui/reasoning-transcript.tsx b/studio/frontend/src/components/assistant-ui/reasoning-transcript.tsx
index 53f67472333..1c34654824c 100644
--- a/studio/frontend/src/components/assistant-ui/reasoning-transcript.tsx
+++ b/studio/frontend/src/components/assistant-ui/reasoning-transcript.tsx
@@ -1123,7 +1123,20 @@ export function ReasoningTranscript({
{ root: scroll, rootMargin: "100% 0px" },
);
proximity?.observe(element);
+ // A capped Thinking box scrolls on its own, which the thread viewport never hears: mount what it reaches.
+ const tail = element.closest<HTMLElement>('[data-slot="reasoning-tail"]');
+ let tailFrame = 0;
+ const onTailScroll = () => {
+ if (tailFrame !== 0) return;
+ tailFrame = requestAnimationFrame(() => {
+ tailFrame = 0;
+ demandNow.current();
+ });
+ };
+ tail?.addEventListener("scroll", onTailScroll, { passive: true });
return () => {
+ tail?.removeEventListener("scroll", onTailScroll);
+ if (tailFrame !== 0) cancelAnimationFrame(tailFrame);
commitEdge.current = { before: () => {}, after: () => {} };
observer.disconnect();
proximity?.disconnect();
diff --git a/studio/frontend/src/components/assistant-ui/reasoning.tsx b/studio/frontend/src/components/assistant-ui/reasoning.tsx
index bbf8ca26e48..96b96e73af1 100644
--- a/studio/frontend/src/components/assistant-ui/reasoning.tsx
+++ b/studio/frontend/src/components/assistant-ui/reasoning.tsx
@@ -33,7 +33,6 @@ import {
clearReasoningRound,
foldIsActive,
reasoningTailCapped,
- reasoningTailFlexBox,
resolveReasoningGroupDuration,
resolveReasoningOpen,
setReasoningRoundOpen,
@@ -57,6 +56,7 @@ import { toolRunIsExempt } from "@/components/assistant-ui/tool-fold-exemptions"
import { useDetachThreadFromBottom } from "@/components/assistant-ui/use-intent-aware-autoscroll";
import { useCollapseScrollLock } from "@/hooks/use-collapse-scroll-lock";
import { formatWorkedFor } from "@/lib/format-worked-for";
+import { inputPointerHeld } from "@/lib/input-pointer-state";
import { cn } from "@/lib/utils";
import {
type ReasoningGroupComponent,
@@ -68,6 +68,7 @@ import { copyToClipboard } from "@/lib/copy-to-clipboard";
import { type VariantProps, cva } from "class-variance-authority";
import { Tick02Icon } from "@/lib/tick-icon";
import { Copy01Icon } from "@/lib/copy-icon";
+import { ArrowExpand01Icon, ArrowShrink01Icon } from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import { IconActionButton } from "./icon-action-button";
import {
@@ -503,105 +504,97 @@ function ReasoningBody({
);
}
-function useTailFlexBox(capped: boolean, streaming: boolean): boolean {
- const [flexBox, setFlexBox] = useState(capped);
- const next = reasoningTailFlexBox({ capped, streaming, previous: flexBox });
- if (next !== flexBox) {
- setFlexBox(next);
- }
- return next;
-}
+const READER_SCROLL_EVENTS = ["wheel", "touchmove", "keydown"] as const;
-// A fixed box (#11703): the newest lines while streaming, the start once finished. Clipped, not an inner
-// scroller, which split the reading anchor across two containers (#11704).
+// A fixed box (#11703) that scrolls on its own and follows a stream until the reader scrolls up.
function ReasoningTail({
- cappable,
+ capped,
expanded,
streaming,
- onExpandedChange,
+ onOverflowChange,
children,
}: {
- streaming: boolean;
- cappable: boolean;
+ capped: boolean;
+ /** Lifted by the header's expand button: uncapped, but keeps the capped spacing so nothing shifts. */
expanded: boolean;
- onExpandedChange: (expanded: boolean) => void;
+ streaming: boolean;
+ onOverflowChange: (overflowing: boolean) => void;
children: ReactNode;
}) {
const boxRef = useRef<HTMLDivElement>(null);
- const capped = cappable && !expanded;
- // Sticky while expanded: an unbounded box cannot measure its cap, and a trace only grows.
- const [overflowing, setOverflowing] = useState(false);
+ const following = useRef(true);
+ const overflowing = useRef(false);
+ const onOverflowRef = useRef(onOverflowChange);
+ onOverflowRef.current = onOverflowChange;
useLayoutEffect(() => {
const box = boxRef.current;
- const content = box?.firstElementChild as HTMLElement | null | undefined;
- if (!cappable) {
- setOverflowing(false);
+ const content = box?.firstElementChild;
+ if (!(capped && box && content)) {
+ box?.removeAttribute("data-more-below");
+ box?.removeAttribute("data-more-above");
return;
}
- if (!capped || !box || !content) return;
- const check = () => setOverflowing(content.offsetHeight > box.clientHeight);
- const observer = new ResizeObserver(check);
+ if (streaming) following.current = true;
+ const below = () => box.scrollHeight - box.scrollTop - box.clientHeight;
+ // Attributes, not state: a scroll must not re-render the trace.
+ const markEdges = () => {
+ box.toggleAttribute("data-more-below", below() > 1);
+ box.toggleAttribute("data-more-above", box.scrollTop > 0);
+ const now = box.scrollHeight > box.clientHeight + 1;
+ if (now !== overflowing.current) {
+ overflowing.current = now;
+ onOverflowRef.current(now);
+ }
+ };
+ const onResize = () => {
+ if (streaming && following.current) box.scrollTop = box.scrollHeight;
+ markEdges();
+ };
+ // Only the reader's own scroll stops the follow: rows mounting above shift scrollTop too.
+ let readerAt = Number.NEGATIVE_INFINITY;
+ const onReader = () => {
+ readerAt = performance.now();
+ };
+ // A scrollbar drag counts for as long as the press that started in the box is held.
+ let pressedHere = false;
+ const onPress = () => {
+ pressedHere = true;
+ onReader();
+ };
+ const onScroll = () => {
+ const atBottom = below() < 24;
+ pressedHere &&= inputPointerHeld();
+ if (atBottom || pressedHere || performance.now() - readerAt < 250) following.current = atBottom;
+ markEdges();
+ };
+ const observer = new ResizeObserver(onResize);
observer.observe(content);
observer.observe(box);
- check();
- return () => observer.disconnect();
- }, [cappable, capped]);
- const clipped = capped && overflowing;
- const flexBox = useTailFlexBox(capped, streaming);
+ box.addEventListener("scroll", onScroll, { passive: true });
+ for (const type of READER_SCROLL_EVENTS) box.addEventListener(type, onReader, { passive: true });
+ box.addEventListener("pointerdown", onPress, { passive: true });
+ onResize();
+ return () => {
+ observer.disconnect();
+ box.removeEventListener("scroll", onScroll);
+ for (const type of READER_SCROLL_EVENTS) box.removeEventListener(type, onReader);
+ box.removeEventListener("pointerdown", onPress);
+ };
+ }, [capped, streaming]);
return (
- <>
- <div
- ref={boxRef}
- data-slot="reasoning-tail"
- data-capped={capped ? "" : undefined}
- data-overflowing={clipped ? "" : undefined}
- onFocus={(event) => {
- // Clipped lines cannot scroll into view: a link focused in them expands the trace.
- const target = event.target.getBoundingClientRect();
- const box = event.currentTarget.getBoundingClientRect();
- if (
- clipped &&
- (streaming ? target.top < box.top : target.bottom > box.bottom)
- )
- onExpandedChange(true);
- }}
- className={cn(
- // The child rule stays on too: it is inert outside a flex box and toggling it restyles every row.
- cappable && "[&>*]:shrink-0",
- cappable && flexBox && "flex flex-col",
- // A mask paints only inside its box: bleed into the side padding so list markers survive.
- capped &&
- "-mx-[calc(1.25rem*var(--ui-space-scale,1))] min-w-0 max-h-[min(18rem,40vh)] overflow-hidden px-[calc(1.25rem*var(--ui-space-scale,1))] supports-[overflow:clip]:overflow-x-visible supports-[overflow:clip]:overflow-y-clip",
- capped && (streaming ? "justify-end" : "justify-start"),
- clipped &&
- (streaming
- ? "[mask-image:linear-gradient(to_bottom,transparent,black_3rem)]"
- : "[mask-image:linear-gradient(to_top,transparent,black_3rem)]"),
- )}
- >
- {children}
- </div>
- {cappable && overflowing && (
- <button
- type="button"
- data-slot="reasoning-show-full"
- aria-expanded={expanded}
- onClick={() => onExpandedChange(!expanded)}
- className="mt-2 inline-flex cursor-pointer items-center gap-1.5 font-medium text-muted-foreground text-xs transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
- >
- {expanded ? "Collapse thinking" : "Expand thinking"}
- <HugeiconsIcon
- icon={ChevronDownStandardIcon}
- aria-hidden={true}
- className={cn(
- "size-3.5 shrink-0 transition-transform duration-200 ease-out",
- // Below the trace, so Collapse points up at what it folds away; -180, not 180, turns a quarter.
- expanded ? "-rotate-180" : "-rotate-90",
- )}
- />
- </button>
+ <div
+ ref={boxRef}
+ data-slot="reasoning-tail"
+ data-capped={capped ? "" : undefined}
+ className={cn(
+ // The mask bleeds into the side padding (keeps list markers); expanded keeps this box so nothing rewraps.
+ (capped || expanded) &&
+ "-ml-[calc(1.25rem*var(--ui-space-scale,1))] -mr-[calc(0.5rem*var(--ui-space-scale,1))] mt-2 min-w-0 overflow-x-hidden overflow-y-auto pl-[calc(1.25rem*var(--ui-space-scale,1))] pr-[calc(0.5rem*var(--ui-space-scale,1))] pb-3 [scrollbar-gutter:stable] [&>[data-slot=reasoning-text]]:pt-1",
+ capped && "max-h-[min(22rem,48vh)]",
)}
- </>
+ >
+ {children}
+ </div>
);
}
@@ -625,12 +618,12 @@ const ReasoningGroupImpl: ReasoningGroupComponent = (props) => {
};
// Full --border: at 60% the line was nearly invisible on both themes.
-function ReasoningEndRule() {
+function ReasoningEndRule({ capped }: { capped: boolean }) {
return (
<div
data-slot="reasoning-end-rule"
aria-hidden={true}
- className="mt-4 border-border border-t"
+ className={cn(capped ? "mt-2" : "mt-6", "mb-2 border-border border-t")}
/>
);
}
@@ -698,7 +691,7 @@ const FoldedReasoningRound: ReasoningGroupComponent = ({
>
{children}
</ReasoningBody>
- {closesTrace && <ReasoningEndRule />}
+ {closesTrace && <ReasoningEndRule capped={false} />}
</div>
);
};
@@ -792,7 +785,9 @@ const ReasoningGroupBlock = ({
// null until toggled by hand, then it outranks the setting for the round.
const [override, setOverride] = useState<boolean | null>(null);
+ // Expand lifts the cap for this round only.
const [tailExpanded, setTailExpanded] = useState(false);
+ const [tailOverflowing, setTailOverflowing] = useState(false);
const [duration, setDuration] = useState<number>(0);
const startTimeRef = useRef<number | null>(null);
@@ -840,6 +835,7 @@ const ReasoningGroupBlock = ({
setClosingCapped(cappedNow);
}
const capped = isOpen ? cappedNow : closingCapped;
+ const showExpand = isOpen && capped && (tailOverflowing || tailExpanded);
// Publish the lead's open state for everything folded under it, and count the tool calls for
// its header. A layout effect, so the folded parts settle before the frame the user sees.
@@ -897,12 +893,29 @@ const ReasoningGroupBlock = ({
duration={persistedDuration ?? duration}
foldedToolCount={isOpen ? 0 : foldedToolCount}
/>
- {isOpen && !isReasoningStreaming && (
- <span className="ml-auto flex items-center leading-none">
- <ReasoningCopyButton
- startIndex={startIndex}
- endIndex={copyEndIndex}
- />
+ {isOpen && (showExpand || !isReasoningStreaming) && (
+ <span className="ml-auto flex items-center gap-1 leading-none">
+ {showExpand && (
+ <IconActionButton
+ label={tailExpanded ? "Collapse thinking" : "Expand thinking"}
+ aria-expanded={tailExpanded}
+ onClick={() => {
+ if (!tailExpanded) detachFromBottom();
+ setTailExpanded(!tailExpanded);
+ }}
+ >
+ <HugeiconsIcon
+ icon={tailExpanded ? ArrowShrink01Icon : ArrowExpand01Icon}
+ className="size-3"
+ />
+ </IconActionButton>
+ )}
+ {!isReasoningStreaming && (
+ <ReasoningCopyButton
+ startIndex={startIndex}
+ endIndex={copyEndIndex}
+ />
+ )}
</span>
)}
</div>
@@ -912,13 +925,10 @@ const ReasoningGroupBlock = ({
ref={reasoningContentRef}
>
<ReasoningTail
- cappable={capped}
- expanded={tailExpanded}
+ capped={capped && !tailExpanded}
+ expanded={capped && tailExpanded}
streaming={isReasoningStreaming}
- onExpandedChange={(expanded) => {
- setTailExpanded(expanded);
- if (expanded) handleOpenChange(true);
- }}
+ onOverflowChange={setTailOverflowing}
>
<ReasoningBody
transcript={transcript}
@@ -933,7 +943,7 @@ const ReasoningGroupBlock = ({
{children}
</ReasoningBody>
</ReasoningTail>
- {closesTrace && <ReasoningEndRule />}
+ {closesTrace && <ReasoningEndRule capped={capped} />}
</ReasoningContent>
</ReasoningRoot>
);
diff --git a/studio/frontend/src/features/chat/index.ts b/studio/frontend/src/features/chat/index.ts
index a198fd2fe13..479cd5015e5 100644
--- a/studio/frontend/src/features/chat/index.ts
+++ b/studio/frontend/src/features/chat/index.ts
@@ -499,7 +499,6 @@ export { resolveReasoningGroupDuration } from "./utils/reasoning-duration";
export {
reasoningFollowsPreference,
reasoningTailCapped,
- reasoningTailFlexBox,
resolveReasoningOpen,
startsNewReasoningRound,
} from "./utils/reasoning-visibility";
diff --git a/studio/frontend/src/features/chat/utils/reasoning-visibility.ts b/studio/frontend/src/features/chat/utils/reasoning-visibility.ts
index 48a5bdc2010..e5a787b4c1d 100644
--- a/studio/frontend/src/features/chat/utils/reasoning-visibility.ts
+++ b/studio/frontend/src/features/chat/utils/reasoning-visibility.ts
@@ -21,27 +21,12 @@ export function resolveReasoningOpen({
return resolveOpen(visibility, isStreaming, override);
}
-/** Under `auto` a block shows a bounded box (#11703) until its Expand toggle lifts it. */
export function reasoningTailCapped({
visibility,
}: Pick<ReasoningOpenStateInput, "visibility">): boolean {
return visibility === "auto";
}
-/** Whether a bounded box keeps its flex layout. Toggling it restyles the whole trace, so it drops
- * only for an Expand while streaming and returns only with the next cap, not when the stream ends. */
-export function reasoningTailFlexBox({
- capped,
- streaming,
- previous,
-}: {
- capped: boolean;
- streaming: boolean;
- previous: boolean;
-}): boolean {
- return capped || (!streaming && previous);
-}
-
/** Whether the block sits where the setting alone would put it. */
export function reasoningFollowsPreference(
open: boolean,
diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.css
index 7a26e0d0429..57dce91c698 100644
--- a/studio/frontend/src/index.css
+++ b/studio/frontend/src/index.css
@@ -1727,6 +1727,28 @@ html[data-code-wrap]:not([data-code-line-numbers]) :is(.aui-thread-root, [data-c
padding-inline-start: 0;
text-indent: 0;
}
+/* Capped Thinking box: fades only an edge with more past it; the second layer keeps the scrollbar unfaded. */
+[data-slot="reasoning-tail"][data-capped] {
+ --trace-fade-top: 0px;
+ --trace-fade-bottom: 0px;
+ mask-image:
+ linear-gradient(to bottom, transparent, #000 var(--trace-fade-top), #000 calc(100% - var(--trace-fade-bottom)), transparent),
+ linear-gradient(#000, #000);
+ mask-size: 100% 100%, calc(1rem * var(--ui-space-scale, 1)) 100%;
+ mask-position: 0 0, right;
+ mask-repeat: no-repeat;
+}
+[data-slot="reasoning-tail"][data-capped][data-more-above] {
+ --trace-fade-top: 1.25rem;
+}
+[data-slot="reasoning-tail"][data-capped][data-more-below] {
+ --trace-fade-bottom: 1.5rem;
+}
+@media print {
+ [data-slot="reasoning-tail"][data-capped] {
+ mask-image: none;
+ }
+}
html[data-code-no-ligatures] :is(pre, code, kbd, samp),
html[data-code-no-ligatures] .aui-reasoning-code-lines {
font-variant-ligatures: none;
diff --git a/studio/frontend/tests/reasoning-live-tail.test.ts b/studio/frontend/tests/reasoning-live-tail.test.ts
index 720984b62d8..0c242ac3c76 100644
--- a/studio/frontend/tests/reasoning-live-tail.test.ts
+++ b/studio/frontend/tests/reasoning-live-tail.test.ts
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-// The Thinking box (#11703): bounded under `auto`, lifted by its Expand toggle, never a scroller (#11704).
+// The Thinking box (#11703): bounded under `auto`, scrolling on its own with a bottom fade, no Expand toggle.
import assert from "node:assert/strict";
import test from "node:test";
@@ -13,7 +13,7 @@ registerBundlerResolver();
const { DISPLAY_VISIBILITIES } = await import(
"../src/features/chat/utils/display-visibility.ts"
);
-const { reasoningTailCapped, reasoningTailFlexBox, resolveReasoningOpen } = await import(
+const { reasoningTailCapped, resolveReasoningOpen } = await import(
"../src/features/chat/utils/reasoning-visibility.ts"
);
@@ -30,78 +30,6 @@ test("only the auto setting bounds a block, whether the stream or a hand opened
}
});
-// Mirrors useTailFlexBox: the first state is `capped`, then each render feeds the last result back.
-function flexBoxTrace(steps: readonly { capped: boolean; streaming: boolean }[]): boolean[] {
- let previous = steps[0]?.capped ?? false;
- return steps.map((step) => {
- previous = reasoningTailFlexBox({ ...step, previous });
- return previous;
- });
-}
-
-test("the flex box survives Expand/Collapse once finished and never flips when a stream ends", () => {
- const capped = { capped: true, streaming: false };
- const expanded = { capped: false, streaming: false };
- const live = { capped: true, streaming: true };
- const liveExpanded = { capped: false, streaming: true };
-
- assert.deepEqual(flexBoxTrace([capped, expanded, capped, expanded]), [true, true, true, true]);
- assert.deepEqual(
- flexBoxTrace([live, liveExpanded, expanded, capped, expanded]),
- [true, false, false, true, true],
- );
- assert.deepEqual(flexBoxTrace([live, capped, expanded]), [true, true, true]);
- assert.deepEqual(flexBoxTrace([expanded, expanded]), [false, false]);
- assert.deepEqual(flexBoxTrace([live, liveExpanded, live]), [true, false, true]);
-});
-
-test("the box clips at the top instead of scrolling, and Expand toggles without a permanent open", () => {
- const tail = reasoning.slice(
- reasoning.indexOf("function ReasoningTail("),
- reasoning.indexOf("// With the fold preference on"),
- );
- assert.match(
- tail,
- /capped &&\s*"-mx-\[[^\]]+\] min-w-0 max-h-\[[^\]]+\] overflow-hidden px-\[[^\]]+\] supports-\[overflow:clip\]:overflow-x-visible supports-\[overflow:clip\]:overflow-y-clip"/,
- );
- // Toggling the flex box or the child rule on a finished box restyles every row.
- assert.match(tail, /cappable && "\[&>\*\]:shrink-0"/);
- assert.match(
- reasoning,
- /const next = reasoningTailFlexBox\(\{ capped, streaming, previous: flexBox \}\);/,
- );
- assert.match(tail, /cappable && flexBox && "flex flex-col"/);
- assert.doesNotMatch(tail, /overflow-(y-)?(auto|scroll)|scrollTop|scrollTo\(/);
- assert.match(
- reasoning,
- /const cappedNow = !foldLead && reasoningTailCapped\(\{ visibility \}\);/,
- );
- assert.match(tail, /\{cappable && overflowing && \(/);
- assert.match(tail, /onClick=\{\(\) => onExpandedChange\(!expanded\)\}/);
- assert.match(tail, /aria-expanded=\{expanded\}/);
- assert.match(tail, /\{expanded \? "Collapse thinking" : "Expand thinking"\}/);
- assert.match(reasoning, /bounded=\{capped && !tailExpanded\}/);
- assert.match(reasoning, /setOverride\(null\);\s*setTailExpanded\(false\);/);
-});
-
-test("changing the setting drops a hand Expand along with the hand open", () => {
- assert.match(
- reasoning,
- /if \(lastVisibility !== visibility\) \{\s*setLastVisibility\(visibility\);\s*setOverride\(null\);\s*setTailExpanded\(false\);\s*\}/,
- );
-});
-
-test("focus landing in the clipped lines lifts the cap instead of staying invisible", () => {
- const tail = reasoning.slice(
- reasoning.indexOf("function ReasoningTail("),
- reasoning.indexOf("// With the fold preference on"),
- );
- assert.match(
- tail,
- /onFocus=\{\(event\) => \{[\s\S]*?clipped &&\s*\(streaming \? target\.top < box\.top : target\.bottom > box\.bottom\)[\s\S]*?onExpandedChange\(true\);/,
- );
-});
-
test("a bounded transcript corrects nothing through the thread and mounts the tail", () => {
assert.match(
transcript,
@@ -132,23 +60,60 @@ test("a closing block keeps the cap it had while open", () => {
assert.ok(open !== -1 && open < reasoning.indexOf("const cappedNow ="));
});
-test("Expand thinking ends in a chevron: right while bounded, up once expanded", () => {
- const tail = reasoning.slice(
- reasoning.indexOf("function ReasoningTail("),
- reasoning.indexOf("// With the fold preference on"),
- );
+const tail = reasoning.slice(
+ reasoning.indexOf("function ReasoningTail("),
+ reasoning.indexOf("// With the fold preference on"),
+);
+
+test("the box scrolls on its own with no border, its scrollbar always showing, close to the text", () => {
assert.match(
tail,
- /\{expanded \? "Collapse thinking" : "Expand thinking"\}\s*<HugeiconsIcon\s+icon=\{ChevronDownStandardIcon\}[\s\S]*?expanded \? "-rotate-180" : "-rotate-90"/,
+ /\(capped \|\| expanded\) &&\s*"-ml-\[[^\]]+\] -mr-\[[^\]]+\] mt-2 min-w-0 overflow-x-hidden overflow-y-auto pl-\[[^\]]+\] pr-\[[^\]]+\] pb-3 \[scrollbar-gutter:stable\] \[&>\[data-slot=reasoning-text\]\]:pt-1"/,
);
+ // Only the cap drops on expand: the box keeps its gutter, so the width holds.
+ assert.match(tail, /capped && "max-h-\[min\(22rem,48vh\)\]"/);
+ assert.doesNotMatch(tail, /hover-scrollbar/);
+ assert.doesNotMatch(tail, /\bborder\b|Expand thinking|overflow-y-clip/);
+ assert.doesNotMatch(reasoning, /reasoning-show-full/);
+ assert.match(reasoning, /const cappedNow = !foldLead && reasoningTailCapped\(\{ visibility \}\);/);
});
-test("a streaming box shows the newest lines, a finished one shows the start", () => {
- const tail = reasoning.slice(
- reasoning.indexOf("function ReasoningTail("),
- reasoning.indexOf("// With the fold preference on"),
- );
- assert.match(tail, /capped && \(streaming \? "justify-end" : "justify-start"\)/);
- assert.match(tail, /to_bottom,transparent[\s\S]*?to_top,transparent/);
- assert.match(reasoning, /streaming=\{isReasoningStreaming\}\s*onExpandedChange=/);
+test("the header's expand button lifts the cap for the round and appears only when the box overflows", () => {
+ assert.match(reasoning, /const showExpand = isOpen && capped && \(tailOverflowing \|\| tailExpanded\);/);
+ assert.match(reasoning, /label=\{tailExpanded \? "Collapse thinking" : "Expand thinking"\}/);
+ assert.match(reasoning, /icon=\{tailExpanded \? ArrowShrink01Icon : ArrowExpand01Icon\}/);
+ assert.match(reasoning, /capped=\{capped && !tailExpanded\}/);
+ assert.match(reasoning, /expanded=\{capped && tailExpanded\}/);
+ assert.match(reasoning, /bounded=\{capped && !tailExpanded\}/);
+ assert.match(reasoning, /setOverride\(null\);\s*setTailExpanded\(false\);/);
+ assert.match(tail, /if \(now !== overflowing\.current\) \{\s*overflowing\.current = now;\s*onOverflowRef\.current\(now\);/);
+});
+
+test("a streaming box follows its newest line until the reader scrolls up", () => {
+ assert.match(tail, /if \(streaming\) following\.current = true;/);
+ assert.match(tail, /if \(streaming && following\.current\) box\.scrollTop = box\.scrollHeight;/);
+ assert.match(tail, /if \(atBottom \|\| pressedHere \|\| performance\.now\(\) - readerAt < 250\) following\.current = atBottom;/);
+ assert.match(reasoning, /const READER_SCROLL_EVENTS = \["wheel", "touchmove", "keydown"\] as const;/);
+});
+
+test("a scrollbar drag stops the follow for as long as the press that started in the box is held", () => {
+ assert.match(tail, /box\.addEventListener\("pointerdown", onPress, \{ passive: true \}\);/);
+ assert.match(tail, /pressedHere &&= inputPointerHeld\(\);/);
+});
+
+test("scrolling inside the capped box mounts the passages it reaches", () => {
+ assert.match(transcript, /const tail = element\.closest<HTMLElement>\('\[data-slot="reasoning-tail"\]'\);/);
+ assert.match(transcript, /tail\?\.addEventListener\("scroll", onTailScroll, \{ passive: true \}\);/);
+ assert.match(transcript, /tailFrame = 0;\s*demandNow\.current\(\);/);
+});
+
+test("each edge fades only while more is past it, set without a re-render", () => {
+ assert.match(tail, /box\.toggleAttribute\("data-more-below", below\(\) > 1\)/);
+ assert.match(tail, /box\.toggleAttribute\("data-more-above", box\.scrollTop > 0\)/);
+ const css = readSrc("index.css");
+ assert.match(css, /\[data-slot="reasoning-tail"\]\[data-capped\]\[data-more-above\] \{\s*--trace-fade-top: 1\.25rem;/);
+ assert.match(css, /\[data-slot="reasoning-tail"\]\[data-capped\]\[data-more-below\] \{\s*--trace-fade-bottom: 1\.5rem;/);
+ assert.match(css, /linear-gradient\(#000, #000\);\s*mask-size: 100% 100%, calc\(1rem \* var\(--ui-space-scale, 1\)\) 100%;\s*mask-position: 0 0, right;/);
+ assert.match(reasoning, /capped \? "mt-2" : "mt-6", "mb-2 border-border border-t"/);
+ assert.doesNotMatch(tail, /setState|useState/);
});
diff --git a/studio/frontend/tests/thinking-fold.test.ts b/studio/frontend/tests/thinking-fold.test.ts
index 0fd86860376..1cee9b96d5b 100644
--- a/studio/frontend/tests/thinking-fold.test.ts
+++ b/studio/frontend/tests/thinking-fold.test.ts
@@ -239,7 +239,7 @@ test("the rule that closes the trace goes on the last thing before the answer",
const reasoning = readSrc("components/assistant-ui/reasoning.tsx");
const toolGroup = readSrc("components/assistant-ui/tool-group.tsx");
assert.equal(
- reasoning.match(/closesTrace && <ReasoningEndRule \/>/g)?.length,
+ reasoning.match(/closesTrace && <ReasoningEndRule capped=\{(?:capped|false)\} \/>/g)?.length,
2,
);
assert.match(
@@ -281,7 +281,7 @@ test("the header row keeps its height when Copy appears", () => {
// A bare span would take the paragraph line-height and push the label down when opened.
assert.match(
reasoning,
- /<span className="ml-auto flex items-center leading-none">\n\s*<ReasoningCopyButton/,
+ /<span className="ml-auto flex items-center gap-1 leading-none">/,
);
});