Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
feat(webv2): give workflow runs their own iteration count and seed preview
Josh Corbettf1a37b075e22
diff --git a/invokeai/frontend/webv2/performance/architecture-baseline.json b/invokeai/frontend/webv2/performance/architecture-baseline.jsonindex ef65d5d84c..aa99a13824 100644--- a/invokeai/frontend/webv2/performance/architecture-baseline.json+++ b/invokeai/frontend/webv2/performance/architecture-baseline.json@@ -551,7 +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/shared/SeedControls.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 8cd708c8c6..c582260de2 100644--- a/invokeai/frontend/webv2/performance/browser-baseline.json+++ b/invokeai/frontend/webv2/performance/browser-baseline.json@@ -1040,8 +1040,8 @@"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/SeedModeMenu.tsx","source:src/features/generation/ui/shared/modelDefaultSettings.ts","source:src/features/generation/ui/useDebouncedDraftValue.ts","source:src/features/generation/ui/useDynamicPrompts.ts",@@ -2072,8 +2072,8 @@"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/SeedModeMenu.tsx","source:src/features/generation/ui/shared/modelDefaultSettings.ts","source:src/features/generation/ui/useDebouncedDraftValue.ts","source:src/features/generation/ui/useDynamicPrompts.ts",@@ -3197,7 +3197,7 @@"source:src/features/generation/queries.ts","source:src/features/generation/react.ts","source:src/features/generation/runtime.ts",- "source:src/features/generation/seedModeMenu.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,8 +3263,8 @@"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/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 b4c684678e..dc5a8a17a8 100644--- a/invokeai/frontend/webv2/src/architecture/dependencyPolicy.test.ts+++ b/invokeai/frontend/webv2/src/architecture/dependencyPolicy.test.ts@@ -242,7 +242,7 @@ describe('feature public-interface registry', () => {// 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')+ checkDependency('features/workflow/ui/fields/WorkflowFieldInput.tsx', '@features/generation/seedControls')).toEqual([]);expect(checkDependency('workbench/invocationSubmit.ts', '@features/generation/data/dynamicPromptsQueries')diff --git a/invokeai/frontend/webv2/src/architecture/featureInterfaces.ts b/invokeai/frontend/webv2/src/architecture/featureInterfaces.tsindex 5c4c449104..27f409a8ae 100644--- a/invokeai/frontend/webv2/src/architecture/featureInterfaces.ts+++ b/invokeai/frontend/webv2/src/architecture/featureInterfaces.ts@@ -30,7 +30,7 @@ export const FEATURE_PUBLIC_INTERFACES: Readonly<Record<string, readonly string['react','runtime','seed',- 'seedModeMenu',+ 'seedControls','settings','widget',],diff --git a/invokeai/frontend/webv2/src/features/generation/seedControls.ts b/invokeai/frontend/webv2/src/features/generation/seedControls.tsnew file mode 100644index 0000000000..7a4a5ea0d1--- /dev/null+++ b/invokeai/frontend/webv2/src/features/generation/seedControls.ts@@ -0,0 +1,12 @@+/**+ * 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/seedModeMenu.ts b/invokeai/frontend/webv2/src/features/generation/seedModeMenu.tsdeleted file mode 100644index cfd4cfb075..0000000000--- a/invokeai/frontend/webv2/src/features/generation/seedModeMenu.ts+++ /dev/null@@ -1,6 +0,0 @@-/**- * 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/ui/shared/SeedModeMenu.tsx b/invokeai/frontend/webv2/src/features/generation/ui/shared/SeedControls.tsxsimilarity index 79%rename from invokeai/frontend/webv2/src/features/generation/ui/shared/SeedModeMenu.tsxrename to invokeai/frontend/webv2/src/features/generation/ui/shared/SeedControls.tsxindex bb49f8f567..11d76b223e 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/shared/SeedModeMenu.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/shared/SeedControls.tsx@@ -1,5 +1,5 @@/* oxlint-disable react-perf/jsx-no-new-function-as-prop */-import type { SeedMode } from '@features/generation/core/seed';+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';@@ -12,6 +12,7 @@ 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,@@ -77,3 +78,22 @@ export const SeedModeMenu = ({ contentClassName, onChange, tooltip, value }: See</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.tsxindex 7cc9e45fc3..70e52ce069 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/shared/SeedField.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/shared/SeedField.tsx@@ -3,7 +3,7 @@ import type { DynamicPromptsSeedBehaviour } from '@features/generation/core/dynaimport type { SeedMode } from '@features/generation/core/seed';import type { ReactNode } from 'react';-import { HStack, InputGroup, NumberInput, Stack, Text } from '@chakra-ui/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 { Field } from '@platform/ui/Field';@@ -11,10 +11,9 @@ import { DicesIcon } from 'lucide-react';import { useId } from 'react';import { useTranslation } from 'react-i18next';-import { SeedModeMenu } from './SeedModeMenu';+import { SeedModeMenu, SeedSequencePreview, TABULAR_NUMS } from './SeedControls';const SEED_END_ELEMENT_PROPS = { pointerEvents: 'auto', pr: '0.5' } as const;-const TABULAR_NUMS = { fontVariantNumeric: 'tabular-nums' } as const;export interface SeedFieldPatch {seed?: number;@@ -104,13 +103,7 @@ export const SeedField = ({</NumberInput.Root><SeedModeMenu value={seedMode} onChange={(nextMode) => onCommit({ seedMode: nextMode })} /></HStack>- {plan ? (- <Text color="fg.subtle" css={TABULAR_NUMS} data-testid="seed-sequence-preview" fontSize="2xs" id={previewId}>- {plan.sequenceLength > 1- ? t('widgets.generate.seedNextBatchRange', { first: plan.startSeed, last: plan.lastSeed })- : t('widgets.generate.seedNextBatch', { seed: plan.startSeed })}- </Text>- ) : null}+ {plan ? <SeedSequencePreview id={previewId} plan={plan} /> : null}{children}</Stack></Field>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.tsxindex 1446a0508d..11fb43a4a3 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@@ -94,7 +94,13 @@ const ADDABLE_LORA = {const galleryValues: Record<string, unknown> = {};const graphNodes: unknown[] = [];const graphEdges: unknown[] = [];-const projectSnapshot = { galleryValues, id: 'project-1', projectGraph: { edges: graphEdges, nodes: graphNodes } };+const workflowValues: Record<string, unknown> = {};+const projectSnapshot = {+ galleryValues,+ id: 'project-1',+ projectGraph: { edges: graphEdges, nodes: graphNodes },+ workflowValues,+};vi.mock('@features/workflow/ui/WorkflowUiContext', () => ({useWorkflowProjectSelector: (selector: (project: typeof projectSnapshot) => unknown) => selector(projectSnapshot),@@ -190,6 +196,7 @@ beforeEach(() => {delete galleryValues.selectedImage;graphNodes.length = 0;graphEdges.length = 0;+ delete workflowValues.batchCount;});afterEach(async () => {@@ -701,6 +708,8 @@ 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.+ host.style.width = '18rem';await renderField(SEED_TEMPLATE, 42, onChange, undefined, { onSeedModeChange, seedMode: 'fixed' });expect(seedInput()?.disabled).toBe(false);@@ -719,6 +728,34 @@ describe('WorkflowFieldInput seed inputs', () => {expect(onChange).not.toHaveBeenCalled();});+ it("previews the next batch from the workflow's own run count and describes the input with it", async () => {+ workflowValues.batchCount = 3;++ await renderField(SEED_TEMPLATE, 42, vi.fn(), undefined, { onSeedModeChange: vi.fn(), seedMode: 'increment' });++ 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(seedInput()?.getAttribute('aria-describedby')).toBe(preview?.id);++ await renderField(SEED_TEMPLATE, 42, vi.fn(), undefined, { onSeedModeChange: vi.fn(), seedMode: 'fixed' });++ expect(host.querySelector('[data-testid="seed-sequence-preview"]')).toBeNull();+ expect(seedInput()?.getAttribute('aria-describedby')).toBeNull();++ // An empty field previews from the template default, which is where the plan starts it.+ workflowValues.batchCount = 2;+ await renderField({ ...SEED_TEMPLATE, default: 1_234 } as FieldInputTemplate, undefined, vi.fn(), undefined, {+ onSeedModeChange: vi.fn(),+ seedMode: 'increment',+ });++ expect(host.querySelector('[data-testid="seed-sequence-preview"]')?.textContent).toBe(+ 'widgets.generate.seedNextBatchRange'+ );+ });+it('quiets the value in random mode but keeps it on show', async () => {await renderField(SEED_TEMPLATE, 42, vi.fn(), undefined, { onSeedModeChange: vi.fn(), seedMode: 'random' });diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.tsxindex 6afd187e71..4a263686bf 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/fields/WorkflowFieldInput.tsx@@ -31,8 +31,9 @@ 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 { SeedModeMenu } from '@features/generation/seedModeMenu';-import { DEFAULT_LORA_WEIGHT_CONFIG, SCHEDULER_OPTIONS } from '@features/generation/settings';+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';import {@@ -161,13 +162,14 @@ const StringInput = ({ id, invalid, onChange, template, value }: WorkflowFieldIn};const NumericInput = ({+ describedBy,disabled,id,invalid,onChange,template,value,-}: WorkflowFieldInputProps & { disabled?: boolean }) => {+}: WorkflowFieldInputProps & { describedBy?: string; disabled?: boolean }) => {const isInteger = template.type.name === 'IntegerField';const numericValue = typeof value === 'number' && Number.isFinite(value) ? value : '';const min = template.minimum ?? template.exclusiveMinimum ?? undefined;@@ -185,6 +187,7 @@ const NumericInput = ({return (<Input+ aria-describedby={describedBy}aria-label={template.title}className="nodrag"disabled={disabled}@@ -217,17 +220,40 @@ const SeedInput = ({...props}: 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 plan =+ seedMode === 'increment' || seedMode === 'decrement'+ ? planSeedSubmission({+ batchCount,+ promptCount: 1,+ seedBehaviour: 'per-iteration',+ seedMode,+ startSeed: wrapSeed(authoredSeed),+ })+ : null;return (- <HStack className="nodrag nokey" gap="1" w="full">- <NumericInput {...props} disabled={seedMode === 'random'} />- <SeedModeMenu- contentClassName="nokey"- tooltip={t('nodes.seedModeTooltip')}- value={seedMode}- onChange={onSeedModeChange}- />- </HStack>+ <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"+ tooltip={t('nodes.seedModeTooltip')}+ value={seedMode}+ onChange={onSeedModeChange}+ />+ </HStack>+ {plan ? <SeedSequencePreview id={previewId} plan={plan} /> : null}+ </Stack>);};diff --git a/invokeai/frontend/webv2/src/workbench/invocation.ts b/invokeai/frontend/webv2/src/workbench/invocation.tsindex ca0e15d739..3770efd7ad 100644--- a/invokeai/frontend/webv2/src/workbench/invocation.ts+++ b/invokeai/frontend/webv2/src/workbench/invocation.ts@@ -95,6 +95,7 @@ export interface InvocationRouteInput {generateValues: Record<string, unknown>;upscaleValues: Record<string, unknown>;videoValues: Record<string, unknown>;+ workflowValues: Record<string, unknown>;invocation: InvocationRoute;mountedWidgetIds: readonly WidgetId[];projectGraph: ProjectGraphState;@@ -139,6 +140,7 @@ export const getInvocationRouteInput = (project: Project): InvocationRouteInputgenerateValues: getProjectWidgetValues(project, 'generate'),upscaleValues: getProjectWidgetValues(project, 'upscale'),videoValues: getProjectWidgetValues(project, 'video'),+ workflowValues: getProjectWidgetValues(project, 'workflow'),invocation: project.invocation,mountedWidgetIds: getMountedWidgetIds(project),projectGraph: project.projectGraph,@@ -152,6 +154,7 @@ export const areInvocationRouteInputsEqual = (left: InvocationRouteInput, right:left.generateValues === right.generateValues &&left.upscaleValues === right.upscaleValues &&left.videoValues === right.videoValues &&+ left.workflowValues === right.workflowValues &&left.canvasBbox.width === right.canvasBbox.width &&left.canvasBbox.height === right.canvasBbox.height &&left.canvasLayers === right.canvasLayers &&diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/IterationsField.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/IterationsField.tsxindex 95028d99d5..b480ddb476 100644--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/IterationsField.tsx+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/IterationsField.tsx@@ -1,6 +1,7 @@import { NumberInput } from '@chakra-ui/react';import { MIN_BATCH_COUNT } from '@features/generation/settings';import { Tooltip } from '@platform/ui/Tooltip';+import { getProjectWidgetValues } from '@workbench/widgetState';import { useActiveProjectSelector, useWorkbenchCommands } from '@workbench/WorkbenchContext';import { useCallback } from 'react';import { useTranslation } from 'react-i18next';@@ -19,10 +20,10 @@ export const IterationsField = () => {const { batchCount, sourceId } = useActiveProjectSelector((project) => {const sourceId = project.invocation.sourceId;- const typeId = sourceId === 'upscale' ? 'upscale' : sourceId === 'video' ? 'video' : 'generate';- const instance = Object.values(project.widgetInstances).find((candidate) => candidate.typeId === typeId);+ const typeId = sourceId === 'upscale' || sourceId === 'video' || sourceId === 'workflow' ? sourceId : 'generate';- return { batchCount: getBatchCount(instance?.state.values ?? {}), sourceId };+ // The same resolution the patch command writes through, so reader and writer agree on the instance.+ return { batchCount: getBatchCount(getProjectWidgetValues(project, typeId)), sourceId };},(left, right) => left.batchCount === right.batchCount && left.sourceId === right.sourceId);@@ -33,7 +34,7 @@ export const IterationsField = () => {return;}- if (sourceId === 'upscale' || sourceId === 'video') {+ if (sourceId === 'upscale' || sourceId === 'video' || sourceId === 'workflow') {widgets.patchValues(sourceId, { batchCount: valueAsNumber });} else {generation.setBatchCount(valueAsNumber);diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/useInvocationState.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/useInvocationState.browser.test.tsxindex 2695deac41..2831c6d101 100644--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/useInvocationState.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/useInvocationState.browser.test.tsx@@ -95,7 +95,15 @@ const buildGenerateProject = (): Project => {let host: HTMLDivElement | null = null;let root: Root | null = null;-const Probe = (): ReactNode => <span data-testid="reasons">{useInvocationState().blockingReasons.join(' | ')}</span>;+const Probe = (): ReactNode => {+ const state = useInvocationState();++ return (+ <span data-batch-count={state.batchCount} data-testid="reasons">+ {state.blockingReasons.join(' | ')}+ </span>+ );+};const renderProbe = async (project: Project) => {harness.project = project;@@ -155,4 +163,14 @@ describe('useInvocationState and the workflow node templates', () => {expect(blockingReasons()).not.toContain('Node definitions are still loading.');});++ it("reports the workflow widget's own iteration count for a workflow route", async () => {+ setArchitectureCapabilities(architectureCapabilitiesFixture);+ let state = workbenchReducer(createInitialWorkbenchState(), { sourceId: 'workflow', type: 'setInvocationSource' });+ state = workbenchReducer(state, { type: 'patchWidgetValues', values: { batchCount: 5 }, widgetId: 'generate' });+ state = workbenchReducer(state, { type: 'patchWidgetValues', values: { batchCount: 3 }, widgetId: 'workflow' });+ await renderProbe(activeProject(state));++ expect(host?.querySelector('[data-testid="reasons"]')?.getAttribute('data-batch-count')).toBe('3');+ });});diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/useInvocationState.ts b/invokeai/frontend/webv2/src/workbench/shell/topbar/useInvocationState.tsindex 0ced0b464d..997d289301 100644--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/useInvocationState.ts+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/useInvocationState.ts@@ -139,7 +139,9 @@ export const useInvocationState = (): InvocationState => {? routeInput.upscaleValues: invocation.sourceId === 'video'? routeInput.videoValues- : routeInput.generateValues;+ : invocation.sourceId === 'workflow'+ ? routeInput.workflowValues+ : routeInput.generateValues;const promptExpansion = useDynamicPrompts(readEffectivePositivePrompt(routeInput.generateValues),diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.test.tsindex 10a727971b..489d32a338 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts@@ -968,6 +968,39 @@ describe('adopting a project from another realm', () => {expect(normalized.queue.items).toEqual([]);});+ it('carries the iteration count workflow runs borrowed from Generate over to the workflow widget once', () => {+ const workflowValuesOf = (candidate: Project) => getProjectWidgetValues(candidate, 'workflow');+ const withoutWorkflowCount = (candidate: Project): Project => {+ const { batchCount: _, ...values } = workflowValuesOf(candidate);+ const instance = candidate.widgetInstances.workflow!;++ return {+ ...candidate,+ widgetInstances: {+ ...candidate.widgetInstances,+ workflow: { ...instance, state: { ...instance.state, values } },+ },+ };+ };+ let state = workbenchReducer(createInitialWorkbenchState(), {+ type: 'patchWidgetValues',+ values: { batchCount: 4 },+ widgetId: 'generate',+ });+ const fresh = getActiveProject(state);++ state = workbenchReducer(state, { type: 'patchWidgetValues', values: { batchCount: 2 }, widgetId: 'workflow' });+ const owned = getActiveProject(state);++ // A fresh project owns its default from the start, so Generate's count never reaches it, reload after reload.+ expect(workflowValuesOf(fresh).batchCount).toBe(1);+ expect(workflowValuesOf(normalizeWorkbenchProject(fresh)).batchCount).toBe(1);+ // A project saved before the widget owned a count keeps the runs it effectively had.+ expect(workflowValuesOf(normalizeWorkbenchProject(withoutWorkflowCount(fresh))).batchCount).toBe(4);+ // A count the workflow already owns is never overwritten by Generate's.+ expect(workflowValuesOf(normalizeWorkbenchProject(owned)).batchCount).toBe(2);+ });+it('preserves and caps session events during live normalization', () => {const project = createInitialWorkbenchState().projects[0]!;project.events = Array.from({ length: PROJECT_EVENT_LIMIT + 1 }, (_, index) => ({@@ -3328,7 +3361,7 @@ describe('workbenchReducer Phase 5 generation flow', () => {// The Automate preset mounts the Workflow widget, which the route requires.let state = workbenchReducer(createInitialWorkbenchState(), { presetId: 'automate', type: 'applyPreset' });- state = workbenchReducer(state, { type: 'patchWidgetValues', values: { batchCount }, widgetId: 'generate' });+ state = workbenchReducer(state, { type: 'patchWidgetValues', values: { batchCount }, widgetId: 'workflow' });state = workbenchReducer(state, {action: {node: {@@ -3388,7 +3421,14 @@ describe('workbenchReducer Phase 5 generation flow', () => {});it('holds a fixed seed as a graph constant and repeats the graph for every run', () => {- const state = submitWorkflow(primeWorkflow(42, 'fixed'));+ // Generate's own iteration count no longer leaks into workflow runs.+ const state = submitWorkflow(+ workbenchReducer(primeWorkflow(42, 'fixed'), {+ type: 'patchWidgetValues',+ values: { batchCount: 5 },+ widgetId: 'generate',+ })+ );const submission = readSubmission(state);expect(submission).toMatchObject({ batchCount: 3, kind: 'workflow' });diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.tsindex f93619297c..9c4ffcfdc0 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts@@ -1183,7 +1183,7 @@ const createWidgetStates = (): WidgetStateMap => ({queue: { id: 'queue', label: 'Queue', values: {}, version: 1 },'server-status': { id: 'server-status', label: 'Server Status', values: {}, version: 1 },users: { id: 'users', label: 'Users', values: {}, version: 1 },- workflow: { graphId: 'workflow-graph', id: 'workflow', label: 'Workflow', values: {}, version: 1 },+ workflow: { graphId: 'workflow-graph', id: 'workflow', label: 'Workflow', values: { batchCount: 1 }, version: 1 },upscale: { graphId: 'upscale-graph', id: 'upscale', label: 'Upscale', values: {}, version: 1 },video: { graphId: 'video-graph', id: 'video', label: 'Video', values: {}, version: 1 },});@@ -1679,6 +1679,24 @@ const assembleWorkbenchProject = (}}+ // Workflow runs used to borrow Generate's iteration count. A project saved before the+ // widget owned one has no key; carry the count over once so it keeps the runs it+ // effectively had. A fresh project starts with the widget's own default, so it never migrates.+ const workflowInstance = widgetInstances.workflow;++ if (workflowInstance && typeof workflowInstance.state.values.batchCount !== 'number') {+ widgetInstances.workflow = {+ ...workflowInstance,+ state: {+ ...workflowInstance.state,+ values: {+ ...workflowInstance.state.values,+ batchCount: sanitizeBatchCount(generateInstance?.state.values.batchCount),+ },+ },+ };+ }+if (leftRegion.instanceIds.includes('upscale') && !widgetInstances.upscale) {widgetInstances.upscale = createWidgetInstance('upscale');}@@ -2450,7 +2468,7 @@ const compileInvocationSnapshot = (}const { graph, ...workflow } = planWorkflowSubmission(project.projectGraph, templatesSnapshot.templates, {- batchCount: sanitizeBatchCount(widgetStates.generate?.values.batchCount),+ batchCount: sanitizeBatchCount(widgetStates.workflow?.values.batchCount),});return { graph, widgetStates, workflow };@@ -3176,19 +3194,21 @@ const enqueueCompiledSnapshot = (const backendSubmission: QueueCompiledSubmission = !backendGraph? { error: `${route.sourceId} queue item is missing a compiled backend graph.`, kind: 'invalid' }: route.sourceId === 'workflow'- ? {- batchCount: compiled.workflow?.batchCount ?? sanitizeBatchCount(widgetStates.generate?.values.batchCount),- ...(compiled.workflow?.seeds.length ? { seeds: compiled.workflow.seeds } : {}),- graph: backendGraph,- kind: 'workflow',- // Provenance for the completed-run capture: a run submitted from a- // library-bound graph knows which record to stamp, even after the- // editor has moved on to another workflow. An unbound graph stamps- // nothing, so an ad-hoc workflow never writes to the library.- ...(project.projectGraph.libraryWorkflowId- ? { libraryWorkflowId: project.projectGraph.libraryWorkflowId }- : {}),- }+ ? !compiled.workflow+ ? { error: 'workflow queue item is missing its seed plan.', kind: 'invalid' }+ : {+ batchCount: compiled.workflow.batchCount,+ ...(compiled.workflow.seeds.length ? { seeds: compiled.workflow.seeds } : {}),+ graph: backendGraph,+ kind: 'workflow',+ // Provenance for the completed-run capture: a run submitted from a+ // library-bound graph knows which record to stamp, even after the+ // editor has moved on to another workflow. An unbound graph stamps+ // nothing, so an ad-hoc workflow never writes to the library.+ ...(project.projectGraph.libraryWorkflowId+ ? { libraryWorkflowId: project.projectGraph.libraryWorkflowId }+ : {}),+ }: sourceGenerateSettings && effectivePrompts? {batchCount: sourceGenerateSettings.batchCount,diff --git a/invokeai/frontend/webv2/vite.config.mts b/invokeai/frontend/webv2/vite.config.mtsindex 4e79afadc5..6634e5d1e6 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/SeedModeMenu.tsx',+ '/features/generation/ui/shared/SeedControls.tsx','/workbench/shell/topbar/LayoutPresetAdminDialogs.tsx','/workbench/shell/topbar/LayoutPresetStrip.tsx','/workbench/shell/topbar/ProjectSwitcher.tsx',