The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
feat(models): der Weg zurueck zu LM Studio kostet denselben einen Klick
purple0f530aa4bede
diff --git a/src/api/lu-engine-switch.ts b/src/api/lu-engine-switch.tsindex 8c8c866c..b708a048 100644--- a/src/api/lu-engine-switch.ts+++ b/src/api/lu-engine-switch.ts@@ -19,6 +19,13 @@import { useLuEngineSwitchStore } from '../stores/luEngineSwitchStore'import { luEngineSwapInFlight } from './lu-engine-swap-lock'import { useProviderStore } from '../stores/providerStore'+import {+ slotHandbackUpdate, standbyOccupant,+ type HandoverSlot, type SlotOccupant,+} from '../lib/openai-slot-handover'+import { isBuiltinEngineEntry, type InstalledModelLike } from '../lib/lmstudio-match'+import { OpenAIProvider } from './providers/openai-provider'+import type { ProviderModel } from './providers/types'import { PROVIDER_PRESETS } from './providers/types'import { slotTakeoverUpdate } from '../lib/openai-slot-handover'import { LU_ENGINE_NAME } from '../lib/engine-name'@@ -105,3 +112,91 @@ export function ensureLuEngineIsChatProvider(): boolean {}))return true}++// ── The way back (A16, A14-3a) ──────────────────────────────────────────────+//+// Windows counter-check 02.09.: start the LM Studio server from the picker,+// chat with an LM Studio model, then click an LU Engine tile. From that moment+// the picker shows LU Engine models and nothing else, although LM Studio's+// server is still up on 1234. The card that offers to start it is gone too,+// correctly, because the server is running. The only way back is Settings, AI+// Backends, Providers, Enable on the standby card, and no line anywhere says+// so. The trip out took one click.+//+// So the trip back takes one click as well. While our engine holds the slot,+// the backend it displaced is asked for its models, they keep their own+// heading in the list, and picking one hands the slot back the way the+// standby card's Enable does, with the same sentence in the same status row+// the outward trip uses.++/** What the pick says when it moved the chat backend to `name`. */+export function chatProviderSwitchNote(name: string): string {+ return `Switched your chat provider to ${name} for this model.`+}++/**+ * The local backend waiting beside the slot while the LU Engine holds it, or+ * null when there is none to go back to.+ *+ * Local only, and never a managed one: a cloud backend on standby has nothing+ * to list from a machine that may be offline, and "managed" is us.+ */+export function standbyChatBackend(): SlotOccupant | null {+ const slot = useProviderStore.getState().providers.openai as HandoverSlot+ if (!(slot.enabled && slot.managed === true)) return null+ const waiting = standbyOccupant(slot)+ if (!waiting || !waiting.isLocal || waiting.managed) return null+ return waiting+}++/**+ * Is this row served by the backend on standby rather than by our engine.+ *+ * Both wear `provider: 'openai'`, because that is the one slot every+ * OpenAI-protocol backend shares. The display name is what tells them apart,+ * and it is the same name the standby card carries.+ */+export function isStandbyBackendRow(row: InstalledModelLike | null | undefined): boolean {+ if (!row || row.provider !== 'openai') return false+ if (isBuiltinEngineEntry(row)) return false+ const waiting = standbyChatBackend()+ if (!waiting) return false+ return (row.providerName || '').toLowerCase() === waiting.name.toLowerCase()+}++/**+ * Hand the slot back when the picked row belongs to the backend on standby.+ *+ * Returns the name it went back to, so the caller can say it, or null when+ * this row had nothing to do with the standby backend and everything stays+ * where it is.+ */+export function handBackChatProviderForRow(row: InstalledModelLike | null | undefined): string | null {+ if (!isStandbyBackendRow(row)) return null+ const { providers, setProviderConfig } = useProviderStore.getState()+ const slot = providers.openai as HandoverSlot+ const update = slotHandbackUpdate(slot)+ if (!update) return null+ setProviderConfig('openai', update)+ return update.name ?? null+}++/**+ * The standby backend's own model list, read straight from its server.+ *+ * A one-off client rather than the registry's cached one: the registry is+ * keyed on the slot, and the slot is currently the LU Engine. Nothing is+ * cached, so a server that has gone away since simply throws and the caller+ * adds no rows, which is exactly the old behaviour.+ */+export async function listStandbyBackendModels(occupant: SlotOccupant): Promise<ProviderModel[]> {+ const client = new OpenAIProvider({+ id: 'openai',+ name: occupant.name,+ enabled: true,+ baseUrl: occupant.baseUrl,+ apiKey: '',+ isLocal: occupant.isLocal,+ })+ return client.listModels()+}diff --git a/src/components/models/ModelSelector.tsx b/src/components/models/ModelSelector.tsxindex 6c5ea01d..37aa1e78 100644--- a/src/components/models/ModelSelector.tsx+++ b/src/components/models/ModelSelector.tsx@@ -23,6 +23,7 @@ import { isBuiltinEngineEntry, type InstalledModelLike } from '../../lib/lmstudiimport {ensureLuEngineIsChatProvider, LU_ENGINE_SWITCH_NOTE, LU_ENGINE_SWAP_BUSY_NOTE,announceLuEngineSwapBusy, luEngineStartFailureNote,+ handBackChatProviderForRow, chatProviderSwitchNote,} from '../../api/lu-engine-switch'import { tryAcquireLuEngineSwap, releaseLuEngineSwap } from '../../api/lu-engine-swap-lock'import { useLuEngineSwitchStore } from '../../stores/luEngineSwitchStore'@@ -705,6 +706,16 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredByconst handleSelectModel = async (model: AIModel) => {const id = lmsIdOf(model)+ // A16 (A14-3a): a row belonging to the backend our engine displaced hands+ // the slot back to it. First thing in the function, because everything+ // below asks who holds the slot: the auto-load branch would warm a model+ // in LM Studio and then route the chat at 8127, and the LU Engine branch+ // would try to load an LM Studio id as a GGUF.+ const handedBackTo = handBackChatProviderForRow(model as unknown as InstalledModelLike)+ if (handedBackTo) {+ useLuEngineSwitchStore.getState().announce(chatProviderSwitchNote(handedBackTo))+ }+if (shouldAutoLoadForSelect(model, lmsLoaded)) {if (selectingLms || togglingLms) return // a load is already in flightsetSelectError(null)diff --git a/src/hooks/__tests__/the-way-back-to-lm-studio.test.ts b/src/hooks/__tests__/the-way-back-to-lm-studio.test.tsnew file mode 100644index 00000000..f12bc9a0--- /dev/null+++ b/src/hooks/__tests__/the-way-back-to-lm-studio.test.ts@@ -0,0 +1,197 @@+/**+ * @vitest-environment jsdom+ *+ * A16 (A14-3a), Windows counter-check 02.09.: "Wer LM Studio einmal verlaesst,+ * findet es im Picker nicht wieder." Start the LM Studio server from the+ * picker, pick an LM Studio model, then click an LU Engine tile. From there+ * the picker lists LU Engine models only, although LM Studio's server is still+ * up on 1234, and the card that offers to start it stays away, correctly,+ * because it IS running. The way back was Settings, AI Backends, Providers,+ * Enable on the standby card, and nothing in the picker said so. The way out+ * had been one click.+ *+ * It is symmetric now. The displaced backend's models stay listed under its own+ * name while it waits beside the slot, and picking one hands the slot back the+ * way the standby card's Enable does, with the same sentence in the same status+ * row the outward switch writes into.+ *+ * Run: npx vitest run src/hooks/__tests__/the-way-back-to-lm-studio.test.ts+ */+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'+import { renderHook, act } from '@testing-library/react'++const activateBuiltinModel = vi.fn(async () => true)+const listStandbyBackendModels = vi.fn()++vi.mock('../../api/backend', () => ({+ isTauri: () => true, isMacOS: () => false, isWindows: () => true, isLinux: () => false,+ backendCall: vi.fn(async () => null),+ secretGet: vi.fn().mockRejectedValue(new Error('no vault')),+ secretSet: vi.fn(), secretDelete: vi.fn(),+}))+vi.mock('../../api/comfyui', () => ({+ getInstalledImageModels: vi.fn(async () => []),+ getInstalledVideoModels: vi.fn(async () => []),+ checkComfyConnection: vi.fn(async () => false),+ readModelDiskSizes: vi.fn(async () => new Map()),+}))+vi.mock('../../api/ollama', () => ({+ listModels: vi.fn(async () => []), unloadModel: vi.fn(async () => undefined),+ pullModel: vi.fn(), pullModelTauri: vi.fn(), deleteModel: vi.fn(), showModel: vi.fn(),+}))+vi.mock('../../api/providers', async () => {+ const actual = await vi.importActual<typeof import('../../api/providers')>('../../api/providers')+ return { ...actual, getEnabledProviders: () => [] }+})+vi.mock('../../api/engine', async () => {+ const actual = await vi.importActual<typeof import('../../api/engine')>('../../api/engine')+ return {+ ...actual,+ listBundledModels: vi.fn(async () => []),+ isManagedBuiltinActive: () => true,+ bundledEngineStatus: vi.fn(async () => ({ running: true, healthy: true, port: 8127 })),+ bundledEmbedStatus: vi.fn(async () => ({ running: true, healthy: true, port: 8128 })),+ startBundledEmbed: vi.fn(),+ activateBuiltinModel: (...a: unknown[]) => activateBuiltinModel(...(a as [])),+ }+})+// Everything about the handback itself is the real thing; only the HTTP call+// to LM Studio's own server is stood in for.+vi.mock('../../api/lu-engine-switch', async () => {+ const actual = await vi.importActual<typeof import('../../api/lu-engine-switch')>('../../api/lu-engine-switch')+ return { ...actual, listStandbyBackendModels: (...a: unknown[]) => listStandbyBackendModels(...(a as [])) }+})++const { useModels } = await import('../useModels')+const { useModelStore } = await import('../../stores/modelStore')+const { useProviderStore } = await import('../../stores/providerStore')+const { useLuEngineSwitchStore } = await import('../../stores/luEngineSwitchStore')+const { __resetLuEngineSwapLockForTests } = await import('../../api/lu-engine-swap-lock')++const LMS_ROW = 'openai::qwen2.5-0.5b-instruct@q4_k_m'+const LU_ROW = 'openai::Phi-4-mini-instruct-Q4_K_M'+const LMS_URL = 'http://localhost:1234/v1'++/** What LM Studio's own /v1/models answers while it waits on standby. */+function lmStudioAnswers() {+ listStandbyBackendModels.mockResolvedValue([+ { id: 'qwen2.5-0.5b-instruct@q4_k_m', name: 'qwen2.5-0.5b-instruct@q4_k_m', provider: 'openai', providerName: 'LM Studio' },+ ])+}++/** The state the counter-check was in: our engine in the slot, LM Studio+ * pushed onto the standby card, its server still running. */+function luEngineTookTheSlotFromLmStudio() {+ useProviderStore.getState().setProviderConfig('openai', {+ enabled: true, managed: true, name: 'LU Engine', baseUrl: 'http://127.0.0.1:8127/v1',+ isLocal: true,+ displaced: { name: 'LM Studio', baseUrl: LMS_URL, isLocal: true },+ })+}++beforeEach(() => {+ activateBuiltinModel.mockReset()+ activateBuiltinModel.mockResolvedValue(true)+ listStandbyBackendModels.mockReset()+ lmStudioAnswers()+ useLuEngineSwitchStore.setState({ note: null, tone: 'info', generation: 0 })+ __resetLuEngineSwapLockForTests()+ useProviderStore.getState().resetProvidersToDefaults()+ luEngineTookTheSlotFromLmStudio()+ useModelStore.setState({ models: [] as never, activeModel: LU_ROW })+})+afterEach(() => { __resetLuEngineSwapLockForTests() })++describe('LM Studio while the LU Engine holds the chat slot', () => {+ it('keeps its models in the list under its own name', async () => {+ const { result } = renderHook(() => useModels())+ await act(async () => { await result.current.fetchModels() })++ const rows = useModelStore.getState().models+ const lms = rows.find((m) => m.name === LMS_ROW)+ expect(lms, 'LM Studio fell out of the list the moment the engine took the slot').toBeTruthy()+ expect((lms as { providerName?: string }).providerName).toBe('LM Studio')+ expect(listStandbyBackendModels).toHaveBeenCalledWith(+ expect.objectContaining({ name: 'LM Studio', baseUrl: LMS_URL }),+ )+ })++ it('gives the slot back when one of its models is picked, and says so', async () => {+ const { result } = renderHook(() => useModels())+ await act(async () => { await result.current.fetchModels() })+ await act(async () => { await result.current.setActiveModel(LMS_ROW) })++ const slot = useProviderStore.getState().providers.openai+ expect(slot.name, 'the slot never went back').toBe('LM Studio')+ expect(slot.baseUrl).toBe(LMS_URL)+ expect(slot.managed, 'our engine is still marked as the backend').not.toBe(true)+ expect(useLuEngineSwitchStore.getState().note)+ .toBe('Switched your chat provider to LM Studio for this model.')+ // And our engine did not try to load an LM Studio id as a GGUF on the way.+ expect(activateBuiltinModel).not.toHaveBeenCalled()+ expect(useModelStore.getState().activeModel).toBe(LMS_ROW)+ })++ it('leaves the LU Engine on the standby card, so the way out stays one click too', async () => {+ const { result } = renderHook(() => useModels())+ await act(async () => { await result.current.fetchModels() })+ await act(async () => { await result.current.setActiveModel(LMS_ROW) })+ const slot = useProviderStore.getState().providers.openai as { displaced?: { name: string } }+ expect(slot.displaced?.name, 'the engine vanished instead of waiting').toBe('LU Engine')+ })++ // NEGATIVE CONTROL: a machine with nothing on standby must not gain an HTTP+ // request on every model refresh.+ it('asks nobody when no backend was displaced', async () => {+ useProviderStore.getState().setProviderConfig('openai', {+ enabled: true, managed: true, name: 'LU Engine', baseUrl: 'http://127.0.0.1:8127/v1',+ isLocal: true, displaced: undefined,+ })+ const { result } = renderHook(() => useModels())+ await act(async () => { await result.current.fetchModels() })+ expect(listStandbyBackendModels).not.toHaveBeenCalled()+ })++ // NEGATIVE CONTROL: the server really having gone away is the old situation+ // and has to stay harmless. No rows, no throw, and the rest of the list is+ // still built.+ it('adds nothing when the standby server has gone away', async () => {+ listStandbyBackendModels.mockRejectedValue(new Error('connection refused'))+ const { result } = renderHook(() => useModels())+ await act(async () => { await result.current.fetchModels() })+ expect(useModelStore.getState().models.some((m) => m.name === LMS_ROW)).toBe(false)+ expect(useProviderStore.getState().providers.openai.managed).toBe(true)+ })++ // NEGATIVE CONTROL: picking one of OUR models must not hand the slot to+ // anybody. Without this the fix would give the slot away on every click.+ it('holds the slot when an LU Engine row is picked', async () => {+ useModelStore.setState({+ models: [+ { name: LU_ROW, model: 'Phi-4-mini-instruct-Q4_K_M', size: 1, type: 'text', provider: 'openai', providerName: 'LU Engine' },+ ] as never,+ activeModel: null,+ })+ const { result } = renderHook(() => useModels())+ await act(async () => { await result.current.setActiveModel(LU_ROW) })+ expect(useProviderStore.getState().providers.openai.managed).toBe(true)+ expect(activateBuiltinModel).toHaveBeenCalledWith(LU_ROW)+ })++ // The picker has no render harness (model-selector-lms.test.ts), so its half+ // is pinned by reading the source: the handback has to be the FIRST thing+ // the pick does, before anything asks who holds the slot.+ it('and the composer picker hands back before it does anything else', async () => {+ const { readFileSync } = await import('node:fs')+ const { resolve, dirname } = await import('node:path')+ const { fileURLToPath } = await import('node:url')+ const src = readFileSync(+ resolve(dirname(fileURLToPath(import.meta.url)), '../../components/models/ModelSelector.tsx'),+ 'utf8',+ )+ const handback = src.indexOf('handBackChatProviderForRow(')+ expect(handback, 'the picker never hands the slot back').toBeGreaterThan(-1)+ expect(handback, 'it hands back after the auto-load branch, which is too late')+ .toBeLessThan(src.indexOf('shouldAutoLoadForSelect(model, lmsLoaded)'))+ })+})diff --git a/src/hooks/useModels.ts b/src/hooks/useModels.tsindex 52a937ab..dc58df33 100644--- a/src/hooks/useModels.ts+++ b/src/hooks/useModels.ts@@ -21,6 +21,8 @@ import { isBuiltinEngineEntry, type InstalledModelLike } from '../lib/lmstudio-mimport {ensureLuEngineIsChatProvider, LU_ENGINE_SWITCH_NOTE, LU_ENGINE_FILE_GONE,announceLuEngineSwapBusy, luEngineStartFailureNote,+ standbyChatBackend, listStandbyBackendModels, handBackChatProviderForRow,+ chatProviderSwitchNote,} from '../api/lu-engine-switch'import { tryAcquireLuEngineSwap, releaseLuEngineSwap } from '../api/lu-engine-swap-lock'import { useLuEngineSwitchStore } from '../stores/luEngineSwitchStore'@@ -239,6 +241,31 @@ export function useModels() {allModels.push(...result.value.filter(m => !isEmbeddingModel(m.name)))}}+ // A16 (A14-3a): the backend our engine displaced keeps its models on+ // screen while it is on standby.+ //+ // The openai slot holds one backend at a time, so while the LU Engine+ // has it, `/v1/models` is asked of the engine and LM Studio drops out of+ // the list even though its server is still running on 1234. The trip out+ // was one click on a tile; the trip back was Settings, AI Backends,+ // Providers, Enable, and nothing on the picker said so. Its rows are+ // listed here under their own name, and picking one hands the slot back+ // (see `handBackChatProviderForRow`).+ //+ // Only reached when a local backend really was displaced, so on the+ // ordinary machine with nothing on standby this costs no request at all.+ const standby = managedBuiltin ? standbyChatBackend() : null+ if (standby) {+ try {+ const waiting = await listStandbyBackendModels(standby)+ allModels.push(...waiting+ .map((pm) => cloudModelRow(pm) satisfies CloudModel)+ .filter((m) => !isEmbeddingModel(m.name)))+ } catch {+ // Its server went away in the meantime. No rows, exactly as before.+ }+ }+// LU Engine model list (the downloaded GGUFs and the user's own folder).//// A14 (2.6.8): asked whether or not the LU Engine is the active chat@@ -518,6 +545,15 @@ export function useModels() {// saying so: the slot has already changed hands and the model the user was// talking to has already been unloaded to make room.let switched = false+ // A16 (A14-3a): the other direction. A row belonging to the backend on+ // standby gives the slot back to it, with the same sentence in the same+ // row the outward switch uses. Done BEFORE the openai config is read below,+ // so the engine branch sees a slot that is no longer ours and keeps its+ // hands off a model it does not serve.+ const handedBackTo = handBackChatProviderForRow(row as unknown as InstalledModelLike | undefined)+ if (handedBackTo) {+ useLuEngineSwitchStore.getState().announce(chatProviderSwitchNote(handedBackTo))+ }if (isLuRow) {// The bolt against two swap_bundled_model calls at one engine, where the// second lands on a process the first is still restarting. It is takendiff --git a/src/lib/release-notes.ts b/src/lib/release-notes.tsindex 2519017e..96a1c043 100644--- a/src/lib/release-notes.ts+++ b/src/lib/release-notes.ts@@ -50,9 +50,10 @@ export const RELEASE_NOTES: ReleaseNote[] = ['The built-in engine goes by LU Engine now. It is the same engine with the same models in the same folder; only the name in Settings, in the model list and in the messages changed.','The LU Engine moves to a free port when 8127 is taken or reserved by the system, and after a start that fails it retries once instead of giving up until the next restart. The next start begins at 8127 again rather than staying on the port it had to move to. Windows port reservations are marked as researched rather than proven, because no such reservation could be staged here.','A chat model you downloaded stays visible as Installed even while the engine is not running, and its tile has a Use button that starts the engine and loads that model, rather than leaving you with a file you cannot reach.',+ 'A running LM Studio stays in the model picker after the chat has moved to the LU Engine. Its models keep their own heading in the list, and picking one gives the local slot back to LM Studio with a line saying so, so the way back costs the same one click the way out did.','The ComfyUI installer checks that the environment it just built can import ComfyUI, installs what is missing, and names a missing Visual C++ runtime instead of ending in a silent crash.','Repair environment runs the same check with a time limit and a Cancel button that stops it, and the trainer setup stopped blaming the network for failures that had nothing to do with the network.',- 'The folder you set under Model Storage is read now, not only written to. Every GGUF in it, up to four levels down, appears under Installed and loads from where it lies, whichever backend is serving your chat: on a machine running Ollama, a GGUF in that folder was found on disk and then listed nowhere. Its tile has a Use button that hands the chat to the LU Engine and says so in one line, and the way back to Ollama or LM Studio is the provider card it always was.',+ 'The folder you set under Model Storage is read now, not only written to. Every GGUF in it, up to four levels down, appears under Installed and loads from where it lies, whichever backend is serving your chat: on a machine running Ollama, a GGUF in that folder was found on disk and then listed nowhere. Its tile has a Use button that hands the chat to the LU Engine and says so in one line, and the way back to Ollama is the provider card it always was.','Model Storage says which backend each folder belongs to. It used to be one field labelled "(auto-detect)" over a paragraph that named all three backends at once, so you could not tell which backend you were setting a folder for. There are three named rows now: the LU Engine folder you set, with the folder that is actually being read spelled out while the field is empty; the LM Studio folder, read only, or a plain sentence that LM Studio is not installed; and Ollama, which keeps its own store and has no folder to set.','On the Mac, picking a model folder under Desktop, Documents or Downloads says up front that macOS will ask once for access to it, instead of letting that dialog arrive out of nowhere on the first scan.','Subfolders named the way ComfyUI names its own, loras or checkpoints, go to ComfyUI through its extra model paths at the next start, so models on a second drive show up there.',diff --git a/src/stores/__tests__/releaseNotesStore.test.ts b/src/stores/__tests__/releaseNotesStore.test.tsindex 281a9dfa..395723f2 100644--- a/src/stores/__tests__/releaseNotesStore.test.ts+++ b/src/stores/__tests__/releaseNotesStore.test.ts@@ -93,6 +93,9 @@ describe('the notes table', () => {// its own as if the engine then lives there. It does not, and the note// has to say which one of the two it is.'begins at 8127 again',+ // A16 (A14-3a): the trip back to LM Studio is new visible behaviour, so+ // it is in the note and pinned here.+ 'the way back costs the same one click',]) {expect(prose, `${shipping}: nothing about "${anchor}"`).toContain(anchor)}