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(mac): local Create actually reaches MLX — plus the e2e that caught it
purple3fe6ce972826
diff --git a/e2e/mac-create-mlx.spec.ts b/e2e/mac-create-mlx.spec.tsnew file mode 100644index 00000000..a0364963--- /dev/null+++ b/e2e/mac-create-mlx.spec.ts@@ -0,0 +1,150 @@+import { test, expect, type Page } from '@playwright/test'+import { tauriMockInit, DEFAULT_ASSISTANT_REPLY, DEFAULT_MODEL_NAME, type TauriMockOptions } from './support/tauri-mock'+import { routeCloud, seedOnboardingDone, cloudSwitch } from './support/cloud-mock'++/**+ * macOS local Create — the MLX path (MAC-5).+ *+ * The Mac has no ComfyUI: local images and video run through the in-process+ * MLX sidecar (commands/mlx.rs, video.rs). Until this file the whole surface+ * had zero e2e coverage, so the platform split was only ever verified by+ * reading code. Every test here pins the platform explicitly — the app derives+ * it from navigator, so an unpinned spec would silently test whatever laptop+ * ran it.+ *+ * What's covered: which lanes the Mac offers, that image and video actually+ * dispatch to MLX (and never to ComfyUI), that the installer a fresh Mac needs+ * exists and works, and — as the regression guard — that Windows is untouched.+ */++const MAC_OPTS: TauriMockOptions = {+ assistantReply: DEFAULT_ASSISTANT_REPLY,+ modelName: DEFAULT_MODEL_NAME,+ platform: 'mac',+}++async function bootLocalCreate(page: Page, opts: TauriMockOptions) {+ await page.addInitScript(tauriMockInit, opts)+ await seedOnboardingDone(page)+ await routeCloud(page, { license: 'active', access: true, mediaLive: true })+ await page.goto('/')+ await expect(cloudSwitch(page)).toBeVisible({ timeout: 20_000 })+ await page.getByRole('button', { name: /^Create$/ }).click()+}++/** Everything the page recorded through the mocked MLX commands. */+function mlxCalls(page: Page) {+ return page.evaluate(() => (window as unknown as { __E2E_MLX_CALLS__?: unknown[] }).__E2E_MLX_CALLS__ ?? [])+}++test('mac local: MLX lanes run locally, cloud-only lanes stay visible as teasers', async ({ page }) => {+ await bootLocalCreate(page, MAC_OPTS)++ // The two lanes MLX genuinely serves are plain, selectable radios.+ await expect(page.getByRole('radio', { name: 'Image', exact: true })).toBeVisible({ timeout: 15_000 })+ await expect(page.getByRole('radio', { name: 'Video', exact: true })).toBeVisible()++ // Everything hosted-only keeps its place in the bar as a locked teaser —+ // David's rule: what can't run locally is still shown, not deleted.+ for (const label of ['Upscale', 'Erase Object', 'Character Studio', 'Talking Character', 'Music', 'Extend Video', 'Motion Control']) {+ await expect(page.getByRole('radio', { name: `${label}, runs on LU Cloud` })).toBeVisible()+ }++ // A locked lane opens the teaser instead of switching the lane.+ await page.getByRole('radio', { name: 'Music, runs on LU Cloud' }).click()+ await expect(page.getByRole('radio', { name: 'Image', exact: true })).toBeChecked()++ // Lanes that need a ComfyUI upload/node have no Mac path at all and are not+ // offered — a visible-but-broken button would be the worse outcome.+ await expect(page.getByRole('radio', { name: /^Remove Background/ })).toHaveCount(0)+ await expect(page.getByRole('radio', { name: /^Edit \/ Image to Image/ })).toHaveCount(0)+ await expect(page.getByRole('radio', { name: /^Animate Image/ })).toHaveCount(0)+})++test('mac local: image generate dispatches to MLX, never to ComfyUI', async ({ page }) => {+ await bootLocalCreate(page, MAC_OPTS)+ await expect(page.getByRole('radio', { name: 'Image', exact: true })).toBeVisible({ timeout: 15_000 })++ const composer = page.locator('textarea').first()+ await composer.fill('a red apple on a wooden table')+ await page.getByRole('button', { name: /^Create$/ }).last().click()++ await expect+ .poll(async () => (await mlxCalls(page)).filter((c: any) => c.cmd === 'mlx_generate').length, { timeout: 30_000 })+ .toBeGreaterThan(0)++ const gen = (await mlxCalls(page)).find((c: any) => c.cmd === 'mlx_generate') as any+ expect(gen.prompt).toContain('a red apple')++ // The render came back as a data: PNG and is on screen.+ await expect(page.locator('img[src^="data:image/png"]').first()).toBeVisible({ timeout: 30_000 })++ // The point of the whole platform split: no ComfyUI call was even attempted.+ const comfy = await page.evaluate(+ () => (window as unknown as { __E2E_COMFY_CALLS__?: unknown[] }).__E2E_COMFY_CALLS__ ?? [],+ )+ expect(comfy).toHaveLength(0)+})++test('mac local: video generate dispatches to the MLX video model', async ({ page }) => {+ await bootLocalCreate(page, MAC_OPTS)+ await page.getByRole('radio', { name: 'Video', exact: true }).click()++ const composer = page.locator('textarea').first()+ await composer.fill('slow drifting clouds over a lake')+ await page.getByRole('button', { name: /^Create$/ }).last().click()++ await expect+ .poll(async () => (await mlxCalls(page)).filter((c: any) => c.cmd === 'video_generate').length, { timeout: 40_000 })+ .toBeGreaterThan(0)++ const gen = (await mlxCalls(page)).find((c: any) => c.cmd === 'video_generate') as any+ expect(gen.id).toBe('wan21-t2v-1.3b')+ expect(gen.prompt).toContain('drifting clouds')+})++test('fresh mac: the Local Media panel installs the engine and a model', async ({ page }) => {+ // A Mac that has never generated anything: no venv, no models. Before MAC-3+ // this state had no way out — the Rust install commands existed but nothing+ // called them, so local Create just failed.+ await page.addInitScript(tauriMockInit, {+ ...MAC_OPTS,+ mlx: { engineInstalled: false, videoEngineInstalled: false, installedImages: [], installedVideos: [] },+ })+ await seedOnboardingDone(page)+ await routeCloud(page, { license: 'active', access: true, mediaLive: true })+ await page.goto('/')+ await expect(cloudSwitch(page)).toBeVisible({ timeout: 20_000 })++ await page.getByRole('button', { name: /^Settings$/ }).click()+ await page.getByRole('button', { name: /AI Backends/i }).click()++ // The Mac gets the MLX installer where other platforms get the ComfyUI panel.+ const section = page.getByRole('button', { name: /Local Media \(Apple MLX\)/i })+ await expect(section).toBeVisible({ timeout: 15_000 })+ await section.click()+ await expect(page.getByRole('button', { name: /ComfyUI/i })).toHaveCount(0)++ // Engine first: a model can't install without it.+ await expect(page.getByText(/about 3 GB of Python packages/i)).toBeVisible()+ await page.getByRole('button', { name: /Install engine/i }).first().click()+ await expect(page.getByText(/^Installed/).first()).toBeVisible({ timeout: 20_000 })++ // Then a model — the catalog row flips to installed and offers Remove.+ await page.getByRole('button', { name: /^Install$/ }).first().click()+ await expect(page.getByRole('button', { name: /Remove/i }).first()).toBeVisible({ timeout: 20_000 })++ const calls = (await mlxCalls(page)) as any[]+ expect(calls.some((c) => c.cmd === 'mlx_image_install_model' && c.id === 'sd-turbo')).toBe(true)+})++test('windows local is unchanged: ComfyUI lanes still offered', async ({ page }) => {+ // Guard against fixing the Mac by breaking everyone else.+ await bootLocalCreate(page, { ...MAC_OPTS, platform: 'windows' })++ await expect(page.getByRole('radio', { name: 'Image', exact: true })).toBeVisible({ timeout: 15_000 })+ await expect(page.getByRole('radio', { name: 'Remove Background', exact: true })).toBeVisible()+ await expect(page.getByRole('radio', { name: 'Edit / Image to Image', exact: true })).toBeVisible()+ await expect(page.getByRole('radio', { name: 'Animate Image', exact: true })).toBeVisible()+ await expect(page.getByRole('radio', { name: 'Music', exact: true })).toBeVisible()+})diff --git a/e2e/support/tauri-mock.ts b/e2e/support/tauri-mock.tsindex 04970cdc..cea94832 100644--- a/e2e/support/tauri-mock.ts+++ b/e2e/support/tauri-mock.ts@@ -21,6 +21,21 @@ export interface TauriMockOptions {assistantReply: string/** Picker id of the bundled starter model the engine reports as loaded. */modelName: string+ /** Shape of the MLX media stack this machine reports. Omit for "set up". */+ mlx?: {+ engineInstalled?: boolean+ videoEngineInstalled?: boolean+ installedImages?: string[]+ installedVideos?: string[]+ }+ /**+ * Which OS the app should believe it is on. `isMacOS()` reads+ * navigator.platform/userAgent, so without this every spec silently inherits+ * the DEV MACHINE's platform — and Mac and Windows disagree about the whole+ * local Create surface (MLX vs ComfyUI). Specs that assert platform+ * behaviour must pin it; the default matches the historical CI target.+ */+ platform?: 'mac' | 'windows'}export const DEFAULT_ASSISTANT_REPLY = 'PONG_BUILTIN_OK the built-in engine answered.'@@ -33,6 +48,24 @@ export const DEFAULT_MODEL_NAME = 'qwen2.5-0.5b-instruct-q4_k_m'*/export function tauriMockInit(opts: TauriMockOptions) {const w = window as any++ // Pin the platform BEFORE the app reads it. isMacOS() (api/backend.ts) tests+ // navigator.platform then userAgent; leaving them alone makes every spec's+ // verdict depend on whose laptop ran it.+ {+ const mac = opts.platform === 'mac'+ const platform = mac ? 'MacIntel' : 'Win32'+ const ua = mac+ ? 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15'+ : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'+ try {+ Object.defineProperty(navigator, 'platform', { get: () => platform, configurable: true })+ Object.defineProperty(navigator, 'userAgent', { get: () => ua, configurable: true })+ } catch {+ /* a locked-down navigator just means the host platform wins */+ }+ }+const MODELS_DIR = '/tmp/lu-e2e/models'const modelFile = `${opts.modelName}.gguf`const modelPath = `${MODELS_DIR}/${modelFile}`@@ -47,6 +80,52 @@ export function tauriMockInit(opts: TauriMockOptions) {// counter and the expert panel rely on.let engineCtx = 8192+ // ── MLX media surface (macOS local Create) ──────────────────────+ // Mirrors commands/mlx.rs + video.rs closely enough that specs can drive the+ // real install/generate flows. `opts.mlx` decides what the machine looks+ // like before the spec touches anything: a fresh Mac (nothing installed) or+ // a set-up one. Every install completes after MLX_INSTALL_POLLS polls, so a+ // spec can watch the panel go busy → done without arbitrary waits.+ const MLX_INSTALL_POLLS = 2+ const mlxImageCatalog = [+ { id: 'sd-turbo', name: 'SD Turbo', repo: 'stabilityai/sd-turbo', sizeGB: 2.6, minRamGB: 8, steps: 4, guidance: 0, defaultSize: 512, unfiltered: false, description: 'Fast 512px baseline.' },+ { id: 'realistic-vision-v51', name: 'Realistic Vision V5.1', repo: 'SG161222/Realistic_Vision_V5.1_noVAE', sizeGB: 4.4, minRamGB: 8, steps: 25, guidance: 7, defaultSize: 512, unfiltered: true, description: 'Photoreal, unfiltered.' },+ ]+ const mlxVideoCatalog = [+ { id: 'wan21-t2v-1.3b', name: 'Wan 2.1 T2V 1.3B', family: 'wan_2', repo: 'Wan-AI/Wan2.1-T2V-1.3B', sizeGB: 18, minRamGB: 16, defaultFrames: 33, needsConvert: true, unfiltered: true, description: 'Smallest local video model.' },+ ]+ const mlx = {+ engineInstalled: opts.mlx?.engineInstalled ?? true,+ videoEngineInstalled: opts.mlx?.videoEngineInstalled ?? true,+ images: new Set<string>(opts.mlx?.installedImages ?? ['sd-turbo']),+ videos: new Set<string>(opts.mlx?.installedVideos ?? ['wan21-t2v-1.3b']),+ }+ // One install slot per kind, exactly like the Rust side.+ const slot = { image: 0, imageEngine: 0, video: 0, videoEngine: 0 }+ let pendingImageId: string | null = null+ let pendingVideoId: string | null = null+ // 1x1 transparent PNG — enough for the gallery to render something real.+ const TINY_PNG =+ 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=='++ function record(bucket: string, entry: any) {+ ;(w[bucket] = w[bucket] || []).push(entry)+ }+ /** Advance an install slot; report 'complete' once it has been polled enough. */+ function installStatus(key: keyof typeof slot, extra?: Record<string, unknown>) {+ slot[key] += 1+ const done = slot[key] >= MLX_INSTALL_POLLS+ return {+ status: done ? 'complete' : 'installing',+ logs: done ? ['download complete', 'ready'] : ['starting…', 'downloading…'],+ error: null,+ download_progress: done ? 100 : 40,+ download_total: 100,+ download_speed: 1024 * 1024,+ ...extra,+ }+ }+const enc = (s: string) => Array.from(new TextEncoder().encode(s))// Ordered OpenAI SSE for one assistant turn, ending with [DONE].@@ -67,6 +146,10 @@ export function tauriMockInit(opts: TauriMockOptions) {}function router(cmd: string, args: any): Promise<any> {+ // The MLX wrappers (api/mlx-image.ts invokeMedia) nest their payload under+ // an `args` key to match the Rust `args: Value` signature — unwrap once so+ // the cases below read the fields the caller actually sent.+ const m = args?.args ?? args ?? {}switch (cmd) {// ── onboarding / lifecycle markers ────────────────────────────case 'is_onboarding_done':@@ -135,14 +218,124 @@ export function tauriMockInit(opts: TauriMockOptions) {// Real Rust returns a shaped object; a null default here trips// useActiveContextWindow (`info.loaded`). Return the "unknown" shape.return Promise.resolve({ loaded: null, max: null, state: null })+ case 'comfyui_status':+ // Recorded, not just refused: a Mac spec asserts this stays at zero.+ record('__E2E_COMFY_CALLS__', { cmd })+ return Promise.reject('not running (e2e)')case 'start_ollama':case 'lmstudio_server_status':- case 'comfyui_status':case 'whisper_status':case 'install_tts_status':case 'search_status':return Promise.reject('not running (e2e)')+ // ── MLX image (commands/mlx.rs) ───────────────────────────────+ case 'mlx_status':+ return Promise.resolve({+ installed: mlx.engineInstalled,+ running: mlx.engineInstalled,+ port: 47712,+ modelLoaded: false,+ modelRepo: null,+ idleSeconds: null,+ })+ case 'mlx_start':+ return Promise.resolve({ ok: true, port: 47712 })+ case 'mlx_unload':+ return Promise.resolve({ ok: true, was_loaded: false, running: true })+ case 'mlx_image_models':+ return Promise.resolve(mlxImageCatalog.map((m) => ({ ...m, installed: mlx.images.has(m.id) })))+ case 'install_mlx_diffusion':+ slot.imageEngine = 0+ return Promise.resolve({ ok: true, status: 'installing' })+ case 'install_mlx_diffusion_status': {+ const s = installStatus('imageEngine')+ if (s.status === 'complete') mlx.engineInstalled = true+ return Promise.resolve(s)+ }+ case 'mlx_image_install_model':+ slot.image = 0+ pendingImageId = m?.id ?? null+ record('__E2E_MLX_CALLS__', { cmd, id: m?.id })+ return Promise.resolve({ ok: true, status: 'installing', id: m?.id })+ case 'mlx_image_install_status': {+ const s = installStatus('image')+ if (s.status === 'complete' && pendingImageId) {+ mlx.images.add(pendingImageId)+ pendingImageId = null+ }+ return Promise.resolve(s)+ }+ case 'mlx_image_delete_model':+ mlx.images.delete(m?.id)+ record('__E2E_MLX_CALLS__', { cmd, id: m?.id })+ return Promise.resolve({ ok: true, id: m?.id })+ case 'mlx_generate':+ // The whole point of the Mac Create path: image renders come from+ // here, never from a ComfyUI workflow submit.+ record('__E2E_MLX_CALLS__', {+ cmd,+ prompt: m?.prompt,+ model: m?.model,+ steps: m?.steps,+ seed: m?.seed,+ width: m?.width,+ height: m?.height,+ })+ return Promise.resolve({ image_base64: TINY_PNG, width: m?.width ?? 512, height: m?.height ?? 512 })++ // ── MLX video (commands/video.rs) ─────────────────────────────+ case 'video_status':+ return Promise.resolve({+ available: mlx.videoEngineInstalled,+ appleSilicon: true,+ mlxInstalled: mlx.videoEngineInstalled,+ mlxVersion: mlx.videoEngineInstalled ? '0.4.0' : null,+ pythonBin: '/tmp/lu-e2e/venv/bin/python',+ modelsRoot: '/tmp/lu-e2e/mlx-video',+ outputsRoot: '/tmp/lu-e2e/videos',+ installedModels: [...mlx.videos],+ running: false,+ })+ case 'video_list_models':+ return Promise.resolve(mlxVideoCatalog.map((m) => ({ ...m, installed: mlx.videos.has(m.id) })))+ case 'video_install_mlx':+ slot.videoEngine = 0+ return Promise.resolve({ ok: true, status: 'installing' })+ case 'video_install_mlx_status': {+ const s = installStatus('videoEngine')+ if (s.status === 'complete') mlx.videoEngineInstalled = true+ return Promise.resolve(s)+ }+ case 'video_install_model':+ slot.video = 0+ pendingVideoId = m?.id ?? null+ record('__E2E_MLX_CALLS__', { cmd, id: args?.id })+ return Promise.resolve({ ok: true, status: 'installing', id: args?.id })+ case 'video_install_model_status': {+ const s = installStatus('video')+ if (s.status === 'complete' && pendingVideoId) {+ mlx.videos.add(pendingVideoId)+ pendingVideoId = null+ }+ return Promise.resolve(s)+ }+ case 'video_delete_model':+ mlx.videos.delete(m?.id)+ record('__E2E_MLX_CALLS__', { cmd, id: m?.id })+ return Promise.resolve({ ok: true, id: m?.id })+ case 'video_generate':+ record('__E2E_MLX_CALLS__', { cmd, id: m?.id, prompt: m?.prompt, seconds: m?.seconds })+ return Promise.resolve({ ok: true, jobId: 'e2e-vid', pid: 4242, output: '/tmp/lu-e2e/videos/e2e-vid.mp4' })+ case 'video_progress':+ // Completes on the first poll — specs assert the wiring, not patience.+ return Promise.resolve({ running: false, status: 'complete', logs: ['done'], error: null })+ case 'video_cancel':+ record('__E2E_MLX_CALLS__', { cmd })+ return Promise.resolve({ ok: true })+ case 'read_media_file':+ return Promise.resolve(`data:video/mp4;base64,${TINY_PNG}`)+// ── chat streaming: drive the onChunk Channel ─────────────────case 'proxy_localhost_stream_chunked': {const channel = args?.onChunkdiff --git a/src/components/layout/AppShell.tsx b/src/components/layout/AppShell.tsxindex 3203d5d6..51c715b9 100644--- a/src/components/layout/AppShell.tsx+++ b/src/components/layout/AppShell.tsx@@ -73,7 +73,10 @@ export function AppShell() {useEffect(() => {void (async () => {try {- const { backendCall, setComfyPort, setComfyHost } = await import('../../api/backend')+ const { backendCall, setComfyPort, setComfyHost, isMacOS } = await import('../../api/backend')+ // Not on the Mac: ComfyUI is never started and never renders there, so+ // mirroring its host/port can only teach the app a wrong address.+ if (isMacOS()) returnconst s = await backendCall<{ port?: number; host?: string }>('comfyui_status')if (typeof s?.port === 'number' && s.port > 0) setComfyPort(s.port)if (typeof s?.host === 'string' && s.host.trim()) setComfyHost(s.host)diff --git a/src/hooks/useCreate.ts b/src/hooks/useCreate.tsindex cd1be364..219e450c 100644--- a/src/hooks/useCreate.ts+++ b/src/hooks/useCreate.ts@@ -143,7 +143,15 @@ export function useCreate() {// `connected` to false is exactly what makes the Stage cover a working// MLX catalog with the ComfyUI "Download & install" card. Left at null// ("not applicable"), which every ComfyUI-gated surface treats as neutral.- const comfyOk = await checkComfyConnection()+ // On the Mac the answer is decided, not probed. ComfyUI is never started+ // there and never renders there, so asking port 8188 can only produce a+ // wrong answer: anything that happens to reply — a manual install, another+ // app — used to drag the whole tab into the ComfyUI path, where the model+ // queries then failed and left the store's list EMPTY while the picker+ // still displayed the MLX catalog. Pressing Create in that state said+ // "No image model selected. Add checkpoints or FLUX models to ComfyUI."+ // (caught by the MLX e2e, MAC-5.)+ const comfyOk = mlxHost ? false : await checkComfyConnection()if (!mlxHost) {setConnected(comfyOk)useCreateStore.getState().setComfyRunning(comfyOk)@@ -470,6 +478,18 @@ export function useCreate() {: []const localOpModel = localOp ? resolveLocalOpPick(state.localOpModel, localOpList) : ''+ // Chip↔run agreement for IMAGE, the same rule the video path already+ // applies further down. ModelChip shows `list[0]` whenever the stored pick+ // isn't in the current list — which includes the empty pick a fresh+ // profile has. Reading the raw store here meant a first-run Mac saw+ // "MLX SD Turbo" in the picker, pressed Create, and got+ // "No image model selected. Add checkpoints or FLUX models to ComfyUI."+ // — a ComfyUI message on the one platform that never runs ComfyUI.+ const effImageModel =+ state.imageModelList.some((m) => m.name === imageModel)+ ? imageModel+ : (state.imageModelList[0]?.name ?? imageModel)+// ── MLX image pipeline (Apple Silicon) — hard rule: Mac local image is the// in-process MLX path, never ComfyUI. Gated on the derived `image` intent// (which already means: no cloudOp, no utilityOp, no removebg, text2img)@@ -477,7 +497,7 @@ export function useCreate() {// checkpoint from a manual install is never hijacked. Generation returns a// base64 PNG stored as a data URL on the gallery item, so display +// download work with no ComfyUI /view route. ──- if (intent === 'image' && isMlxImageHost() && isMlxImageModel(imageModel)) {+ if (intent === 'image' && isMlxImageHost() && isMlxImageModel(effImageModel)) {setError(null)if (!prompt.trim()) { setError('Please enter a prompt.'); return }setIsGenerating(true)@@ -490,7 +510,7 @@ export function useCreate() {setProgress(40, 'Generating with MLX...')const { dataUrl, width: outW, height: outH } = await generateMlxImageDataUrl({prompt, steps, seed, width, height,- model: mlxModelIdFor(imageModel),+ model: mlxModelIdFor(effImageModel),negativePrompt: negativePrompt || undefined,})const elapsed = Math.round((Date.now() - startTime) / 1000)@@ -636,7 +656,7 @@ export function useCreate() {}setError(null)- let activeModel = localOp ? localOpModel : (mode === 'image' ? imageModel : videoModel)+ let activeModel = localOp ? localOpModel : (mode === 'image' ? effImageModel : videoModel)// Chip↔run agreement (live-caught on the extend E2E): the picker DISPLAYS// the first capable model when the stored pick can't run the current// intent, but submit read the raw store — the run then used a model the