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
Stop and send buttons on the chat dictation bar (#7683)
Michael Hanc67410a78740
diff --git a/studio/frontend/src/components/app-sidebar.tsx b/studio/frontend/src/components/app-sidebar.tsxindex 575eda76d04..e51628c30ed 100644--- a/studio/frontend/src/components/app-sidebar.tsx+++ b/studio/frontend/src/components/app-sidebar.tsx@@ -1261,7 +1261,7 @@ export function AppSidebar() {useChatSearchStore.getState().open();closeMobileIfOpen();}}- className="inline-flex h-[33px] w-[28px] cursor-pointer items-center justify-center rounded-[10px] text-nav-icon-idle dark:text-nav-fg-muted transition-colors hover:bg-nav-surface-hover hover:text-black dark:hover:text-white focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"+ className="inline-flex size-[28px] cursor-pointer items-center justify-center rounded-full text-nav-icon-idle dark:text-nav-fg-muted transition-colors hover:bg-nav-surface-hover hover:text-black dark:hover:text-white focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"aria-label={t("shell.navigation.search")}><HugeiconsIcon icon={Search01Icon} strokeWidth={1.75} className="size-icon" />@@ -1285,7 +1285,7 @@ export function AppSidebar() {<buttontype="button"onClick={togglePinned}- className="inline-flex h-[33px] w-[28px] cursor-pointer items-center justify-center rounded-[10px] text-nav-icon-idle dark:text-nav-fg-muted transition-colors hover:bg-nav-surface-hover hover:text-black dark:hover:text-white focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"+ className="inline-flex size-[28px] cursor-pointer items-center justify-center rounded-full text-nav-icon-idle dark:text-nav-fg-muted transition-colors hover:bg-nav-surface-hover hover:text-black dark:hover:text-white focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"aria-label={t("shell.aria.closeSidebar")}><HugeiconsIcon icon={LayoutAlignLeftIcon} strokeWidth={1.75} className="size-icon" />diff --git a/studio/frontend/src/components/assistant-ui/chat-dictation-bar.tsx b/studio/frontend/src/components/assistant-ui/chat-dictation-bar.tsxindex 64b0b467352..d2c7c253277 100644--- a/studio/frontend/src/components/assistant-ui/chat-dictation-bar.tsx+++ b/studio/frontend/src/components/assistant-ui/chat-dictation-bar.tsx@@ -7,7 +7,7 @@ import {subscribeDictationLevel,} from "@/features/chat";import { useAui, useAuiState } from "@assistant-ui/react";-import { CheckIcon, XIcon } from "lucide-react";+import { ArrowUpIcon, SquareIcon } from "lucide-react";import { type FC, useEffect, useRef, useState } from "react";import { TooltipIconButton } from "./tooltip-icon-button";@@ -35,14 +35,23 @@ function formatElapsed(ms: number): string {}/**- * Recording UI shown in place of the composer input: a live waveform with- * discard and confirm on the right. Confirm transcribes; discard keeps the- * existing composer text.+ * Recording UI shown in place of the composer input: a live waveform with stop+ * and send on the right. Stop transcribes into the composer for editing; send+ * transcribes and submits. Escape discards without transcribing, as does a+ * second press of stop once transcription is under way.*/-export const ChatDictationBar: FC = () => {+export const ChatDictationBar: FC<{+ /** Transcribe, then submit the composer. Falls back to stop when absent. */+ onSend?: () => void;+ /** Send is unavailable (e.g. an attachment is still uploading). */+ sendDisabled?: boolean;+}> = ({ onSend, sendDisabled }) => {const aui = useAui();const isDictating = useAuiState((s) => s.composer.dictation != null);- const [transcribing, setTranscribing] = useState(false);+ // Which button started transcription, so only it shows the spinner.+ const [transcribing, setTranscribing] = useState<"stop" | "send" | null>(+ null,+ );const [elapsed, setElapsed] = useState(0);const transcribingRef = useRef(false);// Extra slot: newest sample lands here; the last visible bar slides toward it.@@ -152,38 +161,73 @@ export const ChatDictationBar: FC = () => {unsub();cancelAnimationFrame(raf);transcribingRef.current = false;- setTranscribing(false);+ setTranscribing(null);setElapsed(0);barsRef.current = new Array(BAR_COUNT + 1).fill(0);};}, [isDictating]);+ // No discard button, so Escape drops a recording without transcribing. It+ // stays live while transcribing too, where cancel aborts the request.+ useEffect(() => {+ if (!isDictating) {+ return;+ }+ const onKeyDown = (event: KeyboardEvent) => {+ // defaultPrevented: an open dialog or menu already claimed this Escape.+ if (event.key !== "Escape" || event.defaultPrevented) {+ return;+ }+ cancelActiveStudioDictation();+ };+ window.addEventListener("keydown", onKeyDown);+ return () => window.removeEventListener("keydown", onKeyDown);+ }, [isDictating]);+if (!isDictating) {return null;}- const discard = () => {- cancelActiveStudioDictation();+ // Freeze the timer + waveform while the transcription round trip runs.+ const freeze = (source: "stop" | "send") => {+ transcribingRef.current = true;+ setTranscribing(source);};- const confirm = () => {- // Freeze the timer + waveform before the transcription round trip completes- // and the session ends.- transcribingRef.current = true;- setTranscribing(true);+ // Transcript lands in the composer, ready to edit. A second press while+ // transcribing discards it instead, as Compare's does: Escape is otherwise+ // the only way out, which touch has no way to press.+ const stop = () => {+ if (transcribing !== null) {+ cancelActiveStudioDictation();+ return;+ }+ freeze("stop");aui.composer().stopDictation();};+ // Same transcription, then the message submits on its own.+ const send = () => {+ if (sendDisabled) return;+ if (!onSend) {+ stop();+ return;+ }+ freeze("send");+ onSend();+ };+return (<fieldset// order-2 places the bar in the input's slot after the left "+" tools.- className="unsloth-dictation-bar order-2 m-0 flex min-w-0 flex-1 items-center gap-2 border-0 p-0"+ // No row gap: the wave padding and the timer margin set the spacing.+ className="unsloth-dictation-bar order-2 m-0 flex min-w-0 flex-1 items-center gap-0 border-0 p-0"aria-label="Voice recording"><divref={rowRef}aria-hidden="true"- className="unsloth-dictation-wave grid h-10 min-w-0 flex-1 items-center overflow-hidden px-2"+ className="unsloth-dictation-wave grid h-10 min-w-0 flex-1 items-center overflow-hidden pl-4 pr-2"style={{gridTemplateColumns: `repeat(${BAR_COUNT}, minmax(1px, 3px))`,justifyContent: "space-between",@@ -196,33 +240,43 @@ export const ChatDictationBar: FC = () => {/>))}</div>- <span className="shrink-0 tabular-nums text-sm text-muted-foreground">+ <span className="mr-4 shrink-0 tabular-nums text-sm text-muted-foreground">{formatElapsed(elapsed)}</span>- <div className="flex shrink-0 items-center gap-1">+ <div className="flex shrink-0 items-center gap-2.5"><TooltipIconButtontype="button"- tooltip="Discard recording"- aria-label="Discard recording"+ tooltip={+ transcribing !== null ? "Cancel transcription" : "Stop recording"+ }+ aria-label={+ transcribing !== null ? "Cancel transcription" : "Stop recording"+ }variant="ghost"- onClick={discard}- className="size-8 rounded-full text-muted-foreground hover:text-foreground"+ onClick={stop}+ // Neutral grey in both themes: --secondary is brand green on the+ // default light palette, and too close to --card on dark.+ className="size-9 rounded-full bg-accent text-foreground hover:bg-accent/70 dark:bg-white/10 dark:hover:bg-white/[0.16]">- <XIcon className="size-5" />+ {transcribing === "stop" ? (+ <Spinner className="size-3.5" />+ ) : (+ <SquareIcon className="size-3 fill-current" />+ )}</TooltipIconButton><TooltipIconButtontype="button"- tooltip={transcribing ? "Transcribing…" : "Stop and transcribe"}- aria-label="Stop and transcribe"+ tooltip={transcribing === "send" ? "Transcribing…" : "Send message"}+ aria-label="Send message"variant="default"- onClick={confirm}- disabled={transcribing}- className="size-8 rounded-full"+ onClick={send}+ disabled={transcribing !== null || sendDisabled}+ className="aui-composer-send size-9 rounded-full">- {transcribing ? (- <Spinner className="size-4" />+ {transcribing === "send" ? (+ <Spinner className="size-[18px]" />) : (- <CheckIcon className="size-5" />+ <ArrowUpIcon className="unsloth-send-icon aui-composer-send-icon size-[21px] stroke-2" />)}</TooltipIconButton></div>diff --git a/studio/frontend/src/components/assistant-ui/thread.tsx b/studio/frontend/src/components/assistant-ui/thread.tsxindex 9b3c7aa79e1..6bd99be663c 100644--- a/studio/frontend/src/components/assistant-ui/thread.tsx+++ b/studio/frontend/src/components/assistant-ui/thread.tsx@@ -103,12 +103,18 @@ import { PROMPT_QUEUE_STOP_EVENT } from "@/features/chat/utils/prompt-queue-bounimport {PLUS_MENU_ORDER,composerDraftKey,+ dictationFailed,+ dictationProducedTranscript,readComposerDraft,type PlusMenuItemId,usePlusMenuPrefsStore,writeComposerDraft,} from "@/features/chat";import { deleteThreadMessage } from "@/features/chat/utils/delete-thread-message";+import {+ dictationSendBlocked,+ shouldSubmitDictation,+} from "@/features/chat/utils/dictation-send";import { listThreadDocuments } from "@/features/rag/api/rag-api";import { ThreadDocumentsBar } from "@/features/rag/components/thread-documents-bar";import { KnowledgeBaseComposerButton } from "@/features/rag/components/knowledge-base-composer-button";@@ -1365,7 +1371,8 @@ const ThreadWelcome: FC<{<div className="aui-thread-welcome-message flex w-full flex-col justify-center gap-9 px-4">{/* Center the greeting (sloth + title) over the composer. */}<div className="flex flex-row items-center justify-center gap-[15px]">- {showGreetingSloth && (+ {/* Temporary chat keeps the title on its own, no mascot. */}+ {showGreetingSloth && !incognito && (<MascotImgsrc={currentEmojiSrc}className="size-[44px] -translate-y-[2px]"@@ -1835,6 +1842,94 @@ const Composer: FC<{[],);+ // Recording bar's send: stop dictating, then submit once the transcript+ // lands. Going through the form keeps queueing, indexing holds and draft+ // clearing identical to a typed send.+ const formRef = useRef<HTMLFormElement | null>(null);+ const sendAfterDictationRef = useRef(false);+ const dictationBaseTextRef = useRef("");+ const dictationComposerRef = useRef("");+ // Thread switches reuse this composer, so the send has to know where it+ // started to avoid submitting the destination thread's draft. The list item+ // id, not referenceThreadId: that one moves from null to the remote id when+ // a new chat first persists, which is the same composer.+ const composerIdentity = threadListItemId ?? "";+ const sendAfterDictation = useCallback(() => {+ sendAfterDictationRef.current = true;+ dictationComposerRef.current = composerIdentity;+ aui.composer().stopDictation();+ }, [aui, composerIdentity]);++ // One gate for the recording bar's send: it greys the button out, and holds+ // a pending send when the composer changes under it after the press.+ const dictationBlocked = dictationSendBlocked({+ composerDisabled: Boolean(disabled),+ uploading: hasPendingAttachments,+ researchActive: isResearchActive,+ runActive: threadIsRunning || promptQueueActive,+ queueDisabled: Boolean(disableQueue),+ hasOverlay: Boolean(overlay),+ hasAttachments,+ hasPendingAudio,+ });+ const wasDictatingRef = useRef(false);+ // Composer text while a send waits on dictationBlocked, so an edit can drop it.+ const heldTextRef = useRef<string | null>(null);+ useEffect(() => {+ if (isDictating) {+ if (wasDictatingRef.current) return;+ wasDictatingRef.current = true;+ // A new recording supersedes a send still held for an upload.+ sendAfterDictationRef.current = false;+ heldTextRef.current = null;+ // Text at session start is the dictation base. Anchor on it, not on the+ // text when send was pressed: the browser engine streams interim results+ // into the composer, so a final matching its interim would look unchanged.+ dictationBaseTextRef.current = aui.composer().getState().text;+ return;+ }+ wasDictatingRef.current = false;+ if (!sendAfterDictationRef.current) return;+ // A partial transcript (a failed chunk, or an engine error after one+ // landed) belongs in the composer, but must not send half a message.+ // Silence, a thread switch mid-transcription, or a plus-menu insertion+ // with no speech: keep the draft, submit nothing. Settled before the hold+ // below, so nothing to send never leaves an intent pending.+ const text = composerText;+ const sendable =+ !dictationFailed() &&+ shouldSubmitDictation({+ originComposer: dictationComposerRef.current,+ currentComposer: composerIdentity,+ producedTranscript: dictationProducedTranscript(),+ baseText: dictationBaseTextRef.current,+ text,+ });+ if (!sendable) {+ sendAfterDictationRef.current = false;+ heldTextRef.current = null;+ return;+ }+ // The plus stays live while transcribing, so an upload or an attachment+ // can appear after the press. Keep the intent until the composer accepts+ // a submit again, rather than spending it on one that would bounce.+ if (dictationBlocked) {+ // The bar is gone by now, so the hold is invisible. It lasts only as+ // long as the transcript it was pressed for: editing hands control+ // back, rather than sending that edit when the block clears.+ if (heldTextRef.current === null) {+ heldTextRef.current = text;+ } else if (heldTextRef.current !== text) {+ sendAfterDictationRef.current = false;+ heldTextRef.current = null;+ }+ return;+ }+ sendAfterDictationRef.current = false;+ heldTextRef.current = null;+ formRef.current?.requestSubmit();+ }, [isDictating, aui, composerIdentity, dictationBlocked, composerText]);+const handleSubmit = useCallback((event: Parameters<NonNullable<ComponentProps<"form">["onSubmit"]>>[0]) => {if (isResearchActive) {@@ -2024,7 +2119,13 @@ const Composer: FC<{{isDictating ? (// The recording UI replaces the input and send controls; only the// left plus stays visible alongside it.- <ChatDictationBar />+ <ChatDictationBar+ onSend={sendAfterDictation}+ // Every state handleSubmit rejects, since it would reject after+ // transcription with the send intent already spent. Text presence+ // is left out: the transcript supplies it.+ sendDisabled={dictationBlocked}+ />) : (<><ComposerPrimitive.Input@@ -2086,6 +2187,7 @@ const Composer: FC<{return (<PromptQueueContext.Provider value={queueContextValue}><ComposerPrimitive.Root+ ref={formRef}className="aui-composer-root relative flex w-full flex-col"aria-disabled={disabled}onSubmit={handleSubmit}@@ -3645,7 +3747,7 @@ const ComposerRightControls: FC<{<div className="aui-composer-action-wrapper flex shrink-0 items-center gap-1.5"><ReasoningToggle side={menuSide} />{/* Starts dictation; the recording bar then covers the input row and owns- the stop and discard actions. */}+ the stop and send actions. */}<ComposerPrimitive.If dictation={false}><TooltipIconButtontooltip="Dictate"@@ -3655,7 +3757,8 @@ const ComposerRightControls: FC<{className="size-8 rounded-full text-foreground"onClick={startDictation}>- <MicIcon className="size-5" />+ {/* size-[22px] is the fallback; unsloth-dictate-icon sets the size. */}+ <MicIcon className="unsloth-dictate-icon size-[22px]" /></TooltipIconButton></ComposerPrimitive.If><AuiIf@@ -3674,13 +3777,13 @@ const ComposerRightControls: FC<{// disabled only once a send is parked.disabled={disabled || pendingSend}onClick={(event) => onSendClick?.(event)}- className="aui-composer-send ml-1.5 size-8 rounded-full"+ className="aui-composer-send ml-1.5 size-9 rounded-full"aria-label="Send message">{pendingSend ? (<Spinner className="size-[18px]" />) : (- <ArrowUpIcon className="aui-composer-send-icon size-[21px] stroke-2" />+ <ArrowUpIcon className="unsloth-send-icon aui-composer-send-icon size-[21px] stroke-2" />)}</TooltipIconButton></ComposerPrimitive.Send>@@ -3695,10 +3798,10 @@ const ComposerRightControls: FC<{size="icon"disabled={disabled || queueDisabled}onClick={onQueueClick}- className="aui-composer-send ml-1.5 size-8 rounded-full"+ className="aui-composer-send ml-1.5 size-9 rounded-full"aria-label="Queue message">- <ArrowUpIcon className="aui-composer-send-icon size-[21px] stroke-2" />+ <ArrowUpIcon className="unsloth-send-icon aui-composer-send-icon size-[21px] stroke-2" /></TooltipIconButton></AuiIf>) : null}@@ -3707,7 +3810,7 @@ const ComposerRightControls: FC<{type="button"variant="default"size="icon"- className="aui-composer-cancel ml-1.5 size-8 rounded-full"+ className="aui-composer-cancel ml-1.5 size-9 rounded-full"aria-label={researchStopping ? "Stopping research" : "Stop research"}disabled={researchStopping}onClick={stop}@@ -3727,7 +3830,7 @@ const ComposerRightControls: FC<{type="button"variant="default"size="icon"- className="aui-composer-cancel size-8 rounded-full"+ className="aui-composer-cancel size-9 rounded-full"aria-label="Stop generating"onClick={stop}>@@ -3743,10 +3846,10 @@ const ComposerRightControls: FC<{size="icon"disabled={queueDisabled}onClick={onQueueClick}- className="aui-composer-send size-8 rounded-full"+ className="aui-composer-send size-9 rounded-full"aria-label="Queue message">- <ArrowUpIcon className="aui-composer-send-icon size-[21px] stroke-2" />+ <ArrowUpIcon className="unsloth-send-icon aui-composer-send-icon size-[21px] stroke-2" /></TooltipIconButton>)}</div>diff --git a/studio/frontend/src/features/chat/adapters/dictation-outcome.ts b/studio/frontend/src/features/chat/adapters/dictation-outcome.tsnew file mode 100644index 00000000000..0eaabfbf1d4--- /dev/null+++ b/studio/frontend/src/features/chat/adapters/dictation-outcome.ts@@ -0,0 +1,42 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++/**+ * What the dictation that just ended actually produced.+ *+ * The recording bar's send needs both answers, and cannot get them from the+ * composer: text can change while recording (the plus menu can insert a saved+ * prompt), and a partial transcript still lands there. Module state, not+ * session state, because the bar reads it once the session is gone.+ */+let producedTranscript = false;+let failed = false;++/** Start a session. Clears the previous session's result. */+export function beginDictationSession(): void {+ producedTranscript = false;+ failed = false;+}++/** A final transcript was published to the composer. */+export function markDictationTranscript(): void {+ producedTranscript = true;+}++/** Whether the last dictation published any transcript. */+export function dictationProducedTranscript(): boolean {+ return producedTranscript;+}++/**+ * A transcript chunk, or the session itself, failed. Both engines can still+ * publish what did transcribe, so the text is partial rather than absent.+ */+export function markDictationFailed(): void {+ failed = true;+}++/** Whether the last dictation reported a failure. */+export function dictationFailed(): boolean {+ return failed;+}diff --git a/studio/frontend/src/features/chat/adapters/studio-dictation-adapter.tsx b/studio/frontend/src/features/chat/adapters/studio-dictation-adapter.tsxindex d637a32b0d9..2dc36bb2426 100644--- a/studio/frontend/src/features/chat/adapters/studio-dictation-adapter.tsx+++ b/studio/frontend/src/features/chat/adapters/studio-dictation-adapter.tsx@@ -14,9 +14,9 @@ import {StudioWebSpeechDictationAdapter,} from "./studio-web-speech-dictation-adapter";-// The one live dictation session, so the recording bar's discard (X) can cancel-// it without going through assistant-ui (which only exposes stop, i.e.-// transcribe). Cancelling emits no transcript, so composer text is untouched.+// The one live dictation session, so Escape can discard it without going+// through assistant-ui (which only exposes stop, i.e. transcribe). Cancelling+// emits no transcript, so composer text is untouched.let activeSession: StudioDictationSession | null = null;/** Discard the current dictation without transcribing. Safe to call when idle. */diff --git a/studio/frontend/src/features/chat/adapters/studio-model-dictation-adapter.ts b/studio/frontend/src/features/chat/adapters/studio-model-dictation-adapter.tsindex 8546e3eeab1..780b26f791e 100644--- a/studio/frontend/src/features/chat/adapters/studio-model-dictation-adapter.ts+++ b/studio/frontend/src/features/chat/adapters/studio-model-dictation-adapter.ts@@ -13,6 +13,11 @@ import {import type { DictationAdapter } from "@assistant-ui/react";import { toast } from "sonner";import { startDictationLevelMeter } from "./dictation-level";+import {+ beginDictationSession,+ markDictationFailed,+ markDictationTranscript,+} from "./dictation-outcome";import {type StudioDictationSession,isMissingDeviceError,@@ -265,6 +270,7 @@ export class StudioModelDictationAdapter implements DictationAdapter {if (!StudioModelDictationAdapter.isSupported()) {throw new Error("Recording is not supported in this browser.");}+ beginDictationSession();// Pin the model, language, and linked chat chosen when recording began, so a// mid-session settings change or thread switch cannot affect later segments@@ -362,6 +368,7 @@ export class StudioModelDictationAdapter implements DictationAdapter {stream = null;const corrected = transcript ? applyDictationDictionary(transcript) : "";if (reason !== "cancelled" && corrected) {+ markDictationTranscript();for (const callback of speechCallbacks) {callback({ transcript: corrected, isFinal: true });}@@ -403,6 +410,9 @@ export class StudioModelDictationAdapter implements DictationAdapter {} catch (error) {if (!cancelled && !abortController.signal.aborted) {// Keep transcribed segments, but never hide that part was lost.+ // Only a lost segment is partial: the model preload shares this+ // reporter and can fail without costing any audio.+ markDictationFailed();reportTranscriptionError(error);}} finally {diff --git a/studio/frontend/src/features/chat/adapters/studio-web-speech-dictation-adapter.ts b/studio/frontend/src/features/chat/adapters/studio-web-speech-dictation-adapter.tsindex fb0e4fc0ab7..23236831e99 100644--- a/studio/frontend/src/features/chat/adapters/studio-web-speech-dictation-adapter.ts+++ b/studio/frontend/src/features/chat/adapters/studio-web-speech-dictation-adapter.ts@@ -12,6 +12,11 @@ import type { DictationAdapter } from "@assistant-ui/react";import { toast } from "sonner";import { useChatRuntimeStore } from "../stores/chat-runtime-store";import { startDictationLevelMeter } from "./dictation-level";+import {+ beginDictationSession,+ markDictationFailed,+ markDictationTranscript,+} from "./dictation-outcome";/** Chat open while dictating, so the saved dictation can link back to it. */export function activeDictationChatId(): string | undefined {@@ -139,6 +144,7 @@ export class StudioWebSpeechDictationAdapter implements DictationAdapter {throw new Error("Speech recognition is not supported in this browser.");}+ beginDictationSession();const recognition = new SpeechRecognitionAPI();recognition.lang = this.language ?? resolveDictationLanguage();recognition.continuous = this.continuous;@@ -274,6 +280,7 @@ export class StudioWebSpeechDictationAdapter implements DictationAdapter {stream = null;const transcript = reason === "cancelled" ? "" : finalTranscript;if (transcript) {+ markDictationTranscript();for (const callback of speechCallbacks) {callback({ transcript, isFinal: true });}@@ -371,6 +378,8 @@ export class StudioWebSpeechDictationAdapter implements DictationAdapter {} else {toast.error(description);}+ // Any finalized chunks stay in the composer, but must not send alone.+ markDictationFailed();finish("error");});diff --git a/studio/frontend/src/features/chat/chat-page.tsx b/studio/frontend/src/features/chat/chat-page.tsxindex 81d3c3ed7dc..01f1bb06302 100644--- a/studio/frontend/src/features/chat/chat-page.tsx+++ b/studio/frontend/src/features/chat/chat-page.tsx@@ -3280,16 +3280,6 @@ export function ChatPage({className="max-w-[62vw] !pr-3 sm:max-w-none !h-[var(--studio-chat-control-height,34px)]"/>)}- {incognito && view.mode === "single" && (- <div className="flex h-[var(--studio-chat-control-height,34px)] shrink-0 items-center gap-1.5 self-center rounded-full bg-primary/10 px-2.5 font-medium text-ui-13 text-primary">- <HugeiconsIcon- icon={BubbleChatTemporaryIcon}- strokeWidth={2}- className="size-3.5"- />- <span>Temporary</span>- </div>- )}{view.mode !== "compare" && currentProjectId && (<navaria-label="Project location"@@ -3357,7 +3347,7 @@ export function ChatPage({</div>) : null}</div>- <div className="pointer-events-auto ml-auto flex items-center gap-2">+ <div className="pointer-events-auto ml-auto flex items-center gap-1">{view.mode === "single" && contextUsage ? (<ContextUsageBarused={contextUsage.totalTokens}@@ -3377,7 +3367,7 @@ export function ChatPage({type="button"onClick={toggleIncognito}className={cn(- "flex size-[var(--studio-chat-control-height,34px)] cursor-pointer items-center justify-center rounded-[12px] transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",+ "flex size-[var(--studio-chat-control-height,34px)] cursor-pointer items-center justify-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",incognito? "bg-primary/10 text-primary hover:bg-primary/15": "text-nav-fg hover:bg-nav-surface-hover hover:text-black dark:hover:text-white",@@ -3415,7 +3405,7 @@ export function ChatPage({closeArtifactSurface();openResearchPanel(latestResearchRun.id);}}- className="relative flex size-[var(--studio-chat-control-height,34px)] cursor-pointer items-center justify-center rounded-[12px] text-nav-fg transition-colors hover:bg-nav-surface-hover hover:text-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring dark:hover:text-white"+ className="relative flex size-[var(--studio-chat-control-height,34px)] cursor-pointer items-center justify-center rounded-full text-nav-fg transition-colors hover:bg-nav-surface-hover hover:text-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring dark:hover:text-white"aria-label="Open research activity"aria-pressed={openResearchRunId === latestResearchRun.id}>@@ -3443,7 +3433,7 @@ export function ChatPage({useResearchRunStore.getState().closePanel();setSettingsOpen(true);}}- className="flex size-[var(--studio-chat-control-height,34px)] translate-x-[2px] cursor-pointer items-center justify-center rounded-[12px] text-nav-fg transition-colors hover:bg-nav-surface-hover hover:text-black dark:hover:text-white focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"+ className="flex size-[var(--studio-chat-control-height,34px)] cursor-pointer items-center justify-center rounded-full text-nav-fg transition-colors hover:bg-nav-surface-hover hover:text-black dark:hover:text-white focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"aria-label="Open run settings"><HugeiconsIcondiff --git a/studio/frontend/src/features/chat/index.ts b/studio/frontend/src/features/chat/index.tsindex 1fa09055485..55ca654990f 100644--- a/studio/frontend/src/features/chat/index.ts+++ b/studio/frontend/src/features/chat/index.ts@@ -144,6 +144,10 @@ export {useChatProjects,} from "./hooks/use-chat-projects";export { subscribeDictationLevel } from "./adapters/dictation-level";+export {+ dictationFailed,+ dictationProducedTranscript,+} from "./adapters/dictation-outcome";export {StudioDictationAdapter,cancelActiveStudioDictation,diff --git a/studio/frontend/src/features/chat/shared-composer.tsx b/studio/frontend/src/features/chat/shared-composer.tsxindex 2ecad304e55..b1c1e8973bd 100644--- a/studio/frontend/src/features/chat/shared-composer.tsx+++ b/studio/frontend/src/features/chat/shared-composer.tsx@@ -2298,7 +2298,7 @@ export function SharedComposer({onClick={startDictation}aria-label="Dictate">- <MicIcon className="size-4" />+ <MicIcon className="unsloth-dictate-icon size-4" /></TooltipIconButton>) : (<TooltipIconButton@@ -2347,7 +2347,7 @@ export function SharedComposer({type="button"variant="default"size="icon"- className="ml-1.5 size-8 rounded-full"+ className="ml-1.5 size-9 rounded-full"onClick={stop}><SquareIcon className="size-3 fill-current" />@@ -2358,12 +2358,12 @@ export function SharedComposer({side="bottom"variant="default"size="icon"- className="ml-1.5 size-8 rounded-full"+ className="ml-1.5 size-9 rounded-full"onClick={send}disabled={!canSend}aria-label="Send message">- <ArrowUpIcon className="size-[22px] stroke-2" />+ <ArrowUpIcon className="unsloth-send-icon size-[22px] stroke-2" /></TooltipIconButton>)}</div>diff --git a/studio/frontend/src/features/chat/utils/dictation-send.ts b/studio/frontend/src/features/chat/utils/dictation-send.tsnew file mode 100644index 00000000000..984195c7665--- /dev/null+++ b/studio/frontend/src/features/chat/utils/dictation-send.ts@@ -0,0 +1,80 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++/**+ * Whether the recording bar's send should submit once dictation ends.+ *+ * Only when this recording actually added text: silence and failed+ * transcription leave a pre-recording draft in place rather than sending it+ * half-finished.+ *+ * @param before composer text captured when send was pressed+ * @param after composer text once the session ended+ */+export function dictationProducedText(before: string, after: string): boolean {+ const trimmed = after.trim();+ return trimmed.length > 0 && trimmed !== before.trim();+}++/**+ * Every state the composer's submit rejects.+ *+ * One definition for both jobs: greying out the recording bar's send, and+ * deciding whether a pending send waits rather than being spent on a submit+ * that would bounce. Text presence is not here, since the transcript supplies+ * it after the button is pressed.+ */+export function dictationSendBlocked(state: {+ /** The composer itself is unavailable. */+ composerDisabled: boolean;+ /** An attachment is still uploading. */+ uploading: boolean;+ /** A deep research run owns the composer. */+ researchActive: boolean;+ /** A response is streaming or the prompt queue is going. */+ runActive: boolean;+ /** This composer never queues, it asks the user to wait. */+ queueDisabled: boolean;+ /** An image edit overlay is open. */+ hasOverlay: boolean;+ /** Only text can be queued, so these block while a run is active. */+ hasAttachments: boolean;+ hasPendingAudio: boolean;+}): boolean {+ if (state.composerDisabled || state.uploading || state.researchActive) {+ return true;+ }+ if (!state.runActive) return false;+ return (+ state.queueDisabled ||+ state.hasOverlay ||+ state.hasAttachments ||+ state.hasPendingAudio+ );+}++/**+ * Whether a pending dictation send may submit now.+ *+ * Three ways it must not. The composer is reused across thread switches, so a+ * send pressed in one thread can land after a move to another, where it would+ * submit that thread's draft. The plus menu stays open to the user while+ * recording and can insert a saved prompt, which changes the text without any+ * speech. And silence leaves whatever was already there.+ */+export function shouldSubmitDictation(input: {+ /** Composer identity when send was pressed. */+ originComposer: string;+ /** Composer identity now that the session has ended. */+ currentComposer: string;+ /** The engine published a final transcript. */+ producedTranscript: boolean;+ /** Composer text at session start. */+ baseText: string;+ /** Composer text now. */+ text: string;+}): boolean {+ if (input.originComposer !== input.currentComposer) return false;+ if (!input.producedTranscript) return false;+ return dictationProducedText(input.baseText, input.text);+}diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.cssindex f18be92f949..e6dfb075dd9 100644--- a/studio/frontend/src/index.css+++ b/studio/frontend/src/index.css@@ -1683,8 +1683,10 @@ html[data-chat-font] .aui-root {@apply mt-2 mb-1 mx-3 min-h-12 w-[calc(100%-1.5rem)] resize-none overflow-y-auto bg-transparent pl-2 pr-4 pt-2 pb-3 text-sm font-[450] outline-none placeholder:text-muted-foreground focus-visible:ring-0;}+ /* Same 12px corner gap as the single composer, over this surface's px-1+ and no pb. */.composer-action-wrapper {- @apply relative mx-2 mb-2 flex items-center justify-between;+ @apply relative mx-2 mb-3 flex items-center justify-between;}.composer-footer-note {@@ -1692,7 +1694,9 @@ html[data-chat-font] .aui-root {font-family: var(--font-sans);}- /* Pill composer; own classes so compare-mode keeps its stacked layout. */+ /* Pill composer; own classes so compare-mode keeps its stacked layout. py+ 12px matches the send circle's gap to the right edge, so it sits evenly+ inside the 32px corner. */.unsloth-composer-surface {@apply relative flex w-full flex-col rounded-[32px] bg-background dark:bg-card px-3 py-3 outline-none transition-shadow;container-type: inline-size;@@ -1748,8 +1752,8 @@ html[data-chat-font] .aui-root {.unsloth-composer-line .aui-composer-action-wrapper {order: 3;margin-left: auto;- /* Inset the send circle from the edge, Gemini-style. */- margin-right: -0.125rem;+ /* 12px surface + 4px line padding minus this = 12px edge gap. */+ margin-right: -0.25rem;}.unsloth-composer-line[data-expanded="true"] .unsloth-composer-input {@@ -2867,6 +2871,23 @@ html[data-chat-font] .aui-root {& svg.size-\[20px\] { width: var(--ui-icon-size); height: var(--ui-icon-size); }& svg.size-\[21px\] { width: var(--ui-icon-size); height: var(--ui-icon-size); }& svg.size-\[22px\] { width: var(--ui-icon-size); height: var(--ui-icon-size); }+ /* Mic and send arrow sit above the shared glyph size: both fill their+ viewBox, so they read smaller than the stroked icons beside them. Keep+ after the size-[NN] rules they override. */+ & svg.unsloth-dictate-icon {+ width: calc(var(--ui-icon-size) * 1.2);+ height: calc(var(--ui-icon-size) * 1.2);+ }+ & svg.unsloth-send-icon {+ width: calc(var(--ui-icon-size) * 1.15);+ height: calc(var(--ui-icon-size) * 1.15);+ }+ /* Composer plus keeps its pre-#7400 22px base (1.375x the token is the same+ curve a 22px glyph would follow), so only its scaling changed. */+ & .unsloth-composer-plus svg {+ width: calc(var(--ui-icon-size) * 1.375);+ height: calc(var(--ui-icon-size) * 1.375);+ }& svg.size-\[36px\] { width: min(calc(36px * var(--ui-font-scale, 1)), calc(18px + 18px * var(--ui-font-scale, 1))); height: min(calc(36px * var(--ui-font-scale, 1)), calc(18px + 18px * var(--ui-font-scale, 1))); }& svg.w-3 { width: min(calc(0.75rem * var(--ui-font-scale, 1)), calc(0.375rem + 0.375rem * var(--ui-font-scale, 1))); }& svg.h-3 { height: min(calc(0.75rem * var(--ui-font-scale, 1)), calc(0.375rem + 0.375rem * var(--ui-font-scale, 1))); }diff --git a/studio/frontend/tests/dictation-outcome.test.ts b/studio/frontend/tests/dictation-outcome.test.tsnew file mode 100644index 00000000000..05f7e037c7f--- /dev/null+++ b/studio/frontend/tests/dictation-outcome.test.ts@@ -0,0 +1,61 @@+// 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 test from "node:test";++import {+ beginDictationSession,+ dictationFailed,+ dictationProducedTranscript,+ markDictationFailed,+ markDictationTranscript,+} from "../src/features/chat/adapters/dictation-outcome.ts";++test("a fresh session has produced nothing and failed at nothing", () => {+ beginDictationSession();+ assert.equal(dictationProducedTranscript(), false);+ assert.equal(dictationFailed(), false);+});++test("a published transcript is visible after the session ends", () => {+ beginDictationSession();+ markDictationTranscript();+ assert.equal(dictationProducedTranscript(), true);+});++test("a reported failure is visible after the session ends", () => {+ beginDictationSession();+ markDictationFailed();+ assert.equal(dictationFailed(), true);+});++// A partial transcript is both: text was published, and some was lost.+test("a partial transcript reports both", () => {+ beginDictationSession();+ markDictationTranscript();+ markDictationFailed();+ assert.equal(dictationProducedTranscript(), true);+ assert.equal(dictationFailed(), true);+});++// The recording bar reads these once the session is gone, so they have to+// survive until the next one starts rather than clearing on end.+test("both survive until the next session starts", () => {+ beginDictationSession();+ markDictationTranscript();+ markDictationFailed();+ beginDictationSession();+ assert.equal(dictationProducedTranscript(), false);+ assert.equal(dictationFailed(), false);+});++test("repeated marks in one session stay set", () => {+ beginDictationSession();+ markDictationTranscript();+ markDictationTranscript();+ markDictationFailed();+ markDictationFailed();+ assert.equal(dictationProducedTranscript(), true);+ assert.equal(dictationFailed(), true);+});diff --git a/studio/frontend/tests/dictation-send.test.ts b/studio/frontend/tests/dictation-send.test.tsnew file mode 100644index 00000000000..fbf5be3943c--- /dev/null+++ b/studio/frontend/tests/dictation-send.test.ts@@ -0,0 +1,158 @@+// 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 test from "node:test";++import {+ dictationProducedText,+ dictationSendBlocked,+ shouldSubmitDictation,+} from "../src/features/chat/utils/dictation-send.ts";++test("a transcript into an empty composer sends", () => {+ assert.equal(dictationProducedText("", "hello there"), true);+});++test("a transcript appended to a draft sends", () => {+ assert.equal(dictationProducedText("draft", "draft hello there"), true);+});++test("silence with an empty composer sends nothing", () => {+ assert.equal(dictationProducedText("", ""), false);+});++test("silence keeps a pre-recording draft instead of sending it", () => {+ assert.equal(dictationProducedText("draft", "draft"), false);+});++// Anchored on the text at session start, so a final result identical to the+// interim the browser engine already streamed in still counts as produced.+test("a final transcript matching its interim still sends", () => {+ assert.equal(dictationProducedText("", "hello there"), true);+ assert.equal(dictationProducedText("draft", "draft hello there"), true);+});++test("a whitespace-only transcript does not count as text", () => {+ assert.equal(dictationProducedText("draft", "draft "), false);+ assert.equal(dictationProducedText("", " "), false);+});++const base = {+ originComposer: "item-1",+ currentComposer: "item-1",+ producedTranscript: true,+ baseText: "",+ text: "hello there",+};++test("a transcript submits in the composer the send started in", () => {+ assert.equal(shouldSubmitDictation(base), true);+});++// The composer is reused across thread switches, so a send that lands after+// the move would otherwise submit the destination thread's draft.+test("a thread switch during transcription drops the send", () => {+ assert.equal(+ shouldSubmitDictation({+ ...base,+ currentComposer: "item-2",+ text: "someone else's draft",+ }),+ false,+ );+});++// The identity has to survive a new chat's first persist, which moves+// activeThreadId from null to the remote id without changing the composer.+test("hydrating a new chat keeps the pending send alive", () => {+ assert.equal(shouldSubmitDictation(base), true);+});++test("silence in the original composer sends nothing", () => {+ assert.equal(+ shouldSubmitDictation({+ ...base,+ producedTranscript: false,+ baseText: "draft",+ text: "draft",+ }),+ false,+ );+});++// The plus menu stays open while recording: inserting a saved prompt changes+// the composer without any speech, which text alone cannot tell apart.+test("a menu insertion with no transcript sends nothing", () => {+ assert.equal(+ shouldSubmitDictation({+ ...base,+ producedTranscript: false,+ text: "an inserted saved prompt",+ }),+ false,+ );+});++test("a menu insertion alongside a real transcript still sends", () => {+ assert.equal(+ shouldSubmitDictation({ ...base, text: "an inserted prompt hello there" }),+ true,+ );+});++const open = {+ composerDisabled: false,+ uploading: false,+ researchActive: false,+ runActive: false,+ queueDisabled: false,+ hasOverlay: false,+ hasAttachments: false,+ hasPendingAudio: false,+};++test("an idle composer accepts the dictation send", () => {+ assert.equal(dictationSendBlocked(open), false);+});++test("the composer's own unavailable states block regardless of a run", () => {+ assert.equal(dictationSendBlocked({ ...open, composerDisabled: true }), true);+ assert.equal(dictationSendBlocked({ ...open, uploading: true }), true);+ assert.equal(dictationSendBlocked({ ...open, researchActive: true }), true);+});++// Plain text queues while a response runs, which is what the bar exists for.+test("a running response alone does not block", () => {+ assert.equal(dictationSendBlocked({ ...open, runActive: true }), false);+});++// Only text can be queued, so these block a send that would have to queue.+test("non-queueable content blocks only while a run is active", () => {+ for (const key of [+ "queueDisabled",+ "hasOverlay",+ "hasAttachments",+ "hasPendingAudio",+ ] as const) {+ assert.equal(dictationSendBlocked({ ...open, [key]: true }), false);+ assert.equal(+ dictationSendBlocked({ ...open, runActive: true, [key]: true }),+ true,+ );+ }+});++// The case the button gate cannot cover: an attachment added after the press,+// whose upload finishes before transcription does.+test("an attachment completing mid-transcription blocks a queued send", () => {+ assert.equal(+ dictationSendBlocked({+ ...open,+ runActive: true,+ uploading: false,+ hasAttachments: true,+ }),+ true,+ );+});