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.

refactor(webv2): move the seed control and policy into platform

Josh Corbett408c5644ea1c
diff --git a/invokeai/frontend/webv2/performance/architecture-baseline.json b/invokeai/frontend/webv2/performance/architecture-baseline.json
index aa99a13824..39d604dcd5 100644
--- a/invokeai/frontend/webv2/performance/architecture-baseline.json
+++ b/invokeai/frontend/webv2/performance/architecture-baseline.json
@@ -133,7 +133,6 @@
"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",
@@ -181,6 +180,7 @@
"source:src/platform/browser/randomUuid.ts",
"source:src/platform/browser/sha256.ts",
"source:src/platform/core/concurrency.ts",
+ "source:src/platform/core/seed.ts",
"source:src/platform/i18n/client.ts",
"source:src/platform/i18n/languages.ts",
"source:src/platform/performance/semanticReady.ts",
@@ -528,7 +528,6 @@
"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",
@@ -551,7 +550,6 @@
"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/SeedControls.tsx",
"source:src/features/generation/ui/useDebouncedDraftValue.ts",
"source:src/features/generation/ui/useDynamicPrompts.ts",
"source:src/features/identity/capabilities.ts",
@@ -677,6 +675,7 @@
"source:src/platform/browser/webLocks.ts",
"source:src/platform/core/concurrency.ts",
"source:src/platform/core/json.ts",
+ "source:src/platform/core/seed.ts",
"source:src/platform/i18n/client.ts",
"source:src/platform/i18n/languages.ts",
"source:src/platform/performance/semanticReady.ts",
@@ -725,6 +724,7 @@
"source:src/platform/ui/RetryBoundary.tsx",
"source:src/platform/ui/Row.tsx",
"source:src/platform/ui/Scrollable.tsx",
+ "source:src/platform/ui/SeedInput.tsx",
"source:src/platform/ui/SegmentTabs.tsx",
"source:src/platform/ui/SegmentedControl.tsx",
"source:src/platform/ui/Select.tsx",
diff --git a/invokeai/frontend/webv2/performance/browser-baseline.json b/invokeai/frontend/webv2/performance/browser-baseline.json
index c582260de2..d7990b14ed 100644
--- a/invokeai/frontend/webv2/performance/browser-baseline.json
+++ b/invokeai/frontend/webv2/performance/browser-baseline.json
@@ -524,7 +524,6 @@
"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",
@@ -592,6 +591,7 @@
"source:src/platform/browser/randomUuid.ts",
"source:src/platform/browser/sha256.ts",
"source:src/platform/core/concurrency.ts",
+ "source:src/platform/core/seed.ts",
"source:src/platform/i18n/client.ts",
"source:src/platform/i18n/languages.ts",
"source:src/platform/performance/semanticReady.ts",
@@ -955,7 +955,6 @@
"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",
@@ -1040,7 +1039,6 @@
"source:src/features/generation/ui/shared/GenerateCollapsibleSection.tsx",
"source:src/features/generation/ui/shared/GenerateFieldContextMenu.tsx",
"source:src/features/generation/ui/shared/GenerateToggleSwitch.tsx",
- "source:src/features/generation/ui/shared/SeedControls.tsx",
"source:src/features/generation/ui/shared/SeedField.tsx",
"source:src/features/generation/ui/shared/modelDefaultSettings.ts",
"source:src/features/generation/ui/useDebouncedDraftValue.ts",
@@ -1206,6 +1204,7 @@
"source:src/platform/browser/webLocks.ts",
"source:src/platform/core/concurrency.ts",
"source:src/platform/core/json.ts",
+ "source:src/platform/core/seed.ts",
"source:src/platform/i18n/client.ts",
"source:src/platform/i18n/languages.ts",
"source:src/platform/performance/semanticReady.ts",
@@ -1257,6 +1256,7 @@
"source:src/platform/ui/RetryBoundary.tsx",
"source:src/platform/ui/Row.tsx",
"source:src/platform/ui/Scrollable.tsx",
+ "source:src/platform/ui/SeedInput.tsx",
"source:src/platform/ui/SegmentTabs.tsx",
"source:src/platform/ui/SegmentedControl.tsx",
"source:src/platform/ui/Select.tsx",
@@ -1987,7 +1987,6 @@
"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",
@@ -2072,7 +2071,6 @@
"source:src/features/generation/ui/shared/GenerateCollapsibleSection.tsx",
"source:src/features/generation/ui/shared/GenerateFieldContextMenu.tsx",
"source:src/features/generation/ui/shared/GenerateToggleSwitch.tsx",
- "source:src/features/generation/ui/shared/SeedControls.tsx",
"source:src/features/generation/ui/shared/SeedField.tsx",
"source:src/features/generation/ui/shared/modelDefaultSettings.ts",
"source:src/features/generation/ui/useDebouncedDraftValue.ts",
@@ -2240,6 +2238,7 @@
"source:src/platform/browser/webLocks.ts",
"source:src/platform/core/concurrency.ts",
"source:src/platform/core/json.ts",
+ "source:src/platform/core/seed.ts",
"source:src/platform/i18n/client.ts",
"source:src/platform/i18n/languages.ts",
"source:src/platform/performance/semanticReady.ts",
@@ -2294,6 +2293,7 @@
"source:src/platform/ui/RetryBoundary.tsx",
"source:src/platform/ui/Row.tsx",
"source:src/platform/ui/Scrollable.tsx",
+ "source:src/platform/ui/SeedInput.tsx",
"source:src/platform/ui/SegmentTabs.tsx",
"source:src/platform/ui/SegmentedControl.tsx",
"source:src/platform/ui/Select.tsx",
@@ -3177,7 +3177,6 @@
"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",
@@ -3197,7 +3196,6 @@
"source:src/features/generation/queries.ts",
"source:src/features/generation/react.ts",
"source:src/features/generation/runtime.ts",
- "source:src/features/generation/seedControls.ts",
"source:src/features/generation/settings.ts",
"source:src/features/generation/ui/GenerateAdvancedFields.tsx",
"source:src/features/generation/ui/GenerateCanvasSections.tsx",
@@ -3263,7 +3261,6 @@
"source:src/features/generation/ui/shared/GenerateCollapsibleSection.tsx",
"source:src/features/generation/ui/shared/GenerateFieldContextMenu.tsx",
"source:src/features/generation/ui/shared/GenerateToggleSwitch.tsx",
- "source:src/features/generation/ui/shared/SeedControls.tsx",
"source:src/features/generation/ui/shared/SeedField.tsx",
"source:src/features/generation/ui/shared/modelDefaultSettings.ts",
"source:src/features/generation/ui/useDebouncedDraftValue.ts",
@@ -3495,6 +3492,7 @@
"source:src/platform/browser/webLocks.ts",
"source:src/platform/core/concurrency.ts",
"source:src/platform/core/json.ts",
+ "source:src/platform/core/seed.ts",
"source:src/platform/i18n/client.ts",
"source:src/platform/i18n/languages.ts",
"source:src/platform/performance/semanticReady.ts",
@@ -3547,6 +3545,7 @@
"source:src/platform/ui/RetryBoundary.tsx",
"source:src/platform/ui/Row.tsx",
"source:src/platform/ui/Scrollable.tsx",
+ "source:src/platform/ui/SeedInput.tsx",
"source:src/platform/ui/SegmentTabs.tsx",
"source:src/platform/ui/SegmentedControl.tsx",
"source:src/platform/ui/Select.tsx",
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index 6525e0d4b3..c870d5ca10 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -251,7 +251,23 @@
"view": "View",
"viewJson": "View JSON",
"widgetViewUnavailable": "Widget view unavailable.",
- "loading": "Loading…"
+ "loading": "Loading…",
+ "seedMode": {
+ "label": "Seed mode",
+ "random": "Random",
+ "randomDescription": "Choose a fresh starting seed for each submission.",
+ "fixed": "Fixed",
+ "fixedDescription": "Reuse the entered seed.",
+ "increment": "Increment",
+ "incrementDescription": "Use successive seeds, increasing by 1.",
+ "decrement": "Decrement",
+ "decrementDescription": "Use successive seeds, decreasing by 1."
+ },
+ "newSeed": "New seed",
+ "seedNextBatch": "Next batch: {{seed}}",
+ "seedNextBatchRange": "Next batch: {{first}} → {{last}}",
+ "decreaseValue": "Decrease value",
+ "increaseValue": "Increase value"
},
"app": {
"name": "Invoke AI",
@@ -2175,7 +2191,6 @@
"negativePrompt": "Negative prompt",
"negativePromptAdd": "Negative prompt…",
"negativePromptHide": "Turn off negative prompt",
- "newSeed": "New seed",
"noMatchingPrompts": "No matching prompts.",
"noMatchingTriggers": "No matching triggers.",
"noPromptHistoryYet": "No prompt history yet.",
@@ -2198,19 +2213,6 @@
"promptHistoryEntries": "Prompt history entries",
"promptHistoryKeyboardHelp": "Alt+Up/Down switches between prompts while focused.",
"recentSeeds": "Recent seeds",
- "seedMode": {
- "label": "Seed mode",
- "random": "Random",
- "randomDescription": "Choose a fresh starting seed for each submission.",
- "fixed": "Fixed",
- "fixedDescription": "Reuse the entered seed.",
- "increment": "Increment",
- "incrementDescription": "Use successive seeds, increasing by 1.",
- "decrement": "Decrement",
- "decrementDescription": "Use successive seeds, decreasing by 1."
- },
- "seedNextBatch": "Next batch: {{seed}}",
- "seedNextBatchRange": "Next batch: {{first}} → {{last}}",
"seedSummary": "{{mode}} · {{seed}}",
"renamePresetNamed": "Rename preset {{name}}",
"renamePresetTitle": "Rename preset",
diff --git a/invokeai/frontend/webv2/src/architecture/dependencyPolicy.test.ts b/invokeai/frontend/webv2/src/architecture/dependencyPolicy.test.ts
index dc5a8a17a8..16706c53bd 100644
--- a/invokeai/frontend/webv2/src/architecture/dependencyPolicy.test.ts
+++ b/invokeai/frontend/webv2/src/architecture/dependencyPolicy.test.ts
@@ -238,12 +238,6 @@ 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/seedControls')
- ).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.ts
index 27f409a8ae..c7617b018a 100644
--- a/invokeai/frontend/webv2/src/architecture/featureInterfaces.ts
+++ b/invokeai/frontend/webv2/src/architecture/featureInterfaces.ts
@@ -29,8 +29,6 @@ export const FEATURE_PUBLIC_INTERFACES: Readonly<Record<string, readonly string[
'queries',
'react',
'runtime',
- 'seed',
- 'seedControls',
'settings',
'widget',
],
diff --git a/invokeai/frontend/webv2/src/features/generation/components.ts b/invokeai/frontend/webv2/src/features/generation/components.ts
index fdd6ae878c..2895e7ff4f 100644
--- a/invokeai/frontend/webv2/src/features/generation/components.ts
+++ b/invokeai/frontend/webv2/src/features/generation/components.ts
@@ -13,6 +13,6 @@ export { NegativePromptField } from './ui/promptFields/NegativePromptField';
export { PositivePromptField } from './ui/promptFields/PositivePromptField';
export { PromptTextarea } from './ui/promptFields/PromptTextarea';
export { PROMPT_ATTENTION_TARGET_PROPS } from './ui/promptFields/promptAttentionHotkeys';
-export { SeedField, type SeedFieldPatch, type SeedFieldProps } from './ui/shared/SeedField';
+export { SeedField, type SeedFieldProps } from './ui/shared/SeedField';
export { FluxReduxControls } from './ui/reference-images/ReferenceImageControls';
export { GenerateCollapsibleSection as GenerationSettingsSection } from './ui/shared/GenerateCollapsibleSection';
diff --git a/invokeai/frontend/webv2/src/features/generation/contracts.ts b/invokeai/frontend/webv2/src/features/generation/contracts.ts
index 8df4ecd9fb..7dff1a82ce 100644
--- a/invokeai/frontend/webv2/src/features/generation/contracts.ts
+++ b/invokeai/frontend/webv2/src/features/generation/contracts.ts
@@ -1,4 +1,3 @@
export type * from './core/contracts';
export type * from './core/types';
-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.ts
index 8b3bf84ba6..064aab6f32 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/baseGenerationPolicies.ts
@@ -15,6 +15,7 @@ import {
SUPPORTED_GENERATE_BASES,
type SupportedGenerateBase,
} from '@features/generation/core/supportedBases';
+import { SEED_MAX } from '@platform/core/seed';
import type {
GenerateModelConfig,
@@ -50,7 +51,6 @@ import {
getPidDecoderBaseForMainBase,
getPidDimensionOverrides,
} from './pid';
-import { SEED_MAX } from './seed';
import {
clampDimension,
DEFAULT_HIDIFFUSION_T1_RATIO,
diff --git a/invokeai/frontend/webv2/src/features/generation/core/graph.ts b/invokeai/frontend/webv2/src/features/generation/core/graph.ts
index 1a47119542..09c12d8ca0 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/graph.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/graph.ts
@@ -5,6 +5,8 @@ import type {
ResultDestination,
} from '@features/generation/core/contracts';
+import { SEED_MAX } from '@platform/core/seed';
+
import type {
CompiledGenerateGraph,
ComponentModelConfig,
@@ -47,7 +49,6 @@ import {
import { addKrea2ConditioningEnhancers } from './krea2Conditioning';
import { addPidDecode, getPidDenoiseSize, getPidMetadata, shouldUsePidDecode } from './pidGraph';
import { getEffectiveReferenceImage } from './referenceImage';
-import { SEED_MAX } from './seed';
const getCompatibleComponentSource = (
settings: GenerateSettings,
diff --git a/invokeai/frontend/webv2/src/features/generation/core/settings.test.ts b/invokeai/frontend/webv2/src/features/generation/core/settings.test.ts
index f6b70d94a7..81fe104a7a 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/settings.test.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/settings.test.ts
@@ -1,4 +1,12 @@
import { seedArchitectureCapabilities } from '@features/generation/core/architectureCapabilities.testing';
+import {
+ getSeedSequenceLength,
+ getSeedStep,
+ isSeedMode,
+ planSeedSubmission,
+ SEED_MAX,
+ wrapSeed,
+} from '@platform/core/seed';
import { describe, expect, it } from 'vitest';
import type {
@@ -11,7 +19,6 @@ import type {
} from './types';
import { getGenerationDimensions } from './baseGenerationPolicies';
-import { getSeedSequenceLength, getSeedStep, isSeedMode, planSeedSubmission, SEED_MAX, wrapSeed } from './seed';
import {
calculateNewSize,
clampDimension,
diff --git a/invokeai/frontend/webv2/src/features/generation/core/settings.ts b/invokeai/frontend/webv2/src/features/generation/core/settings.ts
index 3227ebce3c..ba44c1c4c7 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/settings.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/settings.ts
@@ -1,3 +1,5 @@
+import { isSeedMode } from '@platform/core/seed';
+
import type { DynamicPromptsConfig } from './dynamicPrompts';
import type {
AspectRatioId,
@@ -28,7 +30,6 @@ 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 }> = {
diff --git a/invokeai/frontend/webv2/src/features/generation/core/types.ts b/invokeai/frontend/webv2/src/features/generation/core/types.ts
index 966eb9f6b6..a9e5c80178 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/seed';
+import type { SeedMode } from '@platform/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.ts
deleted file mode 100644
index 9098d50e5e..0000000000
--- a/invokeai/frontend/webv2/src/features/generation/seed.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
- * 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/seedControls.ts b/invokeai/frontend/webv2/src/features/generation/seedControls.ts
deleted file mode 100644
index 7a4a5ea0d1..0000000000
--- a/invokeai/frontend/webv2/src/features/generation/seedControls.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-/**
- * The seed mode menu and sequence preview on their own, for hosts that own the
- * seed value and run count themselves (workflow node inputs). Their 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,
- SeedSequencePreview,
- type SeedModeMenuProps,
- type SeedSequencePreviewProps,
-} from './ui/shared/SeedControls';
diff --git a/invokeai/frontend/webv2/src/features/generation/settings.ts b/invokeai/frontend/webv2/src/features/generation/settings.ts
index 6fd259d8dd..cfd82781cb 100644
--- a/invokeai/frontend/webv2/src/features/generation/settings.ts
+++ b/invokeai/frontend/webv2/src/features/generation/settings.ts
@@ -73,17 +73,6 @@ export {
type RebalancePreset,
} from './core/conditioningRebalance';
export { MIN_BATCH_COUNT, sanitizeBatchCount } from './core/batch';
-export {
- getSeedStep,
- isSeedMode,
- planSeedSubmission,
- SEED_MAX,
- SEED_MODES,
- wrapSeed,
- type SeedMode,
- type SeedStep,
- type SeedSubmissionPlan,
-} from './core/seed';
export {
createDynamicPromptsSampleSeed,
DYNAMIC_PROMPTS_DEFAULT_MAX_PROMPTS,
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateRenderSection.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateRenderSection.browser.test.tsx
index ca38a95768..1c515a222a 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateRenderSection.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateRenderSection.browser.test.tsx
@@ -34,7 +34,23 @@ void i18n.use(initReactI18next).init({
resources: {
en: {
translation: {
- common: { seed: 'Seed' },
+ common: {
+ newSeed: 'New seed',
+ seed: 'Seed',
+ seedMode: {
+ decrement: 'Decrement',
+ decrementDescription: 'Use successive seeds, decreasing by 1.',
+ fixed: 'Fixed',
+ fixedDescription: 'Reuse the entered seed.',
+ increment: 'Increment',
+ incrementDescription: 'Use successive seeds, increasing by 1.',
+ label: 'Seed mode',
+ random: 'Random',
+ randomDescription: 'Choose a fresh starting seed for each submission.',
+ },
+ seedNextBatch: 'Next batch: {{seed}}',
+ seedNextBatchRange: 'Next batch: {{first}} → {{last}}',
+ },
widgets: {
generate: {
// Verbatim from `public/locales/en.json`: Ideogram 4's overrides really are labelled
@@ -48,24 +64,10 @@ void i18n.use(initReactI18next).init({
ideogram4PresetDerived: 'Set by the sampler preset unless overridden.',
ideogram4SamplerPreset: 'Sampler preset',
ideogram4Steps: 'Steps',
- newSeed: 'New seed',
override: 'Override',
recentSeeds: 'Recent seeds',
render: 'Render',
scheduler: 'Scheduler',
- seedMode: {
- decrement: 'Decrement',
- decrementDescription: 'Use successive seeds, decreasing by 1.',
- fixed: 'Fixed',
- fixedDescription: 'Reuse the entered seed.',
- increment: 'Increment',
- incrementDescription: 'Use successive seeds, increasing by 1.',
- label: 'Seed mode',
- random: 'Random',
- randomDescription: 'Choose a fresh starting seed for each submission.',
- },
- seedNextBatch: 'Next batch: {{seed}}',
- seedNextBatchRange: 'Next batch: {{first}} → {{last}}',
seedSummary: '{{mode}} · {{seed}}',
steps: 'Steps',
useSeed: 'Use seed {{seed}}',
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateRenderSection.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateRenderSection.tsx
index 69dace30a5..e763545a26 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateRenderSection.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateRenderSection.tsx
@@ -344,11 +344,11 @@ export const GenerateRenderSection = ({
{policy.ui.seedVisible ? (
<Badge size="xs">
{settings.seedMode === 'random'
- ? t('widgets.generate.seedMode.random')
+ ? t('common.seedMode.random')
: settings.seedMode === 'fixed'
? settings.seed
: t('widgets.generate.seedSummary', {
- mode: t(`widgets.generate.seedMode.${settings.seedMode}`),
+ mode: t(`common.seedMode.${settings.seedMode}`),
seed: settings.seed,
})}
</Badge>
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/shared/SeedControls.tsx b/invokeai/frontend/webv2/src/features/generation/ui/shared/SeedControls.tsx
deleted file mode 100644
index afdef847cc..0000000000
--- a/invokeai/frontend/webv2/src/features/generation/ui/shared/SeedControls.tsx
+++ /dev/null
@@ -1,115 +0,0 @@
-/* oxlint-disable react-perf/jsx-no-new-function-as-prop, react-perf/jsx-no-jsx-as-prop */
-import type { SeedMode, SeedSubmissionPlan } 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;
-export const TABULAR_NUMS = { fontVariantNumeric: 'tabular-nums' } 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;
- /** A second tooltip line for hosts that need to say what one step means (a queued run, not a loop pass). */
- description?: 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, description, onChange, 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}`);
- const accessibleName = `${label}: ${valueLabel}`;
-
- return (
- <Menu.Root ids={triggerIds} positioning={SEED_MODE_MENU_POSITIONING}>
- {/* The visible label may truncate in a dense row; the full name always reads here and in the tooltip. */}
- <Tooltip
- content={
- description ? (
- <Stack gap="0.5">
- <Text>{accessibleName}</Text>
- <Text color="fg.subtle">{description}</Text>
- </Stack>
- ) : (
- accessibleName
- )
- }
- ids={triggerIds}
- >
- <Menu.Trigger asChild>
- <Button aria-label={accessibleName} flexShrink={0} gap="1" maxW="9rem" minW="0" size="xs" variant="outline">
- <Icon as={SEED_MODE_ICONS[value]} boxSize="3.5" color="fg.muted" flexShrink={0} />
- <Text as="span" minW="0" truncate>
- {valueLabel}
- </Text>
- <Icon as={ChevronDownIcon} boxSize="3" color="fg.muted" flexShrink={0} />
- </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>
- );
-};
-
-export interface SeedSequencePreviewProps {
- /** Id the seed input names in `aria-describedby`. */
- id?: string;
- plan: Pick<SeedSubmissionPlan, 'lastSeed' | 'sequenceLength' | 'startSeed'>;
-}
-
-/** Where the next submission's seeds start and end; the host resolves the run count it plans with. */
-export const SeedSequencePreview = ({ id, plan }: SeedSequencePreviewProps) => {
- const { t } = useTranslation();
-
- return (
- <Text color="fg.subtle" css={TABULAR_NUMS} data-testid="seed-sequence-preview" fontSize="2xs" id={id}>
- {plan.sequenceLength > 1
- ? t('widgets.generate.seedNextBatchRange', { first: plan.startSeed, last: plan.lastSeed })
- : t('widgets.generate.seedNextBatch', { seed: plan.startSeed })}
- </Text>
- );
-};
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/shared/SeedField.tsx b/invokeai/frontend/webv2/src/features/generation/ui/shared/SeedField.tsx
index 70e52ce069..54b77e11ed 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/shared/SeedField.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/shared/SeedField.tsx
@@ -1,24 +1,11 @@
-/* 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/seed';
+import type { SeedInputPatch } from '@platform/ui/SeedInput';
import type { ReactNode } from 'react';
-import { HStack, InputGroup, NumberInput, Stack } from '@chakra-ui/react';
-import { planSeedSubmission, SEED_MAX } from '@features/generation/core/seed';
-import { IconButton } from '@platform/ui/Button';
+import { Stack } from '@chakra-ui/react';
+import { planSeedSubmission, type SeedMode } from '@platform/core/seed';
import { Field } from '@platform/ui/Field';
-import { DicesIcon } from 'lucide-react';
-import { useId } from 'react';
-import { useTranslation } from 'react-i18next';
-
-import { SeedModeMenu, SeedSequencePreview, TABULAR_NUMS } from './SeedControls';
-
-const SEED_END_ELEMENT_PROPS = { pointerEvents: 'auto', pr: '0.5' } as const;
-
-export interface SeedFieldPatch {
- seed?: number;
- seedMode?: SeedMode;
-}
+import { SeedInput } from '@platform/ui/SeedInput';
export interface SeedFieldProps {
label: string;
@@ -31,17 +18,12 @@ export interface SeedFieldProps {
/** Concrete prompts the next submission carries; one unless dynamic prompts expand it. */
promptCount?: number;
seedBehaviour?: DynamicPromptsSeedBehaviour;
- onCommit: (patch: SeedFieldPatch) => void;
+ onCommit: (patch: SeedInputPatch) => void;
/** Rows under the input, such as recent seeds. */
children?: ReactNode;
}
-/**
- * The seed row every seeded widget shares: the input with the one-shot
- * new-seed action inside it and the mode menu beside it. Random quiets the
- * input but keeps its value; the stepping modes show the seed the next
- * submission starts from and preview where it will end.
- */
+/** The labelled seed row of the Generate-shaped widgets: the shared control under a field label, with its sequence sized by the widget's own batch. */
export const SeedField = ({
batchCount,
children,
@@ -53,8 +35,6 @@ export const SeedField = ({
seedBehaviour = 'per-iteration',
seedMode,
}: SeedFieldProps) => {
- const { t } = useTranslation();
- const previewId = useId();
const isRandom = seedMode === 'random';
const plan =
seedMode === 'increment' || seedMode === 'decrement'
@@ -64,46 +44,7 @@ export const SeedField = ({
return (
<Field error={isRandom ? undefined : error} hint="seed" label={label}>
<Stack gap="1" w="full">
- <HStack gap="1">
- <NumberInput.Root
- disabled={isRandom}
- max={SEED_MAX}
- min={0}
- size="xs"
- value={String(seed)}
- w="full"
- onValueChange={({ valueAsNumber }) => {
- if (Number.isFinite(valueAsNumber)) {
- onCommit({ seed: valueAsNumber });
- }
- }}
- >
- <InputGroup
- endElement={
- <IconButton
- aria-label={t('widgets.generate.newSeed')}
- color="fg.muted"
- disabled={isRandom}
- size="2xs"
- title={t('widgets.generate.newSeed')}
- variant="ghost"
- onClick={() => onCommit({ seed: Math.floor(Math.random() * SEED_MAX) })}
- >
- <DicesIcon />
- </IconButton>
- }
- endElementProps={SEED_END_ELEMENT_PROPS}
- >
- <NumberInput.Input
- aria-describedby={plan ? previewId : undefined}
- aria-label={label}
- css={TABULAR_NUMS}
- />
- </InputGroup>
- </NumberInput.Root>
- <SeedModeMenu value={seedMode} onChange={(nextMode) => onCommit({ seedMode: nextMode })} />
- </HStack>
- {plan ? <SeedSequencePreview id={previewId} plan={plan} /> : null}
+ <SeedInput ariaLabel={label} plan={plan} seed={seed} seedMode={seedMode} onCommit={onCommit} />
{children}
</Stack>
</Field>
diff --git a/invokeai/frontend/webv2/src/features/queue/core/promptBatch.ts b/invokeai/frontend/webv2/src/features/queue/core/promptBatch.ts
index 7d95ae4c3c..f3f29b9399 100644
--- a/invokeai/frontend/webv2/src/features/queue/core/promptBatch.ts
+++ b/invokeai/frontend/webv2/src/features/queue/core/promptBatch.ts
@@ -12,7 +12,8 @@
* route itself.
*/
-const SEED_MAX = 4_294_967_295;
+import { SEED_MAX } from '@platform/core/seed';
+
export const MAX_QUEUE_BATCH_ITEMS = 10_000;
export type QueuePromptSeedBehaviour = 'per-iteration' | 'per-image';
diff --git a/invokeai/frontend/webv2/src/features/upscale/core/settings.ts b/invokeai/frontend/webv2/src/features/upscale/core/settings.ts
index 487e8a6320..a787da5e3c 100644
--- a/invokeai/frontend/webv2/src/features/upscale/core/settings.ts
+++ b/invokeai/frontend/webv2/src/features/upscale/core/settings.ts
@@ -14,7 +14,6 @@ import {
isLoraModelConfig,
isMainModelConfig,
isModelIdentifierConfig,
- isSeedMode,
isVaeCompatibleWithGenerateModel,
isVaeModelConfig,
MAX_NEGATIVE_PROMPT_HEIGHT_PX,
@@ -22,8 +21,8 @@ import {
MIN_NEGATIVE_PROMPT_HEIGHT_PX,
MIN_POSITIVE_PROMPT_HEIGHT_PX,
sanitizeBatchCount,
- SEED_MAX,
} from '@features/generation/settings';
+import { isSeedMode, SEED_MAX } from '@platform/core/seed';
import type { SpandrelModelConfig, TileControlNetModelConfig, UpscaleWidgetValues } from './types';
diff --git a/invokeai/frontend/webv2/src/features/upscale/core/types.ts b/invokeai/frontend/webv2/src/features/upscale/core/types.ts
index 92c9f7fa57..ac3f9dada8 100644
--- a/invokeai/frontend/webv2/src/features/upscale/core/types.ts
+++ b/invokeai/frontend/webv2/src/features/upscale/core/types.ts
@@ -4,10 +4,10 @@ import type {
ImageWithDims,
MainModelConfig,
ModelIdentifierConfig,
- SeedMode,
VaeModelConfig,
VaePrecision,
} from '@features/generation/contracts';
+import type { SeedMode } from '@platform/core/seed';
export type SpandrelModelConfig = ModelIdentifierConfig & { type: 'spandrel_image_to_image' };
export type TileControlNetModelConfig = ModelIdentifierConfig & { type: 'controlnet' };
diff --git a/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx b/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx
index 7a772b8cef..e7170e8eaf 100644
--- a/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx
+++ b/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx
@@ -15,13 +15,12 @@ import {
} from '@chakra-ui/react';
import { GenerationSettingsSection, SeedField } from '@features/generation/components';
import {
- SCHEDULER_OPTIONS,
getDefaultLoraWeight,
isLoraCompatibleWithModel,
isLoraModelConfig,
isMainModelConfig,
isVaeModelConfig,
- SEED_MAX,
+ SCHEDULER_OPTIONS,
} from '@features/generation/settings';
import { ensureModelsLoaded, useModelsSelector } from '@features/models';
import { ModelSelect } from '@features/models/react';
@@ -45,6 +44,7 @@ import {
UPSCALE_TILE_SIZE_MAX,
UPSCALE_TILE_SIZE_MIN,
} from '@features/upscale/core/settings';
+import { SEED_MAX } from '@platform/core/seed';
import { useMountEffect } from '@platform/react/useMountEffect';
import { Combobox, Field, Select, Tooltip } from '@platform/ui';
import { SliderNumberField } from '@platform/ui/SliderNumberField';
diff --git a/invokeai/frontend/webv2/src/features/video/core/settings.ts b/invokeai/frontend/webv2/src/features/video/core/settings.ts
index 17370bf97c..e5819307fc 100644
--- a/invokeai/frontend/webv2/src/features/video/core/settings.ts
+++ b/invokeai/frontend/webv2/src/features/video/core/settings.ts
@@ -6,7 +6,6 @@ import {
isLoraModelConfig,
isMainModelConfig,
isModelIdentifierConfig,
- isSeedMode,
isVaeModelConfig,
MAX_NEGATIVE_PROMPT_HEIGHT_PX,
MAX_POSITIVE_PROMPT_HEIGHT_PX,
@@ -14,6 +13,7 @@ import {
MIN_POSITIVE_PROMPT_HEIGHT_PX,
sanitizeBatchCount,
} from '@features/generation/settings';
+import { isSeedMode } from '@platform/core/seed';
import type {
MiniMaxH3TargetResolution,
diff --git a/invokeai/frontend/webv2/src/features/video/core/types.ts b/invokeai/frontend/webv2/src/features/video/core/types.ts
index 78e90ff9ed..6948e5c5b5 100644
--- a/invokeai/frontend/webv2/src/features/video/core/types.ts
+++ b/invokeai/frontend/webv2/src/features/video/core/types.ts
@@ -3,9 +3,9 @@ import type {
ImageWithDims,
MainModelConfig,
ModelIdentifierConfig,
- SeedMode,
VaeModelConfig,
} from '@features/generation/contracts';
+import type { SeedMode } from '@platform/core/seed';
/**
* How a video generation is conditioned. There is no explicit mode selector:
diff --git a/invokeai/frontend/webv2/src/features/video/core/videoPolicies.ts b/invokeai/frontend/webv2/src/features/video/core/videoPolicies.ts
index 2cf378c18b..3e65ea30a1 100644
--- a/invokeai/frontend/webv2/src/features/video/core/videoPolicies.ts
+++ b/invokeai/frontend/webv2/src/features/video/core/videoPolicies.ts
@@ -12,8 +12,8 @@ import {
isLoraCompatibleWithModel,
isLoraModelConfig,
isWanLoraTargetingMain,
- SEED_MAX,
} from '@features/generation/settings';
+import { SEED_MAX } from '@platform/core/seed';
import type { VideoAspectRatioId, VideoGenerationMode, VideoSettings, VideoTargetResolution } from './types';
diff --git a/invokeai/frontend/webv2/src/features/video/core/widgetValues.ts b/invokeai/frontend/webv2/src/features/video/core/widgetValues.ts
index f85af6279e..c2ed5ca3ec 100644
--- a/invokeai/frontend/webv2/src/features/video/core/widgetValues.ts
+++ b/invokeai/frontend/webv2/src/features/video/core/widgetValues.ts
@@ -4,7 +4,8 @@ import type {
ModelIdentifierConfig,
} from '@features/generation/contracts';
-import { isLoraCompatibleWithModel, isLoraModelConfig, SEED_MAX } from '@features/generation/settings';
+import { isLoraCompatibleWithModel, isLoraModelConfig } from '@features/generation/settings';
+import { SEED_MAX } from '@platform/core/seed';
import type { VideoWidgetValues } from './types';
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.ts b/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.ts
index 8620a94391..1e4bad154e 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.ts
@@ -1,6 +1,4 @@
-import type { SeedMode } from '@features/generation/contracts';
-
-import { isSeedMode, planSeedSubmission, SEED_MAX, wrapSeed } from '@features/generation/seed';
+import { isSeedMode, planSeedSubmission, SEED_MAX, type SeedMode, wrapSeed } from '@platform/core/seed';
import type { CompiledWorkflowGraph, WorkflowBackendGraph } from './graphContracts';
import type {
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/document.ts b/invokeai/frontend/webv2/src/features/workflow/core/document.ts
index dc27372e50..f74aa24334 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/document.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/document.ts
@@ -1,4 +1,4 @@
-import type { SeedMode } from '@features/generation/contracts';
+import type { SeedMode } from '@platform/core/seed';
import type {
ContainerFormElement,
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/types.ts b/invokeai/frontend/webv2/src/features/workflow/core/types.ts
index 96db366020..0e4d503f02 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/types.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/types.ts
@@ -9,7 +9,7 @@
* editor, the workflow library backend, and this workbench.
*/
-import type { SeedMode } from '@features/generation/contracts';
+import type { SeedMode } from '@platform/core/seed';
export type FieldCardinality = 'SINGLE' | 'COLLECTION' | 'SINGLE_OR_COLLECTION';
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.ts b/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.ts
index 54e07df20b..8d4952aa09 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.ts
@@ -1,4 +1,4 @@
-import { SEED_MODES } from '@features/generation/seed';
+import { SEED_MODES } from '@platform/core/seed';
import { z } from 'zod';
import type {
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.browser.test.tsx
index e1ef1906a9..4c5eb28969 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.browser.test.tsx
@@ -685,7 +685,8 @@ describe('WorkflowFieldInput seed inputs', () => {
});
});
};
- const seedInput = () => host.querySelector<HTMLInputElement>('input[type="number"]');
+ const seedInput = () => host.querySelector<HTMLInputElement>('input[aria-label="Seed"]');
+ const diceButton = () => host.querySelector<HTMLButtonElement>('button[aria-label="common.newSeed"]');
const modeTrigger = () => host.querySelector<HTMLButtonElement>('button[aria-haspopup="menu"]');
const menuItem = (mode: string) =>
document.querySelector<HTMLElement>(`[role="menuitemradio"][data-value="${mode}"]`);
@@ -695,6 +696,7 @@ describe('WorkflowFieldInput seed inputs', () => {
expect(seedInput()?.value).toBe('42');
expect(modeTrigger()).toBeNull();
+ expect(diceButton()).toBeNull();
await renderField({ ...SEED_TEMPLATE, name: 'steps' } as FieldInputTemplate, 20, vi.fn(), undefined, {
onSeedModeChange: vi.fn(),
@@ -708,19 +710,20 @@ describe('WorkflowFieldInput seed inputs', () => {
const onChange = vi.fn();
const onSeedModeChange = vi.fn();
- // Box the row at the node width so the width assertions below mean what they say.
+ // Box the row at the node width so the width assertions below mean what they say; the
+ // largest seed has to fit beside the stepper, the dice and the trigger without scrolling.
host.style.width = '18rem';
- await renderField(SEED_TEMPLATE, 42, onChange, undefined, { onSeedModeChange, seedMode: 'fixed' });
+ await renderField(SEED_TEMPLATE, 4_294_967_295, onChange, undefined, { onSeedModeChange, seedMode: 'fixed' });
expect(seedInput()?.disabled).toBe(false);
// Without i18n the label is the long key, which stands in for a long translation: the
// trigger stays bounded and truncates, its accessible name stays whole, and the number
// input keeps a usable width beside it.
- expect(modeTrigger()?.getAttribute('aria-label')).toBe(
- 'widgets.generate.seedMode.label: widgets.generate.seedMode.fixed'
- );
+ expect(modeTrigger()?.getAttribute('aria-label')).toBe('common.seedMode.label: common.seedMode.fixed');
expect(modeTrigger()?.getBoundingClientRect().width).toBeLessThanOrEqual(144);
- expect(seedInput()?.getBoundingClientRect().width).toBeGreaterThan(80);
+ expect((seedInput() as HTMLInputElement).scrollWidth).toBeLessThanOrEqual(
+ (seedInput() as HTMLInputElement).clientWidth
+ );
// xyflow reads `.nokey` to leave a control's keys alone; the trigger and the portaled menu both need it,
// or arrows nudge the node and Backspace deletes it while the menu is in use.
expect(modeTrigger()?.closest('.nokey')).not.toBeNull();
@@ -744,7 +747,7 @@ describe('WorkflowFieldInput seed inputs', () => {
const preview = host.querySelector<HTMLElement>('[data-testid="seed-sequence-preview"]');
// Without i18n resources the key renders, carrying the interpolated bounds.
- expect(preview?.textContent).toBe('widgets.generate.seedNextBatchRange');
+ expect(preview?.textContent).toBe('common.seedNextBatchRange');
expect(seedInput()?.getAttribute('aria-describedby')).toBe(preview?.id);
await renderField(SEED_TEMPLATE, 42, vi.fn(), undefined, { onSeedModeChange: vi.fn(), seedMode: 'fixed' });
@@ -759,15 +762,28 @@ describe('WorkflowFieldInput seed inputs', () => {
seedMode: 'increment',
});
- expect(host.querySelector('[data-testid="seed-sequence-preview"]')?.textContent).toBe(
- 'widgets.generate.seedNextBatchRange'
- );
+ expect(host.querySelector('[data-testid="seed-sequence-preview"]')?.textContent).toBe('common.seedNextBatchRange');
+ });
+
+ it('rolls a new seed from the dice and writes it to the field as an integer in range', async () => {
+ const onChange = vi.fn();
+
+ await renderField(SEED_TEMPLATE, 42, onChange, undefined, { onSeedModeChange: vi.fn(), seedMode: 'fixed' });
+ await settle(() => diceButton()?.click());
+
+ expect(onChange).toHaveBeenCalledTimes(1);
+ const rolled = onChange.mock.calls[0]?.[0] as number;
+
+ expect(Number.isInteger(rolled)).toBe(true);
+ expect(rolled).toBeGreaterThanOrEqual(0);
+ expect(rolled).toBeLessThanOrEqual(4_294_967_295);
});
- it('quiets the value in random mode but keeps it on show', async () => {
+ it('quiets the value and the dice in random mode but keeps the seed on show', async () => {
await renderField(SEED_TEMPLATE, 42, vi.fn(), undefined, { onSeedModeChange: vi.fn(), seedMode: 'random' });
expect(seedInput()?.disabled).toBe(true);
expect(seedInput()?.value).toBe('42');
+ expect(diceButton()?.disabled).toBe(true);
});
});
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.tsx
index c2d64007d7..0caea0e7d1 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.tsx
@@ -1,7 +1,7 @@
-import type { SeedMode } from '@features/generation/contracts';
import type { ModelConfig, ModelTaxonomyType } from '@features/models/react';
import type { FieldInputTemplate } from '@features/workflow/contracts';
import type { LoraFieldCollectionEntry } from '@features/workflow/utility';
+import type { SeedInputPatch } from '@platform/ui/SeedInput';
import {
Badge,
@@ -31,8 +31,6 @@ import { getSelectedGalleryImageFromValues } from '@features/gallery/contracts';
import { GalleryPickerPopover } from '@features/gallery/picker';
import { invalidateGallery } from '@features/gallery/queries';
import { galleryImageUrls, galleryVideoUrls } from '@features/gallery/utility';
-import { planSeedSubmission, wrapSeed } from '@features/generation/seed';
-import { SeedModeMenu, SeedSequencePreview } from '@features/generation/seedControls';
import { DEFAULT_LORA_WEIGHT_CONFIG, sanitizeBatchCount, SCHEDULER_OPTIONS } from '@features/generation/settings';
import { isInvocationNode } from '@features/workflow/contracts';
import { isSeedInputField } from '@features/workflow/graph';
@@ -47,6 +45,7 @@ import {
isLoraFieldCollectionEntry,
toLoraFieldCollectionList,
} from '@features/workflow/utility';
+import { planSeedSubmission, type SeedMode, wrapSeed } from '@platform/core/seed';
import {
assertAccountScopeCurrent,
captureAccountScope,
@@ -69,6 +68,7 @@ import {
Tooltip,
} from '@platform/ui';
import { MiddleTruncate } from '@platform/ui/MiddleTruncate';
+import { SeedInput } from '@platform/ui/SeedInput';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { FilmIcon, ImageIcon, Trash2Icon } from 'lucide-react';
import { lazy, Suspense, useCallback, useEffect, useId, useMemo, useRef, useState, type ChangeEvent } from 'react';
@@ -161,15 +161,7 @@ const StringInput = ({ id, invalid, onChange, template, value }: WorkflowFieldIn
);
};
-const NumericInput = ({
- describedBy,
- disabled,
- id,
- invalid,
- onChange,
- template,
- value,
-}: WorkflowFieldInputProps & { describedBy?: string; disabled?: boolean }) => {
+const NumericInput = ({ id, invalid, onChange, template, value }: WorkflowFieldInputProps) => {
const isInteger = template.type.name === 'IntegerField';
const numericValue = typeof value === 'number' && Number.isFinite(value) ? value : '';
const min = template.minimum ?? template.exclusiveMinimum ?? undefined;
@@ -187,10 +179,8 @@ const NumericInput = ({
return (
<Input
- aria-describedby={describedBy}
aria-label={template.title}
className="nodrag"
- disabled={disabled}
id={id ? `${id}-number-input` : undefined}
max={max !== undefined ? String(max) : undefined}
min={min !== undefined ? String(min) : undefined}
@@ -206,30 +196,25 @@ const NumericInput = ({
};
/**
- * A seed input with its mode beside it. Random quiets the value the way the
- * Generate seed does: the entered seed stays in reserve for Fixed. The mode
- * applies between queued runs; a loop inside a run reuses that run's seed.
- *
- * `nokey` on the row and the portaled menu keeps xyflow's node key handling
- * out of the trigger and the open menu: arrows would nudge the selected node
- * and Backspace would delete it (zag lets unhandled keys propagate).
+ * The shared seed control under a workflow row. The workflow owns the value
+ * and its run count, so the stepping preview is planned here from the
+ * workflow's own iterations; an empty field runs from the template default,
+ * as the plan does. `nokey` keeps xyflow's node key handling out of the row
+ * and the portaled menu: arrows would nudge the node and Backspace delete it.
*/
-const SeedInput = ({
+const WorkflowSeedInput = ({
+ id,
+ invalid,
+ onChange,
onSeedModeChange,
seedMode,
- ...props
+ template,
+ value,
}: WorkflowFieldInputProps & { onSeedModeChange: (seedMode: SeedMode) => void; seedMode: SeedMode }) => {
const { t } = useTranslation();
- const previewId = useId();
- // The workflow's own run count: the stride the next submission takes from this seed.
const batchCount = useWorkflowProjectSelector((project) => sanitizeBatchCount(project.workflowValues.batchCount));
- // An empty field runs from the template default, as the plan does.
- const authoredSeed =
- typeof props.value === 'number'
- ? props.value
- : typeof props.template.default === 'number'
- ? props.template.default
- : 0;
+ const seed = typeof value === 'number' ? value : undefined;
+ const authoredSeed = seed ?? (typeof template.default === 'number' ? template.default : 0);
const plan =
seedMode === 'increment' || seedMode === 'decrement'
? planSeedSubmission({
@@ -240,20 +225,32 @@ const SeedInput = ({
startSeed: wrapSeed(authoredSeed),
})
: null;
+ const onCommit = useCallback(
+ (patch: SeedInputPatch) => {
+ if (patch.seed !== undefined) {
+ onChange(patch.seed);
+ }
+
+ if (patch.seedMode !== undefined) {
+ onSeedModeChange(patch.seedMode);
+ }
+ },
+ [onChange, onSeedModeChange]
+ );
return (
- <Stack className="nodrag nokey" gap="1" w="full">
- <HStack gap="1" w="full">
- <NumericInput {...props} describedBy={plan ? previewId : undefined} disabled={seedMode === 'random'} />
- <SeedModeMenu
- contentClassName="nokey"
- description={t('nodes.seedModeTooltip')}
- value={seedMode}
- onChange={onSeedModeChange}
- />
- </HStack>
- {plan ? <SeedSequencePreview id={previewId} plan={plan} /> : null}
- </Stack>
+ <SeedInput
+ ariaLabel={template.title}
+ className="nodrag nokey"
+ contentClassName="nokey"
+ description={t('nodes.seedModeTooltip')}
+ id={id ? `${id}-number-input` : undefined}
+ invalid={invalid}
+ plan={plan}
+ seed={seed}
+ seedMode={seedMode}
+ onCommit={onCommit}
+ />
);
};
@@ -1229,7 +1226,13 @@ export const WorkflowFieldInput = (props: WorkflowFieldInputProps) => {
}
if (props.onSeedModeChange && isSeedInputField(props.template)) {
- return <SeedInput {...props} onSeedModeChange={props.onSeedModeChange} seedMode={props.seedMode ?? 'fixed'} />;
+ return (
+ <WorkflowSeedInput
+ {...props}
+ onSeedModeChange={props.onSeedModeChange}
+ seedMode={props.seedMode ?? 'fixed'}
+ />
+ );
}
return <NumericInput {...props} />;
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/linear/NodeFieldControl.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/linear/NodeFieldControl.tsx
index 9703fb9773..15d5dc972a 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/linear/NodeFieldControl.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/linear/NodeFieldControl.tsx
@@ -1,4 +1,4 @@
-import type { SeedMode } from '@features/generation/contracts';
+import type { SeedMode } from '@platform/core/seed';
import { Alert, Field, HStack, Icon, Input, Stack, Text } from '@chakra-ui/react';
import { isInvocationNode, type NodeFieldFormElement, type ProjectGraphState } from '@features/workflow/contracts';
diff --git a/invokeai/frontend/webv2/src/features/generation/core/seed.ts b/invokeai/frontend/webv2/src/platform/core/seed.ts
similarity index 87%
rename from invokeai/frontend/webv2/src/features/generation/core/seed.ts
rename to invokeai/frontend/webv2/src/platform/core/seed.ts
index 61b8ec2063..14811d22f5 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/seed.ts
+++ b/invokeai/frontend/webv2/src/platform/core/seed.ts
@@ -1,10 +1,9 @@
/**
* 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.
+ * dependencies) so a graph compiler can import it without becoming
+ * side-effectful; rolldown would otherwise materialise that compiler's facade
+ * and pull the canvas-layer chunk into the settings and palette overlays.
*/
export const SEED_MAX = 4_294_967_295;
@@ -29,7 +28,7 @@ export const wrapSeed = (seed: number): number => {
export interface SeedSequenceInput {
batchCount: number;
- /** Concrete prompts the submission carries; one unless dynamic prompts expanded it. */
+ /** Concrete prompts the submission carries; one unless the host expands a prompt into several. */
promptCount: number;
seedBehaviour: 'per-image' | 'per-iteration';
seedMode: SeedMode;
diff --git a/invokeai/frontend/webv2/src/platform/ui/SeedInput.browser.test.tsx b/invokeai/frontend/webv2/src/platform/ui/SeedInput.browser.test.tsx
new file mode 100644
index 0000000000..945b158f14
--- /dev/null
+++ b/invokeai/frontend/webv2/src/platform/ui/SeedInput.browser.test.tsx
@@ -0,0 +1,204 @@
+/* oxlint-disable react-perf/jsx-no-new-function-as-prop */
+import type { SeedMode } from '@platform/core/seed';
+
+import { ChakraProvider } from '@chakra-ui/react';
+import { planSeedSubmission } from '@platform/core/seed';
+import { system } from '@theme/system';
+import { act, useState } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { userEvent } from 'vitest/browser';
+
+import { SeedInput, type SeedInputPatch } from './SeedInput';
+
+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+
+let host: HTMLDivElement;
+let root: Root;
+
+beforeEach(() => {
+ host = document.createElement('div');
+ document.body.append(host);
+ root = createRoot(host);
+});
+
+afterEach(async () => {
+ await act(() => root.unmount());
+ host.remove();
+});
+
+/** A host that owns the seed the way every widget does: the control only proposes patches. */
+const Host = ({
+ id,
+ initialSeed,
+ onCommit,
+ seedMode,
+}: {
+ id?: string;
+ initialSeed: number | undefined;
+ onCommit: (patch: SeedInputPatch) => void;
+ seedMode: SeedMode;
+}) => {
+ const [seed, setSeed] = useState(initialSeed);
+ const plan =
+ seedMode === 'increment' || seedMode === 'decrement'
+ ? planSeedSubmission({
+ batchCount: 3,
+ promptCount: 1,
+ seedBehaviour: 'per-iteration',
+ seedMode,
+ startSeed: seed ?? 0,
+ })
+ : null;
+
+ return (
+ <SeedInput
+ ariaLabel="Seed"
+ id={id}
+ plan={plan}
+ seed={seed}
+ seedMode={seedMode}
+ onCommit={(patch) => {
+ if (patch.seed !== undefined) {
+ setSeed(patch.seed);
+ }
+
+ onCommit(patch);
+ }}
+ />
+ );
+};
+
+const renderHost = async (seedMode: SeedMode, initialSeed: number | undefined, id?: string) => {
+ const onCommit = vi.fn();
+
+ await act(() => {
+ root.render(
+ <ChakraProvider value={system}>
+ <Host id={id} initialSeed={initialSeed} seedMode={seedMode} onCommit={onCommit} />
+ </ChakraProvider>
+ );
+ });
+
+ return onCommit;
+};
+
+/** Zag writes an external value into the input on an animation frame; wait two out so the DOM is settled. */
+const settle = async (action: () => void) => {
+ await act(async () => {
+ action();
+ await new Promise<void>((resolve) => {
+ requestAnimationFrame(() => requestAnimationFrame(() => resolve()));
+ });
+ });
+};
+
+const seedInput = () => host.querySelector<HTMLInputElement>('input[aria-label="Seed"]');
+const dice = () => host.querySelector<HTMLButtonElement>('button[aria-label="common.newSeed"]');
+
+describe('SeedInput', () => {
+ it('shows the seed the dice rolled, not the one it replaced', async () => {
+ const onCommit = await renderHost('fixed', 42);
+
+ expect(seedInput()?.value).toBe('42');
+
+ await settle(() => dice()?.click());
+
+ const rolled = (onCommit.mock.calls[0]?.[0] as SeedInputPatch | undefined)?.seed as number;
+
+ expect(Number.isInteger(rolled)).toBe(true);
+ expect(rolled).not.toBe(42);
+ // The host adopted the roll; the input has to show it, the same as any other external seed change.
+ expect(seedInput()?.value).toBe(String(rolled));
+ });
+
+ it('shows the rolled seed under a host-supplied id too', async () => {
+ // A host id must reach the element through zag's id map; overriding the attribute
+ // would leave the DOM value stale after an external change.
+ const onCommit = await renderHost('fixed', 42, 'node-1-seed');
+
+ expect(seedInput()?.id).toBe('node-1-seed');
+
+ await settle(() => dice()?.click());
+
+ const rolled = (onCommit.mock.calls[0]?.[0] as SeedInputPatch | undefined)?.seed as number;
+
+ expect(seedInput()?.value).toBe(String(rolled));
+ });
+
+ it('steps the seed with the stepper controls', async () => {
+ const onCommit = await renderHost('fixed', 42);
+
+ // Zag steps on press, so a real pointer sequence rather than a synthetic click.
+ await act(async () => {
+ await userEvent.click(host.querySelector<HTMLButtonElement>('[data-part="increment-trigger"]') as HTMLElement);
+ await new Promise<void>((resolve) => {
+ requestAnimationFrame(() => requestAnimationFrame(() => resolve()));
+ });
+ });
+
+ expect(onCommit).toHaveBeenCalledWith({ seed: 43 });
+ expect(seedInput()?.value).toBe('43');
+ });
+
+ it('commits only integers, rounding a typed fraction', async () => {
+ const onCommit = await renderHost('fixed', 42);
+ const input = seedInput() as HTMLInputElement;
+
+ // A pasted fraction arrives whole; a typed one is rounded at every keystroke, so the
+ // decimal point never survives either way.
+ await act(async () => {
+ await userEvent.fill(input, '1.5');
+ await new Promise<void>((resolve) => {
+ requestAnimationFrame(() => requestAnimationFrame(() => resolve()));
+ });
+ });
+
+ const committed = onCommit.mock.calls.map((call) => (call[0] as SeedInputPatch).seed);
+
+ expect(committed.length).toBeGreaterThan(0);
+ expect(committed.every((seed) => Number.isInteger(seed))).toBe(true);
+ expect(committed.at(-1)).toBe(2);
+ expect(input.value).toBe('2');
+ });
+
+ it('labels the stepper controls', async () => {
+ await renderHost('fixed', 42);
+
+ expect(host.querySelector('[data-part="increment-trigger"]')?.getAttribute('aria-label')).toBe(
+ 'common.increaseValue'
+ );
+ expect(host.querySelector('[data-part="decrement-trigger"]')?.getAttribute('aria-label')).toBe(
+ 'common.decreaseValue'
+ );
+ });
+
+ it('keeps the entered seed on show in random mode while quieting the input and the dice', async () => {
+ await renderHost('random', 42);
+
+ expect(seedInput()?.value).toBe('42');
+ expect(seedInput()?.disabled).toBe(true);
+ expect(dice()?.disabled).toBe(true);
+ });
+
+ it('previews the batch and describes the input with it only in a stepping mode', async () => {
+ await renderHost('increment', 42);
+
+ const preview = host.querySelector<HTMLElement>('[data-testid="seed-sequence-preview"]');
+
+ expect(preview?.textContent).toBe('common.seedNextBatchRange');
+ expect(seedInput()?.getAttribute('aria-describedby')).toBe(preview?.id);
+
+ await renderHost('fixed', 42);
+
+ expect(host.querySelector('[data-testid="seed-sequence-preview"]')).toBeNull();
+ expect(seedInput()?.getAttribute('aria-describedby')).toBeNull();
+ });
+
+ it('renders an empty field for an absent seed without committing anything', async () => {
+ const onCommit = await renderHost('fixed', undefined);
+
+ expect(seedInput()?.value).toBe('');
+ expect(onCommit).not.toHaveBeenCalled();
+ });
+});
diff --git a/invokeai/frontend/webv2/src/platform/ui/SeedInput.tsx b/invokeai/frontend/webv2/src/platform/ui/SeedInput.tsx
new file mode 100644
index 0000000000..4e85a723c7
--- /dev/null
+++ b/invokeai/frontend/webv2/src/platform/ui/SeedInput.tsx
@@ -0,0 +1,223 @@
+/* oxlint-disable react-perf/jsx-no-new-function-as-prop, react-perf/jsx-no-jsx-as-prop */
+import type { SeedMode, SeedSubmissionPlan } from '@platform/core/seed';
+import type { LucideIcon } from 'lucide-react';
+
+import { HStack, Icon, Menu, NumberInput, Portal, Stack, Text } from '@chakra-ui/react';
+import { SEED_MAX, SEED_MODES } from '@platform/core/seed';
+import { ChevronDownIcon, DicesIcon, LocateFixedIcon, MinusIcon, PlusIcon, ShuffleIcon } from 'lucide-react';
+import { useId, useMemo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { Button, IconButton } from './Button';
+import { MenuContent } from './Menu';
+import { Tooltip } from './Tooltip';
+
+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,
+};
+
+export interface SeedModeMenuProps {
+ value: SeedMode;
+ onChange: (mode: SeedMode) => void;
+ /** A second tooltip line for hosts that need to say what one step means (a queued run, not a loop pass). */
+ description?: 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, description, onChange, 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('common.seedMode.label');
+ const valueLabel = t(`common.seedMode.${value}`);
+ const accessibleName = `${label}: ${valueLabel}`;
+
+ return (
+ <Menu.Root ids={triggerIds} positioning={SEED_MODE_MENU_POSITIONING}>
+ {/* The visible label may truncate in a dense row; the full name always reads here and in the tooltip. */}
+ <Tooltip
+ content={
+ description ? (
+ <Stack gap="0.5">
+ <Text>{accessibleName}</Text>
+ <Text color="fg.subtle">{description}</Text>
+ </Stack>
+ ) : (
+ accessibleName
+ )
+ }
+ ids={triggerIds}
+ >
+ <Menu.Trigger asChild>
+ <Button aria-label={accessibleName} flexShrink={0} gap="1" maxW="9rem" minW="0" size="xs" variant="outline">
+ <Icon as={SEED_MODE_ICONS[value]} boxSize="3.5" color="fg.muted" flexShrink={0} />
+ <Text as="span" minW="0" truncate>
+ {valueLabel}
+ </Text>
+ <Icon as={ChevronDownIcon} boxSize="3" color="fg.muted" flexShrink={0} />
+ </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(`common.seedMode.${mode}`)}</Menu.ItemText>
+ <Text color="fg.subtle" fontSize="2xs">
+ {t(`common.seedMode.${mode}Description`)}
+ </Text>
+ </Stack>
+ </Menu.RadioItem>
+ ))}
+ </Menu.RadioItemGroup>
+ </MenuContent>
+ </Menu.Positioner>
+ </Portal>
+ </Menu.Root>
+ );
+};
+
+export interface SeedSequencePreviewProps {
+ /** Id the seed input names in `aria-describedby`. */
+ id?: string;
+ plan: Pick<SeedSubmissionPlan, 'lastSeed' | 'sequenceLength' | 'startSeed'>;
+}
+
+/** Where the next submission's seeds start and end; the host resolves the run count it plans with. */
+export const SeedSequencePreview = ({ id, plan }: SeedSequencePreviewProps) => {
+ const { t } = useTranslation();
+
+ return (
+ <Text color="fg.subtle" css={TABULAR_NUMS} data-testid="seed-sequence-preview" fontSize="2xs" id={id}>
+ {plan.sequenceLength > 1
+ ? t('common.seedNextBatchRange', { first: plan.startSeed, last: plan.lastSeed })
+ : t('common.seedNextBatch', { seed: plan.startSeed })}
+ </Text>
+ );
+};
+
+export interface SeedInputPatch {
+ seed?: number;
+ seedMode?: SeedMode;
+}
+
+export interface SeedInputProps {
+ /** Accessible name of the number input; the host renders any visible label. */
+ ariaLabel: string;
+ /** Absent while the host's field is empty. */
+ seed: number | undefined;
+ seedMode: SeedMode;
+ /** The next submission's stepping plan, resolved by whoever owns the run count; null when the seed holds. */
+ plan: SeedSubmissionPlan | null;
+ id?: string;
+ invalid?: boolean;
+ /** Classes on the row, for hosts whose surroundings watch pointer or keys (xyflow's `nodrag nokey`). */
+ className?: string;
+ description?: string;
+ contentClassName?: string;
+ onCommit: (patch: SeedInputPatch) => void;
+}
+
+/**
+ * The seed control every seeded host shares: the number input with the
+ * one-shot new-seed action inside it, the mode menu beside it, and the
+ * stepping preview underneath. Random quiets the input and the dice but keeps
+ * the value on show, so it is there again the moment the mode changes back.
+ */
+export const SeedInput = ({
+ ariaLabel,
+ className,
+ contentClassName,
+ description,
+ id,
+ invalid,
+ onCommit,
+ plan,
+ seed,
+ seedMode,
+}: SeedInputProps) => {
+ const { t } = useTranslation();
+ const previewId = useId();
+ const isRandom = seedMode === 'random';
+ // The host's id goes through zag's id map, never onto the element: zag syncs the DOM value
+ // by looking the input up under its own id, so an overriding `id` leaves an external change
+ // (the dice, a recall, an advance) invisible until the next keystroke.
+ const inputIds = useMemo(() => (id ? { input: id } : undefined), [id]);
+ const stepperTranslations = useMemo(
+ () => ({ decrementLabel: t('common.decreaseValue'), incrementLabel: t('common.increaseValue') }),
+ [t]
+ );
+
+ return (
+ <Stack className={className} gap="1" w="full">
+ <HStack gap="1">
+ <NumberInput.Root
+ disabled={isRandom}
+ flex="1"
+ ids={inputIds}
+ invalid={invalid}
+ max={SEED_MAX}
+ min={0}
+ minW="0"
+ size="xs"
+ value={seed === undefined ? '' : String(seed)}
+ translations={stepperTranslations}
+ onValueChange={({ valueAsNumber }) => {
+ // A seed is an integer: a typed fraction rounds rather than reaching the graph.
+ if (Number.isFinite(valueAsNumber)) {
+ onCommit({ seed: Math.round(valueAsNumber) });
+ }
+ }}
+ >
+ <NumberInput.Control />
+ <NumberInput.Input
+ aria-describedby={plan ? previewId : undefined}
+ aria-label={ariaLabel}
+ css={TABULAR_NUMS}
+ />
+ </NumberInput.Root>
+ {/* The tooltip is the visible hint; the accessible name stays on the button because a
+ tooltip only describes its trigger while open. */}
+ <Tooltip content={t('common.newSeed')}>
+ <IconButton
+ aria-label={t('common.newSeed')}
+ color="fg.muted"
+ disabled={isRandom}
+ flexShrink={0}
+ size="xs"
+ variant="outline"
+ onClick={() => onCommit({ seed: Math.floor(Math.random() * SEED_MAX) })}
+ >
+ <DicesIcon />
+ </IconButton>
+ </Tooltip>
+ <SeedModeMenu
+ contentClassName={contentClassName}
+ description={description}
+ value={seedMode}
+ onChange={(nextMode) => onCommit({ seedMode: nextMode })}
+ />
+ </HStack>
+ {plan ? <SeedSequencePreview id={previewId} plan={plan} /> : null}
+ </Stack>
+ );
+};
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.ts b/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.ts
index f6afb3f8a5..153c1c6644 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.ts
@@ -8,26 +8,26 @@ import type {
} from '@features/generation/contracts';
import {
+ clampDimension,
+ cloneGenerateWidgetValues,
+ deriveAspectRatioId,
getCompatibleReferenceImages,
getDimensionGrid,
getGenerationUiPolicy,
+ getModelDefaultVae,
getSettingsWithModelDefaults,
hasArchitectureCapabilities,
- isKnownScheduler,
- isVaeCompatibleWithGenerateModel,
- isValidKrea2RebalanceWeights,
- cloneGenerateWidgetValues,
- getModelDefaultVae,
hasModelDefaultVae,
+ isKnownScheduler,
isMainModelConfig,
isModelIdentifierConfig,
- clampDimension,
- deriveAspectRatioId,
- normalizeReferenceImages,
+ isVaeCompatibleWithGenerateModel,
+ isValidKrea2RebalanceWeights,
MAX_HIDIFFUSION_RATIO,
MIN_HIDIFFUSION_T1_RATIO,
- SEED_MAX,
+ normalizeReferenceImages,
} from '@features/generation/settings';
+import { SEED_MAX } from '@platform/core/seed';
export type ImageRecallKind = 'all' | 'remix' | 'prompts' | 'seed' | 'dimensions' | 'clipSkip';
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/videoRecall.ts b/invokeai/frontend/webv2/src/workbench/image-actions/videoRecall.ts
index 8a4f14963d..c27236f232 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/videoRecall.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/videoRecall.ts
@@ -6,7 +6,7 @@ import type {
} from '@features/generation/contracts';
import type { VideoAspectRatioId, VideoTargetResolution, VideoWidgetValues } from '@features/video';
-import { isLoraCompatibleWithModel, isLoraModelConfig, SEED_MAX } from '@features/generation/settings';
+import { isLoraCompatibleWithModel, isLoraModelConfig } from '@features/generation/settings';
import {
findAcceleratorLorasIn,
getAcceleratorSteps,
@@ -19,6 +19,7 @@ import {
isValidVideoNumFrames,
snapVideoNumFrames,
} from '@features/video';
+import { SEED_MAX } from '@platform/core/seed';
/**
* Pure mapping from a video's recorded `core_metadata` to a Video-panel
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
index 9c4ffcfdc0..ea8113f161 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
@@ -70,6 +70,7 @@ import {
type GallerySettings,
type GeneratedImageContract,
} from '@features/gallery/contracts';
+import { planSeedSubmission } from '@platform/core/seed';
import { WIDGET_REGIONS } from '@workbench/layoutContracts';
import { prependProjectEvent, PROJECT_EVENT_LIMIT } from '@workbench/projectEvents';
@@ -93,6 +94,8 @@ import { gateProjectCanvases } from './projectCanvasGate';
import { normalizeRestoredQueueItem } from './queue-integration/queueRunRestoration';
import { getProjectWidgetValues } from './widgetState';
export { nextLayerName } from './canvasProjectMutations';
+import type { ProjectPromptDraftPatch } from '@features/generation/settings';
+
import { compileGenerateGraph, resolveGenerateSeed } from '@features/generation/graph';
import {
addPromptHistoryItem,
@@ -106,8 +109,6 @@ import {
migrateProjectPromptDraft,
normalizeGenerateSettings,
normalizeGenerateWidgetValues,
- planSeedSubmission,
- type ProjectPromptDraftPatch,
removePromptHistoryItem,
sanitizeBatchCount,
syncGenerateWidgetValuesWithModels,
diff --git a/invokeai/frontend/webv2/vite.config.mts b/invokeai/frontend/webv2/vite.config.mts
index 6634e5d1e6..0e69f9a993 100644
--- a/invokeai/frontend/webv2/vite.config.mts
+++ b/invokeai/frontend/webv2/vite.config.mts
@@ -97,7 +97,7 @@ const EDITOR_BOOT_SHARED_MODULES = [
'/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/SeedControls.tsx',
+ '/platform/ui/SeedInput.tsx',
'/workbench/shell/topbar/LayoutPresetAdminDialogs.tsx',
'/workbench/shell/topbar/LayoutPresetStrip.tsx',
'/workbench/shell/topbar/ProjectSwitcher.tsx',
@@ -191,7 +191,7 @@ const getLegacyChunkName = (id: string): string | null => {
'/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',
+ '/platform/core/seed.ts',
])
) {
return 'shared';