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(create): a picture ordered in chat uses the model the Create tab shows
purple55ac8b38e599
diff --git a/src/api/__tests__/model-pick.test.ts b/src/api/__tests__/model-pick.test.tsindex f8fda88f..17e61d6c 100644--- a/src/api/__tests__/model-pick.test.ts+++ b/src/api/__tests__/model-pick.test.ts@@ -13,10 +13,11 @@ vi.mock('../comfyui', async (importOriginal) => {return { ...actual, getImageModels: vi.fn(), getVideoModels: vi.fn() }})-import { pickModelForGeneration } from '../model-pick'+import { pickModelForGeneration, chooseFromUserSelection } from '../model-pick'import { getImageModels, getVideoModels } from '../comfyui'import { useModelPickStore } from '../../stores/modelPickStore'import { useSettingsStore } from '../../stores/settingsStore'+import { useCreateStore } from '../../stores/createStore'import { DEFAULT_SETTINGS } from '../../lib/constants'const IMAGE_MODELS = [@@ -46,6 +47,9 @@ beforeEach(() => {vi.mocked(getImageModels).mockResolvedValue(IMAGE_MODELS)vi.mocked(getVideoModels).mockResolvedValue(VIDEO_MODELS)useSettingsStore.setState({ settings: { ...DEFAULT_SETTINGS } })+ // The Create tab selection is the first source the gate reads, so every+ // pre-existing case has to start from "nothing chosen in Create".+ useCreateStore.setState({ imageModel: '', imageModelType: 'unknown', videoModel: '' })// No pending pick leaks between tests.if (useModelPickStore.getState().pending) useModelPickStore.getState().cancel()})@@ -151,3 +155,89 @@ describe('pickModelForGeneration — video T2V vs I2V', () => {expect(await pickModelForGeneration('video', { inputImage: 'a.png' })).toBe('svd_xt_1_1.safetensors')})})++/**+ * Runde 4, Nebenbefund N1 of the D1 counter-check (Windows build 2026-08-29):+ * `image_generate` with an empty `model` argument built a Realistic Vision+ * graph while the Create tab was set to Z-Image. The Create tab is the model+ * choice the user can see, so it is the first source now.+ */+describe('pickModelForGeneration, the Create tab selection is the default', () => {+ beforeEach(() => {+ useCreateStore.setState({ imageModel: '', imageModelType: 'unknown', videoModel: '' })+ })++ it('image: the Create tab model wins over the automatic pick, no picker card', async () => {+ useCreateStore.getState().setImageModel('RealVisXL_V5.safetensors', 'sdxl')+ const result = await pickModelForGeneration('image', {})+ expect(result).toBe('RealVisXL_V5.safetensors')+ expect(useModelPickStore.getState().pending).toBeNull()+ })++ it('image: the Create tab model also wins over the saved picker preference', async () => {+ useSettingsStore.getState().updateSettings({ preferredImageModel: 'Juggernaut-XL_v9.safetensors' })+ useCreateStore.getState().setImageModel('RealVisXL_V5.safetensors', 'sdxl')+ expect(await pickModelForGeneration('image', {})).toBe('RealVisXL_V5.safetensors')+ })++ it('image: an explicit model argument still beats the Create tab', async () => {+ useCreateStore.getState().setImageModel('RealVisXL_V5.safetensors', 'sdxl')+ const result = await pickModelForGeneration('image', { model: 'Juggernaut-XL_v9.safetensors' })+ expect(result).toBeNull()+ expect(useModelPickStore.getState().pending).toBeNull()+ })++ it('video: the Create tab model answers a text-to-video call', async () => {+ useCreateStore.getState().setVideoModel('wan2.1_t2v_1.3B_bf16.safetensors')+ expect(await pickModelForGeneration('video', {})).toBe('wan2.1_t2v_1.3B_bf16.safetensors')+ })++ // ── Negative controls: nothing chosen, or a choice that cannot serve this+ // call, and the old automation has to run untouched. ──+ it('negative control: no Create selection leaves the saved preference in charge', async () => {+ useSettingsStore.getState().updateSettings({ preferredImageModel: 'Juggernaut-XL_v9.safetensors' })+ expect(await pickModelForGeneration('image', {})).toBe('Juggernaut-XL_v9.safetensors')+ })++ it('negative control: an uninstalled Create selection re-opens the picker', async () => {+ useCreateStore.getState().setImageModel('deleted-last-week.safetensors', 'sdxl')+ const p = pickModelForGeneration('image', {})+ await answerPick({ model: 'Juggernaut-XL_v9.safetensors', save: false })+ expect(await p).toBe('Juggernaut-XL_v9.safetensors')+ })++ it('negative control: a T2V-only Create selection does not hijack image-to-video', async () => {+ useCreateStore.getState().setVideoModel('wan2.1_t2v_1.3B_bf16.safetensors')+ const p = pickModelForGeneration('video', { inputImage: 'a.png' })+ await answerPick({ model: 'svd_xt_1_1.safetensors', save: false })+ expect(await p).toBe('svd_xt_1_1.safetensors')+ })++ it('negative control: nothing chosen anywhere still ends at the picker card', async () => {+ const p = pickModelForGeneration('image', {})+ await answerPick({ model: 'RealVisXL_V5.safetensors', save: false })+ expect(await p).toBe('RealVisXL_V5.safetensors')+ })+})++describe('chooseFromUserSelection', () => {+ const names = ['a.safetensors', 'b.safetensors']++ it('prefers the Create tab choice', () => {+ expect(chooseFromUserSelection(names, 'b.safetensors', 'a.safetensors')).toBe('b.safetensors')+ })++ it('falls back to the saved preference when Create has none', () => {+ expect(chooseFromUserSelection(names, '', 'a.safetensors')).toBe('a.safetensors')+ })++ it('falls back to the saved preference when the Create choice is not installed', () => {+ expect(chooseFromUserSelection(names, 'gone.safetensors', 'a.safetensors')).toBe('a.safetensors')+ })++ it('returns null when neither choice is usable', () => {+ expect(chooseFromUserSelection(names, 'gone.safetensors', 'also-gone.safetensors')).toBeNull()+ expect(chooseFromUserSelection(names, undefined, undefined)).toBeNull()+ expect(chooseFromUserSelection([], 'a.safetensors', 'b.safetensors')).toBeNull()+ })+})diff --git a/src/api/mcp/builtin-tools.ts b/src/api/mcp/builtin-tools.tsindex 46425c21..9f1647cc 100644--- a/src/api/mcp/builtin-tools.ts+++ b/src/api/mcp/builtin-tools.ts@@ -16,6 +16,7 @@ import { isMlxImageHost, generateMlxImageDataUrl, listMlxImageModels, type MlxImimport { getVideoStatus, listVideoModels, generateVideo as generateMlxVideo, getVideoProgress, cancelVideo, type VideoModel } from '../mlx-video'import { pathToFileUrl } from '../../lib/local-media-url'import { RETIRED_MUTATING_NAMES } from '../../lib/retired-tools'+import { resolveMlxModel, defaultMlxImageModel } from '../../lib/mlx-model-match'/*** Helper: current chat id (+ folder workspace) as a fragment to spread into@@ -1041,26 +1042,6 @@ async function executeVideoGenerate(args: Record<string, any>): Promise<string>// ── macOS MLX generation (hard rule: local image/video on Mac is MLX only,// never ComfyUI — see api/mlx-image.ts / api/mlx-video.ts module docs) ────-/** Fuzzy-resolve a chat-typed model name against an installed MLX catalog by- * id or display name. Same tolerant-matching shape as resolveModelName in- * vram-handoff.ts, kept as a separate small helper so this Mac-only path- * doesn't pull in the ComfyUI-flavoured module. */-function resolveMlxModel<T extends { id: string; name: string }>(- requested: string | undefined,- installed: T[],-): T | null {- if (installed.length === 0 || !requested) return null- const norm = (s: string) => s.toLowerCase().replace(/[^a-z0-9]+/g, '')- const r = norm(requested)- if (!r) return null- return (- installed.find((m) => norm(m.id) === r || norm(m.name) === r) ??- installed.find((m) => norm(m.id).includes(r) || norm(m.name).includes(r)) ??- installed.find((m) => r.includes(norm(m.id)) || r.includes(norm(m.name))) ??- null- )-}-function sleep(ms: number): Promise<void> {return new Promise((r) => setTimeout(r, ms))}@@ -1093,7 +1074,11 @@ async function executeImageGenerateMlx(prompt: string, merged: Record<string, an}model = resolved} else {- model = installed.find((m) => m.id === 'sd-turbo') ?? installed[0]+ // Dynamic, like the ComfyUI gate's store reads in api/model-pick.ts: a+ // static import of the create store pulls api/comfyui in at module load+ // and closes an import cycle through the tool registry.+ const { useCreateStore } = await import('../../stores/createStore')+ model = defaultMlxImageModel(installed, useCreateStore.getState().imageModel)!}try {diff --git a/src/api/model-pick.ts b/src/api/model-pick.tsindex 09755d04..99d2093f 100644--- a/src/api/model-pick.ts+++ b/src/api/model-pick.ts@@ -9,10 +9,12 @@ import type { ModelPickKind } from '../stores/modelPickStore'* not the LLM's:** - explicit `model` arg from the user/LLM → no picker (intent wins)+ * - Create tab selection installed → silent use (the user's+ * visible model choice in the product, see chooseFromUserSelection)* - saved preference installed → silent use (Change-Model* affordance shows in the tool call instead)- * - nothing saved (or saved got uninstalled) → ModelPickerCard renders in- * the running tool call; save icon persists the choice for next prompts+ * - nothing chosen anywhere (or it got uninstalled) → ModelPickerCard+ * renders in the running tool call; save icon persists the choice* - ComfyUI unreachable / no models → null (the existing decide* phase reports its own actionable error — UX identical to before)*@@ -21,6 +23,34 @@ import type { ModelPickKind } from '../stores/modelPickStore'* (the rest). The preference keys are per-kind because the sets are* disjoint (SVD can't T2V, Wan 1.3B can't I2V).*/+/**+ * The model the user has ALREADY chosen for this kind, in order of authority,+ * or null when neither choice fits this call.+ *+ * The Create tab comes first. It is the model selection the user can see and+ * changed last, so a Create tab set to Z-Image has to answer a chat request+ * for a picture with Z-Image. Nebenbefund N1 of the D1 counter-check (Windows+ * build, 2026-08-29): with an empty `model` argument the chat tool ignored+ * that and built a Realistic Vision graph in two runs out of two, because the+ * saved picker preference was the only choice this gate ever read.+ *+ * `saved` (the ModelPickerCard preference) stays as the second source, so an+ * install that never opened Create behaves exactly as before. Both have to be+ * in `names`, the installed and eligible set for THIS call: an uninstalled or+ * wrong-capability choice falls through to the picker instead of building a+ * graph around a file ComfyUI does not have.+ */+export function chooseFromUserSelection(+ names: string[],+ createChoice: string | null | undefined,+ saved: string | null | undefined,+): string | null {+ for (const choice of [createChoice, saved]) {+ if (typeof choice === 'string' && choice && names.includes(choice)) return choice+ }+ return null+}+export async function pickModelForGeneration(kind: 'image' | 'video',args: Record<string, any>,@@ -54,7 +84,17 @@ export async function pickModelForGeneration(: pickKind === 'video-t2v' ? 'preferredVideoT2VModel': 'preferredVideoI2VModel'const saved = useSettingsStore.getState().settings[prefKey]- if (saved && names.includes(saved)) return saved++ // The Create tab's own model selection, read through the same store the+ // Create page writes it to. For video the two sub-kinds share one Create+ // selection; `names` already carries the I2V/T2V filter, so a T2V-only+ // choice simply does not answer an image-to-video call.+ const { useCreateStore } = await import('../stores/createStore')+ const createState = useCreateStore.getState()+ const createChoice = pickKind === 'image' ? createState.imageModel : createState.videoModel++ const chosen = chooseFromUserSelection(names, createChoice, saved)+ if (chosen) return chosenconst { useModelPickStore } = await import('../stores/modelPickStore')const choice = await useModelPickStore.getState().request(pickKind, names, names[0])diff --git a/src/lib/__tests__/mlx-model-match.test.ts b/src/lib/__tests__/mlx-model-match.test.tsnew file mode 100644index 00000000..c15813ab--- /dev/null+++ b/src/lib/__tests__/mlx-model-match.test.ts@@ -0,0 +1,67 @@+/**+ * Runde 4, Nebenbefund N1 of the D1 counter-check (Windows build 2026-08-29):+ * `image_generate` with an empty `model` argument ignored the model chosen in+ * the Create tab. The ComfyUI side is fixed in api/model-pick.ts; this covers+ * the macOS MLX side, which had the same shape (sd-turbo, then whatever was+ * installed first, and the user's choice nowhere in the chain).+ *+ * Run: npx vitest run src/lib/__tests__/mlx-model-match.test.ts+ */+import { describe, it, expect } from 'vitest'+import { defaultMlxImageModel, resolveMlxModel } from '../mlx-model-match'++const INSTALLED = [+ { id: 'flux-schnell', name: 'FLUX Schnell' },+ { id: 'sd-turbo', name: 'SD Turbo' },+ { id: 'sdxl-turbo', name: 'SDXL Turbo' },+]++describe('defaultMlxImageModel', () => {+ it('uses the Create tab selection by id', () => {+ expect(defaultMlxImageModel(INSTALLED, 'sdxl-turbo')?.id).toBe('sdxl-turbo')+ })++ it('uses the Create tab selection by display name', () => {+ expect(defaultMlxImageModel(INSTALLED, 'FLUX Schnell')?.id).toBe('flux-schnell')+ })++ it('beats the sd-turbo default', () => {+ expect(defaultMlxImageModel(INSTALLED, 'flux-schnell')?.id).toBe('flux-schnell')+ })++ // ── Negative controls: the old automation has to survive untouched. ──+ it('negative control: no Create selection keeps the sd-turbo default', () => {+ expect(defaultMlxImageModel(INSTALLED, '')?.id).toBe('sd-turbo')+ expect(defaultMlxImageModel(INSTALLED, null)?.id).toBe('sd-turbo')+ expect(defaultMlxImageModel(INSTALLED, undefined)?.id).toBe('sd-turbo')+ })++ it('negative control: a Create selection nothing matches keeps the default', () => {+ expect(defaultMlxImageModel(INSTALLED, 'qqqq')?.id).toBe('sd-turbo')+ })++ it('negative control: without sd-turbo the first installed model still answers', () => {+ const noTurbo = [{ id: 'flux-schnell', name: 'FLUX Schnell' }]+ expect(defaultMlxImageModel(noTurbo, 'qqqq')?.id).toBe('flux-schnell')+ })++ it('negative control: an empty install yields nothing', () => {+ expect(defaultMlxImageModel([], 'sd-turbo')).toBeUndefined()+ })+})++describe('resolveMlxModel keeps its tolerant matching after the move', () => {+ it('matches on a normalized id', () => {+ expect(resolveMlxModel('SD_Turbo', INSTALLED)?.id).toBe('sd-turbo')+ })++ it('matches a substring of a display name', () => {+ expect(resolveMlxModel('schnell', INSTALLED)?.id).toBe('flux-schnell')+ })++ it('negative control: no match and empty input return null', () => {+ expect(resolveMlxModel('midjourney', INSTALLED)).toBeNull()+ expect(resolveMlxModel(undefined, INSTALLED)).toBeNull()+ expect(resolveMlxModel('sd-turbo', [])).toBeNull()+ })+})diff --git a/src/lib/mlx-model-match.ts b/src/lib/mlx-model-match.tsnew file mode 100644index 00000000..7d2aa46a--- /dev/null+++ b/src/lib/mlx-model-match.ts@@ -0,0 +1,62 @@+/**+ * Matching an image/video model NAME typed in a chat call against the models+ * actually installed for the macOS MLX lane, plus the rule for what an+ * argument-less call falls back to.+ *+ * It lives here rather than in api/mcp/builtin-tools.ts because that module+ * closes an import cycle through the tool registry and cannot be loaded by a+ * test (see lib/__tests__/tool-classification.test.ts, which reads it as+ * text). Pure functions, no store and no I/O, so both rules are testable.+ */++/** The shape both MLX catalogs (image and video) share. */+export interface NamedModel {+ id: string+ name: string+}++/**+ * Fuzzy-resolve a chat-typed model name against an installed MLX catalog by id+ * or display name. Same tolerant-matching shape as resolveModelName in+ * api/vram-handoff.ts, kept separate so this Mac-only path does not pull in+ * the ComfyUI-flavoured module.+ */+export function resolveMlxModel<T extends NamedModel>(+ requested: string | undefined,+ installed: T[],+): T | null {+ if (installed.length === 0 || !requested) return null+ const norm = (s: string) => s.toLowerCase().replace(/[^a-z0-9]+/g, '')+ const r = norm(requested)+ if (!r) return null+ return (+ installed.find((m) => norm(m.id) === r || norm(m.name) === r) ??+ installed.find((m) => norm(m.id).includes(r) || norm(m.name).includes(r)) ??+ installed.find((m) => r.includes(norm(m.id)) || r.includes(norm(m.name))) ??+ null+ )+}++/**+ * Which installed MLX image model an argument-less `image_generate` runs on.+ *+ * Same rule the ComfyUI gate follows in api/model-pick.ts, kept in step for+ * cross-platform parity: the Create tab holds the model the user picked and+ * can see, so it answers first. Nebenbefund N1 of the D1 counter-check+ * (Windows build, 2026-08-29) caught the ComfyUI half of this ignoring that+ * choice; the MLX half had the same shape.+ *+ * sd-turbo stays the fallback for an install that never opened Create, then+ * the first installed model. Undefined only for an empty install, which the+ * caller reports with its own message.+ */+export function defaultMlxImageModel<T extends NamedModel>(+ installed: T[],+ createChoice: string | null | undefined,+): T | undefined {+ return (+ resolveMlxModel(createChoice || undefined, installed)+ ?? installed.find((m) => m.id === 'sd-turbo')+ ?? installed[0]+ )+}