Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(webv2): recall a video queue item into the Video panel

Lincoln Steinb0ee9f051628
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index 74bebc5af0..112bb5eacb 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -2116,11 +2116,13 @@
"recallAll": "Recall All",
"recallFromGallery": "Recall this generation from the gallery",
"recallUnavailable": "Nothing recallable for this item — select a supported Generate model first.",
+ "recallUnavailableForItem": "Nothing recallable for this item.",
"resumeProcessor": "Resume Processor",
"sendToCanvas": "Send to canvas",
"sendToCanvasComingSoon": "Sending queue results to the canvas is coming soon.",
"settingsRecalled": "Settings recalled",
"settingsRecalledDescription": "Loaded these settings into Generate.",
+ "settingsRecalledIntoVideoDescription": "Loaded these settings into Video.",
"took": "Took",
"waiting_one": "{{count}} waiting",
"waiting_other": "{{count}} waiting",
diff --git a/invokeai/frontend/webv2/src/features/queue/core/generationMeta.test.ts b/invokeai/frontend/webv2/src/features/queue/core/generationMeta.test.ts
new file mode 100644
index 0000000000..91d9826c27
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/queue/core/generationMeta.test.ts
@@ -0,0 +1,52 @@
+import { describe, expect, it } from 'vitest';
+
+import type { QueueItemReadModel, QueueNodeFieldValue } from './types';
+
+import { extractGenerationMeta } from './generationMeta';
+
+const item = (fieldValues: QueueNodeFieldValue[]): QueueItemReadModel => ({ fieldValues }) as QueueItemReadModel;
+
+const field = (nodePath: string, value: string | number): QueueNodeFieldValue => ({
+ fieldName: 'value',
+ nodePath,
+ value,
+});
+
+describe('extractGenerationMeta', () => {
+ it('reads the prompts and seed by node identity', () => {
+ expect(
+ extractGenerationMeta(
+ item([field('seed', 42), field('positive_prompt', 'a fox running'), field('negative_prompt', 'blurry')])
+ )
+ ).toEqual({ negativePrompt: 'blurry', positivePrompt: 'a fox running', seed: 42 });
+ });
+
+ it('keeps an empty positive prompt empty instead of promoting the negative', () => {
+ // A video submitted in first-frame mode may legitimately carry no positive
+ // prompt: the image drives the clip. Reading by order would drop the blank
+ // and slide 'blurry, low quality' into the positive slot, so recalling it
+ // would put the negative text in the Video panel's subject box.
+ const meta = extractGenerationMeta(
+ item([field('seed', 7), field('positive_prompt', ''), field('negative_prompt', 'blurry, low quality')])
+ );
+
+ expect(meta).toEqual({ negativePrompt: 'blurry, low quality', positivePrompt: '', seed: 7 });
+ });
+
+ it('falls back to value type and order for graphs that name their own nodes', () => {
+ expect(
+ extractGenerationMeta(item([field('noise', 99), field('prompt_a', 'subject'), field('prompt_b', 'avoid')]))
+ ).toEqual({ negativePrompt: 'avoid', positivePrompt: 'subject', seed: 99 });
+ });
+
+ it('recovers a seed by type when only the prompts are named', () => {
+ expect(extractGenerationMeta(item([field('noise', 5), field('positive_prompt', 'a fox')]))).toEqual({
+ positivePrompt: 'a fox',
+ seed: 5,
+ });
+ });
+
+ it('returns an empty meta for an item with no field values', () => {
+ expect(extractGenerationMeta({} as QueueItemReadModel)).toEqual({});
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/queue/core/generationMeta.ts b/invokeai/frontend/webv2/src/features/queue/core/generationMeta.ts
index fc64b7b149..91e06729e4 100644
--- a/invokeai/frontend/webv2/src/features/queue/core/generationMeta.ts
+++ b/invokeai/frontend/webv2/src/features/queue/core/generationMeta.ts
@@ -4,10 +4,17 @@ import type { QueueItemReadModel } from '@features/queue/core/types';
* Best-effort recovery of the human-facing generation parameters for a queue
* item. The reliable source is the local submission snapshot (matched in the
* view by origin), but server items from other clients/sources only carry
- * field values — generic node/field/value substitutions. For
- * webv2 generate batches these are exactly the seed (number) + positive/negative
- * prompts (strings), so we recover them by value type and order, degrading
- * gracefully for unknown graphs.
+ * field values — generic node/field/value substitutions.
+ *
+ * Every batch this client submits names its nodes (`buildGeneratePromptBatchPlan`
+ * stamps the graph's prompt/seed node ids as `node_path`), so read by identity
+ * first. Order alone is not safe: a submission may legitimately carry an EMPTY
+ * positive prompt — the Video panel has no positive-prompt requirement at all —
+ * and a positional scan that skips blanks would slide the negative prompt into
+ * the positive slot and recall it as the subject.
+ *
+ * Unknown graphs (other clients, workflow batches naming their own nodes) fall
+ * back to the original by-type/by-order heuristic.
*/
export interface QueueGenerationMeta {
@@ -16,13 +23,39 @@ export interface QueueGenerationMeta {
seed?: number;
}
+/** The node ids the generate/video graphs give their prompt and seed nodes. */
+const POSITIVE_PROMPT_NODE_PATH = 'positive_prompt';
+const NEGATIVE_PROMPT_NODE_PATH = 'negative_prompt';
+const SEED_NODE_PATH = 'seed';
+
export const extractGenerationMeta = (item: QueueItemReadModel): QueueGenerationMeta => {
+ const fieldValues = item.fieldValues ?? [];
const meta: QueueGenerationMeta = {};
- const prompts: string[] = [];
+ let namedPrompt = false;
- for (const fieldValue of item.fieldValues ?? []) {
- const { value } = fieldValue;
+ for (const { nodePath, value } of fieldValues) {
+ if (nodePath === POSITIVE_PROMPT_NODE_PATH && typeof value === 'string') {
+ // Recorded verbatim, empty included: an empty positive is a real
+ // submission, not a missing field.
+ meta.positivePrompt = value;
+ namedPrompt = true;
+ } else if (nodePath === NEGATIVE_PROMPT_NODE_PATH && typeof value === 'string') {
+ meta.negativePrompt = value;
+ namedPrompt = true;
+ } else if (nodePath === SEED_NODE_PATH && typeof value === 'number') {
+ meta.seed = value;
+ }
+ }
+ if (namedPrompt && meta.seed !== undefined) {
+ return meta;
+ }
+
+ // Fallback for graphs that name their nodes differently: recover by value
+ // type and order, as before. Only fills what the named pass did not.
+ const prompts: string[] = [];
+
+ for (const { value } of fieldValues) {
if (typeof value === 'number' && meta.seed === undefined) {
meta.seed = value;
} else if (typeof value === 'string' && value.trim().length > 0) {
@@ -30,6 +63,10 @@ export const extractGenerationMeta = (item: QueueItemReadModel): QueueGeneration
}
}
+ if (namedPrompt) {
+ return meta;
+ }
+
if (prompts[0] !== undefined) {
meta.positivePrompt = prompts[0];
}
diff --git a/invokeai/frontend/webv2/src/workbench/queue-integration/QueueItemActions.tsx b/invokeai/frontend/webv2/src/workbench/queue-integration/QueueItemActions.tsx
index 8ae6cd0424..64bcc9b238 100644
--- a/invokeai/frontend/webv2/src/workbench/queue-integration/QueueItemActions.tsx
+++ b/invokeai/frontend/webv2/src/workbench/queue-integration/QueueItemActions.tsx
@@ -21,8 +21,8 @@ import { FileTextIcon, WandSparklesIcon } from 'lucide-react';
import { useCallback, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
-import { buildQueueRecallValues, getQueueRecallCapabilities } from './queueRecall';
-import { useLocalGenerateValues } from './useLocalGenerateValues';
+import { getQueueRecallCapabilities, planQueueRecall } from './queueRecall';
+import { useLocalGenerateValues, useLocalQueueItemSource } from './useLocalGenerateValues';
const selectGenerateRecallValues = createGenerateFormValuesSelector();
@@ -35,10 +35,13 @@ const selectGenerateRecallValues = createGenerateFormValuesSelector();
*/
export const QueueItemActions = ({ item }: { item: QueueItemReadModel }) => {
const { t } = useTranslation();
- const { generation } = useWorkbenchCommands();
+ const { generation, widgets } = useWorkbenchCommands();
const openWidget = useOpenWorkbenchWidget();
const notify = useNotify();
const localGenerateValues = useLocalGenerateValues(item.origin);
+ // A video item's prompt belongs to the Video panel, which owns its own prompt
+ // values. Only knowable for items this client submitted; see the hook's note.
+ const isVideoItem = useLocalQueueItemSource(item.origin) === 'video';
const [jsonOpen, setJsonOpen] = useState(false);
const generateValues = useWidgetValuesSelector('generate', selectGenerateRecallValues);
const models = useModelsSelector((snapshot) => snapshot.models);
@@ -56,18 +59,45 @@ export const QueueItemActions = ({ item }: { item: QueueItemReadModel }) => {
const onRecall = useCallback(
(kind: ImageRecallKind) => {
const current = getCurrentGenerateValues({ generateValues, supportedModels });
- const values = buildQueueRecallValues(kind, { current, meta, snapshot: localGenerateValues });
+ const plan = planQueueRecall(kind, { current, isVideoItem, meta, snapshot: localGenerateValues });
- if (!values) {
- notify.info(getImageRecallTitle(kind), t('widgets.queue.recallUnavailable'));
+ if (!plan) {
+ notify.info(
+ getImageRecallTitle(kind),
+ // The Generate copy names a missing Generate model, which is not why
+ // a video recall would come back empty.
+ t(isVideoItem ? 'widgets.queue.recallUnavailableForItem' : 'widgets.queue.recallUnavailable')
+ );
return;
}
- generation.setSettings(values);
+ // Both branches write to the ACTIVE project, not the project that owns the
+ // item: with the default `all` queue scope Recent lists other projects'
+ // items too, and "recall" means "load this into the panel I am looking at".
+ // `openWidget` follows the same rule, so the write and the reveal agree.
+ if (plan.target === 'video') {
+ widgets.patchValues('video', plan.patch);
+ openWidget('video', { preferredRegions: ['left'] });
+ notify.success(getImageRecallTitle(kind), t('widgets.queue.settingsRecalledIntoVideoDescription'));
+ return;
+ }
+
+ generation.setSettings(plan.values);
openWidget('generate', { preferredRegions: ['left'] });
notify.success(getImageRecallTitle(kind), t('widgets.queue.settingsRecalledDescription'));
},
- [generateValues, generation, localGenerateValues, meta, notify, openWidget, supportedModels, t]
+ [
+ generateValues,
+ generation,
+ isVideoItem,
+ localGenerateValues,
+ meta,
+ notify,
+ openWidget,
+ supportedModels,
+ t,
+ widgets,
+ ]
);
const onSendToCanvas = useCallback(
diff --git a/invokeai/frontend/webv2/src/workbench/queue-integration/localQueueItemSource.test.ts b/invokeai/frontend/webv2/src/workbench/queue-integration/localQueueItemSource.test.ts
new file mode 100644
index 0000000000..076f3b2614
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/queue-integration/localQueueItemSource.test.ts
@@ -0,0 +1,75 @@
+import type { ModelConfig } from '@features/models';
+
+import { buildQueueItemOrigin } from '@features/queue/contracts';
+import { createInitialWorkbenchState, workbenchReducer } from '@workbench/workbenchState.testing';
+import { describe, expect, it, vi } from 'vitest';
+
+import { getLocalQueueItemSource } from './useLocalGenerateValues';
+
+vi.mock('@features/queue/devices', async (importOriginal) => {
+ const original = (await importOriginal()) as Record<string, unknown>;
+
+ return {
+ ...original,
+ getGenerationDevicesSnapshot: () => ({ error: null, loadState: 'loaded', options: [], setting: 'auto' }),
+ };
+});
+
+const wanModel: ModelConfig = {
+ base: 'wan',
+ file_size: 1,
+ format: 'diffusers',
+ hash: 'wan-hash',
+ key: 'wan-t2v_a14b-diffusers',
+ name: 'Wan 2.2 t2v_a14b',
+ path: 'wan-t2v_a14b-diffusers',
+ source: 'wan-t2v_a14b-diffusers',
+ source_type: 'path',
+ type: 'main',
+ variant: 't2v_a14b',
+} as ModelConfig;
+
+/** A real state with one submitted queue item, produced by the reducer rather than hand-rolled. */
+const submitVideo = () => {
+ let state = createInitialWorkbenchState();
+
+ state = workbenchReducer(state, {
+ type: 'patchWidgetValues',
+ values: { model: wanModel, positivePrompt: 'a fox running' },
+ widgetId: 'video',
+ });
+ state = workbenchReducer(state, { sourceId: 'video', type: 'setInvocationSource' });
+ state = workbenchReducer(state, { destination: 'gallery', type: 'setInvocationDestination' });
+ state = workbenchReducer(state, {
+ backendSupportsCancellation: true,
+ models: [wanModel],
+ type: 'submitInvocationSnapshot',
+ });
+
+ return state;
+};
+
+describe('getLocalQueueItemSource', () => {
+ it('reports the video source for an item this client submitted from Video', () => {
+ const state = submitVideo();
+ const project = state.projects.find((candidate) => candidate.id === state.activeProjectId)!;
+ const localItem = project.queue.items[0]!;
+
+ expect(localItem.snapshot.sourceId).toBe('video');
+ expect(getLocalQueueItemSource(state.projects, buildQueueItemOrigin(localItem.id, project.id))).toBe('video');
+ // The prefix without a project id is the other shape the submitter emits.
+ expect(getLocalQueueItemSource(state.projects, buildQueueItemOrigin(localItem.id))).toBe('video');
+ });
+
+ it('reports null — not a source — for an item this client did not submit', () => {
+ const state = submitVideo();
+
+ // A foreign item carries no decodable origin, so the caller has to fall back
+ // to the Generate-shaped default rather than guessing at video.
+ expect(getLocalQueueItemSource(state.projects, 'some-other-client')).toBeNull();
+ expect(getLocalQueueItemSource(state.projects, null)).toBeNull();
+ expect(getLocalQueueItemSource(state.projects, undefined)).toBeNull();
+ // Decodable, but no longer present locally (snapshot cleared).
+ expect(getLocalQueueItemSource(state.projects, buildQueueItemOrigin('queue-item-gone'))).toBeNull();
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.test.ts b/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.test.ts
index d24e2fc47c..eb9f0464c3 100644
--- a/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.test.ts
@@ -2,7 +2,12 @@ import type { GenerateWidgetValues } from '@features/generation/contracts';
import { describe, expect, it } from 'vitest';
-import { buildQueueRecallValues, getQueueRecallCapabilities } from './queueRecall';
+import {
+ buildQueueRecallValues,
+ buildVideoQueueRecallPatch,
+ getQueueRecallCapabilities,
+ planQueueRecall,
+} from './queueRecall';
const makeValues = (overrides: Partial<GenerateWidgetValues> = {}): GenerateWidgetValues =>
({
@@ -156,3 +161,69 @@ describe('buildQueueRecallValues', () => {
expect(buildQueueRecallValues('seed', { current: null, meta: { seed: 1 }, snapshot: null })).toBeNull();
});
});
+
+describe('buildVideoQueueRecallPatch', () => {
+ it('patches only the prompt keys, so the rest of the Video panel is untouched', () => {
+ expect(
+ buildVideoQueueRecallPatch('prompts', { negativePrompt: 'blurry', positivePrompt: 'a fox running' })
+ ).toEqual({ negativePrompt: 'blurry', negativePromptEnabled: true, positivePrompt: 'a fox running' });
+ });
+
+ it('leaves the negative toggle alone when no usable negative was recorded', () => {
+ expect(buildVideoQueueRecallPatch('prompts', { positivePrompt: 'a fox running' })).toEqual({
+ positivePrompt: 'a fox running',
+ });
+ expect(buildVideoQueueRecallPatch('prompts', { negativePrompt: '', positivePrompt: 'a fox running' })).toEqual({
+ positivePrompt: 'a fox running',
+ });
+ });
+
+ it('patches the executed seed and stops it being re-randomised', () => {
+ expect(buildVideoQueueRecallPatch('seed', { seed: 4321 })).toEqual({ seed: 4321, shouldRandomizeSeed: false });
+ });
+
+ it('returns null when the meta carries nothing for the verb', () => {
+ expect(buildVideoQueueRecallPatch('prompts', {})).toBeNull();
+ expect(buildVideoQueueRecallPatch('seed', {})).toBeNull();
+ });
+
+ it('returns null for the verbs a video queue item never offers', () => {
+ const meta = { positivePrompt: 'a fox running', seed: 1 };
+
+ // These are disabled by `getQueueRecallCapabilities` for a video item (its
+ // Generate-shaped snapshot is always null), so they must not half-apply.
+ for (const kind of ['all', 'remix', 'dimensions', 'clipSkip'] as const) {
+ expect(buildVideoQueueRecallPatch(kind, meta)).toBeNull();
+ }
+ });
+});
+
+describe('planQueueRecall', () => {
+ const current = makeValues();
+ const meta = { negativePrompt: 'blurry', positivePrompt: 'a fox running', seed: 4321 };
+
+ it('targets Video for an item this client submitted from Video', () => {
+ // The bug this replaced: a video item's prompt was written into Generate.
+ expect(planQueueRecall('prompts', { current, isVideoItem: true, meta, snapshot: null })).toEqual({
+ patch: { negativePrompt: 'blurry', negativePromptEnabled: true, positivePrompt: 'a fox running' },
+ target: 'video',
+ });
+ expect(planQueueRecall('seed', { current, isVideoItem: true, meta, snapshot: null })).toEqual({
+ patch: { seed: 4321, shouldRandomizeSeed: false },
+ target: 'video',
+ });
+ });
+
+ it('targets Generate for a non-video item, and for one whose source is unknown', () => {
+ const plan = planQueueRecall('prompts', { current, isVideoItem: false, meta, snapshot: null });
+
+ expect(plan?.target).toBe('generate');
+ expect(plan).toMatchObject({ values: { positivePrompt: 'a fox running' } });
+ });
+
+ it('returns null rather than falling through to the other panel', () => {
+ // A verb the video branch cannot serve must not quietly recall into Generate.
+ expect(planQueueRecall('all', { current, isVideoItem: true, meta, snapshot: makeValues() })).toBeNull();
+ expect(planQueueRecall('prompts', { current, isVideoItem: true, meta: {}, snapshot: null })).toBeNull();
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.ts b/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.ts
index 9d405e7c66..17f338aa06 100644
--- a/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.ts
+++ b/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.ts
@@ -1,5 +1,6 @@
import type { GenerateWidgetValues } from '@features/generation/contracts';
import type { QueueGenerationMeta } from '@features/queue/contracts';
+import type { VideoWidgetValues } from '@features/video';
import type { ImageRecallCapabilities, ImageRecallKind } from '@workbench/image-actions';
/**
@@ -97,3 +98,92 @@ export const buildQueueRecallValues = (
return snapshot ? { ...current, clipSkip: snapshot.clipSkip } : null;
};
+
+/**
+ * The Video-panel equivalent of {@link buildQueueRecallValues}, for a queue item
+ * this client submitted from Video. Video's prompt is its own widget value, so a
+ * video item's prompt must not be recalled into Generate's — the two panels hold
+ * independent text.
+ *
+ * Only the verbs a video item can actually offer are handled. Its `snapshot` in
+ * {@link getQueueRecallCapabilities} is always null (that lookup is Generate-
+ * shaped), so `all`/`remix`/`dimensions`/`clipSkip` are disabled for video items
+ * and never reach here; prompts and seed come from the session meta, which is
+ * recorded identically for video and image batches.
+ *
+ * Returns a PATCH, not a whole values object: the panel's other settings belong
+ * to whatever the user has configured now, and a wholesale write would drag a
+ * model-family transition along with it.
+ */
+export const buildVideoQueueRecallPatch = (
+ kind: ImageRecallKind,
+ meta: QueueGenerationMeta
+): Partial<VideoWidgetValues> | null => {
+ if (kind === 'prompts') {
+ if (meta.positivePrompt === undefined) {
+ return null;
+ }
+
+ return {
+ positivePrompt: meta.positivePrompt,
+ // Session meta cannot distinguish "no negative recorded" from "negative
+ // disabled, submitted as ''", so an absent or empty negative leaves the
+ // toggle exactly as the user has it rather than flipping it off. This
+ // matches the gallery-side video recall for Wan. MiniMax H3 differs:
+ // it never wires a negative into its metadata, so gallery recall sees
+ // nothing, while the batch still records the field and we recall it —
+ // harmless, since H3's panel hides the negative and the value restored
+ // is the one the panel already held.
+ ...(meta.negativePrompt !== undefined && meta.negativePrompt.length > 0
+ ? { negativePrompt: meta.negativePrompt, negativePromptEnabled: true }
+ : {}),
+ };
+ }
+
+ if (kind === 'seed') {
+ return meta.seed === undefined ? null : { seed: meta.seed, shouldRandomizeSeed: false };
+ }
+
+ return null;
+};
+
+/**
+ * Which panel a queue-item recall targets, and what to write there. A
+ * discriminated union rather than a caller-side `if`: the two panels take
+ * different payloads (Video a partial patch, Generate a whole values object),
+ * so a caller that forgets a branch fails to compile instead of silently
+ * recalling into the wrong panel — which is exactly the bug this replaced.
+ */
+export type QueueRecallPlan =
+ | { target: 'generate'; values: GenerateWidgetValues }
+ | { target: 'video'; patch: Partial<VideoWidgetValues> };
+
+export const planQueueRecall = (
+ kind: ImageRecallKind,
+ {
+ current,
+ isVideoItem,
+ meta,
+ snapshot,
+ }: {
+ current: GenerateWidgetValues | null;
+ /**
+ * Whether this item was submitted from Video BY THIS CLIENT. False also
+ * means "unknown" — a foreign item's `field_values` cannot distinguish a
+ * video batch from an image one, so the Generate-shaped default stands.
+ */
+ isVideoItem: boolean;
+ meta: QueueGenerationMeta;
+ snapshot: GenerateWidgetValues | null;
+ }
+): QueueRecallPlan | null => {
+ if (isVideoItem) {
+ const patch = buildVideoQueueRecallPatch(kind, meta);
+
+ return patch ? { patch, target: 'video' } : null;
+ }
+
+ const values = buildQueueRecallValues(kind, { current, meta, snapshot });
+
+ return values ? { target: 'generate', values } : null;
+};
diff --git a/invokeai/frontend/webv2/src/workbench/queue-integration/useLocalGenerateValues.ts b/invokeai/frontend/webv2/src/workbench/queue-integration/useLocalGenerateValues.ts
index 7a5fd8f50b..8658e3d077 100644
--- a/invokeai/frontend/webv2/src/workbench/queue-integration/useLocalGenerateValues.ts
+++ b/invokeai/frontend/webv2/src/workbench/queue-integration/useLocalGenerateValues.ts
@@ -1,4 +1,6 @@
import type { GenerateWidgetValues } from '@features/generation/contracts';
+import type { InvocationSourceId } from '@workbench/invocationContracts';
+import type { Project } from '@workbench/projectContracts';
import { parseQueueItemOrigin } from '@features/queue/contracts';
import { useWorkbenchSelector } from '@workbench/WorkbenchContext';
@@ -10,23 +12,63 @@ import { useWorkbenchSelector } from '@workbench/WorkbenchContext';
* can recall the exact settings (model, steps, LoRAs, …); absent (item from
* another client, or a cleared snapshot) → only field_values are recoverable.
*/
+/**
+ * The local queue item a server item's origin points at, or null. The single
+ * resolution both lookups below build on: deriving the item's source and its
+ * Generate snapshot from two independent scans would let them disagree about
+ * WHICH item they matched, and a capability matrix computed from one item while
+ * the recall routes by another is how a verb ends up enabled but unserviceable.
+ */
+const findLocalQueueItem = (
+ projects: readonly Pick<Project, 'queue'>[],
+ origin?: string | null
+): Project['queue']['items'][number] | null => {
+ const localId = parseQueueItemOrigin(origin);
+
+ if (!localId) {
+ return null;
+ }
+
+ for (const project of projects) {
+ const localItem = project.queue.items.find((queueItem) => queueItem.id === localId);
+
+ if (localItem) {
+ return localItem;
+ }
+ }
+
+ return null;
+};
+
export const useLocalGenerateValues = (origin?: string | null): GenerateWidgetValues | null =>
useWorkbenchSelector((snapshot) => {
- const localId = parseQueueItemOrigin(origin);
+ const localItem = findLocalQueueItem(snapshot.projects, origin);
- if (!localId) {
+ if (!localItem || (localItem.snapshot.sourceId !== 'generate' && localItem.snapshot.sourceId !== 'canvas')) {
return null;
}
- for (const project of snapshot.projects) {
- const localItem = project.queue.items.find((queueItem) => queueItem.id === localId);
+ const generate = (localItem.snapshot.widgetStates as Record<string, { values?: unknown }>).generate;
- if (localItem && (localItem.snapshot.sourceId === 'generate' || localItem.snapshot.sourceId === 'canvas')) {
- const generate = (localItem.snapshot.widgetStates as Record<string, { values?: unknown }>).generate;
+ return (generate?.values as GenerateWidgetValues | undefined) ?? null;
+ });
- return (generate?.values as GenerateWidgetValues | undefined) ?? null;
- }
- }
+/**
+ * The invocation source a server queue item was submitted from, if this client
+ * submitted it. Decoded the same way as {@link useLocalGenerateValues}, but kept
+ * separate because it answers a different question and returns a primitive, so
+ * it re-renders its host only when the source actually changes.
+ *
+ * `null` means "unknown", not "not video": a foreign item — or one whose local
+ * snapshot has been cleared — carries no source, and its `field_values` cannot
+ * distinguish a video batch from an image one (both record a seed and prompts
+ * through the same batch plan). Callers must treat null as the Generate-shaped
+ * default rather than assuming a source.
+ */
+export const getLocalQueueItemSource = (
+ projects: readonly Pick<Project, 'queue'>[],
+ origin?: string | null
+): InvocationSourceId | null => findLocalQueueItem(projects, origin)?.snapshot.sourceId ?? null;
- return null;
- });
+export const useLocalQueueItemSource = (origin?: string | null): InvocationSourceId | null =>
+ useWorkbenchSelector((snapshot) => getLocalQueueItemSource(snapshot.projects, origin));