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
refactor(webv2): publish the seed policy and mode menu as pure generation entries
Josh Corbett61d5c8e133c7
diff --git a/invokeai/frontend/webv2/performance/architecture-baseline.json b/invokeai/frontend/webv2/performance/architecture-baseline.jsonindex 87d8ab300f..ef65d5d84c 100644--- a/invokeai/frontend/webv2/performance/architecture-baseline.json+++ b/invokeai/frontend/webv2/performance/architecture-baseline.json@@ -133,6 +133,7 @@"source:src/features/fonts/launchpad.tsx","source:src/features/fonts/react.tsx","source:src/features/fonts/runtime.ts",+ "source:src/features/generation/core/seed.ts","source:src/features/identity/capabilities.ts","source:src/features/identity/core/schemas.ts","source:src/features/identity/core/sessionPolicy.ts",@@ -527,6 +528,7 @@"source:src/features/generation/core/promptTemplates.ts","source:src/features/generation/core/referenceImage.ts","source:src/features/generation/core/resolveGenerateWidgetValues.ts",+ "source:src/features/generation/core/seed.ts","source:src/features/generation/core/settings.ts","source:src/features/generation/core/supportedBases.ts","source:src/features/generation/data/architectureCapabilitiesApi.ts",@@ -549,6 +551,7 @@"source:src/features/generation/ui/promptFields/promptFocus.ts","source:src/features/generation/ui/promptFields/promptHistoryNavigation.ts","source:src/features/generation/ui/promptTemplateDraftStore.ts",+ "source:src/features/generation/ui/shared/SeedModeMenu.tsx","source:src/features/generation/ui/useDebouncedDraftValue.ts","source:src/features/generation/ui/useDynamicPrompts.ts","source:src/features/identity/capabilities.ts",diff --git a/invokeai/frontend/webv2/performance/browser-baseline.json b/invokeai/frontend/webv2/performance/browser-baseline.jsonindex d573bd72e8..a25bd7843b 100644--- a/invokeai/frontend/webv2/performance/browser-baseline.json+++ b/invokeai/frontend/webv2/performance/browser-baseline.json@@ -524,6 +524,7 @@"source:src/features/gallery/ui/GalleryUiContext.tsx","source:src/features/gallery/ui/galleryStateView.ts","source:src/features/gallery/ui/launchpad/RecentOutputs.tsx",+ "source:src/features/generation/core/seed.ts","source:src/features/identity/capabilities.ts","source:src/features/identity/core/schemas.ts","source:src/features/identity/core/sessionPolicy.ts",@@ -954,6 +955,7 @@"source:src/features/generation/core/promptTemplates.ts","source:src/features/generation/core/referenceImage.ts","source:src/features/generation/core/resolveGenerateWidgetValues.ts",+ "source:src/features/generation/core/seed.ts","source:src/features/generation/core/settings.ts","source:src/features/generation/core/supportedBases.ts","source:src/features/generation/core/systemPrompts.ts",@@ -1039,6 +1041,7 @@"source:src/features/generation/ui/shared/GenerateFieldContextMenu.tsx","source:src/features/generation/ui/shared/GenerateToggleSwitch.tsx","source:src/features/generation/ui/shared/SeedField.tsx",+ "source:src/features/generation/ui/shared/SeedModeMenu.tsx","source:src/features/generation/ui/shared/modelDefaultSettings.ts","source:src/features/generation/ui/useDebouncedDraftValue.ts","source:src/features/generation/ui/useDynamicPrompts.ts",@@ -1984,6 +1987,7 @@"source:src/features/generation/core/promptTemplates.ts","source:src/features/generation/core/referenceImage.ts","source:src/features/generation/core/resolveGenerateWidgetValues.ts",+ "source:src/features/generation/core/seed.ts","source:src/features/generation/core/settings.ts","source:src/features/generation/core/supportedBases.ts","source:src/features/generation/core/systemPrompts.ts",@@ -2069,6 +2073,7 @@"source:src/features/generation/ui/shared/GenerateFieldContextMenu.tsx","source:src/features/generation/ui/shared/GenerateToggleSwitch.tsx","source:src/features/generation/ui/shared/SeedField.tsx",+ "source:src/features/generation/ui/shared/SeedModeMenu.tsx","source:src/features/generation/ui/shared/modelDefaultSettings.ts","source:src/features/generation/ui/useDebouncedDraftValue.ts","source:src/features/generation/ui/useDynamicPrompts.ts",@@ -3172,6 +3177,7 @@"source:src/features/generation/core/promptTemplates.ts","source:src/features/generation/core/referenceImage.ts","source:src/features/generation/core/resolveGenerateWidgetValues.ts",+ "source:src/features/generation/core/seed.ts","source:src/features/generation/core/settings.ts","source:src/features/generation/core/supportedBases.ts","source:src/features/generation/core/systemPrompts.ts",@@ -3257,6 +3263,7 @@"source:src/features/generation/ui/shared/GenerateFieldContextMenu.tsx","source:src/features/generation/ui/shared/GenerateToggleSwitch.tsx","source:src/features/generation/ui/shared/SeedField.tsx",+ "source:src/features/generation/ui/shared/SeedModeMenu.tsx","source:src/features/generation/ui/shared/modelDefaultSettings.ts","source:src/features/generation/ui/useDebouncedDraftValue.ts","source:src/features/generation/ui/useDynamicPrompts.ts",diff --git a/invokeai/frontend/webv2/src/architecture/dependencyPolicy.test.ts b/invokeai/frontend/webv2/src/architecture/dependencyPolicy.test.tsindex 16706c53bd..b4c684678e 100644--- a/invokeai/frontend/webv2/src/architecture/dependencyPolicy.test.ts+++ b/invokeai/frontend/webv2/src/architecture/dependencyPolicy.test.ts@@ -238,6 +238,12 @@ describe('feature public-interface registry', () => {expect(checkDependency('workbench/invocationSubmit.ts', '@features/generation/prompts')).toEqual([]);expect(checkDependency('app/GenerateWidgetSyncRuntime.tsx', '@features/generation/runtime')).toEqual([]);expect(checkDependency('workbench/widgets/canvas/invoke.ts', '@features/generation/canvasGraph')).toEqual([]);+ // Workflow's pure graph compiler reuses Generate's seed arithmetic through its+ // side-effect-free entry rather than the settings surface.+ expect(checkDependency('features/workflow/core/buildGraph.ts', '@features/generation/seed')).toEqual([]);+ expect(+ checkDependency('features/workflow/ui/fields/WorkflowFieldInput.tsx', '@features/generation/seedModeMenu')+ ).toEqual([]);expect(checkDependency('workbench/invocationSubmit.ts', '@features/generation/data/dynamicPromptsQueries')).toMatchObject([{ rule: 'feature-private-interface' }]);diff --git a/invokeai/frontend/webv2/src/architecture/featureInterfaces.ts b/invokeai/frontend/webv2/src/architecture/featureInterfaces.tsindex c7617b018a..5c4c449104 100644--- a/invokeai/frontend/webv2/src/architecture/featureInterfaces.ts+++ b/invokeai/frontend/webv2/src/architecture/featureInterfaces.ts@@ -29,6 +29,8 @@ export const FEATURE_PUBLIC_INTERFACES: Readonly<Record<string, readonly string['queries','react','runtime',+ 'seed',+ 'seedModeMenu','settings','widget',],diff --git a/invokeai/frontend/webv2/src/features/generation/contracts.ts b/invokeai/frontend/webv2/src/features/generation/contracts.tsindex f30d048a07..8df4ecd9fb 100644--- a/invokeai/frontend/webv2/src/features/generation/contracts.ts+++ b/invokeai/frontend/webv2/src/features/generation/contracts.ts@@ -1,4 +1,4 @@export type * from './core/contracts';export type * from './core/types';-export type { SeedMode, SeedStep, SeedSubmissionPlan } from './core/settings';+export type { SeedMode, SeedStep, SeedSubmissionPlan } from './core/seed';export type { CanvasScaleMethod, CanvasScalingSettings } from './core/canvas/types';diff --git a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.tsindex 38454f6113..8b3bf84ba6 100644--- a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts@@ -50,6 +50,7 @@ import {getPidDecoderBaseForMainBase,getPidDimensionOverrides,} from './pid';+import { SEED_MAX } from './seed';import {clampDimension,DEFAULT_HIDIFFUSION_T1_RATIO,@@ -75,7 +76,6 @@ import {MAX_DIMENSION,MIN_DIMENSION,normalizeGenerateSettings,- SEED_MAX,} from './settings';// Generation policy registry keyed by model base. Display identity stays in @features/models;diff --git a/invokeai/frontend/webv2/src/features/generation/core/graph.ts b/invokeai/frontend/webv2/src/features/generation/core/graph.tsindex 4551ee4f26..1a47119542 100644--- a/invokeai/frontend/webv2/src/features/generation/core/graph.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/graph.ts@@ -47,7 +47,7 @@ import {import { addKrea2ConditioningEnhancers } from './krea2Conditioning';import { addPidDecode, getPidDenoiseSize, getPidMetadata, shouldUsePidDecode } from './pidGraph';import { getEffectiveReferenceImage } from './referenceImage';-import { SEED_MAX } from './settings';+import { SEED_MAX } from './seed';const getCompatibleComponentSource = (settings: GenerateSettings,diff --git a/invokeai/frontend/webv2/src/features/generation/core/seed.ts b/invokeai/frontend/webv2/src/features/generation/core/seed.tsnew file mode 100644index 0000000000..61b8ec2063--- /dev/null+++ b/invokeai/frontend/webv2/src/features/generation/core/seed.ts@@ -0,0 +1,83 @@+/**+ * The seed policy every seeded submission shares: the range, the four modes,+ * and how a submission walks its sequence. Kept pure (no top-level calls, no+ * dependencies) so any owner can import it without taking on the settings+ * module: a side-effectful import here would make the workflow graph compiler+ * side-effectful, which materializes its facade and pulls the canvas-layer+ * chunk into the settings and palette overlays.+ */++export const SEED_MAX = 4_294_967_295;++export const SEED_MODES = ['random', 'fixed', 'increment', 'decrement'] as const;++export type SeedMode = (typeof SEED_MODES)[number];++/** Direction the seed moves between the entries of one submission's sequence. */+export type SeedStep = -1 | 0 | 1;++export const isSeedMode = (value: unknown): value is SeedMode => SEED_MODES.includes(value as SeedMode);++export const getSeedStep = (mode: SeedMode): SeedStep => (mode === 'fixed' ? 0 : mode === 'decrement' ? -1 : 1);++/** Wraps over the inclusive seed range so decrementing past 0 lands on `SEED_MAX`. */+export const wrapSeed = (seed: number): number => {+ const range = SEED_MAX + 1;++ return ((seed % range) + range) % range;+};++export interface SeedSequenceInput {+ batchCount: number;+ /** Concrete prompts the submission carries; one unless dynamic prompts expanded it. */+ promptCount: number;+ seedBehaviour: 'per-image' | 'per-iteration';+ seedMode: SeedMode;+}++/**+ * How many entries of the seed sequence one submission uses. A fixed seed uses+ * its single entry however many images run. Otherwise every iteration takes an+ * entry, and with several prompts sharing disabled every image does.+ */+export const getSeedSequenceLength = ({+ batchCount,+ promptCount,+ seedBehaviour,+ seedMode,+}: SeedSequenceInput): number =>+ seedMode === 'fixed' ? 1 : promptCount > 1 && seedBehaviour === 'per-image' ? promptCount * batchCount : batchCount;++export interface SeedSubmissionPlan {+ /** The last sequence entry the submission uses. */+ lastSeed: number;+ /** What the editable seed becomes once the submission is queued; null when the mode leaves it alone. */+ nextSeed: number | null;+ seedMode: SeedMode;+ sequenceLength: number;+ startSeed: number;+ step: SeedStep;+}++/**+ * The seeds a submission consumes and where the editable seed goes afterwards.+ * Only the stepping modes advance it: random keeps the manual value in reserve,+ * fixed reuses it.+ */+export const planSeedSubmission = ({+ startSeed,+ ...sequence+}: SeedSequenceInput & { startSeed: number }): SeedSubmissionPlan => {+ const step = getSeedStep(sequence.seedMode);+ const sequenceLength = getSeedSequenceLength(sequence);+ const advances = sequence.seedMode === 'increment' || sequence.seedMode === 'decrement';++ return {+ lastSeed: wrapSeed(startSeed + step * (sequenceLength - 1)),+ nextSeed: advances ? wrapSeed(startSeed + step * sequenceLength) : null,+ seedMode: sequence.seedMode,+ sequenceLength,+ startSeed,+ step,+ };+};diff --git a/invokeai/frontend/webv2/src/features/generation/core/settings.test.ts b/invokeai/frontend/webv2/src/features/generation/core/settings.test.tsindex 8b7a74fd44..f6b70d94a7 100644--- a/invokeai/frontend/webv2/src/features/generation/core/settings.test.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/settings.test.ts@@ -11,6 +11,7 @@ import type {} from './types';import { getGenerationDimensions } from './baseGenerationPolicies';+import { getSeedSequenceLength, getSeedStep, isSeedMode, planSeedSubmission, SEED_MAX, wrapSeed } from './seed';import {calculateNewSize,clampDimension,@@ -18,19 +19,13 @@ import {deriveAspectRatioId,getDefaultLoraWeight,getModelDefaultVae,- getSeedSequenceLength,- getSeedStep,hasModelDefaultVae,isLoraCompatibleWithModel,isGenerateSettings,- isSeedMode,moveReferenceImage,normalizeGenerateSettings,- planSeedSubmission,- SEED_MAX,syncGenerateWidgetValuesWithModels,syncGenerateLorasWithModels,- wrapSeed,} from './settings';/** The persisted widget-value shape from before aspect ratio / VAE / seamless / CLIP skip landed. */diff --git a/invokeai/frontend/webv2/src/features/generation/core/settings.ts b/invokeai/frontend/webv2/src/features/generation/core/settings.tsindex 198276ffb6..3227ebce3c 100644--- a/invokeai/frontend/webv2/src/features/generation/core/settings.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/settings.ts@@ -28,6 +28,7 @@ import { isDynamicPromptsSeedBehaviour, sanitizeMaxPrompts, sanitizeSampleSeed }import { clampPidSteps, DEFAULT_PID_STEPS, isPidMode } from './pid';import { isCanonicalPromptTemplateSnapshot, sanitizePromptTemplateSnapshot } from './promptTemplates';import { cloneCroppableImage, isCanonicalCroppableImage, normalizeCroppableImage } from './referenceImage';+import { isSeedMode } from './seed';/** Preset ratios, with the preset to switch to when dimensions are swapped. */export const ASPECT_RATIO_MAP: Record<Exclude<AspectRatioId, 'Free'>, { ratio: number; inverseId: AspectRatioId }> = {@@ -68,8 +69,6 @@ export const DIMENSION_GRID = 8;export const MIN_DIMENSION = 64;export const MAX_DIMENSION = 4096;-export const SEED_MAX = 4_294_967_295;-/** The expansion config the settings describe, under the names the expansion route and preview use. */export const getDynamicPromptsConfig = (settings: Pick<@@ -906,76 +905,3 @@ 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);--export const SEED_MODES = ['random', 'fixed', 'increment', 'decrement'] as const;--export type SeedMode = (typeof SEED_MODES)[number];--/** Direction the seed moves between the entries of one submission's sequence. */-export type SeedStep = -1 | 0 | 1;--export const isSeedMode = (value: unknown): value is SeedMode => SEED_MODES.includes(value as SeedMode);--export const getSeedStep = (mode: SeedMode): SeedStep => (mode === 'fixed' ? 0 : mode === 'decrement' ? -1 : 1);--/** Wraps over the inclusive seed range so decrementing past 0 lands on `SEED_MAX`. */-export const wrapSeed = (seed: number): number => {- const range = SEED_MAX + 1;-- return ((seed % range) + range) % range;-};--export interface SeedSequenceInput {- batchCount: number;- /** Concrete prompts the submission carries; one unless dynamic prompts expanded it. */- promptCount: number;- seedBehaviour: 'per-image' | 'per-iteration';- seedMode: SeedMode;-}--/**- * How many entries of the seed sequence one submission uses. A fixed seed uses- * its single entry however many images run. Otherwise every iteration takes an- * entry, and with several prompts sharing disabled every image does.- */-export const getSeedSequenceLength = ({- batchCount,- promptCount,- seedBehaviour,- seedMode,-}: SeedSequenceInput): number =>- seedMode === 'fixed' ? 1 : promptCount > 1 && seedBehaviour === 'per-image' ? promptCount * batchCount : batchCount;--export interface SeedSubmissionPlan {- /** The last sequence entry the submission uses. */- lastSeed: number;- /** What the editable seed becomes once the submission is queued; null when the mode leaves it alone. */- nextSeed: number | null;- seedMode: SeedMode;- sequenceLength: number;- startSeed: number;- step: SeedStep;-}--/**- * The seeds a submission consumes and where the editable seed goes afterwards.- * Only the stepping modes advance it: random keeps the manual value in reserve,- * fixed reuses it.- */-export const planSeedSubmission = ({- startSeed,- ...sequence-}: SeedSequenceInput & { startSeed: number }): SeedSubmissionPlan => {- const step = getSeedStep(sequence.seedMode);- const sequenceLength = getSeedSequenceLength(sequence);- const advances = sequence.seedMode === 'increment' || sequence.seedMode === 'decrement';-- return {- lastSeed: wrapSeed(startSeed + step * (sequenceLength - 1)),- nextSeed: advances ? wrapSeed(startSeed + step * sequenceLength) : null,- seedMode: sequence.seedMode,- sequenceLength,- startSeed,- step,- };-};diff --git a/invokeai/frontend/webv2/src/features/generation/core/types.ts b/invokeai/frontend/webv2/src/features/generation/core/types.tsindex e6f239313c..966eb9f6b6 100644--- a/invokeai/frontend/webv2/src/features/generation/core/types.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/types.ts@@ -1,7 +1,7 @@import type { BackendGraphContract, GraphContract } from '@features/generation/core/contracts';import type { DynamicPromptsSeedBehaviour } from '@features/generation/core/dynamicPrompts';import type { PromptTemplateSnapshot } from '@features/generation/core/promptTemplates';-import type { SeedMode } from '@features/generation/core/settings';+import type { SeedMode } from '@features/generation/core/seed';export type ModelIdentifierConfig = {key: string;diff --git a/invokeai/frontend/webv2/src/features/generation/seed.ts b/invokeai/frontend/webv2/src/features/generation/seed.tsnew file mode 100644index 0000000000..9098d50e5e--- /dev/null+++ b/invokeai/frontend/webv2/src/features/generation/seed.ts@@ -0,0 +1,17 @@+/**+ * Generation's seed policy, published on its own so pure cores elsewhere can+ * reuse the arithmetic without importing the settings surface.+ */+export {+ getSeedSequenceLength,+ getSeedStep,+ isSeedMode,+ planSeedSubmission,+ SEED_MAX,+ SEED_MODES,+ wrapSeed,+ type SeedMode,+ type SeedSequenceInput,+ type SeedStep,+ type SeedSubmissionPlan,+} from './core/seed';diff --git a/invokeai/frontend/webv2/src/features/generation/seedModeMenu.ts b/invokeai/frontend/webv2/src/features/generation/seedModeMenu.tsnew file mode 100644index 0000000000..cfd4cfb075--- /dev/null+++ b/invokeai/frontend/webv2/src/features/generation/seedModeMenu.ts@@ -0,0 +1,6 @@+/**+ * The seed mode menu on its own, for hosts that own the seed value themselves+ * (workflow node inputs). Its module sits in the editor boot chunk, which every+ * seeded widget already loads, so a new host costs no request of its own.+ */+export { SeedModeMenu, type SeedModeMenuProps } from './ui/shared/SeedModeMenu';diff --git a/invokeai/frontend/webv2/src/features/generation/settings.ts b/invokeai/frontend/webv2/src/features/generation/settings.tsindex a6fe6dab38..6fd259d8dd 100644--- a/invokeai/frontend/webv2/src/features/generation/settings.ts+++ b/invokeai/frontend/webv2/src/features/generation/settings.ts@@ -31,7 +31,6 @@ export {normalizeGenerateSettings,normalizeGenerateWidgetValues,normalizeReferenceImages,- SEED_MAX,syncGenerateWidgetValuesWithModels,} from './core/settings';export {@@ -78,11 +77,13 @@ export {getSeedStep,isSeedMode,planSeedSubmission,+ SEED_MAX,SEED_MODES,+ wrapSeed,type SeedMode,type SeedStep,type SeedSubmissionPlan,-} from './core/settings';+} from './core/seed';export {createDynamicPromptsSampleSeed,DYNAMIC_PROMPTS_DEFAULT_MAX_PROMPTS,diff --git a/invokeai/frontend/webv2/src/features/generation/ui/shared/SeedField.tsx b/invokeai/frontend/webv2/src/features/generation/ui/shared/SeedField.tsxindex f382d2b4dc..7cc9e45fc3 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/shared/SeedField.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/shared/SeedField.tsx@@ -1,78 +1,20 @@/* oxlint-disable react-perf/jsx-no-new-object-as-prop, react-perf/jsx-no-new-function-as-prop, react-perf/jsx-no-jsx-as-prop */import type { DynamicPromptsSeedBehaviour } from '@features/generation/core/dynamicPrompts';-import type { SeedMode } from '@features/generation/core/settings';-import type { LucideIcon } from 'lucide-react';+import type { SeedMode } from '@features/generation/core/seed';import type { ReactNode } from 'react';-import { HStack, Icon, InputGroup, Menu, NumberInput, Portal, Stack, Text } from '@chakra-ui/react';-import { planSeedSubmission, SEED_MAX, SEED_MODES } from '@features/generation/core/settings';-import { Button, IconButton } from '@platform/ui/Button';+import { HStack, InputGroup, NumberInput, Stack, Text } from '@chakra-ui/react';+import { planSeedSubmission, SEED_MAX } from '@features/generation/core/seed';+import { IconButton } from '@platform/ui/Button';import { Field } from '@platform/ui/Field';-import { MenuContent } from '@platform/ui/Menu';-import { Tooltip } from '@platform/ui/Tooltip';-import { ChevronDownIcon, DicesIcon, LocateFixedIcon, MinusIcon, PlusIcon, ShuffleIcon } from 'lucide-react';-import { useId, useMemo } from 'react';+import { DicesIcon } from 'lucide-react';+import { useId } from 'react';import { useTranslation } from 'react-i18next';+import { SeedModeMenu } from './SeedModeMenu';+const SEED_END_ELEMENT_PROPS = { pointerEvents: 'auto', pr: '0.5' } as const;-const SEED_MODE_MENU_POSITIONING = { placement: 'bottom-end' } as const;const TABULAR_NUMS = { fontVariantNumeric: 'tabular-nums' } as const;-const SEED_MODE_ICONS: Record<SeedMode, LucideIcon> = {- decrement: MinusIcon,- fixed: LocateFixedIcon,- increment: PlusIcon,- random: ShuffleIcon,-};--/**- * How the seed moves from one submission to the next. A menu rather than a- * toggle because the choice has four answers, and each needs a line of- * explanation the first time it is read.- */-const SeedModeMenu = ({ onChange, value }: { value: SeedMode; onChange: (mode: SeedMode) => void }) => {- const { t } = useTranslation();- // Shared ids let the tooltip ride the menu trigger without wrapping it- // (wrapping `Menu.Trigger` swallows the anchor ref — see RoutingControl).- const triggerId = useId();- const triggerIds = useMemo(() => ({ trigger: triggerId }), [triggerId]);- const label = t('widgets.generate.seedMode.label');- const valueLabel = t(`widgets.generate.seedMode.${value}`);-- return (- <Menu.Root ids={triggerIds} positioning={SEED_MODE_MENU_POSITIONING}>- <Tooltip content={label} ids={triggerIds}>- <Menu.Trigger asChild>- <Button aria-label={`${label}: ${valueLabel}`} flexShrink={0} gap="1" size="xs" variant="outline">- <Icon as={SEED_MODE_ICONS[value]} boxSize="3.5" color="fg.muted" />- {valueLabel}- <Icon as={ChevronDownIcon} boxSize="3" color="fg.muted" />- </Button>- </Menu.Trigger>- </Tooltip>- <Portal>- <Menu.Positioner>- <MenuContent minW="16rem">- <Menu.RadioItemGroup value={value} onValueChange={(event) => onChange(event.value as SeedMode)}>- {SEED_MODES.map((mode) => (- <Menu.RadioItem key={mode} py="1.5" value={mode}>- {/* The recipe centers the check on the row; on a two-line item it belongs on the label line. */}- <Menu.ItemIndicator top="2" transform="none" />- <Icon alignSelf="flex-start" as={SEED_MODE_ICONS[mode]} boxSize="3.5" color="fg.subtle" mt="0.5" />- <Stack gap="0" minW="0">- <Menu.ItemText>{t(`widgets.generate.seedMode.${mode}`)}</Menu.ItemText>- <Text color="fg.subtle" fontSize="2xs">- {t(`widgets.generate.seedMode.${mode}Description`)}- </Text>- </Stack>- </Menu.RadioItem>- ))}- </Menu.RadioItemGroup>- </MenuContent>- </Menu.Positioner>- </Portal>- </Menu.Root>- );-};export interface SeedFieldPatch {seed?: number;diff --git a/invokeai/frontend/webv2/src/features/generation/ui/shared/SeedModeMenu.tsx b/invokeai/frontend/webv2/src/features/generation/ui/shared/SeedModeMenu.tsxnew file mode 100644index 0000000000..bb49f8f567--- /dev/null+++ b/invokeai/frontend/webv2/src/features/generation/ui/shared/SeedModeMenu.tsx@@ -0,0 +1,79 @@+/* oxlint-disable react-perf/jsx-no-new-function-as-prop */+import type { SeedMode } from '@features/generation/core/seed';+import type { LucideIcon } from 'lucide-react';++import { Icon, Menu, Portal, Stack, Text } from '@chakra-ui/react';+import { SEED_MODES } from '@features/generation/core/seed';+import { Button } from '@platform/ui/Button';+import { MenuContent } from '@platform/ui/Menu';+import { Tooltip } from '@platform/ui/Tooltip';+import { ChevronDownIcon, LocateFixedIcon, MinusIcon, PlusIcon, ShuffleIcon } from 'lucide-react';+import { useId, useMemo } from 'react';+import { useTranslation } from 'react-i18next';++const SEED_MODE_MENU_POSITIONING = { placement: 'bottom-end' } as const;+const SEED_MODE_ICONS: Record<SeedMode, LucideIcon> = {+ decrement: MinusIcon,+ fixed: LocateFixedIcon,+ increment: PlusIcon,+ random: ShuffleIcon,+};++export interface SeedModeMenuProps {+ value: SeedMode;+ onChange: (mode: SeedMode) => void;+ /** Trigger tooltip; the mode label unless the host has more to say about what a step is. */+ tooltip?: string;+ /** Class for the portaled menu content, for hosts whose key handling must skip it (xyflow's `nokey`). */+ contentClassName?: string;+}++/**+ * How the seed moves from one submission to the next. A menu rather than a+ * toggle because the choice has four answers, and each needs a line of+ * explanation the first time it is read.+ */+export const SeedModeMenu = ({ contentClassName, onChange, tooltip, value }: SeedModeMenuProps) => {+ const { t } = useTranslation();+ // Shared ids let the tooltip ride the menu trigger without wrapping it+ // (wrapping `Menu.Trigger` swallows the anchor ref — see RoutingControl).+ const triggerId = useId();+ const triggerIds = useMemo(() => ({ trigger: triggerId }), [triggerId]);+ const label = t('widgets.generate.seedMode.label');+ const valueLabel = t(`widgets.generate.seedMode.${value}`);++ return (+ <Menu.Root ids={triggerIds} positioning={SEED_MODE_MENU_POSITIONING}>+ <Tooltip content={tooltip ?? label} ids={triggerIds}>+ <Menu.Trigger asChild>+ <Button aria-label={`${label}: ${valueLabel}`} flexShrink={0} gap="1" size="xs" variant="outline">+ <Icon as={SEED_MODE_ICONS[value]} boxSize="3.5" color="fg.muted" />+ {valueLabel}+ <Icon as={ChevronDownIcon} boxSize="3" color="fg.muted" />+ </Button>+ </Menu.Trigger>+ </Tooltip>+ <Portal>+ <Menu.Positioner>+ <MenuContent className={contentClassName} minW="16rem">+ <Menu.RadioItemGroup value={value} onValueChange={(event) => onChange(event.value as SeedMode)}>+ {SEED_MODES.map((mode) => (+ <Menu.RadioItem key={mode} py="1.5" value={mode}>+ {/* The recipe centers the check on the row; on a two-line item it belongs on the label line. */}+ <Menu.ItemIndicator top="2" transform="none" />+ <Icon alignSelf="flex-start" as={SEED_MODE_ICONS[mode]} boxSize="3.5" color="fg.subtle" mt="0.5" />+ <Stack gap="0" minW="0">+ <Menu.ItemText>{t(`widgets.generate.seedMode.${mode}`)}</Menu.ItemText>+ <Text color="fg.subtle" fontSize="2xs">+ {t(`widgets.generate.seedMode.${mode}Description`)}+ </Text>+ </Stack>+ </Menu.RadioItem>+ ))}+ </Menu.RadioItemGroup>+ </MenuContent>+ </Menu.Positioner>+ </Portal>+ </Menu.Root>+ );+};diff --git a/invokeai/frontend/webv2/vite.config.mts b/invokeai/frontend/webv2/vite.config.mtsindex c3a4ea8c68..4e79afadc5 100644--- a/invokeai/frontend/webv2/vite.config.mts+++ b/invokeai/frontend/webv2/vite.config.mts@@ -95,6 +95,9 @@ const EDITOR_BOOT_SHARED_MODULES = ['/features/generation/queries.ts','/features/generation/runtime.ts','/features/generation/ui/promptFields/promptAttentionHotkeys.ts',+ // Shared by the Generate/Upscale/Video seed row and workflow seed inputs; left to rolldown it+ // splits into a chunk every editor route would fetch separately.+ '/features/generation/ui/shared/SeedModeMenu.tsx','/workbench/shell/topbar/LayoutPresetAdminDialogs.tsx','/workbench/shell/topbar/LayoutPresetStrip.tsx','/workbench/shell/topbar/ProjectSwitcher.tsx',@@ -187,6 +190,8 @@ const getLegacyChunkName = (id: string): string | null => {'/workbench/palette/paletteStore.ts','/platform/search/dateTokens.ts','/platform/performance/semanticReady.ts',+ // A pure leaf every seeded owner imports; on its own it would cost the editor boot a request.+ '/features/generation/core/seed.ts',])) {return 'shared';