Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Simplify LoRA settings and use popup editor

Bitti6759750b4088
diff --git a/src/components/LoraSettings.tsx b/src/components/LoraSettings.tsx
index e91de2f..ee83780 100644
--- a/src/components/LoraSettings.tsx
+++ b/src/components/LoraSettings.tsx
@@ -1,7 +1,8 @@
import { ArrowDown, ArrowUp, Download, FolderSearch, Layers, LoaderCircle, Plus, Trash2, Wrench } from "lucide-react";
import "../styles/loras.css";
import { useEffect, useRef, useState, useSyncExternalStore } from "react";
-import { effectiveLoraStrength, highestLoraStepOverride, isLoraMultiplier, isLoraStepOverride, loadLoras, MAX_LORA_MULTIPLIER, saveLoras, subscribeLoras, type Lora, type TemplateLora } from "../lib/loras";
+import { highestLoraStepOverride, isLoraStepOverride, loadLoras, saveLoras, subscribeLoras, type Lora, type TemplateLora } from "../lib/loras";
+import { SettingsEditorDialog } from "./SettingsEditorDialog";
import { MAX_GENERATION_STEPS } from "../lib/project";
import { isTauri } from "../lib/persistence";
import { chooseEnginePath } from "../lib/runtime";
@@ -45,8 +46,6 @@ export function LoraEditor({ loraId, onDone }: { loraId: string; onDone: () => v
const existing = loadLoras().find(({ id }) => id === loraId);
const [name, setName] = useState(existing?.name ?? "");
const [path, setPath] = useState(existing?.path ?? "");
- const [multiplier, setMultiplier] = useState(String(existing?.multiplier ?? 1));
- const validMultiplier = multiplier.trim() !== "" && isLoraMultiplier(Number(multiplier));
const [override, setOverride] = useState(existing?.stepOverride !== undefined);
const [steps, setSteps] = useState(String(existing?.stepOverride ?? 3));
const [error, setError] = useState<string | null>(null);
@@ -64,7 +63,7 @@ export function LoraEditor({ loraId, onDone }: { loraId: string; onDone: () => v
} catch (reason) { setError(String(reason)); }
};
const save = async () => {
- if (!name.trim() || (!path.trim() && !existing?.url) || !validMultiplier) return;
+ if (!name.trim() || (!path.trim() && !existing?.url) || (override && !isLoraStepOverride(Number(steps)))) return;
if (path.trim() && (!/^(?:[a-z]:[\\/]|\\\\|\/)/i.test(path.trim()) || path.includes("\0"))) {
setError("Choose a local LoRA file using its absolute path."); return;
}
@@ -74,35 +73,32 @@ export function LoraEditor({ loraId, onDone }: { loraId: string; onDone: () => v
await prepareLora({ id: loraId, name: name.trim(), path: path.trim() }, allowDownload);
}
const library = loadLoras();
- const entry: Lora = { ...library.find(({ id }) => id === loraId), id: loraId, name: name.trim(), path: path.trim(), multiplier: Number(multiplier), stepOverride: override ? Number(steps) : undefined,
+ const entry: Lora = { ...library.find(({ id }) => id === loraId), id: loraId, name: name.trim(), path: path.trim(), stepOverride: override ? Number(steps) : undefined,
...(path.trim() !== existing?.path ? { needsPreparation: undefined } : {}) };
saveLoras(existing ? library.map((lora) => lora.id === loraId ? entry : lora) : [...library, entry]);
if (mounted.current) onDone();
} catch (reason) { setError(String(reason)); }
finally { setSaving(false); }
};
- return <div className="generator-editor">
- <header className="generator-editor__head"><h2 id="lora-editor-heading">{existing ? "Edit Lora" : "Add Lora"}</h2></header>
+ return <SettingsEditorDialog title={existing ? "Edit Lora" : "Add Lora"} headingId="lora-editor-heading" initialFocusLabel="LoRA name" closeLabel="Close LoRA settings" onClose={onDone}>
<fieldset className="lora-manual" disabled={saving}>
- <label>Name<input aria-label="LoRA name" autoFocus value={name} onChange={(event) => setName(event.target.value)} /></label>
+ <label>Name<input aria-label="LoRA name" value={name} onChange={(event) => setName(event.target.value)} /></label>
<label>Local file<div className="settings-path__row"><input aria-label="LoRA path" value={path} onChange={(event) => setPath(event.target.value)} placeholder="Absolute path to a .safetensors file" />
<button className="secondary-button" type="button" disabled={!isTauri()} onClick={() => void browse()}><FolderSearch size={16} /> Browse</button></div></label>
- <label>Multiplier<input aria-label="LoRA multiplier" aria-describedby="lora-multiplier-help" type="number" min={-MAX_LORA_MULTIPLIER} max={MAX_LORA_MULTIPLIER} step="any" value={multiplier} onChange={(event) => setMultiplier(event.target.value)} /></label>
- <p id="lora-multiplier-help">Multiplies this LoRA's strength in every generator. 1 keeps the original strength, 0 disables it, and negative values reverse its effect.</p>
<label className="lora-toggle"><input type="checkbox" checked={override} onChange={(event) => setOverride(event.target.checked)} /> Override step count</label>
{override && <label>Step count<input aria-label="LoRA step override" type="number" min={2} max={MAX_GENERATION_STEPS} step={1} value={steps} onChange={(event) => setSteps(event.target.value)} /></label>}
<p>The highest override among active LoRAs replaces the scene's step count. Without an override, the scene's steps are used.</p>
<label className="lora-toggle"><input type="checkbox" checked={allowDownload} onChange={(event) => setAllowDownload(event.target.checked)} /> Download missing timestep grid</label>
<p>Newly selected files are prepared in place before use. Preparation may embed a timestep grid in the adapter.</p>
- <button className="primary-button" type="button" disabled={Boolean(download?.active) || !name.trim() || (!path.trim() && !existing?.url) || !validMultiplier || (override && !isLoraStepOverride(Number(steps)))} onClick={() => void save()}>{saving ? "Preparing LoRA…" : existing ? "Save Lora" : "Add Lora"}</button>
+ <button className="primary-button" type="button" disabled={Boolean(download?.active) || !name.trim() || (!path.trim() && !existing?.url) || (override && !isLoraStepOverride(Number(steps)))} onClick={() => void save()}>{saving ? "Preparing LoRA…" : existing ? "Save Lora" : "Add Lora"}</button>
{error && <p role="alert">{error}</p>}
</fieldset>
- </div>;
+ </SettingsEditorDialog>;
}
export function TemplateLorasEditor({ value, onChange }: { value: TemplateLora[]; onChange: (value: TemplateLora[]) => void }) {
const library = useLoras();
- const active = value.filter((entry) => entry.enabled && effectiveLoraStrength(entry, library.find(({ id }) => id === entry.loraId)) !== 0);
+ const active = value.filter((entry) => entry.enabled && entry.strength !== 0);
const stepOverride = highestLoraStepOverride(active
.flatMap((entry) => library.filter(({ id }) => id === entry.loraId)));
const available = library.filter((entry) => (entry.path || entry.url) && !value.some(({ loraId }) => loraId === entry.id));
@@ -114,7 +110,7 @@ export function TemplateLorasEditor({ value, onChange }: { value: TemplateLora[]
};
return <section className="template-loras" aria-labelledby="template-loras-heading">
<h3 id="template-loras-heading">LoRAs <small>{active.length} active</small></h3>
- <p>Enable adapters and arrange their order. Strength is multiplied by each LoRA's multiplier in its settings. Either value at 0 disables the adapter.</p>
+ <p>Enable adapters, set their strength, and arrange their order. A strength of 0 disables the adapter.</p>
<p>Missing active LoRAs with download links are downloaded with the generator.</p>
{value.map((entry, index) => {
const lora = library.find(({ id }) => id === entry.loraId);
@@ -123,7 +119,6 @@ export function TemplateLorasEditor({ value, onChange }: { value: TemplateLora[]
<span>{index + 1}.</span>
<label className="lora-toggle"><input type="checkbox" checked={entry.enabled} aria-label={`Enable ${name}`} onChange={(event) => update(index, { enabled: event.target.checked })} /> {name}{!lora?.path && (lora?.url ? " (download required)" : " (file unavailable)")}</label>
<label>Strength<input type="number" step="0.1" aria-label={`${name} strength`} value={entry.strength} onChange={(event) => { const strength = Number(event.target.value); if (event.target.value && Number.isFinite(strength)) update(index, { strength }); }} /></label>
- {lora?.multiplier !== undefined && lora.multiplier !== 1 && <small aria-label={`${name} effective strength`}>× {lora.multiplier} = {Number(effectiveLoraStrength(entry, lora).toPrecision(6))}</small>}
<button className="icon-button" type="button" aria-label={`Move ${name} up`} disabled={index === 0} onClick={() => move(index, -1)}><ArrowUp size={15} /></button>
<button className="icon-button" type="button" aria-label={`Move ${name} down`} disabled={index === value.length - 1} onClick={() => move(index, 1)}><ArrowDown size={15} /></button>
<button className="icon-button" type="button" aria-label={`Deactivate and remove ${name}`} onClick={() => onChange(value.filter((_, i) => i !== index))}><Trash2 size={15} /></button>
diff --git a/src/components/GeneratorTemplateDialog.tsx b/src/components/SettingsEditorDialog.tsx
similarity index 73%
rename from src/components/GeneratorTemplateDialog.tsx
rename to src/components/SettingsEditorDialog.tsx
index 2c7b882..e6740d7 100644
--- a/src/components/GeneratorTemplateDialog.tsx
+++ b/src/components/SettingsEditorDialog.tsx
@@ -1,13 +1,16 @@
import { ArrowLeft, X } from "lucide-react";
import { useEffect, useRef, type ReactNode } from "react";
-export function GeneratorTemplateDialog({ children, footer, onClose }: { children: ReactNode; footer: ReactNode; onClose: () => void }) {
+export function SettingsEditorDialog({ children, footer, title, headingId, initialFocusLabel, closeLabel, onClose }: {
+ children: ReactNode; footer?: ReactNode; title: string; headingId: string;
+ initialFocusLabel: string; closeLabel: string; onClose: () => void;
+}) {
const dialog = useRef<HTMLDivElement>(null);
useEffect(() => {
const opener = document.activeElement as HTMLElement | null;
- dialog.current?.querySelector<HTMLInputElement>('[aria-label="Generator name"]')?.focus();
+ dialog.current?.querySelector<HTMLInputElement>(`[aria-label="${initialFocusLabel}"]`)?.focus();
return () => { requestAnimationFrame(() => { if (opener?.isConnected) opener.focus(); }); };
- }, []);
+ }, [initialFocusLabel]);
return <div className="generator-dialog-overlay" onKeyDown={(event) => {
event.stopPropagation();
if (event.key === "Escape" && !event.defaultPrevented) { event.preventDefault(); onClose(); }
@@ -17,11 +20,11 @@ export function GeneratorTemplateDialog({ children, footer, onClose }: { childre
if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last?.focus(); }
else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first?.focus(); }
}}>
- <div ref={dialog} className="generator-dialog" role="dialog" aria-modal="true" aria-labelledby="generator-editor-heading">
+ <div ref={dialog} className="generator-dialog" role="dialog" aria-modal="true" aria-labelledby={headingId}>
<header className="generator-dialog__head">
<button type="button" className="icon-button icon-button--strong" onClick={onClose} aria-label="Generators" title="Back to generators"><ArrowLeft size={18} /></button>
- <h2 id="generator-editor-heading">Edit generator</h2>
- <button type="button" className="icon-button" aria-label="Close generator settings" onClick={onClose}><X size={18} /></button>
+ <h2 id={headingId}>{title}</h2>
+ <button type="button" className="icon-button" aria-label={closeLabel} onClick={onClose}><X size={18} /></button>
</header>
<div className="generator-dialog__body">{children}</div>
{footer}
diff --git a/src/components/SettingsView.downloads.test.tsx b/src/components/SettingsView.downloads.test.tsx
index 74ddec3..cac0226 100644
--- a/src/components/SettingsView.downloads.test.tsx
+++ b/src/components/SettingsView.downloads.test.tsx
@@ -154,12 +154,10 @@ it("downloads TaoMate and persists manual adapters, activation, strength and ord
fireEvent.click(screen.getByRole("button", { name: "Add Lora" }));
expect(screen.queryByRole("button", { name: "New generator" })).not.toBeInTheDocument();
expect(screen.getByRole("heading", { name: "Add Lora" })).toBeInTheDocument();
+ expect(screen.getByRole("dialog", { name: "Add Lora" })).toBeInTheDocument();
fireEvent.change(screen.getByLabelText("LoRA name"), { target: { value: "My style" } });
fireEvent.change(screen.getByLabelText("LoRA path"), { target: { value: "D:/models/style.safetensors" } });
- expect(screen.getByLabelText("LoRA multiplier")).toHaveValue(1);
- fireEvent.change(screen.getByLabelText("LoRA multiplier"), { target: { value: "" } });
- expect(screen.getByRole("button", { name: "Add Lora" })).toBeDisabled();
- fireEvent.change(screen.getByLabelText("LoRA multiplier"), { target: { value: "0.75" } });
+ expect(screen.queryByLabelText("LoRA multiplier")).not.toBeInTheDocument();
fireEvent.click(screen.getByLabelText("Override step count"));
fireEvent.change(screen.getByLabelText("LoRA step override"), { target: { value: "8" } });
fireEvent.click(screen.getByRole("button", { name: "Add Lora" }));
@@ -167,16 +165,17 @@ it("downloads TaoMate and persists manual adapters, activation, strength and ord
expect(invoke).toHaveBeenCalledWith("prepare_lora", { path: "D:/models/style.safetensors", allowDownload: true });
const manual = loadLoras().find(({ name }) => name === "My style")!;
expect(manual.stepOverride).toBe(8);
- expect(manual.multiplier).toBe(0.75);
+ expect(manual).not.toHaveProperty("multiplier");
+ expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Edit My style LoRA" }));
expect(screen.getByLabelText("LoRA step override")).toHaveValue(8);
- expect(screen.getByLabelText("LoRA multiplier")).toHaveValue(0.75);
+ expect(screen.getByRole("dialog", { name: "Edit Lora" })).toBeInTheDocument();
+ expect(screen.queryByLabelText("LoRA multiplier")).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Generators" }));
fireEvent.click(screen.getByRole("button", { name: "Edit Default generator" }));
fireEvent.change(screen.getByLabelText("Add LoRA to generator"), { target: { value: TAOMATE_LORA.id } });
fireEvent.change(screen.getByLabelText("Add LoRA to generator"), { target: { value: manual.id } });
fireEvent.change(screen.getByLabelText("My style strength"), { target: { value: "-0.5" } });
- expect(screen.getByLabelText("My style effective strength")).toHaveTextContent("-0.375");
fireEvent.click(screen.getByRole("button", { name: "Move My style up" }));
fireEvent.click(screen.getByLabelText("Enable TaoMate 3-Step"));
expect(screen.getByText("1 active")).toBeInTheDocument();
@@ -187,7 +186,6 @@ it("downloads TaoMate and persists manual adapters, activation, strength and ord
render(<SettingsView onClose={() => undefined} />);
fireEvent.click(screen.getByRole("button", { name: "Edit Default generator" }));
expect(screen.getByLabelText("My style strength")).toHaveValue(-0.5);
- expect(screen.getByLabelText("My style effective strength")).toHaveTextContent("-0.375");
expect(screen.getByLabelText("Enable TaoMate 3-Step")).not.toBeChecked();
expect(screen.getByRole("button", { name: "Move My style up" })).toBeDisabled();
});
diff --git a/src/components/SettingsView.test.tsx b/src/components/SettingsView.test.tsx
index 144e972..59de86c 100644
--- a/src/components/SettingsView.test.tsx
+++ b/src/components/SettingsView.test.tsx
@@ -6,6 +6,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { SettingsView } from "./SettingsView";
import { createGeneratorTemplate, loadGeneratorTemplateSettings, saveGeneratorTemplateSettings } from "../lib/settings";
import { loadReferenceIconGeneratorId } from "../lib/referenceIconSettings";
+import { loadLoras } from "../lib/loras";
vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));
@@ -260,6 +261,33 @@ describe("the settings screen", () => {
expect(screen.queryByLabelText("Generator name")).toBeNull();
});
+ it("edits LoRAs in a focused popup and discards unsaved changes on close", async () => {
+ const onClose = vi.fn();
+ render(<SettingsView onClose={onClose} />);
+ const opener = screen.getByRole("button", { name: "Edit TaoMate 3-Step LoRA" });
+ opener.focus(); fireEvent.click(opener);
+ const dialog = screen.getByRole("dialog", { name: "Edit Lora" });
+ const name = within(dialog).getByLabelText("LoRA name");
+ expect(document.activeElement).toBe(name);
+ expect(screen.queryByRole("tab", { name: "Appearance" })).toBeNull();
+ expect(within(dialog).queryByLabelText("LoRA multiplier")).toBeNull();
+ const first = within(dialog).getByRole("button", { name: "Generators" });
+ const last = within(dialog).getByRole("button", { name: "Save Lora" });
+ last.focus(); fireEvent.keyDown(last, { key: "Tab" });
+ expect(document.activeElement).toBe(first);
+ fireEvent.keyDown(first, { key: "Tab", shiftKey: true });
+ expect(document.activeElement).toBe(last);
+ fireEvent.change(name, { target: { value: "Unsaved name" } });
+ fireEvent.keyDown(name, { key: "Escape" });
+ expect(screen.queryByRole("dialog")).toBeNull();
+ expect(onClose).not.toHaveBeenCalled();
+ expect(loadLoras()[0].name).toBe("TaoMate 3-Step");
+ await waitFor(() => expect(document.activeElement).toBe(opener));
+ fireEvent.click(opener);
+ fireEvent.click(screen.getByRole("button", { name: "Close LoRA settings" }));
+ expect(screen.queryByRole("dialog")).toBeNull();
+ });
+
it("defaults icon generation to the sole available generator and remembers a separate selection", () => {
const first = createGeneratorTemplate("Video"), second = createGeneratorTemplate("Icons");
const templates = { templates: [first], defaultTemplateId: first.id, catalogVersion: 9 };
diff --git a/src/components/SettingsView.tsx b/src/components/SettingsView.tsx
index a858295..bbbd7e0 100644
--- a/src/components/SettingsView.tsx
+++ b/src/components/SettingsView.tsx
@@ -1,6 +1,6 @@
-import { GeneratorTemplateDialog } from "./GeneratorTemplateDialog";
+import { SettingsEditorDialog } from "./SettingsEditorDialog";
import { AdditionalSafetensorsEditor } from "./AdditionalSafetensorsEditor";
-import { AlertCircle, ArrowLeft, Check, ChevronLeft, Download, FolderOpen, FolderSearch, LoaderCircle, Monitor, Moon, Plus, RefreshCw, RotateCcw, Sun, Trash2, Video } from "lucide-react";
+import { AlertCircle, ArrowLeft, Check, Download, FolderOpen, FolderSearch, LoaderCircle, Monitor, Moon, Plus, RefreshCw, RotateCcw, Sun, Trash2, Video } from "lucide-react";
import { useCallback, useEffect, useRef, useState, useSyncExternalStore, type ReactNode } from "react";
import { revealDiagnosticLog } from "../lib/diagnostics";
import { isTauri } from "../lib/persistence";
@@ -538,7 +538,7 @@ export function SettingsView({ onClose, updates, initialTab = "engine" }: { onCl
return (
<>
- <main aria-hidden={editingTemplateId ? true : undefined} className="settings-view" ref={page} tabIndex={-1} aria-labelledby="settings-heading" onKeyDown={(event) => {
+ <main aria-hidden={editingTemplateId || editingLoraId ? true : undefined} className="settings-view" ref={page} tabIndex={-1} aria-labelledby="settings-heading" onKeyDown={(event) => {
// The mounted editor must not receive shortcuts while Settings has focus.
event.stopPropagation();
if (event.key === "Escape" && !event.defaultPrevented) onClose();
@@ -581,7 +581,6 @@ export function SettingsView({ onClose, updates, initialTab = "engine" }: { onCl
<div className="settings-view__content">
<div className="settings-view__body" ref={body}>
- {tab === "engine" && editingLoraId && <button type="button" className="secondary-button generator-editor__back" onClick={() => { setEditingTemplateId(null); setEditingLoraId(null); }}><ChevronLeft size={16} /> Generators</button>}
{tab === "updates" && <section className="settings-section" id="settings-panel-updates" role="tabpanel" aria-labelledby="settings-tab-updates">
{updates ?? <p>Updates are available in the desktop app.</p>}
</section>}
@@ -618,8 +617,8 @@ export function SettingsView({ onClose, updates, initialTab = "engine" }: { onCl
role="tabpanel"
aria-labelledby="settings-tab-engine"
>
- {!editingLoraId && <ReferenceIconSetting templates={templateSettings} />}
- {editingLoraId ? <LoraEditor key={editingLoraId} loraId={editingLoraId} onDone={() => setEditingLoraId(null)} /> : <>{generatorSections.filter((section) => section.id === "generators" || section.templates.length > 0).map((section) => <section key={section.id} className="generator-templates" aria-labelledby={`${section.id}-heading`}>
+ <ReferenceIconSetting templates={templateSettings} />
+ {generatorSections.filter((section) => section.id === "generators" || section.templates.length > 0).map((section) => <section key={section.id} className="generator-templates" aria-labelledby={`${section.id}-heading`}>
<header>
<div>
<h2 id={`${section.id}-heading`}>{section.title}</h2>
@@ -655,7 +654,7 @@ export function SettingsView({ onClose, updates, initialTab = "engine" }: { onCl
</div>
))}
</div>
- </section>)}<LoraLibrary onAdd={() => setEditingLoraId(`lora-${crypto.randomUUID()}`)} onEdit={setEditingLoraId} /></>}
+ </section>)}<LoraLibrary onAdd={() => setEditingLoraId(`lora-${crypto.randomUUID()}`)} onEdit={setEditingLoraId} />
</section>}
</div>
@@ -665,7 +664,8 @@ export function SettingsView({ onClose, updates, initialTab = "engine" }: { onCl
{error && <div className="toast" role="alert"><strong>Couldn’t update generator settings</strong><span>{error}</span><button onClick={() => setError(null)}>Dismiss</button></div>}
</div>
</main>
- {editingTemplateId && <GeneratorTemplateDialog onClose={() => setEditingTemplateId(null)} footer={generatorFooter}>{generatorEditor}</GeneratorTemplateDialog>}
+ {editingTemplateId && <SettingsEditorDialog title="Edit generator" headingId="generator-editor-heading" initialFocusLabel="Generator name" closeLabel="Close generator settings" onClose={() => setEditingTemplateId(null)} footer={generatorFooter}>{generatorEditor}</SettingsEditorDialog>}
+ {editingLoraId && <LoraEditor key={editingLoraId} loraId={editingLoraId} onDone={() => setEditingLoraId(null)} />}
</>
);
}
diff --git a/src/lib/loras.test.ts b/src/lib/loras.test.ts
index 0445efa..e855c1f 100644
--- a/src/lib/loras.test.ts
+++ b/src/lib/loras.test.ts
@@ -1,36 +1,34 @@
// @vitest-environment jsdom
import { beforeEach, expect, it } from "vitest";
-import { downloadableTemplateLoras, LIGHTX2V_TURBO_LORA, loadLoras, MAX_LORA_MULTIPLIER, saveLoras, TAOMATE_LORA, TURBO_LORA, VIGGLE_ANIMATE_LORA } from "./loras";
+import { downloadableTemplateLoras, LIGHTX2V_TURBO_LORA, loadLoras, saveLoras, TAOMATE_LORA, TURBO_LORA, VIGGLE_ANIMATE_LORA } from "./loras";
import { createGeneratorTemplate, engineProviderSetting, generationStepsWithLoras, loadGeneratorTemplateSettings, saveGeneratorTemplateSettings, withEngineSettings } from "./settings";
import { createProjectConfig } from "./project";
beforeEach(() => localStorage.clear());
-it("persists library multipliers and combines them with template strengths for generation", () => {
- saveLoras([
+it("ignores legacy library multipliers and uses template strengths directly", () => {
+ localStorage.setItem("slopus.loras.v1", JSON.stringify([
{ id: "style", name: "Style", path: "D:/style.safetensors", multiplier: 0.75 },
{ ...TURBO_LORA, multiplier: 0 },
- ]);
+ ]));
const selection = [
{ loraId: "style", enabled: true, strength: -0.5 },
{ loraId: TURBO_LORA.id, enabled: true, strength: 1 },
];
- expect(loadLoras().find(({ id }) => id === "style")?.multiplier).toBe(0.75);
- expect(downloadableTemplateLoras(selection)).toEqual([]);
- const options = engineProviderSetting(createGeneratorTemplate().paths, undefined, "sage2", selection).options;
- expect(JSON.parse(options.loras as string)).toEqual([{ path: "D:/style.safetensors", strength: -0.375 }]);
+ expect(loadLoras().find(({ id }) => id === "style")).not.toHaveProperty("multiplier");
+ expect(downloadableTemplateLoras(selection)).toEqual([TURBO_LORA]);
+ const options = engineProviderSetting(createGeneratorTemplate().paths, undefined, "sage2", [selection[0]]).options;
+ expect(JSON.parse(options.loras as string)).toEqual([{ path: "D:/style.safetensors", strength: -0.5 }]);
expect(options).not.toHaveProperty("stepOverride");
+ saveLoras(loadLoras());
+ expect(localStorage.getItem("slopus.loras.v1")).not.toContain('"multiplier"');
});
-it.each([NaN, Infinity, -Infinity, 1e39])("rejects invalid library multiplier %s", (multiplier) => {
- expect(() => saveLoras([{ ...TURBO_LORA, multiplier }])).toThrow("LoRA multiplier must be a finite number");
-});
-
-it("rejects combined strengths outside the engine's numeric range", () => {
- saveLoras([{ ...TURBO_LORA, path: "D:/turbo.safetensors", multiplier: MAX_LORA_MULTIPLIER }]);
+it.each([NaN, Infinity, -Infinity, 1e39])("rejects template strength %s outside the engine's numeric range", (strength) => {
+ saveLoras([{ ...TURBO_LORA, path: "D:/turbo.safetensors" }]);
expect(() => engineProviderSetting(createGeneratorTemplate().paths, undefined, "sage2", [
- { loraId: TURBO_LORA.id, enabled: true, strength: 2 },
- ])).toThrow("Combined multiplier for LoRA Turbo");
+ { loraId: TURBO_LORA.id, enabled: true, strength },
+ ])).toThrow("Strength for LoRA Turbo");
});
it("migrates the old schedule to an editable step override", () => {
diff --git a/src/lib/loras.ts b/src/lib/loras.ts
index 1c29944..d36f5d8 100644
--- a/src/lib/loras.ts
+++ b/src/lib/loras.ts
@@ -7,7 +7,6 @@ export interface Lora {
path: string;
url?: string;
stepOverride?: number;
- multiplier?: number;
needsPreparation?: boolean;
}
export interface TemplateLora { loraId: string; enabled: boolean; strength: number }
@@ -30,7 +29,6 @@ export const LIGHTX2V_TURBO_LORA: Lora = {
id: "lightx2v-turbo-6step", name: "LightX2V Turbo", path: "",
url: "https://huggingface.co/silveroxides/MiniMax-H3_tests/resolve/main/experimental/minimax_h3_fl2v_lightx2v_turbo_4to8step_v0.1-v1.0_768p_v4_step600_dareties.safetensors",
stepOverride: 6,
- multiplier: 0.9,
};
const KEY = "slopus.loras.v1";
const EVENT = "slopus:loras-changed";
@@ -45,7 +43,6 @@ export function loadLoras(): Lora[] {
return [{ id: entry.id, name: entry.name, path: entry.path,
...(entry.needsPreparation === true ? { needsPreparation: true } : {}),
...(typeof entry.url === "string" && /^https?:\/\//i.test(entry.url) ? { url: entry.url } : {}),
- ...(isLoraMultiplier(entry.multiplier) ? { multiplier: entry.multiplier } : {}),
...(isLoraStepOverride(entry.stepOverride) ? { stepOverride: entry.stepOverride }
: entry.stepOverride === undefined && entry.schedule === "taomate-3step" ? { stepOverride: 3 } : {}) }];
}) : [];
@@ -57,9 +54,6 @@ export function loadLoras(): Lora[] {
} catch { return [{ ...TAOMATE_LORA }, { ...TURBO_LORA }, { ...VIGGLE_ANIMATE_LORA }, { ...LIGHTX2V_TURBO_LORA }]; }
}
export function saveLoras(loras: Lora[]): void {
- if (loras.some((lora) => lora.multiplier !== undefined && !isLoraMultiplier(lora.multiplier))) {
- throw new Error("LoRA multiplier must be a finite number within the supported range.");
- }
if (loras.some((lora) => lora.stepOverride !== undefined && !isLoraStepOverride(lora.stepOverride))) {
throw new Error(`Step override must be a whole number from 2 to ${MAX_GENERATION_STEPS}.`);
}
@@ -78,13 +72,13 @@ export function normalizeTemplateLoras(value: unknown): TemplateLora[] {
if (!entry || typeof entry.loraId !== "string" || !entry.loraId || ids.has(entry.loraId)) return [];
ids.add(entry.loraId);
return [{ loraId: entry.loraId, enabled: entry.enabled !== false,
- strength: isLoraMultiplier(entry.strength) ? entry.strength : 1 }];
+ strength: isLoraStrength(entry.strength) ? entry.strength : 1 }];
}) : [];
}
export function downloadableTemplateLoras(selection: TemplateLora[] = []): Lora[] {
const active = new Set(selection.filter((entry) => entry.enabled && entry.strength !== 0).map((entry) => entry.loraId));
- return loadLoras().filter((lora) => active.has(lora.id) && lora.multiplier !== 0 && lora.url
+ return loadLoras().filter((lora) => active.has(lora.id) && lora.url
&& (lora.needsPreparation || !lora.path.trim() || /^https?:\/\//i.test(lora.path)));
}
@@ -92,9 +86,8 @@ export function resolveTemplateLoras(selection: TemplateLora[] = []) {
const library = loadLoras();
return selection.filter((entry) => entry.enabled && entry.strength !== 0).flatMap((entry) => {
const lora = library.find(({ id }) => id === entry.loraId);
- const strength = effectiveLoraStrength(entry, lora);
- if (!isLoraMultiplier(strength)) throw new Error(`Combined multiplier for LoRA ${lora?.name ?? entry.loraId} is outside the supported range.`);
- if (strength === 0) return [];
+ const strength = entry.strength;
+ if (!isLoraStrength(strength)) throw new Error(`Strength for LoRA ${lora?.name ?? entry.loraId} is outside the supported range.`);
if (lora?.needsPreparation) throw new Error(`Prepare LoRA ${lora.name} in Settings before using it.`);
if (!lora?.path.trim() || /^https?:\/\//i.test(lora.path)) {
throw new Error(`Download or locate LoRA ${lora?.name ?? entry.loraId}, or disable it in the generator template.`);
@@ -103,14 +96,10 @@ export function resolveTemplateLoras(selection: TemplateLora[] = []) {
});
}
-export const MAX_LORA_MULTIPLIER = 3.4028234663852886e38;
-
-export function isLoraMultiplier(value: unknown): value is number {
- return typeof value === "number" && Number.isFinite(value) && Math.abs(value) <= MAX_LORA_MULTIPLIER;
-}
+export const MAX_LORA_STRENGTH = 3.4028234663852886e38;
-export function effectiveLoraStrength(entry: TemplateLora, lora?: Lora): number {
- return entry.strength * (lora?.multiplier ?? 1);
+export function isLoraStrength(value: unknown): value is number {
+ return typeof value === "number" && Number.isFinite(value) && Math.abs(value) <= MAX_LORA_STRENGTH;
}
export function isLoraStepOverride(value: unknown): value is number {
diff --git a/src/lib/referenceIconWork.test.ts b/src/lib/referenceIconWork.test.ts
index eb60388..8895be3 100644
--- a/src/lib/referenceIconWork.test.ts
+++ b/src/lib/referenceIconWork.test.ts
@@ -80,8 +80,8 @@ it("renders automatic icons with the chosen template without changing the video
icons.defaultSteps = 12;
icons.attention = "exact";
icons.motionCache = true;
- saveLoras([{ id: "style", name: "Style", path: "D:/style.safetensors", multiplier: 0.9, stepOverride: 6 }]);
- icons.loras = [{ loraId: "style", enabled: true, strength: 1 }];
+ saveLoras([{ id: "style", name: "Style", path: "D:/style.safetensors", stepOverride: 6 }]);
+ icons.loras = [{ loraId: "style", enabled: true, strength: 0.9 }];
saveGeneratorTemplateSettings({ templates: [videoTemplate, icons], defaultTemplateId: videoTemplate.id, catalogVersion: 9 });
saveReferenceIconGeneratorId(icons.id);
const { session } = setup([reference("hero")]);
diff --git a/src/lib/weightDownloads.test.ts b/src/lib/weightDownloads.test.ts
index e489388..92af09a 100644
--- a/src/lib/weightDownloads.test.ts
+++ b/src/lib/weightDownloads.test.ts
@@ -140,10 +140,9 @@ it.each([TAOMATE_LORA, TURBO_LORA, VIGGLE_ANIMATE_LORA, LIGHTX2V_TURBO_LORA])("d
expect(invoke).toHaveBeenCalledWith("download_weight", { requestId: expect.any(String), url: lora.url });
const path = `C:/Slopus/weights/${lora.url!.split('/').at(-1)}`;
expect(savedLora()).toMatchObject({ path, stepOverride: lora.stepOverride });
- expect(savedLora().multiplier).toBe(lora.multiplier);
const options = engineProviderSetting(createGeneratorTemplate().paths, undefined, "sage2", [{ loraId: lora.id, enabled: true, strength: 1 }]).options;
expect(options.stepOverride).toBe(lora.stepOverride);
- expect(JSON.parse(options.loras as string)).toEqual([{ path, strength: lora.multiplier ?? 1 }]);
+ expect(JSON.parse(options.loras as string)).toEqual([{ path, strength: 1 }]);
expect(getWeightDownloadState()).toMatchObject({ loraId: lora.id, active: false, completed: 1, error: null });
files.clear();
await refreshDownloadedLoras();