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: answer the first Compare message in both panes (#16693)
Nilaycbbcb5922941
diff --git a/studio/frontend/src/features/chat/shared-composer.tsx b/studio/frontend/src/features/chat/shared-composer.tsxindex 734367365b0..914925410fc 100644--- a/studio/frontend/src/features/chat/shared-composer.tsx+++ b/studio/frontend/src/features/chat/shared-composer.tsx@@ -278,7 +278,7 @@ export type CompareMessagePart =export interface CompareHandle {append: (content: CompareMessagePart[]) => void;- appendMessage: (content: CompareMessagePart[]) => void;+ appendMessage: (content: CompareMessagePart[]) => Promise<void>;startRun: () => void;cancel: () => void;isRunning: () => boolean;@@ -459,15 +459,24 @@ export function RegisterCompareHandle({aui.thread().append({ role: "user", content, createdAt: new Date() } as never),- appendMessage: (content) =>- aui- .thread()- .append({- role: "user",- content,- createdAt: new Date(),- startRun: false,- } as never),+ appendMessage: (content) => {+ const count = aui.thread().getState().messages.length;+ aui.thread().append({+ role: "user",+ content,+ createdAt: new Date(),+ startRun: false,+ } as never);+ return new Promise<void>((resolve) => {+ const landed = () => aui.thread().getState().messages.length > count;+ if (landed()) return resolve();+ const unsubscribe = aui.subscribe(() => {+ if (!landed()) return;+ unsubscribe();+ resolve();+ });+ });+ },startRun: () => {const msgs = aui.thread().getState().messages;const lastId = msgs.length > 0 ? msgs[msgs.length - 1].id : null;@@ -2147,8 +2156,10 @@ export function SharedComposer({const handle1 = handlesRef.current["model1"];const handle2 = handlesRef.current["model2"];- if (handle1) handle1.appendMessage(content);- if (handle2) handle2.appendMessage(content);+ await Promise.all([+ handle1?.appendMessage(content),+ handle2?.appendMessage(content),+ ]);const name1 = model1?.id ? compareModelDisplayName(model1.id) : "";const name2 = model2?.id ? compareModelDisplayName(model2.id) : "";diff --git a/studio/frontend/tests/compare-first-message-new-chat.test.ts b/studio/frontend/tests/compare-first-message-new-chat.test.tsnew file mode 100644index 00000000000..2a9d02d0970--- /dev/null+++ b/studio/frontend/tests/compare-first-message-new-chat.test.ts@@ -0,0 +1,86 @@+// 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 { stripTypeScriptTypes } from "node:module";+import test from "node:test";+import { readSrc } from "./helpers/kit.ts";++const composer = readSrc("features/chat/shared-composer.tsx");++function slice(from: string, to: string): string {+ const start = composer.indexOf(from);+ const end = composer.indexOf(to, start);+ assert.ok(start >= 0 && end > start, `${from} .. ${to}`);+ return composer.slice(start, end);+}++function asyncBody(source: string): string {+ const wrapped = stripTypeScriptTypes(`async function f() {\n${source}\n}`);+ return wrapped.slice(wrapped.indexOf("{") + 1, wrapped.lastIndexOf("}"));+}++const registerHandle = new Function(+ "handlesRef",+ "name",+ "aui",+ asyncBody(+ slice(+ "const currentHandles = handlesRef.current;",+ "return () => {\n delete currentHandles[name];",+ ),+ ),+);++const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor;+const appendBoth = new AsyncFunction(+ "handlesRef",+ "content",+ `${asyncBody(+ slice('const handle1 = handlesRef.current["model1"];', "const name1 ="),+ )}\nreturn { handle1, handle2 };`,+);++function newCompareThread(paneId: string) {+ const listeners = new Set<() => void>();+ const state = { messages: [] as { id: string; role: string }[], isRunning: false };+ const runs: (string | null)[] = [];+ const aui = {+ subscribe(listener: () => void) {+ listeners.add(listener);+ return () => listeners.delete(listener);+ },+ threadListItem: () => ({ getState: () => ({ id: paneId, remoteId: null }) }),+ thread: () => ({+ getState: () => state,+ append() {+ setImmediate(() => {+ state.messages = [...state.messages, { id: `${paneId}-user`, role: "user" }];+ for (const listener of listeners) listener();+ });+ },+ startRun({ parentId }: { parentId: string | null }) {+ runs.push(parentId);+ },+ }),+ };+ return { aui, runs };+}++test("the first message of a new compare chat starts pane 1 on the user message", async () => {+ const handlesRef = { current: {} as Record<string, unknown> };+ const pane1 = newCompareThread("pane1");+ const pane2 = newCompareThread("pane2");+ registerHandle(handlesRef, "model1", pane1.aui);+ registerHandle(handlesRef, "model2", pane2.aui);++ const { handle1, handle2 } = await appendBoth(handlesRef, [+ { type: "text", text: "What is 2+2?" },+ ]);+ await "ready";+ handle1.startRun();+ handle2.startRun();++ assert.deepEqual(pane1.runs, ["pane1-user"]);+ assert.deepEqual(pane2.runs, ["pane2-user"]);+});