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.

feat(ui): persist preset routing

joshistoast8e3734c1f6bb
diff --git a/invokeai/frontend/webv2/src/architecture/workbenchOwnershipManifest.json b/invokeai/frontend/webv2/src/architecture/workbenchOwnershipManifest.json
index ed6d1bca83..7a40270720 100644
--- a/invokeai/frontend/webv2/src/architecture/workbenchOwnershipManifest.json
+++ b/invokeai/frontend/webv2/src/architecture/workbenchOwnershipManifest.json
@@ -103,6 +103,7 @@
"invocationSubmit.ts": "workbench",
"layoutContracts.ts": "workbench",
"layoutPresetActivation.ts": "workbench",
+ "layoutPresetRouting.ts": "workbench",
"layoutPresetSnapshots.ts": "workbench",
"layoutPresets.ts": "workbench",
"panZoom.ts": "workbench",
diff --git a/invokeai/frontend/webv2/src/workbench/layoutContracts.ts b/invokeai/frontend/webv2/src/workbench/layoutContracts.ts
index 32b63d5e53..4553cfd9a3 100644
--- a/invokeai/frontend/webv2/src/workbench/layoutContracts.ts
+++ b/invokeai/frontend/webv2/src/workbench/layoutContracts.ts
@@ -1,3 +1,4 @@
+import type { InvocationSourceId, ResultDestination } from './invocationContracts';
import type { WidgetInstanceId, WidgetTypeId } from './widgetContracts';
/**
@@ -45,10 +46,21 @@ export interface LayoutPresetSnapshot {
widgetRegions: Record<WidgetRegion, WidgetRegionState>;
}
+/**
+ * The route a preset establishes when it is activated. Locks belong to the
+ * live project controller and are intentionally never persisted on a preset.
+ */
+export interface LayoutPresetRoute {
+ sourceId: InvocationSourceId;
+ destination: ResultDestination;
+}
+
export interface LayoutPreset {
id: LayoutPresetId;
label: string;
isBuiltIn?: boolean;
+ /** Missing only on legacy or source-less custom presets. */
+ defaultRoute?: LayoutPresetRoute;
/**
* Icon identifier, not a component: presets are persisted verbatim, so this
* has to survive a round trip through storage. Resolved against the picker's
@@ -64,3 +76,6 @@ export interface LayoutPreset {
* override is what the drift comparison and `Revert to saved layout` read.
*/
export type LayoutPresetOverrides = Record<string, LayoutPresetSnapshot>;
+
+/** Per-account edits to the default routes shipped with built-in presets. */
+export type LayoutPresetRouteOverrides = Record<string, LayoutPresetRoute>;
diff --git a/invokeai/frontend/webv2/src/workbench/layoutPresetRouting.test.ts b/invokeai/frontend/webv2/src/workbench/layoutPresetRouting.test.ts
new file mode 100644
index 0000000000..cf5afb9e33
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/layoutPresetRouting.test.ts
@@ -0,0 +1,32 @@
+import { describe, expect, it } from 'vitest';
+
+import { getLayoutPresetSourceOptions } from './layoutPresetRouting';
+import { layoutPresets } from './layoutPresets';
+
+describe('layout preset routing', () => {
+ it('offers only graph sources contained in the saved arrangement', () => {
+ const compose = layoutPresets[0];
+ const generateOnly = {
+ ...compose,
+ snapshot: {
+ ...compose.snapshot,
+ widgetRegions: {
+ ...compose.snapshot.widgetRegions,
+ bottom: {
+ ...compose.snapshot.widgetRegions.bottom,
+ instanceIds: compose.snapshot.widgetRegions.bottom.instanceIds.filter(
+ (instanceId) => instanceId !== 'workflow:bottom'
+ ),
+ },
+ center: { ...compose.snapshot.widgetRegions.center, activeInstanceId: 'preview', instanceIds: ['preview'] },
+ left: { ...compose.snapshot.widgetRegions.left, activeInstanceId: 'generate', instanceIds: ['generate'] },
+ right: { ...compose.snapshot.widgetRegions.right, activeInstanceId: 'gallery', instanceIds: ['gallery'] },
+ },
+ },
+ };
+
+ expect(getLayoutPresetSourceOptions(generateOnly)).toEqual([
+ { label: 'Generate', sourceId: 'generate', typeId: 'generate' },
+ ]);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/layoutPresetRouting.ts b/invokeai/frontend/webv2/src/workbench/layoutPresetRouting.ts
new file mode 100644
index 0000000000..3952148725
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/layoutPresetRouting.ts
@@ -0,0 +1,74 @@
+import type { InvocationRoute, InvocationSourceId } from './invocationContracts';
+import type { LayoutPreset, LayoutPresetRoute, WidgetRegion } from './layoutContracts';
+
+import { getNaturalDestination, getSourceIdForWidgetTypeId, graphWidgetSources } from './graphWidgets';
+import { isInvocationSourceAvailable } from './invocation';
+
+const activeSourceRegionPriority: WidgetRegion[] = ['center', 'left', 'right', 'bottom'];
+
+const getPresetSourceIds = (preset: LayoutPreset): Set<InvocationSourceId> => {
+ const sourceIds = new Set<InvocationSourceId>();
+
+ for (const region of Object.values(preset.snapshot.widgetRegions)) {
+ for (const instanceId of region.instanceIds) {
+ const typeId = preset.snapshot.widgetInstances[instanceId]?.typeId;
+ const sourceId = typeId ? getSourceIdForWidgetTypeId(typeId) : null;
+
+ if (sourceId && isInvocationSourceAvailable(sourceId)) {
+ sourceIds.add(sourceId);
+ }
+ }
+ }
+
+ return sourceIds;
+};
+
+/** Graph sources that the saved arrangement can actually mount, in routing-menu order. */
+export const getLayoutPresetSourceOptions = (preset: LayoutPreset) => {
+ const sourceIds = getPresetSourceIds(preset);
+
+ return graphWidgetSources.filter((source) => sourceIds.has(source.sourceId));
+};
+
+const getActivePresetSource = (preset: LayoutPreset): InvocationSourceId | null => {
+ for (const regionId of activeSourceRegionPriority) {
+ const region = preset.snapshot.widgetRegions[regionId];
+ const typeId = preset.snapshot.widgetInstances[region.activeInstanceId]?.typeId;
+ const sourceId = typeId ? getSourceIdForWidgetTypeId(typeId) : null;
+
+ if (sourceId && isInvocationSourceAvailable(sourceId)) {
+ return sourceId;
+ }
+ }
+
+ return null;
+};
+
+const resolvePresetRouteCandidate = (invocation: InvocationRoute, preset: LayoutPreset): LayoutPresetRoute => {
+ const sourceIds = getPresetSourceIds(preset);
+
+ if (preset.defaultRoute && sourceIds.has(preset.defaultRoute.sourceId)) {
+ return preset.defaultRoute;
+ }
+
+ if (sourceIds.has(invocation.sourceId)) {
+ return { destination: invocation.destination, sourceId: invocation.sourceId };
+ }
+
+ const activeSourceId = getActivePresetSource(preset);
+
+ return activeSourceId
+ ? { destination: getNaturalDestination(activeSourceId), sourceId: activeSourceId }
+ : { destination: invocation.destination, sourceId: invocation.sourceId };
+};
+
+/** Resolves a safe preset route, then applies each unlocked field independently. */
+export const getInvocationAfterLayoutPreset = (invocation: InvocationRoute, preset: LayoutPreset): InvocationRoute => {
+ const candidate = resolvePresetRouteCandidate(invocation, preset);
+
+ return {
+ ...invocation,
+ destination: invocation.destinationLocked ? invocation.destination : candidate.destination,
+ sourceId: invocation.sourceLocked ? invocation.sourceId : candidate.sourceId,
+ };
+};
diff --git a/invokeai/frontend/webv2/src/workbench/layoutPresetSnapshots.ts b/invokeai/frontend/webv2/src/workbench/layoutPresetSnapshots.ts
index fc5b696e9b..65e0f3361f 100644
--- a/invokeai/frontend/webv2/src/workbench/layoutPresetSnapshots.ts
+++ b/invokeai/frontend/webv2/src/workbench/layoutPresetSnapshots.ts
@@ -29,8 +29,11 @@ export const resolveSavedLayoutPreset = (account: AccountState, presetId: Layout
const builtInPreset = getLayoutPreset(presetId);
const override = account.layoutPresetOverrides?.[builtInPreset.id];
+ const defaultRoute = account.layoutPresetRouteOverrides?.[builtInPreset.id] ?? builtInPreset.defaultRoute;
- return override ? { ...builtInPreset, snapshot: override } : builtInPreset;
+ return override || defaultRoute !== builtInPreset.defaultRoute
+ ? { ...builtInPreset, defaultRoute, snapshot: override ?? builtInPreset.snapshot }
+ : builtInPreset;
};
export const cloneLayoutPresetWidgetRegions = (
diff --git a/invokeai/frontend/webv2/src/workbench/layoutPresets.test.ts b/invokeai/frontend/webv2/src/workbench/layoutPresets.test.ts
index 4f32b3271b..dce1b47818 100644
--- a/invokeai/frontend/webv2/src/workbench/layoutPresets.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/layoutPresets.test.ts
@@ -7,6 +7,7 @@ describe('built-in layout preset descriptors', () => {
expect(
builtInLayoutPresetDescriptors.map(({ defaultKeys, hotkeyId, iconId, preset, tooltip }) => ({
defaultKeys,
+ defaultRoute: preset.defaultRoute,
hotkeyId,
iconId,
label: preset.label,
@@ -16,6 +17,7 @@ describe('built-in layout preset descriptors', () => {
).toEqual([
{
defaultKeys: ['alt+1'],
+ defaultRoute: { destination: 'gallery', sourceId: 'generate' },
hotkeyId: 'selectComposePreset',
iconId: 'type',
label: 'Compose',
@@ -24,6 +26,7 @@ describe('built-in layout preset descriptors', () => {
},
{
defaultKeys: ['alt+2'],
+ defaultRoute: { destination: 'canvas', sourceId: 'canvas' },
hotkeyId: 'selectEditPreset',
iconId: 'layers',
label: 'Edit',
@@ -32,6 +35,7 @@ describe('built-in layout preset descriptors', () => {
},
{
defaultKeys: ['alt+3'],
+ defaultRoute: { destination: 'gallery', sourceId: 'workflow' },
hotkeyId: 'selectAutomatePreset',
iconId: 'workflow',
label: 'Automate',
diff --git a/invokeai/frontend/webv2/src/workbench/layoutPresets.ts b/invokeai/frontend/webv2/src/workbench/layoutPresets.ts
index 83cbc33354..2fe17d94cb 100644
--- a/invokeai/frontend/webv2/src/workbench/layoutPresets.ts
+++ b/invokeai/frontend/webv2/src/workbench/layoutPresets.ts
@@ -2,6 +2,7 @@ import type {
BuiltInLayoutPresetId,
CenterViewId,
LayoutPreset,
+ LayoutPresetRoute,
LayoutPresetSnapshot,
LayoutPresetWidgetInstanceSnapshot,
PanelState,
@@ -101,6 +102,7 @@ export interface BuiltInLayoutPresetDescriptor {
const createPresetDescriptor = ({
centerViewId,
defaultKeys,
+ defaultRoute,
hotkeyId,
id,
iconId,
@@ -111,6 +113,7 @@ const createPresetDescriptor = ({
}: {
centerViewId: CenterViewId;
defaultKeys: readonly string[];
+ defaultRoute: LayoutPresetRoute;
hotkeyId: string;
id: BuiltInLayoutPresetId;
iconId: string;
@@ -123,6 +126,7 @@ const createPresetDescriptor = ({
hotkeyId,
iconId,
preset: {
+ defaultRoute,
id,
isBuiltIn: true,
label,
@@ -141,6 +145,7 @@ export const builtInLayoutPresetDescriptors: BuiltInLayoutPresetDescriptor[] = [
createPresetDescriptor({
centerViewId: 'preview',
defaultKeys: ['alt+1'],
+ defaultRoute: { destination: 'gallery', sourceId: 'generate' },
hotkeyId: 'selectComposePreset',
id: 'compose',
iconId: 'type',
@@ -174,6 +179,7 @@ export const builtInLayoutPresetDescriptors: BuiltInLayoutPresetDescriptor[] = [
createPresetDescriptor({
centerViewId: 'canvas',
defaultKeys: ['alt+2'],
+ defaultRoute: { destination: 'canvas', sourceId: 'canvas' },
hotkeyId: 'selectEditPreset',
id: 'edit',
iconId: 'layers',
@@ -207,6 +213,7 @@ export const builtInLayoutPresetDescriptors: BuiltInLayoutPresetDescriptor[] = [
createPresetDescriptor({
centerViewId: 'workflow',
defaultKeys: ['alt+3'],
+ defaultRoute: { destination: 'gallery', sourceId: 'workflow' },
hotkeyId: 'selectAutomatePreset',
id: 'automate',
iconId: 'workflow',
diff --git a/invokeai/frontend/webv2/src/workbench/projectContracts.ts b/invokeai/frontend/webv2/src/workbench/projectContracts.ts
index 68cca86418..2261bf5e1c 100644
--- a/invokeai/frontend/webv2/src/workbench/projectContracts.ts
+++ b/invokeai/frontend/webv2/src/workbench/projectContracts.ts
@@ -8,6 +8,7 @@ import type {
LayoutPreset,
LayoutPresetId,
LayoutPresetOverrides,
+ LayoutPresetRouteOverrides,
ProjectLayoutState,
WidgetRegion,
WidgetRegionState,
@@ -131,4 +132,6 @@ export interface AccountState {
customLayoutPresets?: LayoutPreset[];
/** Saved edits to a built-in preset's arrangement; see {@link LayoutPresetOverrides}. */
layoutPresetOverrides?: LayoutPresetOverrides;
+ /** Saved edits to built-in preset routes, kept separate from spatial layout drift. */
+ layoutPresetRouteOverrides?: LayoutPresetRouteOverrides;
}
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
index 4f5c1041ec..9dd9a02008 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
@@ -339,8 +339,17 @@ const getCanvas = (state: WorkbenchState) => getActiveProject(state).canvas;
const getLayerIds = (state: WorkbenchState): string[] => getCanvas(state).document.layers.map((layer) => layer.id);
-const primeGenerate = (state = createInitialWorkbenchState(), overrides: Partial<GenerateWidgetValues> = {}) =>
- workbenchReducer(state, { type: 'setGenerateSettings', values: createGenerateValues(overrides) });
+const withInvocationDestination = (state: WorkbenchState, destination: 'canvas' | 'gallery'): WorkbenchState => ({
+ ...state,
+ projects: state.projects.map((project) =>
+ project.id === state.activeProjectId ? { ...project, invocation: { ...project.invocation, destination } } : project
+ ),
+});
+
+const primeGenerate = (
+ state = withInvocationDestination(createInitialWorkbenchState(), 'canvas'),
+ overrides: Partial<GenerateWidgetValues> = {}
+) => workbenchReducer(state, { type: 'setGenerateSettings', values: createGenerateValues(overrides) });
const submitGenerate = (state: WorkbenchState) =>
workbenchReducer(state, { backendSupportsCancellation: true, type: 'submitInvocationSnapshot' });
@@ -600,6 +609,157 @@ describe('workbench widget state updates', () => {
});
describe('workbench layout presets', () => {
+ it('starts initial and newly created projects on the Compose default route', () => {
+ const initial = createInitialWorkbenchState();
+ const withNewProject = workbenchReducer(initial, { type: 'createProject' });
+
+ expect(getProject(initial, initial.activeProjectId).invocation).toEqual({
+ destination: 'gallery',
+ destinationLocked: false,
+ sourceId: 'generate',
+ sourceLocked: false,
+ });
+ expect(getProject(withNewProject, withNewProject.activeProjectId).invocation).toEqual({
+ destination: 'gallery',
+ destinationLocked: false,
+ sourceId: 'generate',
+ sourceLocked: false,
+ });
+ });
+
+ it('applies each built-in preset default route with its layout', () => {
+ let state = createInitialWorkbenchState();
+
+ state = workbenchReducer(state, { presetId: 'compose', type: 'applyPreset' });
+ expect(getActiveProject(state).invocation).toMatchObject({ destination: 'gallery', sourceId: 'generate' });
+
+ state = workbenchReducer(state, { presetId: 'edit', type: 'applyPreset' });
+ expect(getActiveProject(state).invocation).toMatchObject({ destination: 'canvas', sourceId: 'canvas' });
+
+ state = workbenchReducer(state, { presetId: 'automate', type: 'applyPreset' });
+ expect(getActiveProject(state).invocation).toMatchObject({ destination: 'gallery', sourceId: 'workflow' });
+ });
+
+ it('applies an account override for a built-in preset route', () => {
+ let state = createInitialWorkbenchState();
+
+ state = workbenchReducer(state, {
+ defaultRoute: { destination: 'canvas', sourceId: 'workflow' },
+ presetId: 'compose',
+ type: 'setLayoutPresetRoute',
+ });
+ state = workbenchReducer(state, { presetId: 'compose', type: 'applyPreset' });
+
+ expect(getActiveProject(state).invocation).toMatchObject({ destination: 'canvas', sourceId: 'workflow' });
+ });
+
+ it('applies preset routing with the edit preference off in the same undo entry as the layout', () => {
+ const initial = createInitialWorkbenchState();
+ const previousInvocation = getActiveProject(initial).invocation;
+ const state = reduceWorkbench(
+ initial,
+ { presetId: 'edit', type: 'applyPreset' },
+ { autoSwitchInvocationRoute: false }
+ );
+ const project = getActiveProject(state);
+
+ expect(project.invocation).toMatchObject({ destination: 'canvas', sourceId: 'canvas' });
+ expect(project.undoRedo.past).toHaveLength(1);
+ expect(project.undoRedo.past[0]?.project.invocation).toEqual(previousInvocation);
+ });
+
+ it('preserves each locked route field while applying the other preset default', () => {
+ let sourceLocked = createInitialWorkbenchState();
+ sourceLocked = workbenchReducer(sourceLocked, { sourceId: 'upscale', type: 'setInvocationSource' });
+ sourceLocked = workbenchReducer(sourceLocked, { type: 'toggleSourceLock' });
+ sourceLocked = workbenchReducer(sourceLocked, { presetId: 'automate', type: 'applyPreset' });
+
+ expect(getActiveProject(sourceLocked).invocation).toMatchObject({
+ destination: 'gallery',
+ sourceId: 'upscale',
+ sourceLocked: true,
+ });
+
+ let destinationLocked = createInitialWorkbenchState();
+ destinationLocked = workbenchReducer(destinationLocked, {
+ destination: 'canvas',
+ type: 'setInvocationDestination',
+ });
+ destinationLocked = workbenchReducer(destinationLocked, { type: 'toggleDestinationLock' });
+ destinationLocked = workbenchReducer(destinationLocked, { presetId: 'automate', type: 'applyPreset' });
+
+ expect(getActiveProject(destinationLocked).invocation).toMatchObject({
+ destination: 'canvas',
+ destinationLocked: true,
+ sourceId: 'workflow',
+ });
+ });
+
+ it('falls back safely when a custom preset no longer contains its default source', () => {
+ let seeded = createInitialWorkbenchState();
+ seeded = workbenchReducer(seeded, {
+ label: 'Generate only',
+ presetId: 'custom-generate-only',
+ type: 'addLayoutPreset',
+ });
+ const preset = seeded.account.customLayoutPresets?.[0];
+ expect(preset).toBeDefined();
+ if (!preset) {
+ return;
+ }
+
+ const generateOnlyPreset = {
+ ...preset,
+ defaultRoute: { destination: 'gallery' as const, sourceId: 'workflow' as const },
+ snapshot: {
+ ...preset.snapshot,
+ widgetRegions: {
+ ...preset.snapshot.widgetRegions,
+ center: { ...preset.snapshot.widgetRegions.center, activeInstanceId: 'preview', instanceIds: ['preview'] },
+ left: { ...preset.snapshot.widgetRegions.left, activeInstanceId: 'generate', instanceIds: ['generate'] },
+ right: { ...preset.snapshot.widgetRegions.right, activeInstanceId: 'gallery', instanceIds: ['gallery'] },
+ bottom: {
+ ...preset.snapshot.widgetRegions.bottom,
+ instanceIds: preset.snapshot.widgetRegions.bottom.instanceIds.filter(
+ (instanceId) => instanceId !== 'workflow:bottom'
+ ),
+ },
+ },
+ },
+ };
+ seeded = {
+ ...seeded,
+ account: { ...seeded.account, customLayoutPresets: [generateOnlyPreset] },
+ };
+
+ let liveRouteStillPresent = workbenchReducer(seeded, {
+ destination: 'canvas',
+ type: 'setInvocationDestination',
+ });
+ liveRouteStillPresent = workbenchReducer(liveRouteStillPresent, {
+ presetId: generateOnlyPreset.id,
+ type: 'applyPreset',
+ });
+ expect(getActiveProject(liveRouteStillPresent).invocation).toMatchObject({
+ destination: 'canvas',
+ sourceId: 'generate',
+ });
+
+ let liveRouteMissing = workbenchReducer(seeded, { sourceId: 'canvas', type: 'setInvocationSource' });
+ liveRouteMissing = workbenchReducer(liveRouteMissing, {
+ destination: 'canvas',
+ type: 'setInvocationDestination',
+ });
+ liveRouteMissing = workbenchReducer(liveRouteMissing, {
+ presetId: generateOnlyPreset.id,
+ type: 'applyPreset',
+ });
+ expect(getActiveProject(liveRouteMissing).invocation).toMatchObject({
+ destination: 'gallery',
+ sourceId: 'generate',
+ });
+ });
+
it('applies the Compose preset as a full widget-region layout', () => {
let state = createInitialWorkbenchState();
@@ -666,6 +826,101 @@ describe('workbench layout presets', () => {
expect(project.widgetRegions.center.activeInstanceId).toBe('preview');
});
+ it('captures the live source and destination without routing locks when creating a custom preset', () => {
+ let state = createInitialWorkbenchState();
+
+ state = workbenchReducer(state, { sourceId: 'upscale', type: 'setInvocationSource' });
+ state = workbenchReducer(state, { destination: 'canvas', type: 'setInvocationDestination' });
+ state = workbenchReducer(state, { type: 'toggleRoutingLock' });
+ state = workbenchReducer(state, {
+ label: 'Upscale review',
+ presetId: 'custom-layout-route',
+ type: 'addLayoutPreset',
+ });
+
+ expect(state.account.customLayoutPresets?.[0]?.defaultRoute).toEqual({
+ destination: 'canvas',
+ sourceId: 'upscale',
+ });
+ expect(state.account.customLayoutPresets?.[0]?.defaultRoute).not.toHaveProperty('sourceLocked');
+ expect(state.account.customLayoutPresets?.[0]?.defaultRoute).not.toHaveProperty('destinationLocked');
+ });
+
+ it('edits built-in and custom default routes without changing saved layouts', () => {
+ let state = createInitialWorkbenchState();
+
+ state = workbenchReducer(state, {
+ defaultRoute: { destination: 'gallery', sourceId: 'upscale' },
+ presetId: 'compose',
+ type: 'setLayoutPresetRoute',
+ });
+ state = workbenchReducer(state, {
+ label: 'Custom route',
+ presetId: 'custom-layout-route',
+ type: 'addLayoutPreset',
+ });
+ const customSnapshot = state.account.customLayoutPresets?.[0]?.snapshot;
+ state = workbenchReducer(state, {
+ defaultRoute: { destination: 'canvas', sourceId: 'workflow' },
+ presetId: 'custom-layout-route',
+ type: 'setLayoutPresetRoute',
+ });
+
+ expect(state.account.layoutPresetRouteOverrides).toEqual({
+ compose: { destination: 'gallery', sourceId: 'upscale' },
+ });
+ expect(state.account.layoutPresetOverrides).toBeUndefined();
+ expect(state.account.customLayoutPresets?.[0]?.defaultRoute).toEqual({
+ destination: 'canvas',
+ sourceId: 'workflow',
+ });
+ expect(state.account.customLayoutPresets?.[0]?.snapshot).toBe(customSnapshot);
+ });
+
+ it('allows a source-less custom preset to omit its route while built-ins fall back to shipped routing', () => {
+ let state = createInitialWorkbenchState();
+ state = workbenchReducer(state, {
+ label: 'No invoke surface',
+ presetId: 'custom-no-route',
+ type: 'addLayoutPreset',
+ });
+ state = workbenchReducer(state, {
+ defaultRoute: { destination: 'canvas', sourceId: 'upscale' },
+ presetId: 'compose',
+ type: 'setLayoutPresetRoute',
+ });
+ state = workbenchReducer(state, {
+ defaultRoute: null,
+ presetId: 'custom-no-route',
+ type: 'setLayoutPresetRoute',
+ });
+ state = workbenchReducer(state, {
+ defaultRoute: null,
+ presetId: 'compose',
+ type: 'setLayoutPresetRoute',
+ });
+
+ expect(state.account.customLayoutPresets?.[0]).not.toHaveProperty('defaultRoute');
+ expect(state.account.layoutPresetRouteOverrides?.compose).toBeUndefined();
+ });
+
+ it('does not retain a built-in override that matches its shipped route', () => {
+ let state = createInitialWorkbenchState();
+
+ state = workbenchReducer(state, {
+ defaultRoute: { destination: 'canvas', sourceId: 'upscale' },
+ presetId: 'compose',
+ type: 'setLayoutPresetRoute',
+ });
+ state = workbenchReducer(state, {
+ defaultRoute: { destination: 'gallery', sourceId: 'generate' },
+ presetId: 'compose',
+ type: 'setLayoutPresetRoute',
+ });
+
+ expect(state.account.layoutPresetRouteOverrides?.compose).toBeUndefined();
+ });
+
it('renames and deletes only custom layout presets', () => {
let state = createInitialWorkbenchState();
@@ -737,20 +992,32 @@ describe('workbench layout presets', () => {
state = workbenchReducer(state, { region: 'right', sizePx: 320, type: 'setRegionWidgetSize' });
state = workbenchReducer(state, { presetId: 'compose', type: 'saveLayoutPreset' });
+ state = workbenchReducer(state, {
+ defaultRoute: { destination: 'canvas', sourceId: 'upscale' },
+ presetId: 'compose',
+ type: 'setLayoutPresetRoute',
+ });
expect(state.account.layoutPresetOverrides?.compose?.widgetRegions.right.sizePx).toBe(320);
+ expect(state.account.layoutPresetRouteOverrides?.compose).toEqual({ destination: 'canvas', sourceId: 'upscale' });
+
+ state = workbenchReducer(state, { sourceId: 'workflow', type: 'setInvocationSource' });
+ state = workbenchReducer(state, { destination: 'gallery', type: 'setInvocationDestination' });
// Reverting now lands on the saved edit, not on the shipped arrangement.
state = workbenchReducer(state, { region: 'right', sizePx: 500, type: 'setRegionWidgetSize' });
state = workbenchReducer(state, { type: 'resetActiveLayout' });
expect(getActiveProject(state).widgetRegions.right.sizePx).toBe(320);
+ expect(getActiveProject(state).invocation).toMatchObject({ destination: 'gallery', sourceId: 'workflow' });
state = workbenchReducer(state, { presetId: 'compose', type: 'restoreLayoutPresetDefault' });
state = workbenchReducer(state, { type: 'resetActiveLayout' });
expect(state.account.layoutPresetOverrides?.compose).toBeUndefined();
+ expect(state.account.layoutPresetRouteOverrides?.compose).toBeUndefined();
expect(getActiveProject(state).widgetRegions.right.sizePx).toBe(450);
+ expect(getActiveProject(state).invocation).toMatchObject({ destination: 'gallery', sourceId: 'workflow' });
});
it('resolves retired built-in preset ids onto the three shipped presets', () => {
@@ -942,7 +1209,9 @@ describe('workbenchReducer Phase 5 generation flow', () => {
});
it('accepts a staged candidate into a selected raster layer that project undo no longer touches', () => {
- let state = submitGenerate(primeGenerate(withEmptyCanvas(createInitialWorkbenchState())));
+ let state = submitGenerate(
+ primeGenerate(withInvocationDestination(withEmptyCanvas(createInitialWorkbenchState()), 'canvas'))
+ );
const queueItem = getActiveProject(state).queue.items[0];
state = workbenchReducer(state, {
@@ -978,7 +1247,9 @@ describe('workbenchReducer Phase 5 generation flow', () => {
});
it('discards selected and all staged canvas candidates without touching accepted document layers', () => {
- let state = submitGenerate(primeGenerate(withEmptyCanvas(createInitialWorkbenchState())));
+ let state = submitGenerate(
+ primeGenerate(withInvocationDestination(withEmptyCanvas(createInitialWorkbenchState()), 'canvas'))
+ );
const queueItem = getActiveProject(state).queue.items[0];
state = workbenchReducer(state, {
@@ -2462,6 +2733,7 @@ describe('workbench account and project settings', () => {
activeLayoutPresetId: 'compose',
customLayoutPresets: [],
layoutPresetOverrides: {},
+ layoutPresetRouteOverrides: {},
});
});
@@ -2474,6 +2746,56 @@ describe('workbench account and project settings', () => {
expect(state.account.activeLayoutPresetId).toBe('compose');
});
+ it('normalizes persisted preset routes and tolerates legacy custom presets without one', () => {
+ let seeded = createInitialWorkbenchState();
+ seeded = workbenchReducer(seeded, {
+ label: 'Route fixture',
+ presetId: 'custom-route-fixture',
+ type: 'addLayoutPreset',
+ });
+ const fixture = seeded.account.customLayoutPresets?.[0];
+ expect(fixture).toBeDefined();
+ if (!fixture) {
+ return;
+ }
+
+ const { defaultRoute: _removedRoute, ...legacyFixture } = fixture;
+ const hydrated = {
+ ...seeded,
+ account: {
+ activeLayoutPresetId: 'compose',
+ customLayoutPresets: [
+ legacyFixture,
+ {
+ ...fixture,
+ defaultRoute: { destination: 'gallery', sourceId: 'workflow' },
+ id: 'custom-valid-route',
+ },
+ {
+ ...fixture,
+ defaultRoute: { destination: 'nowhere', sourceId: 'unknown' },
+ id: 'custom-invalid-route',
+ },
+ ],
+ layoutPresetRouteOverrides: {
+ broken: { destination: 'nowhere', sourceId: 'unknown' },
+ canvas: { destination: 'gallery', sourceId: 'upscale' },
+ },
+ },
+ } as unknown as WorkbenchState;
+
+ const state = workbenchReducer(seeded, { state: hydrated, type: 'hydrateWorkbench' });
+
+ expect(state.account.customLayoutPresets?.map((preset) => [preset.id, preset.defaultRoute])).toEqual([
+ ['custom-route-fixture', undefined],
+ ['custom-valid-route', { destination: 'gallery', sourceId: 'workflow' }],
+ ['custom-invalid-route', undefined],
+ ]);
+ expect(state.account.layoutPresetRouteOverrides).toEqual({
+ edit: { destination: 'gallery', sourceId: 'upscale' },
+ });
+ });
+
it('updates project settings on the active project only', () => {
let state = createInitialWorkbenchState();
@@ -4215,6 +4537,7 @@ describe('auto invocation route switching', () => {
it('never lets generate edits steal the route from an active canvas source', () => {
let state = createInitialWorkbenchState();
+ state = workbenchReducer(state, { destination: 'canvas', type: 'setInvocationDestination' });
state = workbenchReducer(state, { sourceId: 'canvas', type: 'setInvocationSource' });
// Canvas compiles from generate values, so the generate panel is also the
// canvas parameter panel — editing it expresses canvas intent here.
@@ -4227,6 +4550,10 @@ describe('auto invocation route switching', () => {
it('respects the source and destination locks', () => {
let sourceLockedState = createInitialWorkbenchState();
+ sourceLockedState = workbenchReducer(sourceLockedState, {
+ destination: 'canvas',
+ type: 'setInvocationDestination',
+ });
sourceLockedState = workbenchReducer(sourceLockedState, { type: 'toggleSourceLock' });
sourceLockedState = workbenchReducer(sourceLockedState, {
layer: createRasterLayer('a'),
@@ -4237,6 +4564,10 @@ describe('auto invocation route switching', () => {
let destinationLockedState = createInitialWorkbenchState();
+ destinationLockedState = workbenchReducer(destinationLockedState, {
+ destination: 'canvas',
+ type: 'setInvocationDestination',
+ });
destinationLockedState = workbenchReducer(destinationLockedState, { type: 'toggleDestinationLock' });
destinationLockedState = workbenchReducer(destinationLockedState, {
type: 'patchWidgetValues',
@@ -4270,7 +4601,7 @@ describe('auto invocation route switching', () => {
state = workbenchReducer(state, { sourceId: 'workflow', type: 'setInvocationSource' });
// The dropdown is the strongest intent signal: destination stays put.
- expect(getRoute(state)).toMatchObject({ destination: 'canvas', sourceId: 'workflow' });
+ expect(getRoute(state)).toMatchObject({ destination: 'gallery', sourceId: 'workflow' });
state = workbenchReducer(state, { type: 'patchGenerateSettings', values: { steps: 25 } });
state = workbenchReducer(state, { destination: 'canvas', type: 'setInvocationDestination' });
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
index 536cc10f54..762572cb26 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
@@ -16,6 +16,7 @@ import type {
LayoutPreset,
LayoutPresetId,
LayoutPresetOverrides,
+ LayoutPresetRoute,
LayoutPresetSnapshot,
ProjectLayoutState,
WidgetRegion,
@@ -126,9 +127,11 @@ import {
defaultInvocationRoute,
isInvocationRouteValid,
isInvocationSourceAvailable,
+ isResultDestinationAvailable,
resolveInvocationRoute,
} from './invocation';
-import { defaultLayoutPreset, isBuiltInLayoutPresetId, resolveLayoutPresetId } from './layoutPresets';
+import { getInvocationAfterLayoutPreset } from './layoutPresetRouting';
+import { defaultLayoutPreset, getLayoutPreset, isBuiltInLayoutPresetId, resolveLayoutPresetId } from './layoutPresets';
import {
cloneLayoutPresetWidgetRegions,
createLayoutPresetSnapshot,
@@ -151,8 +154,15 @@ type WorkbenchReducerAction =
| { type: 'switchProject'; projectId: string }
| { type: 'setCenterView'; centerViewId: CenterViewId }
| { type: 'applyPreset'; presetId: LayoutPresetId }
- | { type: 'addLayoutPreset'; presetId: LayoutPresetId; label: string; iconId?: string }
+ | {
+ type: 'addLayoutPreset';
+ presetId: LayoutPresetId;
+ label: string;
+ iconId?: string;
+ defaultRoute?: LayoutPresetRoute | null;
+ }
| { type: 'setLayoutPresetIcon'; presetId: LayoutPresetId; iconId: string }
+ | { type: 'setLayoutPresetRoute'; presetId: LayoutPresetId; defaultRoute: LayoutPresetRoute | null }
| { type: 'saveLayoutPreset'; presetId: LayoutPresetId }
| { type: 'restoreLayoutPresetDefault'; presetId: LayoutPresetId }
| { type: 'renameLayoutPreset'; presetId: LayoutPresetId; label: string }
@@ -1403,7 +1413,7 @@ const createProject = (index: number, id = `project-${index}`): Project => ({
],
graphHistory: [],
id,
- invocation: { ...defaultInvocationRoute },
+ invocation: { ...defaultInvocationRoute, ...defaultLayoutPreset.defaultRoute },
layout: { ...defaultLayoutPreset.snapshot.layout, panels: { ...defaultLayoutPreset.snapshot.layout.panels } },
name: `Project Name #${index}`,
promptHistory: [],
@@ -1551,6 +1561,25 @@ const isLayoutPresetSnapshot = (value: unknown): value is LayoutPresetSnapshot =
);
};
+const normalizeLayoutPresetRoute = (value: unknown): LayoutPresetRoute | undefined => {
+ if (!value || typeof value !== 'object') {
+ return undefined;
+ }
+
+ const route = value as Partial<LayoutPresetRoute>;
+
+ if (
+ typeof route.sourceId !== 'string' ||
+ !isInvocationSourceAvailable(route.sourceId as InvocationSourceId) ||
+ typeof route.destination !== 'string' ||
+ !isResultDestinationAvailable(route.destination as ResultDestination)
+ ) {
+ return undefined;
+ }
+
+ return { destination: route.destination as ResultDestination, sourceId: route.sourceId as InvocationSourceId };
+};
+
const normalizeCustomLayoutPresets = (presets: unknown): LayoutPreset[] => {
if (!Array.isArray(presets)) {
return [];
@@ -1567,8 +1596,11 @@ const normalizeCustomLayoutPresets = (presets: unknown): LayoutPreset[] => {
return [];
}
+ const defaultRoute = normalizeLayoutPresetRoute(record.defaultRoute);
+
return [
{
+ ...(defaultRoute ? { defaultRoute } : {}),
...(typeof record.iconId === 'string' ? { iconId: record.iconId } : {}),
id: record.id,
label: record.label,
@@ -1578,6 +1610,20 @@ const normalizeCustomLayoutPresets = (presets: unknown): LayoutPreset[] => {
});
};
+const normalizeLayoutPresetRouteOverrides = (overrides: unknown) => {
+ if (!overrides || typeof overrides !== 'object') {
+ return {};
+ }
+
+ return Object.fromEntries(
+ Object.entries(overrides as Record<string, unknown>).flatMap(([presetId, route]) => {
+ const normalizedRoute = normalizeLayoutPresetRoute(route);
+
+ return normalizedRoute ? [[resolveLayoutPresetId(presetId), normalizedRoute]] : [];
+ })
+ );
+};
+
const normalizeLayoutPresetOverrides = (overrides: unknown): LayoutPresetOverrides => {
if (!overrides || typeof overrides !== 'object') {
return {};
@@ -1594,6 +1640,7 @@ const normalizeAccount = (account: Partial<WorkbenchState['account']> | undefine
activeLayoutPresetId: resolveLayoutPresetId(account?.activeLayoutPresetId ?? defaultLayoutPreset.id),
customLayoutPresets: normalizeCustomLayoutPresets(account?.customLayoutPresets),
layoutPresetOverrides: normalizeLayoutPresetOverrides(account?.layoutPresetOverrides),
+ layoutPresetRouteOverrides: normalizeLayoutPresetRouteOverrides(account?.layoutPresetRouteOverrides),
});
const normalizeWorkbenchState = (state: WorkbenchState): WorkbenchState => ({
@@ -1653,12 +1700,17 @@ const applyLayoutPresetToProject = (project: Project, preset: LayoutPreset): Pro
};
};
-const updateActiveProjectLayoutPreset = (state: WorkbenchState, preset: LayoutPreset): WorkbenchState =>
+const updateActiveProjectLayoutPreset = (
+ state: WorkbenchState,
+ preset: LayoutPreset,
+ { applyDefaultRoute }: { applyDefaultRoute: boolean }
+): WorkbenchState =>
updateActiveProject(state, (project) => {
const nextProject = pushUndo(project, 'Update layout');
+ const nextLayoutProject = applyLayoutPresetToProject(nextProject, preset);
return {
- ...applyLayoutPresetToProject(nextProject, preset),
+ ...nextLayoutProject,
events: [
{
createdAt: now(),
@@ -1668,6 +1720,9 @@ const updateActiveProjectLayoutPreset = (state: WorkbenchState, preset: LayoutPr
},
...nextProject.events,
],
+ invocation: applyDefaultRoute
+ ? getInvocationAfterLayoutPreset(nextProject.invocation, preset)
+ : nextLayoutProject.invocation,
};
});
@@ -2540,7 +2595,7 @@ export const __workbenchReducerInternal = (
}
case 'applyPreset': {
const preset = getAvailableLayoutPreset(state, action.presetId);
- const nextState = updateActiveProjectLayoutPreset(state, preset);
+ const nextState = updateActiveProjectLayoutPreset(state, preset, { applyDefaultRoute: true });
return {
...nextState,
@@ -2555,6 +2610,16 @@ export const __workbenchReducerInternal = (
}
const preset: LayoutPreset = {
+ ...(action.defaultRoute === null
+ ? {}
+ : {
+ defaultRoute: action.defaultRoute
+ ? { ...action.defaultRoute }
+ : {
+ destination: activeProject.invocation.destination,
+ sourceId: activeProject.invocation.sourceId,
+ },
+ }),
iconId: action.iconId,
id: action.presetId,
label: action.label.trim() || 'Custom layout',
@@ -2600,8 +2665,12 @@ export const __workbenchReducerInternal = (
}
case 'restoreLayoutPresetDefault': {
const { [action.presetId]: removed, ...layoutPresetOverrides } = state.account.layoutPresetOverrides ?? {};
+ const { [action.presetId]: removedRoute, ...layoutPresetRouteOverrides } =
+ state.account.layoutPresetRouteOverrides ?? {};
- return removed ? { ...state, account: { ...state.account, layoutPresetOverrides } } : state;
+ return removed || removedRoute
+ ? { ...state, account: { ...state.account, layoutPresetOverrides, layoutPresetRouteOverrides } }
+ : state;
}
case 'setLayoutPresetIcon': {
return {
@@ -2614,6 +2683,53 @@ export const __workbenchReducerInternal = (
},
};
}
+ case 'setLayoutPresetRoute': {
+ if (isBuiltInLayoutPresetId(action.presetId)) {
+ const shippedRoute = getLayoutPreset(action.presetId).defaultRoute;
+ const matchesShippedRoute =
+ action.defaultRoute !== null &&
+ shippedRoute !== undefined &&
+ action.defaultRoute.destination === shippedRoute.destination &&
+ action.defaultRoute.sourceId === shippedRoute.sourceId;
+
+ if (action.defaultRoute === null || matchesShippedRoute) {
+ const { [action.presetId]: _removed, ...layoutPresetRouteOverrides } =
+ state.account.layoutPresetRouteOverrides ?? {};
+
+ return { ...state, account: { ...state.account, layoutPresetRouteOverrides } };
+ }
+
+ return {
+ ...state,
+ account: {
+ ...state.account,
+ layoutPresetRouteOverrides: {
+ ...state.account.layoutPresetRouteOverrides,
+ [action.presetId]: { ...action.defaultRoute },
+ },
+ },
+ };
+ }
+
+ return {
+ ...state,
+ account: {
+ ...state.account,
+ customLayoutPresets: (state.account.customLayoutPresets ?? []).map((preset) => {
+ if (preset.id !== action.presetId) {
+ return preset;
+ }
+ if (action.defaultRoute) {
+ return { ...preset, defaultRoute: { ...action.defaultRoute } };
+ }
+
+ const { defaultRoute: _removed, ...withoutRoute } = preset;
+
+ return withoutRoute;
+ }),
+ },
+ };
+ }
case 'renameLayoutPreset': {
const label = action.label.trim();
@@ -2661,7 +2777,7 @@ export const __workbenchReducerInternal = (
state.account.activeLayoutPresetId
);
- return updateActiveProjectLayoutPreset(state, preset);
+ return updateActiveProjectLayoutPreset(state, preset, { applyDefaultRoute: false });
}
case 'recoverShellLayout': {
return updateActiveLayout(state, (layout) => ({
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchStateAutoRoute.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchStateAutoRoute.test.ts
index c435ae891b..127b799335 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchStateAutoRoute.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchStateAutoRoute.test.ts
@@ -98,6 +98,6 @@ describe('auto invocation route switching with the preference off', () => {
const project = state.projects.find((candidate) => candidate.id === state.activeProjectId);
expect(project?.projectGraph.nodes).toHaveLength(1);
- expect(project?.invocation).toMatchObject({ destination: 'canvas', sourceId: 'generate' });
+ expect(project?.invocation).toMatchObject({ destination: 'gallery', sourceId: 'generate' });
});
});
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchStore.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchStore.test.ts
index 64e481b5dd..c625f6b3a5 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchStore.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchStore.test.ts
@@ -1,5 +1,6 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
+import type { LayoutPresetRoute } from './layoutContracts';
import type { WorkbenchInternalStore, WorkbenchSnapshot } from './workbenchStore';
import { clearProjectDiagnostics, configureDiagnostics, getProjectDiagnostics } from './diagnostics/logger';
@@ -129,6 +130,30 @@ describe('createWorkbenchStore', () => {
expect(getProjectWidgetValues(store.getSnapshot().activeProject, 'gallery').searchTerm).toBe('positional form');
});
+ it('edits a preset default route through the layout capability', () => {
+ const store = createWorkbenchStore();
+
+ store.commands.layout.setPresetRoute('compose', { destination: 'canvas', sourceId: 'upscale' });
+
+ expect(store.getSnapshot().account.layoutPresetRouteOverrides?.compose).toEqual({
+ destination: 'canvas',
+ sourceId: 'upscale',
+ });
+ });
+
+ it('creates a custom preset with an explicitly selected default route in one command', () => {
+ const store = createWorkbenchStore();
+ const defaultRoute: LayoutPresetRoute = { destination: 'gallery', sourceId: 'workflow' };
+
+ store.commands.layout.createPreset('custom-explicit-route', 'Workflow layout', 'workflow', defaultRoute);
+ defaultRoute.destination = 'canvas';
+
+ expect(store.getSnapshot().account.customLayoutPresets?.[0]?.defaultRoute).toEqual({
+ destination: 'gallery',
+ sourceId: 'workflow',
+ });
+ });
+
it('dispatches nullary commands with no payload', () => {
const store = createWorkbenchStore();
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchStore.ts b/invokeai/frontend/webv2/src/workbench/workbenchStore.ts
index a470efe459..c80c2c3276 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchStore.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchStore.ts
@@ -243,7 +243,13 @@ const createCommands = (dispatch: WorkbenchDispatch, getState: () => WorkbenchSt
applyPreset: command('applyPreset', (presetId: ActionPayload<'applyPreset'>['presetId']) => ({ presetId })),
createPreset: command(
'addLayoutPreset',
- (presetId: ActionPayload<'addLayoutPreset'>['presetId'], label: string, iconId?: string) => ({
+ (
+ presetId: ActionPayload<'addLayoutPreset'>['presetId'],
+ label: string,
+ iconId?: string,
+ defaultRoute?: ActionPayload<'addLayoutPreset'>['defaultRoute']
+ ) => ({
+ defaultRoute,
iconId,
label,
presetId,
@@ -253,6 +259,13 @@ const createCommands = (dispatch: WorkbenchDispatch, getState: () => WorkbenchSt
'setLayoutPresetIcon',
(presetId: ActionPayload<'setLayoutPresetIcon'>['presetId'], iconId: string) => ({ iconId, presetId })
),
+ setPresetRoute: command(
+ 'setLayoutPresetRoute',
+ (
+ presetId: ActionPayload<'setLayoutPresetRoute'>['presetId'],
+ defaultRoute: ActionPayload<'setLayoutPresetRoute'>['defaultRoute']
+ ) => ({ defaultRoute, presetId })
+ ),
deletePreset: command('deleteLayoutPreset', (presetId: ActionPayload<'deleteLayoutPreset'>['presetId']) => ({
presetId,
})),