AI media harness for planning, generating, and editing locally
TypeScript
Support saved latent upscaling
Bittia1d35fe4c97b
diff --git a/lib/slopfab/libslopfab.so b/lib/slopfab/libslopfab.soindex da3864b..c9a2f26 100644--- a/lib/slopfab/libslopfab.so+++ b/lib/slopfab/libslopfab.so@@ -1,3 +1,3 @@version https://git-lfs.github.com/spec/v1-oid sha256:42baf6b979137ab4f261c1d845020a5dc216f16191e2b88710a006172192affa-size 23057992+oid sha256:1d4637d8fe4372ebc859d3ea9f8bc33e8c7012e4be720fe51b4772fb6ef839b5+size 23090992diff --git a/lib/slopfab/slopfab.dll b/lib/slopfab/slopfab.dllindex e538cc5..36d858e 100644--- a/lib/slopfab/slopfab.dll+++ b/lib/slopfab/slopfab.dll@@ -1,3 +1,3 @@version https://git-lfs.github.com/spec/v1-oid sha256:43445d0f5109ce2e58305a27ecdd19d18be1b9ea3c99bc386b19b4ad29289eb8-size 19651072+oid sha256:baadda394f2c6bcd39da606f7cacbf7b6d32465effbd2a4d7cba99e525dbb01c+size 19668480diff --git a/src-tauri/core/src/slopfab/config.rs b/src-tauri/core/src/slopfab/config.rsindex 1e3781d..437df69 100644--- a/src-tauri/core/src/slopfab/config.rs+++ b/src-tauri/core/src/slopfab/config.rs@@ -123,6 +123,13 @@ impl Configuration {}pub(super) fn validate_inputs(&self, request: &GenerationRequest) -> Result<(), String> {+ if request.latent_upscale_source.is_some() {+ if self.model_type != "minimax-h3" { return Err("Saved latent upscaling requires MiniMax H3.".into()); }+ for (label, path) in [("latent upscaler", self.latent_upscaler.as_ref()), ("video VAE", self.models[3].2.as_ref()), ("audio VAE", self.models[4].2.as_ref())] {+ if !path.is_some_and(|path| path.is_file()) { return Err(format!("Download the {label} weights before upscaling.")); }+ }+ return Ok(());+ }if request.single_shot.is_some() && (self.model_type != "minimax-h3" || self.animate) {return Err("Single Shot requires a MiniMax H3 prompt generator.".into());}diff --git a/src-tauri/core/src/slopfab/ffi/handles.rs b/src-tauri/core/src/slopfab/ffi/handles.rsindex 9369bfb..203fe38 100644--- a/src-tauri/core/src/slopfab/ffi/handles.rs+++ b/src-tauri/core/src/slopfab/ffi/handles.rs@@ -24,6 +24,12 @@ pub struct GenerationHandle {}impl GenerationHandle {+ pub fn upscale(api: &Api, source: &str, checkpoint: &std::path::Path, scale: f32, video: &std::path::Path, audio: &std::path::Path, backend: i32, sink: ProgressSink) -> Result<Self, String> {+ let mut callback = Box::new(Callback(sink));+ let userdata = (&mut *callback as *mut Callback).cast();+ let pointer = api.inner.upscale_decode(source, checkpoint, scale, video, audio, backend, Some(progress_callback), userdata)?;+ Ok(Self { api: api.clone(), pointer: NonNull::new(pointer).ok_or("SlopFab returned an empty upscale handle.")?, _callback: Some(callback), terminal: false, succeeded: false })+ }pub(super) fn start(request: RequestHandle,sink: Option<ProgressSink>,@@ -125,6 +131,9 @@ pub struct Output {}impl FinishedGeneration {+ pub fn save_latents(&self, path: &std::path::Path) -> Result<(), String> {+ self.0.api.inner.save_generation_latents(self.0.pointer.as_ptr(), path)+ }pub fn video_decode_timings(&self) -> Result<Option<super::VideoDecodeTimings>, String> {self.0.api.inner.video_decode_timings(self.0.pointer.as_ptr())}diff --git a/src-tauri/core/src/slopfab/ffi/mod.rs b/src-tauri/core/src/slopfab/ffi/mod.rsindex 66f1486..c31a3a7 100644--- a/src-tauri/core/src/slopfab/ffi/mod.rs+++ b/src-tauri/core/src/slopfab/ffi/mod.rs@@ -19,6 +19,7 @@ pub struct Api {path: PathBuf,}impl Api {+ pub fn require_saved_latent_upscale(&self) -> Result<(), String> { self.inner.require_saved_latent_upscale() }pub fn load(path: &Path) -> Result<Self, String> {let inner = raw::Api::load(path)?;inner.version()?;diff --git a/src-tauri/core/src/slopfab/ffi/raw/mod.rs b/src-tauri/core/src/slopfab/ffi/raw/mod.rsindex e44a47b..9a7471c 100644--- a/src-tauri/core/src/slopfab/ffi/raw/mod.rs+++ b/src-tauri/core/src/slopfab/ffi/raw/mod.rs@@ -76,10 +76,13 @@ type SetMotionCache =type SetImageEditPath = unsafe extern "C" fn(*mut Request, *const c_char, i32, i32, i32, i32, f32, i32) -> i32;type SetImageEditRgb = unsafe extern "C" fn(*mut Request, *const u8, usize, i32, i32, usize, i32, i32, i32, i32, f32, i32) -> i32;type ExportRefmod = unsafe extern "C" fn(*const Request, *const c_char, *const c_char, *const c_char, i32) -> i32;+type UpscaleDecode = unsafe extern "C" fn(*const c_char, *const c_char, f32, *const c_char, *const c_char, i32, ProgressFn, *mut c_void, *mut *mut Generation) -> i32;type SetImageGuidance = unsafe extern "C" fn(*mut Request, f32, *const c_char, *const i32, i32) -> i32;pub struct Api {+ upscale_decode: Option<UpscaleDecode>,+ save_generation_latents: Option<unsafe extern "C" fn(*const Generation, *const c_char) -> i32>,set_music_settings: Option<unsafe extern "C" fn(*mut Request, *const c_char) -> i32>,set_vulkan_arithmetic: Option<unsafe extern "C" fn(*mut Request, i32) -> i32>,set_image_guidance: Option<SetImageGuidance>,@@ -331,6 +334,8 @@ impl Api {"slopfab_describe_plan",unsafe extern "C" fn(*const Request, *mut *mut c_char) -> i32),+ upscale_decode: library.get::<UpscaleDecode>(b"slopfab_latent_upscale_decode_file_start\0").ok().map(|f| *f),+ save_generation_latents: library.get::<unsafe extern "C" fn(*const Generation, *const c_char) -> i32>(b"slopfab_generation_save_latents\0").ok().map(|f| *f),generation_start: symbol!("slopfab_generation_start",unsafe extern "C" fn(@@ -747,6 +752,27 @@ impl Api {self.error(unsafe { (self.generation_start)(request, callback, userdata, &mut value) })?;Ok(value)}+ pub fn require_saved_latent_upscale(&self) -> Result<(), String> {+ if self.upscale_decode.is_none() || self.save_generation_latents.is_none() {+ return Err("Update SlopFab to C API 1.43 or later for saved latent upscaling.".into());+ }+ Ok(())+ }+ pub fn upscale_decode(&self, source: &str, checkpoint: &Path, scale: f32, video: &Path, audio: &Path, backend: i32, callback: ProgressFn, userdata: *mut c_void) -> Result<*mut Generation, String> {+ self.require_saved_latent_upscale()?;+ let strings = [source.to_owned(), checkpoint.to_string_lossy().into_owned(), video.to_string_lossy().into_owned(), audio.to_string_lossy().into_owned()]+ .map(|s| CString::new(s).map_err(|_| "Model and latent paths cannot contain null characters.".to_owned()));+ let [source, checkpoint, video, audio] = strings;+ let (source, checkpoint, video, audio) = (source?, checkpoint?, video?, audio?);+ let mut value = ptr::null_mut();+ self.error(unsafe { self.upscale_decode.unwrap()(source.as_ptr(), checkpoint.as_ptr(), scale, video.as_ptr(), audio.as_ptr(), backend, callback, userdata, &mut value) })?;+ Ok(value)+ }+ pub fn save_generation_latents(&self, generation: *mut Generation, path: &Path) -> Result<(), String> {+ let save = self.save_generation_latents.ok_or("The runtime cannot save enlarged latents.")?;+ let path = CString::new(path.to_string_lossy().as_bytes()).map_err(|_| "Invalid latent output path.")?;+ self.error(unsafe { save(generation, path.as_ptr()) })+ }pub fn cancel(&self, generation: *mut Generation) {unsafe { (self.generation_cancel)(generation) }}diff --git a/src-tauri/core/src/slopfab/ffi/tests.rs b/src-tauri/core/src/slopfab/ffi/tests.rsindex e05bb9c..ada81ae 100644--- a/src-tauri/core/src/slopfab/ffi/tests.rs+++ b/src-tauri/core/src/slopfab/ffi/tests.rs@@ -1,5 +1,11 @@use super::*;+#[test]+fn bundled_runtime_exposes_saved_latent_upscale_and_decode() {+ let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../lib/slopfab").join(crate::slopfab::DLL_FILE_NAME);+ Api::load(&path).unwrap().require_saved_latent_upscale().unwrap();+}+#[test]fn continuation_lock_overlap_can_be_enabled_and_disabled() {// Exercise the bundled runtime, including when a running app holds an older staged DLL.diff --git a/src-tauri/core/src/slopfab/generation.rs b/src-tauri/core/src/slopfab/generation.rsindex 9ad2a80..90e0bff 100644--- a/src-tauri/core/src/slopfab/generation.rs+++ b/src-tauri/core/src/slopfab/generation.rs@@ -26,6 +26,7 @@ impl rendered::FrameSource for FrameSource {pub(super) fn run_generation(item: &QueueItem,) -> Result<(OutputMetadata, rendered::RenderedVideo), String> {+ if item.request.latent_upscale_source.is_some() { return run_latent_upscale(item); }if item.request.single_shot.is_some() {ffi::Api::load(&item.configuration.dll_path)?.require_end_anchor()?;return run_single_shot(item, run_single_generation);@@ -266,6 +267,33 @@ fn run_single_generation(collect_output(item, output, source, timing_profile)}+fn run_latent_upscale(item: &QueueItem) -> Result<(OutputMetadata, rendered::RenderedVideo), String> {+ let _models = super::MODEL_ACCESS.read().map_err(|_| "Model access lock failed.")?;+ if item.cancel.load(Ordering::Acquire) { return Err("Upscaling cancelled.".into()); }+ let config = &item.configuration;+ config.validate_inputs(&item.request)?;+ let plan = super::latent_upscale::plan(&item.request)?;+ let api = ffi::Api::load(&config.dll_path)?;+ let platform = config.platform(detect_platform(&api));+ let timing_profile = format!("{}|savedLatentUpscale", config.timing_profile(&api.version()?, platform));+ let source = item.request.latent_upscale_source.as_ref().unwrap();+ let context = CallbackContext { events: item.events.clone(), job_id: item.request.job_id.clone(), frames: plan.aligned_frames,+ canvas_width: plan.canvas_width, canvas_height: plan.canvas_height, reference_count: 0, timing_profile: timing_profile.clone(), planned_steps: 0 };+ let mut generation = ffi::GenerationHandle::upscale(&api, &source.path, config.latent_upscaler.as_ref().unwrap(), source.scale,+ config.models[3].2.as_ref().unwrap(), config.models[4].2.as_ref().unwrap(), platform.backend(), progress_sink(context))?;+ loop {+ if item.cancel.load(Ordering::Acquire) { generation.cancel(); }+ if generation.wait(100)? { break; }+ }+ let generation = generation.finish()?;+ if item.cancel.load(Ordering::Acquire) { return Err("Upscaling cancelled.".into()); }+ let destination = item.request.save_latents_path.as_ref().ok_or("Missing destination for enlarged latents.")?;+ if destination.exists() { return Err("Latents already exist. Start a new upscale to preserve them.".into()); }+ generation.save_latents(destination)?;+ let output = generation.output()?;+ collect_output(item, output, Box::new(FrameSource { generation }), timing_profile)+}+fn collect_output(item: &QueueItem, output: ffi::Output, source: Box<dyn rendered::FrameSource>, timing_profile: String) -> Result<(OutputMetadata, rendered::RenderedVideo), String> {let frames = if item.request.music.is_some() { 0 } else { scene_frame_window(&item.request, output.frames)?.1 };// The VAE decoded both sides of the boundary together. Keep that completediff --git a/src-tauri/core/src/slopfab/generation_tests.rs b/src-tauri/core/src/slopfab/generation_tests.rsindex 56ba29f..fa170fc 100644--- a/src-tauri/core/src/slopfab/generation_tests.rs+++ b/src-tauri/core/src/slopfab/generation_tests.rs@@ -2,6 +2,47 @@ use super::*;use crate::slopfab::{config::Configuration, events::NativeEvent, references::ReferenceVideos, types::{GenerationRequest, ProgressEvent}};use std::sync::{Arc, Mutex, atomic::AtomicBool};+#[test]+#[ignore = "requires local H3 VAE/upscaler weights and a GPU; set SLOPUS_UPSCALE_WEIGHTS"]+fn saved_latent_upscale_gpu_smoke() {+ use std::io::Write;+ use crate::settings::{ProviderOption, ProviderSetting};+ let root = std::path::PathBuf::from(std::env::var("SLOPUS_UPSCALE_WEIGHTS").unwrap());+ let folder = tempfile::tempdir().unwrap();+ let source = folder.path().join("source.safetensors");+ let output = folder.path().join("upscaled.safetensors");+ let video_bytes = 7 * 2 * 96 * 4;+ let audio_bytes = 37 * 2 * 32 * 4;+ let header = serde_json::json!({"__metadata__":{"slopfab_latents":"h3-av-v1", "fps":"24", "sampled":"1", "frames":"22", "width":"64", "height":"32"},+ "video_rows":{"dtype":"F32", "shape":[14,96], "data_offsets":[0,video_bytes]},+ "audio_rows":{"dtype":"F32", "shape":[74,32], "data_offsets":[video_bytes,video_bytes+audio_bytes]}}).to_string();+ let mut file = std::fs::File::create(&source).unwrap();+ file.write_all(&(header.len() as u64).to_le_bytes()).unwrap();+ file.write_all(header.as_bytes()).unwrap();+ file.write_all(&vec![0; video_bytes + audio_bytes]).unwrap();+ drop(file);+ let original = std::fs::read(&source).unwrap();+ let mut options = std::collections::BTreeMap::new();+ for (key, name) in [("latentUpscaler", "minimax_h3_latent_upscaler_3d_conv_v1_fp16.safetensors"),+ ("videoVae", "vae/minimax_h3_video_vae_fp16.safetensors"), ("audioVae", "vae/minimax_h3_audio_vae_fp32.safetensors")] {+ options.insert(key.into(), ProviderOption::String(root.join(name).to_string_lossy().into_owned()));+ }+ let dll = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../lib/slopfab").join(crate::slopfab::DLL_FILE_NAME);+ options.insert("dllPath".into(), ProviderOption::String(dll.to_string_lossy().into_owned()));+ let settings = std::collections::BTreeMap::from([("slopfab".into(), ProviderSetting { enabled: true, model: None, options })]);+ let request = GenerationRequest { job_id: "upscale-smoke".into(),+ latent_upscale_source: Some(crate::slopfab::LatentUpscaleSource { path: source.to_string_lossy().into_owned(), scale: 2.0 }),+ save_latents_path: Some(output.clone()), ..Default::default() };+ let item = QueueItem { request, configuration: Configuration::from_settings(&settings), references: ReferenceVideos::default(),+ events: Arc::new(|_| {}), cancel: Arc::new(AtomicBool::new(false)) };+ let (metadata, rendered) = run_generation(&item).unwrap();+ assert_eq!((metadata.width, metadata.height, metadata.frames, metadata.steps_computed), (128, 64, 22, 0));+ assert_eq!(rendered.frame(0).unwrap().unwrap().len(), 128 * 64 * 4);+ assert!(!rendered.audio_bytes().is_empty());+ assert!(output.is_file());+ assert_eq!(std::fs::read(source).unwrap(), original);+}+#[test]#[ignore = "requires local music weights and a GPU; set SLOPUS_MUSIC_WEIGHTS"]fn music_gpu_smoke() {diff --git a/src-tauri/core/src/slopfab/latent_upscale.rs b/src-tauri/core/src/slopfab/latent_upscale.rsnew file mode 100644index 0000000..3d89b44--- /dev/null+++ b/src-tauri/core/src/slopfab/latent_upscale.rs@@ -0,0 +1,68 @@+use super::types::{GenerationRequest, ResolvedPlan};+use std::{fs::File, io::Read};++/// Read only the bounded archive header; the runtime validates tensors before execution.+pub(super) fn plan(request: &GenerationRequest) -> Result<ResolvedPlan, String> {+ let source = request.latent_upscale_source.as_ref().ok_or("Missing upscale source.")?;+ if ![1.5, 2.0, 4.0].contains(&source.scale) { return Err("Unsupported upscale factor.".into()); }+ let mut file = File::open(&source.path).map_err(|e| format!("Could not read saved latents: {e}"))?;+ let mut length = [0; 8];+ file.read_exact(&mut length).map_err(|e| e.to_string())?;+ let length = u64::from_le_bytes(length);+ if length > 1024 * 1024 { return Err("Invalid latent archive header length.".into()); }+ let mut bytes = vec![0; length as usize];+ file.read_exact(&mut bytes).map_err(|e| e.to_string())?;+ let header: serde_json::Value = serde_json::from_slice(&bytes).map_err(|e| e.to_string())?;+ let meta = &header["__metadata__"];+ if meta["slopfab_latents"] != "h3-av-v1" || meta["fps"] != "24" || meta["sampled"] != "1" {+ return Err("Upscaling requires completed H3 video latents.".into());+ }+ let integer = |key: &str| meta[key].as_str().and_then(|s| s.parse::<i32>().ok()).ok_or_else(|| format!("Invalid latent {key}."));+ let frames = integer("frames")?;+ let width = integer("width")?;+ let height = integer("height")?;+ if frames < 22 || frames % 17 != 5 || [width, height].iter().any(|n| !(32..=8192).contains(n) || n % 32 != 0) {+ return Err("Invalid source latent geometry.".into());+ }+ // Match SlopFab's nearest 32-pixel alignment, including ties to even.+ let scaled = |n: i32| ((n as f64 * f64::from(source.scale) / 32.0).round_ties_even() as i32) * 32;+ let (width, height) = (scaled(width), scaled(height));+ if width > 8192 || height > 8192 { return Err("The enlarged video cannot exceed 8192 pixels per side.".into()); }+ Ok(ResolvedPlan { canvas_width: width, canvas_height: height, aligned_frames: frames, duration_seconds: frames as f64 / 24.0,+ model_evaluations: 0, sequence_rows_without_text: 0, latent_frames: (frames - 5) / 17 * 5 + 2,+ latent_width: width / 16, latent_height: height / 16, description: format!("Upscale saved latents {}x to {width} × {height}", source.scale),+ boundary: "Upscale and decode saved latents without diffusion; the source archive stays unchanged." })+}++#[cfg(test)]+mod tests {+ use super::*;+ use std::io::Write;++ #[test]+ fn saved_latent_upscale_reads_geometry_and_matches_native_alignment() {+ let mut file = tempfile::NamedTempFile::new().unwrap();+ let header = serde_json::json!({"__metadata__": {"slopfab_latents":"h3-av-v1", "fps":"24", "sampled":"1", "frames":"124", "width":"736", "height":"416"}}).to_string();+ file.write_all(&(header.len() as u64).to_le_bytes()).unwrap();+ file.write_all(header.as_bytes()).unwrap();+ let original = std::fs::read(file.path()).unwrap();+ for (scale, width, height) in [(1.5, 1088, 640), (2.0, 1472, 832), (4.0, 2944, 1664)] {+ let request = GenerationRequest { latent_upscale_source: Some(super::super::types::LatentUpscaleSource { path: file.path().to_string_lossy().into_owned(), scale }), ..Default::default() };+ super::super::planning::validate_generation_controls(&request).unwrap();+ let output = plan(&request).unwrap();+ assert_eq!((output.canvas_width, output.canvas_height, output.aligned_frames), (width, height, 124));+ assert_eq!(output.model_evaluations, 0);+ }+ assert_eq!(std::fs::read(file.path()).unwrap(), original);+ }++ #[test]+ fn saved_latent_upscale_rejects_unbounded_headers_and_generation_controls() {+ let mut file = tempfile::NamedTempFile::new().unwrap();+ file.write_all(&u64::MAX.to_le_bytes()).unwrap();+ let mut request = GenerationRequest { latent_upscale_source: Some(super::super::types::LatentUpscaleSource { path: file.path().to_string_lossy().into_owned(), scale: 2.0 }), ..Default::default() };+ assert!(plan(&request).unwrap_err().contains("header length"));+ request.continuation_relative_path = Some("original.safetensors".into());+ assert!(super::super::planning::validate_generation_controls(&request).is_err());+ }+}diff --git a/src-tauri/core/src/slopfab/mod.rs b/src-tauri/core/src/slopfab/mod.rsindex a91e2d5..51c24d2 100644--- a/src-tauri/core/src/slopfab/mod.rs+++ b/src-tauri/core/src/slopfab/mod.rs@@ -15,6 +15,7 @@ mod continuation;mod events;mod ffi;mod generation;+mod latent_upscale;mod lcs;mod lcs_fingerprint;mod h3;diff --git a/src-tauri/core/src/slopfab/planning.rs b/src-tauri/core/src/slopfab/planning.rsindex 539c082..e2b7f38 100644--- a/src-tauri/core/src/slopfab/planning.rs+++ b/src-tauri/core/src/slopfab/planning.rs@@ -27,6 +27,11 @@ pub fn resolve_plan(let configuration = Configuration::from_settings(settings);let api = ffi::Api::load(&configuration.dll_path)?;api.version()?;+ if request.latent_upscale_source.is_some() {+ configuration.validate_inputs(request)?;+ api.require_saved_latent_upscale()?;+ return super::latent_upscale::plan(request);+ }let platform = configuration.platform(detect_platform(&api));let handle = RequestHandle::new(&api)?;configure_request(@@ -57,6 +62,16 @@ pub fn resolve_plan(}pub(super) fn validate_generation_controls(request: &GenerationRequest) -> Result<(), String> {+ if let Some(source) = &request.latent_upscale_source {+ if ![1.5, 2.0, 4.0].contains(&source.scale) || source.path.is_empty() || source.path.contains('\0')+ || request.still_image || request.music.is_some() || request.single_shot.is_some() || request.latent_upscale+ || request.image_edit.is_some() || request.latent_bridge.is_some() || request.continuation_path.is_some()+ || request.continuation_relative_path.is_some() || request.video_transition.is_some()+ || request.reference_count() != 0 {+ return Err("Upscaling requires saved video latents and a scale of 1.5, 2 or 4.".into());+ }+ return Ok(());+ }if let Some(single) = &request.single_shot {if request.music.is_some() || request.still_image || request.image_edit.is_some() || request.video_transition.is_some() || request.latent_bridge.is_some()|| request.frames < 48 || single.ending_prompt.trim().is_empty() || single.ending_prompt.contains('\0') || single.ending_prompt.len() > 1024 * 1024diff --git a/src-tauri/core/src/slopfab/runtime.rs b/src-tauri/core/src/slopfab/runtime.rsindex fe3d88c..caf55a3 100644--- a/src-tauri/core/src/slopfab/runtime.rs+++ b/src-tauri/core/src/slopfab/runtime.rs@@ -126,7 +126,7 @@ impl SlopfabRuntime {settings: &BTreeMap<String, ProviderSetting>,) -> Result<(), String> {let configuration = Configuration::from_settings(settings);- request.steps = configuration.generation_steps(request.steps)?;+ if request.latent_upscale_source.is_none() { request.steps = configuration.generation_steps(request.steps)?; }diagnostics::info("slopfab","generation.enqueue_requested",diff --git a/src-tauri/core/src/slopfab/types.rs b/src-tauri/core/src/slopfab/types.rsindex 2e56bbb..5d932c5 100644--- a/src-tauri/core/src/slopfab/types.rs+++ b/src-tauri/core/src/slopfab/types.rs@@ -54,6 +54,8 @@ pub struct LatentBridgeRequest {#[derive(Debug, Clone, Default, Deserialize, Serialize)]#[serde(rename_all = "camelCase")]pub struct GenerationRequest {+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub latent_upscale_source: Option<LatentUpscaleSource>,#[serde(default, skip_serializing_if = "Option::is_none")]pub single_shot: Option<SingleShotRequest>,#[serde(default, skip_serializing_if = "Option::is_none")]@@ -124,6 +126,13 @@ pub struct GenerationRequest {pub save_latents_path: Option<PathBuf>,}+#[derive(Debug, Clone, Deserialize, Serialize)]+#[serde(rename_all = "camelCase")]+pub struct LatentUpscaleSource {+ pub path: String,+ pub scale: f32,+}+#[derive(Debug, Clone, Deserialize, Serialize)]#[serde(rename_all = "camelCase")]pub struct SingleShotRequest {diff --git a/src-tauri/core/src/worker/protocol.rs b/src-tauri/core/src/worker/protocol.rsindex 6c9e5fc..6933b3d 100644--- a/src-tauri/core/src/worker/protocol.rs+++ b/src-tauri/core/src/worker/protocol.rs@@ -26,7 +26,7 @@ pub const SERVICE_TYPE: &str = "_slopus-worker._tcp.local.";// v19 carries Single Shot ending-first generation; older workers would ignore it.// v20 carries source-initialized continuation; older workers would ignore it.// v21 keeps Single Shot's middle fresh; v20 workers default to a repeated source prior.-pub const PROTOCOL_VERSION: u32 = 21;+pub const PROTOCOL_VERSION: u32 = 22;/// Streaming SeedVR2 restoration; model paths are resolved on the worker.#[derive(Debug, Clone, Serialize, Deserialize)]@@ -186,7 +186,10 @@ pub fn visit_paths(if let Some(slopfab) = settings.get_mut("slopfab") {// The engine library always comes from the machine that runs it.slopfab.options.remove("dllPath");- if !request.latent_upscale { slopfab.options.remove("latentUpscaler"); }+ if !request.latent_upscale && request.latent_upscale_source.is_none() { slopfab.options.remove("latentUpscaler"); }+ if request.latent_upscale_source.is_some() {+ for name in ["transformer", "textEncoder", "tokenizer", "promptEmbedding", "loras"] { slopfab.options.remove(name); }+ }for name in MODEL_OPTIONS {if let Some(ProviderOption::String(value)) = slopfab.options.get_mut(name) {if !value.trim().is_empty() {@@ -213,6 +216,7 @@ pub fn visit_paths(*value = serde_json::to_string(&loras).map_err(|error| error.to_string())?;}}+ if let Some(source) = &mut request.latent_upscale_source { visit(PathKind::Input, &mut source.path)?; }for path in &mut request.reference_paths {visit(PathKind::Input, path)?;}@@ -322,6 +326,22 @@ mod tests {}}+ #[test]+ fn saved_latent_upscale_transfers_archive_and_decoder_weights_only() {+ let mut request: GenerationRequest = serde_json::from_value(serde_json::json!({"jobId":"upscale", "prompt":"", "frames":124, "steps":8, "seed":42, "canvasWidth":736, "canvasHeight":416,+ "latentUpscaleSource": {"path":"C:/project/latents/take.safetensors", "scale":1.5}})).unwrap();+ let mut settings = settings(&[("transformer", "unused"), ("textEncoder", "unused"), ("tokenizer", "unused"), ("loras", "invalid"),+ ("latentUpscaler", "upscaler"), ("videoVae", "video"), ("audioVae", "audio")]);+ let mut seen = Vec::new();+ visit_paths(&mut request, &mut settings, |kind, path| { seen.push((kind, path.clone())); *path = file_token(seen.len() - 1); Ok(()) }).unwrap();+ assert_eq!(seen.len(), 4);+ assert_eq!(seen.last().unwrap().0, PathKind::Input);+ assert!(!seen.iter().any(|(_, path)| path == "unused"));+ let mut restored: GenerationRequest = serde_json::from_slice(&serde_json::to_vec(&request).unwrap()).unwrap();+ visit_paths(&mut restored, &mut settings, |_, path| { *path = format!("/worker/{}", parse_file_token(path).unwrap()); Ok(()) }).unwrap();+ assert_eq!(restored.latent_upscale_source.unwrap().path, "/worker/3");+ }+#[test]fn generation_effects_roundtrip_without_machine_specific_paths() {let effects = serde_json::from_str(include_str!("../../../../fixtures/generation-effects.json")).unwrap();@@ -346,7 +366,7 @@ mod tests {let single = restored.single_shot.unwrap();assert_eq!(single.ending_prompt, "The subject waves goodbye");assert!(single.ending_path.is_none());- assert_eq!(PROTOCOL_VERSION, 21);+ assert_eq!(PROTOCOL_VERSION, 22);}#[test]diff --git a/src-tauri/src/media/artifacts.rs b/src-tauri/src/media/artifacts.rsindex 4645246..49fa5f4 100644--- a/src-tauri/src/media/artifacts.rs+++ b/src-tauri/src/media/artifacts.rs@@ -59,6 +59,12 @@ pub(crate) fn prepare_continuation_path(request.continuation_path = None;request.bridge_left_path = None;request.bridge_right_path = None;+ if let Some(source) = &mut request.latent_upscale_source {+ let root = ProjectRoot::open(folder_path.ok_or("A project folder is required to upscale a Take.")?)?;+ let path = root.existing(&source.path)?;+ if !path.is_file() { return Err("Saved latents must be a file inside this project.".into()); }+ source.path = path.to_string_lossy().into_owned();+ }if let Some(bridge) = &request.latent_bridge {let root = ProjectRoot::open(folder_path.ok_or("A project folder is required for Long Shot.")?)?;let resolve = |relative: &Option<String>| -> Result<PathBuf, String> {diff --git a/src-tauri/src/project/scenes.rs b/src-tauri/src/project/scenes.rsindex 0e36ab6..0c2de7f 100644--- a/src-tauri/src/project/scenes.rs+++ b/src-tauri/src/project/scenes.rs@@ -241,6 +241,10 @@ pub(crate) struct SceneGenerationHistory {#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub(crate) struct SceneGenerationVersion {+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub(crate) original_latent_relative_path: Option<String>,+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub(crate) upscale_factor: Option<f64>,pub(crate) id: String,pub(crate) created_at: String,pub(crate) scene: serde_json::Value,diff --git a/src-tauri/src/project/validation/scenes.rs b/src-tauri/src/project/validation/scenes.rsindex 0d1a453..ab56ad6 100644--- a/src-tauri/src/project/validation/scenes.rs+++ b/src-tauri/src/project/validation/scenes.rs@@ -257,6 +257,8 @@ fn validate_history(job: &mut GenerationJob) -> Result<(), String> {check_iso_datetime("Scene generation media createdAt", &media.created_at)?;media.relative_path = Some(normalize_project_path(media.relative_path.as_deref().ok_or("Scene generation video path is missing.")?)?);version.latent_relative_path = version.latent_relative_path.as_deref().map(normalize_project_path).transpose()?;+ version.original_latent_relative_path = version.original_latent_relative_path.as_deref().map(normalize_project_path).transpose()?;+ if version.upscale_factor.is_some_and(|factor| ![1.5, 2.0, 4.0].contains(&factor)) { return Err("Invalid Take upscale factor.".into()); }if let Some(segments) = &mut media.scene_segments {let mut end = 0u64;for segment in segments {@@ -301,7 +303,7 @@ mod history_tests {job.generator_template_id = Some("generator-original".into());job.generation_history = Some(SceneGenerationHistory {versions: vec![SceneGenerationVersion { id: "take-one".into(), created_at: job.created_at.clone(), scene: input.clone(),- media: config.assets.iter().find(|a| a.kind == "generated").unwrap().clone(), generation_snapshot: Some("saved-inputs".into()), latent_relative_path: Some("latents/one.safetensors".into()) }],+ media: config.assets.iter().find(|a| a.kind == "generated").unwrap().clone(), generation_snapshot: Some("saved-inputs".into()), latent_relative_path: Some("latents/one.safetensors".into()), original_latent_relative_path: None, upscale_factor: None }],primary_id: Some("take-one".into()), selected_id: None, draft: Some(input),});config@@ -310,6 +312,8 @@ mod history_tests {fn scene_history_and_draft_round_trip_without_a_four_take_schema_limit() {let mut config = project_with_history();let history = config.generation_jobs[0].generation_history.as_mut().unwrap();+ history.versions[0].original_latent_relative_path = Some("latents/original.safetensors".into());+ history.versions[0].upscale_factor = Some(1.5);let version = history.versions[0].clone();for i in 2..=6 { let mut take = version.clone(); take.id = format!("take-{i}"); history.versions.push(take); }validate(&mut config).unwrap();@@ -321,11 +325,13 @@ mod history_tests {}#[test]fn history_rejects_unsafe_paths_invalid_settings_and_nested_history() {- for kind in ["path", "settings", "nested", "selection", "duplicate"] {+ for kind in ["path", "settings", "nested", "selection", "duplicate", "original", "scale"] {let mut config = project_with_history();let history = config.generation_jobs[0].generation_history.as_mut().unwrap();match kind {"path" => history.versions[0].media.relative_path = Some("../outside.mp4".into()),+ "original" => history.versions[0].original_latent_relative_path = Some("../outside.safetensors".into()),+ "scale" => history.versions[0].upscale_factor = Some(100.0),"settings" => history.versions[0].scene["steps"] = serde_json::json!(-1),"nested" => history.versions[0].scene["generationHistory"] = serde_json::json!({}),"selection" => history.selected_id = Some("missing".into()),