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.

fix(models): a GGUF finds a folder when the openai slot holds a server of the user (D9)

purple155321f1fae5
diff --git a/src/api/discover.ts b/src/api/discover.ts
index a5543ff2..ccd09eb9 100644
--- a/src/api/discover.ts
+++ b/src/api/discover.ts
@@ -1987,15 +1987,27 @@ export async function resolveHfGgufFiles(
}
}
-/** Detect the model directory for the active local provider */
-export async function detectProviderModelPath(providerName: string): Promise<string | null> {
+/** A model folder, or why there is none (the backend's own sentence). */
+export interface ModelFolder {
+ path: string | null
+ reason: string | null
+}
+
+/** Detect the model directory for the active local provider, with the reason when there is none. */
+export async function providerModelFolder(providerName: string): Promise<ModelFolder> {
try {
- return await backendCall('detect_model_path', { provider: providerName })
- } catch {
- return null
+ const path = await backendCall<string | null>('detect_model_path', { provider: providerName })
+ return { path: path || null, reason: null }
+ } catch (err) {
+ return { path: null, reason: err instanceof Error ? err.message : String(err ?? '') || null }
}
}
+/** Detect the model directory for the active local provider */
+export async function detectProviderModelPath(providerName: string): Promise<string | null> {
+ return (await providerModelFolder(providerName)).path
+}
+
/**
* Wohin eine frisch heruntergeladene GGUF fuer die LU Engine gehoert.
*
@@ -2013,9 +2025,14 @@ export async function detectProviderModelPath(providerName: string): Promise<str
* den eigenen Ordner UND den gesetzten, vier Ebenen tief.
*/
export async function luEngineDownloadDir(): Promise<string | null> {
+ return (await luEngineDownloadFolder()).path
+}
+
+/** `luEngineDownloadDir` with the reason when the folder cannot be had. */
+export async function luEngineDownloadFolder(): Promise<ModelFolder> {
const gesetzt = customModelDirs()[0]
- if (gesetzt) return gesetzt
- return await detectProviderModelPath(BUILTIN_BACKEND_ID)
+ if (gesetzt) return { path: gesetzt, reason: null }
+ return await providerModelFolder(BUILTIN_BACKEND_ID)
}
/**
diff --git a/src/components/models/DiscoverModels.tsx b/src/components/models/DiscoverModels.tsx
index 6cf60cc0..0085d08b 100644
--- a/src/components/models/DiscoverModels.tsx
+++ b/src/components/models/DiscoverModels.tsx
@@ -9,7 +9,7 @@ import {
hfSearchFailureText,
getImageBundles, getVideoBundles, getAudioBundles, getLipsyncBundles, getMotionBundles,
getUncensoredTextModels, getMainstreamTextModels,
- detectProviderModelPath, luEngineDownloadDir,
+ detectProviderModelPath, luEngineDownloadDir, luEngineDownloadFolder, providerModelFolder,
startModelDownload,
installBundleComplete, remoteBundleNotice, checkBundlesOnDisk, resolveHfGgufFiles, ggufRequestFor, quantBudgetBytes, planModelDownload,
imagePartFor, imagePartOf, checkDownloadSpace,
@@ -239,6 +239,17 @@ export function awaitDownloadedFile(
})
}
+/**
+ * D9: when no folder for a GGUF can be had at all. The old sentence blamed
+ * "app permissions" for every cause; the backend's own reason says which.
+ */
+export function noModelFolderError(modelName: string, reason: string | null): string {
+ const why = (reason || '').trim().replace(/\.$/, '')
+ return why
+ ? `LU found no folder to download ${modelName} into: ${why}.`
+ : `LU found no folder to download ${modelName} into.`
+}
+
/**
* D7 (GitHub #215): the line that says which quant a search hit got and why.
* Null when nothing was swapped and the file fits.
@@ -778,13 +789,7 @@ export function DiscoverModels({ category, search = '', searchSubmitToken = 0, o
// them and the file went down the LM Studio branch into a nested folder
// the built-in engine never scans. resolveTextDownloadTarget keeps the
// active-model rule and adds the missing fallback.
- const downloadTarget = chosenTextDownloadTarget(targetInput, targetChoice)
- // Chosen against the chat model: the file goes to the LU Engine, and the
- // chat stays on the model the user is talking to.
- const keepChatModel = downloadTarget === 'builtin' && resolveTextDownloadTarget(targetInput) !== 'builtin'
- const isActiveBuiltin = downloadTarget === 'builtin'
- const isActiveLmStudio = downloadTarget === 'lmstudio'
- const isActiveOllama = downloadTarget === 'ollama'
+ let downloadTarget = chosenTextDownloadTarget(targetInput, targetChoice)
// Ollama-native models land in Ollama whatever the picker holds.
if (model.ollamaModel) {
@@ -804,6 +809,23 @@ export function DiscoverModels({ category, search = '', searchSubmitToken = 0, o
if (!model.downloadUrl || !model.filename) return
setInstallNotice(null)
+ // D9: a server of the user's own in the openai slot (vLLM, LiteLLM, a
+ // Custom one) may read no folder LU knows. Its GGUF goes to the LU Engine
+ // then, and the chat stays on that server, rather than every Get ending
+ // in "Could not determine model directory".
+ const serverName = providers.openai?.name || 'LM Studio'
+ let noFolderOn: string | null = null
+ if (downloadTarget === 'openai-compat' && !hfModelPath && !(await detectProviderModelPath(serverName))) {
+ noFolderOn = serverName
+ downloadTarget = 'builtin'
+ }
+ // Chosen against the chat model: the file goes to the LU Engine, and the
+ // chat stays on the model the user is talking to.
+ const keepChatModel = downloadTarget === 'builtin' && resolveTextDownloadTarget(targetInput) !== 'builtin'
+ const isActiveBuiltin = downloadTarget === 'builtin'
+ const isActiveLmStudio = downloadTarget === 'lmstudio'
+ const isActiveOllama = downloadTarget === 'ollama'
+
// N1: an LFM3 GGUF for LM Studio needs its runtime 2.65.1+. Said before
// the download, which still runs: the file is right, the runtime is old.
if (isActiveLmStudio && isLfm3Model(model.filename)) {
@@ -850,13 +872,17 @@ export function DiscoverModels({ category, search = '', searchSubmitToken = 0, o
if (isActiveBuiltin) {
return await luEngineDownloadDir()
}
- const base = hfModelPath || (await detectProviderModelPath(providers.openai?.name || 'LM Studio'))
+ const base = hfModelPath || (await detectProviderModelPath(serverName))
if (!base) return null
setHfModelPath(base)
const subdir = hfUrlToLmStudioSubdir(model.downloadUrl!)
return subdir ? `${base}/${subdir}` : base
}
+ // The backend's own sentence for a missing folder, asked only once it is missing.
+ const whyNoFolder = async (): Promise<string | null> =>
+ (isActiveBuiltin ? await luEngineDownloadFolder() : await providerModelFolder(serverName)).reason
+
// ── Sharded / multi-part: `ollama pull` cannot load split GGUF
// (ollama/ollama#5245), so the only sound path is a direct multi-part
// download into the LM Studio dir where llama.cpp merges the parts. These
@@ -866,7 +892,7 @@ export function DiscoverModels({ category, search = '', searchSubmitToken = 0, o
if (resolution?.sharded) {
const targetDir = await ensureDirectDir()
if (!targetDir) {
- setInstallError('Could not determine model directory. Please check app permissions.')
+ setInstallError(noModelFolderError(model.name, await whyNoFolder()))
return
}
// The note is about Ollama's split-GGUF gap, so it must only appear when
@@ -922,7 +948,7 @@ export function DiscoverModels({ category, search = '', searchSubmitToken = 0, o
const targetDir = await ensureDirectDir()
if (!targetDir) {
- setInstallError('Could not determine model directory. Please check app permissions.')
+ setInstallError(noModelFolderError(model.name, await whyNoFolder()))
return
}
// A GGUF carries no image tower: llama.cpp reads it from a second file that
@@ -950,7 +976,9 @@ export function DiscoverModels({ category, search = '', searchSubmitToken = 0, o
const plan = planModelDownload(model, realUrl, realName, realBytes, single?.sha256, { part, withImagePart: withPart })
await startPlannedDownload(plan, targetDir, model.group || model.name)
if (isActiveBuiltin && keepChatModel) {
- setInstallNotice(withFitNote(fitNote, `${model.name} is downloading to the LU Engine. Your chat stays on its model; the Neuron tweaker and the model list show it once it is done.`))
+ setInstallNotice(withFitNote(fitNote, noFolderOn
+ ? `${noFolderOn} reads no model folder LU knows, so ${model.name} is downloading to the LU Engine. Your chat stays on ${noFolderOn}; the model list shows it once it is done.`
+ : `${model.name} is downloading to the LU Engine. Your chat stays on its model; the Neuron tweaker and the model list show it once it is done.`))
} else if (isActiveBuiltin) {
// Built-in engine: await the flat GGUF, then make it the active chat
// model so the freshly-added model is chat-ready without a manual switch.
diff --git a/src/components/models/__tests__/a-gguf-finds-a-folder-d9.test.tsx b/src/components/models/__tests__/a-gguf-finds-a-folder-d9.test.tsx
new file mode 100644
index 00000000..b7076fde
--- /dev/null
+++ b/src/components/models/__tests__/a-gguf-finds-a-folder-d9.test.tsx
@@ -0,0 +1,158 @@
+/**
+ * @vitest-environment jsdom
+ *
+ * D9, Discord 02.11. (Windows 11, LU 3.0.8): many chat models in Discover
+ * answered every Get with "Could not determine model directory. Please check
+ * app permissions." Nothing was wrong with the permissions. The openai slot
+ * held a server of the user's own (OpenRouter, Groq, a Custom one, vLLM …),
+ * the download took that slot as its target, asked the backend for that
+ * server's model folder, got "no conventional model directory" back, and the
+ * reason was swallowed on the way.
+ *
+ * Now a server elsewhere counts like a cloud model, a local server without a
+ * known folder hands its GGUF to the LU Engine and keeps the chat, and a real
+ * failure says the backend's reason.
+ *
+ * Run: npx vitest run src/components/models/__tests__/a-gguf-finds-a-folder-d9.test.tsx
+ */
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
+import { render, screen, cleanup, waitFor, fireEvent } from '@testing-library/react'
+
+const started = vi.hoisted(() => [] as Array<{ dir: string }>)
+const setActiveModel = vi.hoisted(() => vi.fn(async () => {}))
+const folders = vi.hoisted(() => ({
+ engine: '/lu/models' as string | null,
+ server: null as string | null,
+ engineReason: 'Create LU Engine models folder: Access is denied.',
+}))
+
+vi.mock('../../../api/backend', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('../../../api/backend')>()),
+ backendCall: vi.fn(async (cmd: string, args?: { provider?: string }) => {
+ if (cmd !== 'detect_model_path') return []
+ if (args?.provider === 'builtin') {
+ if (folders.engine) return folders.engine
+ throw new Error(folders.engineReason)
+ }
+ if (folders.server) return folders.server
+ throw new Error(`No conventional model directory for provider '${args?.provider}'.`)
+ }),
+ openExternal: vi.fn(),
+ isTauri: () => false,
+ isMacOS: () => false,
+}))
+vi.mock('../../../api/comfyui', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('../../../api/comfyui')>()),
+ getSystemVRAM: vi.fn(async () => 16),
+ readComfyFolderLists: vi.fn(async () => ({})),
+ refreshComfyModels: vi.fn(async () => {}),
+}))
+vi.mock('../../../api/discover', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('../../../api/discover')>()),
+ resolveHfGgufFiles: vi.fn(async () => null),
+ checkDownloadSpace: vi.fn(async () => null),
+}))
+vi.mock('../../../api/model-download', () => ({
+ startPlannedDownload: vi.fn(async (_plan: unknown, dir: string) => { started.push({ dir }) }),
+}))
+vi.mock('../../../hooks/useModels', () => ({
+ useModels: () => ({ pullModel: vi.fn(), models: [], fetchModels: async () => {}, setActiveModel }),
+}))
+vi.mock('../../../lib/hardware', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('../../../lib/hardware')>()),
+ getMaxVramGb: vi.fn(async () => 16),
+ getTotalRamGb: vi.fn(async () => 32),
+}))
+vi.mock('../CivitaiSearchPanel', () => ({ CivitaiSearchPanel: () => null }))
+vi.mock('../../chat/LuEngineSwitchBar', () => ({ LuEngineSwitchBar: () => null }))
+
+import { DiscoverModels, noModelFolderError } from '../DiscoverModels'
+import { resolveTextDownloadTarget, slotIsOnThisMachine } from '../../../lib/text-download-target'
+import { useModelStore } from '../../../stores/modelStore'
+import { useProviderStore } from '../../../stores/providerStore'
+import { useUIStore } from '../../../stores/uiStore'
+
+const OPENROUTER = { enabled: true, managed: false, name: 'OpenRouter', baseUrl: 'https://openrouter.ai/api/v1' }
+const VLLM = { enabled: true, managed: false, name: 'vLLM', baseUrl: 'http://localhost:8000/v1' }
+
+function slot(openai: typeof OPENROUTER, activeModel: string, ollama = false) {
+ const p = useProviderStore.getState().providers
+ useProviderStore.setState({
+ providers: { ...p, ollama: { ...p.ollama, enabled: ollama }, openai: { ...p.openai, ...openai } },
+ })
+ useModelStore.setState({ activeModel })
+}
+const firstGet = () => screen.getAllByRole('button', { name: /^Get/ })[0]
+const targetName = () => screen.getByTestId('discover-target-name').textContent
+
+beforeEach(() => {
+ started.length = 0
+ setActiveModel.mockClear()
+ folders.engine = '/lu/models'
+ folders.server = null
+ useUIStore.setState({ discoverTarget: null })
+ vi.stubGlobal('ResizeObserver', class { observe() {} unobserve() {} disconnect() {} })
+})
+afterEach(() => { cleanup(); vi.unstubAllGlobals() })
+
+describe('where a GGUF goes when the openai slot holds a server of the user', () => {
+ it('a server elsewhere counts like a cloud model: the local rule decides', () => {
+ expect(resolveTextDownloadTarget({ activeChatModel: 'openai::deepseek/deepseek-v4', openai: OPENROUTER })).toBe('builtin')
+ expect(resolveTextDownloadTarget({ activeChatModel: 'openai::x', openai: OPENROUTER, ollamaEnabled: true })).toBe('ollama')
+ expect(resolveTextDownloadTarget({ activeChatModel: null, openai: OPENROUTER })).toBe('builtin')
+ expect(resolveTextDownloadTarget({ activeChatModel: 'openai::x', openai: { ...VLLM, baseUrl: 'http://192.168.1.20:8000/v1' } })).toBe('builtin')
+ // A server on this machine stays the target, LM Studio too.
+ expect(resolveTextDownloadTarget({ activeChatModel: 'openai::x', openai: VLLM })).toBe('openai-compat')
+ expect(resolveTextDownloadTarget({ activeChatModel: 'openai::x', openai: { ...VLLM, name: 'LM Studio', baseUrl: 'http://127.0.0.1:1234/v1' } })).toBe('lmstudio')
+ expect(slotIsOnThisMachine('http://[::1]:8080/v1')).toBe(true)
+ expect(slotIsOnThisMachine(undefined)).toBe(true)
+ expect(slotIsOnThisMachine('https://api.groq.com/openai/v1')).toBe(false)
+ })
+
+ it('THE REPORT: OpenRouter in the slot, Get downloads into the LU Engine, no error', async () => {
+ slot(OPENROUTER, 'openai::deepseek/deepseek-v4')
+ render(<DiscoverModels category="text" />)
+ await waitFor(() => expect(targetName()).toBe('LU Engine'))
+ fireEvent.click(firstGet())
+ await waitFor(() => expect(started).toEqual([{ dir: '/lu/models' }]))
+ expect(screen.queryByText(/Could not determine model directory/)).toBeNull()
+ expect(screen.queryByText(/LU found no folder/)).toBeNull()
+ })
+
+ it('a local server without a known folder: the GGUF goes to the LU Engine and the chat stays', async () => {
+ slot(VLLM, 'openai::qwen')
+ render(<DiscoverModels category="text" />)
+ await waitFor(() => expect(targetName()).toBe('vLLM'))
+ fireEvent.click(firstGet())
+ await waitFor(() => expect(started).toEqual([{ dir: '/lu/models' }]))
+ await screen.findByText(/vLLM reads no model folder LU knows, so .+ is downloading to the LU Engine\. Your chat stays on vLLM/)
+ expect(setActiveModel).not.toHaveBeenCalled()
+ expect(useModelStore.getState().activeModel).toBe('openai::qwen')
+ })
+
+ it('a local server with its folder keeps getting the file', async () => {
+ folders.server = '/home/u/.jan/models'
+ slot({ ...VLLM, name: 'Jan', baseUrl: 'http://localhost:1337/v1' }, 'openai::m')
+ render(<DiscoverModels category="text" />)
+ await waitFor(() => expect(targetName()).toBe('Jan'))
+ fireEvent.click(firstGet())
+ await waitFor(() => expect(started.length).toBe(1))
+ expect(started[0].dir.startsWith('/home/u/.jan/models')).toBe(true)
+ })
+
+ it('when even the LU Engine folder cannot be had, the error says the real reason', async () => {
+ folders.engine = null
+ slot(OPENROUTER, 'openai::x')
+ render(<DiscoverModels category="text" />)
+ await waitFor(() => expect(targetName()).toBe('LU Engine'))
+ fireEvent.click(firstGet())
+ await screen.findByText(/LU found no folder to download .+ into: Create LU Engine models folder: Access is denied\./)
+ expect(screen.queryByText(/app permissions/)).toBeNull()
+ expect(started).toEqual([])
+ })
+
+ it('the error sentence without and with a reason', () => {
+ expect(noModelFolderError('M', null)).toBe('LU found no folder to download M into.')
+ expect(noModelFolderError('M', 'Disk gone.')).toBe('LU found no folder to download M into: Disk gone.')
+ })
+})
diff --git a/src/lib/text-download-target.ts b/src/lib/text-download-target.ts
index b8c5f784..925db1b7 100644
--- a/src/lib/text-download-target.ts
+++ b/src/lib/text-download-target.ts
@@ -33,10 +33,33 @@ export type TextDownloadTarget =
export interface TextDownloadTargetInput {
/** `useModelStore.activeModel`: `<providerId>::<id>`, a bare Ollama tag, or null. */
activeChatModel?: string | null
- openai?: { enabled?: boolean; managed?: boolean; name?: string } | null
+ openai?: { enabled?: boolean; managed?: boolean; name?: string; baseUrl?: string } | null
ollamaEnabled?: boolean
}
+/**
+ * True when the server in the `openai` slot runs on this machine, or when the
+ * slot names no address (old entries, tests).
+ *
+ * D9 (Discord 02.11., Windows, 3.0.8): the slot also holds OpenRouter, Groq,
+ * OpenAI and every "Custom" server, and a GGUF cannot go to any of them. The
+ * download used to pick that slot all the same, looked for its model folder,
+ * found none, and every GGUF tile in Discover answered "Could not determine
+ * model directory. Please check app permissions."
+ */
+export function slotIsOnThisMachine(baseUrl?: string): boolean {
+ const url = (baseUrl || '').trim()
+ if (!url) return true
+ let host: string
+ try {
+ host = new URL(url).hostname.toLowerCase()
+ } catch {
+ return true
+ }
+ return host === 'localhost' || host.endsWith('.localhost') || host === '0.0.0.0'
+ || host === '[::1]' || host === '::1' || /^127\./.test(host)
+}
+
function isLmStudioName(name?: string): boolean {
return (name || '').toLowerCase().includes('lm studio')
}
@@ -64,19 +87,22 @@ export function resolveTextDownloadTarget(input: TextDownloadTargetInput): TextD
const { openai, ollamaEnabled } = input
const active = providerIdOf(input.activeChatModel)
const managedBuiltin = !!openai?.enabled && openai?.managed === true
+ // A server elsewhere in the slot counts like a cloud model: no file goes there.
+ const slotTakesFiles = !!openai?.managed || slotIsOnThisMachine(openai?.baseUrl)
if (active === 'ollama') return 'ollama'
- if (active === 'openai') {
+ if (active === 'openai' && slotTakesFiles) {
if (openai?.managed) return 'builtin'
return isLmStudioName(openai?.name) ? 'lmstudio' : 'openai-compat'
}
- // No active model, or an active CLOUD model (anthropic / lu-cloud): a GGUF
+ // No active model, or an active CLOUD model (anthropic / lu-cloud, or a
+ // server elsewhere in the openai slot): a GGUF
// cannot run there, so the local destination is decided on its own.
if (managedBuiltin) return 'builtin'
- if (openai?.enabled && isLmStudioName(openai?.name)) return 'lmstudio'
+ if (openai?.enabled && slotTakesFiles && isLmStudioName(openai?.name)) return 'lmstudio'
if (ollamaEnabled) return 'ollama'
- if (openai?.enabled) return 'openai-compat'
+ if (openai?.enabled && slotTakesFiles) return 'openai-compat'
// Nothing local is enabled at all. The bundled engine is the only backend
// this app can promise, so send the file to its folder rather than to a
// directory no installed program reads.