Skip to content

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.

feat(models): GGUFs im LU-Engine-Ordner erscheinen immer, Use schaltet um

purpleb6f8a957c57f
diff --git a/src/api/__tests__/lu-engine-switch.test.ts b/src/api/__tests__/lu-engine-switch.test.ts
new file mode 100644
index 00000000..4c62565d
--- /dev/null
+++ b/src/api/__tests__/lu-engine-switch.test.ts
@@ -0,0 +1,90 @@
+/**
+ * A14 (2.6.8), David: "Use auf einer LU-Engine-Kachel, waehrend Ollama aktiv
+ * ist: schaltet den Chat-Provider auf die LU Engine um. Wenn die LU Engine als
+ * Provider gar nicht angelegt ist, muss Use sie anlegen."
+ *
+ * Both halves are one write, because `ProviderId` is a fixed set of four slots
+ * and every OpenAI-protocol backend shares the `openai` one: there is no fifth
+ * entry to add, taking the slot IS setting the engine up. This exercises the
+ * real store, so what is proven is the state the app is left in, not the shape
+ * of the call.
+ *
+ * Run: npx vitest run src/api/__tests__/lu-engine-switch.test.ts
+ */
+import { describe, it, expect, beforeEach, vi } from 'vitest'
+
+vi.mock('../providers/registry', () => ({ clearProviderCache: vi.fn() }))
+vi.mock('../backend', () => ({
+ isTauri: () => false,
+ backendCall: vi.fn(async () => null),
+ secretGet: vi.fn().mockRejectedValue(new Error('no vault')),
+ secretSet: vi.fn(),
+ secretDelete: vi.fn(),
+}))
+
+const { ensureLuEngineIsChatProvider, LU_ENGINE_SWITCH_NOTE } = await import('../lu-engine-switch')
+const { useProviderStore } = await import('../../stores/providerStore')
+
+const JAN = { enabled: true, name: 'Jan', baseUrl: 'http://localhost:1337/v1', isLocal: true, managed: false, displaced: undefined }
+
+function slot() {
+ return useProviderStore.getState().providers.openai
+}
+
+beforeEach(() => {
+ useProviderStore.getState().resetProvidersToDefaults()
+})
+
+describe('a pick on an LU Engine model hands it the chat slot', () => {
+ it('turns an off slot back into the engine and says the user has to be told', () => {
+ // The Mac in the report: Ollama in front, the openai slot parked by
+ // onboarding, so Settings shows no engine card at all.
+ useProviderStore.getState().setProviderConfig('openai', { enabled: false, managed: false })
+ expect(ensureLuEngineIsChatProvider()).toBe(true)
+ expect(slot().enabled).toBe(true)
+ expect(slot().managed).toBe(true)
+ expect(slot().name).toBe('LU Engine')
+ expect(slot().baseUrl).toBe('http://127.0.0.1:8127/v1')
+ })
+
+ it('takes the slot from another backend and leaves that one a way back', () => {
+ useProviderStore.getState().setProviderConfig('openai', JAN)
+ expect(ensureLuEngineIsChatProvider()).toBe(true)
+ expect(slot().managed).toBe(true)
+ expect(slot().name).toBe('LU Engine')
+ // The displaced backend keeps a standby card with an Enable button, the
+ // same route the provider card uses. Without this the user's own entry
+ // would vanish without a word, which is the bug R10 exists for.
+ expect(slot().displaced?.name).toBe('Jan')
+ expect(slot().displaced?.baseUrl).toBe('http://localhost:1337/v1')
+ })
+
+ // NEGATIVE CONTROL: an engine that already holds the slot is left completely
+ // alone. Writing the config again would restart the standby bookkeeping and
+ // could drop a card that is still owed, and the user would be told about a
+ // switch that never happened.
+ it('changes nothing and says nothing when the engine already holds the slot', () => {
+ useProviderStore.getState().setProviderConfig('openai', {
+ enabled: true, managed: true, name: 'LU Engine',
+ displaced: { name: 'Jan', baseUrl: 'http://localhost:1337/v1', isLocal: true },
+ })
+ const before = { ...slot() }
+ expect(ensureLuEngineIsChatProvider()).toBe(false)
+ expect(slot()).toEqual(before)
+ expect(slot().displaced?.name).toBe('Jan')
+ })
+
+ // NEGATIVE CONTROL: Ollama lives in its own slot and is not the thing being
+ // replaced. Switching it off here would take the user's other models away
+ // from him for no reason, and the way back is his provider card.
+ it('leaves Ollama switched on', () => {
+ useProviderStore.getState().setProviderConfig('ollama', { enabled: true })
+ useProviderStore.getState().setProviderConfig('openai', { enabled: false, managed: false })
+ ensureLuEngineIsChatProvider()
+ expect(useProviderStore.getState().providers.ollama.enabled).toBe(true)
+ })
+
+ it('the sentence the user reads names the engine and the reason', () => {
+ expect(LU_ENGINE_SWITCH_NOTE).toBe('Switched your chat provider to the LU Engine for this model.')
+ })
+})
diff --git a/src/api/lu-engine-switch.ts b/src/api/lu-engine-switch.ts
new file mode 100644
index 00000000..93c9e4bc
--- /dev/null
+++ b/src/api/lu-engine-switch.ts
@@ -0,0 +1,52 @@
+/**
+ * Handing the shared local slot to the LU Engine because the user picked one
+ * of its models.
+ *
+ * A14 (2.6.8), David: on a Mac with Ollama as the chat backend, a GGUF in the
+ * LU Engine folder is listed now, and Use on it has to do the whole job. Half
+ * a job would be worse than the old invisibility: a tile that starts an engine
+ * nothing routes to, or a picked model that answers from Ollama.
+ *
+ * "The LU Engine is not set up at all" is not a separate case. `ProviderId` is
+ * a fixed set of four slots and every OpenAI-protocol backend shares the
+ * `openai` one, so there is no such thing as adding a fifth entry: taking the
+ * slot IS setting the engine up. That is why this goes through the same
+ * `slotTakeoverUpdate` the provider card uses, which also leaves the backend
+ * it displaces on a standby card with an Enable button, so the way back is the
+ * one the user already knows.
+ */
+
+import { useProviderStore } from '../stores/providerStore'
+import { PROVIDER_PRESETS } from './providers/types'
+import { slotTakeoverUpdate } from '../lib/openai-slot-handover'
+import { LU_ENGINE_NAME } from '../lib/engine-name'
+
+/** What the user is told when the pick moved his chat backend. */
+export const LU_ENGINE_SWITCH_NOTE = 'Switched your chat provider to the LU Engine for this model.'
+
+/** The shipped address of the engine. The real port is written back by
+ * `syncBuiltinEnginePort` as soon as it starts, exactly as it is for a
+ * takeover from the provider card. */
+const FALLBACK_BASE_URL = 'http://127.0.0.1:8127/v1'
+
+/**
+ * Make the LU Engine the backend of the shared local slot.
+ *
+ * Returns true when it was NOT already, which is precisely when the user has
+ * to be told. An engine that already holds the slot is left completely alone:
+ * writing the same config again would restart the standby bookkeeping and
+ * could drop a card that is still owed.
+ */
+export function ensureLuEngineIsChatProvider(): boolean {
+ const { providers, setProviderConfig } = useProviderStore.getState()
+ const slot = providers.openai
+ if (slot.enabled && slot.managed === true) return false
+ const preset = PROVIDER_PRESETS.find((p) => p.id === 'builtin')
+ setProviderConfig('openai', slotTakeoverUpdate(slot, {
+ name: LU_ENGINE_NAME,
+ baseUrl: preset?.baseUrl || FALLBACK_BASE_URL,
+ isLocal: true,
+ managed: true,
+ }))
+ return true
+}
diff --git a/src/components/models/DiscoverModels.tsx b/src/components/models/DiscoverModels.tsx
index 1a28cd45..edd9c8fa 100644
--- a/src/components/models/DiscoverModels.tsx
+++ b/src/components/models/DiscoverModels.tsx
@@ -28,6 +28,7 @@ import { BUILTIN_BACKEND_ID } from '../../lib/onboarding-backend'
import type { InstalledModelLike } from '../../lib/lmstudio-match'
import { findInstalledForDiscoverModel } from '../../lib/discover-installed'
import { isBuiltinEngineEntry } from '../../lib/lmstudio-match'
+import { ensureLuEngineIsChatProvider, LU_ENGINE_SWITCH_NOTE } from '../../api/lu-engine-switch'
import { resolveTextDownloadTarget } from '../../lib/text-download-target'
import { hfUrlToOllamaRef, hfUrlToLmStudioSubdir, parseHfUrl, extractGgufQuant, isShardedOrIncompatibleGguf } from '../../lib/hf-to-provider'
import { GlassCard } from '../ui/GlassCard'
@@ -240,9 +241,16 @@ export function DiscoverModels({ category, search = '', searchSubmitToken = 0 }:
const name = entry?.name
if (!name || usingModel) return
setInstallError(null)
+ setSwitchNote(null)
setUsingModel(name)
try {
if (isBuiltinEngineEntry(entry)) {
+ // A14: the LU Engine's GGUFs are listed even while Ollama or LM Studio
+ // holds the chat, so Use has to hand the slot over first. It has to be
+ // FIRST: diagnoseBuiltinEngine answers nothing at all for a slot that
+ // is not ours, so the old order would repair nothing and then activate
+ // a model no request routes to.
+ if (ensureLuEngineIsChatProvider()) setSwitchNote(LU_ENGINE_SWITCH_NOTE)
const diagnosis = await diagnoseBuiltinEngine({ repair: true, preferModel: name })
if (!diagnosis.ok && diagnosis.reason) setInstallError(diagnosis.reason)
}
@@ -257,6 +265,8 @@ export function DiscoverModels({ category, search = '', searchSubmitToken = 0 }:
const [installingBundle, setInstallingBundle] = useState<string | null>(null)
const [installError, setInstallError] = useState<string | null>(null)
+ // A14: the pick moved the chat backend. Not an error, so its own quiet line.
+ const [switchNote, setSwitchNote] = useState<string | null>(null)
// Confirmation gate for multi-part (sharded) downloads — these sets routinely
// run hundreds of GB across many files, so we never start them silently.
const [confirmDownload, setConfirmDownload] = useState<{ name: string; files: HfGgufFile[]; targetDir: string; totalGB: number; note?: string } | null>(null)
@@ -757,6 +767,16 @@ export function DiscoverModels({ category, search = '', searchSubmitToken = 0 }:
</div>
)}
+ {/* A14: the pick took the chat backend with it, and says so. */}
+ {switchNote && (
+ <div data-testid="lu-engine-switch-note" className="flex items-center gap-2 p-3 rounded-lg bg-white/5 border border-white/10 text-gray-600 dark:text-gray-300 text-sm">
+ <span className="flex-1">{switchNote}</span>
+ <button onClick={() => setSwitchNote(null)} className="text-gray-500 hover:text-gray-300 shrink-0" aria-label="Dismiss">
+ <X size={14} />
+ </button>
+ </div>
+ )}
+
{/* Install error banner */}
{installError && (
<div className="flex items-center gap-2 p-3 rounded-lg bg-red-500/10 border border-red-500/20 text-red-400 text-sm">
diff --git a/src/components/models/ModelManager.tsx b/src/components/models/ModelManager.tsx
index 0b52eb57..3b22d316 100644
--- a/src/components/models/ModelManager.tsx
+++ b/src/components/models/ModelManager.tsx
@@ -21,6 +21,8 @@ import { MlxMediaSettings } from '../settings/MlxMediaSettings'
import { backendCall } from '../../api/backend'
import { customModelDirs } from '../../api/engine'
import { counterView } from '../../lib/inventory-counter'
+import { groupInstalledByProvider } from '../../lib/lu-engine-rows'
+import type { InstalledModelLike } from '../../lib/lmstudio-match'
import type { ModelCategory, AIModel } from '../../types/models'
// One category drives BOTH views (Discover + Installed) — the old split
@@ -402,7 +404,25 @@ export function ModelManager() {
<div className="flex-1 h-px bg-gray-200 dark:bg-white/[0.06]" />
</div>
<div className="space-y-1.5">
- {shown.map((model, i) => (
+ {/* A14: grouped by the backend that serves the row, LU
+ Engine first. Its rows are listed here even while
+ Ollama or LM Studio holds the chat, and using one
+ of them moves the chat backend, so the heading says
+ whose row it is before the click. One group draws
+ no heading: there is nothing to tell apart then. */}
+ {(() => {
+ const providerGroups = groupInstalledByProvider(shown as unknown as InstalledModelLike[])
+ let drawn = 0
+ return providerGroups.map(({ label, models: rows }) => (
+ <div key={label} className="space-y-1.5">
+ {providerGroups.length > 1 && (
+ <p className="px-1 pt-1 text-[0.55rem] font-medium uppercase tracking-widest text-gray-500 dark:text-gray-500">
+ {label}
+ </p>
+ )}
+ {(rows as unknown as AIModel[]).map((model) => {
+ const i = drawn++
+ return (
<motion.div
key={model.name}
initial={{ opacity: 0, y: 4 }}
@@ -423,7 +443,11 @@ export function ModelManager() {
}
/>
</motion.div>
- ))}
+ )
+ })}
+ </div>
+ ))
+ })()}
{shown.length === 0 && (
<p className="text-center text-[0.65rem] text-gray-500 py-6">No installed {modeMeta.label.toLowerCase()} models match "{searchQuery}"</p>
)}
diff --git a/src/components/models/ModelSelector.tsx b/src/components/models/ModelSelector.tsx
index b26fecdd..aff019d8 100644
--- a/src/components/models/ModelSelector.tsx
+++ b/src/components/models/ModelSelector.tsx
@@ -18,6 +18,9 @@ import { lmStudioSlotUpdate, adoptionReplacesBuiltinEngine } from '../../lib/lms
import { nextProbeDelayMs } from '../../lib/probe-backoff'
import { noChatBackendEnabled } from '../../lib/provider-visibility'
import { cloudTeaserModels } from '../../lib/cloud-teaser-models'
+import { splitLuEngineRows, LU_ENGINE_GROUP } from '../../lib/lu-engine-rows'
+import { isBuiltinEngineEntry, type InstalledModelLike } from '../../lib/lmstudio-match'
+import { ensureLuEngineIsChatProvider, LU_ENGINE_SWITCH_NOTE } from '../../api/lu-engine-switch'
import type { AIModel } from '../../types/models'
// ── Local-mode cloud discovery (2.5.8): an "LU Cloud" section at the list's
@@ -542,6 +545,10 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBy
// inline "loading…" state on the row and blocks a second click.
const [selectingLms, setSelectingLms] = useState<string | null>(null)
const [selectError, setSelectError] = useState<string | null>(null)
+ // A14: the one line that says the pick moved the chat backend. Not an error,
+ // so it does not share the red banner: the switch is what the user asked for
+ // by pressing Use, he just has to be told it happened.
+ const [switchNote, setSwitchNote] = useState<string | null>(null)
// VRAM load state for Ollama rows — parity with `lmsLoaded` above, so
// every LOCAL model shows a clear on/off load toggle (not just LM Studio).
// Sourced from /api/ps on dropdown open.
@@ -721,16 +728,25 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBy
return
}
- // Built-in engine rows (ENG-4): swap the GGUF (await) BEFORE activating —
+ // LU Engine rows (ENG-4): swap the GGUF (await) BEFORE activating —
// same contract as the LM Studio path above. A failed llama-server start
// keeps the dropdown open and shows the real reason (Rust appends the
// stderr tail) instead of activating a model that can't answer. Idempotent
// when the model is already loaded (the Rust side compares argv + health).
- if (isManagedBuiltinActive() && getProviderIdFromModel(model.name) === 'openai') {
+ //
+ // A14: the second half of the condition is the case where the LU Engine is
+ // listed but not in front. The rows are visible now on a machine where
+ // Ollama or LM Studio holds the chat, and a row you can see and cannot use
+ // would be worse than the old invisibility, so the pick takes the slot
+ // first and says so.
+ if ((isManagedBuiltinActive() && getProviderIdFromModel(model.name) === 'openai')
+ || isBuiltinEngineEntry(model as unknown as InstalledModelLike)) {
if (selectingLms || togglingLms) return
setSelectError(null)
+ setSwitchNote(null)
setSelectingLms(id)
try {
+ if (ensureLuEngineIsChatProvider()) setSwitchNote(LU_ENGINE_SWITCH_NOTE)
const swapped = await activateBuiltinModel(model.name)
if (swapped) {
// Raw store set — the useModels wrapper would fire a second
@@ -791,6 +807,9 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBy
return () => document.removeEventListener('mousedown', handler)
}, [])
+ // Read reactively, not through isManagedBuiltinActive(): the grouping below
+ // has to redraw the moment a pick hands the slot to the engine.
+ const luEngineHoldsChat = useProviderStore((s) => s.providers.openai.enabled && s.providers.openai.managed === true)
const activeModelObj = models.find((m) => m.name === activeModel)
const activeDisplayName = activeModel
? (activeModelObj && 'displayName' in activeModelObj && activeModelObj.displayName) ||
@@ -811,7 +830,20 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBy
? allTextModels.filter((m) => m.name === activeModel || canUseTools({ name: m.name, supportsTools: m.supportsTools }))
: allTextModels
const hiddenForCode = allTextModels.length - textModels.length
- const groups = groupByFamily(textModels)
+ // A14: while another backend holds the chat, the LU Engine rows are set
+ // apart under their own heading instead of blending into the family groups,
+ // because picking one of them moves the chat backend and a heading is the
+ // cheapest place to say that before the click. While the LU Engine IS the
+ // chat backend nothing is set apart and the picker groups by family exactly
+ // as it always has: there is no consequence to warn about then, and lineage
+ // is what people pick by.
+ const luEngineSplit = luEngineHoldsChat ? { luEngine: [], rest: textModels } : splitLuEngineRows(textModels)
+ const groups: { family: string; models: AIModel[] }[] = [
+ ...(luEngineSplit.luEngine.length > 0
+ ? [{ family: LU_ENGINE_GROUP, models: luEngineSplit.luEngine }]
+ : []),
+ ...groupByFamily(luEngineSplit.rest),
+ ]
const hasOllamaModels = textModels.some(m => ('provider' in m && m.provider === 'ollama') || !('provider' in m))
textModelsEmptyRef.current = textModels.length === 0
@@ -907,6 +939,12 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBy
</div>
)}
+ {switchNote && !selectError && (
+ <div data-testid="lu-engine-switch-note" className="mx-2 mt-2 px-2 py-1.5 rounded bg-white/5 border border-white/10 text-[0.6rem] text-gray-600 dark:text-gray-300 leading-snug">
+ {switchNote}
+ </div>
+ )}
+
{/* Scrollable model list */}
<div className="py-1 max-h-[280px] overflow-y-auto scrollbar-thin">
{textModels.length === 0 && (
diff --git a/src/hooks/__tests__/lu-engine-models-are-listed.test.ts b/src/hooks/__tests__/lu-engine-models-are-listed.test.ts
new file mode 100644
index 00000000..6f312bb8
--- /dev/null
+++ b/src/hooks/__tests__/lu-engine-models-are-listed.test.ts
@@ -0,0 +1,158 @@
+/**
+ * @vitest-environment jsdom
+ *
+ * A14 (2.6.8), David, measured on his Mac: Ollama is the chat backend, the LU
+ * Engine folder is ~/lu-e2e-models and holds Qwen2.5-0.5B-Instruct-Q8_0.gguf,
+ * and the model appears nowhere in the app. Model Storage says in writing that
+ * the folder is read; useModels asked `list_bundled_models` only while the LU
+ * Engine held the chat slot, so the promise was true about the disk and false
+ * about the screen.
+ *
+ * The listing is unconditional now. That opens the two doors this file walks
+ * through as well: the same file can be known twice when the folder points at
+ * ~/.lmstudio/models, and the two resume paths (chat engine, embeddings
+ * server) must keep pointing where they always did.
+ *
+ * Run: npx vitest run src/hooks/__tests__/lu-engine-models-are-listed.test.ts
+ */
+import { describe, it, expect, beforeEach, vi } from 'vitest'
+import { renderHook, act } from '@testing-library/react'
+
+const listBundledModels = vi.fn()
+const resumeStatus = vi.fn(async () => ({ running: true, healthy: true, port: 8127 }))
+const embedStatus = vi.fn(async () => ({ running: true, healthy: true, port: 8128 }))
+let managedBuiltin = false
+let providerRows: Array<{ id: string; listModels: () => Promise<unknown[]> }> = []
+
+vi.mock('../../api/backend', () => ({
+ isTauri: () => true,
+ isMacOS: () => true, // Mac: ComfyUI never auto-starts, so the media lanes stay out of the way
+ isWindows: () => false,
+ isLinux: () => false,
+ backendCall: vi.fn(async () => null),
+}))
+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 () => []),
+ pullModel: vi.fn(),
+ pullModelTauri: vi.fn(),
+ deleteModel: vi.fn(),
+}))
+vi.mock('../../api/providers', async () => {
+ const actual = await vi.importActual<typeof import('../../api/providers')>('../../api/providers')
+ return { ...actual, getEnabledProviders: () => providerRows }
+})
+vi.mock('../../api/engine', async () => {
+ const actual = await vi.importActual<typeof import('../../api/engine')>('../../api/engine')
+ return {
+ ...actual,
+ listBundledModels: (...a: unknown[]) => listBundledModels(...a),
+ isManagedBuiltinActive: () => managedBuiltin,
+ bundledEngineStatus: resumeStatus,
+ bundledEmbedStatus: embedStatus,
+ startBundledEmbed: vi.fn(async () => ({ ok: true })),
+ activateBuiltinModel: vi.fn(async () => true),
+ }
+})
+
+const { useModels } = await import('../useModels')
+const { useModelStore } = await import('../../stores/modelStore')
+const { useProviderStore } = await import('../../stores/providerStore')
+
+const GGUF = { name: 'Qwen2.5-0.5B-Instruct-Q8_0', path: '/Users/d/lu-e2e-models/Qwen2.5-0.5B-Instruct-Q8_0.gguf', size: 531_000_000, loaded: false }
+
+/** An Ollama backend with one model, the shape David's Mac was in. */
+function ollamaHolds(...names: string[]) {
+ providerRows = [{
+ id: 'ollama',
+ listModels: async () => names.map((n) => ({ id: n, provider: 'ollama', providerName: 'Ollama' })),
+ }]
+}
+
+/** LM Studio in the shared openai slot, listing one model over its own API. */
+function lmStudioHolds(...ids: string[]) {
+ providerRows = [{
+ id: 'openai',
+ listModels: async () => ids.map((id) => ({ id, provider: 'openai', providerName: 'LM Studio' })),
+ }]
+}
+
+async function refresh() {
+ const { result } = renderHook(() => useModels())
+ await act(async () => { await result.current.fetchModels() })
+ return useModelStore.getState().models
+}
+
+beforeEach(() => {
+ listBundledModels.mockReset()
+ listBundledModels.mockResolvedValue([GGUF])
+ managedBuiltin = false
+ providerRows = []
+ useModelStore.setState({ models: [] })
+ useProviderStore.getState().setProviderConfig('ollama', { enabled: false })
+})
+
+describe('the GGUF in the LU Engine folder is listed whoever holds the chat', () => {
+ it('shows up while Ollama is the chat backend', async () => {
+ ollamaHolds('llama3.2:3b')
+ const models = await refresh()
+ const row = models.find((m) => m.name === 'openai::Qwen2.5-0.5B-Instruct-Q8_0')
+ expect(row, 'the GGUF David can see on his disk').toBeTruthy()
+ expect((row as { providerName?: string }).providerName).toBe('LU Engine')
+ // The Ollama model it stands beside is untouched.
+ expect(models.some((m) => m.name === 'llama3.2:3b')).toBe(true)
+ })
+
+ it('still shows up while the LU Engine itself holds the chat', async () => {
+ managedBuiltin = true
+ const models = await refresh()
+ expect(models.some((m) => m.name === 'openai::Qwen2.5-0.5B-Instruct-Q8_0')).toBe(true)
+ })
+
+ // NEGATIVE CONTROL: the web and remote-bridge builds have no sidecar and no
+ // route for the command. A throw there must leave the list exactly as it was
+ // and must not take the other backends' rows down with it.
+ it('lists nothing of its own where the command does not exist, and keeps the rest', async () => {
+ ollamaHolds('llama3.2:3b')
+ listBundledModels.mockRejectedValue(new Error('command list_bundled_models not found'))
+ const models = await refresh()
+ expect(models.some((m) => m.providerName === 'LU Engine')).toBe(false)
+ expect(models.some((m) => m.name === 'llama3.2:3b')).toBe(true)
+ })
+})
+
+describe('one file, one row', () => {
+ it('drops the LU Engine row for a GGUF LM Studio already serves', async () => {
+ // The exact collision: the LU Engine folder is set to ~/.lmstudio/models,
+ // so the folder walk finds the same file LM Studio lists over its API.
+ lmStudioHolds('qwen2.5-0.5b-instruct@q8_0')
+ const models = await refresh()
+ const rows = models.filter((m) => m.name.toLowerCase().includes('qwen2.5-0.5b-instruct'))
+ expect(rows.length, 'one model, one row').toBe(1)
+ // Precedence to the backend that is actually serving the chat.
+ expect((rows[0] as { providerName?: string }).providerName).toBe('LM Studio')
+ })
+
+ // NEGATIVE CONTROL: a different quant of the same model is a different file
+ // and a different download. Collapsing those would hide a model the user has.
+ it('keeps both rows when LM Studio serves another quant of the same model', async () => {
+ lmStudioHolds('qwen2.5-0.5b-instruct@q4_k_m')
+ const models = await refresh()
+ expect(models.filter((m) => m.name.toLowerCase().includes('qwen2.5-0.5b-instruct')).length).toBe(2)
+ })
+
+ // NEGATIVE CONTROL: Ollama keeps its own blob store, so an Ollama entry with
+ // a similar name is a SECOND copy of the model, not a second view of one
+ // file. Hiding the GGUF there would hide a real download.
+ it('keeps the GGUF beside a similarly named Ollama model', async () => {
+ ollamaHolds('qwen2.5:0.5b-instruct-q8_0')
+ const models = await refresh()
+ expect(models.some((m) => m.providerName === 'LU Engine')).toBe(true)
+ expect(models.some((m) => m.name === 'qwen2.5:0.5b-instruct-q8_0')).toBe(true)
+ })
+})
diff --git a/src/hooks/__tests__/lu-engine-resume-routing.test.ts b/src/hooks/__tests__/lu-engine-resume-routing.test.ts
new file mode 100644
index 00000000..e9f65f86
--- /dev/null
+++ b/src/hooks/__tests__/lu-engine-resume-routing.test.ts
@@ -0,0 +1,99 @@
+/**
+ * @vitest-environment jsdom
+ *
+ * A14 (2.6.8): `list_bundled_models` is asked unconditionally now, and the two
+ * boot-resume paths hang off that same answer. The chat engine is resumed only
+ * while it holds the slot; the bundled embeddings server is resumed while it
+ * does not, so Document Chat survives a relaunch under LM Studio or Ollama.
+ * Folding the two calls into one made it easy to route both down one branch,
+ * which would either boot a chat engine nothing sends to or take RAG offline
+ * after every restart. So the fork is pinned from both sides.
+ *
+ * `builtinResumeAttempted` is module state, once per app session, so each case
+ * re-imports the hook to start from a fresh app.
+ *
+ * Run: npx vitest run src/hooks/__tests__/lu-engine-resume-routing.test.ts
+ */
+import { describe, it, expect, beforeEach, vi } from 'vitest'
+import { renderHook, act } from '@testing-library/react'
+
+const bundledEngineStatus = vi.fn(async () => ({ running: false, healthy: false, port: 8127 }))
+const bundledEmbedStatus = vi.fn(async () => ({ running: false, healthy: false, port: 8128 }))
+const startBundledEmbed = vi.fn(async () => ({ ok: true }))
+const activateBuiltinModel = vi.fn(async () => true)
+let managedBuiltin = false
+
+const CHAT = { name: 'Qwen2.5-0.5B-Instruct-Q8_0', path: '/m/Qwen2.5-0.5B-Instruct-Q8_0.gguf', size: 1, loaded: false }
+const EMBED = { name: 'nomic-embed-text-v1.5.Q4_K_M', path: '/m/nomic-embed-text-v1.5.Q4_K_M.gguf', size: 1, loaded: false }
+
+vi.mock('../../api/backend', () => ({
+ isTauri: () => true,
+ isMacOS: () => true,
+ isWindows: () => false,
+ isLinux: () => false,
+ backendCall: vi.fn(async () => null),
+}))
+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 () => []),
+ pullModel: vi.fn(),
+ pullModelTauri: vi.fn(),
+ deleteModel: 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 () => [CHAT, EMBED]),
+ isManagedBuiltinActive: () => managedBuiltin,
+ bundledEngineStatus,
+ bundledEmbedStatus,
+ startBundledEmbed,
+ activateBuiltinModel,
+ }
+})
+
+/** One fresh app session. */
+async function bootAndRefresh() {
+ vi.resetModules()
+ const { useModels } = await import('../useModels')
+ const { result } = renderHook(() => useModels())
+ await act(async () => { await result.current.fetchModels() })
+ // The resumes are fired without await on purpose, so the list is not held
+ // hostage by a cold engine start. Let those microtasks land.
+ await act(async () => { await new Promise((r) => setTimeout(r, 0)) })
+}
+
+beforeEach(() => {
+ bundledEngineStatus.mockClear()
+ bundledEmbedStatus.mockClear()
+ startBundledEmbed.mockClear()
+ activateBuiltinModel.mockClear()
+})
+
+describe('the boot resume goes to the right process', () => {
+ it('under a foreign chat backend: the embeddings server, and never the chat engine', async () => {
+ managedBuiltin = false
+ await bootAndRefresh()
+ expect(startBundledEmbed, 'RAG has to survive a relaunch under LM Studio or Ollama').toHaveBeenCalledWith(EMBED.path)
+ // NEGATIVE CONTROL in the same frame: booting the chat engine here would
+ // put a model in memory that no request is routed to.
+ expect(bundledEngineStatus).not.toHaveBeenCalled()
+ })
+
+ it('while the LU Engine holds the chat: both, exactly as before', async () => {
+ managedBuiltin = true
+ await bootAndRefresh()
+ expect(bundledEngineStatus).toHaveBeenCalled()
+ expect(startBundledEmbed).toHaveBeenCalledWith(EMBED.path)
+ })
+})
diff --git a/src/hooks/useModels.ts b/src/hooks/useModels.ts
index c6ca7c46..0b7e2879 100644
--- a/src/hooks/useModels.ts
+++ b/src/hooks/useModels.ts
@@ -15,6 +15,7 @@ import { log } from '../lib/logger'
import { cloudModelRow } from '../lib/cloud-model-row'
import { runEngineResume } from '../lib/engine-resume-policy'
import { engineStartIsWorthRetrying } from '../lib/engine-start-failure'
+import { dropDuplicateLuEngineRows } from '../lib/lu-engine-rows'
import { useModelStore } from '../stores/modelStore'
import { useProviderStore } from '../stores/providerStore'
import { useSettingsStore } from '../stores/settingsStore'
@@ -230,25 +231,34 @@ export function useModels() {
allModels.push(...result.value.filter(m => !isEmbeddingModel(m.name)))
}
}
- // Built-in engine model list (downloaded GGUFs). Guarded: a missing/older
- // backend or non-Tauri dev context just yields no built-in models.
- if (managedBuiltin) {
- try {
- const bundledRaw = await listBundledModels()
- const bundled = bundledToAIModels(bundledRaw)
- allModels.push(...bundled.filter(m => !isEmbeddingModel(m.name)))
- if (!builtinResumeAttempted) {
- builtinResumeAttempted = true
- void resumeBuiltinEngines(bundledRaw)
- }
- } catch { /* engine command unavailable — non-critical */ }
- } else if (!builtinResumeAttempted) {
- // Non-builtin chat backend (LM Studio etc.): still resume the bundled
- // embeddings server when its GGUF exists, so RAG survives a relaunch.
- builtinResumeAttempted = true
- try {
- void resumeEmbedServer(await listBundledModels())
- } catch { /* engine command unavailable — non-critical */ }
+ // 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
+ // backend. It used to be asked only while it was, so on David's Mac with
+ // Ollama in front, the GGUF in his own model folder existed on disk,
+ // Model Storage promised in writing that the folder is read, and the
+ // file appeared nowhere. The command answering at all IS the presence
+ // check for the engine: it is a Tauri command with no bridge route, so
+ // the web and remote-bridge builds, which have no sidecar to start,
+ // still get nothing and are unchanged.
+ let bundledRaw: BundledModel[] | null = null
+ try {
+ bundledRaw = await listBundledModels()
+ } catch { /* engine command unavailable — non-critical */ }
+ if (bundledRaw) {
+ const bundled = bundledToAIModels(bundledRaw).filter(m => !isEmbeddingModel(m.name))
+ // One file, one row: with the folder pointed at ~/.lmstudio/models,
+ // LM Studio lists the model over its own API and the folder walk finds
+ // the same file. The row that is already serving the chat wins.
+ allModels.push(...dropDuplicateLuEngineRows(bundled, allModels))
+ if (!builtinResumeAttempted) {
+ builtinResumeAttempted = true
+ // Unchanged in both directions: the chat engine is only resumed when
+ // it holds the slot, and the embeddings server is resumed when it
+ // does not, so RAG survives a relaunch under a foreign backend.
+ if (managedBuiltin) void resumeBuiltinEngines(bundledRaw)
+ else void resumeEmbedServer(bundledRaw)
+ }
}
const ollamaEnabled = useProviderStore.getState().providers.ollama.enabled
const hasOllamaModels = allModels.some(m => m.provider === 'ollama')
diff --git a/src/lib/__tests__/lu-engine-groups.test.ts b/src/lib/__tests__/lu-engine-groups.test.ts
new file mode 100644
index 00000000..ed5e9623
--- /dev/null
+++ b/src/lib/__tests__/lu-engine-groups.test.ts
@@ -0,0 +1,69 @@
+/**
+ * A14 (2.6.8), David: "Die Modelle erscheinen unter Installed in einer Gruppe
+ * 'LU Engine' (analog zu den Provider-Gruppen)" and the same in the composer's
+ * picker.
+ *
+ * The heading is not decoration. Since the LU Engine's GGUFs are listed even
+ * while Ollama or LM Studio holds the chat, one of those rows is the only kind
+ * of row in the list whose use moves the chat backend, and the user should
+ * read that before he clicks rather than after.
+ *
+ * Run: npx vitest run src/lib/__tests__/lu-engine-groups.test.ts
+ */
+import { describe, it, expect } from 'vitest'
+import { splitLuEngineRows, groupInstalledByProvider, LU_ENGINE_GROUP } from '../lu-engine-rows'
+
+const lu = (n: string) => ({ name: `openai::${n}`, model: n, provider: 'openai', providerName: 'LU Engine' })
+const luOld = (n: string) => ({ name: `openai::${n}`, model: n, provider: 'openai', providerName: 'Built-in Engine' })
+const lms = (n: string) => ({ name: `openai::${n}`, model: n, provider: 'openai', providerName: 'LM Studio' })
+const ollama = (n: string) => ({ name: n, model: n, provider: 'ollama', providerName: 'Ollama' })
+
+describe('splitLuEngineRows', () => {
+ it('separates the engine rows from everything else, order untouched', () => {
+ const { luEngine, rest } = splitLuEngineRows([ollama('a'), lu('b'), lms('c'), lu('d')])
+ expect(luEngine.map((m) => m.model)).toEqual(['b', 'd'])
+ expect(rest.map((m) => m.model)).toEqual(['a', 'c'])
+ })
+
+ it('a row recorded under the old name belongs to the same group', () => {
+ expect(splitLuEngineRows([luOld('b')]).luEngine.length).toBe(1)
+ })
+
+ // NEGATIVE CONTROL: LM Studio shares provider id 'openai' with the engine.
+ // A split that went by provider id would sweep every LM Studio row into the
+ // LU Engine group and offer to switch the backend for models that are
+ // already running on the one in front.
+ it('never takes an LM Studio row along', () => {
+ expect(splitLuEngineRows([lms('c')]).luEngine).toEqual([])
+ })
+})
+
+describe('groupInstalledByProvider', () => {
+ it('puts the LU Engine group first, whatever order the rows arrived in', () => {
+ const groups = groupInstalledByProvider([ollama('a'), lms('c'), lu('b')])
+ expect(groups.map((g) => g.label)).toEqual([LU_ENGINE_GROUP, 'Ollama', 'LM Studio'])
+ expect(groups[0].models.map((m) => m.model)).toEqual(['b'])
+ })
+
+ it('keeps every row: nothing is grouped away', () => {
+ const rows = [ollama('a'), lms('c'), lu('b'), ollama('d')]
+ const groups = groupInstalledByProvider(rows)
+ expect(groups.flatMap((g) => g.models).length).toBe(rows.length)
+ })
+
+ // NEGATIVE CONTROL: a single backend is not a grouping problem. One group is
+ // what the render reads to draw no heading at all, so the Installed list of
+ // a plain Ollama box looks exactly as it did before.
+ it('answers with one group when one backend serves everything', () => {
+ const groups = groupInstalledByProvider([ollama('a'), ollama('d')])
+ expect(groups.length).toBe(1)
+ expect(groups[0].label).toBe('Ollama')
+ })
+
+ // NEGATIVE CONTROL: a row with no provider name is still a model the user
+ // has. It gets a heading rather than an empty one, and is never dropped.
+ it('gives a nameless row a heading instead of losing it', () => {
+ const groups = groupInstalledByProvider([{ name: 'x', model: 'x', provider: 'ollama' }])
+ expect(groups.map((g) => g.label)).toEqual(['Other'])
+ })
+})
diff --git a/src/lib/lu-engine-rows.ts b/src/lib/lu-engine-rows.ts
new file mode 100644
index 00000000..ead118c1
--- /dev/null
+++ b/src/lib/lu-engine-rows.ts
@@ -0,0 +1,103 @@
+/**
+ * The GGUFs in the LU Engine folder as rows in the model list.
+ *
+ * A14 (2.6.8), David, seen on a Mac with Ollama as the chat backend and
+ * ~/lu-e2e-models holding Qwen2.5-0.5B-Instruct-Q8_0.gguf: Model Storage
+ * promises "LU downloads GGUFs here and reads every .gguf in it", and the file
+ * never appeared anywhere. `useModels` asked `list_bundled_models` only while
+ * the LU Engine was the active provider, so on that machine the promise was
+ * true about the disk and false about the screen.
+ *
+ * The listing is unconditional now, which raises two questions this module
+ * answers, both without a browser:
+ *
+ * 1. the same file can be known twice. Set the LU Engine folder to
+ * ~/.lmstudio/models and LM Studio lists the model over its own API while
+ * the folder walk finds the file. One model, two rows, two different ways
+ * to run it, and no way for the user to tell which is which.
+ * 2. picking an LU Engine row while another backend holds the chat has a
+ * consequence, so those rows are set apart under their own heading instead
+ * of blending into the list.
+ */
+
+import { matchesLmStudioInstalled, isBuiltinEngineEntry, type InstalledModelLike } from './lmstudio-match'
+
+/** The heading LU Engine rows sit under, in Installed and in the picker. */
+export const LU_ENGINE_GROUP = 'LU Engine'
+
+/**
+ * LU Engine rows the active provider already lists, removed.
+ *
+ * Precedence goes to the provider that is actually serving the chat, for the
+ * plain reason that its row is the one that works right now: picking it starts
+ * nothing and switches nothing. The LU Engine row for the same file would take
+ * the chat away from the active backend to reach a model the user can already
+ * have, which is a trade nobody asked for.
+ *
+ * Only LM Studio can collide. Ollama keeps its models in its own blob store
+ * under its own names, so an Ollama row and a GGUF on disk are two copies of
+ * the model and not two views of one file, and collapsing them would hide a
+ * real second copy.
+ */
+export function dropDuplicateLuEngineRows<T extends InstalledModelLike>(
+ bundled: T[],
+ alreadyListed: InstalledModelLike[],
+): T[] {
+ if (bundled.length === 0 || alreadyListed.length === 0) return bundled
+ return bundled.filter((row) => {
+ const stem = row.model || row.name || ''
+ if (!stem) return true
+ // The matcher speaks GGUF filenames and the bundled row carries the file
+ // stem, so the extension goes back on. It requires the quant to agree
+ // whenever the filename names one, which is what keeps two quants of the
+ // same model from collapsing into each other.
+ return !matchesLmStudioInstalled(`${stem}.gguf`, alreadyListed)
+ })
+}
+
+/**
+ * The LU Engine rows and everything else, kept apart.
+ *
+ * Order within each half is left exactly as it came in: the list is built in a
+ * deliberate order upstream and this is a split, not a sort.
+ */
+export function splitLuEngineRows<T extends InstalledModelLike>(models: T[]): { luEngine: T[]; rest: T[] } {
+ const luEngine: T[] = []
+ const rest: T[] = []
+ for (const m of models) (isBuiltinEngineEntry(m) ? luEngine : rest).push(m)
+ return { luEngine, rest }
+}
+
+/** One heading and the rows under it. */
+export interface ProviderGroup<T> {
+ label: string
+ models: T[]
+}
+
+/**
+ * Installed rows grouped by the backend that serves them, LU Engine first.
+ *
+ * First because it is the group whose rows carry a consequence: on a machine
+ * where another backend holds the chat, using one of them moves the chat. A
+ * heading the user reads before he clicks is the cheapest way to say that.
+ *
+ * Everything else keeps the order it arrived in. A row with no provider name
+ * at all lands under "Other", which is better than an empty heading and better
+ * than dropping the row.
+ */
+export function groupInstalledByProvider<T extends InstalledModelLike>(models: T[]): ProviderGroup<T>[] {
+ const groups = new Map<string, T[]>()
+ for (const m of models) {
+ const label = isBuiltinEngineEntry(m) ? LU_ENGINE_GROUP : (m.providerName || '').trim() || 'Other'
+ const bucket = groups.get(label)
+ if (bucket) bucket.push(m)
+ else groups.set(label, [m])
+ }
+ const out: ProviderGroup<T>[] = []
+ const lu = groups.get(LU_ENGINE_GROUP)
+ if (lu) out.push({ label: LU_ENGINE_GROUP, models: lu })
+ for (const [label, rows] of groups) {
+ if (label !== LU_ENGINE_GROUP) out.push({ label, models: rows })
+ }
+ return out
+}