Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Allow choosing primary image versions

Bitti0705f055f13c
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 28e6084..47925c2 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -4,6 +4,7 @@ This alpha update adds DMAD LoRA support, resumable model downloads, and improve
## What's new
+- Choose Make Primary on an image version to show it in the main image bar and use it when creating scenes or references from that family.
- Images imported through Timeline or References, including selected video reference frames, appear in the image bar and open for editing.
- Duplicate references from their context menu, including multiple selected references with their prompts, attachments, and media settings.
- Create a video scene with an image as its first frame, or create an image reference, directly from the Image tab's image bar context menu.
diff --git a/src-tauri/src/project/model.rs b/src-tauri/src/project/model.rs
index 5f88a7e..97b9f20 100644
--- a/src-tauri/src/project/model.rs
+++ b/src-tauri/src/project/model.rs
@@ -98,8 +98,8 @@ pub(crate) struct ProjectAsset {
pub(crate) image_generation: Option<super::image::ImageGenerationSnapshot>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) image_draft: Option<bool>,
- /// The original image this one was regenerated or edited from; the image
- /// bar shows a family as the original followed by these.
+ /// The family's primary image; the image bar shows it first, followed by
+ /// the other versions. Choosing a primary keeps the family one level deep.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) parent_asset_id: Option<String>,
pub(crate) created_at: String,
diff --git a/src/components/workspace/ImageBar.tsx b/src/components/workspace/ImageBar.tsx
index 4b00d57..016aac5 100644
--- a/src/components/workspace/ImageBar.tsx
+++ b/src/components/workspace/ImageBar.tsx
@@ -13,9 +13,9 @@ import "../../styles/image-editor.css";
whether the bar is showing a family; without it the bar has no menu.
An image regenerated or edited from another joins that image's family. The
- bar lists the originals; while an image with a family is selected it shows
- just that family — the original first, then the images made from it — with
- a back button at its leading edge that returns to the originals. */
+ bar lists the primary images; while an image with a family is selected it
+ shows just that family — the primary first, then the other versions — with
+ a back button at its leading edge that returns to all primary images. */
export const ImageBar = forwardRef<HTMLDivElement | null, {
images: ProjectAsset[];
selectedId: string | null | undefined;
@@ -28,13 +28,13 @@ export const ImageBar = forwardRef<HTMLDivElement | null, {
const root = imageFamilyRoot(images, selectedId);
const family = imageFamily(images, selectedId);
- // Selecting an image opens its family; Back shows the originals until the
+ // Selecting an image opens its family; Back shows the primaries until the
// next selection.
const [showAll, setShowAll] = useState(false);
useEffect(() => setShowAll(false), [selectedId]);
const inFamily = !showAll && family.length > 1;
- const originals = images.filter((asset) => imageFamilyRoot(images, asset.id) === asset.id);
- const shown = inFamily ? family : originals;
+ const primaries = images.filter((asset) => imageFamilyRoot(images, asset.id) === asset.id);
+ const shown = inFamily ? family : primaries;
const pressed = inFamily ? selectedId : root;
const childCount = (id: string) => images.filter((asset) => asset.id !== id && imageFamilyRoot(images, asset.id) === id).length;
diff --git a/src/components/workspace/ImageEditor.test.tsx b/src/components/workspace/ImageEditor.test.tsx
index 030a5f4..d7f4833 100644
--- a/src/components/workspace/ImageEditor.test.tsx
+++ b/src/components/workspace/ImageEditor.test.tsx
@@ -682,6 +682,32 @@ it("shows an image's family behind a back button, the original first", () => {
expect(bar()).toEqual(["View Original, 3 versions", "View Other"]);
});
+it.each(["Create Scene", "Create Reference"])("uses the chosen primary for %s from the main image bar", (action) => {
+ const initial = parseProjectConfig(fixture);
+ const image = (id: string, parentAssetId?: string) => ({ id, name: id, kind: "image" as const, relativePath: `media/${id}.png`, mimeType: "image/png", createdAt: initial.createdAt, ...(parentAssetId ? { parentAssetId } : {}) });
+ initial.assets = [image("Original"), image("Other"), image("Retry", "Original"), image("Chosen", "Original")];
+ initial.imageScene!.outputAssetId = "Original";
+ const current = setup(initial);
+ fireEvent.contextMenu(screen.getByRole("button", { name: "View Original" }));
+ expect(screen.getByRole("menuitem", { name: "Make Primary" })).toBeDisabled();
+ fireEvent.keyDown(document.activeElement!, { key: "Escape" });
+ fireEvent.keyDown(screen.getByRole("button", { name: "View Chosen" }), { key: "F10", shiftKey: true });
+ fireEvent.click(screen.getByRole("menuitem", { name: "Make Primary" }));
+ expect(current().imageScene).toEqual(initial.imageScene);
+ expect(screen.getByRole("button", { name: "View Original" })).toHaveAttribute("aria-pressed", "true");
+ fireEvent.click(screen.getByRole("button", { name: "Back to all images" }));
+ expect(within(screen.getByLabelText("Generated images")).getAllByRole("button").map((button) => button.getAttribute("aria-label")))
+ .toEqual(["View Chosen, 3 versions", "View Other"]);
+ fireEvent.contextMenu(screen.getByRole("button", { name: "View Chosen, 3 versions" }));
+ expect(screen.queryByRole("menuitem", { name: "Make Primary" })).not.toBeInTheDocument();
+ fireEvent.click(screen.getByRole("menuitem", { name: action }));
+ const reopened = parseProjectConfig(JSON.parse(JSON.stringify(current())));
+ expect(referenceImages(reopened.references[0])[0].relativePath).toBe("media/Chosen.png");
+ if (action === "Create Scene") expect(reopened.generationJobs.at(-1)?.startFrameReferenceId).toBe(reopened.references[0].id);
+ expect(reopened.assets.find((asset) => asset.id === "Original")?.parentAssetId).toBe("Chosen");
+ expect(reopened.assets.find((asset) => asset.id === "Chosen")?.parentAssetId).toBeUndefined();
+});
+
it("removes an original with a family only from inside the family, and the leftmost image takes its place", () => {
const initial = parseProjectConfig(fixture);
const image = (id: string, parentAssetId?: string) => ({ id, name: id, kind: "image" as const, relativePath: `media/generated/${id}.jpg`, mimeType: "image/jpeg", createdAt: initial.createdAt, ...(parentAssetId ? { parentAssetId } : {}) });
diff --git a/src/components/workspace/ImageEditor.tsx b/src/components/workspace/ImageEditor.tsx
index 05fa7b6..6e54e25 100644
--- a/src/components/workspace/ImageEditor.tsx
+++ b/src/components/workspace/ImageEditor.tsx
@@ -5,7 +5,7 @@ import { addImageNode, createImageEditScene, createImageScene, duplicateImageNod
import { compileImageEdits, editGeneratedImage, imageEditDebugPrompt } from "../../lib/imageEditing";
import { outputDimensions } from "../../lib/export";
import { compileImagePrompt } from "../../lib/imagePrompt";
-import { createEmptyImage, imageFamily, removeImageAsset, restoreGeneratedImage, saveImageDraft } from "../../lib/imageHistory";
+import { createEmptyImage, imageFamily, imageFamilyRoot, makeImagePrimary, removeImageAsset, restoreGeneratedImage, saveImageDraft } from "../../lib/imageHistory";
import { isTauri } from "../../lib/persistence";
import { createDraftGenerationJob, isVideoReference, PROJECT_RESOLUTIONS, referenceTypeLabel, type ProjectConfig, type ProjectReference } from "../../lib/project";
import { defaultGeneratorTemplate, loadDebugOptionsEnabled, loadGeneratorTemplateSettings, MINIMAX_H3_MODEL_TYPE, subscribeDebugOptions, subscribeGeneratorTemplates, templateUsable, type GeneratorTemplate } from "../../lib/settings";
@@ -515,6 +515,8 @@ export function ImageEditor({ config, folderPath, onChange: changeConfig, onGene
if (source) replaceScene(createImageEditScene(source, scene));
}) },
...(imageMenu.id ? [
+ ...(imageMenu.inFamily ? [{ label: "Make Primary", icon: <Image16 />, disabled: !canUseMenuImage || imageFamilyRoot(images, imageMenu.id) === imageMenu.id,
+ action: () => onChange((current) => ({ ...current, assets: makeImagePrimary(current.assets, imageMenu.id!) })) }] : []),
{ label: "Edit", icon: <Edit16 />, separator: true, action: () => attempt(() => menuImage?.imageDraft || !menuImage?.width || !menuImage?.height ? selectImage(imageMenu.id!) : replaceScene(editGeneratedImage(config, imageMenu.id!).imageScene!)) },
{ label: "Create Scene", icon: <Film16 />, separator: true, disabled: !canUseMenuImage, action: () => attempt(() => createFromImage(imageMenu.id!, true)) },
{ label: "Create Reference", icon: <References16 />, disabled: !canUseMenuImage, action: () => attempt(() => createFromImage(imageMenu.id!, false)) },
diff --git a/src/lib/imageHistory.test.ts b/src/lib/imageHistory.test.ts
index 9c724e8..4156ff4 100644
--- a/src/lib/imageHistory.test.ts
+++ b/src/lib/imageHistory.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
-import { completeImageDraft, imageFamilyRoot, imageGenerationSnapshot, removeImageAsset, restoreGeneratedImage, saveImageDraft } from "./imageHistory";
+import { completeImageDraft, imageFamily, imageFamilyRoot, imageGenerationSnapshot, makeImagePrimary, removeImageAsset, restoreGeneratedImage, saveImageDraft } from "./imageHistory";
import { imageGenerationSnapshotSchema, parseProjectConfig } from "./project";
import fixture from "../../fixtures/project-v1-image.json";
import snapshotFixture from "../../fixtures/image-generation-snapshot.json";
@@ -107,4 +107,22 @@ describe("generated image history", () => {
const assets = removeImageAsset([image("a"), image("b", "a"), image("c", "a"), image("d")], "a");
expect(assets.map((asset) => [asset.id, asset.parentAssetId])).toEqual([["b", undefined], ["c", "b"], ["d", undefined]]);
});
+
+ it("promotes an image in place, keeps the family flat, and attaches future edits to its new primary", () => {
+ const config = parseProjectConfig(fixture);
+ const image = (id: string, parentAssetId?: string) => ({ id, name: id, kind: "image" as const, relativePath: `media/${id}.png`, mimeType: "image/png", width: 640, height: 480, createdAt: config.createdAt, ...(parentAssetId ? { parentAssetId } : {}) });
+ config.assets = [image("before"), image("original"), image("after"), image("retry", "original"), image("chosen", "original")];
+ const promoted = makeImagePrimary(config.assets, "chosen");
+ expect(promoted.filter((asset) => !asset.parentAssetId).map((asset) => asset.id)).toEqual(["before", "chosen", "after"]);
+ expect(imageFamily(promoted, "original").map((asset) => [asset.id, asset.parentAssetId])).toEqual([
+ ["chosen", undefined], ["original", "chosen"], ["retry", "chosen"],
+ ]);
+ expect(config.assets[1].parentAssetId).toBeUndefined();
+ expect(makeImagePrimary(promoted, "chosen")).toBe(promoted);
+ const reopened = parseProjectConfig(JSON.parse(JSON.stringify({ ...config, assets: promoted })));
+ expect(imageFamilyRoot(reopened.assets, "retry")).toBe("chosen");
+ reopened.imageScene = createImageEditScene({ relativePath: "media/original.png", name: "original", width: 640, height: 480 });
+ expect(saveImageDraft(reopened).assets.at(-1)?.parentAssetId).toBe("chosen");
+ expect(imageFamily(removeImageAsset(promoted, "chosen"), "retry").map((asset) => asset.id)).toEqual(["original", "retry"]);
+ });
});
diff --git a/src/lib/imageHistory.ts b/src/lib/imageHistory.ts
index 0849d57..c43503c 100644
--- a/src/lib/imageHistory.ts
+++ b/src/lib/imageHistory.ts
@@ -18,22 +18,35 @@ export function imageGenerationSnapshot(config: ProjectConfig, prompt: string, g
});
}
-/** The first image of `id`'s family: its parent, or itself when it is an
- * original (or its parent has since been removed). */
+/** The primary image of `id`'s family: its parent, or itself when it is the
+ * primary (or its parent has since been removed). */
export function imageFamilyRoot(assets: readonly ProjectAsset[], id: string | null | undefined): string | undefined {
const asset = assets.find((candidate) => candidate.id === id && candidate.kind === "image");
if (!asset) return undefined;
return asset.parentAssetId && assets.some((candidate) => candidate.id === asset.parentAssetId && candidate.kind === "image") ? asset.parentAssetId : asset.id;
}
-/** An image's family in the bar's order: the original, then the images made
- * from it. An image with no family is a family of one. */
+/** An image's family in the bar's order: the primary, then its other versions.
+ * An image with no family is a family of one. */
export function imageFamily(assets: readonly ProjectAsset[], id: string | null | undefined): ProjectAsset[] {
const root = imageFamilyRoot(assets, id);
if (!root) return [];
return [assets.find((asset) => asset.id === root)!, ...assets.filter((asset) => asset.id !== root && imageFamilyRoot(assets, asset.id) === root)];
}
+/** Promote a version without moving its family in the main bar or changing
+ * any image's contents. All other versions point directly to the new primary. */
+export function makeImagePrimary(assets: ProjectAsset[], id: string): ProjectAsset[] {
+ const primary = assets.find((asset) => asset.id === id && asset.kind === "image");
+ const root = imageFamilyRoot(assets, id);
+ if (!primary || !root || root === id || (!primary.relativePath && !primary.sourcePath)) return assets;
+ const family = new Set(imageFamily(assets, id).map((asset) => asset.id));
+ return assets.flatMap((asset) => asset.id === root
+ ? [{ ...primary, parentAssetId: undefined }, { ...asset, parentAssetId: id }]
+ : asset.id === id ? []
+ : family.has(asset.id) ? [{ ...asset, parentAssetId: id }] : [asset]);
+}
+
/** Removes an image. Its children stay a family: the leftmost of them — the
* oldest — becomes the original the others belong to. */
export function removeImageAsset(assets: readonly ProjectAsset[], id: string): ProjectAsset[] {
diff --git a/src/lib/project.ts b/src/lib/project.ts
index 01745ea..2aa27a0 100644
--- a/src/lib/project.ts
+++ b/src/lib/project.ts
@@ -181,8 +181,8 @@ export const projectAssetSchema = z.object({
hasAudio: z.boolean().nullish(),
imageGeneration: imageGenerationSnapshotSchema.nullish(),
imageDraft: z.boolean().nullish(),
- /** The original image this one was regenerated or edited from. Always the
- * family's first image, never another child, so a family is one level. */
+ /** The family's primary image. Always its first image, never another child,
+ * so a family is one level even after choosing a different primary. */
parentAssetId: idSchema.nullish(),
createdAt: isoDateSchema,
}).superRefine((asset, context) => {
diff --git a/src/lib/workQueue.test.ts b/src/lib/workQueue.test.ts
index 52355cf..6995acc 100644
--- a/src/lib/workQueue.test.ts
+++ b/src/lib/workQueue.test.ts
@@ -14,7 +14,7 @@ import { prepareReferenceVideos, releaseReferenceVideos } from "./referenceVideo
import { downloadTemplateWeights, getWeightDownloadState } from "./weightDownloads";
import { compileImagePrompt } from "./imagePrompt";
import { addImageNode, createImageEditScene } from "./imageScene";
-import { createEmptyImage, restoreGeneratedImage } from "./imageHistory";
+import { createEmptyImage, makeImagePrimary, restoreGeneratedImage } from "./imageHistory";
vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));
vi.mock("@tauri-apps/api/event", () => ({ listen: vi.fn() }));
@@ -123,6 +123,27 @@ describe("image generation work", () => {
expect([first, second].map((item) => result.assets.find((asset) => asset.relativePath === `media/${item.id}.jpg`)!.parentAssetId))
.toEqual(imageDraft ? [undefined, undefined] : ["first", "second"]);
});
+ it("finishes regeneration in the current primary's family after promotion and undo", async () => {
+ const { queue } = setup();
+ const record = imageProject();
+ record.config.assets = ["original", "chosen"].map((id) => ({ id, name: id, kind: "image", relativePath: `media/${id}.jpg`, mimeType: "image/jpeg",
+ createdAt: record.config.createdAt, ...(id === "chosen" ? { parentAssetId: "original" } : {}) }));
+ record.config.imageScene!.outputAssetId = "original";
+ const session = queue.project(record);
+ vi.mocked(invoke).mockResolvedValue({ relativePath: "media/result.jpg", width: 768, height: 768 });
+ queue.enqueueImage(session, template);
+ await waitFor(() => expect(enqueueSlopfabGeneration).toHaveBeenCalledOnce());
+ session.edit((current) => ({ ...current, assets: makeImagePrimary(current.assets, "chosen") }));
+ const work = queue.getSnapshot()[0];
+ await finish(queue, work.id);
+ expect(session.getSnapshot().config.assets.find((asset) => asset.id === work.id)?.parentAssetId).toBe("chosen");
+ session.undo();
+ expect(session.getSnapshot().config.assets.find((asset) => asset.id === "chosen")?.parentAssetId).toBe("original");
+ expect(session.getSnapshot().config.assets.find((asset) => asset.id === work.id)?.parentAssetId).toBe("original");
+ session.redo();
+ expect(session.getSnapshot().config.assets.find((asset) => asset.id === work.id)?.parentAssetId).toBe("chosen");
+ });
+
it("submits whole-image and local edits with separate reference pictures and refmods", async () => {
const { queue } = setup();
const record = imageProject();
diff --git a/src/lib/workQueue.ts b/src/lib/workQueue.ts
index 0fa3c26..dbb6f64 100644
--- a/src/lib/workQueue.ts
+++ b/src/lib/workQueue.ts
@@ -449,7 +449,7 @@ export class WorkQueue {
thumbnail: saved.relativePath,
imageScene: { ...(work.request.imageEdit && JSON.stringify(current.imageScene) === work.snapshot ? createImageEditScene({ ...saved, name: "Edited image" }, current.imageScene ?? undefined) : current.imageScene ?? createImageScene()), outputAssetId: work.id },
} : {}),
- assets: [...current.assets, { id: work.id, kind: "image", name: `Image ${current.assets.filter((asset) => asset.kind === "image").length + 1}`, ...saved, imageGeneration: work.imageGeneration, mimeType: work.request.imageEdit ? "image/png" : "image/jpeg", ...(work.imageParentId && current.assets.some((asset) => asset.id === work.imageParentId) ? { parentAssetId: work.imageParentId } : {}), createdAt: new Date().toISOString() }],
+ assets: [...current.assets, { id: work.id, kind: "image", name: `Image ${current.assets.filter((asset) => asset.kind === "image").length + 1}`, ...saved, imageGeneration: work.imageGeneration, mimeType: work.request.imageEdit ? "image/png" : "image/jpeg", ...(work.imageParentId ? { parentAssetId: imageFamilyRoot(current.assets, work.imageParentId) } : {}), createdAt: new Date().toISOString() }],
}));
try { await work.session.save(); this.patch(work.id, { status: "completed", progress: 1, detail: "Image saved" }); }
catch (reason) { this.patch(work.id, { status: "failed", progress: 1, needsSave: true, detail: "Image created; project save failed", error: describeDiagnosticError(reason) }); }