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.

fix(studio): show original chat model in the header (#13398)

Eyera7be2c951e2db
diff --git a/studio/frontend/src/components/assistant-ui/thread.tsx b/studio/frontend/src/components/assistant-ui/thread.tsx
index 824177b4313..90886b838d1 100644
--- a/studio/frontend/src/components/assistant-ui/thread.tsx
+++ b/studio/frontend/src/components/assistant-ui/thread.tsx
@@ -2346,10 +2346,7 @@ export const Thread: FC<{
"aui-thread-viewport aui-stream-viewport relative flex min-h-0 min-w-0 flex-1 basis-0 flex-col overflow-x-auto overflow-y-auto scroll-smooth px-5",
hideComposer
? "pt-4"
- : // + the chat-model notice, which is an opaque absolute bar
- // directly under the header. 0px whenever it is not showing,
- // so every other surface keeps the padding it had.
- "[--thread-header-offset:calc(var(--studio-content-top-inset,0px)-var(--studio-chat-scroller-top,0px)+var(--studio-chat-header-height,48px)+var(--studio-chat-notice-height,0px))] mt-[var(--studio-chat-scroller-top,0px)] pt-[var(--thread-header-offset)]",
+ : "[--thread-header-offset:calc(var(--studio-content-top-inset,0px)-var(--studio-chat-scroller-top,0px)+var(--studio-chat-header-height,48px))] mt-[var(--studio-chat-scroller-top,0px)] pt-[var(--thread-header-offset)]",
)}
/>
<GeneratedImageViewportOverlay
diff --git a/studio/frontend/src/features/chat/chat-page.tsx b/studio/frontend/src/features/chat/chat-page.tsx
index 5364a0c6004..4c25c7fbc03 100644
--- a/studio/frontend/src/features/chat/chat-page.tsx
+++ b/studio/frontend/src/features/chat/chat-page.tsx
@@ -4646,16 +4646,9 @@ export function ChatPage({
used to own it only renders once it is. Mounted through the route change so it can close
itself on the way out. */}
<McpServersDialogMount />
- {/* `--studio-chat-notice-height` is 0 until ChatModelNotice is on screen; the thread viewport
- adds it to the top padding, so without it the first message reads under an opaque bar.
- Declared on the nearest ancestor of BOTH so the two cannot disagree. `has-[>...]`, not
- `has-[...]`: a `:has()` with a DESCENDANT argument is re-checked on any insertion in the
- subtree, which walks the whole thread on every mutation - 17.5 ms per append on a 357k-
- element thread, against 0.10 ms without this rule (Chromium). ChatModelNotice renders a
- direct child, which tests/thread-ancestor-has-scope.test.ts asserts. */}
<div
data-chat-content-root=""
- className="relative flex min-h-0 min-w-0 flex-1 basis-0 flex-col overflow-hidden has-[>[data-chat-model-notice]]:[--studio-chat-notice-height:2.25rem]"
+ className="relative flex min-h-0 min-w-0 flex-1 basis-0 flex-col overflow-hidden"
>
<NativeModelDropOverlay state={nativeModelDropState} />
{/* Fade under the top bar so messages dissolve as they scroll beneath it, instead of a hard cut. */}
@@ -4663,7 +4656,7 @@ export function ChatPage({
<div
aria-hidden
data-side-panel-inset=""
- className="chat-header-fade pointer-events-none absolute left-[var(--studio-side-panel-left,0px)] right-[calc(var(--thread-scrollbar-gutter,10px)+var(--studio-side-panel-width,0px))] top-[calc(var(--studio-content-top-inset,0px)+var(--studio-chat-header-height,48px)+var(--studio-chat-notice-height,0px))] z-20 h-6 bg-gradient-to-b from-background to-transparent"
+ className="chat-header-fade pointer-events-none absolute left-[var(--studio-side-panel-left,0px)] right-[calc(var(--thread-scrollbar-gutter,10px)+var(--studio-side-panel-width,0px))] top-[calc(var(--studio-content-top-inset,0px)+var(--studio-chat-header-height,48px))] z-20 h-6 bg-gradient-to-b from-background to-transparent"
/>
)}
<div
@@ -4681,7 +4674,7 @@ export function ChatPage({
"right-[var(--thread-scrollbar-gutter,10px)] left-auto w-auto bg-transparent pl-0 pr-[calc(0.5rem*var(--ui-space-scale,1)+var(--studio-chat-header-right-inset,var(--studio-window-control-inset,0px)))]",
)}
>
- <div className="pointer-events-auto flex min-w-0 items-center gap-1">
+ <div className="group/chat-model-controls pointer-events-auto flex min-w-0 items-center gap-1">
{isTauri && !isMobile && !pinned && view.mode !== "compare" && (
<Button
type="button"
@@ -4735,7 +4728,17 @@ export function ChatPage({
triggerDataTour="chat-model-selector"
contentDataTour="chat-model-selector-popover"
showCloudIndicator={isExternalModel}
- className="max-w-[62vw] !pr-3 md:max-w-none !h-[var(--studio-chat-control-height,34px)]"
+ className="max-w-[62vw] !pr-3 md:max-w-none !h-[var(--studio-chat-control-height,34px)] max-sm:group-has-[>[data-chat-model-notice]]/chat-model-controls:!px-2 max-sm:group-has-[>[data-chat-model-notice]]/chat-model-controls:!gap-0"
+ />
+ )}
+ {view.mode === "single" && (
+ <ChatModelNotice
+ active={active}
+ threadId={view.threadId ?? newChatThreadId ?? undefined}
+ checkpoint={inferenceCheckpoint}
+ activeGgufVariant={activeGgufVariant}
+ selectableModelIds={selectableModelIds}
+ onSwitch={handleSwitchBackToChatModel}
/>
)}
{view.mode !== "compare" && currentProjectId && (
@@ -4813,6 +4816,7 @@ export function ChatPage({
(view.mode === "project" && activeThreadId != null)) &&
(contextUsage || contextWindowKnown) ? (
<ContextUsageBar
+ compactUnknownAsIcon={view.mode === "single"}
used={contextUsage?.contextTokens ?? contextUsage?.totalTokens ?? null}
// null on external providers; the bar handles that.
total={loadedContextLength}
@@ -4914,16 +4918,6 @@ export function ChatPage({
</div>
</div>
- {view.mode === "single" && (
- <ChatModelNotice
- threadId={view.threadId ?? newChatThreadId ?? undefined}
- checkpoint={inferenceCheckpoint}
- activeGgufVariant={activeGgufVariant}
- selectableModelIds={selectableModelIds}
- onSwitch={handleSwitchBackToChatModel}
- />
- )}
-
{/* One provider shared by the project and single views, never keyed on thread / nonce / project,
so switching between them reattaches the live run instead of remounting the runtime and
aborting generation (#8908). Any key here brings the bug back. Compare renders as a
diff --git a/studio/frontend/src/features/chat/components/chat-model-notice.tsx b/studio/frontend/src/features/chat/components/chat-model-notice.tsx
index 2e8d14594fa..ac319ecc623 100644
--- a/studio/frontend/src/features/chat/components/chat-model-notice.tsx
+++ b/studio/frontend/src/features/chat/components/chat-model-notice.tsx
@@ -1,9 +1,22 @@
// 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 { ArrowTurnBackwardIcon } from "@hugeicons/core-free-icons";
+import { HugeiconsIcon } from "@hugeicons/react";
+import { Popover as PopoverPrimitive } from "radix-ui";
import { useEffect, useState } from "react";
import { Button } from "@/components/ui/button";
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@/components/ui/popover";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from "@/components/ui/tooltip";
import { modelDisplayName } from "../../model-picker/model-config/model-identity";
import {
CHAT_HISTORY_UPDATED_EVENT,
@@ -53,6 +66,8 @@ export function useChatCreatedModel(
}
type ChatModelNoticeProps = {
+ /** Keep the history reader mounted while the chat route is hidden. */
+ active: boolean;
/** The saved chat on screen, or undefined for an unsent New Chat. */
threadId: string | undefined;
/** The model the composer will actually send to. */
@@ -67,6 +82,7 @@ type ChatModelNoticeProps = {
* automatic switch: for a local model that would evict whatever is resident and spend a
* multi-gigabyte load on opening a chat. */
export function ChatModelNotice({
+ active,
threadId,
checkpoint,
activeGgufVariant,
@@ -74,6 +90,8 @@ export function ChatModelNotice({
onSwitch,
}: ChatModelNoticeProps) {
const createdModel = useChatCreatedModel(threadId);
+ // Drop the portaled UI off-route, retaining the successful read and history subscription.
+ if (!active) return null;
if (!createdModel) return null;
if (chatModelIsResident(createdModel, checkpoint, activeGgufVariant)) {
return null;
@@ -92,26 +110,62 @@ export function ChatModelNotice({
externalModelLabel(createdModel.modelId) ??
modelDisplayName(createdModel.modelId);
return (
- // Positioned, not in flow. The chat header is `absolute ... z-40` with an opaque `bg-background`,
- // so an in-flow sibling starts at y=0 UNDER it and the bar is invisible bar the scrollbar gutter
- // the header leaves uncovered. Offset by the same header height the drop overlay
- // and the header fade use, above the fade (z-20) and below the header (z-40).
- <div
- data-chat-model-notice=""
- data-side-panel-inset=""
- className="absolute left-[var(--studio-side-panel-left,0px)] right-[calc(var(--thread-scrollbar-gutter,10px)+var(--studio-side-panel-width,0px))] top-[calc(var(--studio-content-top-inset,0px)+var(--studio-chat-header-height,48px))] z-30 flex h-[var(--studio-chat-notice-height,2.25rem)] items-center gap-2 border-b border-border/60 bg-muted px-4 text-ui-12 text-muted-foreground"
- >
- <span className="min-w-0 truncate">
- This chat was started on <span className="font-medium">{label}</span>.
- </span>
- <Button
- variant="ghost"
- size="sm"
- className="ml-auto h-6 shrink-0 px-2 text-ui-12"
- onClick={() => onSwitch(switchTarget)}
+ <Popover key={threadId}>
+ <Tooltip>
+ <TooltipTrigger asChild={true} disableClickToggle={true}>
+ <PopoverTrigger asChild={true}>
+ <button
+ type="button"
+ data-chat-model-notice=""
+ aria-label={`Original model: ${label}`}
+ className="flex h-[var(--studio-chat-control-height,34px)] min-w-[calc(30px*var(--ui-space-scale,1))] max-w-56 shrink cursor-pointer items-center rounded-[10px] px-2 text-ui-13 text-nav-fg transition-colors hover:bg-nav-surface-hover hover:text-black focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring aria-expanded:bg-nav-surface-hover aria-expanded:text-black dark:hover:text-white dark:aria-expanded:text-white max-sm:min-w-[calc(22px*var(--ui-space-scale,1))] max-sm:px-1"
+ >
+ <HugeiconsIcon
+ icon={ArrowTurnBackwardIcon}
+ strokeWidth={1.75}
+ className="size-3.5 shrink-0"
+ aria-hidden={true}
+ />
+ {/* Keep the label's spacing inside its clipped box so an icon-only trigger fits. */}
+ <span className="min-w-0 truncate before:inline-block before:w-1.5 before:content-['']">
+ {label}
+ </span>
+ </button>
+ </PopoverTrigger>
+ </TooltipTrigger>
+ <TooltipContent side="bottom" sideOffset={6}>
+ Original model: {label}
+ </TooltipContent>
+ </Tooltip>
+ <PopoverContent
+ align="start"
+ sideOffset={6}
+ collisionPadding={12}
+ aria-label="Original model"
+ className="menu-soft-surface w-64 gap-1 rounded-[14px] p-1"
>
- Switch back
- </Button>
- </div>
+ <div className="space-y-1 px-3 py-2">
+ <p className="text-ui-12 text-muted-foreground">Original model</p>
+ <p className="break-words text-ui-13 font-medium">{label}</p>
+ </div>
+ <PopoverPrimitive.Close asChild={true}>
+ <Button
+ type="button"
+ variant="ghost"
+ size="sm"
+ className="h-8 justify-start gap-2.5 rounded-[10px] px-3 text-ui-13 font-normal"
+ onClick={() => onSwitch(switchTarget)}
+ >
+ <HugeiconsIcon
+ icon={ArrowTurnBackwardIcon}
+ strokeWidth={1.75}
+ className="size-icon"
+ aria-hidden={true}
+ />
+ Switch back
+ </Button>
+ </PopoverPrimitive.Close>
+ </PopoverContent>
+ </Popover>
);
}
diff --git a/studio/frontend/src/features/chat/components/context-usage-bar.tsx b/studio/frontend/src/features/chat/components/context-usage-bar.tsx
index 4258b5884db..2a8f292f285 100644
--- a/studio/frontend/src/features/chat/components/context-usage-bar.tsx
+++ b/studio/frontend/src/features/chat/components/context-usage-bar.tsx
@@ -101,18 +101,21 @@ const Face: FC<{ face: string }> = ({ face }) => {
};
export const ContextUsageBar: FC<
- ContextUsageBarInput & { className?: string }
-> = ({ className, ...input }) => {
+ ContextUsageBarInput & { className?: string; compactUnknownAsIcon?: boolean }
+> = ({ className, compactUnknownAsIcon = false, ...input }) => {
const state = deriveContextUsageBar(input);
if (!state) return null;
const { cached, cacheWrites, promptTokens, completionTokens } = input.estimated
? {}
: input;
- const { percent, advice, face, compactFace } = state;
+ const { percent, advice, face } = state;
+ // A narrow chat header needs the icon fallback even when a provider has no known window.
+ // The tooltip and accessible label still carry the full token count.
+ const compactFace = compactUnknownAsIcon ? null : state.compactFace;
const severity = getSeverityColor(percent ?? 0);
// The ring shows whenever there is a window to fill, even before anything is counted.
- const showRing = compactFace === null;
+ const showRing = state.compactFace === null;
// Mono text, so widths are exact in ch. Full: padding, face, and the gap and ring. Compact: an icon button.
const fullWidth = showRing
? `calc(${faceWidthCh(face)}ch + var(--icon-size) + 7 * var(--spacing))`
diff --git a/studio/frontend/src/features/chat/components/research-activity-panel.tsx b/studio/frontend/src/features/chat/components/research-activity-panel.tsx
index c93221de7b1..d07a0e5b731 100644
--- a/studio/frontend/src/features/chat/components/research-activity-panel.tsx
+++ b/studio/frontend/src/features/chat/components/research-activity-panel.tsx
@@ -894,14 +894,11 @@ export function ResearchActivityPanel({
style={
variant === "panel"
? {
- // The chat-model notice is an opaque absolute bar spanning the whole chat content area, the
- // panel column included, directly under the header. Clear it the same way the header itself is
- // cleared, or its first 2.25rem is painted over and unclickable. 0px whenever no notice is on
- // screen, so this is the geometry it always had.
+ // Keep the panel's controls below the absolute chat header.
height:
- "calc(100% - var(--studio-content-top-inset, 0px) - var(--studio-chat-header-height, 48px) - var(--studio-chat-notice-height, 0px))",
+ "calc(100% - var(--studio-content-top-inset, 0px) - var(--studio-chat-header-height, 48px))",
marginTop:
- "calc(var(--studio-content-top-inset, 0px) + var(--studio-chat-header-height, 48px) + var(--studio-chat-notice-height, 0px))",
+ "calc(var(--studio-content-top-inset, 0px) + var(--studio-chat-header-height, 48px))",
}
: undefined
}
diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.css
index cf8cd9d7513..6d7113322f0 100644
--- a/studio/frontend/src/index.css
+++ b/studio/frontend/src/index.css
@@ -5999,10 +5999,9 @@ html[data-find-bar-open] [data-sonner-toaster][data-y-position="top"] {
.chat-full-view-dock {
--dock-surface: #ffffff;
- /* No header or notice above this thread. */
+ /* No header above this thread. */
--studio-content-top-inset: 0px;
--studio-chat-header-height: 0px;
- --studio-chat-notice-height: 0px;
--studio-chat-scroller-top: 0px;
height: auto;
border-radius: 28px;
diff --git a/studio/frontend/tests/chat-remembers-its-model.test.ts b/studio/frontend/tests/chat-remembers-its-model.test.ts
index c6cc6a84ecc..e8986c7e68b 100644
--- a/studio/frontend/tests/chat-remembers-its-model.test.ts
+++ b/studio/frontend/tests/chat-remembers-its-model.test.ts
@@ -270,122 +270,44 @@ test("a snapshot-path chat is labelled by its repo name, not the revision sha",
assert.match(body, /modelDisplayName\(createdModel\.modelId\)/);
});
-test("the notice clears the chat header instead of rendering underneath it", () => {
- // The bug this pins: the notice was an in-flow sibling of the chat header, and the
- // header is `absolute ... top-[--studio-content-top-inset] z-40` with an OPAQUE
- // bg-background. Per CSS painting order a positioned element is painted above every
- // non-positioned one whatever the source order, so the whole bar sat underneath the
- // header and only the 10px the header's `right-[10px]` leaves uncovered was visible.
- // Measured on a built Unsloth: the notice's rect was {x:280,y:0,w:1220,h:37}, exactly
- // the header's own band, and the before/after screenshots differed by a 10x37 sliver.
- const header = slice(page, "chat-header-fade", "</div>");
- assert.match(header, /z-40/, "the header is still the z-40 absolute overlay");
-
- const body = notice.slice(notice.indexOf("export function ChatModelNotice"));
- // Anchored on the marker attribute, not on `<div className="`: the bar carries
- // other attributes now, and the shape of the opening tag is not the contract.
- const tag = slice(body, "data-chat-model-notice", "\n >");
- const div = slice(tag, 'className="', '"');
- // Positioned, so it is not painted under the header.
- assert.match(div, /\babsolute\b/);
- // Offset by the SAME header height the header, its fade and the drop overlay use,
- // so a change to either variable moves all four together.
+test("the original-model control sits beside the picker in the chat header", () => {
+ const header = slice(page, "chat-header-fade", "{/* One provider shared");
+ assert.match(header, /<ModelSelector[\s\S]*<ChatModelNotice/);
assert.match(
- div,
- /top-\[calc\(var\(--studio-content-top-inset,0px\)\+var\(--studio-chat-header-height,48px\)\)\]/,
+ header,
+ /\{view\.mode === "single" && \(\s*<ChatModelNotice\s+active=\{active\}/,
);
- // Between the header fade (z-20) and the header itself (z-40): over the gradient,
- // under the model picker, whose menu must stay clickable.
- const z = /\bz-(\d+)\b/.exec(div);
- assert.ok(z, "the notice needs an explicit z-index");
- assert.ok(
- Number(z[1]) > 20 && Number(z[1]) < 40,
- `notice z-${z[1]} must sit above the z-20 fade and below the z-40 header`,
- );
- // An overlay over the scrolling conversation must be opaque, or messages read
- // through it. bg-muted/40 was fine only while the bar took its own row.
- assert.doesNotMatch(
- div,
- /bg-muted\//,
- "a translucent overlay lets messages show through",
+ // Hide the portaled UI after the hook runs, keeping the saved model and subscription off-route.
+ assert.match(
+ notice,
+ /const createdModel = useChatCreatedModel\(threadId\);[\s\S]*?if \(!active\) return null;/,
);
+ // A chat change must dismiss a portaled popover along with its old model details.
+ assert.match(notice, /<Popover key=\{threadId\}>/);
});
-test("the conversation reserves the space the notice overlay takes", () => {
- // Measured on a built Unsloth before this: the viewport reserved exactly the
- // header's 48px, the notice sat opaque at y 48..85, and the first message's own
- // rect started at y=48 -- elementFromPoint returned the notice for every sample
- // across its band, in a 2-turn chat AND in a 40-turn chat scrolled to the top.
- // An overlay that reserves nothing hides content; the header gets away with it
- // only because chat-header-fade dissolves what slides under it.
-
- // One declaration of the height, on the nearest ancestor of both, so the bar and
- // the padding cannot drift apart.
- //
- // `has-[>...]`, not `has-[...]`: the descendant form made every DOM change anywhere in the
- // thread re-check this `:has()` on an ancestor of every message, and answering it walks the
- // whole thread. Measured at the 500K rung on a 357,843-element thread, appending one empty span
- // inside a message cost 17.5 / 18.6 ms with the descendant form and 0.10 ms once this rule and
- // the sidebar wrapper's were both put in their child form. The notice is a direct child of the
- // declaring element, so the two selectors match the same elements; that is asserted separately
- // in `tests/thread-ancestor-has-scope.test.ts`, which is what keeps the child form honest.
- assert.match(
- page,
- /has-\[>\[data-chat-model-notice\]\]:\[--studio-chat-notice-height:2\.25rem\]/,
- );
- // The notice claims the same variable rather than a padding of its own.
- assert.match(notice, /data-chat-model-notice=""/);
- assert.match(notice, /h-\[var\(--studio-chat-notice-height,2\.25rem\)\]/);
- assert.doesNotMatch(
- notice.slice(notice.indexOf("data-chat-model-notice")),
- /py-1\.5/,
- "a fixed height and a vertical padding would disagree about the bar's size",
- );
- // The viewport adds it to what it already reserved for the header, defaulting to
- // 0px so every surface without a notice keeps exactly the padding it had.
+test("the conversation and research panel reserve only the chat header", () => {
+ // The original-model control lives inside the header, so it needs no extra row.
+ for (const source of [page, notice, thread, researchPanel]) {
+ assert.doesNotMatch(source, /--studio-chat-notice-height/);
+ }
assert.match(
thread,
- /\[--thread-header-offset:calc\(var\(--studio-content-top-inset,0px\)-var\(--studio-chat-scroller-top,0px\)\+var\(--studio-chat-header-height,48px\)\+var\(--studio-chat-notice-height,0px\)\)\] mt-\[var\(--studio-chat-scroller-top,0px\)\] pt-\[var\(--thread-header-offset\)\]/,
+ /\[--thread-header-offset:calc\(var\(--studio-content-top-inset,0px\)-var\(--studio-chat-scroller-top,0px\)\+var\(--studio-chat-header-height,48px\)\)\] mt-\[var\(--studio-chat-scroller-top,0px\)\] pt-\[var\(--thread-header-offset\)\]/,
);
- // And the fade moves down with it, or it would dissolve behind the opaque bar.
const fade = slice(page, "chat-header-fade", '"');
- assert.match(fade, /\+var\(--studio-chat-notice-height,0px\)\)\]/);
-});
-
-test("the research panel reserves the notice's height too", () => {
- // The thread viewport is not the only surface the bar covers. The notice is an
- // absolute child of the chat content container (chat-page.tsx), so its
- // containing block is that whole container -- the deep-research column
- // included, not just the thread pane. ResearchActivityPanel offsets itself by
- // the header height for exactly the same reason, which lands its header at the
- // notice's top edge.
- //
- // Measured on an Unsloth built from this tree, saved chat on claude-opus-4-5 with
- // the composer on gpt-5-mini and the research panel open: notice rect
- // {top:48,bottom:84,left:280,right:1590}, aside {top:48,left:1099.41,right:1600}
- // -> 36px x 490.59px of the aside covered, which is its entire header band.
- // elementFromPoint at the centre of the "Deep research" h2 (1212,73) and at the
- // centre of the close button (1568,78) BOTH returned the notice, so it was
- // swallowing the clicks, not merely painting over them. With the checkpoint set
- // to the chat's own model the notice self-suppresses and both return the h2 and
- // the button. The aside's margin-top was 48px in every case: nothing
- // compensated for it.
- const style = slice(researchPanel, 'variant === "panel"', ": undefined");
- // Both edges move, or the panel keeps its old height and overflows the bottom.
assert.match(
- style,
- /marginTop:\s*\n?\s*"calc\(var\(--studio-content-top-inset, 0px\) \+ var\(--studio-chat-header-height, 48px\) \+ var\(--studio-chat-notice-height, 0px\)\)"/,
+ fade,
+ /top-\[calc\(var\(--studio-content-top-inset,0px\)\+var\(--studio-chat-header-height,48px\)\)\]/,
);
+ const style = slice(researchPanel, 'variant === "panel"', ": undefined");
assert.match(
style,
- /height:\s*\n?\s*"calc\(100% - var\(--studio-content-top-inset, 0px\) - var\(--studio-chat-header-height, 48px\) - var\(--studio-chat-notice-height, 0px\)\)"/,
+ /marginTop:\s*"calc\(var\(--studio-content-top-inset, 0px\) \+ var\(--studio-chat-header-height, 48px\)\)"/,
);
- // 0px is the only safe fallback: the sheet variant and every chat without a
- // notice must keep the exact geometry they had before this notice existed.
- assert.doesNotMatch(
+ assert.match(
style,
- /--studio-chat-notice-height,\s*2\.25rem/,
- "the panel must not assume a notice is present",
+ /height:\s*"calc\(100% - var\(--studio-content-top-inset, 0px\) - var\(--studio-chat-header-height, 48px\)\)"/,
);
});
diff --git a/studio/frontend/tests/context-usage-compact.test.ts b/studio/frontend/tests/context-usage-compact.test.ts
index 1e758b4cf71..a2503fb25bf 100644
--- a/studio/frontend/tests/context-usage-compact.test.ts
+++ b/studio/frontend/tests/context-usage-compact.test.ts
@@ -21,20 +21,20 @@ test("the compact face is the ring, unless there is no window to fill", () => {
test("the bar hands every input to the state, batching flags included", () => {
const bar = readSrc("features/chat/components/context-usage-bar.tsx");
- assert.match(bar, /\(\{ className, \.\.\.input \}\) => \{\s*const state = deriveContextUsageBar\(input\);/);
+ assert.match(bar, /\(\{ className, compactUnknownAsIcon = false, \.\.\.input \}\) => \{\s*const state = deriveContextUsageBar\(input\);/);
});
test("the header shrinks the context bar before the model name", () => {
const page = readSrc("features/chat/chat-page.tsx");
- assert.match(page, /"pointer-events-auto flex min-w-0 items-center gap-1"/);
+ assert.match(page, /"group\/chat-model-controls pointer-events-auto flex min-w-0 items-center gap-1"/);
assert.match(page, /ml-auto flex min-w-min max-w-max grow basis-0 items-center gap-1 \*:shrink-0/);
});
test("both faces draw the ring, not the line", () => {
const bar = readSrc("features/chat/components/context-usage-bar.tsx");
assert.match(bar, /\{compactFace === null \? \(\s*<span[^>]*>\s*<UsageRing /);
- // Empty before anything is counted, but still drawn.
- assert.match(bar, /const showRing = compactFace === null;/);
+ // The full face retains the state's ring policy; only the compact fallback can opt into an icon.
+ assert.match(bar, /const showRing = state\.compactFace === null;/);
assert.match(bar, /\{showRing \? <UsageRing percent=\{percent\} stroke=\{severity\.stroke\} \/> : null\}/);
assert.doesNotMatch(bar, /style=\{\{ width: `\$\{percent\}%` \}\}/);
});
diff --git a/studio/frontend/tests/thread-ancestor-has-scope.test.ts b/studio/frontend/tests/thread-ancestor-has-scope.test.ts
index c98fa8a570e..aab0b7394ee 100644
--- a/studio/frontend/tests/thread-ancestor-has-scope.test.ts
+++ b/studio/frontend/tests/thread-ancestor-has-scope.test.ts
@@ -116,121 +116,27 @@ test("the sidebar wrapper, an ancestor of the whole app, has no descendant-argum
test("the chat wrapper that contains the thread has no descendant-argument :has()", () => {
const source = parse("../src/features/chat/chat-page.tsx");
- const wrappers = stringLiterals(source).filter((s) =>
- s.includes("--studio-chat-notice-height:"),
- );
- assert.equal(
- wrappers.length,
- 1,
- "expected exactly one className declaring --studio-chat-notice-height",
- );
- assert.deepEqual(
- descendantHasUtilities(wrappers[0]),
- [],
- `the chat wrapper carries a descendant-argument :has(): ${wrappers[0]}`,
- );
- assert.ok(
- wrappers[0].includes("has-[>[data-chat-model-notice]]:[--studio-chat-notice-height:2.25rem]"),
- `the chat wrapper lost the notice-height rule: ${wrappers[0]}`,
- );
-});
-
-/*
- * THE CHILD COMBINATOR IS ONLY EQUIVALENT IF THE NOTICE IS A CHILD.
- *
- * Without this the previous test is satisfied by a selector that matches nothing, the height is
- * never reserved, and the first message reads under the opaque header bar. That is a visible
- * regression with no failing test, which is exactly the shape this file exists to prevent.
- */
-test("ChatModelNotice renders a DIRECT child of the element declaring the notice height", () => {
- const source = parse("../src/features/chat/chat-page.tsx");
-
- const declaringDiv = ((): ts.JsxElement | null => {
- let found: ts.JsxElement | null = null;
- const walk = (node: ts.Node): void => {
- if (found) return;
- if (ts.isJsxElement(node)) {
- const tag = node.openingElement;
- for (const attr of tag.attributes.properties) {
- if (!ts.isJsxAttribute(attr)) continue;
- if (attr.name.getText() !== "className") continue;
- const init = attr.initializer;
- if (!init || !ts.isStringLiteral(init)) continue;
- if (init.text.includes("--studio-chat-notice-height:")) {
- found = node;
- return;
- }
- }
- }
- ts.forEachChild(node, walk);
- };
- walk(source);
- return found;
- })();
-
- assert.ok(declaringDiv, "could not find the element declaring --studio-chat-notice-height");
-
- // A JSX expression container is not a DOM node, so `{cond && <ChatModelNotice/>}` still renders
- // a direct child. Unwrapping one level of `{...}` and of `&&` is therefore correct, and going
- // deeper than that would start accepting real wrappers.
- const directChildTagNames = declaringDiv.children.flatMap((child): string[] => {
- const fromNode = (node: ts.Node): string[] => {
- const tag = openingTag(node);
- if (tag) return [tag.tagName.getText()];
- if (ts.isParenthesizedExpression(node)) return fromNode(node.expression);
- if (
- ts.isBinaryExpression(node)
- && node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken
- ) {
- return fromNode(node.right);
- }
- if (ts.isConditionalExpression(node)) {
- return [...fromNode(node.whenTrue), ...fromNode(node.whenFalse)];
- }
- return [];
- };
- if (ts.isJsxExpression(child)) {
- return child.expression ? fromNode(child.expression) : [];
- }
- return fromNode(child);
- });
-
- assert.ok(
- directChildTagNames.includes("ChatModelNotice"),
- "ChatModelNotice is no longer a direct child of the element whose "
- + "has-[>[data-chat-model-notice]] rule reserves its height, so the height is never "
- + `reserved. Direct children seen: ${directChildTagNames.join(", ")}`,
- );
-});
-
-/*
- * And the notice really is the element the selector names. If `data-chat-model-notice` moved off
- * the component's root onto something inside it, the child combinator would stop matching while
- * every assertion above still passed.
- */
-test("data-chat-model-notice is on the root element ChatModelNotice returns", () => {
- const source = parse("../src/features/chat/components/chat-model-notice.tsx");
- let rootHasAttribute = false;
+ const wrappers: string[] = [];
const walk = (node: ts.Node): void => {
- if (rootHasAttribute) return;
- if (ts.isReturnStatement(node) && node.expression) {
- let expression: ts.Node = node.expression;
- while (ts.isParenthesizedExpression(expression)) expression = expression.expression;
- const tag = openingTag(expression);
- if (tag) {
- for (const attr of tag.attributes.properties) {
- if (!ts.isJsxAttribute(attr)) continue;
- if (attr.name.getText() === "data-chat-model-notice") rootHasAttribute = true;
+ const tag = openingTag(node);
+ if (tag?.attributes.properties.some((attr) =>
+ ts.isJsxAttribute(attr) && attr.name.getText() === "data-chat-content-root",
+ )) {
+ for (const attr of tag.attributes.properties) {
+ if (ts.isJsxAttribute(attr) && attr.name.getText() === "className") {
+ assert.ok(attr.initializer && ts.isStringLiteral(attr.initializer));
+ wrappers.push(attr.initializer.text);
}
}
}
ts.forEachChild(node, walk);
};
walk(source);
- assert.ok(
- rootHasAttribute,
- "no return in chat-model-notice.tsx yields a root element carrying "
- + "data-chat-model-notice, so has-[>[data-chat-model-notice]] cannot match",
+ assert.equal(wrappers.length, 1, "expected exactly one chat content root");
+ assert.deepEqual(
+ descendantHasUtilities(wrappers[0]),
+ [],
+ `the chat wrapper carries a descendant-argument :has(): ${wrappers[0]}`,
);
});