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 LAN address on the API page when LAN access is on (#12906)
Nilay01ed10caee95
diff --git a/studio/frontend/src/config/env.ts b/studio/frontend/src/config/env.tsindex ed05d22e599..ef4510bd493 100644--- a/studio/frontend/src/config/env.ts+++ b/studio/frontend/src/config/env.ts@@ -39,32 +39,23 @@ interface PlatformState {appleSilicon: boolean;fileManager: FileManager | undefined;chatOnly: boolean;- // Why chatOnly is set (null when training is enabled), from /api/health.- // e.g. "mlx_unavailable" on Apple Silicon -> the UI explains the greyed-out- // Train/Export instead of silently disabling them.+ // /api/health reason for chatOnly; null while training is enabled.chatOnlyReason: string | null;- // What specifically blocked that reason, when the backend can name it. Today only the- // MLX gate does: it is all-or-nothing across mlx, mlx-lm and mlx-vlm, so without this- // the greyed-out Train row can only repeat "run `unsloth studio update`".+ // MLX gate covers mlx, mlx-lm, and mlx-vlm together; record the blocker when known.chatOnlyDetail: string | null;- // From /api/health (authed): live tunnel URL, direct (non-tunnel) base, and- // whether the server was launched with --secure.+ // authenticated /api/health values for cloudflareUrl, serverUrl, and secure.cloudflareUrl: string | null;serverUrl: string | null;secure: boolean;+ lanUrls: string[];fetched: boolean;- // Last verdict came from a deferred reply (torch-warm kill switch): nothing settles- // until a first-use operation detects, so the sidebar polls on this.+ // torch-warm kill switch defers detection to first use; the sidebar polls.detectionDeferred: boolean;isChatOnly: () => boolean;- // True until /api/health has answered with a server-measured verdict. Before that `chatOnly`- // is the browser-platform seed below, not an answer, so anything that would gray a- // capability out has to treat it as unknown: rendering the guess blacks out Train and Video- // on every Mac from first paint, visually identical to a measured "unsupported".+ // true until /api/health returns a verdict; guesses cannot gate features.capabilitiesUnknown: () => boolean;}-// Client-side fallback when backend isn't ready yet.function detectLocalPlatform(): DeviceType {if (typeof navigator === "undefined") return "linux";const platform = navigator.platform.toLowerCase();@@ -80,22 +71,18 @@ export const usePlatformStore = create<PlatformState>()((_, get) => ({deviceType: localDeviceType,appleSilicon: false,fileManager: undefined,- // A guess from the user agent, kept only as the pre-measurement fallback for the redirects- // that must decide something before /api/health answers. Capability gating must read- // capabilitiesUnknown() first and hold, not gray a tab out on this.+ // user-agent guess for redirects; capability gates await the server.chatOnly: localDeviceType === "mac",chatOnlyReason: null,chatOnlyDetail: null,cloudflareUrl: null,serverUrl: null,secure: false,+ lanUrls: [],fetched: false,detectionDeferred: false,isChatOnly: () => get().chatOnly,- // `fetched` already means "a server-reported verdict is stored" (see fetchDeviceType), so it- // is the unknown/known line; no second flag to keep in step with it. A deferred reply counts- // as settled even though it carries no device_type: under the torch-warm kill switch nothing- // else is coming this session, so treating it as unknown would spin the tabs forever.+ // deferred detection is settled because no verdict will arrive this session.capabilitiesUnknown: () => {const state = get();return !state.fetched && !state.detectionDeferred;diff --git a/studio/frontend/src/features/api-monitor/api-monitor-page.tsx b/studio/frontend/src/features/api-monitor/api-monitor-page.tsxindex e4884334ee0..6b7824259ab 100644--- a/studio/frontend/src/features/api-monitor/api-monitor-page.tsx+++ b/studio/frontend/src/features/api-monitor/api-monitor-page.tsx@@ -25,7 +25,11 @@ import { useChatRuntimeStore } from "@/features/chat/stores/chat-runtime-store";import type { ApiMonitorEntry } from "@/features/chat";import { isExternalModelId } from "@/features/chat/external-providers";import { modelIdsMatch } from "@/features/hub/lib/model-identity";-import { useSettingsDialogStore } from "@/features/settings";+import {+ lanApiUrls,+ loadLanAccess,+ useSettingsDialogStore,+} from "@/features/settings";import { remoteApiOrigin } from "@/features/settings/api/remote-access-state";import { getApiBase, isTauri } from "@/lib/api-base";import { copyToClipboard } from "@/lib/copy-to-clipboard";@@ -576,25 +580,27 @@ export function ApiMonitorPage(): ReactElement {}, [loading, signalReady]);const serverUrl = usePlatformStore((s) => s.serverUrl);const cloudflareUrl = usePlatformStore((s) => s.cloudflareUrl);+ const lanUrls = usePlatformStore((s) => s.lanUrls);const [unloading, setUnloading] = useState(false);- // A picker load in flight would land after the raw unload, which has no lifecycle guard.+ // block raw unloads while a picker load could finish afterward without a lifecycle guard.const modelLoading = useChatRuntimeStore((s) => s.modelLoading);const [unloadError, setUnloadError] = useState<string | null>(null);useEffect(() => {const refreshRemoteBase = () => {void fetchDeviceType({ force: true });+ loadLanAccess()+ .then((status) =>+ usePlatformStore.setState({ lanUrls: lanApiUrls(status) }),+ )+ .catch(() => undefined);};refreshRemoteBase();window.addEventListener("focus", refreshRemoteBase);return () => window.removeEventListener("focus", refreshRemoteBase);}, []);- // Manual release so VRAM frees without the idle timer. /unload matches on the- // internal id, which the monitor does not carry, so read status. unloadResident owns- // the read/unload/recheck sequence: this page's own feature (an API auto-switch) can- // swap the model out from under the read, and /unload naming a replaced model is a- // successful no-op, so one pass would report success over the model still resident.+ // read status for /unload's internal id; recheck because an API auto-switch can make it a no-op.const unloadActiveModel = async (): Promise<void> => {setUnloading(true);try {@@ -706,13 +712,12 @@ export function ApiMonitorPage(): ReactElement {detailInFlight,]);- // The desktop webview's origin is tauri://, and the packaged app picks its port- // dynamically. Same source as the Agents tab.+ // Tauri uses the runtime API base because its tauri:// origin omits the dynamic port.const origin = typeof window === "undefined" ? "" : window.location.origin;const localOrigin = isTauri ? (serverUrl ?? getApiBase()) : origin;- const baseUrl = `${remoteApiOrigin(cloudflareUrl, localOrigin)}/v1`;+ const baseUrl = `${remoteApiOrigin(cloudflareUrl, localOrigin, lanUrls)}/v1`;const serverStatus = data?.status ?? "idle";- // Older backends omit the field; only an explicit `false` means recording is off.+ // older backends omit the field, so only explicit `false` disables recording.const loggingDisabled = data?.logging_enabled === false;const statusCopy =serverStatus === "generating"diff --git a/studio/frontend/src/features/settings/api/lan-access-state.ts b/studio/frontend/src/features/settings/api/lan-access-state.tsindex 23871411399..e0ff2c83457 100644--- a/studio/frontend/src/features/settings/api/lan-access-state.ts+++ b/studio/frontend/src/features/settings/api/lan-access-state.ts@@ -90,7 +90,7 @@ export function normalizeLanAccessStatus(blockReason: status.block_reason ?? null,bindHost: status.bind_host ?? null,wildcardBind: status.wildcard_bind === true,- // absent on a backend that predates the field, where the web UI is served+ // older backends omit this field but still serve the web UIservesWebUi: status.serves_web_ui !== false,keylessLanEligible: status.keyless_lan_eligible === true,keylessScope,@@ -98,6 +98,11 @@ export function normalizeLanAccessStatus(};}+// launch binds (-H 0.0.0.0, Docker) often use forwarded localhost ports+export function lanApiUrls(status: LanAccessStatus): string[] {+ return status.managedBy === "settings" ? status.urls : [];+}+export function keylessLanAccessDescription(status: LanAccessStatus | null,): string {diff --git a/studio/frontend/src/features/settings/api/remote-access-state.ts b/studio/frontend/src/features/settings/api/remote-access-state.tsindex dea741e3018..7bed619ea05 100644--- a/studio/frontend/src/features/settings/api/remote-access-state.ts+++ b/studio/frontend/src/features/settings/api/remote-access-state.ts@@ -1,6 +1,8 @@// 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 { isLoopbackHost, normalizeHost } from "../components/agent-command.ts";+export type RemoteAccessState =| "off"| "starting"@@ -75,11 +77,21 @@ export function remoteAccessPollDelay(: 5000;}+function isLoopbackOrigin(origin: string): boolean {+ try {+ return isLoopbackHost(normalizeHost(new URL(origin).hostname));+ } catch {+ return false;+ }+}+export function remoteApiOrigin(remoteUrl: string | null,localOrigin: string,+ lanUrls: string[] = [],): string {- return remoteUrl ?? localOrigin;+ const lanUrl = isLoopbackOrigin(localOrigin) ? lanUrls[0] : undefined;+ return remoteUrl ?? lanUrl ?? localOrigin;}export function remoteAccessAutoStartReadOnly(diff --git a/studio/frontend/src/features/settings/components/lan-access-section.tsx b/studio/frontend/src/features/settings/components/lan-access-section.tsxindex e8917b81ce1..c3b9a3cd72d 100644--- a/studio/frontend/src/features/settings/components/lan-access-section.tsx+++ b/studio/frontend/src/features/settings/components/lan-access-section.tsx@@ -20,6 +20,7 @@ import {SelectValue,} from "@/components/ui/select";import { Switch } from "@/components/ui/switch";+import { usePlatformStore } from "@/config/env";import {loadLanAccess,startLanAccess,@@ -36,6 +37,7 @@ import {lanAccessErrorMessage,lanAccessPortReadOnly,lanAccessStopDisconnectsOrigin,+ lanApiUrls,validLanAccessPort,} from "@/features/settings/api/lan-access-state";import { isTauri } from "@/lib/api-base";@@ -246,6 +248,7 @@ export function LanAccessSection() {const applyStatus = useCallback((next: LanAccessStatus) => {setStatus(next);+ usePlatformStore.setState({ lanUrls: lanApiUrls(next) });}, []);useEffect(() => {diff --git a/studio/frontend/src/features/settings/index.ts b/studio/frontend/src/features/settings/index.tsindex 267a2830d70..6df1b9c0078 100644--- a/studio/frontend/src/features/settings/index.ts+++ b/studio/frontend/src/features/settings/index.ts@@ -16,6 +16,8 @@ export {} from "./api/download-transport";export { loadEmbeddingModelSettings } from "./api/embedding-model";export { updateHubSource } from "./api/hub-settings";+export { loadLanAccess } from "./api/lan-access";+export { lanApiUrls } from "./api/lan-access-state";export { loadMultiModelEnabled } from "./api/multi-model";export { loadOpenAIAutoSwitchSettings } from "./api/openai-auto-switch";export { listOpenAIModels } from "./api/openai-models";diff --git a/studio/frontend/tests/lan-access-state.test.ts b/studio/frontend/tests/lan-access-state.test.tsindex 2b4898af6ca..732521d9567 100644--- a/studio/frontend/tests/lan-access-state.test.ts+++ b/studio/frontend/tests/lan-access-state.test.ts@@ -14,6 +14,7 @@ import {lanAccessErrorMessage,lanAccessPortReadOnly,lanAccessStopDisconnectsOrigin,+ lanApiUrls,normalizeLanAccessStatus,validLanAccessPort,} from "../src/features/settings/api/lan-access-state.ts";@@ -201,6 +202,17 @@ test("urls survives a null or non-array payload without throwing", () => {}});+test("only LAN access started from Settings feeds the API base URL", () => {+ const status = (managed: "launch" | "settings" | null) =>+ normalizeLanAccessStatus(+ // biome-ignore lint/style/useNamingConvention: API schema+ apiStatus({ state: "online", urls: [LAN, SECOND], managed_by: managed }),+ );+ assert.deepEqual(lanApiUrls(status("settings")), [LAN, SECOND]);+ assert.deepEqual(lanApiUrls(status("launch")), []);+ assert.deepEqual(lanApiUrls(status(null)), []);+});+test("a public address is carried through so the section can warn about it", () => {const s = normalizeLanAccessStatus(// biome-ignore lint/style/useNamingConvention: API schemadiff --git a/studio/frontend/tests/remote-access-state.test.ts b/studio/frontend/tests/remote-access-state.test.tsindex be35a8426af..a6a4d70fd17 100644--- a/studio/frontend/tests/remote-access-state.test.ts+++ b/studio/frontend/tests/remote-access-state.test.ts@@ -133,19 +133,36 @@ test("poll delay is fast only while a transition is in flight", () => {}});-// ── remoteApiOrigin ──-test("remote origin prefers the live tunnel and falls back to the local one", () => {assert.equal(remoteApiOrigin(TUNNEL, "http://127.0.0.1:8888"), TUNNEL);assert.equal(remoteApiOrigin(null, "http://127.0.0.1:8888"),"http://127.0.0.1:8888",);- // An empty string is a real origin ("" from a non-browser context), not a miss.+ // an empty string is a valid origin from a non-browser context, not a missing valueassert.equal(remoteApiOrigin(null, ""), "");});-// ── remoteAccessAutoStartReadOnly ──+test("a loopback page with LAN access on shows the LAN address", () => {+ const lan = ["http://192.168.1.24:8888", "http://10.0.0.7:8888"];+ assert.equal(+ remoteApiOrigin(null, "http://127.0.0.1:8888", lan),+ "http://192.168.1.24:8888",+ );+ assert.equal(+ remoteApiOrigin(null, "http://localhost:8888", lan),+ "http://192.168.1.24:8888",+ );+ assert.equal(remoteApiOrigin(TUNNEL, "http://127.0.0.1:8888", lan), TUNNEL);+ assert.equal(+ remoteApiOrigin(null, "http://10.0.0.7:8888", lan),+ "http://10.0.0.7:8888",+ );+ assert.equal(+ remoteApiOrigin(null, "http://127.0.0.1:8888", []),+ "http://127.0.0.1:8888",+ );+});test("auto-start is read-only with no status, or under Colab ownership", () => {assert.equal(remoteAccessAutoStartReadOnly(null), true);