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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
feat(webv2): add auto route-switch helper and per-surface edit classifiers
joshistoastc3aaa06000db
diff --git a/invokeai/frontend/webv2/src/features/generation/core/settings.ts b/invokeai/frontend/webv2/src/features/generation/core/settings.tsindex f98223beb2..ef6867ba45 100644--- a/invokeai/frontend/webv2/src/features/generation/core/settings.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/settings.ts@@ -643,3 +643,18 @@ export const isGenerateSettings = (values: unknown): values is GenerateSettingsexport const isGenerateWidgetValues = (values: unknown): values is GenerateWidgetValues =>isGenerateSettings(values) && isGenerateModelConfig((values as unknown as Record<string, unknown>).model);++/**+ * Widget-value keys that carry no generation intent — layout state and the+ * shared topbar batch count. Any other changed key is a high-confidence edit+ * for auto-switching the Invoke route, so new settings count by default.+ */+const GENERATE_UI_NOISE_KEYS: ReadonlySet<string> = new Set([+ 'aspectRatioIsLocked',+ 'batchCount',+ 'negativePromptHeightPx',+ 'positivePromptHeightPx',+]);++export const isHighConfidenceGenerateEdit = (changedKeys: readonly string[]): boolean =>+ changedKeys.some((key) => !GENERATE_UI_NOISE_KEYS.has(key));diff --git a/invokeai/frontend/webv2/src/features/generation/settings.ts b/invokeai/frontend/webv2/src/features/generation/settings.tsindex 8c3c9c229c..7f05b01529 100644--- a/invokeai/frontend/webv2/src/features/generation/settings.ts+++ b/invokeai/frontend/webv2/src/features/generation/settings.ts@@ -13,6 +13,7 @@ export {getDefaultLoraWeight,getModelDefaultVae,hasModelDefaultVae,+ isHighConfidenceGenerateEdit,isLoraCompatibleWithModel,isLoraModelConfig,isMainModelConfig,diff --git a/invokeai/frontend/webv2/src/features/upscale/core/settings.ts b/invokeai/frontend/webv2/src/features/upscale/core/settings.tsindex 7a129d7f63..a91fca73fa 100644--- a/invokeai/frontend/webv2/src/features/upscale/core/settings.ts+++ b/invokeai/frontend/webv2/src/features/upscale/core/settings.ts@@ -350,3 +350,17 @@ export const resolveUpscaleSeed = (values: UpscaleWidgetValues): number =>values.shouldRandomizeSeed ? Math.floor(Math.random() * SEED_MAX) : values.seed;export const cloneUpscaleWidgetValues = (values: UpscaleWidgetValues): UpscaleWidgetValues => structuredClone(values);++/**+ * Widget-value keys that carry no upscale intent — layout state and the shared+ * topbar batch count. Any other changed key is a high-confidence edit for+ * auto-switching the Invoke route, so new settings count by default.+ */+const UPSCALE_UI_NOISE_KEYS: ReadonlySet<string> = new Set([+ 'batchCount',+ 'negativePromptHeightPx',+ 'positivePromptHeightPx',+]);++export const isHighConfidenceUpscaleEdit = (changedKeys: readonly string[]): boolean =>+ changedKeys.some((key) => !UPSCALE_UI_NOISE_KEYS.has(key));diff --git a/invokeai/frontend/webv2/src/features/upscale/index.ts b/invokeai/frontend/webv2/src/features/upscale/index.tsindex d0c5a4a648..6049902d54 100644--- a/invokeai/frontend/webv2/src/features/upscale/index.ts+++ b/invokeai/frontend/webv2/src/features/upscale/index.ts@@ -5,6 +5,7 @@ export {createDefaultUpscaleWidgetValues,getUpscaleOutputDimensions,getUpscaleValidationReasons,+ isHighConfidenceUpscaleEdit,normalizeUpscaleWidgetValues,resolveUpscaleSeed,syncUpscaleWidgetValuesWithModels,diff --git a/invokeai/frontend/webv2/src/workbench/canvasProjectMutations.test.ts b/invokeai/frontend/webv2/src/workbench/canvasProjectMutations.test.tsnew file mode 100644index 0000000000..4be0291689--- /dev/null+++ b/invokeai/frontend/webv2/src/workbench/canvasProjectMutations.test.ts@@ -0,0 +1,53 @@+import type { CanvasProjectMutation } from './canvasProjectMutations';++import { describe, expect, it } from 'vitest';++import { isHighConfidenceCanvasEdit } from './canvasProjectMutations';++const mutation = (value: Record<string, unknown>): CanvasProjectMutation => value as never;++describe('isHighConfidenceCanvasEdit', () => {+ it('counts content edits: layer add/source updates, bbox, and document resize', () => {+ expect(isHighConfidenceCanvasEdit(mutation({ type: 'addCanvasLayer' }))).toBe(true);+ expect(isHighConfidenceCanvasEdit(mutation({ type: 'updateCanvasLayerSource' }))).toBe(true);+ expect(isHighConfidenceCanvasEdit(mutation({ type: 'updateCanvasLayerConfig' }))).toBe(true);+ expect(isHighConfidenceCanvasEdit(mutation({ type: 'commitStagedImage' }))).toBe(true);+ expect(isHighConfidenceCanvasEdit(mutation({ type: 'setCanvasBbox' }))).toBe(true);+ expect(isHighConfidenceCanvasEdit(mutation({ type: 'resizeCanvasDocument' }))).toBe(true);+ });++ it('counts layer patches only when they carry content intent', () => {+ expect(isHighConfidenceCanvasEdit(mutation({ patch: { transform: {} }, type: 'updateCanvasLayer' }))).toBe(true);+ expect(isHighConfidenceCanvasEdit(mutation({ patch: { opacity: 0.5 }, type: 'updateCanvasLayer' }))).toBe(true);+ expect(isHighConfidenceCanvasEdit(mutation({ patch: { blendMode: 'multiply' }, type: 'updateCanvasLayer' }))).toBe(+ true+ );+ expect(+ isHighConfidenceCanvasEdit(mutation({ patch: { isLocked: true, name: 'Layer 1' }, type: 'updateCanvasLayer' }))+ ).toBe(false);+ });++ it('ignores selection, visibility, staging review, snapshots, and hydration', () => {+ const excluded: string[] = [+ 'setCanvasSelectedLayer',+ 'setCanvasLayersEnabled',+ 'setStagedImageIndex',+ 'cycleStagedImage',+ 'discardSelectedStagedImage',+ 'discardAllStagedImages',+ 'clearCanvasStaging',+ 'toggleCanvasStagingVisibility',+ 'toggleCanvasStagingThumbnailsVisibility',+ 'setCanvasStagingAutoSwitch',+ 'rollbackStagedImageCommit',+ 'saveCanvasSnapshot',+ 'restoreCanvasSnapshot',+ 'deleteCanvasSnapshot',+ 'replaceCanvasDocument',+ ];++ for (const type of excluded) {+ expect(isHighConfidenceCanvasEdit(mutation({ type }))).toBe(false);+ }+ });+});diff --git a/invokeai/frontend/webv2/src/workbench/canvasProjectMutations.ts b/invokeai/frontend/webv2/src/workbench/canvasProjectMutations.tsindex d111849a9d..a8e8d2e123 100644--- a/invokeai/frontend/webv2/src/workbench/canvasProjectMutations.ts+++ b/invokeai/frontend/webv2/src/workbench/canvasProjectMutations.ts@@ -136,6 +136,43 @@ const CANVAS_PROJECT_MUTATION_TYPES: ReadonlySet<string> = new Set<CanvasProjectexport const isCanvasProjectMutation = (value: { type: string }): value is CanvasProjectMutation =>CANVAS_PROJECT_MUTATION_TYPES.has(value.type);+/**+ * Mutations that count as deliberate canvas content edits for auto-switching+ * the Invoke route. Selection, visibility, staging review/navigation, snapshot+ * management, and document hydration are excluded — they express review or+ * bookkeeping, not editing intent. `applyCanvasLayerStackMutation` also fires+ * on rare error-rollback paths (staged-result commit failures); that false+ * positive is accepted rather than threading an origin through the engine.+ */+const HIGH_CONFIDENCE_CANVAS_MUTATION_TYPES: ReadonlySet<CanvasProjectMutation['type']> = new Set<+ CanvasProjectMutation['type']+>([+ 'addCanvasLayer',+ 'applyCanvasLayerStackMutation',+ 'commitStagedImage',+ 'convertCanvasLayer',+ 'duplicateCanvasLayer',+ 'mergeCanvasLayersDown',+ 'removeCanvasLayers',+ 'reorderCanvasLayers',+ 'replaceCanvasLayer',+ 'resizeCanvasDocument',+ 'setCanvasBbox',+ 'updateCanvasLayerConfig',+ 'updateCanvasLayerSource',+]);++/** Layer patch keys that carry content intent (move/transform/composite), unlike rename or lock toggles. */+const CONTENT_BEARING_LAYER_PATCH_KEYS = ['transform', 'opacity', 'blendMode'] as const;++export const isHighConfidenceCanvasEdit = (mutation: CanvasProjectMutation): boolean => {+ if (mutation.type === 'updateCanvasLayer') {+ return CONTENT_BEARING_LAYER_PATCH_KEYS.some((key) => key in mutation.patch);+ }++ return HIGH_CONFIDENCE_CANVAS_MUTATION_TYPES.has(mutation.type);+};+type CanvasLayers = CanvasDocumentContractV2['layers'];const layerExists = (layers: CanvasLayers, id: string): boolean => layers.some((layer) => layer.id === id);diff --git a/invokeai/frontend/webv2/src/workbench/invocation.test.ts b/invokeai/frontend/webv2/src/workbench/invocation.test.tsindex 3b1f3585e3..fa8eff301b 100644--- a/invokeai/frontend/webv2/src/workbench/invocation.test.ts+++ b/invokeai/frontend/webv2/src/workbench/invocation.test.ts@@ -13,7 +13,13 @@ import { getDefaultGenerateSettings } from '@features/generation/settings';import { createDefaultUpscaleWidgetValues } from '@features/upscale';import { describe, expect, it, vi } from 'vitest';-import { getInvocationRouteInput, resolveInvocationRoute, resolveInvocationRouteInput } from './invocation';+import {+ autoSwitchDestinations,+ getInvocationRouteInput,+ getRouteAfterHighConfidenceEdit,+ resolveInvocationRoute,+ resolveInvocationRouteInput,+} from './invocation';import { submitResolvedInvocation } from './invocationSubmit';import { createInitialWorkbenchState, workbenchReducer } from './workbenchState.testing';import { createWorkbenchStore } from './workbenchStore';@@ -316,3 +322,47 @@ describe('submitResolvedInvocation', () => {});});});++describe('getRouteAfterHighConfidenceEdit', () => {+ const route = (overrides: Partial<InvocationRoute> = {}): InvocationRoute => ({+ destination: 'canvas',+ destinationLocked: false,+ sourceId: 'generate',+ sourceLocked: false,+ ...overrides,+ });++ it('switches the source and remaps the destination per the auto-switch mapping', () => {+ expect(getRouteAfterHighConfidenceEdit(route(), 'workflow')).toEqual(+ route({ destination: 'gallery', sourceId: 'workflow' })+ );+ expect(getRouteAfterHighConfidenceEdit(route(), 'upscale')).toEqual(+ route({ destination: 'gallery', sourceId: 'upscale' })+ );+ expect(getRouteAfterHighConfidenceEdit(route({ destination: 'gallery' }), 'canvas')).toEqual(+ route({ destination: 'canvas', sourceId: 'canvas' })+ );+ });++ it('covers every source in the destination mapping', () => {+ expect(Object.keys(autoSwitchDestinations).sort()).toEqual(['canvas', 'generate', 'upscale', 'workflow']);+ });++ it('is an identity no-op when the source is unchanged, preserving a manual destination', () => {+ const gallerySameSource = route({ destination: 'gallery' });++ expect(getRouteAfterHighConfidenceEdit(gallerySameSource, 'generate')).toBe(gallerySameSource);+ });++ it('does nothing when the source is locked', () => {+ const locked = route({ sourceLocked: true });++ expect(getRouteAfterHighConfidenceEdit(locked, 'canvas')).toBe(locked);+ });++ it('switches only the source when the destination is locked', () => {+ expect(getRouteAfterHighConfidenceEdit(route({ destinationLocked: true }), 'workflow')).toEqual(+ route({ destinationLocked: true, sourceId: 'workflow' })+ );+ });+});diff --git a/invokeai/frontend/webv2/src/workbench/invocation.ts b/invokeai/frontend/webv2/src/workbench/invocation.tsindex 77914603f3..ed8ecc9c9b 100644--- a/invokeai/frontend/webv2/src/workbench/invocation.ts+++ b/invokeai/frontend/webv2/src/workbench/invocation.ts@@ -75,6 +75,33 @@ export const defaultInvocationRoute: InvocationRoute = {destinationLocked: false,};+/** Destination each surface maps to when the source auto-switches. */+export const autoSwitchDestinations: Record<InvocationSourceId, ResultDestination> = {+ canvas: 'canvas',+ generate: 'gallery',+ upscale: 'gallery',+ workflow: 'gallery',+};++/**+ * Route after a high-confidence edit on `sourceId`; identity-preserving when+ * nothing changes. The destination remaps only on an actual source transition,+ * so repeated edits on the same surface never re-force a manually chosen+ * destination, and locks always win.+ */+export const getRouteAfterHighConfidenceEdit = (+ invocation: InvocationRoute,+ sourceId: InvocationSourceId+): InvocationRoute => {+ if (invocation.sourceLocked || invocation.sourceId === sourceId || !isInvocationSourceAvailable(sourceId)) {+ return invocation;+ }++ const destination = invocation.destinationLocked ? invocation.destination : autoSwitchDestinations[sourceId];++ return { ...invocation, destination, sourceId };+};+const validDestinationIds = new Set(resultDestinations.map((destination) => destination.id));const sourceWidgetIds: Partial<Record<InvocationSourceId, WidgetId>> = {