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): Dedup erkennt die kollabierte LM-Studio-Form

purple52f52d2d29de
diff --git a/src/api/engine.ts b/src/api/engine.ts
index c1b43e37..f63bf9b3 100644
--- a/src/api/engine.ts
+++ b/src/api/engine.ts
@@ -363,6 +363,11 @@ export function bundledToAIModels(models: BundledModel[]): CloudModel[] {
type: 'text' as const,
provider: 'openai' as const,
providerName: LU_ENGINE_NAME,
+ // Carried through since 2.6.8 (A14): the row IS a file, and the Installed
+ // list needs the path to tell "the same GGUF, seen twice" from "two
+ // downloads of the same model". A file under LM Studio's own store is the
+ // case that made this necessary.
+ path: m.path,
// The projector answer from disk, carried as the app-wide capability flag
// so the composer and the agent loop stop guessing from the model name.
// Deliberately left absent (not false) when the backend did not report it,
diff --git a/src/components/models/ModelManager.tsx b/src/components/models/ModelManager.tsx
index 621b6d01..6fd1390a 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 { LuEngineSwitchBar } from '../chat/LuEngineSwitchBar'
import type { InstalledModelLike } from '../../lib/lmstudio-match'
import type { ModelCategory, AIModel } from '../../types/models'
@@ -407,6 +408,10 @@ export function ModelManager() {
<div className="flex-1 h-px bg-gray-200 dark:bg-white/[0.06]" />
</div>
<div className="space-y-1.5">
+ {/* A14: a click on an LU Engine card can move the chat
+ backend, so the same line the composer shows stands
+ here too, from the same store. */}
+ <LuEngineSwitchBar />
{/* 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
@@ -419,7 +424,7 @@ export function ModelManager() {
// is an LU Engine group while another backend holds
// the chat: then the heading is not decoration, it is
// the warning that a click here moves the backend.
- const showHeadings = needsLuEngineHeading(providerGroups, luEngineHoldsChat)
+ const showHeadings = needsLuEngineHeading(providerGroups.map((g) => g.label), luEngineHoldsChat)
let drawn = 0
return providerGroups.map(({ label, models: rows }) => (
<div key={label} className="space-y-1.5">
diff --git a/src/components/models/ModelSelector.tsx b/src/components/models/ModelSelector.tsx
index ce2489a6..466c5f86 100644
--- a/src/components/models/ModelSelector.tsx
+++ b/src/components/models/ModelSelector.tsx
@@ -18,7 +18,7 @@ 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 { splitLuEngineRows, needsLuEngineHeading, 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 { useLuEngineSwitchStore } from '../../stores/luEngineSwitchStore'
@@ -846,6 +846,10 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBy
: []),
...groupByFamily(luEngineSplit.rest),
]
+ // The one rule, asked rather than copied (second review): one group normally
+ // draws no heading, except an LU Engine group under a foreign chat backend,
+ // where the heading is the warning that picking from it moves the backend.
+ const showHeadings = needsLuEngineHeading(groups.map((g) => g.family), luEngineHoldsChat)
const hasOllamaModels = textModels.some(m => ('provider' in m && m.provider === 'ollama') || !('provider' in m))
textModelsEmptyRef.current = textModels.length === 0
@@ -975,7 +979,7 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBy
Engine group under a foreign chat backend draws one
anyway, because that heading is the warning that picking
from it moves the backend (A14 review 7). */}
- {(groups.length > 1 || (!luEngineHoldsChat && family === LU_ENGINE_GROUP)) && (
+ {showHeadings && (
<div className="px-2.5 pt-2 pb-0.5">
<span className="text-[0.55rem] font-medium uppercase tracking-widest text-gray-600">
{family}
diff --git a/src/lib/__tests__/lu-engine-groups.test.ts b/src/lib/__tests__/lu-engine-groups.test.ts
index 5f4ecc75..fc52e1a3 100644
--- a/src/lib/__tests__/lu-engine-groups.test.ts
+++ b/src/lib/__tests__/lu-engine-groups.test.ts
@@ -89,14 +89,61 @@ describe('de-duplication asks about the FILE, never about the model', () => {
// for de-duplication it made a quant-less GGUF in the LU Engine folder
// disappear behind whichever quant LM Studio happened to hold, and those are
// two different files with two different answer qualities.
- it('keeps a quant-less GGUF beside any LM Studio quant of the same model', () => {
+ it('keeps a quant-less GGUF beside a NAMED LM Studio quant of the same model', () => {
+ // LM Studio naming a quant means it knows which file it has, and it is not
+ // this one: ours names none, so the two cannot be shown to be one file.
const row = luFile('Qwen2.5-0.5B-Instruct')
expect(dropDuplicateLuEngineRows([row], lmsHas('qwen2.5-0.5b-instruct@q4_k_m'))).toEqual([row])
expect(dropDuplicateLuEngineRows([row], lmsHas('qwen2.5-0.5b-instruct@q8_0'))).toEqual([row])
- // And the mirror image: LM Studio holding a quant-less collapsed id does
- // not swallow a named quant on our side either.
+ })
+
+ // A14 second review: the collapsed id is the COMMON case, not the exotic
+ // one. LM Studio reports "qwen/qwen2.5-0.5b-instruct" with no quant at all
+ // whenever it holds exactly one quant of a model, which is most of the time,
+ // and the strict rule kept both rows for one file. One nameless row and
+ // exactly one file of that identity can only be each other.
+ it('drops the row for a collapsed LM Studio id when we hold exactly one such file', () => {
const q8 = luFile('Qwen2.5-0.5B-Instruct-Q8_0')
- expect(dropDuplicateLuEngineRows([q8], lmsHas('qwen/qwen2.5-0.5b-instruct'))).toEqual([q8])
+ expect(dropDuplicateLuEngineRows([q8], lmsHas('qwen/qwen2.5-0.5b-instruct'))).toEqual([])
+ })
+
+ // NEGATIVE CONTROL for that route: with TWO quants of the model in our
+ // folder, a nameless LM Studio row cannot say which of them it is. Dropping
+ // either would be a guess, so both stay.
+ it('keeps both when a collapsed id could mean either of two files we hold', () => {
+ const rows = [luFile('Qwen2.5-0.5B-Instruct-Q8_0'), luFile('Qwen2.5-0.5B-Instruct-Q4_K_M')]
+ expect(dropDuplicateLuEngineRows(rows, lmsHas('qwen/qwen2.5-0.5b-instruct'))).toEqual(rows)
+ })
+
+ it('drops the row when the file itself lies in LM Studio own store', () => {
+ // The auto-detect case: the LU Engine folder is ~/.lmstudio/models, so the
+ // folder walk finds LM Studio own files. Then the identity settles it and
+ // no quant needs to be named anywhere.
+ const inStore = {
+ name: 'openai::Qwen2.5-0.5B-Instruct',
+ model: 'Qwen2.5-0.5B-Instruct',
+ path: '/Users/d/.lmstudio/models/qwen/Qwen2.5-0.5B-Instruct/Qwen2.5-0.5B-Instruct.gguf',
+ provider: 'openai',
+ providerName: 'LU Engine',
+ }
+ expect(dropDuplicateLuEngineRows([inStore], lmsHas('qwen/qwen2.5-0.5b-instruct@q4_k_m'))).toEqual([])
+ })
+
+ // NEGATIVE CONTROL: the same shape OUTSIDE LM Studio's store is a real
+ // second download and stays.
+ it('keeps a quant-less file of our own beside a differently quantised LM Studio one', () => {
+ const own = luFile('Qwen2.5-0.5B-Instruct')
+ const second = luFile('Qwen2.5-0.5B-Instruct-Q4_K_M')
+ // Two files of the identity, so route 3 cannot fire and the strict rule
+ // finds no quant on our first file: both stay.
+ expect(dropDuplicateLuEngineRows([own, second], lmsHas('qwen2.5-0.5b-instruct@q8_0'))).toEqual([own, second])
+ })
+
+ it('drops the row when both sides name the same path', () => {
+ const shared = '/Users/d/models/Qwen2.5-0.5B-Instruct-Q8_0.gguf'
+ const ours = { name: 'openai::Qwen2.5-0.5B-Instruct-Q8_0', model: 'Qwen2.5-0.5B-Instruct-Q8_0', path: shared, provider: 'openai', providerName: 'LU Engine' }
+ const theirs = [{ name: 'openai::whatever-lm-studio-calls-it', model: 'whatever-lm-studio-calls-it', path: shared, provider: 'openai', providerName: 'LM Studio' }]
+ expect(dropDuplicateLuEngineRows([ours], theirs)).toEqual([])
})
// NEGATIVE CONTROL: two quants of one model are two files.
@@ -126,9 +173,10 @@ describe('de-duplication asks about the FILE, never about the model', () => {
// ── A14 review 7: the heading is the warning, so it cannot be optional ──────
describe('when the LU Engine heading has to be drawn', () => {
- const luGroup = groupInstalledByProvider([lu('a')])
- const ollamaGroup = groupInstalledByProvider([ollama('a')])
- const both = groupInstalledByProvider([lu('a'), ollama('b')])
+ const labels = <T extends { label: string }>(g: T[]) => g.map((x) => x.label)
+ const luGroup = labels(groupInstalledByProvider([lu('a')]))
+ const ollamaGroup = labels(groupInstalledByProvider([ollama('a')]))
+ const both = labels(groupInstalledByProvider([lu('a'), ollama('b')]))
// THE REVIEW FINDING. A user whose only local models are GGUFs in the LU
// Engine folder, with Ollama or LM Studio in front, got one unlabelled list
@@ -159,3 +207,30 @@ describe('when the LU Engine heading has to be drawn', () => {
expect(needsLuEngineHeading([], false)).toBe(false)
})
})
+
+// ── One rule, two surfaces ──────────────────────────────────────────────────
+//
+// The rule above is proven by behaviour. That both surfaces ASK it, rather
+// than each keeping a copy that drifts, is pinned by reading the source: the
+// Installed list and the composer's picker group by different things and
+// neither component has a render harness in this repo. Weaker proof, and
+// labelled as such: it catches a copy creeping back in, not a broken render.
+describe('the Installed list and the picker ask the same rule', () => {
+ const read = async (p: string) => {
+ const { readFileSync } = await import('node:fs')
+ const { resolve, dirname } = await import('node:path')
+ const { fileURLToPath } = await import('node:url')
+ return readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), p), 'utf8')
+ }
+
+ it('the composer picker calls it instead of counting groups itself', async () => {
+ const src = await read('../../components/models/ModelSelector.tsx')
+ expect(src).toContain('needsLuEngineHeading(groups.map((g) => g.family), luEngineHoldsChat)')
+ expect(src).not.toMatch(/family === LU_ENGINE_GROUP\)\) &&/)
+ })
+
+ it('and so does the Installed list', async () => {
+ const src = await read('../../components/models/ModelManager.tsx')
+ expect(src).toContain('needsLuEngineHeading(providerGroups.map((g) => g.label), luEngineHoldsChat)')
+ })
+})
diff --git a/src/lib/lu-engine-rows.ts b/src/lib/lu-engine-rows.ts
index f77697eb..b2449aad 100644
--- a/src/lib/lu-engine-rows.ts
+++ b/src/lib/lu-engine-rows.ts
@@ -20,7 +20,10 @@
* of blending into the list.
*/
-import { isSameGgufFile, isLmStudioEntry, isBuiltinEngineEntry, type InstalledModelLike } from './lmstudio-match'
+import {
+ isSameGgufFile, isLmStudioEntry, isBuiltinEngineEntry, modelIdentity, extractQuant,
+ 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'
@@ -39,12 +42,25 @@ export const LU_ENGINE_GROUP = 'LU Engine'
* the model and not two views of one file, and collapsing them would hide a
* real second copy.
*
- * A14 review: this asks `isSameGgufFile`, not the Discover badge's matcher.
- * That one answers a catalogue question and treats a name without a quant as
- * "any quant will do", so a quant-less GGUF in the LU Engine folder would have
- * been swallowed by whatever quant LM Studio happened to hold. The two files
- * differ; only one of them is on the user's disk twice. No quant on either
- * side means no match here, so the row stays.
+ * A14 review: this does NOT ask the Discover badge's matcher. That one answers
+ * a catalogue question and treats a name without a quant as "any quant will
+ * do", so a quant-less GGUF in the LU Engine folder would have been swallowed
+ * by whatever quant LM Studio happened to hold. Two files, one of them hidden.
+ *
+ * A14 second review: the strict rule alone was too strict for the commonest
+ * case. LM Studio reports a COLLAPSED id with no quant at all
+ * ("qwen/qwen2.5-0.5b-instruct") whenever it holds exactly one quant of a
+ * model, which is most of the time, and that met neither half of the strict
+ * rule. So there are three ways in, in falling order of certainty:
+ *
+ * 1. the same path. Same file, whatever the two sides call it.
+ * 2. our file lies inside LM Studio's own store, which is what happens the
+ * moment the folder is pointed at ~/.lmstudio/models. Then it IS LM
+ * Studio's file and the model identity is enough.
+ * 3. LM Studio names no quant and we hold exactly ONE file of that identity.
+ * One file and one nameless row can only be each other. Two files of the
+ * same identity and a nameless row cannot be told apart, so nothing is
+ * dropped and the user keeps both.
*/
export function dropDuplicateLuEngineRows<T extends InstalledModelLike>(
bundled: T[],
@@ -53,25 +69,81 @@ export function dropDuplicateLuEngineRows<T extends InstalledModelLike>(
if (bundled.length === 0) return bundled
const lmStudio = alreadyListed.filter(isLmStudioEntry)
if (lmStudio.length === 0) return bundled
- return bundled.filter((row) => !lmStudio.some((other) => sameFile(row, other)))
+ // How many of OUR files share each identity. Route 3 only applies where the
+ // answer is exactly one.
+ const ownByIdentity = new Map<string, number>()
+ for (const row of bundled) {
+ const id = identityOf(row)
+ if (id) ownByIdentity.set(id, (ownByIdentity.get(id) ?? 0) + 1)
+ }
+ return bundled.filter((row) => !lmStudio.some((other) => sameFile(row, other, ownByIdentity)))
}
/** Every id a row can be recognised by. LM Studio reports its own key, our own
- * rows carry the file stem, and both may carry a full path. */
+ * rows carry the file stem, and ours also carry the path. */
function idsOf(m: InstalledModelLike): string[] {
const raw = m as InstalledModelLike & { path?: unknown }
return [m.model, m.name, m.lmsKey, typeof raw.path === 'string' ? raw.path : undefined]
.filter((v): v is string => typeof v === 'string' && v.length > 0)
}
+/** The path a row names, or ''. */
+function pathOf(m: InstalledModelLike): string {
+ const raw = m as InstalledModelLike & { path?: unknown }
+ return typeof raw.path === 'string' ? raw.path : ''
+}
+
+/** Trailing separators and the Windows/POSIX split are not a different file. */
+function normalisePath(p: string): string {
+ return p.replace(/\\/g, '/').replace(/\/+$/, '').toLowerCase()
+}
+
+/** The model identity a row is about, from whichever id carries one. */
+function identityOf(m: InstalledModelLike): string {
+ for (const id of idsOf(m)) {
+ const identity = modelIdentity(id)
+ if (identity && identity.length >= 5) return identity
+ }
+ return ''
+}
+
+/** Does this row's file lie inside LM Studio's own model store. */
+function livesInLmStudioStore(m: InstalledModelLike): boolean {
+ const p = normalisePath(pathOf(m))
+ if (!p) return false
+ return p.includes('/.lmstudio/models/') || p.includes('/.cache/lm-studio/models/')
+}
+
+/** Does any of this row's ids name a quant. */
+function namesAQuant(m: InstalledModelLike): boolean {
+ return idsOf(m).some((id) => extractQuant(id) !== null)
+}
+
/** Two rows pointing at one file on disk. */
-function sameFile(a: InstalledModelLike, b: InstalledModelLike): boolean {
- const idsA = idsOf(a)
- const idsB = idsOf(b)
- // The same path is the same file, whatever the two sides call the model.
- for (const x of idsA) {
- for (const y of idsB) {
- if (x === y) return true
+function sameFile(
+ ours: InstalledModelLike,
+ other: InstalledModelLike,
+ ownByIdentity: Map<string, number>,
+): boolean {
+ // Route 1: the same path, spelled either way round.
+ const ourPath = normalisePath(pathOf(ours))
+ const otherPath = normalisePath(pathOf(other))
+ if (ourPath && ourPath === otherPath) return true
+
+ const ourIdentity = identityOf(ours)
+ const otherIdentity = identityOf(other)
+ const sameModel = !!ourIdentity && ourIdentity === otherIdentity
+
+ // Route 2: our file IS in LM Studio's store, so the identity settles it.
+ if (sameModel && livesInLmStudioStore(ours)) return true
+
+ // Route 3: LM Studio names no quant and we hold exactly one such file.
+ if (sameModel && !namesAQuant(other) && ownByIdentity.get(ourIdentity) === 1) return true
+
+ // Otherwise the strict rule: same filename, or the same quant named on both
+ // sides. A missing quant on either side is not evidence.
+ for (const x of idsOf(ours)) {
+ for (const y of idsOf(other)) {
if (isSameGgufFile(x, y)) return true
}
}
@@ -102,18 +174,17 @@ export interface ProviderGroup<T> {
*
* A14 review 7: the render dropped every heading at one group, which is right
* for a plain Ollama box and wrong for the exact machine this whole change is
- * about. A user whose only local models are GGUFs in the LU Engine folder,
+ * about. Takes bare labels rather than groups so the Installed list and the
+ * composer's picker, which group by different things, can ask the one rule
+ * instead of each keeping a copy of it (second review). A user whose only local models are GGUFs in the LU Engine folder,
* with Ollama or LM Studio in front and nothing of their own installed, saw
* one unlabelled list and a click that moved his chat backend without a word
* of warning. The heading is the warning, so it is drawn whenever a foreign
* backend holds the chat, group count be damned.
*/
-export function needsLuEngineHeading<T extends InstalledModelLike>(
- groups: ProviderGroup<T>[],
- luEngineHoldsChat: boolean,
-): boolean {
- if (groups.length > 1) return true
- return !luEngineHoldsChat && groups.some((g) => g.label === LU_ENGINE_GROUP)
+export function needsLuEngineHeading(labels: string[], luEngineHoldsChat: boolean): boolean {
+ if (labels.length > 1) return true
+ return !luEngineHoldsChat && labels.includes(LU_ENGINE_GROUP)
}
/**
diff --git a/src/types/models.ts b/src/types/models.ts
index df17850d..027f5da9 100644
--- a/src/types/models.ts
+++ b/src/types/models.ts
@@ -42,6 +42,11 @@ export interface CloudModel {
/** Friendly picker label when the server provides one (LU Cloud /models
* `name`) — pickers fall back to the raw id otherwise. */
displayName?: string
+ /** Where the file lies, for a row that IS a file: the LU Engine's GGUFs.
+ * Absent for everything served over a network API. Two rows naming one
+ * path are one model however differently the two backends spell its name,
+ * which is what the Installed list uses to stop showing it twice. */
+ path?: string
}
// Image model (e.g. Stable Diffusion, SDXL, Fooocus, ComfyUI)