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
fix(picker): die abgeschaltete Zeile sagt jetzt, worauf sie wartet
purple50584e3d9e29
diff --git a/src/components/models/ModelSelector.tsx b/src/components/models/ModelSelector.tsxindex a87ebcba..90a06673 100644--- a/src/components/models/ModelSelector.tsx+++ b/src/components/models/ModelSelector.tsx@@ -451,6 +451,34 @@ export function toolBadgeTitle(model: AIModel, support: ToolSupport = 'native'):return how}+/**+ * Which wait a click on a switched-off picker row ran into, or null.+ *+ * A17 (Windows counter-check 03.09.): while a pick is in flight every row in+ * the list carries `aria-disabled`, and the row's onClick read+ * `if (!rowDisabled) void handleSelectModel(model)`. Both busy sentences live+ * inside `handleSelectModel`, so the door that would have said them was the+ * door that never opened: two clicks 150 ms apart, fourteen and eighteen+ * seconds of watching, and not a word on screen. The card path (Models >+ * Installed) says its line because its buttons are not switched off.+ *+ * So the disabled row answers too, and it answers with the SAME split+ * `handleSelectModel` makes: the bolt is the only thing that knows whether the+ * engine is swapping, and the picker's own in-flight state without the bolt is+ * LM Studio warming a model of its own.+ *+ * `pickInFlight` is exactly the reason this picker switches rows off. A row+ * that is dead for any other reason (nothing running, some future rule) is not+ * a wait, and gets silence rather than a sentence about a wait nobody is in.+ */+export function blockedPickWait(+ pickInFlight: boolean,+ luEngineSwapRunning: boolean,+): 'lu-engine' | 'lm-studio' | null {+ if (!pickInFlight) return null+ return luEngineSwapRunning ? 'lu-engine' : 'lm-studio'+}+export function lmsAutoLoadContext(model: AIModel): number {const max ='contextLength' in model && typeof model.contextLength === 'number' && model.contextLength > 0@@ -823,6 +851,25 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBysetOpen(false)}+ /**+ * The answer a click on a switched-off row gets (A17).+ *+ * Not a queued pick: the click is still refused, it just stops being silent.+ * `blockedPickWait` decides whether there is anything to say at all, so a row+ * switched off for some other reason keeps its silence.+ */+ const announceBlockedPick = (pickInFlight: boolean) => {+ const wait = blockedPickWait(pickInFlight, luEngineSwapInFlight())+ if (wait === null) return+ if (wait === 'lm-studio') {+ announceLmStudioLoadBusy()+ setSelectError(LM_STUDIO_LOAD_BUSY_NOTE)+ return+ }+ announceLuEngineSwapBusy()+ setSelectError(LU_ENGINE_SWAP_BUSY_NOTE)+ }+useEffect(() => { fetchModels() }, [fetchModels])// GH #118: an empty picker used to say "No models available" no matter what@@ -1056,7 +1103,12 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBy// a <button>. A <button> can't nest a <button> (invalid HTML →// React hydration error + flaky clicks), so the row is a// role="button" <div> with explicit keyboard activation.- const rowDisabled = selectingLms !== null || togglingLms !== null+ // The one reason this picker switches rows off: a pick is+ // already running. Kept as its own name because the click+ // below hands exactly this to `blockedPickWait`, which is+ // what keeps any future second reason silent (A17).+ const pickInFlight = selectingLms !== null || togglingLms !== null+ const rowDisabled = pickInFlightreturn (<div@@ -1064,9 +1116,23 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredByrole="button"tabIndex={rowDisabled ? -1 : 0}aria-disabled={rowDisabled}- onClick={() => { if (!rowDisabled) void handleSelectModel(model) }}+ onClick={() => {+ // A17: the switched-off row used to swallow the+ // click whole, and both busy sentences sit behind+ // this door in `handleSelectModel`, so nothing was+ // ever said. It says the wait now and still does not+ // pick.+ if (rowDisabled) { announceBlockedPick(pickInFlight); return }+ void handleSelectModel(model)+ }}onKeyDown={(e) => {- if (rowDisabled) return+ if (rowDisabled) {+ if (e.key === 'Enter' || e.key === ' ') {+ e.preventDefault()+ announceBlockedPick(pickInFlight)+ }+ return+ }if (e.key === 'Enter' || e.key === ' ') {e.preventDefault()void handleSelectModel(model)diff --git a/src/components/models/__tests__/a-switched-off-row-still-names-the-wait.test.ts b/src/components/models/__tests__/a-switched-off-row-still-names-the-wait.test.tsnew file mode 100644index 00000000..f633d335--- /dev/null+++ b/src/components/models/__tests__/a-switched-off-row-still-names-the-wait.test.ts@@ -0,0 +1,157 @@+/**+ * @vitest-environment jsdom+ *+ * A17 (Windows counter-check 03.09.), the second durchfaller: "Der Picker sagt+ * nichts, wenn LM Studio gerade laedt."+ *+ * Click an LM Studio row, click a second row 150 ms later, and watch for+ * eighteen seconds. Nothing appears. The markup says why: while a pick is in+ * flight every row carries `role="button" tabindex="-1" aria-disabled="true"`,+ * and the row's click read+ *+ * onClick={() => { if (!rowDisabled) void handleSelectModel(model) }}+ *+ * Both busy sentences live INSIDE `handleSelectModel`, so they sat behind the+ * one door that cannot open while the condition that would say them is true.+ *+ * This file mounts the real picker rather than reading its source, because the+ * bug was never in what the source says: `announceLmStudioLoadBusy()` was+ * there, spelled correctly, unreachable. Only a click on a rendered row can+ * tell those two apart.+ *+ * Run: npx vitest run src/components/models/__tests__/a-switched-off-row-still-names-the-wait.test.ts+ */+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'+import { createElement } from 'react'+import { render, screen, fireEvent, cleanup, act } from '@testing-library/react'+import type { AIModel } from '../../../types/models'++// The picker's own list hook reaches for Tauri on mount. The models are the+// fixture below; nothing else about the hook is under test here.+const setActiveModel = vi.fn()+vi.mock('../../../hooks/useModels', () => ({+ useModels: () => ({+ models: MODELS,+ activeModel: 'openai::model-a',+ setActiveModel,+ fetchModels: vi.fn(),+ }),+}))++// The load that never finishes. This is the whole point: `selectingLms` stays+// set, so every row is switched off for as long as the test needs.+let releaseLoad: (() => void) | null = null+const loadLmStudioModel = vi.fn(() => new Promise<void>((resolve) => { releaseLoad = () => resolve() }))+vi.mock('../../../api/lmstudio', () => ({+ loadLmStudioModel: (...a: unknown[]) => loadLmStudioModel(...(a as [])),+ unloadLmStudioModel: vi.fn(async () => {}),+ listLoadedLmStudioModels: vi.fn(async () => [] as string[]),+}))+vi.mock('../../../api/ollama', () => ({+ listRunningModels: vi.fn(async () => [] as string[]),+ loadModel: vi.fn(async () => {}),+ unloadModel: vi.fn(async () => {}),+ unloadAllModels: vi.fn(async () => {}),+}))+vi.mock('../../../api/backend', () => ({ backendCall: vi.fn(async () => null) }))+vi.mock('../../../api/builtin-ensure', () => ({ diagnoseBuiltinEngine: vi.fn(async () => null) }))++const lmsModel = (name: string): AIModel => ({+ name, model: name, size: 0, type: 'text',+ provider: 'openai', providerName: 'LM Studio',+} as AIModel)++const MODELS: AIModel[] = [lmsModel('openai::model-a'), lmsModel('openai::model-b')]++const { ModelSelector } = await import('../ModelSelector')+const { useLuEngineSwitchStore } = await import('../../../stores/luEngineSwitchStore')+const { useModelStore } = await import('../../../stores/modelStore')+const { LM_STUDIO_LOAD_BUSY_NOTE, LU_ENGINE_SWAP_BUSY_NOTE } = await import('../../../api/lu-engine-switch')+const { __resetLuEngineSwapLockForTests, tryAcquireLuEngineSwap } = await import('../../../api/lu-engine-swap-lock')++function note() { return useLuEngineSwitchStore.getState().note }++/** Open the picker and hand back its rows, in list order. */+function openPicker(): HTMLElement[] {+ render(createElement(ModelSelector))+ fireEvent.click(screen.getByLabelText('Select chat model'))+ return screen.getAllByRole('button').filter((el) => el.getAttribute('aria-disabled') !== null)+}++beforeEach(() => {+ useLuEngineSwitchStore.setState({ note: null, tone: 'info', generation: 0 })+ useModelStore.setState({ models: MODELS })+ __resetLuEngineSwapLockForTests()+ releaseLoad = null+ loadLmStudioModel.mockClear()+})+afterEach(() => {+ cleanup()+ releaseLoad?.()+ useLuEngineSwitchStore.getState().dismiss()+ __resetLuEngineSwapLockForTests()+})++describe('a row that is switched off because a pick is running', () => {+ it('names the LM Studio wait when the second click lands', async () => {+ const rows = openPicker()+ expect(rows.length, 'both rows are on screen').toBe(2)++ // First click: LM Studio starts warming a model and never finishes.+ await act(async () => { fireEvent.click(rows[0]) })+ expect(loadLmStudioModel).toHaveBeenCalledTimes(1)+ expect(rows[1].getAttribute('aria-disabled'), 'the list is switched off').toBe('true')+ expect(note(), 'nothing is said until the second click').toBeNull()++ // Second click, on the switched-off row. This is the click that used to+ // disappear without a word.+ await act(async () => { fireEvent.click(rows[1]) })+ expect(note()).toBe(LM_STUDIO_LOAD_BUSY_NOTE)+ expect(note()).toBe('LM Studio is still loading a model, one moment.')+ // And it stayed a refusal: no second load went out.+ expect(loadLmStudioModel, 'the blocked click queued a pick').toHaveBeenCalledTimes(1)+ expect(setActiveModel, 'the blocked click activated a model').not.toHaveBeenCalled()+ })++ it('names the LU Engine wait instead while a swap of ours is running', async () => {+ const rows = openPicker()+ await act(async () => { fireEvent.click(rows[0]) })+ // The bolt is the only thing that can tell an LM Studio load from a swap+ // of our own engine, exactly as the open door decides it.+ tryAcquireLuEngineSwap()+ await act(async () => { fireEvent.click(rows[1]) })+ expect(note()).toBe(LU_ENGINE_SWAP_BUSY_NOTE)+ })++ it('answers a keyboard activation of the switched-off row too', async () => {+ const rows = openPicker()+ await act(async () => { fireEvent.click(rows[0]) })+ await act(async () => { fireEvent.keyDown(rows[1], { key: 'Enter' }) })+ expect(note()).toBe(LM_STUDIO_LOAD_BUSY_NOTE)+ expect(loadLmStudioModel).toHaveBeenCalledTimes(1)+ })++ // NEGATIVE CONTROL: with nothing running there is no wait, so there is+ // nothing to say. A click on a live row picks, in silence, as it always did.+ it('says nothing when no pick is in flight', async () => {+ const rows = openPicker()+ expect(rows[0].getAttribute('aria-disabled')).toBe('false')+ expect(note()).toBeNull()+ })+})++describe('blockedPickWait, the rule the row asks', () => {+ it('is silent unless a pick is actually in flight', async () => {+ const { blockedPickWait } = await import('../ModelSelector')+ expect(blockedPickWait(false, false), 'a dead row invented a wait').toBeNull()+ // A row switched off for some other reason while our engine happens to be+ // swapping elsewhere is still not a row anyone is waiting on.+ expect(blockedPickWait(false, true)).toBeNull()+ })++ it('lets the bolt pick which of the two waits it is', async () => {+ const { blockedPickWait } = await import('../ModelSelector')+ expect(blockedPickWait(true, false)).toBe('lm-studio')+ expect(blockedPickWait(true, true)).toBe('lu-engine')+ })+})