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): validate invocations against loaded models

joshistoast672ae7f24c75
diff --git a/invokeai/frontend/webv2/src/workbench/graph-preview/GraphPreviewDialog.tsx b/invokeai/frontend/webv2/src/workbench/graph-preview/GraphPreviewDialog.tsx
index e0524b164a..1464312ff4 100644
--- a/invokeai/frontend/webv2/src/workbench/graph-preview/GraphPreviewDialog.tsx
+++ b/invokeai/frontend/webv2/src/workbench/graph-preview/GraphPreviewDialog.tsx
@@ -4,8 +4,9 @@ import type { XYPosition } from '@workbench/workflows/types';
import { Box, Dialog, Portal, SegmentGroup, Text } from '@chakra-ui/react';
import { Button, JsonPreview } from '@workbench/components/ui';
import { formatRoute, isInvocationRouteValid, resolveInvocationRoute } from '@workbench/invocation';
+import { ensureModelsLoaded, useModelsSnapshot } from '@workbench/models/modelsStore';
import { useActiveProject, useWorkbenchDispatch } from '@workbench/WorkbenchContext';
-import { useState, type ReactNode } from 'react';
+import { useEffect, useState, type ReactNode } from 'react';
import { GraphPreviewFlow } from './GraphPreviewFlow';
@@ -39,12 +40,23 @@ export const GraphPreviewDialog = ({
}: GraphPreviewDialogProps) => {
const activeProject = useActiveProject();
const dispatch = useWorkbenchDispatch();
+ const { models, status: modelsStatus } = useModelsSnapshot();
+ const availabilityModels = modelsStatus === 'loaded' ? models : undefined;
const [mode, setMode] = useState<PreviewMode>('nodes');
const dialogRoute = sourceId
- ? resolveInvocationRoute(activeProject, 'dialog', { ...activeProject.invocation, sourceId, sourceLocked: true })
+ ? resolveInvocationRoute(
+ activeProject,
+ 'dialog',
+ { ...activeProject.invocation, sourceId, sourceLocked: true },
+ availabilityModels
+ )
: null;
const canInvoke = dialogRoute ? isInvocationRouteValid(dialogRoute) : false;
+ useEffect(() => {
+ ensureModelsLoaded();
+ }, []);
+
return (
<Dialog.Root open={isOpen} size="xl" onOpenChange={(event) => onOpenChange(event.open)}>
<Portal>
@@ -95,6 +107,7 @@ export const GraphPreviewDialog = ({
dispatch({
backendSupportsCancellation: true,
+ models: availabilityModels,
route: dialogRoute,
type: 'submitResolvedInvocationSnapshot',
});
diff --git a/invokeai/frontend/webv2/src/workbench/invocation.test.ts b/invokeai/frontend/webv2/src/workbench/invocation.test.ts
new file mode 100644
index 0000000000..9934873094
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/invocation.test.ts
@@ -0,0 +1,123 @@
+import { describe, expect, it } from 'vitest';
+
+import type {
+ ComponentModelConfig,
+ GenerateModelConfig,
+ GenerateWidgetValues,
+ MainModelConfig,
+ VaeModelConfig,
+} from './generation/types';
+
+import { getDefaultGenerateSettings } from './generation/baseGenerationPolicies';
+import { resolveInvocationRoute } from './invocation';
+import { createInitialWorkbenchState, workbenchReducer } from './workbenchState';
+
+const animaModel: MainModelConfig = { base: 'anima', key: 'anima-model', name: 'Anima', type: 'main' };
+const animaVae: VaeModelConfig = { base: 'qwen-image', key: 'anima-vae', name: 'Anima VAE', type: 'vae' };
+const flux2Model: MainModelConfig = {
+ base: 'flux2',
+ format: 'gguf_quantized',
+ key: 'flux2-klein-9b',
+ name: 'FLUX.2 Klein 9B',
+ type: 'main',
+ variant: 'klein_9b',
+};
+const incompatibleFlux2Source: MainModelConfig = {
+ base: 'flux2',
+ format: 'diffusers',
+ key: 'flux2-klein-4b-source',
+ name: 'FLUX.2 Klein 4B Source',
+ type: 'main',
+ variant: 'klein_4b',
+};
+const flux2Vae: VaeModelConfig = { base: 'flux2', key: 'flux2-vae', name: 'FLUX.2 VAE', type: 'vae' };
+const flux2Qwen3Encoder: ComponentModelConfig = {
+ base: 'any',
+ key: 'flux2-qwen3-encoder',
+ name: 'Qwen3 8B Encoder',
+ type: 'qwen3_encoder',
+ variant: 'qwen3_8b',
+};
+const qwen3Encoder: ComponentModelConfig = {
+ base: 'any',
+ key: 'qwen3-encoder',
+ name: 'Qwen3 Encoder',
+ type: 'qwen3_encoder',
+ variant: 'qwen3_06b',
+};
+const unknownExternalModel: GenerateModelConfig = {
+ base: 'external',
+ capabilities: { modes: ['txt2img'] },
+ format: 'external_api',
+ key: 'external-unknown',
+ name: 'Unknown External Provider',
+ provider_id: 'future-provider',
+ type: 'external_image_generator',
+};
+
+const createGenerateValues = (
+ model: GenerateModelConfig = animaModel,
+ overrides: Partial<GenerateWidgetValues> = {}
+): GenerateWidgetValues => ({
+ ...getDefaultGenerateSettings(model),
+ model,
+ modelKey: model.key,
+ positivePrompt: 'an anima prompt',
+ ...overrides,
+});
+
+const getActiveProject = (values: GenerateWidgetValues) => {
+ const state = workbenchReducer(createInitialWorkbenchState(), { type: 'setGenerateSettings', values });
+ const project = state.projects.find((candidate) => candidate.id === state.activeProjectId);
+
+ expect(project).toBeDefined();
+
+ return project!;
+};
+
+describe('resolveInvocationRoute', () => {
+ it('invalidates Anima generation until required components are selected', () => {
+ const missingComponentsRoute = resolveInvocationRoute(
+ getActiveProject(createGenerateValues(animaModel, { vae: animaVae }))
+ );
+
+ expect(missingComponentsRoute.sourceValid).toBe(false);
+ expect(missingComponentsRoute.validationReasons).toContain('Generate needs a Qwen3 Encoder for Anima models.');
+
+ const validRoute = resolveInvocationRoute(
+ getActiveProject(createGenerateValues(animaModel, { qwen3EncoderModel: qwen3Encoder, vae: animaVae }))
+ );
+
+ expect(validRoute.sourceValid).toBe(true);
+ expect(validRoute.validationReasons).toEqual([]);
+ });
+
+ it('invalidates non-Diffusers FLUX.2 generation when a stale component source cannot provide the required Qwen3 encoder', () => {
+ const route = resolveInvocationRoute(
+ getActiveProject(
+ createGenerateValues(flux2Model, { componentSourceModel: incompatibleFlux2Source, vae: flux2Vae })
+ )
+ );
+
+ expect(route.sourceValid).toBe(false);
+ expect(route.validationReasons).toContain('Generate needs a Qwen3 Encoder for non-Diffusers FLUX.2 models.');
+ });
+
+ it('invalidates FLUX.2 generation when dimensions are not on the required 16px grid', () => {
+ const route = resolveInvocationRoute(
+ getActiveProject(
+ createGenerateValues(flux2Model, { height: 888, qwen3EncoderModel: flux2Qwen3Encoder, vae: flux2Vae })
+ )
+ );
+
+ expect(route.sourceValid).toBe(false);
+ expect(route.validationReasons).toContain('Generate height must be a multiple of 16.');
+ });
+
+ it('invalidates external providers without a registered invocation node', () => {
+ const route = resolveInvocationRoute(getActiveProject(createGenerateValues(unknownExternalModel)));
+
+ expect(route.sourceValid).toBe(false);
+ expect(route.validationReasons).toContain("No invocation node registered for external provider 'future-provider'.");
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/invocation.ts b/invokeai/frontend/webv2/src/workbench/invocation.ts
index 2f8d0684f5..2e72fadb8d 100644
--- a/invokeai/frontend/webv2/src/workbench/invocation.ts
+++ b/invokeai/frontend/webv2/src/workbench/invocation.ts
@@ -1,3 +1,4 @@
+import type { ModelConfig } from './models/types';
import type {
InvocationMode,
InvocationRoute,
@@ -8,6 +9,12 @@ import type {
WidgetId,
} from './types';
+import {
+ getGenerationModelAvailabilityReasons,
+ getGenerationValidationReasons,
+ isSupportedGenerateModel,
+} from './generation/baseGenerationPolicies';
+import { normalizeGenerateWidgetValues } from './generation/settings';
import { getProjectGraphReadiness } from './workflows/buildGraph';
import { getInvocationTemplatesSnapshot } from './workflows/templates';
@@ -74,25 +81,17 @@ const sourceWidgetIds: Partial<Record<InvocationSourceId, WidgetId>> = {
const isWidgetMounted = (project: Project, widgetId: WidgetId): boolean =>
Object.values(project.widgetRegions).some((region) => region.enabledWidgetIds.includes(widgetId));
-const hasGenerateSnapshotInputs = (project: Project): boolean => {
- const values = project.widgetStates.generate.values;
- const model = values.model;
- const hasFiniteNumber = (key: string) => typeof values[key] === 'number' && Number.isFinite(values[key]);
-
- return (
- typeof values.modelKey === 'string' &&
- typeof values.positivePrompt === 'string' &&
- typeof values.negativePrompt === 'string' &&
- hasFiniteNumber('width') &&
- hasFiniteNumber('height') &&
- hasFiniteNumber('steps') &&
- hasFiniteNumber('cfgScale') &&
- hasFiniteNumber('cfgRescaleMultiplier') &&
- typeof values.scheduler === 'string' &&
- hasFiniteNumber('seed') &&
- typeof values.shouldRandomizeSeed === 'boolean' &&
- Boolean(model && typeof model === 'object' && (model as Record<string, unknown>).type === 'main')
- );
+const getGenerateSnapshotValidationReasons = (project: Project, models?: readonly ModelConfig[]): string[] => {
+ const values = normalizeGenerateWidgetValues(project.widgetStates.generate.values);
+
+ if (!values || !isSupportedGenerateModel(values.model)) {
+ return ['Generate needs a supported model before it can be invoked.'];
+ }
+
+ return [
+ ...getGenerationValidationReasons(values.model, values),
+ ...(models ? getGenerationModelAvailabilityReasons(values.model, values, models) : []),
+ ];
};
export const isResultDestinationAvailable = (destination: ResultDestination): boolean =>
@@ -101,7 +100,8 @@ export const isResultDestinationAvailable = (destination: ResultDestination): bo
export const resolveInvocationRoute = (
project: Project,
mode: InvocationMode = 'global',
- route: InvocationRoute = project.invocation
+ route: InvocationRoute = project.invocation,
+ models?: readonly ModelConfig[]
): ResolvedInvocationRoute => {
const sourceId = route.sourceId;
const destination = route.destination;
@@ -121,8 +121,8 @@ export const resolveInvocationRoute = (
validationReasons.push(`The ${getSourceLabel(sourceId)} widget is not mounted in this project.`);
}
- if (sourceId === 'generate' && !hasGenerateSnapshotInputs(project)) {
- validationReasons.push('Generate needs a supported model before it can be invoked.');
+ if (sourceId === 'generate') {
+ validationReasons.push(...getGenerateSnapshotValidationReasons(project, models));
}
if (projectGraphReadiness && !projectGraphReadiness.canInvoke) {
diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/InvokeControl.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/InvokeControl.tsx
index f710923d71..226b842a9f 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/InvokeControl.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/InvokeControl.tsx
@@ -11,6 +11,7 @@ import {
resolveInvocationRoute,
resultDestinations,
} from '@workbench/invocation';
+import { ensureModelsLoaded, useModelsSnapshot } from '@workbench/models/modelsStore';
import { useActiveProject, useWorkbenchDispatch, useWorkbenchSelector } from '@workbench/WorkbenchContext';
import { useInvocationTemplatesSnapshot } from '@workbench/workflows/templates';
import { CheckIcon, ChevronDownIcon, LockKeyholeIcon, SparklesIcon } from 'lucide-react';
@@ -98,13 +99,15 @@ export const InvokeControl = () => {
const activeProject = useActiveProject();
const dispatch = useWorkbenchDispatch();
const backendConnectionStatus = useWorkbenchSelector((snapshot) => snapshot.state.backendConnection.status);
+ const { models, status: modelsStatus } = useModelsSnapshot();
+ const availabilityModels = modelsStatus === 'loaded' ? models : undefined;
const { invocation } = activeProject;
// Project-graph route validation reads the invocation templates imperatively;
// subscribing here keeps the resolved route live while they load.
useInvocationTemplatesSnapshot();
- const resolvedRoute = resolveInvocationRoute(activeProject);
+ const resolvedRoute = resolveInvocationRoute(activeProject, 'global', activeProject.invocation, availabilityModels);
const isLocked = invocation.sourceLocked || invocation.destinationLocked;
const isConnected = backendConnectionStatus === 'connected';
// Legacy parity: the queue button disables with the full list of reasons,
@@ -117,9 +120,15 @@ export const InvokeControl = () => {
const routeLabel = isValid ? formatRoute(resolvedRoute) : (blockingReasons[0] ?? formatRoute(resolvedRoute));
const resolvedRouteRef = useRef(resolvedRoute);
const isValidRef = useRef(isValid);
+ const modelsRef = useRef(availabilityModels);
resolvedRouteRef.current = resolvedRoute;
isValidRef.current = isValid;
+ modelsRef.current = availabilityModels;
+
+ useEffect(() => {
+ ensureModelsLoaded();
+ }, []);
useEffect(() => {
const onKeyDown = (event: KeyboardEvent) => {
@@ -135,6 +144,7 @@ export const InvokeControl = () => {
dispatch({
backendSupportsCancellation: true,
+ models: modelsRef.current,
route: resolvedRouteRef.current,
type: 'submitResolvedInvocationSnapshot',
});
@@ -154,6 +164,7 @@ export const InvokeControl = () => {
dispatch({
backendSupportsCancellation: true,
+ models: availabilityModels,
route: resolvedRouteRef.current,
type: 'submitResolvedInvocationSnapshot',
});
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
index 19bec4e356..93623c510d 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
@@ -20,18 +20,26 @@ const createGenerateValues = (overrides: Partial<GenerateWidgetValues> = {}): Ge
batchCount: 1,
cfgRescaleMultiplier: 0,
cfgScale: 7,
+ clipEmbedModel: null,
+ clipGEmbedModel: null,
+ clipLEmbedModel: null,
clipSkip: 0,
+ componentSourceModel: null,
height: 1024,
+ loras: [],
model,
modelKey: model.key,
negativePrompt: '',
positivePrompt: 'first prompt',
+ qwen3EncoderModel: null,
+ qwenVLEncoderModel: null,
scheduler: 'euler_a',
seamlessXAxis: false,
seamlessYAxis: false,
seed: 123,
shouldRandomizeSeed: false,
steps: 30,
+ t5EncoderModel: null,
vae: null,
vaePrecision: 'fp32',
width: 1024,
@@ -185,6 +193,18 @@ describe('workbench widget region opening', () => {
});
describe('workbenchReducer Phase 5 generation flow', () => {
+ it('does not notify gallery total subscribers for unchanged or non-finite totals', () => {
+ let state = createInitialWorkbenchState();
+
+ state = workbenchReducer(state, { totalImages: 3, type: 'setGalleryPageInfo' });
+
+ const unchanged = workbenchReducer(state, { totalImages: 3, type: 'setGalleryPageInfo' });
+ const nonFinite = workbenchReducer(state, { totalImages: Number.NaN, type: 'setGalleryPageInfo' });
+
+ expect(unchanged).toBe(state);
+ expect(nonFinite).toBe(state);
+ });
+
it('routes queue results back to the originating project after the user switches projects', () => {
let state = submitGenerate(primeGenerate());
const originProject = getActiveProject(state);
@@ -953,6 +973,9 @@ describe('workbench backend connection recovery', () => {
it('refreshes every project gallery when backend data may have changed', () => {
const initial = createInitialWorkbenchState();
const previousTokens = initial.projects.map((project) => project.widgetStates.gallery.values.galleryRefreshToken);
+ const previousImageTokens = initial.projects.map(
+ (project) => project.widgetStates.gallery.values.galleryImagesRefreshToken
+ );
const state = workbenchReducer(initial, { type: 'refreshBackendData' });
expect(state.projects).toHaveLength(initial.projects.length);
@@ -960,9 +983,22 @@ describe('workbench backend connection recovery', () => {
for (const [index, project] of state.projects.entries()) {
expect(project.widgetStates.gallery.values.galleryRefreshToken).toBeDefined();
expect(project.widgetStates.gallery.values.galleryRefreshToken).not.toBe(previousTokens[index]);
+ expect(project.widgetStates.gallery.values.galleryImagesRefreshToken).toBeDefined();
+ expect(project.widgetStates.gallery.values.galleryImagesRefreshToken).not.toBe(previousImageTokens[index]);
}
});
+ it('can refresh gallery images without invalidating board data', () => {
+ const initial = createInitialWorkbenchState();
+ const state = workbenchReducer(initial, { type: 'touchGalleryImagesRefresh' });
+ const previousValues = getActiveProject(initial).widgetStates.gallery.values;
+ const values = getActiveProject(state).widgetStates.gallery.values;
+
+ expect(values.galleryRefreshToken).toBe(previousValues.galleryRefreshToken);
+ expect(values.galleryImagesRefreshToken).toBeDefined();
+ expect(values.galleryImagesRefreshToken).not.toBe(previousValues.galleryImagesRefreshToken);
+ });
+
it('does not hydrate stale persisted backend connection state', () => {
const initial = createInitialWorkbenchState();
const persisted = {
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
index a435b677a5..fd2fc2c5ca 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
@@ -1,5 +1,6 @@
import type { GallerySettings } from './gallery/settings';
import type { GenerateWidgetValues } from './generation/types';
+import type { ModelConfig } from './models/types';
import type {
CanvasDocumentContract,
CanvasPlacementContract,
@@ -32,9 +33,14 @@ import type {
} from './types';
import type { ProjectGraphState } from './workflows/types';
+import { getGenerationModelAvailabilityReasons } from './generation/baseGenerationPolicies';
import { sanitizeBatchCount } from './generation/batch';
import { compileGenerateGraph, resolveGenerateSeed } from './generation/graph';
-import { normalizeGenerateWidgetValues } from './generation/settings';
+import {
+ cloneGenerateWidgetValues,
+ normalizeGenerateWidgetValues,
+ syncGenerateWidgetValuesWithModels,
+} from './generation/settings';
import {
defaultInvocationRoute,
isInvocationRouteValid,
@@ -82,8 +88,13 @@ type WorkbenchAction =
| { type: 'saveProjectGraphSnapshot' }
| { type: 'restoreProjectGraphSnapshot'; snapshotId: string }
| { type: 'setProjectGraphLibraryBinding'; libraryWorkflowId: string }
- | { type: 'submitInvocationSnapshot'; backendSupportsCancellation: boolean }
- | { type: 'submitResolvedInvocationSnapshot'; backendSupportsCancellation: boolean; route: InvocationRoute }
+ | { type: 'submitInvocationSnapshot'; backendSupportsCancellation: boolean; models?: readonly ModelConfig[] }
+ | {
+ type: 'submitResolvedInvocationSnapshot';
+ backendSupportsCancellation: boolean;
+ route: InvocationRoute;
+ models?: readonly ModelConfig[];
+ }
| {
type: 'markQueueItemBackendSubmitted';
projectId: string;
@@ -118,6 +129,7 @@ type WorkbenchAction =
| { type: 'setGalleryPage'; page: number }
| { type: 'setGalleryPageInfo'; totalImages: number }
| { type: 'touchGalleryRefresh' }
+ | { type: 'touchGalleryImagesRefresh' }
| { type: 'removeGalleryImages'; imageNames: string[] }
| { type: 'setGalleryProjectBoardId'; boardId: string }
| { type: 'acceptStagedImage' }
@@ -730,7 +742,8 @@ const updateActiveInvocation = (
const compileInvocationSnapshot = (
project: Project,
- route: InvocationRoute
+ route: InvocationRoute,
+ models?: readonly ModelConfig[]
): { graph: GraphContract; widgetStates: Record<WidgetId, WidgetStateContract> } | null => {
const widgetStates = cloneWidgetStates(project.widgetStates);
@@ -758,9 +771,18 @@ const compileInvocationSnapshot = (
return null;
}
+ const currentValues = models ? syncGenerateWidgetValuesWithModels(values, models) : values;
+ const availabilityReasons = models
+ ? getGenerationModelAvailabilityReasons(currentValues.model, currentValues, models)
+ : [];
+
+ if (availabilityReasons.length > 0) {
+ return null;
+ }
+
const resolvedSettings: GenerateWidgetValues = {
- ...values,
- seed: resolveGenerateSeed(values),
+ ...currentValues,
+ seed: resolveGenerateSeed(currentValues),
};
const compiledGraph = compileGenerateGraph(
resolvedSettings,
@@ -772,7 +794,7 @@ const compileInvocationSnapshot = (
widgetStates.generate = {
...widgetStates.generate,
graphId: compiledGraph.id,
- values: { ...resolvedSettings, model: { ...resolvedSettings.model } },
+ values: cloneGenerateWidgetValues(resolvedSettings),
};
return { graph: compiledGraph, widgetStates };
@@ -792,17 +814,33 @@ const updateProjectById = (
const updateGalleryValues = (
state: WorkbenchState,
getValues: (values: Record<string, unknown>) => Record<string, unknown>
-): WorkbenchState =>
- updateActiveProject(state, (project) => ({
- ...project,
- widgetStates: {
- ...project.widgetStates,
- gallery: {
- ...project.widgetStates.gallery,
- values: getValues(project.widgetStates.gallery.values),
+): WorkbenchState => {
+ const activeProject = state.projects.find((project) => project.id === state.activeProjectId);
+ const values = activeProject?.widgetStates.gallery.values;
+
+ if (!activeProject || !values) {
+ return state;
+ }
+
+ const nextValues = getValues(values);
+
+ if (nextValues === values) {
+ return state;
+ }
+
+ return updateActiveProject(state, (project) => {
+ return {
+ ...project,
+ widgetStates: {
+ ...project.widgetStates,
+ gallery: {
+ ...project.widgetStates.gallery,
+ values: nextValues,
+ },
},
- },
- }));
+ };
+ });
+};
const refreshProjectBackendData = (project: Project): Project => ({
...project,
@@ -812,6 +850,7 @@ const refreshProjectBackendData = (project: Project): Project => ({
...project.widgetStates.gallery,
values: {
...project.widgetStates.gallery.values,
+ galleryImagesRefreshToken: createId('gallery-images-refresh'),
galleryRefreshToken: createId('gallery-refresh'),
},
},
@@ -958,7 +997,8 @@ const routeQueueItemResults = (project: Project, queueItemId: string, images: Ge
const submitInvocationSnapshot = (
project: Project,
backendSupportsCancellation: boolean,
- route = resolveInvocationRoute(project)
+ route = resolveInvocationRoute(project),
+ models?: readonly ModelConfig[]
): Project => {
if (!isInvocationRouteValid(route)) {
return project;
@@ -966,7 +1006,7 @@ const submitInvocationSnapshot = (
const submittedAt = now();
const queueItemId = createId('queue-item');
- const compiledSnapshot = compileInvocationSnapshot(project, route);
+ const compiledSnapshot = compileInvocationSnapshot(project, route, models);
if (!compiledSnapshot) {
return project;
@@ -1234,7 +1274,7 @@ export const workbenchReducer = (state: WorkbenchState, action: WorkbenchAction)
...project.widgetStates,
generate: {
...project.widgetStates.generate,
- values: { ...action.values, model: { ...action.values.model } },
+ values: cloneGenerateWidgetValues(action.values),
},
},
}));
@@ -1377,7 +1417,7 @@ export const workbenchReducer = (state: WorkbenchState, action: WorkbenchAction)
case 'submitInvocationSnapshot': {
const beforeProject = state.projects.find((project) => project.id === state.activeProjectId);
const nextState = updateActiveProject(state, (project) =>
- submitInvocationSnapshot(project, action.backendSupportsCancellation)
+ submitInvocationSnapshot(project, action.backendSupportsCancellation, undefined, action.models)
);
const afterProject = nextState.projects.find((project) => project.id === nextState.activeProjectId);
@@ -1402,7 +1442,8 @@ export const workbenchReducer = (state: WorkbenchState, action: WorkbenchAction)
submitInvocationSnapshot(
project,
action.backendSupportsCancellation,
- resolveInvocationRoute(project, 'global', action.route)
+ resolveInvocationRoute(project, 'global', action.route, action.models),
+ action.models
)
);
}
@@ -1654,10 +1695,28 @@ export const workbenchReducer = (state: WorkbenchState, action: WorkbenchAction)
return updateGalleryValues(state, (values) => ({ ...values, galleryPage: Math.max(0, action.page) }));
}
case 'setGalleryPageInfo': {
- return updateGalleryValues(state, (values) => ({ ...values, galleryTotalImages: action.totalImages }));
+ if (!Number.isFinite(action.totalImages)) {
+ return state;
+ }
+
+ return updateGalleryValues(state, (values) => {
+ const totalImages = Math.max(0, action.totalImages);
+
+ return values.galleryTotalImages === totalImages ? values : { ...values, galleryTotalImages: totalImages };
+ });
}
case 'touchGalleryRefresh': {
- return updateGalleryValues(state, (values) => ({ ...values, galleryRefreshToken: createId('gallery-refresh') }));
+ return updateGalleryValues(state, (values) => ({
+ ...values,
+ galleryImagesRefreshToken: createId('gallery-images-refresh'),
+ galleryRefreshToken: createId('gallery-refresh'),
+ }));
+ }
+ case 'touchGalleryImagesRefresh': {
+ return updateGalleryValues(state, (values) => ({
+ ...values,
+ galleryImagesRefreshToken: createId('gallery-images-refresh'),
+ }));
}
case 'removeGalleryImages': {
const removedImageNames = new Set(action.imageNames);