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
feat(create): LoRA strength from -10 to 10 with a number field per LoRA
purplec669f6e07359
diff --git a/e2e/lora-stack-follows-the-folder.spec.ts b/e2e/lora-stack-follows-the-folder.spec.tsindex b8c305c0..ce4c4ad2 100644--- a/e2e/lora-stack-follows-the-folder.spec.ts+++ b/e2e/lora-stack-follows-the-folder.spec.ts@@ -76,7 +76,21 @@ test('picks whose files are gone leave the stack, the count matches what is tickawait expect(page.getByText('· 1 active')).toBeVisible()// Gegenprobe 8: the strength reads as a number.await expect(page.getByText('Strength')).toBeVisible()- await expect(page.getByText('0.80', { exact: true })).toBeVisible()+ const strength = page.getByRole('textbox', { name: 'Strength of film_grain_xl' })+ await expect(strength).toHaveValue('0.80')+ // Discord 2026-10-02 (throwaway050558): the number can be typed, negative+ // and beyond the slider's 0 to 2, and more than 10 stops at 10.+ await strength.fill('-4')+ await strength.blur()+ await expect(strength).toHaveValue('-4.00')+ await expect.poll(() => saved(page)).toEqual([{ name: STYLE, strength: -4 }])+ await strength.fill('abc')+ await strength.blur()+ await expect(strength).toHaveValue('-4.00')+ await strength.fill('25')+ await strength.blur()+ await expect(strength).toHaveValue('10.00')+ await expect.poll(() => saved(page)).toEqual([{ name: STYLE, strength: 10 }])await page.evaluate(() => { (window as unknown as { __LORAS__: string[] }).__LORAS__ = [] })await page.getByRole('button', { name: /Rescan/ }).click()await expect(page.getByText(/active/)).toHaveCount(0)diff --git a/src/api/__tests__/lora-strength-reaches-every-graph.test.ts b/src/api/__tests__/lora-strength-reaches-every-graph.test.tsnew file mode 100644index 00000000..c718c772--- /dev/null+++ b/src/api/__tests__/lora-strength-reaches-every-graph.test.ts@@ -0,0 +1,122 @@+/**+ * The LoRA strength the stack holds is the number in the graph ComfyUI gets,+ * on every path that loads a LoRA (Discord 2026-10-02, throwaway050558: LoRAs+ * made for -10 to 10, negative included).+ *+ * There are three such paths in dynamic-workflow.ts:+ * - the standard one, LoraLoader, for every checkpoint and UNET family+ * (SDXL, Krea 2, Z-Image, FLUX, Wan 2.1, Hunyuan, LTX, Mochi, Cosmos),+ * - Wan 2.2, LoraLoaderModelOnly,+ * - MiniMax H3, LoraLoaderModelOnly.+ * ComfyUI's nodes.py declares strength_model and strength_clip on both nodes+ * with min -100 and max 100, so -10 to 10 is valid input.+ *+ * Run: npx vitest run src/api/__tests__/lora-strength-reaches-every-graph.test.ts+ */+import { describe, it, expect, vi, beforeEach } from 'vitest'++vi.mock('../comfyui-nodes', async (importOriginal) => {+ const actual = await importOriginal<typeof import('../comfyui-nodes')>()+ return { ...actual, getAllNodeInfo: vi.fn() }+})+vi.mock('../backend', async (importOriginal) => {+ const actual = await importOriginal<typeof import('../backend')>()+ return { ...actual, localFetch: vi.fn(), comfyuiUrl: (p: string) => `http://test${p}` }+})++import { buildDynamicWorkflow, normalizeLoraStrengths } from '../dynamic-workflow'+import { getAllNodeInfo } from '../comfyui-nodes'+import { localFetch } from '../backend'+import { nodesOf } from './graph-test-support'+import { LORA_STRENGTH_MAX, LORA_STRENGTH_MIN } from '../../lib/lora-strength'++const LORAS = ['slider_age.safetensors', 'slider_detail.safetensors', 'style.safetensors']+const STRENGTHS = [LORA_STRENGTH_MIN, LORA_STRENGTH_MAX, -0.35]+const empty = { input: { required: {} } }+const combo = (key: string, values: string[]) => ({ input: { required: { [key]: [values] } } })++function serve(nodes: Record<string, unknown>, clips: string[], vaes: string[]) {+ vi.mocked(getAllNodeInfo).mockResolvedValue(nodes as never)+ vi.mocked(localFetch).mockResolvedValue({+ ok: true,+ json: async () => ({ CLIPLoader: combo('clip_name', clips), VAELoader: combo('vae_name', vaes) }),+ } as never)+}++const image = (model: string, extra: Record<string, unknown> = {}) => ({+ model, prompt: 'a portrait', negativePrompt: '', sampler: 'euler', scheduler: 'simple',+ steps: 8, cfgScale: 1, width: 1024, height: 1024, seed: 3, batchSize: 1,+ lora: LORAS, loraStrength: STRENGTHS, ...extra,+}) as never++/** The strengths in chain order, read off the nodes the builder wrote. */+function strengthsIn(wf: Awaited<ReturnType<typeof buildDynamicWorkflow>>, klass: string, key: string): unknown[] {+ const byName = new Map(nodesOf(wf, klass).map(([, n]) => [n.inputs.lora_name, n.inputs[key]]))+ return LORAS.map((l) => byName.get(l))+}++beforeEach(() => { vi.clearAllMocks() })++describe('nothing between the stack and the graph narrows the strength', () => {+ it('normalizeLoraStrengths keeps -10, 10 and a negative fraction as they are', () => {+ expect(normalizeLoraStrengths(STRENGTHS, 3)).toEqual([-10, 10, -0.35])+ expect(normalizeLoraStrengths(-10, 2)).toEqual([-10, -10])+ })+})++describe('the standard path, LoraLoader', () => {+ it('SDXL checkpoint: model and clip side both carry the value', async () => {+ serve({+ CheckpointLoaderSimple: combo('ckpt_name', ['Juggernaut-XL_v9.safetensors']),+ LoraLoader: combo('lora_name', LORAS),+ KSampler: empty, EmptyLatentImage: empty, CLIPTextEncode: empty, VAEDecode: empty, SaveImage: empty,+ }, [], [])+ const wf = await buildDynamicWorkflow(image('Juggernaut-XL_v9.safetensors', { steps: 20, cfgScale: 7 }))+ expect(strengthsIn(wf, 'LoraLoader', 'strength_model')).toEqual([-10, 10, -0.35])+ expect(strengthsIn(wf, 'LoraLoader', 'strength_clip')).toEqual([-10, 10, -0.35])+ })++ it('Krea 2 (UNET family): the same values on the same node', async () => {+ serve({+ UNETLoader: combo('unet_name', ['krea2-lustify-v10.safetensors']),+ CLIPLoader: { input: { required: { clip_name: [['qwen3vl_4b.safetensors']], type: [['krea2']] } } },+ VAELoader: combo('vae_name', ['krea_vae.safetensors']),+ LoraLoader: combo('lora_name', LORAS),+ ConditioningZeroOut: empty, EmptyLatentImage: empty, KSampler: empty, CLIPTextEncode: empty, VAEDecode: empty, SaveImage: empty,+ }, ['qwen3vl_4b.safetensors'], ['krea_vae.safetensors'])+ const wf = await buildDynamicWorkflow(image('krea2-lustify-v10.safetensors'))+ expect(strengthsIn(wf, 'LoraLoader', 'strength_model')).toEqual([-10, 10, -0.35])+ expect(strengthsIn(wf, 'LoraLoader', 'strength_clip')).toEqual([-10, 10, -0.35])+ })+})++describe('the video paths, LoraLoaderModelOnly', () => {+ it('Wan 2.2', async () => {+ serve({+ UNETLoader: combo('unet_name', ['wan2.2_ti2v_5B_fp16.safetensors']),+ CLIPLoader: combo('clip_name', ['umt5_xxl_fp8_e4m3fn_scaled.safetensors']),+ VAELoader: combo('vae_name', ['wan2.2_vae.safetensors']),+ Wan22ImageToVideoLatent: { input: { required: { vae: ['VAE'], width: ['INT'], height: ['INT'], length: ['INT'], batch_size: ['INT'] }, optional: { start_image: ['IMAGE', {}] } } },+ ModelSamplingSD3: empty, KSampler: empty, CLIPTextEncode: empty, VAEDecode: empty, ImageScale: empty, LoadImage: empty, VHS_VideoCombine: empty,+ }, ['umt5_xxl_fp8_e4m3fn_scaled.safetensors'], ['wan2.2_vae.safetensors'])+ const wf = await buildDynamicWorkflow(image('wan2.2_ti2v_5B_fp16.safetensors', { steps: 30, cfgScale: 5, width: 1024, height: 576, frames: 49, fps: 24 }))+ expect(strengthsIn(wf, 'LoraLoaderModelOnly', 'strength_model')).toEqual([-10, 10, -0.35])+ })++ it('MiniMax H3', async () => {+ const model = 'minimax_h3_fl2va_pruned_int8_convrot.safetensors'+ const vaes = ['minimax_h3_video_vae_int8_convrot.safetensors', 'minimax_h3_audio_vae_fp32.safetensors']+ const clips = ['qwen3vl_32b_minimax_h3_nvfp4_awq.safetensors']+ serve({+ UNETLoader: combo('unet_name', [model]), CLIPLoader: combo('clip_name', clips), VAELoader: combo('vae_name', vaes),+ LoraLoaderModelOnly: empty, MiniMaxH3ImageToVideo: empty, MiniMaxH3ReferenceToVideo: empty,+ BasicGuider: empty, BasicScheduler: empty, KSamplerSelect: empty, RandomNoise: empty, SamplerCustomAdvanced: empty,+ VAEDecode: empty, VAEDecodeAudio: empty, LoadImage: empty, ImageScale: empty, CreateVideo: empty, SaveVideo: empty,+ }, clips, vaes)+ const wf = await buildDynamicWorkflow(+ image(model, { sampler: 'res_multistep', steps: 20, width: 1344, height: 768, frames: 124, fps: 24 }),+ 'minimaxh3',+ )+ expect(strengthsIn(wf, 'LoraLoaderModelOnly', 'strength_model')).toEqual([-10, 10, -0.35])+ })+})diff --git a/src/components/create/experimental/LoraStrength.tsx b/src/components/create/experimental/LoraStrength.tsxnew file mode 100644index 00000000..7fdc8860--- /dev/null+++ b/src/components/create/experimental/LoraStrength.tsx@@ -0,0 +1,73 @@+import { useId, useState } from 'react'+import { Slider } from '../ui/Slider'+import {+ LORA_SLIDER_MAX, LORA_SLIDER_MIN, LORA_STRENGTH_MAX, LORA_STRENGTH_MIN, LORA_STRENGTH_STEP,+ parseLoraStrength, stepLoraStrength,+} from '../../../lib/lora-strength'++interface Props {+ /** The LoRA file this strength belongs to, for the field's accessible name. */+ name: string+ value: number+ onChange: (v: number) => void+}++const shown = (v: number) => v.toFixed(2)++/**+ * The strength of one LoRA in the stack: the slider for the usual 0 to 2 and+ * a number field for the exact value, which also takes what the slider cannot+ * reach (Discord 2026-10-02, throwaway050558: slider LoRAs for Krea 2 are made+ * for about -10 to 10, negative included).+ *+ * The field is a text input on purpose. While someone types, "-" and "1," are+ * not numbers yet, and a number input hands those back as an empty string, so+ * the half-typed value could not be kept. What is typed is applied as soon as+ * it reads as a number; leaving the field shows the applied value again, so a+ * typo never stays on screen as if it counted.+ */+export function LoraStrength({ name, value, onChange }: Props) {+ const id = useId()+ const [draft, setDraft] = useState<string | null>(null)+ const label = name.replace(/^.*[\\/]/, '').replace(/\.safetensors$/i, '')+ return (+ <div className="space-y-1.5">+ <div className="flex items-center justify-between gap-2">+ <label htmlFor={id} className="t-control text-gray-400">Strength</label>+ <input+ id={id}+ type="text"+ inputMode="decimal"+ autoComplete="off"+ spellCheck={false}+ aria-label={`Strength of ${label}`}+ title={`${LORA_STRENGTH_MIN} to ${LORA_STRENGTH_MAX}`}+ value={draft ?? shown(value)}+ onFocus={(e) => { setDraft(shown(value)); e.target.select() }}+ onChange={(e) => {+ setDraft(e.target.value)+ const typed = parseLoraStrength(e.target.value)+ if (typed !== null) onChange(typed)+ }}+ onBlur={() => setDraft(null)}+ onKeyDown={(e) => {+ if (e.key === 'Enter') { e.currentTarget.blur(); return }+ if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown') return+ e.preventDefault()+ const next = stepLoraStrength(value, e.key === 'ArrowUp' ? 1 : -1)+ onChange(next)+ setDraft(shown(next))+ }}+ className="w-16 h-6 px-1.5 rounded-[var(--radius-control)] bg-white/[0.04] border border-white/[0.08] focus:border-white/20 outline-none text-right t-mono text-gray-200"+ />+ </div>+ <Slider+ min={LORA_SLIDER_MIN}+ max={LORA_SLIDER_MAX}+ step={LORA_STRENGTH_STEP}+ value={Math.max(LORA_SLIDER_MIN, Math.min(LORA_SLIDER_MAX, value))}+ onChange={onChange}+ />+ </div>+ )+}diff --git a/src/components/create/experimental/ParamGroups.tsx b/src/components/create/experimental/ParamGroups.tsxindex 52ccd616..dbd6ccdb 100644--- a/src/components/create/experimental/ParamGroups.tsx+++ b/src/components/create/experimental/ParamGroups.tsx@@ -18,6 +18,7 @@ import { Tooltip } from '../ui/Tooltip'import { cn } from '../ui/cn'import { HINWEIS_TEXT } from '../../../lib/hinweis'import { lorasForRun, loraFitsModel } from '../../../lib/lora-stack'+import { LoraStrength } from './LoraStrength'import { supportsTransparent } from '../../../lib/transparent-image'import { MAX_SHOTS, MAX_SHOT_CHARS, supportsMultishot } from '../../../lib/ltx-multishot'@@ -326,7 +327,7 @@ export function ParamGroups() {</button>{active && fits && (<div className="px-2.5 pb-2">- <Slider label="Strength" min={0} max={2} step={0.05} value={active.strength} onChange={(v) => s.setLoraStrengthFor(name, v)} format={(v) => v.toFixed(2)} />+ <LoraStrength name={name} value={active.strength} onChange={(v) => s.setLoraStrengthFor(name, v)} /></div>)}</div>diff --git a/src/components/create/experimental/__tests__/lora-strength-feld.test.tsx b/src/components/create/experimental/__tests__/lora-strength-feld.test.tsxnew file mode 100644index 00000000..fb02ffb1--- /dev/null+++ b/src/components/create/experimental/__tests__/lora-strength-feld.test.tsx@@ -0,0 +1,137 @@+/**+ * @vitest-environment jsdom+ *+ * The number field beside the LoRA strength slider (Discord 2026-10-02,+ * throwaway050558): exact values, negative ones, and the wide range the slider+ * does not reach. Measured on the rendered control.+ *+ * Run: npx vitest run src/components/create/experimental/__tests__/lora-strength-feld.test.tsx+ */+import { describe, it, expect, afterEach } from 'vitest'+import { useState } from 'react'+import { render, screen, fireEvent, cleanup } from '@testing-library/react'+import { readFileSync } from 'node:fs'+import { resolve } from 'node:path'+import { LoraStrength } from '../LoraStrength'++const NAME = 'styles/krea2_slider_age.safetensors'+const seen: number[] = []++function Harness({ start = 0.8 }: { start?: number }) {+ const [value, setValue] = useState(start)+ return <LoraStrength name={NAME} value={value} onChange={(v) => { seen.push(v); setValue(v) }} />+}++const field = () => screen.getByRole('textbox', { name: 'Strength of krea2_slider_age' }) as HTMLInputElement+const slider = () => screen.getByRole('slider') as HTMLInputElement+const type = (text: string) => fireEvent.change(field(), { target: { value: text } })++afterEach(() => { cleanup(); seen.length = 0 })++describe('the number field', () => {+ it('shows the value with two decimals and is named after its LoRA', () => {+ render(<Harness />)+ expect(field().value).toBe('0.80')+ expect(screen.getByText('Strength')).toBeTruthy()+ })++ it('a typed value is applied, a negative one too', () => {+ render(<Harness />)+ fireEvent.focus(field())+ type('-4')+ expect(seen.at(-1)).toBe(-4)+ fireEvent.blur(field())+ expect(field().value).toBe('-4.00')+ })++ it('typing a negative number digit by digit never loses the minus', () => {+ render(<Harness />)+ fireEvent.focus(field())+ type('-')+ expect(field().value).toBe('-')+ expect(seen).toEqual([])+ type('-7')+ type('-7.')+ expect(field().value).toBe('-7.')+ type('-7.5')+ expect(seen.at(-1)).toBe(-7.5)+ })++ it('the ends are -10 and 10: more is pulled back, and the field says so on leaving', () => {+ render(<Harness />)+ fireEvent.focus(field())+ type('15')+ expect(seen.at(-1)).toBe(10)+ expect(field().value).toBe('15')+ fireEvent.blur(field())+ expect(field().value).toBe('10.00')+ fireEvent.focus(field())+ type('-250')+ fireEvent.blur(field())+ expect(seen.at(-1)).toBe(-10)+ expect(field().value).toBe('-10.00')+ })++ it('a typo changes nothing and is gone when the field is left', () => {+ render(<Harness start={1.25} />)+ fireEvent.focus(field())+ for (const typo of ['abc', '1.2.3', '', '1e3', '--2']) {+ type(typo)+ expect(field().value).toBe(typo)+ }+ expect(seen).toEqual([])+ fireEvent.blur(field())+ expect(field().value).toBe('1.25')+ })++ it('a decimal comma counts', () => {+ render(<Harness />)+ fireEvent.focus(field())+ type('1,5')+ expect(seen.at(-1)).toBe(1.5)+ })++ it('arrow keys step by 0.05, below zero as well, and stop at the ends', () => {+ render(<Harness start={0} />)+ fireEvent.focus(field())+ fireEvent.keyDown(field(), { key: 'ArrowDown' })+ expect(seen.at(-1)).toBe(-0.05)+ expect(field().value).toBe('-0.05')+ fireEvent.keyDown(field(), { key: 'ArrowUp' })+ fireEvent.keyDown(field(), { key: 'ArrowUp' })+ expect(seen.at(-1)).toBe(0.05)+ cleanup()+ render(<Harness start={10} />)+ fireEvent.keyDown(field(), { key: 'ArrowUp' })+ expect(seen.at(-1)).toBe(10)+ })+})++describe('the slider next to it', () => {+ it('covers the usual 0 to 2 in steps of 0.05 and writes into the same value', () => {+ render(<Harness />)+ expect([slider().min, slider().max, slider().step]).toEqual(['0', '2', '0.05'])+ fireEvent.change(slider(), { target: { value: '1.35' } })+ expect(seen.at(-1)).toBe(1.35)+ expect(field().value).toBe('1.35')+ })++ it('rests at its end when the typed value is beyond it, the field keeps the truth', () => {+ render(<Harness start={-6} />)+ expect(slider().value).toBe('0')+ expect(field().value).toBe('-6.00')+ cleanup()+ render(<Harness start={8} />)+ expect(slider().value).toBe('2')+ expect(field().value).toBe('8.00')+ })+})++describe('the LoRA stack', () => {+ it('draws this control for every active LoRA and writes into the store per name', () => {+ const src = readFileSync(resolve(__dirname, '..', 'ParamGroups.tsx'), 'utf8')+ expect(src).toMatch(/<LoraStrength name=\{name\} value=\{active\.strength\} onChange=\{\(v\) => s\.setLoraStrengthFor\(name, v\)\} \/>/)+ // The old slider that stopped at 2 is gone, not kept beside it.+ expect(src).not.toMatch(/label="Strength"/)+ })+})diff --git a/src/lib/__tests__/lora-strength.test.ts b/src/lib/__tests__/lora-strength.test.tsnew file mode 100644index 00000000..b77ddc24--- /dev/null+++ b/src/lib/__tests__/lora-strength.test.ts@@ -0,0 +1,96 @@+/**+ * The strength of a LoRA in the stack (Discord 2026-10-02, throwaway050558).+ * The stack stopped at 0 to 2; slider LoRAs, the Krea 2 ones above all, are+ * made for about -10 to 10. ComfyUI itself takes -100 to 100 on LoraLoader+ * and LoraLoaderModelOnly (nodes.py, strength_model and strength_clip).+ *+ * Run: npx vitest run src/lib/__tests__/lora-strength.test.ts+ */+import { describe, it, expect } from 'vitest'+import {+ LORA_STRENGTH_MAX, LORA_STRENGTH_MIN, LORA_STRENGTH_STEP, LORA_SLIDER_MAX, LORA_SLIDER_MIN,+ clampLoraStrength, defaultLoraStrength, parseLoraStrength, stepLoraStrength,+} from '../lora-strength'++describe('the range', () => {+ it('is -10 to 10 in steps of 0.05, inside what ComfyUI accepts, and the slider keeps 0 to 2', () => {+ expect([LORA_STRENGTH_MIN, LORA_STRENGTH_MAX, LORA_STRENGTH_STEP]).toEqual([-10, 10, 0.05])+ expect(LORA_STRENGTH_MIN).toBeGreaterThanOrEqual(-100)+ expect(LORA_STRENGTH_MAX).toBeLessThanOrEqual(100)+ expect([LORA_SLIDER_MIN, LORA_SLIDER_MAX]).toEqual([0, 2])+ })++ it('clamps at both ends and keeps two decimals', () => {+ expect(clampLoraStrength(10)).toBe(10)+ expect(clampLoraStrength(10.01)).toBe(10)+ expect(clampLoraStrength(250)).toBe(10)+ expect(clampLoraStrength(-10)).toBe(-10)+ expect(clampLoraStrength(-10.01)).toBe(-10)+ expect(clampLoraStrength(-999)).toBe(-10)+ expect(clampLoraStrength(0.8)).toBe(0.8)+ expect(clampLoraStrength(-3.456)).toBe(-3.46)+ expect(clampLoraStrength(1.2345)).toBe(1.23)+ })++ it('never hands out a negative zero', () => {+ expect(Object.is(clampLoraStrength(-0.001), 0)).toBe(true)+ expect(Object.is(clampLoraStrength(-0), 0)).toBe(true)+ })+})++describe('what a typed strength means', () => {+ it('plain numbers, negative ones included', () => {+ expect(parseLoraStrength('1')).toBe(1)+ expect(parseLoraStrength('0.85')).toBe(0.85)+ expect(parseLoraStrength('-4')).toBe(-4)+ expect(parseLoraStrength('-0.35')).toBe(-0.35)+ expect(parseLoraStrength('+2.5')).toBe(2.5)+ expect(parseLoraStrength('.5')).toBe(0.5)+ expect(parseLoraStrength('-.5')).toBe(-0.5)+ expect(parseLoraStrength('3.')).toBe(3)+ expect(parseLoraStrength(' 7 ')).toBe(7)+ expect(parseLoraStrength('0')).toBe(0)+ })++ it('a decimal comma is a point', () => {+ expect(parseLoraStrength('1,5')).toBe(1.5)+ expect(parseLoraStrength('-2,25')).toBe(-2.25)+ })++ it('out of range is pulled to the nearest end', () => {+ expect(parseLoraStrength('15')).toBe(10)+ expect(parseLoraStrength('-15')).toBe(-10)+ expect(parseLoraStrength('99999999999999999999')).toBe(10)+ })++ it('half typed values and typos are not a number', () => {+ for (const typo of ['', ' ', '-', '+', '.', '-.', ',', 'abc', '1.2.3', '1,2,3', '1e3', '--1', '1-', '0x10', 'NaN', 'Infinity', '1 2', '1.5x']) {+ expect(parseLoraStrength(typo), JSON.stringify(typo)).toBeNull()+ }+ })+})++describe('the arrow keys', () => {+ it('move by one step without float dust, and stop at the ends', () => {+ expect(stepLoraStrength(0.8, 1)).toBe(0.85)+ expect(stepLoraStrength(0.8, -1)).toBe(0.75)+ expect(stepLoraStrength(0, -1)).toBe(-0.05)+ expect(stepLoraStrength(-0.05, 1)).toBe(0)+ expect(stepLoraStrength(0.1, 1)).toBe(0.15)+ expect(stepLoraStrength(10, 1)).toBe(10)+ expect(stepLoraStrength(-10, -1)).toBe(-10)+ })+})++describe('the strength a LoRA starts with', () => {+ it('a step distillation starts at 1, the way the official H3 templates load it', () => {+ expect(defaultLoraStrength('minimax_h3_fl2v_turbo_8step_v1.0_comfyui_bf16.safetensors')).toBe(1)+ expect(defaultLoraStrength('minimax_h3_fl2v_turbo_4step_v1.0_768p_comfyui_bf16.safetensors')).toBe(1)+ })++ it('everything else starts at 0.8, a model that merely says turbo too', () => {+ expect(defaultLoraStrength('film_grain_xl.safetensors')).toBe(0.8)+ expect(defaultLoraStrength('char_mira_zimage.safetensors')).toBe(0.8)+ expect(defaultLoraStrength('z_image_turbo_style.safetensors')).toBe(0.8)+ })+})diff --git a/src/lib/lora-strength.ts b/src/lib/lora-strength.tsnew file mode 100644index 00000000..8fd907c6--- /dev/null+++ b/src/lib/lora-strength.ts@@ -0,0 +1,50 @@+// The strength of one LoRA in the stack: the range, the typed number and the+// starting value. Pure, no imports, so the store, the control and the tests+// read the same rules.++/** What the stack lets through. ComfyUI's LoraLoader and LoraLoaderModelOnly+ * take strength_model and strength_clip from -100 to 100 in steps of 0.01+ * (nodes.py), and say themselves that the value can be negative. Slider LoRAs+ * are made for a wide range around zero (Discord 2026-10-02, throwaway050558:+ * Krea 2 LoRAs meant for -10 to 10), so the number field takes that range.+ * The slider keeps the usual 0 to 2. */+export const LORA_STRENGTH_MIN = -10+export const LORA_STRENGTH_MAX = 10+export const LORA_STRENGTH_STEP = 0.05+export const LORA_SLIDER_MIN = 0+export const LORA_SLIDER_MAX = 2++/** Into the allowed range, on ComfyUI's own grid of 0.01. */+export function clampLoraStrength(value: number): number {+ const v = Math.max(LORA_STRENGTH_MIN, Math.min(LORA_STRENGTH_MAX, value))+ // "+ 0" turns a negative zero into a plain one.+ return Math.round(v * 100) / 100 + 0+}++/**+ * What a typed strength means, or null when it is not a number yet ("", "-",+ * "abc", "1.2.3"). A decimal comma counts as a point. A number outside+ * the range is pulled to its nearest end, never thrown away.+ */+export function parseLoraStrength(text: string): number | null {+ const t = text.trim().replace(',', '.')+ if (!/^[+-]?(\d+\.?\d*|\.\d+)$/.test(t)) return null+ const n = Number(t)+ return Number.isFinite(n) ? clampLoraStrength(n) : null+}++/** One step up or down from a value, for the arrow keys of the number field. */+export function stepLoraStrength(value: number, direction: 1 | -1): number {+ return clampLoraStrength(value + direction * LORA_STRENGTH_STEP)+}++/**+ * The strength a LoRA starts with when it is ticked for the first time. A+ * step distillation only does its job at full strength: the official MiniMax+ * H3 templates (video_minimax_h3_t2v and _i2v) load the turbo LoRA at 1. The+ * name test is the one the H3 builder reads the step count with+ * (minimax_h3_fl2v_turbo_8step_...). Everything else starts at the usual 0.8.+ */+export function defaultLoraStrength(name: string): number {+ return /turbo\D*?\d+\s*_?steps?/i.test(name) ? 1 : 0.8+}diff --git a/src/stores/__tests__/lora-strength-je-lora.test.ts b/src/stores/__tests__/lora-strength-je-lora.test.tsnew file mode 100644index 00000000..694d18fb--- /dev/null+++ b/src/stores/__tests__/lora-strength-je-lora.test.ts@@ -0,0 +1,101 @@+/**+ * The stack keeps one strength per LoRA, from -10 to 10, and remembers it+ * while the LoRA is off (Discord 2026-10-02, throwaway050558).+ *+ * Run: npx vitest run src/stores/__tests__/lora-strength-je-lora.test.ts+ */+import { describe, it, expect, beforeEach } from 'vitest'+import { useCreateStore } from '../createStore'++const A = 'krea2_slider_age.safetensors'+const B = 'film_grain_xl.safetensors'+const TURBO = 'minimax_h3_fl2v_turbo_8step_v1.0_comfyui_bf16.safetensors'++const s = () => useCreateStore.getState()+const strengthOf = (name: string) => s().selectedLoras.find((l) => l.name === name)?.strength++beforeEach(() => {+ useCreateStore.setState({ selectedLoras: [], loraStrengths: {} })+})++describe('the range the store lets through', () => {+ it('takes negative and wide values, which the old 0 to 2 clamp cut off', () => {+ s().toggleLora(A)+ s().setLoraStrengthFor(A, -4)+ expect(strengthOf(A)).toBe(-4)+ s().setLoraStrengthFor(A, 7.5)+ expect(strengthOf(A)).toBe(7.5)+ s().setLoraStrengthFor(A, -10)+ expect(strengthOf(A)).toBe(-10)+ s().setLoraStrengthFor(A, 10)+ expect(strengthOf(A)).toBe(10)+ })++ it('pulls anything further out to the ends and ignores what is not a number', () => {+ s().toggleLora(A)+ s().setLoraStrengthFor(A, 42)+ expect(strengthOf(A)).toBe(10)+ s().setLoraStrengthFor(A, -42)+ expect(strengthOf(A)).toBe(-10)+ s().setLoraStrengthFor(A, 1.5)+ s().setLoraStrengthFor(A, Number.NaN)+ s().setLoraStrengthFor(A, Number.POSITIVE_INFINITY)+ expect(strengthOf(A)).toBe(1.5)+ })+})++describe('one value per LoRA', () => {+ it('each LoRA has its own strength', () => {+ s().toggleLora(A)+ s().toggleLora(B)+ s().setLoraStrengthFor(A, -3)+ s().setLoraStrengthFor(B, 1.2)+ expect(s().selectedLoras).toEqual([{ name: A, strength: -3 }, { name: B, strength: 1.2 }])+ })++ it('off and on again brings the own value back, not the default', () => {+ s().toggleLora(A)+ s().setLoraStrengthFor(A, -6.5)+ s().toggleLora(A)+ expect(s().selectedLoras).toEqual([])+ s().toggleLora(A)+ expect(strengthOf(A)).toBe(-6.5)+ })++ it('Clear keeps the remembered values too', () => {+ s().toggleLora(A)+ s().setLoraStrengthFor(A, 3)+ s().clearLoras()+ s().toggleLora(A)+ expect(strengthOf(A)).toBe(3)+ })++ it('a file that is gone takes its remembered value with it', () => {+ s().toggleLora(A)+ s().setLoraStrengthFor(A, 3)+ s().toggleLora(B)+ s().setLoraStrengthFor(B, 0.5)+ s().toggleLora(A)+ s().keepListedLoras([B])+ expect(s().loraStrengths).toEqual({ [B]: 0.5 })+ expect(s().selectedLoras).toEqual([{ name: B, strength: 0.5 }])+ // Same name dropped in again later: a new file, the default.+ s().toggleLora(A)+ expect(strengthOf(A)).toBe(0.8)+ })++ it('a first tick starts at 0.8, the H3 turbo LoRA at 1', () => {+ s().toggleLora(B)+ s().toggleLora(TURBO)+ expect(strengthOf(B)).toBe(0.8)+ expect(strengthOf(TURBO)).toBe(1)+ })++ it('the remembered values are saved with the stack', () => {+ s().toggleLora(A)+ s().setLoraStrengthFor(A, -2)+ const saved = useCreateStore.persist.getOptions().partialize?.(s()) as { selectedLoras: unknown; loraStrengths: unknown }+ expect(saved.selectedLoras).toEqual([{ name: A, strength: -2 }])+ expect(saved.loraStrengths).toEqual({ [A]: -2 })+ })+})diff --git a/src/stores/createStore.ts b/src/stores/createStore.tsindex f7615a4c..47fb4eaa 100644--- a/src/stores/createStore.ts+++ b/src/stores/createStore.ts@@ -31,6 +31,7 @@ const RUNTIME_ONLY_KEYS: readonly string[] = []import type { ModelType, ClassifiedModel } from '../api/comfyui'import { MAX_SHOTS, MAX_SHOT_CHARS } from '../lib/ltx-multishot'+import { clampLoraStrength, defaultLoraStrength } from '../lib/lora-strength'import { classifyModel, hidreamSampling } from '../api/comfyui'import type { HiresUpscaleMethod } from '../api/hires-fix'import { releaseVideoBlobUrl } from '../api/mlx-video'@@ -349,6 +350,9 @@ interface CreateState {targetResolution: '2k' | '4k' | '8k'showNegative: booleanselectedLoras: { name: string; strength: number }[]+ /** The last strength set for each LoRA file, kept while the LoRA is off, so+ * ticking it again brings its own value back instead of the default. */+ loraStrengths: Record<string, number>selectedVae: stringclipSkip: numbergrowMaskBy: number // inpaint mask edge feather (VAEEncodeForInpaint grow_mask_by)@@ -698,6 +702,7 @@ export const useCreateStore = create<CreateState>()(targetResolution: '4k' as '2k' | '4k' | '8k',showNegative: false,selectedLoras: [] as { name: string; strength: number }[],+ loraStrengths: {} as Record<string, number>,selectedVae: 'auto',clipSkip: 0,growMaskBy: 6,@@ -902,8 +907,15 @@ export const useCreateStore = create<CreateState>()(if (changed) set({ cloudStudioOptions: {} })},toggleNegative: () => set((s) => ({ showNegative: !s.showNegative })),- toggleLora: (name) => set((s) => ({ selectedLoras: s.selectedLoras.some((l) => l.name === name) ? s.selectedLoras.filter((l) => l.name !== name) : [...s.selectedLoras, { name, strength: 0.8 }] })),- setLoraStrengthFor: (name, strength) => set((s) => ({ selectedLoras: s.selectedLoras.map((l) => l.name === name ? { ...l, strength: Math.max(0, Math.min(2, strength)) } : l) })),+ toggleLora: (name) => set((s) => ({ selectedLoras: s.selectedLoras.some((l) => l.name === name) ? s.selectedLoras.filter((l) => l.name !== name) : [...s.selectedLoras, { name, strength: s.loraStrengths[name] ?? defaultLoraStrength(name) }] })),+ setLoraStrengthFor: (name, strength) => set((s) => {+ if (!Number.isFinite(strength)) return {}+ const value = clampLoraStrength(strength)+ return {+ selectedLoras: s.selectedLoras.map((l) => l.name === name ? { ...l, strength: value } : l),+ loraStrengths: { ...s.loraStrengths, [name]: value },+ }+ }),clearLoras: () => set((s) => ({selectedLoras: [],selectedCharacter: s.selectedCharacter?.id.startsWith('local:') ? null : s.selectedCharacter,@@ -912,8 +924,13 @@ export const useCreateStore = create<CreateState>()(const kept = s.selectedLoras.filter((l) => listed.includes(l.name))const char = s.selectedCharacterconst charGone = !!char?.id.startsWith('local:') && !listed.includes(char.id.slice('local:'.length))- if (kept.length === s.selectedLoras.length && !charGone) return {}- return { selectedLoras: kept, ...(charGone ? { selectedCharacter: null } : {}) }+ // A deleted file takes its remembered strength with it.+ const remembered = Object.keys(s.loraStrengths)+ const strengths = remembered.every((n) => listed.includes(n))+ ? {}+ : { loraStrengths: Object.fromEntries(remembered.filter((n) => listed.includes(n)).map((n) => [n, s.loraStrengths[n]])) }+ if (kept.length === s.selectedLoras.length && !charGone) return strengths+ return { selectedLoras: kept, ...strengths, ...(charGone ? { selectedCharacter: null } : {}) }}),setSelectedVae: (name) => set({ selectedVae: name || 'auto' }),setClipSkip: (n) => set({ clipSkip: Math.max(0, Math.min(12, Math.floor(n))) }),@@ -1223,6 +1240,7 @@ export const useCreateStore = create<CreateState>()(// are additive and merge() backfills missing keys from defaults. ──showNegative: state.showNegative,selectedLoras: state.selectedLoras,+ loraStrengths: state.loraStrengths,selectedVae: state.selectedVae,clipSkip: state.clipSkip,growMaskBy: state.growMaskBy,