AI media harness for planning, generating, and editing locally
TypeScript
Resolve global and scene LoRA selections
Bitti2e5776f9fbd8
diff --git a/src-tauri/src/project/scenes.rs b/src-tauri/src/project/scenes.rsindex b7f64fc..d8b3f54 100644--- a/src-tauri/src/project/scenes.rs+++ b/src-tauri/src/project/scenes.rs@@ -1,5 +1,12 @@use serde::{Deserialize, Serialize};use std::collections::BTreeMap;+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub(crate) struct SceneLoraOverride {+ pub(crate) lora_id: String,+ pub(crate) enabled: bool,+ pub(crate) strength: f64,+}/// One shot inside a scene. Mirrors `sceneShotSchema` in src/lib/project.ts.////// `startSeconds` and `action` are REQUIRED on the zod side and are plain@@ -40,6 +47,8 @@ pub(crate) struct SceneShot {#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub(crate) struct GenerationJob {+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub(crate) lora_overrides: Option<Vec<SceneLoraOverride>>,#[serde(default, skip_serializing_if = "Option::is_none")]pub(crate) generator_template_id: Option<String>,#[serde(default, skip_serializing_if = "Option::is_none")]@@ -180,6 +189,7 @@ impl GenerationJob {id: id.to_string(),scene_type: None,ending_prompt: None,+ lora_overrides: None,context_scene_id: None,backdrop_color: None,bridge_left_margin: None,diff --git a/src-tauri/src/project/validation/scenes.rs b/src-tauri/src/project/validation/scenes.rsindex dcad665..d9a536f 100644--- a/src-tauri/src/project/validation/scenes.rs+++ b/src-tauri/src/project/validation/scenes.rs@@ -10,6 +10,13 @@ fn validate_jobs(jobs: &mut [GenerationJob]) -> Result<(), String> {let mut previous_id = None;for job in jobs {validate_history(job)?;+ if let Some(loras) = &job.lora_overrides {+ let mut ids = BTreeSet::new();+ if loras.len() > 256 || loras.iter().any(|lora| lora.lora_id.trim().is_empty() || !ids.insert(&lora.lora_id)+ || !lora.strength.is_finite() || lora.strength.abs() > f64::from(f32::MAX)) {+ return Err(format!("Scene '{}' has invalid LoRA overrides.", job.id));+ }+ }if job.generator_template_id.as_ref().is_some_and(|id| id.trim().is_empty()) { return Err("Scene generator template id cannot be empty.".into()); }if job.use_previous_scene_last_frame == Some(true)&& matches!(job.scene_type.as_deref(), None | Some("first-last-frame")) {@@ -281,6 +288,21 @@ fn validate_history(job: &mut GenerationJob) -> Result<(), String> {mod history_tests {use super::*;#[test]+ fn scene_lora_overrides_roundtrip_and_validate_strengths_and_duplicates() {+ let mut wire: serde_json::Value = serde_json::from_str(include_str!("../../../../fixtures/project-v1-complete.json")).unwrap();+ let overrides = serde_json::json!([{ "loraId": "style", "enabled": false, "strength": 0.6 }]);+ wire["generationJobs"][0]["loraOverrides"] = overrides.clone();+ let mut config: ProjectConfig = serde_json::from_value(wire).unwrap();+ validate(&mut config).unwrap();+ assert_eq!(serde_json::to_value(&config).unwrap()["generationJobs"][0]["loraOverrides"], overrides);+ let entries = config.generation_jobs[0].lora_overrides.as_mut().unwrap();+ entries.push(entries[0].clone());+ assert!(validate(&mut config).unwrap_err().contains("LoRA"));+ let entries = config.generation_jobs[0].lora_overrides.as_mut().unwrap();+ entries.pop(); entries[0].strength = 1e39;+ assert!(validate(&mut config).unwrap_err().contains("LoRA"));+ }+ #[test]fn single_shot_fields_survive_native_project_roundtrip() {let mut config: ProjectConfig = serde_json::from_str(include_str!("../../../../fixtures/project-v1-complete.json")).unwrap();config.generation_jobs[0].scene_type = Some("single-shot".into());diff --git a/src/lib/agentGeneration.ts b/src/lib/agentGeneration.tsindex 2008986..2eba489 100644--- a/src/lib/agentGeneration.ts+++ b/src/lib/agentGeneration.ts@@ -6,8 +6,8 @@ import { imageScenePrompt } from "./imageScene";import { longShotBlocker } from "./longShot";import { continuationBlocker, continuationSceneId, generationAssetId, sceneGenerationPending, sceneGenerationSnapshot, sceneTypeFor } from "./project";import type { ProjectSession } from "./projectSession";-import { sceneGenerationRequest, sendBlocker, templateSceneBlocker } from "./sceneGeneration";-import { generatorPathFields, loadGeneratorTemplateSettings, templateSupportsMusic, templateUsable } from "./settings";+import { sceneLoraBlocker, sceneGenerationRequest, sendBlocker, templateSceneBlocker } from "./sceneGeneration";+import { templateWithSceneLoras, generatorPathFields, loadGeneratorTemplateSettings, templateSupportsMusic, templateUsable } from "./settings";import { isWorkActive, projectQueueKey, type WorkQueue } from "./workQueue";export interface SceneGenerateCommand { op: "scene.generate"; scene: string; template: string }@@ -122,7 +122,9 @@ export async function generateAgentScene(queue: WorkQueue, session: ProjectSessiif (!job) throw new Error(`Scene '${command.scene}' no longer exists.`);const template = loadGeneratorTemplateSettings().templates.find((candidate) => candidate.id === command.template);if (!template) throw new Error(`Generator template '${command.template}' no longer exists.`);- if (!templateUsable(template)) throw new Error(`Generator '${template.name}' needs its weights or LoRAs prepared before generation.`);+ const loraBlocker = sceneLoraBlocker(job, template);+ if (loraBlocker) throw new Error(loraBlocker);+ if (!templateUsable(templateWithSceneLoras(template, job))) throw new Error(`Generator '${template.name}' needs its weights or LoRAs prepared before generation.`);if (queue.getSnapshot().some((item) => item.projectKey === projectQueueKey(session.record) && item.sceneId === job.id && isWorkActive(item))) {throw new Error(`Scene '${job.title}' already has generation in progress. Do not submit it again.`);}diff --git a/src/lib/loras.test.ts b/src/lib/loras.test.tsindex 87f6da9..68bf3f8 100644--- a/src/lib/loras.test.ts+++ b/src/lib/loras.test.ts@@ -4,9 +4,67 @@ import { beforeEach, expect, it } from "vitest";import { PIKA_FL2VA_LORA, PIKA_REF2VA_LORA, DMAD_LORA, downloadableTemplateLoras, LIGHTX2V_TURBO_LORA, loadLoras, saveLoras, TAOMATE_LORA, TURBO_LORA, VIGGLE_ANIMATE_LORA } from "./loras";import { createGeneratorTemplate, engineProviderSetting, generationSigmaShifts, generationStepsWithLoras, loadGeneratorTemplateSettings, saveGeneratorTemplateSettings, withEngineSettings } from "./settings";import { createProjectConfig } from "./project";+import { effectiveLoras, moveLibraryLora, selectionConflict, loraSnapshot } from "./loras";+import { generationStepsForTemplate, templateNeedsDownload } from "./settings";+import { createDraftGenerationJob, parseProjectConfig, sceneGenerationSnapshot } from "./project";+import { sceneLoraBlocker, sceneGenerationRequest } from "./sceneGeneration";+import { sceneInput, duplicateScene } from "./sceneHistory";beforeEach(() => { localStorage.clear(); installH3TestDependencies(); });+it("merges global, template and scene LoRAs once in library order and keeps globals active", () => {+ saveLoras([{ id: "style", name: "Style", path: "D:/style", globallyEnabled: true, globalStrength: 0.7 },+ { id: "template", name: "Template", path: "D:/template", stepOverride: 12 },+ { ...PIKA_REF2VA_LORA, path: "D:/pika", globallyEnabled: true }]);+ const template = createGeneratorTemplate();+ template.loras = [{ loraId: "template", enabled: true, strength: 1 }, { loraId: "style", enabled: false, strength: 0 }];+ const overrides = [{ loraId: "style", enabled: false, strength: 0 }, { loraId: "template", enabled: false, strength: 1 }];+ const options = engineProviderSetting(template.paths, undefined, template.attention, template.loras, template.mode, [], true, {}, template, overrides).options;+ expect(JSON.parse(options.loras as string)).toEqual([{ path: "D:/style", strength: 0.7 }, { path: "D:/pika", strength: 1 }]);+ expect(options).toMatchObject({ stepOverride: 6, samplingPreset: "pika-6step", videoSigmaShiftOverride: 12, audioSigmaShiftOverride: 3 });+ expect(options).not.toHaveProperty("motionCache");+ expect(generationStepsForTemplate(30, template, overrides)).toBe(6);+ expect(effectiveLoras([], [], "fibo2")).toEqual([]);+ moveLibraryLora(PIKA_REF2VA_LORA.id, "style");+ expect(effectiveLoras(template.loras, overrides).filter((entry) => entry.enabled).map((entry) => entry.loraId)).toEqual([PIKA_REF2VA_LORA.id, "style"]);+});++it("rejects incompatible global recipes and Pika variants without changing the saved library", () => {+ saveLoras([{ ...DMAD_LORA, globallyEnabled: true }]);+ expect(() => saveLoras(loadLoras().map((lora) => lora.id === PIKA_REF2VA_LORA.id ? { ...lora, globallyEnabled: true } : lora))).toThrow("different sampling recipes");+ expect(loadLoras().find((lora) => lora.id === PIKA_REF2VA_LORA.id)?.globallyEnabled).toBeUndefined();+ expect(selectionConflict([PIKA_REF2VA_LORA, PIKA_FL2VA_LORA].map((lora) => ({ loraId: lora.id, enabled: true, strength: 1 })))).toContain("one Pika");+ expect(() => saveLoras([{ ...DMAD_LORA, globalStrength: 0 }])).toThrow("nonzero");+ expect(templateNeedsDownload(createGeneratorTemplate())).toBe(true);+});++it("blocks a four-update global recipe for Single Shot context and permits Pika's six updates", () => {+ saveLoras([{ ...DMAD_LORA, path: "D:/dmad", globallyEnabled: true }]);+ const job = { ...createDraftGenerationJob("Continue", { sceneType: "single-shot" }), contextSceneId: "original" };+ const template = createGeneratorTemplate();+ expect(sceneLoraBlocker(job, template)).toContain("more than four");+ saveLoras(loadLoras().map((lora) => ({ ...lora, globallyEnabled: lora.id === PIKA_REF2VA_LORA.id })));+ expect(sceneLoraBlocker(job, template)).toBeNull();+});++it("persists scene overrides and records effective render settings without persisting machine paths", () => {+ saveLoras([{ id: "style", name: "Style", path: "D:/private/style", stepOverride: 7 }]);+ const config = createProjectConfig({ name: "Test", prompt: "", aspectRatio: "16:9", resolution: "416p", targetDurationSeconds: 10 });+ const job = { ...createDraftGenerationJob("Walk"), loraOverrides: [{ loraId: "style", enabled: true, strength: 0.4 }] };+ config.generationJobs = [job];+ const template = createGeneratorTemplate();+ const request = sceneGenerationRequest(job, config, "D:/project", 30, template);+ const snapshot = sceneGenerationSnapshot(job, request);+ expect(JSON.parse(snapshot)).toMatchObject({ steps: 7, loras: [{ loraId: "style", strength: 0.4 }] });+ expect(snapshot).not.toContain("private");+ expect(sceneGenerationSnapshot(job, { ...request, steps: 7 })).toBe(snapshot);+ expect(parseProjectConfig(JSON.parse(JSON.stringify(config))).generationJobs[0].loraOverrides).toEqual(job.loraOverrides);+ expect(sceneInput(job).loraOverrides).toEqual(job.loraOverrides);+ expect(duplicateScene(config, job.id)?.config.generationJobs[1].loraOverrides).toEqual(job.loraOverrides);+ saveLoras(loadLoras().map((lora) => lora.id === "style" ? { ...lora, stepOverride: 8 } : lora));+ expect(loraSnapshot(effectiveLoras([], job.loraOverrides))).not.toEqual(request.loraSnapshot);+});+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 },@@ -123,7 +181,7 @@ it("round-trips template order, enabled flags and strengths, and sends only acticonst config = createProjectConfig({ name: "Test", prompt: "", aspectRatio: "16:9", resolution: "416p", targetDurationSeconds: 10 });const runtime = withEngineSettings(config);expect(JSON.parse(runtime.providerSettings.slopfab.options.loras as string)).toEqual([- { path: "D:/style.safetensors", strength: -0.5 }, { path: "C:/weights/TaoMate.safetensors", strength: 1 },+ { path: "C:/weights/TaoMate.safetensors", strength: 1 }, { path: "D:/style.safetensors", strength: -0.5 },]);expect(runtime.providerSettings.slopfab.options.stepOverride).toBe(3);expect(runtime.providerSettings.slopfab.options).not.toHaveProperty("schedule");diff --git a/src/lib/loras.ts b/src/lib/loras.tsindex 7a8b2c8..a3c3a36 100644--- a/src/lib/loras.ts+++ b/src/lib/loras.ts@@ -14,6 +14,8 @@ export interface Lora {audioSigmaShiftOverride?: number;samplingPreset?: "dmad-4step" | "pika-6step";needsPreparation?: boolean;+ globallyEnabled?: boolean;+ globalStrength?: number;}export interface TemplateLora { loraId: string; enabled: boolean; strength: number }export const TAOMATE_LORA: Lora = {@@ -68,6 +70,8 @@ export function loadLoras(): Lora[] {...(isSigmaShift(entry.videoSigmaShiftOverride) ? { videoSigmaShiftOverride: entry.videoSigmaShiftOverride } : {}),...(isSigmaShift(entry.audioSigmaShiftOverride) ? { audioSigmaShiftOverride: entry.audioSigmaShiftOverride } : {}),...(entry.needsPreparation === true ? { needsPreparation: true } : {}),+ ...(entry.globallyEnabled === true ? { globallyEnabled: true } : {}),+ ...(isLoraStrength(entry.globalStrength) && entry.globalStrength !== 0 ? { globalStrength: entry.globalStrength } : {}),...(typeof entry.url === "string" && /^https?:\/\//i.test(entry.url) ? { url: entry.url } : {}),...(isLoraStepOverride(entry.stepOverride) ? { stepOverride: entry.stepOverride }: entry.stepOverride === undefined && entry.schedule === "taomate-3step" ? { stepOverride: 3 } : {}) }];@@ -80,6 +84,10 @@ export function loadLoras(): Lora[] {} catch { return BUNDLED_LORAS.map((lora) => ({ ...lora })); }}export function saveLoras(loras: Lora[]): void {+ if (loras.some((lora) => lora.globalStrength !== undefined && (!isLoraStrength(lora.globalStrength) || lora.globalStrength === 0)))+ throw new Error("Global LoRA strength must be finite, nonzero and within the supported range.");+ const conflict = loraConflict(loras.filter((lora) => lora.globallyEnabled && (lora.modelType ?? "minimax-h3") === "minimax-h3"));+ if (conflict) throw new Error(conflict);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}.`);}@@ -95,6 +103,15 @@ export function subscribeLoras(listener: () => void) {window.addEventListener("storage", storage);return () => { window.removeEventListener(EVENT, listener); window.removeEventListener("storage", storage); };}++export function moveLibraryLora(id: string, targetId: string): void {+ const library = loadLoras();+ const from = library.findIndex((lora) => lora.id === id), to = library.findIndex((lora) => lora.id === targetId);+ if (from < 0 || to < 0 || from === to) return;+ const [entry] = library.splice(from, 1);+ library.splice(to, 0, entry);+ saveLoras(library);+}export function normalizeTemplateLoras(value: unknown): TemplateLora[] {const ids = new Set<string>();return Array.isArray(value) ? value.flatMap((entry) => {@@ -115,6 +132,8 @@ export function downloadableTemplateLoras(selection: TemplateLora[] = []): Lora[* URL adapters itself, so only adapters with neither a file nor a URL fail. */export function resolveTemplateLoras(selection: TemplateLora[] = [], worker = false) {const library = loadLoras();+ const conflict = selectionConflict(selection, library);+ if (conflict) throw new Error(conflict);return selection.filter((entry) => entry.enabled && entry.strength !== 0).flatMap((entry) => {const lora = library.find(({ id }) => id === entry.loraId);const strength = entry.strength;@@ -134,6 +153,40 @@ export function resolveTemplateLoras(selection: TemplateLora[] = [], worker = fa});}+/** Scene choices override templates; global adapters are always applied last.+ * The library order is the execution order, independent of the selection source. */+export function effectiveLoras(selection: TemplateLora[] = [], overrides: TemplateLora[] = [], modelType = "minimax-h3", library = loadLoras()): TemplateLora[] {+ const chosen = new Map(selection.map((entry) => [entry.loraId, entry]));+ for (const entry of overrides) chosen.set(entry.loraId, entry);+ if (modelType === "minimax-h3") for (const lora of library) {+ if (lora.globallyEnabled && (lora.modelType ?? "minimax-h3") === modelType)+ chosen.set(lora.id, { loraId: lora.id, enabled: true, strength: lora.globalStrength ?? 1 });+ }+ const order = new Map(library.map((lora, index) => [lora.id, index]));+ return [...chosen.values()].sort((a, b) => (order.get(a.loraId) ?? Infinity) - (order.get(b.loraId) ?? Infinity));+}++export function loraConflict(loras: Lora[]): string | null {+ if (new Set(loras.flatMap((lora) => lora.samplingPreset ? [lora.samplingPreset] : [])).size > 1)+ return "Active LoRAs require different sampling recipes. Choose either DMAD or Pika H3 Flex.";+ if (loras.some((lora) => lora.id === PIKA_FL2VA_LORA.id) && loras.some((lora) => lora.id === PIKA_REF2VA_LORA.id))+ return "Choose one Pika H3 Flex variant: FL2VA and Ref2VA cannot be enabled together.";+ return null;+}++export function selectionConflict(selection: TemplateLora[], library = loadLoras()): string | null {+ return loraConflict(library.filter((lora) => selection.some((entry) => entry.loraId === lora.id && entry.enabled && entry.strength !== 0)));+}++/** Portable render identity, including recipe changes and the actual stack order. */+export function loraSnapshot(selection: TemplateLora[], library = loadLoras()) {+ return selection.filter((entry) => entry.enabled && entry.strength !== 0).map((entry) => {+ const lora = library.find((lora) => lora.id === entry.loraId);+ return { ...entry, stepOverride: lora?.stepOverride, samplingPreset: lora?.samplingPreset,+ videoSigmaShiftOverride: lora?.videoSigmaShiftOverride, audioSigmaShiftOverride: lora?.audioSigmaShiftOverride };+ });+}+export const MAX_LORA_STRENGTH = 3.4028234663852886e38;export function isLoraStrength(value: unknown): value is number {diff --git a/src/lib/project.ts b/src/lib/project.tsindex 41287da..55fade8 100644--- a/src/lib/project.ts+++ b/src/lib/project.ts@@ -1,4 +1,5 @@import { motionSchema } from "./motion";+import { loraStepOverride } from "./loras";import { generationEffectsSchema, activeGenerationEffects, type GenerationEffects } from "./generationEffects";import { MIN_SIGMA_SHIFT, MAX_SIGMA_SHIFT } from "./sampling";import { z } from "zod";@@ -553,6 +554,8 @@ export function shotReferenceIds(shot: Pick<SceneShot, "action" | "speech">): st}const generationJobBaseSchema = z.object({+ loraOverrides: z.array(z.object({ loraId: idSchema, enabled: z.boolean(), strength: z.number().finite().min(-3.4028234663852886e38).max(3.4028234663852886e38) })).max(256)+ .refine((entries) => new Set(entries.map((entry) => entry.loraId)).size === entries.length, "LoRA overrides must be unique.").nullish(),generatorTemplateId: idSchema.nullish(),id: idSchema,sceneType: sceneTypeSchema.nullish(),@@ -1255,6 +1258,7 @@ export function sceneGenerationSeed(job: GenerationJob): number {}export interface SceneGenerationInput {+ loraSnapshot?: ReturnType<typeof import("./loras").loraSnapshot>;contextSceneId?: string;keystoneRelativePath?: string;singleShot?: { endingPrompt: string };@@ -1301,12 +1305,13 @@ export function sceneGenerationSnapshot(job: GenerationJob, input: SceneGeneratireturn JSON.stringify({...(job.sceneType ? { sceneType: job.sceneType } : {}),prompt: input.prompt,+ ...(input.loraSnapshot?.length ? { loras: input.loraSnapshot } : {}),...(input.contextSceneId ? { contextSceneId: input.contextSceneId, keystoneRelativePath: input.keystoneRelativePath, capstoneLockAfter: 4 } : {}),...(input.singleShot ? { singleShot: input.singleShot, ...(!input.contextSceneId ? { endingPrompt: job.endingPrompt ?? "" } : {}) } : {}),...(input.videoTransition ? { videoTransition: input.videoTransition } : {}),...(input.latentBridge ? { latentBridge: input.latentBridge } : {}),frames: input.frames,- steps: input.steps,+ steps: loraStepOverride(input.loraSnapshot ?? []) ?? input.steps,...(input.audioSteps !== undefined ? { audioSteps: input.audioSteps } : {}),...(activeGenerationEffects(input.generationEffects) ? { generationEffects: activeGenerationEffects(input.generationEffects) } : {}),...(input.videoSigmaShift !== undefined ? { videoSigmaShift: input.videoSigmaShift } : {}),diff --git a/src/lib/runtime.ts b/src/lib/runtime.tsindex cde6387..1058950 100644--- a/src/lib/runtime.ts+++ b/src/lib/runtime.ts@@ -101,6 +101,7 @@ export interface AgentTurnResponse {}export interface SlopfabGenerationRequest {+ loraSnapshot?: ReturnType<typeof import("./loras").loraSnapshot>;contextSceneId?: string;keystoneRelativePath?: string;singleShot?: { endingPrompt: string };diff --git a/src/lib/sceneGeneration.ts b/src/lib/sceneGeneration.tsindex 60f5aea..8307afa 100644--- a/src/lib/sceneGeneration.ts+++ b/src/lib/sceneGeneration.ts@@ -1,4 +1,5 @@import { activeGenerationEffects } from "./generationEffects";+import { effectiveLoras, loraSnapshot, loraStepOverride, selectionConflict } from "./loras";import { generationDimensions } from "./export";import { longShotContinuationInputs, longShotInputs } from "./longShot";import {@@ -26,6 +27,7 @@ export function sceneGenerationRequest(job: GenerationJob, config: ProjectConfigconst longShot = longShotInputs(job, config);return {jobId: job.id,+ loraSnapshot: loraSnapshot(effectiveLoras(template?.loras, job.loraOverrides ?? [], template?.modelType)),...(job.sceneType === "single-shot" && job.contextSceneId ? { contextSceneId: job.contextSceneId,keystoneRelativePath: config.generationJobs.find((scene) => scene.id === job.contextSceneId)?.latentRelativePath ?? undefined } : {}),...(job.sceneType === "single-shot" ? { singleShot: { endingPrompt: job.contextSceneId ? "" : job.endingPrompt?.trim()@@ -129,3 +131,16 @@ export function templateSceneBlocker(type: SceneType, template: GeneratorTemplatreturn null;}+export function sceneLoraBlocker(job: GenerationJob, template: GeneratorTemplate): string | null {+ const selection = effectiveLoras(template.loras, job.loraOverrides ?? [], template.modelType);+ const conflict = selectionConflict(selection);+ if (conflict) return conflict;+ if (job.sceneType === "single-shot" && job.contextSceneId) {+ const active = loraSnapshot(selection);+ const steps = loraStepOverride(active) ?? sceneGenerationSteps(job, template.defaultSteps);+ const updates = active.some((lora) => lora.samplingPreset) ? steps : steps - 1;+ if (updates <= 4) return "Context video needs more than four video sampling updates. Choose a longer sampling recipe or increase the step count.";+ }+ return null;+}+diff --git a/src/lib/settings.ts b/src/lib/settings.tsindex 0cbadc8..fef527c 100644--- a/src/lib/settings.ts+++ b/src/lib/settings.ts@@ -21,7 +21,7 @@ import { loadGenerationPreviewsEnabled } from "./generationPreviewSettings";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 { downloadableTemplateLoras, loadLoras, loraStepOverride, loraSigmaShiftOverrides, isLoraStepOverride, normalizeTemplateLoras, resolveTemplateLoras, subscribeLoras, TURBO_LORA, VIGGLE_ANIMATE_LORA, type TemplateLora } from "./loras";+import { effectiveLoras, selectionConflict, downloadableTemplateLoras, loadLoras, loraStepOverride, loraSigmaShiftOverrides, isLoraStepOverride, normalizeTemplateLoras, resolveTemplateLoras, subscribeLoras, TURBO_LORA, VIGGLE_ANIMATE_LORA, type TemplateLora } from "./loras";import { remoteWorkerSelected, selectedWorker, WORKERS_EVENT } from "./workers";/* Light/dark appearance is machine-level for the same reason and lives in@@ -157,16 +157,24 @@ export function chooseWeightSource(sources: WeightSource[], devices: WeightGpu[]* worker downloads URL weights itself, so a template only needs a source or* a local file for each model; this computer needs everything downloaded. */export function templateUsable(template: GeneratorTemplate): boolean {- if (!remoteWorkerSelected()) return !templateNeedsDownload(template);+ if (selectionConflict(effectiveLoras(template.loras, [], template.modelType))) return false;+ if (!remoteWorkerSelected()) {+ try { resolveTemplateLoras(effectiveLoras(template.loras, [], template.modelType)); return !templateNeedsDownload(template); }+ catch { return false; }+ }if (!generatorPathFields(template).every(({ id, required }) => !required || template.paths[id].trim() || (template.sources?.[id]?.length ?? 0) > 0)) return false;try {- resolveTemplateLoras(template.loras, true);+ resolveTemplateLoras(effectiveLoras(template.loras, [], template.modelType), true);return true;} catch {return false;}}+export function templateWithSceneLoras(template: GeneratorTemplate, job?: { loraOverrides?: TemplateLora[] | null }): GeneratorTemplate {+ return { ...template, loras: effectiveLoras(template.loras, job?.loraOverrides ?? [], template.modelType) };+}+/** Downloaded client weights do not pin a worker to the client's GPU variant.* Explicit local files without a matching download entry remain uploads. */function workerWeight(value: string, sources: WeightSource[] | undefined): string {@@ -182,7 +190,7 @@ export function templateNeedsDownload(template: GeneratorTemplate): boolean {return generatorPathFields(template).some(({ id }) => isDownloadUrl(template.paths[id])|| (template.modelType === MINIMAX_H3_MODEL_TYPE && (id === "videoVae" && template.videoVaeId !== undefined || id === "audioVae" && template.audioVaeId !== undefined || id === "textEncoder" && template.videoVaeId !== undefined) && !template.paths[id].trim())|| (!template.paths[id].trim() && (template.sources?.[id]?.length ?? 0) > 0))- || downloadableTemplateLoras(template.loras).length > 0+ || downloadableTemplateLoras(effectiveLoras(template.loras, [], template.modelType)).length > 0|| (template.additionalSafetensors ?? []).some((file) => !file.downloadedPath || isDownloadUrl(file.downloadedPath));}@@ -724,7 +732,7 @@ export function saveEngineSettings(settings: EngineSettings): void {/** The `slopfab` provider setting these paths describe, with blanks dropped so* an unset field falls through to whatever the project (or the Rust default)* already had rather than overwriting it with "". */-export function engineProviderSetting(settings: EngineSettings, base?: ProviderSetting, attention = defaultGeneratorTemplate().attention, selection = defaultGeneratorTemplate().loras, mode = defaultGeneratorTemplate().mode, additionalSafetensors = defaultGeneratorTemplate().additionalSafetensors, motionCache = defaultGeneratorTemplate().motionCache ?? false, sources = defaultGeneratorTemplate().sources, shifts: SigmaShifts & { modelType?: string; editingModel?: boolean } = defaultGeneratorTemplate()): ProviderSetting {+export function engineProviderSetting(settings: EngineSettings, base?: ProviderSetting, attention = defaultGeneratorTemplate().attention, selection = defaultGeneratorTemplate().loras, mode = defaultGeneratorTemplate().mode, additionalSafetensors = defaultGeneratorTemplate().additionalSafetensors, motionCache = defaultGeneratorTemplate().motionCache ?? false, sources = defaultGeneratorTemplate().sources, shifts: SigmaShifts & { modelType?: string; editingModel?: boolean } = defaultGeneratorTemplate(), sceneLoras: TemplateLora[] = []): ProviderSetting {// Resolve again at submission: a queued generator may predate a default encoder change.if (shifts.modelType === MINIMAX_H3_MODEL_TYPE) {const library = loadGeneratorTemplateSettings().h3Components!;@@ -776,7 +784,7 @@ export function engineProviderSetting(settings: EngineSettings, base?: ProviderSconst path = file?.downloadedPath && !isDownloadUrl(file.downloadedPath) ? file.downloadedPath : remote ? file?.url : undefined;if (path) options.promptEmbedding = path;}- const loras = resolveTemplateLoras(selection, remote);+ const loras = resolveTemplateLoras(effectiveLoras(selection, sceneLoras, shifts.modelType), remote);if (loras.length) options.loras = JSON.stringify(loras.map(({ path, strength }) => ({ path, strength })));const shiftOverrides = loraSigmaShiftOverrides(loras);if (shiftOverrides.videoSigmaShift !== undefined) options.videoSigmaShiftOverride = shiftOverrides.videoSigmaShift;@@ -804,20 +812,20 @@ export function engineProviderSetting(settings: EngineSettings, base?: ProviderS}/** The effective count shown for the selected generator before submission. */-export function generationStepsForTemplate(steps: number, template?: Pick<GeneratorTemplate, "loras">): number {+export function generationStepsForTemplate(steps: number, template?: Pick<GeneratorTemplate, "loras" | "modelType">, overrides: TemplateLora[] = []): number {// Display metadata without resolving weight paths: a template awaiting a// download can still show its step count without throwing during render.- const activeIds = new Set(template?.loras?.filter((entry) => entry.enabled && entry.strength !== 0).map((entry) => entry.loraId));+ const activeIds = new Set(effectiveLoras(template?.loras, overrides, template?.modelType).filter((entry) => entry.enabled && entry.strength !== 0).map((entry) => entry.loraId));return loraStepOverride(loadLoras().filter((lora) => activeIds.has(lora.id))) ?? steps;}-export function sigmaShiftOverridesForTemplate(template?: Pick<GeneratorTemplate, "loras">): SigmaShifts {- const active = new Set(template?.loras?.filter((entry) => entry.enabled && entry.strength !== 0).map((entry) => entry.loraId));+export function sigmaShiftOverridesForTemplate(template?: Pick<GeneratorTemplate, "loras" | "modelType">, overrides: TemplateLora[] = []): SigmaShifts {+ const active = new Set(effectiveLoras(template?.loras, overrides, template?.modelType).filter((entry) => entry.enabled && entry.strength !== 0).map((entry) => entry.loraId));return loraSigmaShiftOverrides(loadLoras().filter((lora) => active.has(lora.id)));}-export function generationSigmaShifts(shifts: { videoSigmaShift?: number | null; audioSigmaShift?: number | null }, template?: GeneratorTemplate): SigmaShifts {- const overrides = sigmaShiftOverridesForTemplate(template);+export function generationSigmaShifts(shifts: { videoSigmaShift?: number | null; audioSigmaShift?: number | null; loraOverrides?: TemplateLora[] | null }, template?: GeneratorTemplate): SigmaShifts {+ const overrides = sigmaShiftOverridesForTemplate(template, shifts.loraOverrides ?? []);return { videoSigmaShift: overrides.videoSigmaShift ?? shifts.videoSigmaShift ?? template?.videoSigmaShift,audioSigmaShift: overrides.audioSigmaShift ?? shifts.audioSigmaShift ?? template?.audioSigmaShift };}diff --git a/src/lib/weightDownloads.test.ts b/src/lib/weightDownloads.test.tsindex 0f99baa..d76e1d7 100644--- a/src/lib/weightDownloads.test.ts+++ b/src/lib/weightDownloads.test.ts@@ -157,6 +157,17 @@ it("preserves additional file edits while a download is in flight and retries faexpect(getWeightDownloadState()).toMatchObject({ active: false, completed: 1, error: null });});+it("downloads globally enabled LoRAs with a generator without baking them into its selection", async () => {+ const template = createGeneratorTemplate();+ saveGeneratorTemplateSettings({ templates: [template], defaultTemplateId: template.id, catalogVersion: 17 });+ saveLoras([{ ...DMAD_LORA, globallyEnabled: true }]);+ expect(templateNeedsDownload(loadGeneratorTemplateSettings().templates[0])).toBe(true);+ await downloadTemplateWeights(template.id);+ expect(invoke).toHaveBeenCalledWith("download_weight", { requestId: expect.any(String), url: DMAD_LORA.url });+ expect(loadLoras().find((lora) => lora.id === DMAD_LORA.id)).toMatchObject({ globallyEnabled: true, path: expect.stringContaining("dmad") });+ expect(loadGeneratorTemplateSettings().templates[0].loras ?? []).toEqual([]);+});+it.each([TAOMATE_LORA, TURBO_LORA, VIGGLE_ANIMATE_LORA, LIGHTX2V_TURBO_LORA, DMAD_LORA, PIKA_FL2VA_LORA, PIKA_REF2VA_LORA])("downloads $name through the weight transfer and restores missing downloads", async (lora) => {const savedLora = () => loadLoras().find(({ id }) => id === lora.id)!;await downloadLora(lora.id);diff --git a/src/lib/weightDownloads.ts b/src/lib/weightDownloads.tsindex c9d4147..1cd9c67 100644--- a/src/lib/weightDownloads.ts+++ b/src/lib/weightDownloads.ts@@ -2,7 +2,7 @@ import { invoke } from "@tauri-apps/api/core";import { listen } from "@tauri-apps/api/event";import { isTauri } from "./persistence";import { OTHER_WEIGHT_TEMPLATES, refreshOtherWeights, otherWeightPaths, saveOtherWeightPath } from "./upscalers";-import { downloadableTemplateLoras, loadLoras, saveLoras, type Lora } from "./loras";+import { effectiveLoras, downloadableTemplateLoras, loadLoras, saveLoras, type Lora } from "./loras";import { chooseWeightSource, ENGINE_PATH_FIELDS, generatorPathFields, isDownloadUrl, loadGeneratorTemplateSettings, saveGeneratorTemplateSettings, templateNeedsDownload,type EnginePathId, type GeneratorTemplate, type WeightGpu, type WeightSource } from "./settings";@@ -262,7 +262,7 @@ async function runTemplateDownload(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], component: h3ComponentForField(template, id, loadGeneratorTemplateSettings().h3Components!) }];});- const loraDownloads = downloadableTemplateLoras(template.loras);+ const loraDownloads = downloadableTemplateLoras(effectiveLoras(template.loras, [], template.modelType));const additionalDownloads = (template.additionalSafetensors ?? []).filter((file) => !file.downloadedPath);publish({ ...state!, files: downloads.length + loraDownloads.length + additionalDownloads.length });unlisten = await listen<{ requestId: string; downloaded: number; total: number | null }>("weight-download-progress", ({ payload }) => {diff --git a/src/lib/workQueue.test.ts b/src/lib/workQueue.test.tsindex cd24f40..64338ec 100644--- a/src/lib/workQueue.test.ts+++ b/src/lib/workQueue.test.ts@@ -27,6 +27,7 @@ import { completeSceneGeneration, sceneInput } from "./sceneHistory";import { newSong } from "./music";import { musicTemplates } from "./settings";import { bridgeGapFrames, currentLongShotArchives } from "./longShot";+import { DMAD_LORA, saveLoras, loadLoras, moveLibraryLora } from "./loras";vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));vi.mock("@tauri-apps/api/event", () => ({ listen: vi.fn() }));@@ -69,6 +70,31 @@ const finish = async (queue: WorkQueue, id: string) => {await waitFor(() => expect(queue.getSnapshot().find((item) => item.id === id)?.status).toBe("completed"));};+it("captures global order and scene overrides before queued generation and keeps globals active", async () => {+ saveLoras([{ ...DMAD_LORA, path: "D:/dmad", globallyEnabled: true },+ { id: "style", name: "Style", path: "D:/style" }, { id: "template", name: "Template", path: "D:/template" }]);+ const { queue, first } = setup();+ first.update((config) => ({ ...config, generationJobs: config.generationJobs.map((job) => ({ ...job,+ loraOverrides: [{ loraId: DMAD_LORA.id, enabled: false, strength: 0 }, { loraId: "template", enabled: false, strength: 1 }, { loraId: "style", enabled: true, strength: 0.6 }] })) }));+ const template = { ...loadGeneratorTemplateSettings().templates[0], loras: [{ loraId: "template", enabled: true, strength: 1 }], motionCache: true };+ const config = first.getSnapshot().config, job = config.generationJobs[0];+ const request = sceneGenerationRequest(job, config, first.record.folderPath, 30, template);+ const snapshot = sceneGenerationSnapshot(job, request);+ const [id] = queue.enqueue(first, [{ job, request, snapshot }], template);+ moveLibraryLora("style", DMAD_LORA.id);+ saveLoras(loadLoras().map((lora) => ({ ...lora, globallyEnabled: false })));+ await waitFor(() => expect(enqueueSlopfabGeneration).toHaveBeenCalledTimes(1));+ const [sent, captured] = vi.mocked(enqueueSlopfabGeneration).mock.calls[0];+ expect(sent.steps).toBe(4);+ expect(sent.videoSigmaShift).toBe(12); expect(sent.audioSigmaShift).toBe(2);+ const options = captured.providerSettings.slopfab.options;+ expect(options.motionCache).toBeUndefined();+ expect(JSON.parse(options.loras as string)).toEqual([{ path: "D:/dmad", strength: 1 }, { path: "D:/style", strength: 0.6 }]);+ expect(first.getSnapshot().config.generationJobs[0].generationSnapshot).toBe(snapshot);+ await finish(queue, id);+ expect(first.getSnapshot().config.generationJobs[0].generationHistory?.versions[0].scene.loraOverrides).toEqual(job.loraOverrides);+});+it("isolates live previews by native job and clears them on disable, cancel and completion", async () => {const { queue, first, second } = setup();const [id] = queue.enqueue(first, [submission(first)]);diff --git a/src/lib/workQueue.ts b/src/lib/workQueue.tsindex 5edfcec..6edf371 100644--- a/src/lib/workQueue.ts+++ b/src/lib/workQueue.ts@@ -1,3 +1,4 @@+import { effectiveLoras, loraSnapshot } from "./loras";import { completeSceneGeneration, sceneInput } from "./sceneHistory";import { musicSongSchema, musicSettingsForModel, newSongVariation, updateSong, type MusicSong } from "./music";import { templateSupportsMusic } from "./settings";@@ -244,7 +245,7 @@ export class WorkQueue {const chosen = template ?? submission.template ?? loadGeneratorTemplateSettings().templates.find(t => t.id === submission.job.generatorTemplateId) ?? defaultGeneratorTemplate(undefined, "video");if (!templateSupportsVideo(chosen)) throw new Error("Choose a generator that supports video generation.");const config = structuredClone({ ...current, providerSettings: { ...current.providerSettings,- slopfab: engineProviderSetting(chosen.paths, current.providerSettings.slopfab, chosen.attention, chosen.loras ?? [], chosen.mode ?? "prompt", chosen.additionalSafetensors ?? [], chosen.motionCache ?? false, chosen.sources ?? {}, chosen),+ slopfab: engineProviderSetting(chosen.paths, current.providerSettings.slopfab, chosen.attention, chosen.loras ?? [], chosen.mode ?? "prompt", chosen.additionalSafetensors ?? [], chosen.motionCache ?? false, chosen.sources ?? {}, chosen, submission.job.loraOverrides ?? []),} });const captured = submission.upscaleSource ? submission.job : { ...submission.job, generatorTemplateId: chosen.id || undefined, steps: submission.request.steps, seed: submission.request.seed };config.generationJobs = config.generationJobs.map(j => j.id === captured.id ? structuredClone(captured) : j);@@ -252,9 +253,11 @@ export class WorkQueue {ids.push(id);let finish!: () => void;const done = new Promise<void>((resolve) => { finish = resolve; });- const request = structuredClone({ ...submission.request, jobId: id, ...(!submission.upscaleSource ? { steps: generationStepsWithLoras(submission.request.steps, config),+ const request = structuredClone({ ...submission.request, jobId: id, loraSnapshot: loraSnapshot(effectiveLoras(chosen.loras, submission.job.loraOverrides ?? [], chosen.modelType)), ...(!submission.upscaleSource ? { steps: generationStepsWithLoras(submission.request.steps, config),...generationSigmaShiftsWithLoras(submission.request, config) } : {}) });- this.work.set(id, { id, session, sceneId: submission.job.id, sceneInput: structuredClone(submission.upscaleSource?.scene ?? sceneInput(captured)), upscaleSource: submission.upscaleSource && structuredClone(submission.upscaleSource), request, config, snapshot: submission.snapshot, cancelled: false, submitted: false, done, finish });+ const snapshot = !submission.upscaleSource && (request.loraSnapshot.length || submission.request.loraSnapshot?.length)+ ? sceneGenerationSnapshot(captured, request) : submission.snapshot;+ this.work.set(id, { id, session, sceneId: submission.job.id, sceneInput: structuredClone(submission.upscaleSource?.scene ?? sceneInput(captured)), upscaleSource: submission.upscaleSource && structuredClone(submission.upscaleSource), request, config, snapshot, cancelled: false, submitted: false, done, finish });this.items = [...this.items, {id, generationGroupId: id, projectKey, folderPath: session.record.folderPath, projectName: config.name,sceneId: submission.job.id, title: submission.job.title, submittedAt: new Date().toISOString(),@@ -263,7 +266,7 @@ export class WorkQueue {settings: { frames: request.frames, steps: request.steps, audioSteps: request.audioSteps, videoSigmaShift: request.videoSigmaShift, audioSigmaShift: request.audioSigmaShift, latentUpscale: request.latentUpscale, seed: request.seed, canvasWidth: request.canvasWidth, canvasHeight: request.canvasHeight },}];this.updateScene(this.work.get(id)!, { status: "queued", stage: "queued", progress: 0, error: null,- ...(!submission.upscaleSource ? { generationSnapshot: submission.snapshot, generatorTemplateId: captured.generatorTemplateId, steps: captured.steps, seed: captured.seed } : {}) });+ ...(!submission.upscaleSource ? { generationSnapshot: snapshot, generatorTemplateId: captured.generatorTemplateId, steps: captured.steps, seed: captured.seed } : {}) });}// Link after the whole batch is present, including sources submitted in// earlier calls. Group IDs survive completed-work cleanup and draft edits.