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: show the model a chat was started on, and offer it back (#9081)
Michael Hanf3b042534594
diff --git a/studio/frontend/src/components/app-sidebar.tsx b/studio/frontend/src/components/app-sidebar.tsxindex 2d699e58ac3..9f0625bc0a8 100644--- a/studio/frontend/src/components/app-sidebar.tsx+++ b/studio/frontend/src/components/app-sidebar.tsx@@ -169,6 +169,7 @@ import {CONVERSATION_MARKDOWN_LABEL,type ProjectRecord,type SidebarItem,+ compareModelDisplayName,} from "@/features/chat";import { sandboxSessionIdFor } from "@/components/assistant-ui/sandbox-files";import {@@ -2518,6 +2519,17 @@ export function AppSidebar() {<span className="truncate">{pendingRename?.id === item.id ? pendingRename.title : item.title}</span>+ {/* The model the chat was started on. Only in the quiet states: the+ spinner takes the same right-hand slot, and the unread dot sits+ over it. The title truncates first, so this never squeezes it out. */}+ {item.modelId && !showWorkSpinner && !hasUnreadActivity && (+ <span+ className="ml-auto max-w-[45%] shrink-0 truncate text-ui-10 text-muted-foreground/70"+ title={item.modelId}+ >+ {compareModelDisplayName(item.modelId)}+ </span>+ )}{showWorkSpinner && (<Spinnerdata-testid="chat-row-spinner"diff --git a/studio/frontend/src/components/assistant-ui/thread.tsx b/studio/frontend/src/components/assistant-ui/thread.tsxindex 2309852a00d..267467a9807 100644--- a/studio/frontend/src/components/assistant-ui/thread.tsx+++ b/studio/frontend/src/components/assistant-ui/thread.tsx@@ -1728,7 +1728,10 @@ 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"- : "pt-[calc(var(--studio-content-top-inset,0px)+48px)]",+ : // + 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.+ "pt-[calc(var(--studio-content-top-inset,0px)+48px+var(--studio-chat-notice-height,0px))]",)}>{!hideWelcome && (diff --git a/studio/frontend/src/features/chat/artifacts/artifact-surface.tsx b/studio/frontend/src/features/chat/artifacts/artifact-surface.tsxindex 92719a09c06..2039e4582f0 100644--- a/studio/frontend/src/features/chat/artifacts/artifact-surface.tsx+++ b/studio/frontend/src/features/chat/artifacts/artifact-surface.tsx@@ -195,9 +195,21 @@ export function ArtifactSurface({className={cn("relative flex min-h-0 flex-col bg-background",variant === "panel"- ? "artifact-panel-shell mx-2 mt-[90px] mb-8 h-[calc(100%_-_122px)] overflow-visible rounded-[28px] border-t border-border/70 bg-card/95"+ ? "artifact-panel-shell mx-2 mb-8 overflow-visible rounded-[28px] border-t border-border/70 bg-card/95": "h-[min(92dvh,900px)] w-[min(96vw,1200px)] overflow-hidden rounded-2xl border border-border shadow-xl",)}+ // The chat-model notice is an absolute child of the chat content container, so+ // it spans this column too, not just the thread pane. Its height is 0 whenever+ // it is not on screen, which leaves the geometry this panel has always had.+ // Both edges move, or the panel keeps its height and overflows the bottom.+ style={+ variant === "panel"+ ? {+ marginTop: "calc(90px + var(--studio-chat-notice-height, 0px))",+ height: "calc(100% - 122px - var(--studio-chat-notice-height, 0px))",+ }+ : undefined+ }aria-label={`${artifact.title} canvas`}><headerdiff --git a/studio/frontend/src/features/chat/chat-page.tsx b/studio/frontend/src/features/chat/chat-page.tsxindex 86f098d7baf..1ac6283cc6c 100644--- a/studio/frontend/src/features/chat/chat-page.tsx+++ b/studio/frontend/src/features/chat/chat-page.tsx@@ -134,6 +134,8 @@ import {ResearchActivityPanel,ResearchActivitySheet,} from "./components/research-activity-panel";+import { ChatModelNotice } from "./components/chat-model-notice";+import { chatModelSwitchMeta } from "./components/chat-model-notice-switch";import { ContextUsageBar } from "./components/context-usage-bar";import { ModelLoadInlineStatus } from "./components/model-load-status";import { ProjectSwitcher } from "./components/project-switcher";@@ -2112,6 +2114,25 @@ export function ChatPage({const persistedActiveThreadId = isAssistantLocalThreadId(activeThreadId)? null: activeThreadId;+ // A chat opened as ?new=<nonce> has no thread in the URL, and it keeps none after+ // the first send, so the model notice never saw the row that send created: switching+ // model in a chat you just started offered nothing until you navigated away and+ // reopened it. The store does learn the id -- runtime-provider publishes it once the+ // visible thread is the one being persisted -- but it still holds the PREVIOUS chat's+ // id for the first render, until ThreadNewChatSwitch blanks it in an effect. Handing+ // that over would put the previous chat's notice on this one. So latch on having seen+ // it blanked for this nonce; before the first send there is nothing to offer anyway.+ const newChatBlankedRef = useRef<string | null>(null);+ if (+ search.new &&+ (activeThreadId === null || isAssistantLocalThreadId(activeThreadId))+ ) {+ newChatBlankedRef.current = search.new;+ }+ const newChatThreadId =+ search.new && newChatBlankedRef.current === search.new+ ? persistedActiveThreadId+ : null;const modelOperationInProgress = useChatRuntimeStore((state) => state.modelLoading,);@@ -3263,6 +3284,33 @@ export function ChatPage({return [...fromLoras, ...localModels];}, [lorasFromStore, localModels]);+ // Everything the picker can offer right now, so the chat's own model is only+ // proposed when selecting it would actually work. A model since deleted, or a+ // connection since removed, drops out and the notice stays quiet.+ const selectableModelIds = useMemo(+ () =>+ new Set<string>([+ ...models.map((model) => model.id),+ ...loraModels.map((model) => model.id),+ ...externalModels.map((model) => model.id),+ ]),+ [models, loraModels, externalModels],+ );++ // Still handleCheckpointChange, the picker's own handler, but reached the way+ // the picker reaches it: with the row's metadata, not the bare id. A local or+ // fine-tuned row is in neither `/api/models/list` nor the external ids, so+ // without it the switch loads on different arguments than the menu would.+ const handleSwitchBackToChatModel = useCallback(+ (modelId: string) => {+ handleCheckpointChange(+ modelId,+ chatModelSwitchMeta(modelId, loraModels),+ );+ },+ [handleCheckpointChange, loraModels],+ );+const inventoryRefreshStartedRef = useRef(false);const refreshDeferredModelInventories = useCallback(() => {inventoryRefreshStartedRef.current = true;@@ -3425,14 +3473,20 @@ export function ChatPage({render their own copy and the shared-composer menu would have none. Italso portals to body, so gate it on `active` like the tour above. */}{active && <BypassPermissionsConfirmDialog />}- <div className="relative flex min-h-0 min-w-0 flex-1 basis-0 flex-col overflow-hidden">+ {/* `--studio-chat-notice-height` is 0 until ChatModelNotice is actually on+ screen, and the thread viewport adds it to the top padding it already+ reserves for the header. Without it the notice is an opaque bar over+ space nothing reserved, and the top of the first message reads+ underneath it. Declared here, on the nearest ancestor of BOTH the+ notice and the viewport, so the two cannot disagree about its height. */}+ <div 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]"><NativeModelDropOverlay state={nativeModelDropState} />{/* Fade under the top bar so messages dissolve as they scrollbeneath it, instead of a hard cut. */}{view.mode !== "compare" && (<divaria-hidden- className="chat-header-fade pointer-events-none absolute left-0 right-[10px] 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"+ className="chat-header-fade pointer-events-none absolute left-0 right-[10px] 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"/>)}<div@@ -3678,6 +3732,15 @@ export function ChatPage({</div></div>+ {view.mode === "single" && (+ <ChatModelNotice+ threadId={view.threadId ?? newChatThreadId ?? undefined}+ checkpoint={inferenceParams.checkpoint}+ selectableModelIds={selectableModelIds}+ onSwitch={handleSwitchBackToChatModel}+ />+ )}+{view.mode === "project" ? (<ProjectLandingkey={view.projectId}diff --git a/studio/frontend/src/features/chat/components/chat-model-notice-switch.ts b/studio/frontend/src/features/chat/components/chat-model-notice-switch.tsnew file mode 100644index 00000000000..c8a2489ee23--- /dev/null+++ b/studio/frontend/src/features/chat/components/chat-model-notice-switch.ts@@ -0,0 +1,44 @@+// 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 type {+ LoraModelOption,+ ModelSelectorChangeMeta,+} from "@/features/model-picker/components/model-selector/types";++/**+ * The picker metadata a "Switch back" has to carry, or undefined when the id+ * needs none.+ *+ * `handleCheckpointChange` is the picker's handler, and the picker never calls+ * it with the id alone. For a Hub row or an external model the id is enough:+ * `selectModel` finds the row in `/api/models/list` (which carries `isGguf`) or+ * `isExternalModelId` routes it. A local / fine-tuned row is in neither, so+ * with no metadata `isGguf` resolves false and the /load request drops+ * `n_parallel`, `n_batch`, `n_ubatch` and `llama_extra_args` and sizes the+ * context down the transformers path -- a different load from the one the same+ * model gets when picked from the menu.+ *+ * Mirrors what the picker itself supplies for these rows, field for field:+ * `localDirectGgufMeta` for a single .gguf file, and the fine-tuned list's own+ * `selectionMeta` for everything else.+ */+export function chatModelSwitchMeta(+ modelId: string,+ loraModels: readonly LoraModelOption[],+): ModelSelectorChangeMeta | undefined {+ const row = loraModels.find((model) => model.id === modelId);+ if (!row) return undefined;+ const isLocal = row.source === "local";+ return {+ source: isLocal ? "local" : row.source === "exported" ? "exported" : "lora",+ // A local folder is not an adapter, and neither is a merged or GGUF export.+ isLora:+ !isLocal && row.exportType !== "merged" && row.exportType !== "gguf",+ // Already on disk: without this the load shows a download progress bar for+ // a model that has nothing to download.+ isDownloaded: true,+ // Set only by chatLocalModelOptions, and only for a single .gguf file.+ isGguf: row.isGguf === true,+ };+}diff --git a/studio/frontend/src/features/chat/components/chat-model-notice.tsx b/studio/frontend/src/features/chat/components/chat-model-notice.tsxnew file mode 100644index 00000000000..edbeed30af4--- /dev/null+++ b/studio/frontend/src/features/chat/components/chat-model-notice.tsx@@ -0,0 +1,99 @@+// 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 { useEffect, useState } from "react";++import { Button } from "@/components/ui/button";+import { compareModelDisplayName } from "../lib/external-model-label";+import { getStoredChatThread } from "../utils/chat-history-storage";++/**+ * The model a saved chat was started on, read once per chat.+ *+ * Every thread row has carried `modelId` since long before this notice, so an+ * existing chat knows its model without any migration. A chat with no row yet+ * (a New Chat that has not been sent) answers null and shows nothing.+ */+export function useChatCreatedModel(+ threadId: string | undefined,+): string | null {+ // Keyed by the chat it was read for, not a bare value. Clearing it in the+ // effect is a frame late: the effect is passive, so the first render for the+ // incoming chat has already committed with the outgoing chat's model, which+ // paints the wrong notice and moves the viewport padding under it. Answering+ // only for a matching key makes that render impossible rather than brief.+ const [read, setRead] = useState<{+ threadId: string;+ modelId: string | null;+ } | null>(null);+ useEffect(() => {+ if (!threadId) return;+ let cancelled = false;+ void getStoredChatThread(threadId)+ .then((thread) => {+ if (!cancelled) setRead({ threadId, modelId: thread?.modelId || null });+ })+ .catch(() => {+ // A failed read is not worth a message: the notice is an offer, not a+ // gate, and the chat runs on whatever is loaded either way.+ });+ return () => {+ cancelled = true;+ };+ }, [threadId]);+ return read && read.threadId === threadId ? read.modelId : null;+}++type ChatModelNoticeProps = {+ /** The saved chat on screen, or undefined for an unsent New Chat. */+ threadId: string | undefined;+ /** The model the composer will actually send to. */+ checkpoint: string;+ /** Every model that can be selected right now, by id. */+ selectableModelIds: ReadonlySet<string>;+ onSwitch: (modelId: string) => void;+};++/**+ * Offers to put a chat back on the model it was started on.+ *+ * Deliberately an offer and not an automatic switch: for a local model that+ * would evict whatever is resident and spend a multi-gigabyte load on opening a+ * chat, which is not what clicking a row in the sidebar should cost.+ */+export function ChatModelNotice({+ threadId,+ checkpoint,+ selectableModelIds,+ onSwitch,+}: ChatModelNoticeProps) {+ const createdModelId = useChatCreatedModel(threadId);+ if (!createdModelId || createdModelId === checkpoint) return null;+ // A model that has since been deleted, or a connection that is gone: the+ // switch could not be honoured, and saying so on every open is just noise.+ if (!selectableModelIds.has(createdModelId)) return null;+ const label = compareModelDisplayName(createdModelId);+ 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 whole bar is invisible bar the 10px the header's `right-[10px]`+ // 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=""+ className="absolute left-0 right-[10px] 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(createdModelId)}+ >+ Switch back+ </Button>+ </div>+ );+}diff --git a/studio/frontend/src/features/chat/components/research-activity-panel.tsx b/studio/frontend/src/features/chat/components/research-activity-panel.tsxindex ac6bc0e417b..2b7e8e1413b 100644--- a/studio/frontend/src/features/chat/components/research-activity-panel.tsx+++ b/studio/frontend/src/features/chat/components/research-activity-panel.tsx@@ -883,10 +883,16 @@ 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 -- the telescope, the title, the status pill and the+ // close button -- is painted over and unclickable. 0px whenever no+ // notice is on screen, so this is the geometry it always had.height:- "calc(100% - var(--studio-content-top-inset, 0px) - var(--studio-chat-header-height, 48px))",+ "calc(100% - var(--studio-content-top-inset, 0px) - var(--studio-chat-header-height, 48px) - var(--studio-chat-notice-height, 0px))",marginTop:- "calc(var(--studio-content-top-inset, 0px) + var(--studio-chat-header-height, 48px))",+ "calc(var(--studio-content-top-inset, 0px) + var(--studio-chat-header-height, 48px) + var(--studio-chat-notice-height, 0px))",}: undefined}diff --git a/studio/frontend/src/features/chat/hooks/use-chat-sidebar-items.ts b/studio/frontend/src/features/chat/hooks/use-chat-sidebar-items.tsindex f59ff9be720..69236cf30f8 100644--- a/studio/frontend/src/features/chat/hooks/use-chat-sidebar-items.ts+++ b/studio/frontend/src/features/chat/hooks/use-chat-sidebar-items.ts@@ -36,6 +36,8 @@ export interface SidebarItem {updatedAt: number;isFork?: boolean;projectId?: string | null;+ /** The model this chat was started on. Single rows only: a compare row runs two. */+ modelId?: string;}function lastActivityAt(thread: ThreadRecord): number {@@ -87,6 +89,8 @@ export function groupThreads(updatedAt: lastActivityAt(t),isFork: Boolean(t.forkedFromThreadId),projectId: t.projectId ?? null,+ // Stamped at creation. Blank on a legacy row, which reads as unknown.+ modelId: t.modelId || undefined,});}}diff --git a/studio/frontend/src/features/chat/index.ts b/studio/frontend/src/features/chat/index.tsindex 4c4f01f48f2..102265c93d4 100644--- a/studio/frontend/src/features/chat/index.ts+++ b/studio/frontend/src/features/chat/index.ts@@ -163,6 +163,7 @@ export {useChatModelRuntime,resyncInferenceStatusAfterServerModelChange,} from "./hooks/use-chat-model-runtime";+export { compareModelDisplayName } from "./lib/external-model-label";export { chatModelLoaded } from "./lib/chat-model-loaded";export type { ChatModelLoadedInput } from "./lib/chat-model-loaded";export {diff --git a/studio/frontend/src/features/chat/local-model-options.ts b/studio/frontend/src/features/chat/local-model-options.tsindex 904af1df791..b972d77200a 100644--- a/studio/frontend/src/features/chat/local-model-options.ts+++ b/studio/frontend/src/features/chat/local-model-options.ts@@ -57,6 +57,12 @@ export function chatLocalModelOptions(baseModel: baseModelLabel(model.source),updatedAt: model.updated_at ?? undefined,source: "local" as const,+ // Only a single .gguf file, which is the one local shape the picker loads+ // straight through as a GGUF (`localDirectGgufMeta`). A GGUF DIRECTORY is+ // deliberately left alone: that row expands to pick a quant, and the+ // variant it yields is not something a chat row records, so claiming GGUF+ // for it would send llama-server flags for a quant nobody chose.+ ...(model.path.toLowerCase().endsWith(".gguf") ? { isGguf: true } : {}),});}return options;diff --git a/studio/frontend/tests/chat-remembers-its-model.test.ts b/studio/frontend/tests/chat-remembers-its-model.test.tsnew file mode 100644index 00000000000..173219cadf4--- /dev/null+++ b/studio/frontend/tests/chat-remembers-its-model.test.ts@@ -0,0 +1,378 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// Every thread row has carried modelId since long before this notice, so the model a chat+// was started on is already known for chats that already exist. What was missing was+// showing it and offering it back. The rules below are the ones that keep the offer from+// becoming a nuisance: it never loads anything on its own, and it stays quiet whenever it+// could not be honoured.++import assert from "node:assert/strict";+import { readFileSync } from "node:fs";+import test from "node:test";++import { chatModelSwitchMeta } from "../src/features/chat/components/chat-model-notice-switch.ts";+import { chatLocalModelOptions } from "../src/features/chat/local-model-options.ts";++function read(path: string): string {+ return readFileSync(new URL(path, import.meta.url), "utf8");+}++const notice = read("../src/features/chat/components/chat-model-notice.tsx");+const page = read("../src/features/chat/chat-page.tsx");+const sidebar = read("../src/components/app-sidebar.tsx");+const items = read("../src/features/chat/hooks/use-chat-sidebar-items.ts");+const thread = read("../src/components/assistant-ui/thread.tsx");+const researchPanel = read(+ "../src/features/chat/components/research-activity-panel.tsx",+);+const artifact = read("../src/features/chat/artifacts/artifact-surface.tsx");++function slice(source: string, from: string, to: string): string {+ const start = source.indexOf(from);+ assert.ok(start !== -1, `not found: ${from}`);+ const end = source.indexOf(to, start + from.length);+ assert.ok(end !== -1, `not found: ${to}`);+ return source.slice(start, end);+}++// Source assertions: use-chat-sidebar-items reaches chat-api, and the label helper reaches+// external-providers, neither of which resolves in a bare node test. The sibling+// thread-scoped suites do the same for the same reason.++test("a single chat row carries the model it was started on", () => {+ const single = slice(items, 'type: "single",', "});");+ assert.match(single, /modelId: t\.modelId \|\| undefined,/);+});++test("a legacy row with no model reads as unknown rather than empty string", () => {+ // db.ts backfills "" onto old records, and "" would render an empty label.+ assert.match(items, /modelId: t\.modelId \|\| undefined,/);+ assert.doesNotMatch(items, /modelId: t\.modelId,/);+});++test("a compare row carries no single model", () => {+ // Two panes, two models: there is no honest one to show, so the field is absent.+ const compare = slice(items, 'type: "compare",', "};");+ assert.doesNotMatch(compare, /modelId/);+});++test("the notice never switches a model on its own", () => {+ // Opening a chat must not evict what is resident: a local load is multi-gigabyte.+ assert.doesNotMatch(notice, /loadModel|setCheckpoint/);+ // The only way out of it is the button.+ assert.match(notice, /onClick=\{\(\) => onSwitch\(createdModelId\)\}/);+});++test("the notice stays quiet when it has nothing to offer", () => {+ const body = notice.slice(notice.indexOf("export function ChatModelNotice"));+ // no stamp, already on it, or a model that has since gone away+ assert.match(+ body,+ /if \(!createdModelId \|\| createdModelId === checkpoint\) return null;/,+ );+ assert.match(+ body,+ /if \(!selectableModelIds\.has\(createdModelId\)\) return null;/,+ );+});++test("switching chats does not show the outgoing chat's model", () => {+ // The read is async, so a stale value would sit over the incoming chat until it lands.+ // Clearing it inside the effect is not enough: the effect is passive, so the first+ // render for the incoming chat commits with the outgoing chat's model already on+ // screen. The answer is keyed by the chat it was read for, so a foreign value cannot+ // be returned at all rather than being returned briefly.+ const hook = notice.slice(+ notice.indexOf("export function useChatCreatedModel"),+ notice.indexOf("type ChatModelNoticeProps"),+ );+ assert.match(hook, /setRead\(\{ threadId, modelId:/);+ assert.match(hook, /return read && read\.threadId === threadId \? read\.modelId : null;/);+ // and a read that resolves after the chat changed is dropped+ assert.match(hook, /if \(!cancelled\) setRead/);+ assert.match(hook, /cancelled = true;/);+});++test("the notice is wired to the picker's own handler, not a private path", () => {+ // handleCheckpointChange carries the confirmations, VRAM checks and external+ // handling; a second switch path would drift from it. The wrapper only+ // resolves the row metadata the picker also supplies, then calls it.+ assert.match(page, /onSwitch=\{handleSwitchBackToChatModel\}/);+ const wrapper = slice(+ page,+ "const handleSwitchBackToChatModel",+ "const inventoryRefreshStartedRef",+ );+ assert.match(wrapper, /handleCheckpointChange\(/);+ assert.match(wrapper, /chatModelSwitchMeta\(modelId, loraModels\)/);+ assert.match(page, /selectableModelIds=\{selectableModelIds\}/);+ // Offered only for a real saved chat, in the single-chat view.+ assert.match(page, /view\.mode === "single" && \(\s*<ChatModelNotice/);+});++test("only models that can actually be selected are offered", () => {+ const set = page.slice(page.indexOf("const selectableModelIds = useMemo"));+ for (const source of ["models", "loraModels", "externalModels"]) {+ assert.ok(+ set.slice(0, 400).includes(`...${source}.map`),+ `${source} is missing from the selectable set`,+ );+ }+});++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 Studio: 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.+ assert.match(div, /top-\[calc\(var\(--studio-content-top-inset,0px\)\+var\(--studio-chat-header-height,48px\)\)\]/);+ // 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");+});++test("the conversation reserves the space the notice overlay takes", () => {+ // Measured on a built Studio 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.+ 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.+ assert.match(+ thread,+ /pt-\[calc\(var\(--studio-content-top-inset,0px\)\+48px\+var\(--studio-chat-notice-height,0px\)\)\]/,+ );+ // 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 a Studio 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\)\)"/,+ );+ 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\)\)"/,+ );+ // 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(+ style,+ /--studio-chat-notice-height,\s*2\.25rem/,+ "the panel must not assume a notice is present",+ );+});++test("the canvas panel reserves the notice's height too", () => {+ // The other column the notice spans. The canvas panel's top offset was a fixed+ // 90px, which clears the 48px header on top of a 34px content inset by 8px and+ // nothing more, so a 36px notice covers the top 28px of the panel: the+ // preview/source tabs and the close control sit in exactly that band, and the+ // notice is opaque and takes pointer events at z-30. Same fix as the research+ // panel, and 0px whenever no notice is on screen.+ const panel = slice(artifact, 'variant === "panel"', "aria-label=");+ assert.match(+ panel,+ /marginTop:\s*\n?\s*"calc\(90px \+ var\(--studio-chat-notice-height, 0px\)\)"/,+ );+ // Both edges move, or the panel keeps its height and overflows the bottom.+ assert.match(+ panel,+ /height:\s*\n?\s*"calc\(100% - 122px - var\(--studio-chat-notice-height, 0px\)\)"/,+ );+ // The class list must not still carry the fixed geometry the style replaces.+ assert.doesNotMatch(panel, /mt-\[90px\]/);+ assert.doesNotMatch(panel, /h-\[calc\(100%_-_122px\)\]/);+ // 0px is the only safe fallback: the overlay variant and every chat without a+ // notice keep the exact geometry they had before this notice existed.+ assert.doesNotMatch(+ panel,+ /--studio-chat-notice-height,\s*2\.25rem/,+ "the panel must not assume a notice is present",+ );+});++test("the sidebar label cannot collide with the spinner or the unread dot", () => {+ // Both take the same right-hand slot, and the dot is positioned over it.+ assert.match(+ sidebar,+ /\{item\.modelId && !showWorkSpinner && !hasUnreadActivity && \(/,+ );+ // The title truncates first, so a long model name never squeezes it out.+ const label = sidebar.slice(+ sidebar.indexOf("{item.modelId && !showWorkSpinner"),+ );+ assert.match(label.slice(0, 400), /max-w-\[45%\]/);+ assert.match(label.slice(0, 400), /compareModelDisplayName\(item\.modelId\)/);+});++test("a chat started as New Chat gets the notice once its row exists", () => {+ // ?new=<nonce> carries no thread in the URL and keeps none after the first send, so+ // the notice saw nothing until the chat was reopened. The store's id is only this+ // chat's after ThreadNewChatSwitch has blanked the previous one, hence the latch.+ const gate = slice(page, "const newChatBlankedRef", "const newChatThreadId =");+ assert.match(gate, /activeThreadId === null \|\| isAssistantLocalThreadId\(activeThreadId\)/);+ assert.match(gate, /newChatBlankedRef\.current = search\.new;/);++ const derived = slice(page, "const newChatThreadId =", "\n const");+ assert.match(derived, /newChatBlankedRef\.current === search\.new/);+ // The latched id is only ever the persisted one, so an unsent chat still offers nothing.+ assert.match(derived, /\? persistedActiveThreadId/);+ assert.match(derived, /: null/);++ const notice = slice(page, "<ChatModelNotice", "/>");+ assert.match(notice, /threadId=\{view\.threadId \?\? newChatThreadId \?\? undefined\}/);+});++// The switch back is the picker's handler, so it has to arrive carrying what the picker+// itself would have put on it. A local or fine-tuned row is in neither /api/models/list+// nor the external ids, so with the bare id selectModel resolves isGguf false and the+// /load request loses n_parallel, n_batch, n_ubatch and llama_extra_args and sizes the+// context down the transformers path.++test("switching back to a single-file local GGUF still loads as a GGUF", () => {+ const meta = chatModelSwitchMeta("/models/qwen3-4b-q4.gguf", [+ {+ id: "/models/qwen3-4b-q4.gguf",+ name: "qwen3-4b-q4",+ source: "local",+ isGguf: true,+ },+ ]);+ assert.deepEqual(meta, {+ source: "local",+ isLora: false,+ isDownloaded: true,+ isGguf: true,+ });+});++test("a single .gguf file carries its format out of the local inventory", () => {+ // chatLocalModelOptions is where the format is either kept or lost; the resolver+ // above has nothing else to read it from.+ const [option] = chatLocalModelOptions([+ {+ id: "/models/qwen3-4b-q4.gguf",+ display_name: "qwen3-4b-q4",+ path: "/models/qwen3-4b-q4.GGUF",+ source: "custom",+ model_format: "gguf",+ },+ ]);+ assert.equal(option.isGguf, true);+});++test("a GGUF directory is not claimed as a GGUF, since its quant is unknown", () => {+ // That row expands in the picker to pick a variant, and a chat row records only+ // modelId. Sending llama-server flags for a quant nobody chose is worse than the+ // plain switch.+ const [option] = chatLocalModelOptions([+ {+ id: "/models/Qwen3-4B-GGUF",+ display_name: "Qwen3-4B-GGUF",+ path: "/models/Qwen3-4B-GGUF",+ source: "models_dir",+ model_format: "gguf",+ },+ ]);+ assert.equal(option.isGguf, undefined);+ assert.equal(+ chatModelSwitchMeta("/models/Qwen3-4B-GGUF", [option])?.isGguf,+ false,+ );+});++test("switching back to a fine-tuned row mirrors the picker's own metadata", () => {+ // Same fields the fine-tuned list's selectionMeta sets, so the two doors agree.+ const adapters = [+ { id: "run-1", name: "run-1", source: "training" as const },+ {+ id: "run-2",+ name: "run-2",+ source: "exported" as const,+ exportType: "merged" as const,+ },+ ];+ assert.deepEqual(chatModelSwitchMeta("run-1", adapters), {+ source: "lora",+ isLora: true,+ isDownloaded: true,+ isGguf: false,+ });+ assert.deepEqual(chatModelSwitchMeta("run-2", adapters), {+ source: "exported",+ isLora: false,+ isDownloaded: true,+ isGguf: false,+ });+});++test("a Hub or external id is still switched on the id alone", () => {+ // Those two resolve without help: /api/models/list carries isGguf, and+ // isExternalModelId routes the rest. Inventing a "local" source for them would+ // send them down the wrong branch of handleCheckpointChange.+ assert.equal(chatModelSwitchMeta("unsloth/Qwen3-4B-GGUF", []), undefined);+ assert.equal(chatModelSwitchMeta("openai:gpt-5-mini", []), undefined);+});