AI media harness for planning, generating, and editing locally
TypeScript
Download template LoRAs with generator weights
Bittic60d4f3f1bf8
diff --git a/docs/generator-weights.md b/docs/generator-weights.mdindex f59c2e8..11457a5 100644--- a/docs/generator-weights.md+++ b/docs/generator-weights.md@@ -13,7 +13,11 @@ Missing managed files become downloadable again. Removing a downloaded LoRAdeletes its managed file; **Add Lora** opens an editor to link a named local file, andremoving that library entry leaves the original file untouched.-Open a generator template and use its **LoRAs** section to add available adapters.+Open a generator template and use its **LoRAs** section to add local or downloadable adapters.+Downloading the generator also downloads any missing active LoRAs with download links.+Already downloaded adapters are reused; disabled and strength-zero adapters are skipped.+The generator stays under **Download** until its model weights and active downloadable+LoRAs are available. Progress, cancellation, and retry cover the entire download.Enable any number, adjust their strengths, and move them up or down. Disabledadapters and strength-zero entries are omitted; the remaining paths and strengthsare passed to SlopFab in displayed order on both CUDA and Vulkan. SlopFab combines@@ -45,6 +49,8 @@ References default to 20 steps.Singularity defaults to **4 steps** and uses[Minimax-h3_Singularity_ref2va_Pruned_v1.3_int8.safetensors](https://huggingface.co/WarmBloodAban/Minimax-h3_Singularity/blob/main/Minimax-h3_Singularity_ref2va_Pruned_v1.3_int8.safetensors)on all GPUs, with the same text encoder and VAEs as First/Last Frame.+It also includes **Turbo**, enabled at strength **1** with its **4-step override**.+Existing Singularity templates receive Turbo once, preserving any existing Turbo selection.All four text encoder downloads use the original Qwen3-VL 32B encoder on all GPUs.The incompatible 4B INT4 ConvRot option is removed from saved Minimax templates;templates using its downloaded file switch back to the original encoder, whichdiff --git a/src/components/LoraSettings.tsx b/src/components/LoraSettings.tsxindex 975cdf4..3d7d5e8 100644--- a/src/components/LoraSettings.tsx+++ b/src/components/LoraSettings.tsx@@ -87,7 +87,7 @@ export function TemplateLorasEditor({ value, onChange }: { value: TemplateLora[]const library = useLoras();const stepOverride = highestLoraStepOverride(value.filter((entry) => entry.enabled && entry.strength !== 0).flatMap((entry) => library.filter(({ id }) => id === entry.loraId)));- const available = library.filter((entry) => entry.path && !value.some(({ loraId }) => loraId === entry.id));+ const available = library.filter((entry) => (entry.path || entry.url) && !value.some(({ loraId }) => loraId === entry.id));const update = (index: number, patch: Partial<TemplateLora>) => onChange(value.map((entry, i) => i === index ? { ...entry, ...patch } : entry));const move = (index: number, delta: number) => {const next = [...value];@@ -97,12 +97,13 @@ export function TemplateLorasEditor({ value, onChange }: { value: TemplateLora[]return <section className="template-loras" aria-labelledby="template-loras-heading"><h3 id="template-loras-heading">LoRAs <small>{value.filter((entry) => entry.enabled && entry.strength !== 0).length} active</small></h3><p>Enable any number of adapters and arrange their order. Strength 0 disables an 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);const name = lora?.name ?? "Missing LoRA";return <div className="template-lora-row" key={entry.loraId}><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 && " (file unavailable)"}</label>+ <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><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>diff --git a/src/components/SettingsView.downloads.test.tsx b/src/components/SettingsView.downloads.test.tsxindex f223e45..25b60dc 100644--- a/src/components/SettingsView.downloads.test.tsx+++ b/src/components/SettingsView.downloads.test.tsx@@ -9,7 +9,7 @@ import { loadGeneratorTemplateSettings } from "../lib/settings";import { getWeightDownloadState } from "../lib/weightDownloads";import { WorkQueuePanel } from "./WorkQueuePanel";import { WorkQueue } from "../lib/workQueue";-import { loadLoras, TAOMATE_LORA } from "../lib/loras";+import { loadLoras, TAOMATE_LORA, TURBO_LORA } from "../lib/loras";vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));vi.mock("@tauri-apps/api/event", () => ({ listen: vi.fn(async () => () => undefined) }));@@ -31,6 +31,24 @@ beforeEach(() => {});afterEach(() => { cleanup(); delete (window as Window & { __TAURI_INTERNALS__?: unknown }).__TAURI_INTERNALS__; });+it("selects an undownloaded LoRA in a generator and downloads it from that generator", async () => {+ render(<SettingsView onClose={() => undefined} />);+ fireEvent.click(screen.getByRole("button", { name: "Edit Default generator" }));+ expect(screen.getByRole("option", { name: "Turbo" })).toBeInTheDocument();+ fireEvent.change(screen.getByLabelText("Add LoRA to generator"), { target: { value: TURBO_LORA.id } });+ expect(screen.getByLabelText("Enable Turbo")).toBeChecked();+ expect(screen.getByText(/step count to 4/)).toBeInTheDocument();+ fireEvent.click(screen.getByRole("button", { name: "Download weights" }));+ await waitFor(() => expect(getWeightDownloadState()).toMatchObject({ templateId: "default", active: false, completed: 1, error: null }));+ expect(loadLoras().find(({ id }) => id === TURBO_LORA.id)?.path).not.toBe("");+ expect(screen.queryByRole("button", { name: "Download weights" })).not.toBeInTheDocument();+ fireEvent.click(screen.getByRole("button", { name: "Generators" }));+ expect(screen.getByRole("radio", { name: "Use Default as the default generator" })).toBeEnabled();+ fireEvent.click(screen.getByRole("button", { name: "Remove LoRA Turbo" }));+ expect(await screen.findByRole("button", { name: "Download generator Default" })).toBeEnabled();+ expect(screen.queryByRole("radio", { name: "Use Default as the default generator" })).not.toBeInTheDocument();+});+it("downloads TaoMate and persists manual adapters, activation, strength and order per template", async () => {const settings = render(<SettingsView onClose={() => undefined} />);fireEvent.click(screen.getByRole("button", { name: "Download LoRA TaoMate 3-Step" }));diff --git a/src/lib/loras.ts b/src/lib/loras.tsindex 788bf75..ac8d208 100644--- a/src/lib/loras.ts+++ b/src/lib/loras.ts@@ -62,6 +62,12 @@ export function normalizeTemplateLoras(value: unknown): TemplateLora[] {}) : [];}+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.url+ && (!lora.path.trim() || /^https?:\/\//i.test(lora.path)));+}+export function resolveTemplateLoras(selection: TemplateLora[] = []) {const library = loadLoras();return selection.filter((entry) => entry.enabled && entry.strength !== 0).map((entry) => {diff --git a/src/lib/settings.test.ts b/src/lib/settings.test.tsindex aa97a9c..0842c49 100644--- a/src/lib/settings.test.ts+++ b/src/lib/settings.test.ts@@ -1,6 +1,7 @@// @vitest-environment jsdomimport { beforeEach, describe, expect, it } from "vitest";+import { TURBO_LORA } from "./loras";import {agentEndpointProviderSettings,createGeneratorTemplate,@@ -73,7 +74,7 @@ describe("generator templates", () => {expect(settings.templates[2]).toEqual(minimaxFastTemplate());expect(settings.templates[3]).toEqual(minimaxSingularityTemplate());expect(settings.defaultTemplateId).toBe(template.id);- expect(settings.catalogVersion).toBe(5);+ expect(settings.catalogVersion).toBe(6);expect(loadGeneratorTemplateSettings()).toEqual(settings);saveGeneratorTemplateSettings({ ...settings, templates: [settings.templates[0]] });expect(loadGeneratorTemplateSettings().templates).toHaveLength(1);@@ -94,7 +95,7 @@ describe("generator templates", () => {const settings = loadGeneratorTemplateSettings();expect(settings.templates).toEqual([expect.objectContaining(custom), minimaxSingularityTemplate()]);expect(settings.defaultTemplateId).toBe(custom.id);- expect(settings.catalogVersion).toBe(5);+ expect(settings.catalogVersion).toBe(6);expect(loadGeneratorTemplateSettings()).toEqual(settings);saveGeneratorTemplateSettings({ ...settings, templates: [custom] });expect(loadGeneratorTemplateSettings().templates).toEqual([expect.objectContaining(custom)]);@@ -108,6 +109,27 @@ describe("generator templates", () => {expect(loadGeneratorTemplateSettings().templates).toEqual([template]);});+ it("adds Turbo to saved Singularity once and preserves other adapters and settings", () => {+ const template = minimaxSingularityTemplate();+ template.defaultSteps = 8;+ template.paths = { transformer: "main", textEncoder: "encoder", videoVae: "video", audioVae: "audio", tokenizer: "" };+ template.loras = [{ loraId: "custom", enabled: false, strength: 0.5 }];+ localStorage.setItem("slopus.generator-templates.v1", JSON.stringify({ templates: [template], defaultTemplateId: template.id, catalogVersion: 5 }));+ const settings = loadGeneratorTemplateSettings();+ expect(settings.templates).toEqual([{ ...template, loras: [...template.loras, { loraId: TURBO_LORA.id, enabled: true, strength: 1 }] }]);+ expect(settings.defaultTemplateId).toBe("");+ expect(loadGeneratorTemplateSettings()).toEqual(settings);+ saveGeneratorTemplateSettings({ ...settings, templates: [template] });+ expect(loadGeneratorTemplateSettings().templates[0].loras).toEqual(template.loras);+ });++ it("preserves an existing disabled Turbo selection during migration", () => {+ const template = minimaxSingularityTemplate();+ template.loras = [{ loraId: TURBO_LORA.id, enabled: false, strength: 0.3 }];+ localStorage.setItem("slopus.generator-templates.v1", JSON.stringify({ templates: [template], catalogVersion: 5 }));+ expect(loadGeneratorTemplateSettings().templates).toEqual([template]);+ });+it("adds First/Last Frame Fast with six steps and its transformer URL", () => {const original = minimaxOriginalTemplate();const fast = minimaxFastTemplate();@@ -127,7 +149,7 @@ describe("generator templates", () => {template.paths[field] = downloadedPath;localStorage.setItem("slopus.generator-templates.v1", JSON.stringify({ templates: [template], catalogVersion: 1 }));const settings = loadGeneratorTemplateSettings();- expect(settings.catalogVersion).toBe(5);+ expect(settings.catalogVersion).toBe(6);expect(settings.templates[0].paths[field]).toBe(downloadedPath);expect(settings.templates[0].sources![field]).toEqual(minimaxOriginalTemplate().sources![field]!.map((source, index) =>index === 0 ? { ...source, downloadedPath } : source));@@ -162,7 +184,7 @@ describe("generator templates", () => {localStorage.setItem("slopus.generator-templates.v1", JSON.stringify({ templates: [template], defaultTemplateId: template.id, catalogVersion: 2 }));const settings = loadGeneratorTemplateSettings();const migrated = settings.templates[0];- expect(settings.catalogVersion).toBe(5);+ expect(settings.catalogVersion).toBe(6);expect(migrated.sources!.textEncoder).toEqual([{ url: originalUrl, gpuModel: "", minVramGb: 0, ...(selection === "cached original" ? { downloadedPath: cachedOriginal } : {}) },custom,diff --git a/src/lib/settings.ts b/src/lib/settings.tsindex f70bf8c..8e1d451 100644--- a/src/lib/settings.ts+++ b/src/lib/settings.ts@@ -15,7 +15,7 @@import { DEFAULT_GENERATION_STEPS, MAX_GENERATION_STEPS, type ProjectConfig, type ProviderSetting } from "./project";// Type-only: erased at build time, so this does not close a cycle with runtime.ts.import type { ProviderId } from "./runtime";-import { highestLoraStepOverride, isLoraStepOverride, normalizeTemplateLoras, resolveTemplateLoras, type TemplateLora } from "./loras";+import { downloadableTemplateLoras, highestLoraStepOverride, isLoraStepOverride, normalizeTemplateLoras, resolveTemplateLoras, subscribeLoras, TURBO_LORA, type TemplateLora } from "./loras";/* Light/dark appearance is machine-level for the same reason and lives in* ./theme.ts, which is separate only because index.html has to read the same@@ -88,15 +88,18 @@ export const isDownloadUrl = (value: string): boolean => /^https?:\/\//i.test(vaexport function templateNeedsDownload(template: GeneratorTemplate): boolean {return ENGINE_PATH_FIELDS.some(({ id }) => isDownloadUrl(template.paths[id])- || (!template.paths[id].trim() && (template.sources?.[id]?.length ?? 0) > 0));+ || (!template.paths[id].trim() && (template.sources?.[id]?.length ?? 0) > 0))+ || downloadableTemplateLoras(template.loras).length > 0;}const GENERATOR_TEMPLATES_EVENT = "slopus:generator-templates-changed";export function subscribeGeneratorTemplates(listener: () => void) {+ const unsubscribeLoras = subscribeLoras(listener);const storage = (event: StorageEvent) => { if (event.key === GENERATOR_TEMPLATES_KEY || event.key === null) listener(); };window.addEventListener(GENERATOR_TEMPLATES_EVENT, listener);window.addEventListener("storage", storage);return () => {+ unsubscribeLoras();window.removeEventListener(GENERATOR_TEMPLATES_EVENT, listener);window.removeEventListener("storage", storage);};@@ -190,6 +193,7 @@ export function minimaxSingularityTemplate(): GeneratorTemplate {const template = minimaxOriginalTemplate();const transformer = "https://huggingface.co/WarmBloodAban/Minimax-h3_Singularity/blob/main/Minimax-h3_Singularity_ref2va_Pruned_v1.3_int8.safetensors";return { ...template, id: "minimax-h3-singularity", name: "Singularity", defaultSteps: 4,+ loras: [{ loraId: TURBO_LORA.id, enabled: true, strength: 1 }],paths: { ...template.paths, transformer },sources: { ...template.sources, transformer: [{ url: transformer, gpuModel: "", minVramGb: 0 }] },};@@ -198,7 +202,7 @@ export function minimaxSingularityTemplate(): GeneratorTemplate {const initialTemplateSettings = (paths = EMPTY_ENGINE_SETTINGS): GeneratorTemplateSettings => ({templates: [{ id: "default", name: "Default", defaultSteps: DEFAULT_GENERATION_STEPS, attention: "sage2", paths: copyPaths(paths) }, minimaxOriginalTemplate(), minimaxReferencesTemplate(), minimaxFastTemplate(), minimaxSingularityTemplate()],defaultTemplateId: "default",- catalogVersion: 5,+ catalogVersion: 6,});const normalizeTemplateSettings = (value: unknown): GeneratorTemplateSettings | null => {@@ -244,7 +248,7 @@ const normalizeTemplateSettings = (value: unknown): GeneratorTemplateSettings |templates,defaultTemplateId: templates.find((template) => template.id === requestedDefault && !templateNeedsDownload(template))?.id?? templates.find((template) => !templateNeedsDownload(template))?.id ?? "",- catalogVersion: typeof record.catalogVersion === "number" && [1, 2, 3, 4, 5].includes(record.catalogVersion) ? record.catalogVersion : 0,+ catalogVersion: typeof record.catalogVersion === "number" && [1, 2, 3, 4, 5, 6].includes(record.catalogVersion) ? record.catalogVersion : 0,};};@@ -307,6 +311,13 @@ export function loadGeneratorTemplateSettings(): GeneratorTemplateSettings {const template = minimaxSingularityTemplate();if (!normalized.templates.some(({ id }) => id === template.id)) normalized.templates.push(template);normalized.catalogVersion = 5;+ }+ if ((normalized.catalogVersion ?? 0) < 6) {+ const singularity = normalized.templates.find(({ id }) => id === "minimax-h3-singularity");+ if (singularity && !singularity.loras?.some(({ loraId }) => loraId === TURBO_LORA.id)) {+ singularity.loras = [...(singularity.loras ?? []), { loraId: TURBO_LORA.id, enabled: true, strength: 1 }];+ }+ normalized = normalizeTemplateSettings({ ...normalized, catalogVersion: 6 })!;localStorage.setItem(GENERATOR_TEMPLATES_KEY, JSON.stringify(normalized));}return normalized;diff --git a/src/lib/weightDownloads.test.ts b/src/lib/weightDownloads.test.tsindex e67fcbe..995ae4f 100644--- a/src/lib/weightDownloads.test.ts+++ b/src/lib/weightDownloads.test.ts@@ -1,6 +1,6 @@// @vitest-environment jsdomimport { invoke } from "@tauri-apps/api/core";-import { downloadLora, removeLora, refreshDownloadedLoras, retryWeightDownload } from "./weightDownloads";+import { cancelWeightDownload, downloadLora, removeLora, refreshDownloadedLoras, retryWeightDownload } from "./weightDownloads";import { loadLoras, saveLoras, TAOMATE_LORA, TURBO_LORA } from "./loras";import { beforeEach, expect, it, vi } from "vitest";import { chooseWeightSource, downloadTemplateWeights, getWeightDownloadState, refreshDownloadedWeights, removeTemplateWeights, updateWeightPath, weightDownloadProgress, type DownloadState } from "./weightDownloads";@@ -141,7 +141,9 @@ it.each([0, 12, 20, 32])("downloads Singularity with four steps and the shared wvi.mocked(invoke).mockImplementation(async (command, args) => command === "weight_download_hardware"? (vram ? [{ name: "GPU", memoryBytes: vram * 1024 ** 3 }] : []) : original(command, args));await downloadTemplateWeights("minimax-h3-singularity");- expect(getWeightDownloadState()).toMatchObject({ active: false, completed: 4, error: null });+ expect(getWeightDownloadState()).toMatchObject({ active: false, completed: 5, files: 5, error: null });+ expect(invoke).toHaveBeenCalledWith("download_weight", expect.objectContaining({ url: TURBO_LORA.url }));+ expect(loadLoras().find(({ id }) => id === TURBO_LORA.id)?.path).not.toBe("");expect(invoke).toHaveBeenCalledWith("download_weight", expect.objectContaining({url: "https://huggingface.co/WarmBloodAban/Minimax-h3_Singularity/blob/main/Minimax-h3_Singularity_ref2va_Pruned_v1.3_int8.safetensors",}));@@ -156,6 +158,63 @@ it.each([0, 12, 20, 32])("downloads Singularity with four steps and the shared wexpect(defaultGeneratorTemplate().defaultSteps).toBe(4);});+it("reuses downloaded template LoRAs and restores readiness when a shared adapter goes missing", async () => {+ await downloadLora(TURBO_LORA.id);+ vi.mocked(invoke).mockClear();+ await downloadTemplateWeights("minimax-h3-singularity");+ expect(getWeightDownloadState()).toMatchObject({ completed: 4, error: null });+ expect(invoke).not.toHaveBeenCalledWith("download_weight", expect.objectContaining({ url: TURBO_LORA.url }));+ const settings = loadGeneratorTemplateSettings();+ const template = settings.templates.find(({ id }) => id === "minimax-h3-singularity")!;+ saveGeneratorTemplateSettings({ ...settings, defaultTemplateId: template.id });+ files.delete(loadLoras().find(({ id }) => id === TURBO_LORA.id)!.path);+ await refreshDownloadedWeights();+ expect(templateNeedsDownload(template)).toBe(true);+ expect(loadGeneratorTemplateSettings().defaultTemplateId).toBe("default");+ vi.mocked(invoke).mockClear();+ await downloadTemplateWeights(template.id);+ expect(getWeightDownloadState()).toMatchObject({ completed: 1, files: 1, error: null });+ expect(templateNeedsDownload(template)).toBe(false);+ expect(vi.mocked(invoke).mock.calls.filter(([command]) => command === "download_weight")).toHaveLength(1);+});++it.each([{ enabled: false, strength: 1 }, { enabled: true, strength: 0 }])("skips inactive template LoRAs: %j", async (selection) => {+ const template = createGeneratorTemplate();+ template.loras = [{ loraId: TURBO_LORA.id, ...selection }];+ saveGeneratorTemplateSettings({ templates: [template], defaultTemplateId: template.id, catalogVersion: 6 });+ expect(templateNeedsDownload(template)).toBe(false);+ await downloadTemplateWeights(template.id);+ expect(invoke).not.toHaveBeenCalledWith("download_weight", expect.anything());+ expect(getWeightDownloadState()).toMatchObject({ files: 0, error: null });+});++it("keeps generator progress and cancellation during its LoRA transfer, then retries only the missing adapter", async () => {+ const normal = vi.mocked(invoke).getMockImplementation()!;+ let started!: () => void;+ const downloadingLora = new Promise<void>((resolve) => { started = resolve; });+ let rejectDownload!: (reason: Error) => void;+ vi.mocked(invoke).mockImplementation(async (command, args) => {+ if (command === "download_weight" && (args as { url: string }).url === TURBO_LORA.url) {+ return new Promise((_resolve, reject) => { rejectDownload = reject; started(); });+ }+ if (command === "cancel_weight_download") { rejectDownload(new Error("Download cancelled.")); return; }+ return normal(command, args);+ });+ const pending = downloadTemplateWeights("minimax-h3-singularity");+ await downloadingLora;+ const state = getWeightDownloadState()!;+ expect(state).toMatchObject({ templateId: "minimax-h3-singularity", currentLoraId: TURBO_LORA.id, completed: 4, files: 5, active: true });+ expect(weightDownloadProgress({ ...state, downloaded: 50, total: 100 })).toBe(90);+ expect(templateNeedsDownload(loadGeneratorTemplateSettings().templates.find(({ id }) => id === state.templateId)!)).toBe(true);+ await cancelWeightDownload();+ await pending;+ expect(getWeightDownloadState()).toMatchObject({ active: false, error: "Download cancelled." });+ vi.mocked(invoke).mockImplementation(normal).mockClear();+ await retryWeightDownload();+ expect(getWeightDownloadState()).toMatchObject({ templateId: state.templateId, completed: 1, files: 1, error: null });+ expect(vi.mocked(invoke).mock.calls.filter(([command]) => command === "download_weight")).toHaveLength(1);+});+it("replaces a URL being typed instead of accumulating partial download sources", () => {let template = createGeneratorTemplate();for (const value of ["https://", "https://e", "https://example.com/model"]) template = updateWeightPath(template, "transformer", value);diff --git a/src/lib/weightDownloads.ts b/src/lib/weightDownloads.tsindex 47b0752..ed19a7c 100644--- a/src/lib/weightDownloads.ts+++ b/src/lib/weightDownloads.ts@@ -1,7 +1,7 @@import { invoke } from "@tauri-apps/api/core";import { listen } from "@tauri-apps/api/event";import { isTauri } from "./persistence";-import { loadLoras, saveLoras } from "./loras";+import { downloadableTemplateLoras, loadLoras, saveLoras, type Lora } from "./loras";import { ENGINE_PATH_FIELDS, isDownloadUrl, loadGeneratorTemplateSettings, saveGeneratorTemplateSettings, templateNeedsDownload,type EnginePathId, type GeneratorTemplate, type WeightSource } from "./settings";@@ -9,6 +9,7 @@ export interface WeightGpu { name: string; memoryBytes: number }export interface DownloadState {templateId: string;loraId?: string;+ currentLoraId?: string;name?: string;field: EnginePathId | null;downloaded: number;@@ -30,7 +31,7 @@ const publish = (next: DownloadState | null) => { state = next; subscribers.forEexport function weightDownloadProgress(download: DownloadState): number {if (!download.files) return 0;- const current = (download.field || download.loraId) && download.total && download.total > 0+ const current = (download.field || download.loraId || download.currentLoraId) && download.total && download.total > 0? Math.min(1, Math.max(0, download.downloaded / download.total)) : 0;return Math.min(download.active ? 99 : 100, 100 * (download.completed + current) / download.files);}@@ -63,6 +64,7 @@ export function refreshDownloadedWeights(): Promise<void> {if (!isTauri()) return Promise.resolve();if (refreshPending) return refreshPending;refreshPending = (async () => {+ await refreshDownloadedLoras();const before = loadGeneratorTemplateSettings();const paths = [...new Set(before.templates.flatMap((template) => Object.values(template.sources ?? {}).flatMap((sources) => sources.flatMap((source) => source.downloadedPath ? [source.downloadedPath] : []))))];if (!paths.length) return;@@ -110,7 +112,8 @@ export async function downloadTemplateWeights(templateId: string): Promise<void>if (!source) throw new Error(`No ${ENGINE_PATH_FIELDS.find((field) => field.id === id)?.label} download matches this GPU and its memory.`);return [{ field: id, source, originalPath: template.paths[id] }];});- publish({ ...state!, files: downloads.length });+ const loraDownloads = downloadableTemplateLoras(template.loras);+ publish({ ...state!, files: downloads.length + loraDownloads.length });unlisten = await listen<{ requestId: string; downloaded: number; total: number | null }>("weight-download-progress", ({ payload }) => {if (payload.requestId === requestId && state?.active) publish({ ...state, downloaded: payload.downloaded, total: payload.total });});@@ -134,6 +137,12 @@ export async function downloadTemplateWeights(templateId: string): Promise<void>saveGeneratorTemplateSettings({ ...current, templates });publish({ ...state!, completed: state!.completed + 1, field: null, downloaded: 0, total: null });}+ for (const lora of loraDownloads) {+ if (cancelled) throw new Error("Download cancelled.");+ publish({ ...state!, currentLoraId: lora.id, downloaded: 0, total: null });+ await transferLora(lora);+ publish({ ...state!, completed: state!.completed + 1, currentLoraId: undefined, downloaded: 0, total: null });+ }publish({ ...state!, active: false });} catch (reason) {publish({ ...state!, active: false, error: reason instanceof Error ? reason.message : String(reason) });@@ -148,6 +157,13 @@ export async function cancelWeightDownload() {if (requestId) await invoke("cancel_weight_download", { requestId });}+async function transferLora(lora: Lora): Promise<void> {+ requestId = crypto.randomUUID();+ const path = await invoke<string>("download_weight", { requestId, url: lora.url });+ if (!path || isDownloadUrl(path)) throw new Error("The download did not return a local file.");+ saveLoras(loadLoras().map((entry) => entry.id === lora.id && entry.url === lora.url && entry.path === lora.path ? { ...entry, path } : entry));+}+/** Uses the same native transfer, storage, cancellation and app-wide lock as weights. */export async function downloadLora(loraId: string): Promise<void> {if (!isTauri() || state?.active) return;@@ -162,10 +178,7 @@ export async function downloadLora(loraId: string): Promise<void> {if (payload.requestId === requestId && state?.active) publish({ ...state, downloaded: payload.downloaded, total: payload.total });});if (cancelled) throw new Error("Download cancelled.");- requestId = crypto.randomUUID();- const path = await invoke<string>("download_weight", { requestId, url: lora.url });- if (!path || isDownloadUrl(path)) throw new Error("The download did not return a local file.");- saveLoras(loadLoras().map((entry) => entry.id === loraId && entry.url === lora.url && entry.path === lora.path ? { ...entry, path } : entry));+ await transferLora(lora);publish({ ...state!, completed: 1, active: false });} catch (reason) {publish({ ...state!, active: false, error: reason instanceof Error ? reason.message : String(reason) });