Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Share filtered reference pickers

Bitti8da3a5532523
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 17a2a54..1b95104 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
+- First and last scene frames use the searchable reference picker with image thumbnails. Reference selectors and prompt chips share configurable filters for images, audio, video, text, and RefMods.
- Configure a character sheet from the Image toolbar's Template menu, with reference-enabled prompts for clothing and other details, then select Execute. A square portrait and three 9:16 full-body views are combined into one child image in the image bar. The front view provides a shared clothing reference for the other views.
- Continue scenes from a selected scene's saved latents, with adjustable overlap and a choice of beginning or end. This replaces Previous scene in First & last frame.
- Export any reference with images, a video or a sound as a refmod `.safetensors` file from References. Exported refmods can be attached to other references and projects.
diff --git a/src/components/ImageProject.integration.test.tsx b/src/components/ImageProject.integration.test.tsx
index 82a77fb..485913b 100644
--- a/src/components/ImageProject.integration.test.tsx
+++ b/src/components/ImageProject.integration.test.tsx
@@ -73,7 +73,7 @@ it.each(["Create Scene", "Create Reference"])("opens and saves the item created
fireEvent.click(screen.getByRole("menuitem", { name: action }));
const navigation = within(screen.getByRole("tablist", { name: "Project views" }));
expect(navigation.getByRole("tab", { name: action === "Create Scene" ? "Video" : "References" })).toHaveAttribute("aria-selected", "true");
- if (action === "Create Scene") expect(screen.getByRole("combobox", { name: "Start frame for this scene" })).toHaveTextContent("Poster");
+ if (action === "Create Scene") expect(screen.getByRole("button", { name: "Start frame for this scene" })).toHaveTextContent("Poster");
else expect(screen.getByLabelText("Reference name")).toHaveValue("Poster");
fireEvent.click(screen.getByRole("button", { name: "Save" }));
await waitFor(() => expect(save).toHaveBeenCalledOnce());
diff --git a/src/components/ProjectWorkspace.test.ts b/src/components/ProjectWorkspace.test.ts
index d1808fd..b4fa3aa 100644
--- a/src/components/ProjectWorkspace.test.ts
+++ b/src/components/ProjectWorkspace.test.ts
@@ -482,7 +482,8 @@ describe("project workspace timecode", () => {
expect(container.querySelector(".job-refs")).toBeNull();
expect(container.querySelector(".scene-settings img, .scene-settings .reference-image-fallback")).toBeNull();
- expect(optionNames(screen.getByRole("combobox", { name: "Start frame for this scene" }))).toContain("Lamp photograph");
+ fireEvent.click(screen.getByRole("button", { name: "Start frame for this scene" }));
+ expect(screen.getByRole("dialog", { name: "Start frame for this scene" })).toHaveTextContent("Lamp photograph");
});
it("keeps scene settings editable while a scene is running", () => {
diff --git a/src/components/workspace/GeneratorView.test.tsx b/src/components/workspace/GeneratorView.test.tsx
index d8a42f8..ca1324b 100644
--- a/src/components/workspace/GeneratorView.test.tsx
+++ b/src/components/workspace/GeneratorView.test.tsx
@@ -10,7 +10,7 @@ import { askNative } from "../../lib/nativeShell";
import { GeneratorView, templateSceneBlocker } from "./GeneratorView";
import { ReferencesView } from "./ReferencesView";
import { choose, chooseOption, comboValue, optionNames } from "./comboTestUtils";
-import { changePromptChip, insertPromptReference, placePromptCaret, typePrompt } from "./promptTestUtils";
+import { chooseReference, changePromptChip, insertPromptReference, placePromptCaret, typePrompt } from "./promptTestUtils";
import { minimaxOriginalTemplate, viggleAnimateTemplate, saveDebugOptionsEnabled } from "../../lib/settings";
vi.mock("../../lib/nativeShell", async (importOriginal) => ({
@@ -112,16 +112,16 @@ it("animates a blank scene only with a video and repainted frame", () => {
expect(screen.queryByLabelText("The sound of this scene")).toBeNull();
choose("Reference video for this scene", "Motion");
expect(generate).toBeDisabled();
- choose("Start frame for this scene", "Repainted frame");
+ chooseReference("Start frame for this scene", "Repainted frame");
expect(generate).toBeEnabled();
fireEvent.click(generate);
expect(submitted).toHaveBeenLastCalledWith([expect.objectContaining({ request: expect.objectContaining({
prompt: "", referenceVideos: [{ name: "Motion", sourcePath: "C:/motion.mp4", startSeconds: 1, durationSeconds: 3, includeAudio: false }],
referencePaths: ["C:/project/references/repainted.png"],
}) })]);
- choose("Start frame for this scene", "None");
+ chooseReference("Start frame for this scene", "None");
expect(generate).toBeDisabled();
- choose("Start frame for this scene", "Repainted frame");
+ chooseReference("Start frame for this scene", "Repainted frame");
expect(generate).toBeEnabled();
choose("Reference video for this scene", "None");
expect(generate).toBeDisabled();
@@ -442,7 +442,7 @@ describe("Generator scene controls", () => {
const state = setup(parseProjectConfig(initial));
expect(optionNames(screen.getByRole("combobox", { name: "The look of this scene" }))).toContain("None");
- chooseOption(screen.getByRole("combobox", { name: "Start frame for this scene" }), "Opening still");
+ chooseReference("Start frame for this scene", "Opening still");
expect(state.latest().generationJobs[0].startFrameReferenceId).toBe("ref-opening");
fireEvent.click(within(screen.getByRole("region", { name: "First scene" })).getByRole("button", { name: "Generate" }));
@@ -456,13 +456,13 @@ describe("Generator scene controls", () => {
const initial = project();
initial.references = [{ id: "closing", kind: "image", name: "Closing still", description: "", relativePath: "references/closing.png", intendedUse: [], createdAt: initial.createdAt }];
const state = setup(initial);
- chooseOption(screen.getByRole("combobox", { name: "Last frame for this scene" }), "Closing still");
+ chooseReference("Last frame for this scene", "Closing still");
expect(state.latest().generationJobs[0].endFrameReferenceId).toBe("closing");
fireEvent.click(within(screen.getByRole("region", { name: "First scene" })).getByRole("button", { name: "Generate" }));
const snapshot = JSON.parse(state.latest().generationJobs[0].generationSnapshot!);
expect(snapshot.prompt).toContain("<Picture 1> is the last frame of the video.");
expect(snapshot.referencePaths[0]).toContain("closing.png");
- chooseOption(screen.getByRole("combobox", { name: "Last frame for this scene" }), "None");
+ chooseReference("Last frame for this scene", "None");
expect(state.latest().generationJobs[0].endFrameReferenceId).toBeUndefined();
});
@@ -517,9 +517,9 @@ describe("Generator scene controls", () => {
const initial = project();
initial.generationJobs[0] = { ...initial.generationJobs[0], status: "completed", outputRelativePath: "media/generated/work-original.mp4", latentRelativePath: "latents/work-original.safetensors" };
const state = setup(initial);
- fireEvent.click(screen.getByRole("combobox", { name: "Start frame for this scene" }));
+ fireEvent.click(screen.getByRole("button", { name: "Start frame for this scene" }));
expect(screen.queryByRole("option", { name: "Previous scene" })).toBeNull();
- fireEvent.click(screen.getByRole("combobox", { name: "Start frame for this scene" }));
+ fireEvent.click(screen.getByRole("button", { name: "Start frame for this scene" }));
fireEvent.click(screen.getByRole("button", { name: "Select scene Second scene" }));
choose("Scene type", "Continue");
choose("Source scene for continuation", "First scene");
diff --git a/src/components/workspace/ImageEditor.tsx b/src/components/workspace/ImageEditor.tsx
index 6aae522..769c8bc 100644
--- a/src/components/workspace/ImageEditor.tsx
+++ b/src/components/workspace/ImageEditor.tsx
@@ -17,6 +17,7 @@ import { ReferenceIcon } from "./ReferenceIcon";
import { ImageBar } from "./ImageBar";
import { CharacterSheetSettings } from "./CharacterSheetSettings";
import type { CharacterSheetOptions } from "../../lib/characterSheet";
+import { referenceMediaTypes } from "../../lib/referenceSelection";
import { DebugPromptDialog } from "./DebugPromptDialog";
import { TagEditor } from "./TagEditor";
import styleSuggestions from "../../lib/imageStyleSuggestions.json";
@@ -491,7 +492,7 @@ export function ImageEditor({ config, folderPath, onChange: changeConfig, onGene
const rootField = (field: string) => `${editorId}-${field}`;
const promptLabel = imageRoot ? "Edit prompt" : selected.kind === "root" ? "Prompt (high-level description)" : "Description";
const promptReferences = config.references.filter((reference) => reference.kind !== "audio" && !isVideoReference(reference))
- .map((reference) => ({ id: reference.id, name: reference.name, detail: referenceTypeLabel(reference), icon: <ReferenceIcon reference={reference} folderPath={folderPath} fallback={reference.kind === "image" ? <Image16 /> : <Text16 />} /> }));
+ .map((reference) => ({ id: reference.id, name: reference.name, mediaTypes: referenceMediaTypes(reference), detail: referenceTypeLabel(reference), icon: <ReferenceIcon reference={reference} folderPath={folderPath} fallback={reference.kind === "image" ? <Image16 /> : <Text16 />} /> }));
// A chip for a video or audio reference names it; one deleted says so.
const missingReference = (id: string) => config.references.find((reference) => reference.id === id)?.name ?? "Deleted reference";
diff --git a/src/components/workspace/PromptTextField.tsx b/src/components/workspace/PromptTextField.tsx
index 2d8217d..3cf2f37 100644
--- a/src/components/workspace/PromptTextField.tsx
+++ b/src/components/workspace/PromptTextField.tsx
@@ -1,17 +1,11 @@
-import { useEffect, useLayoutEffect, useRef, useState, type ClipboardEvent as ReactClipboardEvent, type CSSProperties, type KeyboardEvent as ReactKeyboardEvent, type ReactNode } from "react";
+import { useEffect, useLayoutEffect, useRef, useState, type ClipboardEvent as ReactClipboardEvent, type CSSProperties, type KeyboardEvent as ReactKeyboardEvent } from "react";
import { canTokenizeReference, referenceToken, splitActionText, type ActionPart } from "../../lib/project";
-import { Add14, Delete14 } from "../ui/icons";
-import { Flyout, TextField } from "../ui";
+import { Add14 } from "../ui/icons";
+import { ReferencePicker, type ReferenceOption } from "./ReferencePicker";
+import { filterReferenceOptions, type ReferenceMediaType } from "../../lib/referenceSelection";
import "../../styles/prompt-field.css";
-export interface PromptReference {
- id: string;
- name: string;
- /** A glyph or thumbnail shown beside the name in the picker. */
- icon?: ReactNode;
- /** A second line in the picker, e.g. the kind of reference. */
- detail?: string;
-}
+export type PromptReference = ReferenceOption;
/** How references are written into the value. Each chip stands for one token
* and carries its key: what `split` reads out of the token and `token` writes
@@ -69,11 +63,12 @@ interface Chips {
missingLabel: (key: string) => string;
}
-export function PromptTextField({ value, onChange, references, referenceButtonLabel = "Reference", format = REFERENCE_TOKENS, missingLabel = () => "Deleted reference", missingTooltip = "Left out of the prompt — click to swap it for another reference or remove it", onInsertReference, disabled = false, placeholder, rows = 4, id, className, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy }: {
+export function PromptTextField({ value, onChange, references: allReferences, accept, referenceButtonLabel = "Reference", format = REFERENCE_TOKENS, missingLabel = () => "Deleted reference", missingTooltip = "Left out of the prompt — click to swap it for another reference or remove it", onInsertReference, disabled = false, placeholder, rows = 4, id, className, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy }: {
value: string;
onChange: (value: string) => void;
/** The references the picker offers; a chip for any other key is missing. */
references: readonly PromptReference[];
+ accept?: readonly ReferenceMediaType[];
referenceButtonLabel?: string;
format?: PromptTokenFormat;
missingLabel?: (key: string) => string;
@@ -89,6 +84,7 @@ export function PromptTextField({ value, onChange, references, referenceButtonLa
"aria-label"?: string;
"aria-labelledby"?: string;
}) {
+ const references = filterReferenceOptions(allReferences, accept);
const field = useRef<HTMLDivElement>(null);
const addButton = useRef<HTMLButtonElement>(null);
const selection = useRef<{ start: number; end: number } | null>(null);
@@ -259,10 +255,13 @@ export function PromptTextField({ value, onChange, references, referenceButtonLa
}}
/>
<ReferencePicker
- picking={picking}
+ anchor={picking?.anchor ?? null}
+ current={picking?.current ?? null}
+ currentLabel={picking?.current != null ? label(picking.current) : undefined}
+ title={picking?.current != null ? `Change reference ${label(picking.current)}` : "Insert a reference"}
references={references}
- format={format}
- label={label}
+ referenceKey={format.key}
+ unavailableReason={format.uncitable}
onChoose={choose}
onRemove={() => {
if (!picking) return;
@@ -274,83 +273,6 @@ export function PromptTextField({ value, onChange, references, referenceButtonLa
</div>;
}
-function ReferencePicker({ picking, references, format, label, onChoose, onRemove, onClose }: {
- picking: Picking | null;
- references: readonly PromptReference[];
- format: PromptTokenFormat;
- label: (key: string) => string;
- onChoose: (reference: PromptReference) => void;
- onRemove: () => void;
- onClose: () => void;
-}) {
- const [filter, setFilter] = useState("");
- const list = useRef<HTMLDivElement>(null);
- const filterInput = useRef<HTMLInputElement>(null);
- useEffect(() => { if (picking) setFilter(""); }, [picking]);
- const query = filter.trim().toLowerCase();
- const shown = references.filter((reference) => !query || reference.name.toLowerCase().includes(query));
- const current = picking?.current ?? null;
- const missing = current !== null && !references.some((reference) => format.key(reference) === current);
-
- const move = (event: ReactKeyboardEvent, step: number) => {
- const options = [...(list.current?.querySelectorAll<HTMLButtonElement>("button:not(:disabled)") ?? [])];
- if (!options.length) return;
- event.preventDefault();
- const at = options.indexOf(document.activeElement as HTMLButtonElement);
- options[at < 0 ? (step > 0 ? 0 : options.length - 1) : (at + step + options.length) % options.length].focus();
- };
-
- return <Flyout
- open={Boolean(picking)}
- anchor={picking?.anchor ?? null}
- onClose={onClose}
- aria-label={current !== null ? `Change reference ${label(current)}` : "Insert a reference"}
- className="prompt-reference-picker"
- initialFocus={filterInput}
- width={280}
- >
- {current !== null && <p className="prompt-reference-picker__current">
- {missing ? <><b>{label(current)}</b> can’t be used. Choose a reference to cite instead.</> : <>Cites <b>{label(current)}</b></>}
- </p>}
- {references.length > 6 && <TextField
- inputRef={filterInput}
- value={filter}
- onChange={setFilter}
- placeholder="Find a reference"
- aria-label="Find a reference"
- onKeyDown={(event) => {
- if (event.key === "ArrowDown") move(event, 1);
- if (event.key === "Enter" && shown.length) { event.preventDefault(); if (!format.uncitable?.(shown[0])) onChoose(shown[0]); }
- }}
- />}
- <div ref={list} className="prompt-reference-picker__list" role="group" aria-label="References" onKeyDown={(event) => {
- if (event.key === "ArrowDown") move(event, 1);
- if (event.key === "ArrowUp") move(event, -1);
- }}>
- {shown.map((reference) => {
- const why = format.uncitable?.(reference) ?? null;
- return <button
- key={reference.id}
- type="button"
- className="prompt-reference-picker__option ui-selectable"
- aria-pressed={format.key(reference) === current}
- disabled={why !== null}
- data-tooltip={why ?? undefined}
- onClick={() => onChoose(reference)}
- >
- {reference.icon && <span className="prompt-reference-picker__icon" aria-hidden="true">{reference.icon}</span>}
- <span className="prompt-reference-picker__text"><span>{reference.name}</span>{reference.detail && <small>{reference.detail}</small>}</span>
- </button>;
- })}
- {!references.length && <p className="prompt-reference-picker__empty">No references yet — add them under References.</p>}
- {references.length > 0 && !shown.length && <p className="prompt-reference-picker__empty">No reference matches “{filter.trim()}”.</p>}
- </div>
- {current !== null && <button type="button" className="prompt-reference-picker__option prompt-reference-picker__remove" onClick={onRemove}>
- <span className="prompt-reference-picker__icon" aria-hidden="true"><Delete14 /></span>Remove from the prompt
- </button>}
- </Flyout>;
-}
-
/* --- The editable surface ------------------------------------------------ */
/** Noneditable chips do not receive the browser's text-selection paint.
diff --git a/src/components/workspace/ReferencePicker.tsx b/src/components/workspace/ReferencePicker.tsx
new file mode 100644
index 0000000..823902a
--- /dev/null
+++ b/src/components/workspace/ReferencePicker.tsx
@@ -0,0 +1,69 @@
+import { useEffect, useRef, useState, type KeyboardEvent, type ReactNode } from "react";
+import { filterReferenceOptions, type ReferenceMediaType } from "../../lib/referenceSelection";
+import { Flyout, TextField } from "../ui";
+import { Delete14 } from "../ui/icons";
+import "../../styles/prompt-field.css";
+
+export interface ReferenceOption {
+ id: string;
+ name: string;
+ icon?: ReactNode;
+ detail?: string;
+ mediaTypes?: readonly ReferenceMediaType[];
+}
+const referenceId = (reference: ReferenceOption) => reference.id;
+
+/** Shared by inline prompt chips and standalone reference selectors. */
+export function ReferencePicker({ anchor, references: allReferences, accept, current = null, currentLabel, title, referenceKey = referenceId, unavailableReason,
+ emptyLabel = "No references yet — add them under References.", clearLabel = "Remove from the prompt", allowEmpty = false, onChoose, onRemove, onClose }: {
+ anchor: HTMLElement | null; references: readonly ReferenceOption[]; accept?: readonly ReferenceMediaType[];
+ current?: string | null; currentLabel?: string; title: string;
+ referenceKey?: (reference: ReferenceOption) => string; unavailableReason?: (reference: ReferenceOption) => string | null;
+ emptyLabel?: string; clearLabel?: string; allowEmpty?: boolean;
+ onChoose: (reference: ReferenceOption) => void; onRemove: () => void; onClose: () => void;
+}) {
+ const [filter, setFilter] = useState("");
+ const list = useRef<HTMLDivElement>(null);
+ const filterInput = useRef<HTMLInputElement>(null);
+ useEffect(() => { if (anchor) setFilter(""); }, [anchor, current]);
+ const references = filterReferenceOptions(allReferences, accept);
+ const query = filter.trim().toLowerCase();
+ const shown = references.filter((reference) => !query || reference.name.toLowerCase().includes(query));
+ const missing = current !== null && !references.some((reference) => referenceKey(reference) === current);
+ const move = (event: KeyboardEvent, step: number) => {
+ const options = [...(list.current?.querySelectorAll<HTMLButtonElement>("button:not(:disabled)") ?? [])];
+ if (!options.length) return;
+ event.preventDefault();
+ const at = options.indexOf(document.activeElement as HTMLButtonElement);
+ options[at < 0 ? (step > 0 ? 0 : options.length - 1) : (at + step + options.length) % options.length].focus();
+ };
+ return <Flyout open={Boolean(anchor)} anchor={anchor} onClose={onClose} aria-label={title} className="prompt-reference-picker" initialFocus={filterInput} width={280}>
+ {current !== null && <p className="prompt-reference-picker__current">
+ {missing ? <><b>{currentLabel}</b> can’t be used. Choose another reference.</> : <>{allowEmpty ? "Selected:" : "Cites"} <b>{currentLabel}</b></>}
+ </p>}
+ {references.length > 6 && <TextField inputRef={filterInput} value={filter} onChange={setFilter} placeholder="Find a reference" aria-label="Find a reference"
+ onKeyDown={(event) => {
+ if (event.key === "ArrowDown") move(event, 1);
+ if (event.key === "Enter" && shown.length) { event.preventDefault(); const first = shown.find((reference) => !unavailableReason?.(reference)); if (first) onChoose(first); }
+ }} />}
+ <div ref={list} className="prompt-reference-picker__list" role="group" aria-label="References" onKeyDown={(event) => {
+ if (event.key === "ArrowDown") move(event, 1);
+ if (event.key === "ArrowUp") move(event, -1);
+ }}>
+ {allowEmpty && <button type="button" className="prompt-reference-picker__option ui-selectable" aria-pressed={current === null} onClick={onRemove}>{clearLabel}</button>}
+ {shown.map((reference) => {
+ const why = unavailableReason?.(reference) ?? null;
+ return <button key={reference.id} type="button" className="prompt-reference-picker__option ui-selectable" aria-pressed={referenceKey(reference) === current}
+ disabled={why !== null} data-tooltip={why ?? undefined} onClick={() => onChoose(reference)}>
+ {reference.icon && <span className="prompt-reference-picker__icon" aria-hidden="true">{reference.icon}</span>}
+ <span className="prompt-reference-picker__text"><span>{reference.name}</span>{reference.detail && <small>{reference.detail}</small>}</span>
+ </button>;
+ })}
+ {!references.length && <p className="prompt-reference-picker__empty">{emptyLabel}</p>}
+ {references.length > 0 && !shown.length && <p className="prompt-reference-picker__empty">No reference matches “{filter.trim()}”.</p>}
+ </div>
+ {!allowEmpty && current !== null && <button type="button" className="prompt-reference-picker__option prompt-reference-picker__remove" onClick={onRemove}>
+ <span className="prompt-reference-picker__icon" aria-hidden="true"><Delete14 /></span>{clearLabel}
+ </button>}
+ </Flyout>;
+}
diff --git a/src/components/workspace/ReferenceSelector.test.tsx b/src/components/workspace/ReferenceSelector.test.tsx
new file mode 100644
index 0000000..8469101
--- /dev/null
+++ b/src/components/workspace/ReferenceSelector.test.tsx
@@ -0,0 +1,76 @@
+// @vitest-environment jsdom
+import "@testing-library/jest-dom/vitest";
+import { useState } from "react";
+import { cleanup, fireEvent, render, screen, within } from "@testing-library/react";
+import { afterEach, expect, it, vi } from "vitest";
+import type { ProjectReference } from "../../lib/project";
+import type { ReferenceMediaType } from "../../lib/referenceSelection";
+import { ReferenceSelector } from "./ReferenceSelector";
+import { PromptTextField } from "./PromptTextField";
+
+afterEach(cleanup);
+const base = { description: "", intendedUse: [], createdAt: "2026-01-01T00:00:00.000Z" };
+const references: ProjectReference[] = [
+ { ...base, id: "image", name: "Image", kind: "image", relativePath: "references/image.png" },
+ { ...base, id: "audio", name: "Audio", kind: "audio", sourcePath: "D:/voice.wav" },
+ { ...base, id: "text", name: "Text", kind: "text", description: "A description" },
+];
+
+it.each<{ accept: ReferenceMediaType[]; expected: string[] }>([
+ { accept: ["image"], expected: ["None", "Image"] },
+ { accept: ["audio"], expected: ["None", "Audio"] },
+ { accept: ["image", "audio"], expected: ["None", "Image", "Audio"] },
+])("offers only $accept payloads in a standalone selection", ({ accept, expected }) => {
+ render(<ReferenceSelector aria-label="Frame" value="" references={references} accept={accept} folderPath="D:/Project" onChange={vi.fn()} />);
+ fireEvent.click(screen.getByRole("button", { name: "Frame" }));
+ const choices = within(screen.getByRole("dialog", { name: "Frame" })).getAllByRole("button");
+ expect(choices).toHaveLength(expected.length);
+ choices.forEach((button, index) => expect(button).toHaveAccessibleName(new RegExp(`^${expected[index]}`)));
+});
+
+it("searches, selects, clears and restores focus, while preserving an unavailable saved value", () => {
+ const images: ProjectReference[] = Array.from({ length: 8 }, (_, index) => ({ ...references[0], id: `image-${index}`, name: `Photo ${index}` }));
+ function Harness() {
+ const [value, setValue] = useState("audio");
+ return <ReferenceSelector aria-label="Frame" value={value} references={[...images, references[1]]} accept={["image"]} folderPath="D:/Project" onChange={setValue} />;
+ }
+ render(<Harness />);
+ const trigger = screen.getByRole("button", { name: "Frame" });
+ expect(trigger).toHaveTextContent("Audio");
+ fireEvent.click(trigger);
+ expect(screen.getByRole("dialog", { name: "Frame" })).toHaveTextContent("can’t be used");
+ const search = screen.getByRole("textbox", { name: "Find a reference" });
+ expect(search).toHaveFocus();
+ fireEvent.change(search, { target: { value: "Photo 5" } });
+ const match = screen.getByRole("button", { name: /Photo 5/ });
+ fireEvent.keyDown(search, { key: "ArrowDown" });
+ fireEvent.keyDown(document.activeElement!, { key: "ArrowDown" });
+ expect(match).toHaveFocus();
+ fireEvent.click(match);
+ expect(trigger).toHaveTextContent("Photo 5");
+ expect(trigger).toHaveFocus();
+ fireEvent.click(trigger);
+ fireEvent.click(screen.getByRole("button", { name: "None" }));
+ expect(trigger).toHaveTextContent("None");
+ fireEvent.click(trigger);
+ fireEvent.keyDown(window, { key: "Escape" });
+ expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
+ expect(trigger).toHaveFocus();
+});
+
+it("shares the same media filter with smart-chip insertion", () => {
+ const onChange = vi.fn();
+ render(<PromptTextField aria-label="Prompt" value="" onChange={onChange} accept={["audio"]} references={[
+ { id: "image", name: "Image", mediaTypes: ["image"] }, { id: "audio", name: "Voice", mediaTypes: ["audio"] },
+ ]} />);
+ fireEvent.click(screen.getByRole("button", { name: "Reference" }));
+ expect(screen.queryByRole("button", { name: "Image" })).not.toBeInTheDocument();
+ fireEvent.click(screen.getByRole("button", { name: "Voice" }));
+ expect(onChange).toHaveBeenCalledWith("@[ref:audio]");
+});
+
+it("cannot open a disabled selector", () => {
+ render(<ReferenceSelector aria-label="Frame" value="" references={references} accept={["image"]} folderPath="D:/Project" onChange={vi.fn()} disabled />);
+ fireEvent.click(screen.getByRole("button", { name: "Frame" }));
+ expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
+});
diff --git a/src/components/workspace/ReferenceSelector.tsx b/src/components/workspace/ReferenceSelector.tsx
new file mode 100644
index 0000000..b35c8a4
--- /dev/null
+++ b/src/components/workspace/ReferenceSelector.tsx
@@ -0,0 +1,34 @@
+import { useEffect, useState } from "react";
+import { referenceTypeLabel, type ProjectReference } from "../../lib/project";
+import { referenceMediaTypes, selectReferences, type ReferenceMediaType } from "../../lib/referenceSelection";
+import { Audio16, ChevronDown14, Image16, Text16, Video16 } from "../ui/icons";
+import { ReferenceIcon } from "./ReferenceIcon";
+import { ReferencePicker } from "./ReferencePicker";
+
+/** `accept={["image"]}`, `["audio"]`, or `["image", "audio"]` constrain the
+ * same searchable picker used by prompt chips; selection stores a reference ID. */
+export function ReferenceSelector({ id, value, references, accept, folderPath, disabled, onChange, "aria-label": label }: {
+ id?: string; value: string; references: readonly ProjectReference[]; accept: readonly ReferenceMediaType[]; folderPath: string;
+ disabled?: boolean; onChange: (id: string) => void; "aria-label": string;
+}) {
+ const [anchor, setAnchor] = useState<HTMLButtonElement | null>(null);
+ useEffect(() => { if (disabled) setAnchor(null); }, [disabled]);
+ const selected = selectReferences(references, accept).find((reference) => reference.id === value);
+ const name = selected?.name ?? (value ? references.find((reference) => reference.id === value)?.name ?? "Unavailable reference" : "None");
+ const choose = (next: string) => { anchor?.focus(); setAnchor(null); onChange(next); };
+ const icon = (reference: ProjectReference) => <ReferenceIcon reference={reference} folderPath={folderPath}
+ fallback={reference.kind === "audio" ? <Audio16 /> : reference.kind === "video" ? <Video16 /> : referenceMediaTypes(reference).includes("image") ? <Image16 /> : <Text16 />} />;
+ return <>
+ <button id={id} type="button" className={`reference-selector${value && !selected ? " reference-selector--missing" : ""}`} aria-label={label} aria-haspopup="dialog"
+ aria-expanded={!disabled && Boolean(anchor)} disabled={disabled} data-value={value}
+ onClick={(event) => setAnchor(anchor ? null : event.currentTarget)}>
+ {selected && <span className="reference-selector__icon" aria-hidden="true">{icon(selected)}</span>}
+ <span className="reference-selector__name">{name}</span><ChevronDown14 aria-hidden="true" />
+ </button>
+ <ReferencePicker anchor={disabled ? null : anchor} title={label} current={value || null} currentLabel={name} accept={accept} allowEmpty clearLabel="None"
+ references={references.map((reference) => ({ id: reference.id, name: reference.name, detail: referenceTypeLabel(reference), mediaTypes: referenceMediaTypes(reference),
+ icon: icon(reference) }))}
+ emptyLabel="No matching references — add them under References."
+ onChoose={(reference) => choose(reference.id)} onRemove={() => choose("")} onClose={() => setAnchor(null)} />
+ </>;
+}
diff --git a/src/components/workspace/SceneEditor.tsx b/src/components/workspace/SceneEditor.tsx
index 7178dc6..7fbb73a 100644
--- a/src/components/workspace/SceneEditor.tsx
+++ b/src/components/workspace/SceneEditor.tsx
@@ -42,6 +42,8 @@ import { CommittedNumberInput } from "./CommittedNumberInput";
import { DEFAULT_CONTINUATION_OVERLAP, MAX_CONTINUATION_OVERLAP } from "../../lib/project";
import { PromptTextField } from "./PromptTextField";
import { ReferenceIcon } from "./ReferenceIcon";
+import { ReferenceSelector } from "./ReferenceSelector";
+import { referenceMediaTypes, selectReferences } from "../../lib/referenceSelection";
/** The step the length slider and the cut handles move in. Half a second is the
* finest cut the timestamp format prints exactly (`formatSceneSeconds`), so
@@ -131,7 +133,7 @@ export function ShotInspector({ job, shots, shot, index, endsAt, duration, refer
const pickable = useMemo(() => citable.map((reference) => {
const number = numbered.findIndex((item) => item.id === reference.id) + 1;
return {
- id: reference.id, name: reference.name, detail: `${number > 0 ? `Reference ${number}` : "Not in this scene yet"} · ${referenceTypeLabel(reference)}`,
+ id: reference.id, name: reference.name, mediaTypes: referenceMediaTypes(reference), detail: `${number > 0 ? `Reference ${number}` : "Not in this scene yet"} · ${referenceTypeLabel(reference)}`,
icon: <ReferenceIcon reference={reference} folderPath={folderPath} fallback={isVideoReference(reference) ? <Video16 /> : reference.kind === "audio" ? <Audio16 /> : referenceImages(reference).length ? <Image16 /> : <Text16 />} />,
};
}), [citable, numbered, folderPath]);
@@ -303,7 +305,7 @@ export function SceneInspector({ job, shots, references, folderPath = "", scenes
// is written. One place, never a second field that could disagree with it.
const chosen = shots.map((shot) => shot.settings?.[look.id]?.[0]).find(Boolean) ?? "";
const imageReferences = useMemo(
- () => references.filter((reference) => referenceImages(reference).length > 0 && isReferenceUsable(reference)),
+ () => selectReferences(references, ["image"]),
[references],
);
const videos = usableVideoReferences(references);
@@ -409,17 +411,14 @@ export function SceneInspector({ job, shots, references, folderPath = "", scenes
{!animate && !chosen && defaultLook && <p className="prop-caption">Using project Look: {look.options.find((option) => option.id === defaultLook)?.label ?? defaultLook}.</p>}
{!transition && !pose && !continuing && <>
<PropRow label={animate ? "Repainted frame" : "Start frame"} htmlFor={`${id}-start`}>
- <ComboBox
+ <ReferenceSelector
id={`${id}-start`}
+ references={references} accept={["image"]} folderPath={folderPath}
value={animate
? job.startFrameReferenceId ?? imageReferences.find((reference) => job.referenceIds.includes(reference.id))?.id ?? ""
: job.startFrameReferenceId ?? ""}
disabled={disabled}
aria-label="Start frame for this scene"
- options={[
- { value: "", label: "None" },
- ...imageReferences.map((reference) => ({ value: reference.id, label: reference.name })),
- ]}
onChange={(value) => onChange({
usePreviousSceneLastFrame: undefined,
startFrameReferenceId: value || undefined,
@@ -434,8 +433,8 @@ export function SceneInspector({ job, shots, references, folderPath = "", scenes
{animate && <p className="prop-caption">A frame of the driving video with the character repainted. Keep its pose, framing, background and lighting.</p>}
</>}
{!animate && !transition && !pose && !continuing && <PropRow label="Last frame" htmlFor={`${id}-end`}>
- <ComboBox id={`${id}-end`} value={job.endFrameReferenceId ?? ""} disabled={disabled} aria-label="Last frame for this scene"
- options={[{ value: "", label: "None" }, ...imageReferences.map((reference) => ({ value: reference.id, label: reference.name }))]}
+ <ReferenceSelector id={`${id}-end`} value={job.endFrameReferenceId ?? ""} disabled={disabled} aria-label="Last frame for this scene"
+ references={references} accept={["image"]} folderPath={folderPath}
onChange={(value) => onChange({ endFrameReferenceId: value || undefined })} />
{addImageButton("Add last frame", onAddEndFrame)}
</PropRow>}
diff --git a/src/components/workspace/promptTestUtils.ts b/src/components/workspace/promptTestUtils.ts
index 3a7297c..4c83512 100644
--- a/src/components/workspace/promptTestUtils.ts
+++ b/src/components/workspace/promptTestUtils.ts
@@ -1,4 +1,10 @@
-import { fireEvent, screen } from "@testing-library/react";
+import { fireEvent, screen, within } from "@testing-library/react";
+
+/** Choose a standalone reference using the same flyout as the prompt chips. */
+export const chooseReference = (label: string, name: string) => {
+ fireEvent.click(screen.getByRole("button", { name: label }));
+ fireEvent.click(within(screen.getByRole("dialog", { name: label })).getByText(name, { exact: true }).closest("button")!);
+};
/* PromptTextField is a contenteditable: typing into it is its text and an
input event, and its value reads each chip back as the token it stands for. */
diff --git a/src/lib/referenceSelection.test.ts b/src/lib/referenceSelection.test.ts
new file mode 100644
index 0000000..a922c36
--- /dev/null
+++ b/src/lib/referenceSelection.test.ts
@@ -0,0 +1,30 @@
+import { expect, it } from "vitest";
+import { referenceMediaTypes, selectReferences } from "./referenceSelection";
+import type { ProjectReference } from "./project";
+
+const reference = (id: string, patch: Partial<ProjectReference> = {}): ProjectReference => ({ id, name: id, kind: "text", description: "", intendedUse: [], createdAt: "2026-01-01T00:00:00.000Z", ...patch });
+
+it("selects real image payloads including attachments and video stills, but not generated icons or videos", () => {
+ const references = [
+ reference("legacy", { kind: "image", sourcePath: "D:/picture.png" }),
+ reference("attached", { images: [{ id: "image", name: "Image", relativePath: "references/image.png" }] }),
+ reference("frames", { kind: "video", sourcePath: "D:/clip.mp4", video: { mode: "frames", startSeconds: 0, durationSeconds: 3, includeAudio: false, frames: [{ id: "frame", name: "Frame", relativePath: "references/frame.png", timeSeconds: 1 }] } }),
+ reference("video", { kind: "video", sourcePath: "D:/clip.mp4" }),
+ reference("audio", { kind: "audio", sourcePath: "D:/voice.wav" }),
+ reference("icon", { description: "An illustrated character", iconRelativePath: "references/icon.png" }),
+ reference("empty"),
+ ];
+ expect(selectReferences(references, ["image"]).map((ref) => ref.id)).toEqual(["legacy", "attached", "frames"]);
+ expect(selectReferences(references, ["audio"]).map((ref) => ref.id)).toEqual(["audio"]);
+ expect(selectReferences(references, ["image", "audio"]).map((ref) => ref.id)).toEqual(["legacy", "attached", "frames", "audio"]);
+ expect(selectReferences(references, ["video"]).map((ref) => ref.id)).toEqual(["video"]);
+});
+
+it("recognizes mixed reference payloads without duplicate options, and ignores inactive refmods", () => {
+ const mixed = reference("mixed", { description: "Red coat", images: [{ id: "image", name: "Coat", relativePath: "references/coat.png" }],
+ refmods: [{ id: "encoded", name: "Coat", relativePath: "references/coat.safetensors", strength: 1, copies: 1 }] });
+ expect(referenceMediaTypes(mixed)).toEqual(["image", "text", "refmod"]);
+ expect(selectReferences([mixed], ["image", "text", "refmod"])).toEqual([mixed]);
+ expect(selectReferences([{ ...mixed, refmods: mixed.refmods!.map((refmod) => ({ ...refmod, strength: 0 })) }], ["refmod"])).toEqual([]);
+ expect(selectReferences([mixed], [])).toEqual([]);
+});
diff --git a/src/lib/referenceSelection.ts b/src/lib/referenceSelection.ts
new file mode 100644
index 0000000..eb0b44a
--- /dev/null
+++ b/src/lib/referenceSelection.ts
@@ -0,0 +1,24 @@
+import { activeReferenceRefmods, isAudioReference, isReferenceDescribed, isVideoReference, referenceImages, type ProjectReference } from "./project";
+
+export type ReferenceMediaType = "image" | "audio" | "video" | "text" | "refmod";
+
+/** Match payloads, not just the reference's kind: text references can carry
+ * images, and videos in Frames mode supply stills instead of a video clip. */
+export function referenceMediaTypes(reference: ProjectReference): ReferenceMediaType[] {
+ const types: ReferenceMediaType[] = [];
+ if (referenceImages(reference).length) types.push("image");
+ if (isAudioReference(reference)) types.push("audio");
+ if (isVideoReference(reference) && (reference.relativePath || reference.sourcePath)) types.push("video");
+ if (isReferenceDescribed(reference)) types.push("text");
+ if (activeReferenceRefmods(reference).length) types.push("refmod");
+ return types;
+}
+
+/** Any accepted payload is sufficient; an omitted filter offers everything. */
+export function filterReferenceOptions<T extends { mediaTypes?: readonly ReferenceMediaType[] }>(references: readonly T[], accept?: readonly ReferenceMediaType[]): T[] {
+ return references.filter((reference) => !accept || reference.mediaTypes?.some((type) => accept.includes(type)));
+}
+
+export function selectReferences(references: readonly ProjectReference[], accept: readonly ReferenceMediaType[]): ProjectReference[] {
+ return references.filter((reference) => referenceMediaTypes(reference).some((type) => accept.includes(type)));
+}
diff --git a/src/styles/prompt-field.css b/src/styles/prompt-field.css
index a5883aa..3e50a33 100644
--- a/src/styles/prompt-field.css
+++ b/src/styles/prompt-field.css
@@ -109,3 +109,11 @@
.prompt-reference-picker__text small { color: var(--text-muted); font-size: var(--text-xs); }
.prompt-reference-picker__empty { margin: 0; padding: var(--space-2); color: var(--text-muted); font-size: var(--text-xs); }
.prompt-reference-picker__remove { border-top: 1px solid var(--line); border-radius: 0; color: var(--danger); }
+
+.reference-selector { display: flex; align-items: center; gap: var(--space-2); width: 100%; min-width: 0; min-height: var(--control-md); padding: var(--space-1) var(--space-2); border: 1px solid var(--stroke-control); border-radius: var(--radius-sm); background: var(--fill-control); color: var(--text-primary); text-align: left; font: inherit; }
+.reference-selector:hover:not(:disabled) { background: var(--fill-control-hover); }
+.reference-selector:disabled { color: var(--text-disabled); background: var(--fill-control-disabled); }
+.reference-selector--missing { color: var(--danger); }
+.reference-selector__name { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
+.reference-selector__icon { display: grid; place-items: center; flex: 0 0 24px; width: 24px; height: 24px; overflow: hidden; border-radius: var(--radius-sm); }
+.reference-selector__icon img { width: 100%; height: 100%; object-fit: cover; }