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): die Installed-Kachel bekommt den Use-Knopf, den die Notes versprechen

purpled77e5b82d31c
diff --git a/src/components/models/ModelCard.tsx b/src/components/models/ModelCard.tsx
index d5aa3bc1..a188d6be 100644
--- a/src/components/models/ModelCard.tsx
+++ b/src/components/models/ModelCard.tsx
@@ -1,4 +1,4 @@
-import { Trash2, Info, MessageSquare, Image, Video } from 'lucide-react'
+import { Trash2, Info, MessageSquare, Image, Video, Loader2 } from 'lucide-react'
import { formatBytes } from '../../lib/formatters'
import { BenchmarkButton } from './ModelBenchmark'
import type { AIModel } from '../../types/models'
@@ -10,6 +10,21 @@ interface Props {
onDelete: () => void
onInfo: () => void
canDelete?: boolean
+ /**
+ * A16 (A14-4a): the Use button the 2.6.8 notes promise twice on this tile.
+ *
+ * The Windows counter-check found only Bench and Details here. The tile
+ * itself was the switch, which works and is invisible: nothing on the row
+ * said that clicking it would move the chat backend and load the model, so
+ * the counter-check read the notes as broken and the button as missing.
+ *
+ * Passed only for rows where the word means something, an LU Engine row that
+ * is not already the active one, and it goes through `onSelect`, the same
+ * path the tile click takes.
+ */
+ onUse?: () => void
+ /** While that swap runs. The engine can take seconds to load a cold GGUF. */
+ useBusy?: boolean
}
const TYPE_CONFIG = {
@@ -18,7 +33,7 @@ const TYPE_CONFIG = {
video: { label: 'Video', icon: Video, color: 'text-green-400' },
}
-export function ModelCard({ model, isActive, onSelect, onDelete, onInfo, canDelete = true }: Props) {
+export function ModelCard({ model, isActive, onSelect, onDelete, onInfo, canDelete = true, onUse, useBusy = false }: Props) {
const typeInfo = TYPE_CONFIG[model.type] || TYPE_CONFIG.text
const TypeIcon = typeInfo.icon
@@ -55,6 +70,22 @@ export function ModelCard({ model, isActive, onSelect, onDelete, onInfo, canDele
{/* Actions — always visible (LM-Studio: no hover-to-reveal) */}
<div className="flex items-center gap-0.5 shrink-0">
+ {/* The pick marks the row Active at once, while the engine is still
+ loading the GGUF, so the button stays for as long as its own swap
+ runs. Dropping it there would take the Loading state off screen at
+ the exact moment it is the answer to "did that work". */}
+ {onUse && (!isActive || useBusy) && (
+ <button
+ onClick={(e) => { e.stopPropagation(); if (!useBusy) onUse() }}
+ disabled={useBusy}
+ data-testid="model-card-use"
+ className="px-2 py-0.5 mr-1 rounded text-[0.58rem] font-medium bg-gray-100 dark:bg-white/10 text-gray-700 dark:text-gray-200 hover:bg-gray-200 dark:hover:bg-white/15 border border-gray-200 dark:border-white/10 transition-colors disabled:opacity-60 disabled:cursor-default inline-flex items-center gap-1"
+ title="Load this model on the LU Engine and use it for chat"
+ >
+ {useBusy && <Loader2 size={9} className="animate-spin" />}
+ {useBusy ? 'Loading…' : 'Use'}
+ </button>
+ )}
{model.type === 'text' && (
<div onClick={(e) => e.stopPropagation()}>
<BenchmarkButton modelName={model.name} />
diff --git a/src/components/models/ModelManager.tsx b/src/components/models/ModelManager.tsx
index 6fd1390a..0cede15f 100644
--- a/src/components/models/ModelManager.tsx
+++ b/src/components/models/ModelManager.tsx
@@ -22,6 +22,7 @@ import { backendCall } from '../../api/backend'
import { customModelDirs } from '../../api/engine'
import { counterView } from '../../lib/inventory-counter'
import { groupInstalledByProvider, needsLuEngineHeading } from '../../lib/lu-engine-rows'
+import { isBuiltinEngineEntry } from '../../lib/lmstudio-match'
import { LuEngineSwitchBar } from '../chat/LuEngineSwitchBar'
import type { InstalledModelLike } from '../../lib/lmstudio-match'
import type { ModelCategory, AIModel } from '../../types/models'
@@ -64,6 +65,10 @@ export function ModelManager() {
// A14: whether the LU Engine itself is serving the chat. Decides whether its
// group needs a heading even when it is the only group (review 7).
const luEngineHoldsChat = useProviderStore(s => s.providers.openai.enabled && s.providers.openai.managed === true)
+ // A16 (A14-4a): which row's Use button is mid swap. The engine has to stop,
+ // reload a GGUF that can be several gigabytes and come back healthy, and a
+ // button that looks idle through all of that gets pressed again.
+ const [usingModel, setUsingModel] = useState<string | null>(null)
const [pullOpen, setPullOpen] = useState(false)
const [infoOpen, setInfoOpen] = useState(false)
const [modelInfo, setModelInfo] = useState<any>(null)
@@ -445,7 +450,20 @@ export function ModelManager() {
<ModelCard
model={model}
isActive={model.name === activeModel}
- onSelect={() => setActiveModel(model.name)}
+ onSelect={() => { void setActiveModel(model.name) }}
+ // The Use button the 2.6.8 notes promise on this
+ // tile. Only where the word means anything: an
+ // LU Engine row that is not already active. It
+ // fires the same call the tile click does.
+ onUse={
+ isBuiltinEngineEntry(model as unknown as InstalledModelLike)
+ ? async () => {
+ setUsingModel(model.name)
+ try { await setActiveModel(model.name) } finally { setUsingModel(null) }
+ }
+ : undefined
+ }
+ useBusy={usingModel === model.name}
onDelete={() => setConfirmDelete(model.name)}
onInfo={() => handleInfo(model.name)}
canDelete={
diff --git a/src/components/models/__tests__/installed-tile-has-a-use-button.test.ts b/src/components/models/__tests__/installed-tile-has-a-use-button.test.ts
new file mode 100644
index 00000000..1a10e9b8
--- /dev/null
+++ b/src/components/models/__tests__/installed-tile-has-a-use-button.test.ts
@@ -0,0 +1,170 @@
+/**
+ * @vitest-environment jsdom
+ *
+ * A16 (A14-4a), Windows counter-check 02.09.: the 2.6.8 release notes promise
+ * a Use button on the Installed tile twice ("stays visible as Installed with a
+ * Use button that starts the engine for it", "its tile carries a Use button
+ * that starts the engine and loads that model"). On the real build the tile
+ * carried Bench and Details and nothing else. The tile itself was the switch,
+ * which works and says nothing about itself, so the counter-check filed the
+ * button as missing and was right to.
+ *
+ * The button is here now, on LU Engine rows that are not already active, and
+ * it takes exactly the path the tile click takes (`activateModel` in
+ * useModels, behind the shared bolt in api/lu-engine-swap-lock).
+ *
+ * Run: npx vitest run src/components/models/__tests__/installed-tile-has-a-use-button.test.ts
+ */
+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
+import { createElement } from 'react'
+import { render, screen, cleanup, act, fireEvent } from '@testing-library/react'
+
+const activateBuiltinModel = vi.fn(async () => true)
+
+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', async () => {
+ const actual = await vi.importActual<typeof import('../../../api/comfyui')>('../../../api/comfyui')
+ return {
+ ...actual,
+ getInstalledImageModels: vi.fn(async () => []),
+ getInstalledVideoModels: vi.fn(async () => []),
+ checkComfyConnection: vi.fn(async () => false),
+ refreshComfyModels: vi.fn(async () => undefined),
+ readModelDiskSizes: vi.fn(async () => new Map()),
+ getSystemVRAM: vi.fn(async () => 0),
+ }
+})
+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(async () => ({})),
+}))
+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 () => []),
+ customModelDirs: 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 [])),
+ }
+})
+
+const { ModelManager } = await import('../ModelManager')
+const { useModelStore } = await import('../../../stores/modelStore')
+const { useProviderStore } = await import('../../../stores/providerStore')
+const { __resetLuEngineSwapLockForTests } = await import('../../../api/lu-engine-swap-lock')
+
+const ACTIVE = 'openai::Phi-4-mini-instruct-Q4_K_M'
+const OTHER = 'openai::mlabonne_gemma-3-4b-it-abliterated-Q4_K_M'
+const OLLAMA = 'llama3.2:3b'
+
+function installedList() {
+ return [
+ { name: ACTIVE, model: 'Phi-4-mini-instruct-Q4_K_M', size: 1, type: 'text', provider: 'openai', providerName: 'LU Engine' },
+ { name: OTHER, model: 'mlabonne_gemma-3-4b-it-abliterated-Q4_K_M', size: 1, type: 'text', provider: 'openai', providerName: 'LU Engine' },
+ { name: OLLAMA, model: OLLAMA, size: 1, type: 'text', provider: 'ollama', providerName: 'Ollama' },
+ ] as never
+}
+
+/** The Installed tab of the Models page, as the counter-check had it open. */
+async function openInstalled() {
+ render(createElement(ModelManager))
+ await act(async () => { await Promise.resolve(); await Promise.resolve() })
+ fireEvent.click(screen.getByText('Installed'))
+ await act(async () => { for (let i = 0; i < 20; i++) await Promise.resolve() })
+ // The hook's own fetch answers with the mocked backends (nothing), so the
+ // rows are put in afterwards, which is also what a refresh does.
+ await act(async () => {
+ useModelStore.setState({ models: installedList(), activeModel: ACTIVE })
+ await Promise.resolve()
+ })
+}
+
+/** The Use button on the row for `name`, or null when the row has none. */
+function useButtonFor(name: string): HTMLElement | null {
+ const row = screen.getByText(name).closest('div[class*="rounded-lg"]')
+ return row?.querySelector('[data-testid="model-card-use"]') as HTMLElement | null
+}
+
+beforeEach(() => {
+ activateBuiltinModel.mockReset()
+ activateBuiltinModel.mockResolvedValue(true)
+ __resetLuEngineSwapLockForTests()
+ useProviderStore.getState().resetProvidersToDefaults()
+ useProviderStore.getState().setProviderConfig('openai', {
+ enabled: true, managed: true, name: 'LU Engine', baseUrl: 'http://127.0.0.1:8127/v1',
+ })
+ useModelStore.setState({ models: installedList(), activeModel: ACTIVE, categoryFilter: 'text' })
+})
+afterEach(() => { cleanup(); __resetLuEngineSwapLockForTests() })
+
+describe('the Use button the 2.6.8 notes promise on the Installed tile', () => {
+ it('is on every LU Engine row that is not the active one', async () => {
+ await openInstalled()
+ expect(useButtonFor(OTHER), 'the notes promise this button twice').not.toBeNull()
+ expect(useButtonFor(OTHER)!.textContent).toContain('Use')
+ })
+
+ it('starts the engine on that model, the same way the tile click does', async () => {
+ await openInstalled()
+ await act(async () => { fireEvent.click(useButtonFor(OTHER)!) })
+ expect(activateBuiltinModel).toHaveBeenCalledWith(OTHER)
+ expect(useModelStore.getState().activeModel).toBe(OTHER)
+ })
+
+ it('says Loading while the swap runs and stops saying it afterwards', async () => {
+ let release: (v: boolean) => void = () => {}
+ activateBuiltinModel.mockImplementation(() => new Promise<boolean>((r) => { release = r }))
+ await openInstalled()
+ await act(async () => { fireEvent.click(useButtonFor(OTHER)!) })
+
+ // The row is the active one now, so the busy state is read off the button
+ // the click left behind rather than off a fresh lookup.
+ expect(document.body.textContent, 'a cold GGUF takes seconds and the button looked idle').toContain('Loading…')
+
+ await act(async () => { release(true); await Promise.resolve(); await Promise.resolve() })
+ expect(document.body.textContent).not.toContain('Loading…')
+ })
+
+ // NEGATIVE CONTROL: the active row says Active and offers nothing to press.
+ it('is absent on the model that is already active', async () => {
+ await openInstalled()
+ expect(useButtonFor(ACTIVE), 'Use on the model already in use is noise').toBeNull()
+ expect(document.body.textContent).toContain('Active')
+ })
+
+ // NEGATIVE CONTROL: an Ollama row is served by another backend. A Use button
+ // there would promise something the LU Engine cannot do for that row.
+ it('is absent on a row that is not ours', async () => {
+ await openInstalled()
+ expect(useButtonFor(OLLAMA)).toBeNull()
+ })
+
+ // NEGATIVE CONTROL: the button is a door into the same house, so it obeys
+ // the shared bolt. A press while another swap is running must not send a
+ // second swap_bundled_model at one llama-server.
+ it('is blocked by the shared swap bolt like every other door', async () => {
+ const { tryAcquireLuEngineSwap } = await import('../../../api/lu-engine-swap-lock')
+ await openInstalled()
+ expect(tryAcquireLuEngineSwap(), 'someone else is mid swap').toBe(true)
+ await act(async () => { fireEvent.click(useButtonFor(OTHER)!) })
+ expect(activateBuiltinModel).not.toHaveBeenCalled()
+ })
+})
diff --git a/src/hooks/useModels.ts b/src/hooks/useModels.ts
index 8121d565..7185311c 100644
--- a/src/hooks/useModels.ts
+++ b/src/hooks/useModels.ts
@@ -507,7 +507,11 @@ export function useModels() {
// then started nothing and switched nothing. The user was left on a model
// that answered from nowhere. Same route as the picker and the Use button
// now: hand the slot over, say so, then start.
- const activateModel = useCallback((name: string) => {
+ // A16: the answer is a promise now, so the caller can draw a Loading state
+ // for as long as the swap really runs. It resolves when the engine is up or
+ // has failed, and immediately on the paths that start nothing (a blocked
+ // click, a row that is not ours).
+ const activateModel = useCallback((name: string): Promise<void> => {
const row = useModelStore.getState().models.find((m) => m.name === name)
const isLuRow = isBuiltinEngineEntry(row as unknown as InstalledModelLike | undefined)
// Did THIS click move the chat backend. A failure afterwards has to keep
@@ -530,7 +534,7 @@ export function useModels() {
// dead button and gets clicked again.
if (!tryAcquireLuEngineSwap()) {
useLuEngineSwitchStore.getState().announce(LU_ENGINE_SWAP_BUSY_NOTE)
- return
+ return Promise.resolve()
}
switched = ensureLuEngineIsChatProvider()
if (switched) useLuEngineSwitchStore.getState().announce(LU_ENGINE_SWITCH_NOTE)
@@ -549,7 +553,7 @@ export function useModels() {
useLuEngineSwitchStore.getState()
.announce(switched ? `${LU_ENGINE_SWITCH_NOTE} ${line}` : line, 'error')
}
- void activateBuiltinModel(name)
+ return activateBuiltinModel(name)
// False is not a shrug: the path could not be resolved even after a
// refresh, so the row stands for a file that is no longer there.
.then((swapped) => { if (!swapped && isLuRow) sayItFailed(LU_ENGINE_FILE_GONE) })
@@ -557,7 +561,8 @@ export function useModels() {
// has nothing to say about it. Unchanged, non-critical.
.catch((e) => { if (isLuRow) sayItFailed(e) })
.finally(() => { if (isLuRow) releaseLuEngineSwap() })
- } else if (isLuRow) {
+ }
+ if (isLuRow) {
// Nothing was started, so nothing will release the bolt in a finally.
// Unreachable today (an LU row that got this far has just been given the
// slot by ensureLuEngineIsChatProvider, and its name carries the openai
@@ -565,6 +570,7 @@ export function useModels() {
// costs the user his card until the 60 s limit runs out.
releaseLuEngineSwap()
}
+ return Promise.resolve()
}, [setActiveModel])
return {