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: name an untitled chat's fork after its first reply (follow-up to #14587) (#14636)
Michael Hanc10feb7bc2dd
diff --git a/studio/frontend/src/features/chat/runtime-provider.tsx b/studio/frontend/src/features/chat/runtime-provider.tsxindex e64872ec871..a64f0f2067a 100644--- a/studio/frontend/src/features/chat/runtime-provider.tsx+++ b/studio/frontend/src/features/chat/runtime-provider.tsx@@ -148,6 +148,7 @@ import { usePromptQueueUI } from "./stores/prompt-queue-ui-store";import { ToolPaneScopeContext, toolPaneScope } from "./tool-output-scope";import { ChatProjectScopeContext } from "./chat-project-scope";import { readThreadCreationClaim } from "./utils/chat-thread-creation-claim";+import { claimUntitledForkTitle } from "./utils/untitled-fork-title";import type { MessageRecord, ModelType, ThreadRecord } from "./types";import type { OpenAIChatChunk } from "./types/api";import {@@ -4424,9 +4425,29 @@ function ThreadBackendAutosave({};}, []);+ const nameUntitledFork = useCallback(+ async (threadId: string) => {+ const runtime = aui.threads().__internal_getAssistantRuntime?.();+ if (!runtime) return;+ let item;+ try {+ item = runtime.threads.getItemById(threadId);+ } catch {+ return;+ }+ const { status, remoteId, title } = item.getState();+ if (status !== "regular" || !remoteId || title !== "New Chat") return;+ const record = await getStoredChatThread(remoteId).catch(() => undefined);+ if (!claimUntitledForkTitle(record)) return;+ await item.generateTitle().catch(() => undefined);+ },+ [aui],+ );+useAuiEvent("thread.runEnd", ({ threadId }) => {checkpoints().stop(threadId);queueSave(threadId);+ void nameUntitledFork(threadId);});useAuiEvent("thread.runStart", ({ threadId }) => {diff --git a/studio/frontend/src/features/chat/utils/untitled-fork-title.ts b/studio/frontend/src/features/chat/utils/untitled-fork-title.tsnew file mode 100644index 00000000000..1977c440515--- /dev/null+++ b/studio/frontend/src/features/chat/utils/untitled-fork-title.ts@@ -0,0 +1,25 @@+// 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 { ThreadRecord } from "../types";++const claimed = new Set<string>();++/** assistant-ui titles only threads it created ("new"); a fork opens as "regular", so an untitled+ * chat's fork, left "New Chat" by the backend, would never be named. True once per fork per page. */+export function claimUntitledForkTitle(+ record:+ | Pick<ThreadRecord, "id" | "title" | "forkedFromThreadId">+ | null+ | undefined,+): boolean {+ if (+ !record?.forkedFromThreadId ||+ record.title !== "New Chat" ||+ claimed.has(record.id)+ ) {+ return false;+ }+ claimed.add(record.id);+ return true;+}diff --git a/studio/frontend/tests/untitled-fork-title.test.ts b/studio/frontend/tests/untitled-fork-title.test.tsnew file mode 100644index 00000000000..33f83fe95f3--- /dev/null+++ b/studio/frontend/tests/untitled-fork-title.test.ts@@ -0,0 +1,63 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import assert from "node:assert/strict";+import { readFileSync } from "node:fs";+import test from "node:test";++import { readSrc } from "./helpers/kit.ts";++const { claimUntitledForkTitle } = await import(+ "../src/features/chat/utils/untitled-fork-title.ts"+);++test("assistant-ui titles only a thread it created, never one opened as regular", () => {+ const shipped = readFileSync(+ new URL(+ "../node_modules/@assistant-ui/core/dist/react/runtimes/RemoteThreadListHookInstanceManager.js",+ import.meta.url,+ ),+ "utf8",+ );+ assert.match(+ shipped,+ /if \(state\.status === "new"\) \{[\s\S]{0,400}generateTitle\(\)/,+ "assistant-ui changed when it auto-titles; recheck whether the fork trigger is still needed",+ );+});++test("an untitled fork is claimed once", () => {+ const fork = { id: "fork-a", title: "New Chat", forkedFromThreadId: "src" };+ assert.equal(claimUntitledForkTitle(fork), true);+ assert.equal(claimUntitledForkTitle(fork), false);+});++test("titled forks and chats that are not forks are left alone", () => {+ assert.equal(+ claimUntitledForkTitle({+ id: "fork-b",+ title: "Notes (1)",+ forkedFromThreadId: "src",+ }),+ false,+ );+ assert.equal(+ claimUntitledForkTitle({+ id: "plain",+ title: "New Chat",+ forkedFromThreadId: null,+ }),+ false,+ );+ assert.equal(claimUntitledForkTitle(undefined), false);+});++test("the autosave asks for a title when a run ends in an untitled fork", () => {+ const source = readSrc("features/chat/runtime-provider.tsx");+ const runEnd = source.slice(source.indexOf('useAuiEvent("thread.runEnd"'));+ assert.match(runEnd.slice(0, 300), /nameUntitledFork\(threadId\)/);+ const helper = source.slice(source.indexOf("const nameUntitledFork"));+ assert.match(helper, /status !== "regular"/);+ assert.match(helper, /claimUntitledForkTitle\(record\)/);+ assert.match(helper, /item\.generateTitle\(\)/);+});